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