Implement OpenAndMapFileForRead, RetreiveFileSecurity, StampFileSecurity, TakeOwnersh...
authorEric Kohl <eric.kohl@reactos.org>
Thu, 5 May 2005 16:16:28 +0000 (16:16 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Thu, 5 May 2005 16:16:28 +0000 (16:16 +0000)
svn path=/trunk/; revision=15007

reactos/include/wine/setupapi.h
reactos/lib/setupapi/misc.c
reactos/lib/setupapi/setupapi.spec

index e5596da..a5c5d1d 100644 (file)
@@ -681,7 +681,9 @@ PWSTR    WINAPI MultiByteToUnicode(PCSTR lpMultiByteStr, UINT uCodePage);
 VOID     WINAPI MyFree(PVOID lpMem);
 PVOID    WINAPI MyMalloc(DWORD dwSize);
 PVOID    WINAPI MyRealloc(PVOID lpSrc, DWORD dwSize);
+DWORD    WINAPI OpenAndMapForRead(PCWSTR, PDWORD, PHANDLE, PHANDLE, PVOID *);
 LONG     WINAPI QueryRegistryValue(HKEY, PCWSTR, PBYTE *, PDWORD, PDWORD);
+DWORD    WINAPI RetreiveFileSecurity(PCWSTR, PSECURITY_DESCRIPTOR *);
 BOOL     WINAPI SetupCloseFileQueue( HSPFILEQ );
 void     WINAPI SetupCloseInfFile( HINF hinf );
 BOOL     WINAPI SetupCommitFileQueueA( HWND, HSPFILEQ, PSP_FILE_CALLBACK_A, PVOID );
@@ -820,7 +822,11 @@ BOOL     WINAPI SetupSetFileQueueAlternatePlatformW( HSPFILEQ, PSP_ALTPLATFORM_I
 #define         SetupSetFileQueueAlternatePlatform WINELIB_NAME_AW(SetupSetFileQueueAlternatePlatform)
 BOOL     WINAPI SetupSetFileQueueFlags( HSPFILEQ, DWORD, DWORD );
 void     WINAPI SetupTermDefaultQueueCallback( PVOID );
+DWORD    WINAPI StampFileSecurity(PCWSTR, PSECURITY_DESCRIPTOR);
+DWORD    WINAPI TakeOwnershipOfFile(PCWSTR);
 PSTR     WINAPI UnicodeToMultiByte(PCWSTR lpUnicodeStr, UINT uCodePage);
+BOOL     WINAPI UnmapAndCloseFile(HANDLE, HANDLE, PVOID);
+
 
 #undef DECL_WINELIB_SETUPAPI_TYPE_AW
 
index 4cc0fe4..c1645e3 100644 (file)
@@ -549,12 +549,12 @@ BOOL WINAPI FileExists(LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFileFindData)
  */\r
 DWORD WINAPI CaptureStringArg(LPCWSTR pSrc, LPWSTR *pDst)\r
 {\r
-  if (pDst == NULL)\r
-    return ERROR_INVALID_PARAMETER;\r
+    if (pDst == NULL)\r
+        return ERROR_INVALID_PARAMETER;\r
 \r
-  *pDst = DuplicateString(pSrc);\r
+    *pDst = DuplicateString(pSrc);\r
 \r
-  return ERROR_SUCCESS;\r
+    return ERROR_SUCCESS;\r
 }\r
 \r
 \r
@@ -576,10 +576,265 @@ DWORD WINAPI CaptureStringArg(LPCWSTR pSrc, LPWSTR *pDst)
  */\r
 DWORD WINAPI CaptureAndConvertAnsiArg(LPCSTR pSrc, LPWSTR *pDst)\r
 {\r
-  if (pDst == NULL)\r
-    return ERROR_INVALID_PARAMETER;\r
+    if (pDst == NULL)\r
+        return ERROR_INVALID_PARAMETER;\r
 \r
-  *pDst = MultiByteToUnicode(pSrc, CP_ACP);\r
+    *pDst = MultiByteToUnicode(pSrc, CP_ACP);\r
 \r
-  return ERROR_SUCCESS;\r
+    return ERROR_SUCCESS;\r
+}\r
+\r
+\r
+/**************************************************************************\r
+ * OpenAndMapFileForRead [SETUPAPI.@]\r
+ *\r
+ * Open and map a file to a buffer.\r
+ *\r
+ * PARAMS\r
+ *     lpFileName [I] Name of the file to be opened\r
+ *     lpSize     [O] Pointer to the file size\r
+ *     lpFile     [0] Pointer to the file handle\r
+ *     lpMapping  [0] Pointer to the mapping handle\r
+ *     lpBuffer   [0] Pointer to the file buffer\r
+ *\r
+ * RETURNS\r
+ *     Success: ERROR_SUCCESS\r
+ *     Failure: Other\r
+ *\r
+ * NOTE\r
+ *     Call UnmapAndCloseFile to release the file.\r
+ */\r
+DWORD WINAPI OpenAndMapFileForRead(LPCWSTR lpFileName,\r
+                                   LPDWORD lpSize,\r
+                                   LPHANDLE lpFile,\r
+                                   LPHANDLE lpMapping,\r
+                                   LPVOID *lpBuffer)\r
+{\r
+    DWORD dwError;\r
+\r
+    TRACE("%s %p %p %p %p\n",\r
+          debugstr_w(lpFileName), lpSize, lpFile, lpMapping, lpBuffer);\r
+\r
+    *lpFile = CreateFileW(lpFileName, GENERIC_READ, FILE_SHARE_READ, NULL,\r
+                          OPEN_EXISTING, 0, NULL);\r
+    if (*lpFile == INVALID_HANDLE_VALUE)\r
+        return GetLastError();\r
+\r
+    *lpSize = GetFileSize(*lpFile, NULL);\r
+    if (*lpSize == INVALID_FILE_SIZE)\r
+    {\r
+        dwError = GetLastError();\r
+        CloseHandle(*lpFile);\r
+        return dwError;\r
+    }\r
+\r
+    *lpMapping = CreateFileMappingW(*lpFile, NULL, PAGE_READONLY, 0,\r
+                                    *lpSize, NULL);\r
+    if (*lpMapping == NULL)\r
+    {\r
+        dwError = GetLastError();\r
+        CloseHandle(*lpFile);\r
+        return dwError;\r
+    }\r
+\r
+    *lpBuffer = MapViewOfFile(*lpMapping, FILE_MAP_READ, 0, 0, *lpSize);\r
+    if (*lpBuffer == NULL)\r
+    {\r
+        dwError = GetLastError();\r
+        CloseHandle(*lpMapping);\r
+        CloseHandle(*lpFile);\r
+        return dwError;\r
+    }\r
+\r
+    return ERROR_SUCCESS;\r
+}\r
+\r
+\r
+/**************************************************************************\r
+ * UnmapAndCloseFile [SETUPAPI.@]\r
+ *\r
+ * Unmap and close a mapped file.\r
+ *\r
+ * PARAMS\r
+ *     hFile    [I] Handle to the file\r
+ *     hMapping [I] Handle to the file mapping\r
+ *     lpBuffer [I] Pointer to the file buffer\r
+ *\r
+ * RETURNS\r
+ *     Success: TRUE\r
+ *     Failure: FALSE\r
+ */\r
+BOOL WINAPI UnmapAndCloseFile(HANDLE hFile, HANDLE hMapping, LPVOID lpBuffer)\r
+{\r
+    TRACE("%x %x %p\n",\r
+          hFile, hMapping, lpBuffer);\r
+\r
+    if (!UnmapViewOfFile(lpBuffer))\r
+        return FALSE;\r
+\r
+    if (!CloseHandle(hMapping))\r
+        return FALSE;\r
+\r
+    if (!CloseHandle(hFile))\r
+        return FALSE;\r
+\r
+    return TRUE;\r
+}\r
+\r
+\r
+/**************************************************************************\r
+ * StampFileSecurity [SETUPAPI.@]\r
+ *\r
+ * Assign a new security descriptor to the given file.\r
+ *\r
+ * PARAMS\r
+ *     lpFileName          [I] Name of the file\r
+ *     pSecurityDescriptor [I] New security descriptor\r
+ *\r
+ * RETURNS\r
+ *     Success: ERROR_SUCCESS\r
+ *     Failure: other\r
+ */\r
+DWORD WINAPI StampFileSecurity(LPCWSTR lpFileName, PSECURITY_DESCRIPTOR pSecurityDescriptor)\r
+{\r
+    TRACE("%s %p\n", debugstr_w(lpFileName), pSecurityDescriptor);\r
+\r
+    if (!SetFileSecurityW(lpFileName, OWNER_SECURITY_INFORMATION |\r
+                          GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION,\r
+                          pSecurityDescriptor))\r
+        return GetLastError();\r
+\r
+    return ERROR_SUCCESS;\r
+}\r
+\r
+\r
+/**************************************************************************\r
+ * TakeOwnershipOfFile [SETUPAPI.@]\r
+ *\r
+ * Takes the ownership of the given file.\r
+ *\r
+ * PARAMS\r
+ *     lpFileName [I] Name of the file\r
+ *\r
+ * RETURNS\r
+ *     Success: ERROR_SUCCESS\r
+ *     Failure: other\r
+ */\r
+DWORD WINAPI TakeOwnershipOfFile(LPCWSTR lpFileName)\r
+{\r
+    SECURITY_DESCRIPTOR SecDesc;\r
+    HANDLE hToken = NULL;\r
+    PTOKEN_OWNER pOwner = NULL;\r
+    DWORD dwError;\r
+    DWORD dwSize;\r
+\r
+    TRACE("%s\n", debugstr_w(lpFileName));\r
+\r
+    if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))\r
+        return GetLastError();\r
+\r
+    if (!GetTokenInformation(hToken, TokenOwner, NULL, 0, &dwSize))\r
+    {\r
+        goto fail;\r
+    }\r
+\r
+    pOwner = (PTOKEN_OWNER)MyMalloc(dwSize);\r
+    if (pOwner == NULL)\r
+    {\r
+        CloseHandle(hToken);\r
+        return ERROR_NOT_ENOUGH_MEMORY;\r
+    }\r
+\r
+    if (!GetTokenInformation(hToken, TokenOwner, pOwner, dwSize, &dwSize))\r
+    {\r
+        goto fail;\r
+    }\r
+\r
+    if (!InitializeSecurityDescriptor(&SecDesc, SECURITY_DESCRIPTOR_REVISION))\r
+    {\r
+        goto fail;\r
+    }\r
+\r
+    if (!SetSecurityDescriptorOwner(&SecDesc, pOwner->Owner, FALSE))\r
+    {\r
+        goto fail;\r
+    }\r
+\r
+    if (!SetFileSecurityW(lpFileName, OWNER_SECURITY_INFORMATION, &SecDesc))\r
+    {\r
+        goto fail;\r
+    }\r
+\r
+    MyFree(pOwner);\r
+    CloseHandle(hToken);\r
+\r
+    return ERROR_SUCCESS;\r
+\r
+fail:;\r
+    dwError = GetLastError();\r
+\r
+    if (pOwner != NULL)\r
+        MyFree(pOwner);\r
+\r
+    if (hToken != NULL)\r
+        CloseHandle(hToken);\r
+\r
+    return dwError;\r
+}\r
+\r
+\r
+/**************************************************************************\r
+ * RetreiveFileSecurity [SETUPAPI.@]\r
+ *\r
+ * Retrieve the security descriptor that is associated with the given file.\r
+ *\r
+ * PARAMS\r
+ *     lpFileName [I] Name of the file\r
+ *\r
+ * RETURNS\r
+ *     Success: ERROR_SUCCESS\r
+ *     Failure: other\r
+ */\r
+DWORD WINAPI RetreiveFileSecurity(LPCWSTR lpFileName,\r
+                                  PSECURITY_DESCRIPTOR *pSecurityDescriptor)\r
+{\r
+    PSECURITY_DESCRIPTOR SecDesc;\r
+    DWORD dwSize = 0x100;\r
+    DWORD dwError;\r
+\r
+    SecDesc = (PSECURITY_DESCRIPTOR)MyMalloc(dwSize);\r
+    if (SecDesc == NULL)\r
+        return ERROR_NOT_ENOUGH_MEMORY;\r
+\r
+    if (GetFileSecurityW(lpFileName, OWNER_SECURITY_INFORMATION |\r
+                         GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION,\r
+                         SecDesc, dwSize, &dwSize))\r
+    {\r
+      *pSecurityDescriptor = SecDesc;\r
+      return ERROR_SUCCESS;\r
+    }\r
+\r
+    dwError = GetLastError();\r
+    if (dwError != ERROR_INSUFFICIENT_BUFFER)\r
+    {\r
+        MyFree(SecDesc);\r
+        return dwError;\r
+    }\r
+\r
+    SecDesc = (PSECURITY_DESCRIPTOR)MyRealloc(SecDesc, dwSize);\r
+    if (SecDesc == NULL)\r
+        return ERROR_NOT_ENOUGH_MEMORY;\r
+\r
+    if (GetFileSecurityW(lpFileName, OWNER_SECURITY_INFORMATION |\r
+                         GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION,\r
+                         SecDesc, dwSize, &dwSize))\r
+    {\r
+      *pSecurityDescriptor = SecDesc;\r
+      return ERROR_SUCCESS;\r
+    }\r
+\r
+    dwError = GetLastError();\r
+    MyFree(SecDesc);\r
+\r
+    return dwError;\r
 }\r
