pw.h revision 20267
120253Sjoerg/*-
220253Sjoerg * Copyright (c) 1996 by David L. Nugent <davidn@blaze.net.au>.
320253Sjoerg * All rights reserved.
420253Sjoerg *
520253Sjoerg * Redistribution and use in source and binary forms, with or without
620253Sjoerg * modification, are permitted provided that the following conditions
720253Sjoerg * are met:
820253Sjoerg * 1. Redistributions of source code must retain the above copyright
920253Sjoerg *    notice, this list of conditions and the following disclaimer as
1020253Sjoerg *    the first lines of this file unmodified.
1120253Sjoerg * 2. Redistributions in binary form must reproduce the above copyright
1220253Sjoerg *    notice, this list of conditions and the following disclaimer in the
1320253Sjoerg *    documentation and/or other materials provided with the distribution.
1420253Sjoerg * 3. All advertising materials mentioning features or use of this software
1520253Sjoerg *    must display the following acknowledgement:
1620253Sjoerg *	This product includes software developed by David L. Nugent.
1720253Sjoerg * 4. The name of the author may not be used to endorse or promote products
1820253Sjoerg *    derived from this software without specific prior written permission.
1920253Sjoerg *
2020253Sjoerg * THIS SOFTWARE IS PROVIDED BY THE DAVID L. NUGENT ``AS IS'' AND
2120253Sjoerg * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2220253Sjoerg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2320253Sjoerg * ARE DISCLAIMED.  IN NO EVENT SHALL DAVID L. NUGENT BE LIABLE
2420253Sjoerg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2520253Sjoerg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2620253Sjoerg * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2720253Sjoerg * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2820253Sjoerg * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2920253Sjoerg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3020253Sjoerg * SUCH DAMAGE.
3120253Sjoerg *
3220253Sjoerg *	$Id$
3320253Sjoerg */
3420253Sjoerg
3520253Sjoerg#include <stdio.h>
3620253Sjoerg#include <stdlib.h>
3720253Sjoerg#include <string.h>
3820253Sjoerg#include <unistd.h>
3920253Sjoerg#include <stdarg.h>
4020253Sjoerg#include <errno.h>
4120253Sjoerg#include <sys/types.h>
4220253Sjoerg#include <sys/stat.h>
4320253Sjoerg#include <pwd.h>
4420253Sjoerg#include <grp.h>
4520253Sjoerg#include <sys/queue.h>
4620267Sjoerg#include <sysexits.h>
4720253Sjoerg
4820253Sjoerg#include "psdate.h"
4920253Sjoerg
5020253Sjoergenum _mode
5120253Sjoerg{
5220253Sjoerg        M_ADD,
5320253Sjoerg        M_DELETE,
5420253Sjoerg        M_UPDATE,
5520253Sjoerg        M_PRINT,
5620267Sjoerg	M_NEXT,
5720253Sjoerg        M_NUM
5820253Sjoerg};
5920253Sjoerg
6020253Sjoergenum _which
6120253Sjoerg{
6220253Sjoerg        W_USER,
6320253Sjoerg        W_GROUP,
6420253Sjoerg        W_NUM
6520253Sjoerg};
6620253Sjoerg
6720253Sjoergstruct carg
6820253Sjoerg{
6920253Sjoerg	int		  ch;
7020253Sjoerg	char		  *val;
7120253Sjoerg	LIST_ENTRY(carg)  list;
7220253Sjoerg};
7320253Sjoerg
7420253Sjoergextern LIST_HEAD(cargs, carg) arglist;
7520253Sjoerg
7620253Sjoergstruct userconf
7720253Sjoerg{
7820253Sjoerg	int	default_password;	/* Default password for new users? */
7920253Sjoerg	int	reuse_uids;		/* Reuse uids? */
8020253Sjoerg	int	reuse_gids;		/* Reuse gids? */
8120253Sjoerg	char	*dotdir;		/* Where to obtain skeleton files */
8220253Sjoerg	char	*newmail;		/* Mail to send to new accounts */
8320253Sjoerg	char	*logfile;		/* Where to log changes */
8420253Sjoerg	char	*home;			/* Where to create home directory */
8520253Sjoerg	char	*shelldir;		/* Where shells are located */
8620253Sjoerg	char	**shells;		/* List of shells */
8720253Sjoerg	char	*shell_default;		/* Default shell */
8820253Sjoerg	char	*default_group;		/* Default group number */
8920253Sjoerg	char	**groups;		/* Default (additional) groups */
9020253Sjoerg	char	*default_class;		/* Default user class */
9120253Sjoerg	uid_t	min_uid, max_uid;	/* Allowed range of uids */
9220253Sjoerg	gid_t	min_gid, max_gid;	/* Allowed range of gids */
9320253Sjoerg	int	expire_days;		/* Days to expiry */
9420253Sjoerg	int	password_days;		/* Days to password expiry */
9520253Sjoerg};
9620253Sjoerg
9720253Sjoerg#define _PATH_PW_CONF	"/etc/pw.conf"
9820253Sjoerg#define _UC_MAXLINE	1024
9920253Sjoerg#define _UC_MAXSHELLS	32
10020253Sjoerg#define _UC_MAXGROUPS	200
10120253Sjoerg
10220253Sjoergstruct userconf *read_userconfig(char const * file);
10320253Sjoergint write_userconfig(char const * file);
10420253Sjoergstruct carg *addarg(struct cargs * _args, int ch, char *argstr);
10520253Sjoergstruct carg *getarg(struct cargs * _args, int ch);
10620253Sjoergvoid cmderr(int ec, char const * fmt,...);
10720253Sjoerg
10820253Sjoergint pw_user(struct userconf * cnf, int mode, struct cargs * _args);
10920253Sjoergint pw_group(struct userconf * cnf, int mode, struct cargs * _args);
11020253Sjoerg
11120253Sjoergint addpwent(struct passwd * pwd);
11220253Sjoergint delpwent(struct passwd * pwd);
11320253Sjoergint chgpwent(char const * login, struct passwd * pwd);
11420253Sjoergint fmtpwent(char *buf, struct passwd * pwd);
11520253Sjoerg
11620253Sjoergint addgrent(struct group * grp);
11720253Sjoergint delgrent(struct group * grp);
11820253Sjoergint chggrent(char const * login, struct group * grp);
11920253Sjoergint fmtgrent(char *buf, struct group * grp);
12020253Sjoerg
12120253Sjoergint boolean_val(char const * str, int dflt);
12220253Sjoergchar const *boolean_str(int val);
12320253Sjoergchar *newstr(char const * p);
12420253Sjoerg
12520253Sjoergvoid pw_log(struct userconf * cnf, int mode, int which, char const * fmt,...);
12620253Sjoergchar *pw_pwcrypt(char *password);
12720253Sjoerg
12820253Sjoergextern const char *Modes[];
12920253Sjoergextern const char *Which[];
130