Add kdbus_domain_user_find() to look up domain users

Signed-off-by: Djalal Harouni <tix...@opendz.org>
---
 domain.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/domain.c b/domain.c
index 18dc2a7..a5abb2d 100644
--- a/domain.c
+++ b/domain.c
@@ -446,6 +446,38 @@ kdbus_domain_user_new(struct kdbus_domain *domain, kuid_t 
uid)
 }
 
 /**
+ * kdbus_domain_user_find() - find a domain user with a given uid
+ * @domain             The domain of the user
+ * @uid                        The uid of the user; INVALID_UID for an
+ *                     anonymous user like custom endpoint
+ *
+ * Return: a kdbus_domain_user with the reference counter increased.
+ * If the domain user can't be found, NULL is returned.
+ */
+struct kdbus_domain_user *
+kdbus_domain_user_find(struct kdbus_domain *domain, kuid_t uid)
+{
+       struct kdbus_domain_user *u;
+       struct kdbus_domain_user *user = NULL;
+
+       if (!uid_valid(uid))
+               return user;
+
+       mutex_lock(&domain->lock);
+       hash_for_each_possible(domain->user_hash, u,
+                              hentry, __kuid_val(uid)) {
+               if (!uid_eq(u->uid, uid))
+                       continue;
+
+               user = kdbus_domain_user_ref(u);
+               break;
+       }
+       mutex_unlock(&domain->lock);
+
+       return user;
+}
+
+/**
  * __kdbus_domain_user_account() - account a kdbus_domain_user object
  *                                into the specified domain
  * @domain:            The domain of the user
-- 
1.9.3

_______________________________________________
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to