Renamed cutuserkey() to cutusername(). Function has nothing to do with keys.
[citadel.git] / citadel / user_ops.c
index 397907524e91c04d91a5f8dd4930be81cc4307d7..c5eeabd2cbca8bd9fec607d7d10fc542f15af69d 100644 (file)
@@ -1,7 +1,7 @@
 /* 
  * 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.
@@ -32,6 +32,41 @@ int chkpwd_write_pipe[2];
 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
@@ -40,7 +75,7 @@ int CtdlGetUser(struct ctdluser *usbuf, char *name)
 {
        char usernamekey[USERNAME_SIZE];
        struct cdbdata *cdbus;
-       long len = cutuserkey(name);
+       long len = cutusername(name);
 
        if (usbuf != NULL) {
                memset(usbuf, 0, sizeof(struct ctdluser));
@@ -89,7 +124,7 @@ void CtdlPutUser(struct ctdluser *usbuf)
 {
        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));
 }
@@ -125,8 +160,8 @@ int rename_user(char *oldname, char *newname) {
        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);
@@ -700,9 +735,6 @@ void CtdlUserLogout(void)
         * 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 */
@@ -716,9 +748,6 @@ void CtdlUserLogout(void)
        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();
@@ -918,7 +947,7 @@ int purge_user(char pname[])
        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)) {