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/10.3/usr.sbin/pw/pwupd.h 287084 2015-08-23 21:42:27Z bapt $ 2720253Sjoerg */ 2820253Sjoerg 2920253Sjoerg#ifndef _PWUPD_H_ 3020253Sjoerg#define _PWUPD_H_ 3120253Sjoerg 32285092Sbapt#include <sys/cdefs.h> 33285092Sbapt#include <sys/param.h> 3420253Sjoerg#include <sys/types.h> 35285092Sbapt 3620253Sjoerg#include <pwd.h> 3720253Sjoerg#include <grp.h> 38285092Sbapt#include <stdbool.h> 39287084Sbapt#include <stringlist.h> 4020253Sjoerg 4156000Sdavidn#if defined(__FreeBSD__) 4256000Sdavidn#define RET_SETGRENT int 4356000Sdavidn#else 4456000Sdavidn#define RET_SETGRENT void 4556000Sdavidn#endif 4656000Sdavidn 47285092Sbaptstruct 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 61285092Sbaptstruct userconf { 62287084Sbapt int default_password; /* Default password for new users? */ 63287084Sbapt int reuse_uids; /* Reuse uids? */ 64287084Sbapt int reuse_gids; /* Reuse gids? */ 65287084Sbapt char *nispasswd; /* Path to NIS version of the passwd file */ 66287084Sbapt char *dotdir; /* Where to obtain skeleton files */ 67287084Sbapt char *newmail; /* Mail to send to new accounts */ 68287084Sbapt char *logfile; /* Where to log changes */ 69287084Sbapt char *home; /* Where to create home directory */ 70287084Sbapt mode_t homemode; /* Home directory permissions */ 71287084Sbapt char *shelldir; /* Where shells are located */ 72287084Sbapt char **shells; /* List of shells */ 73287084Sbapt char *shell_default; /* Default shell */ 74287084Sbapt char *default_group; /* Default group number */ 75287084Sbapt StringList *groups; /* Default (additional) groups */ 76287084Sbapt char *default_class; /* Default user class */ 77287084Sbapt uid_t min_uid, max_uid; /* Allowed range of uids */ 78287084Sbapt gid_t min_gid, max_gid; /* Allowed range of gids */ 79287084Sbapt time_t expire_days; /* Days to expiry */ 80287084Sbapt time_t password_days; /* Days to password expiry */ 81285092Sbapt}; 82285092Sbapt 83285092Sbaptstruct pwconf { 84285092Sbapt char rootdir[MAXPATHLEN]; 85285092Sbapt char etcpath[MAXPATHLEN]; 86287084Sbapt int fd; 87287084Sbapt int rootfd; 88285092Sbapt bool checkduplicate; 89285092Sbapt}; 90285092Sbapt 9144229Sdavidnextern struct pwf PWF; 9244229Sdavidnextern struct pwf VPWF; 93285092Sbaptextern 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 107285092Sbapt#define PWF_REGULAR 0 108285092Sbapt#define PWF_ALT 1 109285092Sbapt#define PWF_ROOTDIR 2 110285092Sbapt 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 147287084Sbaptvoid copymkdir(int rootfd, char const * dir, int skelfd, mode_t mode, uid_t uid, 148287084Sbapt gid_t gid, int flags); 149287084Sbaptvoid rm_r(int rootfd, char const * dir, uid_t uid); 15020253Sjoerg__END_DECLS 15120253Sjoerg 15220253Sjoerg#endif /* !_PWUPD_H */ 153