120253Sjoerg/*- 220302Sjoerg * Copyright (C) 1996 320302Sjoerg * David L. Nugent. 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 920302Sjoerg * notice, this list of conditions and the following disclaimer. 1020253Sjoerg * 2. Redistributions in binary form must reproduce the above copyright 1120253Sjoerg * notice, this list of conditions and the following disclaimer in the 1220253Sjoerg * documentation and/or other materials provided with the distribution. 1320253Sjoerg * 1420302Sjoerg * THIS SOFTWARE IS PROVIDED BY DAVID L. NUGENT AND CONTRIBUTORS ``AS IS'' AND 1520253Sjoerg * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1620253Sjoerg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1720302Sjoerg * ARE DISCLAIMED. IN NO EVENT SHALL DAVID L. NUGENT OR CONTRIBUTORS BE LIABLE 1820253Sjoerg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1920253Sjoerg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2020253Sjoerg * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2120253Sjoerg * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2220253Sjoerg * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2320253Sjoerg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2420253Sjoerg * SUCH DAMAGE. 2520253Sjoerg * 2650479Speter * $FreeBSD$ 2720253Sjoerg */ 2820253Sjoerg 2920253Sjoerg#include <stdio.h> 3020253Sjoerg#include <stdlib.h> 3120253Sjoerg#include <string.h> 3220253Sjoerg#include <unistd.h> 3320253Sjoerg#include <stdarg.h> 3420253Sjoerg#include <errno.h> 3520253Sjoerg#include <sys/types.h> 3620253Sjoerg#include <sys/stat.h> 3744229Sdavidn#include <sys/param.h> 3820253Sjoerg#include <pwd.h> 3920253Sjoerg#include <grp.h> 4020253Sjoerg#include <sys/queue.h> 4120267Sjoerg#include <sysexits.h> 4220253Sjoerg 4320253Sjoerg#include "psdate.h" 4444229Sdavidn#include "pwupd.h" 4520253Sjoerg 4620253Sjoergenum _mode 4720253Sjoerg{ 4820253Sjoerg M_ADD, 4920253Sjoerg M_DELETE, 5020253Sjoerg M_UPDATE, 5120253Sjoerg M_PRINT, 5220267Sjoerg M_NEXT, 5352512Sdavidn M_LOCK, 5452512Sdavidn M_UNLOCK, 5520253Sjoerg M_NUM 5620253Sjoerg}; 5720253Sjoerg 5820253Sjoergenum _which 5920253Sjoerg{ 6020253Sjoerg W_USER, 6120253Sjoerg W_GROUP, 6220253Sjoerg W_NUM 6320253Sjoerg}; 6420253Sjoerg 6520253Sjoergstruct carg 6620253Sjoerg{ 6720253Sjoerg int ch; 6820253Sjoerg char *val; 6960938Sjake LIST_ENTRY(carg) list; 7020253Sjoerg}; 7120253Sjoerg 72141608SstefanfLIST_HEAD(cargs, carg); 7320253Sjoerg 7420253Sjoergstruct userconf 7520253Sjoerg{ 7620253Sjoerg int default_password; /* Default password for new users? */ 7720253Sjoerg int reuse_uids; /* Reuse uids? */ 7820253Sjoerg int reuse_gids; /* Reuse gids? */ 7921330Sdavidn char *nispasswd; /* Path to NIS version of the passwd file */ 8020253Sjoerg char *dotdir; /* Where to obtain skeleton files */ 8120253Sjoerg char *newmail; /* Mail to send to new accounts */ 8220253Sjoerg char *logfile; /* Where to log changes */ 8320253Sjoerg char *home; /* Where to create home directory */ 84168044Sle mode_t homemode; /* Home directory permissions */ 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 */ 9520747Sdavidn int numgroups; /* (internal) size of default_group array */ 9620253Sjoerg}; 9720253Sjoerg 98219408Sjkim#define _DEF_DIRMODE (S_IRWXU | S_IRWXG | S_IRWXO) 9920253Sjoerg#define _PATH_PW_CONF "/etc/pw.conf" 10020253Sjoerg#define _UC_MAXLINE 1024 10120253Sjoerg#define _UC_MAXSHELLS 32 10220253Sjoerg 10320253Sjoergstruct userconf *read_userconfig(char const * file); 10420253Sjoergint write_userconfig(char const * file); 10520253Sjoergstruct carg *addarg(struct cargs * _args, int ch, char *argstr); 10620253Sjoergstruct carg *getarg(struct cargs * _args, int ch); 10720253Sjoerg 10820253Sjoergint pw_user(struct userconf * cnf, int mode, struct cargs * _args); 10920253Sjoergint pw_group(struct userconf * cnf, int mode, struct cargs * _args); 11020679Sdavidnchar *pw_checkname(u_char *name, int gecos); 11120253Sjoerg 11220253Sjoergint addpwent(struct passwd * pwd); 11320253Sjoergint delpwent(struct passwd * pwd); 11420253Sjoergint chgpwent(char const * login, struct passwd * pwd); 11520253Sjoergint fmtpwent(char *buf, struct passwd * pwd); 11620253Sjoerg 11721330Sdavidnint addnispwent(const char *path, struct passwd *pwd); 11821330Sdavidnint delnispwent(const char *path, const char *login); 11921330Sdavidnint chgnispwent(const char *path, const char *login, struct passwd *pwd); 12021330Sdavidn 12120253Sjoergint addgrent(struct group * grp); 12220253Sjoergint delgrent(struct group * grp); 12320253Sjoergint chggrent(char const * login, struct group * grp); 12420253Sjoerg 12520253Sjoergint boolean_val(char const * str, int dflt); 12620253Sjoergchar const *boolean_str(int val); 12720253Sjoergchar *newstr(char const * p); 12820253Sjoerg 12979292Skrisvoid pw_log(struct userconf * cnf, int mode, int which, char const * fmt,...) __printflike(4, 5); 13020253Sjoergchar *pw_pwcrypt(char *password); 13120253Sjoerg 13220253Sjoergextern const char *Modes[]; 13320253Sjoergextern const char *Which[]; 134