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

Diff for /src/usr.bin/rdist/common.c between version 1.38 and 1.39

version 1.38, 2018/09/09 13:53:11 version 1.39, 2018/09/21 19:00:45
Line 56 
Line 56 
 char                    host[HOST_NAME_MAX+1];  /* Name of this host */  char                    host[HOST_NAME_MAX+1];  /* Name of this host */
 uid_t                   userid = (uid_t)-1;     /* User's UID */  uid_t                   userid = (uid_t)-1;     /* User's UID */
 gid_t                   groupid = (gid_t)-1;    /* User's GID */  gid_t                   groupid = (gid_t)-1;    /* User's GID */
   gid_t                   gidset[NGROUPS_MAX];    /* User's GID list */
   int                     gidsetlen = 0;          /* Number of GIDS in list */
 char                   *homedir = NULL;         /* User's $HOME */  char                   *homedir = NULL;         /* User's $HOME */
 char                   *locuser = NULL;         /* Local User's name */  char                   *locuser = NULL;         /* Local User's name */
 int                     isserver = FALSE;       /* We're the server */  int                     isserver = FALSE;       /* We're the server */
Line 129 
Line 131 
         homedir = xstrdup(pw->pw_dir);          homedir = xstrdup(pw->pw_dir);
         locuser = xstrdup(pw->pw_name);          locuser = xstrdup(pw->pw_name);
         groupid = pw->pw_gid;          groupid = pw->pw_gid;
           gidsetlen = getgroups(NGROUPS_MAX, gidset);
         gethostname(host, sizeof(host));          gethostname(host, sizeof(host));
 #if 0  #if 0
         if ((cp = strchr(host, '.')) != NULL)          if ((cp = strchr(host, '.')) != NULL)
Line 436 
Line 439 
 {  {
         static char buf[100];          static char buf[100];
         static uid_t lastuid = (uid_t)-1;          static uid_t lastuid = (uid_t)-1;
         struct passwd *pwd = NULL;          const char *name;
   
         /*          /*
          * The value of opts may have changed so we always           * The value of opts may have changed so we always
Line 448 
Line 451 
         }          }
   
         /*          /*
          * Try to avoid getpwuid() call.           * Try to avoid passwd lookup.
          */           */
         if (lastuid == uid && buf[0] != '\0' && buf[0] != ':')          if (lastuid == uid && buf[0] != '\0' && buf[0] != ':')
                 return(buf);                  return(buf);
   
         lastuid = uid;          lastuid = uid;
   
         if ((pwd = getpwuid(uid)) == NULL) {          if ((name = user_from_uid(uid, 1)) == NULL) {
                 if (IS_ON(opts, DO_DEFOWNER) && !isserver)                  if (IS_ON(opts, DO_DEFOWNER) && !isserver)
                         (void) strlcpy(buf, defowner, sizeof(buf));                          (void) strlcpy(buf, defowner, sizeof(buf));
                 else {                  else {
Line 464 
Line 467 
                         (void) snprintf(buf, sizeof(buf), ":%u", uid);                          (void) snprintf(buf, sizeof(buf), ":%u", uid);
                 }                  }
         } else {          } else {
                 (void) strlcpy(buf, pwd->pw_name, sizeof(buf));                  (void) strlcpy(buf, name, sizeof(buf));
         }          }
   
         return(buf);          return(buf);
Line 478 
Line 481 
 {  {
         static char buf[100];          static char buf[100];
         static gid_t lastgid = (gid_t)-1;          static gid_t lastgid = (gid_t)-1;
         struct group *grp = NULL;          const char *name;
   
         /*          /*
          * The value of opts may have changed so we always           * The value of opts may have changed so we always
Line 490 
Line 493 
         }          }
   
         /*          /*
          * Try to avoid getgrgid() call.           * Try to avoid group lookup.
          */           */
         if (lastgid == gid && buf[0] != '\0' && buf[0] != ':')          if (lastgid == gid && buf[0] != '\0' && buf[0] != ':')
                 return(buf);                  return(buf);
   
         lastgid = gid;          lastgid = gid;
   
         if ((grp = (struct group *)getgrgid(gid)) == NULL) {          if ((name = group_from_gid(gid, 1)) == NULL) {
                 if (IS_ON(opts, DO_DEFGROUP) && !isserver)                  if (IS_ON(opts, DO_DEFGROUP) && !isserver)
                         (void) strlcpy(buf, defgroup, sizeof(buf));                          (void) strlcpy(buf, defgroup, sizeof(buf));
                 else {                  else {
Line 506 
Line 509 
                         (void) snprintf(buf, sizeof(buf), ":%u", gid);                          (void) snprintf(buf, sizeof(buf), ":%u", gid);
                 }                  }
         } else          } else
                 (void) strlcpy(buf, grp->gr_name, sizeof(buf));                  (void) strlcpy(buf, name, sizeof(buf));
   
         return(buf);          return(buf);
 }  }
Line 574 
Line 577 
 {  {
         struct passwd *pw;          struct passwd *pw;
         char *pw_dir, *rest;          char *pw_dir, *rest;
           static char lastuser[_PW_NAME_LEN + 1];
           static char lastdir[PATH_MAX];
         size_t len;          size_t len;
   
         if (*file != '~') {          if (*file != '~') {
Line 595 
Line 600 
                 else                  else
                         rest = NULL;                          rest = NULL;
                 if (strcmp(locuser, file) != 0) {                  if (strcmp(locuser, file) != 0) {
                         if ((pw = getpwnam(file)) == NULL) {                          if (strcmp(lastuser, file) != 0) {
                                 error("%s: unknown user name", file);                                  if ((pw = getpwnam(file)) == NULL) {
                                 if (rest != NULL)                                          error("%s: unknown user name", file);
                                         *rest = '/';                                          if (rest != NULL)
                                 return(NULL);                                                  *rest = '/';
                                           return(NULL);
                                   }
                                   strlcpy(lastuser, pw->pw_name, sizeof(lastuser));
                                   strlcpy(lastdir, pw->pw_dir, sizeof(lastdir));
                         }                          }
                         pw_dir = pw->pw_dir;                          pw_dir = lastdir;
                 }                  }
                 if (rest != NULL)                  if (rest != NULL)
                         *rest = '/';                          *rest = '/';

Legend:
Removed from v.1.38  
changed lines
  Added in v.1.39