On 08/05/2015 11:23 AM, Jakub Hrozek wrote:
B)
> >While writing a patch Lukas noticed another similar logging messages
> >>[sssd[pam]] [sss_dp_get_account_msg] (0x0400): Creating request for
> >[LDAP][3][1][name=mof_user6]
> >
> >I investigated it. This is the same thing -- BE_REQ_*, but it is no longer
> >in the provider, but in the responder. Can you please advise me where I
> >could the function 'be_req2str' write?
>I think you should move it to separate file, as you don't want to share more
>code then necessary.
>There are 2 possibilities where to have this file
>a) in src/providers  - responders already link with some modules from this
>folder, so I suppose it's viable
Yes, this is a bit of hierarchy violation, but in the end we need to
share the constants somehow. I think it's fine to keep the definite
version in the providers/dp_* hierarchy, because that's where the
interface is defined, the responder is a consumer.

There is new patch attached.

I think, that constants and const2str() functions should be in one place. I tried to suggest how we might share our constants. That's why I created a new header file in which we could move all the constants in the future.

I am open to discussion. I look forward to your views.

Petr
>From 511224743e8d8e788e9701f0fb3db418ca12b506 Mon Sep 17 00:00:00 2001
From: Petr Cech <pc...@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/ad/ad_id.c                      |  1 +
 src/providers/data_provider.h                 | 16 -------
 src/providers/data_provider_be.c              |  4 +-
 src/providers/data_provider_req.c             | 68 +++++++++++++++++++++++++++
 src/providers/data_provider_req.h             | 51 ++++++++++++++++++++
 src/providers/ipa/ipa_id.c                    |  1 +
 src/providers/ipa/ipa_s2n_exop.c              |  1 +
 src/providers/ipa/ipa_subdomains_ext_groups.c |  1 +
 src/providers/ipa/ipa_subdomains_id.c         |  1 +
 src/providers/ipa/ipa_views.c                 |  1 +
 src/providers/ldap/ldap_id.c                  |  1 +
 src/providers/ldap/sdap_refresh.c             |  1 +
 src/providers/ldap/sdap_sudo.c                |  1 +
 src/providers/proxy/proxy_id.c                |  1 +
 src/providers/simple/simple_access_check.c    |  1 +
 src/responder/autofs/autofssrv_dp.c           |  1 +
 src/responder/common/responder_dp.c           |  5 +-
 src/responder/ssh/sshsrv_dp.c                 |  1 +
 src/responder/sudo/sudosrv_dp.c               |  1 +
 20 files changed, 143 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 ed107fd5dc76b768176a3d7236b0bf1c75f212bf..f71eb862ee935b2c6662678d7c20a12d2e62bf71 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -445,7 +445,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 \
@@ -1191,6 +1192,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 \
@@ -1643,6 +1645,7 @@ simple_access_tests_SOURCES = \
     src/providers/simple/simple_access.c \
     src/providers/simple/simple_access_check.c \
     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/ad/ad_id.c b/src/providers/ad/ad_id.c
index 7a0c6eccd2d2f0d4f8a545a9d4873a9447179a00..c0d8218d46d20f59ef53520dd0c6793ce553773c 100644
--- a/src/providers/ad/ad_id.c
+++ b/src/providers/ad/ad_id.c
@@ -21,6 +21,7 @@
 */
 #include "util/util.h"
 #include "util/strtonum.h"
+#include "providers/data_provider_req.h"
 #include "providers/ad/ad_common.h"
 #include "providers/ad/ad_id.h"
 #include "providers/ad/ad_domain_info.h"
diff --git a/src/providers/data_provider.h b/src/providers/data_provider.h
index 510c63ce41c99314ec8fcf11fffb2e66082e8951..fd4b6d3d7f66756aeb5b4dade3bfbb8953f5ddf1 100644
--- a/src/providers/data_provider.h
+++ b/src/providers/data_provider.h
@@ -131,22 +131,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..60959c50d596c1f32b0f27e947d5c36d5fe9d5f9 100644
--- a/src/providers/data_provider_be.c
+++ b/src/providers/data_provider_be.c
@@ -41,6 +41,7 @@
 #include "db/sysdb.h"
 #include "sbus/sssd_dbus.h"
 #include "providers/dp_backend.h"
