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

Diff for /src/usr.bin/rsync/main.c between version 1.24 and 1.25

version 1.24, 2019/02/17 15:59:09 version 1.25, 2019/02/17 17:19:05
Line 98 
Line 98 
         /* Allocations. */          /* Allocations. */
   
         if ((f = calloc(1, sizeof(struct fargs))) == NULL)          if ((f = calloc(1, sizeof(struct fargs))) == NULL)
                 err(EXIT_FAILURE, "calloc");                  err(1, "calloc");
   
         f->sourcesz = argc - 1;          f->sourcesz = argc - 1;
         if ((f->sources = calloc(f->sourcesz, sizeof(char *))) == NULL)          if ((f->sources = calloc(f->sourcesz, sizeof(char *))) == NULL)
                 err(EXIT_FAILURE, "calloc");                  err(1, "calloc");
   
         for (i = 0; i < argc - 1; i++)          for (i = 0; i < argc - 1; i++)
                 if ((f->sources[i] = strdup(argv[i])) == NULL)                  if ((f->sources[i] = strdup(argv[i])) == NULL)
                         err(EXIT_FAILURE, "strdup");                          err(1, "strdup");
   
         if ((f->sink = strdup(argv[i])) == NULL)          if ((f->sink = strdup(argv[i])) == NULL)
                 err(EXIT_FAILURE, "strdup");                  err(1, "strdup");
   
         /*          /*
          * Test files for its locality.           * Test files for its locality.
Line 124 
Line 124 
         if (fargs_is_remote(f->sink)) {          if (fargs_is_remote(f->sink)) {
                 f->mode = FARGS_SENDER;                  f->mode = FARGS_SENDER;
                 if ((f->host = strdup(f->sink)) == NULL)                  if ((f->host = strdup(f->sink)) == NULL)
                         err(EXIT_FAILURE, "strdup");                          err(1, "strdup");
         }          }
   
         if (fargs_is_remote(f->sources[0])) {          if (fargs_is_remote(f->sources[0])) {
                 if (f->host != NULL)                  if (f->host != NULL)
                         errx(EXIT_FAILURE, "both source and "                          errx(1, "both source and "
                                 "destination cannot be remote files");                                  "destination cannot be remote files");
                 f->mode = FARGS_RECEIVER;                  f->mode = FARGS_RECEIVER;
                 if ((f->host = strdup(f->sources[0])) == NULL)                  if ((f->host = strdup(f->sources[0])) == NULL)
                         err(EXIT_FAILURE, "strdup");                          err(1, "strdup");
         }          }
   
         if (f->host != NULL) {          if (f->host != NULL) {
Line 143 
Line 143 
                         len = strlen(f->host) - 8 + 1;                          len = strlen(f->host) - 8 + 1;
                         memmove(f->host, f->host + 8, len);                          memmove(f->host, f->host + 8, len);
                         if ((cp = strchr(f->host, '/')) == NULL)                          if ((cp = strchr(f->host, '/')) == NULL)
                                 errx(EXIT_FAILURE, "rsync protocol "                                  errx(1, "rsync protocol "
                                         "requires a module name");                                          "requires a module name");
                         *cp++ = '\0';                          *cp++ = '\0';
                         f->module = cp;                          f->module = cp;
Line 164 
Line 164 
                         }                          }
                 }                  }
                 if ((len = strlen(f->host)) == 0)                  if ((len = strlen(f->host)) == 0)
                         errx(EXIT_FAILURE, "empty remote host");                          errx(1, "empty remote host");
                 if (f->remote && strlen(f->module) == 0)                  if (f->remote && strlen(f->module) == 0)
                         errx(EXIT_FAILURE, "empty remote module");                          errx(1, "empty remote module");
         }          }
   
         /* Make sure we have the same "hostspec" for all files. */          /* Make sure we have the same "hostspec" for all files. */
Line 176 
Line 176 
                         for (i = 0; i < f->sourcesz; i++) {                          for (i = 0; i < f->sourcesz; i++) {
                                 if (!fargs_is_remote(f->sources[i]))                                  if (!fargs_is_remote(f->sources[i]))
                                         continue;                                          continue;
                                 errx(EXIT_FAILURE, "remote file in "                                  errx(1, "remote file in "
                                         "list of local sources: %s",                                          "list of local sources: %s",
                                         f->sources[i]);                                          f->sources[i]);
                         }                          }
