X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fuser_ops.c;h=7d4088c56fb20c023eeb724f2d8fd5fcfc8fbfee;hb=da1debddf5988512ac50ff0b62ac85c8f3b8d0f4;hp=5e0219f53f4fd14565e61ff38164740a11c3788c;hpb=f1ee61891901850ebbdee1e9440b363dc6df540a;p=citadel.git diff --git a/citadel/user_ops.c b/citadel/user_ops.c index 5e0219f53..7d4088c56 100644 --- a/citadel/user_ops.c +++ b/citadel/user_ops.c @@ -3,9 +3,9 @@ * * Copyright (c) 1987-2011 by the citadel.org team * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or + * This program is open source software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "sysdep.h" @@ -712,40 +712,42 @@ void cmd_user(char *cmdbuf) */ void do_login(void) { - CC->logged_in = 1; - syslog(LOG_NOTICE, "<%s> logged in\n", CC->curr_user); + struct CitContext *CCC = CC; - CtdlGetUserLock(&CC->user, CC->curr_user); - ++(CC->user.timescalled); - CC->previous_login = CC->user.lastcall; - time(&CC->user.lastcall); + CCC->logged_in = 1; + syslog(LOG_NOTICE, "<%s> logged in\n", CCC->curr_user); + + CtdlGetUserLock(&CCC->user, CCC->curr_user); + ++(CCC->user.timescalled); + CCC->previous_login = CCC->user.lastcall; + time(&CCC->user.lastcall); /* If this user's name is the name of the system administrator * (as specified in setup), automatically assign access level 6. */ - if (!strcasecmp(CC->user.fullname, config.c_sysadm)) { - CC->user.axlevel = AxAideU; + if (!strcasecmp(CCC->user.fullname, config.c_sysadm)) { + CCC->user.axlevel = AxAideU; } /* If we're authenticating off the host system, automatically give * root the highest level of access. */ if (config.c_auth_mode == AUTHMODE_HOST) { - if (CC->user.uid == 0) { - CC->user.axlevel = AxAideU; + if (CCC->user.uid == 0) { + CCC->user.axlevel = AxAideU; } } - CtdlPutUserLock(&CC->user); + CtdlPutUserLock(&CCC->user); /* - * Populate CC->cs_inet_email with a default address. This will be + * Populate CCC->cs_inet_email with a default address. This will be * overwritten with the user's directory address, if one exists, when * the vCard module's login hook runs. */ - snprintf(CC->cs_inet_email, sizeof CC->cs_inet_email, "%s@%s", - CC->user.fullname, config.c_fqdn); - convert_spaces_to_underscores(CC->cs_inet_email); + snprintf(CCC->cs_inet_email, sizeof CCC->cs_inet_email, "%s@%s", + CCC->user.fullname, config.c_fqdn); + convert_spaces_to_underscores(CCC->cs_inet_email); /* Create any personal rooms required by the system. * (Technically, MAILROOM should be there already, but just in case...) @@ -774,18 +776,14 @@ void logged_in_response(void) -/* - * misc things to be taken care of when a user is logged out - */ -void logout(void) -{ - CtdlUserLogout(); -} - - void CtdlUserLogout(void) { CitContext *CCC = MyContext(); + + syslog(LOG_DEBUG, "CtdlUserLogout() logging out <%s> from session %d", + CCC->curr_user, CCC->cs_pid + ); + /* * If there is a download in progress, abort it. */ @@ -805,7 +803,7 @@ void CtdlUserLogout(void) * If we were talking to a network node, we're not anymore... */ if (!IsEmptyStr(CCC->net_node)) { - network_talking_to(CCC->net_node, NTT_REMOVE); + network_talking_to(CCC->net_node, strlen(CCC->net_node), NTT_REMOVE); } /* Run any hooks registered by modules... */ @@ -828,6 +826,15 @@ void CtdlUserLogout(void) /* Clear out the user record in memory so we don't behave like a ghost */ memset(&CCC->user, 0, sizeof(struct ctdluser)); + CCC->curr_user[0] = 0; + CCC->is_master = 0; + CCC->cs_inet_email[0] = 0; + CCC->cs_inet_other_emails[0] = 0; + CCC->cs_inet_fn[0] = 0; + CCC->fake_username[0] = 0; + CCC->fake_hostname[0] = 0; + CCC->fake_roomname[0] = 0; + /* Free any output buffers */ unbuffer_output(); @@ -851,8 +858,23 @@ static int validpw(uid_t uid, const char *pass) begin_critical_section(S_CHKPWD); rv = write(chkpwd_write_pipe[1], &uid, sizeof(uid_t)); + if (rv == -1) { + syslog(LOG_EMERG, "Communicatino with chkpwd broken: %s\n", strerror(errno)); + end_critical_section(S_CHKPWD); + return 0; + } rv = write(chkpwd_write_pipe[1], pass, 256); + if (rv == -1) { + syslog(LOG_EMERG, "Communicatino with chkpwd broken: %s\n", strerror(errno)); + end_critical_section(S_CHKPWD); + return 0; + } rv = read(chkpwd_read_pipe[0], buf, 4); + if (rv == -1) { + syslog(LOG_EMERG, "Communicatino with chkpwd broken: %s\n", strerror(errno)); + end_critical_section(S_CHKPWD); + return 0; + } end_critical_section(S_CHKPWD); if (!strncmp(buf, "PASS", 4)) { @@ -1255,7 +1277,7 @@ void cmd_newu(char *cmdbuf) { int a; long len; - char username[26]; + char username[SIZ]; if (config.c_auth_mode != AUTHMODE_NATIVE) { cprintf("%d This system does not use native mode authentication.\n", @@ -1330,8 +1352,6 @@ void CtdlSetPassword(char *new_pw) */ void cmd_setp(char *new_pw) { - int generate_random_password = 0; - if (CtdlAccessCheck(ac_logged_in)) { return; } @@ -1347,7 +1367,6 @@ void cmd_setp(char *new_pw) if (!strcasecmp(new_pw, "GENERATE_RANDOM_PASSWORD")) { char random_password[17]; - generate_random_password = 1; snprintf(random_password, sizeof random_password, "%08lx%08lx", random(), random()); CtdlSetPassword(random_password); cprintf("%d %s\n", CIT_OK, random_password); @@ -1380,17 +1399,16 @@ void cmd_creu(char *cmdbuf) } extract_token(username, cmdbuf, 0, '|', sizeof username); - extract_token(password, cmdbuf, 1, '|', sizeof password); - ////username[25] = 0; - //password[31] = 0; strproc(username); strproc(password); - len = cutuserkey(username); - if (IsEmptyStr(username)) { cprintf("%d You must supply a user name.\n", ERROR + USERNAME_REQUIRED); return; } + len = cutuserkey(username); + + + extract_token(password, cmdbuf, 1, '|', sizeof password); a = create_user(username, len, 0);