Skip to content
Browse files

Removing syslog and using saslplug utils log. Fixes Issues#1 and 2

  • Loading branch information...
1 parent 832b6fe commit b7c0bb06e0246400c1eec532aba744417e0dc8d5 @ozten committed Dec 15, 2011
Showing with 125 additions and 128 deletions.
  1. +31 −36 plugins/browserid.c
  2. +19 −20 plugins/session.c
  3. +75 −72 plugins/verifier.c
View
67 plugins/browserid.c
@@ -22,7 +22,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#include <syslog.h>
#ifndef macintosh
#include <sys/types.h>
#include <sys/stat.h>
@@ -55,8 +54,6 @@
static const char plugin_id[] = "$Id: browserid.c,v 1.180 2011/08/11 17:00:00 mel Exp $";
-struct context;
-
static const unsigned short version = 5;
/***************************** Common Section *****************************/
@@ -67,7 +64,7 @@ static const unsigned short version = 5;
static void browserid_common_mech_free(void *glob_context,
const sasl_utils_t *utils)
{
- syslog(LOG_DEBUG, "browserid_common_mech_free");
+ utils->log(NULL, SASL_LOG_DEBUG, "browserid_common_mech_free");
return;
}
@@ -83,7 +80,7 @@ static int browserid_server_mech_new(void *glob_context,
unsigned challen __attribute__((unused)),
void **conn_context)
{
- syslog(LOG_DEBUG, "browserid_server_mech_new");
+ sparams->utils->log(NULL, SASL_LOG_DEBUG, "browserid_server_mech_new");
return SASL_OK;
}
@@ -99,7 +96,7 @@ static int _transmit_email(sasl_server_params_t *sparams,
return SASL_NOMEM;
}
strcpy(*serverout, email);
- syslog(LOG_DEBUG, "Sending [%s] back to client", *serverout);
+ sparams->utils->log(NULL, SASL_LOG_DEBUG, "Sending [%s] back to client", *serverout);
return SASL_OK;
}
@@ -124,7 +121,7 @@ static int browserid_server_mech_step(void *conn_context,
struct browserid_response_t *browserid_response;
char email[MAX_EMAIL];
- syslog(LOG_DEBUG, "browserid_server_mech_step clientinlen=%d",
+ sparams->utils->log(NULL, SASL_LOG_DEBUG, "browserid_server_mech_step clientinlen=%d",
clientinlen);
/* should have received assertion NUL audience */
@@ -134,12 +131,12 @@ static int browserid_server_mech_step(void *conn_context,
assertion = clientin;
if (strlen(assertion) > MAX_ASSERTION) {
- syslog(LOG_ERR, "Client send a longer assertion [%u] that we "
+ sparams->utils->log(NULL, SASL_LOG_ERR, "Client send a longer assertion [%u] that we "
"expected, failing", strlen(assertion));
return SASL_BADPROT;
}
- syslog(LOG_DEBUG, "Assertion: [%s]", assertion);
+ sparams->utils->log(NULL, SASL_LOG_DEBUG, "Assertion: [%s]", assertion);
while ((lup < clientinlen) && (clientin[lup] != 0)) ++lup;
@@ -156,15 +153,15 @@ static int browserid_server_mech_step(void *conn_context,
audience_len = (unsigned) (clientin + lup - audience);
if (audience_len > MAX_AUDIENCE) {
- syslog(LOG_ERR, "Client send a longer audience [%u] that "
+ sparams->utils->log(NULL, SASL_LOG_ERR, "Client send a longer audience [%u] that "
"we expected, failing",
strlen(audience));
return SASL_BADPROT;
}
- syslog(LOG_DEBUG, "lup = %d clientinlen = %d", lup,
+ sparams->utils->log(NULL, SASL_LOG_DEBUG, "lup = %d clientinlen = %d", lup,
clientinlen);
- ++lup;
+ ++lup;
if (lup != clientinlen) {
SETERROR(sparams->utils,
"Client sent more data than the two fields we were expecting");
@@ -181,19 +178,19 @@ static int browserid_server_mech_step(void *conn_context,
strncpy(audience_copy, audience, audience_len);
audience_copy[audience_len] = '\0';
- syslog(LOG_DEBUG, "Server side, we've got AUDIENCE[%s] ASSERTION[%s]",
+ sparams->utils->log(NULL, SASL_LOG_DEBUG, "Server side, we've got AUDIENCE[%s] ASSERTION[%s]",
audience_copy, assertion);
if (check_session(sparams->utils, assertion, (char *)&email) == 1) {
- syslog(LOG_DEBUG, "Found email = %s in session", email);
+ sparams->utils->log(NULL, SASL_LOG_DEBUG, "Found email = %s in session", email);
/* set user into the session or whatever... */
result = sparams->canon_user(sparams->utils->conn,
email, 0,
SASL_CU_AUTHID | SASL_CU_AUTHZID,
oparams);
_transmit_email(sparams, serverout, serveroutlen, email);
} else {
- syslog(LOG_DEBUG, "No session hit, using verifier");
+ sparams->utils->log(NULL, SASL_LOG_DEBUG, "No session hit, using verifier");
browserid_response = malloc(sizeof(struct browserid_response_t));
if (browserid_response == NULL) {
MEMERROR(sparams->utils);
@@ -207,14 +204,14 @@ static int browserid_server_mech_step(void *conn_context,
}
if (strcasecmp(browserid_response->status, "okay") == 0) {
- syslog(LOG_DEBUG, "Yes, we're all good! %s %s %s until %llu",
+ sparams->utils->log(NULL, SASL_LOG_DEBUG, "Yes, we're all good! %s %s %s until %llu",
browserid_response->email,
browserid_response->audience,
browserid_response->issuer,
browserid_response->expires);
if (strcasecmp(browserid_response->audience, audience_copy) != 0) {
- syslog(LOG_ERR, "BAD Audience, expected [%s] != [%s]",
+ sparams->utils->log(NULL, SASL_LOG_ERR, "BAD Audience, expected [%s] != [%s]",
audience_copy, browserid_response->audience);
return SASL_BADAUTH;
}
@@ -235,7 +232,7 @@ static int browserid_server_mech_step(void *conn_context,
}
} else {
- syslog(LOG_ERR, "No dice, STATUS=[%s] REASON=[%s]",
+ sparams->utils->log(NULL, SASL_LOG_ERR, "No dice, STATUS=[%s] REASON=[%s]",
browserid_response->status,
browserid_response->reason);
SETERROR(sparams->utils, browserid_response->reason);
@@ -268,7 +265,7 @@ static int browserid_server_mech_step(void *conn_context,
static void browserid_server_mech_dispose(void *conn_context,
const sasl_utils_t *utils)
{
- syslog(LOG_DEBUG, "browserid_server_mech_dispose");
+ utils->log(NULL, SASL_LOG_DEBUG, "browserid_server_mech_dispose");
return;
}
@@ -300,8 +297,7 @@ int browserid_server_plug_init(sasl_utils_t *utils,
sasl_server_plug_t **pluglist,
int *plugcount)
{
- openlog("browserid-server", LOG_NDELAY, LOG_AUTH);
- syslog(LOG_DEBUG, "browserid_server_plug_init");
+ utils->log(NULL, SASL_LOG_DEBUG, "browserid_server_plug_init");
if (maxversion < SASL_SERVER_PLUG_VERSION) {
SETERROR( utils, "ANONYMOUS version mismatch" );
return SASL_BADVERS;
@@ -329,7 +325,7 @@ static int browserid_client_mech_new(void *glob_context,
sasl_client_params_t * params,
void **conn_context)
{
- syslog(LOG_DEBUG, "browserid_client_mech_new");
+ params->utils->log(NULL, SASL_LOG_DEBUG, "browserid_client_mech_new");
client_context_t *context;
context = params->utils->malloc(sizeof(client_context_t));
@@ -363,7 +359,7 @@ static int browserid_client_mech_step1(void *conn_context,
int result;
char *p;
- syslog(LOG_DEBUG, "browserid_client_mech_step1");
+ params->utils->log(NULL, SASL_LOG_DEBUG, "browserid_client_mech_step1");
if (!params || !clientout || !clientoutlen || !oparams) {
PARAMERROR( params->utils );
@@ -425,30 +421,30 @@ static int browserid_client_mech_step1(void *conn_context,
return SASL_INTERACT;
}
if (strlen(browser_assertion) == 0) {
- syslog(LOG_ERR, "browser_assertion is empty, failing");
+ params->utils->log(NULL, SASL_LOG_ERR, "browser_assertion is empty, failing");
return SASL_BADPARAM;
}
if (strlen(browser_assertion) > MAX_ASSERTION) {
- syslog(LOG_ERR, "browser_assertion is larger than we expected "
+ params->utils->log(NULL, SASL_LOG_ERR, "browser_assertion is larger than we expected "
"(%u), failing", strlen(browser_assertion));
return SASL_BADPARAM;
}
if (strlen(browser_audience) == 0) {
- syslog(LOG_ERR, "browser_audience is empty, failing");
+ params->utils->log(NULL, SASL_LOG_ERR, "browser_audience is empty, failing");
return SASL_BADPARAM;
}
if (strlen(browser_audience) > MAX_AUDIENCE) {
- syslog(LOG_ERR, "browser_audience is larger than we expected "
+ params->utils->log(NULL, SASL_LOG_ERR, "browser_audience is larger than we expected "
"(%u), failing", strlen(browser_audience));
return SASL_BADPARAM;
}
- syslog(LOG_DEBUG, "YO ASSERTION=[%s] AUDIENCE=[%s]",
+ params->utils->log(NULL, SASL_LOG_DEBUG, "YO ASSERTION=[%s] AUDIENCE=[%s]",
browser_assertion, browser_audience);
/* send assertion NUL audience NUL */
*clientoutlen = (strlen(browser_assertion) + 1 + strlen(browser_audience) + 1);
- syslog(LOG_DEBUG, "clientoutlen is going to be %u", *clientoutlen);
+ params->utils->log(NULL, SASL_LOG_DEBUG, "clientoutlen is going to be %u", *clientoutlen);
result = _plug_buf_alloc(params->utils, &(context->out_buf),
&(context->out_buf_len), *clientoutlen);
@@ -491,18 +487,18 @@ static int browserid_client_mech_step2(void *conn_context,
char *email;
int result;
- syslog(LOG_DEBUG, "browserid_client_mech_step2 serverinlen=%d", serverinlen);
+ params->utils->log(NULL, SASL_LOG_DEBUG, "browserid_client_mech_step2 serverinlen=%d", serverinlen);
/* should have received email NUL */
email = serverin;
if (strlen(email) > MAX_EMAIL) {
- syslog(LOG_ERR, "Server sent a longer email [%u] that we "
+ params->utils->log(NULL, SASL_LOG_ERR, "Server sent a longer email [%u] that we "
"expected, failing", strlen(email));
return SASL_BADPROT;
}
- syslog(LOG_DEBUG, "client step2 seeing email=[%s]", email);
+ params->utils->log(NULL, SASL_LOG_DEBUG, "client step2 seeing email=[%s]", email);
result = params->canon_user(params->utils->conn, email, 0,
SASL_CU_AUTHID | SASL_CU_AUTHZID, oparams);
@@ -556,7 +552,7 @@ static int browserid_client_mech_step(void *conn_context,
clientoutlen,
oparams);
default:
- syslog(LOG_ERR, "Unknown state in client step %d", context->state);
+ params->utils->log(NULL, SASL_LOG_ERR, "Unknown state in client step %d", context->state);
return SASL_BADPARAM;
}
}
@@ -567,7 +563,7 @@ static int browserid_client_mech_step(void *conn_context,
static void browserid_client_mech_dispose(void *conn_context,
const sasl_utils_t *utils)
{
- syslog(LOG_DEBUG, "browserid_client_mech_dispose");
+ utils->log(NULL, SASL_LOG_DEBUG, "browserid_client_mech_dispose");
client_context_t *context = (client_context_t *) conn_context;
@@ -608,8 +604,7 @@ int browserid_client_plug_init(sasl_utils_t *utils,
sasl_client_plug_t **pluglist,
int *plugcount)
{
- openlog("browserid-client", LOG_NDELAY, LOG_AUTH);
- syslog(LOG_EMERG, "browserid_client_plug_init_plugin initialized");
+ utils->log(NULL, SASL_LOG_ERR, "browserid_client_plug_init_plugin initialized");
if (maxversion < SASL_CLIENT_PLUG_VERSION) {
SETERROR( utils, "ANONYMOUS version mismatch" );
return SASL_BADVERS;
View
39 plugins/session.c
@@ -2,7 +2,6 @@
#include <stdio.h>
#include <string.h>
-#include <syslog.h>
#include <mysql.h>
#include <mysql/errmsg.h>
@@ -22,7 +21,7 @@ static MYSQL * _connect(const sasl_utils_t *utils);
*/
int check_session(const sasl_utils_t *utils, const char *assertion, char *email)
{
- syslog(LOG_DEBUG, "MySQL client version: %s\n",
+ utils->log(NULL, SASL_LOG_DEBUG, "MySQL client version: %s\n",
mysql_get_client_info());
MYSQL *conn;
int query_rs;
@@ -42,40 +41,40 @@ int check_session(const sasl_utils_t *utils, const char *assertion, char *email)
conn = _connect(utils);
if (conn == NULL) {
- syslog(LOG_EMERG, "Unable to connect to mysql server");
- syslog(LOG_EMERG, "Error %u: %s", mysql_errno(conn),
+ utils->log(NULL, SASL_LOG_ERR, "Unable to connect to mysql server");
+ utils->log(NULL, SASL_LOG_ERR, "Error %u: %s", mysql_errno(conn),
mysql_error(conn));
}
mysql_real_escape_string(conn, assertion_esc, assertion,
strlen(assertion));
sprintf(select_email_esc, select_email, assertion_esc);
- syslog(LOG_DEBUG, "Sending %s", select_email_esc);
+ utils->log(NULL, SASL_LOG_DEBUG, "Sending %s", select_email_esc);
if ((query_rs = mysql_query(conn, select_email_esc)) == 0) {
rs = mysql_store_result(conn);
while((row = mysql_fetch_row(rs))) {
- syslog(LOG_DEBUG, "msyql email: %s", row[0]);
+ utils->log(NULL, SASL_LOG_DEBUG, "msyql email: %s", row[0]);
strcpy(email, row[0]);
rv = 1;
/* Touch session */
sprintf(update_session_esc, update_session,
assertion_esc);
- syslog(LOG_DEBUG, "Sending %s", update_session_esc);
+ utils->log(NULL, SASL_LOG_DEBUG, "Sending %s", update_session_esc);
mysql_query(conn, update_session_esc);
break;
}
if (rs != 0) {
mysql_free_result(rs);
}
} else if (query_rs == CR_UNKNOWN_ERROR) {
- syslog(LOG_ERR, "Unkown Error");
+ utils->log(NULL, SASL_LOG_ERR, "Unkown Error");
} else if (query_rs == CR_SERVER_GONE_ERROR || \
query_rs == CR_SERVER_LOST) {
- syslog(LOG_ERR, "Lost connection to MySQL");
+ utils->log(NULL, SASL_LOG_ERR, "Lost connection to MySQL");
} else {
- syslog(LOG_ERR, "Error %u: %s\n", mysql_errno(conn),
+ utils->log(NULL, SASL_LOG_ERR, "Error %u: %s\n", mysql_errno(conn),
mysql_error(conn));
}
mysql_close(conn);
@@ -96,33 +95,33 @@ int create_session(const sasl_utils_t *utils, const char *assertion, const char
conn = _connect(utils);
if (conn == NULL) {
- syslog(LOG_EMERG, "Error %u: %s\n", mysql_errno(conn),
+ utils->log(NULL, SASL_LOG_ERR, "Error %u: %s\n", mysql_errno(conn),
mysql_error(conn));
- syslog(LOG_EMERG, "Unable to connect to mysql server");
+ utils->log(NULL, SASL_LOG_ERR, "Unable to connect to mysql server");
return 0;
}
mysql_real_escape_string(conn, assertion_esc, assertion,
strlen(assertion));
mysql_real_escape_string(conn, email_esc, email, strlen(email));
sprintf(insert_email_esc, insert_email, assertion_esc, email_esc);
- syslog(LOG_DEBUG, "INSERT SQL [%s]", insert_email_esc);
+ utils->log(NULL, SASL_LOG_DEBUG, "INSERT SQL [%s]", insert_email_esc);
if ((query_rs = mysql_query(conn, insert_email_esc)) == 0) {
if (mysql_affected_rows(conn) == 1) {
- syslog(LOG_DEBUG, "Successfully created a session\n");
+ utils->log(NULL, SASL_LOG_DEBUG, "Successfully created a session\n");
rv = 1;
} else {
- syslog(LOG_WARNING,
+ utils->log(NULL, SASL_LOG_WARN,
"WARN: %llu rows affected, expected 1",
mysql_affected_rows(conn));
}
} else if (query_rs == CR_UNKNOWN_ERROR) {
- syslog(LOG_ERR, "Unkown Error");
+ utils->log(NULL, SASL_LOG_ERR, "Unkown Error");
} else if (query_rs == CR_SERVER_GONE_ERROR || \
query_rs == CR_SERVER_LOST) {
- syslog(LOG_ERR, "Lost Mysql Connection");
+ utils->log(NULL, SASL_LOG_ERR, "Lost Mysql Connection");
} else {
- syslog(LOG_ERR, "Error %u: %s\n", mysql_errno(conn),
+ utils->log(NULL, SASL_LOG_ERR, "Error %u: %s\n", mysql_errno(conn),
mysql_error(conn));
}
mysql_close(conn);
@@ -167,12 +166,12 @@ static MYSQL * _connect(const sasl_utils_t *utils)
} else {
sscanf(port_s, "%u", &port);
}
- syslog(LOG_DEBUG, "mysql real connect with host=[%s] user=[%s] "
+ utils->log(NULL, SASL_LOG_DEBUG, "mysql real connect with host=[%s] user=[%s] "
"pass=[%s] for %s on port %u",
host, user, passwd, db, port);
conn = mysql_init(NULL);
if (conn == NULL) {
- syslog(LOG_EMERG, "Unable to mysql_init, this can't end well.");
+ utils->log(NULL, SASL_LOG_ERR, "Unable to mysql_init, this can't end well.");
}
return mysql_real_connect(conn, host, user, passwd, db, port, NULL, 0);
}
View
147 plugins/verifier.c
@@ -2,7 +2,6 @@
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <curl/curl.h>
#include <sasl/sasl.h> /* saslplug.h should have included this ?!? */
@@ -23,6 +22,7 @@ struct json_response {
size_t size;
size_t realsize;
int memerr;
+ sasl_utils_t *utils;
};
/** Callback function for streaming CURL response */
@@ -32,32 +32,32 @@ static size_t write_cb(void *contents, size_t size, size_t nmemb, void *userp)
size_t nextsize;
struct json_response *mem = (struct json_response *)userp;
- /** check for multiplication overflow */
- if (size != 0 && nmemb != 0 && realsize < size) {
- /** CURL spec says number of bytes handled should be returned
- * http://curl.haxx.se/libcurl/c/curl_easy_setopt.html
- */
- syslog(LOG_ERR, "Integer Overflow early, ignoring new contents");
- return 0;
- }
+ /** check for multiplication overflow */
+ if (size != 0 && nmemb != 0 && realsize < size) {
+ /** CURL spec says number of bytes handled should be returned
+ * http://curl.haxx.se/libcurl/c/curl_easy_setopt.html
+ */
+ mem->utils->log(NULL, SASL_LOG_ERR, "Integer Overflow early, ignoring new contents");
+ return 0;
+ }
if (mem->size + realsize >= mem->realsize) {
nextsize = mem->size + realsize + JSON_BUFFER;
if (nextsize < mem->realsize) {
- syslog(LOG_ERR, "Integer Overflow, ignoring new contents");
+ mem->utils->log(NULL, SASL_LOG_ERR, "Integer Overflow, ignoring new contents");
return 0;
}
mem->realsize = nextsize;
void *tmp = malloc(mem->size + realsize + JSON_BUFFER);
if (tmp == NULL) {
- syslog(LOG_ERR, "Unable to grow json_response tmp buffer");
+ mem->utils->log(NULL, SASL_LOG_ERR, "Unable to grow json_response tmp buffer");
mem->memerr = 1;
return 0;
}
memcpy(tmp, mem->memory, mem->size);
free(mem->memory);
mem->memory = malloc(mem->size + realsize + JSON_BUFFER);
if (mem->memory == NULL) {
- syslog(LOG_ERR, "Unable to grow json_response memory slot");
+ mem->utils->log(NULL, SASL_LOG_ERR, "Unable to grow json_response memory slot");
mem->memerr = 1;
return 0;
}
@@ -72,7 +72,8 @@ static size_t write_cb(void *contents, size_t size, size_t nmemb, void *userp)
}
static int parse(const char* resp,
- struct browserid_response_t *browserid_response);
+ struct browserid_response_t *browserid_response,
+ const sasl_utils_t *utils);
/**
* Attempts to verify an assertion and audience against the
@@ -90,7 +91,7 @@ int browserid_verify(const sasl_utils_t *utils,
const char *bid_url;
char *bid_body;
char *bid_body_fmt = "assertion=%s&audience=%s";
- struct json_response json_text;
+ struct json_response json_text; /* context */
char *resp;
@@ -103,7 +104,7 @@ int browserid_verify(const sasl_utils_t *utils,
"https://browserid.org/verify";
}
- syslog(LOG_INFO, "bidurl = %s", bid_url);
+ utils->log(NULL, SASL_LOG_NOTE, "bidurl = %s", bid_url);
bid_body = malloc(strlen(bid_body_fmt) +
strlen(assertion) + strlen(audience) + 1);
@@ -112,7 +113,7 @@ int browserid_verify(const sasl_utils_t *utils,
return SASL_NOMEM;
}
sprintf(bid_body, bid_body_fmt, assertion, audience);
- syslog(LOG_INFO, "bid_body = %d %s", strlen(bid_body), bid_body);
+ utils->log(NULL, SASL_LOG_NOTE, "bid_body = %d %s", strlen(bid_body), bid_body);
strcpy(browserid_response->status, "");
strcpy(browserid_response->email, "");
@@ -122,54 +123,55 @@ int browserid_verify(const sasl_utils_t *utils,
strcpy(browserid_response->reason, "");
if (0 != curl_global_init(CURL_GLOBAL_SSL)) {
- syslog(LOG_ERR, "curl_global_init was non-zero");
+ utils->log(NULL, SASL_LOG_ERR, "curl_global_init was non-zero");
return SASL_FAIL;
}
handle = curl_easy_init();
if (handle == NULL) {
- syslog(LOG_ERR, "Unable to curl_easy_init");
+ utils->log(NULL, SASL_LOG_ERR, "Unable to curl_easy_init");
return SASL_FAIL;
}
if (0 != curl_easy_setopt(handle, CURLOPT_URL, bid_url)) {
- syslog(LOG_ERR, "curl setopt url failed");
+ utils->log(NULL, SASL_LOG_ERR, "curl setopt url failed");
return SASL_FAIL;
- }
+ }
if (0 != curl_easy_setopt(handle, CURLOPT_POST, 1)) {
- syslog(LOG_ERR, "curl setopt post failed");
+ utils->log(NULL, SASL_LOG_ERR, "curl setopt post failed");
return SASL_FAIL;
- }
+ }
if (0 != curl_easy_setopt(handle, CURLOPT_POSTFIELDS, bid_body)) {
- syslog(LOG_ERR, "curl setopt postfields failed");
+ utils->log(NULL, SASL_LOG_ERR, "curl setopt postfields failed");
return SASL_FAIL;
- }
+ }
if (0 != curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1)) {
- syslog(LOG_DEBUG, "curl setopt follow");
+ utils->log(NULL, SASL_LOG_DEBUG, "curl setopt follow");
return SASL_FAIL;
- }
+ }
if (0 != curl_easy_setopt(handle, CURLOPT_USE_SSL, CURLUSESSL_ALL)) {
- syslog(LOG_DEBUG, "curl setopt ssl failed");
+ utils->log(NULL, SASL_LOG_DEBUG, "curl setopt ssl failed");
return SASL_FAIL;
- }
+ }
if (0 != curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION,
write_cb)) {
- syslog(LOG_ERR, "curl setopt write fn failed");
+ utils->log(NULL, SASL_LOG_ERR, "curl setopt write fn failed");
return SASL_FAIL;
- }
+ }
json_text.size = 0;
json_text.memerr = 0;
json_text.realsize = JSON_BUFFER;
+ json_text.utils = utils;
json_text.memory = malloc(JSON_BUFFER);
if (json_text.memory == NULL) {
MEMERROR( utils );
return SASL_NOMEM;
}
if (0 != curl_easy_setopt(handle, CURLOPT_WRITEDATA, &json_text)) {
- syslog(LOG_ERR, "curl setopt writedata failed");
+ utils->log(NULL, SASL_LOG_ERR, "curl setopt writedata failed");
return SASL_FAIL;
- }
+ }
code = curl_easy_perform(handle);
@@ -179,17 +181,17 @@ int browserid_verify(const sasl_utils_t *utils,
}
if (code == 0) {
- r = parse(json_text.memory, browserid_response);
+ r = parse(json_text.memory, browserid_response, utils);
} else {
- syslog(LOG_EMERG, "curl_easy_perform failed [%u] %s", code,
+ utils->log(NULL, SASL_LOG_ERR, "curl_easy_perform failed [%u] %s", code,
curl_easy_strerror(code));
strcpy(browserid_response->status, "curl-error");
- if (strlen(curl_easy_strerror(code)) < MAX_RESP_FIELD) {
- strcpy(browserid_response->reason, curl_easy_strerror(code));
- } else {
- syslog(LOG_ERR, curl_easy_strerror(code));
- strcpy(browserid_response->reason, "Curl failed, error message too large see syslog.");
- }
+ if (strlen(curl_easy_strerror(code)) < MAX_RESP_FIELD) {
+ strcpy(browserid_response->reason, curl_easy_strerror(code));
+ } else {
+ utils->log(NULL, SASL_LOG_ERR, curl_easy_strerror(code));
+ strcpy(browserid_response->reason, "Curl failed, error message too large see syslog.");
+ }
}
curl_easy_cleanup(handle);
@@ -198,32 +200,33 @@ int browserid_verify(const sasl_utils_t *utils,
}
static int parse(const char* resp,
- struct browserid_response_t *browserid_response)
+ struct browserid_response_t *browserid_response,
+ const sasl_utils_t *utils)
{
yajl_val tree = NULL;
char err_buf[256];
- syslog(LOG_DEBUG, "beginning parse %s", resp);
+ utils->log(NULL, SASL_LOG_DEBUG, "beginning parse %s", resp);
tree = yajl_tree_parse(resp, err_buf, 255);
if (!tree) {
- syslog(LOG_ERR, "bid resp=%s", resp);
- syslog(LOG_ERR, "Error parsing BrowserID response [%s]",
+ utils->log(NULL, SASL_LOG_ERR, "bid resp=%s", resp);
+ utils->log(NULL, SASL_LOG_ERR, "Error parsing BrowserID response [%s]",
err_buf);
return SASL_FAIL;
}
- syslog(LOG_DEBUG, "Obtained parser tree");
+ utils->log(NULL, SASL_LOG_DEBUG, "Obtained parser tree");
const char *status_path[] = { "status", (const char *) 0 };
yajl_val status = yajl_tree_get(tree, status_path, yajl_t_string);
if (!status || strlen(status->u.string) >= MAX_STATUS) {
- syslog(LOG_EMERG, "bid resp=%s", resp);
- syslog(LOG_EMERG, "Expected field status is missing or too large");
+ utils->log(NULL, SASL_LOG_ERR, "bid resp=%s", resp);
+ utils->log(NULL, SASL_LOG_ERR, "Expected field status is missing or too large");
return SASL_FAIL;
}
- syslog(LOG_DEBUG, "Obtained status %s", status->u.string);
+ utils->log(NULL, SASL_LOG_DEBUG, "Obtained status %s", status->u.string);
strcpy(browserid_response->status, status->u.string);
@@ -237,53 +240,53 @@ static int parse(const char* resp,
email = yajl_tree_get(tree, email_path, yajl_t_string);
if (!email || strlen(email->u.string) >= MAX_RESP_FIELD) {
- /* Can't continue without email */
- syslog(LOG_ERR, "bid resp=%s", resp);
- syslog(LOG_ERR, "Expected field email is missing or too large.");
- return SASL_FAIL;
+ /* Can't continue without email */
+ utils->log(NULL, SASL_LOG_ERR, "bid resp=%s", resp);
+ utils->log(NULL, SASL_LOG_ERR, "Expected field email is missing or too large.");
+ return SASL_FAIL;
} else {
- strcpy(browserid_response->email, email->u.string);
+ strcpy(browserid_response->email, email->u.string);
}
audience = yajl_tree_get(tree, audience_path, yajl_t_string);
if (!audience) {
- syslog(LOG_ERR, "Expected field audience is missing");
+ utils->log(NULL, SASL_LOG_ERR, "Expected field audience is missing");
} else {
- if (strlen(audience->u.string) < MAX_RESP_FIELD) {
- strcpy(browserid_response->audience, audience->u.string);
- } else {
- syslog(LOG_WARNING, "Audience is too large, skipping");
- }
+ if (strlen(audience->u.string) < MAX_RESP_FIELD) {
+ strcpy(browserid_response->audience, audience->u.string);
+ } else {
+ utils->log(NULL, SASL_LOG_WARN, "Audience is too large, skipping");
+ }
}
issuer = yajl_tree_get(tree, issuer_path, yajl_t_string);
if (!issuer) {
- syslog(LOG_ERR, "Expected field issuer is missing");
+ utils->log(NULL, SASL_LOG_ERR, "Expected field issuer is missing");
} else {
- if (strlen(issuer->u.string) < MAX_RESP_FIELD) {
- strcpy(browserid_response->issuer, issuer->u.string);
- } else {
- syslog(LOG_WARNING, "Issuer is too large, skipping");
- }
+ if (strlen(issuer->u.string) < MAX_RESP_FIELD) {
+ strcpy(browserid_response->issuer, issuer->u.string);
+ } else {
+ utils->log(NULL, SASL_LOG_WARN, "Issuer is too large, skipping");
+ }
}
expires = yajl_tree_get(tree, expires_path, yajl_t_number);
if (!expires) {
- syslog(LOG_INFO, "Expected field expires is missing or not a number");
+ utils->log(NULL, SASL_LOG_NOTE, "Expected field expires is missing or not a number");
} else {
browserid_response->expires = expires->u.number.i;
}
} else {
const char *reason_path[] = { "reason", (const char *) 0 };
yajl_val reason = yajl_tree_get(tree, reason_path, yajl_t_string);
if (!reason) {
- syslog(LOG_ERR, "Expected field reason is missing");
+ utils->log(NULL, SASL_LOG_ERR, "Expected field reason is missing");
} else {
- if (strlen(reason->u.string) < MAX_RESP_FIELD) {
- strcpy(browserid_response->reason, reason->u.string);
- } else {
- syslog(LOG_WARNING, "BrowserID verifier failure reason is too large to copy, skipping.");
- }
+ if (strlen(reason->u.string) < MAX_RESP_FIELD) {
+ strcpy(browserid_response->reason, reason->u.string);
+ } else {
+ utils->log(NULL, SASL_LOG_WARN, "BrowserID verifier failure reason is too large to copy, skipping.");
+ }
}
return SASL_FAIL;

0 comments on commit b7c0bb0

Please sign in to comment.
Something went wrong with that request. Please try again.