svn commit: r285412 - head/usr.sbin/pw
Baptiste Daroussin
bapt at FreeBSD.org
Sat Jul 11 23:07:19 UTC 2015
Author: bapt
Date: Sat Jul 11 23:07:17 2015
New Revision: 285412
URL: https://svnweb.freebsd.org/changeset/base/285412
Log:
Replace custom string array with stringlist(3)
Deleted:
head/usr.sbin/pw/fileupd.c
Modified:
head/usr.sbin/pw/Makefile
head/usr.sbin/pw/pw_conf.c
head/usr.sbin/pw/pw_user.c
head/usr.sbin/pw/pwupd.h
Modified: head/usr.sbin/pw/Makefile
==============================================================================
--- head/usr.sbin/pw/Makefile Sat Jul 11 22:35:07 2015 (r285411)
+++ head/usr.sbin/pw/Makefile Sat Jul 11 23:07:17 2015 (r285412)
@@ -3,8 +3,7 @@
PROG= pw
MAN= pw.conf.5 pw.8
SRCS= pw.c pw_conf.c pw_user.c pw_group.c pw_log.c pw_nis.c pw_vpw.c \
- grupd.c pwupd.c fileupd.c psdate.c \
- bitmap.c cpdir.c rm_r.c
+ grupd.c pwupd.c psdate.c bitmap.c cpdir.c rm_r.c
WARNS?= 3
Modified: head/usr.sbin/pw/pw_conf.c
==============================================================================
--- head/usr.sbin/pw/pw_conf.c Sat Jul 11 22:35:07 2015 (r285411)
+++ head/usr.sbin/pw/pw_conf.c Sat Jul 11 23:07:17 2015 (r285412)
@@ -104,8 +104,7 @@ static struct userconf config =
1000, 32000, /* Allowed range of uids */
1000, 32000, /* Allowed range of gids */
0, /* Days until account expires */
- 0, /* Days until password expires */
- 0 /* size of default_group array */
+ 0 /* Days until password expires */
};
static char const *comments[_UC_FIELDS] =
@@ -234,10 +233,9 @@ read_userconfig(char const * file)
buf = NULL;
linecap = 0;
- config.numgroups = 200;
- config.groups = calloc(config.numgroups, sizeof(char *));
+ config.groups = sl_init();
if (config.groups == NULL)
- err(1, "calloc()");
+ err(1, "sl_init()");
if (file == NULL)
file = _PATH_PW_CONF;
@@ -316,13 +314,8 @@ read_userconfig(char const * file)
? NULL : newstr(q);
break;
case _UC_EXTRAGROUPS:
- for (i = 0; q != NULL; q = strtok(NULL, toks)) {
- if (extendarray(&config.groups, &config.numgroups, i + 2) != -1)
- config.groups[i++] = newstr(q);
- }
- if (i > 0)
- while (i < config.numgroups)
- config.groups[i++] = NULL;
+ for (i = 0; q != NULL; q = strtok(NULL, toks))
+ sl_add(config.groups, newstr(q));
break;
case _UC_DEFAULTCLASS:
config.default_class = (q == NULL || !boolean_val(q, 1))
@@ -442,10 +435,10 @@ write_userconfig(char const * file)
config.default_group : "");
break;
case _UC_EXTRAGROUPS:
- for (j = 0; j < config.numgroups &&
- config.groups[j] != NULL; j++)
+ for (j = 0; config.groups != NULL &&
+ j < (int)config.groups->sl_cur; j++)
sbuf_printf(buf, "%s\"%s\"", j ?
- "," : "", config.groups[j]);
+ "," : "", config.groups->sl_str[j]);
quote = 0;
break;
case _UC_DEFAULTCLASS:
Modified: head/usr.sbin/pw/pw_user.c
==============================================================================
--- head/usr.sbin/pw/pw_user.c Sat Jul 11 22:35:07 2015 (r285411)
+++ head/usr.sbin/pw/pw_user.c Sat Jul 11 23:07:17 2015 (r285412)
@@ -440,18 +440,13 @@ pw_user(int mode, char *name, long id, s
cnf->default_class = pw_checkname(arg->val, 0);
if ((arg = getarg(args, 'G')) != NULL && arg->val) {
- int i = 0;
-
for (p = strtok(arg->val, ", \t"); p != NULL; p = strtok(NULL, ", \t")) {
if ((grp = GETGRNAM(p)) == NULL) {
if (!isdigit((unsigned char)*p) || (grp = GETGRGID((gid_t) atoi(p))) == NULL)
errx(EX_NOUSER, "group `%s' does not exist", p);
}
- if (extendarray(&cnf->groups, &cnf->numgroups, i + 2) != -1)
- cnf->groups[i++] = newstr(grp->gr_name);
+ sl_add(cnf->groups, newstr(grp->gr_name));
}
- while (i < cnf->numgroups)
- cnf->groups[i++] = NULL;
}
if ((arg = getarg(args, 'k')) != NULL) {
@@ -690,7 +685,8 @@ pw_user(int mode, char *name, long id, s
*/
if (mode == M_ADD || getarg(args, 'G') != NULL) {
- int i, j;
+ int j;
+ size_t i;
/* First remove the user from all group */
SETGRENT();
while ((grp = GETGRENT()) != NULL) {
@@ -709,8 +705,8 @@ pw_user(int mode, char *name, long id, s
ENDGRENT();
/* now add to group where needed */
- for (i = 0; cnf->groups[i] != NULL; i++) {
- grp = GETGRNAM(cnf->groups[i]);
+ for (i = 0; i < cnf->groups->sl_cur; i++) {
+ grp = GETGRNAM(cnf->groups->sl_str[i]);
grp = gr_add(grp, pwd->pw_name);
/*
* grp can only be NULL in 2 cases:
@@ -720,7 +716,7 @@ pw_user(int mode, char *name, long id, s
*/
if (grp == NULL)
continue;
- chggrent(cnf->groups[i], grp);
+ chggrent(grp->gr_name, grp);
free(grp);
}
}
Modified: head/usr.sbin/pw/pwupd.h
==============================================================================
--- head/usr.sbin/pw/pwupd.h Sat Jul 11 22:35:07 2015 (r285411)
+++ head/usr.sbin/pw/pwupd.h Sat Jul 11 23:07:17 2015 (r285412)
@@ -36,6 +36,7 @@
#include <pwd.h>
#include <grp.h>
#include <stdbool.h>
+#include <stringlist.h>
#if defined(__FreeBSD__)
#define RET_SETGRENT int
@@ -58,26 +59,25 @@ struct pwf {
};
struct userconf {
- int default_password; /* Default password for new users? */
- int reuse_uids; /* Reuse uids? */
- int reuse_gids; /* Reuse gids? */
- char *nispasswd; /* Path to NIS version of the passwd file */
- char *dotdir; /* Where to obtain skeleton files */
- char *newmail; /* Mail to send to new accounts */
- char *logfile; /* Where to log changes */
- char *home; /* Where to create home directory */
- mode_t homemode; /* Home directory permissions */
- char *shelldir; /* Where shells are located */
- char **shells; /* List of shells */
- char *shell_default; /* Default shell */
- char *default_group; /* Default group number */
- char **groups; /* Default (additional) groups */
- char *default_class; /* Default user class */
- uid_t min_uid, max_uid; /* Allowed range of uids */
- gid_t min_gid, max_gid; /* Allowed range of gids */
- int expire_days; /* Days to expiry */
- int password_days; /* Days to password expiry */
- int numgroups; /* (internal) size of default_group array */
+ int default_password; /* Default password for new users? */
+ int reuse_uids; /* Reuse uids? */
+ int reuse_gids; /* Reuse gids? */
+ char *nispasswd; /* Path to NIS version of the passwd file */
+ char *dotdir; /* Where to obtain skeleton files */
+ char *newmail; /* Mail to send to new accounts */
+ char *logfile; /* Where to log changes */
+ char *home; /* Where to create home directory */
+ mode_t homemode; /* Home directory permissions */
+ char *shelldir; /* Where shells are located */
+ char **shells; /* List of shells */
+ char *shell_default; /* Default shell */
+ char *default_group; /* Default group number */
+ StringList *groups; /* Default (additional) groups */
+ char *default_class; /* Default user class */
+ uid_t min_uid, max_uid; /* Allowed range of uids */
+ gid_t min_gid, max_gid; /* Allowed range of gids */
+ int expire_days; /* Days to expiry */
+ int password_days; /* Days to password expiry */
};
struct pwconf {
@@ -158,7 +158,6 @@ void vendgrent(void);
void copymkdir(char const * dir, char const * skel, mode_t mode, uid_t uid, gid_t gid);
void rm_r(char const * dir, uid_t uid);
-int extendarray(char ***buf, int *buflen, int needed);
__END_DECLS
#endif /* !_PWUPD_H */
More information about the svn-src-all
mailing list