/*
* Server functions which perform operations on user objects.
*
- * Copyright (c) 1987-2018 by the citadel.org team
+ * Copyright (c) 1987-2019 by the citadel.org team
*
* This program is open source software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, version 3.
int chkpwd_read_pipe[2];
+
+/*
+ * Trim a string down to the maximum username size and return the new length
+ */
+long cutusername(char *username) {
+ long len;
+ len = strlen(username);
+ if (len >= USERNAME_SIZE)
+ {
+ syslog(LOG_INFO, "Username too long: %s", username);
+ len = USERNAME_SIZE - 1;
+ username[len]='\0';
+ }
+ return len;
+}
+
+
+/*
+ * makeuserkey() - convert a username into the format used as a database key
+ * (it's just the username converted into lower case)
+ */
+void makeuserkey(char *key, const char *username, long len) {
+ int i;
+
+ if (len >= USERNAME_SIZE)
+ {
+ syslog(LOG_INFO, "Username too long: %s", username);
+ len = USERNAME_SIZE - 1;
+ }
+ for (i=0; i<=len; ++i) {
+ key[i] = tolower(username[i]);
+ }
+}
+
+
/*
* CtdlGetUser() retrieve named user into supplied buffer.
* returns 0 on success
{
char usernamekey[USERNAME_SIZE];
struct cdbdata *cdbus;
- long len = cutuserkey(name);
+ long len = cutusername(name);
if (usbuf != NULL) {
memset(usbuf, 0, sizeof(struct ctdluser));
{
char usernamekey[USERNAME_SIZE];
- makeuserkey(usernamekey, usbuf->fullname, cutuserkey(usbuf->fullname));
+ makeuserkey(usernamekey, usbuf->fullname, cutusername(usbuf->fullname));
usbuf->version = REV_LEVEL;
cdb_store(CDB_USERS, usernamekey, strlen(usernamekey), usbuf, sizeof(struct ctdluser));
}
char newnamekey[USERNAME_SIZE];
/* Create the database keys... */
- makeuserkey(oldnamekey, oldname, cutuserkey(oldname));
- makeuserkey(newnamekey, newname, cutuserkey(newname));
+ makeuserkey(oldnamekey, oldname, cutusername(oldname));
+ makeuserkey(newnamekey, newname, cutusername(newname));
/* Lock up and get going */
begin_critical_section(S_USERS);
* since it's possible to log in again without reconnecting, we cannot
* make that assumption.
*/
- strcpy(CCC->fake_username, "");
- strcpy(CCC->fake_hostname, "");
- strcpy(CCC->fake_roomname, "");
CCC->logged_in = 0;
/* Check to see if the user was deleted while logged in and purge them if necessary */
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();
struct ctdluser usbuf;
char usernamekey[USERNAME_SIZE];
- makeuserkey(usernamekey, pname, cutuserkey(pname));
+ makeuserkey(usernamekey, pname, cutusername(pname));
/* If the name is empty we can't find them in the DB any way so just return */
if (IsEmptyStr(pname)) {