diff options
author | Baptiste Daroussin <bapt@FreeBSD.org> | 2015-06-07 19:33:25 +0000 |
---|---|---|
committer | Baptiste Daroussin <bapt@FreeBSD.org> | 2015-06-07 19:33:25 +0000 |
commit | 34211cbde959d55fb8e6b818365341d0193e7253 (patch) | |
tree | 8f79e703daf7289a07cebb93a170b9836a60087e /pw | |
parent | 7d8cc6729f3fcf5fb4c38936179b2c0b9b026130 (diff) | |
download | pw-darwin-34211cbde959d55fb8e6b818365341d0193e7253.tar.gz pw-darwin-34211cbde959d55fb8e6b818365341d0193e7253.tar.zst pw-darwin-34211cbde959d55fb8e6b818365341d0193e7253.zip |
In case of rename validate the length of the new name
Check early that the new name fits MAXLOGNAME and store it in pwconf
Diffstat (limited to 'pw')
-rw-r--r-- | pw/pw.c | 5 | ||||
-rw-r--r-- | pw/pw_group.c | 9 | ||||
-rw-r--r-- | pw/pw_user.c | 8 | ||||
-rw-r--r-- | pw/pwupd.h | 1 |
4 files changed, 14 insertions, 9 deletions
@@ -234,6 +234,11 @@ main(int argc, char *argv[]) case 'N': conf.dryrun = true; break; + case 'l': + if (strlen(optarg) >= MAXLOGNAME) + errx(EX_USAGE, "new name too long: %s", optarg); + conf.newname = optarg; + break; case 'P': conf.pretty = true; break; diff --git a/pw/pw_group.c b/pw/pw_group.c index b06b59e..f95d263 100644 --- a/pw/pw_group.c +++ b/pw/pw_group.c @@ -51,7 +51,6 @@ int pw_group(int mode, char *name, long id, struct cargs * args) { int rc; - struct carg *a_newname = getarg(args, 'l'); struct carg *arg; struct group *grp = NULL; int grmembers = 0; @@ -133,8 +132,8 @@ pw_group(int mode, char *name, long id, struct cargs * args) if (id > 0) grp->gr_gid = (gid_t) id; - if (a_newname != NULL) - grp->gr_name = pw_checkname(a_newname->val, 0); + if (conf.newname != NULL) + grp->gr_name = pw_checkname(conf.newname, 0); } else { if (name == NULL) /* Required */ errx(EX_DATAERR, "group name required"); @@ -262,8 +261,8 @@ pw_group(int mode, char *name, long id, struct cargs * args) err(EX_IOERR, "group update"); } - if (a_newname != NULL) - name = a_newname->val; + if (conf.newname != NULL) + name = conf.newname; /* grp may have been invalidated */ if ((grp = GETGRNAM(name)) == NULL) errx(EX_SOFTWARE, "group disappeared during update"); diff --git a/pw/pw_user.c b/pw/pw_user.c index c9093bb..6b3a266 100644 --- a/pw/pw_user.c +++ b/pw/pw_user.c @@ -382,10 +382,10 @@ pw_user(int mode, char *name, long id, struct cargs * args) /* * The rest is edit code */ - if ((arg = getarg(args, 'l')) != NULL) { + if (conf.newname != NULL) { if (strcmp(pwd->pw_name, "root") == 0) errx(EX_DATAERR, "can't rename `root' account"); - pwd->pw_name = pw_checkname(arg->val, 0); + pwd->pw_name = pw_checkname(conf.newname, 0); edited = 1; } @@ -676,8 +676,8 @@ pw_user(int mode, char *name, long id, struct cargs * args) pwd = GETPWNAM(name); if (pwd == NULL) { /* This will fail when we rename, so special case that */ - if (mode == M_UPDATE && (arg = getarg(args, 'l')) != NULL) { - name = arg->val; /* update new name */ + if (mode == M_UPDATE && conf.newname != NULL) { + name = conf.newname; /* update new name */ pwd = GETPWNAM(name); /* refetch renamed rec */ } } @@ -83,6 +83,7 @@ struct userconf { struct pwconf { char rootdir[MAXPATHLEN]; char etcpath[MAXPATHLEN]; + char *newname; bool dryrun; bool pretty; bool v7; |