sal_Bool SAL_CALL osl_getHomeDir(oslSecurity Security, rtl_uString **pustrDirectory) { rtl_uString *ustrSysDir = NULL; sal_Bool bSuccess = sal_False; if (Security != NULL) { oslSecurityImpl *pSecImpl = (oslSecurityImpl*)Security; if (pSecImpl->m_pNetResource != NULL) { rtl_uString_newFromStr( &ustrSysDir, pSecImpl->m_pNetResource->lpRemoteName); bSuccess = (sal_Bool)(osl_File_E_None == osl_getFileURLFromSystemPath( ustrSysDir, pustrDirectory )); } else { bSuccess = (sal_Bool)(GetSpecialFolder(&ustrSysDir, CSIDL_PERSONAL) && (osl_File_E_None == osl_getFileURLFromSystemPath(ustrSysDir, pustrDirectory))); } } if ( ustrSysDir ) rtl_uString_release( ustrSysDir ); return bSuccess; }
sal_Bool SAL_CALL osl_getConfigDir(oslSecurity Security, rtl_uString **pustrDirectory) { sal_Bool bSuccess = sal_False; if (Security != NULL) { oslSecurityImpl *pSecImpl = (oslSecurityImpl*)Security; if (pSecImpl->m_pNetResource != NULL) { rtl_uString *ustrSysDir = NULL; rtl_uString_newFromStr( &ustrSysDir, pSecImpl->m_pNetResource->lpRemoteName); bSuccess = (sal_Bool)(osl_File_E_None == osl_getFileURLFromSystemPath( ustrSysDir, pustrDirectory)); if ( ustrSysDir ) rtl_uString_release( ustrSysDir ); } else { if (pSecImpl->m_hToken) { /* not implemented */ OSL_ASSERT(sal_False); } else { rtl_uString *ustrFile = NULL; sal_Unicode sFile[_MAX_PATH]; if ( !GetSpecialFolder( &ustrFile, CSIDL_APPDATA) ) { OSL_VERIFY(GetWindowsDirectoryW(sFile, _MAX_DIR) > 0); rtl_uString_newFromStr( &ustrFile, sFile); } bSuccess = (sal_Bool)(osl_File_E_None == osl_getFileURLFromSystemPath(ustrFile, pustrDirectory)); if ( ustrFile ) rtl_uString_release( ustrFile ); } } } return bSuccess; }
sal_Bool SAL_CALL osl_getHomeDir(oslSecurity Security, rtl_uString **pustrDirectory) { rtl_uString *ustrSysDir = NULL; sal_Bool bSuccess = sal_False; if (Security != NULL) { oslSecurityImpl *pSecImpl = (oslSecurityImpl*)Security; if (pSecImpl->m_pNetResource != NULL) { rtl_uString_newFromStr( &ustrSysDir, pSecImpl->m_pNetResource->lpRemoteName); bSuccess = (sal_Bool)(osl_File_E_None == osl_getFileURLFromSystemPath( ustrSysDir, pustrDirectory )); } else { #if 0 if (pSecImpl->m_hToken) { DWORD nInfoBuffer = 512; UCHAR* pInfoBuffer = malloc(nInfoBuffer); while (!GetTokenInformation(pSecImpl->m_hToken, TokenUser, pInfoBuffer, nInfoBuffer, &nInfoBuffer)) { if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) pInfoBuffer = realloc(pInfoBuffer, nInfoBuffer); else { free(pInfoBuffer); pInfoBuffer = NULL; break; } } /* not implemented */ OSL_ASSERT(sal_False); if (pInfoBuffer) { /* if (EqualSid() ... */ } } else #endif bSuccess = (sal_Bool)(GetSpecialFolder(&ustrSysDir, CSIDL_PERSONAL) && (osl_File_E_None == osl_getFileURLFromSystemPath(ustrSysDir, pustrDirectory))); } } if ( ustrSysDir ) rtl_uString_release( ustrSysDir ); return bSuccess; }
void uno_EnvDcp_getTypeName(rtl_uString const * pEnvDcp, rtl_uString ** ppEnvTypeName) { sal_Int32 colIdx = rtl_ustr_indexOfChar_WithLength(pEnvDcp->buffer, pEnvDcp->length, ':'); if (colIdx >= 0) rtl_uString_newFromStr_WithLength(ppEnvTypeName, pEnvDcp->buffer, colIdx); else rtl_uString_newFromStr(ppEnvTypeName, pEnvDcp->buffer); }
static sal_Bool SAL_CALL getUserNameImpl(oslSecurity Security, rtl_uString **strName, sal_Bool bIncludeDomain) { if (Security != NULL) { oslSecurityImpl *pSecImpl = (oslSecurityImpl*)Security; HANDLE hAccessToken = pSecImpl->m_hToken; if (hAccessToken == NULL) OpenProcessToken(GetCurrentProcess(), TOKEN_DUP_QUERY, &hAccessToken); if (hAccessToken) { DWORD nInfoBuffer = 512; UCHAR* pInfoBuffer = malloc(nInfoBuffer); while (!GetTokenInformation(hAccessToken, TokenUser, pInfoBuffer, nInfoBuffer, &nInfoBuffer)) { if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) pInfoBuffer = realloc(pInfoBuffer, nInfoBuffer); else { free(pInfoBuffer); pInfoBuffer = NULL; break; } } if (pSecImpl->m_hToken == NULL) CloseHandle(hAccessToken); if (pInfoBuffer) { sal_Unicode UserName[128]; sal_Unicode DomainName[128]; sal_Unicode Name[257]; DWORD nUserName = sizeof(UserName); DWORD nDomainName = sizeof(DomainName); SID_NAME_USE sUse; if (LookupAccountSidW(NULL, ((PTOKEN_USER)pInfoBuffer)->User.Sid, UserName, &nUserName, DomainName, &nDomainName, &sUse)) { if (bIncludeDomain) { wcscpy(Name, DomainName); wcscat(Name, L"/"); wcscat(Name, UserName); } else { wcscpy(Name, UserName); } } rtl_uString_newFromStr( strName, Name); free(pInfoBuffer); return sal_True; } } else { DWORD needed=0; sal_Unicode *pNameW=NULL; WNetGetUserW(NULL, NULL, &needed); pNameW = malloc (needed*sizeof(sal_Unicode)); if (WNetGetUserW(NULL, pNameW, &needed) == NO_ERROR) { rtl_uString_newFromStr( strName, pNameW); if (pNameW) free(pNameW); return sal_True; } else if (pSecImpl->m_User[0] != '\0') { rtl_uString_newFromStr(strName, pSecImpl->m_pNetResource->lpRemoteName); if (pNameW) free(pNameW); return sal_True; } if (pNameW) free(pNameW); } } return sal_False; }
static sal_Bool GetSpecialFolder(rtl_uString **strPath, int nFolder) { sal_Bool bRet = sal_False; HINSTANCE hLibrary; sal_Char PathA[_MAX_PATH]; sal_Unicode PathW[_MAX_PATH]; if ((hLibrary = LoadLibrary("shell32.dll")) != NULL) { BOOL (WINAPI *pSHGetSpecialFolderPathA)(HWND, LPSTR, int, BOOL); BOOL (WINAPI *pSHGetSpecialFolderPathW)(HWND, LPWSTR, int, BOOL); pSHGetSpecialFolderPathA = (BOOL (WINAPI *)(HWND, LPSTR, int, BOOL))GetProcAddress(hLibrary, "SHGetSpecialFolderPathA"); pSHGetSpecialFolderPathW = (BOOL (WINAPI *)(HWND, LPWSTR, int, BOOL))GetProcAddress(hLibrary, "SHGetSpecialFolderPathW"); if (pSHGetSpecialFolderPathA) { if (pSHGetSpecialFolderPathA(GetActiveWindow(), PathA, nFolder, TRUE)) { rtl_string2UString( strPath, PathA, (sal_Int32) strlen(PathA), osl_getThreadTextEncoding(), OUSTRING_TO_OSTRING_CVTFLAGS); OSL_ASSERT(*strPath != NULL); bRet = sal_True; } } else if (pSHGetSpecialFolderPathW) { if (pSHGetSpecialFolderPathW(GetActiveWindow(), PathW, nFolder, TRUE)) { rtl_uString_newFromStr( strPath, PathW); bRet = sal_True; } } else { HRESULT (WINAPI *pSHGetSpecialFolderLocation)(HWND, int, LPITEMIDLIST *) = (HRESULT (WINAPI *)(HWND, int, LPITEMIDLIST *))GetProcAddress(hLibrary, "SHGetSpecialFolderLocation"); BOOL (WINAPI *pSHGetPathFromIDListA)(LPCITEMIDLIST, LPSTR) = (BOOL (WINAPI *)(LPCITEMIDLIST, LPSTR))GetProcAddress(hLibrary, "SHGetPathFromIDListA"); BOOL (WINAPI *pSHGetPathFromIDListW)(LPCITEMIDLIST, LPWSTR) = (BOOL (WINAPI *)(LPCITEMIDLIST, LPWSTR))GetProcAddress(hLibrary, "SHGetPathFromIDListW"); HRESULT (WINAPI *pSHGetMalloc)(LPMALLOC *) = (HRESULT (WINAPI *)(LPMALLOC *))GetProcAddress(hLibrary, "SHGetMalloc"); if (pSHGetSpecialFolderLocation && (pSHGetPathFromIDListA || pSHGetPathFromIDListW ) && pSHGetMalloc ) { LPITEMIDLIST pidl; LPMALLOC pMalloc; HRESULT hr; hr = pSHGetSpecialFolderLocation(GetActiveWindow(), nFolder, &pidl); /* Get SHGetSpecialFolderLocation fails if directory does not exists. */ /* If it fails we try to create the directory and redo the call */ if (! SUCCEEDED(hr)) { HKEY hRegKey; if (RegOpenKey(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", &hRegKey) == ERROR_SUCCESS) { LONG lRet; DWORD lSize = SAL_N_ELEMENTS(PathA); DWORD Type = REG_SZ; switch (nFolder) { case CSIDL_APPDATA: lRet = RegQueryValueEx(hRegKey, "AppData", NULL, &Type, (LPBYTE)PathA, &lSize); break; case CSIDL_PERSONAL: lRet = RegQueryValueEx(hRegKey, "Personal", NULL, &Type, (LPBYTE)PathA, &lSize); break; default: lRet = -1l; } if ((lRet == ERROR_SUCCESS) && (Type == REG_SZ)) { if (_access(PathA, 0) < 0) CreateDirectory(PathA, NULL); hr = pSHGetSpecialFolderLocation(GetActiveWindow(), nFolder, &pidl); } RegCloseKey(hRegKey); } } if (SUCCEEDED(hr)) { if (pSHGetPathFromIDListW && pSHGetPathFromIDListW(pidl, PathW)) { /* if directory does not exist, create it */ if (_waccess(PathW, 0) < 0) CreateDirectoryW(PathW, NULL); rtl_uString_newFromStr( strPath, PathW); bRet = sal_True; } else if (pSHGetPathFromIDListA && pSHGetPathFromIDListA(pidl, PathA)) { /* if directory does not exist, create it */ if (_access(PathA, 0) < 0) CreateDirectoryA(PathA, NULL); rtl_string2UString( strPath, PathA, (sal_Int32) strlen(PathA), osl_getThreadTextEncoding(), OUSTRING_TO_OSTRING_CVTFLAGS); OSL_ASSERT(*strPath != NULL); bRet = sal_True; } } if (SUCCEEDED(pSHGetMalloc(&pMalloc))) { pMalloc->lpVtbl->Free(pMalloc, pidl); pMalloc->lpVtbl->Release(pMalloc); } } } } FreeLibrary(hLibrary); return bRet; }
sal_Bool SAL_CALL osl_getUserIdent(oslSecurity Security, rtl_uString **strIdent) { if (Security != NULL) { oslSecurityImpl *pSecImpl = (oslSecurityImpl*)Security; HANDLE hAccessToken = pSecImpl->m_hToken; if (hAccessToken == NULL) OpenProcessToken(GetCurrentProcess(), TOKEN_DUP_QUERY, &hAccessToken); if (hAccessToken) { sal_Char *Ident; DWORD nInfoBuffer = 512; UCHAR* pInfoBuffer = malloc(nInfoBuffer); while (!GetTokenInformation(hAccessToken, TokenUser, pInfoBuffer, nInfoBuffer, &nInfoBuffer)) { if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) pInfoBuffer = realloc(pInfoBuffer, nInfoBuffer); else { free(pInfoBuffer); pInfoBuffer = NULL; break; } } if (pSecImpl->m_hToken == NULL) CloseHandle(hAccessToken); if (pInfoBuffer) { PSID pSid = ((PTOKEN_USER)pInfoBuffer)->User.Sid; PSID_IDENTIFIER_AUTHORITY psia; DWORD dwSubAuthorities; DWORD dwSidRev=SID_REVISION; DWORD dwCounter; DWORD dwSidSize; PUCHAR pSSACount; /* obtain SidIdentifierAuthority */ psia=GetSidIdentifierAuthority(pSid); /* obtain sidsubauthority count */ pSSACount = GetSidSubAuthorityCount(pSid); dwSubAuthorities = (*pSSACount < 5) ? *pSSACount : 5; /* buffer length: S-SID_REVISION- + identifierauthority- + subauthorities- + NULL */ Ident=malloc(88*sizeof(sal_Char)); /* prepare S-SID_REVISION- */ dwSidSize=wsprintf(Ident, TEXT("S-%lu-"), dwSidRev); /* prepare SidIdentifierAuthority */ if ((psia->Value[0] != 0) || (psia->Value[1] != 0)) { dwSidSize+=wsprintf(Ident + strlen(Ident), TEXT("0x%02hx%02hx%02hx%02hx%02hx%02hx"), (USHORT)psia->Value[0], (USHORT)psia->Value[1], (USHORT)psia->Value[2], (USHORT)psia->Value[3], (USHORT)psia->Value[4], (USHORT)psia->Value[5]); } else { dwSidSize+=wsprintf(Ident + strlen(Ident), TEXT("%lu"), (ULONG)(psia->Value[5] ) + (ULONG)(psia->Value[4] << 8) + (ULONG)(psia->Value[3] << 16) + (ULONG)(psia->Value[2] << 24) ); } /* loop through SidSubAuthorities */ for (dwCounter=0; dwCounter < dwSubAuthorities; dwCounter++) { dwSidSize+=wsprintf(Ident + dwSidSize, TEXT("-%lu"), *GetSidSubAuthority(pSid, dwCounter) ); } rtl_uString_newFromAscii( strIdent, Ident ); free(pInfoBuffer); free(Ident); return sal_True; } } else { DWORD needed=0; sal_Unicode *Ident; WNetGetUserA(NULL, NULL, &needed); if (needed < 16) { needed = 16; } Ident=malloc(needed*sizeof(sal_Unicode)); if (WNetGetUserW(NULL, Ident, &needed) != NO_ERROR) { wcscpy(Ident, L"unknown"); Ident[7] = L'\0'; } rtl_uString_newFromStr( strIdent, Ident); free(Ident); return sal_True; } } return sal_False; }
/* Construct the pipe name */ static rtl_uString * get_pipe_path( rtl_uString *pAppPath ) { rtl_uString *pPath = NULL, *pTmp = NULL, *pUserInstallation = NULL; rtl_uString *pResult = NULL, *pBasePath = NULL, *pAbsUserInstallation = NULL; rtlBootstrapHandle handle; rtl_uString *pMd5hash = NULL; sal_Unicode pUnicode[RTL_USTR_MAX_VALUEOFINT32]; /* setup bootstrap filename */ rtl_uString_newFromAscii( &pPath, "file://" ); rtl_uString_newConcat( &pPath, pPath, pAppPath ); rtl_uString_newConcat( &pPath, pPath, pTmp ); rtl_uString_newFromAscii( &pTmp, SAL_CONFIGFILE( "bootstrap" ) ); rtl_uString_newConcat( &pPath, pPath, pTmp ); /* read userinstallation value */ handle = rtl_bootstrap_args_open( pPath ); rtl_uString_newFromAscii( &pTmp, "UserInstallation" ); rtl_bootstrap_get_from_handle( handle, pTmp, &pUserInstallation, NULL ); rtl_bootstrap_args_close( handle ); /* turn it into an absolute path - unwinding symlinks etc. */ if ( osl_getProcessWorkingDir (&pBasePath) || osl_getAbsoluteFileURL( pBasePath, pUserInstallation, &pAbsUserInstallation ) ) rtl_uString_newFromString (&pAbsUserInstallation, pUserInstallation); /* create the pipe name */ pMd5hash = get_md5hash( pAbsUserInstallation ); if ( !pMd5hash ) rtl_uString_new( &pMd5hash ); if ( access( PIPEDEFAULTPATH, W_OK ) == 0 ) rtl_uString_newFromAscii( &pResult, PIPEDEFAULTPATH ); else if ( access( PIPEALTERNATEPATH, W_OK ) == 0 ) rtl_uString_newFromAscii( &pResult, PIPEALTERNATEPATH ); else { fprintf( stderr, "ERROR: no valid pipe path found.\n" ); exit( 1 ); } rtl_uString_newFromAscii( &pTmp, "/OSL_PIPE_" ); rtl_uString_newConcat( &pResult, pResult, pTmp ); rtl_ustr_valueOfInt32( pUnicode, (int)getuid(), 10 ); rtl_uString_newFromStr( &pTmp, pUnicode ); rtl_uString_newConcat( &pResult, pResult, pTmp ); rtl_uString_newFromAscii( &pTmp, "_SingleOfficeIPC_" ); rtl_uString_newConcat( &pResult, pResult, pTmp ); rtl_uString_newConcat( &pResult, pResult, pMd5hash ); /* cleanup */ rtl_uString_release( pMd5hash ); rtl_uString_release( pPath ); rtl_uString_release( pTmp ); if ( pBasePath ) { rtl_uString_release( pBasePath ); } rtl_uString_release( pUserInstallation ); rtl_uString_release( pAbsUserInstallation ); return pResult; }