From bc539790827cbc69585a6ec393f04705e5825eff Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Sat, 11 Jul 2015 16:58:47 +0000 Subject: Separate usernext/groupnext from the main functions --- pw/pw.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'pw/pw.h') diff --git a/pw/pw.h b/pw/pw.h index 6239004..ed3b715 100644 --- a/pw/pw.h +++ b/pw/pw.h @@ -83,7 +83,9 @@ struct carg *addarg(struct cargs * _args, int ch, char *argstr); struct carg *getarg(struct cargs * _args, int ch); int pw_user(int mode, char *name, long id, struct cargs * _args); +int pw_usernext(struct userconf *cnf, bool quiet); int pw_group(int mode, char *name, long id, struct cargs * _args); +int pw_groupnext(struct userconf *cnf, bool quiet); char *pw_checkname(char *name, int gecos); int addnispwent(const char *path, struct passwd *pwd); -- cgit v1.2.3 From 00e5987be5ae3b7c108866ac1dba4403cc4306d5 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Wed, 29 Jul 2015 06:22:41 +0000 Subject: Create a strtounum function using the same API as strtonum This function returns uintmax_t Use this function to convert to gid_t/uid_t --- pw/pw.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'pw/pw.h') diff --git a/pw/pw.h b/pw/pw.h index ed3b715..3ab3c74 100644 --- a/pw/pw.h +++ b/pw/pw.h @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -101,3 +102,6 @@ char *pw_pwcrypt(char *password); extern const char *Modes[]; extern const char *Which[]; + +uintmax_t strtounum(const char *numstr, uintmax_t minval, uintmax_t maxval, + const char **errmsg); -- cgit v1.2.3 From 118a862383488360f366603cc32994fd65718474 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Thu, 30 Jul 2015 06:14:47 +0000 Subject: Improve strtounum Fix many style bugs Better variable naming Use C99 'restrict' were apropriate Fix potential errno race Submitted by: bde --- pw/pw.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'pw/pw.h') diff --git a/pw/pw.h b/pw/pw.h index 3ab3c74..a22572e 100644 --- a/pw/pw.h +++ b/pw/pw.h @@ -103,5 +103,5 @@ char *pw_pwcrypt(char *password); extern const char *Modes[]; extern const char *Which[]; -uintmax_t strtounum(const char *numstr, uintmax_t minval, uintmax_t maxval, - const char **errmsg); +uintmax_t strtounum(const char * __restrict, uintmax_t, uintmax_t, + const char ** __restrict); -- cgit v1.2.3 From e773096e9049d4fb494d9ea86a862cd89d62bdfc Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Sun, 2 Aug 2015 12:47:50 +0000 Subject: Rewrite parsing subcommands arguments of pw(8) Now each subcommands checks its arguments in a dedicated functions. This helps improving input validation, code readability/maintainability While here: - Add a -y option to pw userdel/usermod so it can maintain NIS servers if nispasswd is not defined in pw.conf(5) - Allow pw -r to remove directory with userdel -r - Fix bug when renaming a user which was not renaming the user name it groups it is a member of. - Only parse pw.conf(5) when needed. --- pw/pw.h | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'pw/pw.h') diff --git a/pw/pw.h b/pw/pw.h index a22572e..b6e2ccf 100644 --- a/pw/pw.h +++ b/pw/pw.h @@ -78,21 +78,41 @@ LIST_HEAD(cargs, carg); #define _UC_MAXLINE 1024 #define _UC_MAXSHELLS 32 +struct userconf *get_userconfig(const char *cfg); struct userconf *read_userconfig(char const * file); -int write_userconfig(char const * file); +int write_userconfig(struct userconf *cnf, char const * file); struct carg *addarg(struct cargs * _args, int ch, char *argstr); struct carg *getarg(struct cargs * _args, int ch); -int pw_user(int mode, char *name, long id, struct cargs * _args); -int pw_usernext(struct userconf *cnf, bool quiet); -int pw_group(int mode, char *name, long id, struct cargs * _args); +int pw_group_add(int argc, char **argv, char *name); +int pw_group_del(int argc, char **argv, char *name); +int pw_group_mod(int argc, char **argv, char *name); +int pw_group_next(int argc, char **argv, char *name); +int pw_group_show(int argc, char **argv, char *name); +int pw_user_add(int argc, char **argv, char *name); +int pw_user_add(int argc, char **argv, char *name); +int pw_user_add(int argc, char **argv, char *name); +int pw_user_add(int argc, char **argv, char *name); +int pw_user_del(int argc, char **argv, char *name); +int pw_user_lock(int argc, char **argv, char *name); +int pw_user_mod(int argc, char **argv, char *name); +int pw_user_next(int argc, char **argv, char *name); +int pw_user_show(int argc, char **argv, char *name); +int pw_user_unlock(int argc, char **argv, char *name); int pw_groupnext(struct userconf *cnf, bool quiet); char *pw_checkname(char *name, int gecos); +uintmax_t pw_checkid(char *nptr, uintmax_t maxval); +int pw_checkfd(char *nptr); int addnispwent(const char *path, struct passwd *pwd); int delnispwent(const char *path, const char *login); int chgnispwent(const char *path, const char *login, struct passwd *pwd); +int groupadd(struct userconf *, char *name, gid_t id, char *members, int fd, + bool dryrun, bool pretty, bool precrypted); + +int nis_update(void); + int boolean_val(char const * str, int dflt); char const *boolean_str(int val); char *newstr(char const * p); -- cgit v1.2.3 From 3bb519ecb05089cfdfebe8aeb2d0057b66ec8659 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Sun, 2 Aug 2015 12:48:36 +0000 Subject: Remove dead code --- pw/pw.h | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'pw/pw.h') diff --git a/pw/pw.h b/pw/pw.h index b6e2ccf..e1a3949 100644 --- a/pw/pw.h +++ b/pw/pw.h @@ -64,15 +64,6 @@ enum _which W_NUM }; -struct carg -{ - int ch; - char *val; - LIST_ENTRY(carg) list; -}; - -LIST_HEAD(cargs, carg); - #define _DEF_DIRMODE (S_IRWXU | S_IRWXG | S_IRWXO) #define _PATH_PW_CONF "/etc/pw.conf" #define _UC_MAXLINE 1024 @@ -81,8 +72,6 @@ LIST_HEAD(cargs, carg); struct userconf *get_userconfig(const char *cfg); struct userconf *read_userconfig(char const * file); int write_userconfig(struct userconf *cnf, char const * file); -struct carg *addarg(struct cargs * _args, int ch, char *argstr); -struct carg *getarg(struct cargs * _args, int ch); int pw_group_add(int argc, char **argv, char *name); int pw_group_del(int argc, char **argv, char *name); -- cgit v1.2.3 From 4573132fd44c8bd71211a975ed21e9acbb58ca45 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Sun, 2 Aug 2015 13:22:46 +0000 Subject: Cleanup a bit includes --- pw/pw.h | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'pw/pw.h') diff --git a/pw/pw.h b/pw/pw.h index e1a3949..b389f12 100644 --- a/pw/pw.h +++ b/pw/pw.h @@ -26,23 +26,13 @@ * $FreeBSD$ */ +#include + #define _WITH_GETLINE +#include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "psdate.h" #include "pwupd.h" enum _mode -- cgit v1.2.3