pwd.h revision 245267
143105Sdfr/*-
243105Sdfr * Copyright (c) 1989, 1993
343105Sdfr *	The Regents of the University of California.  All rights reserved.
443105Sdfr * (c) UNIX System Laboratories, Inc.
543105Sdfr * All or some portions of this file are derived from material licensed
643105Sdfr * to the University of California by American Telephone and Telegraph
743105Sdfr * Co. or Unix System Laboratories, Inc. and are reproduced herein with
843105Sdfr * the permission of UNIX System Laboratories, Inc.
943105Sdfr *
1043105Sdfr * Redistribution and use in source and binary forms, with or without
1143105Sdfr * modification, are permitted provided that the following conditions
1243105Sdfr * are met:
1343105Sdfr * 1. Redistributions of source code must retain the above copyright
1443105Sdfr *    notice, this list of conditions and the following disclaimer.
1543105Sdfr * 2. Redistributions in binary form must reproduce the above copyright
1643105Sdfr *    notice, this list of conditions and the following disclaimer in the
1743105Sdfr *    documentation and/or other materials provided with the distribution.
1843105Sdfr * 3. Neither the name of the University nor the names of its contributors
1943105Sdfr *    may be used to endorse or promote products derived from this software
2043105Sdfr *    without specific prior written permission.
2143105Sdfr *
2243105Sdfr * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2343105Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2443105Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2543105Sdfr * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2650477Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2743105Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2843105Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2943105Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3043105Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3143105Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3243105Sdfr * SUCH DAMAGE.
3343105Sdfr *
3443105Sdfr *	@(#)pwd.h	8.2 (Berkeley) 1/21/94
3543105Sdfr * $FreeBSD: stable/9/include/pwd.h 245267 2013-01-10 22:15:13Z brooks $
3648104Syokota */
3743105Sdfr
3848104Syokota#ifndef _PWD_H_
3943105Sdfr#define	_PWD_H_
4048104Syokota
4148104Syokota#include <sys/cdefs.h>
4248104Syokota#include <sys/_types.h>
4348104Syokota
4448104Syokota#ifndef _GID_T_DECLARED
4543105Sdfrtypedef	__gid_t		gid_t;
4643105Sdfr#define	_GID_T_DECLARED
4743105Sdfr#endif
4843105Sdfr
4943105Sdfr#ifndef _TIME_T_DECLARED
5043105Sdfrtypedef	__time_t	time_t;
5143105Sdfr#define	_TIME_T_DECLARED
5243105Sdfr#endif
5343105Sdfr
5443105Sdfr#ifndef _UID_T_DECLARED
5543105Sdfrtypedef	__uid_t		uid_t;
5643105Sdfr#define	_UID_T_DECLARED
5748104Syokota#endif
5848104Syokota
5943105Sdfr#ifndef _SIZE_T_DECLARED
6048104Syokotatypedef __size_t	size_t;
6143105Sdfr#define _SIZE_T_DECLARED
6243105Sdfr#endif
6343105Sdfr
6448104Syokota#define _PATH_PWD		"/etc"
6548104Syokota#define	_PATH_PASSWD		"/etc/passwd"
6648104Syokota#define	_PASSWD			"passwd"
6748104Syokota#define	_PATH_MASTERPASSWD	"/etc/master.passwd"
6848104Syokota#define	_MASTERPASSWD		"master.passwd"
6948104Syokota
7043105Sdfr#define	_PATH_MP_DB		"/etc/pwd.db"
7148104Syokota#define	_MP_DB			"pwd.db"
72111815Sphk#define	_PATH_SMP_DB		"/etc/spwd.db"
73111815Sphk#define	_SMP_DB			"spwd.db"
74111815Sphk
75111815Sphk#define	_PATH_PWD_MKDB		"/usr/sbin/pwd_mkdb"
76111815Sphk
77111815Sphk/* Historically, the keys in _PATH_MP_DB/_PATH_SMP_DB had the format
78111815Sphk * `1 octet tag | key', where the tag is one of the _PW_KEY* values
79111815Sphk * listed below.  These values happen to be ASCII digits.  Starting
8043105Sdfr * with FreeBSD 5.1, the tag is now still a single octet, but the
8143105Sdfr * upper 4 bits are interpreted as a version.  Pre-FreeBSD 5.1 format
8243105Sdfr * entries are version `3' -- this conveniently results in the same
8343105Sdfr * key values as before.  The new, architecture-independent entries
8462225Speter * are version `4'.
8562225Speter * As it happens, some applications read the database directly.
8662225Speter * (Bad app, no cookie!)  Thus, we leave the _PW_KEY* symbols at their
8762225Speter * old pre-FreeBSD 5.1 values so these apps still work.  Consequently
8862225Speter * we have to muck around a bit more to get the correct, versioned
8962225Speter * tag, and that is what the _PW_VERSIONED macro is about.
9043105Sdfr */
9143105Sdfr
9243105Sdfr#define _PW_VERSION_MASK	'\xF0'
9348104Syokota#define _PW_VERSIONED(x, v)	((unsigned char)(((x) & 0xCF) | ((v)<<4)))
9448104Syokota
9548104Syokota#define	_PW_KEYBYNAME		'\x31'	/* stored by name */
9643105Sdfr#define	_PW_KEYBYNUM		'\x32'	/* stored by entry in the "file" */
9747618Sdfr#define	_PW_KEYBYUID		'\x33'	/* stored by uid */
9847618Sdfr#define _PW_KEYYPENABLED	'\x34'	/* YP is enabled */
9947618Sdfr#define	_PW_KEYYPBYNUM		'\x35'	/* special +@netgroup entries */
10047618Sdfr
10143105Sdfr/* The database also contains a key to indicate the format version of
10251052Sdfr * the entries therein.  There may be other, older versioned entries
10348104Syokota * as well.
10448104Syokota */
10552174Sdfr#define _PWD_VERSION_KEY	"\xFF" "VERSION"
10648104Syokota#define _PWD_CURRENT_VERSION	'\x04'
10752174Sdfr
10848104Syokota#define	_PASSWORD_EFMT1		'_'	/* extended encryption format */
10948104Syokota
11048104Syokota#define	_PASSWORD_LEN		128	/* max length, not counting NULL */
11148104Syokota
11248104Syokotastruct passwd {
11348104Syokota	char	*pw_name;		/* user name */
11448104Syokota	char	*pw_passwd;		/* encrypted password */
11548104Syokota	uid_t	pw_uid;			/* user uid */
11648104Syokota	gid_t	pw_gid;			/* user gid */
11743105Sdfr	time_t	pw_change;		/* password change time */
11843105Sdfr	char	*pw_class;		/* user access class */
11943105Sdfr	char	*pw_gecos;		/* Honeywell login info */
12043105Sdfr	char	*pw_dir;		/* home directory */
12143105Sdfr	char	*pw_shell;		/* default shell */
12248104Syokota	time_t	pw_expire;		/* account expiration */
12348104Syokota	int	pw_fields;		/* internal: fields filled in */
12448104Syokota};
12548104Syokota
12648104Syokota/* Mapping from fields to bits for pw_fields. */
12748104Syokota#define _PWF(x)		(1 << x)
12843105Sdfr#define _PWF_NAME	_PWF(0)
12948104Syokota#define _PWF_PASSWD	_PWF(1)
13043105Sdfr#define _PWF_UID	_PWF(2)
13143105Sdfr#define _PWF_GID	_PWF(3)
13248104Syokota#define _PWF_CHANGE	_PWF(4)
13348104Syokota#define _PWF_CLASS	_PWF(5)
13448104Syokota#define _PWF_GECOS	_PWF(6)
13548104Syokota#define _PWF_DIR	_PWF(7)
13648104Syokota#define _PWF_SHELL	_PWF(8)
13748104Syokota#define _PWF_EXPIRE	_PWF(9)
13843105Sdfr
13951052Sdfr/* XXX These flags are bogus.  With nsswitch, there are many
14043105Sdfr * possible sources and they cannot be represented in a small integer.
14148104Syokota */
14243105Sdfr#define _PWF_SOURCE	0x3000
14343105Sdfr#define _PWF_FILES	0x1000
14443105Sdfr#define _PWF_NIS	0x2000
14548104Syokota#define _PWF_HESIOD	0x3000
14643105Sdfr
14743105Sdfr__BEGIN_DECLS
14843105Sdfrstruct passwd	*getpwnam(const char *);
14943105Sdfrstruct passwd	*getpwuid(uid_t);
15043105Sdfr
15143664Syokota#if __XSI_VISIBLE >= 500
15243105Sdfrvoid		 endpwent(void);
15348104Syokotastruct passwd	*getpwent(void);
15454073Smdoddvoid		 setpwent(void);
15548104Syokota#endif
15643105Sdfr
15743105Sdfr#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE >= 500
15848104Syokotaint		 getpwnam_r(const char *, struct passwd *, char *, size_t,
15943105Sdfr		    struct passwd **);
16043105Sdfrint		 getpwuid_r(uid_t, struct passwd *, char *, size_t,
16148104Syokota		    struct passwd **);
16243105Sdfr#endif
16343105Sdfr
16483366Sjulian#if __BSD_VISIBLE
16543105Sdfrint		 getpwent_r(struct passwd *, char *, size_t, struct passwd **);
16683366Sjulianint		 setpassent(int);
16743105Sdfrconst char	*user_from_uid(uid_t, int);
16843105Sdfrint		 uid_from_user(const char *, uid_t *);
16943105Sdfrint		 pwcache_userdb(int (*)(int), void (*)(void),
17083366Sjulian		    struct passwd * (*)(const char *),
17143105Sdfr		    struct passwd * (*)(uid_t));
17283366Sjulian#endif
17343105Sdfr__END_DECLS
17443105Sdfr
17543105Sdfr#endif /* !_PWD_H_ */
17648104Syokota