dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

Blame SOURCES/0173-IFP-Add-domain-and-domainname-attributes-to-the-user.patch

ecf709
From a35b5c33a76857ad9223363e15558facec5c269d Mon Sep 17 00:00:00 2001
ecf709
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
ecf709
Date: Thu, 8 Jun 2017 11:46:25 +0200
ecf709
Subject: [PATCH 173/181] IFP: Add domain and domainname attributes to the user
ecf709
MIME-Version: 1.0
ecf709
Content-Type: text/plain; charset=UTF-8
ecf709
Content-Transfer-Encoding: 8bit
ecf709
ecf709
org.freedekstop.sssd.infopipe.Users.User gets two new attributes:
ecf709
- domain: object path of user's domain
ecf709
- domainname: user's domain name
ecf709
ecf709
org.freedekstop.sssd.infopipe.GetUserAttr can now request new attribute:
ecf709
- domainname: user's domain name
ecf709
ecf709
Resolves:
ecf709
https://pagure.io/SSSD/sssd/issue/2714
ecf709
ecf709
Reviewed-by: Fabiano FidĂȘncio <fidencio@redhat.com>
ecf709
(cherry picked from commit 37d2194cc9ea4d0254c88a3419e2376572562bab)
ecf709
---
ecf709
 src/responder/ifp/ifp_iface.c           |  2 +
ecf709
 src/responder/ifp/ifp_iface.xml         |  2 +
ecf709
 src/responder/ifp/ifp_iface_generated.c | 18 ++++++++
ecf709
 src/responder/ifp/ifp_iface_generated.h |  4 ++
ecf709
 src/responder/ifp/ifp_private.h         |  4 ++
ecf709
 src/responder/ifp/ifp_users.c           | 46 ++++++++++++++++++++
ecf709
 src/responder/ifp/ifp_users.h           |  8 ++++
ecf709
 src/responder/ifp/ifpsrv_cmd.c          |  8 ++++
ecf709
 src/responder/ifp/ifpsrv_util.c         | 74 ++++++++++++++++++++++++++++++++-
ecf709
 src/tests/cmocka/test_ifp.c             | 12 ++++--
ecf709
 10 files changed, 173 insertions(+), 5 deletions(-)
ecf709
ecf709
diff --git a/src/responder/ifp/ifp_iface.c b/src/responder/ifp/ifp_iface.c
ecf709
index e413e74f955c067a0efbe385a08b4b2cc6f2bba1..3293b92d750d33b2ecf77a03098c5169d052c924 100644
ecf709
--- a/src/responder/ifp/ifp_iface.c
ecf709
+++ b/src/responder/ifp/ifp_iface.c
ecf709
@@ -104,6 +104,8 @@ struct iface_ifp_users_user iface_ifp_users_user = {
ecf709
     .get_loginShell = ifp_users_user_get_login_shell,
ecf709
     .get_uniqueID = ifp_users_user_get_unique_id,
ecf709
     .get_groups = ifp_users_user_get_groups,
ecf709
+    .get_domain = ifp_users_user_get_domain,
ecf709
+    .get_domainname = ifp_users_user_get_domainname,
ecf709
     .get_extraAttributes = ifp_users_user_get_extra_attributes
ecf709
 };
ecf709
 
ecf709
diff --git a/src/responder/ifp/ifp_iface.xml b/src/responder/ifp/ifp_iface.xml
ecf709
index 0a23f56907f64c4c24db3ec3c0a312adbdb3edc8..ce071bb999bd207b8cc81f054da80de52a13d3df 100644
ecf709
--- a/src/responder/ifp/ifp_iface.xml
ecf709
+++ b/src/responder/ifp/ifp_iface.xml
ecf709
@@ -188,6 +188,8 @@
ecf709
         <property name="loginShell" type="s" access="read" />
ecf709
         <property name="uniqueID" type="s" access="read" />
ecf709
         <property name="groups" type="ao" access="read" />
ecf709
+        <property name="domain" type="o" access="read" />
ecf709
+        <property name="domainname" type="s" access="read" />
ecf709
         <property name="extraAttributes" type="a{sas}" access="read" />
ecf709
     </interface>
ecf709
 
ecf709
diff --git a/src/responder/ifp/ifp_iface_generated.c b/src/responder/ifp/ifp_iface_generated.c
ecf709
index 211646b6760d15e0df55ac20b9611b800b11d16c..51db4a9e5c7d72663f8845bd0da22d3f21526be8 100644
ecf709
--- a/src/responder/ifp/ifp_iface_generated.c
ecf709
+++ b/src/responder/ifp/ifp_iface_generated.c
ecf709
@@ -982,6 +982,24 @@ const struct sbus_property_meta iface_ifp_users_user__properties[] = {
ecf709
         NULL, /* no invoker */
ecf709
     },
