From d82a0817d265cdded772b782627605901ce99fe5 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Tue, 19 Jan 2016 02:27:10 +0100 Subject: Replace dn_contains_uid with is_user The function dn_contains_uid was used to check, if an entry is an user account. This check uses the objectClass now. --- service_passwords.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/service_passwords.c b/service_passwords.c index 9b8f52a..7ace7fe 100644 --- a/service_passwords.c +++ b/service_passwords.c @@ -72,20 +72,18 @@ static int get_entry(const char *dn, char **attrs, Slapi_Entry **entry) return rc; } -/** Check if the given DN contains a \c uid attribute. +/** Check if the given DN is a user account. * - * This function checks, if the entry specified by the DN contains a \c uid - * attribute and that this attribute is not empty. + * This functions checks, if the given DN is a DN of a user account. All user + * accounts have to have the \c inetOrgPerson object class. * * @param[in] dn DN of the entry. - * @return 0 if the \c uid attribute was found, 1 otherwise + * @return 0 if the entry is a user account, 1 otherwise */ -static int dn_contains_uid(const char *dn) +static int is_user(const char *dn) { - char *attrs[] = { "uid", NULL }; + char *attrs[] = { "objectClass", NULL }; Slapi_Entry *entry = NULL; - Slapi_Attr *attr = NULL; - Slapi_ValueSet *uid_values = NULL; int rc = 0; @@ -96,16 +94,9 @@ static int dn_contains_uid(const char *dn) goto fail1; } - rc |= slapi_entry_attr_find(entry, "uid", &attr); - if (rc != 0 || attr == NULL) { - /* no uid attribute */ - rc = 1; - goto fail1; - } - - rc |= slapi_attr_get_valueset(attr, &uid_values); - if (rc != 0 || slapi_valueset_count(uid_values) == 0) { - /* empty uid value */ + if (slapi_entry_attr_hasvalue( + entry, "objectClass", "inetOrgPerson") == 0) { + /* no user account */ rc = 1; goto fail1; } @@ -454,7 +445,7 @@ static int pre_bind(Slapi_PBlock *pb) } parent_dn = slapi_dn_parent(dn); - rc |= dn_contains_uid(parent_dn); + rc |= is_user(parent_dn); slapi_ch_free_string(&parent_dn); if (rc != 0) { @@ -561,7 +552,7 @@ static int pre_entry(Slapi_PBlock *pb) /* ignore service_password entries */ parent_dn = slapi_dn_parent(result_dn); - rc |= dn_contains_uid(parent_dn); + rc |= is_user(parent_dn); slapi_ch_free_string(&parent_dn); if (rc == 0) { @@ -570,7 +561,7 @@ static int pre_entry(Slapi_PBlock *pb) } /* modify the dn of the returned entry */ - if (dn_contains_uid(result_dn) == 0) { + if (is_user(result_dn) == 0) { new_entry = prepend_service_prefix(entry, service); /* Set the new entry as the new result in the pblock and also set the -- cgit v1.2.3-1-g7c22