1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (C) 1996 5 * David L. Nugent. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY DAVID L. NUGENT AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL DAVID L. NUGENT OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #ifndef _PWUPD_H_ 30 #define _PWUPD_H_ 31 32 #include <sys/param.h> 33 #include <sys/types.h> 34 35 #include <pwd.h> 36 #include <grp.h> 37 #include <stdbool.h> 38 #include <stringlist.h> 39 40 struct pwf { 41 int _altdir; 42 void (*_setpwent)(void); 43 void (*_endpwent)(void); 44 struct passwd * (*_getpwent)(void); 45 struct passwd * (*_getpwuid)(uid_t uid); 46 struct passwd * (*_getpwnam)(const char * nam); 47 void (*_setgrent)(void); 48 void (*_endgrent)(void); 49 struct group * (*_getgrent)(void); 50 struct group * (*_getgrgid)(gid_t gid); 51 struct group * (*_getgrnam)(const char * nam); 52 }; 53 54 struct userconf { 55 int default_password; /* Default password for new users? */ 56 int reuse_uids; /* Reuse uids? */ 57 int reuse_gids; /* Reuse gids? */ 58 char *nispasswd; /* Path to NIS version of the passwd file */ 59 char *dotdir; /* Where to obtain skeleton files */ 60 char *newmail; /* Mail to send to new accounts */ 61 char *logfile; /* Where to log changes */ 62 char *home; /* Where to create home directory */ 63 mode_t homemode; /* Home directory permissions */ 64 char *shelldir; /* Where shells are located */ 65 char **shells; /* List of shells */ 66 char *shell_default; /* Default shell */ 67 char *default_group; /* Default group number */ 68 StringList *groups; /* Default (additional) groups */ 69 char *default_class; /* Default user class */ 70 uid_t min_uid, max_uid; /* Allowed range of uids */ 71 gid_t min_gid, max_gid; /* Allowed range of gids */ 72 time_t expire_days; /* Days to expiry */ 73 time_t password_days; /* Days to password expiry */ 74 }; 75 76 struct pwconf { 77 char rootdir[MAXPATHLEN]; 78 char etcpath[MAXPATHLEN]; 79 FILE *metalog; 80 int fd; 81 int rootfd; 82 bool altroot; 83 bool checkduplicate; 84 }; 85 86 extern struct pwf PWF; 87 extern struct pwf VPWF; 88 extern struct pwconf conf; 89 90 #define SETPWENT() PWF._setpwent() 91 #define ENDPWENT() PWF._endpwent() 92 #define GETPWENT() PWF._getpwent() 93 #define GETPWUID(uid) PWF._getpwuid(uid) 94 #define GETPWNAM(nam) PWF._getpwnam(nam) 95 96 #define SETGRENT() PWF._setgrent() 97 #define ENDGRENT() PWF._endgrent() 98 #define GETGRENT() PWF._getgrent() 99 #define GETGRGID(gid) PWF._getgrgid(gid) 100 #define GETGRNAM(nam) PWF._getgrnam(nam) 101 102 #define PWF_REGULAR 0 103 #define PWF_ALT 1 104 #define PWF_ROOTDIR 2 105 106 #define PWALTDIR() PWF._altdir 107 #ifndef _PATH_PWD 108 #define _PATH_PWD "/etc" 109 #endif 110 #ifndef _GROUP 111 #define _GROUP "group" 112 #endif 113 #ifndef _MASTERPASSWD 114 #define _MASTERPASSWD "master.passwd" 115 #endif 116 117 __BEGIN_DECLS 118 int addpwent(struct passwd * pwd); 119 int delpwent(struct passwd * pwd); 120 int chgpwent(char const * login, struct passwd * pwd); 121 122 char * getpwpath(char const * file); 123 124 int addgrent(struct group * grp); 125 int delgrent(struct group * grp); 126 int chggrent(char const * name, struct group * grp); 127 128 char * getgrpath(const char *file); 129 130 void vsetpwent(void); 131 void vendpwent(void); 132 struct passwd * vgetpwent(void); 133 struct passwd * vgetpwuid(uid_t uid); 134 struct passwd * vgetpwnam(const char * nam); 135 136 struct group * vgetgrent(void); 137 struct group * vgetgrgid(gid_t gid); 138 struct group * vgetgrnam(const char * nam); 139 void vsetgrent(void); 140 void vendgrent(void); 141 142 void copymkdir(int rootfd, char const * dir, int skelfd, mode_t mode, uid_t uid, 143 gid_t gid, int flags); 144 bool rm_r(int rootfd, char const * dir, uid_t uid); 145 __END_DECLS 146 147 #endif /* !_PWUPD_H */ 148