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