Synchronize with trunk revision 59781.
[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 SamCloseHandle(UserHandle);
2100
2101 if (DomainHandle != NULL)
2102 SamCloseHandle(DomainHandle);
2103
2104 if (ServerHandle != NULL)
2105 SamCloseHandle(ServerHandle);
2106
2107 return ApiStatus;
2108 }
2109
2110
2111 /******************************************************************************
2112 * NetUserChangePassword (NETAPI32.@)
2113 * PARAMS
2114 * domainname [I] Optional. Domain on which the user resides or the logon
2115 * domain of the current user if NULL.
2116 * username [I] Optional. Username to change the password for or the name
2117 * of the current user if NULL.
2118 * oldpassword [I] The user's current password.
2119 * newpassword [I] The password that the user will be changed to using.
2120 *
2121 * RETURNS
2122 * Success: NERR_Success.
2123 * Failure: NERR_* failure code or win error code.
2124 *
2125 */
2126 NET_API_STATUS
2127 WINAPI
2128 NetUserChangePassword(LPCWSTR domainname,
2129 LPCWSTR username,
2130 LPCWSTR oldpassword,
2131 LPCWSTR newpassword)
2132 {
2133 PMSV1_0_CHANGEPASSWORD_REQUEST RequestBuffer = NULL;
2134 PMSV1_0_CHANGEPASSWORD_RESPONSE ResponseBuffer = NULL;
2135 ULONG RequestBufferSize;
2136 ULONG ResponseBufferSize = 0;
2137 LPWSTR Ptr;
2138 ANSI_STRING PackageName;
2139 ULONG AuthenticationPackage = 0;
2140 HANDLE LsaHandle = NULL;
2141 NET_API_STATUS ApiStatus = NERR_Success;
2142 NTSTATUS Status = STATUS_SUCCESS;
2143 NTSTATUS ProtocolStatus;
2144
2145 TRACE("(%s, %s, ..., ...)\n", debugstr_w(domainname), debugstr_w(username));
2146
2147 /* FIXME: handle null domain or user name */
2148
2149 /* Check the parameters */
2150 if ((oldpassword == NULL) ||
2151 (newpassword == NULL))
2152 return ERROR_INVALID_PARAMETER;
2153
2154 /* Connect to the LSA server */
2155 Status = LsaConnectUntrusted(&LsaHandle);
2156 if (!NT_SUCCESS(Status))
2157 return NetpNtStatusToApiStatus(Status);
2158
2159 /* Get the authentication package ID */
2160 RtlInitAnsiString(&PackageName,
2161 MSV1_0_PACKAGE_NAME);
2162
2163 Status = LsaLookupAuthenticationPackage(LsaHandle,
2164 &PackageName,
2165 &AuthenticationPackage);
2166 if (!NT_SUCCESS(Status))
2167 {
2168 ApiStatus = NetpNtStatusToApiStatus(Status);
2169 goto done;
2170 }
2171
2172 /* Calculate the request buffer size */
2173 RequestBufferSize = sizeof(MSV1_0_CHANGEPASSWORD_REQUEST) +
2174 ((wcslen(domainname) + 1) * sizeof(WCHAR)) +
2175 ((wcslen(username) + 1) * sizeof(WCHAR)) +
2176 ((wcslen(oldpassword) + 1) * sizeof(WCHAR)) +
2177 ((wcslen(newpassword) + 1) * sizeof(WCHAR));
2178
2179 /* Allocate the request buffer */
2180 ApiStatus = NetApiBufferAllocate(RequestBufferSize,
2181 (PVOID*)&RequestBuffer);
2182 if (ApiStatus != NERR_Success)
2183 goto done;
2184
2185 /* Initialize the request buffer */
2186 RequestBuffer->MessageType = MsV1_0ChangePassword;
2187 RequestBuffer->Impersonating = TRUE;
2188
2189 Ptr = (LPWSTR)((ULONG_PTR)RequestBuffer + sizeof(MSV1_0_CHANGEPASSWORD_REQUEST));
2190
2191 /* Pack the domain name */
2192 RequestBuffer->DomainName.Length = wcslen(domainname) * sizeof(WCHAR);
2193 RequestBuffer->DomainName.MaximumLength = RequestBuffer->DomainName.Length + sizeof(WCHAR);
2194 RequestBuffer->DomainName.Buffer = Ptr;
2195
2196 RtlCopyMemory(RequestBuffer->DomainName.Buffer,
2197 domainname,
2198 RequestBuffer->DomainName.MaximumLength);
2199
2200 Ptr = (LPWSTR)((ULONG_PTR)Ptr + RequestBuffer->DomainName.MaximumLength);
2201
2202 /* Pack the user name */
2203 RequestBuffer->AccountName.Length = wcslen(username) * sizeof(WCHAR);
2204 RequestBuffer->AccountName.MaximumLength = RequestBuffer->AccountName.Length + sizeof(WCHAR);
2205 RequestBuffer->AccountName.Buffer = Ptr;
2206
2207 RtlCopyMemory(RequestBuffer->AccountName.Buffer,
2208 username,
2209 RequestBuffer->AccountName.MaximumLength);
2210
2211 Ptr = (LPWSTR)((ULONG_PTR)Ptr + RequestBuffer->AccountName.MaximumLength);
2212
2213 /* Pack the old password */
2214 RequestBuffer->OldPassword.Length = wcslen(oldpassword) * sizeof(WCHAR);
2215 RequestBuffer->OldPassword.MaximumLength = RequestBuffer->OldPassword.Length + sizeof(WCHAR);
2216 RequestBuffer->OldPassword.Buffer = Ptr;
2217
2218 RtlCopyMemory(RequestBuffer->OldPassword.Buffer,
2219 oldpassword,
2220 RequestBuffer->OldPassword.MaximumLength);
2221
2222 Ptr = (LPWSTR)((ULONG_PTR)Ptr + RequestBuffer->OldPassword.MaximumLength);
2223
2224 /* Pack the new password */
2225 RequestBuffer->NewPassword.Length = wcslen(newpassword) * sizeof(WCHAR);
2226 RequestBuffer->NewPassword.MaximumLength = RequestBuffer->NewPassword.Length + sizeof(WCHAR);
2227 RequestBuffer->NewPassword.Buffer = Ptr;
2228
2229 RtlCopyMemory(RequestBuffer->NewPassword.Buffer,
2230 newpassword,
2231 RequestBuffer->NewPassword.MaximumLength);
2232
2233 /* Call the authentication package */
2234 Status = LsaCallAuthenticationPackage(LsaHandle,
2235 AuthenticationPackage,
2236 RequestBuffer,
2237 RequestBufferSize,
2238 (PVOID*)&ResponseBuffer,
2239 &ResponseBufferSize,
2240 &ProtocolStatus);
2241 if (!NT_SUCCESS(Status))
2242 {
2243 ApiStatus = NetpNtStatusToApiStatus(Status);
2244 goto done;
2245 }
2246
2247 if (!NT_SUCCESS(ProtocolStatus))
2248 {
2249 ApiStatus = NetpNtStatusToApiStatus(ProtocolStatus);
2250 goto done;
2251 }
2252
2253 done:
2254 if (RequestBuffer != NULL)
2255 NetApiBufferFree(RequestBuffer);
2256
2257 if (ResponseBuffer != NULL)
2258 LsaFreeReturnBuffer(ResponseBuffer);
2259
2260 if (LsaHandle != NULL)
2261 NtClose(LsaHandle);
2262
2263 return ApiStatus;
2264 }
2265
2266
2267 /************************************************************
2268 * NetUserDel (NETAPI32.@)
2269 */
2270 NET_API_STATUS
2271 WINAPI
2272 NetUserDel(LPCWSTR servername,
2273 LPCWSTR username)
2274 {
2275 UNICODE_STRING ServerName;
2276 UNICODE_STRING UserName;
2277 SAM_HANDLE ServerHandle = NULL;
2278 SAM_HANDLE DomainHandle = NULL;
2279 SAM_HANDLE UserHandle = NULL;
2280 NET_API_STATUS ApiStatus = NERR_Success;
2281 NTSTATUS Status = STATUS_SUCCESS;
2282
2283 TRACE("(%s, %s)\n", debugstr_w(servername), debugstr_w(username));
2284
2285 if (servername != NULL)
2286 RtlInitUnicodeString(&ServerName, servername);
2287
2288 RtlInitUnicodeString(&UserName, username);
2289
2290 /* Connect to the SAM Server */
2291 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
2292 &ServerHandle,
2293 SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
2294 NULL);
2295 if (!NT_SUCCESS(Status))
2296 {
2297 ERR("SamConnect failed (Status %08lx)\n", Status);
2298 ApiStatus = NetpNtStatusToApiStatus(Status);
2299 goto done;
2300 }
2301
2302 /* Open the Builtin Domain */
2303 Status = OpenBuiltinDomain(ServerHandle,
2304 DOMAIN_LOOKUP,
2305 &DomainHandle);
2306 if (!NT_SUCCESS(Status))
2307 {
2308 ERR("OpenBuiltinDomain failed (Status %08lx)\n", Status);
2309 ApiStatus = NetpNtStatusToApiStatus(Status);
2310 goto done;
2311 }
2312
2313 /* Open the user account in the builtin domain */
2314 ApiStatus = OpenUserByName(DomainHandle,
2315 &UserName,
2316 DELETE,
2317 &UserHandle);
2318 if (ApiStatus != NERR_Success && ApiStatus != ERROR_NONE_MAPPED)
2319 {
2320 TRACE("OpenUserByName failed (ApiStatus %lu)\n", ApiStatus);
2321 goto done;
2322 }
2323
2324 if (UserHandle == NULL)
2325 {
2326 if (DomainHandle != NULL)
2327 {
2328 SamCloseHandle(DomainHandle);
2329 DomainHandle = NULL;
2330 }
2331
2332 /* Open the Acount Domain */
2333 Status = OpenAccountDomain(ServerHandle,
2334 (servername != NULL) ? &ServerName : NULL,
2335 DOMAIN_LOOKUP,
2336 &DomainHandle);
2337 if (!NT_SUCCESS(Status))
2338 {
2339 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
2340 ApiStatus = NetpNtStatusToApiStatus(Status);
2341 goto done;
2342 }
2343
2344 /* Open the user account in the account domain */
2345 ApiStatus = OpenUserByName(DomainHandle,
2346 &UserName,
2347 DELETE,
2348 &UserHandle);
2349 if (ApiStatus != NERR_Success)
2350 {
2351 ERR("OpenUserByName failed (ApiStatus %lu)\n", ApiStatus);
2352 if (ApiStatus == ERROR_NONE_MAPPED)
2353 ApiStatus = NERR_GroupNotFound;
2354 goto done;
2355 }
2356 }
2357
2358 /* Delete the user */
2359 Status = SamDeleteUser(UserHandle);
2360 if (!NT_SUCCESS(Status))
2361 {
2362 ERR("SamDeleteUser failed (Status %08lx)\n", Status);
2363 ApiStatus = NetpNtStatusToApiStatus(Status);
2364 goto done;
2365 }
2366
2367 done:
2368 if (UserHandle != NULL)
2369 SamCloseHandle(UserHandle);
2370
2371 if (DomainHandle != NULL)
2372 SamCloseHandle(DomainHandle);
2373
2374 if (ServerHandle != NULL)
2375 SamCloseHandle(ServerHandle);
2376
2377 return ApiStatus;
2378 }
2379
2380
2381 /************************************************************
2382 * NetUserEnum (NETAPI32.@)
2383 */
2384 NET_API_STATUS
2385 WINAPI
2386 NetUserEnum(LPCWSTR servername,
2387 DWORD level,
2388 DWORD filter,
2389 LPBYTE* bufptr,
2390 DWORD prefmaxlen,
2391 LPDWORD entriesread,
2392 LPDWORD totalentries,
2393 LPDWORD resume_handle)
2394 {
2395 UNICODE_STRING ServerName;
2396 PSAM_RID_ENUMERATION CurrentUser;
2397 PENUM_CONTEXT EnumContext = NULL;
2398 LPVOID Buffer = NULL;
2399 ULONG i;
2400 SAM_HANDLE UserHandle = NULL;
2401 PUSER_ALL_INFORMATION UserInfo = NULL;
2402
2403 NET_API_STATUS ApiStatus = NERR_Success;
2404 NTSTATUS Status = STATUS_SUCCESS;
2405
2406 TRACE("(%s %d 0x%d %p %d %p %p %p)\n", debugstr_w(servername), level,
2407 filter, bufptr, prefmaxlen, entriesread, totalentries, resume_handle);
2408
2409 *entriesread = 0;
2410 *totalentries = 0;
2411 *bufptr = NULL;
2412
2413 if (servername != NULL)
2414 RtlInitUnicodeString(&ServerName, servername);
2415
2416 if (resume_handle != NULL && *resume_handle != 0)
2417 {
2418 EnumContext = (PENUM_CONTEXT)*resume_handle;
2419 }
2420 else
2421 {
2422 ApiStatus = NetApiBufferAllocate(sizeof(ENUM_CONTEXT), (PVOID*)&EnumContext);
2423 if (ApiStatus != NERR_Success)
2424 goto done;
2425
2426 EnumContext->EnumerationContext = 0;
2427 EnumContext->Buffer = NULL;
2428 EnumContext->Count = 0;
2429 EnumContext->Index = 0;
2430 EnumContext->BuiltinDone = FALSE;
2431
2432 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
2433 &EnumContext->ServerHandle,
2434 SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
2435 NULL);
2436 if (!NT_SUCCESS(Status))
2437 {
2438 ERR("SamConnect failed (Status %08lx)\n", Status);
2439 ApiStatus = NetpNtStatusToApiStatus(Status);
2440 goto done;
2441 }
2442
2443 Status = OpenAccountDomain(EnumContext->ServerHandle,
2444 (servername != NULL) ? &ServerName : NULL,
2445 DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP,
2446 &EnumContext->AccountDomainHandle);
2447 if (!NT_SUCCESS(Status))
2448 {
2449 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
2450 ApiStatus = NetpNtStatusToApiStatus(Status);
2451 goto done;
2452 }
2453
2454 Status = OpenBuiltinDomain(EnumContext->ServerHandle,
2455 DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP,
2456 &EnumContext->BuiltinDomainHandle);
2457 if (!NT_SUCCESS(Status))
2458 {
2459 ERR("OpenBuiltinDomain failed (Status %08lx)\n", Status);
2460 ApiStatus = NetpNtStatusToApiStatus(Status);
2461 goto done;
2462 }
2463 }
2464
2465 // while (TRUE)
2466 // {
2467 TRACE("EnumContext->Index: %lu\n", EnumContext->Index);
2468 TRACE("EnumContext->Count: %lu\n", EnumContext->Count);
2469
2470 if (EnumContext->Index >= EnumContext->Count)
2471 {
2472 // if (EnumContext->BuiltinDone == TRUE)
2473 // {
2474 // ApiStatus = NERR_Success;
2475 // goto done;
2476 // }
2477
2478 TRACE("Calling SamEnumerateUsersInDomain\n");
2479 Status = SamEnumerateUsersInDomain(EnumContext->AccountDomainHandle, //BuiltinDomainHandle,
2480 &EnumContext->EnumerationContext,
2481 0,
2482 (PVOID *)&EnumContext->Buffer,
2483 prefmaxlen,
2484 &EnumContext->Count);
2485
2486 TRACE("SamEnumerateUsersInDomain returned (Status %08lx)\n", Status);
2487 if (!NT_SUCCESS(Status))
2488 {
2489 ERR("SamEnumerateUsersInDomain failed (Status %08lx)\n", Status);
2490 ApiStatus = NetpNtStatusToApiStatus(Status);
2491 goto done;
2492 }
2493
2494 if (Status == STATUS_MORE_ENTRIES)
2495 {
2496 ApiStatus = NERR_BufTooSmall;
2497 goto done;
2498 }
2499 else
2500 {
2501 EnumContext->BuiltinDone = TRUE;
2502 }
2503 }
2504
2505 TRACE("EnumContext: %lu\n", EnumContext);
2506 TRACE("EnumContext->Count: %lu\n", EnumContext->Count);
2507 TRACE("EnumContext->Buffer: %p\n", EnumContext->Buffer);
2508
2509 /* Get a pointer to the current user */
2510 CurrentUser = &EnumContext->Buffer[EnumContext->Index];
2511
2512 TRACE("RID: %lu\n", CurrentUser->RelativeId);
2513
2514 Status = SamOpenUser(EnumContext->AccountDomainHandle, //BuiltinDomainHandle,
2515 USER_READ_GENERAL | USER_READ_PREFERENCES | USER_READ_LOGON | USER_READ_ACCOUNT,
2516 CurrentUser->RelativeId,
2517 &UserHandle);
2518 if (!NT_SUCCESS(Status))
2519 {
2520 ERR("SamOpenUser failed (Status %08lx)\n", Status);
2521 ApiStatus = NetpNtStatusToApiStatus(Status);
2522 goto done;
2523 }
2524
2525 Status = SamQueryInformationUser(UserHandle,
2526 UserAllInformation,
2527 (PVOID *)&UserInfo);
2528 if (!NT_SUCCESS(Status))
2529 {
2530 ERR("SamQueryInformationUser failed (Status %08lx)\n", Status);
2531 ApiStatus = NetpNtStatusToApiStatus(Status);
2532 goto done;
2533 }
2534
2535 SamCloseHandle(UserHandle);
2536 UserHandle = NULL;
2537
2538 ApiStatus = BuildUserInfoBuffer(UserInfo,
2539 level,
2540 CurrentUser->RelativeId,
2541 &Buffer);
2542 if (ApiStatus != NERR_Success)
2543 {
2544 ERR("BuildUserInfoBuffer failed (ApiStatus %lu)\n", ApiStatus);
2545 goto done;
2546 }
2547
2548 if (UserInfo != NULL)
2549 {
2550 FreeUserInfo(UserInfo);
2551 UserInfo = NULL;
2552 }
2553
2554 EnumContext->Index++;
2555
2556 (*entriesread)++;
2557 // }
2558
2559 done:
2560 if (ApiStatus == NERR_Success && EnumContext->Index < EnumContext->Count)
2561 ApiStatus = ERROR_MORE_DATA;
2562
2563 if (EnumContext != NULL)
2564 *totalentries = EnumContext->Count;
2565
2566 if (resume_handle == NULL || ApiStatus != ERROR_MORE_DATA)
2567 {
2568 if (EnumContext != NULL)
2569 {
2570 if (EnumContext->BuiltinDomainHandle != NULL)
2571 SamCloseHandle(EnumContext->BuiltinDomainHandle);
2572
2573 if (EnumContext->AccountDomainHandle != NULL)
2574 SamCloseHandle(EnumContext->AccountDomainHandle);
2575
2576 if (EnumContext->ServerHandle != NULL)
2577 SamCloseHandle(EnumContext->ServerHandle);
2578
2579 if (EnumContext->Buffer != NULL)
2580 {
2581 for (i = 0; i < EnumContext->Count; i++)
2582 {
2583 SamFreeMemory(EnumContext->Buffer[i].Name.Buffer);
2584 }
2585
2586 SamFreeMemory(EnumContext->Buffer);
2587 }
2588
2589 NetApiBufferFree(EnumContext);
2590 EnumContext = NULL;
2591 }
2592 }
2593
2594 if (UserHandle != NULL)
2595 SamCloseHandle(UserHandle);
2596
2597 if (UserInfo != NULL)
2598 FreeUserInfo(UserInfo);
2599
2600 if (resume_handle != NULL)
2601 *resume_handle = (DWORD_PTR)EnumContext;
2602
2603 *bufptr = (LPBYTE)Buffer;
2604
2605 TRACE("return %lu\n", ApiStatus);
2606
2607 return ApiStatus;
2608 }
2609
2610
2611 /************************************************************
2612 * NetUserGetGroups (NETAPI32.@)
2613 */
2614 NET_API_STATUS
2615 WINAPI
2616 NetUserGetGroups(LPCWSTR servername,
2617 LPCWSTR username,
2618 DWORD level,
2619 LPBYTE *bufptr,
2620 DWORD prefixmaxlen,
2621 LPDWORD entriesread,
2622 LPDWORD totalentries)
2623 {
2624 UNICODE_STRING ServerName;
2625 UNICODE_STRING UserName;
2626 SAM_HANDLE ServerHandle = NULL;
2627 SAM_HANDLE AccountDomainHandle = NULL;
2628 SAM_HANDLE UserHandle = NULL;
2629 PSID AccountDomainSid = NULL;
2630 PULONG RelativeIds = NULL;
2631 PSID_NAME_USE Use = NULL;
2632 PGROUP_MEMBERSHIP GroupMembership = NULL;
2633 ULONG GroupCount;
2634
2635 NET_API_STATUS ApiStatus = NERR_Success;
2636 NTSTATUS Status = STATUS_SUCCESS;
2637
2638 TRACE("%s %s %d %p %d %p %p stub\n", debugstr_w(servername),
2639 debugstr_w(username), level, bufptr, prefixmaxlen, entriesread,
2640 totalentries);
2641
2642 if (servername != NULL)
2643 RtlInitUnicodeString(&ServerName, servername);
2644
2645 RtlInitUnicodeString(&UserName, username);
2646
2647 /* Connect to the SAM Server */
2648 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
2649 &ServerHandle,
2650 SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
2651 NULL);
2652 if (!NT_SUCCESS(Status))
2653 {
2654 ERR("SamConnect failed (Status %08lx)\n", Status);
2655 ApiStatus = NetpNtStatusToApiStatus(Status);
2656 goto done;
2657 }
2658
2659 /* Get the Account Domain SID */
2660 Status = GetAccountDomainSid((servername != NULL) ? &ServerName : NULL,
2661 &AccountDomainSid);
2662 if (!NT_SUCCESS(Status))
2663 {
2664 ERR("GetAccountDomainSid failed (Status %08lx)\n", Status);
2665 ApiStatus = NetpNtStatusToApiStatus(Status);
2666 goto done;
2667 }
2668
2669 /* Open the Account Domain */
2670 Status = SamOpenDomain(ServerHandle,
2671 DOMAIN_LOOKUP | DOMAIN_GET_ALIAS_MEMBERSHIP,
2672 AccountDomainSid,
2673 &AccountDomainHandle);
2674 if (!NT_SUCCESS(Status))
2675 {
2676 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
2677 ApiStatus = NetpNtStatusToApiStatus(Status);
2678 goto done;
2679 }
2680
2681 /* Get the RID for the given user name */
2682 Status = SamLookupNamesInDomain(AccountDomainHandle,
2683 1,
2684 &UserName,
2685 &RelativeIds,
2686 &Use);
2687 if (!NT_SUCCESS(Status))
2688 {
2689 ERR("SamLookupNamesInDomain failed (Status %08lx)\n", Status);
2690 ApiStatus = NetpNtStatusToApiStatus(Status);
2691 goto done;
2692 }
2693
2694 /* Fail, if it is not a user account */
2695 if (Use[0] != SidTypeUser)
2696 {
2697 ERR("Account is not a User!\n");
2698 ApiStatus = NERR_UserNotFound;
2699 goto done;
2700 }
2701
2702 /* Open the user object */
2703 Status = SamOpenUser(AccountDomainHandle,
2704 USER_LIST_GROUPS,
2705 RelativeIds[0],
2706 &UserHandle);
2707 if (!NT_SUCCESS(Status))
2708 {
2709 ERR("SamOpenUser failed (Status %08lx)\n", Status);
2710 ApiStatus = NetpNtStatusToApiStatus(Status);
2711 goto done;
2712 }
2713
2714 /* Get the group memberships of this user */
2715 Status = SamGetGroupsForUser(UserHandle,
2716 &GroupMembership,
2717 &GroupCount);
2718 if (!NT_SUCCESS(Status))
2719 {
2720 ERR("SamGetGroupsForUser failed (Status %08lx)\n", Status);
2721 ApiStatus = NetpNtStatusToApiStatus(Status);
2722 goto done;
2723 }
2724
2725 /* If there is no group membership, we're done */
2726 if (GroupCount == 0)
2727 {
2728 ApiStatus = NERR_Success;
2729 goto done;
2730 }
2731
2732
2733 done:
2734
2735 if (GroupMembership != NULL)
2736 SamFreeMemory(GroupMembership);
2737
2738 if (UserHandle != NULL)
2739 SamCloseHandle(UserHandle);
2740
2741 if (RelativeIds != NULL)
2742 SamFreeMemory(RelativeIds);
2743
2744 if (Use != NULL)
2745 SamFreeMemory(Use);
2746
2747 if (AccountDomainSid != NULL)
2748 RtlFreeHeap(RtlGetProcessHeap(), 0, AccountDomainSid);
2749
2750 if (AccountDomainHandle != NULL)
2751 SamCloseHandle(AccountDomainHandle);
2752
2753 if (ServerHandle != NULL)
2754 SamCloseHandle(ServerHandle);
2755
2756 if (ApiStatus != NERR_Success && ApiStatus != ERROR_MORE_DATA)
2757 {
2758 *entriesread = 0;
2759 *totalentries = 0;
2760 }
2761 else
2762 {
2763 // *entriesread = Count;
2764 // *totalentries = Count;
2765 }
2766
2767 // *bufptr = (LPBYTE)Buffer;
2768
2769 return ApiStatus;
2770
2771 #if 0
2772 *bufptr = NULL;
2773 *entriesread = 0;
2774 *totalentries = 0;
2775
2776 return ERROR_INVALID_LEVEL;
2777 #endif
2778 }
2779
2780
2781 /************************************************************
2782 * NetUserGetInfo (NETAPI32.@)
2783 */
2784 NET_API_STATUS
2785 WINAPI
2786 NetUserGetInfo(LPCWSTR servername,
2787 LPCWSTR username,
2788 DWORD level,
2789 LPBYTE* bufptr)
2790 {
2791 UNICODE_STRING ServerName;
2792 UNICODE_STRING UserName;
2793 SAM_HANDLE ServerHandle = NULL;
2794 SAM_HANDLE AccountDomainHandle = NULL;
2795 SAM_HANDLE UserHandle = NULL;
2796 PULONG RelativeIds = NULL;
2797 PSID_NAME_USE Use = NULL;
2798 PUSER_ALL_INFORMATION UserInfo = NULL;
2799 LPVOID Buffer = NULL;
2800 NET_API_STATUS ApiStatus = NERR_Success;
2801 NTSTATUS Status = STATUS_SUCCESS;
2802
2803 TRACE("(%s, %s, %d, %p)\n", debugstr_w(servername),
2804 debugstr_w(username), level, bufptr);
2805
2806 if (servername != NULL)
2807 RtlInitUnicodeString(&ServerName, servername);
2808
2809 RtlInitUnicodeString(&UserName, username);
2810
2811 /* Connect to the SAM Server */
2812 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
2813 &ServerHandle,
2814 SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
2815 NULL);
2816 if (!NT_SUCCESS(Status))
2817 {
2818 ERR("SamConnect failed (Status %08lx)\n", Status);
2819 ApiStatus = NetpNtStatusToApiStatus(Status);
2820 goto done;
2821 }
2822
2823 /* Open the Account Domain */
2824 Status = OpenAccountDomain(ServerHandle,
2825 (servername != NULL) ? &ServerName : NULL,
2826 DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP,
2827 &AccountDomainHandle);
2828 if (!NT_SUCCESS(Status))
2829 {
2830 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
2831 ApiStatus = NetpNtStatusToApiStatus(Status);
2832 goto done;
2833 }
2834
2835 /* Get the RID for the given user name */
2836 Status = SamLookupNamesInDomain(AccountDomainHandle,
2837 1,
2838 &UserName,
2839 &RelativeIds,
2840 &Use);
2841 if (!NT_SUCCESS(Status))
2842 {
2843 ERR("SamOpenDomain failed (Status %08lx)\n", Status);
2844 ApiStatus = NetpNtStatusToApiStatus(Status);
2845 goto done;
2846 }
2847
2848 /* Check if the account is a user account */
2849 if (Use[0] != SidTypeUser)
2850 {
2851 ERR("No user found!\n");
2852 ApiStatus = NERR_UserNotFound;
2853 goto done;
2854 }
2855
2856 TRACE("RID: %lu\n", RelativeIds[0]);
2857
2858 /* Open the user object */
2859 Status = SamOpenUser(AccountDomainHandle,
2860 USER_READ_GENERAL | USER_READ_PREFERENCES | USER_READ_LOGON | USER_READ_ACCOUNT,
2861 RelativeIds[0],
2862 &UserHandle);
2863 if (!NT_SUCCESS(Status))
2864 {
2865 ERR("SamOpenUser failed (Status %08lx)\n", Status);
2866 ApiStatus = NetpNtStatusToApiStatus(Status);
2867 goto done;
2868 }
2869
2870 Status = SamQueryInformationUser(UserHandle,
2871 UserAllInformation,
2872 (PVOID *)&UserInfo);
2873 if (!NT_SUCCESS(Status))
2874 {
2875 ERR("SamQueryInformationUser failed (Status %08lx)\n", Status);
2876 ApiStatus = NetpNtStatusToApiStatus(Status);
2877 goto done;
2878 }
2879
2880 ApiStatus = BuildUserInfoBuffer(UserInfo,
2881 level,
2882 RelativeIds[0],
2883 &Buffer);
2884 if (ApiStatus != NERR_Success)
2885 {
2886 ERR("BuildUserInfoBuffer failed (ApiStatus %08lu)\n", ApiStatus);
2887 goto done;
2888 }
2889
2890 done:
2891 if (UserInfo != NULL)
2892 FreeUserInfo(UserInfo);
2893
2894 if (UserHandle != NULL)
2895 SamCloseHandle(UserHandle);
2896
2897 if (RelativeIds != NULL)
2898 SamFreeMemory(RelativeIds);
2899
2900 if (Use != NULL)
2901 SamFreeMemory(Use);
2902
2903 if (AccountDomainHandle != NULL)
2904 SamCloseHandle(AccountDomainHandle);
2905
2906 if (ServerHandle != NULL)
2907 SamCloseHandle(ServerHandle);
2908
2909 *bufptr = (LPBYTE)Buffer;
2910
2911 return ApiStatus;
2912 }
2913
2914
2915 /************************************************************
2916 * NetUserGetLocalGroups (NETAPI32.@)
2917 */
2918 NET_API_STATUS
2919 WINAPI
2920 NetUserGetLocalGroups(LPCWSTR servername,
2921 LPCWSTR username,
2922 DWORD level,
2923 DWORD flags,
2924 LPBYTE* bufptr,
2925 DWORD prefmaxlen,
2926 LPDWORD entriesread,
2927 LPDWORD totalentries)
2928 {
2929 UNICODE_STRING ServerName;
2930 UNICODE_STRING UserName;
2931 SAM_HANDLE ServerHandle = NULL;
2932 SAM_HANDLE BuiltinDomainHandle = NULL;
2933 SAM_HANDLE AccountDomainHandle = NULL;
2934 PSID AccountDomainSid = NULL;
2935 PSID UserSid = NULL;
2936 PULONG RelativeIds = NULL;
2937 PSID_NAME_USE Use = NULL;
2938 ULONG BuiltinMemberCount = 0;
2939 ULONG AccountMemberCount = 0;
2940 PULONG BuiltinAliases = NULL;
2941 PULONG AccountAliases = NULL;
2942 PUNICODE_STRING BuiltinNames = NULL;
2943 PUNICODE_STRING AccountNames = NULL;
2944 PLOCALGROUP_USERS_INFO_0 Buffer = NULL;
2945 ULONG Size;
2946 ULONG Count = 0;
2947 ULONG Index;
2948 ULONG i;
2949 LPWSTR StrPtr;
2950 NET_API_STATUS ApiStatus = NERR_Success;
2951 NTSTATUS Status = STATUS_SUCCESS;
2952
2953 TRACE("(%s, %s, %d, %08x, %p %d, %p, %p) stub!\n",
2954 debugstr_w(servername), debugstr_w(username), level, flags, bufptr,
2955 prefmaxlen, entriesread, totalentries);
2956
2957 if (level != 0)
2958 return ERROR_INVALID_LEVEL;
2959
2960 if (flags & ~LG_INCLUDE_INDIRECT)
2961 return ERROR_INVALID_PARAMETER;
2962
2963 if (flags & LG_INCLUDE_INDIRECT)
2964 {
2965 WARN("The flag LG_INCLUDE_INDIRECT is not supported yet!\n");
2966 }
2967
2968 if (servername != NULL)
2969 RtlInitUnicodeString(&ServerName, servername);
2970
2971 RtlInitUnicodeString(&UserName, username);
2972
2973 /* Connect to the SAM Server */
2974 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
2975 &ServerHandle,
2976 SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
2977 NULL);
2978 if (!NT_SUCCESS(Status))
2979 {
2980 ERR("SamConnect failed (Status %08lx)\n", Status);
2981 ApiStatus = NetpNtStatusToApiStatus(Status);
2982 goto done;
2983 }
2984
2985 /* Open the Builtin Domain */
2986 Status = OpenBuiltinDomain(ServerHandle,
2987 DOMAIN_LOOKUP | DOMAIN_GET_ALIAS_MEMBERSHIP,
2988 &BuiltinDomainHandle);
2989 if (!NT_SUCCESS(Status))
2990 {
2991 ERR("OpenBuiltinDomain failed (Status %08lx)\n", Status);
2992 ApiStatus = NetpNtStatusToApiStatus(Status);
2993 goto done;
2994 }
2995
2996 /* Get the Account Domain SID */
2997 Status = GetAccountDomainSid((servername != NULL) ? &ServerName : NULL,
2998 &AccountDomainSid);
2999 if (!NT_SUCCESS(Status))
3000 {
3001 ERR("GetAccountDomainSid failed (Status %08lx)\n", Status);
3002 ApiStatus = NetpNtStatusToApiStatus(Status);
3003 goto done;
3004 }
3005
3006 /* Open the Account Domain */
3007 Status = SamOpenDomain(ServerHandle,
3008 DOMAIN_LOOKUP | DOMAIN_GET_ALIAS_MEMBERSHIP,
3009 AccountDomainSid,
3010 &AccountDomainHandle);
3011 if (!NT_SUCCESS(Status))
3012 {
3013 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
3014 ApiStatus = NetpNtStatusToApiStatus(Status);
3015 goto done;
3016 }
3017
3018 /* Get the RID for the given user name */
3019 Status = SamLookupNamesInDomain(AccountDomainHandle,
3020 1,
3021 &UserName,
3022 &RelativeIds,
3023 &Use);
3024 if (!NT_SUCCESS(Status))
3025 {
3026 ERR("SamLookupNamesInDomain failed (Status %08lx)\n", Status);
3027 ApiStatus = NetpNtStatusToApiStatus(Status);
3028 goto done;
3029 }
3030
3031 /* Fail, if it is not a user account */
3032 if (Use[0] != SidTypeUser)
3033 {
3034 ERR("Account is not a User!\n");
3035 ApiStatus = NERR_UserNotFound;
3036 goto done;
3037 }
3038
3039 /* Build the User SID from the Account Domain SID and the users RID */
3040 ApiStatus = BuildSidFromSidAndRid(AccountDomainSid,
3041 RelativeIds[0],
3042 &UserSid);
3043 if (ApiStatus != NERR_Success)
3044 {
3045 ERR("BuildSidFromSidAndRid failed!\n");
3046 goto done;
3047 }
3048
3049 /* Get alias memberships in the Builtin Domain */
3050 Status = SamGetAliasMembership(BuiltinDomainHandle,
3051 1,
3052 &UserSid,
3053 &BuiltinMemberCount,
3054 &BuiltinAliases);
3055 if (!NT_SUCCESS(Status))
3056 {
3057 ERR("SamGetAliasMembership failed (Status %08lx)\n", Status);
3058 ApiStatus = NetpNtStatusToApiStatus(Status);
3059 goto done;
3060 }
3061
3062 if (BuiltinMemberCount > 0)
3063 {
3064 /* Get the Names of the builtin alias members */
3065 Status = SamLookupIdsInDomain(BuiltinDomainHandle,
3066 BuiltinMemberCount,
3067 BuiltinAliases,
3068 &BuiltinNames,
3069 NULL);
3070 if (!NT_SUCCESS(Status))
3071 {
3072 ERR("SamLookupIdsInDomain failed (Status %08lx)\n", Status);
3073 ApiStatus = NetpNtStatusToApiStatus(Status);
3074 goto done;
3075 }
3076 }
3077
3078 /* Get alias memberships in the Account Domain */
3079 Status = SamGetAliasMembership(AccountDomainHandle,
3080 1,
3081 &UserSid,
3082 &AccountMemberCount,
3083 &AccountAliases);
3084 if (!NT_SUCCESS(Status))
3085 {
3086 ERR("SamGetAliasMembership failed (Status %08lx)\n", Status);
3087 ApiStatus = NetpNtStatusToApiStatus(Status);
3088 goto done;
3089 }
3090
3091 if (AccountMemberCount > 0)
3092 {
3093 /* Get the Names of the builtin alias members */
3094 Status = SamLookupIdsInDomain(AccountDomainHandle,
3095 AccountMemberCount,
3096 AccountAliases,
3097 &AccountNames,
3098 NULL);
3099 if (!NT_SUCCESS(Status))
3100 {
3101 ERR("SamLookupIdsInDomain failed (Status %08lx)\n", Status);
3102 ApiStatus = NetpNtStatusToApiStatus(Status);
3103 goto done;
3104 }
3105 }
3106
3107 /* Calculate the required buffer size */
3108 Size = 0;
3109
3110 for (i = 0; i < BuiltinMemberCount; i++)
3111 {
3112 if (BuiltinNames[i].Length > 0)
3113 {
3114 Size += (sizeof(LOCALGROUP_USERS_INFO_0) + BuiltinNames[i].Length + sizeof(UNICODE_NULL));
3115 Count++;
3116 }
3117 }
3118
3119 for (i = 0; i < AccountMemberCount; i++)
3120 {
3121 if (BuiltinNames[i].Length > 0)
3122 {
3123 Size += (sizeof(LOCALGROUP_USERS_INFO_0) + AccountNames[i].Length + sizeof(UNICODE_NULL));
3124 Count++;
3125 }
3126 }
3127
3128 if (Size == 0)
3129 {
3130 ApiStatus = NERR_Success;
3131 goto done;
3132 }
3133
3134 /* Allocate buffer */
3135 ApiStatus = NetApiBufferAllocate(Size, (LPVOID*)&Buffer);
3136 if (ApiStatus != NERR_Success)
3137 goto done;
3138
3139 ZeroMemory(Buffer, Size);
3140
3141 StrPtr = (LPWSTR)((INT_PTR)Buffer + Count * sizeof(LOCALGROUP_USERS_INFO_0));
3142
3143 /* Copy data to the allocated buffer */
3144 Index = 0;
3145 for (i = 0; i < BuiltinMemberCount; i++)
3146 {
3147 if (BuiltinNames[i].Length > 0)
3148 {
3149 CopyMemory(StrPtr,
3150 BuiltinNames[i].Buffer,
3151 BuiltinNames[i].Length);
3152 Buffer[Index].lgrui0_name = StrPtr;
3153
3154 StrPtr = (LPWSTR)((INT_PTR)StrPtr + BuiltinNames[i].Length + sizeof(UNICODE_NULL));
3155 Index++;
3156 }
3157 }
3158
3159 for (i = 0; i < AccountMemberCount; i++)
3160 {
3161 if (AccountNames[i].Length > 0)
3162 {
3163 CopyMemory(StrPtr,
3164 AccountNames[i].Buffer,
3165 AccountNames[i].Length);
3166 Buffer[Index].lgrui0_name = StrPtr;
3167
3168 StrPtr = (LPWSTR)((INT_PTR)StrPtr + AccountNames[i].Length + sizeof(UNICODE_NULL));
3169 Index++;
3170 }
3171 }
3172
3173 done:
3174 if (AccountNames != NULL)
3175 SamFreeMemory(AccountNames);
3176
3177 if (BuiltinNames != NULL)
3178 SamFreeMemory(BuiltinNames);
3179
3180 if (AccountAliases != NULL)
3181 SamFreeMemory(AccountAliases);
3182
3183 if (BuiltinAliases != NULL)
3184 SamFreeMemory(BuiltinAliases);
3185
3186 if (RelativeIds != NULL)
3187 SamFreeMemory(RelativeIds);
3188
3189 if (Use != NULL)
3190 SamFreeMemory(Use);
3191
3192 if (UserSid != NULL)
3193 NetApiBufferFree(UserSid);
3194
3195 if (AccountDomainSid != NULL)
3196 RtlFreeHeap(RtlGetProcessHeap(), 0, AccountDomainSid);
3197
3198 if (AccountDomainHandle != NULL)
3199 SamCloseHandle(AccountDomainHandle);
3200
3201 if (BuiltinDomainHandle != NULL)
3202 SamCloseHandle(BuiltinDomainHandle);
3203
3204 if (ServerHandle != NULL)
3205 SamCloseHandle(ServerHandle);
3206
3207 if (ApiStatus != NERR_Success && ApiStatus != ERROR_MORE_DATA)
3208 {
3209 *entriesread = 0;
3210 *totalentries = 0;
3211 }
3212 else
3213 {
3214 *entriesread = Count;
3215 *totalentries = Count;
3216 }
3217
3218 *bufptr = (LPBYTE)Buffer;
3219
3220 return ApiStatus;
3221 }
3222
3223
3224 /******************************************************************************
3225 * NetUserModalsGet (NETAPI32.@)
3226 *
3227 * Retrieves global information for all users and global groups in the security
3228 * database.
3229 *
3230 * PARAMS
3231 * servername [I] Specifies the DNS or the NetBIOS name of the remote server
3232 * on which the function is to execute.
3233 * level [I] Information level of the data.
3234 * 0 Return global passwords parameters. bufptr points to a
3235 * USER_MODALS_INFO_0 struct.
3236 * 1 Return logon server and domain controller information. bufptr
3237 * points to a USER_MODALS_INFO_1 struct.
3238 * 2 Return domain name and identifier. bufptr points to a
3239 * USER_MODALS_INFO_2 struct.
3240 * 3 Return lockout information. bufptr points to a USER_MODALS_INFO_3
3241 * struct.
3242 * bufptr [O] Buffer that receives the data.
3243 *
3244 * RETURNS
3245 * Success: NERR_Success.
3246 * Failure:
3247 * ERROR_ACCESS_DENIED - the user does not have access to the info.
3248 * NERR_InvalidComputer - computer name is invalid.
3249 */
3250 NET_API_STATUS
3251 WINAPI
3252 NetUserModalsGet(LPCWSTR servername,
3253 DWORD level,
3254 LPBYTE *bufptr)
3255 {
3256 UNICODE_STRING ServerName;
3257 SAM_HANDLE ServerHandle = NULL;
3258 SAM_HANDLE DomainHandle = NULL;
3259 PSID DomainSid = NULL;
3260 PDOMAIN_PASSWORD_INFORMATION PasswordInfo = NULL;
3261 PDOMAIN_LOGOFF_INFORMATION LogoffInfo = NULL;
3262 PDOMAIN_SERVER_ROLE_INFORMATION ServerRoleInfo = NULL;
3263 PDOMAIN_REPLICATION_INFORMATION ReplicationInfo = NULL;
3264 PDOMAIN_NAME_INFORMATION NameInfo = NULL;
3265 PDOMAIN_LOCKOUT_INFORMATION LockoutInfo = NULL;
3266 ULONG DesiredAccess;
3267 ULONG BufferSize;
3268 PUSER_MODALS_INFO_0 umi0;
3269 PUSER_MODALS_INFO_1 umi1;
3270 PUSER_MODALS_INFO_2 umi2;
3271 PUSER_MODALS_INFO_3 umi3;
3272 NET_API_STATUS ApiStatus = NERR_Success;
3273 NTSTATUS Status = STATUS_SUCCESS;
3274
3275 TRACE("(%s %d %p)\n", debugstr_w(servername), level, bufptr);
3276
3277 *bufptr = NULL;
3278
3279 if (servername != NULL)
3280 RtlInitUnicodeString(&ServerName, servername);
3281
3282 /* Connect to the SAM Server */
3283 Status = SamConnect