]> code.citadel.org Git - citadel.git/commitdiff
* Further work on creating LDAP entries.
authorArt Cancro <ajc@citadel.org>
Mon, 19 Jan 2004 04:44:11 +0000 (04:44 +0000)
committerArt Cancro <ajc@citadel.org>
Mon, 19 Jan 2004 04:44:11 +0000 (04:44 +0000)
citadel/ChangeLog
citadel/serv_ldap.c
citadel/serv_ldap.h

index 4214a736e5b6a114a62de887660daf962aec9135..81a4425713e18055241d11bb01462e1ef1a15e86 100644 (file)
@@ -1,4 +1,7 @@
  $Log$
+ Revision 614.7  2004/01/19 04:44:11  ajc
+ * Further work on creating LDAP entries.
+
  Revision 614.6  2004/01/18 21:04:40  ajc
  * Reworked vCard etc. functions for addition of new vCard data to LDAP
 
@@ -5233,4 +5236,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import
-
index c9892fe944096717557d76f90c6a606a2aadddfe..36bdeb7c25b81fcd5c679355f3d698add65127ce 100644 (file)
@@ -96,16 +96,18 @@ void CtdlConnectToLdap(void) {
 
 
 
-
 /*
  * Write (add, or change if already exists) a directory entry to the
  * LDAP server, based on the information supplied in a vCard.
  */
 void ctdl_vcard_to_ldap(struct CtdlMessage *msg) {
        struct vCard *v = NULL;
-
+       int i, j;
        char this_dn[SIZ];
+       LDAPMod **attrs = NULL;
+       int num_attrs = 0;
 
+       if (dirserver == NULL) return;
        if (msg == NULL) return;
        if (msg->cm_fields['M'] == NULL) return;
        if (msg->cm_fields['A'] == NULL) return;
@@ -117,11 +119,68 @@ void ctdl_vcard_to_ldap(struct CtdlMessage *msg) {
                config.c_ldap_base_dn
        );
 
+       /* The first LDAP attribute will be an 'objectclass' list.  Citadel
+        * doesn't do anything with this.  It's just there for compatibility
+        * with Kolab.
+        */
+       num_attrs = 1;
+       attrs = mallok( (sizeof(LDAPMod *) * num_attrs) );
+       attrs[0] = mallok(sizeof(LDAPMod));
+       memset(attrs[0], 0, sizeof(LDAPMod));
+       attrs[0]->mod_op        = LDAP_MOD_ADD;
+       attrs[0]->mod_type      = "objectclass";
+       attrs[0]->mod_values    = mallok(5 * sizeof(char *));
+       attrs[0]->mod_values[0] = strdoop("inetOrgPerson");
+       attrs[0]->mod_values[1] = strdoop("organizationalPerson");
+       attrs[0]->mod_values[2] = strdoop("person");
+       attrs[0]->mod_values[3] = strdoop("Top");
+       attrs[0]->mod_values[4] = NULL;
+       
+       /* Convert the vCard fields to LDAP properties */
+       v = vcard_load(msg->cm_fields['M']);
+       if (v->numprops) for (i=0; i<(v->numprops); ++i) {
+/*
+               v->prop[i].name
+               v->prop[i].value
+ */
+       }
+       vcard_free(v);  /* Don't need this anymore. */
+
+       /* The last attribute must be a NULL one. */
+       attrs = realloc(attrs, (sizeof(LDAPMod *) * ++num_attrs) );
+       attrs[num_attrs - 1] = NULL;
+       
        lprintf(9, "this_dn: <%s>\n", this_dn);
 
-       v = vcard_load(msg->cm_fields['M']);
+       begin_critical_section(S_LDAP);
+       i = ldap_add_s(dirserver, this_dn, attrs);
+       end_critical_section(S_LDAP);
+       if (i != LDAP_SUCCESS) {
+               lprintf(3, "ldap_add_s() failed: %s (%d)\n",
+                       ldap_err2string(i), i);
+       }
 
-       vcard_free(v);
+       /* Free the attributes */
+       for (i=0; i<num_attrs; ++i) {
+               if (attrs[i] != NULL) {
+
+                       /* First, free the value strings */
+                       if (attrs[i]->mod_values != NULL) {
+                               for (j=0; attrs[i]->mod_values[j] != NULL; ++j) {
+                                       phree(attrs[i]->mod_values[j]);
+                               }
+                       }
+
+                       /* Free the value strings pointer list */       
+                       if (attrs[i]->mod_values != NULL) {
+                               phree(attrs[i]->mod_values);
+                       }
+
+                       /* Now free the LDAPMod struct itself. */
+                       phree(attrs[i]);
+               }
+       }
+       phree(attrs);
 }
 
 
index b4a9fb24b18a5cb6dd539347fb72d49c90429264..49fe7ba0a8025655528a8d7db233093a62b1009c 100644 (file)
@@ -7,5 +7,4 @@
 
 void ctdl_vcard_to_ldap(struct CtdlMessage *msg);
 
-
 #endif /* HAVE_LDAP */