/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
sal_Int32 nPos = -1; if (!strName.isEmpty())
{
nPos = strGetName.indexOf(strName);
}
CPPUNIT_ASSERT_MESSAGE( "#test comment#: get UserName and compare it with names got at the beginning of the test.",
( nPos >= 0 ) );
CPPUNIT_ASSERT_MESSAGE( "#test comment#: get UserName and compare it with names got at the beginning of the test.",
bRes );
}
/* This defines an own TestPlugIn implementation with an own initialize() method that will be called after loading the PlugIn
*/ #include <cppunit/plugin/TestPlugInDefaultImpl.h>
namespace {
class MyTestPlugInImpl: public CPPUNIT_NS::TestPlugInDefaultImpl
{ public:
MyTestPlugInImpl() {}; void initialize( CPPUNIT_NS::TestFactoryRegistry *registry, const CPPUNIT_NS::PlugInParameters ¶meters ) override;
};
}
void MyTestPlugInImpl::initialize( CPPUNIT_NS::TestFactoryRegistry *, const CPPUNIT_NS::PlugInParameters & )
{ /// start message
t_print("#Initializing ...\n" );
t_print("#\n#logonUser function need root/Administrator account to test.\n" );
t_print("#You can test by login with root/Administrator, and execute:\n" );
t_print("#testshl2 -forward \"username password\" ../../../wntmsci9/bin/Security.dll\n" );
t_print("# where username and password are forwarded account info.\n" );
t_print("#if no text forwarded, this function will be skipped.\n" );
/// get system information #if ( defined UNX ) /// some initialization work for UNIX OS
/// get user ID;
strUserID = OUString::number( getuid( ) );
/// get user Name;
strUserName = OUString::createFromAscii( pw->pw_name );
/// get home directory;
CPPUNIT_ASSERT_EQUAL_MESSAGE( "#Convert from system path to URL failed.",
::osl::File::E_None, ::osl::File::getFileURLFromSystemPath( OUString::createFromAscii( pw->pw_dir ), strHomeDirectory ) );
/// get config directory;
strConfigDirectory = strHomeDirectory.copy(0);
/// is administrator; if( !getuid( ) )
isAdmin = true;
#endif #ifdefined(_WIN32) /// some initialization work for Windows OS
/// Get the user name, computer name, user home directory.
LPWSTR lpszSystemInfo; // pointer to system information string
DWORD cchBuff = BUFSIZE; // size of computer or user name
WCHAR wchBuffer[BUFSIZE]; // buffer for string
// Create buffers that may be large enough. If a buffer is too small, the count parameter will be set to the size needed. const DWORD INITIAL_SIZE = 32;
DWORD cbSid = 0;
DWORD dwSidBufferSize = INITIAL_SIZE;
DWORD cchDomainName = 0;
DWORD dwDomainBufferSize = INITIAL_SIZE;
WCHAR * wszDomainName = nullptr;
SID_NAME_USE eSidType;
DWORD dwErrorCode = 0;
// Create buffers for the SID and the domain name.
PSID pSid = static_cast<PSID>(new BYTE[dwSidBufferSize]);
memset( pSid, 0, dwSidBufferSize);
wszDomainName = new WCHAR[dwDomainBufferSize];
memset(wszDomainName, 0, dwDomainBufferSize*sizeof(WCHAR));
// Obtain the SID for the account name passed. for ( ; ; )
{ // Set the count variables to the buffer sizes and retrieve the SID.
cbSid = dwSidBufferSize;
cchDomainName = dwDomainBufferSize; if (LookupAccountNameW(
nullptr, // Computer name. NULL for the local computer
wszAccName,
pSid, // Pointer to the SID buffer. Use NULL to get the size needed,
&cbSid, // Size of the SID buffer needed.
wszDomainName, // wszDomainName,
&cchDomainName,
&eSidType
))
{ if (eSidType == SID_NAME_USE::SidTypeDomain)
{ // LookupAccountNameW returned SID of a domain; likely the hostname is the same as // username (case-insensitive): something like "JOHNSMITH\JohnSmith", so looking up // for "JohnSmith" without domain returns domain itself. Try getting the SID of the // user using fully qualified name (the case of user of another domain having name // identical this hostname is not handled).
sLookupUserName = OUString::Concat(o3tl::toU(wszDomainName)) + u"\\" + strUserName;
wszAccName = o3tl::toW(sLookupUserName.getStr()); continue;
} if (IsValidSid( pSid) == FALSE)
wprintf(L"# The SID for %s is invalid.\n", wszAccName); break;
}
dwErrorCode = GetLastError();
// Check if one of the buffers was too small. if (dwErrorCode == ERROR_INSUFFICIENT_BUFFER)
{ if (cbSid > dwSidBufferSize)
{ // Reallocate memory for the SID buffer.
wprintf(L"# The SID buffer was too small. It will be reallocated.\n"); delete[] static_cast<BYTE*>(pSid);
pSid = static_cast<PSID>(new BYTE[cbSid]);
memset( pSid, 0, cbSid);
dwSidBufferSize = cbSid;
} if (cchDomainName > dwDomainBufferSize)
{ // Reallocate memory for the domain name buffer.
wprintf(L"# The domain name buffer was too small. It will be reallocated.\n"); delete [] wszDomainName;
wszDomainName = new WCHAR[cchDomainName];
memset(wszDomainName, 0, cchDomainName*sizeof(WCHAR));
dwDomainBufferSize = cchDomainName;
}
} else
{
wprintf(L"# LookupAccountNameW failed. GetLastError returned: %d\n", dwErrorCode); break;
}
}
/* Instantiate and register the own TestPlugIn and instantiate the default main() function. (This is done by CPPUNIT_PLUGIN_IMPLEMENT() for TestPlugInDefaultImpl)
*/
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.