jcs
/subtext
/amendments
/133
sysop: Add support for deleting users
jcs made amendment 133 over 2 years ago
--- mail.c Fri Jun 3 21:11:58 2022
+++ mail.c Tue Jun 7 22:57:36 2022
@@ -610,7 +610,7 @@ mail_find_ids_for_user(struct user *user, size_t *nmai
*mail_ids = xmalloc(mail_ids_size);
if (nmail_ids != NULL)
*nmail_ids = 0;
-
+
nmsgs_for_user = 0;
for (n = 0; o = bile_get_nth_of_type(db->bile, n, DB_MESSAGE_RTYPE);
n++) {
--- sysop.c Tue Jun 7 14:23:43 2022
+++ sysop.c Wed Jun 8 10:31:15 2022
@@ -371,8 +371,8 @@ void
sysop_edit_user(struct session *s, unsigned long id)
{
static struct session_menu_option opts[] = {
- { 'd', "Dd", "Disable account" },
- { 'e', "Ee", "Enable account" },
+ { 'd', "Dd", "Delete account" },
+ { 'e', "Ee", "Enable/disable account" },
{ 'p', "Pp", "Change password" },
{ 's', "Ss", "Toggle sysop flag" },
{ 'q', "QqXx", "Return to users menu" },
@@ -406,11 +406,24 @@ sysop_edit_user(struct session *s, unsigned long id)
handle_opt:
switch (c) {
case 'd':
- user.is_enabled = 0;
- user_save(&user);
+ session_printf(s, "Are you sure you want to permanently "
+ "delete {{B}}%s{{/B}}? [y/N] ", user.username);
+ session_flush(s);
+
+ cc = session_input_char(s);
+ if (cc == 'y' || c == 'Y') {
+ session_printf(s, "%c\r\n", cc);
+ session_flush(s);
+ user_delete(&user);
+ session_printf(s, "\r\n{{B}}User deleted!{{/B}}\r\n");
+ done = true;
+ } else {
+ session_printf(s, "\r\nUser not deleted.\r\n");
+ session_flush(s);
+ }
break;
case 'e':
- user.is_enabled = 1;
+ user.is_enabled = !user.is_enabled;
user_save(&user);
break;
case 'p':
--- user.c Tue Jun 7 12:23:37 2022
+++ user.c Wed Jun 8 10:39:02 2022
@@ -376,4 +376,33 @@ user_change_password(struct session *s, struct user *u
free(password);
if (password_confirm != NULL)
free(password_confirm);
-}
+}
+
+void
+user_delete(struct user *user)
+{
+ struct bile_object *o;
+ unsigned long msg_user_id, id;
+ size_t n;
+
+ /* delete the user's mail */
+ n = 0;
+ while (o = bile_get_nth_of_type(db->bile, n, DB_MESSAGE_RTYPE)) {
+ id = o->id;
+ bile_read(db->bile, DB_MESSAGE_RTYPE, id, (char *)&msg_user_id,
+ sizeof(msg_user_id));
+ free(o);
+
+ if (msg_user_id != user->id) {
+ n++;
+ continue;
+ }
+
+ bile_delete(db->bile, DB_MESSAGE_RTYPE, id);
+
+ /* don't increase n, the remaining messages will shift down */
+ }
+
+ /* delete the user */
+ bile_delete(db->bile, DB_USER_RTYPE, user->id);
+}
--- user.h Tue Jun 7 15:36:26 2022
+++ user.h Wed Jun 8 10:38:23 2022
@@ -52,5 +52,6 @@ void user_set_password(struct user *user, const char *
short user_valid_username(struct user *user, char *username, char **error);
char * user_first_sysop_username(void);
void user_change_password(struct session *s, struct user *user);
+void user_delete(struct user *user);
#endif