]> diplodocus.org Git - nmh/blobdiff - uip/aliasbr.c
Bump up size of two static char[] so gcc knows they won't overflow.
[nmh] / uip / aliasbr.c
index 069e454605f2367059c09915b3b67ba6649ced9b..489b707bdb43f1eb244da9b27fa3ee0daff333ec 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,15 +17,11 @@ 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);
@@ -39,12 +32,9 @@ 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);
@@ -163,7 +155,7 @@ aleq (char *string, char *aliasent)
     while ((c = *string++)) {
        if (*aliasent == '*')
            return 1;
-        if ((c | 040) != (*aliasent | 040))
+        if (tolower((unsigned char)c) != tolower((unsigned char)*aliasent))
             return 0;
         aliasent++;
     }
@@ -182,7 +174,7 @@ alias (char *file)
     FILE *fp;
 
     if (*file != '/'
-            && !HasPrefix(file, "./") && !HasPrefix(file, "../"))
+            && !has_prefix(file, "./") && !has_prefix(file, "../"))
        file = etcpath (file);
     if ((fp = fopen (file, "r")) == NULL) {
        akerrst = file;
@@ -202,7 +194,7 @@ alias (char *file)
                    fclose (fp);
                    return i;
                }
-
+               continue;
            case ':':           /* comment */
            case ';': 
            case '#':
@@ -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)
 {
@@ -490,31 +395,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)
 {
@@ -533,26 +413,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;
-}