summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander V. Chernikov <melifaro@FreeBSD.org>2014-11-04 18:22:33 +0000
committerAlexander V. Chernikov <melifaro@FreeBSD.org>2014-11-04 18:22:33 +0000
commitfb90d29ec2763027a93943b3f30250bd05afd62c (patch)
tree96a455d21208bb7513ef6e9f676483252d38afa3
parenta67255c0571b3f564056b8dd161f54db9815c014 (diff)
parent8c4532e1189f5ef981aff455332acbfbb082cfa9 (diff)
downloadpw-darwin-fb90d29ec2763027a93943b3f30250bd05afd62c.tar.gz
pw-darwin-fb90d29ec2763027a93943b3f30250bd05afd62c.tar.zst
pw-darwin-fb90d29ec2763027a93943b3f30250bd05afd62c.zip
Sync to HEAD@r274095.
-rw-r--r--libutil/gr_util.c17
-rw-r--r--pw/pw_group.c14
-rw-r--r--pw/pw_user.c23
3 files changed, 45 insertions, 9 deletions
diff --git a/libutil/gr_util.c b/libutil/gr_util.c
index 6f74507..465efd9 100644
--- a/libutil/gr_util.c
+++ b/libutil/gr_util.c
@@ -170,14 +170,21 @@ gr_copy(int ffd, int tfd, const struct group *gr, struct group *old_gr)
size_t len;
int eof, readlen;
- sgr = gr;
+ if (old_gr == NULL && gr == NULL)
+ return(-1);
+
+ sgr = old_gr;
+ /* deleting a group */
if (gr == NULL) {
line = NULL;
- if (old_gr == NULL)
+ } else {
+ if ((line = gr_make(gr)) == NULL)
return (-1);
- sgr = old_gr;
- } else if ((line = gr_make(gr)) == NULL)
- return (-1);
+ }
+
+ /* adding a group */
+ if (sgr == NULL)
+ sgr = gr;
eof = 0;
len = 0;
diff --git a/pw/pw_group.c b/pw/pw_group.c
index 391e477..b20ce88 100644
--- a/pw/pw_group.c
+++ b/pw/pw_group.c
@@ -51,6 +51,7 @@ int
pw_group(struct userconf * cnf, int mode, struct cargs * args)
{
int rc;
+ struct carg *a_newname = getarg(args, 'l');
struct carg *a_name = getarg(args, 'n');
struct carg *a_gid = getarg(args, 'g');
struct carg *arg;
@@ -66,6 +67,11 @@ pw_group(struct userconf * cnf, int mode, struct cargs * args)
NULL
};
+ if (a_gid != NULL) {
+ if (strspn(a_gid->val, "0123456789") != strlen(a_gid->val))
+ errx(EX_USAGE, "-g expects a number");
+ }
+
if (mode == M_LOCK || mode == M_UNLOCK)
errx(EX_USAGE, "'lock' command is not available for groups");
@@ -140,8 +146,8 @@ pw_group(struct userconf * cnf, int mode, struct cargs * args)
if (a_gid)
grp->gr_gid = (gid_t) atoi(a_gid->val);
- if ((arg = getarg(args, 'l')) != NULL)
- grp->gr_name = pw_checkname((u_char *)arg->val, 0);
+ if (a_newname != NULL)
+ grp->gr_name = pw_checkname((u_char *)a_newname->val, 0);
} else {
if (a_name == NULL) /* Required */
errx(EX_DATAERR, "group name required");
@@ -270,8 +276,10 @@ pw_group(struct userconf * cnf, int mode, struct cargs * args)
warn("group update");
return EX_IOERR;
}
+
+ arg = a_newname != NULL ? a_newname : a_name;
/* grp may have been invalidated */
- if ((grp = GETGRNAM(a_name->val)) == NULL)
+ if ((grp = GETGRNAM(arg->val)) == NULL)
errx(EX_SOFTWARE, "group disappeared during update");
pw_log(cnf, mode, W_GROUP, "%s(%ld)", grp->gr_name, (long) grp->gr_gid);
diff --git a/pw/pw_user.c b/pw/pw_user.c
index efb2901..483148a 100644
--- a/pw/pw_user.c
+++ b/pw/pw_user.c
@@ -321,6 +321,9 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
(a_uid = a_name)->ch = 'u';
a_name = NULL;
}
+ } else {
+ if (strspn(a_uid->val, "0123456789") != strlen(a_uid->val))
+ errx(EX_USAGE, "-u expects a number");
}
/*
@@ -751,7 +754,25 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args)
*/
if (mode == M_ADD || getarg(args, 'G') != NULL) {
- int i;
+ int i, j;
+ /* First remove the user from all group */
+ SETGRENT();
+ while ((grp = GETGRENT()) != NULL) {
+ char group[MAXLOGNAME];
+ if (grp->gr_mem == NULL)
+ continue;
+ for (i = 0; grp->gr_mem[i] != NULL; i++) {
+ if (strcmp(grp->gr_mem[i] , pwd->pw_name) != 0)
+ continue;
+ for (j = i; grp->gr_mem[j] != NULL ; j++)
+ grp->gr_mem[j] = grp->gr_mem[j+1];
+ strlcpy(group, grp->gr_name, MAXLOGNAME);
+ chggrent(group, grp);
+ }
+ }
+ ENDGRENT();
+
+ /* now add to group where needed */
for (i = 0; cnf->groups[i] != NULL; i++) {
grp = GETGRNAM(cnf->groups[i]);
grp = gr_add(grp, pwd->pw_name);