version 1.4, 1996/07/19 21:57:34 |
version 1.5, 1996/07/25 05:13:49 |
|
|
|
|
rem = 0; |
rem = 0; |
oumask = umask(0); |
oumask = umask(0); |
(void) sprintf(buf, "V%d\n", VERSION); |
(void) snprintf(buf, BUFSIZ, "V%d\n", VERSION); |
(void) write(rem, buf, strlen(buf)); |
(void) write(rem, buf, strlen(buf)); |
|
|
if (getuid() != geteuid()) { |
if (getuid() != geteuid()) { |
|
|
/* |
/* |
* Pass the destination file/directory name to remote. |
* Pass the destination file/directory name to remote. |
*/ |
*/ |
(void) sprintf(buf, "%c%s\n", destdir ? 'T' : 't', dest); |
(void) snprintf(buf, BUFSIZ, "%c%s\n", destdir ? 'T' : 't', dest); |
if (debug) |
if (debug) |
printf("buf = %s", buf); |
printf("buf = %s", buf); |
(void) write(rem, buf, strlen(buf)); |
(void) write(rem, buf, strlen(buf)); |
|
|
log(lfp, "%s: no password entry for uid %d \n", |
log(lfp, "%s: no password entry for uid %d \n", |
target, stb.st_uid); |
target, stb.st_uid); |
pw = NULL; |
pw = NULL; |
(void)sprintf(user, ":%lu", stb.st_uid); |
(void) snprintf(user, sizeof(user), ":%lu", stb.st_uid); |
} |
} |
if (gr == NULL || gr->gr_gid != stb.st_gid) |
if (gr == NULL || gr->gr_gid != stb.st_gid) |
if ((gr = getgrgid(stb.st_gid)) == NULL) { |
if ((gr = getgrgid(stb.st_gid)) == NULL) { |
log(lfp, "%s: no name for group %d\n", |
log(lfp, "%s: no name for group %d\n", |
target, stb.st_gid); |
target, stb.st_gid); |
gr = NULL; |
gr = NULL; |
(void)sprintf(group, ":%lu", stb.st_gid); |
(void) snprintf(group, sizeof(group), ":%lu", stb.st_gid); |
} |
} |
if (u == 1) { |
if (u == 1) { |
if (opts & VERIFY) { |
if (opts & VERIFY) { |
|
|
error("%s: %s\n", target, strerror(errno)); |
error("%s: %s\n", target, strerror(errno)); |
return; |
return; |
} |
} |
(void) sprintf(buf, "D%o %04o 0 0 %s %s %s\n", opts, |
(void) snprintf(buf, BUFSIZ, "D%o %04o 0 0 %s %s %s\n", opts, |
stb.st_mode & 07777, protoname(), protogroup(), rname); |
stb.st_mode & 07777, protoname(), protogroup(), rname); |
if (debug) |
if (debug) |
printf("buf = %s", buf); |
printf("buf = %s", buf); |
|
|
if ((lp = savelink(&stb)) != NULL) { |
if ((lp = savelink(&stb)) != NULL) { |
/* install link */ |
/* install link */ |
if (*lp->target == 0) |
if (*lp->target == 0) |
(void) sprintf(buf, "k%o %s %s\n", opts, |
(void) snprintf(buf, BUFSIZ, "k%o %s %s\n", |
lp->pathname, rname); |
opts, lp->pathname, rname); |
else |
else |
(void) sprintf(buf, "k%o %s/%s %s\n", opts, |
(void) snprintf(buf, BUFSIZ, "k%o %s/%s %s\n", |
lp->target, lp->pathname, rname); |
opts, lp->target, lp->pathname, rname); |
if (debug) |
if (debug) |
printf("buf = %s", buf); |
printf("buf = %s", buf); |
(void) write(rem, buf, strlen(buf)); |
(void) write(rem, buf, strlen(buf)); |
|
|
return; |
return; |
} |
} |
} |
} |
(void) sprintf(buf, "K%o %o %qd %ld %s %s %s\n", opts, |
(void) snprintf(buf, BUFSIZ, "K%o %o %qd %ld %s %s %s\n", |
stb.st_mode & 07777, stb.st_size, stb.st_mtime, |
opts, stb.st_mode & 07777, stb.st_size, stb.st_mtime, |
protoname(), protogroup(), rname); |
protoname(), protogroup(), rname); |
if (debug) |
if (debug) |
printf("buf = %s", buf); |
printf("buf = %s", buf); |
|
|
if ((lp = savelink(&stb)) != NULL) { |
if ((lp = savelink(&stb)) != NULL) { |
/* install link */ |
/* install link */ |
if (*lp->target == 0) |
if (*lp->target == 0) |
(void) sprintf(buf, "k%o %s %s\n", opts, |
(void) snprintf(buf, BUFSIZ, "k%o %s %s\n", opts, |
lp->pathname, rname); |
lp->pathname, rname); |
else |
else |
(void) sprintf(buf, "k%o %s/%s %s\n", opts, |
(void) snprintf(buf, BUFSIZ, "k%o %s/%s %s\n", |
lp->target, lp->pathname, rname); |
opts, lp->target, lp->pathname, rname); |
if (debug) |
if (debug) |
printf("buf = %s", buf); |
printf("buf = %s", buf); |
(void) write(rem, buf, strlen(buf)); |
(void) write(rem, buf, strlen(buf)); |
|
|
error("%s: %s\n", target, strerror(errno)); |
error("%s: %s\n", target, strerror(errno)); |
return; |
return; |
} |
} |
(void) sprintf(buf, "R%o %o %qd %ld %s %s %s\n", opts, |
(void) snprintf(buf, BUFSIZ, "R%o %o %qd %ld %s %s %s\n", opts, |
stb.st_mode & 07777, stb.st_size, stb.st_mtime, |
stb.st_mode & 07777, stb.st_size, stb.st_mtime, |
protoname(), protogroup(), rname); |
protoname(), protogroup(), rname); |
if (debug) |
if (debug) |
|
|
log(lfp, "special \"%s\"\n", sc->sc_name); |
log(lfp, "special \"%s\"\n", sc->sc_name); |
if (opts & VERIFY) |
if (opts & VERIFY) |
continue; |
continue; |
(void) sprintf(buf, "SFILE=%s;%s\n", target, sc->sc_name); |
(void) snprintf(buf, BUFSIZ, "SFILE=%s;%s\n", target, |
|
sc->sc_name); |
if (debug) |
if (debug) |
printf("buf = %s", buf); |
printf("buf = %s", buf); |
(void) write(rem, buf, strlen(buf)); |
(void) write(rem, buf, strlen(buf)); |
|
|
/* |
/* |
* Check to see if the file exists on the remote machine. |
* Check to see if the file exists on the remote machine. |
*/ |
*/ |
(void) sprintf(buf, "Q%s\n", rname); |
(void) snprintf(buf, BUFSIZ, "Q%s\n", rname); |
if (debug) |
if (debug) |
printf("buf = %s", buf); |
printf("buf = %s", buf); |
(void) write(rem, buf, strlen(buf)); |
(void) write(rem, buf, strlen(buf)); |
|
|
|
|
switch (stb.st_mode & S_IFMT) { |
switch (stb.st_mode & S_IFMT) { |
case S_IFREG: |
case S_IFREG: |
(void) sprintf(buf, "Y%qd %ld\n", stb.st_size, |
(void) snprintf(buf, BUFSIZ, "Y%qd %ld\n", stb.st_size, |
stb.st_mtime); |
stb.st_mtime); |
(void) write(rem, buf, strlen(buf)); |
(void) write(rem, buf, strlen(buf)); |
break; |
break; |
|
|
return; |
return; |
} |
} |
buf[0] = '\0'; |
buf[0] = '\0'; |
(void) sprintf(buf + 1, |
(void) snprintf(buf + 1, BUFSIZ - 1, |
"%s: Warning: remote mode %o != local mode %o\n", |
"%s: Warning: remote mode %o != local mode %o\n", |
target, stb.st_mode & 07777, mode); |
target, stb.st_mode & 07777, mode); |
(void) write(rem, buf, strlen(buf + 1) + 1); |
(void) write(rem, buf, strlen(buf + 1) + 1); |
|
|
if (cp == NULL) |
if (cp == NULL) |
strcpy(new, tempname); |
strcpy(new, tempname); |
else if (cp == target) |
else if (cp == target) |
(void) sprintf(new, "/%s", tempname); |
(void) snprintf(new, sizeof(new), "/%s", tempname); |
else { |
else { |
*cp = '\0'; |
*cp = '\0'; |
(void) sprintf(new, "%s/%s", target, tempname); |
(void) snprintf(new, sizeof(new), "%s/%s", target, tempname); |
*cp = '/'; |
*cp = '/'; |
} |
} |
|
|
|
|
(void) fclose(f2); |
(void) fclose(f2); |
if (opts & VERIFY) { |
if (opts & VERIFY) { |
differ: buf[0] = '\0'; |
differ: buf[0] = '\0'; |
(void) sprintf(buf + 1, "need to update: %s\n",target); |
(void) snprintf(buf + 1, BUFSIZ - 1, |
|
"need to update: %s\n",target); |
(void) write(rem, buf, strlen(buf + 1) + 1); |
(void) write(rem, buf, strlen(buf + 1) + 1); |
goto badnew2; |
goto badnew2; |
} |
} |
|
|
|
|
if (opts & COMPARE) { |
if (opts & COMPARE) { |
buf[0] = '\0'; |
buf[0] = '\0'; |
(void) sprintf(buf + 1, "updated %s\n", target); |
(void) snprintf(buf + 1, BUFSIZ - 1, |
|
"updated %s\n", target); |
(void) write(rem, buf, strlen(buf + 1) + 1); |
(void) write(rem, buf, strlen(buf + 1) + 1); |
} else |
} else |
ack(); |
ack(); |
|
|
/* |
/* |
* Tell the remote to clean the files from the last directory sent. |
* Tell the remote to clean the files from the last directory sent. |
*/ |
*/ |
(void) sprintf(buf, "C%o\n", opts & VERIFY); |
(void) snprintf(buf, BUFSIZ, "C%o\n", opts & VERIFY); |
if (debug) |
if (debug) |
printf("buf = %s", buf); |
printf("buf = %s", buf); |
(void) write(rem, buf, strlen(buf)); |
(void) write(rem, buf, strlen(buf)); |
|
|
error("%s:%s: %s\n", host, target, strerror(errno)); |
error("%s:%s: %s\n", host, target, strerror(errno)); |
continue; |
continue; |
} |
} |
(void) sprintf(buf, "Q%s\n", dp->d_name); |
(void) snprintf(buf, BUFSIZ, "Q%s\n", dp->d_name); |
(void) write(rem, buf, strlen(buf)); |
(void) write(rem, buf, strlen(buf)); |
cp = buf; |
cp = buf; |
do { |
do { |
|
|
if (opts & VERIFY) { |
if (opts & VERIFY) { |
cp = buf; |
cp = buf; |
*cp++ = '\0'; |
*cp++ = '\0'; |
(void) sprintf(cp, "need to remove: %s\n", target); |
(void) snprintf(cp, BUFSIZ - 1, |
|
"need to remove: %s\n", target); |
(void) write(rem, buf, strlen(cp) + 1); |
(void) write(rem, buf, strlen(cp) + 1); |
} else |
} else |
removeit(&stb); |
removeit(&stb); |
|
|
removed: |
removed: |
cp = buf; |
cp = buf; |
*cp++ = '\0'; |
*cp++ = '\0'; |
(void) sprintf(cp, "removed %s\n", target); |
(void) snprintf(cp, BUFSIZ - 1, "removed %s\n", target); |
(void) write(rem, buf, strlen(cp) + 1); |
(void) write(rem, buf, strlen(cp) + 1); |
} |
} |
|
|
|
|
(void) close(fd[1]); |
(void) close(fd[1]); |
s = sbuf; |
s = sbuf; |
*s++ = '\0'; |
*s++ = '\0'; |
while ((i = read(fd[0], buf, sizeof(buf))) > 0) { |
while ((i = read(fd[0], buf, BUFSIZ)) > 0) { |
cp = buf; |
cp = buf; |
do { |
do { |
*s++ = *cp++; |
*s++ = *cp++; |
|
|
#endif |
#endif |
/* Print changes locally if not quiet mode */ |
/* Print changes locally if not quiet mode */ |
if (!qflag) |
if (!qflag) |
(void)vprintf(fmt, ap); |
(void) vprintf(fmt, ap); |
|
|
/* Save changes (for mailing) if really updating files */ |
/* Save changes (for mailing) if really updating files */ |
if (!(options & VERIFY) && fp != NULL) |
if (!(options & VERIFY) && fp != NULL) |
(void)vfprintf(fp, fmt, ap); |
(void) vfprintf(fp, fmt, ap); |
va_end(ap); |
va_end(ap); |
} |
} |
|
|
|
|
if (iamremote) { |
if (iamremote) { |
if (!fp && (rem < 0 || !(fp = fdopen(rem, "w")))) |
if (!fp && (rem < 0 || !(fp = fdopen(rem, "w")))) |
return; |
return; |
(void)fprintf(fp, "%crdist: ", 0x01); |
(void) fprintf(fp, "%crdist: ", 0x01); |
(void)vfprintf(fp, fmt, ap); |
(void) vfprintf(fp, fmt, ap); |
fflush(fp); |
fflush(fp); |
} |
} |
else { |
else { |
fflush(stdout); |
fflush(stdout); |
(void)fprintf(stderr, "rdist: "); |
(void) fprintf(stderr, "rdist: "); |
(void)vfprintf(stderr, fmt, ap); |
(void) vfprintf(stderr, fmt, ap); |
fflush(stderr); |
fflush(stderr); |
} |
} |
if (lfp != NULL) { |
if (lfp != NULL) { |
(void)fprintf(lfp, "rdist: "); |
(void) fprintf(lfp, "rdist: "); |
(void)vfprintf(lfp, fmt, ap); |
(void) vfprintf(lfp, fmt, ap); |
fflush(lfp); |
fflush(lfp); |
} |
} |
va_end(ap); |
va_end(ap); |
|
|
if (!fp && !(fp = fdopen(rem, "w"))) |
if (!fp && !(fp = fdopen(rem, "w"))) |
return; |
return; |
if (iamremote) { |
if (iamremote) { |
(void)fprintf(fp, "%crdist: ", 0x02); |
(void) fprintf(fp, "%crdist: ", 0x02); |
(void)vfprintf(fp, fmt, ap); |
(void) vfprintf(fp, fmt, ap); |
fflush(fp); |
fflush(fp); |
} |
} |
else { |
else { |
fflush(stdout); |
fflush(stdout); |
(void)fprintf(stderr, "rdist: "); |
(void) fprintf(stderr, "rdist: "); |
(void)vfprintf(stderr, fmt, ap); |
(void) vfprintf(stderr, fmt, ap); |
fflush(stderr); |
fflush(stderr); |
} |
} |
if (lfp != NULL) { |
if (lfp != NULL) { |
(void)fprintf(lfp, "rdist: "); |
(void) fprintf(lfp, "rdist: "); |
(void)vfprintf(lfp, fmt, ap); |
(void) vfprintf(lfp, fmt, ap); |
fflush(lfp); |
fflush(lfp); |
} |
} |
cleanup(0); |
cleanup(0); |
|
|
#else |
#else |
va_start(ap); |
va_start(ap); |
#endif |
#endif |
(void)vsnprintf(buf, sizeof(buf), fmt, ap); |
(void) vsnprintf(buf, BUFSIZ, fmt, ap); |
va_end(ap); |
va_end(ap); |
comment(buf); |
comment(buf); |
} |
} |