xref: /reactos/dll/win32/samsrv/samsrv.h (revision fb8edf90)
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 
126 /* alias.c */
127 
128 NTSTATUS
129 SampOpenAliasObject(IN PSAM_DB_OBJECT DomainObject,
130                     IN ULONG AliasId,
131                     IN ACCESS_MASK DesiredAccess,
132                     OUT PSAM_DB_OBJECT *AliasObject);
133 
134 NTSTATUS
135 SampAddMemberToAlias(IN PSAM_DB_OBJECT AliasObject,
136                      IN PRPC_SID MemberId);
137 
138 NTSTATUS
139 NTAPI
140 SampRemoveMemberFromAlias(IN PSAM_DB_OBJECT AliasObject,
141                           IN PRPC_SID MemberId);
142 
143 NTSTATUS
144 SampGetMembersInAlias(IN PSAM_DB_OBJECT AliasObject,
145                       OUT PULONG MemberCount,
146                       OUT PSAMPR_SID_INFORMATION *MemberArray);
147 
148 NTSTATUS
149 SampRemoveAllMembersFromAlias(IN PSAM_DB_OBJECT AliasObject);
150 
151 
152 /* database.c */
153 
154 NTSTATUS
155 SampInitDatabase(VOID);
156 
157 NTSTATUS
158 SampCreateDbObject(IN PSAM_DB_OBJECT ParentObject,
159                    IN LPWSTR ContainerName,
160                    IN LPWSTR ObjectName,
161                    IN ULONG RelativeId,
162                    IN SAM_DB_OBJECT_TYPE ObjectType,
163                    IN ACCESS_MASK DesiredAccess,
164                    OUT PSAM_DB_OBJECT *DbObject);
165 
166 NTSTATUS
167 SampOpenDbObject(IN PSAM_DB_OBJECT ParentObject,
168                  IN LPWSTR ContainerName,
169                  IN LPWSTR ObjectName,
170                  IN ULONG RelativeId,
171                  IN SAM_DB_OBJECT_TYPE ObjectType,
172                  IN ACCESS_MASK DesiredAccess,
173                  OUT PSAM_DB_OBJECT *DbObject);
174 
175 NTSTATUS
176 SampValidateDbObject(SAMPR_HANDLE Handle,
177                      SAM_DB_OBJECT_TYPE ObjectType,
178                      ACCESS_MASK DesiredAccess,
179                      PSAM_DB_OBJECT *DbObject);
180 
181 NTSTATUS
182 SampCloseDbObject(PSAM_DB_OBJECT DbObject);
183 
184 NTSTATUS
185 SampDeleteAccountDbObject(PSAM_DB_OBJECT DbObject);
186 
187 NTSTATUS
188 SampSetObjectAttribute(PSAM_DB_OBJECT DbObject,
189                        LPWSTR AttributeName,
190                        ULONG AttributeType,
191                        LPVOID AttributeData,
192                        ULONG AttributeSize);
193 
194 NTSTATUS
195 SampGetObjectAttribute(PSAM_DB_OBJECT DbObject,
196                        LPWSTR AttributeName,
197                        PULONG AttributeType,
198                        LPVOID AttributeData,
199                        PULONG AttributeSize);
200 
201 NTSTATUS
202 SampGetObjectAttributeString(PSAM_DB_OBJECT DbObject,
203                              LPWSTR AttributeName,
204                              PRPC_UNICODE_STRING String);
205 
206 NTSTATUS
207 SampSetObjectAttributeString(PSAM_DB_OBJECT DbObject,
208                              LPWSTR AttributeName,
209                              PRPC_UNICODE_STRING String);
210 
211 
212 /* display.c */
213 
214 NTSTATUS
215 SampInitializeDisplayCache(VOID);
216 
217 NTSTATUS
218 SampShutdownDisplayCache(VOID);
219 
220 NTSTATUS
221 SampFillDisplayCache(
222     _In_ PSAM_DB_OBJECT DomainObject,
223     _In_ DOMAIN_DISPLAY_INFORMATION DisplayInformationClass);
224 
225 
226 /* domain.c */
227 
228 NTSTATUS
229 SampSetAccountNameInDomain(IN PSAM_DB_OBJECT DomainObject,
230                            IN LPCWSTR lpContainerName,
231                            IN LPCWSTR lpAccountName,
232                            IN ULONG ulRelativeId);
233 
234 NTSTATUS
235 SampRemoveAccountNameFromDomain(IN PSAM_DB_OBJECT DomainObject,
236                                 IN LPCWSTR lpContainerName,
237                                 IN LPCWSTR lpAccountName);
238 
239 NTSTATUS
240 SampCheckAccountNameInDomain(IN PSAM_DB_OBJECT DomainObject,
241                              IN LPCWSTR lpAccountName);
242 
243 NTSTATUS
244 SampRemoveMemberFromAllAliases(IN PSAM_DB_OBJECT DomainObject,
245                                IN PRPC_SID MemberSid);
246 
247 NTSTATUS
248 SampCreateAccountSid(IN PSAM_DB_OBJECT DomainObject,
249                      IN ULONG ulRelativeId,
250                      IN OUT PSID *AccountSid);
251 
252 
253 /* group.h */
254 
255 NTSTATUS
256 SampOpenGroupObject(IN PSAM_DB_OBJECT DomainObject,
257                     IN ULONG GroupId,
258                     IN ACCESS_MASK DesiredAccess,
259                     OUT PSAM_DB_OBJECT *GroupObject);
260 
261 NTSTATUS
262 SampAddMemberToGroup(IN PSAM_DB_OBJECT GroupObject,
263                      IN ULONG MemberId);
264 
265 NTSTATUS
266 SampRemoveMemberFromGroup(IN PSAM_DB_OBJECT GroupObject,
267                           IN ULONG MemberId);
268 
269 
270 /* registry.h */
271 
272 NTSTATUS
273 SampRegCloseKey(IN OUT PHANDLE KeyHandle);
274 
275 NTSTATUS
276 SampRegCreateKey(IN HANDLE ParentKeyHandle,
277                  IN LPCWSTR KeyName,
278                  IN ACCESS_MASK DesiredAccess,
279                  OUT PHANDLE KeyHandle);
280 
281 NTSTATUS
282 SampRegDeleteKey(IN HANDLE ParentKeyHandle,
283                  IN LPCWSTR KeyName);
284 
285 NTSTATUS
286 SampRegEnumerateSubKey(IN HANDLE KeyHandle,
287                        IN ULONG Index,
288                        IN ULONG Length,
289                        OUT LPWSTR Buffer);
290 
291 NTSTATUS
292 SampRegOpenKey(IN HANDLE ParentKeyHandle,
293                IN LPCWSTR KeyName,
294                IN ACCESS_MASK DesiredAccess,
295                OUT PHANDLE KeyHandle);
296 
297 NTSTATUS
298 SampRegQueryKeyInfo(IN HANDLE KeyHandle,
299                     OUT PULONG SubKeyCount,
300                     OUT PULONG ValueCount);
301 
302 NTSTATUS
303 SampRegDeleteValue(IN HANDLE KeyHandle,
304                    IN LPCWSTR ValueName);
305 
306 NTSTATUS
307 SampRegEnumerateValue(IN HANDLE KeyHandle,
308                       IN ULONG Index,
309                       OUT LPWSTR Name,
310                       IN OUT PULONG NameLength,
311                       OUT PULONG Type OPTIONAL,
312                       OUT PVOID Data OPTIONAL,
313                       IN OUT PULONG DataLength OPTIONAL);
314 
315 NTSTATUS
316 SampRegQueryValue(IN HANDLE KeyHandle,
317                   IN LPCWSTR ValueName,
318                   OUT PULONG Type OPTIONAL,
319                   OUT LPVOID Data OPTIONAL,
320                   IN OUT PULONG DataLength OPTIONAL);
321 
322 NTSTATUS
323 SampRegSetValue(IN HANDLE KeyHandle,
324                 IN LPCWSTR ValueName,
325                 IN ULONG Type,
326                 IN LPVOID Data,
327                 IN ULONG DataLength);
328 
329 
330 /* samspc.c */
331 
332 VOID
333 SampStartRpcServer(VOID);
334 
335 
336 /* security.c */
337 
338 NTSTATUS
339 SampCreateServerSD(OUT PSECURITY_DESCRIPTOR *ServerSd,
340                    OUT PULONG Size);
341 
342 NTSTATUS
343 SampCreateBuiltinDomainSD(OUT PSECURITY_DESCRIPTOR *DomainSd,
344                           OUT PULONG Size);
345 
346 NTSTATUS
347 SampCreateAccountDomainSD(OUT PSECURITY_DESCRIPTOR *DomainSd,
348                           OUT PULONG Size);
349 
350 NTSTATUS
351 SampCreateAliasSD(OUT PSECURITY_DESCRIPTOR *AliasSd,
352                   OUT PULONG Size);
353 
354 NTSTATUS
355 SampCreateGroupSD(OUT PSECURITY_DESCRIPTOR *GroupSd,
356                   OUT PULONG Size);
357 
358 NTSTATUS
359 SampCreateUserSD(IN PSID UserSid,
360                  OUT PSECURITY_DESCRIPTOR *UserSd,
361                  OUT PULONG Size);
362 
363 
364 /* setup.c */
365 
366 BOOL
367 SampInitializeSAM(VOID);
368 
369 
370 /* user.c */
371 
372 NTSTATUS
373 SampOpenUserObject(IN PSAM_DB_OBJECT DomainObject,
374                    IN ULONG UserId,
375                    IN ACCESS_MASK DesiredAccess,
376                    OUT PSAM_DB_OBJECT *UserObject);
377 
378 NTSTATUS
379 SampAddGroupMembershipToUser(IN PSAM_DB_OBJECT UserObject,
380                              IN ULONG GroupId,
381                              IN ULONG Attributes);
382 
383 NTSTATUS
384 SampRemoveGroupMembershipFromUser(IN PSAM_DB_OBJECT UserObject,
385                                   IN ULONG GroupId);
386 
387 NTSTATUS
388 SampGetUserGroupAttributes(IN PSAM_DB_OBJECT DomainObject,
389                            IN ULONG UserId,
390                            IN ULONG GroupId,
391                            OUT PULONG GroupAttributes);
392 
393 NTSTATUS
394 SampSetUserGroupAttributes(IN PSAM_DB_OBJECT DomainObject,
395                            IN ULONG UserId,
396                            IN ULONG GroupId,
397                            IN ULONG GroupAttributes);
398 
399 NTSTATUS
400 SampRemoveUserFromAllGroups(IN PSAM_DB_OBJECT UserObject);
401 
402 NTSTATUS
403 SampRemoveUserFromAllAliases(IN PSAM_DB_OBJECT UserObject);
404 
405 NTSTATUS
406 SampSetUserPassword(IN PSAM_DB_OBJECT UserObject,
407                     IN PENCRYPTED_NT_OWF_PASSWORD NtPassword,
408                     IN BOOLEAN NtPasswordPresent,
409                     IN PENCRYPTED_LM_OWF_PASSWORD LmPassword,
410                     IN BOOLEAN LmPasswordPresent);
411 
412 NTSTATUS
413 SampGetLogonHoursAttribute(IN PSAM_DB_OBJECT UserObject,
414                            IN OUT PSAMPR_LOGON_HOURS LogonHours);
415 
416 NTSTATUS
417 SampSetLogonHoursAttribute(IN PSAM_DB_OBJECT UserObject,
418                            IN PSAMPR_LOGON_HOURS LogonHours);
419 
420 
421 /* utils.c */
422 
423 INT
424 SampLoadString(HINSTANCE hInstance,
425                UINT uId,
426                LPWSTR lpBuffer,
427                INT nBufferMax);
428 
429 BOOL
430 SampIsSetupRunning(VOID);
431 
432 PSID
433 AppendRidToSid(PSID SrcSid,
434                ULONG Rid);
435 
436 NTSTATUS
437 SampGetRidFromSid(IN PSID Sid,
438                   OUT PULONG Rid);
439 
440 NTSTATUS
441 SampCheckAccountName(IN PRPC_UNICODE_STRING AccountName,
442                      IN USHORT MaxLength);
443 
444 
445 /* Undocumented advapi32 functions */
446 
447 NTSTATUS
448 WINAPI
449 SystemFunction006(LPCSTR password,
450                   LPSTR hash);
451 
452 NTSTATUS
453 WINAPI
454 SystemFunction007(PUNICODE_STRING string,
455                   LPBYTE hash);
456 
457 NTSTATUS
458 WINAPI
459 SystemFunction013(const BYTE *in,
460                   const BYTE *key,
461                   LPBYTE out);
462 
463 #endif /* _SAMSRV_PCH_ */
464