]> diplodocus.org Git - nmh/blobdiff - uip/aliasbr.c
picksbr.c: fprintf function pointer with unsigned-long-long cast.
[nmh] / uip / aliasbr.c
index 015f48a428ce076f3cacff8cc3843ec201744fbf..1376cad7eaada9724c26d913d092e2c73ea972f2 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,24 @@ 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 bool aleq (char *, char *);
 static char *scanp (char *);
 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. */
@@ -132,6 +122,8 @@ akval (struct aka *ak, char *s)
                if (mp  &&  mp->m_ingrp) {
                    char *gname = add (mp->m_gname, NULL);
 
+                    /* 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,16 +147,16 @@ 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++;
     }
 
@@ -202,7 +194,7 @@ alias (char *file)
                    fclose (fp);
                    return i;
                }
-               /* FALLTHRU */
+               continue;
            case ':':           /* comment */
            case ';': 
            case '#':
@@ -221,11 +213,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 +241,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 +271,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 +340,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,9 +348,8 @@ 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++)
@@ -490,31 +394,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 +401,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 +412,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;
-}