Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <algorithm>
21 : #ifdef WNT
22 : #include <windows.h>
23 : #undef min
24 : #endif
25 : #include <osl_Security_Const.h>
26 : #include <osl/thread.h>
27 : #include <rtl/process.h>
28 : #include <rtl/strbuf.hxx>
29 :
30 : using namespace osl;
31 : using namespace rtl;
32 :
33 : /** print a UNI_CODE String.
34 : */
35 4 : inline void printUString( const ::rtl::OUString & str )
36 : {
37 4 : rtl::OString aString;
38 :
39 : //t_print("#printUString_u# " );
40 4 : aString = ::rtl::OUStringToOString( str, RTL_TEXTENCODING_ASCII_US );
41 4 : t_print("%s\n", aString.getStr( ) );
42 4 : }
43 :
44 : // test code start here
45 :
46 : namespace osl_Security
47 : {
48 :
49 : /** testing the method:
50 : Security()
51 : */
52 3 : class ctors : public CppUnit::TestFixture
53 : {
54 : public:
55 : bool bRes, bRes1;
56 :
57 1 : void ctors_001( )
58 : {
59 1 : ::osl::Security aSec;
60 :
61 2 : CPPUNIT_ASSERT_MESSAGE( "#test comment#: create a security its handle should not be NULL.",
62 2 : aSec.getHandle( ) != NULL );
63 1 : }
64 :
65 2 : CPPUNIT_TEST_SUITE( ctors );
66 1 : CPPUNIT_TEST( ctors_001 );
67 5 : CPPUNIT_TEST_SUITE_END( );
68 : }; // class ctors
69 :
70 : /** testing the methods:
71 : inline sal_Bool SAL_CALL logonUser(const ::rtl::OUString& strName,
72 : const ::rtl::OUString& strPasswd);
73 : inline sal_Bool SAL_CALL logonUser(const ::rtl::OUString & strName,
74 : const ::rtl::OUString & strPasswd,
75 : const ::rtl::OUString & strFileServer);
76 : */
77 0 : class logonUser : public CppUnit::TestFixture
78 : {
79 : public:
80 : bool bRes;
81 :
82 0 : void logonUser_user_pwd( )
83 : {
84 0 : ::osl::Security aSec;
85 0 : bRes = aSec.logonUser( aLogonUser, aLogonPasswd );
86 :
87 0 : CPPUNIT_ASSERT_MESSAGE( "#test comment#: check logon user through forwarded user name, pwd, passed in (UNX), failed in (W32).",
88 0 : bRes );
89 0 : }
90 :
91 0 : void logonUser_user_pwd_server( )
92 : {
93 0 : ::osl::Security aSec;
94 0 : bRes = aSec.logonUser( aLogonUser, aLogonPasswd, aFileServer );
95 :
96 0 : CPPUNIT_ASSERT_MESSAGE( "#test comment#: check logon user through forwarded user name, pwd and server name, failed in (UNX)(W32).",
97 0 : bRes );
98 0 : }
99 :
100 2 : CPPUNIT_TEST_SUITE( logonUser );
101 1 : if ( !aStringForward.isEmpty() && aStringForward.indexOf( (sal_Unicode)' ' ) != -1 && ( aStringForward.indexOf( ( sal_Unicode ) ' ' ) == aStringForward.lastIndexOf( ( sal_Unicode ) ' ' ) ) )
102 : /// if user name and passwd are forwarded
103 : {
104 0 : CPPUNIT_TEST( logonUser_user_pwd );
105 : }
106 1 : if ( !aStringForward.isEmpty() && aStringForward.indexOf( (sal_Unicode)' ' ) != -1 && ( aStringForward.indexOf( ( sal_Unicode ) ' ' ) != aStringForward.lastIndexOf( ( sal_Unicode ) ' ' ) ) )
107 : /// if user name and passwd and file server are forwarded
108 : {
109 0 : CPPUNIT_TEST( logonUser_user_pwd_server );
110 1 : }
111 5 : CPPUNIT_TEST_SUITE_END( );
112 : }; // class logonUser
113 :
114 : /** testing the method:
115 : inline sal_Bool Security::getUserIdent( rtl::OUString& strIdent) const
116 : */
117 3 : class getUserIdent : public CppUnit::TestFixture
118 : {
119 : public:
120 : bool bRes, bRes1;
121 :
122 1 : void getUserIdent_001( )
123 : {
124 1 : ::osl::Security aSec;
125 2 : ::rtl::OUString strID;
126 1 : bRes = aSec.getUserIdent( strID );
127 :
128 2 : rtl::OStringBuffer aMessage;
129 1 : aMessage.append("strUserID: ");
130 1 : aMessage.append(rtl::OUStringToOString(strUserID, osl_getThreadTextEncoding()));
131 1 : aMessage.append(", strID: ");
132 1 : aMessage.append(rtl::OUStringToOString(strID, osl_getThreadTextEncoding()));
133 1 : aMessage.append(", bRes: ");
134 1 : aMessage.append(bRes);
135 :
136 2 : CPPUNIT_ASSERT_MESSAGE( aMessage.getStr(), strUserID.equals(strID) && bRes );
137 1 : }
138 :
139 2 : CPPUNIT_TEST_SUITE( getUserIdent );
140 1 : CPPUNIT_TEST( getUserIdent_001 );
141 5 : CPPUNIT_TEST_SUITE_END( );
142 : }; // class getUserIdent
143 :
144 : /** testing the method:
145 : inline sal_Bool SAL_CALL getUserName( ::rtl::OUString& strName) const;
146 : */
147 3 : class getUserName : public CppUnit::TestFixture
148 : {
149 : public:
150 : bool bRes, bRes1;
151 :
152 1 : void getUserName_001( )
153 : {
154 1 : ::osl::Security aSec;
155 : #ifdef WNT
156 : ::rtl::OUString strName( strUserName ), strGetName;
157 : #else
158 2 : ::rtl::OUString strName( strUserName ), strGetName;
159 : #endif
160 1 : bRes = aSec.getUserName( strGetName );
161 :
162 1 : sal_Int32 nPos = -1;
163 1 : if (!strName.isEmpty())
164 : {
165 1 : nPos = strGetName.indexOf(strName);
166 : }
167 2 : CPPUNIT_ASSERT_MESSAGE( "#test comment#: get UserName and compare it with names got at the beginning of the test.",
168 2 : ( nPos >= 0 ) && bRes );
169 1 : }
170 :
171 2 : CPPUNIT_TEST_SUITE( getUserName );
172 1 : CPPUNIT_TEST( getUserName_001 );
173 5 : CPPUNIT_TEST_SUITE_END( );
174 : }; // class getUserName
175 :
176 : /** testing the method:
177 : inline sal_Bool Security::getConfigDir( rtl::OUString& strDirectory ) const
178 : */
179 3 : class getConfigDir : public CppUnit::TestFixture
180 : {
181 : public:
182 : bool bRes, bRes1;
183 :
184 1 : void getConfigDir_001( )
185 : {
186 1 : ::osl::Security aSec;
187 2 : ::rtl::OUString strConfig;
188 1 : bRes = aSec.getConfigDir( strConfig );
189 :
190 2 : CPPUNIT_ASSERT_MESSAGE( "failed to find a ConfigDir!", bRes );
191 1 : }
192 :
193 2 : CPPUNIT_TEST_SUITE( getConfigDir );
194 1 : CPPUNIT_TEST( getConfigDir_001 );
195 5 : CPPUNIT_TEST_SUITE_END( );
196 : }; // class getConfigDir
197 :
198 : /** testing the method:
199 : inline sal_Bool SAL_CALL isAdministrator() const;
200 : */
201 3 : class isAdministrator : public CppUnit::TestFixture
202 : {
203 : public:
204 : bool bRes;
205 :
206 1 : void isAdministrator_001( )
207 : {
208 1 : ::osl::Security aSec;
209 1 : bRes = aSec.isAdministrator( );
210 :
211 2 : CPPUNIT_ASSERT_MESSAGE( "#test comment#: check if the user is administrator at beginning, compare here.",
212 2 : bRes == isAdmin );
213 1 : }
214 :
215 2 : CPPUNIT_TEST_SUITE( isAdministrator );
216 1 : CPPUNIT_TEST( isAdministrator_001 );
217 5 : CPPUNIT_TEST_SUITE_END( );
218 : }; // class isAdministrator
219 :
220 : /** testing the method:
221 : inline oslSecurity getHandle() const;
222 : */
223 3 : class getHandle : public CppUnit::TestFixture
224 : {
225 : public:
226 : bool bRes;
227 :
228 1 : void getHandle_001( )
229 : {
230 1 : ::osl::Security aSec;
231 1 : bRes = aSec.isAdministrator( ) == bool(osl_isAdministrator( aSec.getHandle( ) ));
232 :
233 2 : CPPUNIT_ASSERT_MESSAGE( "#test comment#: use getHandle function to call C API.",
234 2 : bRes );
235 1 : }
236 :
237 2 : CPPUNIT_TEST_SUITE( getHandle );
238 1 : CPPUNIT_TEST( getHandle_001 );
239 5 : CPPUNIT_TEST_SUITE_END( );
240 : }; // class getHandle
241 :
242 6 : class UserProfile : public CppUnit::TestFixture
243 : {
244 : public:
245 :
246 1 : void loadUserProfile( )
247 : {
248 1 : ::osl::Security aSec;
249 1 : bool bValue = osl_loadUserProfile(aSec.getHandle());
250 :
251 1 : CPPUNIT_ASSERT_MESSAGE( "empty function.", !bValue );
252 1 : }
253 :
254 1 : void unloadUserProfile( )
255 : {
256 1 : ::osl::Security aSec;
257 1 : osl_unloadUserProfile(aSec.getHandle());
258 1 : CPPUNIT_ASSERT_MESSAGE( "empty function.", true );
259 1 : }
260 :
261 2 : CPPUNIT_TEST_SUITE( UserProfile );
262 1 : CPPUNIT_TEST( loadUserProfile );
263 1 : CPPUNIT_TEST( unloadUserProfile );
264 5 : CPPUNIT_TEST_SUITE_END( );
265 : }; // class UserProfile
266 :
267 3 : class loginUserOnFileServer : public CppUnit::TestFixture
268 : {
269 : public:
270 :
271 1 : void loginUserOnFileServer_001( )
272 : {
273 1 : rtl::OUString suUserName;
274 2 : rtl::OUString suPassword;
275 2 : rtl::OUString suFileServer;
276 2 : ::osl::Security aSec;
277 1 : oslSecurity pSec = aSec.getHandle();
278 :
279 1 : oslSecurityError erg = osl_loginUserOnFileServer(suUserName.pData, suPassword.pData, suFileServer.pData, &pSec);
280 :
281 2 : CPPUNIT_ASSERT_MESSAGE( "empty function.", erg == osl_Security_E_UserUnknown );
282 1 : }
283 :
284 2 : CPPUNIT_TEST_SUITE( loginUserOnFileServer );
285 1 : CPPUNIT_TEST( loginUserOnFileServer_001 );
286 5 : CPPUNIT_TEST_SUITE_END( );
287 : }; // class loginUserOnFileServer
288 :
289 1 : CPPUNIT_TEST_SUITE_REGISTRATION(osl_Security::ctors);
290 1 : CPPUNIT_TEST_SUITE_REGISTRATION(osl_Security::logonUser);
291 1 : CPPUNIT_TEST_SUITE_REGISTRATION(osl_Security::getUserIdent);
292 1 : CPPUNIT_TEST_SUITE_REGISTRATION(osl_Security::getUserName);
293 1 : CPPUNIT_TEST_SUITE_REGISTRATION(osl_Security::getConfigDir);
294 1 : CPPUNIT_TEST_SUITE_REGISTRATION(osl_Security::isAdministrator);
295 1 : CPPUNIT_TEST_SUITE_REGISTRATION(osl_Security::getHandle);
296 1 : CPPUNIT_TEST_SUITE_REGISTRATION(osl_Security::UserProfile);
297 1 : CPPUNIT_TEST_SUITE_REGISTRATION(osl_Security::loginUserOnFileServer);
298 :
299 : } // namespace osl_Security
300 :
301 : /* This defines an own TestPlugIn implementation with an own initialize()
302 : method that will be called after loading the PlugIn
303 : */
304 : #include <cppunit/plugin/TestPlugInDefaultImpl.h>
305 :
306 1 : class MyTestPlugInImpl: public CPPUNIT_NS::TestPlugInDefaultImpl
307 : {
308 : public:
309 1 : MyTestPlugInImpl() {};
310 : void initialize( CPPUNIT_NS::TestFactoryRegistry *registry,
311 : const CPPUNIT_NS::PlugInParameters ¶meters ) SAL_OVERRIDE;
312 : };
313 :
314 1 : void MyTestPlugInImpl::initialize( CPPUNIT_NS::TestFactoryRegistry *,
315 : const CPPUNIT_NS::PlugInParameters & )
316 : {
317 : /// start message
318 1 : t_print("#Initializing ...\n" );
319 1 : t_print("#\n#logonUser function need root/Administrator account to test.\n" );
320 1 : t_print("#You can test by login with root/Administrator, and execute:\n" );
321 1 : t_print("#testshl2 -forward \"username password\" ../../../wntmsci9/bin/Security.dll\n" );
322 1 : t_print("# where username and password are forwarded account info.\n" );
323 1 : t_print("#if no text forwarded, this function will be skipped.\n" );
324 :
325 : /// get system information
326 : #if ( defined UNX )
327 : /// some initialization work for UNIX OS
328 :
329 : struct passwd* pw;
330 1 : CPPUNIT_ASSERT_MESSAGE( "getpwuid: no password entry\n",( pw = getpwuid( getuid() ) ) != NULL );
331 :
332 : /// get user ID;
333 1 : strUserID = OUString::number( getuid( ) );
334 :
335 : /// get user Name;
336 1 : strUserName = ::rtl::OUString::createFromAscii( pw->pw_name );
337 :
338 : /// get home directory;
339 1 : char *pw_dir = pw->pw_dir;
340 1 : if( getenv( "FAKEROOTKEY" ) )
341 0 : pw_dir = getenv("HOME");
342 2 : CPPUNIT_ASSERT_MESSAGE( "#Convert from system path to URL failed.",
343 1 : ::osl::File::E_None == ::osl::File::getFileURLFromSystemPath( ::rtl::OUString::createFromAscii( pw_dir ), strHomeDirectory ) );
344 :
345 : /// get config directory;
346 1 : strConfigDirectory = strHomeDirectory.copy(0);
347 :
348 : /// is administrator;
349 1 : if( !getuid( ) )
350 0 : isAdmin = true;
351 :
352 : #endif
353 : #if defined ( WNT )
354 : /// some initialization work for Windows OS
355 :
356 : /// Get the user name, computer name, user home directory.
357 : LPTSTR lpszSystemInfo; // pointer to system information string
358 : DWORD cchBuff = BUFSIZE; // size of computer or user name
359 : TCHAR tchBuffer[BUFSIZE]; // buffer for string
360 :
361 : lpszSystemInfo = tchBuffer;
362 : cchBuff = BUFSIZE;
363 : if( GetUserNameA(lpszSystemInfo, &cchBuff) )
364 : strUserName = ::rtl::OUString::createFromAscii( lpszSystemInfo );
365 :
366 : if( GetComputerName(lpszSystemInfo, &cchBuff) )
367 : strComputerName = ::rtl::OUString::createFromAscii( lpszSystemInfo );
368 :
369 : /// Get user home directory.
370 : HKEY hRegKey;
371 : sal_Char PathA[_MAX_PATH];
372 : ::rtl::OUString strHome;
373 : if (RegOpenKey(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", &hRegKey) == ERROR_SUCCESS)
374 : {
375 : LONG lRet, lSize = sizeof(PathA);
376 : DWORD Type;
377 :
378 : lRet = RegQueryValueEx(hRegKey, "AppData", NULL, &Type, ( unsigned char * )PathA, ( unsigned long * )&lSize);
379 : if ( ( lRet == ERROR_SUCCESS ) && ( Type == REG_SZ ) && ( _access( PathA, 0 ) == 0 ) )
380 : {
381 : CPPUNIT_ASSERT_MESSAGE( "#Convert from system path to URL failed.",
382 : ::osl::File::E_None == ::osl::File::getFileURLFromSystemPath( ::rtl::OUString::createFromAscii( PathA ), strConfigDirectory ) );
383 : }
384 :
385 : lRet = RegQueryValueEx(hRegKey, "Personal", NULL, &Type, ( unsigned char * )PathA, ( unsigned long * )&lSize);
386 : if ( ( lRet == ERROR_SUCCESS ) && ( Type == REG_SZ ) && ( _access( PathA, 0 ) == 0 ) )
387 : {
388 : CPPUNIT_ASSERT_MESSAGE( "#Convert from system path to URL failed.",
389 : ::osl::File::E_None == ::osl::File::getFileURLFromSystemPath( ::rtl::OUString::createFromAscii( PathA ), strHomeDirectory ) );
390 : }
391 :
392 : RegCloseKey(hRegKey);
393 : }
394 :
395 : /// Get user Security ID:
396 :
397 : // Create buffers that may be large enough. If a buffer is too small, the count parameter will be set to the size needed.
398 : const DWORD INITIAL_SIZE = 32;
399 : DWORD cbSid = 0;
400 : DWORD dwSidBufferSize = INITIAL_SIZE;
401 : DWORD cchDomainName = 0;
402 : DWORD dwDomainBufferSize = INITIAL_SIZE;
403 : WCHAR * wszDomainName = NULL;
404 : SID_NAME_USE eSidType;
405 : DWORD dwErrorCode = 0;
406 :
407 : LPCWSTR wszAccName = ( LPWSTR ) strUserName.getStr( );
408 :
409 : // Create buffers for the SID and the domain name.
410 : PSID pSid = (PSID) new BYTE[dwSidBufferSize];
411 : CPPUNIT_ASSERT_MESSAGE("# creating SID buffer failed.\n", pSid!= NULL );
412 : memset( pSid, 0, dwSidBufferSize);
413 :
414 : wszDomainName = new WCHAR[dwDomainBufferSize];
415 : CPPUNIT_ASSERT_MESSAGE("# creating Domain name buffer failed.\n", wszDomainName != NULL );
416 : memset(wszDomainName, 0, dwDomainBufferSize*sizeof(WCHAR));
417 :
418 : // Obtain the SID for the account name passed.
419 : for ( ; ; )
420 : {
421 : // Set the count variables to the buffer sizes and retrieve the SID.
422 : cbSid = dwSidBufferSize;
423 : cchDomainName = dwDomainBufferSize;
424 : if (LookupAccountNameW(
425 : NULL, // Computer name. NULL for the local computer
426 : wszAccName,
427 : pSid, // Pointer to the SID buffer. Use NULL to get the size needed,
428 : &cbSid, // Size of the SID buffer needed.
429 : wszDomainName, // wszDomainName,
430 : &cchDomainName,
431 : &eSidType
432 : ))
433 : {
434 : if (IsValidSid( pSid) == FALSE)
435 : wprintf(L"# The SID for %s is invalid.\n", wszAccName);
436 : break;
437 : }
438 : dwErrorCode = GetLastError();
439 :
440 : // Check if one of the buffers was too small.
441 : if (dwErrorCode == ERROR_INSUFFICIENT_BUFFER)
442 : {
443 : if (cbSid > dwSidBufferSize)
444 : {
445 : // Reallocate memory for the SID buffer.
446 : wprintf(L"# The SID buffer was too small. It will be reallocated.\n");
447 : FreeSid( pSid);
448 : pSid = (PSID) new BYTE[cbSid];
449 : CPPUNIT_ASSERT_MESSAGE("# re-creating SID buffer failed.\n", pSid!= NULL );
450 : memset( pSid, 0, cbSid);
451 : dwSidBufferSize = cbSid;
452 : }
453 : if (cchDomainName > dwDomainBufferSize)
454 : {
455 : // Reallocate memory for the domain name buffer.
456 : wprintf(L"# The domain name buffer was too small. It will be reallocated.\n");
457 : delete [] wszDomainName;
458 : wszDomainName = new WCHAR[cchDomainName];
459 : CPPUNIT_ASSERT_MESSAGE("# re-creating domain name buffer failed.\n", wszDomainName!= NULL );
460 : memset(wszDomainName, 0, cchDomainName*sizeof(WCHAR));
461 : dwDomainBufferSize = cchDomainName;
462 : }
463 : }
464 : else
465 : {
466 : wprintf(L"# LookupAccountNameW failed. GetLastError returned: %d\n", dwErrorCode);
467 : break;
468 : }
469 : }
470 :
471 : // now got SID successfully, only need to compare SID, so I copied the rest lines from source to convert SID to OUString.
472 : PSID_IDENTIFIER_AUTHORITY psia;
473 : DWORD dwSubAuthorities;
474 : DWORD dwSidRev=SID_REVISION;
475 : DWORD dwCounter;
476 : DWORD dwSidSize;
477 : sal_Char *Ident;
478 :
479 : /* obtain SidIdentifierAuthority */
480 : psia=GetSidIdentifierAuthority(pSid);
481 :
482 : /* obtain sidsubauthority count */
483 : dwSubAuthorities=std::min((int) *GetSidSubAuthorityCount(pSid), 5);
484 :
485 : /* buffer length: S-SID_REVISION- + identifierauthority- + subauthorities- + NULL */
486 : Ident=(sal_Char * )malloc(88*sizeof(sal_Char));
487 :
488 : /* prepare S-SID_REVISION- */
489 : dwSidSize=wsprintf(Ident, TEXT("S-%lu-"), dwSidRev);
490 :
491 : /* prepare SidIdentifierAuthority */
492 : if ((psia->Value[0] != 0) || (psia->Value[1] != 0))
493 : {
494 : dwSidSize+=wsprintf(Ident + strlen(Ident),
495 : TEXT("0x%02hx%02hx%02hx%02hx%02hx%02hx"),
496 : (sal_uInt16)psia->Value[0],
497 : (sal_uInt16)psia->Value[1],
498 : (sal_uInt16)psia->Value[2],
499 : (sal_uInt16)psia->Value[3],
500 : (sal_uInt16)psia->Value[4],
501 : (sal_uInt16)psia->Value[5]);
502 : }
503 : else
504 : {
505 : dwSidSize+=wsprintf(Ident + strlen(Ident),
506 : TEXT("%lu"),
507 : (sal_uInt32)(psia->Value[5] ) +
508 : (sal_uInt32)(psia->Value[4] << 8) +
509 : (sal_uInt32)(psia->Value[3] << 16) +
510 : (sal_uInt32)(psia->Value[2] << 24) );
511 : }
512 :
513 : /* loop through SidSubAuthorities */
514 : for (dwCounter=0; dwCounter < dwSubAuthorities; dwCounter++)
515 : {
516 : dwSidSize+=wsprintf(Ident + dwSidSize, TEXT("-%lu"),
517 : *GetSidSubAuthority(pSid, dwCounter) );
518 : }
519 :
520 : strUserID = ::rtl::OUString::createFromAscii( Ident );
521 :
522 : free(Ident);
523 : delete [] reinterpret_cast<BYTE*>(pSid);
524 : delete [] wszDomainName;
525 :
526 : /// check if logged in user is administrator:
527 :
528 : BOOL b;
529 : SID_IDENTIFIER_AUTHORITY NtAuthority = { SECURITY_NT_AUTHORITY };
530 : PSID AdministratorsGroup;
531 : b = AllocateAndInitializeSid(
532 : &NtAuthority,
533 : 2,
534 : SECURITY_BUILTIN_DOMAIN_RID,
535 : DOMAIN_ALIAS_RID_ADMINS,
536 : 0, 0, 0, 0, 0, 0,
537 : &AdministratorsGroup);
538 : if(b)
539 : {
540 : if (!CheckTokenMembership( NULL, AdministratorsGroup, &b))
541 : {
542 : b = FALSE;
543 : }
544 : FreeSid(AdministratorsGroup);
545 : }
546 :
547 : isAdmin = ( sal_Bool )b;
548 :
549 : #endif
550 :
551 : /// print the information.
552 1 : t_print("#\n#Retrieved system information is below:\n");
553 :
554 1 : t_print("Computer Name: ");
555 1 : if ( strComputerName.isEmpty())
556 1 : t_print("Not retrieved\n" );
557 : else
558 0 : printUString( strComputerName );
559 :
560 1 : t_print("Current User Name: ");
561 1 : if ( strUserName.isEmpty())
562 0 : t_print("Not retrieved\n" );
563 : else
564 1 : printUString( strUserName );
565 :
566 1 : t_print("Current User Home Directory:");
567 1 : if ( strHomeDirectory.isEmpty())
568 0 : t_print("Not retrieved\n" );
569 : else
570 1 : printUString( strHomeDirectory );
571 :
572 1 : t_print("Current Config Directory: ");
573 1 : if ( strConfigDirectory.isEmpty())
574 0 : t_print("Not retrieved\n" );
575 : else
576 1 : printUString( strConfigDirectory );
577 :
578 1 : t_print("Current UserID: ");
579 1 : if ( strUserID.isEmpty())
580 0 : t_print("Not retrieved\n" );
581 : else
582 1 : printUString( strUserID );
583 :
584 1 : t_print("Current User is: ");
585 1 : if ( !isAdmin )
586 1 : t_print("NOT Administrator.\n" );
587 : else
588 0 : t_print("Administrator.\n" );
589 :
590 : /// get and display forwarded text if available.
591 4 : rtl::OUString args[ 3 ];
592 1 : int argsCount = 0;
593 1 : sal_uInt32 n = rtl_getAppCommandArgCount();
594 3 : for (sal_uInt32 i = 0; i < n; ++i)
595 : {
596 2 : rtl::OUString arg;
597 2 : rtl_getAppCommandArg(i, &arg.pData);
598 2 : if( arg.startsWith("-") )
599 1 : continue;
600 1 : if( argsCount >= 3 )
601 : {
602 : SAL_WARN( "sal.osl", "Too many test arguments" );
603 0 : continue;
604 : }
605 1 : args[ argsCount++ ] = arg;
606 1 : }
607 : /// only forwarded two parameters, username and password.
608 1 : if( argsCount == 2 )
609 : {
610 0 : aLogonUser = args[ 0 ];
611 0 : t_print("\n#Forwarded username: ");
612 0 : printUString( aLogonUser);
613 :
614 0 : aLogonPasswd = args[ 1 ];
615 0 : t_print("#Forwarded password: ");
616 0 : for (int i = 0; i < aLogonPasswd.getLength(); ++i)
617 0 : t_print("*");
618 0 : t_print("\n" );
619 : }
620 1 : else if( argsCount == 3 )
621 : /// forwarded three parameters, username, password and fileserver.
622 : {
623 0 : aLogonUser = args[ 0 ];
624 0 : t_print("#Forwarded username: ");
625 0 : printUString( aLogonUser);
626 :
627 0 : aLogonPasswd = args[ 1 ];
628 0 : t_print("#Forwarded password: ");
629 0 : for (int i = 0; i < aLogonPasswd.getLength(); ++i)
630 0 : t_print("*");
631 0 : t_print("\n" );
632 :
633 0 : aFileServer = args[ 2 ];
634 0 : t_print("#Forwarded FileServer: ");
635 0 : printUString( aFileServer );
636 : }
637 4 : t_print("#\n#Initialization Done.\n" );
638 :
639 1 : }
640 :
641 : /* Instantiate and register the own TestPlugIn and instantiate the default
642 : main() function.
643 : (This is done by CPPUNIT_PLUGIN_IMPLEMENT() for TestPlugInDefaultImpl)
644 : */
645 :
646 1 : CPPUNIT_PLUGIN_EXPORTED_FUNCTION_IMPL( MyTestPlugInImpl );
647 3 : CPPUNIT_PLUGIN_IMPLEMENT_MAIN();
648 :
649 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|