* mkpasswd.c: make default home directory /home/$user if one

can't be found in user registry. Allow user to override
        that with command line arg.
        (longopts): Fix typo in `local-groups' option.
        (main): Initialize `passed_home_path' before first usage.
This commit is contained in:
Corinna Vinschen 2000-12-07 10:31:01 +00:00
parent 37c49e19f2
commit 9ae2974ffd
2 changed files with 58 additions and 19 deletions

View File

@ -1,3 +1,15 @@
Tue Dec 7 11:15:00 2000 Corinna Vinschen <corinna@vinschen.de>
* mkpasswd.c: Slight formatting changes to the below patch.
(longopts): Fix typo in `local-groups' option.
(main): Initialize `passed_home_path' before first usage.
Tue Dec 7 11:15:00 2000 Chris Abbey <cabbey@bresnanlink.net>
* mkpasswd.c: make default home directory /home/$user if one
can't be found in user registry. Allow user to override
that with command line arg.
Sun Dec 3 00:40:47 2000 Christopher Faylor <cgf@cygnus.com> Sun Dec 3 00:40:47 2000 Christopher Faylor <cgf@cygnus.com>
* Makefile.in: Use CXX to build the DLL. * Makefile.in: Use CXX to build the DLL.

View File

@ -102,7 +102,8 @@ uni2ansi (LPWSTR wcs, char *mbs)
} }
int int
enum_users (LPWSTR servername, int print_sids, int print_cygpath) enum_users (LPWSTR servername, int print_sids, int print_cygpath,
const char * passed_home_path)
{ {
USER_INFO_3 *buffer; USER_INFO_3 *buffer;
DWORD entriesread = 0; DWORD entriesread = 0;
@ -160,6 +161,12 @@ enum_users (LPWSTR servername, int print_sids, int print_cygpath)
else else
psx_dir (homedir_w32, homedir_psx); psx_dir (homedir_w32, homedir_psx);
if (homedir_psx[0] == '\0')
{
strcat (homedir_psx, passed_home_path);
strcat (homedir_psx, username);
}
if (print_sids) if (print_sids)
{ {
if (!LookupAccountName (servername ? ansi_srvname : NULL, if (!LookupAccountName (servername ? ansi_srvname : NULL,
@ -309,15 +316,17 @@ usage ()
fprintf (stderr, "Usage: mkpasswd [OPTION]... [domain]\n\n"); fprintf (stderr, "Usage: mkpasswd [OPTION]... [domain]\n\n");
fprintf (stderr, "This program prints a /etc/passwd file to stdout\n\n"); fprintf (stderr, "This program prints a /etc/passwd file to stdout\n\n");
fprintf (stderr, "Options:\n"); fprintf (stderr, "Options:\n");
fprintf (stderr, " -l,--local print local user accounts\n"); fprintf (stderr, " -l,--local print local user accounts\n");
fprintf (stderr, " -d,--domain print domain accounts (from current domain\n"); fprintf (stderr, " -d,--domain print domain accounts (from current domain\n");
fprintf (stderr, " if no domain specified)\n"); fprintf (stderr, " if no domain specified)\n");
fprintf (stderr, " -g,--local-groups print local group information too\n"); fprintf (stderr, " -g,--local-groups print local group information too\n");
fprintf (stderr, " if no domain specified\n"); fprintf (stderr, " if no domain specified\n");
fprintf (stderr, " -m,--no-mount don't use mount points for home dir\n"); fprintf (stderr, " -m,--no-mount don't use mount points for home dir\n");
fprintf (stderr, " -s,--no-sids don't print SIDs in GCOS field\n"); fprintf (stderr, " -s,--no-sids don't print SIDs in GCOS field\n");
fprintf (stderr, " (this affects ntsec)\n"); fprintf (stderr, " (this affects ntsec)\n");
fprintf (stderr, " -?,--help displays this message\n\n"); fprintf (stderr, " -p,--path-to-home path if user account has no home dir, use\n");
fprintf (stderr, " path instead of /home/\n");
fprintf (stderr, " -?,--help displays this message\n\n");
fprintf (stderr, "One of `-l', `-d' or `-g' must be given on NT/W2K.\n"); fprintf (stderr, "One of `-l', `-d' or `-g' must be given on NT/W2K.\n");
return 1; return 1;
} }
@ -325,14 +334,15 @@ usage ()
struct option longopts[] = { struct option longopts[] = {
{"local", no_argument, NULL, 'l'}, {"local", no_argument, NULL, 'l'},
{"domain", no_argument, NULL, 'd'}, {"domain", no_argument, NULL, 'd'},
{"loca-groups", no_argument, NULL, 'g'}, {"local-groups", no_argument, NULL, 'g'},
{"no-mount", no_argument, NULL, 'm'}, {"no-mount", no_argument, NULL, 'm'},
{"no-sids", no_argument, NULL, 's'}, {"no-sids", no_argument, NULL, 's'},
{"path-to-home",required_argument, NULL, 'p'},
{"help", no_argument, NULL, 'h'}, {"help", no_argument, NULL, 'h'},
{0, no_argument, NULL, 0} {0, no_argument, NULL, 0}
}; };
char opts[] = "ldgsmh"; char opts[] = "ldgsmhp:";
int int
main (int argc, char **argv) main (int argc, char **argv)
@ -348,11 +358,13 @@ main (int argc, char **argv)
int print_cygpath = 1; int print_cygpath = 1;
int i; int i;
char name[256], dom[256]; char name[256], dom[256], passed_home_path[MAX_PATH];
DWORD len, len2; DWORD len, len2;
PSID sid; PSID sid;
SID_NAME_USE use; SID_NAME_USE use;
passed_home_path[0] = '\0';
if (GetVersion () < 0x80000000) if (GetVersion () < 0x80000000)
if (argc == 1) if (argc == 1)
return usage (); return usage ();
@ -376,6 +388,17 @@ main (int argc, char **argv)
case 'm': case 'm':
print_cygpath = 0; print_cygpath = 0;
break; break;
case 'p':
if (optarg[0] != '/')
{
fprintf (stderr, "%s: `%s' is not a fully qualified path.\n",
argv[0], optarg);
return 1;
}
strcpy (passed_home_path, optarg);
if (optarg[strlen (optarg)-1] != '/')
strcat (passed_home_path, "/");
break;
case 'h': case 'h':
return usage (); return usage ();
default: default:
@ -400,6 +423,9 @@ main (int argc, char **argv)
} }
} }
if (passed_home_path[0] == '\0')
strcpy (passed_home_path, "/home/");
/* This takes Windows 9x/ME into account. */ /* This takes Windows 9x/ME into account. */
if (GetVersion () >= 0x80000000) if (GetVersion () >= 0x80000000)
{ {
@ -407,10 +433,11 @@ main (int argc, char **argv)
if (!GetUserName (name, (len = 256, &len))) if (!GetUserName (name, (len = 256, &len)))
strcpy (name, "unknown"); strcpy (name, "unknown");
printf ("%s::%ld:%ld::/home/%s:/bin/sh\n", name, printf ("%s::%ld:%ld::%s%s:/bin/sh\n", name,
DOMAIN_USER_RID_ADMIN, DOMAIN_USER_RID_ADMIN,
DOMAIN_ALIAS_RID_ADMINS, DOMAIN_ALIAS_RID_ADMINS,
name); passed_home_path,
name);
return 0; return 0;
} }
@ -496,11 +523,11 @@ main (int argc, char **argv)
exit (1); exit (1);
} }
enum_users (servername, print_sids, print_cygpath); enum_users (servername, print_sids, print_cygpath, passed_home_path);
} }
if (print_local) if (print_local)
enum_users (NULL, print_sids, print_cygpath); enum_users (NULL, print_sids, print_cygpath, passed_home_path);
if (servername) if (servername)
netapibufferfree (servername); netapibufferfree (servername);