]> diplodocus.org Git - nmh/blobdiff - uip/aliasbr.c
Support command issuance and timestamps.
[nmh] / uip / aliasbr.c
index c7ea3a33f02dc2b60e3fda722ae71c4e5a57aef0..40687bbc846a143cc1e26702063b8f87b25420b2 100644 (file)
@@ -1,6 +1,4 @@
-
-/*
- * aliasbr.c -- new aliasing mechanism
+/* aliasbr.c -- new aliasing mechanism
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -11,7 +9,6 @@
 #include <h/aliasbr.h>
 #include <h/addrsbr.h>
 #include <h/utils.h>
-#include <grp.h>
 #include <pwd.h>
 
 static int akvis;
@@ -20,31 +17,18 @@ static char *akerrst;
 struct aka *akahead = NULL;
 struct aka *akatail = NULL;
 
-struct home *homehead = NULL;
-struct home *hometail = NULL;
-
 /*
  * prototypes
  */
-int alias (char *);
-int akvisible (void);
-void init_pw (void);
-char *akresult (struct aka *);
-char *akvalue (char *);
-char *akerror (int);
-
 static  char *akval (struct aka *, char *);
-static int aleq (char *, char *);
-static char *scanp (char *);
+static bool aleq (char *, char *) PURE;
+static char *scanp (char *) PURE;
 static char *getp (char *);
 static char *seekp (char *, char *, char **);
 static int addfile (struct aka *, char *);
-static int addgroup (struct aka *, char *);
-static int addmember (struct aka *, char *);
 static char *getalias (char *);
 static void add_aka (struct aka *, char *);
 static struct aka *akalloc (char *);
-static struct home *hmalloc (struct passwd *);
 
 
 /* Do mh alias substitution on 's' and return the results. */
@@ -130,8 +114,10 @@ akval (struct aka *ak, char *s)
                struct mailname *mp = getm (name, NULL, 0, NULL, 0);
 
                if (mp  &&  mp->m_ingrp) {
-                   char *gname = add (mp->m_gname, NULL);
+                   char *gname = mh_xstrdup(FENDNULL(mp->m_gname));
 
+                    /* FIXME: gname must be true;  add() never returns NULL.
+                    * Is some other test required? */
                    if (gname  &&  aleq (name, ak->ak_name)) {
                        /* Will leak cp. */
                        cp = concat (gname, akresult (ak), NULL);
@@ -155,20 +141,20 @@ akval (struct aka *ak, char *s)
 }
 
 
-static int
+static bool
 aleq (char *string, char *aliasent)
 {
     char c;
 
     while ((c = *string++)) {
        if (*aliasent == '*')
-           return 1;
-        if ((c | 040) != (*aliasent | 040))
-            return 0;
+           return true;
+        if (tolower((unsigned char)c) != tolower((unsigned char)*aliasent))
+            return false;
         aliasent++;
     }
 
-    return (*aliasent == 0 || *aliasent == '*');
+    return *aliasent == 0 || *aliasent == '*';
 }
 
 
@@ -182,7 +168,7 @@ alias (char *file)
     FILE *fp;
 
     if (*file != '/'
-           && (strncmp (file, "./", 2) && strncmp (file, "../", 3)))
+            && !has_prefix(file, "./") && !has_prefix(file, "../"))
        file = etcpath (file);
     if ((fp = fopen (file, "r")) == NULL) {
        akerrst = file;
@@ -202,7 +188,7 @@ alias (char *file)
                    fclose (fp);
                    return i;
                }
-
+               continue;
            case ':':           /* comment */
            case ';': 
            case '#':
@@ -221,11 +207,11 @@ alias (char *file)
        }
        switch (lc) {
            case ':': 
-               ak->ak_visible = 0;
+               ak->ak_visible = false;
                break;
 
            case ';': 
-               ak->ak_visible = 1;
+               ak->ak_visible = true;
                break;
 
            default: 
@@ -249,28 +235,6 @@ alias (char *file)
                }
                break;
 
-           case '=':           /* UNIX group */
-               if (!*(cp = getp (pp + 1))) {
-                   fclose (fp);
-                   return AK_ERROR;
-               }
-               if (!addgroup (ak, cp)) {
-                   fclose (fp);
-                   return AK_NOGROUP;
-               }
-               break;
-
-           case '+':           /* UNIX group members */
-               if (!*(cp = getp (pp + 1))) {
-                   fclose (fp);
-                   return AK_ERROR;
-               }
-               if (!addmember (ak, cp)) {
-                   fclose (fp);
-                   return AK_NOGROUP;
-               }
-               break;
-
            default:            /* list */
                while ((cp = getalias (pp)))
                    add_aka (ak, cp);
