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