[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.9 and 1.10

version 1.9, 2007/07/26 16:10:16 version 1.10, 2008/11/14 11:58:08
Line 46 
Line 46 
 # include <unistd.h>  # include <unistd.h>
 #endif /* HAVE_UNISTD_H */  #endif /* HAVE_UNISTD_H */
 #include <pwd.h>  #include <pwd.h>
   #include <grp.h>
 #ifdef HAVE_GETSPNAM  #ifdef HAVE_GETSPNAM
 # include <shadow.h>  # include <shadow.h>
 #endif /* HAVE_GETSPNAM */  #endif /* HAVE_GETSPNAM */
Line 70 
Line 71 
 #include "sudo.h"  #include "sudo.h"
   
 #ifndef lint  #ifndef lint
 __unused static const char rcsid[] = "$Sudo: getspwuid.c,v 1.65.2.2 2007/06/12 01:28:41 millert Exp $";  __unused static const char rcsid[] = "$Sudo: getspwuid.c,v 1.78 2005/02/12 22:56:06 millert Exp $";
 #endif /* lint */  #endif /* lint */
   
 /*  /*
  * Global variables (yuck)   * Exported for auth/secureware.c
  */   */
 #if defined(HAVE_GETPRPWNAM) && defined(__alpha)  #if defined(HAVE_GETPRPWNAM) && defined(__alpha)
 int crypt_type = INT_MAX;  int crypt_type = INT_MAX;
 #endif /* HAVE_GETPRPWNAM && __alpha */  #endif /* HAVE_GETPRPWNAM && __alpha */
   
   
 /*  /*
  * Return a copy of the encrypted password for the user described by pw.   * Return a copy of the encrypted password for the user described by pw.
  * If shadow passwords are in use, look in the shadow file.   * If shadow passwords are in use, look in the shadow file.
Line 106 
Line 106 
     {      {
         struct pr_passwd *spw;          struct pr_passwd *spw;
   
         setprpwent();  
         if ((spw = getprpwnam(pw->pw_name)) && spw->ufld.fd_encrypt) {          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 */
             epw = estrdup(spw->ufld.fd_encrypt);              epw = estrdup(spw->ufld.fd_encrypt);
         }          }
         endprpwent();  
         if (epw)          if (epw)
             return(epw);              return(epw);
     }      }
Line 122 
Line 120 
     {      {
         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)
             epw = estrdup(spw->sp_pwdp);              epw = estrdup(spw->sp_pwdp);
         endspent();  
         if (epw)          if (epw)
             return(epw);              return(epw);
     }      }
Line 134 
Line 130 
     {      {
         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)
             epw = estrdup(spw->pw_passwd);              epw = estrdup(spw->pw_passwd);
         endspwent();  
         if (epw)          if (epw)
             return(epw);              return(epw);
     }      }
Line 146 
Line 140 
     {      {
         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)
             epw = estrdup(spw->pwa_passwd);              epw = estrdup(spw->pwa_passwd);
         endpwaent();  
         if (epw)          if (epw)
             return(epw);              return(epw);
     }      }
Line 158 
Line 150 
     {      {
         AUTHORIZATION *spw;          AUTHORIZATION *spw;
   
         setauthent();  
         if ((spw = getauthuid(pw->pw_uid)) && spw->a_password)          if ((spw = getauthuid(pw->pw_uid)) && spw->a_password)
             epw = estrdup(spw->a_password);              epw = estrdup(spw->a_password);
         endauthent();  
         if (epw)          if (epw)
             return(epw);              return(epw);
     }      }
