summaryrefslogtreecommitdiff
path: root/server/responder
diff options
context:
space:
mode:
authorSimo Sorce <ssorce@redhat.com>2009-08-05 14:11:12 -0400
committerStephen Gallagher <sgallagh@redhat.com>2009-08-10 09:42:20 -0400
commit11c621b5ee1a0cdc27610f8b172017764acc285e (patch)
tree181c9079440367711c66d7281fc0aecb458fee77 /server/responder
parentf1e4471551aa74015579bff0b64735cc9b085b74 (diff)
downloadsssd-11c621b5ee1a0cdc27610f8b172017764acc285e.tar.gz
sssd-11c621b5ee1a0cdc27610f8b172017764acc285e.tar.bz2
sssd-11c621b5ee1a0cdc27610f8b172017764acc285e.zip
Simplify interfaces initialization
Make as much as possible static, and remove use of talloc_reference and allocation/deallocation of memory when not necessary. Fix also responder use of rctx->conn, was mistakenly used for both monitor and dp connections.
Diffstat (limited to 'server/responder')
-rw-r--r--server/responder/common/responder.h12
-rw-r--r--server/responder/common/responder_common.c30
-rw-r--r--server/responder/common/responder_dp.c24
-rw-r--r--server/responder/nss/nsssrv.c39
-rw-r--r--server/responder/nss/nsssrv.h2
-rw-r--r--server/responder/nss/nsssrv_dp.c12
-rw-r--r--server/responder/pam/pamsrv.c39
-rw-r--r--server/responder/pam/pamsrv.h2
-rw-r--r--server/responder/pam/pamsrv_dp.c26
9 files changed, 86 insertions, 100 deletions
diff --git a/server/responder/common/responder.h b/server/responder/common/responder.h
index 5bde42ac..0f090831 100644
--- a/server/responder/common/responder.h
+++ b/server/responder/common/responder.h
@@ -64,16 +64,14 @@ struct resp_ctx {
const char *sock_name;
const char *priv_sock_name;
- struct sbus_connection *conn;
- struct sbus_method_ctx *sm_ctx;
+ struct sbus_connection *mon_conn;
+ struct sbus_connection *dp_conn;
struct sss_domain_info *domains;
- struct sbus_method *sss_sbus_methods;
struct sss_cmd_table *sss_cmds;
const char *sss_pipe_name;
const char *confdb_service_path;
- struct sbus_method *dp_methods;
struct sss_names_ctx *names;
@@ -100,12 +98,12 @@ struct sss_cmd_table {
int sss_process_init(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct confdb_ctx *cdb,
- struct sbus_method sss_sbus_methods[],
struct sss_cmd_table sss_cmds[],
const char *sss_pipe_name,
const char *sss_priv_pipe_name,
const char *confdb_service_path,
- struct sbus_method dp_methods[],
+ struct sbus_interface *dp_intf,
+ struct sbus_interface *monitor_intf,
struct resp_ctx **responder_ctx);
int sss_parse_name(TALLOC_CTX *memctx,
@@ -119,7 +117,7 @@ int sss_cmd_get_version(struct cli_ctx *cctx);
struct cli_protocol_version *register_cli_protocol_version(void);
/* responder_dp.c */
-int sss_dp_init(struct resp_ctx *rctx, struct sbus_method dp_methods[]);
+int sss_dp_init(struct resp_ctx *rctx, struct sbus_interface *intf);
#define NSS_DP_USER 1
#define NSS_DP_GROUP 2
diff --git a/server/responder/common/responder_common.c b/server/responder/common/responder_common.c
index c8e5d818..f3df7c65 100644
--- a/server/responder/common/responder_common.c
+++ b/server/responder/common/responder_common.c
@@ -285,7 +285,8 @@ static void accept_fd_handler(struct tevent_context *ev,
return;
}
-static int sss_sbus_init(struct resp_ctx *rctx)
+static int sss_monitor_init(struct resp_ctx *rctx,
+ struct sbus_interface *intf)
{
char *sbus_address;
int ret;
@@ -297,21 +298,8 @@ static int sss_sbus_init(struct resp_ctx *rctx)
return ret;
}
- ret = monitor_init_sbus_methods(rctx, rctx->sss_sbus_methods,
- &rctx->sm_ctx);
- if (ret != EOK) {
- DEBUG(0, ("Could not initialize SBUS methods.\n"));
- return ret;
- }
-
- /* FIXME: remove this */
- if (talloc_reference(rctx, rctx->sm_ctx) == NULL) {
- DEBUG(0, ("Failed to take memory reference\n"));
- return ENOMEM;
- }
-
ret = sbus_client_init(rctx, rctx->ev, sbus_address,
- rctx->sm_ctx, &rctx->conn,
+ intf, &rctx->mon_conn,
NULL, NULL);
if (ret != EOK) {
DEBUG(0, ("Failed to connect to monitor services.\n"));
@@ -455,12 +443,12 @@ failed:
int sss_process_init(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct confdb_ctx *cdb,
- struct sbus_method sss_sbus_methods[],
struct sss_cmd_table sss_cmds[],
const char *sss_pipe_name,
const char *sss_priv_pipe_name,
const char *confdb_service_path,
- struct sbus_method dp_methods[],
+ struct sbus_interface *dp_intf,
+ struct sbus_interface *monitor_intf,
struct resp_ctx **responder_ctx)
{
struct resp_ctx *rctx;
@@ -473,12 +461,10 @@ int sss_process_init(TALLOC_CTX *mem_ctx,
}
rctx->ev = ev;
rctx->cdb = cdb;
- rctx->sss_sbus_methods = sss_sbus_methods;
rctx->sss_cmds = sss_cmds;
rctx->sock_name = sss_pipe_name;
rctx->priv_sock_name = sss_priv_pipe_name;
rctx->confdb_service_path = confdb_service_path;
- rctx->dp_methods = dp_methods;
ret = confdb_get_domains(rctx->cdb, rctx, &rctx->domains);
if (ret != EOK) {
@@ -486,18 +472,18 @@ int sss_process_init(TALLOC_CTX *mem_ctx,
return ret;
}
- ret = sss_sbus_init(rctx);
+ ret = sss_monitor_init(rctx, monitor_intf);
if (ret != EOK) {
DEBUG(0, ("fatal error setting up message bus\n"));
return ret;
}
- ret = sss_dp_init(rctx, rctx->dp_methods);
+ ret = sss_dp_init(rctx, dp_intf);
if (ret != EOK) {
DEBUG(0, ("fatal error setting up backend connector\n"));
return ret;
}
- else if (!rctx->conn) {
+ else if (!rctx->dp_conn) {
DEBUG(0, ("Data Provider is not yet available. Retrying.\n"));
return EIO;
}
diff --git a/server/responder/common/responder_dp.c b/server/responder/common/responder_dp.c
index 547cb272..dc810fd9 100644
--- a/server/responder/common/responder_dp.c
+++ b/server/responder/common/responder_dp.c
@@ -10,7 +10,7 @@
struct sss_dp_pvt_ctx {
struct resp_ctx *rctx;
- struct sbus_method *methods;
+ struct sbus_interface *intf;
time_t last_retry;
int retries;
};
@@ -49,20 +49,8 @@ static void sss_dp_conn_reconnect(struct sss_dp_pvt_ctx *pvt)
return;
}
- ret = dp_init_sbus_methods(rctx, pvt->methods, &rctx->sm_ctx);
- if (ret != EOK) {
- DEBUG(0, ("Could not initialize SBUS methods.\n"));
- return;
- }
-
- /* FIXME: remove this */
- if (talloc_reference(rctx, rctx->sm_ctx) == NULL) {
- DEBUG(0, ("Failed to take memory reference\n"));
- return;
- }
-
ret = sbus_client_init(rctx, rctx->ev, sbus_address,
- rctx->sm_ctx, &rctx->conn,
+ pvt->intf, &rctx->dp_conn,
sss_dp_conn_destructor, pvt);
if (ret != EOK) {
DEBUG(4, ("Failed to reconnect [%d(%s)]!\n", ret, strerror(ret)));
@@ -109,7 +97,7 @@ int sss_dp_conn_destructor(void *data)
return 0;
}
-int sss_dp_init(struct resp_ctx *rctx, struct sbus_method *dp_methods)
+int sss_dp_init(struct resp_ctx *rctx, struct sbus_interface *dp_intf)
{
struct sss_dp_pvt_ctx *pvt;
@@ -117,7 +105,7 @@ int sss_dp_init(struct resp_ctx *rctx, struct sbus_method *dp_methods)
if (!pvt) return ENOMEM;
pvt->rctx = rctx;
- pvt->methods = dp_methods;
+ pvt->intf = dp_intf;
sss_dp_conn_reconnect(pvt);
@@ -243,12 +231,12 @@ int nss_dp_send_acct_req(struct resp_ctx *rctx, TALLOC_CTX *memctx,
* in some pathological cases it may happen that nss starts up before
* dp connection code is actually able to establish a connection.
*/
- if (!rctx->conn) {
+ if (!rctx->dp_conn) {
DEBUG(1, ("The Data Provider connection is not available yet!"
" This maybe a bug, it shouldn't happen!\n"));
return EIO;
}
- dbus_conn = sbus_get_connection(rctx->conn);
+ dbus_conn = sbus_get_connection(rctx->dp_conn);
/* create the message */
msg = dbus_message_new_method_call(NULL,
diff --git a/server/responder/nss/nsssrv.c b/server/responder/nss/nsssrv.c
index d104c7c8..248d5384 100644
--- a/server/responder/nss/nsssrv.c
+++ b/server/responder/nss/nsssrv.c
@@ -57,12 +57,20 @@ static int service_pong(DBusMessage *message, struct sbus_connection *conn);
static int service_reload(DBusMessage *message, struct sbus_connection *conn);
static int service_res_init(DBusMessage *message, struct sbus_connection *conn);
-struct sbus_method nss_sbus_methods[] = {
- {SERVICE_METHOD_IDENTITY, service_identity},
- {SERVICE_METHOD_PING, service_pong},
- {SERVICE_METHOD_RELOAD, service_reload},
- {SERVICE_METHOD_RES_INIT, service_res_init},
- {NULL, NULL}
+struct sbus_method monitor_nss_methods[] = {
+ { MON_CLI_METHOD_IDENTITY, service_identity },
+ { MON_CLI_METHOD_PING, service_pong },
+ { MON_CLI_METHOD_RELOAD, service_reload },
+ { MON_CLI_METHOD_RES_INIT, service_res_init },
+ { NULL, NULL }
+};
+
+struct sbus_interface monitor_nss_interface = {
+ MONITOR_INTERFACE,
+ MONITOR_PATH,
+ SBUS_DEFAULT_VTABLE,
+ monitor_nss_methods,
+ NULL
};
static int service_identity(DBusMessage *message, struct sbus_connection *conn)
@@ -252,19 +260,10 @@ static void nss_shutdown(struct resp_ctx *rctx)
static void nss_dp_reconnect_init(struct sbus_connection *conn, int status, void *pvt)
{
- int ret;
struct resp_ctx *rctx = talloc_get_type(pvt, struct resp_ctx);
/* Did we reconnect successfully? */
if (status == SBUS_RECONNECT_SUCCESS) {
- /* Add the methods back to the new connection */
- ret = sbus_conn_add_method_ctx(rctx->conn,
- rctx->sm_ctx);
- if (ret != EOK) {
- DEBUG(0, ("Could not re-add methods on reconnection.\n"));
- nss_shutdown(rctx);
- }
-
DEBUG(1, ("Reconnected to the Data Provider.\n"));
return;
}
@@ -280,7 +279,7 @@ int nss_process_init(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct confdb_ctx *cdb)
{
- struct sbus_method *nss_dp_methods;
+ struct sbus_interface *nss_dp_interface;
struct sss_cmd_table *nss_cmds;
struct nss_ctx *nctx;
int ret, max_retries;
@@ -297,15 +296,15 @@ int nss_process_init(TALLOC_CTX *mem_ctx,
return ret;
}
- nss_dp_methods = get_nss_dp_methods();
+ nss_dp_interface = get_nss_dp_interface();
nss_cmds = get_nss_cmds();
ret = sss_process_init(nctx, ev, cdb,
- nss_sbus_methods,
nss_cmds,
SSS_NSS_SOCKET_NAME, NULL,
NSS_SRV_CONFIG,
- nss_dp_methods,
+ nss_dp_interface,
+ &monitor_nss_interface,
&nctx->rctx);
if (ret != EOK) {
return ret;
@@ -327,7 +326,7 @@ int nss_process_init(TALLOC_CTX *mem_ctx,
return ret;
}
- sbus_reconnect_init(nctx->rctx->conn,
+ sbus_reconnect_init(nctx->rctx->dp_conn,
max_retries,
nss_dp_reconnect_init, nctx->rctx);
diff --git a/server/responder/nss/nsssrv.h b/server/responder/nss/nsssrv.h
index cbbb9cc6..f79d056c 100644
--- a/server/responder/nss/nsssrv.h
+++ b/server/responder/nss/nsssrv.h
@@ -68,7 +68,7 @@ struct nss_packet;
int nss_cmd_execute(struct cli_ctx *cctx);
/* from nsssrv_dp.c */
-struct sbus_method *get_nss_dp_methods(void);
+struct sbus_interface *get_nss_dp_interface(void);
struct sss_cmd_table *get_nss_cmds(void);
#endif /* __NSSSRV_H__ */
diff --git a/server/responder/nss/nsssrv_dp.c b/server/responder/nss/nsssrv_dp.c
index 7150a594..92a2d441 100644
--- a/server/responder/nss/nsssrv_dp.c
+++ b/server/responder/nss/nsssrv_dp.c
@@ -66,7 +66,15 @@ static struct sbus_method nss_dp_methods[] = {
{ NULL, NULL }
};
-struct sbus_method *get_nss_dp_methods(void)
+struct sbus_interface nss_dp_interface = {
+ DATA_PROVIDER_INTERFACE,
+ DATA_PROVIDER_PATH,
+ SBUS_DEFAULT_VTABLE,
+ nss_dp_methods,
+ NULL
+};
+
+struct sbus_interface *get_nss_dp_interface(void)
{
- return nss_dp_methods;
+ return &nss_dp_interface;
}
diff --git a/server/responder/pam/pamsrv.c b/server/responder/pam/pamsrv.c
index cd423714..48286ecd 100644
--- a/server/responder/pam/pamsrv.c
+++ b/server/responder/pam/pamsrv.c
@@ -60,12 +60,20 @@ static int service_pong(DBusMessage *message, struct sbus_connection *conn);
static int service_reload(DBusMessage *message, struct sbus_connection *conn);
static int service_res_init(DBusMessage *message, struct sbus_connection *conn);
-struct sbus_method sss_sbus_methods[] = {
- {SERVICE_METHOD_IDENTITY, service_identity},
- {SERVICE_METHOD_PING, service_pong},
- {SERVICE_METHOD_RELOAD, service_reload},
- {SERVICE_METHOD_RES_INIT, service_res_init},
- {NULL, NULL}
+struct sbus_method monitor_pam_methods[] = {
+ { MON_CLI_METHOD_IDENTITY, service_identity },
+ { MON_CLI_METHOD_PING, service_pong },
+ { MON_CLI_METHOD_RELOAD, service_reload },
+ { MON_CLI_METHOD_RES_INIT, service_res_init },
+ { NULL, NULL }
+};
+
+struct sbus_interface monitor_pam_interface = {
+ MONITOR_INTERFACE,
+ MONITOR_PATH,
+ SBUS_DEFAULT_VTABLE,
+ monitor_pam_methods,
+ NULL
};
static int service_identity(DBusMessage *message, struct sbus_connection *conn)
@@ -142,19 +150,10 @@ static int service_reload(DBusMessage *message, struct sbus_connection *conn) {
static void pam_dp_reconnect_init(struct sbus_connection *conn, int status, void *pvt)
{
- int ret;
struct resp_ctx *rctx = talloc_get_type(pvt, struct resp_ctx);
/* Did we reconnect successfully? */
if (status == SBUS_RECONNECT_SUCCESS) {
- /* Add the methods back to the new connection */
- ret = sbus_conn_add_method_ctx(rctx->conn,
- rctx->sm_ctx);
- if (ret != EOK) {
- DEBUG(0, ("Could not re-add methods on reconnection.\n"));
- pam_shutdown(rctx);
- }
-
DEBUG(1, ("Reconnected to the Data Provider.\n"));
return;
}
@@ -190,7 +189,7 @@ static int pam_process_init(struct main_context *main_ctx,
return ret;
}
- sbus_reconnect_init(rctx->conn, max_retries,
+ sbus_reconnect_init(rctx->dp_conn, max_retries,
pam_dp_reconnect_init, rctx);
return EOK;
@@ -202,7 +201,7 @@ int main(int argc, const char *argv[])
poptContext pc;
struct main_context *main_ctx;
int ret;
- struct sbus_method *pam_dp_methods;
+ struct sbus_interface *pam_dp_interface;
struct sss_cmd_table *sss_cmds;
struct resp_ctx *rctx;
@@ -229,17 +228,17 @@ int main(int argc, const char *argv[])
ret = server_setup("sssd[pam]", 0, PAM_SRV_CONFIG, &main_ctx);
if (ret != EOK) return 2;
- pam_dp_methods = register_pam_dp_methods();
+ pam_dp_interface = get_pam_dp_interface();
sss_cmds = register_sss_cmds();
ret = sss_process_init(main_ctx,
main_ctx->event_ctx,
main_ctx->confdb_ctx,
- sss_sbus_methods,
sss_cmds,
SSS_PAM_SOCKET_NAME,
SSS_PAM_PRIV_SOCKET_NAME,
PAM_SRV_CONFIG,
- pam_dp_methods,
+ pam_dp_interface,
+ &monitor_pam_interface,
&rctx);
if (ret != EOK) return 3;
diff --git a/server/responder/pam/pamsrv.h b/server/responder/pam/pamsrv.h
index fa688fe1..1de1cee8 100644
--- a/server/responder/pam/pamsrv.h
+++ b/server/responder/pam/pamsrv.h
@@ -22,7 +22,7 @@ struct pam_auth_req {
void *data;
};
-struct sbus_method *register_pam_dp_methods(void);
+struct sbus_interface *get_pam_dp_interface(void);
struct sss_cmd_table *register_sss_cmds(void);
int pam_dp_send_req(struct pam_auth_req *preq, int timeout);
diff --git a/server/responder/pam/pamsrv_dp.c b/server/responder/pam/pamsrv_dp.c
index c7a536e8..c0a286b2 100644
--- a/server/responder/pam/pamsrv_dp.c
+++ b/server/responder/pam/pamsrv_dp.c
@@ -92,12 +92,12 @@ int pam_dp_send_req(struct pam_auth_req *preq, int timeout)
* in some pathological cases it may happen that nss starts up before
* dp connection code is actually able to establish a connection.
*/
- if (!preq->cctx->rctx->conn) {
+ if (!preq->cctx->rctx->dp_conn) {
DEBUG(1, ("The Data Provider connection is not available yet!"
" This maybe a bug, it shouldn't happen!\n"));
return EIO;
}
- dbus_conn = sbus_get_connection(preq->cctx->rctx->conn);
+ dbus_conn = sbus_get_connection(preq->cctx->rctx->dp_conn);
msg = dbus_message_new_method_call(NULL,
DP_CLI_PATH,
@@ -169,12 +169,20 @@ static int pam_dp_identity(DBusMessage *message, struct sbus_connection *conn)
return EOK;
}
-struct sbus_method *register_pam_dp_methods(void)
-{
- static struct sbus_method pam_dp_methods[] = {
- { DP_CLI_METHOD_IDENTITY, pam_dp_identity },
- { NULL, NULL }
- };
+static struct sbus_method pam_dp_methods[] = {
+ { DP_CLI_METHOD_IDENTITY, pam_dp_identity },
+ { NULL, NULL }
+};
+
+struct sbus_interface pam_dp_interface = {
+ DATA_PROVIDER_INTERFACE,
+ DATA_PROVIDER_PATH,
+ SBUS_DEFAULT_VTABLE,
+ pam_dp_methods,
+ NULL
+};
- return pam_dp_methods;
+struct sbus_interface *get_pam_dp_interface(void)
+{
+ return &pam_dp_interface;
}