]> sourceware.org Git - newlib-cygwin.git/blob - winsup/utils/mkpasswd.c
* cygpath.cc (do_sysfolders): Use cygwin_conv_path.
[newlib-cygwin.git] / winsup / utils / mkpasswd.c
1 /* mkpasswd.c:
2
3 Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc.
4
5 This file is part of Cygwin.
6
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
9 details. */
10
11 #include <ctype.h>
12 #include <stdlib.h>
13 #include <wchar.h>
14 #include <stdio.h>
15 #include <windows.h>
16 #include <io.h>
17 #include <unistd.h>
18 #include <sys/cygwin.h>
19 #include <getopt.h>
20 #include <lmaccess.h>
21 #include <lmapibuf.h>
22 #include <sys/fcntl.h>
23 #include <lmerr.h>
24 #include <lmcons.h>
25
26 #define print_win_error(x) _print_win_error(x, __LINE__)
27
28 static const char version[] = "$Revision$";
29
30 SID_IDENTIFIER_AUTHORITY sid_world_auth = {SECURITY_WORLD_SID_AUTHORITY};
31 SID_IDENTIFIER_AUTHORITY sid_nt_auth = {SECURITY_NT_AUTHORITY};
32
33 typedef struct {
34 LPWSTR DomainControllerName;
35 LPWSTR DomainControllerAddress;
36 ULONG DomainControllerAddressType;
37 GUID DomainGuid;
38 LPWSTR DomainName;
39 LPWSTR DnsForestName;
40 ULONG Flags;
41 LPWSTR DcSiteName;
42 LPWSTR ClientSiteName;
43 } *PDOMAIN_CONTROLLER_INFOW;
44
45 NET_API_STATUS WINAPI (*netapibufferfree)(PVOID);
46 NET_API_STATUS WINAPI (*netuserenum)(LPWSTR,DWORD,DWORD,PBYTE*,DWORD,PDWORD,PDWORD,PDWORD);
47 NET_API_STATUS WINAPI (*netlocalgroupenum)(LPWSTR,DWORD,PBYTE*,DWORD,PDWORD,PDWORD,PDWORD);
48 NET_API_STATUS WINAPI (*netgetdcname)(LPWSTR,LPWSTR,PBYTE*);
49 NET_API_STATUS WINAPI (*netusergetinfo)(LPWSTR,LPWSTR,DWORD,PBYTE*);
50 NET_API_STATUS WINAPI (*dsgetdcname)(LPWSTR,LPWSTR,GUID*,LPWSTR,ULONG,PDOMAIN_CONTROLLER_INFOW*);
51
52 #ifndef min
53 #define min(a,b) (((a)<(b))?(a):(b))
54 #endif
55
56 BOOL
57 load_netapi ()
58 {
59 HANDLE h = LoadLibrary ("netapi32.dll");
60
61 if (!h)
62 return FALSE;
63
64 if (!(netapibufferfree = (void *) GetProcAddress (h, "NetApiBufferFree")))
65 return FALSE;
66 if (!(netuserenum = (void *) GetProcAddress (h, "NetUserEnum")))
67 return FALSE;
68 if (!(netlocalgroupenum = (void *) GetProcAddress (h, "NetLocalGroupEnum")))
69 return FALSE;
70 if (!(netgetdcname = (void *) GetProcAddress (h, "NetGetDCName")))
71 return FALSE;
72 if (!(netusergetinfo = (void *) GetProcAddress (h, "NetUserGetInfo")))
73 return FALSE;
74
75 dsgetdcname = (void *) GetProcAddress (h, "DsGetDcNameW");
76
77 return TRUE;
78 }
79
80 char *
81 put_sid (PSID sid)
82 {
83 static char s[512];
84 char t[32];
85 DWORD i;
86
87 strcpy (s, "S-1-");
88 sprintf(t, "%u", GetSidIdentifierAuthority (sid)->Value[5]);
89 strcat (s, t);
90 for (i = 0; i < *GetSidSubAuthorityCount (sid); ++i)
91 {
92 sprintf(t, "-%lu", *GetSidSubAuthority (sid, i));
93 strcat (s, t);
94 }
95 return s;
96 }
97
98 void
99 psx_dir (char *in, char *out)
100 {
101 if (isalpha (in[0]) && in[1] == ':')
102 {
103 sprintf (out, "/cygdrive/%c", in[0]);
104 in += 2;
105 out += strlen (out);
106 }
107
108 while (*in)
109 {
110 if (*in == '\\')
111 *out = '/';
112 else
113 *out = *in;
114 in++;
115 out++;
116 }
117
118 *out = '\0';
119 }
120
121 void
122 uni2ansi (LPWSTR wcs, char *mbs, int size)
123 {
124 if (wcs)
125 WideCharToMultiByte (CP_ACP, 0, wcs, -1, mbs, size, NULL, NULL);
126 else
127 *mbs = '\0';
128 }
129
130 void
131 _print_win_error(DWORD code, int line)
132 {
133 char buf[4096];
134
135 if (FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
136 | FORMAT_MESSAGE_IGNORE_INSERTS,
137 NULL,
138 code,
139 MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
140 (LPTSTR) buf, sizeof (buf), NULL))
141 fprintf (stderr, "mkpasswd (%d): [%lu] %s", line, code, buf);
142 else
143 fprintf (stderr, "mkpasswd (%d): error %lu", line, code);
144 }
145
146 void
147 current_user (int print_sids, int print_cygpath,
148 const char * passed_home_path, int id_offset, const char * disp_username)
149 {
150 char name[UNLEN + 1], *envname, *envdomain;
151 DWORD len;
152 HANDLE ptok;
153 int errpos = 0;
154 struct {
155 PSID psid;
156 int buffer[10];
157 } tu, tg;
158
159
160 if ((!GetUserName (name, (len = sizeof (name), &len)) && (errpos = __LINE__))
161 || !name[0]
162 || !(envname = getenv("USERNAME"))
163 || strcasecmp (envname, name)
164 || (disp_username && strcasecmp(envname, disp_username))
165 || (!GetComputerName (name, (len = sizeof (name), &len))
166 && (errpos = __LINE__))
167 || !(envdomain = getenv("USERDOMAIN"))
168 || !envdomain[0]
169 || !strcasecmp (envdomain, name)
170 || (!OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &ptok)
171 && (errpos = __LINE__))
172 || (!GetTokenInformation (ptok, TokenUser, &tu, sizeof tu, &len)
173 && (errpos = __LINE__))
174 || (!GetTokenInformation (ptok, TokenPrimaryGroup, &tg, sizeof tg, &len)
175 && (errpos = __LINE__))
176 || (!CloseHandle (ptok) && (errpos = __LINE__)))
177 {
178 if (errpos)
179 _print_win_error (GetLastError (), errpos);
180 return;
181 }
182
183 int uid = *GetSidSubAuthority (tu.psid, *GetSidSubAuthorityCount(tu.psid) - 1);
184 int gid = *GetSidSubAuthority (tg.psid, *GetSidSubAuthorityCount(tg.psid) - 1);
185 char homedir_psx[MAX_PATH] = {0}, homedir_w32[MAX_PATH] = {0};
186
187 char *envhomedrive = getenv ("HOMEDRIVE");
188 char *envhomepath = getenv ("HOMEPATH");
189
190 if (passed_home_path[0] == '\0')
191 {
192 if (envhomepath && envhomepath[0])
193 {
194 if (envhomedrive)
195 strlcpy (homedir_w32, envhomedrive, sizeof (homedir_w32));
196 if (envhomepath[0] != '\\')
197 strlcat (homedir_w32, "\\", sizeof (homedir_w32));
198 strlcat (homedir_w32, envhomepath, sizeof (homedir_w32));
199 if (print_cygpath)
200 cygwin_conv_path (CCP_WIN_A_TO_POSIX | CCP_ABSOLUTE, homedir_w32,
201 homedir_psx, MAX_PATH);
202 else
203 psx_dir (homedir_w32, homedir_psx);
204 }
205 else
206 {
207 strlcpy (homedir_psx, "/home/", sizeof (homedir_psx));
208 strlcat (homedir_psx, envname, sizeof (homedir_psx));
209 }
210 }
211 else
212 {
213 strlcpy (homedir_psx, passed_home_path, sizeof (homedir_psx));
214 strlcat (homedir_psx, envname, sizeof (homedir_psx));
215 }
216
217 printf ("%s:unused_by_nt/2000/xp:%u:%u:%s%s%s%s%s%s%s%s:%s:/bin/bash\n",
218 envname,
219 uid + id_offset,
220 gid + id_offset,
221 envname,
222 print_sids ? "," : "",
223 print_sids ? "U-" : "",
224 print_sids ? envdomain : "",
225 print_sids ? "\\" : "",
226 print_sids ? envname : "",
227 print_sids ? "," : "",
228 print_sids ? put_sid (tu.psid) : "",
229 homedir_psx);
230 }
231
232 int
233 enum_users (LPWSTR servername, int print_sids, int print_cygpath,
234 const char * passed_home_path, int id_offset, char *disp_username)
235 {
236 USER_INFO_3 *buffer;
237 DWORD entriesread = 0;
238 DWORD totalentries = 0;
239 DWORD resume_handle = 0;
240 DWORD rc;
241 char ansi_srvname[256];
242 WCHAR uni_name[512];
243
244 if (servername)
245 uni2ansi (servername, ansi_srvname, sizeof (ansi_srvname));
246
247 do
248 {
249 DWORD i;
250
251 if (disp_username != NULL)
252 {
253 MultiByteToWideChar (CP_ACP, 0, disp_username, -1, uni_name, 512 );
254 rc = netusergetinfo(servername, (LPWSTR) & uni_name, 3,
255 (void *) &buffer );
256 entriesread=1;
257 }
258 else
259 rc = netuserenum (servername, 3, FILTER_NORMAL_ACCOUNT,
260 (void *) &buffer, 1024,
261 &entriesread, &totalentries, &resume_handle);
262 switch (rc)
263 {
264 case ERROR_ACCESS_DENIED:
265 print_win_error(rc);
266 exit (1);
267
268 case ERROR_MORE_DATA:
269 case ERROR_SUCCESS:
270 break;
271
272 default:
273 print_win_error(rc);
274 exit (1);
275 }
276
277 for (i = 0; i < entriesread; i++)
278 {
279 char username[100];
280 char fullname[100];
281 char homedir_psx[MAX_PATH];
282 char homedir_w32[MAX_PATH];
283 char domain_name[100];
284 DWORD domname_len = 100;
285 char psid_buffer[1024];
286 PSID psid = (PSID) psid_buffer;
287 DWORD sid_length = 1024;
288 SID_NAME_USE acc_type;
289
290 int uid = buffer[i].usri3_user_id;
291 int gid = buffer[i].usri3_primary_group_id;
292 uni2ansi (buffer[i].usri3_name, username, sizeof (username));
293 uni2ansi (buffer[i].usri3_full_name, fullname, sizeof (fullname));
294 homedir_w32[0] = homedir_psx[0] = '\0';
295 if (passed_home_path[0] == '\0')
296 {
297 uni2ansi (buffer[i].usri3_home_dir, homedir_w32,
298 sizeof (homedir_w32));
299 if (homedir_w32[0] != '\0')
300 {
301 if (print_cygpath)
302 cygwin_conv_path (CCP_WIN_A_TO_POSIX | CCP_ABSOLUTE,
303 homedir_w32, homedir_psx, MAX_PATH);
304 else
305 psx_dir (homedir_w32, homedir_psx);
306 }
307 else
308 {
309 strcpy (homedir_psx, "/home/");
310 strcat (homedir_psx, username);
311 }
312 }
313 else
314 {
315 strcpy (homedir_psx, passed_home_path);
316 strcat (homedir_psx, username);
317 }
318
319 if (print_sids)
320 {
321 if (!LookupAccountName (servername ? ansi_srvname : NULL,
322 username,
323 psid, &sid_length,
324 domain_name, &domname_len,
325 &acc_type))
326 {
327 print_win_error(GetLastError ());
328 fprintf(stderr, " (%s)\n", username);
329 continue;
330 }
331 else if (acc_type == SidTypeDomain)
332 {
333 char domname[356];
334
335 strcpy (domname, domain_name);
336 strcat (domname, "\\");
337 strcat (domname, username);
338 sid_length = 1024;
339 domname_len = 100;
340 if (!LookupAccountName (servername ? ansi_srvname : NULL,
341 domname,
342 psid, &sid_length,
343 domain_name, &domname_len,
344 &acc_type))
345 {
346 print_win_error(GetLastError ());
347 fprintf(stderr, " (%s)\n", domname);
348 continue;
349 }
350 }
351 }
352 printf ("%s:unused_by_nt/2000/xp:%u:%u:%s%s%s%s%s%s%s%s:%s:/bin/bash\n",
353 username,
354 uid + id_offset,
355 gid + id_offset,
356 fullname,
357 print_sids && fullname[0] ? "," : "",
358 print_sids ? "U-" : "",
359 print_sids ? domain_name : "",
360 print_sids && domain_name[0] ? "\\" : "",
361 print_sids ? username : "",
362 print_sids ? "," : "",
363 print_sids ? put_sid (psid) : "",
364 homedir_psx);
365 }
366
367 netapibufferfree (buffer);
368
369 }
370 while (rc == ERROR_MORE_DATA);
371
372 return 0;
373 }
374
375 int
376 enum_local_groups (int print_sids)
377 {
378 LOCALGROUP_INFO_0 *buffer;
379 DWORD entriesread = 0;
380 DWORD totalentries = 0;
381 DWORD resume_handle = 0;
382 DWORD rc ;
383
384 do
385 {
386 DWORD i;
387
388 rc = netlocalgroupenum (NULL, 0, (void *) &buffer, 1024,
389 &entriesread, &totalentries, &resume_handle);
390 switch (rc)
391 {
392 case ERROR_ACCESS_DENIED:
393 print_win_error(rc);
394 exit (1);
395
396 case ERROR_MORE_DATA:
397 case ERROR_SUCCESS:
398 break;
399
400 default:
401 print_win_error(rc);
402 exit (1);
403 }
404
405 for (i = 0; i < entriesread; i++)
406 {
407 char localgroup_name[100];
408 char domain_name[100];
409 DWORD domname_len = 100;
410 char psid_buffer[1024];
411 PSID psid = (PSID) psid_buffer;
412 DWORD sid_length = 1024;
413 DWORD gid;
414 SID_NAME_USE acc_type;
415 uni2ansi (buffer[i].lgrpi0_name, localgroup_name, sizeof (localgroup_name));
416
417 if (!LookupAccountName (NULL, localgroup_name, psid,
418 &sid_length, domain_name, &domname_len,
419 &acc_type))
420 {
421 print_win_error(GetLastError ());
422 fprintf(stderr, " (%s)\n", localgroup_name);
423 continue;
424 }
425 else if (acc_type == SidTypeDomain)
426 {
427 char domname[356];
428
429 strcpy (domname, domain_name);
430 strcat (domname, "\\");
431 strcat (domname, localgroup_name);
432 sid_length = 1024;
433 domname_len = 100;
434 if (!LookupAccountName (NULL, domname,
435 psid, &sid_length,
436 domain_name, &domname_len,
437 &acc_type))
438 {
439 print_win_error(GetLastError ());
440 fprintf(stderr, " (%s)\n", domname);
441 continue;
442 }
443 }
444
445 gid = *GetSidSubAuthority (psid, *GetSidSubAuthorityCount(psid) - 1);
446
447 printf ("%s:*:%ld:%ld:%s%s::\n", localgroup_name, gid, gid,
448 print_sids ? "," : "",
449 print_sids ? put_sid (psid) : "");
450 }
451
452 netapibufferfree (buffer);
453
454 }
455 while (rc == ERROR_MORE_DATA);
456
457 return 0;
458 }
459
460 void
461 print_special (int print_sids,
462 PSID_IDENTIFIER_AUTHORITY auth, BYTE cnt,
463 DWORD sub1, DWORD sub2, DWORD sub3, DWORD sub4,
464 DWORD sub5, DWORD sub6, DWORD sub7, DWORD sub8)
465 {
466 char name[256], dom[256];
467 DWORD len, len2, rid;
468 PSID sid;
469 SID_NAME_USE use;
470
471 if (AllocateAndInitializeSid (auth, cnt, sub1, sub2, sub3, sub4,
472 sub5, sub6, sub7, sub8, &sid))
473 {
474 if (LookupAccountSid (NULL, sid,
475 name, (len = 256, &len),
476 dom, (len2 = 256, &len),
477 &use))
478 {
479 if (sub8)
480 rid = sub8;
481 else if (sub7)
482 rid = sub7;
483 else if (sub6)
484 rid = sub6;
485 else if (sub5)
486 rid = sub5;
487 else if (sub4)
488 rid = sub4;
489 else if (sub3)
490 rid = sub3;
491 else if (sub2)
492 rid = sub2;
493 else
494 rid = sub1;
495 printf ("%s:*:%lu:%lu:%s%s::\n",
496 name, rid, rid == 18 ? 544 : rid, /* SYSTEM hack */
497 print_sids ? "," : "",
498 print_sids ? put_sid (sid) : "");
499 }
500 FreeSid (sid);
501 }
502 }
503
504 int
505 usage (FILE * stream, int isNT)
506 {
507 fprintf (stream, "Usage: mkpasswd [OPTION]... [domain]...\n"
508 "Print /etc/passwd file to stdout\n\n"
509 "Options:\n");
510 if (isNT)
511 fprintf (stream, " -l,--local print local user accounts\n"
512 " -c,--current print current account, if a domain account\n"
513 " -d,--domain print domain accounts (from current domain\n"
514 " if no domains specified)\n"
515 " -o,--id-offset offset change the default offset (10000) added to uids\n"
516 " in domain accounts.\n"
517 " -g,--local-groups print local group information too\n"
518 " if no domain specified\n"
519 " -m,--no-mount don't use mount points for home dir\n"
520 " -s,--no-sids don't print SIDs in GCOS field\n"
521 " (this affects ntsec)\n");
522 fprintf (stream, " -p,--path-to-home path use specified path and not user account home dir or /home\n"
523 " -u,--username username only return information for the specified user\n"
524 " -h,--help displays this message\n"
525 " -v,--version version information and exit\n\n");
526 if (isNT)
527 fprintf (stream, "One of '-l', '-d' or '-g' must be given.\n");
528 return 1;
529 }
530
531 struct option longopts[] = {
532 {"local", no_argument, NULL, 'l'},
533 {"current", no_argument, NULL, 'c'},
534 {"domain", no_argument, NULL, 'd'},
535 {"id-offset", required_argument, NULL, 'o'},
536 {"local-groups", no_argument, NULL, 'g'},
537 {"no-mount", no_argument, NULL, 'm'},
538 {"no-sids", no_argument, NULL, 's'},
539 {"path-to-home", required_argument, NULL, 'p'},
540 {"username", required_argument, NULL, 'u'},
541 {"help", no_argument, NULL, 'h'},
542 {"version", no_argument, NULL, 'v'},
543 {0, no_argument, NULL, 0}
544 };
545
546 char opts[] = "lcdo:gsmhp:u:v";
547
548 static void
549 print_version ()
550 {
551 const char *v = strchr (version, ':');
552 int len;
553 if (!v)
554 {
555 v = "?";
556 len = 1;
557 }
558 else
559 {
560 v += 2;
561 len = strchr (v, ' ') - v;
562 }
563 printf ("\
564 mkpasswd (cygwin) %.*s\n\
565 passwd File Generator\n\
566 Copyright 1997, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.\n\
567 Compiled on %s\n\
568 ", len, v, __DATE__);
569 }
570
571 int
572 main (int argc, char **argv)
573 {
574 LPWSTR servername = NULL;
575 DWORD rc = ERROR_SUCCESS;
576 WCHAR domain_name[200];
577 int print_local = 0;
578 int print_current = 0;
579 int print_domain = 0;
580 int print_local_groups = 0;
581 int domain_specified = 0;
582 int print_sids = 1;
583 int print_cygpath = 1;
584 int id_offset = 10000;
585 int i;
586 int isNT;
587 char *disp_username = NULL;
588 char name[256], passed_home_path[MAX_PATH];
589 DWORD len;
590
591 isNT = (GetVersion () < 0x80000000);
592 passed_home_path[0] = '\0';
593 if (!isatty (1))
594 setmode (1, O_BINARY);
595
596 if (isNT && argc == 1)
597 return usage (stderr, isNT);
598 else
599 {
600 while ((i = getopt_long (argc, argv, opts, longopts, NULL)) != EOF)
601 switch (i)
602 {
603 case 'l':
604 print_local = 1;
605 break;
606 case 'c':
607 print_current = 1;
608 break;
609 case 'd':
610 print_domain = 1;
611 break;
612 case 'o':
613 id_offset = strtol (optarg, NULL, 10);
614 break;
615 case 'g':
616 print_local_groups = 1;
617 break;
618 case 's':
619 print_sids = 0;
620 break;
621 case 'm':
622 print_cygpath = 0;
623 break;
624 case 'p':
625 if (optarg[0] != '/')
626 {
627 fprintf (stderr, "%s: '%s' is not a fully qualified path.\n",
628 argv[0], optarg);
629 return 1;
630 }
631 strcpy (passed_home_path, optarg);
632 if (optarg[strlen (optarg)-1] != '/')
633 strcat (passed_home_path, "/");
634 break;
635 case 'u':
636 disp_username = optarg;
637 break;
638 case 'h':
639 usage (stdout, isNT);
640 return 0;
641 case 'v':
642 print_version ();
643 return 0;
644 default:
645 fprintf (stderr, "Try '%s --help' for more information.\n", argv[0]);
646 return 1;
647 }
648 }
649 if (!isNT)
650 {
651 /* This takes Windows 9x/ME into account. */
652 if (passed_home_path[0] == '\0')
653 strcpy (passed_home_path, "/home/");
654 if (!disp_username)
655 {
656 printf ("admin:use_crypt:%lu:%lu:Administrator:%sadmin:/bin/bash\n",
657 DOMAIN_USER_RID_ADMIN,
658 DOMAIN_ALIAS_RID_ADMINS,
659 passed_home_path);
660 if (GetUserName (name, (len = 256, &len)))
661 disp_username = name;
662 }
663 if (disp_username && disp_username[0])
664 {
665 /* Create a pseudo random uid */
666 unsigned long uid = 0, i;
667 for (i = 0; disp_username[i]; i++)
668 uid += toupper (disp_username[i]) << ((6 * i) % 25);
669 uid = (uid % (1000 - DOMAIN_USER_RID_ADMIN - 1))
670 + DOMAIN_USER_RID_ADMIN + 1;
671
672 printf ("%s:use_crypt:%lu:%lu:%s:%s%s:/bin/bash\n",
673 disp_username,
674 uid,
675 DOMAIN_ALIAS_RID_ADMINS,
676 disp_username,
677 passed_home_path,
678 disp_username);
679 }
680 return 0;
681 }
682 if (!print_local && !print_domain && !print_local_groups)
683 {
684 fprintf (stderr, "%s: Specify one of '-l', '-d' or '-g'\n", argv[0]);
685 return 1;
686 }
687 if (optind < argc)
688 {
689 if (!print_domain)
690 {
691 fprintf (stderr, "%s: A domain name is only accepted "
692 "when '-d' is given.\n", argv[0]);
693 return 1;
694 }
695 domain_specified = 1;
696 }
697 if (!load_netapi ())
698 {
699 print_win_error(GetLastError ());
700 return 1;
701 }
702
703 if (disp_username == NULL)
704 {
705 if (print_local)
706 {
707 /* Generate service starter account entries. */
708 printf ("SYSTEM:*:18:544:,S-1-5-18::\n");
709 printf ("LocalService:*:19:544:U-NT AUTHORITY\\LocalService,S-1-5-19::\n");
710 printf ("NetworkService:*:20:544:U-NT AUTHORITY\\NetworkService,S-1-5-20::\n");
711 /* Get 'administrators' group (has localized name). */
712 if (!print_local_groups)
713 print_special (print_sids, &sid_nt_auth, 2, SECURITY_BUILTIN_DOMAIN_RID,
714 DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0);
715 }
716 if (print_local_groups)
717 enum_local_groups (print_sids);
718 }
719
720 if (print_local)
721 enum_users (NULL, print_sids, print_cygpath, passed_home_path, 0,
722 disp_username);
723
724 i = 1;
725 if (print_domain)
726 do
727 {
728 PDOMAIN_CONTROLLER_INFOW pdci = NULL;
729
730 if (dsgetdcname)
731 {
732 if (domain_specified)
733 {
734 mbstowcs (domain_name, argv[optind], strlen (argv[optind]) + 1);
735 rc = dsgetdcname (NULL, domain_name, NULL, NULL, 0, &pdci);
736 }
737 else
738 rc = dsgetdcname (NULL, NULL, NULL, NULL, 0, &pdci);
739 if (rc != ERROR_SUCCESS)
740 {
741 print_win_error(rc);
742 return 1;
743 }
744 servername = pdci->DomainControllerName;
745 }
746 else
747 {
748 rc = netgetdcname (NULL, NULL, (void *) &servername);
749 if (rc == ERROR_SUCCESS && domain_specified)
750 {
751 LPWSTR server = servername;
752 mbstowcs (domain_name, argv[optind], strlen (argv[optind]) + 1);
753 rc = netgetdcname (server, domain_name, (void *) &servername);
754 netapibufferfree (server);
755 }
756 if (rc != ERROR_SUCCESS)
757 {
758 print_win_error(rc);
759 return 1;
760 }
761 }
762 enum_users (servername, print_sids, print_cygpath, passed_home_path,
763 id_offset * i++, disp_username);
764 netapibufferfree (pdci ? (PVOID) pdci : (PVOID) servername);
765 }
766 while (++optind < argc);
767
768 if (print_current && !print_domain)
769 current_user(print_sids, print_cygpath, passed_home_path,
770 id_offset, disp_username);
771
772 return 0;
773 }
This page took 0.074693 seconds and 6 git commands to generate.