Line 186 
Line 186 
                                     !fargs_is_daemon(f->sources[i]))                                      !fargs_is_daemon(f->sources[i]))
                                         continue;                                          continue;
                                 if (fargs_is_daemon(f->sources[i]))                                  if (fargs_is_daemon(f->sources[i]))
                                         errx(EXIT_FAILURE, "remote "                                          errx(1, "remote "
                                                 "daemon in list of "                                                  "daemon in list of "
                                                 "remote sources: %s",                                                  "remote sources: %s",
                                                 f->sources[i]);                                                  f->sources[i]);
                                 errx(EXIT_FAILURE, "local file in "                                  errx(1, "local file in "
                                         "list of remote sources: %s",                                          "list of remote sources: %s",
                                         f->sources[i]);                                          f->sources[i]);
                         }                          }
         } else {          } else {
                 if (f->mode != FARGS_RECEIVER)                  if (f->mode != FARGS_RECEIVER)
                         errx(EXIT_FAILURE, "sender mode for remote "                          errx(1, "sender mode for remote "
                                 "daemon receivers not yet supported");                                  "daemon receivers not yet supported");
                 for (i = 0; i < f->sourcesz; i++) {                  for (i = 0; i < f->sourcesz; i++) {
                         if (fargs_is_daemon(f->sources[i]))                          if (fargs_is_daemon(f->sources[i]))
                                 continue;                                  continue;
                         errx(EXIT_FAILURE, "non-remote daemon file "                          errx(1, "non-remote daemon file "
                                 "in list of remote daemon sources: "                                  "in list of remote daemon sources: "
                                 "%s", f->sources[i]);                                  "%s", f->sources[i]);
                 }                  }
Line 245 
Line 245 
                         cp += 8;                          cp += 8;
                         if (strncmp(cp, f->host, len) ||                          if (strncmp(cp, f->host, len) ||
                             (cp[len] != '/' && cp[len] != '\0'))                              (cp[len] != '/' && cp[len] != '\0'))
                                 errx(EXIT_FAILURE, "different remote "                                  errx(1, "different remote "
                                         "host: %s", f->sources[i]);                                          "host: %s", f->sources[i]);
                         memmove(f->sources[i],                          memmove(f->sources[i],
                                 f->sources[i] + len + 8 + 1,                                  f->sources[i] + len + 8 + 1,
Line 258 
Line 258 
                         /* host::path */                          /* host::path */
                         if (strncmp(cp, f->host, len) ||                          if (strncmp(cp, f->host, len) ||
                             (cp[len] != ':' && cp[len] != '\0'))                              (cp[len] != ':' && cp[len] != '\0'))
                                 errx(EXIT_FAILURE, "different remote "                                  errx(1, "different remote "
                                         "host: %s", f->sources[i]);                                          "host: %s", f->sources[i]);
                         memmove(f->sources[i], f->sources[i] + len + 2,                          memmove(f->sources[i], f->sources[i] + len + 2,
                             j - len - 1);                              j - len - 1);
Line 269 
Line 269 
                         /* host:path */                          /* host:path */
                         if (strncmp(cp, f->host, len) ||                          if (strncmp(cp, f->host, len) ||
                             (cp[len] != ':' && cp[len] != '\0'))                              (cp[len] != ':' && cp[len] != '\0'))
                                 errx(EXIT_FAILURE, "different remote "                                  errx(1, "different remote "
                                         "host: %s", f->sources[i]);                                          "host: %s", f->sources[i]);
                         memmove(f->sources[i],                          memmove(f->sources[i],
                                 f->sources[i] + len + 1, j - len);                                  f->sources[i] + len + 1, j - len);
Line 321 
Line 321 
   
         if (pledge("stdio unix rpath wpath cpath dpath inet fattr chown dns getpw proc exec unveil",          if (pledge("stdio unix rpath wpath cpath dpath inet fattr chown dns getpw proc exec unveil",
             NULL) == -1)              NULL) == -1)
                 err(EXIT_FAILURE, "pledge");                  err(1, "pledge");
   
         memset(&opts, 0, sizeof(struct opts));          memset(&opts, 0, sizeof(struct opts));
   
Line 401 
Line 401 
   
         if (opts.server) {          if (opts.server) {
                 if (pledge("stdio unix rpath wpath cpath dpath fattr chown getpw unveil", NULL) == -1)                  if (pledge("stdio unix rpath wpath cpath dpath fattr chown getpw unveil", NULL) == -1)
                         err(EXIT_FAILURE, "pledge");                          err(1, "pledge");
                 return rsync_server(&opts, (size_t)argc, argv);                  return rsync_server(&opts, (size_t)argc, argv);
         }          }
   
Line 428 
Line 428 
                 assert(fargs->mode == FARGS_RECEIVER);                  assert(fargs->mode == FARGS_RECEIVER);
                 if (pledge("stdio unix rpath wpath cpath dpath inet fattr chown dns getpw unveil",                  if (pledge("stdio unix rpath wpath cpath dpath inet fattr chown dns getpw unveil",
                     NULL) == -1)                      NULL) == -1)
                         err(EXIT_FAILURE, "pledge");                          err(1, "pledge");
                 rc = rsync_socket(&opts, fargs);                  rc = rsync_socket(&opts, fargs);
                 fargs_free(fargs);                  fargs_free(fargs);
                 return rc;                  return rc;
Line 438 
Line 438 
   
         if (pledge("stdio unix rpath wpath cpath dpath fattr chown getpw proc exec unveil",          if (pledge("stdio unix rpath wpath cpath dpath fattr chown getpw proc exec unveil",
             NULL) == -1)              NULL) == -1)
                 err(EXIT_FAILURE, "pledge");                  err(1, "pledge");
   
         /* Create a bidirectional socket and start our child. */          /* Create a bidirectional socket and start our child. */
   
         if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0, fds) == -1)          if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0, fds) == -1)
                 err(EXIT_FAILURE, "socketpair");                  err(1, "socketpair");
   
         if ((child = fork()) == -1) {          if ((child = fork()) == -1) {
                 close(fds[0]);                  close(fds[0]);
                 close(fds[1]);                  close(fds[1]);
                 err(EXIT_FAILURE, "fork");                  err(1, "fork");
         }          }
   
         /* Drop the fork possibility. */          /* Drop the fork possibility. */
   
         if (pledge("stdio unix rpath wpath cpath dpath fattr chown getpw exec unveil", NULL) == -1)          if (pledge("stdio unix rpath wpath cpath dpath fattr chown getpw exec unveil", NULL) == -1)
                 err(EXIT_FAILURE, "pledge");                  err(1, "pledge");
   
         if (child == 0) {          if (child == 0) {
                 close(fds[0]);                  close(fds[0]);
                 fds[0] = -1;                  fds[0] = -1;
                 if (pledge("stdio exec", NULL) == -1)                  if (pledge("stdio exec", NULL) == -1)
                         err(EXIT_FAILURE, "pledge");                          err(1, "pledge");
                 rsync_child(&opts, fds[1], fargs);                  rsync_child(&opts, fds[1], fargs);
                 /* NOTREACHED */                  /* NOTREACHED */
         }          }
