Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/sup/source - add new ignore chown/chgrp flag



details:   https://anonhg.NetBSD.org/src/rev/e63910d2426d
branches:  trunk
changeset: 785993:e63910d2426d
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Apr 09 16:39:19 2013 +0000

description:
- add new ignore chown/chgrp flag
- bump strings space to 8K someone has 4K paths now.
- use snprintf where possible and detect long lines.

diffstat:

 usr.sbin/sup/source/sup.1       |  10 +++-
 usr.sbin/sup/source/sup.h       |   4 +-
 usr.sbin/sup/source/supcdefs.h  |   3 +-
 usr.sbin/sup/source/supcmain.c  |   8 ++-
 usr.sbin/sup/source/supcmeat.c  |  88 ++++++++++++++++++++++++----------------
 usr.sbin/sup/source/supcparse.c |   8 ++-
 6 files changed, 76 insertions(+), 45 deletions(-)

diffs (truncated from 389 to 300 lines):

diff -r 7cad64ce2f7e -r e63910d2426d usr.sbin/sup/source/sup.1
--- a/usr.sbin/sup/source/sup.1 Tue Apr 09 16:38:18 2013 +0000
+++ b/usr.sbin/sup/source/sup.1 Tue Apr 09 16:39:19 2013 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: sup.1,v 1.21 2011/09/22 07:30:04 mrg Exp $
+.\"    $NetBSD: sup.1,v 1.22 2013/04/09 16:39:19 christos Exp $
 .\"
 .\" Copyright (c) 1992 Carnegie Mellon University
 .\" All Rights Reserved.
@@ -45,7 +45,7 @@
 .\" 04-Apr-85  Steven Shafer (sas) at Carnegie-Mellon University
 .\"    Created.
 .\"
-.TH SUP 1 10/01/08
+.TH SUP 1 2013/03/13
 .CM 4
 .SH "NAME"
 sup \- software upgrade protocol
@@ -266,6 +266,12 @@
 Messages will be printed that indicate what would happen if
 an actual upgrade were done.
 .TP
+.B i
+Ignore errors from
+.IR chown(2)
+or
+.IR chgrp(2) .
+.TP
 .B -k
 .I Sup
 will check the modification times of
diff -r 7cad64ce2f7e -r e63910d2426d usr.sbin/sup/source/sup.h
--- a/usr.sbin/sup/source/sup.h Tue Apr 09 16:38:18 2013 +0000
+++ b/usr.sbin/sup/source/sup.h Tue Apr 09 16:39:19 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sup.h,v 1.11 2007/12/20 20:14:24 christos Exp $        */
+/*     $NetBSD: sup.h,v 1.12 2013/04/09 16:39:20 christos Exp $        */
 
 /*
  * Copyright (c) 1992 Carnegie Mellon University
@@ -169,7 +169,7 @@
 #endif
 
 /* String length */
-#define STRINGLENGTH   2000
+#define STRINGLENGTH   8192
 
 /* Password transmission encryption key */
 #define PSWDCRYPT      "SuperMan"
