summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2012-01-31 22:59:58 +0100
committerStephen Gallagher <sgallagh@redhat.com>2012-01-31 20:30:25 -0500
commitab68008f87504ace9451c14ba2a7e8dfec435779 (patch)
treeca43219fe43d1d68d0a543311d596c46c9654b96
parent25a9a1768d2e3587cc68b76a0a5df1e42a2c89ab (diff)
downloadsssd-ab68008f87504ace9451c14ba2a7e8dfec435779.tar.gz
sssd-ab68008f87504ace9451c14ba2a7e8dfec435779.tar.xz
sssd-ab68008f87504ace9451c14ba2a7e8dfec435779.zip
Refactor nss_cmd_send_empty
-rw-r--r--src/responder/common/responder.h2
-rw-r--r--src/responder/common/responder_cmd.c37
-rw-r--r--src/responder/nss/nsssrv_cmd.c37
-rw-r--r--src/responder/nss/nsssrv_netgroup.c4
-rw-r--r--src/responder/nss/nsssrv_private.h3
-rw-r--r--src/responder/nss/nsssrv_services.c4
6 files changed, 46 insertions, 41 deletions
diff --git a/src/responder/common/responder.h b/src/responder/common/responder.h
index b8d7f8ab7..c60eeab23 100644
--- a/src/responder/common/responder.h
+++ b/src/responder/common/responder.h
@@ -155,6 +155,8 @@ struct sss_domain_info *
responder_get_domain(struct sss_domain_info *doms, const char *domain);
/* responder_cmd.c */
+int sss_cmd_empty_packet(struct sss_packet *packet);
+int sss_cmd_send_empty(struct cli_ctx *cctx, TALLOC_CTX *freectx);
int sss_cmd_execute(struct cli_ctx *cctx, struct sss_cmd_table *sss_cmds);
void sss_cmd_done(struct cli_ctx *cctx, void *freectx);
int sss_cmd_get_version(struct cli_ctx *cctx);
diff --git a/src/responder/common/responder_cmd.c b/src/responder/common/responder_cmd.c
index cd9890305..bf0bb82ba 100644
--- a/src/responder/common/responder_cmd.c
+++ b/src/responder/common/responder_cmd.c
@@ -23,6 +23,43 @@
#include "responder/common/responder.h"
#include "responder/common/responder_packet.h"
+int sss_cmd_empty_packet(struct sss_packet *packet)
+{
+ uint8_t *body;
+ size_t blen;
+ int ret;
+
+ ret = sss_packet_grow(packet, 2*sizeof(uint32_t));
+ if (ret != EOK) return ret;
+
+ sss_packet_get_body(packet, &body, &blen);
+ ((uint32_t *)body)[0] = 0; /* num results */
+ ((uint32_t *)body)[1] = 0; /* reserved */
+
+ return EOK;
+}
+
+int sss_cmd_send_empty(struct cli_ctx *cctx, TALLOC_CTX *freectx)
+{
+ int ret;
+
+ /* create response packet */
+ ret = sss_packet_new(cctx->creq, 0,
+ sss_packet_get_cmd(cctx->creq->in),
+ &cctx->creq->out);
+ if (ret != EOK) {
+ return ret;
+ }
+
+ ret = sss_cmd_empty_packet(cctx->creq->out);
+ if (ret != EOK) {
+ return ret;
+ }
+
+ sss_packet_set_error(cctx->creq->out, EOK);
+ sss_cmd_done(cctx, freectx);
+ return EOK;
+}
void sss_cmd_done(struct cli_ctx *cctx, void *freectx)
{
diff --git a/src/responder/nss/nsssrv_cmd.c b/src/responder/nss/nsssrv_cmd.c
index 579c76026..bbb115c8c 100644
--- a/src/responder/nss/nsssrv_cmd.c
+++ b/src/responder/nss/nsssrv_cmd.c
@@ -46,41 +46,10 @@ static int nss_cmd_send_error(struct nss_cmd_ctx *cmdctx, int err)
return EOK;
}
-int fill_empty(struct sss_packet *packet)
-{
- uint8_t *body;
- size_t blen;
- int ret;
-
- ret = sss_packet_grow(packet, 2*sizeof(uint32_t));
- if (ret != EOK) return ret;
-
- sss_packet_get_body(packet, &body, &blen);
- ((uint32_t *)body)[0] = 0; /* num results */
- ((uint32_t *)body)[1] = 0; /* reserved */
-
- return EOK;
-}
-
static int nss_cmd_send_empty(struct nss_cmd_ctx *cmdctx)
{
struct cli_ctx *cctx = cmdctx->cctx;
- int ret;
-
- /* create response packet */
- ret = sss_packet_new(cctx->creq, 0,
- sss_packet_get_cmd(cctx->creq->in),
- &cctx->creq->out);
- if (ret != EOK) {
- return ret;
- }
- ret = fill_empty(cctx->creq->out);
- if (ret != EOK) {
- return ret;
- }
- sss_packet_set_error(cctx->creq->out, EOK);
- sss_cmd_done(cctx, cmdctx);
- return EOK;
+ return sss_cmd_send_empty(cctx, cmdctx);
}
int nss_cmd_done(struct nss_cmd_ctx *cmdctx, int ret)
@@ -1674,7 +1643,7 @@ static int nss_cmd_retpwent(struct cli_ctx *cctx, int num)
none:
if (ret == ENOENT) {
- ret = fill_empty(cctx->creq->out);
+ ret = sss_cmd_empty_packet(cctx->creq->out);
}
return ret;
}
@@ -2913,7 +2882,7 @@ static int nss_cmd_retgrent(struct cli_ctx *cctx, int num)
none:
if (ret == ENOENT) {
- ret = fill_empty(cctx->creq->out);
+ ret = sss_cmd_empty_packet(cctx->creq->out);
}
return ret;
}
diff --git a/src/responder/nss/nsssrv_netgroup.c b/src/responder/nss/nsssrv_netgroup.c
index bb047d6a3..093329fa3 100644
--- a/src/responder/nss/nsssrv_netgroup.c
+++ b/src/responder/nss/nsssrv_netgroup.c
@@ -618,7 +618,7 @@ static void nss_cmd_setnetgrent_done(struct tevent_req *req)
if (ret == EOK) {
if (reqret == ENOENT) {
/* Notify the caller that this entry wasn't found */
- fill_empty(cmdctx->cctx->creq->out);
+ sss_cmd_empty_packet(cmdctx->cctx->creq->out);
} else {
packet = cmdctx->cctx->creq->out;
ret = sss_packet_grow(packet, 2*sizeof(uint32_t));
@@ -803,7 +803,7 @@ static errno_t nss_cmd_getnetgrent_process(struct nss_cmd_ctx *cmdctx,
if (!netgr->entries || netgr->entries[0] == NULL) {
/* No entries */
DEBUG(5, ("No entries found\n"));
- ret = fill_empty(client->creq->out);
+ ret = sss_cmd_empty_packet(client->creq->out);
if (ret != EOK) {
return nss_cmd_done(cmdctx, ret);
}
diff --git a/src/responder/nss/nsssrv_private.h b/src/responder/nss/nsssrv_private.h
index 83936fac7..876552fb9 100644
--- a/src/responder/nss/nsssrv_private.h
+++ b/src/responder/nss/nsssrv_private.h
@@ -109,9 +109,6 @@ struct setent_step_ctx {
/* Finish the request */
int nss_cmd_done(struct nss_cmd_ctx *cmdctx, int ret);
-/* Respond with no entries */
-int fill_empty(struct sss_packet *packet);
-
int setent_remove_ref(TALLOC_CTX *ctx);
errno_t setent_add_ref(TALLOC_CTX *memctx,
struct getent_ctx *getent_ctx,
diff --git a/src/responder/nss/nsssrv_services.c b/src/responder/nss/nsssrv_services.c
index 9013c682d..da37708b4 100644
--- a/src/responder/nss/nsssrv_services.c
+++ b/src/responder/nss/nsssrv_services.c
@@ -994,7 +994,7 @@ nss_cmd_getserv_done(struct tevent_req *req)
if (ret == EOK) {
if (reqret == ENOENT) {
/* Notify the caller that this entry wasn't found */
- ret = fill_empty(cmdctx->cctx->creq->out);
+ ret = sss_cmd_empty_packet(cmdctx->cctx->creq->out);
} else {
i = dctx->res->count;
ret = fill_service(cmdctx->cctx->creq->out,
@@ -1793,7 +1793,7 @@ retservent(struct cli_ctx *cctx, int num)
none:
if (ret == ENOENT) {
- ret = fill_empty(cctx->creq->out);
+ ret = sss_cmd_empty_packet(cctx->creq->out);
}
return ret;
}