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