Line 171 
Line 161 
     return(estrdup(pw->pw_passwd));      return(estrdup(pw->pw_passwd));
 }  }
   
 /*  void
  * Dynamically allocate space for a struct password and the constituent parts  sudo_setspent()
  * that we care about.  Fills in pw_passwd from shadow file if necessary.  
  */  
 struct passwd *  
 sudo_pwdup(pw)  
     const struct passwd *pw;  
 {  {
     char *cp;  #ifdef HAVE_GETPRPWNAM
     const char *pw_passwd, *pw_shell;      setprpwent();
     size_t nsize, psize, csize, gsize, dsize, ssize, total;  
     struct passwd *newpw;  
   
     /* Get shadow password if available. */  
     pw_passwd = sudo_getepw(pw);  
   
     /* If shell field is empty, expand to _PATH_BSHELL. */  
     pw_shell = (pw->pw_shell == NULL || pw->pw_shell[0] == '\0')  
         ? _PATH_BSHELL : pw->pw_shell;  
   
     /* Allocate in one big chunk for easy freeing. */  
     nsize = psize = csize = gsize = dsize = ssize = 0;  
     total = sizeof(struct passwd);  
     if (pw->pw_name) {  
             nsize = strlen(pw->pw_name) + 1;  
             total += nsize;  
     }  
     if (pw_passwd) {  
             psize = strlen(pw_passwd) + 1;  
             total += psize;  
     }  
 #ifdef HAVE_LOGIN_CAP_H  
     if (pw->pw_class) {  
             csize = strlen(pw->pw_class) + 1;  
             total += csize;  
     }  
 #endif  #endif
     if (pw->pw_gecos) {  #ifdef HAVE_GETSPNAM
             gsize = strlen(pw->pw_gecos) + 1;      setspent();
             total += gsize;  
     }  
     if (pw->pw_dir) {  
             dsize = strlen(pw->pw_dir) + 1;  
             total += dsize;  
     }  
     if (pw_shell) {  
             ssize = strlen(pw_shell) + 1;  
             total += ssize;  
     }  
     if ((cp = malloc(total)) == NULL)  
             return (NULL);  
     newpw = (struct passwd *)cp;  
   
     /*  
      * Copy in passwd contents and make strings relative to space  
      * at the end of the buffer.  
      */  
     (void)memcpy(newpw, pw, sizeof(struct passwd));  
     cp += sizeof(struct passwd);  
     if (nsize) {  
             (void)memcpy(cp, pw->pw_name, nsize);  
             newpw->pw_name = cp;  
             cp += nsize;  
     }  
     if (psize) {  
             (void)memcpy(cp, pw_passwd, psize);  
             newpw->pw_passwd = cp;  
             cp += psize;  
     }  
 #ifdef HAVE_LOGIN_CAP_H  
     if (csize) {  
             (void)memcpy(cp, pw->pw_class, csize);  
             newpw->pw_class = cp;  
             cp += csize;  
     }  
 #endif  #endif
     if (gsize) {  #ifdef HAVE_GETSPWUID
             (void)memcpy(cp, pw->pw_gecos, gsize);      setspwent();
             newpw->pw_gecos = cp;  #endif
             cp += gsize;  #ifdef HAVE_GETPWANAM
     }      setpwaent();
     if (dsize) {  #endif
             (void)memcpy(cp, pw->pw_dir, dsize);  #ifdef HAVE_GETAUTHUID
             newpw->pw_dir = cp;      setauthent();
             cp += dsize;  #endif
     }  
     if (ssize) {  
             (void)memcpy(cp, pw_shell, ssize);  
             newpw->pw_shell = cp;  
             cp += ssize;  
     }  
   
     return (newpw);  
 }  }
   
 /*  void
  * Get a password entry by uid and allocate space for it.  sudo_endspent()
  * Fills in pw_passwd from shadow file if necessary.  
  */  
 struct passwd *  
 sudo_getpwuid(uid)  
     uid_t uid;  
 {  {
     struct passwd *pw;  #ifdef HAVE_GETPRPWNAM
       endprpwent();
     if ((pw = getpwuid(uid)) == NULL)  #endif
         return(NULL);  #ifdef HAVE_GETSPNAM
     else      endspent();
         return(sudo_pwdup(pw));  #endif
 }  #ifdef HAVE_GETSPWUID
       endspwent();
 /*  #endif
  * Get a password entry by name and allocate space for it.  #ifdef HAVE_GETPWANAM
  * Fills in pw_passwd from shadow file if necessary.      endpwaent();
  */  #endif
 struct passwd *  #ifdef HAVE_GETAUTHUID
 sudo_getpwnam(name)      endauthent();
     const char *name;  #endif
 {  
     struct passwd *pw;  
   
     if ((pw = getpwnam(name)) == NULL)  
         return(NULL);  
     else  
         return(sudo_pwdup(pw));  
 }  }

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.10