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

Diff for /src/usr.bin/sudo/Attic/getspwuid.c between version 1.4 and 1.5

version 1.4, 2000/11/21 17:58:44 version 1.5, 2002/01/03 03:49:16
Line 1 
Line 1 
 /*  /*
  * Copyright (c) 1996, 1998, 1999 Todd C. Miller <Todd.Miller@courtesan.com>   * Copyright (c) 1996, 1998-2001 Todd C. Miller <Todd.Miller@courtesan.com>
  * All rights reserved.   * All rights reserved.
  *   *
  * Redistribution and use in source and binary forms, with or without   * Redistribution and use in source and binary forms, with or without
Line 34 
Line 34 
   
 #include "config.h"  #include "config.h"
   
   #include <sys/types.h>
   #include <sys/stat.h>
   #include <sys/param.h>
 #include <stdio.h>  #include <stdio.h>
 #ifdef STDC_HEADERS  #ifdef STDC_HEADERS
 # include <stdlib.h>  # include <stdlib.h>
   # include <stddef.h>
   #else
   # ifdef HAVE_STDLIB_H
   #  include <stdlib.h>
   # endif
 #endif /* STDC_HEADERS */  #endif /* STDC_HEADERS */
 #ifdef HAVE_STRING_H  #ifdef HAVE_STRING_H
   # if defined(HAVE_MEMORY_H) && !defined(STDC_HEADERS)
   #  include <memory.h>
   # endif
 # include <string.h>  # include <string.h>
   #else
   # ifdef HAVE_STRINGS_H
   #  include <strings.h>
   # endif
 #endif /* HAVE_STRING_H */  #endif /* HAVE_STRING_H */
 #ifdef HAVE_STRINGS_H  
 # include <strings.h>  
 #endif /* HAVE_STRINGS_H */  
 #ifdef HAVE_UNISTD_H  #ifdef HAVE_UNISTD_H
 # include <unistd.h>  # include <unistd.h>
 #endif /* HAVE_UNISTD_H */  #endif /* HAVE_UNISTD_H */
 #include <sys/types.h>  
 #include <sys/stat.h>  
 #include <sys/param.h>  
 #include <pwd.h>  #include <pwd.h>
 #ifdef HAVE_GETSPNAM  #ifdef HAVE_GETSPNAM
 # include <shadow.h>  # include <shadow.h>
Line 75 
Line 84 
 #include "sudo.h"  #include "sudo.h"
   
 #ifndef lint  #ifndef lint
 static const char rcsid[] = "$Sudo: getspwuid.c,v 1.56 2000/02/18 17:56:26 millert Exp $";  static const char rcsid[] = "$Sudo: getspwuid.c,v 1.61 2001/12/14 19:52:47 millert Exp $";
 #endif /* lint */  #endif /* lint */
   
 #ifndef STDC_HEADERS  
 extern char *getenv     __P((const char *));  
 #endif /* !STDC_HEADERS */  
   
 /*  /*
  * Global variables (yuck)   * Global variables (yuck)
  */   */
Line 98 
Line 103 
   
   
 /*  /*
  * Return the user's shell based on either the SHELL   * Return the user's shell based on either the SHELL environment variable
  * environment variable or the passwd(5) entry (in that order).   * (already assigned to user_shell) or, failing that, the passwd(5) entry.
  */   */
 static char *  static char *
 sudo_getshell(pw)  sudo_getshell(pw)
