=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/sudo/Attic/getspwuid.c,v retrieving revision 1.4 retrieving revision 1.4.4.1 diff -c -r1.4 -r1.4.4.1 *** src/usr.bin/sudo/Attic/getspwuid.c 2000/11/21 17:58:44 1.4 --- src/usr.bin/sudo/Attic/getspwuid.c 2002/01/18 16:14:46 1.4.4.1 *************** *** 1,5 **** /* ! * Copyright (c) 1996, 1998, 1999 Todd C. Miller * All rights reserved. * * Redistribution and use in source and binary forms, with or without --- 1,5 ---- /* ! * Copyright (c) 1996, 1998-2001 Todd C. Miller * All rights reserved. * * Redistribution and use in source and binary forms, with or without *************** *** 34,55 **** #include "config.h" #include #ifdef STDC_HEADERS # include #endif /* STDC_HEADERS */ #ifdef HAVE_STRING_H # include #endif /* HAVE_STRING_H */ - #ifdef HAVE_STRINGS_H - # include - #endif /* HAVE_STRINGS_H */ #ifdef HAVE_UNISTD_H # include #endif /* HAVE_UNISTD_H */ - #include - #include - #include #include #ifdef HAVE_GETSPNAM # include --- 34,64 ---- #include "config.h" + #include + #include + #include #include #ifdef STDC_HEADERS # include + # include + #else + # ifdef HAVE_STDLIB_H + # include + # endif #endif /* STDC_HEADERS */ #ifdef HAVE_STRING_H + # if defined(HAVE_MEMORY_H) && !defined(STDC_HEADERS) + # include + # endif # include + #else + # ifdef HAVE_STRINGS_H + # include + # endif #endif /* HAVE_STRING_H */ #ifdef HAVE_UNISTD_H # include #endif /* HAVE_UNISTD_H */ #include #ifdef HAVE_GETSPNAM # include *************** *** 75,87 **** #include "sudo.h" #ifndef lint ! static const char rcsid[] = "$Sudo: getspwuid.c,v 1.56 2000/02/18 17:56:26 millert Exp $"; #endif /* lint */ - #ifndef STDC_HEADERS - extern char *getenv __P((const char *)); - #endif /* !STDC_HEADERS */ - /* * Global variables (yuck) */ --- 84,92 ---- #include "sudo.h" #ifndef lint ! static const char rcsid[] = "$Sudo: getspwuid.c,v 1.62 2002/01/15 23:43:59 millert Exp $"; #endif /* lint */ /* * Global variables (yuck) */ *************** *** 93,189 **** /* * Local functions not visible outside getspwuid.c */ - static char *sudo_getshell __P((struct passwd *)); static struct passwd *sudo_pwdup __P((struct passwd *)); /* ! * Return the user's shell based on either the SHELL ! * environment variable or the passwd(5) entry (in that order). */ - static char * - sudo_getshell(pw) - struct passwd *pw; - { - char *pw_shell; - - if ((pw_shell = getenv("SHELL")) == NULL) - pw_shell = pw->pw_shell; - - /* empty string "" means bourne shell */ - if (*pw_shell == '\0') - pw_shell = _PATH_BSHELL; - - return(pw_shell); - } - - /* - * Return the encrypted password for the user described by pw. If shadow - * passwords are in use, look in the shadow file. - */ char * sudo_getepw(pw) struct passwd *pw; { /* If there is a function to check for shadow enabled, use it... */ #ifdef HAVE_ISCOMSEC if (!iscomsec()) ! return(pw->pw_passwd); #endif /* HAVE_ISCOMSEC */ #ifdef HAVE_ISSECURE if (!issecure()) ! return(pw->pw_passwd); #endif /* HAVE_ISSECURE */ #ifdef HAVE_GETPRPWNAM { struct pr_passwd *spw; ! spw = getprpwnam(pw->pw_name); ! if (spw != NULL && spw->ufld.fd_encrypt != NULL) { # ifdef __alpha crypt_type = spw->ufld.fd_oldcrypt; # endif /* __alpha */ ! return(spw->ufld.fd_encrypt); } } #endif /* HAVE_GETPRPWNAM */ #ifdef HAVE_GETSPNAM { struct spwd *spw; if ((spw = getspnam(pw->pw_name)) && spw->sp_pwdp) ! return(spw->sp_pwdp); } #endif /* HAVE_GETSPNAM */ #ifdef HAVE_GETSPWUID { struct s_passwd *spw; if ((spw = getspwuid(pw->pw_uid)) && spw->pw_passwd) ! return(spw->pw_passwd); } #endif /* HAVE_GETSPWUID */ #ifdef HAVE_GETPWANAM { struct passwd_adjunct *spw; if ((spw = getpwanam(pw->pw_name)) && spw->pwa_passwd) ! return(spw->pwa_passwd); } #endif /* HAVE_GETPWANAM */ #ifdef HAVE_GETAUTHUID { AUTHORIZATION *spw; if ((spw = getauthuid(pw->pw_uid)) && spw->a_password) ! return(spw->a_password); } #endif /* HAVE_GETAUTHUID */ /* Fall back on normal password. */ ! return(pw->pw_passwd); } /* --- 98,194 ---- /* * Local functions not visible outside getspwuid.c */ static struct passwd *sudo_pwdup __P((struct passwd *)); /* ! * Return a copy of the encrypted password for the user described by pw. ! * If shadow passwords are in use, look in the shadow file. */ char * sudo_getepw(pw) struct passwd *pw; { + char *epw; /* If there is a function to check for shadow enabled, use it... */ #ifdef HAVE_ISCOMSEC if (!iscomsec()) ! return(estrdup(pw->pw_passwd)); #endif /* HAVE_ISCOMSEC */ #ifdef HAVE_ISSECURE if (!issecure()) ! return(estrdup(pw->pw_passwd)); #endif /* HAVE_ISSECURE */ + epw = NULL; #ifdef HAVE_GETPRPWNAM { struct pr_passwd *spw; ! setprpwent(); ! if ((spw = getprpwnam(pw->pw_name)) && spw->ufld.fd_encrypt) { # ifdef __alpha crypt_type = spw->ufld.fd_oldcrypt; # endif /* __alpha */ ! epw = estrdup(spw->ufld.fd_encrypt); } + endprpwent(); + if (epw) + return(epw); } #endif /* HAVE_GETPRPWNAM */ #ifdef HAVE_GETSPNAM { struct spwd *spw; + setspent(); if ((spw = getspnam(pw->pw_name)) && spw->sp_pwdp) ! epw = estrdup(spw->sp_pwdp); ! endspent(); ! if (epw) ! return(epw); } #endif /* HAVE_GETSPNAM */ #ifdef HAVE_GETSPWUID { struct s_passwd *spw; + setspwent(); if ((spw = getspwuid(pw->pw_uid)) && spw->pw_passwd) ! epw = estrdup(spw->pw_passwd); ! endspwent(); ! if (epw) ! return(epw); } #endif /* HAVE_GETSPWUID */ #ifdef HAVE_GETPWANAM { struct passwd_adjunct *spw; + setpwaent(); if ((spw = getpwanam(pw->pw_name)) && spw->pwa_passwd) ! epw = estrdup(spw->pwa_passwd); ! endpwaent(); ! if (epw) ! return(epw); } #endif /* HAVE_GETPWANAM */ #ifdef HAVE_GETAUTHUID { AUTHORIZATION *spw; + setauthent(); if ((spw = getauthuid(pw->pw_uid)) && spw->a_password) ! epw = estrdup(spw->a_password); ! endauthent(); ! if (epw) ! return(epw); } #endif /* HAVE_GETAUTHUID */ /* Fall back on normal password. */ ! return(estrdup(pw->pw_passwd)); } /* *************** *** 210,220 **** local_pw->pw_class = estrdup(pw->pw_class); #endif ! /* pw_shell is a special case since we overide with $SHELL */ ! local_pw->pw_shell = estrdup(sudo_getshell(pw)); /* pw_passwd gets a shadow password if applicable */ ! local_pw->pw_passwd = estrdup(sudo_getepw(pw)); return(local_pw); } --- 215,228 ---- local_pw->pw_class = estrdup(pw->pw_class); #endif ! /* If shell field is empty, expand to _PATH_BSHELL. */ ! if (local_pw->pw_shell[0] == '\0') ! local_pw->pw_shell = _PATH_BSHELL; ! else ! local_pw->pw_shell = estrdup(pw->pw_shell); /* pw_passwd gets a shadow password if applicable */ ! local_pw->pw_passwd = sudo_getepw(pw); return(local_pw); }