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: releng/11.0/usr.sbin/pw/pwupd.h 286196 2015-08-02 12:47:50Z bapt $ 2720253Sjoerg */ 2820253Sjoerg 2920253Sjoerg#ifndef _PWUPD_H_ 3020253Sjoerg#define _PWUPD_H_ 3120253Sjoerg 32284120Sbapt#include <sys/cdefs.h> 33284118Sbapt#include <sys/param.h> 3420253Sjoerg#include <sys/types.h> 35284120Sbapt 3620253Sjoerg#include <pwd.h> 3720253Sjoerg#include <grp.h> 38284121Sbapt#include <stdbool.h> 39285412Sbapt#include <stringlist.h> 4020253Sjoerg 4156000Sdavidn#if defined(__FreeBSD__) 4256000Sdavidn#define RET_SETGRENT int 4356000Sdavidn#else 4456000Sdavidn#define RET_SETGRENT void 4556000Sdavidn#endif 4656000Sdavidn 47284118Sbaptstruct pwf { 4844229Sdavidn int _altdir; 4944229Sdavidn void (*_setpwent)(void); 5044229Sdavidn void (*_endpwent)(void); 5144229Sdavidn struct passwd * (*_getpwent)(void); 5244229Sdavidn struct passwd * (*_getpwuid)(uid_t uid); 5344229Sdavidn struct passwd * (*_getpwnam)(const char * nam); 5456000Sdavidn RET_SETGRENT (*_setgrent)(void); 5544229Sdavidn void (*_endgrent)(void); 5644229Sdavidn struct group * (*_getgrent)(void); 5744229Sdavidn struct group * (*_getgrgid)(gid_t gid); 5844229Sdavidn struct group * (*_getgrnam)(const char * nam); 5944229Sdavidn}; 6044229Sdavidn 61284118Sbaptstruct userconf { 62285412Sbapt int default_password; /* Default password for new users? */ 63285412Sbapt int reuse_uids; /* Reuse uids? */ 64285412Sbapt int reuse_gids; /* Reuse gids? */ 65285412Sbapt char *nispasswd; /* Path to NIS version of the passwd file */ 66285412Sbapt char *dotdir; /* Where to obtain skeleton files */ 67285412Sbapt char *newmail; /* Mail to send to new accounts */ 68285412Sbapt char *logfile; /* Where to log changes */ 69285412Sbapt char *home; /* Where to create home directory */ 70285412Sbapt mode_t homemode; /* Home directory permissions */ 71285412Sbapt char *shelldir; /* Where shells are located */ 72285412Sbapt char **shells; /* List of shells */ 73285412Sbapt char *shell_default; /* Default shell */ 74285412Sbapt char *default_group; /* Default group number */ 75285412Sbapt StringList *groups; /* Default (additional) groups */ 76285412Sbapt char *default_class; /* Default user class */ 77285412Sbapt uid_t min_uid, max_uid; /* Allowed range of uids */ 78285412Sbapt gid_t min_gid, max_gid; /* Allowed range of gids */ 79286196Sbapt time_t expire_days; /* Days to expiry */ 80286196Sbapt time_t password_days; /* Days to password expiry */ 81284118Sbapt}; 82284118Sbapt 83284118Sbaptstruct pwconf { 84284118Sbapt char rootdir[MAXPATHLEN]; 85284118Sbapt char etcpath[MAXPATHLEN]; 86285133Sbapt int fd; 87285430Sbapt int rootfd; 88284133Sbapt bool checkduplicate; 89284118Sbapt}; 90284118Sbapt 9144229Sdavidnextern struct pwf PWF; 9244229Sdavidnextern struct pwf VPWF; 93284118Sbaptextern struct pwconf conf; 9444229Sdavidn 9544229Sdavidn#define SETPWENT() PWF._setpwent() 9644229Sdavidn#define ENDPWENT() PWF._endpwent() 9744229Sdavidn#define GETPWENT() PWF._getpwent() 9844229Sdavidn#define GETPWUID(uid) PWF._getpwuid(uid) 9944229Sdavidn#define GETPWNAM(nam) PWF._getpwnam(nam) 10044229Sdavidn 10144229Sdavidn#define SETGRENT() PWF._setgrent() 10244229Sdavidn#define ENDGRENT() PWF._endgrent() 10344229Sdavidn#define GETGRENT() PWF._getgrent() 10444229Sdavidn#define GETGRGID(gid) PWF._getgrgid(gid) 10544229Sdavidn#define GETGRNAM(nam) PWF._getgrnam(nam) 10644229Sdavidn 107283961Sbapt#define PWF_REGULAR 0 108283961Sbapt#define PWF_ALT 1 109283961Sbapt#define PWF_ROOTDIR 2 110283961Sbapt 11144229Sdavidn#define PWALTDIR() PWF._altdir 11244229Sdavidn#ifndef _PATH_PWD 11344229Sdavidn#define _PATH_PWD "/etc" 11444229Sdavidn#endif 11544229Sdavidn#ifndef _GROUP 11644229Sdavidn#define _GROUP "group" 11744229Sdavidn#endif 11844229Sdavidn#ifndef _MASTERPASSWD 11944229Sdavidn#define _MASTERPASSWD "master.passwd" 12044229Sdavidn#endif 12144229Sdavidn 12220253Sjoerg__BEGIN_DECLS 12399806Salfredint addpwent(struct passwd * pwd); 12499806Salfredint delpwent(struct passwd * pwd); 12599806Salfredint chgpwent(char const * login, struct passwd * pwd); 12620747Sdavidn 12799806Salfredchar * getpwpath(char const * file); 12844229Sdavidn 12999806Salfredint addgrent(struct group * grp); 13099806Salfredint delgrent(struct group * grp); 13199806Salfredint chggrent(char const * name, struct group * grp); 13220253Sjoerg 13399806Salfredchar * getgrpath(const char *file); 13420253Sjoerg 13599806Salfredvoid vsetpwent(void); 13699806Salfredvoid vendpwent(void); 13799806Salfredstruct passwd * vgetpwent(void); 13899806Salfredstruct passwd * vgetpwuid(uid_t uid); 13999806Salfredstruct passwd * vgetpwnam(const char * nam); 14044229Sdavidn 14199806Salfredstruct group * vgetgrent(void); 14299806Salfredstruct group * vgetgrgid(gid_t gid); 14399806Salfredstruct group * vgetgrnam(const char * nam); 14499806SalfredRET_SETGRENT vsetgrent(void); 14599806Salfredvoid vendgrent(void); 14644229Sdavidn 147285430Sbaptvoid copymkdir(int rootfd, char const * dir, int skelfd, mode_t mode, uid_t uid, 148285430Sbapt gid_t gid, int flags); 149285433Sbaptvoid rm_r(int rootfd, char const * dir, uid_t uid); 15020253Sjoerg__END_DECLS 15120253Sjoerg 15220253Sjoerg#endif /* !_PWUPD_H */ 153