2 * Copyright (c) 1996, 1998-2005, 2010
3 * Todd C. Miller <Todd.Miller@courtesan.com>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 * Sponsored in part by the Defense Advanced Research Projects
18 * Agency (DARPA) and Air Force Research Laboratory, Air Force
19 * Materiel Command, USAF, under agreement number F39502-99-1-0512.
24 #include <sys/types.h>
26 #include <sys/param.h>
35 #endif /* STDC_HEADERS */
38 #endif /* HAVE_STRING_H */
41 #endif /* HAVE_STRINGS_H */
44 #endif /* HAVE_UNISTD_H */
49 #endif /* HAVE_GETSPNAM */
50 #ifdef HAVE_GETPRPWNAM
53 # include <hpsecurity.h>
55 # include <sys/security.h>
58 #endif /* HAVE_GETPRPWNAM */
60 # include <sys/label.h>
61 # include <sys/audit.h>
63 #endif /* HAVE_GETPWANAM */
64 #ifdef HAVE_GETAUTHUID
66 #endif /* HAVE_GETAUTHUID */
71 * Exported for auth/secureware.c
73 #if defined(HAVE_GETPRPWNAM) && defined(__alpha)
74 int crypt_type = INT_MAX;
75 #endif /* HAVE_GETPRPWNAM && __alpha */
78 * Return a copy of the encrypted password for the user described by pw.
79 * If shadow passwords are in use, look in the shadow file.
82 sudo_getepw(const struct passwd *pw)
85 debug_decl(sudo_getepw, SUDO_DEBUG_AUTH)
87 /* If there is a function to check for shadow enabled, use it... */
91 #endif /* HAVE_ISCOMSEC */
95 #endif /* HAVE_ISSECURE */
97 #ifdef HAVE_GETPRPWNAM
99 struct pr_passwd *spw;
101 if ((spw = getprpwnam(pw->pw_name)) && spw->ufld.fd_encrypt) {
103 crypt_type = spw->ufld.fd_oldcrypt;
104 # endif /* __alpha */
105 epw = spw->ufld.fd_encrypt;
108 #endif /* HAVE_GETPRPWNAM */
113 if ((spw = getspnam(pw->pw_name)) && spw->sp_pwdp)
116 #endif /* HAVE_GETSPNAM */
117 #ifdef HAVE_GETSPWUID
119 struct s_passwd *spw;
121 if ((spw = getspwuid(pw->pw_uid)) && spw->pw_passwd)
122 epw = spw->pw_passwd;
124 #endif /* HAVE_GETSPWUID */
125 #ifdef HAVE_GETPWANAM
127 struct passwd_adjunct *spw;
129 if ((spw = getpwanam(pw->pw_name)) && spw->pwa_passwd)
130 epw = spw->pwa_passwd;
132 #endif /* HAVE_GETPWANAM */
133 #ifdef HAVE_GETAUTHUID
137 if ((spw = getauthuid(pw->pw_uid)) && spw->a_password)
138 epw = spw->a_password;
140 #endif /* HAVE_GETAUTHUID */
142 #if defined(HAVE_ISCOMSEC) || defined(HAVE_ISSECURE)
145 /* If no shadow password, fall back on regular password. */
146 debug_return_str(estrdup(epw ? epw : pw->pw_passwd));
152 debug_decl(sudo_setspent, SUDO_DEBUG_AUTH)
154 #ifdef HAVE_GETPRPWNAM
160 #ifdef HAVE_GETSPWUID
163 #ifdef HAVE_GETPWANAM
166 #ifdef HAVE_GETAUTHUID
175 debug_decl(sudo_endspent, SUDO_DEBUG_AUTH)
177 #ifdef HAVE_GETPRPWNAM
183 #ifdef HAVE_GETSPWUID
186 #ifdef HAVE_GETPWANAM
189 #ifdef HAVE_GETAUTHUID