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