[mw-devel] [Git][arthur/mw][master] Restrict wizchat messages to wizchat permission holders, fixes #13

Justin Mitchell arthur at sucs.org
Fri Jan 22 16:18:25 GMT 2016


Justin Mitchell pushed to branch master at Justin Mitchell / mw


Commits:
4f639e10 by Justin Mitchell at 2016-01-22T16:18:08Z
Restrict wizchat messages to wizchat permission holders, fixes #13

- - - - -


3 changed files:

- src/server/replay.c
- src/server/servsock.c
- src/server/servsock.h


Changes:

=====================================
src/server/replay.c
=====================================
--- a/src/server/replay.c
+++ b/src/server/replay.c
@@ -18,6 +18,8 @@
 #include <rooms.h>
 #include <talker_privs.h>
 #include <ipc.h>
+#include <perms.h>
+#include <special.h>
 
 #include "servsock.h"
 #include "replay.h"
@@ -185,6 +187,13 @@ void replay(ipc_connection_t *conn, ipc_message_t *msg)
 			json_decref(j);
 			continue;
 		}
+		if (store[idx]->head.type == IPC_WIZ) {
+			if (s_wizchat(&user)) {
+				/* we are a wiz, we see this */
+				msg_attach(store[idx], conn);
+			}
+			continue;
+		}
 
 		/* send them everything else */
 		if (store[idx]->head.dst)


=====================================
src/server/servsock.c
=====================================
--- a/src/server/servsock.c
+++ b/src/server/servsock.c
@@ -408,6 +408,14 @@ void process_msg(ipc_connection_t *conn, ipc_message_t *msg)
 	if (msg->head.type == IPC_EVENT) {
 		printf("Event message\n");
 		msg_attach_to_all(msg);
+		ipcmsg_destroy(msg);
+		return;
+	}
+
+	if (msg->head.type == IPC_WIZ) {
+		printf("Wiz message\n");
+		msg_attach_to_perm(msg, PERM_WIZCHAT);
+		ipcmsg_destroy(msg);
 		return;
 	}
 
@@ -415,6 +423,7 @@ void process_msg(ipc_connection_t *conn, ipc_message_t *msg)
 	if (msg->head.dst == SYSTEM_USER) {
 		printf("Broadcast message to system user %s\n", ipc_nametype(msg->head.type));
 		msg_attach_to_all(msg);
+		ipcmsg_destroy(msg);
 		return;
 	}
 
@@ -544,6 +553,38 @@ int msg_attach_to_userid(ipc_message_t *msg, uint32_t userposn)
 	return found;
 }
 
+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);
+}
+
 /* attach messgae to outgoing queue */
 void msg_attach(ipc_message_t *msg, ipc_connection_t *conn)
 {


=====================================
src/server/servsock.h
=====================================
--- a/src/server/servsock.h
+++ b/src/server/servsock.h
@@ -2,6 +2,12 @@
 #define SERVSOCK_H
 #include <user.h>
 
+typedef enum {
+	PERM_WIZCHAT,
+	PERM_CHANGEINFO
+} perm_t;
+
+
 /* servsock.c */
 int open_mainsock(uint16_t port);
 ipc_connection_t *add_connection(int fd);
@@ -14,6 +20,7 @@ void msg_attach_to_all(ipc_message_t *msg);
 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);
+void msg_attach_to_perm(ipc_message_t *msg, perm_t perm);
 void msg_attach(ipc_message_t *msg, ipc_connection_t *conn);
 void migrate_old_folders(void);
 void init_server(void);



View it on GitLab: https://projects.sucs.org/arthur/mw/commit/4f639e10bc5234b2afeb51e6efbdad46a44c9c6c
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sucs.org/pipermail/mw-devel/attachments/20160122/80634ba7/attachment.html>


More information about the mw-devel mailing list