[mw-devel] [Git][arthur/mw][master] Fix new user logins
Andrew Price
welshbyte at sucs.org
Thu Jan 14 12:39:59 GMT 2016
Andrew Price pushed to branch master at Justin Mitchell / mw
Commits:
7e8ca22f by Andrew Price at 2016-01-14T12:27:40Z
Fix new user logins
In main(), login_ok() was being called before ipc_connect() but when a
new user is created, the login_ok() call leads to a broadcast() call
which attempts to reconnect to the server through ipc_check() and fails
because ipc_connect() hasn't set the server location yet. This bug has
been lurking for a while but it has only recently turned into a segfault
due to the NULL server location. Move the broadcast() calls to come
after the ipc_connect() for now.
- - - - -
3 changed files:
- src/client/main.c
- src/client/user.c
- src/client/user.h
Changes:
=====================================
src/client/main.c
=====================================
--- a/src/client/main.c
+++ b/src/client/main.c
@@ -581,7 +581,7 @@ int main(int argc, char **argv)
printf("%s\n",version);
/* log the user in by asking for their name (and details) */
- login_ok(user, &autochat);
+ int login_status = login_ok(user, &autochat);
if (!access(LOCKFILE,00))
{
@@ -602,6 +602,15 @@ int main(int argc, char **argv)
if (ipc_connect(targethost, user) < 0)
exit(1);
+
+ /* Now that we have a connection, announce the new user (if new) */
+ if (login_status >= 2) /* New user */
+ broadcast(3, "Created user %s: %s <%s>", user->record.name,
+ user->record.realname,
+ user->record.contact);
+ if (login_status == 3) /* Autoregistered */
+ broadcast(3, "Auto-registered %s", user->record.name);
+
if ((s_quiet(user) || u_god(user)) && qflag)
{
extern int talker_logontype;
=====================================
src/client/user.c
=====================================
--- a/src/client/user.c
+++ b/src/client/user.c
@@ -70,7 +70,7 @@ static int old_usr(struct user *usr)
exit(0);
}
printf(_("Hello %s.\n"), usr->record.name);
- return(true);
+ return 1;
}
void strip_name(char *string)
@@ -133,12 +133,13 @@ void pick_salt(char *salt)
strcpy(salt,"ab");
}
-static void set_defaults(struct person *tmp)
+static int set_defaults(struct person *tmp)
{
int i, n;
struct folder f;
struct Header head;
long curtime = time(NULL);
+ int ret = 0;
/* set default colour scheme. wont effect users if they dont have colour on, obviously */
tmp->colour=0;
@@ -225,8 +226,9 @@ MAX OF 10 MESSAGES IN THE LAST 2 WEEKS
tmp->chatprivs|=CP_SCRIPT;
}
mwlog("AUTOREGISTER %s",getmylogin());
- broadcast(3, "AutoRegister for %s",getmylogin());
+ ret = 1; /* Autoregistered */
}
+ return ret;
}
static int new_usr(char *name, struct user *u)
@@ -284,28 +286,34 @@ static int new_usr(char *name, struct user *u)
strip_str(usr->contact);
mwlog("CREATED: %s <%s>",usr->realname, usr->contact);
- broadcast(3, "Created user %s: %s <%s>", name, usr->realname, usr->contact);
- set_defaults(usr);
+
+ int ret = 2; /* New user */
+ ret += set_defaults(usr);
printf(_("Creating new user %s\n"),name);
userdb_write(u);
- return(true);
+ return ret;
}
- else return(false);
+ else return 0;
}
-void login_ok(struct user *usr, int *autochat)
+/**
+ * Returns: 1: Existing user
+ * 2: New user
+ * 3: New user, autoregistered
+ */
+int login_ok(struct user *usr, int *autochat)
{
- /* main function */
char name[NAMESIZE+1];
- int okay;
+ int ret = 0;
do{
get_login(name, *autochat);
if(user_exists(name, usr))
- okay=old_usr(usr);
+ ret = old_usr(usr);
else
- okay=new_usr(name, usr);
- }while (!okay);
+ ret = new_usr(name, usr);
+ } while (!ret);
+ return ret;
}
void list_users(int newonly)
=====================================
src/client/user.h
=====================================
--- a/src/client/user.h
+++ b/src/client/user.h
@@ -8,7 +8,7 @@ char *getmylogin(void);
void get_login(char *name, int autochat);
void list_users(int newonly);
void list_users_since(long date);
-void login_ok(struct user *usr, int *autochat);
+int login_ok(struct user *usr, int *autochat);
void strip_name(char *string);
void pick_salt(char *salt);
void search(const char *args, const char *ptr);
View it on GitLab: https://projects.sucs.org/arthur/mw/commit/7e8ca22f21aa9cc2776aa169c260e96572beab96
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sucs.org/pipermail/mw-devel/attachments/20160114/585af21c/attachment.html>
More information about the mw-devel
mailing list