BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.bin / rdist / docmd.c
index 5ec716a..cd5aba2 100644 (file)
+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    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
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)docmd.c     4.7 (Berkeley) 83/10/27";
-#endif
+static char sccsid[] = "@(#)docmd.c    5.8 (Berkeley) 3/1/91";
+#endif /* not lint */
 
 #include "defs.h"
 
 #include "defs.h"
+#include <setjmp.h>
+#include <netdb.h>
+
+FILE   *lfp;                   /* log file for recording files updated */
+struct subcmd *subcmds;        /* list of sub-commands for current cmd */
+jmp_buf        env;
 
 
-FILE   *lfp;           /* log file for recording files updated */
+void cleanup(), lostconn();
+
+/*
+ * Do the commands in cmds (initialized by yyparse).
+ */
+docmds(dhosts, argc, argv)
+       char **dhosts;
+       int argc;
+       char **argv;
+{
+       register struct cmd *c;
+       register struct namelist *f;
+       register char **cpp;
+       extern struct cmd *cmds;
+
+       signal(SIGHUP, cleanup);
+       signal(SIGINT, cleanup);
+       signal(SIGQUIT, cleanup);
+       signal(SIGTERM, cleanup);
+
+       for (c = cmds; c != NULL; c = c->c_next) {
+               if (dhosts != NULL && *dhosts != NULL) {
+                       for (cpp = dhosts; *cpp; cpp++)
+                               if (strcmp(c->c_name, *cpp) == 0)
+                                       goto fndhost;
+                       continue;
+               }
+       fndhost:
+               if (argc) {
+                       for (cpp = argv; *cpp; cpp++) {
+                               if (c->c_label != NULL &&
+                                   strcmp(c->c_label, *cpp) == 0) {
+                                       cpp = NULL;
+                                       goto found;
+                               }
+                               for (f = c->c_files; f != NULL; f = f->n_next)
+                                       if (strcmp(f->n_name, *cpp) == 0)
+                                               goto found;
+                       }
+                       continue;
+               } else
+                       cpp = NULL;
+       found:
+               switch (c->c_type) {
+               case ARROW:
+                       doarrow(cpp, c->c_files, c->c_name, c->c_cmds);
+                       break;
+               case DCOLON:
+                       dodcolon(cpp, c->c_files, c->c_name, c->c_cmds);
+                       break;
+               default:
+                       fatal("illegal command type %d\n", c->c_type);
+               }
+       }
+       closeconn();
+}
 
 /*
  * Process commands for sending files to other machines.
  */
 
 /*
  * Process commands for sending files to other machines.
  */
