]> sourceware.org Git - newlib-cygwin.git/blob - winsup/utils/mkpasswd.c
Cygwin: add 3.2.1 release file and add fixes up to this point
[newlib-cygwin.git] / winsup / utils / mkpasswd.c
1 /* mkpasswd.c:
2
3 This file is part of Cygwin.
4
5 This software is a copyrighted work licensed under the terms of the
6 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
7 details. */
8
9 #define _WIN32_WINNT 0x0a00
10 #include <errno.h>
11 #include <ctype.h>
12 #include <stdlib.h>
13 #include <wchar.h>
14 #include <wctype.h>
15 #include <locale.h>
16 #include <stdio.h>
17 #include <unistd.h>
18 #include <inttypes.h>
19 #include <getopt.h>
20 #include <io.h>
21 #include <pwd.h>
22 #include <sys/fcntl.h>
23 #include <sys/cygwin.h>
24 #include <cygwin/version.h>
25 #include <windows.h>
26 #include <lm.h>
27 #include <iptypes.h>
28 #include <wininet.h>
29 #include <ntsecapi.h>
30 #include <dsgetdc.h>
31 #include <ntdef.h>
32
33 #define print_win_error(x) _print_win_error(x, __LINE__)
34
35 SID_IDENTIFIER_AUTHORITY sid_world_auth = {SECURITY_WORLD_SID_AUTHORITY};
36 SID_IDENTIFIER_AUTHORITY sid_nt_auth = {SECURITY_NT_AUTHORITY};
37
38 #ifndef min
39 #define min(a,b) (((a)<(b))?(a):(b))
40 #endif
41
42 typedef struct
43 {
44 char *str;
45 BOOL domain;
46 BOOL with_dom;
47 } domlist_t;
48
49 static void
50 _print_win_error(DWORD code, int line)
51 {
52 char buf[4096];
53
54 if (FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
55 | FORMAT_MESSAGE_IGNORE_INSERTS,
56 NULL,
57 code,
58 MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
59 (LPTSTR) buf, sizeof (buf), NULL))
60 fprintf (stderr, "mkpasswd (%d): [%" PRIu32 "] %s",
61 line, (unsigned int) code, buf);
62 else
63 fprintf (stderr, "mkpasswd (%d): error %" PRIu32,
64 line, (unsigned int) code);
65 }
66
67 static char *
68 put_sid (PSID sid)
69 {
70 static char s[512];
71 char t[32];
72 DWORD i;
73
74 strcpy (s, "S-1-");
75 sprintf(t, "%u", GetSidIdentifierAuthority (sid)->Value[5]);
76 strcat (s, t);
77 for (i = 0; i < *GetSidSubAuthorityCount (sid); ++i)
78 {
79 sprintf(t, "-%" PRIu32, (unsigned int) *GetSidSubAuthority (sid, i));
80 strcat (s, t);
81 }
82 return s;
83 }
84
85 static void
86 uni2ansi (LPWSTR wcs, char *mbs, int size)
87 {
88 if (wcs)
89 wcstombs (mbs, wcs, size);
90 else
91 *mbs = '\0';
92 }
93
94 typedef struct {
95 PSID psid;
96 int buffer[10];
97 } sidbuf;
98
99 static sidbuf curr_user;
100 static sidbuf curr_pgrp;
101 static BOOL got_curr_user = FALSE;
102
103 static void
104 fetch_current_user_sid ()
105 {
106 DWORD len;
107 HANDLE ptok;
108
109 if (!OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &ptok)
110 || !GetTokenInformation (ptok, TokenUser, &curr_user, sizeof curr_user,
111 &len)
112 || !GetTokenInformation (ptok, TokenPrimaryGroup, &curr_pgrp,
113 sizeof curr_pgrp, &len)
114 || !CloseHandle (ptok))
115 {
116 print_win_error (GetLastError ());
117 return;
118 }
119 }
120
121 static void
122 enum_unix_users (domlist_t *mach, const char *sep, DWORD id_offset,
123 char *unix_user_list)
124 {
125 WCHAR machine[INTERNET_MAX_HOST_NAME_LENGTH + 1];
126 SID_IDENTIFIER_AUTHORITY auth = { { 0, 0, 0, 0, 0, 22 } };
127 char *ustr, *user_list;
128 WCHAR user[UNLEN + sizeof ("Unix User\\") + 1];
129 WCHAR dom[MAX_DOMAIN_NAME_LEN + 1];
130 DWORD ulen, dlen, sidlen;
131 PSID psid;
132 PSID numeric_psid;
133 char psid_buffer[SECURITY_MAX_SID_SIZE];
134 SID_NAME_USE acc_type;
135
136 int ret = mbstowcs (machine, mach->str, INTERNET_MAX_HOST_NAME_LENGTH + 1);
137 if (ret < 1 || ret >= INTERNET_MAX_HOST_NAME_LENGTH + 1)
138 {
139 fprintf (stderr, "%s: Invalid machine name '%s'. Skipping...\n",
140 program_invocation_short_name, mach->str);
141 return;
142 }
143
144 if (!AllocateAndInitializeSid (&auth, 2, 1, 0, 0, 0, 0, 0, 0, 0,
145 &numeric_psid))
146 return;
147
148 if (!(user_list = strdup (unix_user_list)))
149 {
150 FreeSid (numeric_psid);
151 return;
152 }
153
154 for (ustr = strtok (user_list, ","); ustr; ustr = strtok (NULL, ","))
155 {
156 if (!isdigit ((unsigned char) ustr[0]) && ustr[0] != '-')
157 {
158 PWCHAR p = wcpcpy (user, L"Unix User\\");
159 ret = mbstowcs (p, ustr, UNLEN + 1);
160 if (ret < 1 || ret >= UNLEN + 1)
161 {
162 fprintf (stderr, "%s: Invalid user name '%s'. Skipping...\n",
163 program_invocation_short_name, ustr);
164 continue;
165 }
166 psid = (PSID) psid_buffer;
167 sidlen = SECURITY_MAX_SID_SIZE;
168 dlen = MAX_DOMAIN_NAME_LEN + 1;
169 if (LookupAccountNameW (machine, user, psid, &sidlen,
170 dom, &dlen, &acc_type))
171 printf ("%s%s%ls:*:%" PRIu32 ":99999:,%s::\n",
172 "Unix_User",
173 sep,
174 user + 10,
175 (unsigned int) (id_offset +
176 *GetSidSubAuthority (psid,
177 *GetSidSubAuthorityCount(psid) - 1)),
178 put_sid (psid));
179 }
180 else
181 {
182 DWORD start, stop;
183 char *p = ustr;
184 if (*p == '-')
185 start = 0;
186 else
187 start = strtol (p, &p, 10);
188 if (!*p)
189 stop = start;
190 else if (*p++ != '-' || !isdigit ((unsigned char) *p)
191 || (stop = strtol (p, &p, 10)) < start || *p)
192 {
193 fprintf (stderr, "%s: Malformed unix user list entry '%s'. "
194 "Skipping...\n",
195 program_invocation_short_name, ustr);
196 continue;
197 }
198 for (; start <= stop; ++ start)
199 {
200 psid = numeric_psid;
201 *GetSidSubAuthority (psid, *GetSidSubAuthorityCount(psid) - 1)
202 = start;
203 ulen = GNLEN + 1;
204 dlen = MAX_DOMAIN_NAME_LEN + 1;
205 if (LookupAccountSidW (machine, psid, user, &ulen,
206 dom, &dlen, &acc_type)
207 && !iswdigit (user[0]))
208 printf ("%s%s%ls:*:%" PRIu32 ":99999:,%s::\n",
209 "Unix_User",
210 sep,
211 user,
212 (unsigned int) (id_offset + start),
213 put_sid (psid));
214 }
215 }
216 }
217
218 free (user_list);
219 FreeSid (numeric_psid);
220 }
221
222 static int
223 enum_users (domlist_t *mach, const char *sep, const char *passed_home_path,
224 DWORD id_offset, char *disp_username, int print_current)
225 {
226 WCHAR machine[INTERNET_MAX_HOST_NAME_LENGTH + 1];
227 USER_INFO_3 *buffer;
228 DWORD entriesread = 0;
229 DWORD totalentries = 0;
230 DWORD resume_handle = 0;
231 DWORD rc;
232 WCHAR uni_name[UNLEN + 1];
233
234 int ret = mbstowcs (machine, mach->str, INTERNET_MAX_HOST_NAME_LENGTH + 1);
235 if (ret < 1 || ret >= INTERNET_MAX_HOST_NAME_LENGTH + 1)
236 {
237 fprintf (stderr, "%s: Invalid machine name '%s'. Skipping...\n",
238 program_invocation_short_name, mach->str);
239 return 1;
240 }
241
242 do
243 {
244 DWORD i;
245
246 if (disp_username != NULL)
247 {
248 mbstowcs (uni_name, disp_username, UNLEN + 1);
249 rc = NetUserGetInfo (machine, (LPWSTR) &uni_name, 3,
250 (void *) &buffer);
251 entriesread = 1;
252 /* Avoid annoying error messages just because the user hasn't been
253 found. */
254 if (rc == NERR_UserNotFound)
255 return 0;
256 }
257 else
258 rc = NetUserEnum (machine, 3, FILTER_NORMAL_ACCOUNT,
259 (void *) &buffer, MAX_PREFERRED_LENGTH,
260 &entriesread, &totalentries, &resume_handle);
261 switch (rc)
262 {
263 case ERROR_ACCESS_DENIED:
264 print_win_error(rc);
265 return 1;
266
267 case ERROR_MORE_DATA:
268 case ERROR_SUCCESS:
269 break;
270
271 default:
272 print_win_error(rc);
273 return 1;
274 }
275
276 for (i = 0; i < entriesread; i++)
277 {
278 char homedir_psx[PATH_MAX];
279 WCHAR domain_name[MAX_DOMAIN_NAME_LEN + 1];
280 DWORD domname_len = MAX_DOMAIN_NAME_LEN + 1;
281 char psid_buffer[SECURITY_MAX_SID_SIZE];
282 PSID psid = (PSID) psid_buffer;
283 DWORD sid_length = SECURITY_MAX_SID_SIZE;
284 SID_NAME_USE acc_type;
285
286 int uid = buffer[i].usri3_user_id;
287 int gid = buffer[i].usri3_primary_group_id;
288 homedir_psx[0] = '\0';
289 if (passed_home_path[0] == '\0')
290 {
291 if (buffer[i].usri3_home_dir[0] != L'\0')
292 cygwin_conv_path (CCP_WIN_W_TO_POSIX | CCP_ABSOLUTE,
293 buffer[i].usri3_home_dir, homedir_psx,
294 PATH_MAX);
295 else
296 uni2ansi (buffer[i].usri3_name,
297 stpcpy (homedir_psx, "/home/"), PATH_MAX - 6);
298 }
299 else
300 uni2ansi (buffer[i].usri3_name,
301 stpcpy (homedir_psx, passed_home_path),
302 PATH_MAX - strlen (passed_home_path));
303
304 if (!LookupAccountNameW (machine, buffer[i].usri3_name,
305 psid, &sid_length, domain_name,
306 &domname_len, &acc_type))
307 {
308 print_win_error(GetLastError ());
309 fprintf(stderr, " (%ls)\n", buffer[i].usri3_name);
310 continue;
311 }
312 else if (acc_type == SidTypeDomain)
313 {
314 WCHAR domname[MAX_DOMAIN_NAME_LEN + UNLEN + 2];
315 PWCHAR p;
316
317 p = wcpcpy (domname, machine);
318 p = wcpcpy (p, L"\\");
319 p = wcpncpy (p, buffer[i].usri3_name, UNLEN);
320 *p = L'\0';
321 sid_length = SECURITY_MAX_SID_SIZE;
322 domname_len = sizeof (domname);
323 if (!LookupAccountNameW (machine, domname, psid,
324 &sid_length, domain_name,
325 &domname_len, &acc_type))
326 {
327 print_win_error(GetLastError ());
328 fprintf(stderr, " (%ls)\n", domname);
329 continue;
330 }
331 }
332 if (!print_current)
333 /* fall through */;
334 else if (EqualSid (curr_user.psid, psid))
335 got_curr_user = TRUE;
336
337 printf ("%ls%s%ls:*:%" PRIu32 ":%" PRIu32
338 ":%ls%sU-%ls\\%ls,%s:%s:/bin/bash\n",
339 mach->with_dom ? domain_name : L"",
340 mach->with_dom ? sep : "",
341 buffer[i].usri3_name,
342 (unsigned int) (id_offset + uid),
343 (unsigned int) (id_offset + gid),
344 buffer[i].usri3_full_name ?: L"",
345 buffer[i].usri3_full_name
346 && buffer[i].usri3_full_name[0] ? "," : "",
347 domain_name,
348 buffer[i].usri3_name,
349 put_sid (psid),
350 homedir_psx);
351 }
352
353 NetApiBufferFree (buffer);
354
355 }
356 while (rc == ERROR_MORE_DATA);
357
358 return 0;
359 }
360
361 static int __attribute__ ((__noreturn__))
362 usage (FILE * stream)
363 {
364 fprintf (stream,
365 "Usage: %s [OPTIONS]...\n"
366 "\n"
367 "Write /etc/passwd-like output to stdout\n"
368 "\n"
369 "Don't use this command to generate a local /etc/passwd file, unless you\n"
370 "really need one. See the Cygwin User's Guide for more information.\n"
371 "\n"
372 "Options:\n"
373 "\n"
374 " -l,--local [machine] Print local user accounts of \"machine\",\n"
375 " from local machine if no machine specified.\n"
376 " Automatically adding machine prefix for local\n"
377 " machine depends on settings in /etc/nsswitch.conf.\n"
378 " -L,--Local machine Ditto, but generate username with machine prefix.\n"
379 " -d,--domain [domain] Print domain accounts,\n"
380 " from current domain if no domain specified.\n"
381 " -c,--current Print current user.\n"
382 " -S,--separator char For -L use character char as domain\\user\n"
383 " separator in username instead of the default '%s'.\n"
384 " -o,--id-offset offset Change the default offset (0x10000) added to uids\n"
385 " of foreign local machine accounts. Use with -l/-L.\n"
386 " -u,--username username Only return information for the specified user.\n"
387 " One of -l, -d must be specified, too\n"
388 " -b,--no-builtin Don't print BUILTIN users.\n"
389 " -p,--path-to-home path Use specified path instead of user account home dir\n"
390 " or /home prefix.\n"
391 " -U,--unix userlist Print UNIX users when using -l on a UNIX Samba\n"
392 " server. Userlist is a comma-separated list of\n"
393 " usernames or uid ranges (root,-25,50-100).\n"
394 " Enumerating large ranges can take a long time!\n"
395 " -h,--help Displays this message.\n"
396 " -V,--version Version information and exit.\n"
397 "\n"
398 "Default is to print local accounts on stand-alone machines, domain accounts\n"
399 "on domain controllers and domain member machines.\n"
400 "\n", program_invocation_short_name,
401 (const char *) cygwin_internal (CW_GETNSSSEP));
402 exit (stream == stdout ? 0 : 1);
403 }
404
405 static struct option longopts[] = {
406 {"no-builtin", no_argument, NULL, 'b'},
407 {"current", no_argument, NULL, 'c'},
408 {"Current", no_argument, NULL, 'C'},
409 {"domain", optional_argument, NULL, 'd'},
410 {"Domain", optional_argument, NULL, 'D'},
411 {"local-groups", no_argument, NULL, 'g'},
412 {"help", no_argument, NULL, 'h'},
413 {"local", optional_argument, NULL, 'l'},
414 {"Local", optional_argument, NULL, 'L'},
415 {"no-mount", no_argument, NULL, 'm'},
416 {"id-offset", required_argument, NULL, 'o'},
417 {"path-to-home", required_argument, NULL, 'p'},
418 {"no-sids", no_argument, NULL, 's'},
419 {"separator", required_argument, NULL, 'S'},
420 {"username", required_argument, NULL, 'u'},
421 {"unix", required_argument, NULL, 'U'},
422 {"version", no_argument, NULL, 'V'},
423 {0, no_argument, NULL, 0}
424 };
425
426 static char opts[] = "bcCd::D::ghl::L::mo:sS:p:u:U:V";
427
428 static void
429 print_version ()
430 {
431 printf ("mkpasswd (cygwin) %d.%d.%d\n"
432 "Passwd File Generator\n"
433 "Copyright (C) 1997 - %s Cygwin Authors\n"
434 "This is free software; see the source for copying conditions. There is NO\n"
435 "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
436 CYGWIN_VERSION_DLL_MAJOR / 1000,
437 CYGWIN_VERSION_DLL_MAJOR % 1000,
438 CYGWIN_VERSION_DLL_MINOR,
439 strrchr (__DATE__, ' ') + 1);
440 }
441
442 int
443 main (int argc, char **argv)
444 {
445 int print_domlist = 0;
446 domlist_t domlist[32];
447 char cname[1024];
448 char *opt, *p, *ep;
449 int print_current = 0;
450 int print_builtin = 1;
451 char *print_unix = NULL;
452 const char *nss_sep = (const char *) cygwin_internal (CW_GETNSSSEP);
453 const char *sep_char = nss_sep;
454 DWORD id_offset = 0x10000, off;
455 int c, i;
456 char *disp_username = NULL;
457 char passed_home_path[PATH_MAX];
458 int optional_args = 0;
459 uintptr_t nss_src = cygwin_internal (CW_GETNSS_PWD_SRC);
460
461 passed_home_path[0] = '\0';
462 if (!isatty (1))
463 setmode (1, O_BINARY);
464
465 /* Use locale from environment. If not set or set to "C", use UTF-8. */
466 setlocale (LC_CTYPE, "");
467 if (!strcmp (setlocale (LC_CTYPE, NULL), "C"))
468 setlocale (LC_CTYPE, "en_US.UTF-8");
469 fetch_current_user_sid ();
470
471 if (argc == 1)
472 {
473 int enums = ENUM_PRIMARY | ENUM_LOCAL | ENUM_BUILTIN;
474 uintptr_t ticket = cygwin_internal (CW_SETENT, FALSE, enums, NULL);
475 if (ticket)
476 {
477 struct passwd *pwd;
478
479 while ((pwd = (struct passwd *) cygwin_internal (CW_GETENT, FALSE,
480 ticket)))
481 printf ("%s:%s:%u:%u:%s:%s:%s\n", pwd->pw_name, pwd->pw_passwd,
482 pwd->pw_uid, pwd->pw_gid, pwd->pw_gecos, pwd->pw_dir,
483 pwd->pw_shell);
484 cygwin_internal (CW_ENDENT, FALSE, ticket);
485 }
486 return 0;
487 }
488
489 unsetenv ("POSIXLY_CORRECT"); /* To get optional arg processing right. */
490 while ((c = getopt_long (argc, argv, opts, longopts, NULL)) != EOF)
491 switch (c)
492 {
493 case 'd':
494 case 'D':
495 case 'l':
496 case 'L':
497 if (print_domlist >= 32)
498 {
499 fprintf (stderr, "%s: Can not enumerate from more than 32 "
500 "domains and machines.\n",
501 program_invocation_short_name);
502 return 1;
503 }
504 domlist[print_domlist].domain = (c == 'd' || c == 'D');
505 opt = optarg ?:
506 argv[optind] && argv[optind][0] != '-' ? argv[optind] : NULL;
507 if (argv[optind] && opt == argv[optind])
508 ++optional_args;
509 for (i = 0; i < print_domlist; ++i)
510 if (domlist[i].domain == domlist[print_domlist].domain
511 && ((!domlist[i].str && !opt)
512 || (domlist[i].str && opt
513 && (off = strlen (domlist[i].str))
514 && !strncmp (domlist[i].str, opt, off)
515 && (!opt[off] || opt[off] == ','))))
516 {
517 fprintf (stderr, "%s: Duplicate %s '%s'. Skipping...\n",
518 program_invocation_short_name,
519 domlist[i].domain ? "domain" : "machine",
520 domlist[i].str);
521 break;
522 }
523 domlist[print_domlist].str = opt;
524 if (opt && (p = strchr (opt, ',')))
525 {
526 if (p == opt)
527 {
528 fprintf (stderr, "%s: Malformed domain string '%s'. "
529 "Skipping...\n", program_invocation_short_name, opt);
530 break;
531 }
532 *p = '\0';
533 }
534 if (c == 'l' || c == 'L')
535 {
536 DWORD csize = sizeof cname;
537
538 domlist[print_domlist].with_dom = (c == 'L');
539 if (!opt)
540 {
541 /* If the system uses /etc/passwd exclusively as account DB,
542 create local group names the old fashioned way. */
543 if (nss_src == NSS_SRC_FILES)
544 {
545 GetComputerNameExA (ComputerNameNetBIOS, cname, &csize);
546 domlist[print_domlist].str = cname;
547 }
548 }
549 else if (nss_src != NSS_SRC_FILES)
550 {
551 /* If the system uses Windows account DBs, check if machine
552 name is local machine. If so, remove the domain name to
553 enforce system naming convention. */
554 if (GetComputerNameExA (strchr (opt, '.')
555 ? ComputerNameDnsFullyQualified
556 : ComputerNameNetBIOS,
557 cname, &csize)
558 && strcasecmp (opt, cname) == 0)
559 domlist[print_domlist].str = NULL;
560 }
561 }
562 ++print_domlist;
563 break;
564 case 'S':
565 sep_char = optarg;
566 if (strlen (sep_char) > 1)
567 {
568 fprintf (stderr, "%s: Only one ASCII character allowed as "
569 "domain\\user separator character.\n",
570 program_invocation_short_name);
571 return 1;
572 }
573 if (*sep_char == ':')
574 {
575 fprintf (stderr, "%s: Colon not allowed as domain\\user separator "
576 "character.\n", program_invocation_short_name);
577 return 1;
578 }
579 break;
580 case 'U':
581 print_unix = optarg;
582 break;
583 case 'c':
584 case 'C':
585 print_current = 1;
586 break;
587 case 'o':
588 id_offset = strtoul (optarg, &ep, 10);
589 break;
590 case 'b':
591 print_builtin = 0;
592 break;
593 case 'p':
594 if (optarg[0] != '/')
595 {
596 fprintf (stderr, "%s: '%s' is not a fully qualified path.\n",
597 program_invocation_short_name, optarg);
598 return 1;
599 }
600 strcpy (passed_home_path, optarg);
601 if (optarg[strlen (optarg)-1] != '/')
602 strcat (passed_home_path, "/");
603 break;
604 case 'u':
605 disp_username = optarg;
606 break;
607 case 'h':
608 usage (stdout);
609 case 'V':
610 print_version ();
611 return 0;
612 case 'g': /* deprecated */
613 case 's': /* deprecated */
614 case 'm': /* deprecated */
615 break;
616 default:
617 fprintf (stderr, "Try `%s --help' for more information.\n",
618 program_invocation_short_name);
619 return 1;
620 }
621
622 optind += optional_args;
623 if (argv[optind])
624 {
625 fprintf (stderr,
626 "mkpasswd: non-option command line argument `%s' is not allowed.\n"
627 "Try `mkpasswd --help' for more information.\n", argv[optind]);
628 exit (1);
629 }
630
631 struct passwd *ppwd = NULL;
632 const char *ppwd_sid = NULL;
633 if (print_current)
634 {
635 ppwd = (struct passwd *) cygwin_internal (CW_GETPWSID, TRUE,
636 curr_user.psid);
637 if (ppwd)
638 ppwd_sid = strrchr (ppwd->pw_gecos, ',');
639 }
640
641 int enums = ENUM_NONE;
642 WCHAR tdoms[print_domlist * 258];
643 PWCHAR t = tdoms;
644 if (!disp_username && print_builtin && print_domlist)
645 enums |= ENUM_BUILTIN;
646 for (i = 0; i < print_domlist; ++i)
647 {
648 if (domlist[i].domain)
649 {
650 if (domlist[i].str)
651 {
652 enums |= ENUM_TDOMS;
653 t += mbstowcs (t, domlist[i].str, 257);
654 *t++ = L'\0';
655 }
656 else
657 enums |= ENUM_PRIMARY;
658 }
659 else if (!domlist[i].str)
660 enums |= ENUM_LOCAL;
661 }
662 if (t > tdoms)
663 *t++ = L'\0';
664 if (enums)
665 {
666 uintptr_t ticket = cygwin_internal (CW_SETENT, FALSE, enums,
667 t > tdoms ? tdoms : NULL);
668 if (ticket)
669 {
670 struct passwd *pwd;
671
672 while ((pwd = (struct passwd *)
673 cygwin_internal (CW_GETENT, FALSE, ticket)))
674 {
675 p = NULL;
676 if (disp_username
677 && strcasecmp (disp_username, pwd->pw_name) != 0
678 && (!(p = strchr (pwd->pw_name, nss_sep[0]))
679 || strcasecmp (disp_username, p + 1) != 0))
680 continue;
681 printf ("%s:%s:%u:%u:%s:%s%s:%s\n", pwd->pw_name, pwd->pw_passwd,
682 pwd->pw_uid, pwd->pw_gid, pwd->pw_gecos,
683 passed_home_path[0] ? passed_home_path : "",
684 passed_home_path[0] ? (p ? p + 1 : pwd->pw_name)
685 : pwd->pw_dir,
686 pwd->pw_shell);
687 const char *pwd_sid = strrchr (pwd->pw_gecos, ',');
688 if (ppwd && ppwd_sid && pwd_sid && !strcmp (pwd_sid, ppwd_sid))
689 got_curr_user = TRUE;
690 }
691 cygwin_internal (CW_ENDENT, FALSE, ticket);
692 }
693 }
694
695 if (print_current && !got_curr_user)
696 {
697 p = strchr (ppwd->pw_name, nss_sep[0]);
698 printf ("%s:%s:%u:%u:%s:%s%s:%s\n", ppwd->pw_name, ppwd->pw_passwd,
699 ppwd->pw_uid, ppwd->pw_gid, ppwd->pw_gecos,
700 passed_home_path[0] ? passed_home_path : "",
701 passed_home_path[0] ? (p ? p + 1 : ppwd->pw_name) : ppwd->pw_dir,
702 ppwd->pw_shell);
703 }
704
705 off = 0xfd000000;
706 for (i = 0; i < print_domlist; ++i)
707 {
708 if (domlist[i].domain || !domlist[i].str)
709 continue;
710 enum_users (domlist + i, sep_char, passed_home_path,
711 (nss_src == NSS_SRC_FILES) ? 0x30000 : off,
712 disp_username, print_current);
713 if (!domlist[i].domain && domlist[i].str && print_unix)
714 enum_unix_users (domlist + i, sep_char, 0xff000000, print_unix);
715 off += id_offset;
716 }
717
718 return 0;
719 }
This page took 0.074186 seconds and 5 git commands to generate.