jcs
/subtext
/amendments
/562
user: Add user_first_sysop_id()
The username can be found from this, but just returning a username
is harder to find an id for.
jcs made amendment 562 about 1 year ago
--- console.c Sun Nov 19 10:49:40 2023
+++ console.c Thu Nov 23 11:03:22 2023
@@ -62,9 +62,10 @@ struct console *
console_init(void)
{
char title[64];
- char *sysop_username = NULL;
struct console *console;
struct focusable *focusable;
+ struct username_cache *ucache = NULL;
+ unsigned long sysop_id;
Rect bounds;
short width, height;
@@ -135,11 +136,10 @@ console_init(void)
console->session->vt100 = 1;
console->session->tspeed = 19200;
- if ((sysop_username = user_first_sysop_username()) != NULL) {
- strlcpy(console->session->autologin_username, sysop_username,
+ sysop_id = user_first_sysop_id();
+ if (sysop_id && (ucache = user_username(sysop_id)) != NULL)
+ strlcpy(console->session->autologin_username, ucache->username,
sizeof(console->session->autologin_username));
- xfree(&sysop_username);
- }
return console;
}
--- user.c Fri Mar 3 13:58:47 2023
+++ user.c Thu Nov 23 10:59:01 2023
@@ -299,12 +299,11 @@ user_username_is_banned(char *username)
return false;
}
-char *
-user_first_sysop_username(void)
+unsigned long
+user_first_sysop_id(void)
{
struct user user;
struct bile_object *o;
- char *ret = NULL;
size_t nuser;
nuser = 0;
@@ -312,14 +311,12 @@ user_first_sysop_username(void)
bile_read(db->bile, DB_USER_RTYPE, o->id, (char *)&user,
sizeof(user));
xfree(&o);
- if (user.is_sysop) {
- ret = xstrdup(user.username);
- break;
- }
+ if (user.is_sysop)
+ return user.id;
nuser++;
}
- return ret;
+ return 0;
}
void
--- user.h Wed Mar 1 17:39:06 2023
+++ user.h Thu Nov 23 10:58:51 2023
@@ -52,7 +52,7 @@ short user_authenticate(struct user *user, const char
bool user_set_password(struct user *user, const char *password);
bool user_valid_username(struct user *user, char *username, char **error);
bool user_username_is_banned(char *username);
-char * user_first_sysop_username(void);
+unsigned long user_first_sysop_id(void);
void user_change_password(struct session *s, struct user *user);
void user_delete(struct user *user);