* Global variables
*/
const char *Prog;
-static bool cflg = false;
static bool eflg = false;
static bool md5flg = false;
#ifdef USE_SHA_CRYPT
static bool sflg = false;
#endif
-static const char *crypt_method = NULL;
+static /*@null@*//*@observer@*/const char *crypt_method = NULL;
+#define cflg (NULL != crypt_method)
#ifdef USE_SHA_CRYPT
static long sha_rounds = 5000;
#endif
(void) fputs (_(" -m, --md5 encrypt the clear text password using\n"
" the MD5 algorithm\n"),
usageout);
+ (void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout);
#ifdef USE_SHA_CRYPT
(void) fputs (_(" -s, --sha-rounds number of SHA rounds for the SHA*\n"
" crypt algorithms\n"),
*/
static void process_flags (int argc, char **argv)
{
- int option_index = 0;
int c;
static struct option long_options[] = {
{"crypt-method", required_argument, NULL, 'c'},
{"encrypted", no_argument, NULL, 'e'},
{"help", no_argument, NULL, 'h'},
{"md5", no_argument, NULL, 'm'},
+ {"root", required_argument, NULL, 'R'},
#ifdef USE_SHA_CRYPT
{"sha-rounds", required_argument, NULL, 's'},
#endif
while ((c = getopt_long (argc, argv,
#ifdef USE_SHA_CRYPT
- "c:ehms:",
+ "c:ehmR:s:",
#else
- "c:ehm",
+ "c:ehmR:",
#endif
- long_options, &option_index)) != -1) {
+ long_options, NULL)) != -1) {
switch (c) {
case 'c':
- cflg = true;
crypt_method = optarg;
break;
case 'e':
case 'm':
md5flg = true;
break;
+ case 'R': /* no-op, handled in process_root_flag () */
+ break;
#ifdef USE_SHA_CRYPT
case 's':
sflg = true;
(void) bindtextdomain (PACKAGE, LOCALEDIR);
(void) textdomain (PACKAGE);
+ process_root_flag ("-R", argc, argv);
+
process_flags (argc, argv);
OPENLOG ("chgpasswd");
newpwd = cp;
if ( (!eflg)
&& ( (NULL == crypt_method)
- || (0 != strcmp(crypt_method, "NONE")))) {
+ || (0 != strcmp (crypt_method, "NONE")))) {
void *arg = NULL;
if (md5flg) {
crypt_method = "MD5";
}
#endif
cp = pw_encrypt (newpwd,
- crypt_make_salt(crypt_method, arg));
+ crypt_make_salt (crypt_method, arg));
}
/*
*/
sg = sgr_locate (name);
- if ( (NULL == sp)
- && (strcmp (pw->pw_passwd,
+ if ( (NULL == sg)
+ && (strcmp (gr->gr_passwd,
SHADOW_PASSWD_STRING) == 0)) {
static char *empty = NULL;
/* If the password is set to 'x' in
* group, but there are no entries in
* gshadow, create one.
*/
- newsg.sg_namp = name;
+ newsg.sg_name = name;
/* newsg.sg_passwd = NULL; will be set later */
newsg.sg_adm = ∅
newsg.sg_mem = dup_list (gr->gr_mem);
newsg = *sg;
newsg.sg_passwd = cp;
}
-#endif
if ( (NULL == sg)
- || (strcmp (gr->gr_passwd, SHADOW_PASSWD_STRING) != 0)) {
+ || (strcmp (gr->gr_passwd, SHADOW_PASSWD_STRING) != 0))
+#endif
+ {
newgr = *gr;
newgr.gr_passwd = cp;
}
continue;
}
}
-#endif
if ( (NULL == sg)
- || (strcmp (gr->gr_passwd, SHADOW_PASSWD_STRING) != 0)) {
+ || (strcmp (gr->gr_passwd, SHADOW_PASSWD_STRING) != 0))
+#endif
+ {
if (gr_update (&newgr) == 0) {
fprintf (stderr,
_("%s: line %d: failed to prepare the new %s entry '%s'\n"),