don't redefine _PATH_TMP; don't assume it begins "/tmp/";
[unix-history] / usr / src / usr.bin / rdist / server.c
index 65c6951..534bf09 100644 (file)
@@ -2,21 +2,11 @@
  * Copyright (c) 1983 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1983 Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * %sccs.include.redist.c%
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)server.c   5.10 (Berkeley) %G%";
+static char sccsid[] = "@(#)server.c   5.13 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "defs.h"
 #endif /* not lint */
 
 #include "defs.h"
@@ -283,7 +273,7 @@ sendf(rname, opts)
        if (except(target))
                return;
        if ((opts & FOLLOW ? stat(target, &stb) : lstat(target, &stb)) < 0) {
        if (except(target))
                return;
        if ((opts & FOLLOW ? stat(target, &stb) : lstat(target, &stb)) < 0) {
-               error("%s: %s\n", target, sys_errlist[errno]);
+               error("%s: %s\n", target, strerror(errno));
                return;
        }
        if ((u = update(rname, opts, &stb)) == 0) {
                return;
        }
        if ((u = update(rname, opts, &stb)) == 0) {
@@ -318,7 +308,7 @@ sendf(rname, opts)
        switch (stb.st_mode & S_IFMT) {
        case S_IFDIR:
                if ((d = opendir(target)) == NULL) {
        switch (stb.st_mode & S_IFMT) {
        case S_IFDIR:
                if ((d = opendir(target)) == NULL) {
-                       error("%s: %s\n", target, sys_errlist[errno]);
+                       error("%s: %s\n", target, strerror(errno));
                        return;
                }
                (void) sprintf(buf, "D%o %04o 0 0 %s %s %s\n", opts,
                        return;
                }
                (void) sprintf(buf, "D%o %04o 0 0 %s %s %s\n", opts,
@@ -431,7 +421,7 @@ sendf(rname, opts)
        }
 
        if ((f = open(target, 0)) < 0) {
        }
 
        if ((f = open(target, 0)) < 0) {
-               error("%s: %s\n", target, sys_errlist[errno]);
+               error("%s: %s\n", target, strerror(errno));
                return;
        }
        (void) sprintf(buf, "R%o %o %ld %ld %s %s %s\n", opts,
                return;
        }
        (void) sprintf(buf, "R%o %o %ld %ld %s %s %s\n", opts,
@@ -627,7 +617,7 @@ query(name)
                if (errno == ENOENT)
                        (void) write(rem, "N\n", 2);
                else
                if (errno == ENOENT)
                        (void) write(rem, "N\n", 2);
                else
-                       error("%s:%s: %s\n", host, target, sys_errlist[errno]);
+                       error("%s:%s: %s\n", host, target, strerror(errno));
                *tp = '\0';
                return;
        }
                *tp = '\0';
                return;
        }
@@ -662,7 +652,7 @@ recvf(cmd, type)
        struct timeval tvp[2];
        char *owner, *group;
        char new[BUFSIZ];
        struct timeval tvp[2];
        char *owner, *group;
        char new[BUFSIZ];
-       extern char *tmpname;
+       extern char *tempname;
 
        cp = cmd;
        opts = 0;
 
        cp = cmd;
        opts = 0;
@@ -747,7 +737,7 @@ recvf(cmd, type)
                                ack();
                        return;
                }
                                ack();
                        return;
                }
-               error("%s:%s: %s\n", host, target, sys_errlist[errno]);
+               error("%s:%s: %s\n", host, target, strerror(errno));
                tp = stp[--catname];
                *tp = '\0';
                return;
                tp = stp[--catname];
                *tp = '\0';
                return;
@@ -757,12 +747,12 @@ recvf(cmd, type)
                (void) sprintf(tp, "/%s", cp);
        cp = rindex(target, '/');
        if (cp == NULL)
                (void) sprintf(tp, "/%s", cp);
        cp = rindex(target, '/');
        if (cp == NULL)
-               strcpy(new, tmpname);
+               strcpy(new, tempname);
        else if (cp == target)
        else if (cp == target)
-               (void) sprintf(new, "/%s", tmpname);
+               (void) sprintf(new, "/%s", tempname);
        else {
                *cp = '\0';
        else {
                *cp = '\0';
-               (void) sprintf(new, "%s/%s", target, tmpname);
+               (void) sprintf(new, "%s/%s", target, tempname);
                *cp = '/';
        }
 
                *cp = '/';
        }
 
@@ -842,7 +832,7 @@ recvf(cmd, type)
                return;
        }
        if (wrerr) {
                return;
        }
        if (wrerr) {
-               error("%s:%s: %s\n", host, new, sys_errlist[olderrno]);
+               error("%s:%s: %s\n", host, new, strerror(errno));
                (void) unlink(new);
                return;
        }
                (void) unlink(new);
                return;
        }
@@ -854,7 +844,7 @@ recvf(cmd, type)
                        goto badt;
                if ((f2 = fopen(new, "r")) == NULL) {
                badn:
                        goto badt;
                if ((f2 = fopen(new, "r")) == NULL) {
                badn:
-                       error("%s:%s: %s\n", host, new, sys_errlist[errno]);
+                       error("%s:%s: %s\n", host, new, strerror(errno));
                        (void) unlink(new);
                        return;
                }
                        (void) unlink(new);
                        return;
                }