Line 107 
Line 112 
 {  {
     char *pw_shell;      char *pw_shell;
   
     if ((pw_shell = getenv("SHELL")) == NULL)      if ((pw_shell = user_shell) == NULL)
         pw_shell = pw->pw_shell;          pw_shell = pw->pw_shell;
   
     /* empty string "" means bourne shell */      /* empty string "" means bourne shell */
Line 118 
Line 123 
 }  }
   
 /*  /*
  * Return the encrypted password for the user described by pw.  If shadow   * Return a copy of the encrypted password for the user described by pw.
  * passwords are in use, look in the shadow file.   * If shadow passwords are in use, look in the shadow file.
  */   */
 char *  char *
 sudo_getepw(pw)  sudo_getepw(pw)
     struct passwd *pw;      struct passwd *pw;
 {  {
       char *epw;
   
     /* If there is a function to check for shadow enabled, use it... */      /* If there is a function to check for shadow enabled, use it... */
 #ifdef HAVE_ISCOMSEC  #ifdef HAVE_ISCOMSEC
     if (!iscomsec())      if (!iscomsec())
         return(pw->pw_passwd);          return(estrdup(pw->pw_passwd));
 #endif /* HAVE_ISCOMSEC */  #endif /* HAVE_ISCOMSEC */
 #ifdef HAVE_ISSECURE  #ifdef HAVE_ISSECURE
     if (!issecure())      if (!issecure())
         return(pw->pw_passwd);          return(estrdup(pw->pw_passwd));
 #endif /* HAVE_ISSECURE */  #endif /* HAVE_ISSECURE */
   
       epw = NULL;
 #ifdef HAVE_GETPRPWNAM  #ifdef HAVE_GETPRPWNAM
     {      {
         struct pr_passwd *spw;          struct pr_passwd *spw;
   
         spw = getprpwnam(pw->pw_name);          setprpwent();
         if (spw != NULL && spw->ufld.fd_encrypt != NULL) {          if ((spw = getprpwnam(pw->pw_name)) && spw->ufld.fd_encrypt) {
 # ifdef __alpha  # ifdef __alpha
             crypt_type = spw->ufld.fd_oldcrypt;              crypt_type = spw->ufld.fd_oldcrypt;
 # endif /* __alpha */  # endif /* __alpha */
             return(spw->ufld.fd_encrypt);              epw = estrdup(spw->ufld.fd_encrypt);
         }          }
           endprpwent();
           if (epw)
               return(epw);
     }      }
 #endif /* HAVE_GETPRPWNAM */  #endif /* HAVE_GETPRPWNAM */
 #ifdef HAVE_GETSPNAM  #ifdef HAVE_GETSPNAM
     {      {
         struct spwd *spw;          struct spwd *spw;
   
           setspent();
         if ((spw = getspnam(pw->pw_name)) && spw->sp_pwdp)          if ((spw = getspnam(pw->pw_name)) && spw->sp_pwdp)
             return(spw->sp_pwdp);              epw = estrdup(spw->sp_pwdp);
           endspent();
           if (epw)
               return(epw);
     }      }
 #endif /* HAVE_GETSPNAM */  #endif /* HAVE_GETSPNAM */
 #ifdef HAVE_GETSPWUID  #ifdef HAVE_GETSPWUID
     {      {
         struct s_passwd *spw;          struct s_passwd *spw;
   
           setspwent();
         if ((spw = getspwuid(pw->pw_uid)) && spw->pw_passwd)          if ((spw = getspwuid(pw->pw_uid)) && spw->pw_passwd)
             return(spw->pw_passwd);              epw = estrdup(spw->pw_passwd);
           endspwent();
           if (epw)
               return(epw);
     }      }
 #endif /* HAVE_GETSPWUID */  #endif /* HAVE_GETSPWUID */
 #ifdef HAVE_GETPWANAM  #ifdef HAVE_GETPWANAM
     {      {
         struct passwd_adjunct *spw;          struct passwd_adjunct *spw;
   
           setpwaent();
         if ((spw = getpwanam(pw->pw_name)) && spw->pwa_passwd)          if ((spw = getpwanam(pw->pw_name)) && spw->pwa_passwd)
             return(spw->pwa_passwd);              epw = estrdup(spw->pwa_passwd);
           endpwaent();
           if (epw)
               return(epw);
     }      }
 #endif /* HAVE_GETPWANAM */  #endif /* HAVE_GETPWANAM */
 #ifdef HAVE_GETAUTHUID  #ifdef HAVE_GETAUTHUID
     {      {
         AUTHORIZATION *spw;          AUTHORIZATION *spw;
   
           setauthent();
         if ((spw = getauthuid(pw->pw_uid)) && spw->a_password)          if ((spw = getauthuid(pw->pw_uid)) && spw->a_password)
             return(spw->a_password);              epw = estrdup(spw->a_password);
           endauthent();
           if (epw)
               return(epw);
     }      }
 #endif /* HAVE_GETAUTHUID */  #endif /* HAVE_GETAUTHUID */
   
     /* Fall back on normal password. */      /* Fall back on normal password. */
     return(pw->pw_passwd);      return(estrdup(pw->pw_passwd));
 }  }
   
 /*  /*
Line 214 
Line 240 
     local_pw->pw_shell = estrdup(sudo_getshell(pw));      local_pw->pw_shell = estrdup(sudo_getshell(pw));
   
     /* pw_passwd gets a shadow password if applicable */      /* pw_passwd gets a shadow password if applicable */
     local_pw->pw_passwd = estrdup(sudo_getepw(pw));      local_pw->pw_passwd = sudo_getepw(pw);
   
     return(local_pw);      return(local_pw);
 }  }

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5