advapi32: add more helper functions
Robert Reif
reif at earthlink.net
Sat Jul 29 08:09:00 CDT 2006
Add ADVAPI_GetComputerNameW and make ADVAPI_IsLocalComputer use it.
Add ADVAPI_GetComputerSid.
Applies on top of previous patch.
-------------- next part --------------
diff -pu wine.cvs/dlls/advapi32/advapi32_misc.h wine/dlls/advapi32/advapi32_misc.h
--- wine.cvs/dlls/advapi32/advapi32_misc.h 2006-07-29 08:59:38.000000000 -0400
+++ wine/dlls/advapi32/advapi32_misc.h 2006-07-29 08:44:32.000000000 -0400
@@ -21,6 +21,8 @@
#define __WINE_ADVAPI32MISC_H
const char * debugstr_sid(PSID sid);
+LPCWSTR ADVAPI_GetComputerNameW();
BOOL ADVAPI_IsLocalComputer(LPCWSTR ServerName);
+BOOL ADVAPI_GetComputerSid(PSID sid);
#endif /* __WINE_ADVAPI32MISC_H */
diff -pu wine.cvs/dlls/advapi32/security.c wine/dlls/advapi32/security.c
--- wine.cvs/dlls/advapi32/security.c 2006-07-29 08:59:38.000000000 -0400
+++ wine/dlls/advapi32/security.c 2006-07-29 09:05:13.000000000 -0400
@@ -319,29 +319,77 @@ static void GetWorldAccessACL(PACL pACL)
}
/************************************************************
+ * ADVAPI_GetComputerNameW
+ *
+ * Gets the local computer name.
+ */
+LPCWSTR ADVAPI_GetComputerNameW()
+{
+ static WCHAR buf[MAX_COMPUTERNAME_LENGTH + 1];
+ DWORD dwSize = sizeof(buf);
+ if (!GetComputerNameW(buf, &dwSize))
+ buf[0] = 0;
+ return buf;
+}
+
+/************************************************************
* ADVAPI_IsLocalComputer
*
* Checks whether the server name indicates local machine.
*/
BOOL ADVAPI_IsLocalComputer(LPCWSTR ServerName)
{
- DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1;
BOOL Result;
- LPWSTR buf;
+ LPCWSTR buf;
if (!ServerName || !ServerName[0])
return TRUE;
- buf = HeapAlloc(GetProcessHeap(), 0, dwSize * sizeof(WCHAR));
- Result = GetComputerNameW(buf, &dwSize);
- if (Result && (ServerName[0] == '\\') && (ServerName[1] == '\\'))
+ buf = ADVAPI_GetComputerNameW();
+ if ((ServerName[0] == '\\') && (ServerName[1] == '\\'))
ServerName += 2;
- Result = Result && !lstrcmpW(ServerName, buf);
- HeapFree(GetProcessHeap(), 0, buf);
+ Result = !lstrcmpW(ServerName, buf);
return Result;
}
+/************************************************************
+ * ADVAPI_GetComputerSid
+ *
+ * Reads the computer SID from the registry.
+ */
+BOOL ADVAPI_GetComputerSid(PSID sid)
+{
+ HKEY key;
+ LONG ret;
+
+ if ((ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
+ "SECURITY\\SAM\\Domains\\Account", 0,
+ KEY_READ, &key)) == ERROR_SUCCESS)
+ {
+ static const WCHAR V[] = { 'V',0 };
+ DWORD size = 0;
+ ret = RegQueryValueExW(key, V, NULL, NULL, NULL, &size);
+ if (ret == ERROR_MORE_DATA || ret == ERROR_SUCCESS)
+ {
+ BYTE * data = HeapAlloc(GetProcessHeap(), 0, size);
+ if (data)
+ {
+ if ((ret = RegQueryValueExW(key, V, NULL, NULL,
+ data, &size)) == ERROR_SUCCESS)
+ {
+ /* the SID is in the last 24 bytes of the binary data */
+ CopyMemory(sid, &data[size-24], 24);
+ return TRUE;
+ }
+ }
+ }
+ RegCloseKey(key);
+ }
+
+ return FALSE;
+}
+
/* ##############################
###### TOKEN FUNCTIONS ######
##############################
More information about the wine-patches
mailing list