Commit debca6e4 authored by Justin Mitchell's avatar Justin Mitchell
Browse files

Make the server login more robust

parent d9791920
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ const char * get_nonce()

int match_nonce(const char *test)
{
	if (test == NULL) return 0;
	if (strcmp(test, NONCE)==0) return 1;
	return 0;
}
+10 −2
Original line number Diff line number Diff line
@@ -306,13 +306,21 @@ void process_msg(ipc_connection_t *conn, ipc_message_t *msg)
			return;
		}

		if (username == NULL || *username == 0) {
			_autodestroy ipc_message_t * error = msg_error("NOUSER");
			msg_attach(error, conn);
			printf("Missing username\n");
			conn->state = IPCSTATE_PURGE;
			return;
		}
		
		const char * action = ipcmsg_getstring(msg, "action");

		if (!user_exists(username, &(conn->user))) {
			printf("New user=%s for conn fd=%d not found\n", username, conn->fd);

			// they dont exist, so create them
			if (strcasecmp(action, "autoreg")==0) {
			if (action && strcasecmp(action, "autoreg")==0) {
				const char * password = ipcmsg_getstring(msg, "password");
				const char * realname = ipcmsg_getstring(msg, "realname");
				const char * contact = ipcmsg_getstring(msg, "contact");
@@ -361,7 +369,7 @@ void process_msg(ipc_connection_t *conn, ipc_message_t *msg)
		
		// we really must write proper authentication
		// for now just bodge similar operation to existing client	
		if (strcasecmp(action, "auth")==0) {
		if (action && strcasecmp(action, "auth")==0) {
			const char * password = ipcmsg_getstring(msg, "password");
			char salt[3];