xref: /reactos/dll/win32/sfc_os/sfc_os.c (revision 50cf16b3)
1 /*
2  * System File Checker (Windows File Protection)
3  *
4  * Copyright 2008 Pierre Schweitzer
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20 
21 #include <stdarg.h>
22 
23 #define WIN32_NO_STATUS
24 
25 #include <windef.h>
26 #include <winbase.h>
27 #include <winreg.h>
28 #include <winuser.h>
29 #include <winwlx.h>
30 
31 #define NDEBUG
32 #include <debug.h>
33 
34 HINSTANCE hLibModule;
35 
36 typedef struct _PROTECTED_FILE_DATA
37 {
38     WCHAR FileName[MAX_PATH];
39     DWORD FileNumber;
40 } PROTECTED_FILE_DATA, *PPROTECTED_FILE_DATA;
41 
42 
43 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
44 {
45     switch (fdwReason)
46     {
47         case DLL_PROCESS_ATTACH:
48         {
49             DisableThreadLibraryCalls(hinstDLL);
50             hLibModule = hinstDLL;
51             break;
52         }
53         case DLL_PROCESS_DETACH:
54         {
55             break;
56         }
57     }
58 
59     return TRUE;
60 }
61 
62 
63 /******************************************************************
64  *              SfcIsFileProtected     [sfc_os.@]
65  *
66  * Check, if the given File is protected by the System
67  *
68  * PARAMS
69  *  RpcHandle    [I] This must be NULL
70  *  ProtFileName [I] Filename with Path to check
71  *
72  * RETURNS
73  *  Failure: FALSE with GetLastError() != ERROR_FILE_NOT_FOUND
74  *  Success: TRUE, when the File is Protected
75  *           FALSE with GetLastError() == ERROR_FILE_NOT_FOUND,
76  *           when the File is not Protected
77  *
78  *
79  * BUGS
80  *  We return always the Result for: "File is not Protected"
81  *
82  */
83 BOOL WINAPI SfcIsFileProtected(HANDLE RpcHandle, LPCWSTR ProtFileName)
84 {
85     static BOOL reported = FALSE;
86 
87     if (reported) {
88         DPRINT("(%p, %S) stub\n", RpcHandle, ProtFileName);
89     }
90     else
91     {
92         DPRINT1("(%p, %S) stub\n", RpcHandle, ProtFileName);
93         reported = TRUE;
94     }
95 
96     SetLastError(ERROR_FILE_NOT_FOUND);
97     return FALSE;
98 }
99 
100 /******************************************************************
101  *              SfcIsKeyProtected     [sfc_os.@]
102  *
103  * Check, if the given Registry Key is protected by the System
104  *
105  * PARAMS
106  *  hKey          [I] Handle to the root registry key
107  *  lpSubKey      [I] Name of the subkey to check
108  *  samDesired    [I] The Registry View to Examine (32 or 64 bit)
109  *
110  * RETURNS
111  *  Failure: FALSE with GetLastError() != ERROR_FILE_NOT_FOUND
112  *  Success: TRUE, when the Key is Protected
113  *           FALSE with GetLastError() == ERROR_FILE_NOT_FOUND,
114  *           when the Key is not Protected
115  *
116  */
117 BOOL WINAPI SfcIsKeyProtected(HKEY hKey, LPCWSTR lpSubKey, REGSAM samDesired)
118 {
119     static BOOL reported = FALSE;
120 
121     if (reported) {
122         DPRINT("(%p, %S) stub\n", hKey, lpSubKey);
123     }
124     else
125     {
126         DPRINT1("(%p, %S) stub\n", hKey, lpSubKey);
127         reported = TRUE;
128     }
129 
130     if( !hKey ) {
131         SetLastError(ERROR_INVALID_HANDLE);
132         return FALSE;
133     }
134 
135     SetLastError(ERROR_FILE_NOT_FOUND);
136     return FALSE;
137 }
138 
139 /******************************************************************
140  *              SfcGetNextProtectedFile     [sfc_os.@]
141  */
142 BOOL WINAPI SfcGetNextProtectedFile(HANDLE RpcHandle, PPROTECTED_FILE_DATA ProtFileData)
143 {
144     if (!ProtFileData)
145     {
146         SetLastError(ERROR_INVALID_PARAMETER);
147         return FALSE;
148     }
149 
150     UNIMPLEMENTED;
151     SetLastError(ERROR_NO_MORE_FILES);
152     return FALSE;
153 }
154 
155 /******************************************************************
156  *              SfcFileException     [sfc_os.@]
157  *
158  * Disable the protection for the given file during one minute
159  *
160  * PARAMS
161  *  dwUnknown0    [I] Set to 0
162  *  pwszFile      [I] Name of the file to unprotect
163  *  dwUnknown1    [I] Set to -1
164  *
165  * RETURNS
166  *  Failure: 1;
167  *  Success: 0;
168  *
169  */
170 DWORD WINAPI SfcFileException(DWORD dwUnknown0, PWCHAR pwszFile, DWORD dwUnknown1)
171 {
172     UNIMPLEMENTED;
173     /* Always return success */
174     return 0;
175 }
176 
177 /******************************************************************
178  *              SfcWLEventLogoff     [sfc_os.@]
179  *
180  * Logoff notification function
181  *
182  * PARAMS
183  *  pInfo         [I] Pointer to logoff notification information
184  *
185  * RETURNS
186  *  nothing
187  *
188  */
189 VOID
190 WINAPI
191 SfcWLEventLogoff(
192     PWLX_NOTIFICATION_INFO pInfo)
193 {
194     UNIMPLEMENTED;
195 }
196 
197 /******************************************************************
198  *              SfcWLEventLogon     [sfc_os.@]
199  *
200  * Logon notification function
201  *
202  * PARAMS
203  *  pInfo         [I] Pointer to logon notification information
204  *
205  * RETURNS
206  *  nothing
207  *
208  */
209 VOID
210 WINAPI
211 SfcWLEventLogon(
212     PWLX_NOTIFICATION_INFO pInfo)
213 {
214     UNIMPLEMENTED;
215 }
216