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