-dohcmds(files, hosts, cmds)
-       struct block *files, *hosts, *cmds;
+doarrow(filev, files, rhost, cmds)
+       char **filev;
+       struct namelist *files;
+       char *rhost;
+       struct subcmd *cmds;
 {
 {
-       register struct block *h, *f, *c;
+       register struct namelist *f;
+       register struct subcmd *sc;
        register char **cpp;
        register char **cpp;
-       static struct block excpt = { EXCEPT };
-       char *cp;
-       int n, ddir;
+       int n, ddir, opts = options;
 
        if (debug)
 
        if (debug)
-               printf("dohcmds(%x, %x, %x)\n", files, hosts, cmds);
+               printf("doarrow(%x, %s, %x)\n", files, rhost, cmds);
 
 
-       files = expand(files, 0);
        if (files == NULL) {
                error("no files to be updated\n");
                return;
        }
        if (files == NULL) {
                error("no files to be updated\n");
                return;
        }
-       hosts = expand(hosts, 1);
-       if (hosts == NULL) {
-               error("empty list of hosts to be updated\n");
-               return;
+
+       subcmds = cmds;
+       ddir = files->n_next != NULL;   /* destination is a directory */
+       if (nflag)
+               printf("updating host %s\n", rhost);
+       else {
+               if (setjmp(env))
+                       goto done;
+               signal(SIGPIPE, lostconn);
+               if (!makeconn(rhost))
+                       return;
+               if ((lfp = fopen(tempfile, "w")) == NULL) {
+                       fatal("cannot open %s\n", tempfile);
+                       exit(1);
+               }
        }
        }
-       ddir = files->b_next != NULL;
-       f = NULL;
-       except = NULL;
-       for (c = cmds; c != NULL; c = c->b_next) {
-               if (c->b_type != EXCEPT)
+       for (f = files; f != NULL; f = f->n_next) {
+               if (filev) {
+                       for (cpp = filev; *cpp; cpp++)
+                               if (strcmp(f->n_name, *cpp) == 0)
+                                       goto found;
+                       if (!nflag)
+                               (void) fclose(lfp);
                        continue;
                        continue;
-               if (except == NULL)
-                       except = &excpt;
-               for (h = c->b_args; h != NULL; h = h->b_next) {
-                       cp = h->b_name;
-                       if (*cp == '~') {
-                               (void) exptilde(buf, cp);
-                               cp = buf;
-                       }
-                       if (f == NULL)
-                               except->b_args = f = expand(makeblock(NAME, cp), 0);
-                       else
-                               f->b_next = expand(makeblock(NAME, cp), 0);
-                       while (f->b_next != NULL)
-                               f = f->b_next;
                }
                }
-       }
-
-       for (h = hosts; h != NULL; h = h->b_next) {
-               if (!qflag)
-                       printf("updating host %s\n", h->b_name);
-               if (!nflag) {
-                       if (!makeconn(h->b_name))
+       found:
+               n = 0;
+               for (sc = cmds; sc != NULL; sc = sc->sc_next) {
+                       if (sc->sc_type != INSTALL)
                                continue;
                                continue;
-                       if ((lfp = fopen(tmpfile, "w")) == NULL) {
-                               fatal("cannot open %s\n", tmpfile);
-                               exit(1);
-                       }
+                       n++;
+                       install(f->n_name, sc->sc_name,
+                               sc->sc_name == NULL ? 0 : ddir, sc->sc_options);
+                       opts = sc->sc_options;
                }
                }
-               for (f = files; f != NULL; f = f->b_next) {
-                       if (filec) {
-                               for (cpp = filev; *cpp; cpp++)
-                                       if (!strcmp(f->b_name, *cpp))
-                                               goto found;
-                               if (!nflag)
-                                       (void) fclose(lfp);
+               if (n == 0)
+                       install(f->n_name, NULL, 0, options);
+       }
+done:
+       if (!nflag) {
+               (void) signal(SIGPIPE, cleanup);
+               (void) fclose(lfp);
+               lfp = NULL;
+       }
+       for (sc = cmds; sc != NULL; sc = sc->sc_next)
+               if (sc->sc_type == NOTIFY)
+                       notify(tempfile, rhost, sc->sc_args, 0);
+       if (!nflag) {
+               (void) unlink(tempfile);
+               for (; ihead != NULL; ihead = ihead->nextp) {
+                       free(ihead);
+                       if ((opts & IGNLNKS) || ihead->count == 0)
                                continue;
                                continue;
-                       }
-               found:
-                       n = 0;
-                       for (c = cmds; c != NULL; c = c->b_next) {
-                               if (c->b_type != INSTALL)
-                                       continue;
-                               n++;
-                               if (c->b_name == NULL)
-                                       install(f->b_name, f->b_name, 0, c->b_options);
-                               else
-                                       install(f->b_name, c->b_name, ddir, c->b_options);
-                       }
-                       if (n == 0)
-                               install(f->b_name, f->b_name, 0, options);
+                       log(lfp, "%s: Warning: missing links\n",
+                               ihead->pathname);
                }
                }
-               if (!nflag) {
-                       /* signal end of connection */
-                       (void) write(rem, "\2\n", 2);
-                       (void) close(rem);
-                       (void) fclose(lfp);
-               }
-               for (c = cmds; c != NULL; c = c->b_next)
-                       if (c->b_type == NOTIFY)
-                               notify(tmpfile, h->b_name, c->b_args, 0);
        }
        }
-       if (!nflag)
-               (void) unlink(tmpfile);
 }
 
 /*
 }
 
 /*
@@ -108,161 +186,193 @@ dohcmds(files, hosts, cmds)
 makeconn(rhost)
        char *rhost;
 {
 makeconn(rhost)
        char *rhost;
 {
-       register struct block *c;
-       register char *ruser;
+       register char *ruser, *cp;
+       static char *cur_host = NULL;
+       static int port = -1;
+       char tuser[20];
+       int n;
        extern char user[];
        extern char user[];
+       extern int userid;
 
 
-       (void) sprintf(buf, "/usr/local/rdist -Server%s%s",
-               nflag ? " -n" : "", qflag ? " -q" : "");
+       if (debug)
+               printf("makeconn(%s)\n", rhost);
 
 
-       ruser = rindex(rhost, '.');
-       if (ruser != NULL) {
-               *ruser++ = '\0';
-               if (!okname(ruser))
+       if (cur_host != NULL && rem >= 0) {
+               if (strcmp(cur_host, rhost) == 0)
+                       return(1);
+               closeconn();
+       }
+       cur_host = rhost;
+       cp = index(rhost, '@');
+       if (cp != NULL) {
+               char c = *cp;
+
+               *cp = '\0';
+               strncpy(tuser, rhost, sizeof(tuser)-1);
+               *cp = c;
+               rhost = cp + 1;
+               ruser = tuser;
+               if (*ruser == '\0')
+                       ruser = user;
+               else if (!okname(ruser))
                        return(0);
        } else
                ruser = user;
                        return(0);
        } else
                ruser = user;
+       if (!qflag)
+               printf("updating host %s\n", rhost);
+       (void) sprintf(buf, "%s -Server%s", _PATH_RDIST, qflag ? " -q" : "");
+       if (port < 0) {
+               struct servent *sp;
+
+               if ((sp = getservbyname("shell", "tcp")) == NULL)
+                       fatal("shell/tcp: unknown service");
+               port = sp->s_port;
+       }
 
        if (debug) {
 
        if (debug) {
-               printf("makeconn(%s)\n", rhost);
-               printf("luser = %s, ruser = %s\n", user, ruser);
+               printf("port = %d, luser = %s, ruser = %s\n", ntohs(port), user, ruser);
                printf("buf = %s\n", buf);
        }
 
        fflush(stdout);
                printf("buf = %s\n", buf);
        }
 
        fflush(stdout);
-       rem = rcmd(&rhost, IPPORT_CMDSERVER, user, ruser, buf, 0);
+       setreuid(userid, 0);
+       rem = rcmd(&rhost, port, user, ruser, buf, 0);
+       setreuid(0, userid);
        if (rem < 0)
                return(0);
        if (rem < 0)
                return(0);
-       if (response() < 0)
-               return(0);
-       return(1);
+       cp = buf;
+       if (read(rem, cp, 1) != 1)
+               lostconn();
+       if (*cp == 'V') {
+               do {
+                       if (read(rem, cp, 1) != 1)
+                               lostconn();
+               } while (*cp++ != '\n' && cp < &buf[BUFSIZ]);
+               *--cp = '\0';
+               cp = buf;
+               n = 0;
+               while (*cp >= '0' && *cp <= '9')
+                       n = (n * 10) + (*cp++ - '0');
+               if (*cp == '\0' && n == VERSION)
+                       return(1);
+               error("connection failed: version numbers don't match (local %d, remote %d)\n", VERSION, n);
+       } else
+               error("connection failed: version numbers don't match\n");
+       closeconn();
+       return(0);
 }
 
 /*
 }
 
 /*
- * Update the file(s) if they are different.
- * destdir = 1 if destination should be a directory
- * (i.e., more than one source is being copied to the same destination).
+ * Signal end of previous connection.
  */
  */
-install(src, dest, destdir, opts)
-       char *src, *dest;
-       int destdir, opts;
+closeconn()
 {
 {
-       register char *cp;
-
-       if (exclude(src))
-               return;
-
-       if (nflag || debug) {
-               printf("%s%s%s%s%s %s %s\n", opts & VERIFY ? "verify":"install",
-                       opts & WHOLE ? " -w" : "",
-                       opts & YOUNGER ? " -y" : "",
-                       opts & COMPARE ? " -b" : "",
-                       opts & REMOVE ? " -r" : "", src, dest);
-               if (nflag)
-                       return;
-       }
-       /*
-        * Pass the destination file/directory name to remote.
-        */
-       (void) sprintf(buf, "%c%s\n", destdir ? 'T' : 't', dest);
        if (debug)
        if (debug)
-               printf("buf = %s", buf);
-       (void) write(rem, buf, strlen(buf));
-
-       if (!destdir && (opts & WHOLE))
-               opts |= STRIP;
-       if (opts & REMOVE) {
-               opts &= ~REMOVE;
-               rmchk(src, NULL, opts);
+               printf("closeconn()\n");
+
+       if (rem >= 0) {
+               (void) write(rem, "\2\n", 2);
+               (void) close(rem);
+               rem = -1;
        }
        }
-       sendf(src, NULL, opts);
 }
 
 }
 
-struct tstamp {
-       time_t  lastmod;
-       FILE    *tfp;
-} ts[NSTAMPS];
+void
+lostconn()
+{
+       if (iamremote)
+               cleanup();
+       log(lfp, "rdist: lost connection\n");
+       longjmp(env, 1);
+}
+
+okname(name)
+       register char *name;
+{
+       register char *cp = name;
+       register int c;
 
 
-int    nstamps;
+       do {
+               c = *cp;
+               if (c & 0200)
+                       goto bad;
+               if (!isalpha(c) && !isdigit(c) && c != '_' && c != '-')
+                       goto bad;
+               cp++;
+       } while (*cp);
+       return(1);
+bad:
+       error("invalid user name %s\n", name);
+       return(0);
+}
 
 
-extern char target[], *tp;
+time_t lastmod;
+FILE   *tfp;
+extern char target[], *tp;
 
 /*
  * Process commands for comparing files to time stamp files.
  */
 
 /*
  * Process commands for comparing files to time stamp files.
  */
-dofcmds(files, stamps, cmds)
-       struct block *files, *stamps, *cmds;
+dodcolon(filev, files, stamp, cmds)
+       char **filev;
+       struct namelist *files;
+       char *stamp;
+       struct subcmd *cmds;
 {
 {
-       register struct block *b;
-       register struct tstamp *t;
+       register struct subcmd *sc;
+       register struct namelist *f;
        register char **cpp;
        struct timeval tv[2];
        struct timezone tz;
        struct stat stb;
        register char **cpp;
        struct timeval tv[2];
        struct timezone tz;
        struct stat stb;
-       extern char *tmpinc;
 
        if (debug)
 
        if (debug)
-               printf("dofcmds()\n");
+               printf("dodcolon()\n");
 
 
-       files = expand(files, 0);
-       if (files == NULL){
+       if (files == NULL) {
                error("no files to be updated\n");
                return;
        }
                error("no files to be updated\n");
                return;
        }
-       stamps = expand(stamps, 0);
-       if (stamps == NULL) {
-               error("empty time stamp file list\n");
+       if (stat(stamp, &stb) < 0) {
+               error("%s: %s\n", stamp, strerror(errno));
                return;
        }
                return;
        }
-       except = cmds;
-
-       t = ts;
-       nstamps = 0;
-       for (b = stamps; b != NULL; b = b->b_next) {
-               if (stat(b->b_name, &stb) < 0) {
-                       error("%s: %s\n", b->b_name, sys_errlist[errno]);
-                       continue;
+       if (debug)
+               printf("%s: %d\n", stamp, stb.st_mtime);
+
+       subcmds = cmds;
+       lastmod = stb.st_mtime;
+       if (nflag || (options & VERIFY))
+               tfp = NULL;
+       else {
+               if ((tfp = fopen(tempfile, "w")) == NULL) {
+                       error("%s: %s\n", stamp, strerror(errno));
+                       return;
                }
                }
-               if (++nstamps > NSTAMPS)
-                       fatal("too many time stamp files in one command\n");
-               if (debug)
-                       printf("%s: %d\n", b->b_name, stb.st_mtime);
-               t->lastmod = stb.st_mtime;
                (void) gettimeofday(&tv[0], &tz);
                tv[1] = tv[0];
                (void) gettimeofday(&tv[0], &tz);
                tv[1] = tv[0];
-               (void) utimes(b->b_name, tv);
-               if (!nflag && !(options & VERIFY)) {
-                       if ((t->tfp = fopen(tmpfile, "w")) == NULL)
-                               error("%s: %s\n", b->b_name, sys_errlist[errno]);
-                       (*tmpinc)++;
-               } else
-                       t->tfp = NULL;
-               t++;
+               (void) utimes(stamp, tv);
        }
 
        }
 
-       for (b = files; b != NULL; b = b->b_next) {
-               if (filec) {
+       for (f = files; f != NULL; f = f->n_next) {
+               if (filev) {
                        for (cpp = filev; *cpp; cpp++)
                        for (cpp = filev; *cpp; cpp++)
-                               if (!strcmp(b->b_name, *cpp))
+                               if (strcmp(f->n_name, *cpp) == 0)
                                        goto found;
                        continue;
                }
        found:
                tp = NULL;
                                        goto found;
                        continue;
                }
        found:
                tp = NULL;
-               cmptime(b->b_name);
+               cmptime(f->n_name);
        }
 
        }
 
-       *tmpinc = 'A';
-       for (t = ts; t < &ts[nstamps]; t++) {
-               if (t->tfp != NULL)
-                       (void) fclose(t->tfp);
-               for (b = cmds; b != NULL; b = b->b_next)
-                       if (b->b_type == NOTIFY)
-                               notify(tmpfile, NULL, b->b_args, t->lastmod);
-               if (!nflag && !(options & VERIFY))
-                       (void) unlink(tmpfile);
-               (*tmpinc)++;
-       }
+       if (tfp != NULL)
+               (void) fclose(tfp);
+       for (sc = cmds; sc != NULL; sc = sc->sc_next)
+               if (sc->sc_type == NOTIFY)
+                       notify(tempfile, NULL, sc->sc_args, lastmod);
+       if (!nflag && !(options & VERIFY))
+               (void) unlink(tempfile);
 }
 
 /*
 }
 
 /*
@@ -271,26 +381,31 @@ dofcmds(files, stamps, cmds)
 cmptime(name)
        char *name;
 {
 cmptime(name)
        char *name;
 {
-       register struct tstamp *t;
        struct stat stb;
 
        if (debug)
                printf("cmptime(%s)\n", name);
 
        struct stat stb;
 
        if (debug)
                printf("cmptime(%s)\n", name);
 
-       if (exclude(name))
+       if (except(name))
                return;
 
                return;
 
+       if (nflag) {
+               printf("comparing dates: %s\n", name);
+               return;
+       }
+
        /*
         * first time cmptime() is called?
         */
        if (tp == NULL) {
        /*
         * first time cmptime() is called?
         */
        if (tp == NULL) {
-               exptilde(target, name);
+               if (exptilde(target, name) == NULL)
+                       return;
                tp = name = target;
                while (*tp)
                        tp++;
        }
        if (access(name, 4) < 0 || stat(name, &stb) < 0) {
                tp = name = target;
                while (*tp)
                        tp++;
        }
        if (access(name, 4) < 0 || stat(name, &stb) < 0) {
-               error("%s: %s\n", name, sys_errlist[errno]);
+               error("%s: %s\n", name, strerror(errno));
                return;
        }
 
                return;
        }
 
@@ -307,10 +422,8 @@ cmptime(name)
                return;
        }
 
                return;
        }
 
