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
;
31 RTL_RESOURCE SampResource
;
34 /* FUNCTIONS *****************************************************************/
40 UNICODE_STRING EmptyNtPassword
= {0, 0, NULL
};
41 CHAR EmptyLmPassword
[15] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,};
44 /* Calculate the NT hash value of the empty password */
45 Status
= SystemFunction007(&EmptyNtPassword
,
46 (LPBYTE
)&EmptyNtHash
);
47 if (!NT_SUCCESS(Status
))
49 ERR("Calculation of the empty NT hash failed (Status 0x%08lx)\n", Status
);
53 /* Calculate the LM hash value of the empty password */
54 Status
= SystemFunction006(EmptyLmPassword
,
56 if (!NT_SUCCESS(Status
))
58 ERR("Calculation of the empty LM hash failed (Status 0x%08lx)\n", Status
);
67 SamIConnect(IN PSAMPR_SERVER_NAME ServerName
,
68 OUT SAMPR_HANDLE
*ServerHandle
,
69 IN ACCESS_MASK DesiredAccess
,
72 PSAM_DB_OBJECT ServerObject
;
75 TRACE("SamIConnect(%p %p %lx %ld)\n",
76 ServerName
, ServerHandle
, DesiredAccess
, Trusted
);
78 /* Map generic access rights */
79 RtlMapGenericMask(&DesiredAccess
,
82 /* Open the Server Object */
83 Status
= SampOpenDbObject(NULL
,
90 if (NT_SUCCESS(Status
))
92 ServerObject
->Trusted
= Trusted
;
93 *ServerHandle
= (SAMPR_HANDLE
)ServerObject
;
96 TRACE("SamIConnect done (Status 0x%08lx)\n", Status
);
106 NTSTATUS Status
= STATUS_SUCCESS
;
108 TRACE("SamIInitialize() called\n");
110 Status
= SampInitHashes();
111 if (!NT_SUCCESS(Status
))
114 if (SampIsSetupRunning())
116 Status
= SampInitializeRegistry();
117 if (!NT_SUCCESS(Status
))
121 RtlInitializeResource(&SampResource
);
123 /* Initialize the SAM database */
124 Status
= SampInitDatabase();
125 if (!NT_SUCCESS(Status
))
128 /* Start the RPC server */
129 SampStartRpcServer();
137 SampInitializeRegistry(VOID
)
139 TRACE("SampInitializeRegistry() called\n");
143 return STATUS_SUCCESS
;
149 SamIFree_SAMPR_ENUMERATION_BUFFER(PSAMPR_ENUMERATION_BUFFER Ptr
)
155 if (Ptr
->Buffer
!= NULL
)
157 for (i
= 0; i
< Ptr
->EntriesRead
; i
++)
159 if (Ptr
->Buffer
[i
].Name
.Buffer
!= NULL
)
160 MIDL_user_free(Ptr
->Buffer
[i
].Name
.Buffer
);
163 MIDL_user_free(Ptr
->Buffer
);
173 SamIFree_SAMPR_GET_GROUPS_BUFFER(PSAMPR_GET_GROUPS_BUFFER Ptr
)
177 if (Ptr
->Groups
!= NULL
)
178 MIDL_user_free(Ptr
->Groups
);
187 SamIFree_SAMPR_GET_MEMBERS_BUFFER(PSAMPR_GET_MEMBERS_BUFFER Ptr
)
191 if (Ptr
->Members
!= NULL
)
192 MIDL_user_free(Ptr
->Members
);
194 if (Ptr
->Attributes
!= NULL
)
195 MIDL_user_free(Ptr
->Attributes
);
204 SamIFree_SAMPR_PSID_ARRAY(PSAMPR_PSID_ARRAY Ptr
)
208 if (Ptr
->Sids
!= NULL
)
210 MIDL_user_free(Ptr
->Sids
);
218 SamIFree_SAMPR_RETURNED_USTRING_ARRAY(PSAMPR_RETURNED_USTRING_ARRAY Ptr
)
224 if (Ptr
->Element
!= NULL
)
226 for (i
= 0; i
< Ptr
->Count
; i
++)
228 if (Ptr
->Element
[i
].Buffer
!= NULL
)
229 MIDL_user_free(Ptr
->Element
[i
].Buffer
);
232 MIDL_user_free(Ptr
->Element
);
242 SamIFree_SAMPR_SR_SECURITY_DESCRIPTOR(PSAMPR_SR_SECURITY_DESCRIPTOR Ptr
)
246 if (Ptr
->SecurityDescriptor
!= NULL
)
247 MIDL_user_free(Ptr
->SecurityDescriptor
);
256 SamIFree_SAMPR_ULONG_ARRAY(PSAMPR_ULONG_ARRAY Ptr
)
260 if (Ptr
->Element
!= NULL
)
262 MIDL_user_free(Ptr
->Element
);
272 SamIFree_SAMPR_USER_INFO_BUFFER(PSAMPR_USER_INFO_BUFFER Ptr
,
273 USER_INFORMATION_CLASS InformationClass
)
278 switch (InformationClass
)
280 case UserGeneralInformation
:
281 if (Ptr
->General
.UserName
.Buffer
!= NULL
)
282 MIDL_user_free(Ptr
->General
.UserName
.Buffer
);
284 if (Ptr
->General
.FullName
.Buffer
!= NULL
)
285 MIDL_user_free(Ptr
->General
.FullName
.Buffer
);
287 if (Ptr
->General
.AdminComment
.Buffer
!= NULL
)
288 MIDL_user_free(Ptr
->General
.AdminComment
.Buffer
);
290 if (Ptr
->General
.UserComment
.Buffer
!= NULL
)
291 MIDL_user_free(Ptr
->General
.UserComment
.Buffer
);
294 case UserPreferencesInformation
:
295 if (Ptr
->Preferences
.UserComment
.Buffer
!= NULL
)
296 MIDL_user_free(Ptr
->Preferences
.UserComment
.Buffer
);
298 if (Ptr
->Preferences
.Reserved1
.Buffer
!= NULL
)
299 MIDL_user_free(Ptr
->Preferences
.Reserved1
.Buffer
);
302 case UserLogonInformation
:
303 if (Ptr
->Logon
.UserName
.Buffer
!= NULL
)
304 MIDL_user_free(Ptr
->Logon
.UserName
.Buffer
);
306 if (Ptr
->Logon
.FullName
.Buffer
!= NULL
)
307 MIDL_user_free(Ptr
->Logon
.FullName
.Buffer
);
309 if (Ptr
->Logon
.HomeDirectory
.Buffer
!= NULL
)
310 MIDL_user_free(Ptr
->Logon
.HomeDirectory
.Buffer
);
312 if (Ptr
->Logon
.HomeDirectoryDrive
.Buffer
!= NULL
)
313 MIDL_user_free(Ptr
->Logon
.HomeDirectoryDrive
.Buffer
);
315 if (Ptr
->Logon
.ScriptPath
.Buffer
!= NULL
)
316 MIDL_user_free(Ptr
->Logon
.ScriptPath
.Buffer
);
318 if (Ptr
->Logon
.ProfilePath
.Buffer
!= NULL
)
319 MIDL_user_free(Ptr
->Logon
.ProfilePath
.Buffer
);
321 if (Ptr
->Logon
.WorkStations
.Buffer
!= NULL
)
322 MIDL_user_free(Ptr
->Logon
.WorkStations
.Buffer
);
324 if (Ptr
->Logon
.LogonHours
.LogonHours
!= NULL
)
325 MIDL_user_free(Ptr
->Logon
.LogonHours
.LogonHours
);
328 case UserLogonHoursInformation
:
329 if (Ptr
->LogonHours
.LogonHours
.LogonHours
!= NULL
)
330 MIDL_user_free(Ptr
->LogonHours
.LogonHours
.LogonHours
);
333 case UserAccountInformation
:
334 if (Ptr
->Account
.UserName
.Buffer
!= NULL
)
335 MIDL_user_free(Ptr
->Account
.UserName
.Buffer
);
337 if (Ptr
->Account
.FullName
.Buffer
!= NULL
)
338 MIDL_user_free(Ptr
->Account
.FullName
.Buffer
);
340 if (Ptr
->Account
.HomeDirectory
.Buffer
!= NULL
)
341 MIDL_user_free(Ptr
->Account
.HomeDirectory
.Buffer
);
343 if (Ptr
->Account
.HomeDirectoryDrive
.Buffer
!= NULL
)
344 MIDL_user_free(Ptr
->Account
.HomeDirectoryDrive
.Buffer
);
346 if (Ptr
->Account
.ScriptPath
.Buffer
!= NULL
)
347 MIDL_user_free(Ptr
->Account
.ScriptPath
.Buffer
);
349 if (Ptr
->Account
.ProfilePath
.Buffer
!= NULL
)
350 MIDL_user_free(Ptr
->Account
.ProfilePath
.Buffer
);
352 if (Ptr
->Account
.AdminComment
.Buffer
!= NULL
)
353 MIDL_user_free(Ptr
->Account
.AdminComment
.Buffer
);
355 if (Ptr
->Account
.WorkStations
.Buffer
!= NULL
)
356 MIDL_user_free(Ptr
->Account
.WorkStations
.Buffer
);
358 if (Ptr
->Account
.LogonHours
.LogonHours
!= NULL
)
359 MIDL_user_free(Ptr
->Account
.LogonHours
.LogonHours
);
362 case UserNameInformation
:
363 if (Ptr
->Name
.UserName
.Buffer
!= NULL
)
364 MIDL_user_free(Ptr
->Name
.UserName
.Buffer
);
366 if (Ptr
->Name
.FullName
.Buffer
!= NULL
)
367 MIDL_user_free(Ptr
->Name
.FullName
.Buffer
);
370 case UserAccountNameInformation
:
371 if (Ptr
->AccountName
.UserName
.Buffer
!= NULL
)
372 MIDL_user_free(Ptr
->AccountName
.UserName
.Buffer
);
375 case UserFullNameInformation
:
376 if (Ptr
->FullName
.FullName
.Buffer
!= NULL
)
377 MIDL_user_free(Ptr
->FullName
.FullName
.Buffer
);
380 case UserPrimaryGroupInformation
:
383 case UserHomeInformation
:
384 if (Ptr
->Home
.HomeDirectory
.Buffer
!= NULL
)
385 MIDL_user_free(Ptr
->Home
.HomeDirectory
.Buffer
);
387 if (Ptr
->Home
.HomeDirectoryDrive
.Buffer
!= NULL
)
388 MIDL_user_free(Ptr
->Home
.HomeDirectoryDrive
.Buffer
);
391 case UserScriptInformation
:
392 if (Ptr
->Script
.ScriptPath
.Buffer
!= NULL
)
393 MIDL_user_free(Ptr
->Script
.ScriptPath
.Buffer
);
395 case UserProfileInformation
:
396 if (Ptr
->Profile
.ProfilePath
.Buffer
!= NULL
)
397 MIDL_user_free(Ptr
->Profile
.ProfilePath
.Buffer
);
399 case UserAdminCommentInformation
:
400 if (Ptr
->AdminComment
.AdminComment
.Buffer
!= NULL
)
401 MIDL_user_free(Ptr
->AdminComment
.AdminComment
.Buffer
);
404 case UserWorkStationsInformation
:
405 if (Ptr
->WorkStations
.WorkStations
.Buffer
!= NULL
)
406 MIDL_user_free(Ptr
->WorkStations
.WorkStations
.Buffer
);
409 case UserSetPasswordInformation
:
410 ERR("Information class UserSetPasswordInformation cannot be queried!\n");
413 case UserControlInformation
:
416 case UserExpiresInformation
:
419 case UserInternal1Information
:
422 case UserInternal2Information
:
425 case UserParametersInformation
:
426 if (Ptr
->Parameters
.Parameters
.Buffer
!= NULL
)
427 MIDL_user_free(Ptr
->Parameters
.Parameters
.Buffer
);
430 case UserAllInformation
:
431 if (Ptr
->All
.UserName
.Buffer
!= NULL
)
432 MIDL_user_free(Ptr
->All
.UserName
.Buffer
);
434 if (Ptr
->All
.FullName
.Buffer
!= NULL
)
435 MIDL_user_free(Ptr
->All
.FullName
.Buffer
);
437 if (Ptr
->All
.HomeDirectory
.Buffer
!= NULL
)
438 MIDL_user_free(Ptr
->All
.HomeDirectory
.Buffer
);
440 if (Ptr
->All
.HomeDirectoryDrive
.Buffer
!= NULL
)
441 MIDL_user_free(Ptr
->All
.HomeDirectoryDrive
.Buffer
);
443 if (Ptr
->All
.ScriptPath
.Buffer
!= NULL
)
444 MIDL_user_free(Ptr
->All
.ScriptPath
.Buffer
);
446 if (Ptr
->All
.ProfilePath
.Buffer
!= NULL
)
447 MIDL_user_free(Ptr
->All
.ProfilePath
.Buffer
);
449 if (Ptr
->All
.AdminComment
.Buffer
!= NULL
)
450 MIDL_user_free(Ptr
->All
.AdminComment
.Buffer
);
452 if (Ptr
->All
.WorkStations
.Buffer
!= NULL
)
453 MIDL_user_free(Ptr
->All
.WorkStations
.Buffer
);
455 if (Ptr
->All
.UserComment
.Buffer
!= NULL
)
456 MIDL_user_free(Ptr
->All
.UserComment
.Buffer
);
458 if (Ptr
->All
.Parameters
.Buffer
!= NULL
)
459 MIDL_user_free(Ptr
->All
.Parameters
.Buffer
);
461 if (Ptr
->All
.LmOwfPassword
.Buffer
!= NULL
)
462 MIDL_user_free(Ptr
->All
.LmOwfPassword
.Buffer
);
464 if (Ptr
->All
.NtOwfPassword
.Buffer
!= NULL
)
465 MIDL_user_free(Ptr
->All
.NtOwfPassword
.Buffer
);
467 if (Ptr
->All
.PrivateData
.Buffer
!= NULL
)
468 MIDL_user_free(Ptr
->All
.PrivateData
.Buffer
);
470 if (Ptr
->All
.SecurityDescriptor
.SecurityDescriptor
!= NULL
)
471 MIDL_user_free(Ptr
->All
.SecurityDescriptor
.SecurityDescriptor
);
473 if (Ptr
->All
.LogonHours
.LogonHours
!= NULL
)
474 MIDL_user_free(Ptr
->All
.LogonHours
.LogonHours
);
478 FIXME("Unsupported information class: %lu\n", InformationClass
);