<html lang='en'>
<head>
<meta content='text/html; charset=utf-8' http-equiv='Content-Type'>
<title>
GitLab
</title>
</meta>
</head>
<style>
  img {
    max-width: 100%;
    height: auto;
  }
  p.details {
    font-style:italic;
    color:#777
  }
  .footer p {
    font-size:small;
    color:#777
  }
  pre.commit-message {
    white-space: pre-wrap;
  }
  .file-stats a {
    text-decoration: none;
  }
  .file-stats .new-file {
    color: #090;
  }
  .file-stats .deleted-file {
    color: #B00;
  }
</style>
<body>
<div class='content'>
<h3>Andrew Price pushed to branch master at <a href="https://projects.sucs.org/arthur/mw">Justin Mitchell / mw</a></h3>
<h4>
Commits:
</h4>
<ul>
<li>
<strong><a href="https://projects.sucs.org/arthur/mw/commit/7e8ca22f21aa9cc2776aa169c260e96572beab96">7e8ca22f</a></strong>
<div>
<span>by Andrew Price</span>
<i>at 2016-01-14T12:27:40Z</i>
</div>
<pre class='commit-message'>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.</pre>
</li>
</ul>
<h4>3 changed files:</h4>
<ul>
<li class='file-stats'>
<a href='#diff-0'>
src/client/main.c
</a>
</li>
<li class='file-stats'>
<a href='#diff-1'>
src/client/user.c
</a>
</li>
<li class='file-stats'>
<a href='#diff-2'>
src/client/user.h
</a>
</li>
</ul>
<h4>Changes:</h4>
<li id='diff-0'>
<a href='https://projects.sucs.org/arthur/mw/commit/7e8ca22f21aa9cc2776aa169c260e96572beab96#diff-0'>
<strong>
src/client/main.c
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/src/client/main.c
</span><span style="color: #000000;background-color: #ddffdd">+++ b/src/client/main.c
</span><span style="color: #aaaaaa">@@ -581,7 +581,7 @@ int main(int argc, char **argv)
</span>   printf("%s\n",version);
 
        /* log the user in by asking for their name (and details) */
<span style="color: #000000;background-color: #ffdddd">-        login_ok(user, &autochat);
</span><span style="color: #000000;background-color: #ddffdd">+   int login_status = login_ok(user, &autochat);
</span> 
        if (!access(LOCKFILE,00))
        {
<span style="color: #aaaaaa">@@ -602,6 +602,15 @@ int main(int argc, char **argv)
</span> 
        if (ipc_connect(targethost, user) < 0)
                exit(1);
<span style="color: #000000;background-color: #ddffdd">+
+       /* 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);
+
</span>   if ((s_quiet(user) || u_god(user)) && qflag)
        {
                extern int talker_logontype;
</code></pre>

<br>
</li>
<li id='diff-1'>
<a href='https://projects.sucs.org/arthur/mw/commit/7e8ca22f21aa9cc2776aa169c260e96572beab96#diff-1'>
<strong>
src/client/user.c
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/src/client/user.c
</span><span style="color: #000000;background-color: #ddffdd">+++ b/src/client/user.c
</span><span style="color: #aaaaaa">@@ -70,7 +70,7 @@ static int old_usr(struct user *usr)
</span>           exit(0);
        }
        printf(_("Hello %s.\n"), usr->record.name);
<span style="color: #000000;background-color: #ffdddd">-        return(true);
</span><span style="color: #000000;background-color: #ddffdd">+   return 1;
</span> }
 
 void strip_name(char *string)
<span style="color: #aaaaaa">@@ -133,12 +133,13 @@ void pick_salt(char *salt)
</span>   strcpy(salt,"ab");
 }
 
<span style="color: #000000;background-color: #ffdddd">-static void set_defaults(struct person *tmp)
</span><span style="color: #000000;background-color: #ddffdd">+static int set_defaults(struct person *tmp)
</span> {
        int             i, n;
        struct folder   f;
        struct Header   head;
        long            curtime = time(NULL);
<span style="color: #000000;background-color: #ddffdd">+        int ret = 0;
</span> 
        /* set default colour scheme. wont effect users if they dont have colour on, obviously */
        tmp->colour=0;
<span style="color: #aaaaaa">@@ -225,8 +226,9 @@ MAX OF 10 MESSAGES IN THE LAST 2 WEEKS
</span>                   tmp->chatprivs|=CP_SCRIPT;
                }
                mwlog("AUTOREGISTER %s",getmylogin());