Line 468 
Line 468 
         close(fds[1]);          close(fds[1]);
         fds[1] = -1;          fds[1] = -1;
         if (pledge("stdio unix rpath wpath cpath dpath fattr chown getpw unveil", NULL) == -1)          if (pledge("stdio unix rpath wpath cpath dpath fattr chown getpw unveil", NULL) == -1)
                 err(EXIT_FAILURE, "pledge");                  err(1, "pledge");
         rc = rsync_client(&opts, fds[0], fargs);          rc = rsync_client(&opts, fds[0], fargs);
         fargs_free(fargs);          fargs_free(fargs);
   
Line 484 
Line 484 
         }          }
   
         if (waitpid(child, &st, 0) == -1)          if (waitpid(child, &st, 0) == -1)
                 err(EXIT_FAILURE, "waitpid");                  err(1, "waitpid");
         if (!(WIFEXITED(st) && WEXITSTATUS(st) == EXIT_SUCCESS))          if (!(WIFEXITED(st) && WEXITSTATUS(st) == 0))
                 rc = 0;                  rc = 0;
   
         if (fds[0] != -1)          if (fds[0] != -1)
Line 495 
Line 495 
         fprintf(stderr, "usage: %s [-Daglnoprtv] "          fprintf(stderr, "usage: %s [-Daglnoprtv] "
                 "[-e ssh-prog] [--delete] [--rsync-path=prog] src ... dst\n",                  "[-e ssh-prog] [--delete] [--rsync-path=prog] src ... dst\n",
                 getprogname());                  getprogname());
         return EXIT_FAILURE;          return 1;
 }  }

Legend:
Removed from v.1.24  
changed lines
  Added in v.1.25