xref: /reactos/dll/win32/samsrv/samsrv.h (revision a1fc312a)
1 /*
2  * COPYRIGHT:       See COPYING in the top level directory
3  * PROJECT:         Security Account Manager (LSA) Server
4  * FILE:            reactos/dll/win32/samsrv/samsrv.h
5  * PURPOSE:         Common header file
6  *
7  * PROGRAMMERS:     Eric Kohl
8  */
9 
10 #ifndef _SAMSRV_PCH_
11 #define _SAMSRV_PCH_
12 
13 #include <stdio.h>
14 #include <stdlib.h>
15 
16 #define WIN32_NO_STATUS
17 #define _INC_WINDOWS
18 #define COM_NO_WINDOWS_H
19 
20 #include <windef.h>
21 #include <winbase.h>
22 #include <winreg.h>
23 #define NTOS_MODE_USER
24 #include <ndk/ketypes.h>
25 #include <ndk/kefuncs.h>
26 #include <ndk/obfuncs.h>
27 #include <ndk/rtlfuncs.h>
28 #include <ddk/ntsam.h>
29 #include <sddl.h>
30 #include <sam_s.h>
31 
32 #include <wine/debug.h>
33 WINE_DEFAULT_DEBUG_CHANNEL(samsrv);
34 
35 typedef enum _SAM_DB_OBJECT_TYPE
36 {
37     SamDbIgnoreObject,
38     SamDbServerObject,
39     SamDbDomainObject,
40     SamDbAliasObject,
41     SamDbGroupObject,
42     SamDbUserObject
43 } SAM_DB_OBJECT_TYPE;
44 
45 typedef struct _SAM_DB_OBJECT
46 {
47     ULONG Signature;
48     SAM_DB_OBJECT_TYPE ObjectType;
49     ULONG RefCount;
50     ACCESS_MASK Access;
51     LPWSTR Name;
52     HANDLE KeyHandle;
53     HANDLE MembersKeyHandle;  // only used by Aliases
54     ULONG RelativeId;
55     BOOLEAN Trusted;
56     struct _SAM_DB_OBJECT *ParentObject;
57 } SAM_DB_OBJECT, *PSAM_DB_OBJECT;
58 
59 #define SAMP_DB_SIGNATURE 0x87654321
60 
61 typedef struct _SAM_ALIAS_FIXED_DATA
62 {
63     ULONG Version;
64     ULONG Reserved;
65     ULONG AliasId;
66 } SAM_ALIAS_FIXED_DATA, *PSAM_ALIAS_FIXED_DATA;
67 
68 typedef struct _SAM_DOMAIN_FIXED_DATA
69 {
70     ULONG Version;
71     ULONG Reserved;
72     LARGE_INTEGER CreationTime;
73     LARGE_INTEGER DomainModifiedCount;
74     LARGE_INTEGER MaxPasswordAge;               /* relative Time */
75     LARGE_INTEGER MinPasswordAge;               /* relative Time */
76     LARGE_INTEGER ForceLogoff;                  /* relative Time */
77     LARGE_INTEGER LockoutDuration;              /* relative Time */
78     LARGE_INTEGER LockoutObservationWindow;     /* relative Time */
79     LARGE_INTEGER ModifiedCountAtLastPromotion;
80     ULONG NextRid;
81     ULONG PasswordProperties;
82     USHORT MinPasswordLength;
83     USHORT PasswordHistoryLength;
84     USHORT LockoutThreshold;
85     DOMAIN_SERVER_ENABLE_STATE DomainServerState;
86     DOMAIN_SERVER_ROLE DomainServerRole;
87     BOOLEAN UasCompatibilityRequired;
88 } SAM_DOMAIN_FIXED_DATA, *PSAM_DOMAIN_FIXED_DATA;
89 
90 typedef struct _SAM_GROUP_FIXED_DATA
91 {
92     ULONG Version;
93     ULONG Reserved;
94     ULONG GroupId;
95     ULONG Attributes;
96 } SAM_GROUP_FIXED_DATA, *PSAM_GROUP_FIXED_DATA;
97 
98 typedef struct _SAM_USER_FIXED_DATA
99 {
100     ULONG Version;
101     ULONG Reserved;
102     LARGE_INTEGER LastLogon;
103     LARGE_INTEGER LastLogoff;
104     LARGE_INTEGER PasswordLastSet;
105     LARGE_INTEGER AccountExpires;
106     LARGE_INTEGER LastBadPasswordTime;
107     ULONG UserId;
108     ULONG PrimaryGroupId;
109     ULONG UserAccountControl;
110     USHORT CountryCode;
111     USHORT CodePage;
112     USHORT BadPasswordCount;
113     USHORT LogonCount;
114     USHORT AdminCount;
115     USHORT OperatorCount;
116 } SAM_USER_FIXED_DATA, *PSAM_USER_FIXED_DATA;
117 
118 
119 extern PGENERIC_MAPPING pServerMapping;
120 extern ENCRYPTED_NT_OWF_PASSWORD EmptyNtHash;
121 extern ENCRYPTED_LM_OWF_PASSWORD EmptyLmHash;
122 extern RTL_RESOURCE SampResource;
123 extern NT_PRODUCT_TYPE SampProductType;
124 
125 /* alias.c */
126 
127 NTSTATUS
128 SampOpenAliasObject(IN PSAM_DB_OBJECT DomainObject,
129                     IN ULONG AliasId,
130                     IN ACCESS_MASK DesiredAccess,
131                     OUT PSAM_DB_OBJECT *AliasObject);
132 
133 NTSTATUS
134 SampAddMemberToAlias(IN PSAM_DB_OBJECT AliasObject,
135                      IN PRPC_SID MemberId);
136 
137 NTSTATUS
138 NTAPI
139 SampRemoveMemberFromAlias(IN PSAM_DB_OBJECT AliasObject,
140                           IN PRPC_SID MemberId);
141 
142 NTSTATUS
143 SampGetMembersInAlias(IN PSAM_DB_OBJECT AliasObject,
144                       OUT PULONG MemberCount,
145                       OUT PSAMPR_SID_INFORMATION *MemberArray);
146 
147 NTSTATUS
148 SampRemoveAllMembersFromAlias(IN PSAM_DB_OBJECT AliasObject);
149 
150 
151 /* database.c */
152 
153 NTSTATUS
154 SampInitDatabase(VOID);
155 
156 NTSTATUS
157 SampCreateDbObject(IN PSAM_DB_OBJECT ParentObject,
158                    IN LPWSTR ContainerName,
159                    IN LPWSTR ObjectName,
160                    IN ULONG RelativeId,
161                    IN SAM_DB_OBJECT_TYPE ObjectType,
162                    IN ACCESS_MASK DesiredAccess,
163                    OUT PSAM_DB_OBJECT *DbObject);
164 
165 NTSTATUS
166 SampOpenDbObject(IN PSAM_DB_OBJECT ParentObject,
167                  IN LPWSTR ContainerName,
168                  IN LPWSTR ObjectName,
169                  IN ULONG RelativeId,
170                  IN SAM_DB_OBJECT_TYPE ObjectType,
171                  IN ACCESS_MASK DesiredAccess,
172                  OUT PSAM_DB_OBJECT *DbObject);
173 
174 NTSTATUS
175 SampValidateDbObject(SAMPR_HANDLE Handle,
176                      SAM_DB_OBJECT_TYPE ObjectType,
177                      ACCESS_MASK DesiredAccess,
178                      PSAM_DB_OBJECT *DbObject);
179 
180 NTSTATUS
181 SampCloseDbObject(PSAM_DB_OBJECT DbObject);
182 
183 NTSTATUS
184 SampDeleteAccountDbObject(PSAM_DB_OBJECT DbObject);
185 
186 NTSTATUS
187 SampSetObjectAttribute(PSAM_DB_OBJECT DbObject,
188                        LPWSTR AttributeName,
189                        ULONG AttributeType,
190                        LPVOID AttributeData,
191                        ULONG AttributeSize);
192 
193 NTSTATUS
194 SampGetObjectAttribute(PSAM_DB_OBJECT DbObject,
195                        LPWSTR AttributeName,
196                        PULONG AttributeType,
197                        LPVOID AttributeData,
198                        PULONG AttributeSize);
199 
200 NTSTATUS
201 SampGetObjectAttributeString(PSAM_DB_OBJECT DbObject,
202                              LPWSTR AttributeName,
203                              PRPC_UNICODE_STRING String);
204 
205 NTSTATUS
206 SampSetObjectAttributeString(PSAM_DB_OBJECT DbObject,
207                              LPWSTR AttributeName,
208                              PRPC_UNICODE_STRING String);
209 
210 /* domain.c */
211 
212 NTSTATUS
213 SampSetAccountNameInDomain(IN PSAM_DB_OBJECT DomainObject,
214                            IN LPCWSTR lpContainerName,
215                            IN LPCWSTR lpAccountName,
216                            IN ULONG ulRelativeId);
217 
218 NTSTATUS
219 SampRemoveAccountNameFromDomain(IN PSAM_DB_OBJECT DomainObject,
220                                 IN LPCWSTR lpContainerName,
221                                 IN LPCWSTR lpAccountName);
222 
223 NTSTATUS
224 SampCheckAccountNameInDomain(IN PSAM_DB_OBJECT DomainObject,
225                              IN LPCWSTR lpAccountName);
226 
227 NTSTATUS
228 SampRemoveMemberFromAllAliases(IN PSAM_DB_OBJECT DomainObject,
229                                IN PRPC_SID MemberSid);
230 
231 NTSTATUS
232 SampCreateAccountSid(IN PSAM_DB_OBJECT DomainObject,
233                      IN ULONG ulRelativeId,
234                      IN OUT PSID *AccountSid);
235 
236 /* group.h */
237 
238 NTSTATUS
239 SampOpenGroupObject(IN PSAM_DB_OBJECT DomainObject,
240                     IN ULONG GroupId,
241                     IN ACCESS_MASK DesiredAccess,
242                     OUT PSAM_DB_OBJECT *GroupObject);
243 
244 NTSTATUS
245 SampAddMemberToGroup(IN PSAM_DB_OBJECT GroupObject,
246                      IN ULONG MemberId);
247 
248 NTSTATUS
249 SampRemoveMemberFromGroup(IN PSAM_DB_OBJECT GroupObject,
250                           IN ULONG MemberId);
251 
252 
253 /* registry.h */
254 
255 NTSTATUS
256 SampRegCloseKey(IN OUT PHANDLE KeyHandle);
257 
258 NTSTATUS
259 SampRegCreateKey(IN HANDLE ParentKeyHandle,
260                  IN LPCWSTR KeyName,
261                  IN ACCESS_MASK DesiredAccess,
262                  OUT PHANDLE KeyHandle);
263 
264 NTSTATUS
265 SampRegDeleteKey(IN HANDLE ParentKeyHandle,
266                  IN LPCWSTR KeyName);
267 
268 NTSTATUS
269 SampRegEnumerateSubKey(IN HANDLE KeyHandle,
270                        IN ULONG Index,
271                        IN ULONG Length,
272                        OUT LPWSTR Buffer);
273 
274 NTSTATUS
275 SampRegOpenKey(IN HANDLE ParentKeyHandle,
276                IN LPCWSTR KeyName,
277                IN ACCESS_MASK DesiredAccess,
278                OUT PHANDLE KeyHandle);
279 
280 NTSTATUS
281 SampRegQueryKeyInfo(IN HANDLE KeyHandle,
282                     OUT PULONG SubKeyCount,
283                     OUT PULONG ValueCount);
284 
285 NTSTATUS
286 SampRegDeleteValue(IN HANDLE KeyHandle,
287                    IN LPCWSTR ValueName);
288 
289 NTSTATUS
290 SampRegEnumerateValue(IN HANDLE KeyHandle,
291                       IN ULONG Index,
292                       OUT LPWSTR Name,
293                       IN OUT PULONG NameLength,
294                       OUT PULONG Type OPTIONAL,
295                       OUT PVOID Data OPTIONAL,
296                       IN OUT PULONG DataLength OPTIONAL);
297 
298 NTSTATUS
299 SampRegQueryValue(IN HANDLE KeyHandle,
300                   IN LPCWSTR ValueName,
301                   OUT PULONG Type OPTIONAL,
302                   OUT LPVOID Data OPTIONAL,
303                   IN OUT PULONG DataLength OPTIONAL);
304 
305 NTSTATUS
306 SampRegSetValue(IN HANDLE KeyHandle,
307                 IN LPCWSTR ValueName,
308                 IN ULONG Type,
309                 IN LPVOID Data,
310                 IN ULONG DataLength);
311 
312 
313 /* samspc.c */
314 
315 VOID
316 SampStartRpcServer(VOID);
317 
318 
319 /* security.c */
320 
321 NTSTATUS
322 SampCreateServerSD(OUT PSECURITY_DESCRIPTOR *ServerSd,
323                    OUT PULONG Size);
324 
325 NTSTATUS
326 SampCreateBuiltinDomainSD(OUT PSECURITY_DESCRIPTOR *DomainSd,
327                           OUT PULONG Size);
328 
329 NTSTATUS
330 SampCreateAccountDomainSD(OUT PSECURITY_DESCRIPTOR *DomainSd,
331                           OUT PULONG Size);
332 
333 NTSTATUS
334 SampCreateAliasSD(OUT PSECURITY_DESCRIPTOR *AliasSd,
335                   OUT PULONG Size);
336 
337 NTSTATUS
338 SampCreateGroupSD(OUT PSECURITY_DESCRIPTOR *GroupSd,
339                   OUT PULONG Size);
340 
341 NTSTATUS
342 SampCreateUserSD(IN PSID UserSid,
343                  OUT PSECURITY_DESCRIPTOR *UserSd,
344                  OUT PULONG Size);
345 
346 /* setup.c */
347 
348 BOOL
349 SampInitializeSAM(VOID);
350 
351 
352 /* user.c */
353 
354 NTSTATUS
355 SampOpenUserObject(IN PSAM_DB_OBJECT DomainObject,
356                    IN ULONG UserId,
357                    IN ACCESS_MASK DesiredAccess,
358                    OUT PSAM_DB_OBJECT *UserObject);
359 
360 NTSTATUS
361 SampAddGroupMembershipToUser(IN PSAM_DB_OBJECT UserObject,
362                              IN ULONG GroupId,
363                              IN ULONG Attributes);
364 
365 NTSTATUS
366 SampRemoveGroupMembershipFromUser(IN PSAM_DB_OBJECT UserObject,
367                                   IN ULONG GroupId);
368 
369 NTSTATUS
370 SampGetUserGroupAttributes(IN PSAM_DB_OBJECT DomainObject,
371                            IN ULONG UserId,
372                            IN ULONG GroupId,
373                            OUT PULONG GroupAttributes);
374 
375 NTSTATUS
376 SampSetUserGroupAttributes(IN PSAM_DB_OBJECT DomainObject,
377                            IN ULONG UserId,
378                            IN ULONG GroupId,
379                            IN ULONG GroupAttributes);
380 
381 NTSTATUS
382 SampRemoveUserFromAllGroups(IN PSAM_DB_OBJECT UserObject);
383 
384 NTSTATUS
385 SampRemoveUserFromAllAliases(IN PSAM_DB_OBJECT UserObject);
386 
387 NTSTATUS
388 SampSetUserPassword(IN PSAM_DB_OBJECT UserObject,
389                     IN PENCRYPTED_NT_OWF_PASSWORD NtPassword,
390                     IN BOOLEAN NtPasswordPresent,
391                     IN PENCRYPTED_LM_OWF_PASSWORD LmPassword,
392                     IN BOOLEAN LmPasswordPresent);
393 
394 NTSTATUS
395 SampGetLogonHoursAttribute(IN PSAM_DB_OBJECT UserObject,
396                            IN OUT PSAMPR_LOGON_HOURS LogonHours);
397 
398 NTSTATUS
399 SampSetLogonHoursAttribute(IN PSAM_DB_OBJECT UserObject,
400                            IN PSAMPR_LOGON_HOURS LogonHours);
401 
402 
403 /* utils.c */
404 
405 INT
406 SampLoadString(HINSTANCE hInstance,
407                UINT uId,
408                LPWSTR lpBuffer,
409                INT nBufferMax);
410 
411 BOOL
412 SampIsSetupRunning(VOID);
413 
414 PSID
415 AppendRidToSid(PSID SrcSid,
416                ULONG Rid);
417 
418 NTSTATUS
419 SampGetRidFromSid(IN PSID Sid,
420                   OUT PULONG Rid);
421 
422 NTSTATUS
423 SampCheckAccountName(IN PRPC_UNICODE_STRING AccountName,
424                      IN USHORT MaxLength);
425 
426 
427 /* Undocumented advapi32 functions */
428 
429 NTSTATUS
430 WINAPI
431 SystemFunction006(LPCSTR password,
432                   LPSTR hash);
433 
434 NTSTATUS
435 WINAPI
436 SystemFunction007(PUNICODE_STRING string,
437                   LPBYTE hash);
438 
439 NTSTATUS
440 WINAPI
441 SystemFunction013(const BYTE *in,
442                   const BYTE *key,
443                   LPBYTE out);
444 
445 #endif /* _SAMSRV_PCH_ */
446