[mw-devel] [Git][arthur/mw][master] IPC_HELLO was broken by the changes to PROTOCOL

Justin Mitchell arthur at sucs.org
Tue Oct 6 12:01:29 BST 2015


Justin Mitchell pushed to branch master at Justin Mitchell / mw


Commits:
264828c9 by Justin Mitchell at 2015-10-06T12:00:57Z
IPC_HELLO was broken by the changes to PROTOCOL

- - - - -


3 changed files:

- src/ipc.c
- src/server/PROTOCOL
- src/server/servsock.c


Changes:

=====================================
src/ipc.c
=====================================
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -63,7 +63,8 @@ void ipc_connect(const char *target)
 	ipcsock->state = IPCSTATE_CONNECTED;
 
 	ipc_message_t * msg = ipcmsg_create(IPC_HELLO, userposn);
-	ipcmsg_append(msg, &userposn, sizeof(userposn));
+	uint32_t pid = getpid();
+	ipcmsg_append(msg, &pid, sizeof(pid));
 	const char *nonce = get_nonce();
 	ipcmsg_append(msg, nonce, strlen(nonce));
 	ipcmsg_send(msg, ipcsock);


=====================================
src/server/PROTOCOL
=====================================
--- a/src/server/PROTOCOL
+++ b/src/server/PROTOCOL
@@ -20,7 +20,7 @@ IPC_* codes using FCC are json formatted messages.
 
 IPC_HELLO - Login to the server, start a session
 	Body: (binary)
-		userid - 4 bytes - offset in users db 
+		pid - 4 bytes - Process / Session ID
 		nonce - to end - unique version string for server
 	Response:
 		none


=====================================
src/server/servsock.c
=====================================
--- a/src/server/servsock.c
+++ b/src/server/servsock.c
@@ -264,20 +264,24 @@ void process_msg(ipc_connection_t *conn, ipc_message_t *msg)
 	/* client just told us who they are */
 	if (msg->head.type == IPC_HELLO) {
 		int wfd;
-		memcpy(&conn->addr, &msg->head.src, sizeof(conn->addr));
 		if (msg->bodylen < 4) {
 			printf("Invalid HELO from fd=%d. dropping.\n", conn->fd);
 			ipcmsg_destroy(msg);
 			drop_connection(conn);
 			return;
 		}
+		/* user id / userposn is in the header src */
+		memcpy(&conn->user, &(msg->head.src), sizeof(conn->user));
+		/* first 4 bytes of body are PID / Session ID */
+		memcpy(&conn->addr, msg->body, sizeof(conn->addr));
+		/* rest of body is the NONCE,
+		 * check this to make sure we have a matching client */
 		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);
 		wfd = who_open(O_RDWR);
 		who_add(wfd, conn->addr, conn->user);



View it on GitLab: https://projects.sucs.org/arthur/mw/commit/264828c9efdc4cc0718f4560ce49b52bd6cadbed
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sucs.org/pipermail/mw-devel/attachments/20151006/46d13e34/attachment.html>


More information about the mw-devel mailing list