From 8c50bd085c0efe5fde354deee2c8118887aae29d Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Fri, 18 Sep 2009 12:35:34 +0200 Subject: Use syslog for logging error conditions in SSSD This is just a band-aid until ELAPI is fully functional and ready to use. --- server/providers/data_provider.c | 64 ++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 28 deletions(-) (limited to 'server/providers/data_provider.c') diff --git a/server/providers/data_provider.c b/server/providers/data_provider.c index f8efcc8d8..f4affd1ad 100644 --- a/server/providers/data_provider.c +++ b/server/providers/data_provider.c @@ -43,6 +43,8 @@ #define DP_CONF_ENTRY "config/services/dp" +#define PRG_NAME "sssd" + struct dp_backend; struct dp_frontend; @@ -151,7 +153,7 @@ static int dp_monitor_init(struct dp_ctx *dpctx) /* Set up SBUS connection to the monitor */ ret = monitor_get_sbus_address(dpctx, dpctx->cdb, &sbus_address); if (ret != EOK) { - DEBUG(0, ("Could not locate monitor address.\n")); + SYSLOG_ERROR("Could not locate monitor address.\n"); return ret; } @@ -159,7 +161,7 @@ static int dp_monitor_init(struct dp_ctx *dpctx) &monitor_dp_interface, &conn, NULL, NULL); if (ret != EOK) { - DEBUG(0, ("Failed to connect to monitor services.\n")); + SYSLOG_ERROR("Failed to connect to monitor services.\n"); return ret; } @@ -168,7 +170,7 @@ static int dp_monitor_init(struct dp_ctx *dpctx) DATA_PROVIDER_SERVICE_NAME, DATA_PROVIDER_VERSION); if (ret != EOK) { - DEBUG(0, ("Failed to identify to the monitor!\n")); + SYSLOG_ERROR("Failed to identify to the monitor!\n"); return ret; } @@ -202,7 +204,7 @@ static int dp_client_init(struct sbus_connection *conn, void *data) dpcli = talloc(conn, struct dp_client); if (!dpcli) { - DEBUG(0,("Out of memory?!\n")); + SYSLOG_ERROR("Out of memory?!\n"); talloc_zfree(conn); return ENOMEM; } @@ -216,7 +218,7 @@ static int dp_client_init(struct sbus_connection *conn, void *data) dpcli->timeout = tevent_add_timer(dpctx->ev, dpcli, tv, init_timeout, dpcli); if (!dpcli->timeout) { - DEBUG(0,("Out of memory?!\n")); + SYSLOG_ERROR("Out of memory?!\n"); talloc_zfree(conn); return ENOMEM; } @@ -248,7 +250,7 @@ static int client_registration(DBusMessage *message, data = sbus_conn_get_private_data(conn); dpcli = talloc_get_type(data, struct dp_client); if (!dpcli) { - DEBUG(0, ("Connection holds no valid init data\n")); + SYSLOG_ERROR("Connection holds no valid init data\n"); return EINVAL; } @@ -276,14 +278,14 @@ static int client_registration(DBusMessage *message, case DP_CLI_BACKEND: dpbe = talloc_zero(dpcli->dpctx, struct dp_backend); if (!dpbe) { - DEBUG(0, ("Out of memory!\n")); + SYSLOG_ERROR("Out of memory!\n"); sbus_disconnect(conn); return ENOMEM; } dpbe->domain = talloc_strdup(dpbe, cli_domain); if (!dpbe->domain) { - DEBUG(0, ("Out of memory!\n")); + SYSLOG_ERROR("Out of memory!\n"); sbus_disconnect(conn); return ENOMEM; } @@ -300,14 +302,14 @@ static int client_registration(DBusMessage *message, case DP_CLI_FRONTEND: dpfe = talloc_zero(dpcli->dpctx, struct dp_frontend); if (!dpfe) { - DEBUG(0, ("Out of memory!\n")); + SYSLOG_ERROR("Out of memory!\n"); sbus_disconnect(conn); return ENOMEM; } dpfe->name = talloc_strdup(dpfe, cli_name); if (!dpfe->name) { - DEBUG(0, ("Out of memory!\n")); + SYSLOG_ERROR("Out of memory!\n"); sbus_disconnect(conn); return ENOMEM; } @@ -330,7 +332,7 @@ static int client_registration(DBusMessage *message, /* reply that all is ok */ reply = dbus_message_new_method_return(message); if (!reply) { - DEBUG(0, ("Dbus Out of memory!\n")); + SYSLOG_ERROR("Dbus Out of memory!\n"); return ENOMEM; } @@ -338,7 +340,7 @@ static int client_registration(DBusMessage *message, DBUS_TYPE_UINT16, &version, DBUS_TYPE_INVALID); if (!dbret) { - DEBUG(0, ("Failed to build dbus reply\n")); + SYSLOG_ERROR("Failed to build dbus reply\n"); dbus_message_unref(reply); sbus_disconnect(conn); return EIO; @@ -373,7 +375,7 @@ static void be_got_account_info(DBusPendingCall *pending, void *data) * until reply is valid or timeout has occurred. If reply is NULL * here, something is seriously wrong and we should bail out. */ - DEBUG(0, ("Severe error. A reply callback was called but no reply was received and no timeout occurred\n")); + SYSLOG_ERROR("Severe error. A reply callback was called but no reply was received and no timeout occurred\n"); /* Destroy this connection */ sbus_disconnect(bereq->be->dpcli->conn); @@ -402,8 +404,8 @@ static void be_got_account_info(DBusPendingCall *pending, void *data) break; case DBUS_MESSAGE_TYPE_ERROR: - DEBUG(0,("The Data Provider returned an error [%s], closing connection.\n", - dbus_message_get_error_name(reply))); + SYSLOG_ERROR("The Data Provider returned an error [%s], closing connection.\n", + dbus_message_get_error_name(reply)); /* Falling through to default intentionally*/ default: /* @@ -468,7 +470,7 @@ static int dp_send_acct_req(struct dp_be_request *bereq, DP_CLI_INTERFACE, DP_CLI_METHOD_GETACCTINFO); if (msg == NULL) { - DEBUG(0,("Out of memory?!\n")); + SYSLOG_ERROR("Out of memory?!\n"); return ENOMEM; } @@ -492,7 +494,7 @@ static int dp_send_acct_req(struct dp_be_request *bereq, * We can't communicate on this connection * We'll drop it using the default destructor. */ - DEBUG(0, ("D-BUS send failed.\n")); + SYSLOG_ERROR("D-BUS send failed.\n"); dbus_message_unref(msg); return EIO; } @@ -688,7 +690,7 @@ static void be_got_pam_reply(DBusPendingCall *pending, void *data) * until reply is valid or timeout has occurred. If reply is NULL * here, something is seriously wrong and we should bail out. */ - DEBUG(0, ("Severe error. A reply callback was called but no reply was received and no timeout occurred\n")); + SYSLOG_ERROR("Severe error. A reply callback was called but no reply was received and no timeout occurred\n"); /* Destroy this connection */ sbus_disconnect(bereq->be->dpcli->conn); @@ -715,8 +717,8 @@ static void be_got_pam_reply(DBusPendingCall *pending, void *data) break; case DBUS_MESSAGE_TYPE_ERROR: - DEBUG(0,("The Data Provider returned an error [%s], closing connection.\n", - dbus_message_get_error_name(reply))); + SYSLOG_ERROR("The Data Provider returned an error [%s], closing connection.\n", + dbus_message_get_error_name(reply)); /* Falling through to default intentionally*/ default: /* @@ -765,7 +767,7 @@ static int dp_call_pamhandler(struct dp_be_request *bereq, struct pam_data *pd) DP_CLI_INTERFACE, DP_CLI_METHOD_PAMHANDLER); if (msg == NULL) { - DEBUG(0,("Out of memory?!\n")); + SYSLOG_ERROR("Out of memory?!\n"); return ENOMEM; } @@ -786,7 +788,7 @@ static int dp_call_pamhandler(struct dp_be_request *bereq, struct pam_data *pd) * We can't communicate on this connection * We'll drop it using the default destructor. */ - DEBUG(0, ("D-BUS send failed.\n")); + SYSLOG_ERROR("D-BUS send failed.\n"); dbus_message_unref(msg); return EIO; } @@ -827,7 +829,7 @@ static int dp_pamhandler(DBusMessage *message, struct sbus_connection *conn) ret = dp_unpack_pam_request(message, pd, &dbus_error); if (!ret) { - DEBUG(0,("Failed, to parse message!\n")); + SYSLOG_ERROR("Failed, to parse message!\n"); if (dbus_error_is_set(&dbus_error)) dbus_error_free(&dbus_error); talloc_free(pd); return EIO; @@ -838,7 +840,7 @@ static int dp_pamhandler(DBusMessage *message, struct sbus_connection *conn) reply = dbus_message_new_method_return(message); if (!reply) { - DEBUG(0,("Out of memory?!\n")); + SYSLOG_ERROR("Out of memory?!\n"); talloc_free(pd); return ENOMEM; } @@ -964,7 +966,7 @@ static int dp_process_init(TALLOC_CTX *mem_ctx, dpctx = talloc_zero(mem_ctx, struct dp_ctx); if (!dpctx) { - DEBUG(0, ("fatal error initializing dp_ctx\n")); + SYSLOG_ERROR("fatal error initializing dp_ctx\n"); return ENOMEM; } dpctx->ev = ev; @@ -972,13 +974,13 @@ static int dp_process_init(TALLOC_CTX *mem_ctx, ret = dp_monitor_init(dpctx); if (ret != EOK) { - DEBUG(0, ("fatal error setting up monitor bus\n")); + SYSLOG_ERROR("fatal error setting up monitor bus\n"); return ret; } ret = dp_srv_init(dpctx); if (ret != EOK) { - DEBUG(0, ("fatal error setting up server bus\n")); + SYSLOG_ERROR("fatal error setting up server bus\n"); return ret; } @@ -1011,8 +1013,11 @@ int main(int argc, const char *argv[]) poptFreeContext(pc); + /* enable syslog logging */ + openlog(PRG_NAME, LOG_PID, LOG_DAEMON); + /* set up things like debug , signals, daemonization, etc... */ - ret = server_setup("sssd[dp]", 0, DP_CONF_ENTRY, &main_ctx); + ret = server_setup(PRG_NAME, 0, DP_CONF_ENTRY, &main_ctx); if (ret != EOK) return 2; ret = die_if_parent_died(); @@ -1029,6 +1034,9 @@ int main(int argc, const char *argv[]) /* loop on main */ server_loop(main_ctx); + /* close syslog */ + closelog(); + return 0; } -- cgit