fix auth for certain glib clients
This commit is contained in:
parent
438a1a85e8
commit
fcc9835419
1 changed files with 15 additions and 9 deletions
20
server.c
20
server.c
|
@ -422,7 +422,9 @@ struct jb_server *jb_server_create(const char *socket_path)
|
||||||
int jb_server_turn(struct jb_server *s)
|
int jb_server_turn(struct jb_server *s)
|
||||||
{
|
{
|
||||||
static const char agree_unix_fd[] = "AGREE_UNIX_FD\r\n";
|
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;
|
static const int data_buffer_len = 4096;
|
||||||
|
|
||||||
TRYST(poll(s->fds, s->fd_num, -1));
|
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
|
// Immediately after connecting, clients must send a null byte
|
||||||
// SPEC: https://dbus.freedesktop.org/doc/dbus-specification.html#auth-nul-byte
|
// SPEC: https://dbus.freedesktop.org/doc/dbus-specification.html#auth-nul-byte
|
||||||
if (*data != '\0' || *(data + 1) == '\0') {
|
char *auth_string = data;
|
||||||
_client_die("expected initial auth message to begin with a nul byte");
|
if (*auth_string == '\0') {
|
||||||
|
auth_string++;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *auth_string = data + 1;
|
// TODO: the code below is hacky and does not reflect the specification
|
||||||
|
if (strcmp(auth_string, "AUTH\r\n") == 0) {
|
||||||
if (strcmp(auth_string, "AUTH EXTERNAL 31303030\r\n") != 0 && strcmp(auth_string, "AUTH\r\n") != 0)
|
send(fd, auth_list, sizeof(auth_list) - 1, 0);
|
||||||
_client_die("bad auth");
|
} 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);
|
send(fd, auth_ok, sizeof(auth_ok) - 1, 0);
|
||||||
c->state = JB_CLIENT_STATE_WAIT_BEGIN;
|
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;
|
} break;
|
||||||
case JB_CLIENT_STATE_WAIT_BEGIN: {
|
case JB_CLIENT_STATE_WAIT_BEGIN: {
|
||||||
// Right now, we're expecting the client to either immediately begin the connection,
|
// Right now, we're expecting the client to either immediately begin the connection,
|
||||||
|
|
Loading…
Reference in a new issue