Permalink
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 16, 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
@@ -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
@@ -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);
}
Oops, something went wrong.

0 comments on commit b7c0bb0

Please sign in to comment.