]> granicus.if.org Git - sudo/commitdiff
Convert NEW_DEFAULT anf NEW_MEMBER into static functions.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 31 Aug 2007 17:56:30 +0000 (17:56 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 31 Aug 2007 17:56:30 +0000 (17:56 +0000)
gram.y
parse.h

diff --git a/gram.y b/gram.y
index b94d8cb75ab44e407b5608d5b57fbb7b974c9075..5d1cad807ea6c81ee12ded6738d8763e38cece64 100644 (file)
--- a/gram.y
+++ b/gram.y
@@ -75,6 +75,8 @@ struct userspec_list userspecs;
  */
 static void  add_defaults      __P((int, struct member *, struct defaults *));
 static void  add_userspec      __P((struct member *, struct privilege *));
+static struct defaults *new_default __P((char *, char *, int));
+static struct member *new_member __P((char *, int));
        void  yyerror           __P((const char *));
 
 void
@@ -215,19 +217,19 @@ defaults_list     :       defaults_entry
                ;
 
 defaults_entry :       DEFVAR {
-                           NEW_DEFAULT($$, $1, NULL, TRUE);
+                           $$ = new_default($1, NULL, TRUE);
                        }
                |       '!' DEFVAR {
-                           NEW_DEFAULT($$, $2, NULL, FALSE);
+                           $$ = new_default($2, NULL, FALSE);
                        }
                |       DEFVAR '=' WORD {
-                           NEW_DEFAULT($$, $1, $3, TRUE);
+                           $$ = new_default($1, $3, TRUE);
                        }
                |       DEFVAR '+' WORD {
-                           NEW_DEFAULT($$, $1, $3, '+');
+                           $$ = new_default($1, $3, '+');
                        }
                |       DEFVAR '-' WORD {
-                           NEW_DEFAULT($$, $1, $3, '-');
+                           $$ = new_default($1, $3, '-');
                        }
                ;
 
@@ -278,19 +280,19 @@ ophost            :       host {
                ;
 
 host           :       ALIAS {
-                           NEW_MEMBER($$, $1, ALIAS);
+                           $$ = new_member($1, ALIAS);
                        }
                |       ALL {
-                           NEW_MEMBER($$, NULL, ALL);
+                           $$ = new_member(NULL, ALL);
                        }
                |       NETGROUP {
-                           NEW_MEMBER($$, $1, NETGROUP);
+                           $$ = new_member($1, NETGROUP);
                        }
                |       NTWKADDR {
-                           NEW_MEMBER($$, $1, NTWKADDR);
+                           $$ = new_member($1, NTWKADDR);
                        }
                |       WORD {
-                           NEW_MEMBER($$, $1, WORD);
+                           $$ = new_member($1, WORD);
                        }
                ;
 
@@ -348,19 +350,19 @@ oprunasuser       :       runasuser {
                ;
 
 runasuser      :       ALIAS {
-                           NEW_MEMBER($$, $1, ALIAS);
+                           $$ = new_member($1, ALIAS);
                        }
                |       ALL {
-                           NEW_MEMBER($$, NULL, ALL);
+                           $$ = new_member(NULL, ALL);
                        }
                |       NETGROUP {
-                           NEW_MEMBER($$, $1, NETGROUP);
+                           $$ = new_member($1, NETGROUP);
                        }
                |       USERGROUP {
-                           NEW_MEMBER($$, $1, USERGROUP);
+                           $$ = new_member($1, USERGROUP);
                        }
                |       WORD {
-                           NEW_MEMBER($$, $1, WORD);
+                           $$ = new_member($1, WORD);
                        }
                ;
 
@@ -388,16 +390,16 @@ cmndtag           :       /* empty */ {
                ;
 
 cmnd           :       ALL {
-                           NEW_MEMBER($$, NULL, ALL);
+                           $$ = new_member(NULL, ALL);
                        }
                |       ALIAS {
-                           NEW_MEMBER($$, $1, ALIAS);
+                           $$ = new_member($1, ALIAS);
                        }
                |       COMMAND {
                            struct sudo_command *c = emalloc(sizeof(*c));
                            c->cmnd = $1.cmnd;
                            c->args = $1.args;
-                           NEW_MEMBER($$, (char *)c, COMMAND);
+                           $$ = new_member((char *)c, COMMAND);
                        }
                ;
 
@@ -485,23 +487,59 @@ opuser            :       user {
                ;
 
 user           :       ALIAS {
-                           NEW_MEMBER($$, $1, ALIAS);
+                           $$ = new_member($1, ALIAS);
                        }
                |       ALL {
-                           NEW_MEMBER($$, NULL, ALL);
+                           $$ = new_member(NULL, ALL);
                        }
                |       NETGROUP {
-                           NEW_MEMBER($$, $1, NETGROUP);
+                           $$ = new_member($1, NETGROUP);
                        }
                |       USERGROUP {
-                           NEW_MEMBER($$, $1, USERGROUP);
+                           $$ = new_member($1, USERGROUP);
                        }
                |       WORD {
-                           NEW_MEMBER($$, $1, WORD);
+                           $$ = new_member($1, WORD);
                        }
                ;
 
 %%
+static struct defaults *
+new_default(var, val, op)
+    char *var;
+    char *val;
+    int op;
+{
+    struct defaults *d;
+
+    d = emalloc(sizeof(struct defaults));
+    d->var = var;
+    d->val = val;
+    LH_INIT(&d->binding);
+    d->type = 0;
+    d->op = op;
+    d->prev = d;
+    d->next = NULL;
+
+    return(d);
+}
+
+static struct member *
+new_member(name, type)
+    char *name;
+    int type;
+{
+    struct member *m;
+
+    m = emalloc(sizeof(struct member));
+    m->name = name;
+    m->type = type;
+    m->prev = m;
+    m->next = NULL;
+
+    return(m);
+}
+
 /*
  * Add a list of defaults structures to the defaults list.
  * The binding, if non-NULL, specifies a list of hosts, users, or
diff --git a/parse.h b/parse.h
index 793544b226646730073dc7b6c3b4426020152a4c..a6e6b464f9cccfff9ee92b8860f78ec26b26a9d0 100644 (file)
--- a/parse.h
+++ b/parse.h
@@ -148,31 +148,6 @@ struct defaults {
     struct defaults *prev, *next;
 };
 
-/*
- * Allocate space for a defaults entry and populate it.
- */
-#undef NEW_DEFAULT
-#define NEW_DEFAULT(r, v1, v2, o) do {                 \
-    (r)       = emalloc(sizeof(struct defaults));      \
-    (r)->var  = (v1);                                  \
-    (r)->val  = (v2);                                  \
-    (r)->op   = (o);                                   \
-    (r)->prev = (r);                                   \
-    (r)->next = NULL;                                  \
-} while (0)
-
-/*
- * Allocate space for a member and populate it.
- */
-#undef NEW_MEMBER
-#define NEW_MEMBER(r, n, t) do {                       \
-    (r)       = emalloc(sizeof(struct member));                \
-    (r)->name = (n);                                   \
-    (r)->type = (t);                                   \
-    (r)->prev = (r);                                   \
-    (r)->next = NULL;                                  \
-} while (0)
-
 /*
  * Append one queue (or single entry) to another using the
  * circular properties of the prev pointer to simplify the logic.