{
struct defaults *def;
- LH_FOREACH_FWD(defaults, def) {
+ LH_FOREACH_FWD(&defaults, def) {
if (skip_cmnd == (def->type == DEFAULTS_CMND))
continue;
switch (def->type) {
/* 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));
}
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);
}
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);
}
efree(d->val);
efree(d);
}
- LH_INIT(defaults);
+ LH_INIT(&defaults);
init_aliases();
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 ||
/* 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) {
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);
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)
}
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)
#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) {
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);
#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.
#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)
/* 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");
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:
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);
}
(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;
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);
}
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);
}
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;
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
* 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.",
}
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;
FILE *fp;
/* Check for existing entry */
- LH_FOREACH_FWD(sudoerslist, entry) {
+ LH_FOREACH_FWD(&sudoerslist, entry) {
if (strcmp(path, entry->path) == 0)
break;
}
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,
}
}
}
- 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,
}
}
}
- 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,
}
/* 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);
}
{
struct sudoersfile *sp;
- LH_FOREACH_FWD(sudoerslist, sp) {
+ LH_FOREACH_FWD(&sudoerslist, sp) {
if (sp->tpath != NULL)
(void) unlink(sp->tpath);
}