+ /* If we are using LDAP authentication, extract the user's email addresses from the directory. */
+#ifdef HAVE_LDAP
+ if ((CtdlGetConfigInt("c_auth_mode") == AUTHMODE_LDAP) || (CtdlGetConfigInt("c_auth_mode") == AUTHMODE_LDAP_AD)) {
+ char new_emailaddrs[512];
+ if (CtdlGetConfigInt("c_ldap_sync_email_addrs") > 0) {
+ if (extract_email_addresses_from_ldap(CC->ldap_dn, new_emailaddrs) == 0) {
+ CtdlSetEmailAddressesForUser(CC->user.fullname, new_emailaddrs);
+ }
+ }
+ }
+#endif
+
+ /* If the user does not have any email addresses assigned, generate one. */
+ if (IsEmptyStr(CC->user.emailaddrs)) {
+ char synthetic_email_addr[1024];
+ snprintf(synthetic_email_addr, sizeof synthetic_email_addr, "ctdl%08lx@%s", CC->user.usernum, CtdlGetConfigStr("c_fqdn"));
+ CtdlSetEmailAddressesForUser(CC->user.fullname, synthetic_email_addr);
+ strncpy(CC->user.emailaddrs, synthetic_email_addr, sizeof(CC->user.emailaddrs));
+ syslog(LOG_DEBUG, "user_ops: auto-generated email address <%s> for <%s>", synthetic_email_addr, CC->user.fullname);
+ }