diff -r 7cad64ce2f7e -r e63910d2426d usr.sbin/sup/source/supcdefs.h
--- a/usr.sbin/sup/source/supcdefs.h    Tue Apr 09 16:38:18 2013 +0000
+++ b/usr.sbin/sup/source/supcdefs.h    Tue Apr 09 16:39:19 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: supcdefs.h,v 1.14 2011/09/21 19:34:54 christos Exp $   */
+/*     $NetBSD: supcdefs.h,v 1.15 2013/04/09 16:39:20 christos Exp $   */
 
 /*
  * Copyright (c) 1992 Carnegie Mellon University
@@ -117,6 +117,7 @@
 #define CFCOMPRESS     04000
 #define CFSILENT       10000
 #define CFCANONICALIZE 20000
+#define CFIGNCHERR     40000
 
 /*************************
  ***   M A C R O S    ***
diff -r 7cad64ce2f7e -r e63910d2426d usr.sbin/sup/source/supcmain.c
--- a/usr.sbin/sup/source/supcmain.c    Tue Apr 09 16:38:18 2013 +0000
+++ b/usr.sbin/sup/source/supcmain.c    Tue Apr 09 16:39:19 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: supcmain.c,v 1.32 2011/09/21 19:34:54 christos Exp $   */
+/*     $NetBSD: supcmain.c,v 1.33 2013/04/09 16:39:20 christos Exp $   */
 
 /*
  * Copyright (c) 1992 Carnegie Mellon University
@@ -470,7 +470,7 @@
        int oflags, aflags;
        int c;
 
-#define SUPOPTIONS "abBCdDeEfkKlmM:NoOPRsStuvXzZ=:"
+#define SUPOPTIONS "abBCdDeEifkKlmM:NoOPRsStuvXzZ=:"
 
        oflags = aflags = 0;
        while ((c = getopt(*argc, *argv, SUPOPTIONS)) != -1)
@@ -524,6 +524,10 @@
                case 'f':
                        oflags |= CFLIST;
                        break;
+               case 'i':
+                       oflags |= CFIGNCHERR;
+                       aflags &= ~CFIGNCHERR;
+                       break;
                case 'k':
                        oflags |= CFKEEP;
                        aflags &= ~CFKEEP;
diff -r 7cad64ce2f7e -r e63910d2426d usr.sbin/sup/source/supcmeat.c
--- a/usr.sbin/sup/source/supcmeat.c    Tue Apr 09 16:38:18 2013 +0000
+++ b/usr.sbin/sup/source/supcmeat.c    Tue Apr 09 16:39:19 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: supcmeat.c,v 1.41 2013/03/08 20:56:44 christos Exp $   */
+/*     $NetBSD: supcmeat.c,v 1.42 2013/04/09 16:39:20 christos Exp $   */
 
 /*
  * Copyright (c) 1992 Carnegie Mellon University
@@ -334,7 +334,8 @@
        /* read time of last upgrade from when file */
 
        if ((thisC->Cflags & CFURELSUF) && thisC->Crelease)
-               (void) sprintf(relsufix, ".%s", thisC->Crelease);
+               (void) snprintf(relsufix, sizeof(relsufix), ".%s",
+                   thisC->Crelease);
        else
                relsufix[0] = '\0';
        lasttime = getwhen(collname, relsufix);
@@ -404,7 +405,7 @@
        int f, x;
 
        /* lock collection if desired */
