pwd.h revision 245267
1139969Simp/*- 21556Srgrimes * Copyright (c) 1989, 1993 31556Srgrimes * The Regents of the University of California. All rights reserved. 41556Srgrimes * (c) UNIX System Laboratories, Inc. 51556Srgrimes * All or some portions of this file are derived from material licensed 61556Srgrimes * to the University of California by American Telephone and Telegraph 71556Srgrimes * Co. or Unix System Laboratories, Inc. and are reproduced herein with 81556Srgrimes * the permission of UNIX System Laboratories, Inc. 91556Srgrimes * 101556Srgrimes * Redistribution and use in source and binary forms, with or without 111556Srgrimes * modification, are permitted provided that the following conditions 121556Srgrimes * are met: 131556Srgrimes * 1. Redistributions of source code must retain the above copyright 141556Srgrimes * notice, this list of conditions and the following disclaimer. 151556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 161556Srgrimes * notice, this list of conditions and the following disclaimer in the 171556Srgrimes * documentation and/or other materials provided with the distribution. 181556Srgrimes * 3. Neither the name of the University nor the names of its contributors 191556Srgrimes * may be used to endorse or promote products derived from this software 201556Srgrimes * without specific prior written permission. 211556Srgrimes * 221556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 231556Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 241556Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 251556Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 261556Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 271556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 281556Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 291556Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 301556Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 311556Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3217987Speter * SUCH DAMAGE. 3350471Speter * 341556Srgrimes * @(#)pwd.h 8.2 (Berkeley) 1/21/94 351556Srgrimes * $FreeBSD: stable/9/include/pwd.h 245267 2013-01-10 22:15:13Z brooks $ 361556Srgrimes */ 371556Srgrimes 381556Srgrimes#ifndef _PWD_H_ 391556Srgrimes#define _PWD_H_ 401556Srgrimes 411556Srgrimes#include <sys/cdefs.h> 421556Srgrimes#include <sys/_types.h> 431556Srgrimes 441556Srgrimes#ifndef _GID_T_DECLARED 451556Srgrimestypedef __gid_t gid_t; 461556Srgrimes#define _GID_T_DECLARED 471556Srgrimes#endif 481556Srgrimes 491556Srgrimes#ifndef _TIME_T_DECLARED 501556Srgrimestypedef __time_t time_t; 511556Srgrimes#define _TIME_T_DECLARED 521556Srgrimes#endif 531556Srgrimes 541556Srgrimes#ifndef _UID_T_DECLARED 551556Srgrimestypedef __uid_t uid_t; 561556Srgrimes#define _UID_T_DECLARED 571556Srgrimes#endif 581556Srgrimes 591556Srgrimes#ifndef _SIZE_T_DECLARED 601556Srgrimestypedef __size_t size_t; 611556Srgrimes#define _SIZE_T_DECLARED 621556Srgrimes#endif 631556Srgrimes 641556Srgrimes#define _PATH_PWD "/etc" 651556Srgrimes#define _PATH_PASSWD "/etc/passwd" 661556Srgrimes#define _PASSWD "passwd" 671556Srgrimes#define _PATH_MASTERPASSWD "/etc/master.passwd" 681556Srgrimes#define _MASTERPASSWD "master.passwd" 691556Srgrimes 701556Srgrimes#define _PATH_MP_DB "/etc/pwd.db" 711556Srgrimes#define _MP_DB "pwd.db" 721556Srgrimes#define _PATH_SMP_DB "/etc/spwd.db" 731556Srgrimes#define _SMP_DB "spwd.db" 741556Srgrimes 751556Srgrimes#define _PATH_PWD_MKDB "/usr/sbin/pwd_mkdb" 761556Srgrimes 771556Srgrimes/* Historically, the keys in _PATH_MP_DB/_PATH_SMP_DB had the format 781556Srgrimes * `1 octet tag | key', where the tag is one of the _PW_KEY* values 791556Srgrimes * listed below. These values happen to be ASCII digits. Starting 801556Srgrimes * with FreeBSD 5.1, the tag is now still a single octet, but the 811556Srgrimes * upper 4 bits are interpreted as a version. Pre-FreeBSD 5.1 format 821556Srgrimes * entries are version `3' -- this conveniently results in the same 831556Srgrimes * key values as before. The new, architecture-independent entries 841556Srgrimes * are version `4'. 851556Srgrimes * As it happens, some applications read the database directly. 861556Srgrimes * (Bad app, no cookie!) Thus, we leave the _PW_KEY* symbols at their 871556Srgrimes * old pre-FreeBSD 5.1 values so these apps still work. Consequently 881556Srgrimes * we have to muck around a bit more to get the correct, versioned 891556Srgrimes * tag, and that is what the _PW_VERSIONED macro is about. 901556Srgrimes */ 911556Srgrimes 921556Srgrimes#define _PW_VERSION_MASK '\xF0' 931556Srgrimes#define _PW_VERSIONED(x, v) ((unsigned char)(((x) & 0xCF) | ((v)<<4))) 941556Srgrimes 951556Srgrimes#define _PW_KEYBYNAME '\x31' /* stored by name */ 961556Srgrimes#define _PW_KEYBYNUM '\x32' /* stored by entry in the "file" */ 971556Srgrimes#define _PW_KEYBYUID '\x33' /* stored by uid */ 981556Srgrimes#define _PW_KEYYPENABLED '\x34' /* YP is enabled */ 99223186Sjilles#define _PW_KEYYPBYNUM '\x35' /* special +@netgroup entries */ 1001556Srgrimes 1011556Srgrimes/* The database also contains a key to indicate the format version of 1021556Srgrimes * the entries therein. There may be other, older versioned entries 1031556Srgrimes * as well. 1041556Srgrimes */ 105223186Sjilles#define _PWD_VERSION_KEY "\xFF" "VERSION" 1061556Srgrimes#define _PWD_CURRENT_VERSION '\x04' 1071556Srgrimes 1081556Srgrimes#define _PASSWORD_EFMT1 '_' /* extended encryption format */ 1091556Srgrimes 1101556Srgrimes#define _PASSWORD_LEN 128 /* max length, not counting NULL */ 1111556Srgrimes 1121556Srgrimesstruct passwd { 1131556Srgrimes char *pw_name; /* user name */ 1141556Srgrimes char *pw_passwd; /* encrypted password */ 1151556Srgrimes uid_t pw_uid; /* user uid */ 1161556Srgrimes gid_t pw_gid; /* user gid */ 1171556Srgrimes time_t pw_change; /* password change time */ 11866612Sbrian char *pw_class; /* user access class */ 1191556Srgrimes char *pw_gecos; /* Honeywell login info */ 12096922Stjr char *pw_dir; /* home directory */ 1211556Srgrimes char *pw_shell; /* default shell */ 1221556Srgrimes time_t pw_expire; /* account expiration */ 1231556Srgrimes int pw_fields; /* internal: fields filled in */ 1241556Srgrimes}; 1251556Srgrimes 1261556Srgrimes/* Mapping from fields to bits for pw_fields. */ 1271556Srgrimes#define _PWF(x) (1 << x) 1281556Srgrimes#define _PWF_NAME _PWF(0) 1291556Srgrimes#define _PWF_PASSWD _PWF(1) 1301556Srgrimes#define _PWF_UID _PWF(2) 1311556Srgrimes#define _PWF_GID _PWF(3) 1321556Srgrimes#define _PWF_CHANGE _PWF(4) 13317987Speter#define _PWF_CLASS _PWF(5) 1341556Srgrimes#define _PWF_GECOS _PWF(6) 13517987Speter#define _PWF_DIR _PWF(7) 1361556Srgrimes#define _PWF_SHELL _PWF(8) 1371556Srgrimes#define _PWF_EXPIRE _PWF(9) 1381556Srgrimes 1391556Srgrimes/* XXX These flags are bogus. With nsswitch, there are many 1401556Srgrimes * possible sources and they cannot be represented in a small integer. 1411556Srgrimes */ 1421556Srgrimes#define _PWF_SOURCE 0x3000 1431556Srgrimes#define _PWF_FILES 0x1000 1441556Srgrimes#define _PWF_NIS 0x2000 1451556Srgrimes#define _PWF_HESIOD 0x3000 146 147__BEGIN_DECLS 148struct passwd *getpwnam(const char *); 149struct passwd *getpwuid(uid_t); 150 151#if __XSI_VISIBLE >= 500 152void endpwent(void); 153struct passwd *getpwent(void); 154void setpwent(void); 155#endif 156 157#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE >= 500 158int getpwnam_r(const char *, struct passwd *, char *, size_t, 159 struct passwd **); 160int getpwuid_r(uid_t, struct passwd *, char *, size_t, 161 struct passwd **); 162#endif 163 164#if __BSD_VISIBLE 165int getpwent_r(struct passwd *, char *, size_t, struct passwd **); 166int setpassent(int); 167const char *user_from_uid(uid_t, int); 168int uid_from_user(const char *, uid_t *); 169int pwcache_userdb(int (*)(int), void (*)(void), 170 struct passwd * (*)(const char *), 171 struct passwd * (*)(uid_t)); 172#endif 173__END_DECLS 174 175#endif /* !_PWD_H_ */ 176