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