fix auth for certain glib clients

This commit is contained in:
hippoz 2022-12-25 23:55:29 +02:00
parent 438a1a85e8
commit fcc9835419
Signed by: hippoz
GPG key ID: 56C4E02A85F2FBED

View file

@ -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,