diff --git a/alias.c b/alias.c index 79c296be5..57495fb95 100644 --- a/alias.c +++ b/alias.c @@ -114,7 +114,7 @@ alias_add(name, type, members) a = emalloc(sizeof(*a)); a->name = name; a->type = type; - list2head(&a->members, members); + list2tq(&a->members, members); if (rbinsert(aliases, a)) { efree(a); snprintf(errbuf, sizeof(errbuf), "Alias `%s' already defined", name); diff --git a/defaults.c b/defaults.c index d55a51272..fc630cb82 100644 --- a/defaults.c +++ b/defaults.c @@ -501,7 +501,7 @@ update_defaults(skip_cmnd) { struct defaults *def; - lh_foreach_fwd(&defaults, def) { + tq_foreach_fwd(&defaults, def) { if (skip_cmnd == (def->type == DEFAULTS_CMND)) continue; switch (def->type) { diff --git a/gram.y b/gram.y index 50c1dbf19..6e31dcd83 100644 --- a/gram.y +++ b/gram.y @@ -242,8 +242,8 @@ privileges : privilege privilege : hostlist '=' cmndspeclist { struct privilege *p = emalloc(sizeof(*p)); - list2head(&p->hostlist, $1); - list2head(&p->cmndlist, $3); + list2tq(&p->hostlist, $1); + list2tq(&p->cmndlist, $3); p->prev = p; p->next = NULL; $$ = p; @@ -287,8 +287,8 @@ cmndspeclist : cmndspec $3->tags.noexec = $3->prev->tags.noexec; if ($3->tags.setenv == UNSPEC) $3->tags.setenv = $3->prev->tags.setenv; - if (lh_empty(&$3->runaslist) && - !lh_empty(&$3->prev->runaslist)) + if (tq_empty(&$3->runaslist) && + !tq_empty(&$3->prev->runaslist)) $3->runaslist = $3->prev->runaslist; $$ = $1; } @@ -296,7 +296,7 @@ cmndspeclist : cmndspec cmndspec : runasspec cmndtag opcmnd { struct cmndspec *cs = emalloc(sizeof(*cs)); - list2head(&cs->runaslist, $1); + list2tq(&cs->runaslist, $1); cs->tags = $2; cs->cmnd = $3; cs->prev = cs; @@ -506,7 +506,7 @@ new_default(var, val, op) d = emalloc(sizeof(struct defaults)); d->var = var; d->val = val; - lh_init(&d->binding); + tq_init(&d->binding); d->type = 0; d->op = op; d->prev = d; @@ -549,9 +549,9 @@ add_defaults(type, binding, defs) */ for (d = defs; d != NULL; d = d->next) { d->type = type; - list2head(&d->binding, binding); + list2tq(&d->binding, binding); } - lh_append(&defaults, defs); + tq_append(&defaults, defs); } /* @@ -566,11 +566,11 @@ add_userspec(members, privs) struct userspec *u; u = emalloc(sizeof(*u)); - list2head(&u->users, members); - list2head(&u->privileges, privs); + list2tq(&u->users, members); + list2tq(&u->privileges, privs); u->prev = u; u->next = NULL; - lh_append(&userspecs, u); + tq_append(&userspecs, u); } /* @@ -588,21 +588,21 @@ init_parser(path, quiet) struct privilege *priv; struct cmndspec *cs; - while ((us = lh_pop(&userspecs)) != NULL) { - while ((m = lh_pop(&us->users)) != NULL) { + while ((us = tq_pop(&userspecs)) != NULL) { + while ((m = tq_pop(&us->users)) != NULL) { efree(m->name); efree(m); } - while ((priv = lh_pop(&us->privileges)) != NULL) { - while ((m = lh_pop(&priv->hostlist)) != NULL) { + while ((priv = tq_pop(&us->privileges)) != NULL) { + while ((m = tq_pop(&priv->hostlist)) != NULL) { efree(m->name); efree(m); } freed = NULL; - while ((cs = lh_pop(&priv->cmndlist)) != NULL) { - if (lh_last(&cs->runaslist) != freed) { - freed = lh_last(&cs->runaslist); - while ((m = lh_pop(&cs->runaslist)) != NULL) { + while ((cs = tq_pop(&priv->cmndlist)) != NULL) { + if (tq_last(&cs->runaslist) != freed) { + freed = tq_last(&cs->runaslist); + while ((m = tq_pop(&cs->runaslist)) != NULL) { efree(m->name); efree(m); } @@ -614,13 +614,13 @@ init_parser(path, quiet) efree(priv); } } - lh_init(&userspecs); + tq_init(&userspecs); freed = NULL; - while ((d = lh_pop(&defaults)) != NULL) { - if (lh_last(&d->binding) != freed) { - freed = lh_last(&d->binding); - while ((m = lh_pop(&d->binding)) != NULL) { + while ((d = tq_pop(&defaults)) != NULL) { + if (tq_last(&d->binding) != freed) { + freed = tq_last(&d->binding); + while ((m = tq_pop(&d->binding)) != NULL) { efree(m->name); efree(m); } @@ -629,7 +629,7 @@ init_parser(path, quiet) efree(d->val); efree(d); } - lh_init(&defaults); + tq_init(&defaults); init_aliases(); diff --git a/list.c b/list.c index 0f1073160..89b715ed2 100644 --- a/list.c +++ b/list.c @@ -51,13 +51,13 @@ struct list_head_proto { * Returns the popped element. */ void * -lh_pop(vh) +tq_pop(vh) void *vh; { struct list_head_proto *h = (struct list_head_proto *)vh; void *last = NULL; - if (!lh_empty(h)) { + if (!tq_empty(h)) { last = (void *)h->last; if (h->first == h->last) { h->first = NULL; @@ -75,7 +75,7 @@ lh_pop(vh) * with a head node. */ void -list2head(vh, vl) +list2tq(vh, vl) void *vh; void *vl; { @@ -115,7 +115,7 @@ list_append(vl1, vl2) * e from a semi-circle queue to normal doubly-linked list. */ void -lh_append(vh, vl) +tq_append(vh, vl) void *vh; void *vl; { diff --git a/list.h b/list.h index 3d7548451..a1dcd82d8 100644 --- a/list.h +++ b/list.h @@ -23,13 +23,13 @@ * Convenience macro for declaring a list head. */ #ifdef __STDC__ -#define LH_DECLARE(n) \ +#define TQ_DECLARE(n) \ struct n##_list { \ struct n *first; \ struct n *last; \ }; #else -#define LH_DECLARE(n) \ +#define TQ_DECLARE(n) \ struct n/**/_list { \ struct n *first; \ struct n *last; \ @@ -39,19 +39,19 @@ struct n/**/_list { \ /* * Foreach loops: forward and reverse */ -#undef lh_foreach_fwd -#define lh_foreach_fwd(h, v) \ +#undef tq_foreach_fwd +#define tq_foreach_fwd(h, v) \ for ((v) = (h)->first; (v) != NULL; (v) = (v)->next) -#undef lh_foreach_rev -#define lh_foreach_rev(h, v) \ +#undef tq_foreach_rev +#define tq_foreach_rev(h, v) \ for ((v) = (h)->last; (v) != NULL; (v) = (v)->prev) /* * Init a list head. */ -#undef lh_init -#define lh_init(h) do { \ +#undef tq_init +#define tq_init(h) do { \ (h)->first = NULL; \ (h)->last = NULL; \ } while (0) @@ -59,14 +59,14 @@ struct n/**/_list { \ /* * Simple macros to avoid exposing first/last and prev/next. */ -#undef lh_empty -#define lh_empty(h) ((h)->first == NULL) +#undef tq_empty +#define tq_empty(h) ((h)->first == NULL) -#undef lh_first -#define lh_first(h) ((h)->first) +#undef tq_first +#define tq_first(h) ((h)->first) -#undef lh_last -#define lh_last(h) ((h)->last) +#undef tq_last +#define tq_last(h) ((h)->last) #undef list_next #define list_next(e) ((e)->next) @@ -77,9 +77,9 @@ struct n/**/_list { \ /* * Prototypes for list.c */ -void *lh_pop __P((void *)); -void lh_append __P((void *, void *)); +void *tq_pop __P((void *)); +void tq_append __P((void *, void *)); void list_append __P((void *, void *)); -void list2head __P((void *, void *)); +void list2tq __P((void *, void *)); #endif /* _SUDO_LIST_H */ diff --git a/match.c b/match.c index b070f3a18..fc9fd5127 100644 --- a/match.c +++ b/match.c @@ -111,7 +111,7 @@ userlist_matches(pw, list) struct alias *a; int rval, matched = UNSPEC; - lh_foreach_rev(list, m) { + tq_foreach_rev(list, m) { switch (m->type) { case ALL: matched = !m->negated; @@ -156,10 +156,10 @@ runaslist_matches(list) struct alias *a; int rval, matched = UNSPEC; - if (lh_empty(list)) + if (tq_empty(list)) return(userpw_matches(def_runas_default, runas_pw->pw_name, runas_pw)); - lh_foreach_rev(list, m) { + tq_foreach_rev(list, m) { switch (m->type) { case ALL: matched = !m->negated; @@ -203,7 +203,7 @@ hostlist_matches(list) struct alias *a; int rval, matched = UNSPEC; - lh_foreach_rev(list, m) { + tq_foreach_rev(list, m) { switch (m->type) { case ALL: matched = !m->negated; @@ -278,7 +278,7 @@ cmndlist_matches(list) struct member *m; int rval, matched = UNSPEC; - lh_foreach_rev(list, m) { + tq_foreach_rev(list, m) { rval = cmnd_matches(m); if (rval != UNSPEC) { matched = m->negated ? !rval : rval; diff --git a/parse.c b/parse.c index 5e28b68f9..ffe7c910a 100644 --- a/parse.c +++ b/parse.c @@ -109,13 +109,13 @@ sudoers_lookup(pwflag) CLR(validated, FLAG_NO_USER); CLR(validated, FLAG_NO_HOST); match = DENY; - lh_foreach_rev(&userspecs, us) { + tq_foreach_rev(&userspecs, us) { if (userlist_matches(sudo_user.pw, &us->users) != ALLOW) continue; - lh_foreach_rev(&us->privileges, priv) { + tq_foreach_rev(&us->privileges, priv) { if (hostlist_matches(&priv->hostlist) != ALLOW) continue; - lh_foreach_rev(&priv->cmndlist, cs) { + tq_foreach_rev(&priv->cmndlist, cs) { /* Only check the command when listing another user. */ if (user_uid == 0 || list_pw == NULL || user_uid == list_pw->pw_uid || @@ -146,17 +146,17 @@ sudoers_lookup(pwflag) set_perms(PERM_RUNAS); match = UNSPEC; - lh_foreach_rev(&userspecs, us) { + tq_foreach_rev(&userspecs, us) { if (userlist_matches(sudo_user.pw, &us->users) != ALLOW) continue; CLR(validated, FLAG_NO_USER); - lh_foreach_rev(&us->privileges, priv) { + tq_foreach_rev(&us->privileges, priv) { host_match = hostlist_matches(&priv->hostlist); if (host_match == ALLOW) CLR(validated, FLAG_NO_HOST); else continue; - lh_foreach_rev(&priv->cmndlist, cs) { + tq_foreach_rev(&priv->cmndlist, cs) { runas_match = runaslist_matches(&cs->runaslist); if (runas_match == ALLOW) { cmnd_match = cmnd_matches(cs->cmnd); @@ -224,24 +224,24 @@ display_privs(v, pw) printf("User %s may run the following commands on this host:\n", pw->pw_name); - lh_foreach_fwd(&userspecs, us) { + tq_foreach_fwd(&userspecs, us) { /* XXX - why only check the first privilege here? */ if (userlist_matches(pw, &us->users) != ALLOW || hostlist_matches(&us->privileges.first->hostlist) != ALLOW) continue; - lh_foreach_fwd(&us->privileges, priv) { + tq_foreach_fwd(&us->privileges, priv) { tags.noexec = def_noexec; tags.setenv = def_setenv; tags.nopasswd = !def_authenticate; lbuf_append(&lbuf, " ", NULL); - lh_foreach_fwd(&priv->cmndlist, cs) { - if (cs != lh_first(&priv->cmndlist)) + tq_foreach_fwd(&priv->cmndlist, cs) { + if (cs != tq_first(&priv->cmndlist)) lbuf_append(&lbuf, ", ", NULL); lbuf_append(&lbuf, "(", NULL); - if (!lh_empty(&cs->runaslist)) { - lh_foreach_fwd(&cs->runaslist, m) { - if (m != lh_first(&cs->runaslist)) + if (!tq_empty(&cs->runaslist)) { + tq_foreach_fwd(&cs->runaslist, m) { + if (m != tq_first(&cs->runaslist)) lbuf_append(&lbuf, ", ", NULL); print_member(&lbuf, m->name, m->type, m->negated, RUNASALIAS); @@ -294,7 +294,7 @@ display_defaults(pw) lbuf_init(&lbuf, NULL, 4, 0); - lh_foreach_fwd(&defaults, d) { + tq_foreach_fwd(&defaults, d) { switch (d->type) { case DEFAULTS_HOST: if (hostlist_matches(&d->binding) != ALLOW) @@ -381,12 +381,12 @@ display_bound_defaults(dtype) } lbuf_init(&lbuf, NULL, 4, 0); printf("Per-%s Defaults entries:\n", dname); - lh_foreach_fwd(&defaults, d) { + tq_foreach_fwd(&defaults, d) { if (d->type != dtype) continue; - if (binding != lh_first(&d->binding)) { - binding = lh_first(&d->binding); + if (binding != tq_first(&d->binding)) { + binding = tq_first(&d->binding); lbuf_append(&lbuf, " Defaults", dsep, NULL); for (m = binding; m != NULL; m = m->next) { if (m != binding) @@ -429,15 +429,15 @@ display_cmnd(v, pw) #endif if (rval != 0 && !def_ignore_local_sudoers) { match = NULL; - lh_foreach_rev(&userspecs, us) { + tq_foreach_rev(&userspecs, us) { if (userlist_matches(pw, &us->users) != ALLOW) continue; - lh_foreach_rev(&us->privileges, priv) { + tq_foreach_rev(&us->privileges, priv) { host_match = hostlist_matches(&priv->hostlist); if (host_match != ALLOW) continue; - lh_foreach_rev(&priv->cmndlist, cs) { + tq_foreach_rev(&priv->cmndlist, cs) { runas_match = runaslist_matches(&cs->runaslist); if (runas_match == ALLOW) { cmnd_match = cmnd_matches(cs->cmnd); @@ -489,8 +489,8 @@ print_member(lbuf, name, type, negated, alias_type) break; case ALIAS: if ((a = find_alias(name, alias_type)) != NULL) { - lh_foreach_fwd(&a->members, m) { - if (m != lh_first(&a->members)) + tq_foreach_fwd(&a->members, m) { + if (m != tq_first(&a->members)) lbuf_append(lbuf, ", ", NULL); print_member(lbuf, m->name, m->type, negated ? !m->negated : m->negated, alias_type); diff --git a/parse.h b/parse.h index 8244b8118..ebc6b12a0 100644 --- a/parse.h +++ b/parse.h @@ -68,11 +68,11 @@ struct cmndtag { /* * Tail queue list head structure. */ -LH_DECLARE(defaults) -LH_DECLARE(userspec) -LH_DECLARE(member) -LH_DECLARE(privilege) -LH_DECLARE(cmndspec) +TQ_DECLARE(defaults) +TQ_DECLARE(userspec) +TQ_DECLARE(member) +TQ_DECLARE(privilege) +TQ_DECLARE(cmndspec) /* * Structure describing a user specification and list thereof. diff --git a/testsudoers.c b/testsudoers.c index 582a77e9e..b7016968c 100644 --- a/testsudoers.c +++ b/testsudoers.c @@ -268,16 +268,16 @@ main(argc, argv) /* This loop must match the one in sudoers_lookup() */ printf("\nEntries for user %s:\n", user_name); matched = UNSPEC; - lh_foreach_rev(&userspecs, us) { + tq_foreach_rev(&userspecs, us) { if (userlist_matches(sudo_user.pw, &us->users) != ALLOW) continue; - lh_foreach_rev(&us->privileges, priv) { + tq_foreach_rev(&us->privileges, priv) { putchar('\n'); print_privilege(priv); /* XXX */ putchar('\n'); if (hostlist_matches(&priv->hostlist) == ALLOW) { puts("\thost matched"); - lh_foreach_rev(&priv->cmndlist, cs) { + tq_foreach_rev(&priv->cmndlist, cs) { if (runaslist_matches(&cs->runaslist) == ALLOW) { puts("\trunas matched"); rval = cmnd_matches(cs->cmnd); @@ -385,7 +385,7 @@ print_defaults() struct defaults *d; struct member *m; - lh_foreach_fwd(&defaults, d) { + tq_foreach_fwd(&defaults, d) { (void) fputs("Defaults", stdout); switch (d->type) { case DEFAULTS_HOST: @@ -401,8 +401,8 @@ print_defaults() putchar('!'); break; } - lh_foreach_fwd(&d->binding, m) { - if (m != lh_first(&d->binding)) + tq_foreach_fwd(&d->binding, m) { + if (m != tq_first(&d->binding)) putchar(','); print_member(m); } @@ -436,8 +436,8 @@ print_alias(v1, v2) (void) printf("Runas_Alias\t%s = ", a->name); break; } - lh_foreach_fwd(&a->members, m) { - if (m != lh_first(&a->members)) + tq_foreach_fwd(&a->members, m) { + if (m != tq_first(&a->members)) fputs(", ", stdout); if (m->type == COMMAND) { c = (struct sudo_command *) m->name; @@ -462,20 +462,20 @@ print_privilege(priv) for (p = priv; p != NULL; p = p->next) { if (p != priv) fputs(" : ", stdout); - lh_foreach_fwd(&p->hostlist, m) { - if (m != lh_first(&p->hostlist)) + tq_foreach_fwd(&p->hostlist, m) { + if (m != tq_first(&p->hostlist)) fputs(", ", stdout); print_member(m); } fputs(" = ", stdout); tags.nopasswd = tags.noexec = UNSPEC; - lh_foreach_fwd(&p->cmndlist, cs) { - if (cs != lh_first(&p->cmndlist)) + tq_foreach_fwd(&p->cmndlist, cs) { + if (cs != tq_first(&p->cmndlist)) fputs(", ", stdout); - if (!lh_empty(&cs->runaslist)) { + if (!tq_empty(&cs->runaslist)) { fputs("(", stdout); - lh_foreach_fwd(&cs->runaslist, m) { - if (m != lh_first(&cs->runaslist)) + tq_foreach_fwd(&cs->runaslist, m) { + if (m != tq_first(&cs->runaslist)) fputs(", ", stdout); print_member(m); } @@ -497,9 +497,9 @@ print_userspecs() struct member *m; struct userspec *us; - lh_foreach_fwd(&userspecs, us) { - lh_foreach_fwd(&us->users, m) { - if (m != lh_first(&us->users)) + tq_foreach_fwd(&userspecs, us) { + tq_foreach_fwd(&us->users, m) { + if (m != tq_first(&us->users)) fputs(", ", stdout); print_member(m); } diff --git a/visudo.c b/visudo.c index 5304ccfb8..70522c4cd 100644 --- a/visudo.c +++ b/visudo.c @@ -213,8 +213,8 @@ main(argc, argv) setup_signals(); /* Edit the sudoers file(s) */ - lh_foreach_fwd(&sudoerslist, sp) { - if (sp != lh_first(&sudoerslist)) { + tq_foreach_fwd(&sudoerslist, sp) { + if (sp != tq_first(&sudoerslist)) { printf("press return to edit %s: ", sp->path); while ((ch = getchar()) != EOF && ch != '\n') continue; @@ -226,7 +226,7 @@ main(argc, argv) reparse_sudoers(editor, args, strict, quiet); /* Install the sudoers temp files. */ - lh_foreach_fwd(&sudoerslist, sp) { + tq_foreach_fwd(&sudoerslist, sp) { if (!sp->modified) (void) unlink(sp->tpath); else @@ -401,8 +401,8 @@ reparse_sudoers(editor, args, strict, quiet) * Parse the edited sudoers files and do sanity checking */ do { - sp = lh_first(&sudoerslist); - last = lh_last(&sudoerslist); + sp = tq_first(&sudoerslist); + last = tq_last(&sudoerslist); fp = fopen(sp->tpath, "r+"); if (fp == NULL) errorx(1, "can't re-open temporary file (%s), %s unchanged.", @@ -438,7 +438,7 @@ reparse_sudoers(editor, args, strict, quiet) } if (parse_error) { /* Edit file with the parse error */ - lh_foreach_fwd(&sudoerslist, sp) { + tq_foreach_fwd(&sudoerslist, sp) { if (errorfile == NULL || strcmp(sp->path, errorfile) == 0) { edit_sudoers(sp, editor, args, errorlineno); break; @@ -725,7 +725,7 @@ open_sudoers(path, keepopen) FILE *fp; /* Check for existing entry */ - lh_foreach_fwd(&sudoerslist, entry) { + tq_foreach_fwd(&sudoerslist, entry) { if (strcmp(path, entry->path) == 0) break; } @@ -903,8 +903,8 @@ check_aliases(strict) int error = 0; /* Forward check. */ - lh_foreach_fwd(&userspecs, us) { - lh_foreach_fwd(&us->users, m) { + tq_foreach_fwd(&userspecs, us) { + tq_foreach_fwd(&us->users, m) { if (m->type == USERALIAS) { if (find_alias(m->name, m->type) == NULL) { fprintf(stderr, @@ -914,8 +914,8 @@ check_aliases(strict) } } } - lh_foreach_fwd(&us->privileges, priv) { - lh_foreach_fwd(&priv->hostlist, m) { + tq_foreach_fwd(&us->privileges, priv) { + tq_foreach_fwd(&priv->hostlist, m) { if (m->type == HOSTALIAS) { if (find_alias(m->name, m->type) == NULL) { fprintf(stderr, @@ -925,8 +925,8 @@ check_aliases(strict) } } } - lh_foreach_fwd(&priv->cmndlist, cs) { - lh_foreach_fwd(&cs->runaslist, m) { + tq_foreach_fwd(&priv->cmndlist, cs) { + tq_foreach_fwd(&cs->runaslist, m) { if (m->type == RUNASALIAS) { if (find_alias(m->name, m->type) == NULL) { fprintf(stderr, @@ -949,18 +949,18 @@ check_aliases(strict) } /* Reverse check (destructive) */ - lh_foreach_fwd(&userspecs, us) { - lh_foreach_fwd(&us->users, m) { + tq_foreach_fwd(&userspecs, us) { + tq_foreach_fwd(&us->users, m) { if (m->type == USERALIAS) (void) alias_remove(m->name, m->type); } - lh_foreach_fwd(&us->privileges, priv) { - lh_foreach_fwd(&priv->hostlist, m) { + tq_foreach_fwd(&us->privileges, priv) { + tq_foreach_fwd(&priv->hostlist, m) { if (m->type == HOSTALIAS) (void) alias_remove(m->name, m->type); } - lh_foreach_fwd(&priv->cmndlist, cs) { - lh_foreach_fwd(&cs->runaslist, m) { + tq_foreach_fwd(&priv->cmndlist, cs) { + tq_foreach_fwd(&cs->runaslist, m) { if (m->type == RUNASALIAS) (void) alias_remove(m->name, m->type); } @@ -1000,7 +1000,7 @@ cleanup(gotsignal) { struct sudoersfile *sp; - lh_foreach_fwd(&sudoerslist, sp) { + tq_foreach_fwd(&sudoerslist, sp) { if (sp->tpath != NULL) (void) unlink(sp->tpath); }