pwd.h revision 113666
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.
181539Srgrimes * 3. All advertising materials mentioning features or use of this software
191539Srgrimes *    must display the following acknowledgement:
201539Srgrimes *	This product includes software developed by the University of
211539Srgrimes *	California, Berkeley and its contributors.
221539Srgrimes * 4. Neither the name of the University nor the names of its contributors
231539Srgrimes *    may be used to endorse or promote products derived from this software
241539Srgrimes *    without specific prior written permission.
251539Srgrimes *
261539Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
271539Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
281539Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
291539Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
301539Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
311539Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
321539Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
331539Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
341539Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
351539Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
361539Srgrimes * SUCH DAMAGE.
371539Srgrimes *
381539Srgrimes *	@(#)pwd.h	8.2 (Berkeley) 1/21/94
3990644Simp * $FreeBSD: head/include/pwd.h 113666 2003-04-18 14:11:17Z nectar $
401539Srgrimes */
411539Srgrimes
421539Srgrimes#ifndef _PWD_H_
431539Srgrimes#define	_PWD_H_
441539Srgrimes
4598070Smike#include <sys/cdefs.h>
4698070Smike#include <sys/_types.h>
471539Srgrimes
48102227Smike#ifndef _GID_T_DECLARED
49102227Smiketypedef	__gid_t		gid_t;
50102227Smike#define	_GID_T_DECLARED
5198070Smike#endif
5298070Smike
53102227Smike#ifndef _TIME_T_DECLARED
54102227Smiketypedef	__time_t	time_t;
55102227Smike#define	_TIME_T_DECLARED
5698070Smike#endif
5798070Smike
58102227Smike#ifndef _UID_T_DECLARED
59102227Smiketypedef	__uid_t		uid_t;
60102227Smike#define	_UID_T_DECLARED
6198070Smike#endif
6298070Smike
63113596Snectar#ifndef _SIZE_T_DECLARED
64113596Snectartypedef __size_t	size_t;
65113596Snectar#define _SIZE_T_DECLARED
66113596Snectar#endif
67113596Snectar
682552Sgpalmer#define _PATH_PWD		"/etc"
691539Srgrimes#define	_PATH_PASSWD		"/etc/passwd"
702552Sgpalmer#define	_PASSWD			"passwd"
711539Srgrimes#define	_PATH_MASTERPASSWD	"/etc/master.passwd"
722552Sgpalmer#define	_MASTERPASSWD		"master.passwd"
731539Srgrimes
741539Srgrimes#define	_PATH_MP_DB		"/etc/pwd.db"
752552Sgpalmer#define	_MP_DB			"pwd.db"
761539Srgrimes#define	_PATH_SMP_DB		"/etc/spwd.db"
772552Sgpalmer#define	_SMP_DB			"spwd.db"
781539Srgrimes
791539Srgrimes#define	_PATH_PWD_MKDB		"/usr/sbin/pwd_mkdb"
801539Srgrimes
81113666Snectar/* Historically, the keys in _PATH_MP_DB/_PATH_SMP_DB had the format
82113666Snectar * `1 octet tag | key', where the tag is one of the _PW_KEY* values
83113666Snectar * listed below.  These values happen to be ASCII digits.  Starting
84113666Snectar * with FreeBSD 5.1, the tag is now still a single octet, but the
85113666Snectar * upper 4 bits are interpreted as a version.  Pre-FreeBSD 5.1 format
86113666Snectar * entries are version `3' -- this conveniently results in the same
87113666Snectar * key values as before.  The new, architecture-independent entries
88113666Snectar * are version `4'.
89113666Snectar * As it happens, some applications read the database directly.
90113666Snectar * (Bad app, no cookie!)  Thus, we leave the _PW_KEY* symbols at their
91113666Snectar * old pre-FreeBSD 5.1 values so these apps still work.  Consequently
92113666Snectar * we have to do muck around a bit more to get the correct, versioned
93113666Snectar * tag, and that is what the _PW_VERSIONED macros is about.
94113666Snectar */
951539Srgrimes
96113596Snectar#define _PW_VERSION_MASK	'0xF0'
97113666Snectar#define _PW_VERSIONED(x, v)	((unsigned char)(((x) & 0xCF) | ((v)<<4)))
98113596Snectar
99113666Snectar#define	_PW_KEYBYNAME		'\x31'	/* stored by name */
100113666Snectar#define	_PW_KEYBYNUM		'\x32'	/* stored by entry in the "file" */
101113666Snectar#define	_PW_KEYBYUID		'\x33'	/* stored by uid */
102113666Snectar#define _PW_KEYYPENABLED	'\x34'	/* YP is enabled */
103113666Snectar#define	_PW_KEYYPBYNUM		'\x35'	/* special +@netgroup entries */
104113596Snectar
105113666Snectar/* The database also contains a key to indicate the format version of
106113666Snectar * the entries therein.  There may be other, older versioned entries
107113666Snectar * as well.
108113666Snectar */
109113666Snectar#define _PWD_VERSION_KEY	"\xFF" "VERSION"
110113666Snectar#define _PWD_CURRENT_VERSION	'\x04'
111113666Snectar
1121539Srgrimes#define	_PASSWORD_EFMT1		'_'	/* extended encryption format */
1131539Srgrimes
1141539Srgrimes#define	_PASSWORD_LEN		128	/* max length, not counting NULL */
1151539Srgrimes
1161539Srgrimesstruct passwd {
1171539Srgrimes	char	*pw_name;		/* user name */
1181539Srgrimes	char	*pw_passwd;		/* encrypted password */
11942780Sdes	uid_t	pw_uid;			/* user uid */
12042780Sdes	gid_t	pw_gid;			/* user gid */
1211539Srgrimes	time_t	pw_change;		/* password change time */
1221539Srgrimes	char	*pw_class;		/* user access class */
1231539Srgrimes	char	*pw_gecos;		/* Honeywell login info */
1241539Srgrimes	char	*pw_dir;		/* home directory */
1251539Srgrimes	char	*pw_shell;		/* default shell */
1261539Srgrimes	time_t	pw_expire;		/* account expiration */
1272915Swollman	int	pw_fields;		/* internal: fields filled in */
1281539Srgrimes};
1291539Srgrimes
1302915Swollman/* Mapping from fields to bits for pw_fields. */
1312915Swollman#define _PWF(x)		(1 << x)
1322915Swollman#define _PWF_NAME	_PWF(0)
1332915Swollman#define _PWF_PASSWD	_PWF(1)
1342915Swollman#define _PWF_UID	_PWF(2)
1352915Swollman#define _PWF_GID	_PWF(3)
1362915Swollman#define _PWF_CHANGE	_PWF(4)
1372915Swollman#define _PWF_CLASS	_PWF(5)
1382915Swollman#define _PWF_GECOS	_PWF(6)
1392915Swollman#define _PWF_DIR	_PWF(7)
1402915Swollman#define _PWF_SHELL	_PWF(8)
1412915Swollman#define _PWF_EXPIRE	_PWF(9)
1422915Swollman
143113596Snectar/* XXX These flags are bogus.  With nsswitch, there are many
144113596Snectar * possible sources and they cannot be represented in a small integer.
145113596Snectar */
14694688Sdes#define _PWF_SOURCE	0x3000
14794688Sdes#define _PWF_FILES	0x1000
14894688Sdes#define _PWF_NIS	0x2000
14994688Sdes#define _PWF_HESIOD	0x3000
15094688Sdes
1511539Srgrimes__BEGIN_DECLS
15298070Smikestruct passwd	*getpwnam(const char *);
15393032Simpstruct passwd	*getpwuid(uid_t);
15498070Smike
15598070Smike#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE >= 500
15698070Smikevoid		 endpwent(void);
15793032Simpstruct passwd	*getpwent(void);
15898070Smikevoid		 setpwent(void);
159113596Snectarint		 getpwnam_r(const char *, struct passwd *, char *, size_t,
160113596Snectar		    struct passwd **);
161113596Snectarint		 getpwuid_r(uid_t, struct passwd *, char *, size_t,
162113596Snectar		    struct passwd **);
16398070Smike#endif
16498070Smike
16598070Smike#if __BSD_VISIBLE
166113596Snectarint		 getpwent_r(struct passwd *, char *, size_t, struct passwd **);
16793032Simpint		 setpassent(int);
16893032Simpconst char	*user_from_uid(uid_t, int);
1691539Srgrimes#endif
1701539Srgrimes__END_DECLS
1711539Srgrimes
1721539Srgrimes#endif /* !_PWD_H_ */
173