pwupd.h revision 283961
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: head/usr.sbin/pw/pwupd.h 283961 2015-06-03 19:08:25Z bapt $
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
4444229Sdavidnstruct pwf
4544229Sdavidn{
4644229Sdavidn	int		    _altdir;
4744229Sdavidn	void		  (*_setpwent)(void);
4844229Sdavidn	void		  (*_endpwent)(void);
4944229Sdavidn	struct passwd * (*_getpwent)(void);
5044229Sdavidn	struct passwd	* (*_getpwuid)(uid_t uid);
5144229Sdavidn	struct passwd	* (*_getpwnam)(const char * nam);
5256000Sdavidn	RET_SETGRENT	  (*_setgrent)(void);
5344229Sdavidn	void		  (*_endgrent)(void);
5444229Sdavidn	struct group  * (*_getgrent)(void);
5544229Sdavidn	struct group  * (*_getgrgid)(gid_t gid);
5644229Sdavidn	struct group  * (*_getgrnam)(const char * nam);
5744229Sdavidn};
5844229Sdavidn
5944229Sdavidnextern struct pwf PWF;
6044229Sdavidnextern struct pwf VPWF;
6144229Sdavidn
6244229Sdavidn#define SETPWENT()	PWF._setpwent()
6344229Sdavidn#define ENDPWENT()	PWF._endpwent()
6444229Sdavidn#define GETPWENT()	PWF._getpwent()
6544229Sdavidn#define GETPWUID(uid)	PWF._getpwuid(uid)
6644229Sdavidn#define GETPWNAM(nam)	PWF._getpwnam(nam)
6744229Sdavidn
6844229Sdavidn#define SETGRENT()	PWF._setgrent()
6944229Sdavidn#define ENDGRENT()	PWF._endgrent()
7044229Sdavidn#define GETGRENT()	PWF._getgrent()
7144229Sdavidn#define GETGRGID(gid)	PWF._getgrgid(gid)
7244229Sdavidn#define GETGRNAM(nam)	PWF._getgrnam(nam)
7344229Sdavidn
74283961Sbapt#define PWF_REGULAR 0
75283961Sbapt#define PWF_ALT 1
76283961Sbapt#define PWF_ROOTDIR 2
77283961Sbapt
7844229Sdavidn#define PWALTDIR()	PWF._altdir
7944229Sdavidn#ifndef _PATH_PWD
8044229Sdavidn#define _PATH_PWD	"/etc"
8144229Sdavidn#endif
8244229Sdavidn#ifndef _GROUP
8344229Sdavidn#define _GROUP		"group"
8444229Sdavidn#endif
8544229Sdavidn#ifndef _MASTERPASSWD
8644229Sdavidn#define _MASTERPASSWD	"master.passwd"
8744229Sdavidn#endif
8844229Sdavidn
8920253Sjoerg__BEGIN_DECLS
9099806Salfredint addpwent(struct passwd * pwd);
9199806Salfredint delpwent(struct passwd * pwd);
9299806Salfredint chgpwent(char const * login, struct passwd * pwd);
9320747Sdavidn
9499806Salfredint setpwdir(const char * dir);
9599806Salfredchar * getpwpath(char const * file);
9644229Sdavidn
9799806Salfredint addgrent(struct group * grp);
9899806Salfredint delgrent(struct group * grp);
9999806Salfredint chggrent(char const * name, struct group * grp);
10020253Sjoerg
10199806Salfredint setgrdir(const char * dir);
10299806Salfredchar * getgrpath(const char *file);
10320253Sjoerg
10499806Salfredvoid vsetpwent(void);
10599806Salfredvoid vendpwent(void);
10699806Salfredstruct passwd * vgetpwent(void);
10799806Salfredstruct passwd * vgetpwuid(uid_t uid);
10899806Salfredstruct passwd * vgetpwnam(const char * nam);
10944229Sdavidn
11099806Salfredstruct group * vgetgrent(void);
11199806Salfredstruct group * vgetgrgid(gid_t gid);
11299806Salfredstruct group * vgetgrnam(const char * nam);
11399806SalfredRET_SETGRENT   vsetgrent(void);
11499806Salfredvoid           vendgrent(void);
11544229Sdavidn
11699806Salfredvoid copymkdir(char const * dir, char const * skel, mode_t mode, uid_t uid, gid_t gid);
11799806Salfredvoid rm_r(char const * dir, uid_t uid);
11899806Salfredint extendarray(char ***buf, int *buflen, int needed);
11920253Sjoerg__END_DECLS
12020253Sjoerg
12120253Sjoerg#endif				/* !_PWUPD_H */
122