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

Diff for /src/usr.bin/chpass/Attic/pw_yp.c between version 1.15 and 1.16

version 1.15, 2002/06/04 00:09:08 version 1.16, 2002/06/27 19:02:40
Line 50 
Line 50 
 #include <pwd.h>  #include <pwd.h>
 #include <err.h>  #include <err.h>
 #include <errno.h>  #include <errno.h>
   #include <unistd.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <rpc/rpc.h>  #include <rpc/rpc.h>
 #include <rpcsvc/yp_prot.h>  #include <rpcsvc/yp_prot.h>
Line 63 
Line 64 
 static char *domain;  static char *domain;
   
 int  int
 pw_yp(pw, uid)  pw_yp(struct passwd *pw, uid_t uid)
         struct passwd *pw;  
         uid_t uid;  
 {  {
         char *master;          char buf[10], *master, *p;
         char *p;  
         char buf[10];  
         int r, rpcport, status, alen;          int r, rpcport, status, alen;
         struct yppasswd yppasswd;          struct yppasswd yppasswd;
         struct timeval tv;          struct timeval tv;
         CLIENT *client;          CLIENT *client;
         extern char *getpass();  
   
         /*          /*
          * Get local domain           * Get local domain
          */           */
Line 126 
Line 122 
                 (void)fprintf(stderr, "Cancelled.\n");                  (void)fprintf(stderr, "Cancelled.\n");
                 return(0);                  return(0);
         }          }
   
         for (alen = 0, p = pw->pw_gecos; *p; p++)          for (alen = 0, p = pw->pw_gecos; *p; p++)
                 if (*p == '&')                  if (*p == '&')
                         alen = alen + strlen(pw->pw_name) - 1;                          alen = alen + strlen(pw->pw_name) - 1;
Line 142 
Line 138 
         /* tell rpc.yppasswdd */          /* tell rpc.yppasswdd */
         yppasswd.newpw.pw_name  = pw->pw_name;          yppasswd.newpw.pw_name  = pw->pw_name;
         yppasswd.newpw.pw_passwd= pw->pw_passwd;          yppasswd.newpw.pw_passwd= pw->pw_passwd;
         yppasswd.newpw.pw_uid   = pw->pw_uid;          yppasswd.newpw.pw_uid   = pw->pw_uid;
         yppasswd.newpw.pw_gid   = pw->pw_gid;          yppasswd.newpw.pw_gid   = pw->pw_gid;
         yppasswd.newpw.pw_gecos = pw->pw_gecos;          yppasswd.newpw.pw_gecos = pw->pw_gecos;
         yppasswd.newpw.pw_dir   = pw->pw_dir;          yppasswd.newpw.pw_dir   = pw->pw_dir;
Line 176 
Line 172 
 }  }
   
 static char *  static char *
 pwskip(p)  pwskip(char *p)
         char *p;  
 {  {
         while (*p && *p != ':' && *p != '\n')          while (*p && *p != ':' && *p != '\n')
                 ++p;                  ++p;
Line 187 
Line 182 
 }  }
   
 static struct passwd *  static struct passwd *
 interpret(pwent, line)  interpret(struct passwd *pwent, char *line)
         struct passwd *pwent;  
         char *line;  
 {  {
         char    *p = line;          char    *p = line;
   
Line 202 
Line 195 
         pwent->pw_change = 0;          pwent->pw_change = 0;
         pwent->pw_expire = 0;          pwent->pw_expire = 0;
         pwent->pw_class = "";          pwent->pw_class = "";
   
         /* line without colon separators is no good, so ignore it */          /* line without colon separators is no good, so ignore it */
         if(!strchr(p,':'))          if(!strchr(p,':'))
                 return(NULL);                  return(NULL);
Line 229 
Line 222 
 static char *__yplin;  static char *__yplin;
   
 struct passwd *  struct passwd *
 ypgetpwnam(nam)  ypgetpwnam(char *nam)
         char *nam;  
 {  {
         static struct passwd pwent;          static struct passwd pwent;
         char *val;  
         int reason, vallen;          int reason, vallen;
           char *val;
   
         /*          /*
          * Get local domain           * Get local domain
          */           */
Line 259 
Line 251 
                 free(__yplin);                  free(__yplin);
         if (!(__yplin = (char *)malloc(vallen + 1)))          if (!(__yplin = (char *)malloc(vallen + 1)))
                 err(1, NULL);                  err(1, NULL);
         strcpy(__yplin, val);   /* ok */          strlcpy(__yplin, val, vallen + 1);
         free(val);          free(val);
   
         return(interpret(&pwent, __yplin));          return(interpret(&pwent, __yplin));
 }  }
   
 struct passwd *  struct passwd *
 ypgetpwuid(uid)  ypgetpwuid(uid_t uid)
         uid_t uid;  
 {  {
         static struct passwd pwent;          static struct passwd pwent;
         char *val;  
         int reason, vallen;          int reason, vallen;
         char namebuf[16];          char namebuf[16], *val;
   
         if (!domain && (reason = yp_get_default_domain(&domain))) {          if (!domain && (reason = yp_get_default_domain(&domain))) {
                 fprintf(stderr, "%s: can't get local YP domain. Reason: %s\n",                  fprintf(stderr, "%s: can't get local YP domain. Reason: %s\n",
                     __progname, yperr_string(reason));                      __progname, yperr_string(reason));
                 exit(1);                  exit(1);
         }          }
   
         snprintf(namebuf, sizeof namebuf, "%u", uid);          snprintf(namebuf, sizeof namebuf, "%u", (u_int)uid);
         reason = yp_match(domain, "passwd.byuid", namebuf, strlen(namebuf),          reason = yp_match(domain, "passwd.byuid", namebuf, strlen(namebuf),
             &val, &vallen);              &val, &vallen);
         switch(reason) {          switch(reason) {
Line 295 
Line 285 
                 free(__yplin);                  free(__yplin);
         if (!(__yplin = (char *)malloc(vallen + 1)))          if (!(__yplin = (char *)malloc(vallen + 1)))
                 err(1, NULL);                  err(1, NULL);
         strcpy(__yplin, val);   /* ok */          strlcpy(__yplin, val, vallen + 1);
         free(val);          free(val);
   
         return(interpret(&pwent, __yplin));          return(interpret(&pwent, __yplin));

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.16