From 405a06682b3772b70bb06d3adba780a062959641 Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Thu, 2 Feb 2012 08:44:08 +0100 Subject: RESPONDERS: Provide a common sss_cmd_send_error function The common function could be reused in new responders --- src/responder/common/responder.h | 1 + src/responder/common/responder_cmd.c | 17 +++++++++++++++++ src/responder/nss/nsssrv_cmd.c | 14 +------------- 3 files changed, 19 insertions(+), 13 deletions(-) (limited to 'src/responder') diff --git a/src/responder/common/responder.h b/src/responder/common/responder.h index c60eeab2..1c85b9d2 100644 --- a/src/responder/common/responder.h +++ b/src/responder/common/responder.h @@ -157,6 +157,7 @@ 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_send_error(struct cli_ctx *cctx, int err); 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 bf0bb82b..bfac8f97 100644 --- a/src/responder/common/responder_cmd.c +++ b/src/responder/common/responder_cmd.c @@ -23,6 +23,23 @@ #include "responder/common/responder.h" #include "responder/common/responder_packet.h" +int sss_cmd_send_error(struct cli_ctx *cctx, int err) +{ + 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) { + DEBUG(SSSDBG_CRIT_FAILURE, ("Cannot create new packet: %d\n", ret)); + return ret; + } + + sss_packet_set_error(cctx->creq->out, err); + return EOK; +} + int sss_cmd_empty_packet(struct sss_packet *packet) { uint8_t *body; diff --git a/src/responder/nss/nsssrv_cmd.c b/src/responder/nss/nsssrv_cmd.c index bbb115c8..1dff829e 100644 --- a/src/responder/nss/nsssrv_cmd.c +++ b/src/responder/nss/nsssrv_cmd.c @@ -31,19 +31,7 @@ static int nss_cmd_send_error(struct nss_cmd_ctx *cmdctx, int err) { - 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; - } - - sss_packet_set_error(cctx->creq->out, err); - return EOK; + return sss_cmd_send_error(cmdctx->cctx, err); } static int nss_cmd_send_empty(struct nss_cmd_ctx *cmdctx) -- cgit