+#include "providers/data_provider_req.h"
 #include "providers/fail_over.h"
 #include "providers/dp_refresh.h"
 #include "providers/dp_ptask.h"
@@ -1104,7 +1105,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..2a7e4fed2f19f75bd2504b915e6a8c75a1482614
--- /dev/null
+++ b/src/providers/data_provider_req.c
@@ -0,0 +1,68 @@
+/*
+    SSSD
+
+    Data Provider -- backend request
+
+    Copyright (C) Petr Cech <pc...@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"
+
+const char *be_req2str(dbus_uint32_t req_type)
+{
+    switch (req_type & BE_REQ_TYPE_MASK) {
+    case BE_REQ_USER:
+        return req_type & BE_REQ_FAST ?
+               "FAST BE_REQ_USER" : "BE_REQ_USER";
+    case BE_REQ_GROUP:
+        return req_type & BE_REQ_FAST ?
+               "FAST BE_REQ_GROUP" : "BE_REQ_GROUP";
+    case BE_REQ_INITGROUPS:
+        return req_type & BE_REQ_FAST ?
+               "FAST BE_REQ_INITGROUPS" : "BE_REQ_INITGROUPS";
+    case BE_REQ_NETGROUP:
+        return req_type & BE_REQ_FAST ?
+               "FAST BE_REQ_NETGROUP" : "BE_REQ_NETGROUP";
+    case BE_REQ_SERVICES:
+        return req_type & BE_REQ_FAST ?
+                "FAST BE_REQ_SERVICES" : "BE_REQ_SERVICES";
+    case BE_REQ_SUDO_FULL:
+        return req_type & BE_REQ_FAST ?
+               "FAST BE_REQ_SUDO_FULL" : "BE_REQ_SUDO_FULL";
+    case BE_REQ_SUDO_RULES:
+        return req_type & BE_REQ_FAST ?
+               "FAST BE_REQ_SUDO_RULES" : "BE_REQ_SUDO_RULES";
+    case BE_REQ_AUTOFS:
+        return req_type & BE_REQ_FAST ?
+               "FAST BE_REQ_AUTOFS" : "BE_REQ_AUTOFS";
+    case BE_REQ_HOST:
+        return req_type & BE_REQ_FAST ?
+               "FAST BE_REQ_HOST" : "BE_REQ_HOST";
+    case BE_REQ_BY_SECID:
+        return req_type & BE_REQ_FAST ?
+               "FAST BE_REQ_BY_SECID" : "BE_REQ_BY_SECID";
+    case BE_REQ_USER_AND_GROUP:
+        return req_type & BE_REQ_FAST ?
+               "FAST BE_REQ_USER_AND_GROUP" : "BE_REQ_USER_AND_GROUP";
+    case BE_REQ_BY_UUID:
+        return req_type & BE_REQ_FAST ?
+               "FAST BE_REQ_BY_UUID" : "BE_REQ_BY_UUID";
+    case BE_REQ_BY_CERT:
+        return req_type & BE_REQ_FAST ?
+               "FAST BE_REQ_BY_CERT" : "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 <pc...@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/providers/ipa/ipa_id.c b/src/providers/ipa/ipa_id.c
index e81ccb34dd6eb44618538593f5473fbe5e89d896..af566fd450552649db293348e184115106d6fcbd 100644
--- a/src/providers/ipa/ipa_id.c
+++ b/src/providers/ipa/ipa_id.c
@@ -26,6 +26,7 @@
 
 #include "util/util.h"
 #include "db/sysdb.h"
+#include "providers/data_provider_req.h"
 #include "providers/ldap/ldap_common.h"
 #include "providers/ldap/sdap_async.h"
 #include "providers/ipa/ipa_id.h"
diff --git a/src/providers/ipa/ipa_s2n_exop.c b/src/providers/ipa/ipa_s2n_exop.c
index 1e6368dc7ef1a6f60b541409f7f6740d602f0d43..681fd7b5af687e4ed70b5fd88a30c0ade78a403d 100644
--- a/src/providers/ipa/ipa_s2n_exop.c
+++ b/src/providers/ipa/ipa_s2n_exop.c
@@ -22,6 +22,7 @@
 #include "util/util.h"
 #include "util/sss_nss.h"
 #include "db/sysdb.h"
+#include "providers/data_provider_req.h"
 #include "providers/ldap/sdap_async_private.h"
 #include "providers/ldap/ldap_common.h"
 #include "providers/ipa/ipa_id.h"
diff --git a/src/providers/ipa/ipa_subdomains_ext_groups.c b/src/providers/ipa/ipa_subdomains_ext_groups.c
index d487a58b8adffabe09ff50e31cb750b800b1d252..2f4b978388cda0c51140ba10f263cde46b3400eb 100644
--- a/src/providers/ipa/ipa_subdomains_ext_groups.c
+++ b/src/providers/ipa/ipa_subdomains_ext_groups.c
@@ -25,6 +25,7 @@
 
 #include "util/util.h"
 #include "db/sysdb.h"
+#include "providers/data_provider_req.h"
 #include "providers/ldap/ldap_common.h"
 #include "providers/ldap/sdap_async.h"
 #include "providers/ipa/ipa_id.h"
diff --git a/src/providers/ipa/ipa_subdomains_id.c b/src/providers/ipa/ipa_subdomains_id.c
index ad1743ae5fe7ff80518e7bc58e4df04143732719..0ce131d604e1738791156ec51e978fccbab5d7fa 100644
--- a/src/providers/ipa/ipa_subdomains_id.c
+++ b/src/providers/ipa/ipa_subdomains_id.c
@@ -28,6 +28,7 @@
 #include "util/sss_nss.h"
 #include "util/strtonum.h"
 #include "db/sysdb.h"
+#include "providers/data_provider_req.h"
 #include "providers/ldap/ldap_common.h"
 #include "providers/ldap/sdap_async.h"
 #include "providers/ipa/ipa_id.h"
diff --git a/src/providers/ipa/ipa_views.c b/src/providers/ipa/ipa_views.c
index 331e1180b72767c2a8e0c56e53fb7afeaf4a3390..3e14c82e2344b11c33ad1a354cf889371038f8d2 100644
--- a/src/providers/ipa/ipa_views.c
+++ b/src/providers/ipa/ipa_views.c
@@ -24,6 +24,7 @@
 
 #include "util/util.h"
 #include "util/strtonum.h"
+#include "providers/data_provider_req.h"
 #include "providers/ldap/sdap_async.h"
 #include "providers/ipa/ipa_id.h"
 
diff --git a/src/providers/ldap/ldap_id.c b/src/providers/ldap/ldap_id.c
index 905bbd94d36e52e212d118e728f5fe46fa5bc64a..2d6a3d5fb2a24977c1edcd84e99928c8b0fa24cc 100644
--- a/src/providers/ldap/ldap_id.c
+++ b/src/providers/ldap/ldap_id.c
@@ -30,6 +30,7 @@
 #include "util/strtonum.h"
 #include "util/cert.h"
 #include "db/sysdb.h"
+#include "providers/data_provider_req.h"
 #include "providers/ldap/ldap_common.h"
 #include "providers/ldap/sdap_async.h"
 #include "providers/ldap/sdap_idmap.h"
diff --git a/src/providers/ldap/sdap_refresh.c b/src/providers/ldap/sdap_refresh.c
index bda50aeb3e44510f3afc1a10cb09336a6eec26ec..6c8ca81ed9980458c36fa28541f14399a9dc10eb 100644
--- a/src/providers/ldap/sdap_refresh.c
+++ b/src/providers/ldap/sdap_refresh.c
@@ -21,6 +21,7 @@
 #include <talloc.h>
 #include <tevent.h>
 
+#include "providers/data_provider_req.h"
 #include "providers/ldap/sdap.h"
 #include "providers/ldap/ldap_common.h"
 
diff --git a/src/providers/ldap/sdap_sudo.c b/src/providers/ldap/sdap_sudo.c
index edef44208b69af454da0fc906e608b91d5634e90..edaf4662e98330a49f4719b2b5090959546b6310 100644
--- a/src/providers/ldap/sdap_sudo.c
+++ b/src/providers/ldap/sdap_sudo.c
@@ -23,6 +23,7 @@
 #include <tevent.h>
 
 #include "providers/dp_backend.h"
+#include "providers/data_provider_req.h"
 #include "providers/ldap/ldap_common.h"
 #include "providers/ldap/sdap.h"
 #include "providers/ldap/sdap_async.h"
diff --git a/src/providers/proxy/proxy_id.c b/src/providers/proxy/proxy_id.c
index f8b8cbdf2322ae302328e249f9165957ce7395c3..49a4df616ff97b80d605db22faa12e4661a73e06 100644
--- a/src/providers/proxy/proxy_id.c
+++ b/src/providers/proxy/proxy_id.c
@@ -26,6 +26,7 @@
 
 #include "util/sss_format.h"
 #include "util/strtonum.h"
+#include "providers/data_provider_req.h"
 #include "providers/proxy/proxy.h"
 
 /* =Getpwnam-wrapper======================================================*/
