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#ifndef _PWUPD_H_ 3020253Sjoerg#define _PWUPD_H_ 3120253Sjoerg 3220253Sjoerg#include <sys/types.h> 3320253Sjoerg#include <pwd.h> 3420253Sjoerg#include <grp.h> 3520253Sjoerg 3620253Sjoerg#include <sys/cdefs.h> 3720253Sjoerg 3856000Sdavidn#if defined(__FreeBSD__) 3956000Sdavidn#define RET_SETGRENT int 4056000Sdavidn#else 4156000Sdavidn#define RET_SETGRENT void 4256000Sdavidn#endif 4356000Sdavidn 4420253Sjoergenum updtype 4520253Sjoerg{ 4620253Sjoerg UPD_DELETE = -1, 4720253Sjoerg UPD_CREATE = 0, 4820253Sjoerg UPD_REPLACE = 1 4920253Sjoerg}; 5020253Sjoerg 5120253Sjoerg__BEGIN_DECLS 5299806Salfredint fileupdate(char const * fname, mode_t fm, char const * nline, char const * pfx, int pfxlen, int updmode); 5320253Sjoerg__END_DECLS 5420253Sjoerg 5520253Sjoergenum pwdfmttype 5620253Sjoerg{ 5720253Sjoerg PWF_STANDARD, /* MASTER format but with '*' as password */ 5820253Sjoerg PWF_PASSWD, /* V7 format */ 5920253Sjoerg PWF_GROUP = PWF_PASSWD, 6020253Sjoerg PWF_MASTER /* MASTER format with password */ 6120253Sjoerg}; 6220253Sjoerg 6344229Sdavidnstruct pwf 6444229Sdavidn{ 6544229Sdavidn int _altdir; 6644229Sdavidn void (*_setpwent)(void); 6744229Sdavidn void (*_endpwent)(void); 6844229Sdavidn struct passwd * (*_getpwent)(void); 6944229Sdavidn struct passwd * (*_getpwuid)(uid_t uid); 7044229Sdavidn struct passwd * (*_getpwnam)(const char * nam); 7144229Sdavidn int (*_pwdb)(char *arg, ...); 7256000Sdavidn RET_SETGRENT (*_setgrent)(void); 7344229Sdavidn void (*_endgrent)(void); 7444229Sdavidn struct group * (*_getgrent)(void); 7544229Sdavidn struct group * (*_getgrgid)(gid_t gid); 7644229Sdavidn struct group * (*_getgrnam)(const char * nam); 7744229Sdavidn int (*_grdb)(char *arg, ...); 7844229Sdavidn}; 7944229Sdavidn 8044229Sdavidnextern struct pwf PWF; 8144229Sdavidnextern struct pwf VPWF; 8244229Sdavidn 8344229Sdavidn#define SETPWENT() PWF._setpwent() 8444229Sdavidn#define ENDPWENT() PWF._endpwent() 8544229Sdavidn#define GETPWENT() PWF._getpwent() 8644229Sdavidn#define GETPWUID(uid) PWF._getpwuid(uid) 8744229Sdavidn#define GETPWNAM(nam) PWF._getpwnam(nam) 8844229Sdavidn#define PWDB(args) PWF._pwdb(args) 8944229Sdavidn 9044229Sdavidn#define SETGRENT() PWF._setgrent() 9144229Sdavidn#define ENDGRENT() PWF._endgrent() 9244229Sdavidn#define GETGRENT() PWF._getgrent() 9344229Sdavidn#define GETGRGID(gid) PWF._getgrgid(gid) 9444229Sdavidn#define GETGRNAM(nam) PWF._getgrnam(nam) 9544229Sdavidn#define GRDB(args) PWF._grdb(args) 9644229Sdavidn 9744229Sdavidn#define PWALTDIR() PWF._altdir 9844229Sdavidn#ifndef _PATH_PWD 9944229Sdavidn#define _PATH_PWD "/etc" 10044229Sdavidn#endif 10144229Sdavidn#ifndef _GROUP 10244229Sdavidn#define _GROUP "group" 10344229Sdavidn#endif 10444229Sdavidn#ifndef _PASSWD 10544229Sdavidn#define _PASSWD "passwd" 10644229Sdavidn#endif 10744229Sdavidn#ifndef _MASTERPASSWD 10844229Sdavidn#define _MASTERPASSWD "master.passwd" 10944229Sdavidn#endif 11044229Sdavidn#ifndef _GROUP 11144229Sdavidn#define _GROUP "group" 11244229Sdavidn#endif 11344229Sdavidn 11420253Sjoerg__BEGIN_DECLS 11599806Salfredint addpwent(struct passwd * pwd); 11699806Salfredint delpwent(struct passwd * pwd); 11799806Salfredint chgpwent(char const * login, struct passwd * pwd); 11899806Salfredint fmtpwent(char *buf, struct passwd * pwd); 11999806Salfredint fmtpwentry(char *buf, struct passwd * pwd, int type); 12020747Sdavidn 12199806Salfredint setpwdir(const char * dir); 12299806Salfredchar * getpwpath(char const * file); 12399806Salfredint pwdb(char *arg, ...); 12444229Sdavidn 12599806Salfredint addgrent(struct group * grp); 12699806Salfredint delgrent(struct group * grp); 12799806Salfredint chggrent(char const * name, struct group * grp); 12899806Salfredint fmtgrent(char **buf, int * buflen, struct group * grp); 12999806Salfredint fmtgrentry(char **buf, int * buflen, struct group * grp, int type); 13099806Salfredint editgroups(char *name, char **groups); 13120253Sjoerg 13299806Salfredint setgrdir(const char * dir); 13399806Salfredchar * getgrpath(const char *file); 13499806Salfredint grdb(char *arg, ...); 13520253Sjoerg 13699806Salfredvoid vsetpwent(void); 13799806Salfredvoid vendpwent(void); 13899806Salfredstruct passwd * vgetpwent(void); 13999806Salfredstruct passwd * vgetpwuid(uid_t uid); 14099806Salfredstruct passwd * vgetpwnam(const char * nam); 14199806Salfredstruct passwd * vgetpwent(void); 14299806Salfredint vpwdb(char *arg, ...); 14344229Sdavidn 14499806Salfredstruct group * vgetgrent(void); 14599806Salfredstruct group * vgetgrgid(gid_t gid); 14699806Salfredstruct group * vgetgrnam(const char * nam); 14799806Salfredstruct group * vgetgrent(void); 14899806Salfredint vgrdb(char *arg, ...); 14999806SalfredRET_SETGRENT vsetgrent(void); 15099806Salfredvoid vendgrent(void); 15144229Sdavidn 15299806Salfredvoid copymkdir(char const * dir, char const * skel, mode_t mode, uid_t uid, gid_t gid); 15399806Salfredvoid rm_r(char const * dir, uid_t uid); 15499806Salfredint extendline(char **buf, int *buflen, int needed); 15599806Salfredint extendarray(char ***buf, int *buflen, int needed); 15620253Sjoerg__END_DECLS 15720253Sjoerg 15844229Sdavidn#define PWBUFSZ 1024 15944229Sdavidn 16020253Sjoerg#endif /* !_PWUPD_H */ 161