>From bb50f8cc4c50a68c0046e768b721e24d37752813 Mon Sep 17 00:00:00 2001
From: Petr Cech <pcech@redhat.com>
Date: Tue, 18 Aug 2015 06:59:31 -0400
Subject: [PATCH] DATA_PROVIDER: BE_REQ as string in log message

Add be_req2str() for translation BE_REQ to string.
So we will have
|| Got request for [0x1001][FAST BE_REQ_USER][1][name=celestian]
instead of
|| Got request for [0x1001][1][name=celestian]

Function be_req2str() is used in data provider and in responder too.
So this patch create new header file data_provider_req.h which
delivers function be_req2str() and definitions of BE_REQ_*.

Resolves:
https://fedorahosted.org/sssd/ticket/2708
---
 Makefile.am                         |  5 +++-
 src/providers/data_provider.h       | 17 +----------
 src/providers/data_provider_be.c    |  3 +-
 src/providers/data_provider_req.c   | 58 +++++++++++++++++++++++++++++++++++++
 src/providers/data_provider_req.h   | 51 ++++++++++++++++++++++++++++++++
 src/responder/common/responder_dp.c |  4 +--
 6 files changed, 118 insertions(+), 20 deletions(-)
 create mode 100644 src/providers/data_provider_req.c
 create mode 100644 src/providers/data_provider_req.h

diff --git a/Makefile.am b/Makefile.am
index 851f943a4c57b70cee4f4f34e83457e7d204aff1..dc0670a5c720ab58a47e7da356578256b4659695 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -449,7 +449,8 @@ SSSD_RESPONDER_OBJ = \
     src/monitor/monitor_iface_generated.c \
     src/monitor/monitor_iface_generated.h \
     src/providers/data_provider_iface_generated.c \
-    src/providers/data_provider_iface_generated.h
+    src/providers/data_provider_iface_generated.h \
+    src/providers/data_provider_req.c
 
 SSSD_TOOLS_OBJ = \
     src/tools/sss_sync_ops.c \
@@ -587,6 +588,7 @@ dist_noinst_HEADERS = \
     src/confdb/confdb_private.h \
     src/confdb/confdb_setup.h \
     src/providers/data_provider.h \
+    src/providers/data_provider_req.h \
     src/providers/dp_backend.h \
     src/providers/dp_dyndns.h \
     src/providers/dp_ptask_private.h \
@@ -1201,6 +1203,7 @@ endif
 
 sssd_be_SOURCES = \
     src/providers/data_provider_be.c \
+    src/providers/data_provider_req.c \
     src/providers/data_provider_fo.c \
     src/providers/data_provider_opts.c \
     src/providers/data_provider_callbacks.c \
diff --git a/src/providers/data_provider.h b/src/providers/data_provider.h
index 510c63ce41c99314ec8fcf11fffb2e66082e8951..39051b90c3aad96f62dcbb86a20bcfd8c954879b 100644
--- a/src/providers/data_provider.h
+++ b/src/providers/data_provider.h
@@ -43,6 +43,7 @@
 #include "sbus/sbus_client.h"
 #include "sss_client/sss_cli.h"
 #include "util/authtok.h"
+#include "providers/data_provider_req.h"
 #include "providers/data_provider_iface_generated.h"
 
 #define DATA_PROVIDER_VERSION 0x0001
@@ -131,22 +132,6 @@
 #define BE_FILTER_CERT 6
 #define BE_FILTER_WILDCARD 7
 
