summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Gallagher <sgallagh@redhat.com>2009-11-19 16:37:51 -0500
committerStephen Gallagher <sgallagh@redhat.com>2009-11-23 12:46:30 -0500
commit64e5787639836a49ddc589eda65be454c4bdff58 (patch)
tree75fdc5923cd6854547be1cdd62110a0bd602aaab
parent23341562c1cd4baf46cbc4eacaa09d6b6cb00e82 (diff)
downloadsssd-64e5787639836a49ddc589eda65be454c4bdff58.tar.gz
sssd-64e5787639836a49ddc589eda65be454c4bdff58.tar.bz2
sssd-64e5787639836a49ddc589eda65be454c4bdff58.zip
Speed up user requests while offline
This adds a new boolean option to sss_dp_send_acct_req() called fast_reply. If we make a request to the backends and we are currently offline, this option will determine whether we should immediately return from the cache (acceptable for NSS requests) or potentially wait for an online check to complete (required for PAM requests).
-rw-r--r--server/providers/data_provider.h1
-rw-r--r--server/providers/data_provider_be.c113
-rw-r--r--server/responder/common/responder.h3
-rw-r--r--server/responder/common/responder_dp.c7
-rw-r--r--server/responder/nss/nsssrv_cmd.c22
-rw-r--r--server/responder/pam/pamsrv_cmd.c8
6 files changed, 102 insertions, 52 deletions
diff --git a/server/providers/data_provider.h b/server/providers/data_provider.h
index 33aed3f2..c5246623 100644
--- a/server/providers/data_provider.h
+++ b/server/providers/data_provider.h
@@ -73,6 +73,7 @@
#define BE_REQ_USER 0x0001
#define BE_REQ_GROUP 0x0002
#define BE_REQ_INITGROUPS 0x0003
+#define BE_REQ_FAST 0x1000
/* AUTH related common data and functions */
diff --git a/server/providers/data_provider_be.c b/server/providers/data_provider_be.c
index b5d24600..02d5a0d1 100644
--- a/server/providers/data_provider_be.c
+++ b/server/providers/data_provider_be.c
@@ -251,36 +251,43 @@ static void acctinfo_callback(struct be_req *req,
dbus_uint32_t err_min = 0;
const char *err_msg = NULL;
- err_maj = dp_err_type;
- err_min = errnum;
- if (errstr) {
- err_msg = errstr;
- } else {
- err_msg = dp_err_to_string(req, dp_err_type, errnum);
- }
- if (!err_msg) {
- DEBUG(1, ("Failed to set err_msg, Out of memory?\n"));
- err_msg = "OOM";
- }
-
reply = (DBusMessage *)req->pvt;
- dbret = dbus_message_append_args(reply,
- DBUS_TYPE_UINT16, &err_maj,
- DBUS_TYPE_UINT32, &err_min,
- DBUS_TYPE_STRING, &err_msg,
- DBUS_TYPE_INVALID);
- if (!dbret) {
- DEBUG(1, ("Failed to generate dbus reply\n"));
- return;
- }
+ if (reply) {
+ /* Return a reply if one was requested
+ * There may not be one if this request began
+ * while we were offline
+ */
- dbus_conn = sbus_get_connection(req->becli->conn);
- dbus_connection_send(dbus_conn, reply, NULL);
- dbus_message_unref(reply);
+ err_maj = dp_err_type;
+ err_min = errnum;
+ if (errstr) {
+ err_msg = errstr;
+ } else {
+ err_msg = dp_err_to_string(req, dp_err_type, errnum);
+ }
+ if (!err_msg) {
+ DEBUG(1, ("Failed to set err_msg, Out of memory?\n"));
+ err_msg = "OOM";
+ }
- DEBUG(4, ("Request processed. Returned %d,%d,%s\n",
- err_maj, err_min, err_msg));
+ dbret = dbus_message_append_args(reply,
+ DBUS_TYPE_UINT16, &err_maj,
+ DBUS_TYPE_UINT32, &err_min,
+ DBUS_TYPE_STRING, &err_msg,
+ DBUS_TYPE_INVALID);
+ if (!dbret) {
+ DEBUG(1, ("Failed to generate dbus reply\n"));
+ return;
+ }
+
+ dbus_conn = sbus_get_connection(req->becli->conn);
+ dbus_connection_send(dbus_conn, reply, NULL);
+ dbus_message_unref(reply);
+
+ DEBUG(4, ("Request processed. Returned %d,%d,%s\n",
+ err_maj, err_min, err_msg));
+ }
/* finally free the request */
talloc_free(req);
@@ -329,6 +336,36 @@ static int be_get_account_info(DBusMessage *message, struct sbus_connection *con
reply = dbus_message_new_method_return(message);
if (!reply) return ENOMEM;
+ /* If we are offline and fast reply was requested
+ * return offline immediately
+ */
+ if ((type & BE_REQ_FAST) && becli->bectx->offstat.offline) {
+ /* Send back an immediate reply */
+ err_maj = DP_ERR_OFFLINE;
+ err_min = EAGAIN;
+ err_msg = "Fast reply - offline";
+
+ dbret = dbus_message_append_args(reply,
+ DBUS_TYPE_UINT16, &err_maj,
+ DBUS_TYPE_UINT32, &err_min,
+ DBUS_TYPE_STRING, &err_msg,
+ DBUS_TYPE_INVALID);
+ if (!dbret) return EIO;
+
+ DEBUG(4, ("Request processed. Returned %d,%d,%s\n",
+ err_maj, err_min, err_msg));
+
+ sbus_conn_send_reply(conn, reply);
+ dbus_message_unref(reply);
+ reply = NULL;
+ /* This reply will be queued and sent
+ * when we reenter the mainloop.
+ *
+ * Continue processing in case we are
+ * going back online.
+ */
+ }
+
if (attrs) {
if (strcmp(attrs, "core") == 0) attr_type = BE_ATTR_CORE;
else if (strcmp(attrs, "membership") == 0) attr_type = BE_ATTR_MEM;
@@ -410,19 +447,21 @@ done:
talloc_free(be_req);
}
- dbret = dbus_message_append_args(reply,
- DBUS_TYPE_UINT16, &err_maj,
- DBUS_TYPE_UINT32, &err_min,
- DBUS_TYPE_STRING, &err_msg,
- DBUS_TYPE_INVALID);
- if (!dbret) return EIO;
+ if (reply) {
+ dbret = dbus_message_append_args(reply,
+ DBUS_TYPE_UINT16, &err_maj,
+ DBUS_TYPE_UINT32, &err_min,
+ DBUS_TYPE_STRING, &err_msg,
+ DBUS_TYPE_INVALID);
+ if (!dbret) return EIO;
- DEBUG(4, ("Request processed. Returned %d,%d,%s\n",
- err_maj, err_min, err_msg));
+ DEBUG(4, ("Request processed. Returned %d,%d,%s\n",
+ err_maj, err_min, err_msg));
- /* send reply back */
- sbus_conn_send_reply(conn, reply);
- dbus_message_unref(reply);
+ /* send reply back */
+ sbus_conn_send_reply(conn, reply);
+ dbus_message_unref(reply);
+ }
return EOK;
}
diff --git a/server/responder/common/responder.h b/server/responder/common/responder.h
index a597e68e..9294f402 100644
--- a/server/responder/common/responder.h
+++ b/server/responder/common/responder.h
@@ -145,7 +145,8 @@ typedef void (*sss_dp_callback_t)(uint16_t err_maj, uint32_t err_min,
int sss_dp_send_acct_req(struct resp_ctx *rctx, TALLOC_CTX *callback_memctx,
sss_dp_callback_t callback, void *callback_ctx,
- int timeout, const char *domain, int type,
+ int timeout, const char *domain,
+ bool fast_reply, int type,
const char *opt_name, uint32_t opt_id);
#endif /* __SSS_RESPONDER_H__ */
diff --git a/server/responder/common/responder_dp.c b/server/responder/common/responder_dp.c
index 943b72c5..03e83ec6 100644
--- a/server/responder/common/responder_dp.c
+++ b/server/responder/common/responder_dp.c
@@ -243,7 +243,8 @@ static int sss_dp_send_acct_req_create(struct resp_ctx *rctx,
int sss_dp_send_acct_req(struct resp_ctx *rctx, TALLOC_CTX *callback_memctx,
sss_dp_callback_t callback, void *callback_ctx,
- int timeout, const char *domain, int type,
+ int timeout, const char *domain,
+ bool fast_reply, int type,
const char *opt_name, uint32_t opt_id)
{
int ret, hret;
@@ -279,6 +280,10 @@ int sss_dp_send_acct_req(struct resp_ctx *rctx, TALLOC_CTX *callback_memctx,
return EINVAL;
}
+ if (fast_reply) {
+ be_type |= BE_REQ_FAST;
+ }
+
if (dp_requests == NULL) {
/* Create a hash table to handle queued update requests */
ret = hash_create(10, &dp_requests, NULL);
diff --git a/server/responder/nss/nsssrv_cmd.c b/server/responder/nss/nsssrv_cmd.c
index 4473e6c8..97178978 100644
--- a/server/responder/nss/nsssrv_cmd.c
+++ b/server/responder/nss/nsssrv_cmd.c
@@ -351,7 +351,8 @@ static errno_t check_cache(struct nss_dom_ctx *dctx,
*/
ret = sss_dp_send_acct_req(cctx->rctx, NULL, NULL, NULL,
timeout, dctx->domain->name,
- req_type, opt_name, opt_id);
+ true, req_type,
+ opt_name, opt_id);
if (ret != EOK) {
DEBUG(3, ("Failed to dispatch request: %d(%s)\n",
ret, strerror(ret)));
@@ -376,7 +377,8 @@ static errno_t check_cache(struct nss_dom_ctx *dctx,
ret = sss_dp_send_acct_req(cctx->rctx, cmdctx,
callback, dctx, timeout,
- dctx->domain->name, req_type,
+ dctx->domain->name,
+ true, req_type,
opt_name, opt_id);
if (ret != EOK) {
DEBUG(3, ("Failed to dispatch request: %d(%s)\n",
@@ -1125,8 +1127,8 @@ static void nss_cmd_setpwent_callback(void *ptr, int status,
timeout = SSS_CLI_SOCKET_TIMEOUT;
ret = sss_dp_send_acct_req(cctx->rctx, cmdctx,
nss_cmd_setpw_dp_callback, dctx,
- timeout, dom->name, SSS_DP_USER,
- NULL, 0);
+ timeout, dom->name, true,
+ SSS_DP_USER, NULL, 0);
} else {
ret = sysdb_get_ctx_from_list(cctx->rctx->db_list,
dctx->domain, &sysdb);
@@ -1272,8 +1274,8 @@ static int nss_cmd_setpwent_ext(struct cli_ctx *cctx, bool immediate)
timeout = SSS_CLI_SOCKET_TIMEOUT;
ret = sss_dp_send_acct_req(cctx->rctx, cmdctx,
nss_cmd_setpw_dp_callback, dctx,
- timeout, dom->name, SSS_DP_USER,
- NULL, 0);
+ timeout, dom->name, true,
+ SSS_DP_USER, NULL, 0);
} else {
ret = sysdb_get_ctx_from_list(cctx->rctx->db_list,
dctx->domain, &sysdb);
@@ -2448,8 +2450,8 @@ static void nss_cmd_setgrent_callback(void *ptr, int status,
timeout = SSS_CLI_SOCKET_TIMEOUT;
ret = sss_dp_send_acct_req(cctx->rctx, cmdctx,
nss_cmd_setgr_dp_callback, dctx,
- timeout, dom->name, SSS_DP_GROUP,
- NULL, 0);
+ timeout, dom->name, true,
+ SSS_DP_GROUP, NULL, 0);
} else {
ret = sysdb_get_ctx_from_list(cctx->rctx->db_list,
dctx->domain, &sysdb);
@@ -2595,8 +2597,8 @@ static int nss_cmd_setgrent_ext(struct cli_ctx *cctx, bool immediate)
timeout = SSS_CLI_SOCKET_TIMEOUT;
ret = sss_dp_send_acct_req(cctx->rctx, cmdctx,
nss_cmd_setgr_dp_callback, dctx,
- timeout, dom->name, SSS_DP_GROUP,
- NULL, 0);
+ timeout, dom->name, true,
+ SSS_DP_GROUP, NULL, 0);
} else {
ret = sysdb_get_ctx_from_list(cctx->rctx->db_list,
dctx->domain, &sysdb);
diff --git a/server/responder/pam/pamsrv_cmd.c b/server/responder/pam/pamsrv_cmd.c
index 8627d5cb..44799266 100644
--- a/server/responder/pam/pamsrv_cmd.c
+++ b/server/responder/pam/pamsrv_cmd.c
@@ -725,7 +725,8 @@ static int pam_forwarder(struct cli_ctx *cctx, int pam_cmd)
ret = sss_dp_send_acct_req(preq->cctx->rctx, preq,
pam_check_user_dp_callback, preq,
- timeout, preq->domain->name, SSS_DP_INITGROUPS,
+ timeout, preq->domain->name,
+ false, SSS_DP_INITGROUPS,
preq->pd->user, 0);
}
else {
@@ -840,7 +841,8 @@ static void pam_check_user_callback(void *ptr, int status,
ret = sss_dp_send_acct_req(preq->cctx->rctx, preq,
pam_check_user_dp_callback, preq,
- timeout, preq->domain->name, SSS_DP_USER,
+ timeout, preq->domain->name,
+ false, SSS_DP_USER,
preq->pd->user, 0);
if (ret != EOK) {
DEBUG(3, ("Failed to dispatch request: %d(%s)\n",
@@ -910,7 +912,7 @@ static void pam_check_user_callback(void *ptr, int status,
pam_check_user_dp_callback,
preq, timeout,
preq->domain->name,
- SSS_DP_USER,
+ false, SSS_DP_USER,
preq->pd->user, 0);
}
else {