xref: /freebsd/include/pwd.h (revision b0d29bc47dba79f6f38e67eabadfb4b32ffd9390)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1989, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  * (c) UNIX System Laboratories, Inc.
7  * All or some portions of this file are derived from material licensed
8  * to the University of California by American Telephone and Telegraph
9  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10  * the permission of UNIX System Laboratories, Inc.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. Neither the name of the University nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  *	@(#)pwd.h	8.2 (Berkeley) 1/21/94
37  * $FreeBSD$
38  */
39 
40 #ifndef _PWD_H_
41 #define	_PWD_H_
42 
43 #include <sys/cdefs.h>
44 #include <sys/_types.h>
45 
46 #ifndef _GID_T_DECLARED
47 typedef	__gid_t		gid_t;
48 #define	_GID_T_DECLARED
49 #endif
50 
51 #ifndef _TIME_T_DECLARED
52 typedef	__time_t	time_t;
53 #define	_TIME_T_DECLARED
54 #endif
55 
56 #ifndef _UID_T_DECLARED
57 typedef	__uid_t		uid_t;
58 #define	_UID_T_DECLARED
59 #endif
60 
61 #ifndef _SIZE_T_DECLARED
62 typedef __size_t	size_t;
63 #define _SIZE_T_DECLARED
64 #endif
65 
66 #define _PATH_PWD		"/etc"
67 #define	_PATH_PASSWD		"/etc/passwd"
68 #define	_PASSWD			"passwd"
69 #define	_PATH_MASTERPASSWD	"/etc/master.passwd"
70 #define	_MASTERPASSWD		"master.passwd"
71 
72 #define	_PATH_MP_DB		"/etc/pwd.db"
73 #define	_MP_DB			"pwd.db"
74 #define	_PATH_SMP_DB		"/etc/spwd.db"
75 #define	_SMP_DB			"spwd.db"
76 
77 #define	_PATH_PWD_MKDB		"/usr/sbin/pwd_mkdb"
78 
79 /* Historically, the keys in _PATH_MP_DB/_PATH_SMP_DB had the format
80  * `1 octet tag | key', where the tag is one of the _PW_KEY* values
81  * listed below.  These values happen to be ASCII digits.  Starting
82  * with FreeBSD 5.1, the tag is now still a single octet, but the
83  * upper 4 bits are interpreted as a version.  Pre-FreeBSD 5.1 format
84  * entries are version `3' -- this conveniently results in the same
85  * key values as before.  The new, architecture-independent entries
86  * are version `4'.
87  * As it happens, some applications read the database directly.
88  * (Bad app, no cookie!)  Thus, we leave the _PW_KEY* symbols at their
89  * old pre-FreeBSD 5.1 values so these apps still work.  Consequently
90  * we have to muck around a bit more to get the correct, versioned
91  * tag, and that is what the _PW_VERSIONED macro is about.
92  */
93 
94 #define _PW_VERSION_MASK	'\xF0'
95 #define _PW_VERSIONED(x, v)	((unsigned char)(((x) & 0xCF) | ((v)<<4)))
96 
97 #define	_PW_KEYBYNAME		'\x31'	/* stored by name */
98 #define	_PW_KEYBYNUM		'\x32'	/* stored by entry in the "file" */
99 #define	_PW_KEYBYUID		'\x33'	/* stored by uid */
100 #define _PW_KEYYPENABLED	'\x34'	/* YP is enabled */
101 #define	_PW_KEYYPBYNUM		'\x35'	/* special +@netgroup entries */
102 
103 /* The database also contains a key to indicate the format version of
104  * the entries therein.  There may be other, older versioned entries
105  * as well.
106  */
107 #define _PWD_VERSION_KEY	"\xFF" "VERSION"
108 #define _PWD_CURRENT_VERSION	'\x04'
109 
110 #define	_PASSWORD_EFMT1		'_'	/* extended encryption format */
111 
112 #define	_PASSWORD_LEN		128	/* max length, not counting NULL */
113 
114 struct passwd {
115 	char	*pw_name;		/* user name */
116 	char	*pw_passwd;		/* encrypted password */
117 	uid_t	pw_uid;			/* user uid */
118 	gid_t	pw_gid;			/* user gid */
119 	time_t	pw_change;		/* password change time */
120 	char	*pw_class;		/* user access class */
121 	char	*pw_gecos;		/* Honeywell login info */
122 	char	*pw_dir;		/* home directory */
123 	char	*pw_shell;		/* default shell */
124 	time_t	pw_expire;		/* account expiration */
125 	int	pw_fields;		/* internal: fields filled in */
126 };
127 
128 /* Mapping from fields to bits for pw_fields. */
129 #define _PWF(x)		(1 << x)
130 #define _PWF_NAME	_PWF(0)
131 #define _PWF_PASSWD	_PWF(1)
132 #define _PWF_UID	_PWF(2)
133 #define _PWF_GID	_PWF(3)
134 #define _PWF_CHANGE	_PWF(4)
135 #define _PWF_CLASS	_PWF(5)
136 #define _PWF_GECOS	_PWF(6)
137 #define _PWF_DIR	_PWF(7)
138 #define _PWF_SHELL	_PWF(8)
139 #define _PWF_EXPIRE	_PWF(9)
140 
141 /* XXX These flags are bogus.  With nsswitch, there are many
142  * possible sources and they cannot be represented in a small integer.
143  */
144 #define _PWF_SOURCE	0x3000
145 #define _PWF_FILES	0x1000
146 #define _PWF_NIS	0x2000
147 #define _PWF_HESIOD	0x3000
148 
149 __BEGIN_DECLS
150 struct passwd	*getpwnam(const char *);
151 struct passwd	*getpwuid(uid_t);
152 
153 #if __XSI_VISIBLE >= 500
154 void		 endpwent(void);
155 struct passwd	*getpwent(void);
156 void		 setpwent(void);
157 #endif
158 
159 #if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE >= 500
160 int		 getpwnam_r(const char *, struct passwd *, char *, size_t,
161 		    struct passwd **);
162 int		 getpwuid_r(uid_t, struct passwd *, char *, size_t,
163 		    struct passwd **);
164 #endif
165 
166 #if __BSD_VISIBLE
167 int		 getpwent_r(struct passwd *, char *, size_t, struct passwd **);
168 int		 setpassent(int);
169 const char	*user_from_uid(uid_t, int);
170 int		 uid_from_user(const char *, uid_t *);
171 int		 pwcache_userdb(int (*)(int), void (*)(void),
172 		    struct passwd * (*)(const char *),
173 		    struct passwd * (*)(uid_t));
174 #endif
175 __END_DECLS
176 
177 #endif /* !_PWD_H_ */
178