00001 /*- 00002 * Copyright (c) 1989, 1993 00003 * The Regents of the University of California. All rights reserved. 00004 * (c) UNIX System Laboratories, Inc. 00005 * All or some portions of this file are derived from material licensed 00006 * to the University of California by American Telephone and Telegraph 00007 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 00008 * the permission of UNIX System Laboratories, Inc. 00009 * 00010 * Redistribution and use in source and binary forms, with or without 00011 * modification, are permitted provided that the following conditions 00012 * are met: 00013 * 1. Redistributions of source code must retain the above copyright 00014 * notice, this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright 00016 * notice, this list of conditions and the following disclaimer in the 00017 * documentation and/or other materials provided with the distribution. 00018 * 3. All advertising materials mentioning features or use of this software 00019 * must display the following acknowledgement: 00020 * This product includes software developed by the University of 00021 * California, Berkeley and its contributors. 00022 * 4. Neither the name of the University nor the names of its contributors 00023 * may be used to endorse or promote products derived from this software 00024 * without specific prior written permission. 00025 * 00026 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 00027 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00028 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00029 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 00030 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00031 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00032 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00033 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00034 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00035 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00036 * SUCH DAMAGE. 00037 * 00038 * @(#)pwd.h 8.2 (Berkeley) 1/21/94 00039 * $FreeBSD: src/include/pwd.h,v 1.16 2005/01/26 17:26:54 nectar Exp $ 00040 * © Portions copyright (c) 2005-2006 Nokia Corporation. All rights reserved. 00041 */ 00042 00043 #ifndef _PWD_H_ 00044 #define _PWD_H_ 00045 00046 #include <sys/cdefs.h> 00047 #include <sys/_types.h> 00048 00049 #ifndef _GID_T_DECLARED 00050 typedef __gid_t gid_t; 00051 #define _GID_T_DECLARED 00052 #endif 00053 00054 #ifndef _TIME_T_DECLARED 00055 typedef __time_t time_t; 00056 #define _TIME_T_DECLARED 00057 #endif 00058 00059 #ifndef _UID_T_DECLARED 00060 typedef __uid_t uid_t; 00061 #define _UID_T_DECLARED 00062 #endif 00063 00064 #ifndef _SIZE_T_DECLARED 00065 typedef __size_t size_t; 00066 #define _SIZE_T_DECLARED 00067 #endif 00068 00069 #define _PATH_PWD "/etc" 00070 #define _PATH_PASSWD "/etc/passwd" 00071 #define _PASSWD "passwd" 00072 #define _PATH_MASTERPASSWD "/etc/master.passwd" 00073 #define _MASTERPASSWD "master.passwd" 00074 00075 #define _PATH_MP_DB "/etc/pwd.db" 00076 #define _MP_DB "pwd.db" 00077 #define _PATH_SMP_DB "/etc/spwd.db" 00078 #define _SMP_DB "spwd.db" 00079 00080 #define _PATH_PWD_MKDB "/usr/sbin/pwd_mkdb" 00081 00082 /* Historically, the keys in _PATH_MP_DB/_PATH_SMP_DB had the format 00083 * `1 octet tag | key', where the tag is one of the _PW_KEY* values 00084 * listed below. These values happen to be ASCII digits. Starting 00085 * with FreeBSD 5.1, the tag is now still a single octet, but the 00086 * upper 4 bits are interpreted as a version. Pre-FreeBSD 5.1 format 00087 * entries are version `3' -- this conveniently results in the same 00088 * key values as before. The new, architecture-independent entries 00089 * are version `4'. 00090 * As it happens, some applications read the database directly. 00091 * (Bad app, no cookie!) Thus, we leave the _PW_KEY* symbols at their 00092 * old pre-FreeBSD 5.1 values so these apps still work. Consequently 00093 * we have to muck around a bit more to get the correct, versioned 00094 * tag, and that is what the _PW_VERSIONED macro is about. 00095 */ 00096 00097 #define _PW_VERSION_MASK '\xF0' 00098 #define _PW_VERSIONED(x, v) ((unsigned char)(((x) & 0xCF) | ((v)<<4))) 00099 00100 #define _PW_KEYBYNAME '\x31' /* stored by name */ 00101 #define _PW_KEYBYNUM '\x32' /* stored by entry in the "file" */ 00102 #define _PW_KEYBYUID '\x33' /* stored by uid */ 00103 #define _PW_KEYYPENABLED '\x34' /* YP is enabled */ 00104 #define _PW_KEYYPBYNUM '\x35' /* special + @ netgroup entries */ 00105 00106 /* The database also contains a key to indicate the format version of 00107 * the entries therein. There may be other, older versioned entries 00108 * as well. 00109 */ 00110 #define _PWD_VERSION_KEY "\xFF" "VERSION" 00111 #define _PWD_CURRENT_VERSION '\x04' 00112 00113 #define _PASSWORD_EFMT1 '_' /* extended encryption format */ 00114 00115 #define _PASSWORD_LEN 128 /* max length, not counting NULL */ 00116 00117 struct passwd { 00118 char *pw_name; /* user name */ 00119 char *pw_passwd; /* encrypted password */ 00120 uid_t pw_uid; /* user uid */ 00121 gid_t pw_gid; /* user gid */ 00122 time_t pw_change; /* password change time */ 00123 char *pw_class; /* user access class */ 00124 char *pw_gecos; /* Honeywell login info */ 00125 char *pw_dir; /* home directory */ 00126 char *pw_shell; /* default shell */ 00127 time_t pw_expire; /* account expiration */ 00128 int pw_fields; /* internal: fields filled in */ 00129 }; 00130 00131 /* Mapping from fields to bits for pw_fields. */ 00132 #define _PWF(x) (1 << x) 00133 #define _PWF_NAME _PWF(0) 00134 #define _PWF_PASSWD _PWF(1) 00135 #define _PWF_UID _PWF(2) 00136 #define _PWF_GID _PWF(3) 00137 #define _PWF_CHANGE _PWF(4) 00138 #define _PWF_CLASS _PWF(5) 00139 #define _PWF_GECOS _PWF(6) 00140 #define _PWF_DIR _PWF(7) 00141 #define _PWF_SHELL _PWF(8) 00142 #define _PWF_EXPIRE _PWF(9) 00143 00144 /* XXX These flags are bogus. With nsswitch, there are many 00145 * possible sources and they cannot be represented in a small integer. 00146 */ 00147 #define _PWF_SOURCE 0x3000 00148 #define _PWF_FILES 0x1000 00149 #define _PWF_NIS 0x2000 00150 #define _PWF_HESIOD 0x3000 00151 00152 __BEGIN_DECLS 00153 IMPORT_C struct passwd *getpwnam(const char *); 00154 IMPORT_C struct passwd *getpwuid(uid_t); 00155 00156 #if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE >= 500 00157 IMPORT_C void endpwent(void); 00158 IMPORT_C struct passwd *getpwent(void); 00159 IMPORT_C void setpwent(void); 00160 IMPORT_C int getpwnam_r(const char *, struct passwd *, char *, size_t, 00161 struct passwd **); 00162 IMPORT_C int getpwuid_r(uid_t, struct passwd *, char *, size_t, 00163 struct passwd **); 00164 #endif 00165 00166 __END_DECLS 00167 00168 #endif /* !_PWD_H_ */