Add option --password to groupadd and groupmod (similar to useradd and usermod).

This commit is contained in:
nekral-guest
2008-01-05 14:17:43 +00:00
parent e94d2da45e
commit f8a95f7ca1
4 changed files with 48 additions and 5 deletions
+20 -2
View File
@@ -68,6 +68,7 @@ static int is_shadow_grp;
*/
static char *group_name;
static gid_t group_id;
static char *group_passwd;
static char *empty_list = NULL;
static char *Prog;
@@ -75,6 +76,7 @@ static char *Prog;
static int oflg = 0; /* permit non-unique group ID to be specified with -g */
static int gflg = 0; /* ID value for the new group */
static int fflg = 0; /* if group already exists, do nothing and exit(0) */
static int pflg = 0; /* new encrypted password */
#ifdef USE_PAM
static pam_handle_t *pamh = NULL;
@@ -127,7 +129,11 @@ static void new_grent (struct group *grent)
{
memzero (grent, sizeof *grent);
grent->gr_name = group_name;
grent->gr_passwd = SHADOW_PASSWD_STRING; /* XXX warning: const */
if (pflg) {
grent->gr_passwd = group_passwd;
} else {
grent->gr_passwd = SHADOW_PASSWD_STRING; /* XXX warning: const */
}
grent->gr_gid = group_id;
grent->gr_mem = &empty_list;
}
@@ -143,7 +149,11 @@ static void new_sgent (struct sgrp *sgent)
{
memzero (sgent, sizeof *sgent);
sgent->sg_name = group_name;
sgent->sg_passwd = "!"; /* XXX warning: const */
if (pflg) {
sgent->sg_passwd = group_passwd;
} else {
sgent->sg_passwd = "!"; /* XXX warning: const */
}
sgent->sg_adm = &empty_list;
sgent->sg_mem = &empty_list;
}
@@ -168,6 +178,9 @@ static void grp_update (void)
new_grent (&grp);
#ifdef SHADOWGRP
new_sgent (&sgrp);
if (is_shadow_grp && pflg) {
grent->gr_passwd = SHADOW_PASSWD_STRING; /* XXX warning: const */
}
#endif /* SHADOWGRP */
/*
@@ -393,6 +406,7 @@ static void process_flags (int argc, char **argv)
{"help", no_argument, NULL, 'h'},
{"key", required_argument, NULL, 'K'},
{"non-unique", required_argument, NULL, 'o'},
{"password", required_argument, NULL, 'p'},
{NULL, 0, NULL, '\0'}
};
@@ -440,6 +454,10 @@ static void process_flags (int argc, char **argv)
case 'o':
oflg++;
break;
case 'p':
pglf++;
group_passwd = optarg;
break;
default:
usage ();
}