Skip to content

Commit

Permalink
Fix #386 - honor log_level option on clients too
Browse files Browse the repository at this point in the history
Signed-off-by: Howard Chu <hyc@symas.com>
  • Loading branch information
hyc authored and quanah committed May 3, 2022
1 parent 1a0bb2d commit cb549ef
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/saslplug.h
Expand Up @@ -305,7 +305,7 @@ typedef struct sasl_client_params {
int (*spare_fptr1)(void);

unsigned int cbindingdisp;
int spare_int2;
int log_level;
int spare_int3;

/* flags field as passed to sasl_client_new */
Expand Down
5 changes: 4 additions & 1 deletion lib/client.c
Expand Up @@ -403,7 +403,7 @@ int sasl_client_new(const char *service,
sasl_utils_t *utils;
sasl_getopt_t *getopt;
void *context;
const char *mlist = NULL;
const char *mlist = NULL, *log_level;
int plus = 0;

if (_sasl_client_active == 0) return SASL_NOTINIT;
Expand Down Expand Up @@ -445,9 +445,12 @@ int sasl_client_new(const char *service,
utils->conn= *pconn;
conn->cparams->utils = utils;

log_level = NULL;
if(_sasl_getcallback(*pconn, SASL_CB_GETOPT, (sasl_callback_ft *)&getopt, &context) == SASL_OK) {
getopt(context, NULL, "log_level", &log_level, NULL);

This comment has been minimized.

Copy link
@panlinux

panlinux May 25, 2022

Contributor

Is there an example on how to set this log_level option for a client? I tried the usual suspects (ldapwhoami, smtptest from cyrus, sasl-sample-client) but none seemed to have a way to pass sasl config options to the tool. They don't even seem to open the generic .confsasl configuration file in/etc/sasl2and other places, where I could setlog_level: 7` for example.

This comment has been minimized.

Copy link
@hyc

hyc May 25, 2022

Author Contributor

The application must supply a SASL_CB_GETOPT callback in the list of callbacks passed to sasl_client_init. Unlike servers, clients don't look for a sasl/foo.conf file by default.

getopt(context, NULL, "client_mech_list", &mlist, NULL);
}
conn->cparams->log_level = log_level ? atoi(log_level) : SASL_LOG_ERR;

/* if we have a client_mech_list, create ordered list of
available mechanisms for this conn */
Expand Down
7 changes: 6 additions & 1 deletion lib/common.c
Expand Up @@ -1480,13 +1480,18 @@ static int _sasl_syslog(void *context,
const char *message)
{
int syslog_priority;
sasl_server_conn_t *sconn;

if (context) {
if (((sasl_conn_t *)context)->type == SASL_CONN_SERVER) {
sasl_server_conn_t *sconn;
sconn = (sasl_server_conn_t *)context;
if (sconn->sparams->log_level < priority)
return SASL_OK;
} else {
sasl_client_conn_t *conn;
conn = (sasl_client_conn_t *)context;
if (conn->cparams->log_level < priority)
return SASL_OK;
}
}

Expand Down

0 comments on commit cb549ef

Please sign in to comment.