By Harry Coin:
[citadel.git] / citadel / modules / vcard / serv_vcard.c
index dad28b8dd508f1d2ec7b8832e81eddb6f2b7c367..39820f7762dc7a821609c060995ec6ecb99c77c0 100644 (file)
@@ -441,18 +441,19 @@ int vcard_upload_beforesave(struct CtdlMessage *msg, recptypes *recp) {
                vcard_set_prop(v, "FBURL;PREF", buf, 0);
        }
 
                vcard_set_prop(v, "FBURL;PREF", buf, 0);
        }
 
-       /* If the vCard has no UID, then give it one. */
+
        s = vcard_get_prop(v, "UID", 1, 0, 0);
        s = vcard_get_prop(v, "UID", 1, 0, 0);
-       if (s == NULL) {
+       if (s == NULL) { /* Note LDAP auth sets UID from the LDAP UUID, use that if it exists. */
+         /* Enforce local UID policy if applicable */
+         if (yes_my_citadel_config) {
+               snprintf(buf, sizeof buf, VCARD_EXT_FORMAT, msg->cm_fields[eAuthor], NODENAME);
+         } else {
+               /* If the vCard has no UID, then give it one. */
                generate_uuid(buf);
                generate_uuid(buf);
-               vcard_set_prop(v, "UID", buf, 0);
-       }
+         }
+         vcard_set_prop(v, "UID", buf, 0);
+    }
 
 
-       /* Enforce local UID policy if applicable */
-       if (yes_my_citadel_config) {
-               snprintf(buf, sizeof buf, VCARD_EXT_FORMAT, msg->cm_fields[eAuthor], NODENAME);
-               vcard_set_prop(v, "UID", buf, 0);
-       }
 
        /* 
         * Set the EUID of the message to the UID of the vCard.
 
        /* 
         * Set the EUID of the message to the UID of the vCard.
@@ -849,7 +850,9 @@ void vcard_newuser(struct ctdluser *usbuf) {
        char buf[256];
        int i;
        struct vCard *v;
        char buf[256];
        int i;
        struct vCard *v;
+       int need_default_vcard;
 
 
+       need_default_vcard =1;
        vcard_fn_to_n(vname, usbuf->fullname, sizeof vname);
        syslog(LOG_DEBUG, "Converted <%s> to <%s>", usbuf->fullname, vname);
 
        vcard_fn_to_n(vname, usbuf->fullname, sizeof vname);
        syslog(LOG_DEBUG, "Converted <%s> to <%s>", usbuf->fullname, vname);
 
@@ -875,16 +878,11 @@ void vcard_newuser(struct ctdluser *usbuf) {
 #endif // HAVE_GETPWUID_R
                        snprintf(buf, sizeof buf, "%s@%s", pwd.pw_name, config.c_fqdn);
                        vcard_add_prop(v, "email;internet", buf);
 #endif // HAVE_GETPWUID_R
                        snprintf(buf, sizeof buf, "%s@%s", pwd.pw_name, config.c_fqdn);
                        vcard_add_prop(v, "email;internet", buf);
+                       need_default_vcard=0;
                }
        }
 #endif
 
                }
        }
 #endif
 
-       /* Everyone gets an email address based on their display name */
-       snprintf(buf, sizeof buf, "%s@%s", usbuf->fullname, config.c_fqdn);
-       for (i=0; buf[i]; ++i) {
-               if (buf[i] == ' ') buf[i] = '_';
-       }
-       vcard_add_prop(v, "email;internet", buf);
 
 #ifdef HAVE_LDAP
        /*
 
 #ifdef HAVE_LDAP
        /*
@@ -892,20 +890,29 @@ void vcard_newuser(struct ctdluser *usbuf) {
         * into the user's vCard.
         */
        if ((config.c_auth_mode == AUTHMODE_LDAP) || (config.c_auth_mode == AUTHMODE_LDAP_AD)) {
         * into the user's vCard.
         */
        if ((config.c_auth_mode == AUTHMODE_LDAP) || (config.c_auth_mode == AUTHMODE_LDAP_AD)) {
-            uid_t ldap_uid;
+            //uid_t ldap_uid;
            int found_user;
             char ldap_cn[512];
             char ldap_dn[512];
            int found_user;
             char ldap_cn[512];
             char ldap_dn[512];
-           found_user = CtdlTryUserLDAP(usbuf->fullname, ldap_dn, sizeof ldap_dn, ldap_cn, sizeof ldap_cn, &ldap_uid);
+           found_user = CtdlTryUserLDAP(usbuf->fullname, ldap_dn, sizeof ldap_dn, ldap_cn, sizeof ldap_cn, &usbuf->uid,1);
             if (found_user == 0) {
                if (Ctdl_LDAP_to_vCard(ldap_dn, v)) {
                        /* Allow global address book and internet directory update without login long enough to write this. */
                        CC->vcard_updated_by_ldap++;  /* Otherwise we'll only update the user config. */
             if (found_user == 0) {
                if (Ctdl_LDAP_to_vCard(ldap_dn, v)) {
                        /* Allow global address book and internet directory update without login long enough to write this. */
                        CC->vcard_updated_by_ldap++;  /* Otherwise we'll only update the user config. */
+                       need_default_vcard=0;
                        syslog(LOG_DEBUG, "LDAP Created Initial Vcard for %s\n",usbuf->fullname);
                }
            }
        }
 #endif
                        syslog(LOG_DEBUG, "LDAP Created Initial Vcard for %s\n",usbuf->fullname);
                }
            }
        }
 #endif
+       if (need_default_vcard!=0) {
+         /* Everyone gets an email address based on their display name */
+         snprintf(buf, sizeof buf, "%s@%s", usbuf->fullname, config.c_fqdn);
+         for (i=0; buf[i]; ++i) {
+               if (buf[i] == ' ') buf[i] = '_';
+         }
+         vcard_add_prop(v, "email;internet", buf);
+    }
 
        vcard_write_user(usbuf, v);
        vcard_free(v);
 
        vcard_write_user(usbuf, v);
        vcard_free(v);