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