Sync with NetBSD rcp, add v6 parsing support and no setuid code at all.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@23028 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -1,3 +1,8 @@
|
|||||||
|
2008-04-17 Love H<>rnquist <20>strand <lha@it.su.se>
|
||||||
|
|
||||||
|
* Sync with NetBSD rcp, add v6 parsing support and no setuid code
|
||||||
|
at all.
|
||||||
|
|
||||||
2007-12-13 Love H<>rnquist <20>strand <lha@it.su.se>
|
2007-12-13 Love H<>rnquist <20>strand <lha@it.su.se>
|
||||||
|
|
||||||
* Makefile.am: Add missing files, from Buchan Milne.
|
* Makefile.am: Add missing files, from Buchan Milne.
|
||||||
|
@@ -43,9 +43,10 @@ extern int iamremote;
|
|||||||
|
|
||||||
BUF *allocbuf (BUF *, int, int);
|
BUF *allocbuf (BUF *, int, int);
|
||||||
char *colon (char *);
|
char *colon (char *);
|
||||||
|
char *unbracket(char *);
|
||||||
void lostconn (int);
|
void lostconn (int);
|
||||||
void nospace (void);
|
void nospace (void);
|
||||||
int okname (char *);
|
int okname (char *);
|
||||||
void run_err (const char *, ...);
|
void run_err (const char *, ...);
|
||||||
int susystem (char *, int);
|
int susystem (char *);
|
||||||
void verifydir (char *);
|
void verifydir (char *);
|
||||||
|
@@ -10,11 +10,7 @@
|
|||||||
* 2. Redistributions in binary form must reproduce the above copyright
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
* 3. All advertising materials mentioning features or use of this software
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
* must display the following acknowledgement:
|
|
||||||
* This product includes software developed by the University of
|
|
||||||
* California, Berkeley and its contributors.
|
|
||||||
* 4. Neither the name of the University nor the names of its contributors
|
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
@@ -118,16 +114,12 @@ main(int argc, char **argv)
|
|||||||
remout = STDOUT_FILENO;
|
remout = STDOUT_FILENO;
|
||||||
|
|
||||||
if (fflag) { /* Follow "protocol", send data. */
|
if (fflag) { /* Follow "protocol", send data. */
|
||||||
response();
|
(void)response();
|
||||||
if (setuid(userid) < 0)
|
|
||||||
errx(1, "setuid failed");
|
|
||||||
source(argc, argv);
|
source(argc, argv);
|
||||||
exit(errs);
|
exit(errs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tflag) { /* Receive data. */
|
if (tflag) { /* Receive data. */
|
||||||
if (setuid(userid) < 0)
|
|
||||||
errx(1, "setuid failed");
|
|
||||||
sink(argc, argv);
|
sink(argc, argv);
|
||||||
exit(errs);
|
exit(errs);
|
||||||
}
|
}
|
||||||
@@ -165,7 +157,7 @@ toremote(char *targ, int argc, char **argv)
|
|||||||
if (*targ == 0)
|
if (*targ == 0)
|
||||||
targ = ".";
|
targ = ".";
|
||||||
|
|
||||||
if ((thost = strchr(argv[argc - 1], '@'))) {
|
if ((thost = strchr(argv[argc - 1], '@')) != NULL) {
|
||||||
/* user@host */
|
/* user@host */
|
||||||
*thost++ = 0;
|
*thost++ = 0;
|
||||||
tuser = argv[argc - 1];
|
tuser = argv[argc - 1];
|
||||||
@@ -177,6 +169,7 @@ toremote(char *targ, int argc, char **argv)
|
|||||||
thost = argv[argc - 1];
|
thost = argv[argc - 1];
|
||||||
tuser = NULL;
|
tuser = NULL;
|
||||||
}
|
}
|
||||||
|
thost = unbracket(thost);
|
||||||
|
|
||||||
for (i = 0; i < argc - 1; i++) {
|
for (i = 0; i < argc - 1; i++) {
|
||||||
src = colon(argv[i]);
|
src = colon(argv[i]);
|
||||||
@@ -188,6 +181,7 @@ toremote(char *targ, int argc, char **argv)
|
|||||||
host = strchr(argv[i], '@');
|
host = strchr(argv[i], '@');
|
||||||
if (host) {
|
if (host) {
|
||||||
*host++ = '\0';
|
*host++ = '\0';
|
||||||
|
host = unbracket(host);
|
||||||
suser = argv[i];
|
suser = argv[i];
|
||||||
if (*suser == '\0')
|
if (*suser == '\0')
|
||||||
suser = pwd->pw_name;
|
suser = pwd->pw_name;
|
||||||
@@ -200,16 +194,17 @@ toremote(char *targ, int argc, char **argv)
|
|||||||
tuser ? tuser : "", tuser ? "@" : "",
|
tuser ? tuser : "", tuser ? "@" : "",
|
||||||
thost, targ);
|
thost, targ);
|
||||||
} else {
|
} else {
|
||||||
|
host = unbracket(argv[i]);
|
||||||
ret = asprintf(&bp,
|
ret = asprintf(&bp,
|
||||||
"exec %s%s %s -n %s %s '%s%s%s:%s'",
|
"exec %s%s %s -n %s %s '%s%s%s:%s'",
|
||||||
_PATH_RSH, eflag ? " -e" : "",
|
_PATH_RSH, eflag ? " -e" : "",
|
||||||
argv[i], cmd, src,
|
host, cmd, src,
|
||||||
tuser ? tuser : "", tuser ? "@" : "",
|
tuser ? tuser : "", tuser ? "@" : "",
|
||||||
thost, targ);
|
thost, targ);
|
||||||
}
|
}
|
||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
err (1, "malloc");
|
err (1, "malloc");
|
||||||
susystem(bp, userid);
|
susystem(bp);
|
||||||
free(bp);
|
free(bp);
|
||||||
} else { /* local to remote */
|
} else { /* local to remote */
|
||||||
if (remin == -1) {
|
if (remin == -1) {
|
||||||
@@ -223,8 +218,6 @@ toremote(char *targ, int argc, char **argv)
|
|||||||
if (response() < 0)
|
if (response() < 0)
|
||||||
exit(1);
|
exit(1);
|
||||||
free(bp);
|
free(bp);
|
||||||
if (setuid(userid) < 0)
|
|
||||||
errx(1, "setuid failed");
|
|
||||||
}
|
}
|
||||||
source(1, argv+i);
|
source(1, argv+i);
|
||||||
}
|
}
|
||||||
@@ -246,7 +239,7 @@ tolocal(int argc, char **argv)
|
|||||||
argv[i], argv[argc - 1]);
|
argv[i], argv[argc - 1]);
|
||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
err (1, "malloc");
|
err (1, "malloc");
|
||||||
if (susystem(bp, userid))
|
if (susystem(bp))
|
||||||
++errs;
|
++errs;
|
||||||
free(bp);
|
free(bp);
|
||||||
continue;
|
continue;
|
||||||
@@ -275,8 +268,6 @@ tolocal(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
free(bp);
|
free(bp);
|
||||||
sink(1, argv + argc - 1);
|
sink(1, argv + argc - 1);
|
||||||
if (seteuid(0) < 0)
|
|
||||||
exit(1);
|
|
||||||
close(remin);
|
close(remin);
|
||||||
remin = remout = -1;
|
remin = remout = -1;
|
||||||
}
|
}
|
||||||
@@ -289,7 +280,8 @@ source(int argc, char **argv)
|
|||||||
static BUF buffer;
|
static BUF buffer;
|
||||||
BUF *bp;
|
BUF *bp;
|
||||||
off_t i;
|
off_t i;
|
||||||
int amt, fd, haderr, indx, result;
|
off_t amt;
|
||||||
|
int fd, haderr, indx, result;
|
||||||
char *last, *name, buf[BUFSIZ];
|
char *last, *name, buf[BUFSIZ];
|
||||||
|
|
||||||
for (indx = 0; indx < argc; ++indx) {
|
for (indx = 0; indx < argc; ++indx) {
|
||||||
@@ -349,14 +341,14 @@ next: close(fd);
|
|||||||
if (i + amt > stb.st_size)
|
if (i + amt > stb.st_size)
|
||||||
amt = stb.st_size - i;
|
amt = stb.st_size - i;
|
||||||
if (!haderr) {
|
if (!haderr) {
|
||||||
result = read(fd, bp->buf, amt);
|
result = read(fd, bp->buf, (size_t)amt);
|
||||||
if (result != amt)
|
if (result != amt)
|
||||||
haderr = result >= 0 ? EIO : errno;
|
haderr = result >= 0 ? EIO : errno;
|
||||||
}
|
}
|
||||||
if (haderr)
|
if (haderr)
|
||||||
write(remout, bp->buf, amt);
|
write(remout, bp->buf, amt);
|
||||||
else {
|
else {
|
||||||
result = write(remout, bp->buf, amt);
|
result = write(remout, bp->buf, (size_t)amt);
|
||||||
if (result != amt)
|
if (result != amt)
|
||||||
haderr = result >= 0 ? EIO : errno;
|
haderr = result >= 0 ? EIO : errno;
|
||||||
}
|
}
|
||||||
@@ -404,7 +396,7 @@ rsource(char *name, struct stat *statp)
|
|||||||
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, ".."))
|
||||||
@@ -600,7 +592,7 @@ bad: run_err("%s: %s", np, strerror(errno));
|
|||||||
if (count == bp->cnt) {
|
if (count == bp->cnt) {
|
||||||
/* Keep reading so we stay sync'd up. */
|
/* Keep reading so we stay sync'd up. */
|
||||||
if (wrerr == NO) {
|
if (wrerr == NO) {
|
||||||
j = write(ofd, bp->buf, count);
|
j = write(ofd, bp->buf, (size_t)count);
|
||||||
if (j != count) {
|
if (j != count) {
|
||||||
wrerr = YES;
|
wrerr = YES;
|
||||||
wrerrno = j >= 0 ? EIO : errno;
|
wrerrno = j >= 0 ? EIO : errno;
|
||||||
@@ -611,7 +603,7 @@ bad: run_err("%s: %s", np, strerror(errno));
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (count != 0 && wrerr == NO &&
|
if (count != 0 && wrerr == NO &&
|
||||||
(j = write(ofd, bp->buf, count)) != count) {
|
(j = write(ofd, bp->buf, (size_t)count)) != count) {
|
||||||
wrerr = YES;
|
wrerr = YES;
|
||||||
wrerrno = j >= 0 ? EIO : errno;
|
wrerrno = j >= 0 ? EIO : errno;
|
||||||
}
|
}
|
||||||
|
@@ -61,6 +61,21 @@ colon(cp)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
unbracket(char *cp)
|
||||||
|
{
|
||||||
|
char *ep;
|
||||||
|
|
||||||
|
if (*cp == '[') {
|
||||||
|
ep = cp + (strlen(cp) - 1);
|
||||||
|
if (*ep == ']') {
|
||||||
|
*ep = '\0';
|
||||||
|
++cp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (cp);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
verifydir(cp)
|
verifydir(cp)
|
||||||
char *cp;
|
char *cp;
|
||||||
@@ -98,8 +113,7 @@ bad: warnx("%s: invalid user name", cp0);
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
susystem(s, userid)
|
susystem(s)
|
||||||
int userid;
|
|
||||||
char *s;
|
char *s;
|
||||||
{
|
{
|
||||||
void (*istat)(int), (*qstat)(int);
|
void (*istat)(int), (*qstat)(int);
|
||||||
@@ -112,8 +126,6 @@ susystem(s, userid)
|
|||||||
return (127);
|
return (127);
|
||||||
|
|
||||||
case 0:
|
case 0:
|
||||||
if (setuid(userid) < 0)
|
|
||||||
_exit(127);
|
|
||||||
execl(_PATH_BSHELL, "sh", "-c", s, NULL);
|
execl(_PATH_BSHELL, "sh", "-c", s, NULL);
|
||||||
_exit(127);
|
_exit(127);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user