From: Todd C. Miller Date: Fri, 31 Aug 2007 01:12:50 +0000 (+0000) Subject: Change list head macros to take a pointer, not a struct. X-Git-Tag: SUDO_1_7_0~392 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d1dbe2ecee132524fd7474d09f6412b62f675f77;p=sudo Change list head macros to take a pointer, not a struct. --- diff --git a/defaults.c b/defaults.c index ec016b879..27d17340c 100644 --- a/defaults.c +++ b/defaults.c @@ -501,7 +501,7 @@ update_defaults(skip_cmnd) { struct defaults *def; - LH_FOREACH_FWD(defaults, def) { + LH_FOREACH_FWD(&defaults, def) { if (skip_cmnd == (def->type == DEFAULTS_CMND)) continue; switch (def->type) { diff --git a/gram.y b/gram.y index 0d965a3a8..b94d8cb75 100644 --- a/gram.y +++ b/gram.y @@ -246,8 +246,8 @@ privilege : hostlist '=' cmndspeclist { /* propagate tags and runas lists */ tags.nopasswd = tags.noexec = tags.setenv = UNSPEC; for (cs = $3; cs != NULL; cs = cs->next) { - if (LH_EMPTY(cs->runaslist) && - !LH_EMPTY(cs->prev->runaslist)) { + if (LH_EMPTY(&cs->runaslist) && + !LH_EMPTY(&cs->prev->runaslist)) { memcpy(&cs->runaslist, &cs->prev->runaslist, sizeof(cs->runaslist)); } @@ -559,24 +559,24 @@ init_parser(path, quiet) struct privilege *priv; struct cmndspec *cs; - while ((us = LH_LAST(userspecs)) != NULL) { - LH_POP(userspecs); - while ((m = LH_LAST(us->users)) != NULL) { - LH_POP(us->users); + while ((us = LH_LAST(&userspecs)) != NULL) { + LH_POP(&userspecs); + while ((m = LH_LAST(&us->users)) != NULL) { + LH_POP(&us->users); efree(m->name); efree(m); } - while ((priv = LH_LAST(us->privileges)) != NULL) { - LH_POP(us->privileges); - while ((m = LH_LAST(priv->hostlist)) != NULL) { - LH_POP(priv->hostlist); + while ((priv = LH_LAST(&us->privileges)) != NULL) { + LH_POP(&us->privileges); + while ((m = LH_LAST(&priv->hostlist)) != NULL) { + LH_POP(&priv->hostlist); efree(m->name); efree(m); } - while ((cs = LH_LAST(priv->cmndlist)) != NULL) { - LH_POP(priv->cmndlist); - while ((m = LH_LAST(cs->runaslist)) != NULL) { - LH_POP(cs->runaslist); + while ((cs = LH_LAST(&priv->cmndlist)) != NULL) { + LH_POP(&priv->cmndlist); + while ((m = LH_LAST(&cs->runaslist)) != NULL) { + LH_POP(&cs->runaslist); efree(m->name); efree(m); } @@ -587,15 +587,15 @@ init_parser(path, quiet) efree(priv); } } - LH_INIT(userspecs); + LH_INIT(&userspecs); lastbinding = NULL; - while ((d = LH_LAST(defaults)) != NULL) { - LH_POP(defaults); - if (LH_FIRST(d->binding) != lastbinding) { - lastbinding = LH_FIRST(d->binding); - while ((m = LH_LAST(d->binding)) != NULL) { - LH_POP(d->binding); + while ((d = LH_LAST(&defaults)) != NULL) { + LH_POP(&defaults); + if (LH_FIRST(&d->binding) != lastbinding) { + lastbinding = LH_FIRST(&d->binding); + while ((m = LH_LAST(&d->binding)) != NULL) { + LH_POP(&d->binding); efree(m->name); efree(m); } @@ -604,7 +604,7 @@ init_parser(path, quiet) efree(d->val); efree(d); } - LH_INIT(defaults); + LH_INIT(&defaults); init_aliases(); diff --git a/parse.c b/parse.c index 56ff01bef..2433005eb 100644 --- a/parse.c +++ b/parse.c @@ -112,13 +112,13 @@ sudoers_lookup(pwflag) match = DENY; /* XXX - it should be faster to start from the bottom and work our way up and then just stop at the first match. */ - LH_FOREACH_FWD(userspecs, us) { + LH_FOREACH_FWD(&userspecs, us) { if (userlist_matches(sudo_user.pw, &us->users) != ALLOW) continue; - LH_FOREACH_FWD(us->privileges, priv) { + LH_FOREACH_FWD(&us->privileges, priv) { if (hostlist_matches(&priv->hostlist) != ALLOW) continue; - LH_FOREACH_FWD(priv->cmndlist, cs) { + LH_FOREACH_FWD(&priv->cmndlist, cs) { /* Only check the command when listing another user. */ if (user_uid == 0 || list_pw == NULL || user_uid == list_pw->pw_uid || @@ -148,19 +148,19 @@ sudoers_lookup(pwflag) /* XXX - it should be faster to start from the bottom and work our way up and then just stop at the first match. */ match = UNSPEC; - LH_FOREACH_FWD(userspecs, us) { + LH_FOREACH_FWD(&userspecs, us) { if (userlist_matches(sudo_user.pw, &us->users) != ALLOW) continue; CLR(validated, FLAG_NO_USER); - LH_FOREACH_FWD(us->privileges, priv) { + LH_FOREACH_FWD(&us->privileges, priv) { host_match = hostlist_matches(&priv->hostlist); if (host_match == UNSPEC) continue; if (host_match == ALLOW) CLR(validated, FLAG_NO_HOST); runas = NULL; - LH_FOREACH_FWD(priv->cmndlist, cs) { - if (!LH_EMPTY(cs->runaslist)) + LH_FOREACH_FWD(&priv->cmndlist, cs) { + if (!LH_EMPTY(&cs->runaslist)) runas = &cs->runaslist; runas_match = runaslist_matches(runas); if (runas_match != UNSPEC) { @@ -227,24 +227,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) { + LH_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) { + LH_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)) + LH_FOREACH_FWD(&priv->cmndlist, cs) { + if (cs != LH_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 (!LH_EMPTY(&cs->runaslist)) { + LH_FOREACH_FWD(&cs->runaslist, m) { + if (m != LH_FIRST(&cs->runaslist)) lbuf_append(&lbuf, ", ", NULL); print_member(&lbuf, m->name, m->type, m->negated, RUNASALIAS); @@ -297,7 +297,7 @@ display_defaults(pw) lbuf_init(&lbuf, NULL, 4, 0); - LH_FOREACH_FWD(defaults, d) { + LH_FOREACH_FWD(&defaults, d) { switch (d->type) { case DEFAULTS_HOST: if (hostlist_matches(&d->binding) != ALLOW) @@ -384,12 +384,12 @@ display_bound_defaults(dtype) } lbuf_init(&lbuf, NULL, 4, 0); printf("Per-%s Defaults entries:\n", dname); - LH_FOREACH_FWD(defaults, d) { + LH_FOREACH_FWD(&defaults, d) { if (d->type != dtype) continue; - if (binding != LH_FIRST(d->binding)) { - binding = LH_FIRST(d->binding); + if (binding != LH_FIRST(&d->binding)) { + binding = LH_FIRST(&d->binding); lbuf_append(&lbuf, " Defaults", dsep, NULL); for (m = binding; m != NULL; m = m->next) { if (m != binding) @@ -433,17 +433,17 @@ display_cmnd(v, pw) #endif if (rval != 0 && !def_ignore_local_sudoers) { match = NULL; - LH_FOREACH_FWD(userspecs, us) { + LH_FOREACH_FWD(&userspecs, us) { if (userlist_matches(pw, &us->users) != ALLOW) continue; - LH_FOREACH_FWD(us->privileges, priv) { + LH_FOREACH_FWD(&us->privileges, priv) { host_match = hostlist_matches(&priv->hostlist); if (host_match == UNSPEC) continue; runas = NULL; - LH_FOREACH_FWD(priv->cmndlist, cs) { - if (!LH_EMPTY(cs->runaslist) != NULL) + LH_FOREACH_FWD(&priv->cmndlist, cs) { + if (!LH_EMPTY(&cs->runaslist) != NULL) runas = &cs->runaslist; runas_match = runaslist_matches(runas); if (runas_match != UNSPEC) { @@ -493,8 +493,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)) + LH_FOREACH_FWD(&a->members, m) { + if (m != LH_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 b181f414c..793544b22 100644 --- a/parse.h +++ b/parse.h @@ -218,11 +218,11 @@ struct defaults { #undef LH_FOREACH_FWD #define LH_FOREACH_FWD(h, v) \ - for ((v) = (h).first; (v) != NULL; (v) = (v)->next) + for ((v) = (h)->first; (v) != NULL; (v) = (v)->next) #undef LH_FOREACH_REV #define LH_FOREACH_REV(h, v) \ - for ((v) = (h).last; (v) != NULL; (v) = (v)->prev) + for ((v) = (h)->last; (v) != NULL; (v) = (v)->prev) /* * Pop the last element off the end of h. @@ -231,29 +231,29 @@ struct defaults { #undef LH_POP #define LH_POP(h) do { \ if (!LH_EMPTY(h)) { \ - if ((h).first == (h).last) \ - (h).first = (h).last = NULL; \ + if ((h)->first == (h)->last) \ + (h)->first = (h)->last = NULL; \ else { \ - (h).last = (h).last->prev; \ - (h).last->next = NULL; \ + (h)->last = (h)->last->prev; \ + (h)->last->next = NULL; \ } \ } \ } while (0) #undef LH_INIT #define LH_INIT(h) do { \ - (h).first = NULL; \ - (h).last = NULL; \ + (h)->first = NULL; \ + (h)->last = NULL; \ } while (0) #undef LH_EMPTY -#define LH_EMPTY(h) ((h).first == NULL) +#define LH_EMPTY(h) ((h)->first == NULL) #undef LH_FIRST -#define LH_FIRST(h) ((h).first) +#define LH_FIRST(h) ((h)->first) #undef LH_LAST -#define LH_LAST(h) ((h).last) +#define LH_LAST(h) ((h)->last) #undef LIST_NEXT #define LIST_NEXT(e) ((e)->next) diff --git a/testsudoers.c b/testsudoers.c index cf9a0b4f6..0d6ffaf5a 100644 --- a/testsudoers.c +++ b/testsudoers.c @@ -269,18 +269,18 @@ main(argc, argv) /* This loop must match the one in sudoers_lookup() */ printf("\nEntries for user %s:\n", user_name); matched = UNSPEC; - LH_FOREACH_FWD(userspecs, us) { + LH_FOREACH_FWD(&userspecs, us) { if (userlist_matches(sudo_user.pw, &us->users) != TRUE) continue; - LH_FOREACH_FWD(us->privileges, priv) { + LH_FOREACH_FWD(&us->privileges, priv) { putchar('\n'); print_privilege(priv); /* XXX */ putchar('\n'); if (hostlist_matches(&priv->hostlist) == TRUE) { puts("\thost matched"); runas = NULL; - LH_FOREACH_FWD(priv->cmndlist, cs) { - if (!LH_EMPTY(cs->runaslist)) + LH_FOREACH_FWD(&priv->cmndlist, cs) { + if (!LH_EMPTY(&cs->runaslist)) runas = &cs->runaslist; if (runaslist_matches(runas) == TRUE) { puts("\trunas matched"); @@ -388,7 +388,7 @@ print_defaults() struct defaults *d; struct member *m; - LH_FOREACH_FWD(defaults, d) { + LH_FOREACH_FWD(&defaults, d) { (void) fputs("Defaults", stdout); switch (d->type) { case DEFAULTS_HOST: @@ -404,8 +404,8 @@ print_defaults() putchar('!'); break; } - LH_FOREACH_FWD(d->binding, m) { - if (m != LH_FIRST(d->binding)) + LH_FOREACH_FWD(&d->binding, m) { + if (m != LH_FIRST(&d->binding)) putchar(','); print_member(m); } @@ -439,8 +439,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)) + LH_FOREACH_FWD(&a->members, m) { + if (m != LH_FIRST(&a->members)) fputs(", ", stdout); if (m->type == COMMAND) { c = (struct sudo_command *) m->name; @@ -465,20 +465,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)) + LH_FOREACH_FWD(&p->hostlist, m) { + if (m != LH_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)) + LH_FOREACH_FWD(&p->cmndlist, cs) { + if (cs != LH_FIRST(&p->cmndlist)) fputs(", ", stdout); - if (!LH_EMPTY(cs->runaslist)) { + if (!LH_EMPTY(&cs->runaslist)) { fputs("(", stdout); - LH_FOREACH_FWD(cs->runaslist, m) { - if (m != LH_FIRST(cs->runaslist)) + LH_FOREACH_FWD(&cs->runaslist, m) { + if (m != LH_FIRST(&cs->runaslist)) fputs(", ", stdout); print_member(m); } @@ -500,9 +500,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)) + LH_FOREACH_FWD(&userspecs, us) { + LH_FOREACH_FWD(&us->users, m) { + if (m != LH_FIRST(&us->users)) fputs(", ", stdout); print_member(m); } diff --git a/visudo.c b/visudo.c index 59954857c..3e2bb4f75 100644 --- a/visudo.c +++ b/visudo.c @@ -212,8 +212,8 @@ main(argc, argv) setup_signals(); /* Edit the sudoers file(s) */ - LH_FOREACH_FWD(sudoerslist, sp) { - if (sp != LH_FIRST(sudoerslist)) { + LH_FOREACH_FWD(&sudoerslist, sp) { + if (sp != LH_FIRST(&sudoerslist)) { printf("press return to edit %s: ", sp->path); while ((ch = getchar()) != EOF && ch != '\n') continue; @@ -225,7 +225,7 @@ main(argc, argv) reparse_sudoers(editor, args, strict, quiet); /* Install the sudoers temp files. */ - LH_FOREACH_FWD(sudoerslist, sp) { + LH_FOREACH_FWD(&sudoerslist, sp) { if (!sp->modified) (void) unlink(sp->tpath); else @@ -400,8 +400,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 = LH_FIRST(&sudoerslist); + last = LH_LAST(&sudoerslist); fp = fopen(sp->tpath, "r+"); if (fp == NULL) errorx(1, "can't re-open temporary file (%s), %s unchanged.", @@ -437,7 +437,7 @@ reparse_sudoers(editor, args, strict, quiet) } if (parse_error) { /* Edit file with the parse error */ - LH_FOREACH_FWD(sudoerslist, sp) { + LH_FOREACH_FWD(&sudoerslist, sp) { if (errorfile == NULL || strcmp(sp->path, errorfile) == 0) { edit_sudoers(sp, editor, args, errorlineno); break; @@ -708,7 +708,7 @@ open_sudoers(path, keepopen) FILE *fp; /* Check for existing entry */ - LH_FOREACH_FWD(sudoerslist, entry) { + LH_FOREACH_FWD(&sudoerslist, entry) { if (strcmp(path, entry->path) == 0) break; } @@ -886,8 +886,8 @@ check_aliases(strict) int error = 0; /* Forward check. */ - LH_FOREACH_FWD(userspecs, us) { - LH_FOREACH_FWD(us->users, m) { + LH_FOREACH_FWD(&userspecs, us) { + LH_FOREACH_FWD(&us->users, m) { if (m->type == USERALIAS) { if (find_alias(m->name, m->type) == NULL) { fprintf(stderr, @@ -897,8 +897,8 @@ check_aliases(strict) } } } - LH_FOREACH_FWD(us->privileges, priv) { - LH_FOREACH_FWD(priv->hostlist, m) { + LH_FOREACH_FWD(&us->privileges, priv) { + LH_FOREACH_FWD(&priv->hostlist, m) { if (m->type == HOSTALIAS) { if (find_alias(m->name, m->type) == NULL) { fprintf(stderr, @@ -908,8 +908,8 @@ check_aliases(strict) } } } - LH_FOREACH_FWD(priv->cmndlist, cs) { - LH_FOREACH_FWD(cs->runaslist, m) { + LH_FOREACH_FWD(&priv->cmndlist, cs) { + LH_FOREACH_FWD(&cs->runaslist, m) { if (m->type == RUNASALIAS) { if (find_alias(m->name, m->type) == NULL) { fprintf(stderr, @@ -932,18 +932,18 @@ check_aliases(strict) } /* Reverse check (destructive) */ - LH_FOREACH_FWD(userspecs, us) { - LH_FOREACH_FWD(us->users, m) { + LH_FOREACH_FWD(&userspecs, us) { + LH_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) { + LH_FOREACH_FWD(&us->privileges, priv) { + LH_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) { + LH_FOREACH_FWD(&priv->cmndlist, cs) { + LH_FOREACH_FWD(&cs->runaslist, m) { if (m->type == RUNASALIAS) (void) alias_remove(m->name, m->type); } @@ -983,7 +983,7 @@ cleanup(gotsignal) { struct sudoersfile *sp; - LH_FOREACH_FWD(sudoerslist, sp) { + LH_FOREACH_FWD(&sudoerslist, sp) { if (sp->tpath != NULL) (void) unlink(sp->tpath); }