pw.h revision 20267
178064Sume/*- 262638Skris * Copyright (c) 1996 by David L. Nugent <davidn@blaze.net.au>. 355505Sshin * All rights reserved. 455505Sshin * 555505Sshin * Redistribution and use in source and binary forms, with or without 655505Sshin * modification, are permitted provided that the following conditions 755505Sshin * are met: 855505Sshin * 1. Redistributions of source code must retain the above copyright 955505Sshin * notice, this list of conditions and the following disclaimer as 1055505Sshin * the first lines of this file unmodified. 1155505Sshin * 2. Redistributions in binary form must reproduce the above copyright 1255505Sshin * notice, this list of conditions and the following disclaimer in the 1355505Sshin * documentation and/or other materials provided with the distribution. 1455505Sshin * 3. All advertising materials mentioning features or use of this software 1555505Sshin * must display the following acknowledgement: 1655505Sshin * This product includes software developed by David L. Nugent. 1755505Sshin * 4. The name of the author may not be used to endorse or promote products 1855505Sshin * derived from this software without specific prior written permission. 1955505Sshin * 2055505Sshin * THIS SOFTWARE IS PROVIDED BY THE DAVID L. NUGENT ``AS IS'' AND 2155505Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2255505Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2355505Sshin * ARE DISCLAIMED. IN NO EVENT SHALL DAVID L. NUGENT BE LIABLE 2455505Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2555505Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2655505Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2755505Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2855505Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2955505Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3055505Sshin * SUCH DAMAGE. 3155505Sshin * 3255505Sshin * $Id$ 3355505Sshin */ 3455505Sshin 3555505Sshin#include <stdio.h> 3655505Sshin#include <stdlib.h> 3755505Sshin#include <string.h> 3878064Sume#include <unistd.h> 3955505Sshin#include <stdarg.h> 4055505Sshin#include <errno.h> 4155505Sshin#include <sys/types.h> 4255505Sshin#include <sys/stat.h> 4362638Skris#include <pwd.h> 4455505Sshin#include <grp.h> 4562638Skris#include <sys/queue.h> 4655505Sshin#include <sysexits.h> 4755505Sshin 4855505Sshin#include "psdate.h" 4955505Sshin 5062638Skrisenum _mode 5162638Skris{ 5262638Skris M_ADD, 5355505Sshin M_DELETE, 5455505Sshin M_UPDATE, 5555505Sshin M_PRINT, 5655505Sshin M_NEXT, 5762638Skris M_NUM 5855505Sshin}; 5978064Sume 60173412Skevloenum _which 61173412Skevlo{ 62173412Skevlo W_USER, 6355505Sshin W_GROUP, 6455505Sshin W_NUM 65250227Sjkim}; 66250227Sjkim 6755505Sshinstruct carg 6855505Sshin{ 6955505Sshin int ch; 7055505Sshin char *val; 7155505Sshin LIST_ENTRY(carg) list; 7255505Sshin}; 7355505Sshin 7455505Sshinextern LIST_HEAD(cargs, carg) arglist; 7555505Sshin 7655505Sshinstruct userconf 7755505Sshin{ 7855505Sshin int default_password; /* Default password for new users? */ 7955505Sshin int reuse_uids; /* Reuse uids? */ 8055505Sshin int reuse_gids; /* Reuse gids? */ 8155505Sshin char *dotdir; /* Where to obtain skeleton files */ 8255505Sshin char *newmail; /* Mail to send to new accounts */ 8355505Sshin char *logfile; /* Where to log changes */ 8455505Sshin char *home; /* Where to create home directory */ 8555505Sshin char *shelldir; /* Where shells are located */ 8655505Sshin char **shells; /* List of shells */ 8755505Sshin char *shell_default; /* Default shell */ 8855505Sshin char *default_group; /* Default group number */ 8955505Sshin char **groups; /* Default (additional) groups */ 9055505Sshin char *default_class; /* Default user class */ 9155505Sshin uid_t min_uid, max_uid; /* Allowed range of uids */ 9255505Sshin gid_t min_gid, max_gid; /* Allowed range of gids */ 9355505Sshin int expire_days; /* Days to expiry */ 9455505Sshin int password_days; /* Days to password expiry */ 9555505Sshin}; 9655505Sshin 9755505Sshin#define _PATH_PW_CONF "/etc/pw.conf" 9855505Sshin#define _UC_MAXLINE 1024 9955505Sshin#define _UC_MAXSHELLS 32 10055505Sshin#define _UC_MAXGROUPS 200 10155505Sshin 10255505Sshinstruct userconf *read_userconfig(char const * file); 10355505Sshinint write_userconfig(char const * file); 10455505Sshinstruct carg *addarg(struct cargs * _args, int ch, char *argstr); 10555505Sshinstruct carg *getarg(struct cargs * _args, int ch); 10655505Sshinvoid cmderr(int ec, char const * fmt,...); 10755505Sshin 10855505Sshinint pw_user(struct userconf * cnf, int mode, struct cargs * _args); 10955505Sshinint pw_group(struct userconf * cnf, int mode, struct cargs * _args); 11055505Sshin 11155505Sshinint addpwent(struct passwd * pwd); 11255505Sshinint delpwent(struct passwd * pwd); 11355505Sshinint chgpwent(char const * login, struct passwd * pwd); 11455505Sshinint fmtpwent(char *buf, struct passwd * pwd); 11555505Sshin 11655505Sshinint addgrent(struct group * grp); 11755505Sshinint delgrent(struct group * grp); 11855505Sshinint chggrent(char const * login, struct group * grp); 11955505Sshinint fmtgrent(char *buf, struct group * grp); 12055505Sshin 12155505Sshinint boolean_val(char const * str, int dflt); 12255505Sshinchar const *boolean_str(int val); 12355505Sshinchar *newstr(char const * p); 12455505Sshin 12555505Sshinvoid pw_log(struct userconf * cnf, int mode, int which, char const * fmt,...); 12655505Sshinchar *pw_pwcrypt(char *password); 12755505Sshin 12855505Sshinextern const char *Modes[]; 12955505Sshinextern const char *Which[]; 13055505Sshin