From 88a9c6a44b474bff0f7e22f9eb28a9e55df2c0b5 Mon Sep 17 00:00:00 2001
From: Stephen Gallagher <sgallagh@redhat.com>
Date: Wed, 22 Sep 2010 16:44:54 -0400
Subject: Split out some helper functions for the NSS responder

Create a new private header and make some functions available for
other object files.
---
 src/responder/nss/nsssrv_cmd.c     | 100 +++++-----------------------
 src/responder/nss/nsssrv_private.h | 130 +++++++++++++++++++++++++++++++++++++
 2 files changed, 147 insertions(+), 83 deletions(-)
 create mode 100644 src/responder/nss/nsssrv_private.h

diff --git a/src/responder/nss/nsssrv_cmd.c b/src/responder/nss/nsssrv_cmd.c
index c789a595..6e1dc7bb 100644
--- a/src/responder/nss/nsssrv_cmd.c
+++ b/src/responder/nss/nsssrv_cmd.c
@@ -21,46 +21,12 @@
 
 #include "util/util.h"
 #include "responder/nss/nsssrv.h"
+#include "responder/nss/nsssrv_private.h"
 #include "responder/common/negcache.h"
 #include "confdb/confdb.h"
 #include "db/sysdb.h"
 #include <time.h>
 
-struct nss_cmd_ctx {
-    struct cli_ctx *cctx;
-    char *name;
-    uint32_t id;
-
-    bool immediate;
-    bool check_next;
-    bool enum_cached;
-
-    int saved_dom_idx;
-    int saved_cur;
-};
-
-struct dom_ctx {
-    struct sss_domain_info *domain;
-    struct ldb_result *res;
-};
-
-struct getent_ctx {
-    struct dom_ctx *doms;
-    int num;
-    bool ready;
-    struct setent_req_list *reqs;
-};
-
-struct nss_dom_ctx {
-    struct nss_cmd_ctx *cmdctx;
-    struct sss_domain_info *domain;
-
-    bool check_provider;
-
-    /* cache results */
-    struct ldb_result *res;
-};
-
 static int nss_cmd_send_error(struct nss_cmd_ctx *cmdctx, int err)
 {
     struct cli_ctx *cctx = cmdctx->cctx;
@@ -78,20 +44,8 @@ static int nss_cmd_send_error(struct nss_cmd_ctx *cmdctx, int err)
     return EOK;
 }
 