-       (void) sprintf(buf, FILELOCK, collname);
+       (void) snprintf(buf, sizeof(buf), FILELOCK, collname);
        f = open(buf, O_RDONLY, 0);
        if (f >= 0) {
 
@@ -495,15 +496,19 @@
 
 
        if ((thisC->Cflags & CFURELSUF) && release)
-               (void) sprintf(relsufix, ".%s", release);
+               (void) snprintf(relsufix, sizeof(relsufix), ".%s", release);
        else
                relsufix[0] = '\0';
-       (void) sprintf(buf, FILELAST, collname, relsufix);
+       (void) snprintf(buf, sizeof(buf), FILELAST, collname, relsufix);
        f = fopen(buf, "r");
        if (f) {
                while ((p = fgets(buf, STRINGLENGTH, f))) {
                        if ((q = strchr(p, '\n')))
                                *q = '\0';
+                       else {
+                               p[512] = '\0';
+                               goaway("Line too long in LAST: %s", p);
+                       }
                        if (strchr("#;:", *p))
                                continue;
                        if (canonicalize(p) != 0)
@@ -513,12 +518,16 @@
                (void) fclose(f);
        }
        refuseT = NULL;
-       (void) sprintf(buf, FILEREFUSE, collname);
+       (void) snprintf(buf, sizeof(buf), FILEREFUSE, collname);
        f = fopen(buf, "r");
        if (f) {
                while ((p = fgets(buf, STRINGLENGTH, f))) {
                        if ((q = strchr(p, '\n')))
                                *q = '\0';
+                       else {
+                               p[512] = '\0';
+                               goaway("Line too long in REFUSE: %s", p);
+                       }
                        if (strchr("#;:", *p))
                                continue;
                        (void) Tinsert(&refuseT, p, FALSE);
@@ -670,11 +679,9 @@
                }
                if (rmdir(name) < 0) {
                        (void) chmod(name, sbuf.st_mode | S_IRWXU);
-                       if (strlen(name) < MAXPATHLEN - 3) {
-                               sprintf(pname, "%s/..", name);
-                               if (stat(pname, &pbuf) == 0)
-                                       (void) chmod(pname, pbuf.st_mode | S_IRWXU);
-                       }
+                       snprintf(pname, sizeof(pname), "%s/..", name);
+                       if (stat(pname, &pbuf) == 0)
+                               (void) chmod(pname, pbuf.st_mode | S_IRWXU);
                        runp("rm", "rm", "-rf", name, 0);
                }
                if (rmdir(name) < 0 && errno != ENOENT) {
@@ -797,11 +804,9 @@
        if (S_ISDIR(statp->st_mode)) {
                if (rmdir(name) < 0) {
                        (void) chmod(name, statp->st_mode | S_IRWXU);
-                       if (strlen(name) < MAXPATHLEN - 3) {
-                               sprintf(pname, "%s/..", name);
-                               if (stat(pname, &pbuf) == 0)
-                                       (void) chmod(pname, pbuf.st_mode | S_IRWXU);
-                       }
+                       snprintf(pname, sizeof(pname), "%s/..", name);
+                       if (stat(pname, &pbuf) == 0)
+                           (void) chmod(pname, pbuf.st_mode | S_IRWXU);
                        runp("rm", "rm", "-rf", name, 0);
                }
                if (rmdir(name) < 0)
@@ -905,10 +910,12 @@
                return (FALSE);
        }
        if ((t->Tflags & FNOACCT) == 0) {
-               if (chown(t->Tname, t->Tuid, t->Tgid) < 0)
+               if (chown(t->Tname, t->Tuid, t->Tgid) < 0 &&
+                   (thisC->Cflags & CFIGNCHERR) == 0)
                        goaway("Can't chown %s (%s)", t->Tname,
                            strerror(errno)); 
-               if (chmod(t->Tname, t->Tmode & S_IMODE) < 0)
+               if (chmod(t->Tname, t->Tmode & S_IMODE) < 0 &&
+                   (thisC->Cflags & CFIGNCHERR) == 0)
                        goaway("Can't chmod %s (%s)", t->Tname,
                            strerror(errno)); 
        }
@@ -1000,10 +1007,12 @@
                }
                vnotify(0, "Updating file %s", t->Tname);
                if ((t->Tflags & FNOACCT) == 0) {
-                       if (chown(t->Tname, t->Tuid, t->Tgid) < 0)
+                       if (chown(t->Tname, t->Tuid, t->Tgid) < 0 &&
+                           (thisC->Cflags & CFIGNCHERR) == 0)
                                goaway("Can't chown %s (%s)", t->Tname,
                                    strerror(errno)); 
-                       if (chmod(t->Tname, t->Tmode & S_IMODE) < 0)
+                       if (chmod(t->Tname, t->Tmode & S_IMODE) < 0 &&
+                           (thisC->Cflags & CFIGNCHERR) == 0)
                                goaway("Can't chmod %s (%s)", t->Tname,
                                    strerror(errno)); 
                }
@@ -1040,10 +1049,11 @@
                        return (TRUE);  /* mark upgrade as nogood */
                }
                path(t->Tname, dirpart, filepart);
-               (void) sprintf(filename, FILEBACKUP, dirpart, filepart);
+               (void) snprintf(filename, sizeof(filename), FILEBACKUP,
+                   dirpart, filepart);
                fout = fopen(filename, "w");
                if (fout == NULL) {
-                       (void) sprintf(buf, FILEBKDIR, dirpart);
+                       (void) snprintf(buf, sizeof(buf), FILEBKDIR, dirpart);
                        (void) mkdir(buf, 0755);
                        fout = fopen(filename, "w");
                }
@@ -1066,10 +1076,12 @@
        if ((t->Tflags & FNOACCT) == 0) {
                /* convert user and group names to local ids */
                ugconvert(t->Tuser, t->Tgroup, &t->Tuid, &t->Tgid, &t->Tmode);
-               if (chown(t->Tname, t->Tuid, t->Tgid) < 0)
+               if (chown(t->Tname, t->Tuid, t->Tgid) < 0 &&
+                   (thisC->Cflags & CFIGNCHERR) == 0)
                        goaway("Can't chown %s (%s)", t->Tname,
                            strerror(errno)); 
-               if (chmod(t->Tname, t->Tmode & S_IMODE) < 0)
+               if (chmod(t->Tname, t->Tmode & S_IMODE) < 0 &&
+                   (thisC->Cflags & CFIGNCHERR) == 0)
                        goaway("Can't chmod %s (%s)", t->Tname,
                            strerror(errno)); 
        }
@@ -1242,7 +1254,8 @@
        for (;;) {
                /* try destination directory */
                path(to, dpart, fpart);
-               (void) sprintf(tname, "%s/#%d.sup", dpart, thispid);
+               (void) snprintf(tname, sizeof(tname), "%s/#%d.sup", dpart,
+                   thispid);
                tof = open(tname, (O_WRONLY | O_CREAT | O_TRUNC | O_EXCL), 0600);
                if (tof >= 0)
                        break;
@@ -1251,7 +1264,7 @@
                        if (chdir(thisC->Cbase) < 0)
                                goaway("Can't chdir to %s (%s)", thisC->Cbase,
                                    strerror(errno));
-               (void) sprintf(tname, "sup/#%d.sup", thispid);
+               (void) snprintf(tname, sizeof(tname), "sup/#%d.sup", thispid);
                tof = open(tname, (O_WRONLY | O_CREAT | O_TRUNC | O_EXCL), 0600);
                if (tof >= 0) {
                        if (thisC->Cprefix)
@@ -1261,7 +1274,7 @@
                        break;
                }
                /* try base directory */
-               (void) sprintf(tname, "#%d.sup", thispid);
+               (void) snprintf(tname, sizeof(tname), "#%d.sup", thispid);
                tof = open(tname, (O_WRONLY | O_CREAT | O_TRUNC | O_EXCL), 0600);
                if (thisC->Cprefix)
                        if (chdir(thisC->Cprefix) < 0)
@@ -1271,19 +1284,21 @@
                        break;
 #ifdef VAR_TMP
                /* try /var/tmp */
-               (void) sprintf(tname, "/var/tmp/#%d.sup", thispid);
+               (void) snprintf(tname, sizeof(tname), "/var/tmp/#%d.sup",
+                   thispid);
                tof = open(tname, (O_WRONLY | O_CREAT | O_TRUNC | O_EXCL), 0600);
                if (tof >= 0)
                        break;
 #else
                /* try /usr/tmp */
-               (void) sprintf(tname, "/usr/tmp/#%d.sup", thispid);
+               (void) snprintf(tname, sizeof(tname), "/usr/tmp/#%d.sup",
+                   thispid);
                tof = open(tname, (O_WRONLY | O_CREAT | O_TRUNC | O_EXCL), 0600);
                if (tof >= 0)
                        break;
 #endif
                /* try /tmp */



Home | Main Index | Thread Index | Old Index