From 059e0fda44491f74a2dd51f595b82b5748b6cead Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Tue, 30 Jan 2024 15:05:37 +0100 Subject: [PATCH] Client: store auth credentials for later use Store the client's auth credentials, so they can be used by extensions later. --- dix/dispatch.c | 8 ++++++++ include/dixstruct.h | 6 ++++++ include/meson.build | 3 +++ meson.build | 10 ++++++++++ os/connection.c | 17 +++++++++++++++++ 5 files changed, 44 insertions(+) diff --git a/dix/dispatch.c b/dix/dispatch.c index eaac39b7c9..7aba3088b9 100644 --- a/dix/dispatch.c +++ b/dix/dispatch.c @@ -3549,6 +3549,14 @@ CloseDownClient(ClientPtr client) nextFreeClientID = client->index; clients[client->index] = NullClient; SmartLastClient = NullClient; + +#ifdef CONFIG_STORE_CLIENT_CREDS + if (client->authProto) + free(client->authProto); + if (client->authToken) + free(client->authToken); +#endif /* CONFIG_STORE_CLIENT_CREDS */ + dixFreeObjectWithPrivates(client, PRIVATE_CLIENT); while (!clients[currentMaxClients - 1]) diff --git a/include/dixstruct.h b/include/dixstruct.h index fb0ac14b89..64bdd7ca28 100644 --- a/include/dixstruct.h +++ b/include/dixstruct.h @@ -111,6 +111,12 @@ typedef struct _Client { DeviceIntPtr clientPtr; ClientIdPtr clientIds; int req_fds; + +#ifdef CONFIG_STORE_CLIENT_CREDS + /* auth credentials used to connect */ + char *authProto; + char *authToken; // hex printed +#endif /* CONFIG_STORE_CLIENT_CREDS */ } ClientRec; static inline void diff --git a/include/meson.build b/include/meson.build index 236b953636..825db320f7 100644 --- a/include/meson.build +++ b/include/meson.build @@ -242,6 +242,9 @@ conf_data.set('XV', build_xv ? '1' : false) conf_data.set('XvExtension', build_xv ? '1' : false) conf_data.set('XvMCExtension', build_xvmc ? '1' : false) +# enable auto-selected internal lib functions +conf_data.set('CONFIG_STORE_CLIENT_CREDS', build_store_client_creds ? '1' : false) + conf_data.set('HAVE_SHA1_IN_' + sha1.to_upper(), '1', description: 'Use @0@ SHA1 functions'.format(sha1)) conf_data.set('HAVE_LIBUNWIND', get_option('libunwind')) diff --git a/meson.build b/meson.build index 1de3e2a4f4..e1e43d1605 100644 --- a/meson.build +++ b/meson.build @@ -114,8 +114,18 @@ if not libsystemd_daemon_dep.found() libsystemd_daemon_dep = dependency('libsystemd-daemon', required: false) endif +# +# internal lib components needed by other features +# (will be enabled later, as needed) +# + +# small hashtable implementation build_hashtable = false +# storing client's auth credentials so they can later be retrieved by extensions +build_store_client_creds = false + + # Resolve default values of some options xkb_dir = get_option('xkb_dir') if xkb_dir == '' diff --git a/os/connection.c b/os/connection.c index a3c8f2a998..6a5bc383dd 100644 --- a/os/connection.c +++ b/os/connection.c @@ -576,6 +576,23 @@ ClientAuthorized(ClientPtr client, priv->auth_id = auth_id; priv->conn_time = 0; +#ifdef CONFIG_STORE_CLIENT_CREDS + { + /* store auth credentials for later use */ + client->authProto = calloc(proto_n+1, 1); + memcpy(client->authProto, auth_proto, proto_n); + + client->authToken = calloc(string_n*2+1, 1); + char *ptr = client->authToken; + for (int x=0; xfd);