#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdarg.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <pwd.h>
#include <grp.h>
#include <sys/queue.h>
#include <sysexits.h>
#include "psdate.h"
#include "pwupd.h"
enum _mode
{
M_ADD,
M_DELETE,
M_UPDATE,
M_PRINT,
M_NEXT,
M_LOCK,
M_UNLOCK,
M_NUM
};
enum _which
{
W_USER,
W_GROUP,
W_NUM
};
struct carg
{
int ch;
char *val;
LIST_ENTRY(carg) list;
};
LIST_HEAD(cargs, carg);
struct userconf
{
int default_password;
int reuse_uids;
int reuse_gids;
char *nispasswd;
char *dotdir;
char *newmail;
char *logfile;
char *home;
mode_t homemode;
char *shelldir;
char **shells;
char *shell_default;
char *default_group;
char **groups;
char *default_class;
uid_t min_uid, max_uid;
gid_t min_gid, max_gid;
int expire_days;
int password_days;
int numgroups;
};
#define _DEF_DIRMODE (S_IRWXU | S_IRWXG | S_IRWXO)
#define _PATH_PW_CONF "/etc/pw.conf"
#define _UC_MAXLINE 1024
#define _UC_MAXSHELLS 32
struct userconf *read_userconfig(char const * file);
int write_userconfig(char const * file);
struct carg *addarg(struct cargs * _args, int ch, char *argstr);
struct carg *getarg(struct cargs * _args, int ch);
int pw_user(struct userconf * cnf, int mode, struct cargs * _args);
int pw_group(struct userconf * cnf, int mode, struct cargs * _args);
char *pw_checkname(u_char *name, int gecos);
int addpwent(struct passwd * pwd);
int delpwent(struct passwd * pwd);
int chgpwent(char const * login, struct passwd * pwd);
int fmtpwent(char *buf, struct passwd * pwd);
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 addgrent(struct group * grp);
int delgrent(struct group * grp);
int chggrent(char const * login, struct group * grp);
int boolean_val(char const * str, int dflt);
char const *boolean_str(int val);
char *newstr(char const * p);
void pw_log(struct userconf * cnf, int mode, int which, char const * fmt,...) __printflike(4, 5);
char *pw_pwcrypt(char *password);
extern const char *Modes[];
extern const char *Which[];