11539Srgrimes/*- 21539Srgrimes * Copyright (c) 1989, 1993 31539Srgrimes * The Regents of the University of California. All rights reserved. 41539Srgrimes * (c) UNIX System Laboratories, Inc. 51539Srgrimes * All or some portions of this file are derived from material licensed 61539Srgrimes * to the University of California by American Telephone and Telegraph 71539Srgrimes * Co. or Unix System Laboratories, Inc. and are reproduced herein with 81539Srgrimes * the permission of UNIX System Laboratories, Inc. 91539Srgrimes * 101539Srgrimes * Redistribution and use in source and binary forms, with or without 111539Srgrimes * modification, are permitted provided that the following conditions 121539Srgrimes * are met: 131539Srgrimes * 1. Redistributions of source code must retain the above copyright 141539Srgrimes * notice, this list of conditions and the following disclaimer. 151539Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 161539Srgrimes * notice, this list of conditions and the following disclaimer in the 171539Srgrimes * documentation and/or other materials provided with the distribution. 18203964Simp * 3. Neither the name of the University nor the names of its contributors 191539Srgrimes * may be used to endorse or promote products derived from this software 201539Srgrimes * without specific prior written permission. 211539Srgrimes * 221539Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 231539Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 241539Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 251539Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 261539Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 271539Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 281539Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 291539Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 301539Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 311539Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 321539Srgrimes * SUCH DAMAGE. 331539Srgrimes * 341539Srgrimes * @(#)pwd.h 8.2 (Berkeley) 1/21/94 3590644Simp * $FreeBSD$ 361539Srgrimes */ 371539Srgrimes 381539Srgrimes#ifndef _PWD_H_ 391539Srgrimes#define _PWD_H_ 401539Srgrimes 4198070Smike#include <sys/cdefs.h> 4298070Smike#include <sys/_types.h> 431539Srgrimes 44102227Smike#ifndef _GID_T_DECLARED 45102227Smiketypedef __gid_t gid_t; 46102227Smike#define _GID_T_DECLARED 4798070Smike#endif 4898070Smike 49102227Smike#ifndef _TIME_T_DECLARED 50102227Smiketypedef __time_t time_t; 51102227Smike#define _TIME_T_DECLARED 5298070Smike#endif 5398070Smike 54102227Smike#ifndef _UID_T_DECLARED 55102227Smiketypedef __uid_t uid_t; 56102227Smike#define _UID_T_DECLARED 5798070Smike#endif 5898070Smike 59113596Snectar#ifndef _SIZE_T_DECLARED 60113596Snectartypedef __size_t size_t; 61113596Snectar#define _SIZE_T_DECLARED 62113596Snectar#endif 63113596Snectar 642552Sgpalmer#define _PATH_PWD "/etc" 651539Srgrimes#define _PATH_PASSWD "/etc/passwd" 662552Sgpalmer#define _PASSWD "passwd" 671539Srgrimes#define _PATH_MASTERPASSWD "/etc/master.passwd" 682552Sgpalmer#define _MASTERPASSWD "master.passwd" 691539Srgrimes 701539Srgrimes#define _PATH_MP_DB "/etc/pwd.db" 712552Sgpalmer#define _MP_DB "pwd.db" 721539Srgrimes#define _PATH_SMP_DB "/etc/spwd.db" 732552Sgpalmer#define _SMP_DB "spwd.db" 741539Srgrimes 751539Srgrimes#define _PATH_PWD_MKDB "/usr/sbin/pwd_mkdb" 761539Srgrimes 77113666Snectar/* Historically, the keys in _PATH_MP_DB/_PATH_SMP_DB had the format 78113666Snectar * `1 octet tag | key', where the tag is one of the _PW_KEY* values 79113666Snectar * listed below. These values happen to be ASCII digits. Starting 80113666Snectar * with FreeBSD 5.1, the tag is now still a single octet, but the 81113666Snectar * upper 4 bits are interpreted as a version. Pre-FreeBSD 5.1 format 82113666Snectar * entries are version `3' -- this conveniently results in the same 83113666Snectar * key values as before. The new, architecture-independent entries 84113666Snectar * are version `4'. 85113666Snectar * As it happens, some applications read the database directly. 86113666Snectar * (Bad app, no cookie!) Thus, we leave the _PW_KEY* symbols at their 87113666Snectar * old pre-FreeBSD 5.1 values so these apps still work. Consequently 88140868Snectar * we have to muck around a bit more to get the correct, versioned 89140868Snectar * tag, and that is what the _PW_VERSIONED macro is about. 90113666Snectar */ 911539Srgrimes 92140868Snectar#define _PW_VERSION_MASK '\xF0' 93113666Snectar#define _PW_VERSIONED(x, v) ((unsigned char)(((x) & 0xCF) | ((v)<<4))) 94113596Snectar 95113666Snectar#define _PW_KEYBYNAME '\x31' /* stored by name */ 96113666Snectar#define _PW_KEYBYNUM '\x32' /* stored by entry in the "file" */ 97113666Snectar#define _PW_KEYBYUID '\x33' /* stored by uid */ 98113666Snectar#define _PW_KEYYPENABLED '\x34' /* YP is enabled */ 99113666Snectar#define _PW_KEYYPBYNUM '\x35' /* special +@netgroup entries */ 100113596Snectar 101113666Snectar/* The database also contains a key to indicate the format version of 102113666Snectar * the entries therein. There may be other, older versioned entries 103113666Snectar * as well. 104113666Snectar */ 105113666Snectar#define _PWD_VERSION_KEY "\xFF" "VERSION" 106113666Snectar#define _PWD_CURRENT_VERSION '\x04' 107113666Snectar 1081539Srgrimes#define _PASSWORD_EFMT1 '_' /* extended encryption format */ 1091539Srgrimes 1101539Srgrimes#define _PASSWORD_LEN 128 /* max length, not counting NULL */ 1111539Srgrimes 1121539Srgrimesstruct passwd { 1131539Srgrimes char *pw_name; /* user name */ 1141539Srgrimes char *pw_passwd; /* encrypted password */ 11542780Sdes uid_t pw_uid; /* user uid */ 11642780Sdes gid_t pw_gid; /* user gid */ 1171539Srgrimes time_t pw_change; /* password change time */ 1181539Srgrimes char *pw_class; /* user access class */ 1191539Srgrimes char *pw_gecos; /* Honeywell login info */ 1201539Srgrimes char *pw_dir; /* home directory */ 1211539Srgrimes char *pw_shell; /* default shell */ 1221539Srgrimes time_t pw_expire; /* account expiration */ 1232915Swollman int pw_fields; /* internal: fields filled in */ 1241539Srgrimes}; 1251539Srgrimes 1262915Swollman/* Mapping from fields to bits for pw_fields. */ 1272915Swollman#define _PWF(x) (1 << x) 1282915Swollman#define _PWF_NAME _PWF(0) 1292915Swollman#define _PWF_PASSWD _PWF(1) 1302915Swollman#define _PWF_UID _PWF(2) 1312915Swollman#define _PWF_GID _PWF(3) 1322915Swollman#define _PWF_CHANGE _PWF(4) 1332915Swollman#define _PWF_CLASS _PWF(5) 1342915Swollman#define _PWF_GECOS _PWF(6) 1352915Swollman#define _PWF_DIR _PWF(7) 1362915Swollman#define _PWF_SHELL _PWF(8) 1372915Swollman#define _PWF_EXPIRE _PWF(9) 1382915Swollman 139113596Snectar/* XXX These flags are bogus. With nsswitch, there are many 140113596Snectar * possible sources and they cannot be represented in a small integer. 141113596Snectar */ 14294688Sdes#define _PWF_SOURCE 0x3000 14394688Sdes#define _PWF_FILES 0x1000 14494688Sdes#define _PWF_NIS 0x2000 14594688Sdes#define _PWF_HESIOD 0x3000 14694688Sdes 1471539Srgrimes__BEGIN_DECLS 14898070Smikestruct passwd *getpwnam(const char *); 14993032Simpstruct passwd *getpwuid(uid_t); 15098070Smike 151189819Sdas#if __XSI_VISIBLE >= 500 15298070Smikevoid endpwent(void); 15393032Simpstruct passwd *getpwent(void); 15498070Smikevoid setpwent(void); 155189819Sdas#endif 156189819Sdas 157189819Sdas#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE >= 500 158113596Snectarint getpwnam_r(const char *, struct passwd *, char *, size_t, 159113596Snectar struct passwd **); 160113596Snectarint getpwuid_r(uid_t, struct passwd *, char *, size_t, 161113596Snectar struct passwd **); 16298070Smike#endif 16398070Smike 16498070Smike#if __BSD_VISIBLE 165113596Snectarint getpwent_r(struct passwd *, char *, size_t, struct passwd **); 16693032Simpint setpassent(int); 16793032Simpconst char *user_from_uid(uid_t, int); 168241731Sbrooksint uid_from_user(const char *, uid_t *); 169241731Sbrooksint pwcache_userdb(int (*)(int), void (*)(void), 170241731Sbrooks struct passwd * (*)(const char *), 171241731Sbrooks struct passwd * (*)(uid_t)); 1721539Srgrimes#endif 1731539Srgrimes__END_DECLS 1741539Srgrimes 1751539Srgrimes#endif /* !_PWD_H_ */ 176