@@ -301,10 +265,6 @@ akerror (int i)
            snprintf (buffer, sizeof(buffer), "out of memory while on '%s'", akerrst);
            break;
 
-       case AK_NOGROUP: 
-           snprintf (buffer, sizeof(buffer), "no such group as '%s'", akerrst);
-           break;
-
        default: 
            snprintf (buffer, sizeof(buffer), "unknown error (%d)", i);
            break;
@@ -374,67 +334,6 @@ addfile (struct aka *ak, char *file)
 }
 
 
-static int
-addgroup (struct aka *ak, char *grp)
-{
-    char *gp;
-    struct group *gr = getgrnam (grp);
-    struct home *hm = NULL;
-
-    if (!gr)
-       gr = getgrgid (atoi (grp));
-    if (!gr) {
-       akerrst = grp;
-       return 0;
-    }
-
-    while ((gp = *gr->gr_mem++))
-    {
-       struct passwd *pw;
-       for (hm = homehead; hm; hm = hm->h_next)
-           if (!strcmp (hm->h_name, gp)) {
-               add_aka (ak, hm->h_name);
-               break;
-           }
-        if ((pw = getpwnam(gp)))
-       {
-               hmalloc(pw);
-               add_aka (ak, gp);
-       }
-    }
-
-    return 1;
-}
-
-
-static int
-addmember (struct aka *ak, char *grp)
-{
-    gid_t gid;
-    struct group *gr = getgrnam (grp);
-    struct home *hm = NULL;
-
-    if (gr)
-       gid = gr->gr_gid;
-    else {
-       gid = atoi (grp);
-       gr = getgrgid (gid);
-    }
-    if (!gr) {
-       akerrst = grp;
-       return 0;
-    }
-
-    init_pw ();
-
-    for (hm = homehead; hm; hm = hm->h_next)
-       if (hm->h_gid == gid)
-           add_aka (ak, hm->h_name);
-
-    return 1;
-}
-
-
 static char *
 getalias (char *addrs)
 {
@@ -443,15 +342,14 @@ getalias (char *addrs)
 
     if (cp == NULL)
        cp = addrs;
-    else
-       if (*cp == 0)
-           return (cp = NULL);
+    else if (*cp == 0)
+        return cp = NULL;
 
     /* Remove leading any space from the address. */
     for (pp = cp; isspace ((unsigned char) *pp); pp++)
        continue;
     if (*pp == 0)
-       return (cp = NULL);
+       return cp = NULL;
     /* Find the end of the address. */
     for (qp = pp; *qp != 0 && *qp != ','; qp++)
        continue;
@@ -490,31 +388,6 @@ add_aka (struct aka *ak, char *pp)
 }
 
 
-void
-init_pw (void)
-{
-    struct passwd  *pw;
-    static int init;
-  
-    if (!init)
-    {
-       /* if the list has yet to be initialized */
-       /* zap the list, and rebuild from scratch */
-       homehead=NULL;
-       hometail=NULL;
-       init++;
-
-       setpwent ();
-
-       while ((pw = getpwent ()))
-           if (!hmalloc (pw))
-               break;
-
-       endpwent ();
-    }
-}
-
-
 static struct aka *
 akalloc (char *id)
 {
@@ -522,7 +395,7 @@ akalloc (char *id)
 
     NEW(p);
     p->ak_name = getcpy (id);
-    p->ak_visible = 0;
+    p->ak_visible = false;
     p->ak_addr = NULL;
     p->ak_next = NULL;
     if (akatail != NULL)
@@ -533,26 +406,3 @@ akalloc (char *id)
 
     return p;
 }
-
-
-static struct home *
-hmalloc (struct passwd *pw)
-{
-    struct home *p;
-
-    NEW(p);
-    p->h_name = getcpy (pw->pw_name);
-    p->h_uid = pw->pw_uid;
-    p->h_gid = pw->pw_gid;
-    p->h_home = getcpy (pw->pw_dir);
-    p->h_shell = getcpy (pw->pw_shell);
-    p->h_ngrps = 0;
-    p->h_next = NULL;
-    if (hometail != NULL)
-       hometail->h_next = p;
-    if (homehead == NULL)
-       homehead = p;
-    hometail = p;
-
-    return p;
-}