index 277bea8..6ceeec8 100644 (file)
 @ stub MyGetFileTitle\r
 @ stdcall MyMalloc(long)\r
 @ stdcall MyRealloc(ptr long)\r
-@ stub OpenAndMapFileForRead\r
+@ stdcall OpenAndMapFileForRead(wstr ptr ptr ptr ptr)\r
 @ stub OutOfMemory\r
 @ stub QueryMultiSzValueToArray\r
 @ stdcall QueryRegistryValue(long wstr ptr ptr ptr)\r
 @ stub ReadAsciiOrUnicodeTextFile\r
 @ stub RegistryDelnode\r
-@ stub RetreiveFileSecurity\r
+@ stdcall RetreiveFileSecurity(wstr ptr)\r
 @ stub RetrieveServiceConfig\r
 @ stub SearchForInfFile\r
 @ stub SetArrayToMultiSzValue\r
 @ stdcall SetupTermDefaultQueueCallback(ptr)\r
 @ stdcall SetupTerminateFileLog(long)\r
 @ stub ShouldDeviceBeExcluded\r
-@ stub StampFileSecurity\r
+@ stdcall StampFileSecurity(wstr ptr)\r
 @ stub StringTableAddString\r
 @ stub StringTableAddStringEx\r
 @ stub StringTableDestroy\r
 @ stub StringTableSetExtraData\r
 @ stub StringTableStringFromId\r
 @ stub StringTableTrim\r
-@ stub TakeOwnershipOfFile\r
+@ stdcall TakeOwnershipOfFile(wstr)\r
 @ stdcall UnicodeToMultiByte(wstr long)\r
-@ stub UnmapAndCloseFile\r
+@ stdcall UnmapAndCloseFile(long long ptr)\r
 @ stub VerifyCatalogFile\r
 @ stub VerifyFile\r
 @ stub pSetupAccessRunOnceNodeList\r