X-Git-Url: https://git.cameronkatri.com/pw-darwin.git/blobdiff_plain/e07217893e016b8c0d1adc04a1117c7a80719800..fcf4b2f12ab5618542cc036a40239eedd658f95a:/pw/pw_group.c diff --git a/pw/pw_group.c b/pw/pw_group.c index 22e80b0..a294d4e 100644 --- a/pw/pw_group.c +++ b/pw/pw_group.c @@ -1,4 +1,6 @@ /*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * * Copyright (C) 1996 * David L. Nugent. All rights reserved. * @@ -32,10 +34,10 @@ static const char rcsid[] = #include #include #include -#include #include #include -#include +#include +#include #include #include @@ -64,13 +66,18 @@ grp_set_passwd(struct group *grp, bool update, int fd, bool precrypted) } if ((istty = isatty(fd))) { - n = t; - /* Disable echo */ - n.c_lflag &= ~(ECHO); - tcsetattr(fd, TCSANOW, &n); - printf("%sassword for group %s:", update ? "New p" : "P", - grp->gr_name); - fflush(stdout); + if (tcgetattr(fd, &t) == -1) + istty = 0; + else { + n = t; + /* Disable echo */ + n.c_lflag &= ~(ECHO); + tcsetattr(fd, TCSANOW, &n); + printf("%sassword for group %s:", + update ? "New p" : "P", + grp->gr_name); + fflush(stdout); + } } b = read(fd, line, sizeof(line) - 1); if (istty) { /* Restore state */ @@ -180,7 +187,8 @@ gr_gidpolicy(struct userconf * cnf, intmax_t id) gid = (gid_t) id; if ((grp = GETGRGID(gid)) != NULL && conf.checkduplicate) - errx(EX_DATAERR, "gid `%ju' has already been allocated", (uintmax_t)grp->gr_gid); + errx(EX_DATAERR, "gid `%ju' has already been allocated", + (uintmax_t)grp->gr_gid); return (gid); } @@ -222,7 +230,8 @@ gr_gidpolicy(struct userconf * cnf, intmax_t id) * Another sanity check */ if (gid < cnf->min_gid || gid > cnf->max_gid) - errx(EX_SOFTWARE, "unable to allocate a new gid - range fully used"); + errx(EX_SOFTWARE, "unable to allocate a new gid - range fully " + "used"); bm_dealloc(&bm); return (gid); } @@ -257,9 +266,9 @@ pw_group_next(int argc, char **argv, char *arg1 __unused) struct userconf *cnf; const char *cfg = NULL; int ch; - bool quiet; + bool quiet = false; - while ((ch = getopt(argc, argv, "Cq")) != -1) { + while ((ch = getopt(argc, argv, "C:q")) != -1) { switch (ch) { case 'C': cfg = optarg; @@ -280,7 +289,7 @@ int pw_group_show(int argc, char **argv, char *arg1) { struct group *grp = NULL; - char *name; + char *name = NULL; intmax_t id = -1; int ch; bool all, force, quiet, pretty; @@ -295,7 +304,7 @@ pw_group_show(int argc, char **argv, char *arg1) }; if (arg1 != NULL) { - if (strspn(arg1, "0123456789") == strlen(arg1)) + if (arg1[strspn(arg1, "0123456789")] == '\0') id = pw_checkid(arg1, GID_MAX); else name = arg1; @@ -358,7 +367,7 @@ pw_group_del(int argc, char **argv, char *arg1) bool nis = false; if (arg1 != NULL) { - if (strspn(arg1, "0123456789") == strlen(arg1)) + if (arg1[strspn(arg1, "0123456789")] == '\0') id = pw_checkid(arg1, GID_MAX); else name = arg1; @@ -489,7 +498,7 @@ pw_group_add(int argc, char **argv, char *arg1) quiet = precrypted = dryrun = pretty = nis = false; if (arg1 != NULL) { - if (strspn(arg1, "0123456789") == strlen(arg1)) + if (arg1[strspn(arg1, "0123456789")] == '\0') id = pw_checkid(arg1, GID_MAX); else name = arg1; @@ -575,7 +584,7 @@ pw_group_mod(int argc, char **argv, char *arg1) quiet = pretty = dryrun = nis = precrypted = false; if (arg1 != NULL) { - if (strspn(arg1, "0123456789") == strlen(arg1)) + if (arg1[strspn(arg1, "0123456789")] == '\0') id = pw_checkid(arg1, GID_MAX); else name = arg1; @@ -662,6 +671,11 @@ pw_group_mod(int argc, char **argv, char *arg1) grp_add_members(&grp, newmembers); } + if (dryrun) { + print_group(grp, pretty); + return (EXIT_SUCCESS); + } + if ((rc = chggrent(name, grp)) != 0) { if (rc == -1) errx(EX_IOERR, "group '%s' not available (NIS?)",