<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>Justin Mitchell 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/4f639e10bc5234b2afeb51e6efbdad46a44c9c6c">4f639e10</a></strong>
<div>
<span>by Justin Mitchell</span>
<i>at 2016-01-22T16:18:08Z</i>
</div>
<pre class='commit-message'>Restrict wizchat messages to wizchat permission holders, fixes #13</pre>
</li>
</ul>
<h4>3 changed files:</h4>
<ul>
<li class='file-stats'>
<a href='#diff-0'>
src/server/replay.c
</a>
</li>
<li class='file-stats'>
<a href='#diff-1'>
src/server/servsock.c
</a>
</li>
<li class='file-stats'>
<a href='#diff-2'>
src/server/servsock.h
</a>
</li>
</ul>
<h4>Changes:</h4>
<li id='diff-0'>
<a href='https://projects.sucs.org/arthur/mw/commit/4f639e10bc5234b2afeb51e6efbdad46a44c9c6c#diff-0'>
<strong>
src/server/replay.c
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/src/server/replay.c
</span><span style="color: #000000;background-color: #ddffdd">+++ b/src/server/replay.c
</span><span style="color: #aaaaaa">@@ -18,6 +18,8 @@
</span> #include <rooms.h>
 #include <talker_privs.h>
 #include <ipc.h>
<span style="color: #000000;background-color: #ddffdd">+#include <perms.h>
+#include <special.h>
</span> 
 #include "servsock.h"
 #include "replay.h"
<span style="color: #aaaaaa">@@ -185,6 +187,13 @@ void replay(ipc_connection_t *conn, ipc_message_t *msg)
</span>                   json_decref(j);
                        continue;
                }
<span style="color: #000000;background-color: #ddffdd">+                if (store[idx]->head.type == IPC_WIZ) {
+                       if (s_wizchat(&user)) {
+                               /* we are a wiz, we see this */
+                               msg_attach(store[idx], conn);
+                       }
+                       continue;
+               }
</span> 
                /* send them everything else */
                if (store[idx]->head.dst)
</code></pre>

<br>
</li>
<li id='diff-1'>
<a href='https://projects.sucs.org/arthur/mw/commit/4f639e10bc5234b2afeb51e6efbdad46a44c9c6c#diff-1'>
<strong>
src/server/servsock.c
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/src/server/servsock.c
</span><span style="color: #000000;background-color: #ddffdd">+++ b/src/server/servsock.c
</span><span style="color: #aaaaaa">@@ -408,6 +408,14 @@ void process_msg(ipc_connection_t *conn, ipc_message_t *msg)
</span>   if (msg->head.type == IPC_EVENT) {
                printf("Event message\n");
                msg_attach_to_all(msg);
<span style="color: #000000;background-color: #ddffdd">+                ipcmsg_destroy(msg);
+               return;
+       }
+
+       if (msg->head.type == IPC_WIZ) {
+               printf("Wiz message\n");
+               msg_attach_to_perm(msg, PERM_WIZCHAT);
+               ipcmsg_destroy(msg);
</span>           return;
        }
 
<span style="color: #aaaaaa">@@ -415,6 +423,7 @@ void process_msg(ipc_connection_t *conn, ipc_message_t *msg)
</span>   if (msg->head.dst == SYSTEM_USER) {
                printf("Broadcast message to system user %s\n", ipc_nametype(msg->head.type));
                msg_attach_to_all(msg);
<span style="color: #000000;background-color: #ddffdd">+                ipcmsg_destroy(msg);
</span>           return;
        }
 
<span style="color: #aaaaaa">@@ -544,6 +553,38 @@ int msg_attach_to_userid(ipc_message_t *msg, uint32_t userposn)
</span>   return found;
 }
 
<span style="color: #000000;background-color: #ddffdd">+void msg_attach_to_perm(ipc_message_t *msg, perm_t perm)
+{
+       int users_fd = userdb_open(O_RDONLY);
+       struct user user;
+       struct person *urec = &user.record;
+       struct list_head *pos;
+
+       if (users_fd < 0)
+               return;
+
+       list_for_each(pos, &connection_list) {
+               ipc_connection_t *c = list_entry(pos, ipc_connection_t, list);
+               if (c->state != IPCSTATE_VALID) continue;
+
+               if (pread(users_fd, urec, sizeof(*urec), c->user) <= 0) continue;
+
+               if (perm == PERM_WIZCHAT) {
+                       if (!s_wizchat(&user)) continue;
+               } else
+               if (perm == PERM_CHANGEINFO) {
+                       if (!s_changeinfo(&user)) continue;
+               }
+
+               /* person not on talker, just skip them */
+               if (!cm_test(&user, CM_ONCHAT)) continue;
+
+               msg_attach(msg, c);
+               printf("Restricted Broadcast to %s in %d\n", urec->name, urec->room);
+       }
+       close(users_fd);
+}
+
</span> /* attach messgae to outgoing queue */
 void msg_attach(ipc_message_t *msg, ipc_connection_t *conn)
 {
</code></pre>

<br>
</li>
<li id='diff-2'>
<a href='https://projects.sucs.org/arthur/mw/commit/4f639e10bc5234b2afeb51e6efbdad46a44c9c6c#diff-2'>
<strong>
src/server/servsock.h
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/src/server/servsock.h
</span><span style="color: #000000;background-color: #ddffdd">+++ b/src/server/servsock.h
</span><span style="color: #aaaaaa">@@ -2,6 +2,12 @@
</span> #define SERVSOCK_H
 #include <user.h>
 
<span style="color: #000000;background-color: #ddffdd">+typedef enum {
+       PERM_WIZCHAT,
+       PERM_CHANGEINFO
+} perm_t;
+
+
</span> /* servsock.c */
 int open_mainsock(uint16_t port);
 ipc_connection_t *add_connection(int fd);
<span style="color: #aaaaaa">@@ -14,6 +20,7 @@ void msg_attach_to_all(ipc_message_t *msg);
</span> int msg_attach_to_userid(ipc_message_t *msg, uint32_t userposn);
 int msg_attach_to_username(ipc_message_t *msg, const char *username);
 void msg_attach_to_channel(ipc_message_t *msg, int channel, const char * exclude);
<span style="color: #000000;background-color: #ddffdd">+void msg_attach_to_perm(ipc_message_t *msg, perm_t perm);
</span> void msg_attach(ipc_message_t *msg, ipc_connection_t *conn);
 void migrate_old_folders(void);
 void init_server(void);
</code></pre>

<br>
</li>

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

<br>
<a href="https://projects.sucs.org/arthur/mw/commit/4f639e10bc5234b2afeb51e6efbdad46a44c9c6c">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/4f639e10bc5234b2afeb51e6efbdad46a44c9c6c"}}</script>
</p>
</div>
</body>
</html>