1995-11-21 02:28:36 +00:00
|
|
|
/*
|
2010-06-14 12:19:49 -04:00
|
|
|
* Copyright (c) 1996, 1998-2005, 2010
|
|
|
|
* Todd C. Miller <Todd.Miller@courtesan.com>
|
1995-11-21 02:28:36 +00:00
|
|
|
*
|
2004-02-13 21:36:43 +00:00
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
1999-07-31 16:19:45 +00:00
|
|
|
*
|
2004-02-13 21:36:43 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
2003-04-16 00:42:10 +00:00
|
|
|
*
|
|
|
|
* Sponsored in part by the Defense Advanced Research Projects
|
|
|
|
* Agency (DARPA) and Air Force Research Laboratory, Air Force
|
|
|
|
* Materiel Command, USAF, under agreement number F39502-99-1-0512.
|
1995-11-21 02:28:36 +00:00
|
|
|
*/
|
|
|
|
|
2004-11-19 18:39:14 +00:00
|
|
|
#include <config.h>
|
1995-11-21 02:28:36 +00:00
|
|
|
|
2001-12-14 19:52:47 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/param.h>
|
1995-11-21 02:28:36 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#ifdef STDC_HEADERS
|
1999-08-22 09:59:28 +00:00
|
|
|
# include <stdlib.h>
|
2001-12-14 19:52:47 +00:00
|
|
|
# include <stddef.h>
|
|
|
|
#else
|
|
|
|
# ifdef HAVE_STDLIB_H
|
|
|
|
# include <stdlib.h>
|
|
|
|
# endif
|
1995-11-21 02:28:36 +00:00
|
|
|
#endif /* STDC_HEADERS */
|
1995-11-21 21:27:08 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
1999-08-22 09:59:28 +00:00
|
|
|
# include <string.h>
|
1995-11-21 21:27:08 +00:00
|
|
|
#endif /* HAVE_STRING_H */
|
2010-06-29 13:08:05 -04:00
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif /* HAVE_STRINGS_H */
|
1995-11-21 02:28:36 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
1999-08-22 09:59:28 +00:00
|
|
|
# include <unistd.h>
|
1995-11-21 02:28:36 +00:00
|
|
|
#endif /* HAVE_UNISTD_H */
|
|
|
|
#include <pwd.h>
|
2004-11-16 04:24:11 +00:00
|
|
|
#include <grp.h>
|
1998-09-21 04:00:56 +00:00
|
|
|
#ifdef HAVE_GETSPNAM
|
1999-08-22 09:59:28 +00:00
|
|
|
# include <shadow.h>
|
1998-09-21 04:00:56 +00:00
|
|
|
#endif /* HAVE_GETSPNAM */
|
1998-10-21 23:50:10 +00:00
|
|
|
#ifdef HAVE_GETPRPWNAM
|
1999-08-22 09:59:28 +00:00
|
|
|
# ifdef __hpux
|
|
|
|
# undef MAXINT
|
|
|
|
# include <hpsecurity.h>
|
|
|
|
# else
|
|
|
|
# include <sys/security.h>
|
|
|
|
# endif /* __hpux */
|
|
|
|
# include <prot.h>
|
1998-10-21 23:50:10 +00:00
|
|
|
#endif /* HAVE_GETPRPWNAM */
|
1998-09-21 04:00:56 +00:00
|
|
|
#ifdef HAVE_GETPWANAM
|
1999-08-22 09:59:28 +00:00
|
|
|
# include <sys/label.h>
|
|
|
|
# include <sys/audit.h>
|
|
|
|
# include <pwdadj.h>
|
1998-09-21 04:00:56 +00:00
|
|
|
#endif /* HAVE_GETPWANAM */
|
|
|
|
#ifdef HAVE_GETAUTHUID
|
1999-08-22 09:59:28 +00:00
|
|
|
# include <auth.h>
|
1998-09-21 04:00:56 +00:00
|
|
|
#endif /* HAVE_GETAUTHUID */
|
1995-11-21 02:28:36 +00:00
|
|
|
|
2010-03-14 19:58:47 -04:00
|
|
|
#include "sudoers.h"
|
1998-10-19 18:32:39 +00:00
|
|
|
|
1995-11-23 01:35:00 +00:00
|
|
|
/*
|
2005-01-05 19:41:31 +00:00
|
|
|
* Exported for auth/secureware.c
|
1995-11-23 01:35:00 +00:00
|
|
|
*/
|
1998-10-21 23:50:10 +00:00
|
|
|
#if defined(HAVE_GETPRPWNAM) && defined(__alpha)
|
1998-10-22 00:19:01 +00:00
|
|
|
int crypt_type = INT_MAX;
|
1998-10-21 23:50:10 +00:00
|
|
|
#endif /* HAVE_GETPRPWNAM && __alpha */
|
2004-11-15 14:53:05 +00:00
|
|
|
|
1999-07-22 12:49:28 +00:00
|
|
|
/*
|
2001-05-10 18:55:12 +00:00
|
|
|
* Return a copy of the encrypted password for the user described by pw.
|
|
|
|
* If shadow passwords are in use, look in the shadow file.
|
1995-11-21 02:28:36 +00:00
|
|
|
*/
|
2000-02-18 17:56:28 +00:00
|
|
|
char *
|
2010-04-22 18:09:53 -04:00
|
|
|
sudo_getepw(const struct passwd *pw)
|
1995-11-21 02:28:36 +00:00
|
|
|
{
|
2010-03-14 19:58:47 -04:00
|
|
|
char *epw = NULL;
|
1998-11-03 20:02:52 +00:00
|
|
|
|
1999-07-22 12:49:28 +00:00
|
|
|
/* If there is a function to check for shadow enabled, use it... */
|
1998-11-03 20:02:52 +00:00
|
|
|
#ifdef HAVE_ISCOMSEC
|
|
|
|
if (!iscomsec())
|
2010-03-14 19:58:47 -04:00
|
|
|
goto done;
|
1998-11-03 20:02:52 +00:00
|
|
|
#endif /* HAVE_ISCOMSEC */
|
|
|
|
#ifdef HAVE_ISSECURE
|
|
|
|
if (!issecure())
|
2010-03-14 19:58:47 -04:00
|
|
|
goto done;
|
1998-11-03 20:02:52 +00:00
|
|
|
#endif /* HAVE_ISSECURE */
|
|
|
|
|
1998-10-21 23:50:10 +00:00
|
|
|
#ifdef HAVE_GETPRPWNAM
|
1998-09-21 04:00:56 +00:00
|
|
|
{
|
1998-11-04 01:39:18 +00:00
|
|
|
struct pr_passwd *spw;
|
1998-09-21 04:00:56 +00:00
|
|
|
|
2001-05-10 18:55:12 +00:00
|
|
|
if ((spw = getprpwnam(pw->pw_name)) && spw->ufld.fd_encrypt) {
|
1999-10-07 21:21:08 +00:00
|
|
|
# ifdef __alpha
|
1999-08-14 15:34:55 +00:00
|
|
|
crypt_type = spw->ufld.fd_oldcrypt;
|
1999-10-07 21:21:08 +00:00
|
|
|
# endif /* __alpha */
|
2010-03-14 19:58:47 -04:00
|
|
|
epw = spw->ufld.fd_encrypt;
|
1998-09-21 04:00:56 +00:00
|
|
|
}
|
|
|
|
}
|
1998-10-21 23:50:10 +00:00
|
|
|
#endif /* HAVE_GETPRPWNAM */
|
1998-09-21 04:00:56 +00:00
|
|
|
#ifdef HAVE_GETSPNAM
|
|
|
|
{
|
1998-11-04 01:39:18 +00:00
|
|
|
struct spwd *spw;
|
1995-11-21 02:28:36 +00:00
|
|
|
|
1999-08-14 15:34:55 +00:00
|
|
|
if ((spw = getspnam(pw->pw_name)) && spw->sp_pwdp)
|
2010-03-14 19:58:47 -04:00
|
|
|
epw = spw->sp_pwdp;
|
1998-09-21 04:00:56 +00:00
|
|
|
}
|
|
|
|
#endif /* HAVE_GETSPNAM */
|
|
|
|
#ifdef HAVE_GETSPWUID
|
|
|
|
{
|
1998-11-04 01:39:18 +00:00
|
|
|
struct s_passwd *spw;
|
1995-11-21 02:28:36 +00:00
|
|
|
|
1999-08-14 15:34:55 +00:00
|
|
|
if ((spw = getspwuid(pw->pw_uid)) && spw->pw_passwd)
|
2010-03-14 19:58:47 -04:00
|
|
|
epw = spw->pw_passwd;
|
1998-09-21 04:00:56 +00:00
|
|
|
}
|
|
|
|
#endif /* HAVE_GETSPWUID */
|
|
|
|
#ifdef HAVE_GETPWANAM
|
|
|
|
{
|
1998-11-04 01:39:18 +00:00
|
|
|
struct passwd_adjunct *spw;
|
1995-11-21 02:28:36 +00:00
|
|
|
|
1999-08-14 15:34:55 +00:00
|
|
|
if ((spw = getpwanam(pw->pw_name)) && spw->pwa_passwd)
|
2010-03-14 19:58:47 -04:00
|
|
|
epw = spw->pwa_passwd;
|
1998-09-21 04:00:56 +00:00
|
|
|
}
|
|
|
|
#endif /* HAVE_GETPWANAM */
|
|
|
|
#ifdef HAVE_GETAUTHUID
|
|
|
|
{
|
1998-11-04 01:39:18 +00:00
|
|
|
AUTHORIZATION *spw;
|
1995-11-21 02:28:36 +00:00
|
|
|
|
1999-08-14 15:34:55 +00:00
|
|
|
if ((spw = getauthuid(pw->pw_uid)) && spw->a_password)
|
2010-03-14 19:58:47 -04:00
|
|
|
epw = spw->a_password;
|
1998-09-21 04:00:56 +00:00
|
|
|
}
|
|
|
|
#endif /* HAVE_GETAUTHUID */
|
|
|
|
|
2010-03-14 19:58:47 -04:00
|
|
|
#if defined(HAVE_ISCOMSEC) || defined(HAVE_ISSECURE)
|
|
|
|
done:
|
|
|
|
#endif
|
|
|
|
/* If no shadow password, fall back on regular password. */
|
|
|
|
return estrdup(epw ? epw : pw->pw_passwd);
|
1995-11-21 02:28:36 +00:00
|
|
|
}
|
|
|
|
|
2004-11-15 04:06:16 +00:00
|
|
|
void
|
2010-04-22 18:09:53 -04:00
|
|
|
sudo_setspent(void)
|
2004-11-15 04:06:16 +00:00
|
|
|
{
|
|
|
|
#ifdef HAVE_GETPRPWNAM
|
|
|
|
setprpwent();
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_GETSPNAM
|
|
|
|
setspent();
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_GETSPWUID
|
|
|
|
setspwent();
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_GETPWANAM
|
|
|
|
setpwaent();
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_GETAUTHUID
|
|
|
|
setauthent();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-04-22 18:09:53 -04:00
|
|
|
sudo_endspent(void)
|
2004-11-15 04:06:16 +00:00
|
|
|
{
|
|
|
|
#ifdef HAVE_GETPRPWNAM
|
|
|
|
endprpwent();
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_GETSPNAM
|
|
|
|
endspent();
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_GETSPWUID
|
|
|
|
endspwent();
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_GETPWANAM
|
|
|
|
endpwaent();
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_GETAUTHUID
|
|
|
|
endauthent();
|
|
|
|
#endif
|
2004-11-16 04:24:11 +00:00
|
|
|
}
|