2 * Copyright (c) 1996, 1998-2005 Todd C. Miller <Todd.Miller@courtesan.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 * Sponsored in part by the Defense Advanced Research Projects
17 * Agency (DARPA) and Air Force Research Laboratory, Air Force
18 * Materiel Command, USAF, under agreement number F39502-99-1-0512.
23 #include <sys/types.h>
25 #include <sys/param.h>
34 #endif /* STDC_HEADERS */
36 # if defined(HAVE_MEMORY_H) && !defined(STDC_HEADERS)
41 # ifdef HAVE_STRINGS_H
44 #endif /* HAVE_STRING_H */
47 #endif /* HAVE_UNISTD_H */
52 #endif /* HAVE_GETSPNAM */
53 #ifdef HAVE_GETPRPWNAM
56 # include <hpsecurity.h>
58 # include <sys/security.h>
61 #endif /* HAVE_GETPRPWNAM */
63 # include <sys/label.h>
64 # include <sys/audit.h>
66 #endif /* HAVE_GETPWANAM */
67 #ifdef HAVE_GETAUTHUID
69 #endif /* HAVE_GETAUTHUID */
74 __unused static const char rcsid[] = "$Sudo: getspwuid.c,v 1.78 2005/02/12 22:56:06 millert Exp $";
78 * Exported for auth/secureware.c
80 #if defined(HAVE_GETPRPWNAM) && defined(__alpha)
81 int crypt_type = INT_MAX;
82 #endif /* HAVE_GETPRPWNAM && __alpha */
85 * Return a copy of the encrypted password for the user described by pw.
86 * If shadow passwords are in use, look in the shadow file.
90 const struct passwd *pw;
94 /* If there is a function to check for shadow enabled, use it... */
97 return(estrdup(pw->pw_passwd));
98 #endif /* HAVE_ISCOMSEC */
101 return(estrdup(pw->pw_passwd));
102 #endif /* HAVE_ISSECURE */
105 #ifdef HAVE_GETPRPWNAM
107 struct pr_passwd *spw;
109 if ((spw = getprpwnam(pw->pw_name)) && spw->ufld.fd_encrypt) {
111 crypt_type = spw->ufld.fd_oldcrypt;
112 # endif /* __alpha */
113 epw = estrdup(spw->ufld.fd_encrypt);
118 #endif /* HAVE_GETPRPWNAM */
123 if ((spw = getspnam(pw->pw_name)) && spw->sp_pwdp)
124 epw = estrdup(spw->sp_pwdp);
128 #endif /* HAVE_GETSPNAM */
129 #ifdef HAVE_GETSPWUID
131 struct s_passwd *spw;
133 if ((spw = getspwuid(pw->pw_uid)) && spw->pw_passwd)
134 epw = estrdup(spw->pw_passwd);
138 #endif /* HAVE_GETSPWUID */
139 #ifdef HAVE_GETPWANAM
141 struct passwd_adjunct *spw;
143 if ((spw = getpwanam(pw->pw_name)) && spw->pwa_passwd)
144 epw = estrdup(spw->pwa_passwd);
148 #endif /* HAVE_GETPWANAM */
149 #ifdef HAVE_GETAUTHUID
153 if ((spw = getauthuid(pw->pw_uid)) && spw->a_password)
154 epw = estrdup(spw->a_password);
158 #endif /* HAVE_GETAUTHUID */
160 /* Fall back on normal password. */
161 return(estrdup(pw->pw_passwd));
167 #ifdef HAVE_GETPRPWNAM
173 #ifdef HAVE_GETSPWUID
176 #ifdef HAVE_GETPWANAM
179 #ifdef HAVE_GETAUTHUID
187 #ifdef HAVE_GETPRPWNAM
193 #ifdef HAVE_GETSPWUID
196 #ifdef HAVE_GETPWANAM
199 #ifdef HAVE_GETAUTHUID