@@ -886,7 +876,7 @@ recvf(cmd, type)
        tvp[1].tv_sec = mtime;
        tvp[1].tv_usec = 0;
        if (utimes(new, tvp) < 0) {
        tvp[1].tv_sec = mtime;
        tvp[1].tv_usec = 0;
        if (utimes(new, tvp) < 0) {
-               note("%s:utimes failed %s: %s\n", host, new, sys_errlist[errno]);
+               note("%s:utimes failed %s: %s\n", host, new, strerror(errno));
        }
        if (chog(new, owner, group, mode) < 0) {
                (void) unlink(new);
        }
        if (chog(new, owner, group, mode) < 0) {
                (void) unlink(new);
@@ -895,7 +885,7 @@ recvf(cmd, type)
 fixup:
        if (rename(new, target) < 0) {
 badt:
 fixup:
        if (rename(new, target) < 0) {
 badt:
-               error("%s:%s: %s\n", host, target, sys_errlist[errno]);
+               error("%s:%s: %s\n", host, target, strerror(errno));
                (void) unlink(new);
                return;
        }
                (void) unlink(new);
                return;
        }
@@ -948,12 +938,12 @@ hardlink(cmd)
        }
        if (chkparent(target) < 0 ) {
                error("%s:%s: %s (no parent)\n",
        }
        if (chkparent(target) < 0 ) {
                error("%s:%s: %s (no parent)\n",
-                       host, target, sys_errlist[errno]);
+                       host, target, strerror(errno));
                return;
        }
        if (exists && (unlink(target) < 0)) {
                error("%s:%s: %s (unlink)\n",
                return;
        }
        if (exists && (unlink(target) < 0)) {
                error("%s:%s: %s (unlink)\n",
-                       host, target, sys_errlist[errno]);
+                       host, target, strerror(errno));
                return;
        }
        if (link(oldname, target) < 0) {
                return;
        }
        if (link(oldname, target) < 0) {
@@ -1050,7 +1040,7 @@ ok:
        if (chown(file, uid, gid) < 0 ||
            (mode & 07000) && chmod(file, mode) < 0) {
                note("%s: chown or chmod failed: file %s:  %s",
        if (chown(file, uid, gid) < 0 ||
            (mode & 07000) && chmod(file, mode) < 0) {
                note("%s: chown or chmod failed: file %s:  %s",
-                            host, file, sys_errlist[errno]);
+                            host, file, strerror(errno));
        }
        if (userid)
                setreuid(0, userid);
        }
        if (userid)
                setreuid(0, userid);
@@ -1159,7 +1149,7 @@ clean(cp)
                return;
        }
        if ((d = opendir(target)) == NULL) {
                return;
        }
        if ((d = opendir(target)) == NULL) {
-               error("%s:%s: %s\n", host, target, sys_errlist[errno]);
+               error("%s:%s: %s\n", host, target, strerror(errno));
                return;
        }
        ack();
                return;
        }
        ack();
@@ -1181,7 +1171,7 @@ clean(cp)
                        ;
                tp--;
                if (lstat(target, &stb) < 0) {
                        ;
                tp--;
                if (lstat(target, &stb) < 0) {
-                       error("%s:%s: %s\n", host, target, sys_errlist[errno]);
+                       error("%s:%s: %s\n", host, target, strerror(errno));
                        continue;
                }
                (void) sprintf(buf, "Q%s\n", dp->d_name);
                        continue;
                }
                (void) sprintf(buf, "Q%s\n", dp->d_name);
@@ -1259,7 +1249,7 @@ remove(stp)
                        ;
                tp--;
                if (lstat(target, &stb) < 0) {
                        ;
                tp--;
                if (lstat(target, &stb) < 0) {
-                       error("%s:%s: %s\n", host, target, sys_errlist[errno]);
+                       error("%s:%s: %s\n", host, target, strerror(errno));
                        continue;
                }
                remove(&stb);
                        continue;
                }
                remove(&stb);
@@ -1269,7 +1259,7 @@ remove(stp)
        *tp = '\0';
        if (rmdir(target) < 0) {
 bad:
        *tp = '\0';
        if (rmdir(target) < 0) {
 bad:
-               error("%s:%s: %s\n", host, target, sys_errlist[errno]);
+               error("%s:%s: %s\n", host, target, strerror(errno));
                return;
        }
 removed:
                return;
        }
 removed:
@@ -1291,7 +1281,7 @@ dospecial(cmd)
        extern int userid, groupid;
 
        if (pipe(fd) < 0) {
        extern int userid, groupid;
 
        if (pipe(fd) < 0) {
-               error("%s\n", sys_errlist[errno]);
+               error("%s\n", strerror(errno));
                return;
        }
        if ((pid = fork()) == 0) {
                return;
        }
        if ((pid = fork()) == 0) {
@@ -1473,7 +1463,7 @@ response()
  */
 cleanup()
 {
  */
 cleanup()
 {
-       (void) unlink(tmpfile);
+       (void) unlink(tempfile);
        exit(1);
 }
 
        exit(1);
 }