-#define BE_REQ_USER          0x0001
-#define BE_REQ_GROUP         0x0002
-#define BE_REQ_INITGROUPS    0x0003
-#define BE_REQ_NETGROUP      0x0004
-#define BE_REQ_SERVICES      0x0005
-#define BE_REQ_SUDO_FULL     0x0006
-#define BE_REQ_SUDO_RULES    0x0007
-#define BE_REQ_AUTOFS        0x0009
-#define BE_REQ_HOST          0x0010
-#define BE_REQ_BY_SECID      0x0011
-#define BE_REQ_USER_AND_GROUP 0x0012
-#define BE_REQ_BY_UUID       0x0013
-#define BE_REQ_BY_CERT       0x0014
-#define BE_REQ_TYPE_MASK     0x00FF
-#define BE_REQ_FAST          0x1000
-
 #define DP_SEC_ID "secid"
 #define DP_CERT "cert"
 /* sizeof() counts the trailing \0 so we must substract 1 for the string
diff --git a/src/providers/data_provider_be.c b/src/providers/data_provider_be.c
index d147630248f0a24f5a632760b55b9284a6928e40..d71a69cb8e2997975828236998ec0b0e3f353f07 100644
--- a/src/providers/data_provider_be.c
+++ b/src/providers/data_provider_be.c
@@ -1104,7 +1104,8 @@ static int be_get_account_info(struct sbus_request *dbus_req, void *user_data)
         return EOK; /* handled */
 
     DEBUG(SSSDBG_FUNC_DATA,
-          "Got request for [%#x][%d][%s]\n", type, attr_type, filter);
+          "Got request for [%#x][%s][%d][%s]\n", type, be_req2str(type),
+          attr_type, filter);
 
     /* If we are offline and fast reply was requested
      * return offline immediately
diff --git a/src/providers/data_provider_req.c b/src/providers/data_provider_req.c
new file mode 100644
index 0000000000000000000000000000000000000000..94aacb676f3b5beebe3a809efa83972e9563af49
--- /dev/null
+++ b/src/providers/data_provider_req.c
@@ -0,0 +1,58 @@
+/*
+    SSSD
+
+    Data Provider -- backend request
+
+    Copyright (C) Petr Cech <pcech@redhat.com> 2015
+
+    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/>.
+*/
+
+#include "providers/data_provider_req.h"
+
+#define be_req_to_str(req_type, be_req_t) \
+        ((req_type) & BE_REQ_FAST) ? "FAST " #be_req_t : #be_req_t
+
+const char *be_req2str(dbus_uint32_t req_type)
+{
+    switch (req_type & BE_REQ_TYPE_MASK) {
+    case BE_REQ_USER:
+        return be_req_to_str(req_type, BE_REQ_USER);
+    case BE_REQ_GROUP:
+        return be_req_to_str(req_type, BE_REQ_GROUP);
+    case BE_REQ_INITGROUPS:
+        return be_req_to_str(req_type, BE_REQ_INITGROUPS);
+    case BE_REQ_NETGROUP:
+        return be_req_to_str(req_type, BE_REQ_NETGROUP);
+    case BE_REQ_SERVICES:
+        return be_req_to_str(req_type, BE_REQ_SERVICES);
+    case BE_REQ_SUDO_FULL:
+        return be_req_to_str(req_type, BE_REQ_SUDO_FULL);
+    case BE_REQ_SUDO_RULES:
+        return be_req_to_str(req_type, BE_REQ_SUDO_RULES);
+    case BE_REQ_AUTOFS:
+        return be_req_to_str(req_type, BE_REQ_AUTOFS);
+    case BE_REQ_HOST:
+        return be_req_to_str(req_type, BE_REQ_HOST);
+    case BE_REQ_BY_SECID:
+        return be_req_to_str(req_type, BE_REQ_BY_SECID);
+    case BE_REQ_USER_AND_GROUP:
+        return be_req_to_str(req_type, BE_REQ_USER_AND_GROUP);
+    case BE_REQ_BY_UUID:
+        return be_req_to_str(req_type, BE_REQ_BY_UUID);
+    case BE_REQ_BY_CERT:
+        return be_req_to_str(req_type, BE_REQ_BY_CERT);
+    }
+    return "UNKNOWN_REQ";
+}
diff --git a/src/providers/data_provider_req.h b/src/providers/data_provider_req.h
new file mode 100644
index 0000000000000000000000000000000000000000..338f8192f80f732b89c5dc3dd3b79fb5a6edb8c7
--- /dev/null
+++ b/src/providers/data_provider_req.h
@@ -0,0 +1,51 @@
+/*
+    SSSD
+
+    Data Provider -- backend request
+
+    Copyright (C) Petr Cech <pcech@redhat.com> 2015
+
+    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 __DATA_PROVIDER_REQ__
+#define __DATA_PROVIDER_REQ__
+
+#include <dbus/dbus.h>
+
+#define BE_REQ_USER           0x0001
+#define BE_REQ_GROUP          0x0002
+#define BE_REQ_INITGROUPS     0x0003
+#define BE_REQ_NETGROUP       0x0004
+#define BE_REQ_SERVICES       0x0005
+#define BE_REQ_SUDO_FULL      0x0006
+#define BE_REQ_SUDO_RULES     0x0007
+#define BE_REQ_AUTOFS         0x0009
+#define BE_REQ_HOST           0x0010
+#define BE_REQ_BY_SECID       0x0011
+#define BE_REQ_USER_AND_GROUP 0x0012
+#define BE_REQ_BY_UUID        0x0013
+#define BE_REQ_BY_CERT        0x0014
+#define BE_REQ_TYPE_MASK      0x00FF
+#define BE_REQ_FAST           0x1000
+
+/**
+ * @brief Convert request type to string for logging purpose.
+ *
+ * @param[in] req_type Type of request.
+ * @return Pointer to string with request type. There could be 'fast' flag.
+ */
+const char *be_req2str(dbus_uint32_t req_type);
+
+#endif /* __DATA_PROVIDER_REQ__ */
diff --git a/src/responder/common/responder_dp.c b/src/responder/common/responder_dp.c
index f7f8df04e80439d2d02df3e4d2aa4f3576997f36..d1c1609ca1700dab50b0db8958fda7923f1a22d1 100644
--- a/src/responder/common/responder_dp.c
+++ b/src/responder/common/responder_dp.c
@@ -620,8 +620,8 @@ sss_dp_get_account_msg(void *pvt)
 
     /* create the message */
     DEBUG(SSSDBG_TRACE_FUNC,
-          "Creating request for [%s][%u][%d][%s]\n",
-           info->dom->name, be_type, attrs, filter);
+          "Creating request for [%s][%#x][%s][%d][%s]\n",
+           info->dom->name, be_type, be_req2str(be_type), attrs, filter);
 
     dbret = dbus_message_append_args(msg,
                                      DBUS_TYPE_UINT32, &be_type,
-- 
2.4.3

