diff options
Diffstat (limited to 'pw')
-rw-r--r-- | pw/Makefile.depend | 20 | ||||
-rw-r--r-- | pw/pw.h | 1 | ||||
-rw-r--r-- | pw/pw_conf.c | 35 | ||||
-rw-r--r-- | pw/pw_group.c | 19 | ||||
-rw-r--r-- | pw/pw_user.c | 44 |
5 files changed, 65 insertions, 54 deletions
diff --git a/pw/Makefile.depend b/pw/Makefile.depend new file mode 100644 index 0000000..1797aa7 --- /dev/null +++ b/pw/Makefile.depend @@ -0,0 +1,20 @@ +# Autogenerated - do NOT edit! + +DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,} + +DIRDEPS = \ + gnu/lib/libgcc \ + include \ + include/xlocale \ + lib/${CSU_DIR} \ + lib/libc \ + lib/libcompiler_rt \ + lib/libcrypt \ + lib/libutil \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif @@ -26,7 +26,6 @@ * $FreeBSD$ */ -#define _WITH_GETLINE #include <stdio.h> #include <stdlib.h> #include <string.h> diff --git a/pw/pw_conf.c b/pw/pw_conf.c index 1289b3e..edeb015 100644 --- a/pw/pw_conf.c +++ b/pw/pw_conf.c @@ -226,21 +226,35 @@ newstr(char const * p) struct userconf * read_userconfig(char const * file) { - FILE *fp; - char *buf, *p; - size_t linecap; - ssize_t linelen; - - buf = NULL; - linecap = 0; + FILE *fp; extendarray(&config.groups, &config.numgroups, 200); memset(config.groups, 0, config.numgroups * sizeof(char *)); if (file == NULL) file = _PATH_PW_CONF; - if ((fp = fopen(file, "r")) != NULL) { - while ((linelen = getline(&buf, &linecap, fp)) > 0) { + int buflen = LNBUFSZ; + char *buf = malloc(buflen); + + nextline: + while (fgets(buf, buflen, fp) != NULL) { + char *p; + + while ((p = strchr(buf, '\n')) == NULL) { + int l; + if (extendline(&buf, &buflen, buflen + LNBUFSZ) == -1) { + int ch; + while ((ch = fgetc(fp)) != '\n' && ch != EOF); + goto nextline; /* Ignore it */ + } + l = strlen(buf); + if (fgets(buf + l, buflen - l, fp) == NULL) + break; /* Unterminated last line */ + } + + if (p != NULL) + *p = '\0'; + if (*buf && (p = strtok(buf, " \t\r\n=")) != NULL && *p != '#') { static char const toks[] = " \t\r\n,="; char *q = strtok(NULL, toks); @@ -354,8 +368,7 @@ read_userconfig(char const * file) } } } - if (linecap > 0) - free(buf); + free(buf); fclose(fp); } return &config; diff --git a/pw/pw_group.c b/pw/pw_group.c index 391e477..3259412 100644 --- a/pw/pw_group.c +++ b/pw/pw_group.c @@ -227,12 +227,10 @@ pw_group(struct userconf * cnf, int mode, struct cargs * args) else if (arg->ch == 'm') { int k = 0; - if (grp->gr_mem != NULL) { - while (grp->gr_mem[k] != NULL) { - if (extendarray(&members, &grmembers, i + 2) != -1) - members[i++] = grp->gr_mem[k]; - k++; - } + while (grp->gr_mem[k] != NULL) { + if (extendarray(&members, &grmembers, i + 2) != -1) + members[i++] = grp->gr_mem[k]; + k++; } } @@ -313,9 +311,6 @@ delete_members(char ***members, int *grmembers, int *i, struct carg *arg, int k; struct passwd *pwd; - if (grp->gr_mem == NULL) - return; - k = 0; while (grp->gr_mem[k] != NULL) { matchFound = false; @@ -420,10 +415,8 @@ print_group(struct group * grp, int pretty) printf("Group Name: %-15s #%lu\n" " Members: ", grp->gr_name, (long) grp->gr_gid); - if (grp->gr_mem != NULL) { - for (i = 0; grp->gr_mem[i]; i++) - printf("%s%s", i ? "," : "", grp->gr_mem[i]); - } + for (i = 0; grp->gr_mem[i]; i++) + printf("%s%s", i ? "," : "", grp->gr_mem[i]); fputs("\n\n", stdout); } return EXIT_SUCCESS; diff --git a/pw/pw_user.c b/pw/pw_user.c index 4b3f550..def238c 100644 --- a/pw/pw_user.c +++ b/pw/pw_user.c @@ -380,8 +380,6 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args) char file[MAXPATHLEN]; char home[MAXPATHLEN]; uid_t uid = pwd->pw_uid; - struct group *gr; - char grname[LOGNAMESIZE]; if (strcmp(pwd->pw_name, "root") == 0) errx(EX_DATAERR, "cannot remove user 'root'"); @@ -408,11 +406,6 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args) */ sprintf(file, "%s/%s", _PATH_MAILDIR, pwd->pw_name); strlcpy(home, pwd->pw_dir, sizeof(home)); - gr = GETGRGID(pwd->pw_gid); - if (gr != NULL) - strlcpy(grname, gr->gr_name, LOGNAMESIZE); - else - grname[0] = '\0'; rc = delpwent(pwd); if (rc == -1) @@ -432,23 +425,19 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args) } grp = GETGRNAM(a_name->val); - if (grp != NULL && - (grp->gr_mem == NULL || *grp->gr_mem == NULL) && - strcmp(a_name->val, grname) == 0) + if (grp != NULL && *grp->gr_mem == NULL) delgrent(GETGRNAM(a_name->val)); SETGRENT(); while ((grp = GETGRENT()) != NULL) { int i; char group[MAXLOGNAME]; - if (grp->gr_mem != NULL) { - for (i = 0; grp->gr_mem[i] != NULL; i++) { - if (!strcmp(grp->gr_mem[i], a_name->val)) { - while (grp->gr_mem[i] != NULL) { - grp->gr_mem[i] = grp->gr_mem[i+1]; - } - strlcpy(group, grp->gr_name, MAXLOGNAME); - chggrent(group, grp); - } + for (i = 0; grp->gr_mem[i] != NULL; i++) { + if (!strcmp(grp->gr_mem[i], a_name->val)) { + while (grp->gr_mem[i] != NULL) { + grp->gr_mem[i] = grp->gr_mem[i+1]; + } + strlcpy(group, grp->gr_name, MAXLOGNAME); + chggrent(group, grp); } } } @@ -919,8 +908,7 @@ pw_gidpolicy(struct userconf * cnf, struct cargs * args, char *nam, gid_t prefer errx(EX_NOUSER, "group `%s' is not defined", a_gid->val); } gid = grp->gr_gid; - } else if ((grp = GETGRNAM(nam)) != NULL && - (grp->gr_mem == NULL || grp->gr_mem[0] == NULL)) { + } else if ((grp = GETGRNAM(nam)) != NULL && grp->gr_mem[0] == NULL) { gid = grp->gr_gid; /* Already created? Use it anyway... */ } else { struct cargs grpargs; @@ -1194,16 +1182,14 @@ print_user(struct passwd * pwd, int pretty, int v7) while ((grp=GETGRENT()) != NULL) { int i = 0; - if (grp->gr_mem != NULL) { - while (grp->gr_mem[i] != NULL) + while (grp->gr_mem[i] != NULL) + { + if (strcmp(grp->gr_mem[i], pwd->pw_name)==0) { - if (strcmp(grp->gr_mem[i], pwd->pw_name)==0) - { - printf(j++ == 0 ? " Groups: %s" : ",%s", grp->gr_name); - break; - } - ++i; + printf(j++ == 0 ? " Groups: %s" : ",%s", grp->gr_name); + break; } + ++i; } } ENDGRENT(); |