>From 8bbe0f8af2a1d01780ac3a9f4f8f935247dafcf2 Mon Sep 17 00:00:00 2001
From: Michal Zidek <mzidek@redhat.com>
Date: Mon, 4 Mar 2013 13:12:58 +0100
Subject: [PATCH] Use the same dbg level for all ncache hits.

We used different debug levels for messages informing
about negative cache hits (old levels 2,3,4). Now it is
only SSSDBG_TRACE_FUNC (same level is used in nsssrv_services.c
and proposed in the ticket bellow).

https://fedorahosted.org/sssd/ticket/1771
---
 src/responder/nss/nsssrv_cmd.c | 59 +++++++++++++++++++++++++++++-------------
 src/responder/pam/pamsrv_cmd.c |  6 ++---
 2 files changed, 44 insertions(+), 21 deletions(-)

diff --git a/src/responder/nss/nsssrv_cmd.c b/src/responder/nss/nsssrv_cmd.c
index 7f31a2b..74f530a 100644
--- a/src/responder/nss/nsssrv_cmd.c
+++ b/src/responder/nss/nsssrv_cmd.c
@@ -335,8 +335,9 @@ static int fill_pwent(struct sss_packet *packet,
                                         nctx->neg_timeout,
                                         dom, orig_name);
             if (ncret == EEXIST) {
-                DEBUG(4, ("User [%s@%s] filtered out! (negative cache)\n",
-                          orig_name, domain));
+                DEBUG(SSSDBG_TRACE_FUNC,
+                      ("User [%s@%s] filtered out! (negative cache)\n",
+                       orig_name, domain));
                 continue;
             }
         }
@@ -739,8 +740,9 @@ static int nss_cmd_getpwnam_search(struct nss_dom_ctx *dctx)
 
         /* if neg cached, return we didn't find it */
         if (ret == EEXIST) {
-            DEBUG(2, ("User [%s] does not exist in [%s]! (negative cache)\n",
-                      name, dom->name));
+            DEBUG(SSSDBG_TRACE_FUNC,
+                  ("User [%s] does not exist in [%s]! (negative cache)\n",
+                   name, dom->name));
             /* if a multidomain search, try with next */
             if (cmdctx->check_next) {
                 dom = get_next_domain(dom, false);
@@ -1209,8 +1211,9 @@ static int nss_cmd_getpwuid(struct cli_ctx *cctx)
 
     ret = sss_ncache_check_uid(nctx->ncache, nctx->neg_timeout, cmdctx->id);
     if (ret == EEXIST) {
-        DEBUG(3, ("Uid [%lu] does not exist! (negative cache)\n",
-                  (unsigned long)cmdctx->id));
+        DEBUG(SSSDBG_TRACE_FUNC,
+              ("Uid [%lu] does not exist! (negative cache)\n",
+               (unsigned long)cmdctx->id));
         ret = ENOENT;
         goto done;
     }
@@ -1933,10 +1936,10 @@ static int fill_members(struct sss_packet *packet,
                                         nctx->neg_timeout,
                                         dom, tmpstr);
             if (ret == EEXIST) {
-                DEBUG(SSSDBG_TRACE_FUNC, ("Group [%s] member [%s@%s] filtered out!"
-                                          " (negative cache)\n",
-                                          (char *)&body[rzero+STRS_ROFFSET],
-                                          tmpstr, domain));
+                DEBUG(SSSDBG_TRACE_FUNC,
+                      ("Group [%s] member [%s@%s] filtered out!"
+                       " (negative cache)\n",
+                       (char *)&body[rzero+STRS_ROFFSET], tmpstr, domain));
                 continue;
             }
         }
@@ -2090,8 +2093,9 @@ static int fill_grent(struct sss_packet *packet,
             ret = sss_ncache_check_group(nctx->ncache,
                                          nctx->neg_timeout, dom, orig_name);
             if (ret == EEXIST) {
-                DEBUG(4, ("Group [%s@%s] filtered out! (negative cache)\n",
-                          orig_name, domain));
+                DEBUG(SSSDBG_TRACE_FUNC,
+                      ("Group [%s@%s] filtered out! (negative cache)\n",
+                       orig_name, domain));
                 continue;
             }
         }
@@ -2314,8 +2318,9 @@ static int nss_cmd_getgrnam_search(struct nss_dom_ctx *dctx)
 
         /* if neg cached, return we didn't find it */
         if (ret == EEXIST) {
-            DEBUG(2, ("Group [%s] does not exist in [%s]! (negative cache)\n",
-                    name, dom->name));
+            DEBUG(SSSDBG_TRACE_FUNC,
+                  ("Group [%s] does not exist in [%s]! (negative cache)\n",
+                   name, dom->name));
             /* if a multidomain search, try with next */
             if (cmdctx->check_next) {
                 dom = get_next_domain(dom, false);
@@ -2784,8 +2789,9 @@ static int nss_cmd_getgrgid(struct cli_ctx *cctx)
 
     ret = sss_ncache_check_gid(nctx->ncache, nctx->neg_timeout, cmdctx->id);
     if (ret == EEXIST) {
-        DEBUG(3, ("Gid [%lu] does not exist! (negative cache)\n",
-                  (unsigned long)cmdctx->id));
+        DEBUG(SSSDBG_TRACE_FUNC,
+              ("Gid [%lu] does not exist! (negative cache)\n",
+               (unsigned long)cmdctx->id));
         ret = ENOENT;
         goto done;
     }
@@ -3599,8 +3605,9 @@ static int nss_cmd_initgroups_search(struct nss_dom_ctx *dctx)
 
         /* if neg cached, return we didn't find it */
         if (ret == EEXIST) {
-            DEBUG(2, ("User [%s] does not exist in [%s]! (negative cache)\n",
-                      name, dom->name));
+            DEBUG(SSSDBG_TRACE_FUNC,
+                  ("User [%s] does not exist in [%s]! (negative cache)\n",
+                   name, dom->name));
             /* if a multidomain search, try with next */
             if (cmdctx->check_next) {
                 dom = get_next_domain(dom, false);
@@ -3904,3 +3911,19 @@ static struct sss_cmd_table nss_cmds[] = {
 struct sss_cmd_table *get_nss_cmds(void) {
     return nss_cmds;
 }
+
+int nss_cmd_execute(struct cli_ctx *cctx)
+{
+    enum sss_cli_command cmd;
+    int i;
+
+    cmd = sss_packet_get_cmd(cctx->creq->in);
+
+    for (i = 0; nss_cmds[i].cmd != SSS_CLI_NULL; i++) {
+        if (cmd == nss_cmds[i].cmd) {
+            return nss_cmds[i].fn(cctx);
+        }
+    }
+
+    return EINVAL;
+}
diff --git a/src/responder/pam/pamsrv_cmd.c b/src/responder/pam/pamsrv_cmd.c
index 9d38c03..69791a0 100644
--- a/src/responder/pam/pamsrv_cmd.c
+++ b/src/responder/pam/pamsrv_cmd.c
@@ -1115,9 +1115,9 @@ static int pam_forwarder(struct cli_ctx *cctx, int pam_cmd)
             }
 
             /* Try the next domain */
-            DEBUG(4, ("User [%s@%s] filtered out (negative cache). "
-                      "Trying next domain.\n",
-                      pd->user, dom->name));
+            DEBUG(SSSDBG_TRACE_FUNC,
+                  ("User [%s@%s] filtered out (negative cache). "
+                   "Trying next domain.\n", pd->user, dom->name));
         }
         if (!dom) {
             ret = ENOENT;
-- 
1.7.11.2

