Add support for multiple Debug lines per program. Callers may

register arbitrary debug facilities or use built-in defaults.  We
now use separate Debug statements for plugins and programs.
This commit is contained in:
Todd C. Miller
2014-10-22 13:23:05 -06:00
parent a7e724b75d
commit 866cfc4fc3
100 changed files with 1509 additions and 949 deletions

View File

@@ -398,7 +398,7 @@ sudo_ldap_conf_add_ports(void)
char *host, *port, defport[13];
char hostbuf[LINE_MAX * 2];
int len;
debug_decl(sudo_ldap_conf_add_ports, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_conf_add_ports, SUDO_DEBUG_LDAP, sudoers_debug_instance)
hostbuf[0] = '\0';
len = snprintf(defport, sizeof(defport), ":%d", ldap_conf.port);
@@ -448,7 +448,7 @@ sudo_ldap_parse_uri(const struct ldap_config_str_list *uri_list)
char hostbuf[LINE_MAX];
int nldap = 0, nldaps = 0;
int rc = -1;
debug_decl(sudo_ldap_parse_uri, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_parse_uri, SUDO_DEBUG_LDAP, sudoers_debug_instance)
hostbuf[0] = '\0';
STAILQ_FOREACH(entry, uri_list, entries) {
@@ -524,7 +524,7 @@ sudo_ldap_join_uri(struct ldap_config_str_list *uri_list)
struct ldap_config_str *uri;
size_t len = 0;
char *buf, *cp;
debug_decl(sudo_ldap_join_uri, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_join_uri, SUDO_DEBUG_LDAP, sudoers_debug_instance)
STAILQ_FOREACH(uri, uri_list, entries) {
if (ldap_conf.ssl_mode == SUDO_LDAP_STARTTLS) {
@@ -556,7 +556,7 @@ sudo_ldap_init(LDAP **ldp, const char *host, int port)
{
LDAP *ld;
int rc = LDAP_CONNECT_ERROR;
debug_decl(sudo_ldap_init, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_init, SUDO_DEBUG_LDAP, sudoers_debug_instance)
#ifdef HAVE_LDAPSSL_INIT
if (ldap_conf.ssl_mode != SUDO_LDAP_CLEAR) {
@@ -653,7 +653,7 @@ sudo_ldap_check_non_unix_group(LDAP *ld, LDAPMessage *entry, struct passwd *pw)
struct berval **bv, **p;
char *val;
int ret = false;
debug_decl(sudo_ldap_check_non_unix_group, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_check_non_unix_group, SUDO_DEBUG_LDAP, sudoers_debug_instance)
if (!entry)
debug_return_bool(ret);
@@ -694,7 +694,7 @@ sudo_ldap_check_host(LDAP *ld, LDAPMessage *entry)
struct berval **bv, **p;
char *val;
bool ret = false;
debug_decl(sudo_ldap_check_host, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_check_host, SUDO_DEBUG_LDAP, sudoers_debug_instance)
if (!entry)
debug_return_bool(ret);
@@ -726,7 +726,7 @@ sudo_ldap_check_runas_user(LDAP *ld, LDAPMessage *entry)
struct berval **bv, **p;
char *val;
bool ret = false;
debug_decl(sudo_ldap_check_runas_user, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_check_runas_user, SUDO_DEBUG_LDAP, sudoers_debug_instance)
if (!runas_pw)
debug_return_bool(UNSPEC);
@@ -797,7 +797,7 @@ sudo_ldap_check_runas_group(LDAP *ld, LDAPMessage *entry)
struct berval **bv, **p;
char *val;
bool ret = false;
debug_decl(sudo_ldap_check_runas_group, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_check_runas_group, SUDO_DEBUG_LDAP, sudoers_debug_instance)
/* runas_gr is only set if the user specified the -g flag */
if (!runas_gr)
@@ -830,7 +830,7 @@ static bool
sudo_ldap_check_runas(LDAP *ld, LDAPMessage *entry)
{
bool ret;
debug_decl(sudo_ldap_check_runas, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_check_runas, SUDO_DEBUG_LDAP, sudoers_debug_instance)
if (!entry)
debug_return_bool(false);
@@ -846,7 +846,7 @@ sudo_ldap_extract_digest(char **cmnd, struct sudo_digest *digest)
{
char *ep, *cp = *cmnd;
int digest_type = SUDO_DIGEST_INVALID;
debug_decl(sudo_ldap_check_command, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_check_command, SUDO_DEBUG_LDAP, sudoers_debug_instance)
/*
* Check for and extract a digest prefix, e.g.
@@ -912,7 +912,7 @@ sudo_ldap_check_command(LDAP *ld, LDAPMessage *entry, int *setenv_implied)
char *allowed_cmnd, *allowed_args, *val;
bool foundbang;
int ret = UNSPEC;
debug_decl(sudo_ldap_check_command, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_check_command, SUDO_DEBUG_LDAP, sudoers_debug_instance)
if (!entry)
debug_return_bool(ret);
@@ -980,7 +980,7 @@ sudo_ldap_check_bool(LDAP *ld, LDAPMessage *entry, char *option)
struct berval **bv, **p;
char ch, *var;
int ret = UNSPEC;
debug_decl(sudo_ldap_check_bool, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_check_bool, SUDO_DEBUG_LDAP, sudoers_debug_instance)
if (entry == NULL)
debug_return_bool(ret);
@@ -1014,7 +1014,7 @@ sudo_ldap_parse_options(LDAP *ld, LDAPMessage *entry)
{
struct berval **bv, **p;
char op, *var, *val;
debug_decl(sudo_ldap_parse_options, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_parse_options, SUDO_DEBUG_LDAP, sudoers_debug_instance)
if (entry == NULL)
debug_return;
@@ -1085,7 +1085,7 @@ sudo_ldap_timefilter(char *buffer, size_t buffersize)
time_t now;
char timebuffer[sizeof("20120727121554.0Z")];
int bytes = 0;
debug_decl(sudo_ldap_timefilter, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_timefilter, SUDO_DEBUG_LDAP, sudoers_debug_instance)
/* Make sure we have a formatted timestamp for __now__. */
time(&now);
@@ -1119,7 +1119,7 @@ static char *
sudo_ldap_build_default_filter(void)
{
char *filt;
debug_decl(sudo_ldap_build_default_filter, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_build_default_filter, SUDO_DEBUG_LDAP, sudoers_debug_instance)
if (ldap_conf.search_filter)
sudo_easprintf(&filt, "(&%s(cn=defaults))", ldap_conf.search_filter);
@@ -1232,7 +1232,7 @@ sudo_ldap_build_pass1(struct passwd *pw)
struct group_list *grlist;
size_t sz = 0;
int i;
debug_decl(sudo_ldap_build_pass1, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_build_pass1, SUDO_DEBUG_LDAP, sudoers_debug_instance)
/* If there is a filter, allocate space for the global AND. */
if (ldap_conf.timed || ldap_conf.search_filter)
@@ -1348,7 +1348,7 @@ static char *
sudo_ldap_build_pass2(void)
{
char *filt, timebuffer[TIMEFILTER_LENGTH + 1];
debug_decl(sudo_ldap_build_pass2, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_build_pass2, SUDO_DEBUG_LDAP, sudoers_debug_instance)
/* Short circuit if no non-Unix group support. */
if (!def_use_netgroups && !def_group_plugin) {
@@ -1389,7 +1389,7 @@ sudo_ldap_decode_secret(const char *secret)
{
unsigned char *result = NULL;
size_t len, reslen;
debug_decl(sudo_ldap_decode_secret, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_decode_secret, SUDO_DEBUG_LDAP, sudoers_debug_instance)
if (strncasecmp(secret, "base64:", sizeof("base64:") - 1) == 0) {
/*
@@ -1415,7 +1415,7 @@ sudo_ldap_read_secret(const char *path)
{
FILE *fp;
char buf[LINE_MAX];
debug_decl(sudo_ldap_read_secret, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_read_secret, SUDO_DEBUG_LDAP, sudoers_debug_instance)
if ((fp = fopen(path_ldap_secret, "r")) != NULL) {
if (fgets(buf, sizeof(buf), fp) != NULL) {
@@ -1444,7 +1444,7 @@ sudo_ldap_parse_keyword(const char *keyword, const char *value,
{
struct ldap_config_table *cur;
const char *errstr;
debug_decl(sudo_ldap_parse_keyword, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_parse_keyword, SUDO_DEBUG_LDAP, sudoers_debug_instance)
/* Look up keyword in config tables */
for (cur = table; cur->conf_str != NULL; cur++) {
@@ -1500,7 +1500,7 @@ static const char *
sudo_krb5_ccname_path(const char *old_ccname)
{
const char *ccname = old_ccname;
debug_decl(sudo_krb5_ccname_path, SUDO_DEBUG_LDAP)
debug_decl(sudo_krb5_ccname_path, SUDO_DEBUG_LDAP, sudoers_debug_instance)
/* Strip off leading FILE: or WRFILE: prefix. */
switch (ccname[0]) {
@@ -1527,7 +1527,7 @@ sudo_check_krb5_ccname(const char *ccname)
{
int fd = -1;
const char *ccname_path;
debug_decl(sudo_check_krb5_ccname, SUDO_DEBUG_LDAP)
debug_decl(sudo_check_krb5_ccname, SUDO_DEBUG_LDAP, sudoers_debug_instance)
/* Strip off prefix to get path name. */
ccname_path = sudo_krb5_ccname_path(ccname);
@@ -1556,7 +1556,7 @@ sudo_ldap_read_config(void)
FILE *fp;
char *cp, *keyword, *value, *line = NULL;
size_t linesize = 0;
debug_decl(sudo_ldap_read_config, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_read_config, SUDO_DEBUG_LDAP, sudoers_debug_instance)
/* defaults */
ldap_conf.version = 3;
@@ -1790,7 +1790,7 @@ sudo_ldap_get_first_rdn(LDAP *ld, LDAPMessage *entry)
#ifdef HAVE_LDAP_STR2DN
char *dn, *rdn = NULL;
LDAPDN tmpDN;
debug_decl(sudo_ldap_get_first_rdn, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_get_first_rdn, SUDO_DEBUG_LDAP, sudoers_debug_instance)
if ((dn = ldap_get_dn(ld, entry)) == NULL)
debug_return_str(NULL);
@@ -1802,7 +1802,7 @@ sudo_ldap_get_first_rdn(LDAP *ld, LDAPMessage *entry)
debug_return_str(rdn);
#else
char *dn, **edn;
debug_decl(sudo_ldap_get_first_rdn, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_get_first_rdn, SUDO_DEBUG_LDAP, sudoers_debug_instance)
if ((dn = ldap_get_dn(ld, entry)) == NULL)
return NULL;
@@ -1827,7 +1827,7 @@ sudo_ldap_display_defaults(struct sudo_nss *nss, struct passwd *pw,
LDAPMessage *entry, *result;
char *prefix, *filt;
int rc, count = 0;
debug_decl(sudo_ldap_display_defaults, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_display_defaults, SUDO_DEBUG_LDAP, sudoers_debug_instance)
if (handle == NULL || handle->ld == NULL)
goto done;
@@ -1873,7 +1873,7 @@ static int
sudo_ldap_display_bound_defaults(struct sudo_nss *nss, struct passwd *pw,
struct sudo_lbuf *lbuf)
{
debug_decl(sudo_ldap_display_bound_defaults, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_display_bound_defaults, SUDO_DEBUG_LDAP, sudoers_debug_instance)
debug_return_int(0);
}
@@ -1885,7 +1885,7 @@ sudo_ldap_display_entry_short(LDAP *ld, LDAPMessage *entry, struct sudo_lbuf *lb
{
struct berval **bv, **p;
int count = 0;
debug_decl(sudo_ldap_display_entry_short, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_display_entry_short, SUDO_DEBUG_LDAP, sudoers_debug_instance)
sudo_lbuf_append(lbuf, " (");
@@ -1955,7 +1955,7 @@ sudo_ldap_display_entry_long(LDAP *ld, LDAPMessage *entry, struct sudo_lbuf *lbu
struct berval **bv, **p;
char *rdn;
int count = 0;
debug_decl(sudo_ldap_display_entry_long, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_display_entry_long, SUDO_DEBUG_LDAP, sudoers_debug_instance)
/* extract the dn, only show the first rdn */
rdn = sudo_ldap_get_first_rdn(ld, entry);
@@ -2040,7 +2040,7 @@ sudo_ldap_display_privs(struct sudo_nss *nss, struct passwd *pw,
struct ldap_result *lres;
LDAPMessage *entry;
int i, count = 0;
debug_decl(sudo_ldap_display_privs, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_display_privs, SUDO_DEBUG_LDAP, sudoers_debug_instance)
if (handle == NULL || handle->ld == NULL)
goto done;
@@ -2071,7 +2071,7 @@ sudo_ldap_display_cmnd(struct sudo_nss *nss, struct passwd *pw)
LDAPMessage *entry;
bool found = false;
int i;
debug_decl(sudo_ldap_display_cmnd, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_display_cmnd, SUDO_DEBUG_LDAP, sudoers_debug_instance)
if (handle == NULL || handle->ld == NULL)
goto done;
@@ -2108,7 +2108,7 @@ sudo_set_krb5_ccache_name(const char *name, const char **old_name)
int rc = 0;
unsigned int junk;
static bool initialized;
debug_decl(sudo_set_krb5_ccache_name, SUDO_DEBUG_LDAP)
debug_decl(sudo_set_krb5_ccache_name, SUDO_DEBUG_LDAP, sudoers_debug_instance)
if (!initialized) {
sudo_gss_krb5_ccache_name =
@@ -2151,7 +2151,7 @@ sudo_krb5_copy_cc_file(const char *old_ccname)
ssize_t nread, nwritten = -1;
static char new_ccname[sizeof(_PATH_TMP) + sizeof("sudocc_XXXXXXXX") - 1];
char buf[10240], *ret = NULL;
debug_decl(sudo_krb5_copy_cc_file, SUDO_DEBUG_LDAP)
debug_decl(sudo_krb5_copy_cc_file, SUDO_DEBUG_LDAP, sudoers_debug_instance)
old_ccname = sudo_krb5_ccname_path(old_ccname);
if (old_ccname != NULL) {
@@ -2212,7 +2212,7 @@ sudo_ldap_sasl_interact(LDAP *ld, unsigned int flags, void *_auth_id,
char *auth_id = (char *)_auth_id;
sasl_interact_t *interact = (sasl_interact_t *)_interact;
int rc = LDAP_SUCCESS;
debug_decl(sudo_ldap_sasl_interact, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_sasl_interact, SUDO_DEBUG_LDAP, sudoers_debug_instance)
for (; interact->id != SASL_CB_LIST_END; interact++) {
if (interact->id != SASL_CB_USER) {
@@ -2254,7 +2254,7 @@ sudo_ldap_set_options_table(LDAP *ld, struct ldap_config_table *table)
struct ldap_config_table *cur;
int ival, rc, errors = 0;
char *sval;
debug_decl(sudo_ldap_set_options_table, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_set_options_table, SUDO_DEBUG_LDAP, sudoers_debug_instance)
for (cur = table; cur->conf_str != NULL; cur++) {
if (cur->opt_val == -1)
@@ -2299,7 +2299,7 @@ static int
sudo_ldap_set_options_global(void)
{
int rc;
debug_decl(sudo_ldap_set_options_global, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_set_options_global, SUDO_DEBUG_LDAP, sudoers_debug_instance)
/* Set ber options */
#ifdef LBER_OPT_DEBUG_LEVEL
@@ -2320,7 +2320,7 @@ static int
sudo_ldap_set_options_conn(LDAP *ld)
{
int rc;
debug_decl(sudo_ldap_set_options_conn, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_set_options_conn, SUDO_DEBUG_LDAP, sudoers_debug_instance)
/* Parse per-connection LDAP options table. */
rc = sudo_ldap_set_options_table(ld, ldap_conf_conn);
@@ -2382,7 +2382,7 @@ static struct ldap_result *
sudo_ldap_result_alloc(void)
{
struct ldap_result *result;
debug_decl(sudo_ldap_result_alloc, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_result_alloc, SUDO_DEBUG_LDAP, sudoers_debug_instance)
result = sudo_ecalloc(1, sizeof(*result));
STAILQ_INIT(&result->searches);
@@ -2397,7 +2397,7 @@ static void
sudo_ldap_result_free(struct ldap_result *lres)
{
struct ldap_search_result *s;
debug_decl(sudo_ldap_result_free, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_result_free, SUDO_DEBUG_LDAP, sudoers_debug_instance)
if (lres != NULL) {
if (lres->nentries) {
@@ -2422,7 +2422,7 @@ sudo_ldap_result_add_search(struct ldap_result *lres, LDAP *ldap,
LDAPMessage *searchresult)
{
struct ldap_search_result *news;
debug_decl(sudo_ldap_result_add_search, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_result_add_search, SUDO_DEBUG_LDAP, sudoers_debug_instance)
/* Create new entry and add it to the end of the chain. */
news = sudo_ecalloc(1, sizeof(*news));
@@ -2441,7 +2441,7 @@ static int
sudo_ldap_bind_s(LDAP *ld)
{
int rc;
debug_decl(sudo_ldap_bind_s, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_bind_s, SUDO_DEBUG_LDAP, sudoers_debug_instance)
#ifdef HAVE_LDAP_SASL_INTERACTIVE_BIND_S
if (ldap_conf.rootuse_sasl == true ||
@@ -2537,7 +2537,7 @@ sudo_ldap_open(struct sudo_nss *nss)
sigaction_t sa, saved_sa_pipe;
bool ldapnoinit = false;
struct sudo_ldap_handle *handle;
debug_decl(sudo_ldap_open, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_open, SUDO_DEBUG_LDAP, sudoers_debug_instance)
/* Ignore SIGPIPE if we cannot bind to the server. */
memset(&sa, 0, sizeof(sa));
@@ -2641,7 +2641,7 @@ sudo_ldap_setdefs(struct sudo_nss *nss)
LDAPMessage *entry, *result;
char *filt;
int rc;
debug_decl(sudo_ldap_setdefs, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_setdefs, SUDO_DEBUG_LDAP, sudoers_debug_instance)
if (handle == NULL || handle->ld == NULL)
debug_return_int(-1);
@@ -2684,7 +2684,7 @@ sudo_ldap_lookup(struct sudo_nss *nss, int ret, int pwflag)
LDAPMessage *entry;
int i, rc, setenv_implied;
struct ldap_result *lres = NULL;
debug_decl(sudo_ldap_lookup, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_lookup, SUDO_DEBUG_LDAP, sudoers_debug_instance)
if (handle == NULL || handle->ld == NULL)
debug_return_int(ret);
@@ -2803,7 +2803,7 @@ ldap_entry_compare(const void *a, const void *b)
{
const struct ldap_entry_wrapper *aw = a;
const struct ldap_entry_wrapper *bw = b;
debug_decl(ldap_entry_compare, SUDO_DEBUG_LDAP)
debug_decl(ldap_entry_compare, SUDO_DEBUG_LDAP, sudoers_debug_instance)
debug_return_int(bw->order < aw->order ? -1 :
(bw->order > aw->order ? 1 : 0));
@@ -2816,7 +2816,7 @@ ldap_entry_compare(const void *a, const void *b)
static struct ldap_search_result *
sudo_ldap_result_last_search(struct ldap_result *lres)
{
debug_decl(sudo_ldap_result_last_search, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_result_last_search, SUDO_DEBUG_LDAP, sudoers_debug_instance)
debug_return_ptr(STAILQ_LAST(&lres->searches, ldap_search_result, entries));
}
@@ -2831,7 +2831,7 @@ sudo_ldap_result_add_entry(struct ldap_result *lres, LDAPMessage *entry)
struct berval **bv;
double order = 0.0;
char *ep;
debug_decl(sudo_ldap_result_add_entry, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_result_add_entry, SUDO_DEBUG_LDAP, sudoers_debug_instance)
/* Determine whether the entry has the sudoOrder attribute. */
last = sudo_ldap_result_last_search(lres);
@@ -2874,7 +2874,7 @@ static void
sudo_ldap_result_free_nss(struct sudo_nss *nss)
{
struct sudo_ldap_handle *handle = nss->handle;
debug_decl(sudo_ldap_result_free_nss, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_result_free_nss, SUDO_DEBUG_LDAP, sudoers_debug_instance)
if (handle->result != NULL) {
DPRINTF1("removing reusable search result");
@@ -2904,7 +2904,7 @@ sudo_ldap_result_get(struct sudo_nss *nss, struct passwd *pw)
LDAP *ld = handle->ld;
int pass, rc;
char *filt;
debug_decl(sudo_ldap_result_get, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_result_get, SUDO_DEBUG_LDAP, sudoers_debug_instance)
/*
* If we already have a cached result, return it so we don't have to
@@ -3000,7 +3000,7 @@ static int
sudo_ldap_close(struct sudo_nss *nss)
{
struct sudo_ldap_handle *handle = nss->handle;
debug_decl(sudo_ldap_close, SUDO_DEBUG_LDAP)
debug_decl(sudo_ldap_close, SUDO_DEBUG_LDAP, sudoers_debug_instance)
if (handle != NULL) {
/* Free the result before unbinding; it may use the LDAP connection. */