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