+/**********************************************************************
+ * LookupPrivilegeDisplayNameA EXPORTED
+ *
+ * @unimplemented
+ */
+BOOL
+WINAPI
+LookupPrivilegeDisplayNameA(LPCSTR lpSystemName,
+ LPCSTR lpName,
+ LPSTR lpDisplayName,
+ LPDWORD cbDisplayName,
+ LPDWORD lpLanguageId)
+{
+ FIXME("%s() not implemented!\n", __FUNCTION__);
+ SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
+ return FALSE;
+}
+
+
+/**********************************************************************
+ * LookupPrivilegeDisplayNameW EXPORTED
+ *
+ * @unimplemented
+ */
+BOOL
+WINAPI
+LookupPrivilegeDisplayNameW(LPCWSTR lpSystemName,
+ LPCWSTR lpName,
+ LPWSTR lpDisplayName,
+ LPDWORD cbDisplayName,
+ LPDWORD lpLanguageId)
+{
+ FIXME("%s() not implemented!\n", __FUNCTION__);
+ SetLastError (ERROR_CALL_NOT_IMPLEMENTED);
+ return FALSE;
+}
+
+/**********************************************************************
+ * LookupPrivilegeNameA EXPORTED
+ *
+ * @implemented
+ */
+BOOL
+WINAPI
+LookupPrivilegeNameA(LPCSTR lpSystemName,
+ PLUID lpLuid,
+ LPSTR lpName,
+ LPDWORD cchName)
+{
+ UNICODE_STRING lpSystemNameW;
+ BOOL ret;
+ DWORD wLen = 0;
+
+ TRACE("%s %p %p %p\n", debugstr_a(lpSystemName), lpLuid, lpName, cchName);
+
+ RtlCreateUnicodeStringFromAsciiz(&lpSystemNameW, lpSystemName);
+ ret = LookupPrivilegeNameW(lpSystemNameW.Buffer, lpLuid, NULL, &wLen);
+ if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
+ {
+ LPWSTR lpNameW = HeapAlloc(GetProcessHeap(), 0, wLen * sizeof(WCHAR));
+
+ ret = LookupPrivilegeNameW(lpSystemNameW.Buffer, lpLuid, lpNameW,
+ &wLen);
+ if (ret)
+ {
+ /* Windows crashes if cchName is NULL, so will I */
+ unsigned int len = WideCharToMultiByte(CP_ACP, 0, lpNameW, -1, lpName,
+ *cchName, NULL, NULL);
+
+ if (len == 0)
+ {
+ /* WideCharToMultiByte failed */
+ ret = FALSE;
+ }
+ else if (len > *cchName)
+ {
+ *cchName = len;
+ SetLastError(ERROR_INSUFFICIENT_BUFFER);
+ ret = FALSE;
+ }
+ else
+ {
+ /* WideCharToMultiByte succeeded, output length needs to be
+ * length not including NULL terminator
+ */
+ *cchName = len - 1;
+ }
+ }
+ HeapFree(GetProcessHeap(), 0, lpNameW);
+ }
+ RtlFreeUnicodeString(&lpSystemNameW);
+ return ret;
+}
+
+/******************************************************************************
+ * GetFileSecurityA [ADVAPI32.@]
+ *
+ * Obtains Specified information about the security of a file or directory.
+ *
+ * PARAMS
+ * lpFileName [I] Name of the file to get info for
+ * RequestedInformation [I] SE_ flags from "winnt.h"
+ * pSecurityDescriptor [O] Destination for security information
+ * nLength [I] Length of pSecurityDescriptor
+ * lpnLengthNeeded [O] Destination for length of returned security information
+ *
+ * RETURNS
+ * Success: TRUE. pSecurityDescriptor contains the requested information.
+ * Failure: FALSE. lpnLengthNeeded contains the required space to return the info.
+ *
+ * NOTES
+ * The information returned is constrained by the callers access rights and
+ * privileges.
+ *
+ * @implemented
+ */
+BOOL
+WINAPI
+GetFileSecurityA(LPCSTR lpFileName,
+ SECURITY_INFORMATION RequestedInformation,
+ PSECURITY_DESCRIPTOR pSecurityDescriptor,
+ DWORD nLength,
+ LPDWORD lpnLengthNeeded)
+{
+ UNICODE_STRING FileName;
+ BOOL bResult;
+
+ if (!RtlCreateUnicodeStringFromAsciiz(&FileName, lpFileName))
+ {
+ SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ return FALSE;
+ }
+
+ bResult = GetFileSecurityW(FileName.Buffer,
+ RequestedInformation,
+ pSecurityDescriptor,
+ nLength,
+ lpnLengthNeeded);
+
+ RtlFreeUnicodeString(&FileName);
+
+ return bResult;
+}
+
+/*
+ * @implemented
+ */
+BOOL
+WINAPI
+GetFileSecurityW(LPCWSTR lpFileName,
+ SECURITY_INFORMATION RequestedInformation,
+ PSECURITY_DESCRIPTOR pSecurityDescriptor,
+ DWORD nLength,
+ LPDWORD lpnLengthNeeded)
+{
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ IO_STATUS_BLOCK StatusBlock;
+ UNICODE_STRING FileName;
+ ULONG AccessMask = 0;
+ HANDLE FileHandle;
+ NTSTATUS Status;
+
+ TRACE("GetFileSecurityW() called\n");
+
+ QuerySecurityAccessMask(RequestedInformation, &AccessMask);
+
+ if (!RtlDosPathNameToNtPathName_U(lpFileName,
+ &FileName,
+ NULL,
+ NULL))
+ {
+ ERR("Invalid path\n");
+ SetLastError(ERROR_INVALID_NAME);
+ return FALSE;
+ }
+
+ InitializeObjectAttributes(&ObjectAttributes,
+ &FileName,
+ OBJ_CASE_INSENSITIVE,
+ NULL,
+ NULL);
+
+ Status = NtOpenFile(&FileHandle,
+ AccessMask,
+ &ObjectAttributes,
+ &StatusBlock,
+ FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+ 0);
+
+ RtlFreeHeap(RtlGetProcessHeap(),
+ 0,
+ FileName.Buffer);
+
+ if (!NT_SUCCESS(Status))
+ {
+ ERR("NtOpenFile() failed (Status %lx)\n", Status);
+ SetLastError(RtlNtStatusToDosError(Status));
+ return FALSE;
+ }
+
+ Status = NtQuerySecurityObject(FileHandle,
+ RequestedInformation,
+ pSecurityDescriptor,
+ nLength,
+ lpnLengthNeeded);
+ NtClose(FileHandle);
+ if (!NT_SUCCESS(Status))
+ {
+ ERR("NtQuerySecurityObject() failed (Status %lx)\n", Status);
+ SetLastError(RtlNtStatusToDosError(Status));
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/******************************************************************************
+ * SetFileSecurityA [ADVAPI32.@]
+ * Sets the security of a file or directory
+ *
+ * @implemented
+ */
+BOOL
+WINAPI
+SetFileSecurityA(LPCSTR lpFileName,
+ SECURITY_INFORMATION SecurityInformation,
+ PSECURITY_DESCRIPTOR pSecurityDescriptor)
+{
+ UNICODE_STRING FileName;
+ BOOL bResult;
+
+ if (!RtlCreateUnicodeStringFromAsciiz(&FileName, lpFileName))
+ {
+ SetLastError(ERROR_NOT_ENOUGH_MEMORY);
+ return FALSE;
+ }
+
+ bResult = SetFileSecurityW(FileName.Buffer,
+ SecurityInformation,
+ pSecurityDescriptor);
+
+ RtlFreeUnicodeString(&FileName);
+
+ return bResult;
+}
+
+/******************************************************************************
+ * SetFileSecurityW [ADVAPI32.@]
+ * Sets the security of a file or directory
+ *
+ * @implemented
+ */
+BOOL
+WINAPI
+SetFileSecurityW(LPCWSTR lpFileName,
+ SECURITY_INFORMATION SecurityInformation,
+ PSECURITY_DESCRIPTOR pSecurityDescriptor)
+{
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ IO_STATUS_BLOCK StatusBlock;
+ UNICODE_STRING FileName;
+ ULONG AccessMask = 0;
+ HANDLE FileHandle;
+ NTSTATUS Status;
+
+ TRACE("SetFileSecurityW() called\n");
+
+ SetSecurityAccessMask(SecurityInformation, &AccessMask);
+
+ if (!RtlDosPathNameToNtPathName_U(lpFileName,
+ &FileName,
+ NULL,
+ NULL))
+ {
+ ERR("Invalid path\n");
+ SetLastError(ERROR_INVALID_NAME);
+ return FALSE;
+ }
+
+ InitializeObjectAttributes(&ObjectAttributes,
+ &FileName,
+ OBJ_CASE_INSENSITIVE,
+ NULL,
+ NULL);
+
+ Status = NtOpenFile(&FileHandle,
+ AccessMask,
+ &ObjectAttributes,
+ &StatusBlock,
+ FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+ 0);
+
+ RtlFreeHeap(RtlGetProcessHeap(),
+ 0,
+ FileName.Buffer);
+
+ if (!NT_SUCCESS(Status))
+ {
+ ERR("NtOpenFile() failed (Status %lx)\n", Status);
+ SetLastError(RtlNtStatusToDosError(Status));
+ return FALSE;
+ }
+
+ Status = NtSetSecurityObject(FileHandle,
+ SecurityInformation,
+ pSecurityDescriptor);
+ NtClose(FileHandle);
+
+ if (!NT_SUCCESS(Status))
+ {
+ ERR("NtSetSecurityObject() failed (Status %lx)\n", Status);
+ SetLastError(RtlNtStatusToDosError(Status));
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/******************************************************************************
+ * QueryWindows31FilesMigration [ADVAPI32.@]
+ *
+ * PARAMS
+ * x1 []
+ */
+BOOL WINAPI
+QueryWindows31FilesMigration( DWORD x1 )
+{
+ FIXME("(%d):stub\n",x1);
+ return TRUE;
+}
+
+/******************************************************************************
+ * SynchronizeWindows31FilesAndWindowsNTRegistry [ADVAPI32.@]
+ *
+ * PARAMS
+ * x1 []
+ * x2 []
+ * x3 []
+ * x4 []
+ */
+BOOL WINAPI
+SynchronizeWindows31FilesAndWindowsNTRegistry( DWORD x1, DWORD x2, DWORD x3,
+ DWORD x4 )
+{
+ FIXME("(0x%08x,0x%08x,0x%08x,0x%08x):stub\n",x1,x2,x3,x4);
+ return TRUE;
+}
+
+/*
+ * @implemented
+ */
+BOOL
+WINAPI
+RevertToSelf(VOID)
+{
+ NTSTATUS Status;
+ HANDLE Token = NULL;
+
+ Status = NtSetInformationThread(NtCurrentThread(),
+ ThreadImpersonationToken,
+ &Token,
+ sizeof(HANDLE));
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastError(RtlNtStatusToDosError(Status));
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/*
+ * @implemented
+ */
+BOOL
+WINAPI
+ImpersonateSelf(SECURITY_IMPERSONATION_LEVEL ImpersonationLevel)
+{
+ NTSTATUS Status;
+
+ Status = RtlImpersonateSelf(ImpersonationLevel);
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastError(RtlNtStatusToDosError(Status));
+ return FALSE;
+ }
+
+ return TRUE;
+}
+