3 * Copyright (C) 2005 Eric Kohl
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 /* INCLUDES *****************************************************************/
24 WINE_DEFAULT_DEBUG_CHANNEL(samsrv
);
27 /* GLOBALS *******************************************************************/
29 ENCRYPTED_NT_OWF_PASSWORD EmptyNtHash
;
30 ENCRYPTED_LM_OWF_PASSWORD EmptyLmHash
;
33 /* FUNCTIONS *****************************************************************/
39 UNICODE_STRING EmptyNtPassword
= {0, 0, NULL
};
40 CHAR EmptyLmPassword
[15] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,};
43 /* Calculate the NT hash value of the empty password */
44 Status
= SystemFunction007(&EmptyNtPassword
,
45 (LPBYTE
)&EmptyNtHash
);
46 if (!NT_SUCCESS(Status
))
48 ERR("Calculation of the empty NT hash failed (Status 0x%08lx)\n", Status
);
52 /* Calculate the LM hash value of the empty password */
53 Status
= SystemFunction006(EmptyLmPassword
,
55 if (!NT_SUCCESS(Status
))
57 ERR("Calculation of the empty LM hash failed (Status 0x%08lx)\n", Status
);
66 SamIConnect(IN PSAMPR_SERVER_NAME ServerName
,
67 OUT SAMPR_HANDLE
*ServerHandle
,
68 IN ACCESS_MASK DesiredAccess
,
71 PSAM_DB_OBJECT ServerObject
;
74 TRACE("SamIConnect(%p %p %lx %ld)\n",
75 ServerName
, ServerHandle
, DesiredAccess
, Trusted
);
77 /* Map generic access rights */
78 RtlMapGenericMask(&DesiredAccess
,
81 /* Open the Server Object */
82 Status
= SampOpenDbObject(NULL
,
89 if (NT_SUCCESS(Status
))
91 ServerObject
->Trusted
= Trusted
;
92 *ServerHandle
= (SAMPR_HANDLE
)ServerObject
;
95 TRACE("SamIConnect done (Status 0x%08lx)\n", Status
);
105 NTSTATUS Status
= STATUS_SUCCESS
;
107 TRACE("SamIInitialize() called\n");
109 Status
= SampInitHashes();
110 if (!NT_SUCCESS(Status
))
113 if (SampIsSetupRunning())
115 Status
= SampInitializeRegistry();
116 if (!NT_SUCCESS(Status
))
120 /* Initialize the SAM database */
121 Status
= SampInitDatabase();
122 if (!NT_SUCCESS(Status
))
125 /* Start the RPC server */
126 SampStartRpcServer();
134 SampInitializeRegistry(VOID
)
136 TRACE("SampInitializeRegistry() called\n");
140 return STATUS_SUCCESS
;
146 SamIFree_SAMPR_ENUMERATION_BUFFER(PSAMPR_ENUMERATION_BUFFER Ptr
)
152 if (Ptr
->Buffer
!= NULL
)
154 for (i
= 0; i
< Ptr
->EntriesRead
; i
++)
156 if (Ptr
->Buffer
[i
].Name
.Buffer
!= NULL
)
157 MIDL_user_free(Ptr
->Buffer
[i
].Name
.Buffer
);
160 MIDL_user_free(Ptr
->Buffer
);
170 SamIFree_SAMPR_GET_GROUPS_BUFFER(PSAMPR_GET_GROUPS_BUFFER Ptr
)
174 if (Ptr
->Groups
!= NULL
)
175 MIDL_user_free(Ptr
->Groups
);
184 SamIFree_SAMPR_PSID_ARRAY(PSAMPR_PSID_ARRAY Ptr
)
188 if (Ptr
->Sids
!= NULL
)
190 MIDL_user_free(Ptr
->Sids
);
198 SamIFree_SAMPR_RETURNED_USTRING_ARRAY(PSAMPR_RETURNED_USTRING_ARRAY Ptr
)
204 if (Ptr
->Element
!= NULL
)
206 for (i
= 0; i
< Ptr
->Count
; i
++)
208 if (Ptr
->Element
[i
].Buffer
!= NULL
)
209 MIDL_user_free(Ptr
->Element
[i
].Buffer
);
212 MIDL_user_free(Ptr
->Element
);
222 SamIFree_SAMPR_ULONG_ARRAY(PSAMPR_ULONG_ARRAY Ptr
)
226 if (Ptr
->Element
!= NULL
)
228 MIDL_user_free(Ptr
->Element
);
238 SamIFree_SAMPR_USER_INFO_BUFFER(PSAMPR_USER_INFO_BUFFER Ptr
,
239 USER_INFORMATION_CLASS InformationClass
)
244 switch (InformationClass
)
246 case UserGeneralInformation
:
247 if (Ptr
->General
.UserName
.Buffer
!= NULL
)
248 MIDL_user_free(Ptr
->General
.UserName
.Buffer
);
250 if (Ptr
->General
.FullName
.Buffer
!= NULL
)
251 MIDL_user_free(Ptr
->General
.FullName
.Buffer
);
253 if (Ptr
->General
.AdminComment
.Buffer
!= NULL
)
254 MIDL_user_free(Ptr
->General
.AdminComment
.Buffer
);
256 if (Ptr
->General
.UserComment
.Buffer
!= NULL
)
257 MIDL_user_free(Ptr
->General
.UserComment
.Buffer
);
260 case UserPreferencesInformation
:
261 if (Ptr
->Preferences
.UserComment
.Buffer
!= NULL
)
262 MIDL_user_free(Ptr
->Preferences
.UserComment
.Buffer
);
264 if (Ptr
->Preferences
.Reserved1
.Buffer
!= NULL
)
265 MIDL_user_free(Ptr
->Preferences
.Reserved1
.Buffer
);
268 case UserLogonInformation
:
269 if (Ptr
->Logon
.UserName
.Buffer
!= NULL
)
270 MIDL_user_free(Ptr
->Logon
.UserName
.Buffer
);
272 if (Ptr
->Logon
.FullName
.Buffer
!= NULL
)
273 MIDL_user_free(Ptr
->Logon
.FullName
.Buffer
);
275 if (Ptr
->Logon
.HomeDirectory
.Buffer
!= NULL
)
276 MIDL_user_free(Ptr
->Logon
.HomeDirectory
.Buffer
);
278 if (Ptr
->Logon
.HomeDirectoryDrive
.Buffer
!= NULL
)
279 MIDL_user_free(Ptr
->Logon
.HomeDirectoryDrive
.Buffer
);
281 if (Ptr
->Logon
.ScriptPath
.Buffer
!= NULL
)
282 MIDL_user_free(Ptr
->Logon
.ScriptPath
.Buffer
);
284 if (Ptr
->Logon
.ProfilePath
.Buffer
!= NULL
)
285 MIDL_user_free(Ptr
->Logon
.ProfilePath
.Buffer
);
287 if (Ptr
->Logon
.WorkStations
.Buffer
!= NULL
)
288 MIDL_user_free(Ptr
->Logon
.WorkStations
.Buffer
);
290 if (Ptr
->Logon
.LogonHours
.LogonHours
!= NULL
)
291 MIDL_user_free(Ptr
->Logon
.LogonHours
.LogonHours
);
294 case UserLogonHoursInformation
:
295 if (Ptr
->LogonHours
.LogonHours
.LogonHours
!= NULL
)
296 MIDL_user_free(Ptr
->LogonHours
.LogonHours
.LogonHours
);
299 case UserAccountInformation
:
300 if (Ptr
->Account
.UserName
.Buffer
!= NULL
)
301 MIDL_user_free(Ptr
->Account
.UserName
.Buffer
);
303 if (Ptr
->Account
.FullName
.Buffer
!= NULL
)
304 MIDL_user_free(Ptr
->Account
.FullName
.Buffer
);
306 if (Ptr
->Account
.HomeDirectory
.Buffer
!= NULL
)
307 MIDL_user_free(Ptr
->Account
.HomeDirectory
.Buffer
);
309 if (Ptr
->Account
.HomeDirectoryDrive
.Buffer
!= NULL
)
310 MIDL_user_free(Ptr
->Account
.HomeDirectoryDrive
.Buffer
);
312 if (Ptr
->Account
.ScriptPath
.Buffer
!= NULL
)
313 MIDL_user_free(Ptr
->Account
.ScriptPath
.Buffer
);
315 if (Ptr
->Account
.ProfilePath
.Buffer
!= NULL
)
316 MIDL_user_free(Ptr
->Account
.ProfilePath
.Buffer
);
318 if (Ptr
->Account
.AdminComment
.Buffer
!= NULL
)
319 MIDL_user_free(Ptr
->Account
.AdminComment
.Buffer
);
321 if (Ptr
->Account
.WorkStations
.Buffer
!= NULL
)
322 MIDL_user_free(Ptr
->Account
.WorkStations
.Buffer
);
324 if (Ptr
->Account
.LogonHours
.LogonHours
!= NULL
)
325 MIDL_user_free(Ptr
->Account
.LogonHours
.LogonHours
);
328 case UserNameInformation
:
329 if (Ptr
->Name
.UserName
.Buffer
!= NULL
)
330 MIDL_user_free(Ptr
->Name
.UserName
.Buffer
);
332 if (Ptr
->Name
.FullName
.Buffer
!= NULL
)
333 MIDL_user_free(Ptr
->Name
.FullName
.Buffer
);
336 case UserAccountNameInformation
:
337 if (Ptr
->AccountName
.UserName
.Buffer
!= NULL
)
338 MIDL_user_free(Ptr
->AccountName
.UserName
.Buffer
);
341 case UserFullNameInformation
:
342 if (Ptr
->FullName
.FullName
.Buffer
!= NULL
)
343 MIDL_user_free(Ptr
->FullName
.FullName
.Buffer
);
346 case UserPrimaryGroupInformation
:
349 case UserHomeInformation
:
350 if (Ptr
->Home
.HomeDirectory
.Buffer
!= NULL
)
351 MIDL_user_free(Ptr
->Home
.HomeDirectory
.Buffer
);
353 if (Ptr
->Home
.HomeDirectoryDrive
.Buffer
!= NULL
)
354 MIDL_user_free(Ptr
->Home
.HomeDirectoryDrive
.Buffer
);
357 case UserScriptInformation
:
358 if (Ptr
->Script
.ScriptPath
.Buffer
!= NULL
)
359 MIDL_user_free(Ptr
->Script
.ScriptPath
.Buffer
);
361 case UserProfileInformation
:
362 if (Ptr
->Profile
.ProfilePath
.Buffer
!= NULL
)
363 MIDL_user_free(Ptr
->Profile
.ProfilePath
.Buffer
);
365 case UserAdminCommentInformation
:
366 if (Ptr
->AdminComment
.AdminComment
.Buffer
!= NULL
)
367 MIDL_user_free(Ptr
->AdminComment
.AdminComment
.Buffer
);
370 case UserWorkStationsInformation
:
371 if (Ptr
->WorkStations
.WorkStations
.Buffer
!= NULL
)
372 MIDL_user_free(Ptr
->WorkStations
.WorkStations
.Buffer
);
375 case UserSetPasswordInformation
:
376 ERR("Information class UserSetPasswordInformation cannot be queried!\n");
379 case UserControlInformation
:
382 case UserExpiresInformation
:
385 case UserInternal1Information
:
388 case UserInternal2Information
:
391 case UserParametersInformation
:
392 if (Ptr
->Parameters
.Parameters
.Buffer
!= NULL
)
393 MIDL_user_free(Ptr
->Parameters
.Parameters
.Buffer
);
396 case UserAllInformation
:
397 if (Ptr
->All
.UserName
.Buffer
!= NULL
)
398 MIDL_user_free(Ptr
->All
.UserName
.Buffer
);
400 if (Ptr
->All
.FullName
.Buffer
!= NULL
)
401 MIDL_user_free(Ptr
->All
.FullName
.Buffer
);
403 if (Ptr
->All
.HomeDirectory
.Buffer
!= NULL
)
404 MIDL_user_free(Ptr
->All
.HomeDirectory
.Buffer
);
406 if (Ptr
->All
.HomeDirectoryDrive
.Buffer
!= NULL
)
407 MIDL_user_free(Ptr
->All
.HomeDirectoryDrive
.Buffer
);
409 if (Ptr
->All
.ScriptPath
.Buffer
!= NULL
)
410 MIDL_user_free(Ptr
->All
.ScriptPath
.Buffer
);
412 if (Ptr
->All
.ProfilePath
.Buffer
!= NULL
)
413 MIDL_user_free(Ptr
->All
.ProfilePath
.Buffer
);
415 if (Ptr
->All
.AdminComment
.Buffer
!= NULL
)
416 MIDL_user_free(Ptr
->All
.AdminComment
.Buffer
);
418 if (Ptr
->All
.WorkStations
.Buffer
!= NULL
)
419 MIDL_user_free(Ptr
->All
.WorkStations
.Buffer
);
421 if (Ptr
->All
.UserComment
.Buffer
!= NULL
)
422 MIDL_user_free(Ptr
->All
.UserComment
.Buffer
);
424 if (Ptr
->All
.Parameters
.Buffer
!= NULL
)
425 MIDL_user_free(Ptr
->All
.Parameters
.Buffer
);
427 if (Ptr
->All
.LmOwfPassword
.Buffer
!= NULL
)
428 MIDL_user_free(Ptr
->All
.LmOwfPassword
.Buffer
);
430 if (Ptr
->All
.NtOwfPassword
.Buffer
!= NULL
)
431 MIDL_user_free(Ptr
->All
.NtOwfPassword
.Buffer
);
433 if (Ptr
->All
.PrivateData
.Buffer
!= NULL
)
434 MIDL_user_free(Ptr
->All
.PrivateData
.Buffer
);
436 if (Ptr
->All
.SecurityDescriptor
.SecurityDescriptor
!= NULL
)
437 MIDL_user_free(Ptr
->All
.SecurityDescriptor
.SecurityDescriptor
);
439 if (Ptr
->All
.LogonHours
.LogonHours
!= NULL
)
440 MIDL_user_free(Ptr
->All
.LogonHours
.LogonHours
);
444 FIXME("Unsupported information class: %lu\n", InformationClass
);