/*
- * Copyright (c) 2003-2009 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 2003-2010 Todd C. Miller <Todd.Miller@courtesan.com>
*
* This code is derived from software contributed by Aaron Spangler.
*
if (rc == LDAP_SUCCESS && (entry = ldap_first_entry(ld, result))) {
bv = ldap_get_values_len(ld, entry, "sudoOption");
if (bv != NULL) {
- if (lbuf->len == 0)
- prefix = " ";
- else
- prefix = ", ";
+ prefix = " ";
for (p = bv; *p != NULL; p++) {
lbuf_append(lbuf, prefix, (*p)->bv_val, NULL);
prefix = ", ";
}
ldap_value_free_len(bv);
}
+ lbuf_append(lbuf, "\n", NULL);
- lbuf_print(lbuf); /* forces a newline */
return(count);
}
/* extract the dn, only show the first rdn */
rdn = sudo_ldap_get_first_rdn(ld, entry);
- lbuf_print(lbuf); /* force a newline */
- lbuf_append(lbuf, "LDAP Role: ", rdn ? rdn : "UNKNOWN", NULL);
- lbuf_print(lbuf);
+ lbuf_append(lbuf, "\nLDAP Role: ", rdn ? rdn : "UNKNOWN", "\n", NULL);
if (rdn)
ldap_memfree(rdn);
ldap_value_free_len(bv);
} else
lbuf_append(lbuf, def_runas_default, NULL);
- lbuf_print(lbuf);
+ lbuf_append(lbuf, "\n", NULL);
/* get the RunAsGroup Values from the entry */
bv = ldap_get_values_len(ld, entry, "sudoRunAsGroup");
lbuf_append(lbuf, (*p)->bv_val, NULL);
}
ldap_value_free_len(bv);
- lbuf_print(lbuf);
+ lbuf_append(lbuf, "\n", NULL);
}
/* get the Option Values from the entry */
lbuf_append(lbuf, (*p)->bv_val, NULL);
}
ldap_value_free_len(bv);
- lbuf_print(lbuf);
+ lbuf_append(lbuf, "\n", NULL);
}
/* get the Command Values from the entry */
bv = ldap_get_values_len(ld, entry, "sudoCommand");
if (bv != NULL) {
- lbuf_append(lbuf, " Commands:", NULL);
- lbuf_print(lbuf);
+ lbuf_append(lbuf, " Commands:\n", NULL);
for (p = bv; *p != NULL; p++) {
- lbuf_append(lbuf, "\t", (*p)->bv_val, NULL);
- lbuf_print(lbuf);
+ lbuf_append(lbuf, "\t", (*p)->bv_val, "\n", NULL);
count++;
}
ldap_value_free_len(bv);
/*
- * Copyright (c) 2004-2005, 2007-2009 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 2004-2005, 2007-2010 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
sudo_file_append_cmnd(cs, &tags, lbuf);
nfound++;
}
- lbuf_print(lbuf); /* forces a newline */
+ lbuf_append(lbuf, "\n", NULL);
}
return(nfound);
}
tags.setenv = UNSPEC;
tags.nopasswd = UNSPEC;
tags.transcript = UNSPEC;
- lbuf_print(lbuf); /* force a newline */
- lbuf_append(lbuf, "Sudoers entry:", NULL);
- lbuf_print(lbuf);
+ lbuf_append(lbuf, "\nSudoers entry:\n", NULL);
tq_foreach_fwd(&priv->cmndlist, cs) {
lbuf_append(lbuf, " RunAsUsers: ", NULL);
if (!tq_empty(&cs->runasuserlist)) {
} else {
lbuf_append(lbuf, pw->pw_name, NULL);
}
- lbuf_print(lbuf);
+ lbuf_append(lbuf, "\n", NULL);
if (!tq_empty(&cs->runasgrouplist)) {
lbuf_append(lbuf, " RunAsGroups: ", NULL);
tq_foreach_fwd(&cs->runasgrouplist, m) {
print_member(lbuf, m->name, m->type, m->negated,
RUNASALIAS);
}
- lbuf_print(lbuf);
+ lbuf_append(lbuf, "\n", NULL);
}
- lbuf_append(lbuf, " Commands: ", NULL);
- lbuf_print(lbuf);
- lbuf_append(lbuf, "\t", NULL);
+ lbuf_append(lbuf, " Commands:\n\t", NULL);
sudo_file_append_cmnd(cs, &tags, lbuf);
- lbuf_print(lbuf);
+ lbuf_append(lbuf, "\n", NULL);
nfound++;
}
}
if (nss->handle == NULL)
return(-1);
- if (lbuf->len == 0)
- prefix = " ";
- else
- prefix = ", ";
-
+ prefix = " ";
tq_foreach_fwd(&defaults, d) {
switch (d->type) {
case DEFAULTS_HOST:
/*
- * Copyright (c) 2007-2009 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 2007-2010 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* Print out privileges for the specified user.
* We only get here if the user is allowed to run something on this host.
*/
-/* XXX - conversation function or newlines in lbuf */
void
display_privs(snl, pw)
struct sudo_nss_list *snl;
lbuf_init(&lbuf, output, 4, NULL, sudo_user.cols);
/* Display defaults from all sources. */
+ lbuf_append(&lbuf, "Matching Defaults entries for ", pw->pw_name,
+ " on this host:\n", NULL);
count = 0;
- tq_foreach_fwd(snl, nss)
+ tq_foreach_fwd(snl, nss) {
count += nss->display_defaults(nss, pw, &lbuf);
+ }
if (count) {
- printf("Matching Defaults entries for %s on this host:\n", pw->pw_name);
+ lbuf_append(&lbuf, "\n\n", NULL);
lbuf_print(&lbuf);
- putchar('\n');
}
/* Display Runas and Cmnd-specific defaults from all sources. */
+ lbuf.len = 0;
+ lbuf_append(&lbuf, "Runas and Command-specific defaults for", pw->pw_name,
+ ":\n", NULL);
count = 0;
- tq_foreach_fwd(snl, nss)
+ tq_foreach_fwd(snl, nss) {
count += nss->display_bound_defaults(nss, pw, &lbuf);
+ }
if (count) {
- printf("Runas and Command-specific defaults for %s:\n", pw->pw_name);
+ lbuf_append(&lbuf, "\n\n", NULL);
lbuf_print(&lbuf);
- putchar('\n');
}
/* Display privileges from all sources. */
- printf("User %s may run the following commands on this host:\n",
- pw->pw_name);
- tq_foreach_fwd(snl, nss)
- (void) nss->display_privs(nss, pw, &lbuf);
- if (lbuf.len != 0)
- lbuf_print(&lbuf); /* print remainder, if any */
+ lbuf.len = 0;
+ lbuf_append(&lbuf, "User ", pw->pw_name,
+ " may run the following commands on this host:\n", NULL);
+ count = 0;
+ tq_foreach_fwd(snl, nss) {
+ count += nss->display_privs(nss, pw, &lbuf);
+ }
+ if (count) {
+ lbuf_print(&lbuf);
+ }
+
lbuf_destroy(&lbuf);
}