diff --git a/src/providers/simple/simple_access_check.c b/src/providers/simple/simple_access_check.c
index 14d833be2bccda9ded3b04b881b09fd0be6684bf..1c4d0cbb315b9d426ff8ad936b1047a345c3162d 100644
--- a/src/providers/simple/simple_access_check.c
+++ b/src/providers/simple/simple_access_check.c
@@ -20,6 +20,7 @@
 */
 
 #include "providers/dp_backend.h"
+#include "providers/data_provider_req.h"
 #include "providers/simple/simple_access.h"
 #include "util/sss_utf8.h"
 #include "db/sysdb.h"
diff --git a/src/responder/autofs/autofssrv_dp.c b/src/responder/autofs/autofssrv_dp.c
index 041f0629eafadb92fc6b8ec7190830a2662b40a0..934449171d08deafc383bce2328cde1b86b84e36 100644
--- a/src/responder/autofs/autofssrv_dp.c
+++ b/src/responder/autofs/autofssrv_dp.c
@@ -26,6 +26,7 @@
 #include "util/util.h"
 #include "sbus/sbus_client.h"
 #include "providers/data_provider.h"
+#include "providers/data_provider_req.h"
 #include "responder/common/responder.h"
 #include "responder/autofs/autofs_private.h"
 
diff --git a/src/responder/common/responder_dp.c b/src/responder/common/responder_dp.c
index f7f8df04e80439d2d02df3e4d2aa4f3576997f36..d5a1d50ba4ad65637ae643465f76fc5b590c68ef 100644
--- a/src/responder/common/responder_dp.c
+++ b/src/responder/common/responder_dp.c
@@ -26,6 +26,7 @@
 #include "responder/common/responder_packet.h"
 #include "responder/common/responder.h"
 #include "providers/data_provider.h"
