summaryrefslogtreecommitdiffstats
path: root/qacp.c
diff options
context:
space:
mode:
authorNathan Straz <nstraz@redhat.com>2013-10-02 14:09:14 -0400
committerNathan Straz <nstraz@redhat.com>2013-10-02 14:11:34 -0400
commit8ca5b74eaf0a15248578d4eaf19762d57b44099e (patch)
treec1e48a5ecfde0730249485fc9a4a5862fa8b110f /qacp.c
parentb1c21ed4dc79b4250d604570c7516e267a521792 (diff)
downloadqarsh-8ca5b74eaf0a15248578d4eaf19762d57b44099e.tar.gz
qarsh-8ca5b74eaf0a15248578d4eaf19762d57b44099e.tar.xz
qarsh-8ca5b74eaf0a15248578d4eaf19762d57b44099e.zip
Prevent copying multiple files over one remote file
Also drop the rstat of the parent directory, just let the remote side send us an error.
Diffstat (limited to 'qacp.c')
-rw-r--r--qacp.c55
1 files changed, 15 insertions, 40 deletions
diff --git a/qacp.c b/qacp.c
index b2f4535..4e75a1e 100644
--- a/qacp.c
+++ b/qacp.c
@@ -554,12 +554,11 @@ sendfiles(char **argv, int argc, int fileidx)
int file;
char *rmtpath;
char *destpath;
- char *tmpstr;
char *lbnp; /* local file basename */
- char *rdnp; /* remote path dirname */
struct qp_rstat_pkt *rstatp;
int rstaterrno;
int fail = 0;
+ int destisdir = 0;
if ((rmtpath = strchr(argv[argc-1], ':')) == NULL) {
@@ -608,48 +607,24 @@ sendfiles(char **argv, int argc, int fileidx)
rstatp = qacp_rstat(rmtpath, &rstaterrno);
+ if (rstatp && S_ISDIR(rstatp->qp_st_mode)) {
+ destisdir = 1;
+ } else if ((argc - fileidx) > 2) {
+ fprintf(stderr, "Will not copy multiple files to the same remote file\n");
+ close(qacp_fd);
+ return -1;
+ }
+
for (file = fileidx; file < (argc - 1); file++) {
lbnp = basename(argv[file]);
- if (rstatp) {
- /*
- * If rmtpath is a dir, then we tack on the
- * local files basename.
- */
- if (S_ISDIR(rstatp->qp_st_mode)) {
- destpath = malloc(strlen(rmtpath) + strlen(lbnp) + 2);
- strcpy(destpath, rmtpath);
- if (destpath[strlen(destpath)-1] != '/') strcat(destpath, "/");
- strcat(destpath, lbnp);
- }
-
- /* It rmtpath is a file, then we leave it as is */
- if (S_ISREG(rstatp->qp_st_mode)) {
- destpath = strdup(rmtpath);
- }
+ if (destisdir) {
+ destpath = malloc(strlen(rmtpath) + strlen(lbnp) + 2);
+ strcpy(destpath, rmtpath);
+ if (destpath[strlen(destpath)-1] != '/') strcat(destpath, "/");
+ strcat(destpath, lbnp);
} else {
- struct qp_rstat_pkt *tmprstatp;
-
- /* rmtpath does not exist, check if the dirname does */
- tmpstr = strdup(rmtpath);
- rdnp = strdup(dirname(tmpstr));
- free(tmpstr);
-
- tmprstatp = qacp_rstat(rdnp, &rstaterrno);
- free(rdnp);
-
- if (tmprstatp) {
- /* Ok, the dir exists, i.e. rmtpath is /tmp/foo
- * and the first rstat was an error. Now we know
- * that /tmp exists, we leave destpath == rmtpath.
- */
- destpath = strdup(rmtpath);
- free_rstat(tmprstatp);
- } else {
- fprintf(stderr, "%s:%s - %s\n", rhost, rmtpath,
- strerror(rstaterrno));
- return -1;
- }
+ destpath = strdup(rmtpath);
}
if (qacp_sendonefile(rhost, argv[file], destpath) < 0) {