add --prefix option
This commit is contained in:
@ -80,6 +80,8 @@ static char *group_passwd;
|
||||
static gid_t group_id;
|
||||
static gid_t group_newid;
|
||||
|
||||
static const char* prefix = "";
|
||||
|
||||
static struct cleanup_info_mod info_passwd;
|
||||
static struct cleanup_info_mod info_group;
|
||||
#ifdef SHADOWGRP
|
||||
@ -128,6 +130,7 @@ static void usage (int status)
|
||||
(void) fputs (_(" -p, --password PASSWORD change the password to this (encrypted)\n"
|
||||
" PASSWORD\n"), usageout);
|
||||
(void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout);
|
||||
(void) fputs (_(" -P, --prefix PREFIX_DIR prefix directory where are located the /etc/* files\n"), usageout);
|
||||
(void) fputs ("\n", usageout);
|
||||
exit (status);
|
||||
}
|
||||
@ -340,7 +343,7 @@ static void check_new_name (void)
|
||||
* If the entry is found, too bad.
|
||||
*/
|
||||
/* local, no need for xgetgrnam */
|
||||
if (getgrnam (group_newname) != NULL) {
|
||||
if (prefix_getgrnam (group_newname) != NULL) {
|
||||
fprintf (stderr,
|
||||
_("%s: group '%s' already exists\n"),
|
||||
Prog, group_newname);
|
||||
@ -376,9 +379,10 @@ static void process_flags (int argc, char **argv)
|
||||
{"non-unique", no_argument, NULL, 'o'},
|
||||
{"password", required_argument, NULL, 'p'},
|
||||
{"root", required_argument, NULL, 'R'},
|
||||
{"prefix", required_argument, NULL, 'P'},
|
||||
{NULL, 0, NULL, '\0'}
|
||||
};
|
||||
while ((c = getopt_long (argc, argv, "g:hn:op:R:",
|
||||
while ((c = getopt_long (argc, argv, "g:hn:op:R:P:",
|
||||
long_options, NULL)) != -1) {
|
||||
switch (c) {
|
||||
case 'g':
|
||||
@ -407,6 +411,8 @@ static void process_flags (int argc, char **argv)
|
||||
break;
|
||||
case 'R': /* no-op, handled in process_root_flag () */
|
||||
break;
|
||||
case 'P': /* no-op, handled in process_prefix_flag () */
|
||||
break;
|
||||
default:
|
||||
usage (E_USAGE);
|
||||
}
|
||||
@ -697,8 +703,8 @@ void update_primary_groups (gid_t ogid, gid_t ngid)
|
||||
{
|
||||
struct passwd *pwd;
|
||||
|
||||
setpwent ();
|
||||
while ((pwd = getpwent ()) != NULL) {
|
||||
prefix_setpwent ();
|
||||
while ((pwd = prefix_getpwent ()) != NULL) {
|
||||
if (pwd->pw_gid == ogid) {
|
||||
const struct passwd *lpwd;
|
||||
struct passwd npwd;
|
||||
@ -720,7 +726,7 @@ void update_primary_groups (gid_t ogid, gid_t ngid)
|
||||
}
|
||||
}
|
||||
}
|
||||
endpwent ();
|
||||
prefix_endpwent ();
|
||||
}
|
||||
|
||||
/*
|
||||
@ -746,6 +752,7 @@ int main (int argc, char **argv)
|
||||
(void) textdomain (PACKAGE);
|
||||
|
||||
process_root_flag ("-R", argc, argv);
|
||||
prefix = process_prefix_flag ("-P", argc, argv);
|
||||
|
||||
OPENLOG ("groupmod");
|
||||
#ifdef WITH_AUDIT
|
||||
@ -805,7 +812,7 @@ int main (int argc, char **argv)
|
||||
/*
|
||||
* Start with a quick check to see if the group exists.
|
||||
*/
|
||||
grp = getgrnam (group_name); /* local, no need for xgetgrnam */
|
||||
grp = prefix_getgrnam (group_name); /* local, no need for xgetgrnam */
|
||||
if (NULL == grp) {
|
||||
fprintf (stderr,
|
||||
_("%s: group '%s' does not exist\n"),
|
||||
|
Reference in New Issue
Block a user