Bug Summary

File:sal/qa/osl/security/osl_Security.cxx
Location:line 376, column 53
Description:Access to field 'pw_name' results in a dereference of a null pointer (loaded from variable 'pw')

Annotated Source Code

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