[BACK]Return to getspwuid.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / sudo

Annotation of src/usr.bin/sudo/getspwuid.c, Revision 1.10

1.1       millert     1: /*
1.9       millert     2:  * Copyright (c) 1996, 1998-2005 Todd C. Miller <Todd.Miller@courtesan.com>
1.1       millert     3:  *
1.8       millert     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.
1.1       millert     7:  *
1.8       millert     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.
1.7       millert    15:  *
                     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.
1.1       millert    19:  */
                     20:
1.9       millert    21: #include <config.h>
1.1       millert    22:
1.5       millert    23: #include <sys/types.h>
                     24: #include <sys/stat.h>
                     25: #include <sys/param.h>
1.1       millert    26: #include <stdio.h>
                     27: #ifdef STDC_HEADERS
                     28: # include <stdlib.h>
1.5       millert    29: # include <stddef.h>
                     30: #else
                     31: # ifdef HAVE_STDLIB_H
                     32: #  include <stdlib.h>
                     33: # endif
1.1       millert    34: #endif /* STDC_HEADERS */
                     35: #ifdef HAVE_STRING_H
1.5       millert    36: # if defined(HAVE_MEMORY_H) && !defined(STDC_HEADERS)
                     37: #  include <memory.h>
                     38: # endif
1.1       millert    39: # include <string.h>
1.5       millert    40: #else
                     41: # ifdef HAVE_STRINGS_H
                     42: #  include <strings.h>
                     43: # endif
1.1       millert    44: #endif /* HAVE_STRING_H */
                     45: #ifdef HAVE_UNISTD_H
                     46: # include <unistd.h>
                     47: #endif /* HAVE_UNISTD_H */
                     48: #include <pwd.h>
1.10    ! millert    49: #include <grp.h>
1.1       millert    50: #ifdef HAVE_GETSPNAM
                     51: # include <shadow.h>
                     52: #endif /* HAVE_GETSPNAM */
                     53: #ifdef HAVE_GETPRPWNAM
                     54: # ifdef __hpux
                     55: #  undef MAXINT
                     56: #  include <hpsecurity.h>
                     57: # else
                     58: #  include <sys/security.h>
                     59: # endif /* __hpux */
                     60: # include <prot.h>
                     61: #endif /* HAVE_GETPRPWNAM */
                     62: #ifdef HAVE_GETPWANAM
                     63: # include <sys/label.h>
                     64: # include <sys/audit.h>
                     65: # include <pwdadj.h>
                     66: #endif /* HAVE_GETPWANAM */
                     67: #ifdef HAVE_GETAUTHUID
                     68: # include <auth.h>
                     69: #endif /* HAVE_GETAUTHUID */
                     70:
                     71: #include "sudo.h"
                     72:
                     73: #ifndef lint
