[SAMSRV]
[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 NTSTATUS
234 SampCreateAccountSid(IN PSAM_DB_OBJECT DomainObject,
235 IN ULONG ulRelativeId,
236 IN OUT PSID *AccountSid);
237
238 /* group.h */
239
240 NTSTATUS
241 SampOpenGroupObject(IN PSAM_DB_OBJECT DomainObject,
242 IN ULONG GroupId,
243 IN ACCESS_MASK DesiredAccess,
244 OUT PSAM_DB_OBJECT *GroupObject);
245
246 NTSTATUS
247 SampAddMemberToGroup(IN PSAM_DB_OBJECT GroupObject,
248 IN ULONG MemberId);
249
250 NTSTATUS
251 SampRemoveMemberFromGroup(IN PSAM_DB_OBJECT GroupObject,
252 IN ULONG MemberId);
253
254
255 /* registry.h */
256
257 NTSTATUS
258 SampRegCloseKey(IN OUT PHANDLE KeyHandle);
259
260 NTSTATUS
261 SampRegCreateKey(IN HANDLE ParentKeyHandle,
262 IN LPCWSTR KeyName,
263 IN ACCESS_MASK DesiredAccess,
264 OUT PHANDLE KeyHandle);
265
266 NTSTATUS
267 SampRegDeleteKey(IN HANDLE ParentKeyHandle,
268 IN LPCWSTR KeyName);
269
270 NTSTATUS
271 SampRegEnumerateSubKey(IN HANDLE KeyHandle,
272 IN ULONG Index,
273 IN ULONG Length,
274 OUT LPWSTR Buffer);
275
276 NTSTATUS
277 SampRegOpenKey(IN HANDLE ParentKeyHandle,
278 IN LPCWSTR KeyName,
279 IN ACCESS_MASK DesiredAccess,
280 OUT PHANDLE KeyHandle);
281
282 NTSTATUS
283 SampRegQueryKeyInfo(IN HANDLE KeyHandle,
284 OUT PULONG SubKeyCount,
285 OUT PULONG ValueCount);
286
287 NTSTATUS
288 SampRegDeleteValue(IN HANDLE KeyHandle,
289 IN LPCWSTR ValueName);
290
291 NTSTATUS
292 SampRegEnumerateValue(IN HANDLE KeyHandle,
293 IN ULONG Index,
294 OUT LPWSTR Name,
295 IN OUT PULONG NameLength,
296 OUT PULONG Type OPTIONAL,
297 OUT PVOID Data OPTIONAL,
298 IN OUT PULONG DataLength OPTIONAL);
299
300 NTSTATUS
301 SampRegQueryValue(IN HANDLE KeyHandle,
302 IN LPCWSTR ValueName,
303 OUT PULONG Type OPTIONAL,
304 OUT LPVOID Data OPTIONAL,
305 IN OUT PULONG DataLength OPTIONAL);
306
307 NTSTATUS
308 SampRegSetValue(IN HANDLE KeyHandle,
309 IN LPCWSTR ValueName,
310 IN ULONG Type,
311 IN LPVOID Data,
312 IN ULONG DataLength);
313
314
315 /* samspc.c */
316
317 VOID
318 SampStartRpcServer(VOID);
319
320
321 /* security.c */
322
323 NTSTATUS
324 SampCreateServerSD(OUT PSECURITY_DESCRIPTOR *ServerSd,
325 OUT PULONG Size);
326
327 NTSTATUS
328 SampCreateBuiltinDomainSD(OUT PSECURITY_DESCRIPTOR *DomainSd,
329 OUT PULONG Size);
330
331 NTSTATUS
332 SampCreateAccountDomainSD(OUT PSECURITY_DESCRIPTOR *DomainSd,
333 OUT PULONG Size);
334
335 NTSTATUS
336 SampCreateAliasSD(OUT PSECURITY_DESCRIPTOR *AliasSd,
337 OUT PULONG Size);
338
339 NTSTATUS
340 SampCreateGroupSD(OUT PSECURITY_DESCRIPTOR *GroupSd,
341 OUT PULONG Size);
342
343 NTSTATUS
344 SampCreateUserSD(IN PSID UserSid,
345 OUT PSECURITY_DESCRIPTOR *UserSd,
346 OUT PULONG Size);
347
348 /* setup.c */
349
350 BOOL
351 SampInitializeSAM(VOID);
352
353
354 /* user.c */
355
356 NTSTATUS
357 SampOpenUserObject(IN PSAM_DB_OBJECT DomainObject,
358 IN ULONG UserId,
359 IN ACCESS_MASK DesiredAccess,
360 OUT PSAM_DB_OBJECT *UserObject);
361
362 NTSTATUS
363 SampAddGroupMembershipToUser(IN PSAM_DB_OBJECT UserObject,
364 IN ULONG GroupId,
365 IN ULONG Attributes);
366
367 NTSTATUS
368 SampRemoveGroupMembershipFromUser(IN PSAM_DB_OBJECT UserObject,
369 IN ULONG GroupId);
370
371 NTSTATUS
372 SampGetUserGroupAttributes(IN PSAM_DB_OBJECT DomainObject,
373 IN ULONG UserId,
374 IN ULONG GroupId,
375 OUT PULONG GroupAttributes);
376
377 NTSTATUS
378 SampSetUserGroupAttributes(IN PSAM_DB_OBJECT DomainObject,
379 IN ULONG UserId,
380 IN ULONG GroupId,
381 IN ULONG GroupAttributes);
382
383 NTSTATUS
384 SampRemoveUserFromAllGroups(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 SampGetLogonHoursAttrbute(IN PSAM_DB_OBJECT UserObject,
395 IN OUT PSAMPR_LOGON_HOURS LogonHours);
396
397 NTSTATUS
398 SampSetLogonHoursAttrbute(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 /* EOF */