ecf709
     {
ecf709
+        "domain", /* name */
ecf709
+        "o", /* type */
ecf709
+        SBUS_PROPERTY_READABLE,
ecf709
+        offsetof(struct iface_ifp_users_user, get_domain),
ecf709
+        sbus_invoke_get_o,
ecf709
+        0, /* not writable */
ecf709
+        NULL, /* no invoker */
ecf709
+    },
ecf709
+    {
ecf709
+        "domainname", /* name */
ecf709
+        "s", /* type */
ecf709
+        SBUS_PROPERTY_READABLE,
ecf709
+        offsetof(struct iface_ifp_users_user, get_domainname),
ecf709
+        sbus_invoke_get_s,
ecf709
+        0, /* not writable */
ecf709
+        NULL, /* no invoker */
ecf709
+    },
ecf709
+    {
ecf709
         "extraAttributes", /* name */
ecf709
         "a{sas}", /* type */
ecf709
         SBUS_PROPERTY_READABLE,
ecf709
diff --git a/src/responder/ifp/ifp_iface_generated.h b/src/responder/ifp/ifp_iface_generated.h
ecf709
index e69fc3a3efc6bdcef5d6539790908795818cd857..76f729fcb268e9c07668b3a5ee5bbd7d0b44ca16 100644
ecf709
--- a/src/responder/ifp/ifp_iface_generated.h
ecf709
+++ b/src/responder/ifp/ifp_iface_generated.h
ecf709
@@ -88,6 +88,8 @@
ecf709
 #define IFACE_IFP_USERS_USER_LOGINSHELL "loginShell"
ecf709
 #define IFACE_IFP_USERS_USER_UNIQUEID "uniqueID"
ecf709
 #define IFACE_IFP_USERS_USER_GROUPS "groups"
ecf709
+#define IFACE_IFP_USERS_USER_DOMAIN "domain"
ecf709
+#define IFACE_IFP_USERS_USER_DOMAINNAME "domainname"
ecf709
 #define IFACE_IFP_USERS_USER_EXTRAATTRIBUTES "extraAttributes"
ecf709
 
ecf709
 /* constants for org.freedesktop.sssd.infopipe.Groups */
ecf709
@@ -288,6 +290,8 @@ struct iface_ifp_users_user {
ecf709
     void (*get_loginShell)(struct sbus_request *, void *data, const char **);
ecf709
     void (*get_uniqueID)(struct sbus_request *, void *data, const char **);
ecf709
     void (*get_groups)(struct sbus_request *, void *data, const char ***, int *);
ecf709
+    void (*get_domain)(struct sbus_request *, void *data, const char **);
ecf709
+    void (*get_domainname)(struct sbus_request *, void *data, const char **);
ecf709
     void (*get_extraAttributes)(struct sbus_request *, void *data, hash_table_t **);
ecf709
 };
ecf709
 
ecf709
diff --git a/src/responder/ifp/ifp_private.h b/src/responder/ifp/ifp_private.h
ecf709
index e800070a59f77f8ce58a2fc402e616bb773e996b..a6e5701b8d1ebb27af0c35fa3ebe0c6c00d16bd6 100644
ecf709
--- a/src/responder/ifp/ifp_private.h
ecf709
+++ b/src/responder/ifp/ifp_private.h
ecf709
@@ -70,6 +70,10 @@ errno_t ifp_req_create(struct sbus_request *dbus_req,
ecf709
 /* Returns an appropriate DBus error for specific ifp_req_create failures */
ecf709
 int ifp_req_create_handle_failure(struct sbus_request *dbus_req, errno_t err);
ecf709
 
ecf709
+errno_t ifp_add_value_to_dict(DBusMessageIter *iter_dict,
ecf709
+                              const char *key,
ecf709
+                              const char *value);
ecf709
+
ecf709
 errno_t ifp_add_ldb_el_to_dict(DBusMessageIter *iter_dict,
ecf709
                                struct ldb_message_element *el);
ecf709
 const char **
ecf709
diff --git a/src/responder/ifp/ifp_users.c b/src/responder/ifp/ifp_users.c
ecf709
index 188194f2ab356d0e67b0f26b003f3a9ce48e6acd..90b947ed9ca345fbeba6772c90f898451a0868aa 100644
ecf709
--- a/src/responder/ifp/ifp_users.c
ecf709
+++ b/src/responder/ifp/ifp_users.c
ecf709
@@ -1328,6 +1328,52 @@ void ifp_users_user_get_groups(struct sbus_request *sbus_req,
ecf709
     *_size = num_groups;
ecf709
 }
ecf709
 
ecf709
+void ifp_users_user_get_domain(struct sbus_request *sbus_req,
ecf709
+                               void *data,
ecf709
+                               const char **_out)
ecf709
+{
ecf709
+    const char *domainname;
ecf709
+
ecf709
+    *_out = NULL;
ecf709
+    ifp_users_user_get_domainname(sbus_req, data, &domainname);
ecf709
+
ecf709
+    if (domainname == NULL) {
ecf709
+        return;
ecf709
+    }
ecf709
+
ecf709
+    *_out = sbus_opath_compose(sbus_req, IFP_PATH_DOMAINS,
ecf709
+                               domainname);
ecf709
+}
ecf709
+
ecf709
+void ifp_users_user_get_domainname(struct sbus_request *sbus_req,
ecf709
+                                   void *data,
ecf709
+                                   const char **_out)
ecf709
+{
ecf709
+    struct ifp_ctx *ifp_ctx;
ecf709
+    struct sss_domain_info *domain;
ecf709
+    errno_t ret;
ecf709
+
ecf709
+    *_out = NULL;
ecf709
+
ecf709
+    ifp_ctx = talloc_get_type(data, struct ifp_ctx);
ecf709
+    if (ifp_ctx == NULL) {
ecf709
+        DEBUG(SSSDBG_CRIT_FAILURE, "Invalid pointer!\n");
ecf709
+        return;
ecf709
+    }
ecf709
+
ecf709
+    if (!ifp_is_user_attr_allowed(ifp_ctx, "domainname")) {
ecf709
+        DEBUG(SSSDBG_TRACE_ALL, "Attribute domainname is not allowed\n");
ecf709
+        return;
ecf709
+    }
ecf709
+
ecf709
+    ret = ifp_users_user_get(sbus_req, ifp_ctx, &domain, NULL);
ecf709
+    if (ret != EOK) {
ecf709
+        return;
ecf709
+    }
ecf709
+
ecf709
+    *_out = domain->name;
ecf709
+}
ecf709
+
ecf709
 void ifp_users_user_get_extra_attributes(struct sbus_request *sbus_req,
ecf709
                                          void *data,
ecf709
                                          hash_table_t **_out)
ecf709
diff --git a/src/responder/ifp/ifp_users.h b/src/responder/ifp/ifp_users.h
ecf709
index f8fefeb7f658b6e0a5f72371da1b025d69e6f412..715a8bc31996bfd93c21dbe263f2567bd0b50b03 100644
ecf709
--- a/src/responder/ifp/ifp_users.h
ecf709
+++ b/src/responder/ifp/ifp_users.h
ecf709
@@ -103,6 +103,14 @@ void ifp_users_user_get_groups(struct sbus_request *sbus_req,
ecf709
                                const char ***_out,
ecf709
                                int *_size);
ecf709
 
ecf709
+void ifp_users_user_get_domain(struct sbus_request *sbus_req,
ecf709
+                               void *data,
ecf709
+                               const char **_out);
ecf709
+
ecf709
+void ifp_users_user_get_domainname(struct sbus_request *sbus_req,
ecf709
+                                   void *data,
ecf709
+                                   const char **_out);
ecf709
+
ecf709
 void ifp_users_user_get_extra_attributes(struct sbus_request *sbus_req,
ecf709
                                          void *data,
ecf709
                                          hash_table_t **_out);
ecf709
diff --git a/src/responder/ifp/ifpsrv_cmd.c b/src/responder/ifp/ifpsrv_cmd.c
ecf709
index 70728e1bb656fd032b7f1c240683e8aa3b91a726..d86aed57206ba8f0a6facbd64051fa7c901513f3 100644
ecf709
--- a/src/responder/ifp/ifpsrv_cmd.c
ecf709
+++ b/src/responder/ifp/ifpsrv_cmd.c
ecf709
@@ -233,6 +233,14 @@ ifp_user_get_attr_handle_reply(struct sss_domain_info *domain,
ecf709
         }
ecf709
 
ecf709
         for (ai = 0; attrs[ai]; ai++) {
ecf709
+            if (strcmp(attrs[ai], "domainname") == 0) {
ecf709
+                ret = ifp_add_value_to_dict(&iter_dict, "domainname",
ecf709
+                                            domain->name);
ecf709
+                DEBUG(SSSDBG_MINOR_FAILURE,
ecf709
+                      "Cannot add attribute %s to message\n", attrs[ai]);
ecf709
+                continue;
ecf709
+            }
ecf709
+
ecf709
             el = sss_view_ldb_msg_find_element(domain, res->msgs[0], attrs[ai]);
ecf709
             if (el == NULL || el->num_values == 0) {
ecf709
                 DEBUG(SSSDBG_MINOR_FAILURE,
ecf709
diff --git a/src/responder/ifp/ifpsrv_util.c b/src/responder/ifp/ifpsrv_util.c
ecf709
index 5866d30d8a5845c21f5b05fc5de150162eba747e..643881515fb4805ae93ba56c3bca9d1da7796319 100644
ecf709
--- a/src/responder/ifp/ifpsrv_util.c
ecf709
+++ b/src/responder/ifp/ifpsrv_util.c
ecf709
@@ -29,7 +29,7 @@
ecf709
 #define IFP_USER_DEFAULT_ATTRS {SYSDB_NAME, SYSDB_UIDNUM,   \
ecf709
                                 SYSDB_GIDNUM, SYSDB_GECOS,  \
ecf709
                                 SYSDB_HOMEDIR, SYSDB_SHELL, \
ecf709
-                                "groups", \
ecf709
+                                "groups", "domain", "domainname", \
ecf709
                                 NULL}
ecf709
 
ecf709
 errno_t ifp_req_create(struct sbus_request *dbus_req,
ecf709
@@ -100,6 +100,78 @@ int ifp_req_create_handle_failure(struct sbus_request *dbus_req, errno_t err)
ecf709
                                             "Cannot create IFP request\n"));
ecf709
 }
ecf709
 
ecf709
+errno_t ifp_add_value_to_dict(DBusMessageIter *iter_dict,
ecf709
+                              const char *key,
ecf709
+                              const char *value)
ecf709
+{
ecf709
+    DBusMessageIter iter_dict_entry;
ecf709
+    DBusMessageIter iter_dict_val;
ecf709
+    DBusMessageIter iter_array;
ecf709
+    dbus_bool_t dbret;
ecf709
+
ecf709
+    if (value == NULL || key == NULL) {
ecf709
+        return EINVAL;
ecf709
+    }
ecf709
+
ecf709
+    dbret = dbus_message_iter_open_container(iter_dict,
ecf709
+                                             DBUS_TYPE_DICT_ENTRY, NULL,
ecf709
+                                             &iter_dict_entry);
ecf709
+    if (!dbret) {
ecf709
+        return ENOMEM;
ecf709
+    }
ecf709
+
ecf709
+    /* Start by appending the key */
ecf709
+    dbret = dbus_message_iter_append_basic(&iter_dict_entry,
ecf709
+                                           DBUS_TYPE_STRING, &key);
ecf709
+    if (!dbret) {
ecf709
+        return ENOMEM;
ecf709
+    }
ecf709
+
ecf709
+    dbret = dbus_message_iter_open_container(&iter_dict_entry,
ecf709
+                                             DBUS_TYPE_VARIANT,
ecf709
+                                             DBUS_TYPE_ARRAY_AS_STRING
ecf709
+                                             DBUS_TYPE_STRING_AS_STRING,
ecf709
+                                             &iter_dict_val);
ecf709
+    if (!dbret) {
ecf709
+        return ENOMEM;
ecf709
+    }
ecf709
+
ecf709
+    /* Open container for values */
ecf709
+    dbret = dbus_message_iter_open_container(&iter_dict_val,
ecf709
+                                 DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING,
ecf709
+                                 &iter_array);
ecf709
+    if (!dbret) {
ecf709
+        return ENOMEM;
ecf709
+    }
ecf709
+
ecf709
+    dbret = dbus_message_iter_append_basic(&iter_array,
ecf709
+                                           DBUS_TYPE_STRING,
ecf709
+                                           &value);
ecf709
+    if (!dbret) {
ecf709
+        return ENOMEM;
ecf709
+    }
ecf709
+
ecf709
+    dbret = dbus_message_iter_close_container(&iter_dict_val,
ecf709
+                                              &iter_array);
ecf709
+    if (!dbret) {
ecf709
+        return ENOMEM;
ecf709
+    }
ecf709
+
ecf709
+    dbret = dbus_message_iter_close_container(&iter_dict_entry,
ecf709
+                                              &iter_dict_val);
ecf709
+    if (!dbret) {
ecf709
+        return ENOMEM;
ecf709
+    }
ecf709
+
ecf709
+    dbret = dbus_message_iter_close_container(iter_dict,
ecf709
+                                              &iter_dict_entry);
ecf709
+    if (!dbret) {
ecf709
+        return ENOMEM;
ecf709
+    }
ecf709
+
ecf709
+    return EOK;
ecf709
+}
ecf709
+
ecf709
 errno_t ifp_add_ldb_el_to_dict(DBusMessageIter *iter_dict,
ecf709
                                struct ldb_message_element *el)
ecf709
 {
ecf709
diff --git a/src/tests/cmocka/test_ifp.c b/src/tests/cmocka/test_ifp.c
ecf709
index 21c5475d1c74cd8325815653166bef194ea84f7b..45f718341222c6803a65130741590e10e7aded84 100644
ecf709
--- a/src/tests/cmocka/test_ifp.c
ecf709
+++ b/src/tests/cmocka/test_ifp.c
ecf709
@@ -269,7 +269,7 @@ void test_attr_acl(void **state)
ecf709
     const char *exp_defaults[] = { SYSDB_NAME, SYSDB_UIDNUM,
ecf709
                                    SYSDB_GIDNUM, SYSDB_GECOS,
ecf709
                                    SYSDB_HOMEDIR, SYSDB_SHELL,
ecf709
-                                   "groups", NULL };
ecf709
+                                   "groups", "domain", "domainname", NULL };
ecf709
     attr_parse_test(exp_defaults, NULL);
ecf709
 
ecf709
     /* Test adding some attributes to the defaults */
ecf709
@@ -277,13 +277,14 @@ void test_attr_acl(void **state)
ecf709
                               SYSDB_NAME, SYSDB_UIDNUM,
ecf709
                               SYSDB_GIDNUM, SYSDB_GECOS,
ecf709
                               SYSDB_HOMEDIR, SYSDB_SHELL,
ecf709
-                              "groups", NULL };
ecf709
+                              "groups", "domain", "domainname", NULL };
ecf709
     attr_parse_test(exp_add, "+telephoneNumber, +streetAddress");