-       for (t = ts; t < &ts[nstamps]; t++) {
-               if (stb.st_mtime > t->lastmod)
-                       log(t->tfp, "new: %s\n", name);
-       }
+       if (stb.st_mtime > lastmod)
+               log(tfp, "new: %s\n", name);
 }
 
 rcmptime(st)
 }
 
 rcmptime(st)
@@ -326,7 +439,7 @@ rcmptime(st)
                printf("rcmptime(%x)\n", st);
 
        if ((d = opendir(target)) == NULL) {
                printf("rcmptime(%x)\n", st);
 
        if ((d = opendir(target)) == NULL) {
-               error("%s: %s\n", target, sys_errlist[errno]);
+               error("%s: %s\n", target, strerror(errno));
                return;
        }
        otp = tp;
                return;
        }
        otp = tp;
@@ -358,14 +471,14 @@ rcmptime(st)
  */
 notify(file, rhost, to, lmod)
        char *file, *rhost;
  */
 notify(file, rhost, to, lmod)
        char *file, *rhost;
-       register struct block *to;
+       register struct namelist *to;
        time_t lmod;
 {
        register int fd, len;
        FILE *pf, *popen();
        struct stat stb;
 
        time_t lmod;
 {
        register int fd, len;
        FILE *pf, *popen();
        struct stat stb;
 
-       if (options & VERIFY)
+       if ((options & VERIFY) || to == NULL)
                return;
        if (!qflag) {
                printf("notify ");
                return;
        if (!qflag) {
                printf("notify ");
@@ -377,11 +490,11 @@ notify(file, rhost, to, lmod)
                return;
 
        if ((fd = open(file, 0)) < 0) {
                return;
 
        if ((fd = open(file, 0)) < 0) {
-               error("%s: %s\n", file, sys_errlist[errno]);
+               error("%s: %s\n", file, strerror(errno));
                return;
        }
        if (fstat(fd, &stb) < 0) {
                return;
        }
        if (fstat(fd, &stb) < 0) {
-               error("%s: %s\n", file, sys_errlist[errno]);
+               error("%s: %s\n", file, strerror(errno));
                (void) close(fd);
                return;
        }
                (void) close(fd);
                return;
        }
@@ -392,9 +505,10 @@ notify(file, rhost, to, lmod)
        /*
         * Create a pipe to mailling program.
         */
        /*
         * Create a pipe to mailling program.
         */
-       pf = popen(MAILCMD, "w");
+       (void)sprintf(buf, "%s -oi -t", _PATH_SENDMAIL);
+       pf = popen(buf, "w");
        if (pf == NULL) {
        if (pf == NULL) {
-               error("notify: \"%s\" failed\n", MAILCMD);
+               error("notify: \"%s\" failed\n", _PATH_SENDMAIL);
                (void) close(fd);
                return;
        }
                (void) close(fd);
                return;
        }
@@ -403,17 +517,17 @@ notify(file, rhost, to, lmod)
         */
        fprintf(pf, "From: rdist (Remote distribution program)\n");
        fprintf(pf, "To:");
         */
        fprintf(pf, "From: rdist (Remote distribution program)\n");
        fprintf(pf, "To:");
-       if (!any('@', to->b_name) && host != NULL)
-               fprintf(pf, " %s@%s", to->b_name, rhost);
+       if (!any('@', to->n_name) && rhost != NULL)
+               fprintf(pf, " %s@%s", to->n_name, rhost);
        else
        else
-               fprintf(pf, " %s", to->b_name);
-       to = to->b_next;
+               fprintf(pf, " %s", to->n_name);
+       to = to->n_next;
        while (to != NULL) {
        while (to != NULL) {
-               if (!any('@', to->b_name) && host != NULL)
-                       fprintf(pf, ", %s@%s", to->b_name, rhost);
+               if (!any('@', to->n_name) && rhost != NULL)
+                       fprintf(pf, ", %s@%s", to->n_name, rhost);
                else
                else
-                       fprintf(pf, ", %s", to->b_name);
-               to = to->b_next;
+                       fprintf(pf, ", %s", to->n_name);
+               to = to->n_next;
        }
        putc('\n', pf);
        if (rhost != NULL)
        }
        putc('\n', pf);
        if (rhost != NULL)
@@ -429,43 +543,47 @@ notify(file, rhost, to, lmod)
        (void) pclose(pf);
 }
 
        (void) pclose(pf);
 }
 
-struct block *except;          /* list of files to exclude */
-
 /*
 /*
- * Return true if name is in list.
+ * Return true if name is in the list.
  */
  */
-exclude(file)
+inlist(list, file)
+       struct namelist *list;
        char *file;
 {
        char *file;
 {
-       register struct block *b, *c;
+       register struct namelist *nl;
 
 
-       for (c = except; c != NULL; c = c->b_next) {
-               if (c->b_type != EXCEPT)
-                       continue;
-               for (b = c->b_args; b != NULL; b = b->b_next)
-                       if (!strcmp(file, b->b_name))
-                               return(1);
-       }
+       for (nl = list; nl != NULL; nl = nl->n_next)
+               if (!strcmp(file, nl->n_name))
+                       return(1);
        return(0);
 }
 
        return(0);
 }
 
-okname(name)
-       register char *name;
+/*
+ * Return TRUE if file is in the exception list.
+ */
+except(file)
+       char *file;
 {
 {
-       register char *cp = name;
-       register int c;
+       register struct subcmd *sc;
+       register struct namelist *nl;
 
 
-       do {
-               c = *cp;
-               if (c & 0200)
-                       goto bad;
-               if (!isalpha(c) && !isdigit(c) && c != '_' && c != '-')
-                       goto bad;
-               cp++;
-       } while (*cp);
-       return(1);
-bad:
-       error("invalid user name %s\n", name);
+       if (debug)
+               printf("except(%s)\n", file);
+
+       for (sc = subcmds; sc != NULL; sc = sc->sc_next) {
+               if (sc->sc_type != EXCEPT && sc->sc_type != PATTERN)
+                       continue;
+               for (nl = sc->sc_args; nl != NULL; nl = nl->n_next) {
+                       if (sc->sc_type == EXCEPT) {
+                               if (!strcmp(file, nl->n_name))
+                                       return(1);
+                               continue;
+                       }
+                       re_comp(nl->n_name);
+                       if (re_exec(file) > 0)
+                               return(1);
+               }
+       }
        return(0);
 }
 
        return(0);
 }