<span style="color: #000000;background-color: #ffdddd">-                broadcast(3, "AutoRegister for %s",getmylogin());
</span><span style="color: #000000;background-color: #ddffdd">+           ret = 1; /* Autoregistered */
</span>   }
<span style="color: #000000;background-color: #ddffdd">+        return ret;
</span> }
 
 static int new_usr(char *name, struct user *u)
<span style="color: #aaaaaa">@@ -284,28 +286,34 @@ static int new_usr(char *name, struct user *u)
</span>           strip_str(usr->contact);
 
                mwlog("CREATED: %s <%s>",usr->realname, usr->contact);
<span style="color: #000000;background-color: #ffdddd">-                broadcast(3, "Created user %s: %s <%s>", name, usr->realname, usr->contact);
-               set_defaults(usr);
</span><span style="color: #000000;background-color: #ddffdd">+
+               int ret = 2; /* New user */
+               ret += set_defaults(usr);
</span>           printf(_("Creating new user %s\n"),name);
 
                userdb_write(u);
<span style="color: #000000;background-color: #ffdddd">-                return(true);
</span><span style="color: #000000;background-color: #ddffdd">+           return ret;
</span>   }
<span style="color: #000000;background-color: #ffdddd">-        else return(false);
</span><span style="color: #000000;background-color: #ddffdd">+   else return 0;
</span> }
 
<span style="color: #000000;background-color: #ffdddd">-void login_ok(struct user *usr, int *autochat)
</span><span style="color: #000000;background-color: #ddffdd">+/**
+ * Returns: 1: Existing user
+ *          2: New user
+ *          3: New user, autoregistered
+ */
+int login_ok(struct user *usr, int *autochat)
</span> {
<span style="color: #000000;background-color: #ffdddd">-        /* main function */
</span>   char name[NAMESIZE+1];
<span style="color: #000000;background-color: #ffdddd">-        int okay;
</span><span style="color: #000000;background-color: #ddffdd">+   int ret = 0;
</span>   do{
                get_login(name, *autochat);
                if(user_exists(name, usr))
<span style="color: #000000;background-color: #ffdddd">-                        okay=old_usr(usr);
</span><span style="color: #000000;background-color: #ddffdd">+                   ret = old_usr(usr);
</span>           else
<span style="color: #000000;background-color: #ffdddd">-                        okay=new_usr(name, usr);
-       }while (!okay);
</span><span style="color: #000000;background-color: #ddffdd">+                   ret = new_usr(name, usr);
+       } while (!ret);
+       return ret;
</span> }
 
 void list_users(int newonly)
</code></pre>

<br>
</li>
<li id='diff-2'>
<a href='https://projects.sucs.org/arthur/mw/commit/7e8ca22f21aa9cc2776aa169c260e96572beab96#diff-2'>
<strong>
src/client/user.h
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/src/client/user.h
</span><span style="color: #000000;background-color: #ddffdd">+++ b/src/client/user.h
</span><span style="color: #aaaaaa">@@ -8,7 +8,7 @@ char *getmylogin(void);
</span> void get_login(char *name, int autochat);
 void list_users(int newonly);
 void list_users_since(long date);
<span style="color: #000000;background-color: #ffdddd">-void login_ok(struct user *usr, int *autochat);
</span><span style="color: #000000;background-color: #ddffdd">+int login_ok(struct user *usr, int *autochat);
</span> void strip_name(char *string);
 void pick_salt(char *salt);
 void search(const char *args, const char *ptr);
</code></pre>

<br>
</li>

</div>
<div class='footer' style='margin-top: 10px;'>
<p>

<br>
<a href="https://projects.sucs.org/arthur/mw/commit/7e8ca22f21aa9cc2776aa169c260e96572beab96">View it on GitLab</a>.
<br>
You're receiving this email because of your account on projects.sucs.org.
If you'd like to receive fewer emails, you can adjust your notification settings.
<script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ViewAction","name":"View Commit","url":"https://projects.sucs.org/arthur/mw/commit/7e8ca22f21aa9cc2776aa169c260e96572beab96"}}</script>
</p>
</div>
</body>
</html>