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