Move code to display a cmndspec in long form to display_cmndspec_long().

This commit is contained in:
Todd C. Miller
2023-08-09 09:58:24 -06:00
parent 5a1a3ff74b
commit f6291bf83e

View File

@@ -140,32 +140,25 @@ new_long_entry(struct cmndspec *cs, struct cmndspec *prev_cs)
debug_return_bool(false); debug_return_bool(false);
} }
static int static void
display_priv_long(struct sudoers_parse_tree *parse_tree, struct passwd *pw, display_cmndspec_long(struct sudoers_parse_tree *parse_tree, struct passwd *pw,
struct userspec *us, struct sudo_lbuf *lbuf) struct userspec *us, struct privilege *priv, struct cmndspec *cs,
struct cmndspec *prev_cs, struct sudo_lbuf *lbuf)
{ {
struct privilege *priv;
int nfound = 0;
debug_decl(display_priv_long, SUDOERS_DEBUG_PARSER);
TAILQ_FOREACH(priv, &us->privileges, entries) {
struct cmndspec *cs, *prev_cs;
if (hostlist_matches(parse_tree, pw, &priv->hostlist) != ALLOW)
continue;
prev_cs = NULL;
TAILQ_FOREACH(cs, &priv->cmndlist, entries) {
struct defaults *d; struct defaults *d;
struct member *m; struct member *m;
debug_decl(display_cmndspec_long, SUDOERS_DEBUG_PARSER);
if (new_long_entry(cs, prev_cs)) { if (new_long_entry(cs, prev_cs)) {
unsigned int olen; unsigned int olen;
if (prev_cs != NULL)
sudo_lbuf_append(lbuf, "\n");
if (priv->ldap_role != NULL) { if (priv->ldap_role != NULL) {
sudo_lbuf_append(lbuf, _("\nLDAP Role: %s\n"), sudo_lbuf_append(lbuf, _("LDAP Role: %s\n"),
priv->ldap_role); priv->ldap_role);
} else { } else {
sudo_lbuf_append(lbuf, _("\nSudoers entry: %s\n"), sudo_lbuf_append(lbuf, _("Sudoers entry: %s\n"),
us->file); us->file);
} }
sudo_lbuf_append(lbuf, "%s", _(" RunAsUsers: ")); sudo_lbuf_append(lbuf, "%s", _(" RunAsUsers: "));
@@ -263,6 +256,27 @@ display_priv_long(struct sudoers_parse_tree *parse_tree, struct passwd *pw,
sudoers_format_member(lbuf, parse_tree, cs->cmnd, "\n\t", sudoers_format_member(lbuf, parse_tree, cs->cmnd, "\n\t",
CMNDALIAS); CMNDALIAS);
sudo_lbuf_append(lbuf, "\n"); sudo_lbuf_append(lbuf, "\n");
debug_return;
}
static int
display_priv_long(struct sudoers_parse_tree *parse_tree, struct passwd *pw,
struct userspec *us, struct sudo_lbuf *lbuf)
{
struct privilege *priv;
int nfound = 0;
debug_decl(display_priv_long, SUDOERS_DEBUG_PARSER);
TAILQ_FOREACH(priv, &us->privileges, entries) {
struct cmndspec *cs, *prev_cs;
if (hostlist_matches(parse_tree, pw, &priv->hostlist) != ALLOW)
continue;
prev_cs = NULL;
sudo_lbuf_append(lbuf, "\n");
TAILQ_FOREACH(cs, &priv->cmndlist, entries) {
display_cmndspec_long(parse_tree, pw, us, priv, cs, prev_cs, lbuf);
prev_cs = cs; prev_cs = cs;
nfound++; nfound++;
} }