/*1* SPDX-License-Identifier: ISC2*3* Copyright (c) 1996, 1998-2005, 2010-2012, 2014-20154* Todd C. Miller <[email protected]>5*6* Permission to use, copy, modify, and distribute this software for any7* purpose with or without fee is hereby granted, provided that the above8* copyright notice and this permission notice appear in all copies.9*10* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES11* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF12* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR13* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES14* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN15* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF16* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.17*18* Sponsored in part by the Defense Advanced Research Projects19* Agency (DARPA) and Air Force Research Laboratory, Air Force20* Materiel Command, USAF, under agreement number F39502-99-1-0512.21*/2223#include <config.h>2425#include <stdio.h>26#include <stdlib.h>27#include <string.h>28#include <unistd.h>29#include <pwd.h>30#ifdef HAVE_GETSPNAM31# include <shadow.h>32#endif /* HAVE_GETSPNAM */33#ifdef HAVE_GETPRPWNAM34# ifdef __hpux35# undef MAXINT36# include <hpsecurity.h>37# else38# include <sys/security.h>39# endif /* __hpux */40# include <prot.h>41#endif /* HAVE_GETPRPWNAM */4243#include <sudoers.h>4445/*46* Exported for auth/secureware.c47*/48#if defined(HAVE_GETPRPWNAM) && defined(__alpha)49int crypt_type = INT_MAX;50#endif /* HAVE_GETPRPWNAM && __alpha */5152/*53* Return a copy of the encrypted password for the user described by pw.54* If shadow passwords are in use, look in the shadow file.55*/56char *57sudo_getepw(const struct passwd *pw)58{59char *epw = NULL;60debug_decl(sudo_getepw, SUDOERS_DEBUG_AUTH);6162/* If there is a function to check for shadow enabled, use it... */63#ifdef HAVE_ISCOMSEC64if (!iscomsec())65goto done;66#endif /* HAVE_ISCOMSEC */6768#ifdef HAVE_GETPWNAM_SHADOW69{70struct passwd *spw;7172/* On OpenBSD we need to closed the non-shadow passwd db first. */73endpwent();74if ((spw = getpwnam_shadow(pw->pw_name)) != NULL)75epw = spw->pw_passwd;76setpassent(1);77}78#endif /* HAVE_GETPWNAM_SHADOW */79#ifdef HAVE_GETPRPWNAM80{81struct pr_passwd *spw;8283if ((spw = getprpwnam(pw->pw_name)) && spw->ufld.fd_encrypt) {84# ifdef __alpha85crypt_type = spw->ufld.fd_oldcrypt;86# endif /* __alpha */87epw = spw->ufld.fd_encrypt;88}89}90#endif /* HAVE_GETPRPWNAM */91#ifdef HAVE_GETSPNAM92{93struct spwd *spw;9495if ((spw = getspnam(pw->pw_name)) && spw->sp_pwdp)96epw = spw->sp_pwdp;97}98#endif /* HAVE_GETSPNAM */99100#if defined(HAVE_ISCOMSEC)101done:102#endif103/* If no shadow password, fall back on regular password. */104debug_return_str(strdup(epw ? epw : pw->pw_passwd));105}106107void108sudo_setspent(void)109{110debug_decl(sudo_setspent, SUDOERS_DEBUG_AUTH);111112#ifdef HAVE_GETPRPWNAM113setprpwent();114#endif115#ifdef HAVE_GETSPNAM116setspent();117#endif118debug_return;119}120121void122sudo_endspent(void)123{124debug_decl(sudo_endspent, SUDOERS_DEBUG_AUTH);125126#ifdef HAVE_GETPRPWNAM127endprpwent();128#endif129#ifdef HAVE_GETSPNAM130endspent();131#endif132debug_return;133}134135136