xref: /freebsd/usr.sbin/pw/pwupd.h (revision cbd30a72ca196976c1c700400ecd424baa1b9c16)
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$
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 #include <stringlist.h>
40 
41 struct pwf {
42 	int		    _altdir;
43 	void		  (*_setpwent)(void);
44 	void		  (*_endpwent)(void);
45 	struct passwd * (*_getpwent)(void);
46 	struct passwd	* (*_getpwuid)(uid_t uid);
47 	struct passwd	* (*_getpwnam)(const char * nam);
48 	void		  (*_setgrent)(void);
49 	void		  (*_endgrent)(void);
50 	struct group  * (*_getgrent)(void);
51 	struct group  * (*_getgrgid)(gid_t gid);
52 	struct group  * (*_getgrnam)(const char * nam);
53 };
54 
55 struct userconf {
56 	int		default_password;	/* Default password for new users? */
57 	int		reuse_uids;		/* Reuse uids? */
58 	int		reuse_gids;		/* Reuse gids? */
59 	char		*nispasswd;		/* Path to NIS version of the passwd file */
60 	char		*dotdir;		/* Where to obtain skeleton files */
61 	char		*newmail;		/* Mail to send to new accounts */
62 	char		*logfile;		/* Where to log changes */
63 	char		*home;			/* Where to create home directory */
64 	mode_t		homemode;		/* Home directory permissions */
65 	char		*shelldir;		/* Where shells are located */
66 	char		**shells;		/* List of shells */
67 	char		*shell_default;		/* Default shell */
68 	char		*default_group;		/* Default group number */
69 	StringList	*groups;		/* Default (additional) groups */
70 	char		*default_class;		/* Default user class */
71 	uid_t		min_uid, max_uid;	/* Allowed range of uids */
72 	gid_t		min_gid, max_gid;	/* Allowed range of gids */
73 	time_t		expire_days;		/* Days to expiry */
74 	time_t		password_days;		/* Days to password expiry */
75 };
76 
77 struct pwconf {
78 	char		 rootdir[MAXPATHLEN];
79 	char		 etcpath[MAXPATHLEN];
80 	int		 fd;
81 	int		 rootfd;
82 	bool		 checkduplicate;
83 };
84 
85 extern struct pwf PWF;
86 extern struct pwf VPWF;
87 extern struct pwconf conf;
88 
89 #define SETPWENT()	PWF._setpwent()
90 #define ENDPWENT()	PWF._endpwent()
91 #define GETPWENT()	PWF._getpwent()
92 #define GETPWUID(uid)	PWF._getpwuid(uid)
93 #define GETPWNAM(nam)	PWF._getpwnam(nam)
94 
95 #define SETGRENT()	PWF._setgrent()
96 #define ENDGRENT()	PWF._endgrent()
97 #define GETGRENT()	PWF._getgrent()
98 #define GETGRGID(gid)	PWF._getgrgid(gid)
99 #define GETGRNAM(nam)	PWF._getgrnam(nam)
100 
101 #define PWF_REGULAR 0
102 #define PWF_ALT 1
103 #define PWF_ROOTDIR 2
104 
105 #define PWALTDIR()	PWF._altdir
106 #ifndef _PATH_PWD
107 #define _PATH_PWD	"/etc"
108 #endif
109 #ifndef _GROUP
110 #define _GROUP		"group"
111 #endif
112 #ifndef _MASTERPASSWD
113 #define _MASTERPASSWD	"master.passwd"
114 #endif
115 
116 __BEGIN_DECLS
117 int addpwent(struct passwd * pwd);
118 int delpwent(struct passwd * pwd);
119 int chgpwent(char const * login, struct passwd * pwd);
120 
121 char * getpwpath(char const * file);
122 
123 int addgrent(struct group * grp);
124 int delgrent(struct group * grp);
125 int chggrent(char const * name, struct group * grp);
126 
127 char * getgrpath(const char *file);
128 
129 void vsetpwent(void);
130 void vendpwent(void);
131 struct passwd * vgetpwent(void);
132 struct passwd * vgetpwuid(uid_t uid);
133 struct passwd * vgetpwnam(const char * nam);
134 
135 struct group * vgetgrent(void);
136 struct group * vgetgrgid(gid_t gid);
137 struct group * vgetgrnam(const char * nam);
138 void           vsetgrent(void);
139 void           vendgrent(void);
140 
141 void copymkdir(int rootfd, char const * dir, int skelfd, mode_t mode, uid_t uid,
142     gid_t gid, int flags);
143 void rm_r(int rootfd, char const * dir, uid_t uid);
144 __END_DECLS
145 
146 #endif				/* !_PWUPD_H */
147