[mw-devel] MW3 r1277 - in trunk/src: . server

arthur at sucs.org arthur at sucs.org
Wed Nov 7 17:24:00 GMT 2012


Author: arthur
Date: 2012-11-07 17:23:59 +0000 (Wed, 07 Nov 2012)
New Revision: 1277

Added:
   trunk/src/nonce.c
Modified:
   trunk/src/Makefile
   trunk/src/ipc.c
   trunk/src/server/Makefile
   trunk/src/server/servsock.c
Log:
generate a unique compile time key to stop incompatible client versions


Modified: trunk/src/Makefile
===================================================================
--- trunk/src/Makefile	2012-11-07 15:18:02 UTC (rev 1276)
+++ trunk/src/Makefile	2012-11-07 17:23:59 UTC (rev 1277)
@@ -59,9 +59,16 @@
 topten.o sort.o tidyup.o gags.o script_inst.o script.o\
 incoming.o command.o chattable.o alias.o frl.o hash.o vars.o expand.o\
 files.o completion.o iconv.o gagtable.o \
-js.o sqlite.o ipc.o log.o uri.o socket.o
+js.o sqlite.o ipc.o log.o uri.o socket.o nonce.o
 	$(CC) $(LDFLAGS) $(LDLIBS) -o $@ $^
 
+nonce.c: nonce.h
+
+nonce.h:
+	echo -n "#define NONCE \"" > nonce.h
+	dd if=/dev/urandom bs=1 count=8 | base64 | sed -e 's/$$/"/' >> nonce.h
+	cproto nonce.c >> nonce.h
+
 del_user: del_user.o perms.o strings.o
 	$(CC) $(LDFLAGS) -o $@ $^
 
@@ -72,7 +79,7 @@
 	install -d $(DESTDIR)$(STATEDIR)
 
 clean:
-	-rm -f *.o *.d mw del_user
+	-rm -f *.o *.d nonce.h mw del_user
 
 ifndef TESTDIR
 test testclean:

Modified: trunk/src/ipc.c
===================================================================
--- trunk/src/ipc.c	2012-11-07 15:18:02 UTC (rev 1276)
+++ trunk/src/ipc.c	2012-11-07 17:23:59 UTC (rev 1277)
@@ -20,6 +20,8 @@
 
 extern int32_t userposn;
 
+const char *get_nonce(void);
+
 void ipc_connect(const char *target)
 {
 	const char * host = target;
@@ -48,6 +50,10 @@
 	pid_t mypid = getpid();
 	ipc_message_t * msg = ipcmsg_create(FOURCC("HELO"), mypid);
 	ipcmsg_append(msg, &userposn, sizeof(userposn));
+	printf("Fetching nonce\n");
+	const char *nonce = get_nonce();
+	ipcmsg_append(msg, nonce, strlen(nonce));
+	printf("Sending nonce '%s'\n", nonce);
 	ipcmsg_send(msg, ipcsock);
 	ipcmsg_destroy(msg);
 }

Added: trunk/src/nonce.c
===================================================================
--- trunk/src/nonce.c	                        (rev 0)
+++ trunk/src/nonce.c	2012-11-07 17:23:59 UTC (rev 1277)
@@ -0,0 +1,13 @@
+#include <string.h>
+#include "nonce.h"
+
+const char * get_nonce()
+{
+	return NONCE;
+}
+
+int match_nonce(const char *test)
+{
+	if (strcmp(test, NONCE)==0) return 1;
+	return 0;
+}

Modified: trunk/src/server/Makefile
===================================================================
--- trunk/src/server/Makefile	2012-11-07 15:18:02 UTC (rev 1276)
+++ trunk/src/server/Makefile	2012-11-07 17:23:59 UTC (rev 1277)
@@ -49,7 +49,7 @@
 
 .PHONY: build install clean test
 
-mwserv: mwserv.o servsock.o ../socket.o ../files.o ../strings.o ../ipc.o ../iconv.o
+mwserv: mwserv.o servsock.o ../socket.o ../files.o ../strings.o ../ipc.o ../iconv.o ../nonce.o
 	$(CC) $(LDFLAGS) $(LDLIBS) -o $@ $^
 
 clean:

Modified: trunk/src/server/servsock.c
===================================================================
--- trunk/src/server/servsock.c	2012-11-07 15:18:02 UTC (rev 1276)
+++ trunk/src/server/servsock.c	2012-11-07 17:23:59 UTC (rev 1277)
@@ -18,6 +18,7 @@
 #include "../socket.h"
 #include "servsock.h"
 #include "../files.h"
+#include "../nonce.h"
 
 struct list_head connection_list;
 
@@ -229,12 +230,18 @@
 	/* client just told us who they are */
 	if (msg->head.type == FOURCC("HELO")) {
 		memcpy(&conn->addr, &msg->head.src, sizeof(conn->addr));
-		if (msg->bodylen != 4) {
+		if (msg->bodylen < 4) {
 			printf("Invalid HELO from fd=%d. dropping.\n", conn->fd);
 			ipcmsg_destroy(msg);
 			drop_connection(conn);
 			return;
 		}
+		if (!match_nonce(&msg->body[4])) {
+			printf("Mismatched nonce from fd=%d. dropping.\n", conn->fd);
+			ipcmsg_destroy(msg);
+			drop_connection(conn);
+			return;
+		}
 		memcpy(&conn->user, msg->body, sizeof(conn->user));
 		printf("WHO Add: pid=%d posn=%d\n", conn->addr, conn->user);
 		who_add(conn->addr, conn->user);




More information about the mw-devel mailing list