summaryrefslogtreecommitdiff
path: root/server/util.c
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2006-11-11 14:02:25 +0000
committerArthur de Jong <arthur@arthurdejong.org>2006-11-11 14:02:25 +0000
commitdb14b113e055fa7ab006cfe1c04961bba19a85de (patch)
tree4ffec7243dd1c56f3fdfddbe294e7451c408f384 /server/util.c
parentbffd85ce667130419ddb381421e1a524f490b981 (diff)
simplify some functions to pass file pointer around instead of struct and buffer (initially only for alias_byname())
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/libnss_ldapd@84 ef36b2f9-881f-0410-afb5-c4e39611909c
Diffstat (limited to 'server/util.c')
-rw-r--r--server/util.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/server/util.c b/server/util.c
index 786d0a8..e2888f6 100644
--- a/server/util.c
+++ b/server/util.c
@@ -50,6 +50,9 @@
#include "ldap-nss.h"
#include "util.h"
+#include "nslcd-server.h"
+#include "common.h"
+#include "log.h"
static enum nss_status do_getrdnvalue (const char *dn,
const char *rdntype,
@@ -249,6 +252,75 @@ _nss_ldap_getrdnvalue (LDAPMessage * entry,
return status;
}
+int _nss_ldap_write_rndvalue(FILE *fp,LDAPMessage *entry,const char *rdntype)
+{
+ char *dn;
+ int status=456;
+ char **vals;
+ int32_t tmpint32;
+ char **exploded_dn;
+ char **exploded_rdn;
+ char rdnava[64];
+ int rdnavalen;
+ int i;
+ /* log call */
+ log_log(LOG_DEBUG,"_nss_ldap_write_rndvalue(%s)",rdntype);
+ /* get the dn from the entry */
+ dn=_nss_ldap_get_dn(entry);
+ if (dn==NULL)
+ return NSLCD_RESULT_NOTFOUND;
+ /* append a `=' to the rdntype */
+ snprintf(rdnava,sizeof(rdnava),"%s=",rdntype);
+ rdnavalen=strlen(rdnava);
+ /* explode dn */
+ exploded_dn=ldap_explode_dn(dn,0);
+ if (exploded_dn!=NULL)
+ {
+ /*
+ * attempt to get the naming attribute's principal
+ * value by parsing the RDN. We need to support
+ * multivalued RDNs (as they're essentially mandated
+ * for services)
+ */
+ exploded_rdn=ldap_explode_rdn(exploded_dn[0],0);
+ if (exploded_rdn!=NULL)
+ {
+ for (i=0;exploded_rdn[i]!=NULL;i++)
+ {
+ /* if the values begins with rndava */
+ if (strncasecmp(exploded_rdn[i],rdnava,rdnavalen)==0)
+ {
+ /* FIXME: handle case where WRITE fails */
+ WRITE_STRING(fp,exploded_rdn[i]+rdnavalen);
+ status=0;
+ break;
+ }
+ }
+ ldap_value_free(exploded_rdn);
+ }
+ ldap_value_free(exploded_dn);
+ }
+ ldap_memfree(dn);
+ /*
+ * If examining the DN failed, then pick the nominal first
+ * value of cn as the canonical name (recall that attributes
+ * are sets, not sequences)
+ */
+ if (status==456)
+ {
+ vals=_nss_ldap_get_values(entry,rdntype);
+ if (vals!=NULL)
+ {
+ /* write the first entry */
+ WRITE_STRING(fp,vals[0]);
+ status=NSS_STATUS_SUCCESS;
+ ldap_value_free(vals);
+ status=0;
+ }
+ }
+ return status;
+}
+
static enum nss_status
do_getrdnvalue (const char *dn,
const char *rdntype,