1.10    ! millert    74: __unused static const char rcsid[] = "$Sudo: getspwuid.c,v 1.78 2005/02/12 22:56:06 millert Exp $";
1.1       millert    75: #endif /* lint */
                     76:
                     77: /*
1.10    ! millert    78:  * Exported for auth/secureware.c
1.1       millert    79:  */
                     80: #if defined(HAVE_GETPRPWNAM) && defined(__alpha)
                     81: int crypt_type = INT_MAX;
                     82: #endif /* HAVE_GETPRPWNAM && __alpha */
                     83:
                     84: /*
1.5       millert    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.
1.1       millert    87:  */
1.2       millert    88: char *
1.1       millert    89: sudo_getepw(pw)
1.8       millert    90:     const struct passwd *pw;
1.1       millert    91: {
1.5       millert    92:     char *epw;
1.1       millert    93:
                     94:     /* If there is a function to check for shadow enabled, use it... */
                     95: #ifdef HAVE_ISCOMSEC
                     96:     if (!iscomsec())
1.5       millert    97:        return(estrdup(pw->pw_passwd));
1.1       millert    98: #endif /* HAVE_ISCOMSEC */
                     99: #ifdef HAVE_ISSECURE
                    100:     if (!issecure())
1.5       millert   101:        return(estrdup(pw->pw_passwd));
1.1       millert   102: #endif /* HAVE_ISSECURE */
                    103:
1.5       millert   104:     epw = NULL;
1.1       millert   105: #ifdef HAVE_GETPRPWNAM
                    106:     {
                    107:        struct pr_passwd *spw;
                    108:
1.5       millert   109:        if ((spw = getprpwnam(pw->pw_name)) && spw->ufld.fd_encrypt) {
1.1       millert   110: # ifdef __alpha
                    111:            crypt_type = spw->ufld.fd_oldcrypt;
                    112: # endif /* __alpha */
1.5       millert   113:            epw = estrdup(spw->ufld.fd_encrypt);
1.1       millert   114:        }
1.5       millert   115:        if (epw)
                    116:            return(epw);
1.1       millert   117:     }
                    118: #endif /* HAVE_GETPRPWNAM */
                    119: #ifdef HAVE_GETSPNAM
                    120:     {
                    121:        struct spwd *spw;
                    122:
                    123:        if ((spw = getspnam(pw->pw_name)) && spw->sp_pwdp)
1.5       millert   124:            epw = estrdup(spw->sp_pwdp);
                    125:        if (epw)
                    126:            return(epw);
1.1       millert   127:     }
                    128: #endif /* HAVE_GETSPNAM */
                    129: #ifdef HAVE_GETSPWUID
                    130:     {
                    131:        struct s_passwd *spw;
                    132:
                    133:        if ((spw = getspwuid(pw->pw_uid)) && spw->pw_passwd)
1.5       millert   134:            epw = estrdup(spw->pw_passwd);
                    135:        if (epw)
                    136:            return(epw);
1.1       millert   137:     }
                    138: #endif /* HAVE_GETSPWUID */
                    139: #ifdef HAVE_GETPWANAM
                    140:     {
                    141:        struct passwd_adjunct *spw;
                    142:
                    143:        if ((spw = getpwanam(pw->pw_name)) && spw->pwa_passwd)
1.5       millert   144:            epw = estrdup(spw->pwa_passwd);
                    145:        if (epw)
                    146:            return(epw);
1.1       millert   147:     }
                    148: #endif /* HAVE_GETPWANAM */
                    149: #ifdef HAVE_GETAUTHUID
                    150:     {
                    151:        AUTHORIZATION *spw;
                    152:
                    153:        if ((spw = getauthuid(pw->pw_uid)) && spw->a_password)
1.5       millert   154:            epw = estrdup(spw->a_password);
                    155:        if (epw)
                    156:            return(epw);
1.1       millert   157:     }
                    158: #endif /* HAVE_GETAUTHUID */
                    159:
                    160:     /* Fall back on normal password. */
1.5       millert   161:     return(estrdup(pw->pw_passwd));
1.1       millert   162: }
                    163:
1.10    ! millert   164: void
        !           165: sudo_setspent()
1.1       millert   166: {
1.10    ! millert   167: #ifdef HAVE_GETPRPWNAM
        !           168:     setprpwent();
        !           169: #endif
        !           170: #ifdef HAVE_GETSPNAM
        !           171:     setspent();
        !           172: #endif
        !           173: #ifdef HAVE_GETSPWUID
        !           174:     setspwent();
        !           175: #endif
        !           176: #ifdef HAVE_GETPWANAM
        !           177:     setpwaent();
1.8       millert   178: #endif
1.10    ! millert   179: #ifdef HAVE_GETAUTHUID
        !           180:     setauthent();
1.4       millert   181: #endif
1.3       millert   182: }
                    183:
1.10    ! millert   184: void
        !           185: sudo_endspent()
1.3       millert   186: {
1.10    ! millert   187: #ifdef HAVE_GETPRPWNAM
        !           188:     endprpwent();
        !           189: #endif
        !           190: #ifdef HAVE_GETSPNAM
        !           191:     endspent();
        !           192: #endif
        !           193: #ifdef HAVE_GETSPWUID
        !           194:     endspwent();
        !           195: #endif
        !           196: #ifdef HAVE_GETPWANAM
        !           197:     endpwaent();
        !           198: #endif
        !           199: #ifdef HAVE_GETAUTHUID
        !           200:     endauthent();
        !           201: #endif
1.1       millert   202: }