Changeset View
Changeset View
Standalone View
Standalone View
sender.c
/* $Id$ */ | /* $Id$ */ | ||||
/* | /* | ||||
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> | * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> | ||||
* | * | ||||
* Permission to use, copy, modify, and distribute this software for any | * Permission to use, copy, modify, and distribute this software for any | ||||
* purpose with or without fee is hereby granted, provided that the above | * purpose with or without fee is hereby granted, provided that the above | ||||
* copyright notice and this permission notice appear in all copies. | * copyright notice and this permission notice appear in all copies. | ||||
* | * | ||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||||
*/ | */ | ||||
#include <sys/capsicum.h> | |||||
#include <sys/mman.h> | #include <sys/mman.h> | ||||
#include <sys/queue.h> | #include <sys/queue.h> | ||||
#include <sys/stat.h> | #include <sys/stat.h> | ||||
#include <assert.h> | #include <assert.h> | ||||
#include <errno.h> | |||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <inttypes.h> | #include <inttypes.h> | ||||
#include <poll.h> | #include <poll.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include "extern.h" | #include "extern.h" | ||||
▲ Show 20 Lines • Show All 373 Lines • ▼ Show 20 Lines | rsync_sender(struct sess *sess, int fdin, | ||||
struct send_dlq sdlq; | struct send_dlq sdlq; | ||||
struct send_dl *dl; | struct send_dl *dl; | ||||
struct send_up up; | struct send_up up; | ||||
struct stat st; | struct stat st; | ||||
void *wbuf = NULL; | void *wbuf = NULL; | ||||
size_t wbufpos = 0, wbufsz = 0, wbufmax = 0; | size_t wbufpos = 0, wbufsz = 0, wbufmax = 0; | ||||
ssize_t ssz; | ssize_t ssz; | ||||
if (pledge("stdio getpw rpath unveil", NULL) == -1) { | cap_rights_t rights; | ||||
ERR(sess, "pledge"); | fileargs_t* fa = fileargs_init(argc, argv, O_RDONLY|O_NONBLOCK, 0, | ||||
cap_rights_init(&rights, CAP_FSTAT, CAP_READ, CAP_EVENT, CAP_MMAP_R)); | |||||
if (fa == NULL) { | |||||
ERR(sess, "fileargs_init"); | |||||
return 0; | return 0; | ||||
} | } | ||||
if (cap_enter() < 0 && errno != ENOSYS) { | |||||
ERR(sess, "cap_enter"); | |||||
return 0; | |||||
} | |||||
memset(&up, 0, sizeof(struct send_up)); | memset(&up, 0, sizeof(struct send_up)); | ||||
TAILQ_INIT(&sdlq); | TAILQ_INIT(&sdlq); | ||||
up.stat.fd = -1; | up.stat.fd = -1; | ||||
up.stat.map = MAP_FAILED; | up.stat.map = MAP_FAILED; | ||||
up.stat.htabsz = 65536; | up.stat.htabsz = 65536; | ||||
up.stat.htab = calloc(up.stat.htabsz, sizeof(struct blkhashq)); | up.stat.htab = calloc(up.stat.htabsz, sizeof(struct blkhashq)); | ||||
if (up.stat.htab == NULL) { | if (up.stat.htab == NULL) { | ||||
ERR(sess, "calloc"); | ERR(sess, "calloc"); | ||||
goto out; | goto out; | ||||
} | } | ||||
/* Initially clear the hashtable. */ | /* Initially clear the hashtable. */ | ||||
for (i = 0; i < up.stat.htabsz; i++) | for (i = 0; i < up.stat.htabsz; i++) | ||||
TAILQ_INIT(&up.stat.htab[i]); | TAILQ_INIT(&up.stat.htab[i]); | ||||
/* | /* | ||||
* Generate the list of files we want to send from our | * Generate the list of files we want to send from our | ||||
* command-line input. | * command-line input. | ||||
* This will also remove all invalid files. | * This will also remove all invalid files. | ||||
*/ | */ | ||||
if (!flist_gen(sess, argc, argv, &fl, &flsz)) { | if (!flist_gen(sess, argc, argv, &fl, &flsz, fa)) { | ||||
ERRX1(sess, "flist_gen"); | ERRX1(sess, "flist_gen"); | ||||
goto out; | goto out; | ||||
} | } | ||||
/* Client sends zero-length exclusions if deleting. */ | /* Client sends zero-length exclusions if deleting. */ | ||||
if (!sess->opts->server && sess->opts->del && | if (!sess->opts->server && sess->opts->del && | ||||
!io_write_int(sess, fdout, 0)) { | !io_write_int(sess, fdout, 0)) { | ||||
▲ Show 20 Lines • Show All 239 Lines • ▼ Show 20 Lines | if (up.cur == NULL) { | ||||
} | } | ||||
/* | /* | ||||
* Non-blocking open of file. | * Non-blocking open of file. | ||||
* This will be picked up in the state machine | * This will be picked up in the state machine | ||||
* block of not being primed. | * block of not being primed. | ||||
*/ | */ | ||||
up.stat.fd = open(fl[up.cur->idx].path, | up.stat.fd = fileargs_open(fa, fl[up.cur->idx].path); | ||||
O_RDONLY|O_NONBLOCK, 0); | |||||
if (up.stat.fd == -1) { | if (up.stat.fd == -1) { | ||||
ERR(sess, "%s: open", fl[up.cur->idx].path); | ERR(sess, "%s: open", fl[up.cur->idx].path); | ||||
goto out; | goto out; | ||||
} | } | ||||
pfd[2].fd = up.stat.fd; | pfd[2].fd = up.stat.fd; | ||||
} | } | ||||
} | } | ||||
Show All 35 Lines |