From fcc9835419b8ea82417ee4ab049f3969a0037c5f Mon Sep 17 00:00:00 2001 From: hippoz <10706925-hippoz@users.noreply.gitlab.com> Date: Sun, 25 Dec 2022 23:55:29 +0200 Subject: [PATCH] fix auth for certain glib clients --- server.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/server.c b/server.c index a007c0b..ce3248f 100644 --- a/server.c +++ b/server.c @@ -422,7 +422,9 @@ struct jb_server *jb_server_create(const char *socket_path) int jb_server_turn(struct jb_server *s) { static const char agree_unix_fd[] = "AGREE_UNIX_FD\r\n"; - static const char auth_ok[] = "OK 1234deadbeef\r\n"; + static const char auth_ok[] = "OK aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n"; + static const char auth_list[] = "REJECTED EXTERNAL\r\n"; + static const char auth_data[] = "DATA\r\n"; static const int data_buffer_len = 4096; TRYST(poll(s->fds, s->fd_num, -1)); @@ -467,16 +469,20 @@ int jb_server_turn(struct jb_server *s) // Immediately after connecting, clients must send a null byte // SPEC: https://dbus.freedesktop.org/doc/dbus-specification.html#auth-nul-byte - if (*data != '\0' || *(data + 1) == '\0') { - _client_die("expected initial auth message to begin with a nul byte"); + char *auth_string = data; + if (*auth_string == '\0') { + auth_string++; } - char *auth_string = data + 1; - - if (strcmp(auth_string, "AUTH EXTERNAL 31303030\r\n") != 0 && strcmp(auth_string, "AUTH\r\n") != 0) - _client_die("bad auth"); - send(fd, auth_ok, sizeof(auth_ok) - 1, 0); - c->state = JB_CLIENT_STATE_WAIT_BEGIN; + // TODO: the code below is hacky and does not reflect the specification + if (strcmp(auth_string, "AUTH\r\n") == 0) { + send(fd, auth_list, sizeof(auth_list) - 1, 0); + } else if (strcmp(auth_string, "AUTH EXTERNAL 31303030\r\n") == 0 || strcmp(auth_string, "DATA\r\n") == 0) { + send(fd, auth_ok, sizeof(auth_ok) - 1, 0); + c->state = JB_CLIENT_STATE_WAIT_BEGIN; + } else if (strcmp(auth_string, "AUTH EXTERNAL\r\n") == 0) { + send(fd, auth_data, sizeof(auth_data) - 1, 0); + } } break; case JB_CLIENT_STATE_WAIT_BEGIN: { // Right now, we're expecting the client to either immediately begin the connection,