From e96b8a7ee7627f35d18722616f030101c149cb2a Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Sun, 17 Feb 2008 02:00:15 +0000 Subject: [PATCH] The fix to Bug 311 didn't work. Applied a cleaner fix. --- citadel/modules/vcard/serv_vcard.c | 43 ++++++++++++++---------------- citadel/serv_vcard.h | 1 - citadel/user_ops.c | 20 -------------- 3 files changed, 20 insertions(+), 44 deletions(-) diff --git a/citadel/modules/vcard/serv_vcard.c b/citadel/modules/vcard/serv_vcard.c index a3b0fc46c..00411d6d7 100644 --- a/citadel/modules/vcard/serv_vcard.c +++ b/citadel/modules/vcard/serv_vcard.c @@ -968,25 +968,6 @@ void cmd_greg(char *argbuf) - - -/* - * Add an email alias to a users vcard - */ - -void vcard_add_alias(struct ctdluser *usbuf, char *addr) -{ - struct vCard *v; - - v = vcard_get_user(usbuf); - vcard_add_prop(v, "email;internet", addr); - vcard_write_user(usbuf, v); - vcard_free(v); -} - - - - /* * When a user is being created, create his/her vCard. */ @@ -1002,14 +983,30 @@ void vcard_newuser(struct ctdluser *usbuf) { /* Create and save the vCard */ v = vcard_new(); if (v == NULL) return; - sprintf(buf, "%s@%s", usbuf->fullname, config.c_fqdn); - for (i=0; buf[i]; ++i) { - if (buf[i] == ' ') buf[i] = '_'; - } vcard_add_prop(v, "fn", usbuf->fullname); vcard_add_prop(v, "n", vname); vcard_add_prop(v, "adr", "adr:;;_;_;_;00000;__"); + + /* If using host auth mode, we add an email address based on the login */ + if (config.c_auth_mode == AUTHMODE_HOST) { + struct passwd pwd; + struct passwd **result; + char pwd_buffer[SIZ]; + + if (getpwuid_r(usbuf->uid, &pwd, pwd_buffer, sizeof pwd_buffer, result) == 0) { + snprintf(buf, sizeof buf, "%s@%s", pwd.pw_name, config.c_fqdn); + vcard_add_prop(v, "email;internet", buf); + } + } + + /* 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); } diff --git a/citadel/serv_vcard.h b/citadel/serv_vcard.h index 22077653e..003b8d3d7 100644 --- a/citadel/serv_vcard.h +++ b/citadel/serv_vcard.h @@ -9,4 +9,3 @@ enum { V2L_DELETE }; -void vcard_add_alias(struct ctdluser *usbuf, char *addr); diff --git a/citadel/user_ops.c b/citadel/user_ops.c index 79bbb9a07..7f84fa21e 100644 --- a/citadel/user_ops.c +++ b/citadel/user_ops.c @@ -50,7 +50,6 @@ #include "citadel_dirs.h" #include "genstamp.h" #include "threads.h" -#include "serv_vcard.h" /* FIXME: Get this dependancy out. Needed for vcard_add_alias */ /* These pipes are used to talk to the chkpwd daemon, which is forked during startup */ int chkpwd_write_pipe[2]; @@ -874,8 +873,6 @@ int purge_user(char pname[]) } - - /* * create_user() - back end processing to create a new user * @@ -980,23 +977,6 @@ int create_user(char *newusername, int become_user) /* Perform any create functions registered by server extensions */ PerformUserHooks(&usbuf, EVT_NEWUSER); - /* In host auth mode the user was created with an email address of the users - * full name from the passwd gecos field. - * Not sure what would have happened if that wasn't set to something - * but thats another story - * We need to add an email alias to the users vCard for the proper username - */ - if (config.c_auth_mode == AUTHMODE_HOST) - { - char user_alias[SIZ]; - - if (strcmp(username, newusername)) - { - sprintf(user_alias, "%s@%s", newusername, config.c_fqdn); - vcard_add_alias(&usbuf, user_alias); - } - } - /* Everything below this line can be bypassed if administratively * creating a user, instead of doing self-service account creation */ -- 2.30.2