* Got Citadel talking to LDAP. Still requires manual creation of schema
authorArt Cancro <ajc@citadel.org>
Sat, 24 Jan 2004 05:47:50 +0000 (05:47 +0000)
committerArt Cancro <ajc@citadel.org>
Sat, 24 Jan 2004 05:47:50 +0000 (05:47 +0000)
  and container entries, which I don't like; we'll have to fix that.  It
  also does not yet populate all fields.

citadel/ChangeLog
citadel/serv_ldap.c
citadel/server_main.c

index e73de5eae82a181976b08882c6200aa2812bd717..67acde9b63c0c37d2fca97169b032f262d4628be 100644 (file)
@@ -1,4 +1,9 @@
  $Log$
+ Revision 614.9  2004/01/24 05:47:50  ajc
+ * Got Citadel talking to LDAP.  Still requires manual creation of schema
+   and container entries, which I don't like; we'll have to fix that.  It
+   also does not yet populate all fields.
+
  Revision 614.8  2004/01/19 21:01:15  error
  * Clear out the autom4te.cache when bootstrapping to avoid autoheader problems
 
@@ -5239,4 +5244,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 36bdeb7c25b81fcd5c679355f3d698add65127ce..17adac87b878149e5cda0ee393dcb29406faa59b 100644 (file)
@@ -42,6 +42,7 @@
 #include "msgbase.h"
 #include "serv_ldap.h"
 #include "vcard.h"
+#include "tools.h"
 
 #ifdef HAVE_LDAP
 
@@ -107,12 +108,19 @@ void ctdl_vcard_to_ldap(struct CtdlMessage *msg) {
        LDAPMod **attrs = NULL;
        int num_attrs = 0;
 
+       char givenname[SIZ];
+       char sn[SIZ];
+
        if (dirserver == NULL) return;
        if (msg == NULL) return;
        if (msg->cm_fields['M'] == NULL) return;
        if (msg->cm_fields['A'] == NULL) return;
        if (msg->cm_fields['N'] == NULL) return;
 
+       /* Initialize variables */
+       strcpy(givenname, "_");
+       strcpy(sn, "_");
+
        sprintf(this_dn, "cn=%s,ou=%s,%s",
                msg->cm_fields['A'],
                msg->cm_fields['N'],
@@ -135,31 +143,77 @@ void ctdl_vcard_to_ldap(struct CtdlMessage *msg) {
        attrs[0]->mod_values[2] = strdoop("person");
        attrs[0]->mod_values[3] = strdoop("Top");
        attrs[0]->mod_values[4] = NULL;
+
+       /* Add a "cn" (Common Name) attribute based on the user's screen name */
+       attrs = reallok(attrs, (sizeof(LDAPMod *) * ++num_attrs) );
+       attrs[num_attrs-1] = mallok(sizeof(LDAPMod));
+       memset(attrs[num_attrs-1], 0, sizeof(LDAPMod));
+       attrs[num_attrs-1]->mod_op              = LDAP_MOD_ADD;
+       attrs[num_attrs-1]->mod_type            = "cn";
+       attrs[num_attrs-1]->mod_values          = mallok(2 * sizeof(char *));
+       attrs[num_attrs-1]->mod_values[0]       = strdoop(msg->cm_fields['A']);
+       attrs[num_attrs-1]->mod_values[1]       = 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
- */
+
+               if (!strcasecmp(v->prop[i].name, "n")) {
+                       extract_token(sn,               v->prop[i].value, 0, ';');
+                       extract_token(givenname,        v->prop[i].value, 1, ';');
+               }
+
        }
        vcard_free(v);  /* Don't need this anymore. */
 
+       /* "sn" (surname) based on info in vCard */
+       attrs = reallok(attrs, (sizeof(LDAPMod *) * ++num_attrs) );
+       attrs[num_attrs-1] = mallok(sizeof(LDAPMod));
+       memset(attrs[num_attrs-1], 0, sizeof(LDAPMod));
+       attrs[num_attrs-1]->mod_op              = LDAP_MOD_ADD;
+       attrs[num_attrs-1]->mod_type            = "sn";
+       attrs[num_attrs-1]->mod_values          = mallok(2 * sizeof(char *));
+       attrs[num_attrs-1]->mod_values[0]       = strdoop(sn);
+       attrs[num_attrs-1]->mod_values[1]       = NULL;
+       
+       /* "givenname" (first name) based on info in vCard */
+       attrs = reallok(attrs, (sizeof(LDAPMod *) * ++num_attrs) );
+       attrs[num_attrs-1] = mallok(sizeof(LDAPMod));
+       memset(attrs[num_attrs-1], 0, sizeof(LDAPMod));
+       attrs[num_attrs-1]->mod_op              = LDAP_MOD_ADD;
+       attrs[num_attrs-1]->mod_type            = "givenname";
+       attrs[num_attrs-1]->mod_values          = mallok(2 * sizeof(char *));
+       attrs[num_attrs-1]->mod_values[0]       = strdoop(givenname);
+       attrs[num_attrs-1]->mod_values[1]       = NULL;
+
        /* 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);
 
+       lprintf(9, "Calling ldap_add_s()\n");
        begin_critical_section(S_LDAP);
        i = ldap_add_s(dirserver, this_dn, attrs);
        end_critical_section(S_LDAP);
+
+       /* If the entry already exists, repopulate it instead */
+       if (i == LDAP_ALREADY_EXISTS) {
+               for (j=0; j<(num_attrs-1); ++j) {
+                       attrs[j]->mod_op = LDAP_MOD_REPLACE;
+               }
+               lprintf(9, "Calling ldap_modify_s()\n");
+               begin_critical_section(S_LDAP);
+               i = ldap_modify_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);
        }
 
+       lprintf(9, "Freeing attributes\n");
        /* Free the attributes */
        for (i=0; i<num_attrs; ++i) {
                if (attrs[i] != NULL) {
@@ -181,6 +235,7 @@ void ctdl_vcard_to_ldap(struct CtdlMessage *msg) {
                }
        }
        phree(attrs);
+       lprintf(9, "LDAP operation complete.\n");
 }
 
 
index 94ee493ff340281bdbe39fb0dbd658e922205a20..5dcc778fe1863a81969ac674f63e05368475900b 100644 (file)
@@ -138,14 +138,15 @@ int main(int argc, char **argv)
        }
 
        /* Tell 'em who's in da house */
-       lprintf(1,
-               "\n\n*** Citadel/UX messaging server engine v%d.%02d ***\n"
-               "Copyright (C) 1987-2003 by the Citadel/UX development team.\n"
-               "This program is distributed under the terms of the GNU "
-               "General Public License.\n\n",
+       lprintf(1, "\n");
+       lprintf(1, "\n");
+       lprintf(1,"*** Citadel/UX messaging server engine v%d.%02d ***\n",
                (REV_LEVEL/100),
-               (REV_LEVEL%100)
-       );
+               (REV_LEVEL%100) );
+       lprintf(1,"Copyright (C) 1987-2003 by the Citadel/UX development team.\n");
+       lprintf(1,"This program is distributed under the terms of the GNU ");
+       lprintf(1,"General Public License.\n");
+       lprintf(1, "\n");
 
        /* Initialize... */
        init_sysdep();