]> err.no Git - yubikey-server-c/commitdiff
use syslog rather than printf for logging
authorTollef Fog Heen <tfheen@err.no>
Mon, 12 Oct 2009 10:59:01 +0000 (12:59 +0200)
committerTollef Fog Heen <tfheen@err.no>
Mon, 12 Oct 2009 11:05:10 +0000 (13:05 +0200)
configure.ac
src/main.c

index 29155ee0f35e8a4eaa5d3f2c20becd767b831ed6..5cda9d07527eaece77d51f2e5b00f503900377f6 100644 (file)
@@ -23,7 +23,7 @@ fi
 PKG_CHECK_MODULES([libmicrohttpd], [libmicrohttpd])
 
 AC_CHECK_LIB([yubikey], [yubikey_modhex_decode],[], AC_MSG_ERROR([libyubikey is not installed or not new enough]))
-
+AM_CONFIG_HEADER(src/config.h)
 AC_CONFIG_FILES([
   Makefile
   src/Makefile
index c52d24fa22da90b6a551abf57648e4fd315aa880..9e02fe9e8c077f2ffdbdae16bbe4919a83938e90 100644 (file)
@@ -33,7 +33,9 @@
 #include <gcrypt.h>
 #include <sys/select.h>
 #include <arpa/inet.h>
+#include <syslog.h>
 #include "util.h"
+#include "config.h"
 
 #ifdef UNUSED
 #elif defined(__GNUC__)
@@ -185,14 +187,15 @@ static int get_shared_secret(const char *id, char **shared_secret,
                           1);      /* ask for binary results */
 
        if (PQresultStatus(res) != PGRES_TUPLES_OK) {
-               fprintf(stderr, "SELECT failed: %s", PQerrorMessage(db_conn));
+               syslog(LOG_ERR, "Failed to get shared secret for id=%s: %s",
+                      id, PQerrorMessage(db_conn));
                r = -1;
                goto free_mem;
                /* XXX Return error object */
        }
        if (PQntuples(res) == 0) {
+               syslog(LOG_INFO, "No such id: %s", id);
                /* XXX Better handling */
-               fprintf(stderr, "No such secrets: %s\n", id);
                r = -1;
                goto free_mem;
        }
@@ -264,7 +267,8 @@ static int set_data_for_uid(char *uid, struct ykc_stats *stats)
                           1);      /* ask for binary results */
 
        if (PQresultStatus(res) != PGRES_COMMAND_OK) {
-               fprintf(stderr, "UPDATE failed: %s\n", PQerrorMessage(db_conn));
+               syslog(LOG_ERR, "UPDATE for %s failed: %s", uid,
+                      PQerrorMessage(db_conn));
                r = -1;
                goto free_mem;
        }
@@ -296,7 +300,8 @@ static int get_data_for_uid(char *uid, struct ykc_stats *stats)
 
        if (PQresultStatus(res) != PGRES_TUPLES_OK)
        {
-               fprintf(stderr, "SELECT failed: %s", PQerrorMessage(db_conn));
+               syslog(LOG_ERR, "Failed to get shared secret for uid=%s: %s",
+                      uid, PQerrorMessage(db_conn));
                r = -1;
                goto free_mem;
        }
@@ -356,8 +361,8 @@ static int handle_request(void * UNUSED(data),
        id = MHD_lookup_connection_value(conn, MHD_GET_ARGUMENT_KIND, "id");
        otp = MHD_lookup_connection_value(conn, MHD_GET_ARGUMENT_KIND, "otp");
        h = MHD_lookup_connection_value(conn, MHD_GET_ARGUMENT_KIND, "h");
-       fprintf(stderr, "got params: url=%s id=%s otp=%s, h=%s\n", url, id,
-               otp, h);
+       syslog(LOG_DEBUG, "Got new connection with parameters: "
+              "url=%s id=%s otp=%s, h=%s\n", url, id, otp, h);
 
        /* Do query to grab shared secret, we need this later anyway */
        if (get_shared_secret(id, &shared_secret, &shared_secret_len) < 0) {
@@ -421,7 +426,8 @@ static int handle_request(void * UNUSED(data),
                signature = sign_request(shared_secret, shared_secret_len,
                                         NULL, status, timestamp);
                send_response(conn, signature, status, NULL, timestamp);
-               fprintf(stderr, "replay\n");
+               syslog(LOG_NOTICE, "Replay attempt for otp=%s, id=%s, uid=%s",
+                      otp, id, uid);
                goto free_mem;
        }
 
@@ -434,7 +440,8 @@ static int handle_request(void * UNUSED(data),
        stats.session_use = token.use;
        set_data_for_uid(uid, &stats);
        /* Generate response, sign it */
-       fprintf(stderr, "ok request\n");
+       syslog(LOG_INFO, "OK request for otp=%s, id=%s, uid=%s",
+              otp, id, uid);
        status = "OK";
        signature = sign_request(shared_secret, shared_secret_len,
                                 NULL, status, timestamp);
@@ -455,11 +462,14 @@ int main(int UNUSED(argc), char ** UNUSED(argv))
 {
        struct MHD_Daemon *d;
 
+       openlog("yubikeyd", LOG_PID, LOG_AUTHPRIV);
+       syslog(LOG_NOTICE, "yubikeyd version %s starting up", VERSION);
+
        /* XXX connect args should go in config file */
        db_conn = PQconnectdb("dbname=yubikey port=5433");
        if (PQstatus(db_conn) != CONNECTION_OK) {
-               fprintf(stderr, "Connection to database failed: %s",
-                       PQerrorMessage(db_conn));
+               syslog(LOG_ERR, "connection to database failed: %s",
+                      PQerrorMessage(db_conn));
                exit(1);
        }
        d = MHD_start_daemon(MHD_USE_DEBUG,
@@ -470,7 +480,7 @@ int main(int UNUSED(argc), char ** UNUSED(argv))
                             NULL, /* Data for default handler */
                             MHD_OPTION_END);
        if (d == NULL) {
-               fprintf(stderr, "Could not start daemon\n");
+               syslog(LOG_ERR, "could not start daemon, unsure why\n");
                exit(1);
        }
        while (1) {