* Sync up to trunk head (r60691).
[reactos.git] / dll / win32 / netapi32 / user.c
1 /*
2 * Copyright 2002 Andriy Palamarchuk
3 *
4 * netapi32 user functions
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 /*
22 * TODO:
23 * Implement NetUserGetGroups (WIP)
24 * Implement NetUserSetGroups
25 * NetUserGetLocalGroups does not support LG_INCLUDE_INDIRECT yet.
26 * Add missing information levels.
27 * ...
28 */
29
30 #include "netapi32.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(netapi32);
33
34
35 typedef struct _ENUM_CONTEXT
36 {
37 SAM_HANDLE ServerHandle;
38 SAM_HANDLE BuiltinDomainHandle;
39 SAM_HANDLE AccountDomainHandle;
40
41 SAM_ENUMERATE_HANDLE EnumerationContext;
42 PSAM_RID_ENUMERATION Buffer;
43 ULONG Count;
44 ULONG Index;
45 BOOLEAN BuiltinDone;
46
47 } ENUM_CONTEXT, *PENUM_CONTEXT;
48
49
50 static
51 ULONG
52 DeltaTimeToSeconds(LARGE_INTEGER DeltaTime)
53 {
54 LARGE_INTEGER Seconds;
55
56 if (DeltaTime.QuadPart == 0)
57 return 0;
58
59 Seconds.QuadPart = -DeltaTime.QuadPart / 10000000;
60
61 if (Seconds.HighPart != 0)
62 return TIMEQ_FOREVER;
63
64 return Seconds.LowPart;
65 }
66
67
68 static
69 ULONG
70 GetAccountFlags(ULONG AccountControl)
71 {
72 ULONG Flags = UF_SCRIPT;
73
74 if (AccountControl & USER_ACCOUNT_DISABLED)
75 Flags |= UF_ACCOUNTDISABLE;
76
77 if (AccountControl & USER_HOME_DIRECTORY_REQUIRED)
78 Flags |= UF_HOMEDIR_REQUIRED;
79
80 if (AccountControl & USER_PASSWORD_NOT_REQUIRED)
81 Flags |= UF_PASSWD_NOTREQD;
82
83 // UF_PASSWD_CANT_CHANGE
84
85 if (AccountControl & USER_ACCOUNT_AUTO_LOCKED)
86 Flags |= UF_LOCKOUT;
87
88 if (AccountControl & USER_DONT_EXPIRE_PASSWORD)
89 Flags |= UF_DONT_EXPIRE_PASSWD;
90
91 /*
92 if (AccountControl & USER_ENCRYPTED_TEXT_PASSWORD_ALLOWED)
93 Flags |= UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED;
94
95 if (AccountControl & USER_SMARTCARD_REQUIRED)
96 Flags |= UF_SMARTCARD_REQUIRED;
97
98 if (AccountControl & USER_TRUSTED_FOR_DELEGATION)
99 Flags |= UF_TRUSTED_FOR_DELEGATION;
100
101 if (AccountControl & USER_NOT_DELEGATED)
102 Flags |= UF_NOT_DELEGATED;
103
104 if (AccountControl & USER_USE_DES_KEY_ONLY)
105 Flags |= UF_USE_DES_KEY_ONLY;
106
107 if (AccountControl & USER_DONT_REQUIRE_PREAUTH)
108 Flags |= UF_DONT_REQUIRE_PREAUTH;
109
110 if (AccountControl & USER_PASSWORD_EXPIRED)
111 Flags |= UF_PASSWORD_EXPIRED;
112 */
113
114 /* Set account type flags */
115 if (AccountControl & USER_TEMP_DUPLICATE_ACCOUNT)
116 Flags |= UF_TEMP_DUPLICATE_ACCOUNT;
117 else if (AccountControl & USER_NORMAL_ACCOUNT)
118 Flags |= UF_NORMAL_ACCOUNT;
119 else if (AccountControl & USER_INTERDOMAIN_TRUST_ACCOUNT)
120 Flags |= UF_INTERDOMAIN_TRUST_ACCOUNT;
121 else if (AccountControl & USER_WORKSTATION_TRUST_ACCOUNT)
122 Flags |= UF_WORKSTATION_TRUST_ACCOUNT;
123 else if (AccountControl & USER_SERVER_TRUST_ACCOUNT)
124 Flags |= UF_SERVER_TRUST_ACCOUNT;
125
126 return Flags;
127 }
128
129
130 static
131 ULONG
132 GetAccountControl(ULONG Flags)
133 {
134 ULONG AccountControl = 0;
135
136 if (Flags & UF_ACCOUNTDISABLE)
137 AccountControl |= USER_ACCOUNT_DISABLED;
138
139 if (Flags & UF_HOMEDIR_REQUIRED)
140 AccountControl |= USER_HOME_DIRECTORY_REQUIRED;
141
142 if (Flags & UF_PASSWD_NOTREQD)
143 AccountControl |= USER_PASSWORD_NOT_REQUIRED;
144
145 if (Flags & UF_LOCKOUT)
146 AccountControl |= USER_ACCOUNT_AUTO_LOCKED;
147
148 if (Flags & UF_DONT_EXPIRE_PASSWD)
149 AccountControl |= USER_DONT_EXPIRE_PASSWORD;
150
151 /* Set account type flags */
152 if (Flags & UF_TEMP_DUPLICATE_ACCOUNT)
153 AccountControl |= USER_TEMP_DUPLICATE_ACCOUNT;
154 else if (Flags & UF_NORMAL_ACCOUNT)
155 AccountControl |= USER_NORMAL_ACCOUNT;
156 else if (Flags & UF_INTERDOMAIN_TRUST_ACCOUNT)
157 AccountControl |= USER_INTERDOMAIN_TRUST_ACCOUNT;
158 else if (Flags & UF_WORKSTATION_TRUST_ACCOUNT)
159 AccountControl |= USER_WORKSTATION_TRUST_ACCOUNT;
160 else if (Flags & UF_SERVER_TRUST_ACCOUNT)
161 AccountControl |= USER_SERVER_TRUST_ACCOUNT;
162
163 return AccountControl;
164 }
165
166
167 static
168 DWORD
169 GetPasswordAge(IN PLARGE_INTEGER PasswordLastSet)
170 {
171 LARGE_INTEGER SystemTime;
172 ULONG SystemSecondsSince1970;
173 ULONG PasswordSecondsSince1970;
174 NTSTATUS Status;
175
176 Status = NtQuerySystemTime(&SystemTime);
177 if (!NT_SUCCESS(Status))
178 return 0;
179
180 RtlTimeToSecondsSince1970(&SystemTime, &SystemSecondsSince1970);
181 RtlTimeToSecondsSince1970(PasswordLastSet, &PasswordSecondsSince1970);
182
183 return SystemSecondsSince1970 - PasswordSecondsSince1970;
184 }
185
186
187 static
188 NET_API_STATUS
189 BuildUserInfoBuffer(PUSER_ALL_INFORMATION UserInfo,
190 DWORD level,
191 ULONG RelativeId,
192 LPVOID *Buffer)
193 {
194 UNICODE_STRING LogonServer = RTL_CONSTANT_STRING(L"\\\\*");
195 LPVOID LocalBuffer = NULL;
196 PUSER_INFO_0 UserInfo0;
197 PUSER_INFO_1 UserInfo1;
198 PUSER_INFO_2 UserInfo2;
199 PUSER_INFO_3 UserInfo3;
200 PUSER_INFO_4 UserInfo4;
201 PUSER_INFO_10 UserInfo10;
202 PUSER_INFO_11 UserInfo11;
203 PUSER_INFO_20 UserInfo20;
204 PUSER_INFO_23 UserInfo23;
205 LPWSTR Ptr;
206 ULONG Size = 0;
207 NET_API_STATUS ApiStatus = NERR_Success;
208
209 *Buffer = NULL;
210
211 switch (level)
212 {
213 case 0:
214 Size = sizeof(USER_INFO_0) +
215 UserInfo->UserName.Length + sizeof(WCHAR);
216 break;
217
218 case 1:
219 Size = sizeof(USER_INFO_1) +
220 UserInfo->UserName.Length + sizeof(WCHAR);
221
222 if (UserInfo->HomeDirectory.Length > 0)
223 Size += UserInfo->HomeDirectory.Length + sizeof(WCHAR);
224
225 if (UserInfo->AdminComment.Length > 0)
226 Size += UserInfo->AdminComment.Length + sizeof(WCHAR);
227
228 if (UserInfo->ScriptPath.Length > 0)
229 Size += UserInfo->ScriptPath.Length + sizeof(WCHAR);
230 break;
231
232 case 2:
233 Size = sizeof(USER_INFO_2) +
234 UserInfo->UserName.Length + sizeof(WCHAR);
235
236 if (UserInfo->HomeDirectory.Length > 0)
237 Size += UserInfo->HomeDirectory.Length + sizeof(WCHAR);
238
239 if (UserInfo->AdminComment.Length > 0)
240 Size += UserInfo->AdminComment.Length + sizeof(WCHAR);
241
242 if (UserInfo->ScriptPath.Length > 0)
243 Size += UserInfo->ScriptPath.Length + sizeof(WCHAR);
244
245 if (UserInfo->FullName.Length > 0)
246 Size += UserInfo->FullName.Length + sizeof(WCHAR);
247
248 if (UserInfo->UserComment.Length > 0)
249 Size += UserInfo->UserComment.Length + sizeof(WCHAR);
250
251 if (UserInfo->Parameters.Length > 0)
252 Size += UserInfo->Parameters.Length + sizeof(WCHAR);
253
254 if (UserInfo->WorkStations.Length > 0)
255 Size += UserInfo->WorkStations.Length + sizeof(WCHAR);
256
257 if (UserInfo->LogonHours.UnitsPerWeek > 0)
258 Size += (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8;
259
260 if (LogonServer.Length > 0)
261 Size += LogonServer.Length + sizeof(WCHAR);
262 break;
263
264 case 3:
265 Size = sizeof(USER_INFO_3) +
266 UserInfo->UserName.Length + sizeof(WCHAR);
267
268 if (UserInfo->HomeDirectory.Length > 0)
269 Size += UserInfo->HomeDirectory.Length + sizeof(WCHAR);
270
271 if (UserInfo->AdminComment.Length > 0)
272 Size += UserInfo->AdminComment.Length + sizeof(WCHAR);
273
274 if (UserInfo->ScriptPath.Length > 0)
275 Size += UserInfo->ScriptPath.Length + sizeof(WCHAR);
276
277 if (UserInfo->FullName.Length > 0)
278 Size += UserInfo->FullName.Length + sizeof(WCHAR);
279
280 if (UserInfo->UserComment.Length > 0)
281 Size += UserInfo->UserComment.Length + sizeof(WCHAR);
282
283 if (UserInfo->Parameters.Length > 0)
284 Size += UserInfo->Parameters.Length + sizeof(WCHAR);
285
286 if (UserInfo->WorkStations.Length > 0)
287 Size += UserInfo->WorkStations.Length + sizeof(WCHAR);
288
289 if (UserInfo->LogonHours.UnitsPerWeek > 0)
290 Size += (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8;
291
292 if (LogonServer.Length > 0)
293 Size += LogonServer.Length + sizeof(WCHAR);
294
295 if (UserInfo->ProfilePath.Length > 0)
296 Size += UserInfo->ProfilePath.Length + sizeof(WCHAR);
297
298 if (UserInfo->HomeDirectoryDrive.Length > 0)
299 Size += UserInfo->HomeDirectoryDrive.Length + sizeof(WCHAR);
300 break;
301
302 case 4:
303 Size = sizeof(USER_INFO_4) +
304 UserInfo->UserName.Length + sizeof(WCHAR);
305
306 if (UserInfo->HomeDirectory.Length > 0)
307 Size += UserInfo->HomeDirectory.Length + sizeof(WCHAR);
308
309 if (UserInfo->AdminComment.Length > 0)
310 Size += UserInfo->AdminComment.Length + sizeof(WCHAR);
311
312 if (UserInfo->ScriptPath.Length > 0)
313 Size += UserInfo->ScriptPath.Length + sizeof(WCHAR);
314
315 if (UserInfo->FullName.Length > 0)
316 Size += UserInfo->FullName.Length + sizeof(WCHAR);
317
318 if (UserInfo->UserComment.Length > 0)
319 Size += UserInfo->UserComment.Length + sizeof(WCHAR);
320
321 if (UserInfo->Parameters.Length > 0)
322 Size += UserInfo->Parameters.Length + sizeof(WCHAR);
323
324 if (UserInfo->WorkStations.Length > 0)
325 Size += UserInfo->WorkStations.Length + sizeof(WCHAR);
326
327 if (UserInfo->LogonHours.UnitsPerWeek > 0)
328 Size += (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8;
329
330 if (LogonServer.Length > 0)
331 Size += LogonServer.Length + sizeof(WCHAR);
332
333 /* FIXME: usri4_user_sid */
334
335 if (UserInfo->ProfilePath.Length > 0)
336 Size += UserInfo->ProfilePath.Length + sizeof(WCHAR);
337
338 if (UserInfo->HomeDirectoryDrive.Length > 0)
339 Size += UserInfo->HomeDirectoryDrive.Length + sizeof(WCHAR);
340 break;
341
342 case 10:
343 Size = sizeof(USER_INFO_10) +
344 UserInfo->UserName.Length + sizeof(WCHAR);
345
346 if (UserInfo->AdminComment.Length > 0)
347 Size += UserInfo->AdminComment.Length + sizeof(WCHAR);
348
349 if (UserInfo->UserComment.Length > 0)
350 Size += UserInfo->UserComment.Length + sizeof(WCHAR);
351
352 if (UserInfo->FullName.Length > 0)
353 Size += UserInfo->FullName.Length + sizeof(WCHAR);
354 break;
355
356 case 11:
357 Size = sizeof(USER_INFO_11) +
358 UserInfo->UserName.Length + sizeof(WCHAR);
359
360 if (UserInfo->AdminComment.Length > 0)
361 Size += UserInfo->AdminComment.Length + sizeof(WCHAR);
362
363 if (UserInfo->UserComment.Length > 0)
364 Size += UserInfo->UserComment.Length + sizeof(WCHAR);
365
366 if (UserInfo->FullName.Length > 0)
367 Size += UserInfo->FullName.Length + sizeof(WCHAR);
368
369 if (UserInfo->HomeDirectory.Length > 0)
370 Size += UserInfo->HomeDirectory.Length + sizeof(WCHAR);
371
372 if (UserInfo->Parameters.Length > 0)
373 Size += UserInfo->Parameters.Length + sizeof(WCHAR);
374
375 if (LogonServer.Length > 0)
376 Size += LogonServer.Length + sizeof(WCHAR);
377
378 if (UserInfo->WorkStations.Length > 0)
379 Size += UserInfo->WorkStations.Length + sizeof(WCHAR);
380
381 if (UserInfo->LogonHours.UnitsPerWeek > 0)
382 Size += (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8;
383 break;
384
385 case 20:
386 Size = sizeof(USER_INFO_20) +
387 UserInfo->UserName.Length + sizeof(WCHAR);
388
389 if (UserInfo->FullName.Length > 0)
390 Size += UserInfo->FullName.Length + sizeof(WCHAR);
391
392 if (UserInfo->AdminComment.Length > 0)
393 Size += UserInfo->AdminComment.Length + sizeof(WCHAR);
394 break;
395
396 case 23:
397 Size = sizeof(USER_INFO_23) +
398 UserInfo->UserName.Length + sizeof(WCHAR);
399
400 if (UserInfo->FullName.Length > 0)
401 Size += UserInfo->FullName.Length + sizeof(WCHAR);
402
403 if (UserInfo->AdminComment.Length > 0)
404 Size += UserInfo->AdminComment.Length + sizeof(WCHAR);
405
406 /* FIXME: usri23_user_sid */
407 break;
408
409 default:
410 ApiStatus = ERROR_INVALID_LEVEL;
411 goto done;
412 }
413
414 ApiStatus = NetApiBufferAllocate(Size, &LocalBuffer);
415 if (ApiStatus != NERR_Success)
416 goto done;
417
418 ZeroMemory(LocalBuffer, Size);
419
420 switch (level)
421 {
422 case 0:
423 UserInfo0 = (PUSER_INFO_0)LocalBuffer;
424
425 Ptr = (LPWSTR)((ULONG_PTR)UserInfo0 + sizeof(USER_INFO_0));
426 UserInfo0->usri0_name = Ptr;
427
428 memcpy(UserInfo0->usri0_name,
429 UserInfo->UserName.Buffer,
430 UserInfo->UserName.Length);
431 UserInfo0->usri0_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
432 break;
433
434 case 1:
435 UserInfo1 = (PUSER_INFO_1)LocalBuffer;
436
437 Ptr = (LPWSTR)((ULONG_PTR)UserInfo1 + sizeof(USER_INFO_1));
438
439 UserInfo1->usri1_name = Ptr;
440
441 memcpy(UserInfo1->usri1_name,
442 UserInfo->UserName.Buffer,
443 UserInfo->UserName.Length);
444 UserInfo1->usri1_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
445
446 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserName.Length + sizeof(WCHAR));
447
448 UserInfo1->usri1_password = NULL;
449
450 UserInfo1->usri1_password_age = GetPasswordAge(&UserInfo->PasswordLastSet);
451
452 /* FIXME: UserInfo1->usri1_priv */
453
454 if (UserInfo->HomeDirectory.Length > 0)
455 {
456 UserInfo1->usri1_home_dir = Ptr;
457
458 memcpy(UserInfo1->usri1_home_dir,
459 UserInfo->HomeDirectory.Buffer,
460 UserInfo->HomeDirectory.Length);
461 UserInfo1->usri1_home_dir[UserInfo->HomeDirectory.Length / sizeof(WCHAR)] = UNICODE_NULL;
462
463 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->HomeDirectory.Length + sizeof(WCHAR));
464 }
465
466 if (UserInfo->AdminComment.Length > 0)
467 {
468 UserInfo1->usri1_comment = Ptr;
469
470 memcpy(UserInfo1->usri1_comment,
471 UserInfo->AdminComment.Buffer,
472 UserInfo->AdminComment.Length);
473 UserInfo1->usri1_comment[UserInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
474
475 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->AdminComment.Length + sizeof(WCHAR));
476 }
477
478 UserInfo1->usri1_flags = GetAccountFlags(UserInfo->UserAccountControl);
479
480 if (UserInfo->ScriptPath.Length > 0)
481 {
482 UserInfo1->usri1_script_path = Ptr;
483
484 memcpy(UserInfo1->usri1_script_path,
485 UserInfo->ScriptPath.Buffer,
486 UserInfo->ScriptPath.Length);
487 UserInfo1->usri1_script_path[UserInfo->ScriptPath.Length / sizeof(WCHAR)] = UNICODE_NULL;
488 }
489 break;
490
491 case 2:
492 UserInfo2 = (PUSER_INFO_2)LocalBuffer;
493
494 Ptr = (LPWSTR)((ULONG_PTR)UserInfo2 + sizeof(USER_INFO_2));
495
496 UserInfo2->usri2_name = Ptr;
497
498 memcpy(UserInfo2->usri2_name,
499 UserInfo->UserName.Buffer,
500 UserInfo->UserName.Length);
501 UserInfo2->usri2_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
502
503 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserName.Length + sizeof(WCHAR));
504
505 UserInfo2->usri2_password_age = GetPasswordAge(&UserInfo->PasswordLastSet);
506
507 /* FIXME: usri2_priv */
508
509 if (UserInfo->HomeDirectory.Length > 0)
510 {
511 UserInfo2->usri2_home_dir = Ptr;
512
513 memcpy(UserInfo2->usri2_home_dir,
514 UserInfo->HomeDirectory.Buffer,
515 UserInfo->HomeDirectory.Length);
516 UserInfo2->usri2_home_dir[UserInfo->HomeDirectory.Length / sizeof(WCHAR)] = UNICODE_NULL;
517
518 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->HomeDirectory.Length + sizeof(WCHAR));
519 }
520
521 if (UserInfo->AdminComment.Length > 0)
522 {
523 UserInfo2->usri2_comment = Ptr;
524
525 memcpy(UserInfo2->usri2_comment,
526 UserInfo->AdminComment.Buffer,
527 UserInfo->AdminComment.Length);
528 UserInfo2->usri2_comment[UserInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
529
530 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->AdminComment.Length + sizeof(WCHAR));
531 }
532
533 UserInfo2->usri2_flags = GetAccountFlags(UserInfo->UserAccountControl);
534
535 if (UserInfo->ScriptPath.Length > 0)
536 {
537 UserInfo2->usri2_script_path = Ptr;
538
539 memcpy(UserInfo2->usri2_script_path,
540 UserInfo->ScriptPath.Buffer,
541 UserInfo->ScriptPath.Length);
542 UserInfo2->usri2_script_path[UserInfo->ScriptPath.Length / sizeof(WCHAR)] = UNICODE_NULL;
543
544 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->ScriptPath.Length + sizeof(WCHAR));
545 }
546
547 /* FIXME: usri2_auth_flags */
548
549 if (UserInfo->FullName.Length > 0)
550 {
551 UserInfo2->usri2_full_name = Ptr;
552
553 memcpy(UserInfo2->usri2_full_name,
554 UserInfo->FullName.Buffer,
555 UserInfo->FullName.Length);
556 UserInfo2->usri2_full_name[UserInfo->FullName.Length / sizeof(WCHAR)] = UNICODE_NULL;
557
558 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->FullName.Length + sizeof(WCHAR));
559 }
560
561 if (UserInfo->UserComment.Length > 0)
562 {
563 UserInfo2->usri2_usr_comment = Ptr;
564
565 memcpy(UserInfo2->usri2_usr_comment,
566 UserInfo->UserComment.Buffer,
567 UserInfo->UserComment.Length);
568 UserInfo2->usri2_usr_comment[UserInfo->UserComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
569
570 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserComment.Length + sizeof(WCHAR));
571 }
572
573 if (UserInfo->Parameters.Length > 0)
574 {
575 UserInfo2->usri2_parms = Ptr;
576
577 memcpy(UserInfo2->usri2_parms,
578 UserInfo->Parameters.Buffer,
579 UserInfo->Parameters.Length);
580 UserInfo2->usri2_parms[UserInfo->Parameters.Length / sizeof(WCHAR)] = UNICODE_NULL;
581
582 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->Parameters.Length + sizeof(WCHAR));
583 }
584
585 if (UserInfo->WorkStations.Length > 0)
586 {
587 UserInfo2->usri2_workstations = Ptr;
588
589 memcpy(UserInfo2->usri2_workstations,
590 UserInfo->WorkStations.Buffer,
591 UserInfo->WorkStations.Length);
592 UserInfo2->usri2_workstations[UserInfo->WorkStations.Length / sizeof(WCHAR)] = UNICODE_NULL;
593
594 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->WorkStations.Length + sizeof(WCHAR));
595 }
596
597 RtlTimeToSecondsSince1970(&UserInfo->LastLogon,
598 &UserInfo2->usri2_last_logon);
599
600 RtlTimeToSecondsSince1970(&UserInfo->LastLogoff,
601 &UserInfo2->usri2_last_logoff);
602
603 RtlTimeToSecondsSince1970(&UserInfo->AccountExpires,
604 &UserInfo2->usri2_acct_expires);
605
606 UserInfo2->usri2_max_storage = USER_MAXSTORAGE_UNLIMITED;
607 UserInfo2->usri2_units_per_week = UserInfo->LogonHours.UnitsPerWeek;
608
609 if (UserInfo->LogonHours.UnitsPerWeek > 0)
610 {
611 UserInfo2->usri2_logon_hours = (PVOID)Ptr;
612
613 memcpy(UserInfo2->usri2_logon_hours,
614 UserInfo->LogonHours.LogonHours,
615 (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8);
616
617 Ptr = (LPWSTR)((ULONG_PTR)Ptr + (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8);
618 }
619
620 UserInfo2->usri2_bad_pw_count = UserInfo->BadPasswordCount;
621 UserInfo2->usri2_num_logons = UserInfo->LogonCount;
622
623 if (LogonServer.Length > 0)
624 {
625 UserInfo2->usri2_logon_server = Ptr;
626
627 memcpy(UserInfo2->usri2_logon_server,
628 LogonServer.Buffer,
629 LogonServer.Length);
630 UserInfo2->usri2_logon_server[LogonServer.Length / sizeof(WCHAR)] = UNICODE_NULL;
631
632 Ptr = (LPWSTR)((ULONG_PTR)Ptr + LogonServer.Length + sizeof(WCHAR));
633 }
634
635 UserInfo2->usri2_country_code = UserInfo->CountryCode;
636 UserInfo2->usri2_code_page = UserInfo->CodePage;
637 break;
638
639 case 3:
640 UserInfo3 = (PUSER_INFO_3)LocalBuffer;
641
642 Ptr = (LPWSTR)((ULONG_PTR)UserInfo3 + sizeof(USER_INFO_3));
643
644 UserInfo3->usri3_name = Ptr;
645
646 memcpy(UserInfo3->usri3_name,
647 UserInfo->UserName.Buffer,
648 UserInfo->UserName.Length);
649 UserInfo3->usri3_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
650
651 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserName.Length + sizeof(WCHAR));
652
653 UserInfo3->usri3_password_age = GetPasswordAge(&UserInfo->PasswordLastSet);
654
655 /* FIXME: usri3_priv */
656
657 if (UserInfo->HomeDirectory.Length > 0)
658 {
659 UserInfo3->usri3_home_dir = Ptr;
660
661 memcpy(UserInfo3->usri3_home_dir,
662 UserInfo->HomeDirectory.Buffer,
663 UserInfo->HomeDirectory.Length);
664 UserInfo3->usri3_home_dir[UserInfo->HomeDirectory.Length / sizeof(WCHAR)] = UNICODE_NULL;
665
666 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->HomeDirectory.Length + sizeof(WCHAR));
667 }
668
669 if (UserInfo->AdminComment.Length > 0)
670 {
671 UserInfo3->usri3_comment = Ptr;
672
673 memcpy(UserInfo3->usri3_comment,
674 UserInfo->AdminComment.Buffer,
675 UserInfo->AdminComment.Length);
676 UserInfo3->usri3_comment[UserInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
677
678 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->AdminComment.Length + sizeof(WCHAR));
679 }
680
681 UserInfo3->usri3_flags = GetAccountFlags(UserInfo->UserAccountControl);
682
683 if (UserInfo->ScriptPath.Length > 0)
684 {
685 UserInfo3->usri3_script_path = Ptr;
686
687 memcpy(UserInfo3->usri3_script_path,
688 UserInfo->ScriptPath.Buffer,
689 UserInfo->ScriptPath.Length);
690 UserInfo3->usri3_script_path[UserInfo->ScriptPath.Length / sizeof(WCHAR)] = UNICODE_NULL;
691
692 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->ScriptPath.Length + sizeof(WCHAR));
693 }
694
695 /* FIXME: usri3_auth_flags */
696
697 if (UserInfo->FullName.Length > 0)
698 {
699 UserInfo3->usri3_full_name = Ptr;
700
701 memcpy(UserInfo3->usri3_full_name,
702 UserInfo->FullName.Buffer,
703 UserInfo->FullName.Length);
704 UserInfo3->usri3_full_name[UserInfo->FullName.Length / sizeof(WCHAR)] = UNICODE_NULL;
705
706 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->FullName.Length + sizeof(WCHAR));
707 }
708
709 if (UserInfo->UserComment.Length > 0)
710 {
711 UserInfo3->usri3_usr_comment = Ptr;
712
713 memcpy(UserInfo3->usri3_usr_comment,
714 UserInfo->UserComment.Buffer,
715 UserInfo->UserComment.Length);
716 UserInfo3->usri3_usr_comment[UserInfo->UserComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
717
718 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserComment.Length + sizeof(WCHAR));
719 }
720
721 if (UserInfo->Parameters.Length > 0)
722 {
723 UserInfo3->usri3_parms = Ptr;
724
725 memcpy(UserInfo3->usri3_parms,
726 UserInfo->Parameters.Buffer,
727 UserInfo->Parameters.Length);
728 UserInfo3->usri3_parms[UserInfo->Parameters.Length / sizeof(WCHAR)] = UNICODE_NULL;
729
730 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->Parameters.Length + sizeof(WCHAR));
731 }
732
733 if (UserInfo->WorkStations.Length > 0)
734 {
735 UserInfo3->usri3_workstations = Ptr;
736
737 memcpy(UserInfo3->usri3_workstations,
738 UserInfo->WorkStations.Buffer,
739 UserInfo->WorkStations.Length);
740 UserInfo3->usri3_workstations[UserInfo->WorkStations.Length / sizeof(WCHAR)] = UNICODE_NULL;
741
742 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->WorkStations.Length + sizeof(WCHAR));
743 }
744
745 RtlTimeToSecondsSince1970(&UserInfo->LastLogon,
746 &UserInfo3->usri3_last_logon);
747
748 RtlTimeToSecondsSince1970(&UserInfo->LastLogoff,
749 &UserInfo3->usri3_last_logoff);
750
751 RtlTimeToSecondsSince1970(&UserInfo->AccountExpires,
752 &UserInfo3->usri3_acct_expires);
753
754 UserInfo3->usri3_max_storage = USER_MAXSTORAGE_UNLIMITED;
755 UserInfo3->usri3_units_per_week = UserInfo->LogonHours.UnitsPerWeek;
756
757 if (UserInfo->LogonHours.UnitsPerWeek > 0)
758 {
759 UserInfo3->usri3_logon_hours = (PVOID)Ptr;
760
761 memcpy(UserInfo3->usri3_logon_hours,
762 UserInfo->LogonHours.LogonHours,
763 (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8);
764
765 Ptr = (LPWSTR)((ULONG_PTR)Ptr + (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8);
766 }
767
768 UserInfo3->usri3_bad_pw_count = UserInfo->BadPasswordCount;
769 UserInfo3->usri3_num_logons = UserInfo->LogonCount;
770
771 if (LogonServer.Length > 0)
772 {
773 UserInfo3->usri3_logon_server = Ptr;
774
775 memcpy(UserInfo3->usri3_logon_server,
776 LogonServer.Buffer,
777 LogonServer.Length);
778 UserInfo3->usri3_logon_server[LogonServer.Length / sizeof(WCHAR)] = UNICODE_NULL;
779
780 Ptr = (LPWSTR)((ULONG_PTR)Ptr + LogonServer.Length + sizeof(WCHAR));
781 }
782
783 UserInfo3->usri3_country_code = UserInfo->CountryCode;
784 UserInfo3->usri3_code_page = UserInfo->CodePage;
785 UserInfo3->usri3_user_id = RelativeId;
786 UserInfo3->usri3_primary_group_id = UserInfo->PrimaryGroupId;
787
788 if (UserInfo->ProfilePath.Length > 0)
789 {
790 UserInfo3->usri3_profile = Ptr;
791
792 memcpy(UserInfo3->usri3_profile,
793 UserInfo->ProfilePath.Buffer,
794 UserInfo->ProfilePath.Length);
795 UserInfo3->usri3_profile[UserInfo->ProfilePath.Length / sizeof(WCHAR)] = UNICODE_NULL;
796
797 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->ProfilePath.Length + sizeof(WCHAR));
798 }
799
800 if (UserInfo->HomeDirectoryDrive.Length > 0)
801 {
802 UserInfo3->usri3_home_dir_drive = Ptr;
803
804 memcpy(UserInfo3->usri3_home_dir_drive,
805 UserInfo->HomeDirectoryDrive.Buffer,
806 UserInfo->HomeDirectoryDrive.Length);
807 UserInfo3->usri3_home_dir_drive[UserInfo->HomeDirectoryDrive.Length / sizeof(WCHAR)] = UNICODE_NULL;
808
809 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->HomeDirectoryDrive.Length + sizeof(WCHAR));
810 }
811
812 UserInfo3->usri3_password_expired = (UserInfo->UserAccountControl & USER_PASSWORD_EXPIRED);
813 break;
814
815 case 4:
816 UserInfo4 = (PUSER_INFO_4)LocalBuffer;
817
818 Ptr = (LPWSTR)((ULONG_PTR)UserInfo4 + sizeof(USER_INFO_4));
819
820 UserInfo4->usri4_name = Ptr;
821
822 memcpy(UserInfo4->usri4_name,
823 UserInfo->UserName.Buffer,
824 UserInfo->UserName.Length);
825 UserInfo4->usri4_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
826
827 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserName.Length + sizeof(WCHAR));
828
829 UserInfo4->usri4_password = NULL;
830 UserInfo4->usri4_password_age = GetPasswordAge(&UserInfo->PasswordLastSet);
831
832 /* FIXME: usri4_priv */
833
834 if (UserInfo->HomeDirectory.Length > 0)
835 {
836 UserInfo4->usri4_home_dir = Ptr;
837
838 memcpy(UserInfo4->usri4_home_dir,
839 UserInfo->HomeDirectory.Buffer,
840 UserInfo->HomeDirectory.Length);
841 UserInfo4->usri4_home_dir[UserInfo->HomeDirectory.Length / sizeof(WCHAR)] = UNICODE_NULL;
842
843 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->HomeDirectory.Length + sizeof(WCHAR));
844 }
845
846 if (UserInfo->AdminComment.Length > 0)
847 {
848 UserInfo4->usri4_comment = Ptr;
849
850 memcpy(UserInfo4->usri4_comment,
851 UserInfo->AdminComment.Buffer,
852 UserInfo->AdminComment.Length);
853 UserInfo4->usri4_comment[UserInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
854
855 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->AdminComment.Length + sizeof(WCHAR));
856 }
857
858 UserInfo4->usri4_flags = GetAccountFlags(UserInfo->UserAccountControl);
859
860 if (UserInfo->ScriptPath.Length > 0)
861 {
862 UserInfo4->usri4_script_path = Ptr;
863
864 memcpy(UserInfo4->usri4_script_path,
865 UserInfo->ScriptPath.Buffer,
866 UserInfo->ScriptPath.Length);
867 UserInfo4->usri4_script_path[UserInfo->ScriptPath.Length / sizeof(WCHAR)] = UNICODE_NULL;
868
869 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->ScriptPath.Length + sizeof(WCHAR));
870 }
871
872 /* FIXME: usri4_auth_flags */
873
874 if (UserInfo->FullName.Length > 0)
875 {
876 UserInfo4->usri4_full_name = Ptr;
877
878 memcpy(UserInfo4->usri4_full_name,
879 UserInfo->FullName.Buffer,
880 UserInfo->FullName.Length);
881 UserInfo4->usri4_full_name[UserInfo->FullName.Length / sizeof(WCHAR)] = UNICODE_NULL;
882
883 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->FullName.Length + sizeof(WCHAR));
884 }
885
886 if (UserInfo->UserComment.Length > 0)
887 {
888 UserInfo4->usri4_usr_comment = Ptr;
889
890 memcpy(UserInfo4->usri4_usr_comment,
891 UserInfo->UserComment.Buffer,
892 UserInfo->UserComment.Length);
893 UserInfo4->usri4_usr_comment[UserInfo->UserComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
894
895 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserComment.Length + sizeof(WCHAR));
896 }
897
898 if (UserInfo->Parameters.Length > 0)
899 {
900 UserInfo4->usri4_parms = Ptr;
901
902 memcpy(UserInfo4->usri4_parms,
903 UserInfo->Parameters.Buffer,
904 UserInfo->Parameters.Length);
905 UserInfo4->usri4_parms[UserInfo->Parameters.Length / sizeof(WCHAR)] = UNICODE_NULL;
906
907 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->Parameters.Length + sizeof(WCHAR));
908 }
909
910 if (UserInfo->WorkStations.Length > 0)
911 {
912 UserInfo4->usri4_workstations = Ptr;
913
914 memcpy(UserInfo4->usri4_workstations,
915 UserInfo->WorkStations.Buffer,
916 UserInfo->WorkStations.Length);
917 UserInfo4->usri4_workstations[UserInfo->WorkStations.Length / sizeof(WCHAR)] = UNICODE_NULL;
918
919 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->WorkStations.Length + sizeof(WCHAR));
920 }
921
922 RtlTimeToSecondsSince1970(&UserInfo->LastLogon,
923 &UserInfo4->usri4_last_logon);
924
925 RtlTimeToSecondsSince1970(&UserInfo->LastLogoff,
926 &UserInfo4->usri4_last_logoff);
927
928 RtlTimeToSecondsSince1970(&UserInfo->AccountExpires,
929 &UserInfo4->usri4_acct_expires);
930
931 UserInfo4->usri4_max_storage = USER_MAXSTORAGE_UNLIMITED;
932 UserInfo4->usri4_units_per_week = UserInfo->LogonHours.UnitsPerWeek;
933
934 if (UserInfo->LogonHours.UnitsPerWeek > 0)
935 {
936 UserInfo4->usri4_logon_hours = (PVOID)Ptr;
937
938 memcpy(UserInfo4->usri4_logon_hours,
939 UserInfo->LogonHours.LogonHours,
940 (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8);
941
942 Ptr = (LPWSTR)((ULONG_PTR)Ptr + (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8);
943 }
944
945 UserInfo4->usri4_bad_pw_count = UserInfo->BadPasswordCount;
946 UserInfo4->usri4_num_logons = UserInfo->LogonCount;
947
948 if (LogonServer.Length > 0)
949 {
950 UserInfo4->usri4_logon_server = Ptr;
951
952 memcpy(UserInfo4->usri4_logon_server,
953 LogonServer.Buffer,
954 LogonServer.Length);
955 UserInfo4->usri4_logon_server[LogonServer.Length / sizeof(WCHAR)] = UNICODE_NULL;
956
957 Ptr = (LPWSTR)((ULONG_PTR)Ptr + LogonServer.Length + sizeof(WCHAR));
958 }
959
960 UserInfo4->usri4_country_code = UserInfo->CountryCode;
961 UserInfo4->usri4_code_page = UserInfo->CodePage;
962
963 /* FIXME: usri4_user_sid */
964
965 UserInfo4->usri4_primary_group_id = UserInfo->PrimaryGroupId;
966
967 if (UserInfo->ProfilePath.Length > 0)
968 {
969 UserInfo4->usri4_profile = Ptr;
970
971 memcpy(UserInfo4->usri4_profile,
972 UserInfo->ProfilePath.Buffer,
973 UserInfo->ProfilePath.Length);
974 UserInfo4->usri4_profile[UserInfo->ProfilePath.Length / sizeof(WCHAR)] = UNICODE_NULL;
975
976 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->ProfilePath.Length + sizeof(WCHAR));
977 }
978
979 if (UserInfo->HomeDirectoryDrive.Length > 0)
980 {
981 UserInfo4->usri4_home_dir_drive = Ptr;
982
983 memcpy(UserInfo4->usri4_home_dir_drive,
984 UserInfo->HomeDirectoryDrive.Buffer,
985 UserInfo->HomeDirectoryDrive.Length);
986 UserInfo4->usri4_home_dir_drive[UserInfo->HomeDirectoryDrive.Length / sizeof(WCHAR)] = UNICODE_NULL;
987
988 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->HomeDirectoryDrive.Length + sizeof(WCHAR));
989 }
990
991 UserInfo4->usri4_password_expired = (UserInfo->UserAccountControl & USER_PASSWORD_EXPIRED);
992 break;
993
994 case 10:
995 UserInfo10 = (PUSER_INFO_10)LocalBuffer;
996
997 Ptr = (LPWSTR)((ULONG_PTR)UserInfo10 + sizeof(USER_INFO_10));
998
999 UserInfo10->usri10_name = Ptr;
1000
1001 memcpy(UserInfo10->usri10_name,
1002 UserInfo->UserName.Buffer,
1003 UserInfo->UserName.Length);
1004 UserInfo10->usri10_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
1005
1006 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserName.Length + sizeof(WCHAR));
1007
1008 if (UserInfo->AdminComment.Length > 0)
1009 {
1010 UserInfo10->usri10_comment = Ptr;
1011
1012 memcpy(UserInfo10->usri10_comment,
1013 UserInfo->AdminComment.Buffer,
1014 UserInfo->AdminComment.Length);
1015 UserInfo10->usri10_comment[UserInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
1016
1017 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->AdminComment.Length + sizeof(WCHAR));
1018 }
1019
1020 if (UserInfo->UserComment.Length > 0)
1021 {
1022 UserInfo10->usri10_usr_comment = Ptr;
1023
1024 memcpy(UserInfo10->usri10_usr_comment,
1025 UserInfo->UserComment.Buffer,
1026 UserInfo->UserComment.Length);
1027 UserInfo10->usri10_usr_comment[UserInfo->UserComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
1028
1029 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserComment.Length + sizeof(WCHAR));
1030 }
1031
1032 if (UserInfo->FullName.Length > 0)
1033 {
1034 UserInfo10->usri10_full_name = Ptr;
1035
1036 memcpy(UserInfo10->usri10_full_name,
1037 UserInfo->FullName.Buffer,
1038 UserInfo->FullName.Length);
1039 UserInfo10->usri10_full_name[UserInfo->FullName.Length / sizeof(WCHAR)] = UNICODE_NULL;
1040
1041 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->FullName.Length + sizeof(WCHAR));
1042 }
1043 break;
1044
1045 case 11:
1046 UserInfo11 = (PUSER_INFO_11)LocalBuffer;
1047
1048 Ptr = (LPWSTR)((ULONG_PTR)UserInfo11 + sizeof(USER_INFO_11));
1049
1050 UserInfo11->usri11_name = Ptr;
1051
1052 memcpy(UserInfo11->usri11_name,
1053 UserInfo->UserName.Buffer,
1054 UserInfo->UserName.Length);
1055 UserInfo11->usri11_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
1056
1057 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserName.Length + sizeof(WCHAR));
1058
1059 if (UserInfo->AdminComment.Length > 0)
1060 {
1061 UserInfo11->usri11_comment = Ptr;
1062
1063 memcpy(UserInfo11->usri11_comment,
1064 UserInfo->AdminComment.Buffer,
1065 UserInfo->AdminComment.Length);
1066 UserInfo11->usri11_comment[UserInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
1067
1068 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->AdminComment.Length + sizeof(WCHAR));
1069 }
1070
1071 if (UserInfo->UserComment.Length > 0)
1072 {
1073 UserInfo11->usri11_usr_comment = Ptr;
1074
1075 memcpy(UserInfo11->usri11_usr_comment,
1076 UserInfo->UserComment.Buffer,
1077 UserInfo->UserComment.Length);
1078 UserInfo11->usri11_usr_comment[UserInfo->UserComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
1079
1080 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserComment.Length + sizeof(WCHAR));
1081 }
1082
1083 if (UserInfo->FullName.Length > 0)
1084 {
1085 UserInfo11->usri11_full_name = Ptr;
1086
1087 memcpy(UserInfo11->usri11_full_name,
1088 UserInfo->FullName.Buffer,
1089 UserInfo->FullName.Length);
1090 UserInfo11->usri11_full_name[UserInfo->FullName.Length / sizeof(WCHAR)] = UNICODE_NULL;
1091
1092 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->FullName.Length + sizeof(WCHAR));
1093 }
1094
1095 /* FIXME: usri11_priv */
1096 /* FIXME: usri11_auth_flags */
1097
1098 UserInfo11->usri11_password_age = GetPasswordAge(&UserInfo->PasswordLastSet);
1099
1100 if (UserInfo->HomeDirectory.Length > 0)
1101 {
1102 UserInfo11->usri11_home_dir = Ptr;
1103
1104 memcpy(UserInfo11->usri11_home_dir,
1105 UserInfo->HomeDirectory.Buffer,
1106 UserInfo->HomeDirectory.Length);
1107 UserInfo11->usri11_home_dir[UserInfo->HomeDirectory.Length / sizeof(WCHAR)] = UNICODE_NULL;
1108
1109 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->HomeDirectory.Length + sizeof(WCHAR));
1110 }
1111
1112 if (UserInfo->Parameters.Length > 0)
1113 {
1114 UserInfo11->usri11_parms = Ptr;
1115
1116 memcpy(UserInfo11->usri11_parms,
1117 UserInfo->Parameters.Buffer,
1118 UserInfo->Parameters.Length);
1119 UserInfo11->usri11_parms[UserInfo->Parameters.Length / sizeof(WCHAR)] = UNICODE_NULL;
1120
1121 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->Parameters.Length + sizeof(WCHAR));
1122 }
1123
1124 RtlTimeToSecondsSince1970(&UserInfo->LastLogon,
1125 &UserInfo11->usri11_last_logon);
1126
1127 RtlTimeToSecondsSince1970(&UserInfo->LastLogoff,
1128 &UserInfo11->usri11_last_logoff);
1129
1130 UserInfo11->usri11_bad_pw_count = UserInfo->BadPasswordCount;
1131 UserInfo11->usri11_num_logons = UserInfo->LogonCount;
1132
1133 if (LogonServer.Length > 0)
1134 {
1135 UserInfo11->usri11_logon_server = Ptr;
1136
1137 memcpy(UserInfo11->usri11_logon_server,
1138 LogonServer.Buffer,
1139 LogonServer.Length);
1140 UserInfo11->usri11_logon_server[LogonServer.Length / sizeof(WCHAR)] = UNICODE_NULL;
1141
1142 Ptr = (LPWSTR)((ULONG_PTR)Ptr + LogonServer.Length + sizeof(WCHAR));
1143 }
1144
1145 UserInfo11->usri11_country_code = UserInfo->CountryCode;
1146
1147 if (UserInfo->WorkStations.Length > 0)
1148 {
1149 UserInfo11->usri11_workstations = Ptr;
1150
1151 memcpy(UserInfo11->usri11_workstations,
1152 UserInfo->WorkStations.Buffer,
1153 UserInfo->WorkStations.Length);
1154 UserInfo11->usri11_workstations[UserInfo->WorkStations.Length / sizeof(WCHAR)] = UNICODE_NULL;
1155
1156 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->WorkStations.Length + sizeof(WCHAR));
1157 }
1158
1159 UserInfo11->usri11_max_storage = USER_MAXSTORAGE_UNLIMITED;
1160 UserInfo11->usri11_units_per_week = UserInfo->LogonHours.UnitsPerWeek;
1161
1162 if (UserInfo->LogonHours.UnitsPerWeek > 0)
1163 {
1164 UserInfo11->usri11_logon_hours = (PVOID)Ptr;
1165
1166 memcpy(UserInfo11->usri11_logon_hours,
1167 UserInfo->LogonHours.LogonHours,
1168 (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8);
1169
1170 Ptr = (LPWSTR)((ULONG_PTR)Ptr + (((ULONG)UserInfo->LogonHours.UnitsPerWeek) + 7) / 8);
1171 }
1172
1173 UserInfo11->usri11_code_page = UserInfo->CodePage;
1174 break;
1175
1176 case 20:
1177 UserInfo20 = (PUSER_INFO_20)LocalBuffer;
1178
1179 Ptr = (LPWSTR)((ULONG_PTR)UserInfo20 + sizeof(USER_INFO_20));
1180
1181 UserInfo20->usri20_name = Ptr;
1182
1183 memcpy(UserInfo20->usri20_name,
1184 UserInfo->UserName.Buffer,
1185 UserInfo->UserName.Length);
1186 UserInfo20->usri20_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
1187
1188 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserName.Length + sizeof(WCHAR));
1189
1190 if (UserInfo->FullName.Length > 0)
1191 {
1192 UserInfo20->usri20_full_name = Ptr;
1193
1194 memcpy(UserInfo20->usri20_full_name,
1195 UserInfo->FullName.Buffer,
1196 UserInfo->FullName.Length);
1197 UserInfo20->usri20_full_name[UserInfo->FullName.Length / sizeof(WCHAR)] = UNICODE_NULL;
1198
1199 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->FullName.Length + sizeof(WCHAR));
1200 }
1201
1202 if (UserInfo->AdminComment.Length > 0)
1203 {
1204 UserInfo20->usri20_comment = Ptr;
1205
1206 memcpy(UserInfo20->usri20_comment,
1207 UserInfo->AdminComment.Buffer,
1208 UserInfo->AdminComment.Length);
1209 UserInfo20->usri20_comment[UserInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
1210
1211 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->AdminComment.Length + sizeof(WCHAR));
1212 }
1213
1214 UserInfo20->usri20_flags = GetAccountFlags(UserInfo->UserAccountControl);
1215
1216 UserInfo20->usri20_user_id = RelativeId;
1217 break;
1218
1219 case 23:
1220 UserInfo23 = (PUSER_INFO_23)LocalBuffer;
1221
1222 Ptr = (LPWSTR)((ULONG_PTR)UserInfo23 + sizeof(USER_INFO_23));
1223
1224 UserInfo23->usri23_name = Ptr;
1225
1226 memcpy(UserInfo23->usri23_name,
1227 UserInfo->UserName.Buffer,
1228 UserInfo->UserName.Length);
1229 UserInfo23->usri23_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
1230
1231 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserName.Length + sizeof(WCHAR));
1232
1233 if (UserInfo->FullName.Length > 0)
1234 {
1235 UserInfo23->usri23_full_name = Ptr;
1236
1237 memcpy(UserInfo23->usri23_full_name,
1238 UserInfo->FullName.Buffer,
1239 UserInfo->FullName.Length);
1240 UserInfo23->usri23_full_name[UserInfo->FullName.Length / sizeof(WCHAR)] = UNICODE_NULL;
1241
1242 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->FullName.Length + sizeof(WCHAR));
1243 }
1244
1245 if (UserInfo->AdminComment.Length > 0)
1246 {
1247 UserInfo23->usri23_comment = Ptr;
1248
1249 memcpy(UserInfo23->usri23_comment,
1250 UserInfo->AdminComment.Buffer,
1251 UserInfo->AdminComment.Length);
1252 UserInfo23->usri23_comment[UserInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
1253
1254 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->AdminComment.Length + sizeof(WCHAR));
1255 }
1256
1257 UserInfo23->usri23_flags = GetAccountFlags(UserInfo->UserAccountControl);
1258
1259 /* FIXME: usri23_user_sid */
1260 break;
1261 }
1262
1263 done:
1264 if (ApiStatus == NERR_Success)
1265 {
1266 *Buffer = LocalBuffer;
1267 }
1268 else
1269 {
1270 if (LocalBuffer != NULL)
1271 NetApiBufferFree(LocalBuffer);
1272 }
1273
1274 return ApiStatus;
1275 }
1276
1277
1278 static
1279 VOID
1280 FreeUserInfo(PUSER_ALL_INFORMATION UserInfo)
1281 {
1282 if (UserInfo->UserName.Buffer != NULL)
1283 SamFreeMemory(UserInfo->UserName.Buffer);
1284
1285 if (UserInfo->FullName.Buffer != NULL)
1286 SamFreeMemory(UserInfo->FullName.Buffer);
1287
1288 if (UserInfo->HomeDirectory.Buffer != NULL)
1289 SamFreeMemory(UserInfo->HomeDirectory.Buffer);
1290
1291 if (UserInfo->HomeDirectoryDrive.Buffer != NULL)
1292 SamFreeMemory(UserInfo->HomeDirectoryDrive.Buffer);
1293
1294 if (UserInfo->ScriptPath.Buffer != NULL)
1295 SamFreeMemory(UserInfo->ScriptPath.Buffer);
1296
1297 if (UserInfo->ProfilePath.Buffer != NULL)
1298 SamFreeMemory(UserInfo->ProfilePath.Buffer);
1299
1300 if (UserInfo->AdminComment.Buffer != NULL)
1301 SamFreeMemory(UserInfo->AdminComment.Buffer);
1302
1303 if (UserInfo->WorkStations.Buffer != NULL)
1304 SamFreeMemory(UserInfo->WorkStations.Buffer);
1305
1306 if (UserInfo->UserComment.Buffer != NULL)
1307 SamFreeMemory(UserInfo->UserComment.Buffer);
1308
1309 if (UserInfo->Parameters.Buffer != NULL)
1310 SamFreeMemory(UserInfo->Parameters.Buffer);
1311
1312 if (UserInfo->PrivateData.Buffer != NULL)
1313 SamFreeMemory(UserInfo->PrivateData.Buffer);
1314
1315 if (UserInfo->LogonHours.LogonHours != NULL)
1316 SamFreeMemory(UserInfo->LogonHours.LogonHours);
1317
1318 SamFreeMemory(UserInfo);
1319 }
1320
1321
1322 static
1323 NET_API_STATUS
1324 SetUserInfo(SAM_HANDLE UserHandle,
1325 LPBYTE UserInfo,
1326 DWORD Level)
1327 {
1328 USER_ALL_INFORMATION UserAllInfo;
1329 PUSER_INFO_0 UserInfo0;
1330 PUSER_INFO_1 UserInfo1;
1331 PUSER_INFO_2 UserInfo2;
1332 PUSER_INFO_3 UserInfo3;
1333 PUSER_INFO_4 UserInfo4;
1334 PUSER_INFO_1003 UserInfo1003;
1335 PUSER_INFO_1006 UserInfo1006;
1336 PUSER_INFO_1007 UserInfo1007;
1337 PUSER_INFO_1008 UserInfo1008;
1338 PUSER_INFO_1009 UserInfo1009;
1339 PUSER_INFO_1011 UserInfo1011;
1340 PUSER_INFO_1012 UserInfo1012;
1341 PUSER_INFO_1013 UserInfo1013;
1342 PUSER_INFO_1014 UserInfo1014;
1343 PUSER_INFO_1017 UserInfo1017;
1344 PUSER_INFO_1018 UserInfo1018;
1345 PUSER_INFO_1024 UserInfo1024;
1346 PUSER_INFO_1025 UserInfo1025;
1347 PUSER_INFO_1051 UserInfo1051;
1348 PUSER_INFO_1052 UserInfo1052;
1349 PUSER_INFO_1053 UserInfo1053;
1350 NET_API_STATUS ApiStatus = NERR_Success;
1351 NTSTATUS Status = STATUS_SUCCESS;
1352
1353 ZeroMemory(&UserAllInfo, sizeof(USER_ALL_INFORMATION));
1354
1355 switch (Level)
1356 {
1357 case 0:
1358 UserInfo0 = (PUSER_INFO_0)UserInfo;
1359
1360 RtlInitUnicodeString(&UserAllInfo.UserName,
1361 UserInfo0->usri0_name);
1362
1363 UserAllInfo.WhichFields |= USER_ALL_USERNAME;
1364 break;
1365
1366 case 1:
1367 UserInfo1 = (PUSER_INFO_1)UserInfo;
1368
1369 // usri1_name ignored
1370
1371 if (UserInfo1->usri1_password != NULL)
1372 {
1373 RtlInitUnicodeString(&UserAllInfo.NtPassword,
1374 UserInfo1->usri1_password);
1375 UserAllInfo.NtPasswordPresent = TRUE;
1376 UserAllInfo.WhichFields |= USER_ALL_NTPASSWORDPRESENT;
1377 }
1378
1379 // usri1_password_age ignored
1380
1381 // UserInfo1->usri1_priv
1382
1383 if (UserInfo1->usri1_home_dir != NULL)
1384 {
1385 RtlInitUnicodeString(&UserAllInfo.HomeDirectory,
1386 UserInfo1->usri1_home_dir);
1387 UserAllInfo.WhichFields |= USER_ALL_HOMEDIRECTORY;
1388 }
1389
1390 if (UserInfo1->usri1_comment != NULL)
1391 {
1392 RtlInitUnicodeString(&UserAllInfo.AdminComment,
1393 UserInfo1->usri1_comment);
1394 UserAllInfo.WhichFields |= USER_ALL_ADMINCOMMENT;
1395 }
1396
1397 UserAllInfo.UserAccountControl = GetAccountControl(UserInfo1->usri1_flags);
1398 UserAllInfo.WhichFields |= USER_ALL_USERACCOUNTCONTROL;
1399
1400 if (UserInfo1->usri1_script_path != NULL)
1401 {
1402 RtlInitUnicodeString(&UserAllInfo.ScriptPath,
1403 UserInfo1->usri1_script_path);
1404 UserAllInfo.WhichFields |= USER_ALL_SCRIPTPATH;
1405 }
1406 break;
1407
1408 case 2:
1409 UserInfo2 = (PUSER_INFO_2)UserInfo;
1410
1411 // usri2_name ignored
1412
1413 if (UserInfo2->usri2_password != NULL)
1414 {
1415 RtlInitUnicodeString(&UserAllInfo.NtPassword,
1416 UserInfo2->usri2_password);
1417 UserAllInfo.NtPasswordPresent = TRUE;
1418 UserAllInfo.WhichFields |= USER_ALL_NTPASSWORDPRESENT;
1419 }
1420
1421 // usri2_password_age ignored
1422
1423 // UserInfo2->usri2_priv;
1424
1425 if (UserInfo2->usri2_home_dir != NULL)
1426 {
1427 RtlInitUnicodeString(&UserAllInfo.HomeDirectory,
1428 UserInfo2->usri2_home_dir);
1429 UserAllInfo.WhichFields |= USER_ALL_HOMEDIRECTORY;
1430 }
1431
1432 if (UserInfo2->usri2_comment != NULL)
1433 {
1434 RtlInitUnicodeString(&UserAllInfo.AdminComment,
1435 UserInfo2->usri2_comment);
1436 UserAllInfo.WhichFields |= USER_ALL_ADMINCOMMENT;
1437 }
1438
1439 UserAllInfo.UserAccountControl = GetAccountControl(UserInfo2->usri2_flags);
1440 UserAllInfo.WhichFields |= USER_ALL_USERACCOUNTCONTROL;
1441
1442 if (UserInfo2->usri2_script_path != NULL)
1443 {
1444 RtlInitUnicodeString(&UserAllInfo.ScriptPath,
1445 UserInfo2->usri2_script_path);
1446 UserAllInfo.WhichFields |= USER_ALL_SCRIPTPATH;
1447 }
1448
1449 // UserInfo2->usri2_auth_flags;
1450
1451 if (UserInfo2->usri2_full_name != NULL)
1452 {
1453 RtlInitUnicodeString(&UserAllInfo.FullName,
1454 UserInfo2->usri2_full_name);
1455 UserAllInfo.WhichFields |= USER_ALL_FULLNAME;
1456 }
1457
1458 if (UserInfo2->usri2_usr_comment != NULL)
1459 {
1460 RtlInitUnicodeString(&UserAllInfo.UserComment,
1461 UserInfo2->usri2_usr_comment);
1462 UserAllInfo.WhichFields |= USER_ALL_USERCOMMENT;
1463 }
1464
1465 if (UserInfo2->usri2_parms != NULL)
1466 {
1467 RtlInitUnicodeString(&UserAllInfo.Parameters,
1468 UserInfo2->usri2_parms);
1469 UserAllInfo.WhichFields |= USER_ALL_PARAMETERS;
1470 }
1471
1472 if (UserInfo2->usri2_workstations != NULL)
1473 {
1474 RtlInitUnicodeString(&UserAllInfo.WorkStations,
1475 UserInfo2->usri2_workstations);
1476 UserAllInfo.WhichFields |= USER_ALL_WORKSTATIONS;
1477 }
1478
1479 // usri2_last_logon ignored
1480 // usri2_last_logoff ignored
1481
1482 if (UserInfo2->usri2_acct_expires == TIMEQ_FOREVER)
1483 {
1484 UserAllInfo.AccountExpires.LowPart = 0;
1485 UserAllInfo.AccountExpires.HighPart = 0;
1486 }
1487 else
1488 {
1489 RtlSecondsSince1970ToTime(UserInfo2->usri2_acct_expires,
1490 &UserAllInfo.AccountExpires);
1491 }
1492 UserAllInfo.WhichFields |= USER_ALL_ACCOUNTEXPIRES;
1493
1494 // usri2_max_storage ignored
1495
1496 // UserInfo2->usri2_units_per_week;
1497 // UserInfo2->usri2_logon_hours;
1498
1499 // usri2_bad_pw_count ignored
1500 // usri2_num_logons ignored
1501 // usri2_logon_server ignored
1502
1503 UserAllInfo.CountryCode = UserInfo2->usri2_country_code;
1504 UserAllInfo.WhichFields |= USER_ALL_COUNTRYCODE;
1505
1506 UserAllInfo.CodePage = UserInfo2->usri2_code_page;
1507 UserAllInfo.WhichFields |= USER_ALL_CODEPAGE;
1508 break;
1509
1510 case 3:
1511 UserInfo3 = (PUSER_INFO_3)UserInfo;
1512
1513 // usri3_name ignored
1514
1515 if (UserInfo3->usri3_password != NULL)
1516 {
1517 RtlInitUnicodeString(&UserAllInfo.NtPassword,
1518 UserInfo3->usri3_password);
1519 UserAllInfo.NtPasswordPresent = TRUE;
1520 UserAllInfo.WhichFields |= USER_ALL_NTPASSWORDPRESENT;
1521 }
1522
1523 // usri3_password_age ignored
1524
1525 // UserInfo3->usri3_priv;
1526
1527 if (UserInfo3->usri3_home_dir != NULL)
1528 {
1529 RtlInitUnicodeString(&UserAllInfo.HomeDirectory,
1530 UserInfo3->usri3_home_dir);
1531 UserAllInfo.WhichFields |= USER_ALL_HOMEDIRECTORY;
1532 }
1533
1534 if (UserInfo3->usri3_comment != NULL)
1535 {
1536 RtlInitUnicodeString(&UserAllInfo.AdminComment,
1537 UserInfo3->usri3_comment);
1538 UserAllInfo.WhichFields |= USER_ALL_ADMINCOMMENT;
1539 }
1540
1541 UserAllInfo.UserAccountControl = GetAccountControl(UserInfo3->usri3_flags);
1542 UserAllInfo.WhichFields |= USER_ALL_USERACCOUNTCONTROL;
1543
1544 if (UserInfo3->usri3_script_path != NULL)
1545 {
1546 RtlInitUnicodeString(&UserAllInfo.ScriptPath,
1547 UserInfo3->usri3_script_path);
1548 UserAllInfo.WhichFields |= USER_ALL_SCRIPTPATH;
1549 }
1550
1551 // UserInfo3->usri3_auth_flags;
1552
1553 if (UserInfo3->usri3_full_name != NULL)
1554 {
1555 RtlInitUnicodeString(&UserAllInfo.FullName,
1556 UserInfo3->usri3_full_name);
1557 UserAllInfo.WhichFields |= USER_ALL_FULLNAME;
1558 }
1559
1560 if (UserInfo3->usri3_usr_comment != NULL)
1561 {
1562 RtlInitUnicodeString(&UserAllInfo.UserComment,
1563 UserInfo3->usri3_usr_comment);
1564 UserAllInfo.WhichFields |= USER_ALL_USERCOMMENT;
1565 }
1566
1567 if (UserInfo3->usri3_parms != NULL)
1568 {
1569 RtlInitUnicodeString(&UserAllInfo.Parameters,
1570 UserInfo3->usri3_parms);
1571 UserAllInfo.WhichFields |= USER_ALL_PARAMETERS;
1572 }
1573
1574 if (UserInfo3->usri3_workstations != NULL)
1575 {
1576 RtlInitUnicodeString(&UserAllInfo.WorkStations,
1577 UserInfo3->usri3_workstations);
1578 UserAllInfo.WhichFields |= USER_ALL_WORKSTATIONS;
1579 }
1580
1581 // usri3_last_logon ignored
1582 // usri3_last_logoff ignored
1583
1584 if (UserInfo3->usri3_acct_expires == TIMEQ_FOREVER)
1585 {
1586 UserAllInfo.AccountExpires.LowPart = 0;
1587 UserAllInfo.AccountExpires.HighPart = 0;
1588 }
1589 else
1590 {
1591 RtlSecondsSince1970ToTime(UserInfo3->usri3_acct_expires,
1592 &UserAllInfo.AccountExpires);
1593 }
1594 UserAllInfo.WhichFields |= USER_ALL_ACCOUNTEXPIRES;
1595
1596 // usri3_max_storage ignored
1597
1598 // UserInfo3->usri3_units_per_week;
1599 // UserInfo3->usri3_logon_hours;
1600
1601 // usri3_bad_pw_count ignored
1602 // usri3_num_logons ignored
1603 // usri3_logon_server ignored
1604
1605 UserAllInfo.CountryCode = UserInfo3->usri3_country_code;
1606 UserAllInfo.WhichFields |= USER_ALL_COUNTRYCODE;
1607
1608 UserAllInfo.CodePage = UserInfo3->usri3_code_page;
1609 UserAllInfo.WhichFields |= USER_ALL_CODEPAGE;
1610
1611 // usri3_user_id ignored
1612
1613 UserAllInfo.PrimaryGroupId = UserInfo3->usri3_primary_group_id;
1614 UserAllInfo.WhichFields |= USER_ALL_PRIMARYGROUPID;
1615
1616 if (UserInfo3->usri3_profile != NULL)
1617 {
1618 RtlInitUnicodeString(&UserAllInfo.ProfilePath,
1619 UserInfo3->usri3_profile);
1620 UserAllInfo.WhichFields |= USER_ALL_PROFILEPATH;
1621 }
1622
1623 if (UserInfo3->usri3_home_dir_drive != NULL)
1624 {
1625 RtlInitUnicodeString(&UserAllInfo.HomeDirectoryDrive,
1626 UserInfo3->usri3_home_dir_drive);
1627 UserAllInfo.WhichFields |= USER_ALL_HOMEDIRECTORYDRIVE;
1628 }
1629
1630 UserAllInfo.PasswordExpired = (UserInfo3->usri3_password_expired != 0);
1631 UserAllInfo.WhichFields |= USER_ALL_PASSWORDEXPIRED;
1632 break;
1633
1634 case 4:
1635 UserInfo4 = (PUSER_INFO_4)UserInfo;
1636
1637 // usri4_name ignored
1638
1639 if (UserInfo4->usri4_password != NULL)
1640 {
1641 RtlInitUnicodeString(&UserAllInfo.NtPassword,
1642 UserInfo4->usri4_password);
1643 UserAllInfo.NtPasswordPresent = TRUE;
1644 UserAllInfo.WhichFields |= USER_ALL_NTPASSWORDPRESENT;
1645 }
1646
1647 // usri4_password_age ignored
1648
1649 // UserInfo3->usri4_priv;
1650
1651 if (UserInfo4->usri4_home_dir != NULL)
1652 {
1653 RtlInitUnicodeString(&UserAllInfo.HomeDirectory,
1654 UserInfo4->usri4_home_dir);
1655 UserAllInfo.WhichFields |= USER_ALL_HOMEDIRECTORY;
1656 }
1657
1658 if (UserInfo4->usri4_comment != NULL)
1659 {
1660 RtlInitUnicodeString(&UserAllInfo.AdminComment,
1661 UserInfo4->usri4_comment);
1662 UserAllInfo.WhichFields |= USER_ALL_ADMINCOMMENT;
1663 }
1664
1665 UserAllInfo.UserAccountControl = GetAccountControl(UserInfo4->usri4_flags);
1666 UserAllInfo.WhichFields |= USER_ALL_USERACCOUNTCONTROL;
1667
1668 if (UserInfo4->usri4_script_path != NULL)
1669 {
1670 RtlInitUnicodeString(&UserAllInfo.ScriptPath,
1671 UserInfo4->usri4_script_path);
1672 UserAllInfo.WhichFields |= USER_ALL_SCRIPTPATH;
1673 }
1674
1675 // UserInfo4->usri4_auth_flags;
1676
1677 if (UserInfo4->usri4_full_name != NULL)
1678 {
1679 RtlInitUnicodeString(&UserAllInfo.FullName,
1680 UserInfo4->usri4_full_name);
1681 UserAllInfo.WhichFields |= USER_ALL_FULLNAME;
1682 }
1683
1684 if (UserInfo4->usri4_usr_comment != NULL)
1685 {
1686 RtlInitUnicodeString(&UserAllInfo.UserComment,
1687 UserInfo4->usri4_usr_comment);
1688 UserAllInfo.WhichFields |= USER_ALL_USERCOMMENT;
1689 }
1690
1691 if (UserInfo4->usri4_parms != NULL)
1692 {
1693 RtlInitUnicodeString(&UserAllInfo.Parameters,
1694 UserInfo4->usri4_parms);
1695 UserAllInfo.WhichFields |= USER_ALL_PARAMETERS;
1696 }
1697
1698 if (UserInfo4->usri4_workstations != NULL)
1699 {
1700 RtlInitUnicodeString(&UserAllInfo.WorkStations,
1701 UserInfo4->usri4_workstations);
1702 UserAllInfo.WhichFields |= USER_ALL_WORKSTATIONS;
1703 }
1704
1705 // usri4_last_logon ignored
1706 // usri4_last_logoff ignored
1707
1708 if (UserInfo4->usri4_acct_expires == TIMEQ_FOREVER)
1709 {
1710 UserAllInfo.AccountExpires.LowPart = 0;
1711 UserAllInfo.AccountExpires.HighPart = 0;
1712 }
1713 else
1714 {
1715 RtlSecondsSince1970ToTime(UserInfo4->usri4_acct_expires,
1716 &UserAllInfo.AccountExpires);
1717 }
1718 UserAllInfo.WhichFields |= USER_ALL_ACCOUNTEXPIRES;
1719
1720 // usri4_max_storage ignored
1721
1722 // UserInfo3->usri4_units_per_week;
1723 // UserInfo3->usri4_logon_hours;
1724
1725 // usri4_bad_pw_count ignored
1726 // usri4_num_logons ignored
1727 // usri4_logon_server ignored
1728
1729 UserAllInfo.CountryCode = UserInfo4->usri4_country_code;
1730 UserAllInfo.WhichFields |= USER_ALL_COUNTRYCODE;
1731
1732 UserAllInfo.CodePage = UserInfo4->usri4_code_page;
1733 UserAllInfo.WhichFields |= USER_ALL_CODEPAGE;
1734
1735 // usri4_user_sid ignored
1736
1737 UserAllInfo.PrimaryGroupId = UserInfo4->usri4_primary_group_id;
1738 UserAllInfo.WhichFields |= USER_ALL_PRIMARYGROUPID;
1739
1740 if (UserInfo4->usri4_profile != NULL)
1741 {
1742 RtlInitUnicodeString(&UserAllInfo.ProfilePath,
1743 UserInfo4->usri4_profile);
1744 UserAllInfo.WhichFields |= USER_ALL_PROFILEPATH;
1745 }
1746
1747 if (UserInfo4->usri4_home_dir_drive != NULL)
1748 {
1749 RtlInitUnicodeString(&UserAllInfo.HomeDirectoryDrive,
1750 UserInfo4->usri4_home_dir_drive);
1751 UserAllInfo.WhichFields |= USER_ALL_HOMEDIRECTORYDRIVE;
1752 }
1753
1754 UserAllInfo.PasswordExpired = (UserInfo4->usri4_password_expired != 0);
1755 UserAllInfo.WhichFields |= USER_ALL_PASSWORDEXPIRED;
1756 break;
1757
1758 // case 21:
1759 // case 22:
1760
1761 case 1003:
1762 UserInfo1003 = (PUSER_INFO_1003)UserInfo;
1763
1764 if (UserInfo1003->usri1003_password != NULL)
1765 {
1766 RtlInitUnicodeString(&UserAllInfo.NtPassword,
1767 UserInfo1003->usri1003_password);
1768 UserAllInfo.NtPasswordPresent = TRUE;
1769 UserAllInfo.WhichFields |= USER_ALL_NTPASSWORDPRESENT;
1770 }
1771 break;
1772
1773 // case 1005:
1774
1775 case 1006:
1776 UserInfo1006 = (PUSER_INFO_1006)UserInfo;
1777
1778 if (UserInfo1006->usri1006_home_dir != NULL)
1779 {
1780 RtlInitUnicodeString(&UserAllInfo.HomeDirectory,
1781 UserInfo1006->usri1006_home_dir);
1782 UserAllInfo.WhichFields |= USER_ALL_HOMEDIRECTORY;
1783 }
1784 break;
1785
1786 case 1007:
1787 UserInfo1007 = (PUSER_INFO_1007)UserInfo;
1788
1789 if (UserInfo1007->usri1007_comment != NULL)
1790 {
1791 RtlInitUnicodeString(&UserAllInfo.AdminComment,
1792 UserInfo1007->usri1007_comment);
1793 UserAllInfo.WhichFields |= USER_ALL_ADMINCOMMENT;
1794 }
1795 break;
1796
1797 case 1008:
1798 UserInfo1008 = (PUSER_INFO_1008)UserInfo;
1799 UserAllInfo.UserAccountControl = GetAccountControl(UserInfo1008->usri1008_flags);
1800 UserAllInfo.WhichFields |= USER_ALL_USERACCOUNTCONTROL;
1801 break;
1802
1803 case 1009:
1804 UserInfo1009 = (PUSER_INFO_1009)UserInfo;
1805
1806 if (UserInfo1009->usri1009_script_path != NULL)
1807 {
1808 RtlInitUnicodeString(&UserAllInfo.ScriptPath,
1809 UserInfo1009->usri1009_script_path);
1810 UserAllInfo.WhichFields |= USER_ALL_SCRIPTPATH;
1811 }
1812 break;
1813
1814 // case 1010:
1815
1816 case 1011:
1817 UserInfo1011 = (PUSER_INFO_1011)UserInfo;
1818
1819 if (UserInfo1011->usri1011_full_name != NULL)
1820 {
1821 RtlInitUnicodeString(&UserAllInfo.FullName,
1822 UserInfo1011->usri1011_full_name);
1823 UserAllInfo.WhichFields |= USER_ALL_FULLNAME;
1824 }
1825 break;
1826
1827 case 1012:
1828 UserInfo1012 = (PUSER_INFO_1012)UserInfo;
1829
1830 if (UserInfo1012->usri1012_usr_comment != NULL)
1831 {
1832 RtlInitUnicodeString(&UserAllInfo.UserComment,
1833 UserInfo1012->usri1012_usr_comment);
1834 UserAllInfo.WhichFields |= USER_ALL_USERCOMMENT;
1835 }
1836 break;
1837
1838 case 1013:
1839 UserInfo1013 = (PUSER_INFO_1013)UserInfo;
1840
1841 if (UserInfo1013->usri1013_parms != NULL)
1842 {
1843 RtlInitUnicodeString(&UserAllInfo.Parameters,
1844 UserInfo1013->usri1013_parms);
1845 UserAllInfo.WhichFields |= USER_ALL_PARAMETERS;
1846 }
1847 break;
1848
1849 case 1014:
1850 UserInfo1014 = (PUSER_INFO_1014)UserInfo;
1851
1852 if (UserInfo1014->usri1014_workstations != NULL)
1853 {
1854 RtlInitUnicodeString(&UserAllInfo.WorkStations,
1855 UserInfo1014->usri1014_workstations);
1856 UserAllInfo.WhichFields |= USER_ALL_WORKSTATIONS;
1857 }
1858 break;
1859
1860 case 1017:
1861 UserInfo1017 = (PUSER_INFO_1017)UserInfo;
1862
1863 if (UserInfo1017->usri1017_acct_expires == TIMEQ_FOREVER)
1864 {
1865 UserAllInfo.AccountExpires.LowPart = 0;
1866 UserAllInfo.AccountExpires.HighPart = 0;
1867 }
1868 else
1869 {
1870 RtlSecondsSince1970ToTime(UserInfo1017->usri1017_acct_expires,
1871 &UserAllInfo.AccountExpires);
1872 }
1873 UserAllInfo.WhichFields |= USER_ALL_ACCOUNTEXPIRES;
1874 break;
1875
1876 case 1018:
1877 UserInfo1018 = (PUSER_INFO_1018)UserInfo;
1878
1879 if (UserInfo1018->usri1018_max_storage != USER_MAXSTORAGE_UNLIMITED)
1880 {
1881 // FIXME: Report error
1882 return ERROR_INVALID_PARAMETER;
1883 }
1884 break;
1885
1886 // case 1020:
1887
1888 case 1024:
1889 UserInfo1024 = (PUSER_INFO_1024)UserInfo;
1890
1891 UserAllInfo.CountryCode = UserInfo1024->usri1024_country_code;
1892 UserAllInfo.WhichFields |= USER_ALL_COUNTRYCODE;
1893 break;
1894
1895 case 1025:
1896 UserInfo1025 = (PUSER_INFO_1025)UserInfo;
1897
1898 UserAllInfo.CodePage = UserInfo1025->usri1025_code_page;
1899 UserAllInfo.WhichFields |= USER_ALL_CODEPAGE;
1900 break;
1901
1902 case 1051:
1903 UserInfo1051 = (PUSER_INFO_1051)UserInfo;
1904
1905 UserAllInfo.PrimaryGroupId = UserInfo1051->usri1051_primary_group_id;
1906 UserAllInfo.WhichFields |= USER_ALL_PRIMARYGROUPID;
1907 break;
1908
1909 case 1052:
1910 UserInfo1052 = (PUSER_INFO_1052)UserInfo;
1911
1912 if (UserInfo1052->usri1052_profile != NULL)
1913 {
1914 RtlInitUnicodeString(&UserAllInfo.ProfilePath,
1915 UserInfo1052->usri1052_profile);
1916 UserAllInfo.WhichFields |= USER_ALL_PROFILEPATH;
1917 }
1918 break;
1919
1920 case 1053:
1921 UserInfo1053 = (PUSER_INFO_1053)UserInfo;
1922
1923 if (UserInfo1053->usri1053_home_dir_drive != NULL)
1924 {
1925 RtlInitUnicodeString(&UserAllInfo.HomeDirectoryDrive,
1926 UserInfo1053->usri1053_home_dir_drive);
1927 UserAllInfo.WhichFields |= USER_ALL_HOMEDIRECTORYDRIVE;
1928 }
1929 break;
1930
1931 default:
1932 ERR("Unsupported level %lu!\n", Level);
1933 return ERROR_INVALID_PARAMETER;
1934 }
1935
1936 Status = SamSetInformationUser(UserHandle,
1937 UserAllInformation,
1938 &UserAllInfo);
1939 if (!NT_SUCCESS(Status))
1940 {
1941 ERR("SamSetInformationUser failed (Status %08lx)\n", Status);
1942 ApiStatus = NetpNtStatusToApiStatus(Status);
1943 goto done;
1944 }
1945
1946 done:
1947 return ApiStatus;
1948 }
1949
1950
1951 static
1952 NET_API_STATUS
1953 OpenUserByName(SAM_HANDLE DomainHandle,
1954 PUNICODE_STRING UserName,
1955 ULONG DesiredAccess,
1956 PSAM_HANDLE UserHandle)
1957 {
1958 PULONG RelativeIds = NULL;
1959 PSID_NAME_USE Use = NULL;
1960 NET_API_STATUS ApiStatus = NERR_Success;
1961 NTSTATUS Status = STATUS_SUCCESS;
1962
1963 /* Get the RID for the given user name */
1964 Status = SamLookupNamesInDomain(DomainHandle,
1965 1,
1966 UserName,
1967 &RelativeIds,
1968 &Use);
1969 if (!NT_SUCCESS(Status))
1970 {
1971 ERR("SamLookupNamesInDomain failed (Status %08lx)\n", Status);
1972 return NetpNtStatusToApiStatus(Status);
1973 }
1974
1975 /* Fail, if it is not an alias account */
1976 if (Use[0] != SidTypeUser)
1977 {
1978 ERR("Object is not a user!\n");
1979 ApiStatus = NERR_GroupNotFound;
1980 goto done;
1981 }
1982
1983 /* Open the alias account */
1984 Status = SamOpenUser(DomainHandle,
1985 DesiredAccess,
1986 RelativeIds[0],
1987 UserHandle);
1988 if (!NT_SUCCESS(Status))
1989 {
1990 ERR("SamOpenUser failed (Status %08lx)\n", Status);
1991 ApiStatus = NetpNtStatusToApiStatus(Status);
1992 goto done;
1993 }
1994
1995 done:
1996 if (RelativeIds != NULL)
1997 SamFreeMemory(RelativeIds);
1998
1999 if (Use != NULL)
2000 SamFreeMemory(Use);
2001
2002 return ApiStatus;
2003 }
2004
2005
2006 /************************************************************
2007 * NetUserAdd (NETAPI32.@)
2008 */
2009 NET_API_STATUS
2010 WINAPI
2011 NetUserAdd(LPCWSTR servername,
2012 DWORD level,
2013 LPBYTE bufptr,
2014 LPDWORD parm_err)
2015 {
2016 UNICODE_STRING ServerName;
2017 UNICODE_STRING UserName;
2018 SAM_HANDLE ServerHandle = NULL;
2019 SAM_HANDLE DomainHandle = NULL;
2020 SAM_HANDLE UserHandle = NULL;
2021 ULONG GrantedAccess;
2022 ULONG RelativeId;
2023 NET_API_STATUS ApiStatus = NERR_Success;
2024 NTSTATUS Status = STATUS_SUCCESS;
2025
2026 TRACE("(%s, %d, %p, %p)\n", debugstr_w(servername), level, bufptr, parm_err);
2027
2028 /* Check the info level */
2029 switch (level)
2030 {
2031 case 1:
2032 case 2:
2033 case 3:
2034 case 4:
2035 break;
2036
2037 default:
2038 return ERROR_INVALID_LEVEL;
2039 }
2040
2041 if (servername != NULL)
2042 RtlInitUnicodeString(&ServerName, servername);
2043
2044 /* Connect to the SAM Server */
2045 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
2046 &ServerHandle,
2047 SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
2048 NULL);
2049 if (!NT_SUCCESS(Status))
2050 {
2051 ERR("SamConnect failed (Status %08lx)\n", Status);
2052 ApiStatus = NetpNtStatusToApiStatus(Status);
2053 goto done;
2054 }
2055
2056 /* Open the Account Domain */
2057 Status = OpenAccountDomain(ServerHandle,
2058 (servername != NULL) ? &ServerName : NULL,
2059 DOMAIN_CREATE_USER | DOMAIN_LOOKUP | DOMAIN_READ_PASSWORD_PARAMETERS,
2060 &DomainHandle);
2061 if (!NT_SUCCESS(Status))
2062 {
2063 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
2064 ApiStatus = NetpNtStatusToApiStatus(Status);
2065 goto done;
2066 }
2067
2068 /* Initialize the user name string */
2069 RtlInitUnicodeString(&UserName,
2070 ((PUSER_INFO_1)bufptr)->usri1_name);
2071
2072 /* Create the user account */
2073 Status = SamCreateUser2InDomain(DomainHandle,
2074 &UserName,
2075 USER_NORMAL_ACCOUNT,
2076 USER_ALL_ACCESS | DELETE | WRITE_DAC,
2077 &UserHandle,
2078 &GrantedAccess,
2079 &RelativeId);
2080 if (!NT_SUCCESS(Status))
2081 {
2082 ERR("SamCreateUser2InDomain failed (Status %08lx)\n", Status);
2083 ApiStatus = NetpNtStatusToApiStatus(Status);
2084 goto done;
2085 }
2086
2087 /* Set user information */
2088 ApiStatus = SetUserInfo(UserHandle,
2089 bufptr,
2090 level);
2091 if (ApiStatus != NERR_Success)
2092 {
2093 ERR("SetUserInfo failed (Status %lu)\n", ApiStatus);
2094 goto done;
2095 }
2096
2097 done:
2098 if (UserHandle != NULL)
2099 {
2100 if (ApiStatus != NERR_Success)
2101 SamDeleteUser(UserHandle);
2102 else
2103 SamCloseHandle(UserHandle);
2104 }
2105
2106 if (DomainHandle != NULL)
2107 SamCloseHandle(DomainHandle);
2108
2109 if (ServerHandle != NULL)
2110 SamCloseHandle(ServerHandle);
2111
2112 return ApiStatus;
2113 }
2114
2115
2116 /******************************************************************************
2117 * NetUserChangePassword (NETAPI32.@)
2118 * PARAMS
2119 * domainname [I] Optional. Domain on which the user resides or the logon
2120 * domain of the current user if NULL.
2121 * username [I] Optional. Username to change the password for or the name
2122 * of the current user if NULL.
2123 * oldpassword [I] The user's current password.
2124 * newpassword [I] The password that the user will be changed to using.
2125 *
2126 * RETURNS
2127 * Success: NERR_Success.
2128 * Failure: NERR_* failure code or win error code.
2129 *
2130 */
2131 NET_API_STATUS
2132 WINAPI
2133 NetUserChangePassword(LPCWSTR domainname,
2134 LPCWSTR username,
2135 LPCWSTR oldpassword,
2136 LPCWSTR newpassword)
2137 {
2138 PMSV1_0_CHANGEPASSWORD_REQUEST RequestBuffer = NULL;
2139 PMSV1_0_CHANGEPASSWORD_RESPONSE ResponseBuffer = NULL;
2140 ULONG RequestBufferSize;
2141 ULONG ResponseBufferSize = 0;
2142 LPWSTR Ptr;
2143 ANSI_STRING PackageName;
2144 ULONG AuthenticationPackage = 0;
2145 HANDLE LsaHandle = NULL;
2146 NET_API_STATUS ApiStatus = NERR_Success;
2147 NTSTATUS Status = STATUS_SUCCESS;
2148 NTSTATUS ProtocolStatus;
2149
2150 TRACE("(%s, %s, ..., ...)\n", debugstr_w(domainname), debugstr_w(username));
2151
2152 /* FIXME: handle null domain or user name */
2153
2154 /* Check the parameters */
2155 if ((oldpassword == NULL) ||
2156 (newpassword == NULL))
2157 return ERROR_INVALID_PARAMETER;
2158
2159 /* Connect to the LSA server */
2160 Status = LsaConnectUntrusted(&LsaHandle);
2161 if (!NT_SUCCESS(Status))
2162 return NetpNtStatusToApiStatus(Status);
2163
2164 /* Get the authentication package ID */
2165 RtlInitAnsiString(&PackageName,
2166 MSV1_0_PACKAGE_NAME);
2167
2168 Status = LsaLookupAuthenticationPackage(LsaHandle,
2169 &PackageName,
2170 &AuthenticationPackage);
2171 if (!NT_SUCCESS(Status))
2172 {
2173 ApiStatus = NetpNtStatusToApiStatus(Status);
2174 goto done;
2175 }
2176
2177 /* Calculate the request buffer size */
2178 RequestBufferSize = sizeof(MSV1_0_CHANGEPASSWORD_REQUEST) +
2179 ((wcslen(domainname) + 1) * sizeof(WCHAR)) +
2180 ((wcslen(username) + 1) * sizeof(WCHAR)) +
2181 ((wcslen(oldpassword) + 1) * sizeof(WCHAR)) +
2182 ((wcslen(newpassword) + 1) * sizeof(WCHAR));
2183
2184 /* Allocate the request buffer */
2185 ApiStatus = NetApiBufferAllocate(RequestBufferSize,
2186 (PVOID*)&RequestBuffer);
2187 if (ApiStatus != NERR_Success)
2188 goto done;
2189
2190 /* Initialize the request buffer */
2191 RequestBuffer->MessageType = MsV1_0ChangePassword;
2192 RequestBuffer->Impersonating = TRUE;
2193
2194 Ptr = (LPWSTR)((ULONG_PTR)RequestBuffer + sizeof(MSV1_0_CHANGEPASSWORD_REQUEST));
2195
2196 /* Pack the domain name */
2197 RequestBuffer->DomainName.Length = wcslen(domainname) * sizeof(WCHAR);
2198 RequestBuffer->DomainName.MaximumLength = RequestBuffer->DomainName.Length + sizeof(WCHAR);
2199 RequestBuffer->DomainName.Buffer = Ptr;
2200
2201 RtlCopyMemory(RequestBuffer->DomainName.Buffer,
2202 domainname,
2203 RequestBuffer->DomainName.MaximumLength);
2204
2205 Ptr = (LPWSTR)((ULONG_PTR)Ptr + RequestBuffer->DomainName.MaximumLength);
2206
2207 /* Pack the user name */
2208 RequestBuffer->AccountName.Length = wcslen(username) * sizeof(WCHAR);
2209 RequestBuffer->AccountName.MaximumLength = RequestBuffer->AccountName.Length + sizeof(WCHAR);
2210 RequestBuffer->AccountName.Buffer = Ptr;
2211
2212 RtlCopyMemory(RequestBuffer->AccountName.Buffer,
2213 username,
2214 RequestBuffer->AccountName.MaximumLength);
2215
2216 Ptr = (LPWSTR)((ULONG_PTR)Ptr + RequestBuffer->AccountName.MaximumLength);
2217
2218 /* Pack the old password */
2219 RequestBuffer->OldPassword.Length = wcslen(oldpassword) * sizeof(WCHAR);
2220 RequestBuffer->OldPassword.MaximumLength = RequestBuffer->OldPassword.Length + sizeof(WCHAR);
2221 RequestBuffer->OldPassword.Buffer = Ptr;
2222
2223 RtlCopyMemory(RequestBuffer->OldPassword.Buffer,
2224 oldpassword,
2225 RequestBuffer->OldPassword.MaximumLength);
2226
2227 Ptr = (LPWSTR)((ULONG_PTR)Ptr + RequestBuffer->OldPassword.MaximumLength);
2228
2229 /* Pack the new password */
2230 RequestBuffer->NewPassword.Length = wcslen(newpassword) * sizeof(WCHAR);
2231 RequestBuffer->NewPassword.MaximumLength = RequestBuffer->NewPassword.Length + sizeof(WCHAR);
2232 RequestBuffer->NewPassword.Buffer = Ptr;
2233
2234 RtlCopyMemory(RequestBuffer->NewPassword.Buffer,
2235 newpassword,
2236 RequestBuffer->NewPassword.MaximumLength);
2237
2238 /* Call the authentication package */
2239 Status = LsaCallAuthenticationPackage(LsaHandle,
2240 AuthenticationPackage,
2241 RequestBuffer,
2242 RequestBufferSize,
2243 (PVOID*)&ResponseBuffer,
2244 &ResponseBufferSize,
2245 &ProtocolStatus);
2246 if (!NT_SUCCESS(Status))
2247 {
2248 ApiStatus = NetpNtStatusToApiStatus(Status);
2249 goto done;
2250 }
2251
2252 if (!NT_SUCCESS(ProtocolStatus))
2253 {
2254 ApiStatus = NetpNtStatusToApiStatus(ProtocolStatus);
2255 goto done;
2256 }
2257
2258 done:
2259 if (RequestBuffer != NULL)
2260 NetApiBufferFree(RequestBuffer);
2261
2262 if (ResponseBuffer != NULL)
2263 LsaFreeReturnBuffer(ResponseBuffer);
2264
2265 if (LsaHandle != NULL)
2266 NtClose(LsaHandle);
2267
2268 return ApiStatus;
2269 }
2270
2271
2272 /************************************************************
2273 * NetUserDel (NETAPI32.@)
2274 */
2275 NET_API_STATUS
2276 WINAPI
2277 NetUserDel(LPCWSTR servername,
2278 LPCWSTR username)
2279 {
2280 UNICODE_STRING ServerName;
2281 UNICODE_STRING UserName;
2282 SAM_HANDLE ServerHandle = NULL;
2283 SAM_HANDLE DomainHandle = NULL;
2284 SAM_HANDLE UserHandle = NULL;
2285 NET_API_STATUS ApiStatus = NERR_Success;
2286 NTSTATUS Status = STATUS_SUCCESS;
2287
2288 TRACE("(%s, %s)\n", debugstr_w(servername), debugstr_w(username));
2289
2290 if (servername != NULL)
2291 RtlInitUnicodeString(&ServerName, servername);
2292
2293 RtlInitUnicodeString(&UserName, username);
2294
2295 /* Connect to the SAM Server */
2296 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
2297 &ServerHandle,
2298 SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
2299 NULL);
2300 if (!NT_SUCCESS(Status))
2301 {
2302 ERR("SamConnect failed (Status %08lx)\n", Status);
2303 ApiStatus = NetpNtStatusToApiStatus(Status);
2304 goto done;
2305 }
2306
2307 /* Open the Builtin Domain */
2308 Status = OpenBuiltinDomain(ServerHandle,
2309 DOMAIN_LOOKUP,
2310 &DomainHandle);
2311 if (!NT_SUCCESS(Status))
2312 {
2313 ERR("OpenBuiltinDomain failed (Status %08lx)\n", Status);
2314 ApiStatus = NetpNtStatusToApiStatus(Status);
2315 goto done;
2316 }
2317
2318 /* Open the user account in the builtin domain */
2319 ApiStatus = OpenUserByName(DomainHandle,
2320 &UserName,
2321 DELETE,
2322 &UserHandle);
2323 if (ApiStatus != NERR_Success && ApiStatus != ERROR_NONE_MAPPED)
2324 {
2325 TRACE("OpenUserByName failed (ApiStatus %lu)\n", ApiStatus);
2326 goto done;
2327 }
2328
2329 if (UserHandle == NULL)
2330 {
2331 if (DomainHandle != NULL)
2332 {
2333 SamCloseHandle(DomainHandle);
2334 DomainHandle = NULL;
2335 }
2336
2337 /* Open the Acount Domain */
2338 Status = OpenAccountDomain(ServerHandle,
2339 (servername != NULL) ? &ServerName : NULL,
2340 DOMAIN_LOOKUP,
2341 &DomainHandle);
2342 if (!NT_SUCCESS(Status))
2343 {
2344 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
2345 ApiStatus = NetpNtStatusToApiStatus(Status);
2346 goto done;
2347 }
2348
2349 /* Open the user account in the account domain */
2350 ApiStatus = OpenUserByName(DomainHandle,
2351 &UserName,
2352 DELETE,
2353 &UserHandle);
2354 if (ApiStatus != NERR_Success)
2355 {
2356 ERR("OpenUserByName failed (ApiStatus %lu)\n", ApiStatus);
2357 if (ApiStatus == ERROR_NONE_MAPPED)
2358 ApiStatus = NERR_UserNotFound;
2359 goto done;
2360 }
2361 }
2362
2363 /* Delete the user */
2364 Status = SamDeleteUser(UserHandle);
2365 if (!NT_SUCCESS(Status))
2366 {
2367 ERR("SamDeleteUser failed (Status %08lx)\n", Status);
2368 ApiStatus = NetpNtStatusToApiStatus(Status);
2369 goto done;
2370 }
2371
2372 done:
2373 if (UserHandle != NULL)
2374 SamCloseHandle(UserHandle);
2375
2376 if (DomainHandle != NULL)
2377 SamCloseHandle(DomainHandle);
2378
2379 if (ServerHandle != NULL)
2380 SamCloseHandle(ServerHandle);
2381
2382 return ApiStatus;
2383 }
2384
2385
2386 /************************************************************
2387 * NetUserEnum (NETAPI32.@)
2388 */
2389 NET_API_STATUS
2390 WINAPI
2391 NetUserEnum(LPCWSTR servername,
2392 DWORD level,
2393 DWORD filter,
2394 LPBYTE* bufptr,
2395 DWORD prefmaxlen,
2396 LPDWORD entriesread,
2397 LPDWORD totalentries,
2398 LPDWORD resume_handle)
2399 {
2400 UNICODE_STRING ServerName;
2401 PSAM_RID_ENUMERATION CurrentUser;
2402 PENUM_CONTEXT EnumContext = NULL;
2403 LPVOID Buffer = NULL;
2404 ULONG i;
2405 SAM_HANDLE UserHandle = NULL;
2406 PUSER_ALL_INFORMATION UserInfo = NULL;
2407
2408 NET_API_STATUS ApiStatus = NERR_Success;
2409 NTSTATUS Status = STATUS_SUCCESS;
2410
2411 TRACE("(%s %d 0x%d %p %d %p %p %p)\n", debugstr_w(servername), level,
2412 filter, bufptr, prefmaxlen, entriesread, totalentries, resume_handle);
2413
2414 *entriesread = 0;
2415 *totalentries = 0;
2416 *bufptr = NULL;
2417
2418 if (servername != NULL)
2419 RtlInitUnicodeString(&ServerName, servername);
2420
2421 if (resume_handle != NULL && *resume_handle != 0)
2422 {
2423 EnumContext = (PENUM_CONTEXT)*resume_handle;
2424 }
2425 else
2426 {
2427 ApiStatus = NetApiBufferAllocate(sizeof(ENUM_CONTEXT), (PVOID*)&EnumContext);
2428 if (ApiStatus != NERR_Success)
2429 goto done;
2430
2431 EnumContext->EnumerationContext = 0;
2432 EnumContext->Buffer = NULL;
2433 EnumContext->Count = 0;
2434 EnumContext->Index = 0;
2435 EnumContext->BuiltinDone = FALSE;
2436
2437 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
2438 &EnumContext->ServerHandle,
2439 SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
2440 NULL);
2441 if (!NT_SUCCESS(Status))
2442 {
2443 ERR("SamConnect failed (Status %08lx)\n", Status);
2444 ApiStatus = NetpNtStatusToApiStatus(Status);
2445 goto done;
2446 }
2447
2448 Status = OpenAccountDomain(EnumContext->ServerHandle,
2449 (servername != NULL) ? &ServerName : NULL,
2450 DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP,
2451 &EnumContext->AccountDomainHandle);
2452 if (!NT_SUCCESS(Status))
2453 {
2454 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
2455 ApiStatus = NetpNtStatusToApiStatus(Status);
2456 goto done;
2457 }
2458
2459 Status = OpenBuiltinDomain(EnumContext->ServerHandle,
2460 DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP,
2461 &EnumContext->BuiltinDomainHandle);
2462 if (!NT_SUCCESS(Status))
2463 {
2464 ERR("OpenBuiltinDomain failed (Status %08lx)\n", Status);
2465 ApiStatus = NetpNtStatusToApiStatus(Status);
2466 goto done;
2467 }
2468 }
2469
2470 // while (TRUE)
2471 // {
2472 TRACE("EnumContext->Index: %lu\n", EnumContext->Index);
2473 TRACE("EnumContext->Count: %lu\n", EnumContext->Count);
2474
2475 if (EnumContext->Index >= EnumContext->Count)
2476 {
2477 // if (EnumContext->BuiltinDone == TRUE)
2478 // {
2479 // ApiStatus = NERR_Success;
2480 // goto done;
2481 // }
2482
2483 TRACE("Calling SamEnumerateUsersInDomain\n");
2484 Status = SamEnumerateUsersInDomain(EnumContext->AccountDomainHandle, //BuiltinDomainHandle,
2485 &EnumContext->EnumerationContext,
2486 0,
2487 (PVOID *)&EnumContext->Buffer,
2488 prefmaxlen,
2489 &EnumContext->Count);
2490
2491 TRACE("SamEnumerateUsersInDomain returned (Status %08lx)\n", Status);
2492 if (!NT_SUCCESS(Status))
2493 {
2494 ERR("SamEnumerateUsersInDomain failed (Status %08lx)\n", Status);
2495 ApiStatus = NetpNtStatusToApiStatus(Status);
2496 goto done;
2497 }
2498
2499 if (Status == STATUS_MORE_ENTRIES)
2500 {
2501 ApiStatus = NERR_BufTooSmall;
2502 goto done;
2503 }
2504 else
2505 {
2506 EnumContext->BuiltinDone = TRUE;
2507 }
2508 }
2509
2510 TRACE("EnumContext: %lu\n", EnumContext);
2511 TRACE("EnumContext->Count: %lu\n", EnumContext->Count);
2512 TRACE("EnumContext->Buffer: %p\n", EnumContext->Buffer);
2513
2514 /* Get a pointer to the current user */
2515 CurrentUser = &EnumContext->Buffer[EnumContext->Index];
2516
2517 TRACE("RID: %lu\n", CurrentUser->RelativeId);
2518
2519 Status = SamOpenUser(EnumContext->AccountDomainHandle, //BuiltinDomainHandle,
2520 USER_READ_GENERAL | USER_READ_PREFERENCES | USER_READ_LOGON | USER_READ_ACCOUNT,
2521 CurrentUser->RelativeId,
2522 &UserHandle);
2523 if (!NT_SUCCESS(Status))
2524 {
2525 ERR("SamOpenUser failed (Status %08lx)\n", Status);
2526 ApiStatus = NetpNtStatusToApiStatus(Status);
2527 goto done;
2528 }
2529
2530 Status = SamQueryInformationUser(UserHandle,
2531 UserAllInformation,
2532 (PVOID *)&UserInfo);
2533 if (!NT_SUCCESS(Status))
2534 {
2535 ERR("SamQueryInformationUser failed (Status %08lx)\n", Status);
2536 ApiStatus = NetpNtStatusToApiStatus(Status);
2537 goto done;
2538 }
2539
2540 SamCloseHandle(UserHandle);
2541 UserHandle = NULL;
2542
2543 ApiStatus = BuildUserInfoBuffer(UserInfo,
2544 level,
2545 CurrentUser->RelativeId,
2546 &Buffer);
2547 if (ApiStatus != NERR_Success)
2548 {
2549 ERR("BuildUserInfoBuffer failed (ApiStatus %lu)\n", ApiStatus);
2550 goto done;
2551 }
2552
2553 if (UserInfo != NULL)
2554 {
2555 FreeUserInfo(UserInfo);
2556 UserInfo = NULL;
2557 }
2558
2559 EnumContext->Index++;
2560
2561 (*entriesread)++;
2562 // }
2563
2564 done:
2565 if (ApiStatus == NERR_Success && EnumContext->Index < EnumContext->Count)
2566 ApiStatus = ERROR_MORE_DATA;
2567
2568 if (EnumContext != NULL)
2569 *totalentries = EnumContext->Count;
2570
2571 if (resume_handle == NULL || ApiStatus != ERROR_MORE_DATA)
2572 {
2573 if (EnumContext != NULL)
2574 {
2575 if (EnumContext->BuiltinDomainHandle != NULL)
2576 SamCloseHandle(EnumContext->BuiltinDomainHandle);
2577
2578 if (EnumContext->AccountDomainHandle != NULL)
2579 SamCloseHandle(EnumContext->AccountDomainHandle);
2580
2581 if (EnumContext->ServerHandle != NULL)
2582 SamCloseHandle(EnumContext->ServerHandle);
2583
2584 if (EnumContext->Buffer != NULL)
2585 {
2586 for (i = 0; i < EnumContext->Count; i++)
2587 {
2588 SamFreeMemory(EnumContext->Buffer[i].Name.Buffer);
2589 }
2590
2591 SamFreeMemory(EnumContext->Buffer);
2592 }
2593
2594 NetApiBufferFree(EnumContext);
2595 EnumContext = NULL;
2596 }
2597 }
2598
2599 if (UserHandle != NULL)
2600 SamCloseHandle(UserHandle);
2601
2602 if (UserInfo != NULL)
2603 FreeUserInfo(UserInfo);
2604
2605 if (resume_handle != NULL)
2606 *resume_handle = (DWORD_PTR)EnumContext;
2607
2608 *bufptr = (LPBYTE)Buffer;
2609
2610 TRACE("return %lu\n", ApiStatus);
2611
2612 return ApiStatus;
2613 }
2614
2615
2616 /************************************************************
2617 * NetUserGetGroups (NETAPI32.@)
2618 */
2619 NET_API_STATUS
2620 WINAPI
2621 NetUserGetGroups(LPCWSTR servername,
2622 LPCWSTR username,
2623 DWORD level,
2624 LPBYTE *bufptr,
2625 DWORD prefixmaxlen,
2626 LPDWORD entriesread,
2627 LPDWORD totalentries)
2628 {
2629 UNICODE_STRING ServerName;
2630 UNICODE_STRING UserName;
2631 SAM_HANDLE ServerHandle = NULL;
2632 SAM_HANDLE AccountDomainHandle = NULL;
2633 SAM_HANDLE UserHandle = NULL;
2634 PSID AccountDomainSid = NULL;
2635 PULONG RelativeIds = NULL;
2636 PSID_NAME_USE Use = NULL;
2637 PGROUP_MEMBERSHIP GroupMembership = NULL;
2638 ULONG GroupCount;
2639
2640 NET_API_STATUS ApiStatus = NERR_Success;
2641 NTSTATUS Status = STATUS_SUCCESS;
2642
2643 TRACE("%s %s %d %p %d %p %p stub\n", debugstr_w(servername),
2644 debugstr_w(username), level, bufptr, prefixmaxlen, entriesread,
2645 totalentries);
2646
2647 if (servername != NULL)
2648 RtlInitUnicodeString(&ServerName, servername);
2649
2650 RtlInitUnicodeString(&UserName, username);
2651
2652 /* Connect to the SAM Server */
2653 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
2654 &ServerHandle,
2655 SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
2656 NULL);
2657 if (!NT_SUCCESS(Status))
2658 {
2659 ERR("SamConnect failed (Status %08lx)\n", Status);
2660 ApiStatus = NetpNtStatusToApiStatus(Status);
2661 goto done;
2662 }
2663
2664 /* Get the Account Domain SID */
2665 Status = GetAccountDomainSid((servername != NULL) ? &ServerName : NULL,
2666 &AccountDomainSid);
2667 if (!NT_SUCCESS(Status))
2668 {
2669 ERR("GetAccountDomainSid failed (Status %08lx)\n", Status);
2670 ApiStatus = NetpNtStatusToApiStatus(Status);
2671 goto done;
2672 }
2673
2674 /* Open the Account Domain */
2675 Status = SamOpenDomain(ServerHandle,
2676 DOMAIN_LOOKUP | DOMAIN_GET_ALIAS_MEMBERSHIP,
2677 AccountDomainSid,
2678 &AccountDomainHandle);
2679 if (!NT_SUCCESS(Status))
2680 {
2681 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
2682 ApiStatus = NetpNtStatusToApiStatus(Status);
2683 goto done;
2684 }
2685
2686 /* Get the RID for the given user name */
2687 Status = SamLookupNamesInDomain(AccountDomainHandle,
2688 1,
2689 &UserName,
2690 &RelativeIds,
2691 &Use);
2692 if (!NT_SUCCESS(Status))
2693 {
2694 ERR("SamLookupNamesInDomain failed (Status %08lx)\n", Status);
2695 if (Status == STATUS_NONE_MAPPED)
2696 ApiStatus = NERR_UserNotFound;
2697 else
2698 ApiStatus = NetpNtStatusToApiStatus(Status);
2699 goto done;
2700 }
2701
2702 /* Fail, if it is not a user account */
2703 if (Use[0] != SidTypeUser)
2704 {
2705 ERR("Account is not a User!\n");
2706 ApiStatus = NERR_UserNotFound;
2707 goto done;
2708 }
2709
2710 /* Open the user object */
2711 Status = SamOpenUser(AccountDomainHandle,
2712 USER_LIST_GROUPS,
2713 RelativeIds[0],
2714 &UserHandle);
2715 if (!NT_SUCCESS(Status))
2716 {
2717 ERR("SamOpenUser failed (Status %08lx)\n", Status);
2718 ApiStatus = NetpNtStatusToApiStatus(Status);
2719 goto done;
2720 }
2721
2722 /* Get the group memberships of this user */
2723 Status = SamGetGroupsForUser(UserHandle,
2724 &GroupMembership,
2725 &GroupCount);
2726 if (!NT_SUCCESS(Status))
2727 {
2728 ERR("SamGetGroupsForUser failed (Status %08lx)\n", Status);
2729 ApiStatus = NetpNtStatusToApiStatus(Status);
2730 goto done;
2731 }
2732
2733 /* If there is no group membership, we're done */
2734 if (GroupCount == 0)
2735 {
2736 ApiStatus = NERR_Success;
2737 goto done;
2738 }
2739
2740
2741 done:
2742
2743 if (GroupMembership != NULL)
2744 SamFreeMemory(GroupMembership);
2745
2746 if (UserHandle != NULL)
2747 SamCloseHandle(UserHandle);
2748
2749 if (RelativeIds != NULL)
2750 SamFreeMemory(RelativeIds);
2751
2752 if (Use != NULL)
2753 SamFreeMemory(Use);
2754
2755 if (AccountDomainSid != NULL)
2756 RtlFreeHeap(RtlGetProcessHeap(), 0, AccountDomainSid);
2757
2758 if (AccountDomainHandle != NULL)
2759 SamCloseHandle(AccountDomainHandle);
2760
2761 if (ServerHandle != NULL)
2762 SamCloseHandle(ServerHandle);
2763
2764 if (ApiStatus != NERR_Success && ApiStatus != ERROR_MORE_DATA)
2765 {
2766 *entriesread = 0;
2767 *totalentries = 0;
2768 }
2769 else
2770 {
2771 // *entriesread = Count;
2772 // *totalentries = Count;
2773 }
2774
2775 // *bufptr = (LPBYTE)Buffer;
2776
2777 return ApiStatus;
2778
2779 #if 0
2780 *bufptr = NULL;
2781 *entriesread = 0;
2782 *totalentries = 0;
2783
2784 return ERROR_INVALID_LEVEL;
2785 #endif
2786 }
2787
2788
2789 /************************************************************
2790 * NetUserGetInfo (NETAPI32.@)
2791 */
2792 NET_API_STATUS
2793 WINAPI
2794 NetUserGetInfo(LPCWSTR servername,
2795 LPCWSTR username,
2796 DWORD level,
2797 LPBYTE* bufptr)
2798 {
2799 UNICODE_STRING ServerName;
2800 UNICODE_STRING UserName;
2801 SAM_HANDLE ServerHandle = NULL;
2802 SAM_HANDLE AccountDomainHandle = NULL;
2803 SAM_HANDLE UserHandle = NULL;
2804 PULONG RelativeIds = NULL;
2805 PSID_NAME_USE Use = NULL;
2806 PUSER_ALL_INFORMATION UserInfo = NULL;
2807 LPVOID Buffer = NULL;
2808 NET_API_STATUS ApiStatus = NERR_Success;
2809 NTSTATUS Status = STATUS_SUCCESS;
2810
2811 TRACE("(%s, %s, %d, %p)\n", debugstr_w(servername),
2812 debugstr_w(username), level, bufptr);
2813
2814 if (servername != NULL)
2815 RtlInitUnicodeString(&ServerName, servername);
2816
2817 RtlInitUnicodeString(&UserName, username);
2818
2819 /* Connect to the SAM Server */
2820 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
2821 &ServerHandle,
2822 SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
2823 NULL);
2824 if (!NT_SUCCESS(Status))
2825 {
2826 ERR("SamConnect failed (Status %08lx)\n", Status);
2827 ApiStatus = NetpNtStatusToApiStatus(Status);
2828 goto done;
2829 }
2830
2831 /* Open the Account Domain */
2832 Status = OpenAccountDomain(ServerHandle,
2833 (servername != NULL) ? &ServerName : NULL,
2834 DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP,
2835 &AccountDomainHandle);
2836 if (!NT_SUCCESS(Status))
2837 {
2838 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
2839 ApiStatus = NetpNtStatusToApiStatus(Status);
2840 goto done;
2841 }
2842
2843 /* Get the RID for the given user name */
2844 Status = SamLookupNamesInDomain(AccountDomainHandle,
2845 1,
2846 &UserName,
2847 &RelativeIds,
2848 &Use);
2849 if (!NT_SUCCESS(Status))
2850 {
2851 ERR("SamOpenDomain failed (Status %08lx)\n", Status);
2852 if (Status == STATUS_NONE_MAPPED)
2853 ApiStatus = NERR_UserNotFound;
2854 else
2855 ApiStatus = NetpNtStatusToApiStatus(Status);
2856 goto done;
2857 }
2858
2859 /* Check if the account is a user account */
2860 if (Use[0] != SidTypeUser)
2861 {
2862 ERR("No user found!\n");
2863 ApiStatus = NERR_UserNotFound;
2864 goto done;
2865 }
2866
2867 TRACE("RID: %lu\n", RelativeIds[0]);
2868
2869 /* Open the user object */
2870 Status = SamOpenUser(AccountDomainHandle,
2871 USER_READ_GENERAL | USER_READ_PREFERENCES | USER_READ_LOGON | USER_READ_ACCOUNT,
2872 RelativeIds[0],
2873 &UserHandle);
2874 if (!NT_SUCCESS(Status))
2875 {
2876 ERR("SamOpenUser failed (Status %08lx)\n", Status);
2877 ApiStatus = NetpNtStatusToApiStatus(Status);
2878 goto done;
2879 }
2880
2881 Status = SamQueryInformationUser(UserHandle,
2882 UserAllInformation,
2883 (PVOID *)&UserInfo);
2884 if (!NT_SUCCESS(Status))
2885 {
2886 ERR("SamQueryInformationUser failed (Status %08lx)\n", Status);
2887 ApiStatus = NetpNtStatusToApiStatus(Status);
2888 goto done;
2889 }
2890
2891 ApiStatus = BuildUserInfoBuffer(UserInfo,
2892 level,
2893 RelativeIds[0],
2894 &Buffer);
2895 if (ApiStatus != NERR_Success)
2896 {
2897 ERR("BuildUserInfoBuffer failed (ApiStatus %08lu)\n", ApiStatus);
2898 goto done;
2899 }
2900
2901 done:
2902 if (UserInfo != NULL)
2903 FreeUserInfo(UserInfo);
2904
2905 if (UserHandle != NULL)
2906 SamCloseHandle(UserHandle);
2907
2908 if (RelativeIds != NULL)
2909 SamFreeMemory(RelativeIds);
2910
2911 if (Use != NULL)
2912 SamFreeMemory(Use);
2913
2914 if (AccountDomainHandle != NULL)
2915 SamCloseHandle(AccountDomainHandle);
2916
2917 if (ServerHandle != NULL)
2918 SamCloseHandle(ServerHandle);
2919
2920 *bufptr = (LPBYTE)Buffer;
2921
2922 return ApiStatus;
2923 }
2924
2925
2926 /************************************************************
2927 * NetUserGetLocalGroups (NETAPI32.@)
2928 */
2929 NET_API_STATUS
2930 WINAPI
2931 NetUserGetLocalGroups(LPCWSTR servername,
2932 LPCWSTR username,
2933 DWORD level,
2934 DWORD flags,
2935 LPBYTE* bufptr,
2936 DWORD prefmaxlen,
2937 LPDWORD entriesread,
2938 LPDWORD totalentries)
2939 {
2940 UNICODE_STRING ServerName;
2941 UNICODE_STRING UserName;
2942 SAM_HANDLE ServerHandle = NULL;
2943 SAM_HANDLE BuiltinDomainHandle = NULL;
2944 SAM_HANDLE AccountDomainHandle = NULL;
2945 PSID AccountDomainSid = NULL;
2946 PSID UserSid = NULL;
2947 PULONG RelativeIds = NULL;
2948 PSID_NAME_USE Use = NULL;
2949 ULONG BuiltinMemberCount = 0;
2950 ULONG AccountMemberCount = 0;
2951 PULONG BuiltinAliases = NULL;
2952 PULONG AccountAliases = NULL;
2953 PUNICODE_STRING BuiltinNames = NULL;
2954 PUNICODE_STRING AccountNames = NULL;
2955 PLOCALGROUP_USERS_INFO_0 Buffer = NULL;
2956 ULONG Size;
2957 ULONG Count = 0;
2958 ULONG Index;
2959 ULONG i;
2960 LPWSTR StrPtr;
2961 NET_API_STATUS ApiStatus = NERR_Success;
2962 NTSTATUS Status = STATUS_SUCCESS;
2963
2964 TRACE("(%s, %s, %d, %08x, %p %d, %p, %p) stub!\n",
2965 debugstr_w(servername), debugstr_w(username), level, flags, bufptr,
2966 prefmaxlen, entriesread, totalentries);
2967
2968 if (level != 0)
2969 return ERROR_INVALID_LEVEL;
2970
2971 if (flags & ~LG_INCLUDE_INDIRECT)
2972 return ERROR_INVALID_PARAMETER;
2973
2974 if (flags & LG_INCLUDE_INDIRECT)
2975 {
2976 WARN("The flag LG_INCLUDE_INDIRECT is not supported yet!\n");
2977 }
2978
2979 if (servername != NULL)
2980 RtlInitUnicodeString(&ServerName, servername);
2981
2982 RtlInitUnicodeString(&UserName, username);
2983
2984 /* Connect to the SAM Server */
2985 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
2986 &ServerHandle,
2987 SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
2988 NULL);
2989 if (!NT_SUCCESS(Status))
2990 {
2991 ERR("SamConnect failed (Status %08lx)\n", Status);
2992 ApiStatus = NetpNtStatusToApiStatus(Status);
2993 goto done;
2994 }
2995
2996 /* Open the Builtin Domain */
2997 Status = OpenBuiltinDomain(ServerHandle,
2998 DOMAIN_LOOKUP | DOMAIN_GET_ALIAS_MEMBERSHIP,
2999 &BuiltinDomainHandle);
3000 if (!NT_SUCCESS(Status))
3001 {
3002 ERR("OpenBuiltinDomain failed (Status %08lx)\n", Status);
3003 ApiStatus = NetpNtStatusToApiStatus(Status);
3004 goto done;
3005 }
3006
3007 /* Get the Account Domain SID */
3008 Status = GetAccountDomainSid((servername != NULL) ? &ServerName : NULL,
3009 &AccountDomainSid);
3010 if (!NT_SUCCESS(Status))
3011 {
3012 ERR("GetAccountDomainSid failed (Status %08lx)\n", Status);
3013 ApiStatus = NetpNtStatusToApiStatus(Status);
3014 goto done;
3015 }
3016
3017 /* Open the Account Domain */
3018 Status = SamOpenDomain(ServerHandle,
3019 DOMAIN_LOOKUP | DOMAIN_GET_ALIAS_MEMBERSHIP,
3020 AccountDomainSid,
3021 &AccountDomainHandle);
3022 if (!NT_SUCCESS(Status))
3023 {
3024 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
3025 ApiStatus = NetpNtStatusToApiStatus(Status);
3026 goto done;
3027 }
3028
3029 /* Get the RID for the given user name */
3030 Status = SamLookupNamesInDomain(AccountDomainHandle,
3031 1,
3032 &UserName,
3033 &RelativeIds,
3034 &Use);
3035 if (!NT_SUCCESS(Status))
3036 {
3037 ERR("SamLookupNamesInDomain failed (Status %08lx)\n", Status);
3038 if (Status == STATUS_NONE_MAPPED)
3039 ApiStatus = NERR_UserNotFound;
3040 else
3041 ApiStatus = NetpNtStatusToApiStatus(Status);
3042 goto done;
3043 }
3044
3045 /* Fail, if it is not a user account */
3046 if (Use[0] != SidTypeUser)
3047 {
3048 ERR("Account is not a User!\n");
3049 ApiStatus = NERR_UserNotFound;
3050 goto done;
3051 }
3052
3053 /* Build the User SID from the Account Domain SID and the users RID */
3054 ApiStatus = BuildSidFromSidAndRid(AccountDomainSid,
3055 RelativeIds[0],
3056 &UserSid);
3057 if (ApiStatus != NERR_Success)
3058 {
3059 ERR("BuildSidFromSidAndRid failed!\n");
3060 goto done;
3061 }
3062
3063 /* Get alias memberships in the Builtin Domain */
3064 Status = SamGetAliasMembership(BuiltinDomainHandle,
3065 1,
3066 &UserSid,
3067 &BuiltinMemberCount,
3068 &BuiltinAliases);
3069 if (!NT_SUCCESS(Status))
3070 {
3071 ERR("SamGetAliasMembership failed (Status %08lx)\n", Status);
3072 ApiStatus = NetpNtStatusToApiStatus(Status);
3073 goto done;
3074 }
3075
3076 if (BuiltinMemberCount > 0)
3077 {
3078 /* Get the Names of the builtin alias members */
3079 Status = SamLookupIdsInDomain(BuiltinDomainHandle,
3080 BuiltinMemberCount,
3081 BuiltinAliases,
3082 &BuiltinNames,
3083 NULL);
3084 if (!NT_SUCCESS(Status))
3085 {
3086 ERR("SamLookupIdsInDomain failed (Status %08lx)\n", Status);
3087 ApiStatus = NetpNtStatusToApiStatus(Status);
3088 goto done;
3089 }
3090 }
3091
3092 /* Get alias memberships in the Account Domain */
3093 Status = SamGetAliasMembership(AccountDomainHandle,
3094 1,
3095 &UserSid,
3096 &AccountMemberCount,
3097 &AccountAliases);
3098 if (!NT_SUCCESS(Status))
3099 {
3100 ERR("SamGetAliasMembership failed (Status %08lx)\n", Status);
3101 ApiStatus = NetpNtStatusToApiStatus(Status);
3102 goto done;
3103 }
3104
3105 if (AccountMemberCount > 0)
3106 {
3107 /* Get the Names of the builtin alias members */
3108 Status = SamLookupIdsInDomain(AccountDomainHandle,
3109 AccountMemberCount,
3110 AccountAliases,
3111 &AccountNames,
3112 NULL);
3113 if (!NT_SUCCESS(Status))
3114 {
3115 ERR("SamLookupIdsInDomain failed (Status %08lx)\n", Status);
3116 ApiStatus = NetpNtStatusToApiStatus(Status);
3117 goto done;
3118 }
3119 }
3120
3121 /* Calculate the required buffer size */
3122 Size = 0;
3123
3124 for (i = 0; i < BuiltinMemberCount; i++)
3125 {
3126 if (BuiltinNames[i].Length > 0)
3127 {
3128 Size += (sizeof(LOCALGROUP_USERS_INFO_0) + BuiltinNames[i].Length + sizeof(UNICODE_NULL));
3129 Count++;
3130 }
3131 }
3132
3133 for (i = 0; i < AccountMemberCount; i++)
3134 {
3135 if (AccountNames[i].Length > 0)
3136 {
3137 Size += (sizeof(LOCALGROUP_USERS_INFO_0) + AccountNames[i].Length + sizeof(UNICODE_NULL));
3138 Count++;
3139 }
3140 }
3141
3142 if (Size == 0)
3143 {
3144 ApiStatus = NERR_Success;
3145 goto done;
3146 }
3147
3148 /* Allocate buffer */
3149 ApiStatus = NetApiBufferAllocate(Size, (LPVOID*)&Buffer);
3150 if (ApiStatus != NERR_Success)
3151 goto done;
3152
3153 ZeroMemory(Buffer, Size);
3154
3155 StrPtr = (LPWSTR)((INT_PTR)Buffer + Count * sizeof(LOCALGROUP_USERS_INFO_0));
3156
3157 /* Copy data to the allocated buffer */
3158 Index = 0;
3159 for (i = 0; i < BuiltinMemberCount; i++)
3160 {
3161 if (BuiltinNames[i].Length > 0)
3162 {
3163 CopyMemory(StrPtr,
3164 BuiltinNames[i].Buffer,
3165 BuiltinNames[i].Length);
3166 Buffer[Index].lgrui0_name = StrPtr;
3167
3168 StrPtr = (LPWSTR)((INT_PTR)StrPtr + BuiltinNames[i].Length + sizeof(UNICODE_NULL));
3169 Index++;
3170 }
3171 }
3172
3173 for (i = 0; i < AccountMemberCount; i++)
3174 {
3175 if (AccountNames[i].Length > 0)
3176 {
3177 CopyMemory(StrPtr,
3178 AccountNames[i].Buffer,
3179 AccountNames[i].Length);
3180 Buffer[Index].lgrui0_name = StrPtr;
3181
3182 StrPtr = (LPWSTR)((INT_PTR)StrPtr + AccountNames[i].Length + sizeof(UNICODE_NULL));
3183 Index++;
3184 }
3185 }
3186
3187 done:
3188 if (AccountNames != NULL)
3189 SamFreeMemory(AccountNames);
3190
3191 if (BuiltinNames != NULL)
3192 SamFreeMemory(BuiltinNames);
3193
3194 if (AccountAliases != NULL)
3195 SamFreeMemory(AccountAliases);
3196
3197 if (BuiltinAliases != NULL)
3198 SamFreeMemory(BuiltinAliases);
3199
3200 if (RelativeIds != NULL)
3201 SamFreeMemory(RelativeIds);
3202
3203 if (Use != NULL)
3204 SamFreeMemory(Use);
3205
3206 if (UserSid != NULL)
3207 NetApiBufferFree(UserSid);
3208
3209 if (AccountDomainSid != NULL)
3210 RtlFreeHeap(RtlGetProcessHeap(), 0, AccountDomainSid);
3211
3212 if (AccountDomainHandle != NULL)
3213 SamCloseHandle(AccountDomainHandle);
3214
3215 if (BuiltinDomainHandle != NULL)
3216 SamCloseHandle(BuiltinDomainHandle);
3217
3218 if (ServerHandle != NULL)
3219 SamCloseHandle(ServerHandle);
3220
3221 if (ApiStatus != NERR_Success && ApiStatus != ERROR_MORE_DATA)
3222 {
3223 *entriesread = 0;
3224 *totalentries = 0;
3225 }
3226 else
3227 {
3228 *entriesread = Count;
3229 *totalentries = Count;
3230 }
3231
3232 *bufptr = (LPBYTE)Buffer;
3233
3234 return ApiStatus;
3235 }
3236
3237
3238 /******************************************************************************
3239 * NetUserModalsGet (NETAPI32.@)
3240 *
3241 * Retrieves global information for all users and global groups in the security
3242 * database.
3243 *
3244 * PARAMS
3245 * servername [I] Specifies the DNS or the NetBIOS name of the remote server
3246 * on which the function is to execute.
3247 * level [I] Information level of the data.
3248 * 0 Return global passwords parameters. bufptr points to a
3249 * USER_MODALS_INFO_0 struct.
3250 * 1 Return logon server and domain controller information. bufptr
3251 * points to a USER_MODALS_INFO_1 struct.
3252 * 2 Return domain name and identifier. bufptr points to a
3253 * USER_MODALS_INFO_2 struct.
3254 * 3 Return lockout information. bufptr points to a USER_MODALS_INFO_3
3255 * struct.
3256 * bufptr [O] Buffer that receives the data.
3257 *
3258 * RETURNS
3259 * Success: NERR_Success.
3260 * Failure:
3261 * ERROR_ACCESS_DENIED - the user does not have access to the info.
3262 * NERR_InvalidComputer - computer name is invalid.
3263 */
3264 NET_API_STATUS
3265 WINAPI
3266 NetUserModalsGet(LPCWSTR servername,
3267 DWORD level,
3268 LPBYTE *bufptr)
3269 {
3270 UNICODE_STRING ServerName;
3271 SAM_HANDLE ServerHandle = NULL;
3272 SAM_HANDLE DomainHandle = NULL;
3273 PSID DomainSid = NULL;
3274 PDOMAIN_PASSWORD_INFORMATION PasswordInfo = NULL;
3275 PDOMAIN_LOGOFF_INFORMATION LogoffInfo = NULL;
3276 PDOMAIN_SERVER_ROLE_INFORMATION ServerRoleInfo = NULL;
3277 PDOMAIN_REPLICATION_INFORMATION ReplicationInfo = NULL;
3278 PDOMAIN_NAME_INFORMATION NameInfo = NULL;
3279 PDOMAIN_LOCKOUT_INFORMATION LockoutInfo = NULL;
3280 ULONG DesiredAccess;
3281 ULONG BufferSize;
3282 PUSER_MODALS_INFO_0 umi0;
3283 PUSER_MODALS_INFO_1 umi1;
3284 PUSER_MODALS_INFO_2 umi2;
3285 PUSER_MODALS_INFO_3 umi3;
3286 NET_API_STATUS ApiStatus = NERR_Success;
3287 NTSTATUS Status = STATUS_SUCCESS;
3288
3289 TRACE("(%s %d %p)\n", debugstr_w(servername), level, bufptr);
3290
3291 *bufptr = NULL;
3292
3293 if (servername != NULL)
3294 RtlInitUnicodeString(&ServerName, servername);
3295
3296 /* Connect to the SAM Server */
3297 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
3298 &ServerHandle,
3299 SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
3300 NULL);
3301 if (!NT_SUCCESS(Status))
3302 {
3303 ERR("SamConnect failed (Status %08lx)\n", Status);
3304 ApiStatus = NetpNtStatusToApiStatus(Status);
3305 goto done;
3306 }
3307
3308 /* Get the Account Domain SID */
3309 Status = GetAccountDomainSid((servername != NULL) ? &ServerName : NULL,
3310 &DomainSid);
3311 if (!NT_SUCCESS(Status))
3312 {
3313 ERR("GetAccountDomainSid failed (Status %08lx)\n", Status);
3314 ApiStatus = NetpNtStatusToApiStatus(Status);
3315 goto done;
3316 }
3317
3318 switch (level)
3319 {
3320 case 0:
3321 DesiredAccess = DOMAIN_READ_OTHER_PARAMETERS | DOMAIN_READ_PASSWORD_PARAMETERS;
3322 break;
3323
3324 case 1:
3325 DesiredAccess = DOMAIN_READ_OTHER_PARAMETERS;
3326 break;
3327
3328 case 2:
3329 DesiredAccess = DOMAIN_READ_OTHER_PARAMETERS;
3330 break;
3331
3332 case 3:
3333 DesiredAccess = DOMAIN_READ_PASSWORD_PARAMETERS;
3334 break;
3335
3336 default:
3337 ApiStatus = ERROR_INVALID_LEVEL;
3338 goto done;
3339 }
3340
3341 /* Open the Account Domain */
3342 Status = SamOpenDomain(ServerHandle,
3343 DesiredAccess,
3344 DomainSid,
3345 &DomainHandle);
3346 if (!NT_SUCCESS(Status))
3347 {
3348 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
3349 ApiStatus = NetpNtStatusToApiStatus(Status);
3350 goto done;
3351 }
3352
3353 switch (level)
3354 {
3355 case 0:
3356 /* return global passwords parameters */
3357 Status = SamQueryInformationDomain(DomainHandle,
3358 DomainPasswordInformation,
3359 (PVOID*)&PasswordInfo);
3360 if (!NT_SUCCESS(Status))
3361 {
3362 ApiStatus = NetpNtStatusToApiStatus(Status);
3363 goto done;
3364 }
3365
3366 Status = SamQueryInformationDomain(DomainHandle,
3367 DomainLogoffInformation,
3368 (PVOID*)&LogoffInfo);
3369 if (!NT_SUCCESS(Status))
3370 {
3371 ApiStatus = NetpNtStatusToApiStatus(Status);
3372 goto done;
3373 }
3374
3375 BufferSize = sizeof(USER_MODALS_INFO_0);
3376 break;
3377
3378 case 1:
3379 /* return logon server and domain controller info */
3380 Status = SamQueryInformationDomain(DomainHandle,
3381 DomainServerRoleInformation,
3382 (PVOID*)&ServerRoleInfo);
3383 if (!NT_SUCCESS(Status))
3384 {
3385 ApiStatus = NetpNtStatusToApiStatus(Status);
3386 goto done;
3387 }
3388
3389 Status = SamQueryInformationDomain(DomainHandle,
3390 DomainReplicationInformation,
3391 (PVOID*)&ReplicationInfo);
3392 if (!NT_SUCCESS(Status))
3393 {
3394 ApiStatus = NetpNtStatusToApiStatus(Status);
3395 goto done;
3396 }
3397
3398 BufferSize = sizeof(USER_MODALS_INFO_1) +
3399 ReplicationInfo->ReplicaSourceNodeName.Length + sizeof(WCHAR);
3400 break;
3401
3402 case 2:
3403 /* return domain name and identifier */
3404 Status = SamQueryInformationDomain(DomainHandle,
3405 DomainNameInformation,
3406 (PVOID*)&NameInfo);
3407 if (!NT_SUCCESS(Status))
3408 {
3409 ApiStatus = NetpNtStatusToApiStatus(Status);
3410 goto done;
3411 }
3412
3413 BufferSize = sizeof( USER_MODALS_INFO_2 ) +
3414 NameInfo->DomainName.Length + sizeof(WCHAR) +
3415 RtlLengthSid(DomainSid);
3416 break;
3417
3418 case 3:
3419 /* return lockout information */
3420 Status = SamQueryInformationDomain(DomainHandle,
3421 DomainLockoutInformation,
3422 (PVOID*)&LockoutInfo);
3423 if (!NT_SUCCESS(Status))
3424 {
3425 ApiStatus = NetpNtStatusToApiStatus(Status);
3426 goto done;
3427 }
3428
3429 BufferSize = sizeof(USER_MODALS_INFO_3);
3430 break;
3431
3432 default:
3433 TRACE("Invalid level %d is specified\n", level);
3434 ApiStatus = ERROR_INVALID_LEVEL;
3435 goto done;
3436 }
3437
3438
3439 ApiStatus = NetApiBufferAllocate(BufferSize,
3440 (LPVOID *)bufptr);
3441 if (ApiStatus != NERR_Success)
3442 {
3443 WARN("NetApiBufferAllocate() failed\n");
3444 goto done;
3445 }
3446
3447 switch (level)
3448 {
3449 case 0:
3450 umi0 = (PUSER_MODALS_INFO_0)*bufptr;
3451
3452 umi0->usrmod0_min_passwd_len = PasswordInfo->MinPasswordLength;
3453 umi0->usrmod0_max_passwd_age = (ULONG)(PasswordInfo->MaxPasswordAge.QuadPart / 10000000);
3454 umi0->usrmod0_min_passwd_age =
3455 DeltaTimeToSeconds(PasswordInfo->MinPasswordAge);
3456 umi0->usrmod0_force_logoff =
3457 DeltaTimeToSeconds(LogoffInfo->ForceLogoff);
3458 umi0->usrmod0_password_hist_len = PasswordInfo->PasswordHistoryLength;
3459 break;
3460
3461 case 1:
3462 umi1 = (PUSER_MODALS_INFO_1)*bufptr;
3463
3464 switch (ServerRoleInfo->DomainServerRole)
3465 {
3466
3467 umi1->usrmod1_role = UAS_ROLE_STANDALONE;
3468 umi1->usrmod1_role = UAS_ROLE_MEMBER;
3469
3470 case DomainServerRolePrimary:
3471 umi1->usrmod1_role = UAS_ROLE_PRIMARY;
3472 break;
3473
3474 case DomainServerRoleBackup:
3475 umi1->usrmod1_role = UAS_ROLE_BACKUP;
3476 break;
3477
3478 default:
3479 ApiStatus = NERR_InternalError;
3480 goto done;
3481 }
3482
3483 umi1->usrmod1_primary = (LPWSTR)(*bufptr + sizeof(USER_MODALS_INFO_1));
3484 RtlCopyMemory(umi1->usrmod1_primary,
3485 ReplicationInfo->ReplicaSourceNodeName.Buffer,
3486 ReplicationInfo->ReplicaSourceNodeName.Length);
3487 umi1->usrmod1_primary[ReplicationInfo->ReplicaSourceNodeName.Length / sizeof(WCHAR)] = UNICODE_NULL;
3488 break;
3489
3490 case 2:
3491 umi2 = (PUSER_MODALS_INFO_2)*bufptr;
3492
3493 umi2->usrmod2_domain_name = (LPWSTR)(*bufptr + sizeof(USER_MODALS_INFO_2));
3494 RtlCopyMemory(umi2->usrmod2_domain_name,
3495 NameInfo->DomainName.Buffer,
3496 NameInfo->DomainName.Length);
3497 umi2->usrmod2_domain_name[NameInfo->DomainName.Length / sizeof(WCHAR)] = UNICODE_NULL;
3498
3499 umi2->usrmod2_domain_id = *bufptr +
3500 sizeof(USER_MODALS_INFO_2) +
3501 NameInfo->DomainName.Length + sizeof(WCHAR);
3502 RtlCopyMemory(umi2->usrmod2_domain_id,
3503 DomainSid,
3504 RtlLengthSid(DomainSid));
3505 break;
3506
3507 case 3:
3508 umi3 = (PUSER_MODALS_INFO_3)*bufptr;
3509 umi3->usrmod3_lockout_duration =
3510 DeltaTimeToSeconds(LockoutInfo->LockoutDuration);
3511 umi3->usrmod3_lockout_observation_window =
3512 DeltaTimeToSeconds(LockoutInfo->LockoutObservationWindow );
3513 umi3->usrmod3_lockout_threshold = LockoutInfo->LockoutThreshold;
3514 break;
3515 }
3516
3517 done:
3518 if (LockoutInfo != NULL)
3519 SamFreeMemory(LockoutInfo);
3520
3521 if (NameInfo != NULL)
3522 SamFreeMemory(NameInfo);
3523
3524 if (ReplicationInfo != NULL)
3525 SamFreeMemory(ReplicationInfo);
3526
3527 if (ServerRoleInfo != NULL)
3528 SamFreeMemory(ServerRoleInfo);
3529
3530 if (LogoffInfo != NULL)
3531 SamFreeMemory(LogoffInfo);
3532
3533 if (PasswordInfo != NULL)
3534 SamFreeMemory(PasswordInfo);
3535
3536 if (DomainSid != NULL)
3537 RtlFreeHeap(RtlGetProcessHeap(), 0, DomainSid);
3538
3539 if (DomainHandle != NULL)
3540 SamCloseHandle(DomainHandle);
3541
3542 if (ServerHandle != NULL)
3543 SamCloseHandle(ServerHandle);
3544
3545 return ApiStatus;
3546 }
3547
3548
3549 /******************************************************************************
3550 * NetUserModalsSet (NETAPI32.@)
3551 */
3552 NET_API_STATUS
3553 WINAPI
3554 NetUserModalsSet(IN LPCWSTR servername,
3555 IN DWORD level,
3556 IN LPBYTE buf,
3557 OUT LPDWORD parm_err)
3558 {
3559 FIXME("(%s %d %p %p)\n", debugstr_w(servername), level, buf, parm_err);
3560 return ERROR_ACCESS_DENIED;
3561 }
3562
3563
3564 /******************************************************************************
3565 * NetUserSetGroups (NETAPI32.@)
3566 */
3567 NET_API_STATUS
3568 WINAPI
3569 NetUserSetGroups(LPCWSTR servername,
3570 LPCWSTR username,
3571 DWORD level,
3572 LPBYTE buf,
3573 DWORD num_entries)
3574 {
3575 FIXME("(%s %s %lu %p %lu)\n",
3576 debugstr_w(servername), debugstr_w(username), level, buf, num_entries);
3577 return ERROR_ACCESS_DENIED;
3578 }
3579
3580
3581 /******************************************************************************
3582 * NetUserSetInfo (NETAPI32.@)
3583 */
3584 NET_API_STATUS
3585 WINAPI
3586 NetUserSetInfo(LPCWSTR servername,
3587 LPCWSTR username,
3588 DWORD level,
3589 LPBYTE buf,
3590 LPDWORD parm_err)
3591 {
3592 UNICODE_STRING ServerName;
3593 UNICODE_STRING UserName;
3594 SAM_HANDLE ServerHandle = NULL;
3595 SAM_HANDLE AccountDomainHandle = NULL;
3596 SAM_HANDLE UserHandle = NULL;
3597 NET_API_STATUS ApiStatus = NERR_Success;
3598 NTSTATUS Status = STATUS_SUCCESS;
3599
3600 TRACE("(%s %s %lu %p %p)\n",
3601 debugstr_w(servername), debugstr_w(username), level, buf, parm_err);
3602
3603 if (parm_err != NULL)
3604 *parm_err = PARM_ERROR_NONE;
3605
3606 /* Check the info level */
3607 switch (level)
3608 {
3609 case 0:
3610 case 1:
3611 case 2:
3612 case 3:
3613 // case 4:
3614 // case 21:
3615 // case 22:
3616 case 1003:
3617 // case 1005:
3618 case 1006:
3619 case 1007:
3620 case 1008:
3621 case 1009:
3622 // case 1010:
3623 case 1011:
3624 case 1012:
3625 case 1013:
3626 case 1014:
3627 // case 1017:
3628 // case 1018:
3629 // case 1020:
3630 case 1024:
3631 case 1025:
3632 case 1051:
3633 case 1052:
3634 case 1053:
3635 break;
3636
3637 default:
3638 return ERROR_INVALID_LEVEL;
3639 }
3640
3641 if (servername != NULL)
3642 RtlInitUnicodeString(&ServerName, servername);
3643
3644 RtlInitUnicodeString(&UserName, username);
3645
3646 /* Connect to the SAM Server */
3647 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
3648 &ServerHandle,
3649 SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
3650 NULL);
3651 if (!NT_SUCCESS(Status))
3652 {
3653 ERR("SamConnect failed (Status %08lx)\n", Status);
3654 ApiStatus = NetpNtStatusToApiStatus(Status);
3655 goto done;
3656 }
3657
3658 /* Open the Account Domain */
3659 Status = OpenAccountDomain(ServerHandle,
3660 (servername != NULL) ? &ServerName : NULL,
3661 DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP | DOMAIN_READ_PASSWORD_PARAMETERS,
3662 &AccountDomainHandle);
3663 if (!NT_SUCCESS(Status))
3664 {
3665 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
3666 ApiStatus = NetpNtStatusToApiStatus(Status);
3667 goto done;
3668 }
3669
3670 /* Open the User Account */
3671 ApiStatus = OpenUserByName(AccountDomainHandle,
3672 &UserName,
3673 USER_ALL_ACCESS,
3674 &UserHandle);
3675 if (ApiStatus != NERR_Success)
3676 {
3677 ERR("OpenUserByName failed (ApiStatus %lu)\n", ApiStatus);
3678 goto done;
3679 }
3680
3681 /* Set user information */
3682 ApiStatus = SetUserInfo(UserHandle,
3683 buf,
3684 level);
3685 if (ApiStatus != NERR_Success)
3686 {
3687 ERR("SetUserInfo failed (Status %lu)\n", ApiStatus);
3688 }
3689
3690 done:
3691 if (UserHandle != NULL)
3692 SamCloseHandle(UserHandle);
3693
3694 if (AccountDomainHandle != NULL)
3695 SamCloseHandle(AccountDomainHandle);
3696
3697 if (ServerHandle != NULL)
3698 SamCloseHandle(ServerHandle);
3699
3700 return ApiStatus;
3701 }
3702
3703 /* EOF */