version 1.43.2.3, 2001/03/21 19:46:28 |
version 1.43.2.4, 2001/05/07 21:09:33 |
|
|
#include "atomicio.h" |
#include "atomicio.h" |
#include "pathnames.h" |
#include "pathnames.h" |
#include "log.h" |
#include "log.h" |
|
#include "scp-common.h" |
|
|
/* For progressmeter() -- number of seconds before xfer considered "stalled" */ |
/* For progressmeter() -- number of seconds before xfer considered "stalled" */ |
#define STALLTIME 5 |
#define STALLTIME 5 |
|
|
static struct timeval start; |
static struct timeval start; |
|
|
/* Number of bytes of current file transferred so far. */ |
/* Number of bytes of current file transferred so far. */ |
volatile u_long statbytes; |
volatile off_t statbytes; |
|
|
/* Total size of current file. */ |
/* Total size of current file. */ |
off_t totalbytes = 0; |
off_t totalbytes = 0; |
|
|
char *buf; |
char *buf; |
} BUF; |
} BUF; |
|
|
extern int iamremote; |
|
|
|
BUF *allocbuf(BUF *, int, int); |
BUF *allocbuf(BUF *, int, int); |
char *colon(char *); |
|
void lostconn(int); |
void lostconn(int); |
void nospace(void); |
void nospace(void); |
int okname(char *); |
int okname(char *); |
|
|
#define CMDNEEDS 64 |
#define CMDNEEDS 64 |
char cmd[CMDNEEDS]; /* must hold "rcp -r -p -d\0" */ |
char cmd[CMDNEEDS]; /* must hold "rcp -r -p -d\0" */ |
|
|
int main(int, char *[]); |
|
int response(void); |
int response(void); |
void rsource(char *, struct stat *); |
void rsource(char *, struct stat *); |
void sink(int, char *[]); |
void sink(int, char *[]); |
void source(int, char *[]); |
void source(int, char *[]); |
void tolocal(int, char *[]); |
void tolocal(int, char *[]); |
char *cleanhostname(char *); |
|
void toremote(char *, int, char *[]); |
void toremote(char *, int, char *[]); |
void usage(void); |
void usage(void); |
|
|
|
|
iamremote = 1; |
iamremote = 1; |
tflag = 1; |
tflag = 1; |
break; |
break; |
case '?': |
|
default: |
default: |
usage(); |
usage(); |
} |
} |
|
|
exit(errs != 0); |
exit(errs != 0); |
} |
} |
|
|
char * |
|
cleanhostname(host) |
|
char *host; |
|
{ |
|
if (*host == '[' && host[strlen(host) - 1] == ']') { |
|
host[strlen(host) - 1] = '\0'; |
|
return (host + 1); |
|
} else |
|
return host; |
|
} |
|
|
|
void |
void |
toremote(targ, argc, argv) |
toremote(targ, argc, argv) |
char *targ, *argv[]; |
char *targ, *argv[]; |
|
|
struct stat stb; |
struct stat stb; |
static BUF buffer; |
static BUF buffer; |
BUF *bp; |
BUF *bp; |
off_t i; |
off_t i, amt, result; |
int amt, fd, haderr, indx, result; |
int fd, haderr, indx; |
char *last, *name, buf[2048]; |
char *last, *name, buf[2048]; |
|
int len; |
|
|
for (indx = 0; indx < argc; ++indx) { |
for (indx = 0; indx < argc; ++indx) { |
name = argv[indx]; |
name = argv[indx]; |
statbytes = 0; |
statbytes = 0; |
|
len = strlen(name); |
|
while (len > 1 && name[len-1] == '/') |
|
name[--len] = '\0'; |
if ((fd = open(name, O_RDONLY, 0)) < 0) |
if ((fd = open(name, O_RDONLY, 0)) < 0) |
goto syserr; |
goto syserr; |
if (fstat(fd, &stb) < 0) { |
if (fstat(fd, &stb) < 0) { |
|
|
#define FILEMODEMASK (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO) |
#define FILEMODEMASK (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO) |
snprintf(buf, sizeof buf, "C%04o %lld %s\n", |
snprintf(buf, sizeof buf, "C%04o %lld %s\n", |
(u_int) (stb.st_mode & FILEMODEMASK), |
(u_int) (stb.st_mode & FILEMODEMASK), |
stb.st_size, last); |
(long long)stb.st_size, last); |
if (verbose_mode) { |
if (verbose_mode) { |
fprintf(stderr, "Sending file modes: %s", buf); |
fprintf(stderr, "Sending file modes: %s", buf); |
fflush(stderr); |
fflush(stderr); |
|
|
closedir(dirp); |
closedir(dirp); |
return; |
return; |
} |
} |
while ((dp = readdir(dirp))) { |
while ((dp = readdir(dirp)) != NULL) { |
if (dp->d_ino == 0) |
if (dp->d_ino == 0) |
continue; |
continue; |
if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) |
if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) |
|
|
off_t size; |
off_t size; |
int setimes, targisdir, wrerrno = 0; |
int setimes, targisdir, wrerrno = 0; |
char ch, *cp, *np, *targ, *why, *vect[1], buf[2048]; |
char ch, *cp, *np, *targ, *why, *vect[1], buf[2048]; |
int dummy_usec; |
|
struct timeval tv[2]; |
struct timeval tv[2]; |
|
|
|
#define atime tv[0] |
|
#define mtime tv[1] |
#define SCREWUP(str) { why = str; goto screwup; } |
#define SCREWUP(str) { why = str; goto screwup; } |
|
|
setimes = targisdir = 0; |
setimes = targisdir = 0; |
|
|
if (ch == '\n') |
if (ch == '\n') |
*--cp = 0; |
*--cp = 0; |
|
|
#define getnum(t) (t) = 0; \ |
|
while (*cp >= '0' && *cp <= '9') (t) = (t) * 10 + (*cp++ - '0'); |
|
cp = buf; |
cp = buf; |
if (*cp == 'T') { |
if (*cp == 'T') { |
setimes++; |
setimes++; |
cp++; |
cp++; |
getnum(tv[1].tv_sec); |
mtime.tv_sec = strtol(cp, &cp, 10); |
if (*cp++ != ' ') |
if (!cp || *cp++ != ' ') |
SCREWUP("mtime.sec not delimited"); |
SCREWUP("mtime.sec not delimited"); |
getnum(dummy_usec); |
mtime.tv_usec = strtol(cp, &cp, 10); |
tv[1].tv_usec = 0; |
if (!cp || *cp++ != ' ') |
if (*cp++ != ' ') |
|
SCREWUP("mtime.usec not delimited"); |
SCREWUP("mtime.usec not delimited"); |
getnum(tv[0].tv_sec); |
atime.tv_sec = strtol(cp, &cp, 10); |
if (*cp++ != ' ') |
if (!cp || *cp++ != ' ') |
SCREWUP("atime.sec not delimited"); |
SCREWUP("atime.sec not delimited"); |
getnum(dummy_usec); |
atime.tv_usec = strtol(cp, &cp, 10); |
tv[0].tv_usec = 0; |
if (!cp || *cp++ != '\0') |
if (*cp++ != '\0') |
|
SCREWUP("atime.usec not delimited"); |
SCREWUP("atime.usec not delimited"); |
(void) atomicio(write, remout, "", 1); |
(void) atomicio(write, remout, "", 1); |
continue; |
continue; |
|
|
if (*cp++ != ' ') |
if (*cp++ != ' ') |
SCREWUP("mode not delimited"); |
SCREWUP("mode not delimited"); |
|
|
for (size = 0; *cp >= '0' && *cp <= '9';) |
for (size = 0; isdigit(*cp);) |
size = size * 10 + (*cp++ - '0'); |
size = size * 10 + (*cp++ - '0'); |
if (*cp++ != ' ') |
if (*cp++ != ' ') |
SCREWUP("size not delimited"); |
SCREWUP("size not delimited"); |
|
|
continue; |
continue; |
} else if (j <= 0) { |
} else if (j <= 0) { |
run_err("%s", j ? strerror(errno) : |
run_err("%s", j ? strerror(errno) : |
"dropped connection"); |
"dropped connection"); |
exit(1); |
exit(1); |
} |
} |
amt -= j; |
amt -= j; |
|
|
if (exists || omode != mode) |
if (exists || omode != mode) |
if (fchmod(ofd, omode)) |
if (fchmod(ofd, omode)) |
run_err("%s: set mode: %s", |
run_err("%s: set mode: %s", |
np, strerror(errno)); |
np, strerror(errno)); |
} else { |
} else { |
if (!exists && omode != mode) |
if (!exists && omode != mode) |
if (fchmod(ofd, omode & ~mask)) |
if (fchmod(ofd, omode & ~mask)) |
run_err("%s: set mode: %s", |
run_err("%s: set mode: %s", |
np, strerror(errno)); |
np, strerror(errno)); |
} |
} |
if (close(ofd) == -1) { |
if (close(ofd) == -1) { |
wrerr = YES; |
wrerr = YES; |
|
|
setimes = 0; |
setimes = 0; |
if (utimes(np, tv) < 0) { |
if (utimes(np, tv) < 0) { |
run_err("%s: set times: %s", |
run_err("%s: set times: %s", |
np, strerror(errno)); |
np, strerror(errno)); |
wrerr = DISPLAYED; |
wrerr = DISPLAYED; |
} |
} |
} |
} |
|
|
usage() |
usage() |
{ |
{ |
(void) fprintf(stderr, "usage: scp " |
(void) fprintf(stderr, "usage: scp " |
"[-pqrvC46] [-S ssh] [-P port] [-c cipher] [-i identity] f1 f2; or:\n" |
"[-pqrvBC46] [-S ssh] [-P port] [-c cipher] [-i identity] f1 f2\n" |
" scp [options] f1 ... fn directory\n"); |
" or: scp [options] f1 ... fn directory\n"); |
exit(1); |
exit(1); |
} |
} |
|
|
|
|
fprintf(stderr, "\n"); |
fprintf(stderr, "\n"); |
} |
} |
va_end(ap); |
va_end(ap); |
} |
|
|
|
char * |
|
colon(cp) |
|
char *cp; |
|
{ |
|
int flag = 0; |
|
|
|
if (*cp == ':') /* Leading colon is part of file name. */ |
|
return (0); |
|
if (*cp == '[') |
|
flag = 1; |
|
|
|
for (; *cp; ++cp) { |
|
if (*cp == '@' && *(cp+1) == '[') |
|
flag = 1; |
|
if (*cp == ']' && *(cp+1) == ':' && flag) |
|
return (cp+1); |
|
if (*cp == ':' && !flag) |
|
return (cp); |
|
if (*cp == '/') |
|
return (0); |
|
} |
|
return (0); |
|
} |
} |
|
|
void |
void |