ecf709
 
ecf709
     /* Test removing some attributes to the defaults */
ecf709
     const char *exp_rm[] = { SYSDB_NAME,
ecf709
                              SYSDB_GIDNUM, SYSDB_GECOS,
ecf709
                              SYSDB_HOMEDIR, "groups",
ecf709
+                             "domain", "domainname",
ecf709
                              NULL };
ecf709
     attr_parse_test(exp_rm, "-"SYSDB_SHELL ",-"SYSDB_UIDNUM);
ecf709
 
ecf709
@@ -292,6 +293,7 @@ void test_attr_acl(void **state)
ecf709
                                  SYSDB_NAME, SYSDB_UIDNUM,
ecf709
                                  SYSDB_GIDNUM, SYSDB_GECOS,
ecf709
                                  SYSDB_HOMEDIR, "groups",
ecf709
+                                 "domain", "domainname",
ecf709
                                  NULL };
ecf709
     attr_parse_test(exp_add_rm, "+telephoneNumber, -"SYSDB_SHELL);
ecf709
 
ecf709
@@ -299,7 +301,8 @@ void test_attr_acl(void **state)
ecf709
     const char *exp_add_rm_override[] = { SYSDB_NAME, SYSDB_UIDNUM,
ecf709
                                           SYSDB_GIDNUM, SYSDB_GECOS,
ecf709
                                           SYSDB_HOMEDIR, SYSDB_SHELL,
ecf709
-                                          "groups", NULL };
ecf709
+                                          "groups", "domain",
ecf709
+                                          "domainname", NULL };
ecf709
     attr_parse_test(exp_add_rm_override,
ecf709
                     "+telephoneNumber, -telephoneNumber, +telephoneNumber");
ecf709
 
ecf709
@@ -307,7 +310,8 @@ void test_attr_acl(void **state)
ecf709
     const char *rm_all[] = { NULL };
ecf709
     attr_parse_test(rm_all,  "-"SYSDB_NAME ", -"SYSDB_UIDNUM
ecf709
                              ", -"SYSDB_GIDNUM ", -"SYSDB_GECOS
ecf709
-                             ", -"SYSDB_HOMEDIR ", -"SYSDB_SHELL", -groups");
ecf709
+                             ", -"SYSDB_HOMEDIR ", -"SYSDB_SHELL", -groups, "
ecf709
+                             "-domain, -domainname");
ecf709
 
ecf709
     /* Malformed list */
ecf709
     attr_parse_test(NULL,  "missing_plus_or_minus");
ecf709
-- 
ecf709
2.9.4
ecf709