From: Art Cancro Date: Thu, 20 Dec 2018 19:54:48 +0000 (-0500) Subject: Auto-generated email address is now derived from the screen name. Fall back to other... X-Git-Tag: v939~323 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=8db8def130c7e0b01dfce85aa2bc207e22188b94 Auto-generated email address is now derived from the screen name. Fall back to other methods if that address already exists. --- diff --git a/citadel/internet_addressing.c b/citadel/internet_addressing.c index 90dd55a57..74f69493f 100644 --- a/citadel/internet_addressing.c +++ b/citadel/internet_addressing.c @@ -1519,7 +1519,9 @@ int CtdlDirectoryLookup(char *target, char *internet_addr, size_t targbuflen) { char key[SIZ]; /* Dump it in there unchanged, just for kicks */ - safestrncpy(target, internet_addr, targbuflen); + if (target != NULL) { + safestrncpy(target, internet_addr, targbuflen); + } /* Only do lookups for addresses with hostnames in them */ if (num_tokens(internet_addr, '@') != 2) return(-1); @@ -1530,7 +1532,9 @@ int CtdlDirectoryLookup(char *target, char *internet_addr, size_t targbuflen) { directory_key(key, internet_addr); cdbrec = cdb_fetch(CDB_DIRECTORY, key, strlen(key) ); if (cdbrec != NULL) { - safestrncpy(target, cdbrec->ptr, targbuflen); + if (target != NULL) { + safestrncpy(target, cdbrec->ptr, targbuflen); + } cdb_free(cdbrec); return(0); } @@ -1716,7 +1720,31 @@ void CtdlSetEmailAddressesForUser(char *requested_user, char *new_emailaddrs) void AutoGenerateEmailAddressForUser(struct ctdluser *user) { char synthetic_email_addr[1024]; - snprintf(synthetic_email_addr, sizeof synthetic_email_addr, "ctdl%08lx@%s", user->usernum, CtdlGetConfigStr("c_fqdn")); + int i, j; + int u = 0; + + for (i=0; u==0; ++i) { + if (i == 0) { + // first try just converting the user name to lowercase and replacing spaces with underscores + snprintf(synthetic_email_addr, sizeof synthetic_email_addr, "%s@%s", user->fullname, CtdlGetConfigStr("c_fqdn")); + for (j=0; ((synthetic_email_addr[j] != '\0')&&(synthetic_email_addr[j] != '@')); j++) { + synthetic_email_addr[j] = tolower(synthetic_email_addr[j]); + if (!isalnum(synthetic_email_addr[j])) { + synthetic_email_addr[j] = '_'; + } + } + } + else if (i == 1) { + // then try 'ctdl' followed by the user number + snprintf(synthetic_email_addr, sizeof synthetic_email_addr, "ctdl%08lx@%s", user->usernum, CtdlGetConfigStr("c_fqdn")); + } + else if (i > 1) { + // oof. just keep trying other numbers until we find one + snprintf(synthetic_email_addr, sizeof synthetic_email_addr, "ctdl%08x@%s", i, CtdlGetConfigStr("c_fqdn")); + } + u = CtdlDirectoryLookup(NULL, synthetic_email_addr, 0); + } + CtdlSetEmailAddressesForUser(user->fullname, synthetic_email_addr); strncpy(CC->user.emailaddrs, synthetic_email_addr, sizeof(user->emailaddrs)); syslog(LOG_DEBUG, "user_ops: auto-generated email address <%s> for <%s>", synthetic_email_addr, user->fullname); diff --git a/citadel/user_ops.c b/citadel/user_ops.c index 607f16b3a..dab7f296b 100644 --- a/citadel/user_ops.c +++ b/citadel/user_ops.c @@ -717,7 +717,7 @@ void CtdlUserLogout(void) strcpy(CCC->fake_roomname, ""); CCC->logged_in = 0; - /* Check to see if the user was deleted whilst logged in and purge them if necessary */ + /* Check to see if the user was deleted while logged in and purge them if necessary */ if ((CCC->user.axlevel == AxDeleted) && (CCC->user.usernum)) { purge_user(CCC->user.fullname); } @@ -938,8 +938,9 @@ int purge_user(char pname[]) makeuserkey(usernamekey, pname, cutuserkey(pname)); /* If the name is empty we can't find them in the DB any way so just return */ - if (IsEmptyStr(pname)) + if (IsEmptyStr(pname)) { return(ERROR + NO_SUCH_USER); + } if (CtdlGetUser(&usbuf, pname) != 0) { syslog(LOG_ERR, "user_ops: cannot purge user <%s> - not found", pname);