9612850d8112247f6436ec19c9eca66f597fe50f
[reactos.git] / reactos / 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 NetUserChangePassword
24 * Implement NetUserGetGroups
25 * Implement NetUserSetGroups
26 * NetUserGetLocalGroups does not support LG_INCLUDE_INDIRECT yet.
27 * Add missing information levels.
28 * ...
29 */
30
31 #include "netapi32.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(netapi32);
34
35
36 typedef struct _ENUM_CONTEXT
37 {
38 SAM_HANDLE ServerHandle;
39 SAM_HANDLE BuiltinDomainHandle;
40 SAM_HANDLE AccountDomainHandle;
41
42 SAM_ENUMERATE_HANDLE EnumerationContext;
43 PSAM_RID_ENUMERATION Buffer;
44 ULONG Count;
45 ULONG Index;
46 BOOLEAN BuiltinDone;
47
48 } ENUM_CONTEXT, *PENUM_CONTEXT;
49
50
51 static
52 ULONG
53 GetAccountFlags(ULONG AccountControl)
54 {
55 ULONG Flags = UF_SCRIPT;
56
57 if (AccountControl & USER_ACCOUNT_DISABLED)
58 Flags |= UF_ACCOUNTDISABLE;
59
60 if (AccountControl & USER_HOME_DIRECTORY_REQUIRED)
61 Flags |= UF_HOMEDIR_REQUIRED;
62
63 if (AccountControl & USER_PASSWORD_NOT_REQUIRED)
64 Flags |= UF_PASSWD_NOTREQD;
65
66 // UF_PASSWD_CANT_CHANGE
67
68 if (AccountControl & USER_ACCOUNT_AUTO_LOCKED)
69 Flags |= UF_LOCKOUT;
70
71 if (AccountControl & USER_DONT_EXPIRE_PASSWORD)
72 Flags |= UF_DONT_EXPIRE_PASSWD;
73
74 /*
75 if (AccountControl & USER_ENCRYPTED_TEXT_PASSWORD_ALLOWED)
76 Flags |= UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED;
77
78 if (AccountControl & USER_SMARTCARD_REQUIRED)
79 Flags |= UF_SMARTCARD_REQUIRED;
80
81 if (AccountControl & USER_TRUSTED_FOR_DELEGATION)
82 Flags |= UF_TRUSTED_FOR_DELEGATION;
83
84 if (AccountControl & USER_NOT_DELEGATED)
85 Flags |= UF_NOT_DELEGATED;
86
87 if (AccountControl & USER_USE_DES_KEY_ONLY)
88 Flags |= UF_USE_DES_KEY_ONLY;
89
90 if (AccountControl & USER_DONT_REQUIRE_PREAUTH)
91 Flags |= UF_DONT_REQUIRE_PREAUTH;
92
93 if (AccountControl & USER_PASSWORD_EXPIRED)
94 Flags |= UF_PASSWORD_EXPIRED;
95 */
96
97 /* Set account type flags */
98 if (AccountControl & USER_TEMP_DUPLICATE_ACCOUNT)
99 Flags |= UF_TEMP_DUPLICATE_ACCOUNT;
100 else if (AccountControl & USER_NORMAL_ACCOUNT)
101 Flags |= UF_NORMAL_ACCOUNT;
102 else if (AccountControl & USER_INTERDOMAIN_TRUST_ACCOUNT)
103 Flags |= UF_INTERDOMAIN_TRUST_ACCOUNT;
104 else if (AccountControl & USER_WORKSTATION_TRUST_ACCOUNT)
105 Flags |= UF_WORKSTATION_TRUST_ACCOUNT;
106 else if (AccountControl & USER_SERVER_TRUST_ACCOUNT)
107 Flags |= UF_SERVER_TRUST_ACCOUNT;
108
109 return Flags;
110 }
111
112
113 static
114 NET_API_STATUS
115 BuildUserInfoBuffer(PUSER_ACCOUNT_INFORMATION UserInfo,
116 DWORD level,
117 ULONG RelativeId,
118 LPVOID *Buffer)
119 {
120 LPVOID LocalBuffer = NULL;
121 PUSER_INFO_0 UserInfo0;
122 PUSER_INFO_1 UserInfo1;
123 PUSER_INFO_2 UserInfo2;
124 PUSER_INFO_3 UserInfo3;
125 PUSER_INFO_10 UserInfo10;
126 PUSER_INFO_20 UserInfo20;
127 PUSER_INFO_23 UserInfo23;
128 LPWSTR Ptr;
129 ULONG Size = 0;
130 NET_API_STATUS ApiStatus = NERR_Success;
131
132 *Buffer = NULL;
133
134 switch (level)
135 {
136 case 0:
137 Size = sizeof(USER_INFO_0) +
138 UserInfo->UserName.Length + sizeof(WCHAR);
139 break;
140
141 case 1:
142 Size = sizeof(USER_INFO_1) +
143 UserInfo->UserName.Length + sizeof(WCHAR);
144
145 if (UserInfo->HomeDirectory.Length > 0)
146 Size += UserInfo->HomeDirectory.Length + sizeof(WCHAR);
147
148 if (UserInfo->AdminComment.Length > 0)
149 Size += UserInfo->AdminComment.Length + sizeof(WCHAR);
150
151 if (UserInfo->ScriptPath.Length > 0)
152 Size += UserInfo->ScriptPath.Length + sizeof(WCHAR);
153 break;
154
155 case 2:
156 Size = sizeof(USER_INFO_2) +
157 UserInfo->UserName.Length + sizeof(WCHAR);
158
159 if (UserInfo->HomeDirectory.Length > 0)
160 Size += UserInfo->HomeDirectory.Length + sizeof(WCHAR);
161
162 if (UserInfo->AdminComment.Length > 0)
163 Size += UserInfo->AdminComment.Length + sizeof(WCHAR);
164
165 if (UserInfo->ScriptPath.Length > 0)
166 Size += UserInfo->ScriptPath.Length + sizeof(WCHAR);
167
168 if (UserInfo->FullName.Length > 0)
169 Size += UserInfo->FullName.Length + sizeof(WCHAR);
170
171 /* FIXME: usri2_usr_comment */
172 /* FIXME: usri2_parms */
173
174 if (UserInfo->WorkStations.Length > 0)
175 Size += UserInfo->WorkStations.Length + sizeof(WCHAR);
176
177 /* FIXME: usri2_logon_hours */
178 /* FIXME: usri2_logon_server */
179 break;
180
181 case 3:
182 Size = sizeof(USER_INFO_3) +
183 UserInfo->UserName.Length + sizeof(WCHAR);
184
185 if (UserInfo->HomeDirectory.Length > 0)
186 Size += UserInfo->HomeDirectory.Length + sizeof(WCHAR);
187
188 if (UserInfo->AdminComment.Length > 0)
189 Size += UserInfo->AdminComment.Length + sizeof(WCHAR);
190
191 if (UserInfo->ScriptPath.Length > 0)
192 Size += UserInfo->ScriptPath.Length + sizeof(WCHAR);
193
194 if (UserInfo->FullName.Length > 0)
195 Size += UserInfo->FullName.Length + sizeof(WCHAR);
196
197 /* FIXME: usri3_usr_comment */
198 /* FIXME: usri3_parms */
199
200 if (UserInfo->WorkStations.Length > 0)
201 Size += UserInfo->WorkStations.Length + sizeof(WCHAR);
202
203 /* FIXME: usri3_logon_hours */
204 /* FIXME: usri3_logon_server */
205
206 if (UserInfo->ProfilePath.Length > 0)
207 Size += UserInfo->ProfilePath.Length + sizeof(WCHAR);
208
209 if (UserInfo->HomeDirectoryDrive.Length > 0)
210 Size += UserInfo->HomeDirectoryDrive.Length + sizeof(WCHAR);
211 break;
212
213 // case 4:
214
215 case 10:
216 Size = sizeof(USER_INFO_10) +
217 UserInfo->UserName.Length + sizeof(WCHAR);
218
219 if (UserInfo->AdminComment.Length > 0)
220 Size += UserInfo->AdminComment.Length + sizeof(WCHAR);
221
222 /* FIXME: usri10_usr_comment */
223
224 if (UserInfo->FullName.Length > 0)
225 Size += UserInfo->FullName.Length + sizeof(WCHAR);
226 break;
227
228 // case 11:
229
230 case 20:
231 Size = sizeof(USER_INFO_20) +
232 UserInfo->UserName.Length + sizeof(WCHAR);
233
234 if (UserInfo->FullName.Length > 0)
235 Size += UserInfo->FullName.Length + sizeof(WCHAR);
236
237 if (UserInfo->AdminComment.Length > 0)
238 Size += UserInfo->AdminComment.Length + sizeof(WCHAR);
239 break;
240
241 case 23:
242 Size = sizeof(USER_INFO_23) +
243 UserInfo->UserName.Length + sizeof(WCHAR);
244
245 if (UserInfo->FullName.Length > 0)
246 Size += UserInfo->FullName.Length + sizeof(WCHAR);
247
248 if (UserInfo->AdminComment.Length > 0)
249 Size += UserInfo->AdminComment.Length + sizeof(WCHAR);
250
251 /* FIXME: usri23_user_sid */
252 break;
253
254 default:
255 ApiStatus = ERROR_INVALID_LEVEL;
256 goto done;
257 }
258
259 ApiStatus = NetApiBufferAllocate(Size, &LocalBuffer);
260 if (ApiStatus != NERR_Success)
261 goto done;
262
263 ZeroMemory(LocalBuffer, Size);
264
265 switch (level)
266 {
267 case 0:
268 UserInfo0 = (PUSER_INFO_0)LocalBuffer;
269
270 Ptr = (LPWSTR)((ULONG_PTR)UserInfo0 + sizeof(USER_INFO_0));
271 UserInfo0->usri0_name = Ptr;
272
273 memcpy(UserInfo0->usri0_name,
274 UserInfo->UserName.Buffer,
275 UserInfo->UserName.Length);
276 UserInfo0->usri0_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
277 break;
278
279 case 1:
280 UserInfo1 = (PUSER_INFO_1)LocalBuffer;
281
282 Ptr = (LPWSTR)((ULONG_PTR)UserInfo1 + sizeof(USER_INFO_1));
283
284 UserInfo1->usri1_name = Ptr;
285
286 memcpy(UserInfo1->usri1_name,
287 UserInfo->UserName.Buffer,
288 UserInfo->UserName.Length);
289 UserInfo1->usri1_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
290
291 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserName.Length + sizeof(WCHAR));
292
293 UserInfo1->usri1_password = NULL;
294
295 /* FIXME: UserInfo1->usri1_password_age */
296 /* FIXME: UserInfo1->usri1_priv */
297
298 if (UserInfo->HomeDirectory.Length > 0)
299 {
300 UserInfo1->usri1_home_dir = Ptr;
301
302 memcpy(UserInfo1->usri1_home_dir,
303 UserInfo->HomeDirectory.Buffer,
304 UserInfo->HomeDirectory.Length);
305 UserInfo1->usri1_home_dir[UserInfo->HomeDirectory.Length / sizeof(WCHAR)] = UNICODE_NULL;
306
307 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->HomeDirectory.Length + sizeof(WCHAR));
308 }
309
310 if (UserInfo->AdminComment.Length > 0)
311 {
312 UserInfo1->usri1_comment = Ptr;
313
314 memcpy(UserInfo1->usri1_comment,
315 UserInfo->AdminComment.Buffer,
316 UserInfo->AdminComment.Length);
317 UserInfo1->usri1_comment[UserInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
318
319 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->AdminComment.Length + sizeof(WCHAR));
320 }
321
322 UserInfo1->usri1_flags = GetAccountFlags(UserInfo->UserAccountControl);
323
324 if (UserInfo->ScriptPath.Length > 0)
325 {
326 UserInfo1->usri1_script_path = Ptr;
327
328 memcpy(UserInfo1->usri1_script_path,
329 UserInfo->ScriptPath.Buffer,
330 UserInfo->ScriptPath.Length);
331 UserInfo1->usri1_script_path[UserInfo->ScriptPath.Length / sizeof(WCHAR)] = UNICODE_NULL;
332 }
333 break;
334
335 case 2:
336 UserInfo2 = (PUSER_INFO_2)LocalBuffer;
337
338 Ptr = (LPWSTR)((ULONG_PTR)UserInfo2 + sizeof(USER_INFO_2));
339
340 UserInfo2->usri2_name = Ptr;
341
342 memcpy(UserInfo2->usri2_name,
343 UserInfo->UserName.Buffer,
344 UserInfo->UserName.Length);
345 UserInfo2->usri2_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
346
347 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserName.Length + sizeof(WCHAR));
348
349 /* FIXME: usri2_password_age */
350 /* FIXME: usri2_priv */
351
352 if (UserInfo->HomeDirectory.Length > 0)
353 {
354 UserInfo2->usri2_home_dir = Ptr;
355
356 memcpy(UserInfo2->usri2_home_dir,
357 UserInfo->HomeDirectory.Buffer,
358 UserInfo->HomeDirectory.Length);
359 UserInfo2->usri2_home_dir[UserInfo->HomeDirectory.Length / sizeof(WCHAR)] = UNICODE_NULL;
360
361 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->HomeDirectory.Length + sizeof(WCHAR));
362 }
363
364 if (UserInfo->AdminComment.Length > 0)
365 {
366 UserInfo2->usri2_comment = Ptr;
367
368 memcpy(UserInfo2->usri2_comment,
369 UserInfo->AdminComment.Buffer,
370 UserInfo->AdminComment.Length);
371 UserInfo2->usri2_comment[UserInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
372
373 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->AdminComment.Length + sizeof(WCHAR));
374 }
375
376 UserInfo2->usri2_flags = GetAccountFlags(UserInfo->UserAccountControl);
377
378 if (UserInfo->ScriptPath.Length > 0)
379 {
380 UserInfo2->usri2_script_path = Ptr;
381
382 memcpy(UserInfo2->usri2_script_path,
383 UserInfo->ScriptPath.Buffer,
384 UserInfo->ScriptPath.Length);
385 UserInfo2->usri2_script_path[UserInfo->ScriptPath.Length / sizeof(WCHAR)] = UNICODE_NULL;
386
387 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->ScriptPath.Length + sizeof(WCHAR));
388 }
389
390 /* FIXME: usri2_auth_flags */
391
392 if (UserInfo->FullName.Length > 0)
393 {
394 UserInfo2->usri2_full_name = Ptr;
395
396 memcpy(UserInfo2->usri2_full_name,
397 UserInfo->FullName.Buffer,
398 UserInfo->FullName.Length);
399 UserInfo2->usri2_full_name[UserInfo->FullName.Length / sizeof(WCHAR)] = UNICODE_NULL;
400
401 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->FullName.Length + sizeof(WCHAR));
402 }
403
404 /* FIXME: usri2_usr_comment */
405 /* FIXME: usri2_parms */
406
407 if (UserInfo->WorkStations.Length > 0)
408 {
409 UserInfo2->usri2_workstations = Ptr;
410
411 memcpy(UserInfo2->usri2_workstations,
412 UserInfo->WorkStations.Buffer,
413 UserInfo->WorkStations.Length);
414 UserInfo2->usri2_workstations[UserInfo->WorkStations.Length / sizeof(WCHAR)] = UNICODE_NULL;
415
416 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->WorkStations.Length + sizeof(WCHAR));
417 }
418
419 RtlTimeToSecondsSince1970(&UserInfo->LastLogon,
420 &UserInfo2->usri2_last_logon);
421
422 RtlTimeToSecondsSince1970(&UserInfo->LastLogoff,
423 &UserInfo2->usri2_last_logoff);
424
425 RtlTimeToSecondsSince1970(&UserInfo->AccountExpires,
426 &UserInfo2->usri2_acct_expires);
427
428 UserInfo2->usri2_max_storage = USER_MAXSTORAGE_UNLIMITED;
429
430 /* FIXME: usri2_units_per_week */
431 /* FIXME: usri2_logon_hours */
432
433 UserInfo2->usri2_bad_pw_count = UserInfo->BadPasswordCount;
434 UserInfo2->usri2_num_logons = UserInfo->LogonCount;
435
436 /* FIXME: usri2_logon_server */
437 /* FIXME: usri2_country_code */
438 /* FIXME: usri2_code_page */
439
440 break;
441
442 case 3:
443 UserInfo3 = (PUSER_INFO_3)LocalBuffer;
444
445 Ptr = (LPWSTR)((ULONG_PTR)UserInfo3 + sizeof(USER_INFO_3));
446
447 UserInfo3->usri3_name = Ptr;
448
449 memcpy(UserInfo3->usri3_name,
450 UserInfo->UserName.Buffer,
451 UserInfo->UserName.Length);
452 UserInfo3->usri3_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
453
454 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserName.Length + sizeof(WCHAR));
455
456 /* FIXME: usri3_password_age */
457 /* FIXME: usri3_priv */
458
459 if (UserInfo->HomeDirectory.Length > 0)
460 {
461 UserInfo3->usri3_home_dir = Ptr;
462
463 memcpy(UserInfo3->usri3_home_dir,
464 UserInfo->HomeDirectory.Buffer,
465 UserInfo->HomeDirectory.Length);
466 UserInfo3->usri3_home_dir[UserInfo->HomeDirectory.Length / sizeof(WCHAR)] = UNICODE_NULL;
467
468 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->HomeDirectory.Length + sizeof(WCHAR));
469 }
470
471 if (UserInfo->AdminComment.Length > 0)
472 {
473 UserInfo3->usri3_comment = Ptr;
474
475 memcpy(UserInfo3->usri3_comment,
476 UserInfo->AdminComment.Buffer,
477 UserInfo->AdminComment.Length);
478 UserInfo3->usri3_comment[UserInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
479
480 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->AdminComment.Length + sizeof(WCHAR));
481 }
482
483 UserInfo3->usri3_flags = GetAccountFlags(UserInfo->UserAccountControl);
484
485 if (UserInfo->ScriptPath.Length > 0)
486 {
487 UserInfo3->usri3_script_path = Ptr;
488
489 memcpy(UserInfo3->usri3_script_path,
490 UserInfo->ScriptPath.Buffer,
491 UserInfo->ScriptPath.Length);
492 UserInfo3->usri3_script_path[UserInfo->ScriptPath.Length / sizeof(WCHAR)] = UNICODE_NULL;
493
494 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->ScriptPath.Length + sizeof(WCHAR));
495 }
496
497 /* FIXME: usri3_auth_flags */
498
499 if (UserInfo->FullName.Length > 0)
500 {
501 UserInfo3->usri3_full_name = Ptr;
502
503 memcpy(UserInfo3->usri3_full_name,
504 UserInfo->FullName.Buffer,
505 UserInfo->FullName.Length);
506 UserInfo3->usri3_full_name[UserInfo->FullName.Length / sizeof(WCHAR)] = UNICODE_NULL;
507
508 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->FullName.Length + sizeof(WCHAR));
509 }
510
511 /* FIXME: usri3_usr_comment */
512 /* FIXME: usri3_parms */
513
514 if (UserInfo->WorkStations.Length > 0)
515 {
516 UserInfo3->usri3_workstations = Ptr;
517
518 memcpy(UserInfo3->usri3_workstations,
519 UserInfo->WorkStations.Buffer,
520 UserInfo->WorkStations.Length);
521 UserInfo3->usri3_workstations[UserInfo->WorkStations.Length / sizeof(WCHAR)] = UNICODE_NULL;
522
523 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->WorkStations.Length + sizeof(WCHAR));
524 }
525
526 RtlTimeToSecondsSince1970(&UserInfo->LastLogon,
527 &UserInfo3->usri3_last_logon);
528
529 RtlTimeToSecondsSince1970(&UserInfo->LastLogoff,
530 &UserInfo3->usri3_last_logoff);
531
532 RtlTimeToSecondsSince1970(&UserInfo->AccountExpires,
533 &UserInfo3->usri3_acct_expires);
534
535 UserInfo3->usri3_max_storage = USER_MAXSTORAGE_UNLIMITED;
536
537 /* FIXME: usri3_units_per_week */
538 /* FIXME: usri3_logon_hours */
539
540 UserInfo3->usri3_bad_pw_count = UserInfo->BadPasswordCount;
541 UserInfo3->usri3_num_logons = UserInfo->LogonCount;
542
543 /* FIXME: usri3_logon_server */
544 /* FIXME: usri3_country_code */
545 /* FIXME: usri3_code_page */
546
547 UserInfo3->usri3_user_id = RelativeId;
548 UserInfo3->usri3_primary_group_id = UserInfo->PrimaryGroupId;
549
550 if (UserInfo->ProfilePath.Length > 0)
551 {
552 UserInfo3->usri3_profile = Ptr;
553
554 memcpy(UserInfo3->usri3_profile,
555 UserInfo->ProfilePath.Buffer,
556 UserInfo->ProfilePath.Length);
557 UserInfo3->usri3_profile[UserInfo->ProfilePath.Length / sizeof(WCHAR)] = UNICODE_NULL;
558
559 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->ProfilePath.Length + sizeof(WCHAR));
560 }
561
562 if (UserInfo->HomeDirectoryDrive.Length > 0)
563 {
564 UserInfo3->usri3_home_dir_drive = Ptr;
565
566 memcpy(UserInfo3->usri3_home_dir_drive,
567 UserInfo->HomeDirectoryDrive.Buffer,
568 UserInfo->HomeDirectoryDrive.Length);
569 UserInfo3->usri3_home_dir_drive[UserInfo->HomeDirectoryDrive.Length / sizeof(WCHAR)] = UNICODE_NULL;
570
571 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->HomeDirectoryDrive.Length + sizeof(WCHAR));
572 }
573
574 UserInfo3->usri3_password_expired = (UserInfo->UserAccountControl & USER_PASSWORD_EXPIRED);
575 break;
576
577 // case 4:
578
579 case 10:
580 UserInfo10 = (PUSER_INFO_10)LocalBuffer;
581
582 Ptr = (LPWSTR)((ULONG_PTR)UserInfo10 + sizeof(USER_INFO_10));
583
584 UserInfo10->usri10_name = Ptr;
585
586 memcpy(UserInfo10->usri10_name,
587 UserInfo->UserName.Buffer,
588 UserInfo->UserName.Length);
589 UserInfo10->usri10_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
590
591 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserName.Length + sizeof(WCHAR));
592
593 if (UserInfo->AdminComment.Length > 0)
594 {
595 UserInfo10->usri10_comment = Ptr;
596
597 memcpy(UserInfo10->usri10_comment,
598 UserInfo->AdminComment.Buffer,
599 UserInfo->AdminComment.Length);
600 UserInfo10->usri10_comment[UserInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
601
602 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->AdminComment.Length + sizeof(WCHAR));
603 }
604
605 /* FIXME: usri10_usr_comment */
606
607 if (UserInfo->FullName.Length > 0)
608 {
609 UserInfo10->usri10_full_name = Ptr;
610
611 memcpy(UserInfo10->usri10_full_name,
612 UserInfo->FullName.Buffer,
613 UserInfo->FullName.Length);
614 UserInfo10->usri10_full_name[UserInfo->FullName.Length / sizeof(WCHAR)] = UNICODE_NULL;
615
616 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->FullName.Length + sizeof(WCHAR));
617 }
618 break;
619
620 // case 11:
621
622 case 20:
623 UserInfo20 = (PUSER_INFO_20)LocalBuffer;
624
625 Ptr = (LPWSTR)((ULONG_PTR)UserInfo20 + sizeof(USER_INFO_20));
626
627 UserInfo20->usri20_name = Ptr;
628
629 memcpy(UserInfo20->usri20_name,
630 UserInfo->UserName.Buffer,
631 UserInfo->UserName.Length);
632 UserInfo20->usri20_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
633
634 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserName.Length + sizeof(WCHAR));
635
636 if (UserInfo->FullName.Length > 0)
637 {
638 UserInfo20->usri20_full_name = Ptr;
639
640 memcpy(UserInfo20->usri20_full_name,
641 UserInfo->FullName.Buffer,
642 UserInfo->FullName.Length);
643 UserInfo20->usri20_full_name[UserInfo->FullName.Length / sizeof(WCHAR)] = UNICODE_NULL;
644
645 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->FullName.Length + sizeof(WCHAR));
646 }
647
648 if (UserInfo->AdminComment.Length > 0)
649 {
650 UserInfo20->usri20_comment = Ptr;
651
652 memcpy(UserInfo20->usri20_comment,
653 UserInfo->AdminComment.Buffer,
654 UserInfo->AdminComment.Length);
655 UserInfo20->usri20_comment[UserInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
656
657 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->AdminComment.Length + sizeof(WCHAR));
658 }
659
660 UserInfo20->usri20_flags = GetAccountFlags(UserInfo->UserAccountControl);
661
662 UserInfo20->usri20_user_id = RelativeId;
663 break;
664
665 case 23:
666 UserInfo23 = (PUSER_INFO_23)LocalBuffer;
667
668 Ptr = (LPWSTR)((ULONG_PTR)UserInfo23 + sizeof(USER_INFO_23));
669
670 UserInfo23->usri23_name = Ptr;
671
672 memcpy(UserInfo23->usri23_name,
673 UserInfo->UserName.Buffer,
674 UserInfo->UserName.Length);
675 UserInfo23->usri23_name[UserInfo->UserName.Length / sizeof(WCHAR)] = UNICODE_NULL;
676
677 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->UserName.Length + sizeof(WCHAR));
678
679 if (UserInfo->FullName.Length > 0)
680 {
681 UserInfo23->usri23_full_name = Ptr;
682
683 memcpy(UserInfo23->usri23_full_name,
684 UserInfo->FullName.Buffer,
685 UserInfo->FullName.Length);
686 UserInfo23->usri23_full_name[UserInfo->FullName.Length / sizeof(WCHAR)] = UNICODE_NULL;
687
688 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->FullName.Length + sizeof(WCHAR));
689 }
690
691 if (UserInfo->AdminComment.Length > 0)
692 {
693 UserInfo23->usri23_comment = Ptr;
694
695 memcpy(UserInfo23->usri23_comment,
696 UserInfo->AdminComment.Buffer,
697 UserInfo->AdminComment.Length);
698 UserInfo23->usri23_comment[UserInfo->AdminComment.Length / sizeof(WCHAR)] = UNICODE_NULL;
699
700 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->AdminComment.Length + sizeof(WCHAR));
701 }
702
703 UserInfo23->usri23_flags = GetAccountFlags(UserInfo->UserAccountControl);
704
705 /* FIXME: usri23_user_sid */
706 break;
707 }
708
709 done:
710 if (ApiStatus == NERR_Success)
711 {
712 *Buffer = LocalBuffer;
713 }
714 else
715 {
716 if (LocalBuffer != NULL)
717 NetApiBufferFree(LocalBuffer);
718 }
719
720 return ApiStatus;
721 }
722
723
724 static
725 VOID
726 FreeUserInfo(PUSER_ACCOUNT_INFORMATION UserInfo)
727 {
728 if (UserInfo->UserName.Buffer != NULL)
729 SamFreeMemory(UserInfo->UserName.Buffer);
730
731 if (UserInfo->FullName.Buffer != NULL)
732 SamFreeMemory(UserInfo->FullName.Buffer);
733
734 if (UserInfo->HomeDirectory.Buffer != NULL)
735 SamFreeMemory(UserInfo->HomeDirectory.Buffer);
736
737 if (UserInfo->HomeDirectoryDrive.Buffer != NULL)
738 SamFreeMemory(UserInfo->HomeDirectoryDrive.Buffer);
739
740 if (UserInfo->ScriptPath.Buffer != NULL)
741 SamFreeMemory(UserInfo->ScriptPath.Buffer);
742
743 if (UserInfo->ProfilePath.Buffer != NULL)
744 SamFreeMemory(UserInfo->ProfilePath.Buffer);
745
746 if (UserInfo->AdminComment.Buffer != NULL)
747 SamFreeMemory(UserInfo->AdminComment.Buffer);
748
749 if (UserInfo->WorkStations.Buffer != NULL)
750 SamFreeMemory(UserInfo->WorkStations.Buffer);
751
752 if (UserInfo->LogonHours.LogonHours != NULL)
753 SamFreeMemory(UserInfo->LogonHours.LogonHours);
754
755 SamFreeMemory(UserInfo);
756 }
757
758
759 static
760 NET_API_STATUS
761 SetUserInfo(SAM_HANDLE UserHandle,
762 LPBYTE UserInfo,
763 DWORD Level)
764 {
765 USER_ALL_INFORMATION UserAllInfo;
766 PUSER_INFO_0 UserInfo0;
767 PUSER_INFO_1 UserInfo1;
768 PUSER_INFO_2 UserInfo2;
769 PUSER_INFO_3 UserInfo3;
770 PUSER_INFO_1003 UserInfo1003;
771 PUSER_INFO_1006 UserInfo1006;
772 PUSER_INFO_1007 UserInfo1007;
773 PUSER_INFO_1009 UserInfo1009;
774 PUSER_INFO_1011 UserInfo1011;
775 PUSER_INFO_1012 UserInfo1012;
776 PUSER_INFO_1013 UserInfo1013;
777 PUSER_INFO_1014 UserInfo1014;
778 PUSER_INFO_1052 UserInfo1052;
779 PUSER_INFO_1053 UserInfo1053;
780 NET_API_STATUS ApiStatus = NERR_Success;
781 NTSTATUS Status = STATUS_SUCCESS;
782
783 ZeroMemory(&UserAllInfo, sizeof(USER_ALL_INFORMATION));
784
785 switch (Level)
786 {
787 case 0:
788 UserInfo0 = (PUSER_INFO_0)UserInfo;
789
790 RtlInitUnicodeString(&UserAllInfo.UserName,
791 UserInfo0->usri0_name);
792
793 UserAllInfo.WhichFields |= USER_ALL_USERNAME;
794 break;
795
796 case 1:
797 UserInfo1 = (PUSER_INFO_1)UserInfo;
798
799 // usri1_name ignored
800
801 if (UserInfo1->usri1_password != NULL)
802 {
803 RtlInitUnicodeString(&UserAllInfo.NtPassword,
804 UserInfo1->usri1_password);
805 UserAllInfo.NtPasswordPresent = TRUE;
806 UserAllInfo.WhichFields |= USER_ALL_NTPASSWORDPRESENT;
807 }
808
809 // usri1_password_age ignored
810
811 // UserInfo1->usri1_priv
812
813 if (UserInfo1->usri1_home_dir != NULL)
814 {
815 RtlInitUnicodeString(&UserAllInfo.HomeDirectory,
816 UserInfo1->usri1_home_dir);
817 UserAllInfo.WhichFields |= USER_ALL_HOMEDIRECTORY;
818 }
819
820 if (UserInfo1->usri1_comment != NULL)
821 {
822 RtlInitUnicodeString(&UserAllInfo.AdminComment,
823 UserInfo1->usri1_comment);
824 UserAllInfo.WhichFields |= USER_ALL_ADMINCOMMENT;
825 }
826
827 // UserInfo1->usri1_flags
828 // UserAllInfo.WhichFields |= USER_ALL_USERACCOUNTCONTROL;
829
830 if (UserInfo1->usri1_script_path != NULL)
831 {
832 RtlInitUnicodeString(&UserAllInfo.ScriptPath,
833 UserInfo1->usri1_script_path);
834 UserAllInfo.WhichFields |= USER_ALL_SCRIPTPATH;
835 }
836 break;
837
838 case 2:
839 UserInfo2 = (PUSER_INFO_2)UserInfo;
840
841 // usri2_name ignored
842
843 if (UserInfo2->usri2_password != NULL)
844 {
845 RtlInitUnicodeString(&UserAllInfo.NtPassword,
846 UserInfo2->usri2_password);
847 UserAllInfo.NtPasswordPresent = TRUE;
848 UserAllInfo.WhichFields |= USER_ALL_NTPASSWORDPRESENT;
849 }
850
851 // usri2_password_age ignored
852
853 // UserInfo2->usri2_priv;
854
855 if (UserInfo2->usri2_home_dir != NULL)
856 {
857 RtlInitUnicodeString(&UserAllInfo.HomeDirectory,
858 UserInfo2->usri2_home_dir);
859 UserAllInfo.WhichFields |= USER_ALL_HOMEDIRECTORY;
860 }
861
862 if (UserInfo2->usri2_comment != NULL)
863 {
864 RtlInitUnicodeString(&UserAllInfo.AdminComment,
865 UserInfo2->usri2_comment);
866 UserAllInfo.WhichFields |= USER_ALL_ADMINCOMMENT;
867 }
868
869 // UserInfo2->usri2_flags;
870
871 if (UserInfo2->usri2_script_path != NULL)
872 {
873 RtlInitUnicodeString(&UserAllInfo.ScriptPath,
874 UserInfo2->usri2_script_path);
875 UserAllInfo.WhichFields |= USER_ALL_SCRIPTPATH;
876 }
877
878 // UserInfo2->usri2_auth_flags;
879
880 if (UserInfo2->usri2_full_name != NULL)
881 {
882 RtlInitUnicodeString(&UserAllInfo.FullName,
883 UserInfo2->usri2_full_name);
884 UserAllInfo.WhichFields |= USER_ALL_FULLNAME;
885 }
886
887 if (UserInfo2->usri2_usr_comment != NULL)
888 {
889 RtlInitUnicodeString(&UserAllInfo.UserComment,
890 UserInfo2->usri2_usr_comment);
891 UserAllInfo.WhichFields |= USER_ALL_USERCOMMENT;
892 }
893
894 if (UserInfo2->usri2_parms != NULL)
895 {
896 RtlInitUnicodeString(&UserAllInfo.Parameters,
897 UserInfo2->usri2_parms);
898 UserAllInfo.WhichFields |= USER_ALL_PARAMETERS;
899 }
900
901 if (UserInfo2->usri2_workstations != NULL)
902 {
903 RtlInitUnicodeString(&UserAllInfo.WorkStations,
904 UserInfo2->usri2_workstations);
905 UserAllInfo.WhichFields |= USER_ALL_WORKSTATIONS;
906 }
907
908 // usri2_last_logon ignored
909 // usri2_last_logoff ignored
910
911 // UserInfo2->usri2_acct_expires;
912 // UserInfo2->usri2_max_storage;
913 // UserInfo2->usri2_units_per_week;
914 // UserInfo2->usri2_logon_hours;
915
916 // usri2_bad_pw_count ignored
917 // usri2_num_logons ignored
918 // usri2_logon_server ignored
919
920 // UserInfo2->usri2_country_code;
921 // UserInfo2->usri2_code_page;
922 break;
923
924 case 3:
925 UserInfo3 = (PUSER_INFO_3)UserInfo;
926
927 // usri3_name ignored
928
929 if (UserInfo3->usri3_password != NULL)
930 {
931 RtlInitUnicodeString(&UserAllInfo.NtPassword,
932 UserInfo3->usri3_password);
933 UserAllInfo.NtPasswordPresent = TRUE;
934 UserAllInfo.WhichFields |= USER_ALL_NTPASSWORDPRESENT;
935 }
936
937 // usri3_password_age ignored
938
939 // UserInfo3->usri3_priv;
940
941 if (UserInfo3->usri3_home_dir != NULL)
942 {
943 RtlInitUnicodeString(&UserAllInfo.HomeDirectory,
944 UserInfo3->usri3_home_dir);
945 UserAllInfo.WhichFields |= USER_ALL_HOMEDIRECTORY;
946 }
947
948 if (UserInfo3->usri3_comment != NULL)
949 {
950 RtlInitUnicodeString(&UserAllInfo.AdminComment,
951 UserInfo3->usri3_comment);
952 UserAllInfo.WhichFields |= USER_ALL_ADMINCOMMENT;
953 }
954
955 // UserInfo3->usri3_flags;
956 // UserAllInfo.WhichFields |= USER_ALL_USERACCOUNTCONTROL;
957
958 if (UserInfo3->usri3_script_path != NULL)
959 {
960 RtlInitUnicodeString(&UserAllInfo.ScriptPath,
961 UserInfo3->usri3_script_path);
962 UserAllInfo.WhichFields |= USER_ALL_SCRIPTPATH;
963 }
964
965 // UserInfo3->usri3_auth_flags;
966
967 if (UserInfo3->usri3_full_name != NULL)
968 {
969 RtlInitUnicodeString(&UserAllInfo.FullName,
970 UserInfo3->usri3_full_name);
971 UserAllInfo.WhichFields |= USER_ALL_FULLNAME;
972 }
973
974 if (UserInfo3->usri3_usr_comment != NULL)
975 {
976 RtlInitUnicodeString(&UserAllInfo.UserComment,
977 UserInfo3->usri3_usr_comment);
978 UserAllInfo.WhichFields |= USER_ALL_USERCOMMENT;
979 }
980
981 if (UserInfo3->usri3_parms != NULL)
982 {
983 RtlInitUnicodeString(&UserAllInfo.Parameters,
984 UserInfo3->usri3_parms);
985 UserAllInfo.WhichFields |= USER_ALL_PARAMETERS;
986 }
987
988 if (UserInfo3->usri3_workstations != NULL)
989 {
990 RtlInitUnicodeString(&UserAllInfo.WorkStations,
991 UserInfo3->usri3_workstations);
992 UserAllInfo.WhichFields |= USER_ALL_WORKSTATIONS;
993 }
994
995 // usri3_last_logon ignored
996 // usri3_last_logoff ignored
997
998 // UserInfo3->usri3_acct_expires;
999 // UserInfo3->usri3_max_storage;
1000 // UserInfo3->usri3_units_per_week;
1001 // UserInfo3->usri3_logon_hours;
1002
1003 // usri3_bad_pw_count ignored
1004 // usri3_num_logons ignored
1005 // usri3_logon_server ignored
1006
1007 // UserInfo3->usri3_country_code;
1008 // UserInfo3->usri3_code_page;
1009
1010 // usri3_user_id ignored
1011
1012 // UserInfo3->usri3_primary_group_id;
1013
1014 if (UserInfo3->usri3_profile != NULL)
1015 {
1016 RtlInitUnicodeString(&UserAllInfo.ProfilePath,
1017 UserInfo3->usri3_profile);
1018 UserAllInfo.WhichFields |= USER_ALL_PROFILEPATH;
1019 }
1020
1021 if (UserInfo3->usri3_home_dir_drive != NULL)
1022 {
1023 RtlInitUnicodeString(&UserAllInfo.HomeDirectoryDrive,
1024 UserInfo3->usri3_home_dir_drive);
1025 UserAllInfo.WhichFields |= USER_ALL_HOMEDIRECTORYDRIVE;
1026 }
1027
1028 // UserInfo3->usri3_password_expired;
1029 break;
1030
1031 // case 4:
1032 // case 21:
1033 // case 22:
1034
1035 case 1003:
1036 UserInfo1003 = (PUSER_INFO_1003)UserInfo;
1037
1038 if (UserInfo1003->usri1003_password != NULL)
1039 {
1040 RtlInitUnicodeString(&UserAllInfo.NtPassword,
1041 UserInfo1003->usri1003_password);
1042 UserAllInfo.NtPasswordPresent = TRUE;
1043 UserAllInfo.WhichFields |= USER_ALL_NTPASSWORDPRESENT;
1044 }
1045 break;
1046
1047 // case 1005:
1048
1049 case 1006:
1050 UserInfo1006 = (PUSER_INFO_1006)UserInfo;
1051
1052 if (UserInfo1006->usri1006_home_dir != NULL)
1053 {
1054 RtlInitUnicodeString(&UserAllInfo.HomeDirectory,
1055 UserInfo1006->usri1006_home_dir);
1056 UserAllInfo.WhichFields |= USER_ALL_HOMEDIRECTORY;
1057 }
1058 break;
1059
1060 case 1007:
1061 UserInfo1007 = (PUSER_INFO_1007)UserInfo;
1062
1063 if (UserInfo1007->usri1007_comment != NULL)
1064 {
1065 RtlInitUnicodeString(&UserAllInfo.AdminComment,
1066 UserInfo1007->usri1007_comment);
1067 UserAllInfo.WhichFields |= USER_ALL_ADMINCOMMENT;
1068 }
1069 break;
1070
1071 // case 1008:
1072
1073 case 1009:
1074 UserInfo1009 = (PUSER_INFO_1009)UserInfo;
1075
1076 if (UserInfo1009->usri1009_script_path != NULL)
1077 {
1078 RtlInitUnicodeString(&UserAllInfo.ScriptPath,
1079 UserInfo1009->usri1009_script_path);
1080 UserAllInfo.WhichFields |= USER_ALL_SCRIPTPATH;
1081 }
1082 break;
1083
1084 // case 1010:
1085
1086 case 1011:
1087 UserInfo1011 = (PUSER_INFO_1011)UserInfo;
1088
1089 if (UserInfo1011->usri1011_full_name != NULL)
1090 {
1091 RtlInitUnicodeString(&UserAllInfo.FullName,
1092 UserInfo1011->usri1011_full_name);
1093 UserAllInfo.WhichFields |= USER_ALL_FULLNAME;
1094 }
1095 break;
1096
1097 case 1012:
1098 UserInfo1012 = (PUSER_INFO_1012)UserInfo;
1099
1100 if (UserInfo1012->usri1012_usr_comment != NULL)
1101 {
1102 RtlInitUnicodeString(&UserAllInfo.UserComment,
1103 UserInfo1012->usri1012_usr_comment);
1104 UserAllInfo.WhichFields |= USER_ALL_USERCOMMENT;
1105 }
1106 break;
1107
1108 case 1013:
1109 UserInfo1013 = (PUSER_INFO_1013)UserInfo;
1110
1111 if (UserInfo1013->usri1013_parms != NULL)
1112 {
1113 RtlInitUnicodeString(&UserAllInfo.Parameters,
1114 UserInfo1013->usri1013_parms);
1115 UserAllInfo.WhichFields |= USER_ALL_PARAMETERS;
1116 }
1117 break;
1118
1119 case 1014:
1120 UserInfo1014 = (PUSER_INFO_1014)UserInfo;
1121
1122 if (UserInfo1014->usri1014_workstations != NULL)
1123 {
1124 RtlInitUnicodeString(&UserAllInfo.WorkStations,
1125 UserInfo1014->usri1014_workstations);
1126 UserAllInfo.WhichFields |= USER_ALL_WORKSTATIONS;
1127 }
1128 break;
1129
1130 // case 1017:
1131 // case 1020:
1132 // case 1024:
1133 // case 1051:
1134
1135 case 1052:
1136 UserInfo1052 = (PUSER_INFO_1052)UserInfo;
1137
1138 if (UserInfo1052->usri1052_profile != NULL)
1139 {
1140 RtlInitUnicodeString(&UserAllInfo.ProfilePath,
1141 UserInfo1052->usri1052_profile);
1142 UserAllInfo.WhichFields |= USER_ALL_PROFILEPATH;
1143 }
1144 break;
1145
1146 case 1053:
1147 UserInfo1053 = (PUSER_INFO_1053)UserInfo;
1148
1149 if (UserInfo1053->usri1053_home_dir_drive != NULL)
1150 {
1151 RtlInitUnicodeString(&UserAllInfo.HomeDirectoryDrive,
1152 UserInfo1053->usri1053_home_dir_drive);
1153 UserAllInfo.WhichFields |= USER_ALL_HOMEDIRECTORYDRIVE;
1154 }
1155 break;
1156
1157 default:
1158 ERR("Unsupported level %lu!\n", Level);
1159 return ERROR_INVALID_PARAMETER;
1160 }
1161
1162 Status = SamSetInformationUser(UserHandle,
1163 UserAllInformation,
1164 &UserAllInfo);
1165 if (!NT_SUCCESS(Status))
1166 {
1167 ERR("SamSetInformationUser failed (Status %08lx)\n", Status);
1168 ApiStatus = NetpNtStatusToApiStatus(Status);
1169 goto done;
1170 }
1171
1172 done:
1173 return ApiStatus;
1174 }
1175
1176
1177 static
1178 NET_API_STATUS
1179 OpenUserByName(SAM_HANDLE DomainHandle,
1180 PUNICODE_STRING UserName,
1181 ULONG DesiredAccess,
1182 PSAM_HANDLE UserHandle)
1183 {
1184 PULONG RelativeIds = NULL;
1185 PSID_NAME_USE Use = NULL;
1186 NET_API_STATUS ApiStatus = NERR_Success;
1187 NTSTATUS Status = STATUS_SUCCESS;
1188
1189 /* Get the RID for the given user name */
1190 Status = SamLookupNamesInDomain(DomainHandle,
1191 1,
1192 UserName,
1193 &RelativeIds,
1194 &Use);
1195 if (!NT_SUCCESS(Status))
1196 {
1197 ERR("SamLookupNamesInDomain failed (Status %08lx)\n", Status);
1198 return NetpNtStatusToApiStatus(Status);
1199 }
1200
1201 /* Fail, if it is not an alias account */
1202 if (Use[0] != SidTypeUser)
1203 {
1204 ERR("Object is not a user!\n");
1205 ApiStatus = NERR_GroupNotFound;
1206 goto done;
1207 }
1208
1209 /* Open the alias account */
1210 Status = SamOpenUser(DomainHandle,
1211 DesiredAccess,
1212 RelativeIds[0],
1213 UserHandle);
1214 if (!NT_SUCCESS(Status))
1215 {
1216 ERR("SamOpenUser failed (Status %08lx)\n", Status);
1217 ApiStatus = NetpNtStatusToApiStatus(Status);
1218 goto done;
1219 }
1220
1221 done:
1222 if (RelativeIds != NULL)
1223 SamFreeMemory(RelativeIds);
1224
1225 if (Use != NULL)
1226 SamFreeMemory(Use);
1227
1228 return ApiStatus;
1229 }
1230
1231
1232 /************************************************************
1233 * NetUserAdd (NETAPI32.@)
1234 */
1235 NET_API_STATUS
1236 WINAPI
1237 NetUserAdd(LPCWSTR servername,
1238 DWORD level,
1239 LPBYTE bufptr,
1240 LPDWORD parm_err)
1241 {
1242 UNICODE_STRING ServerName;
1243 UNICODE_STRING UserName;
1244 SAM_HANDLE ServerHandle = NULL;
1245 SAM_HANDLE DomainHandle = NULL;
1246 SAM_HANDLE UserHandle = NULL;
1247 ULONG GrantedAccess;
1248 ULONG RelativeId;
1249 NET_API_STATUS ApiStatus = NERR_Success;
1250 NTSTATUS Status = STATUS_SUCCESS;
1251
1252 TRACE("(%s, %d, %p, %p)\n", debugstr_w(servername), level, bufptr, parm_err);
1253
1254 /* Check the info level */
1255 switch (level)
1256 {
1257 case 1:
1258 case 2:
1259 case 3:
1260 case 4:
1261 break;
1262
1263 default:
1264 return ERROR_INVALID_LEVEL;
1265 }
1266
1267 if (servername != NULL)
1268 RtlInitUnicodeString(&ServerName, servername);
1269
1270 /* Connect to the SAM Server */
1271 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
1272 &ServerHandle,
1273 SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
1274 NULL);
1275 if (!NT_SUCCESS(Status))
1276 {
1277 ERR("SamConnect failed (Status %08lx)\n", Status);
1278 ApiStatus = NetpNtStatusToApiStatus(Status);
1279 goto done;
1280 }
1281
1282 /* Open the Account Domain */
1283 Status = OpenAccountDomain(ServerHandle,
1284 (servername != NULL) ? &ServerName : NULL,
1285 DOMAIN_CREATE_USER | DOMAIN_LOOKUP,
1286 &DomainHandle);
1287 if (!NT_SUCCESS(Status))
1288 {
1289 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
1290 ApiStatus = NetpNtStatusToApiStatus(Status);
1291 goto done;
1292 }
1293
1294 /* Initialize the user name string */
1295 RtlInitUnicodeString(&UserName,
1296 ((PUSER_INFO_1)bufptr)->usri1_name);
1297
1298 /* Create the user account */
1299 Status = SamCreateUser2InDomain(DomainHandle,
1300 &UserName,
1301 USER_NORMAL_ACCOUNT,
1302 USER_ALL_ACCESS | DELETE | WRITE_DAC,
1303 &UserHandle,
1304 &GrantedAccess,
1305 &RelativeId);
1306 if (!NT_SUCCESS(Status))
1307 {
1308 ERR("SamCreateUser2InDomain failed (Status %08lx)\n", Status);
1309 ApiStatus = NetpNtStatusToApiStatus(Status);
1310 goto done;
1311 }
1312
1313 /* Set user information */
1314 ApiStatus = SetUserInfo(UserHandle,
1315 bufptr,
1316 level);
1317 if (ApiStatus != NERR_Success)
1318 {
1319 ERR("SetUserInfo failed (Status %lu)\n", ApiStatus);
1320 goto done;
1321 }
1322
1323 done:
1324 if (UserHandle != NULL)
1325 SamCloseHandle(UserHandle);
1326
1327 if (DomainHandle != NULL)
1328 SamCloseHandle(DomainHandle);
1329
1330 if (ServerHandle != NULL)
1331 SamCloseHandle(ServerHandle);
1332
1333 return ApiStatus;
1334 }
1335
1336
1337 /******************************************************************************
1338 * NetUserChangePassword (NETAPI32.@)
1339 * PARAMS
1340 * domainname [I] Optional. Domain on which the user resides or the logon
1341 * domain of the current user if NULL.
1342 * username [I] Optional. Username to change the password for or the name
1343 * of the current user if NULL.
1344 * oldpassword [I] The user's current password.
1345 * newpassword [I] The password that the user will be changed to using.
1346 *
1347 * RETURNS
1348 * Success: NERR_Success.
1349 * Failure: NERR_* failure code or win error code.
1350 *
1351 */
1352 NET_API_STATUS
1353 WINAPI
1354 NetUserChangePassword(LPCWSTR domainname,
1355 LPCWSTR username,
1356 LPCWSTR oldpassword,
1357 LPCWSTR newpassword)
1358 {
1359 TRACE("(%s, %s, ..., ...)\n", debugstr_w(domainname), debugstr_w(username));
1360 return NERR_Success;
1361 }
1362
1363
1364 /************************************************************
1365 * NetUserDel (NETAPI32.@)
1366 */
1367 NET_API_STATUS
1368 WINAPI
1369 NetUserDel(LPCWSTR servername,
1370 LPCWSTR username)
1371 {
1372 UNICODE_STRING ServerName;
1373 UNICODE_STRING UserName;
1374 SAM_HANDLE ServerHandle = NULL;
1375 SAM_HANDLE DomainHandle = NULL;
1376 SAM_HANDLE UserHandle = NULL;
1377 NET_API_STATUS ApiStatus = NERR_Success;
1378 NTSTATUS Status = STATUS_SUCCESS;
1379
1380 TRACE("(%s, %s)\n", debugstr_w(servername), debugstr_w(username));
1381
1382 if (servername != NULL)
1383 RtlInitUnicodeString(&ServerName, servername);
1384
1385 RtlInitUnicodeString(&UserName, username);
1386
1387 /* Connect to the SAM Server */
1388 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
1389 &ServerHandle,
1390 SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
1391 NULL);
1392 if (!NT_SUCCESS(Status))
1393 {
1394 ERR("SamConnect failed (Status %08lx)\n", Status);
1395 ApiStatus = NetpNtStatusToApiStatus(Status);
1396 goto done;
1397 }
1398
1399 /* Open the Builtin Domain */
1400 Status = OpenBuiltinDomain(ServerHandle,
1401 DOMAIN_LOOKUP,
1402 &DomainHandle);
1403 if (!NT_SUCCESS(Status))
1404 {
1405 ERR("OpenBuiltinDomain failed (Status %08lx)\n", Status);
1406 ApiStatus = NetpNtStatusToApiStatus(Status);
1407 goto done;
1408 }
1409
1410 /* Open the user account in the builtin domain */
1411 ApiStatus = OpenUserByName(DomainHandle,
1412 &UserName,
1413 DELETE,
1414 &UserHandle);
1415 if (ApiStatus != NERR_Success && ApiStatus != ERROR_NONE_MAPPED)
1416 {
1417 TRACE("OpenUserByName failed (ApiStatus %lu)\n", ApiStatus);
1418 goto done;
1419 }
1420
1421 if (UserHandle == NULL)
1422 {
1423 if (DomainHandle != NULL)
1424 {
1425 SamCloseHandle(DomainHandle);
1426 DomainHandle = NULL;
1427 }
1428
1429 /* Open the Acount Domain */
1430 Status = OpenAccountDomain(ServerHandle,
1431 (servername != NULL) ? &ServerName : NULL,
1432 DOMAIN_LOOKUP,
1433 &DomainHandle);
1434 if (!NT_SUCCESS(Status))
1435 {
1436 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
1437 ApiStatus = NetpNtStatusToApiStatus(Status);
1438 goto done;
1439 }
1440
1441 /* Open the user account in the account domain */
1442 ApiStatus = OpenUserByName(DomainHandle,
1443 &UserName,
1444 DELETE,
1445 &UserHandle);
1446 if (ApiStatus != NERR_Success)
1447 {
1448 ERR("OpenUserByName failed (ApiStatus %lu)\n", ApiStatus);
1449 if (ApiStatus == ERROR_NONE_MAPPED)
1450 ApiStatus = NERR_GroupNotFound;
1451 goto done;
1452 }
1453 }
1454
1455 /* Delete the user */
1456 Status = SamDeleteUser(UserHandle);
1457 if (!NT_SUCCESS(Status))
1458 {
1459 ERR("SamDeleteUser failed (Status %08lx)\n", Status);
1460 ApiStatus = NetpNtStatusToApiStatus(Status);
1461 goto done;
1462 }
1463
1464 done:
1465 if (UserHandle != NULL)
1466 SamCloseHandle(UserHandle);
1467
1468 if (DomainHandle != NULL)
1469 SamCloseHandle(DomainHandle);
1470
1471 if (ServerHandle != NULL)
1472 SamCloseHandle(ServerHandle);
1473
1474 return ApiStatus;
1475 }
1476
1477
1478 /************************************************************
1479 * NetUserEnum (NETAPI32.@)
1480 */
1481 NET_API_STATUS
1482 WINAPI
1483 NetUserEnum(LPCWSTR servername,
1484 DWORD level,
1485 DWORD filter,
1486 LPBYTE* bufptr,
1487 DWORD prefmaxlen,
1488 LPDWORD entriesread,
1489 LPDWORD totalentries,
1490 LPDWORD resume_handle)
1491 {
1492 UNICODE_STRING ServerName;
1493 PSAM_RID_ENUMERATION CurrentUser;
1494 PENUM_CONTEXT EnumContext = NULL;
1495 LPVOID Buffer = NULL;
1496 ULONG i;
1497 SAM_HANDLE UserHandle = NULL;
1498 PUSER_ACCOUNT_INFORMATION UserInfo = NULL;
1499
1500 NET_API_STATUS ApiStatus = NERR_Success;
1501 NTSTATUS Status = STATUS_SUCCESS;
1502
1503 TRACE("(%s %d 0x%d %p %d %p %p %p)\n", debugstr_w(servername), level,
1504 filter, bufptr, prefmaxlen, entriesread, totalentries, resume_handle);
1505
1506 *entriesread = 0;
1507 *totalentries = 0;
1508 *bufptr = NULL;
1509
1510 if (servername != NULL)
1511 RtlInitUnicodeString(&ServerName, servername);
1512
1513 if (resume_handle != NULL && *resume_handle != 0)
1514 {
1515 EnumContext = (PENUM_CONTEXT)*resume_handle;
1516 }
1517 else
1518 {
1519 ApiStatus = NetApiBufferAllocate(sizeof(ENUM_CONTEXT), (PVOID*)&EnumContext);
1520 if (ApiStatus != NERR_Success)
1521 goto done;
1522
1523 EnumContext->EnumerationContext = 0;
1524 EnumContext->Buffer = NULL;
1525 EnumContext->Count = 0;
1526 EnumContext->Index = 0;
1527 EnumContext->BuiltinDone = FALSE;
1528
1529 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
1530 &EnumContext->ServerHandle,
1531 SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
1532 NULL);
1533 if (!NT_SUCCESS(Status))
1534 {
1535 ERR("SamConnect failed (Status %08lx)\n", Status);
1536 ApiStatus = NetpNtStatusToApiStatus(Status);
1537 goto done;
1538 }
1539
1540 Status = OpenAccountDomain(EnumContext->ServerHandle,
1541 (servername != NULL) ? &ServerName : NULL,
1542 DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP,
1543 &EnumContext->AccountDomainHandle);
1544 if (!NT_SUCCESS(Status))
1545 {
1546 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
1547 ApiStatus = NetpNtStatusToApiStatus(Status);
1548 goto done;
1549 }
1550
1551 Status = OpenBuiltinDomain(EnumContext->ServerHandle,
1552 DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP,
1553 &EnumContext->BuiltinDomainHandle);
1554 if (!NT_SUCCESS(Status))
1555 {
1556 ERR("OpenBuiltinDomain failed (Status %08lx)\n", Status);
1557 ApiStatus = NetpNtStatusToApiStatus(Status);
1558 goto done;
1559 }
1560 }
1561
1562 // while (TRUE)
1563 // {
1564 TRACE("EnumContext->Index: %lu\n", EnumContext->Index);
1565 TRACE("EnumContext->Count: %lu\n", EnumContext->Count);
1566
1567 if (EnumContext->Index >= EnumContext->Count)
1568 {
1569 // if (EnumContext->BuiltinDone == TRUE)
1570 // {
1571 // ApiStatus = NERR_Success;
1572 // goto done;
1573 // }
1574
1575 TRACE("Calling SamEnumerateUsersInDomain\n");
1576 Status = SamEnumerateUsersInDomain(EnumContext->AccountDomainHandle, //BuiltinDomainHandle,
1577 &EnumContext->EnumerationContext,
1578 0,
1579 (PVOID *)&EnumContext->Buffer,
1580 prefmaxlen,
1581 &EnumContext->Count);
1582
1583 TRACE("SamEnumerateUsersInDomain returned (Status %08lx)\n", Status);
1584 if (!NT_SUCCESS(Status))
1585 {
1586 ERR("SamEnumerateUsersInDomain failed (Status %08lx)\n", Status);
1587 ApiStatus = NetpNtStatusToApiStatus(Status);
1588 goto done;
1589 }
1590
1591 if (Status == STATUS_MORE_ENTRIES)
1592 {
1593 ApiStatus = NERR_BufTooSmall;
1594 goto done;
1595 }
1596 else
1597 {
1598 EnumContext->BuiltinDone = TRUE;
1599 }
1600 }
1601
1602 TRACE("EnumContext: %lu\n", EnumContext);
1603 TRACE("EnumContext->Count: %lu\n", EnumContext->Count);
1604 TRACE("EnumContext->Buffer: %p\n", EnumContext->Buffer);
1605
1606 /* Get a pointer to the current user */
1607 CurrentUser = &EnumContext->Buffer[EnumContext->Index];
1608
1609 TRACE("RID: %lu\n", CurrentUser->RelativeId);
1610
1611 Status = SamOpenUser(EnumContext->AccountDomainHandle, //BuiltinDomainHandle,
1612 USER_READ_GENERAL | USER_READ_PREFERENCES | USER_READ_LOGON | USER_READ_ACCOUNT,
1613 CurrentUser->RelativeId,
1614 &UserHandle);
1615 if (!NT_SUCCESS(Status))
1616 {
1617 ERR("SamOpenUser failed (Status %08lx)\n", Status);
1618 ApiStatus = NetpNtStatusToApiStatus(Status);
1619 goto done;
1620 }
1621
1622 Status = SamQueryInformationUser(UserHandle,
1623 UserAccountInformation,
1624 (PVOID *)&UserInfo);
1625 if (!NT_SUCCESS(Status))
1626 {
1627 ERR("SamQueryInformationUser failed (Status %08lx)\n", Status);
1628 ApiStatus = NetpNtStatusToApiStatus(Status);
1629 goto done;
1630 }
1631
1632 SamCloseHandle(UserHandle);
1633 UserHandle = NULL;
1634
1635 ApiStatus = BuildUserInfoBuffer(UserInfo,
1636 level,
1637 CurrentUser->RelativeId,
1638 &Buffer);
1639 if (ApiStatus != NERR_Success)
1640 {
1641 ERR("BuildUserInfoBuffer failed (ApiStatus %lu)\n", ApiStatus);
1642 goto done;
1643 }
1644
1645 if (UserInfo != NULL)
1646 {
1647 FreeUserInfo(UserInfo);
1648 UserInfo = NULL;
1649 }
1650
1651 EnumContext->Index++;
1652
1653 (*entriesread)++;
1654 // }
1655
1656 done:
1657 if (ApiStatus == NERR_Success && EnumContext->Index < EnumContext->Count)
1658 ApiStatus = ERROR_MORE_DATA;
1659
1660 if (EnumContext != NULL)
1661 *totalentries = EnumContext->Count;
1662
1663 if (resume_handle == NULL || ApiStatus != ERROR_MORE_DATA)
1664 {
1665 if (EnumContext != NULL)
1666 {
1667 if (EnumContext->BuiltinDomainHandle != NULL)
1668 SamCloseHandle(EnumContext->BuiltinDomainHandle);
1669
1670 if (EnumContext->AccountDomainHandle != NULL)
1671 SamCloseHandle(EnumContext->AccountDomainHandle);
1672
1673 if (EnumContext->ServerHandle != NULL)
1674 SamCloseHandle(EnumContext->ServerHandle);
1675
1676 if (EnumContext->Buffer != NULL)
1677 {
1678 for (i = 0; i < EnumContext->Count; i++)
1679 {
1680 SamFreeMemory(EnumContext->Buffer[i].Name.Buffer);
1681 }
1682
1683 SamFreeMemory(EnumContext->Buffer);
1684 }
1685
1686 NetApiBufferFree(EnumContext);
1687 EnumContext = NULL;
1688 }
1689 }
1690
1691 if (UserHandle != NULL)
1692 SamCloseHandle(UserHandle);
1693
1694 if (UserInfo != NULL)
1695 FreeUserInfo(UserInfo);
1696
1697 if (resume_handle != NULL)
1698 *resume_handle = (DWORD_PTR)EnumContext;
1699
1700 *bufptr = (LPBYTE)Buffer;
1701
1702 TRACE("return %lu\n", ApiStatus);
1703
1704 return ApiStatus;
1705 }
1706
1707
1708 /************************************************************
1709 * NetUserGetGroups (NETAPI32.@)
1710 */
1711 NET_API_STATUS
1712 WINAPI
1713 NetUserGetGroups(LPCWSTR servername,
1714 LPCWSTR username,
1715 DWORD level,
1716 LPBYTE *bufptr,
1717 DWORD prefixmaxlen,
1718 LPDWORD entriesread,
1719 LPDWORD totalentries)
1720 {
1721 FIXME("%s %s %d %p %d %p %p stub\n", debugstr_w(servername),
1722 debugstr_w(username), level, bufptr, prefixmaxlen, entriesread,
1723 totalentries);
1724
1725 *bufptr = NULL;
1726 *entriesread = 0;
1727 *totalentries = 0;
1728
1729 return ERROR_INVALID_LEVEL;
1730 }
1731
1732
1733 /************************************************************
1734 * NetUserGetInfo (NETAPI32.@)
1735 */
1736 NET_API_STATUS
1737 WINAPI
1738 NetUserGetInfo(LPCWSTR servername,
1739 LPCWSTR username,
1740 DWORD level,
1741 LPBYTE* bufptr)
1742 {
1743 UNICODE_STRING ServerName;
1744 UNICODE_STRING UserName;
1745 SAM_HANDLE ServerHandle = NULL;
1746 SAM_HANDLE AccountDomainHandle = NULL;
1747 SAM_HANDLE UserHandle = NULL;
1748 PULONG RelativeIds = NULL;
1749 PSID_NAME_USE Use = NULL;
1750 PUSER_ACCOUNT_INFORMATION UserInfo = NULL;
1751 LPVOID Buffer = NULL;
1752 NET_API_STATUS ApiStatus = NERR_Success;
1753 NTSTATUS Status = STATUS_SUCCESS;
1754
1755 TRACE("(%s, %s, %d, %p)\n", debugstr_w(servername),
1756 debugstr_w(username), level, bufptr);
1757
1758 if (servername != NULL)
1759 RtlInitUnicodeString(&ServerName, servername);
1760
1761 RtlInitUnicodeString(&UserName, username);
1762
1763 /* Connect to the SAM Server */
1764 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
1765 &ServerHandle,
1766 SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
1767 NULL);
1768 if (!NT_SUCCESS(Status))
1769 {
1770 ERR("SamConnect failed (Status %08lx)\n", Status);
1771 ApiStatus = NetpNtStatusToApiStatus(Status);
1772 goto done;
1773 }
1774
1775 /* Open the Account Domain */
1776 Status = OpenAccountDomain(ServerHandle,
1777 (servername != NULL) ? &ServerName : NULL,
1778 DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP,
1779 &AccountDomainHandle);
1780 if (!NT_SUCCESS(Status))
1781 {
1782 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
1783 ApiStatus = NetpNtStatusToApiStatus(Status);
1784 goto done;
1785 }
1786
1787 /* Get the RID for the given user name */
1788 Status = SamLookupNamesInDomain(AccountDomainHandle,
1789 1,
1790 &UserName,
1791 &RelativeIds,
1792 &Use);
1793 if (!NT_SUCCESS(Status))
1794 {
1795 ERR("SamOpenDomain failed (Status %08lx)\n", Status);
1796 ApiStatus = NetpNtStatusToApiStatus(Status);
1797 goto done;
1798 }
1799
1800 /* Check if the account is a user account */
1801 if (Use[0] != SidTypeUser)
1802 {
1803 ERR("No user found!\n");
1804 ApiStatus = NERR_UserNotFound;
1805 goto done;
1806 }
1807
1808 TRACE("RID: %lu\n", RelativeIds[0]);
1809
1810 /* Open the user object */
1811 Status = SamOpenUser(AccountDomainHandle,
1812 USER_READ_GENERAL | USER_READ_PREFERENCES | USER_READ_LOGON | USER_READ_ACCOUNT,
1813 RelativeIds[0],
1814 &UserHandle);
1815 if (!NT_SUCCESS(Status))
1816 {
1817 ERR("SamOpenUser failed (Status %08lx)\n", Status);
1818 ApiStatus = NetpNtStatusToApiStatus(Status);
1819 goto done;
1820 }
1821
1822 Status = SamQueryInformationUser(UserHandle,
1823 UserAccountInformation,
1824 (PVOID *)&UserInfo);
1825 if (!NT_SUCCESS(Status))
1826 {
1827 ERR("SamQueryInformationUser failed (Status %08lx)\n", Status);
1828 ApiStatus = NetpNtStatusToApiStatus(Status);
1829 goto done;
1830 }
1831
1832 ApiStatus = BuildUserInfoBuffer(UserInfo,
1833 level,
1834 RelativeIds[0],
1835 &Buffer);
1836 if (ApiStatus != NERR_Success)
1837 {
1838 ERR("BuildUserInfoBuffer failed (ApiStatus %08lu)\n", ApiStatus);
1839 goto done;
1840 }
1841
1842 done:
1843 if (UserInfo != NULL)
1844 FreeUserInfo(UserInfo);
1845
1846 if (UserHandle != NULL)
1847 SamCloseHandle(UserHandle);
1848
1849 if (RelativeIds != NULL)
1850 SamFreeMemory(RelativeIds);
1851
1852 if (Use != NULL)
1853 SamFreeMemory(Use);
1854
1855 if (AccountDomainHandle != NULL)
1856 SamCloseHandle(AccountDomainHandle);
1857
1858 if (ServerHandle != NULL)
1859 SamCloseHandle(ServerHandle);
1860
1861 *bufptr = (LPBYTE)Buffer;
1862
1863 return ApiStatus;
1864 }
1865
1866
1867 /************************************************************
1868 * NetUserGetLocalGroups (NETAPI32.@)
1869 */
1870 NET_API_STATUS
1871 WINAPI
1872 NetUserGetLocalGroups(LPCWSTR servername,
1873 LPCWSTR username,
1874 DWORD level,
1875 DWORD flags,
1876 LPBYTE* bufptr,
1877 DWORD prefmaxlen,
1878 LPDWORD entriesread,
1879 LPDWORD totalentries)
1880 {
1881 UNICODE_STRING ServerName;
1882 UNICODE_STRING UserName;
1883 SAM_HANDLE ServerHandle = NULL;
1884 SAM_HANDLE BuiltinDomainHandle = NULL;
1885 SAM_HANDLE AccountDomainHandle = NULL;
1886 PSID AccountDomainSid = NULL;
1887 PSID UserSid = NULL;
1888 PULONG RelativeIds = NULL;
1889 PSID_NAME_USE Use = NULL;
1890 ULONG BuiltinMemberCount = 0;
1891 ULONG AccountMemberCount = 0;
1892 PULONG BuiltinAliases = NULL;
1893 PULONG AccountAliases = NULL;
1894 PUNICODE_STRING BuiltinNames = NULL;
1895 PUNICODE_STRING AccountNames = NULL;
1896 PLOCALGROUP_USERS_INFO_0 Buffer = NULL;
1897 ULONG Size;
1898 ULONG Count = 0;
1899 ULONG Index;
1900 ULONG i;
1901 LPWSTR StrPtr;
1902 NET_API_STATUS ApiStatus = NERR_Success;
1903 NTSTATUS Status = STATUS_SUCCESS;
1904
1905 TRACE("(%s, %s, %d, %08x, %p %d, %p, %p) stub!\n",
1906 debugstr_w(servername), debugstr_w(username), level, flags, bufptr,
1907 prefmaxlen, entriesread, totalentries);
1908
1909 if (level != 0)
1910 return ERROR_INVALID_LEVEL;
1911
1912 if (flags & ~LG_INCLUDE_INDIRECT)
1913 return ERROR_INVALID_PARAMETER;
1914
1915 if (flags & LG_INCLUDE_INDIRECT)
1916 {
1917 WARN("The flag LG_INCLUDE_INDIRECT is not supported yet!\n");
1918 }
1919
1920 if (servername != NULL)
1921 RtlInitUnicodeString(&ServerName, servername);
1922
1923 RtlInitUnicodeString(&UserName, username);
1924
1925 /* Connect to the SAM Server */
1926 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
1927 &ServerHandle,
1928 SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
1929 NULL);
1930 if (!NT_SUCCESS(Status))
1931 {
1932 ERR("SamConnect failed (Status %08lx)\n", Status);
1933 ApiStatus = NetpNtStatusToApiStatus(Status);
1934 goto done;
1935 }
1936
1937 /* Open the Builtin Domain */
1938 Status = OpenBuiltinDomain(ServerHandle,
1939 DOMAIN_LOOKUP | DOMAIN_GET_ALIAS_MEMBERSHIP,
1940 &BuiltinDomainHandle);
1941 if (!NT_SUCCESS(Status))
1942 {
1943 ERR("OpenBuiltinDomain failed (Status %08lx)\n", Status);
1944 ApiStatus = NetpNtStatusToApiStatus(Status);
1945 goto done;
1946 }
1947
1948 /* Get the Account Domain SID */
1949 Status = GetAccountDomainSid((servername != NULL) ? &ServerName : NULL,
1950 &AccountDomainSid);
1951 if (!NT_SUCCESS(Status))
1952 {
1953 ERR("GetAccountDomainSid failed (Status %08lx)\n", Status);
1954 ApiStatus = NetpNtStatusToApiStatus(Status);
1955 goto done;
1956 }
1957
1958 /* Open the Account Domain */
1959 Status = SamOpenDomain(ServerHandle,
1960 DOMAIN_LOOKUP | DOMAIN_GET_ALIAS_MEMBERSHIP,
1961 AccountDomainSid,
1962 &AccountDomainHandle);
1963 if (!NT_SUCCESS(Status))
1964 {
1965 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
1966 ApiStatus = NetpNtStatusToApiStatus(Status);
1967 goto done;
1968 }
1969
1970 /* Get the RID for the given user name */
1971 Status = SamLookupNamesInDomain(AccountDomainHandle,
1972 1,
1973 &UserName,
1974 &RelativeIds,
1975 &Use);
1976 if (!NT_SUCCESS(Status))
1977 {
1978 ERR("SamLookupNamesInDomain failed (Status %08lx)\n", Status);
1979 ApiStatus = NetpNtStatusToApiStatus(Status);
1980 goto done;
1981 }
1982
1983 /* Fail, if it is not a user account */
1984 if (Use[0] != SidTypeUser)
1985 {
1986 ERR("Account is not a User!\n");
1987 ApiStatus = NERR_UserNotFound;
1988 goto done;
1989 }
1990
1991 /* Build the User SID from the Account Domain SID and the users RID */
1992 ApiStatus = BuildSidFromSidAndRid(AccountDomainSid,
1993 RelativeIds[0],
1994 &UserSid);
1995 if (ApiStatus != NERR_Success)
1996 {
1997 ERR("BuildSidFromSidAndRid failed!\n");
1998 goto done;
1999 }
2000
2001 /* Get alias memberships in the Builtin Domain */
2002 Status = SamGetAliasMembership(BuiltinDomainHandle,
2003 1,
2004 &UserSid,
2005 &BuiltinMemberCount,
2006 &BuiltinAliases);
2007 if (!NT_SUCCESS(Status))
2008 {
2009 ERR("SamGetAliasMembership failed (Status %08lx)\n", Status);
2010 ApiStatus = NetpNtStatusToApiStatus(Status);
2011 goto done;
2012 }
2013
2014 if (BuiltinMemberCount > 0)
2015 {
2016 /* Get the Names of the builtin alias members */
2017 Status = SamLookupIdsInDomain(BuiltinDomainHandle,
2018 BuiltinMemberCount,
2019 BuiltinAliases,
2020 &BuiltinNames,
2021 NULL);
2022 if (!NT_SUCCESS(Status))
2023 {
2024 ERR("SamLookupIdsInDomain failed (Status %08lx)\n", Status);
2025 ApiStatus = NetpNtStatusToApiStatus(Status);
2026 goto done;
2027 }
2028 }
2029
2030 /* Get alias memberships in the Account Domain */
2031 Status = SamGetAliasMembership(AccountDomainHandle,
2032 1,
2033 &UserSid,
2034 &AccountMemberCount,
2035 &AccountAliases);
2036 if (!NT_SUCCESS(Status))
2037 {
2038 ERR("SamGetAliasMembership failed (Status %08lx)\n", Status);
2039 ApiStatus = NetpNtStatusToApiStatus(Status);
2040 goto done;
2041 }
2042
2043 if (AccountMemberCount > 0)
2044 {
2045 /* Get the Names of the builtin alias members */
2046 Status = SamLookupIdsInDomain(AccountDomainHandle,
2047 AccountMemberCount,
2048 AccountAliases,
2049 &AccountNames,
2050 NULL);
2051 if (!NT_SUCCESS(Status))
2052 {
2053 ERR("SamLookupIdsInDomain failed (Status %08lx)\n", Status);
2054 ApiStatus = NetpNtStatusToApiStatus(Status);
2055 goto done;
2056 }
2057 }
2058
2059 /* Calculate the required buffer size */
2060 Size = 0;
2061
2062 for (i = 0; i < BuiltinMemberCount; i++)
2063 {
2064 if (BuiltinNames[i].Length > 0)
2065 {
2066 Size += (sizeof(LOCALGROUP_USERS_INFO_0) + BuiltinNames[i].Length + sizeof(UNICODE_NULL));
2067 Count++;
2068 }
2069 }
2070
2071 for (i = 0; i < AccountMemberCount; i++)
2072 {
2073 if (BuiltinNames[i].Length > 0)
2074 {
2075 Size += (sizeof(LOCALGROUP_USERS_INFO_0) + AccountNames[i].Length + sizeof(UNICODE_NULL));
2076 Count++;
2077 }
2078 }
2079
2080 if (Size == 0)
2081 {
2082 ApiStatus = NERR_Success;
2083 goto done;
2084 }
2085
2086 /* Allocate buffer */
2087 ApiStatus = NetApiBufferAllocate(Size, (LPVOID*)&Buffer);
2088 if (ApiStatus != NERR_Success)
2089 goto done;
2090
2091 ZeroMemory(Buffer, Size);
2092
2093 StrPtr = (LPWSTR)((INT_PTR)Buffer + Count * sizeof(LOCALGROUP_USERS_INFO_0));
2094
2095 /* Copy data to the allocated buffer */
2096 Index = 0;
2097 for (i = 0; i < BuiltinMemberCount; i++)
2098 {
2099 if (BuiltinNames[i].Length > 0)
2100 {
2101 CopyMemory(StrPtr,
2102 BuiltinNames[i].Buffer,
2103 BuiltinNames[i].Length);
2104 Buffer[Index].lgrui0_name = StrPtr;
2105
2106 StrPtr = (LPWSTR)((INT_PTR)StrPtr + BuiltinNames[i].Length + sizeof(UNICODE_NULL));
2107 Index++;
2108 }
2109 }
2110
2111 for (i = 0; i < AccountMemberCount; i++)
2112 {
2113 if (AccountNames[i].Length > 0)
2114 {
2115 CopyMemory(StrPtr,
2116 AccountNames[i].Buffer,
2117 AccountNames[i].Length);
2118 Buffer[Index].lgrui0_name = StrPtr;
2119
2120 StrPtr = (LPWSTR)((INT_PTR)StrPtr + AccountNames[i].Length + sizeof(UNICODE_NULL));
2121 Index++;
2122 }
2123 }
2124
2125 done:
2126 if (AccountNames != NULL)
2127 SamFreeMemory(AccountNames);
2128
2129 if (BuiltinNames != NULL)
2130 SamFreeMemory(BuiltinNames);
2131
2132 if (AccountAliases != NULL)
2133 SamFreeMemory(AccountAliases);
2134
2135 if (BuiltinAliases != NULL)
2136 SamFreeMemory(BuiltinAliases);
2137
2138 if (RelativeIds != NULL)
2139 SamFreeMemory(RelativeIds);
2140
2141 if (Use != NULL)
2142 SamFreeMemory(Use);
2143
2144 if (UserSid != NULL)
2145 NetApiBufferFree(UserSid);
2146
2147 if (AccountDomainSid != NULL)
2148 RtlFreeHeap(RtlGetProcessHeap(), 0, AccountDomainSid);
2149
2150 if (AccountDomainHandle != NULL)
2151 SamCloseHandle(AccountDomainHandle);
2152
2153 if (BuiltinDomainHandle != NULL)
2154 SamCloseHandle(BuiltinDomainHandle);
2155
2156 if (ServerHandle != NULL)
2157 SamCloseHandle(ServerHandle);
2158
2159 if (ApiStatus != NERR_Success && ApiStatus != ERROR_MORE_DATA)
2160 {
2161 *entriesread = 0;
2162 *totalentries = 0;
2163 }
2164 else
2165 {
2166 *entriesread = Count;
2167 *totalentries = Count;
2168 }
2169
2170 *bufptr = (LPBYTE)Buffer;
2171
2172 return ApiStatus;
2173 }
2174
2175
2176 /******************************************************************************
2177 * NetUserSetGroups (NETAPI32.@)
2178 */
2179 NET_API_STATUS
2180 WINAPI
2181 NetUserSetGroups(LPCWSTR servername,
2182 LPCWSTR username,
2183 DWORD level,
2184 LPBYTE buf,
2185 DWORD num_entries)
2186 {
2187 FIXME("(%s %s %lu %p %lu)\n",
2188 debugstr_w(servername), debugstr_w(username), level, buf, num_entries);
2189 return ERROR_ACCESS_DENIED;
2190 }
2191
2192
2193 /******************************************************************************
2194 * NetUserSetInfo (NETAPI32.@)
2195 */
2196 NET_API_STATUS
2197 WINAPI
2198 NetUserSetInfo(LPCWSTR servername,
2199 LPCWSTR username,
2200 DWORD level,
2201 LPBYTE buf,
2202 LPDWORD parm_err)
2203 {
2204 UNICODE_STRING ServerName;
2205 UNICODE_STRING UserName;
2206 SAM_HANDLE ServerHandle = NULL;
2207 SAM_HANDLE AccountDomainHandle = NULL;
2208 SAM_HANDLE UserHandle = NULL;
2209 NET_API_STATUS ApiStatus = NERR_Success;
2210 NTSTATUS Status = STATUS_SUCCESS;
2211
2212 TRACE("(%s %s %lu %p %p)\n",
2213 debugstr_w(servername), debugstr_w(username), level, buf, parm_err);
2214
2215 /* Check the info level */
2216 switch (level)
2217 {
2218 case 0:
2219 case 1:
2220 case 2:
2221 case 3:
2222 // case 4:
2223 // case 21:
2224 // case 22:
2225 case 1003:
2226 // case 1005:
2227 case 1006:
2228 case 1007:
2229 // case 1008:
2230 case 1009:
2231 // case 1010:
2232 case 1011:
2233 case 1012:
2234 case 1013:
2235 case 1014:
2236 // case 1017:
2237 // case 1020:
2238 // case 1024:
2239 // case 1051:
2240 case 1052:
2241 case 1053:
2242 break;
2243
2244 default:
2245 return ERROR_INVALID_LEVEL;
2246 }
2247
2248 if (servername != NULL)
2249 RtlInitUnicodeString(&ServerName, servername);
2250
2251 RtlInitUnicodeString(&UserName, username);
2252
2253 /* Connect to the SAM Server */
2254 Status = SamConnect((servername != NULL) ? &ServerName : NULL,
2255 &ServerHandle,
2256 SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
2257 NULL);
2258 if (!NT_SUCCESS(Status))
2259 {
2260 ERR("SamConnect failed (Status %08lx)\n", Status);
2261 ApiStatus = NetpNtStatusToApiStatus(Status);
2262 goto done;
2263 }
2264
2265 /* Open the Account Domain */
2266 Status = OpenAccountDomain(ServerHandle,
2267 (servername != NULL) ? &ServerName : NULL,
2268 DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP,
2269 &AccountDomainHandle);
2270 if (!NT_SUCCESS(Status))
2271 {
2272 ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
2273 ApiStatus = NetpNtStatusToApiStatus(Status);
2274 goto done;
2275 }
2276
2277 /* Open the User Account */
2278 ApiStatus = OpenUserByName(AccountDomainHandle,
2279 &UserName,
2280 USER_ALL_ACCESS,
2281 &UserHandle);
2282 if (ApiStatus != NERR_Success)
2283 {
2284 ERR("OpenUserByName failed (ApiStatus %lu)\n", ApiStatus);
2285 goto done;
2286 }
2287
2288 /* Set user information */
2289 ApiStatus = SetUserInfo(UserHandle,
2290 buf,
2291 level);
2292 if (ApiStatus != NERR_Success)
2293 {
2294 ERR("SetUserInfo failed (Status %lu)\n", ApiStatus);
2295 }
2296
2297 done:
2298 if (UserHandle != NULL)
2299 SamCloseHandle(UserHandle);
2300
2301 if (AccountDomainHandle != NULL)
2302 SamCloseHandle(AccountDomainHandle);
2303
2304 if (ServerHandle != NULL)
2305 SamCloseHandle(ServerHandle);
2306
2307 return ApiStatus;
2308 }
2309
2310 /* EOF */