-#define NSS_CMD_FATAL_ERROR(cctx) do { \
-    DEBUG(1,("Fatal error, killing connection!\n")); \
-    talloc_free(cctx); \
-    return; \
-} while(0)
-
-#define NSS_CMD_FATAL_ERROR_CODE(cctx, ret) do { \
-    DEBUG(1,("Fatal error, killing connection!\n")); \
-    talloc_free(cctx); \
-    return ret; \
-} while(0)
-
-static struct sss_domain_info *nss_get_dom(struct sss_domain_info *doms,
-                                           const char *domain)
+struct sss_domain_info *nss_get_dom(struct sss_domain_info *doms,
+                                    const char *domain)
 {
     struct sss_domain_info *dom;
 
@@ -103,7 +57,7 @@ static struct sss_domain_info *nss_get_dom(struct sss_domain_info *doms,
     return dom;
 }
 
-static int fill_empty(struct sss_packet *packet)
+int fill_empty(struct sss_packet *packet)
 {
     uint8_t *body;
     size_t blen;
@@ -140,7 +94,7 @@ static int nss_cmd_send_empty(struct nss_cmd_ctx *cmdctx)
     return EOK;
 }
 
-static int nss_cmd_done(struct nss_cmd_ctx *cmdctx, int ret)
+int nss_cmd_done(struct nss_cmd_ctx *cmdctx, int ret)
 {
     switch (ret) {
     case EOK:
@@ -178,20 +132,9 @@ static int nss_cmd_done(struct nss_cmd_ctx *cmdctx, int ret)
  *  Enumeration procedures *
  ***************************/
 
-struct setent_req_list {
-    struct setent_req_list *prev;
-    struct setent_req_list *next;
-    struct getent_ctx *getent_ctx;
-
-    struct tevent_req *req;
-};
-
-static int
-setent_remove_ref(TALLOC_CTX *ctx);
-static errno_t
-setent_add_ref(TALLOC_CTX *memctx,
-               struct getent_ctx *getent_ctx,
-               struct tevent_req *req)
+errno_t setent_add_ref(TALLOC_CTX *memctx,
+                       struct getent_ctx *getent_ctx,
+                       struct tevent_req *req)
 {
     struct setent_req_list *entry =
             talloc_zero(memctx, struct setent_req_list);
@@ -207,8 +150,7 @@ setent_add_ref(TALLOC_CTX *memctx,
     return EOK;
 }
 
-static int
-setent_remove_ref(TALLOC_CTX *ctx)
+int setent_remove_ref(TALLOC_CTX *ctx)
 {
     struct setent_req_list *entry =
             talloc_get_type(ctx, struct setent_req_list);
@@ -223,14 +165,6 @@ struct setent_ctx {
     struct getent_ctx *getent_ctx;
 };
 
-struct setent_step_ctx {
-    struct nss_ctx *nctx;
-    struct nss_dom_ctx *dctx;
-    struct getent_ctx *getent_ctx;
-    struct resp_ctx *rctx;
-    bool enum_cached;
-};
-
 /****************************************************************************
  * PASSWD db related functions
  ***************************************************************************/
@@ -410,14 +344,14 @@ static int nss_cmd_getpw_send_reply(struct nss_dom_ctx *dctx, bool filter)
 
 /* FIXME: do not check res->count, but get in a msgs and check in parent */
 /* FIXME: do not sss_cmd_done, but return error and let parent do it */
-static errno_t check_cache(struct nss_dom_ctx *dctx,
-                           struct nss_ctx *nctx,
-                           struct ldb_result *res,
-                           int req_type,
-                           const char *opt_name,
-                           uint32_t opt_id,
-                           sss_dp_callback_t callback,
-                           void *pvt)
+errno_t check_cache(struct nss_dom_ctx *dctx,
+                    struct nss_ctx *nctx,
+                    struct ldb_result *res,
+                    int req_type,
+                    const char *opt_name,
+                    uint32_t opt_id,
+                    sss_dp_callback_t callback,
+                    void *pvt)
 {
     errno_t ret;
     int timeout;
diff --git a/src/responder/nss/nsssrv_private.h b/src/responder/nss/nsssrv_private.h
new file mode 100644
index 00000000..15cb6302
--- /dev/null
+++ b/src/responder/nss/nsssrv_private.h
@@ -0,0 +1,130 @@
+/*
+    SSSD
+
+    nsssrv_private.h
+
+    Authors:
+        Stephen Gallagher <sgallagh@redhat.com>
+
+    Copyright (C) 2010 Red Hat
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef NSSSRV_PRIVATE_H_
+#define NSSSRV_PRIVATE_H_
+
+#include "dhash.h"
+
+struct nss_cmd_ctx {
+    struct cli_ctx *cctx;
+    char *name;
+    uint32_t id;
+
+    bool immediate;
+    bool check_next;
+    bool enum_cached;
+
+    int saved_dom_idx;
+    int saved_cur;
+};
+
+struct dom_ctx {
+    struct sss_domain_info *domain;
+    struct ldb_result *res;
+};
+
+struct setent_req_list {
+    struct setent_req_list *prev;
+    struct setent_req_list *next;
+    struct getent_ctx *getent_ctx;
+
+    struct tevent_req *req;
+};
+
+struct getent_ctx {
+    struct dom_ctx *doms;
+    int num;
+    bool ready;
+    struct setent_req_list *reqs;
+
+    /* Netgroup-specific */
+    hash_table_t *lookup_table;
+    struct sysdb_netgroup_ctx **triples;
+    char *name;
+    char *domain;
+};
+
+struct nss_dom_ctx {
+    struct nss_cmd_ctx *cmdctx;
+    struct sss_domain_info *domain;
+
+    bool check_provider;
+
+    /* cache results */
+    struct ldb_result *res;
+
+    /* Netgroup-specific */
+    struct getent_ctx *netgr;
+};
+
+struct setent_step_ctx {
+    struct nss_ctx *nctx;
+    struct nss_dom_ctx *dctx;
+    struct getent_ctx *getent_ctx;
+    struct resp_ctx *rctx;
+    bool enum_cached;
+    bool check_next;
+
+    /* Netgroup-specific */
+    char *name;
+};
+
+#define NSS_CMD_FATAL_ERROR(cctx) do { \
+    DEBUG(1,("Fatal error, killing connection!\n")); \
+    talloc_free(cctx); \
+    return; \
+} while(0)
+
+#define NSS_CMD_FATAL_ERROR_CODE(cctx, ret) do { \
+    DEBUG(1,("Fatal error, killing connection!\n")); \
+    talloc_free(cctx); \
+    return ret; \
+} while(0)
+
+/* Find a particular domain object by name */
+struct sss_domain_info *nss_get_dom(struct sss_domain_info *doms,
+                                    const char *domain);
+
+/* 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,
+                       struct tevent_req *req);
+
+errno_t check_cache(struct nss_dom_ctx *dctx,
+                    struct nss_ctx *nctx,
+                    struct ldb_result *res,
+                    int req_type,
+                    const char *opt_name,
+                    uint32_t opt_id,
+                    sss_dp_callback_t callback,
+                    void *pvt);
+
+#endif /* NSSSRV_PRIVATE_H_ */
-- 
cgit