/************************************************************************** * WNetGetUser [USER.516] */ WORD WINAPI WNetGetUser16( LPSTR szUser, LPINT16 nBufferSize ) { DWORD lpBufferSize, ret; if(!szUser || !nBufferSize) return WN16_BAD_POINTER; lpBufferSize = *nBufferSize; ret = WNetGetUserA( NULL, szUser, &lpBufferSize ); *nBufferSize = lpBufferSize; switch (ret) { case NO_ERROR: return WN16_SUCCESS; case ERROR_MORE_DATA: return WN16_MORE_DATA; default: FIXME("Untranslated return value %d\n", ret); } return ret; }
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; }