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