+#include "providers/data_provider_req.h"
 #include "sbus/sbus_client.h"
 
 struct sss_dp_req;
@@ -620,8 +621,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,
diff --git a/src/responder/ssh/sshsrv_dp.c b/src/responder/ssh/sshsrv_dp.c
index 90b0b5754e695c4757287d8694e390daee17af5d..af8c3ba628caa7f723732f146b48c8ee57a563fe 100644
--- a/src/responder/ssh/sshsrv_dp.c
+++ b/src/responder/ssh/sshsrv_dp.c
@@ -26,6 +26,7 @@
 #include "util/util.h"
 #include "sbus/sbus_client.h"
 #include "providers/data_provider.h"
+#include "providers/data_provider_req.h"
 #include "responder/common/responder.h"
 #include "responder/ssh/sshsrv_private.h"
 
diff --git a/src/responder/sudo/sudosrv_dp.c b/src/responder/sudo/sudosrv_dp.c
index 95595fba2ad81e837de7222ece626d331299848c..3fa6663553749c57cdd0216a4acaf93429a6d16d 100644
--- a/src/responder/sudo/sudosrv_dp.c
+++ b/src/responder/sudo/sudosrv_dp.c
@@ -27,6 +27,7 @@
 #include "util/util.h"
 #include "sbus/sbus_client.h"
 #include "providers/data_provider.h"
+#include "providers/data_provider_req.h"
 #include "responder/common/responder.h"
 #include "responder/sudo/sudosrv_private.h"
 #include "db/sysdb.h"
-- 
2.4.3

_______________________________________________
sssd-devel mailing list
sssd-devel@lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/sssd-devel

Reply via email to