* Completed the per-user initialization of LDAP entries.
authorArt Cancro <ajc@citadel.org>
Thu, 5 Feb 2004 03:54:14 +0000 (03:54 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 5 Feb 2004 03:54:14 +0000 (03:54 +0000)
citadel/ChangeLog
citadel/citadel-slapd.conf
citadel/serv_ldap.c

index bcfa0729153001cb33a732565cf6b91800808985..231c496e962482e69c6d7ec64723a7fc5e7784e6 100644 (file)
@@ -1,4 +1,7 @@
  $Log$
+ Revision 614.15  2004/02/05 03:54:14  ajc
+ * Completed the per-user initialization of LDAP entries.
+
  Revision 614.14  2004/02/04 18:27:25  error
  * Don't delete temp file when composing message until after server writes
    it successfully (or an error occurs in the client itself).
@@ -5265,4 +5268,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 810ff9ba0f6e9ba7e108f9aeb93b7ec23037bbe3..10c0c564326f6364ac7ccbe7a2c9993f4bf1646b 100644 (file)
@@ -3,16 +3,12 @@ include /usr/local/citadel/citadel-openldap.schema
 pidfile                /usr/local/citadel/openldap-data/slapd.pid
 argsfile       /usr/local/citadel/openldap-data/slapd.args
 
-database bdb
-suffix "dc=servername,dc=domain,dc=org"
-rootdn "cn=manager,dc=servername,dc=domain,dc=org"
-rootpw secret
-
-directory /usr/local/citadel/openldap-data
-
-index  objectClass     eq
-
-
-
+database       bdb
+allow          bind_v2
+suffix         "dc=servername,dc=domain,dc=org"
+rootdn         "cn=manager,dc=servername,dc=domain,dc=org"
+rootpw         secret
 
+directory      /usr/local/citadel/openldap-data
 
+index          objectClass     eq
index 11ebc6c90d13079ceb11930ebdcf6cbd0405a9cc..69f7222d2777b051990ee292f82579801ace08bb 100644 (file)
@@ -211,10 +211,18 @@ void ctdl_vcard_to_ldap(struct CtdlMessage *msg) {
        int num_attrs = 0;
        int num_emails = 0;
        int alias_attr = (-1);
+       int num_phones = 0;
+       int phone_attr = (-1);
+       int have_addr = 0;
+       int have_cn = 0;
 
        char givenname[SIZ];
        char sn[SIZ];
        char uid[SIZ];
+       char street[SIZ];
+       char city[SIZ];
+       char state[SIZ];
+       char zipcode[SIZ];
 
        if (dirserver == NULL) return;
        if (msg == NULL) return;
@@ -250,23 +258,15 @@ void ctdl_vcard_to_ldap(struct CtdlMessage *msg) {
        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    = mallok(2 * 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;
+       */
+       attrs[0]->mod_values[1] = 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) {
@@ -276,6 +276,18 @@ void ctdl_vcard_to_ldap(struct CtdlMessage *msg) {
                        extract_token(givenname,        v->prop[i].value, 1, ';');
                }
 
+               if (!strcasecmp(v->prop[i].name, "fn")) {
+                       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(v->prop[i].value);
+                       attrs[num_attrs-1]->mod_values[1]       = NULL;
+                       have_cn = 1;
+               }
+
                if (!strcasecmp(v->prop[i].name, "title")) {
                        attrs = reallok(attrs, (sizeof(LDAPMod *) * ++num_attrs) );
                        attrs[num_attrs-1] = mallok(sizeof(LDAPMod));
@@ -287,6 +299,101 @@ void ctdl_vcard_to_ldap(struct CtdlMessage *msg) {
                        attrs[num_attrs-1]->mod_values[1]       = NULL;
                }
 
+               if (!strcasecmp(v->prop[i].name, "org")) {
+                       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            = "o";
+                       attrs[num_attrs-1]->mod_values          = mallok(2 * sizeof(char *));
+                       attrs[num_attrs-1]->mod_values[0]       = strdoop(v->prop[i].value);
+                       attrs[num_attrs-1]->mod_values[1]       = NULL;
+               }
+
+               if ( (!strcasecmp(v->prop[i].name, "adr"))
+                  ||(!strncasecmp(v->prop[i].name, "adr;", 4)) ) {
+                       /* Unfortunately, we can only do a single address */
+                       if (!have_addr) {
+                               have_addr = 1;
+                               strcpy(street, "");
+                               extract_token(&street[strlen(street)],
+                                       v->prop[i].value, 0, ';'); /* po box */
+                               strcat(street, " ");
+                               extract_token(&street[strlen(street)],
+                                       v->prop[i].value, 1, ';'); /* extend addr */
+                               strcat(street, " ");
+                               extract_token(&street[strlen(street)],
+                                       v->prop[i].value, 2, ';'); /* street */
+                               striplt(street);
+                               extract_token(city, v->prop[i].value, 3, ';');
+                               extract_token(state, v->prop[i].value, 4, ';');
+                               extract_token(zipcode, v->prop[i].value, 5, ';');
+
+                               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            = "street";
+                               attrs[num_attrs-1]->mod_values          = mallok(2 * sizeof(char *));
+                               attrs[num_attrs-1]->mod_values[0]       = strdoop(street);
+                               attrs[num_attrs-1]->mod_values[1]       = NULL;
+
+                               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            = "l";
+                               attrs[num_attrs-1]->mod_values          = mallok(2 * sizeof(char *));
+                               attrs[num_attrs-1]->mod_values[0]       = strdoop(city);
+                               attrs[num_attrs-1]->mod_values[1]       = NULL;
+
+                               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            = "st";
+                               attrs[num_attrs-1]->mod_values          = mallok(2 * sizeof(char *));
+                               attrs[num_attrs-1]->mod_values[0]       = strdoop(state);
+                               attrs[num_attrs-1]->mod_values[1]       = NULL;
+
+                               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            = "postalcode";
+                               attrs[num_attrs-1]->mod_values          = mallok(2 * sizeof(char *));
+                               attrs[num_attrs-1]->mod_values[0]       = strdoop(zipcode);
+                               attrs[num_attrs-1]->mod_values[1]       = NULL;
+                       }
+               }
+
+               if ( (!strcasecmp(v->prop[i].name, "tel"))
+                  ||(!strncasecmp(v->prop[i].name, "tel;", 4)) ) {
+                       ++num_phones;
+                       /* The first 'tel' property creates the 'telephoneNumber' attribute */
+                       if (num_phones == 1) {
+                               attrs = reallok(attrs, (sizeof(LDAPMod *) * ++num_attrs) );
+                               phone_attr = num_attrs-1;
+                               attrs[phone_attr] = mallok(sizeof(LDAPMod));
+                               memset(attrs[phone_attr], 0, sizeof(LDAPMod));
+                               attrs[phone_attr]->mod_op               = LDAP_MOD_ADD;
+                               attrs[phone_attr]->mod_type             = "telephoneNumber";
+                               attrs[phone_attr]->mod_values           = mallok(2 * sizeof(char *));
+                               attrs[phone_attr]->mod_values[0]        = strdoop(v->prop[i].value);
+                               attrs[phone_attr]->mod_values[1]        = NULL;
+                       }
+                       /* Subsequent 'tel' properties *add to* the 'telephoneNumber' attribute */
+                       else {
+                               attrs[phone_attr]->mod_values = reallok(attrs[phone_attr]->mod_values,
+                                                                    num_phones * sizeof(char *));
+                               attrs[phone_attr]->mod_values[num_phones-1]
+                                                                       = strdoop(v->prop[i].value);
+                               attrs[phone_attr]->mod_values[num_phones]
+                                                                       = NULL;
+                       }
+               }
+
+
                if ( (!strcasecmp(v->prop[i].name, "email"))
                   ||(!strcasecmp(v->prop[i].name, "email;internet")) ) {
        
@@ -362,6 +469,20 @@ void ctdl_vcard_to_ldap(struct CtdlMessage *msg) {
        attrs[num_attrs-1]->mod_values[0]       = strdoop(uid);
        attrs[num_attrs-1]->mod_values[1]       = NULL;
 
+       /* Add a "cn" (Common Name) attribute based on the user's screen name,
+        * but only there was no 'fn' (full name) property in the vCard 
+        */
+       if (!have_cn) {
+               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;
+       }
+       
        /* The last attribute must be a NULL one. */
        attrs = realloc(attrs, (sizeof(LDAPMod *) * ++num_attrs) );
        attrs[num_attrs - 1] = NULL;