Skip to content

Commit

Permalink
use default sock path if $OIDC_SOCK not set
Browse files Browse the repository at this point in the history
  • Loading branch information
zachmann committed Aug 21, 2024
1 parent 799f60d commit 862366e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ This did not work as intended. We made the following changes:
### Enhancements

- `oidc-add` can now also take an issuer url to load the default account for this issuer, i.e. `oidc-add <issuer_url>`
- If no socket path is set a default path is tried. The default path
is `$TMPDIR/oidc-agent-service-$UID/oidc-agent.sock`, this is the path used by `oidc-agent-service`

### Bugfixes

Expand Down
21 changes: 18 additions & 3 deletions src/ipc/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@

#ifndef MINGW

char* defaultSocketPath() {
const char* tmp = getenv("TMPDIR") ?: "/tmp";
uid_t uid = getuid();
return oidc_sprintf("%s/oidc-agent-service-%d/oidc-agent.sock", tmp, uid);
}

oidc_error_t initConnectionWithoutPath(struct connection* con, int isServer,
int tcp) {
con->server = secAlloc(sizeof(struct sockaddr_un));
Expand Down Expand Up @@ -115,15 +121,24 @@ oidc_error_t ipc_client_init(struct connection* con, unsigned char remote) {
#else
const char* env_var_name =
remote ? OIDC_REMOTE_SOCK_ENV_NAME : OIDC_SOCK_ENV_NAME;
unsigned char usedDefault = 0;
#ifdef ANY_MSYS
char* path = getRegistryValue(env_var_name);
#else
char* path = oidc_strcopy(getenv(env_var_name));
if (path == NULL) {
path = defaultSocketPath();
usedDefault = 1;
}
#endif
if (path == NULL) {
char* err = oidc_sprintf("Could not get the socket path from env var '%s'. "
"Have you set the env var?\n",
env_var_name);
char* err = oidc_sprintf(
"Could not get the socket path from env var '%s'%s. "
"Have you set the env var?\nIs a agent running?\n",
env_var_name,
usedDefault
? " and could not connect to default oidc-agent-service path"
: "");
logger(WARNING, "Could not get the socket path from env var '%s'",
env_var_name);
oidc_seterror(err);
Expand Down
2 changes: 2 additions & 0 deletions src/ipc/ipc.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

#include "utils/oidc_error.h"

char* defaultSocketPath();

#ifndef MINGW
oidc_error_t initConnectionWithoutPath(struct connection*, int, int);
oidc_error_t initConnectionWithPath(struct connection*, const char*);
Expand Down
4 changes: 3 additions & 1 deletion src/oidc-gen/gen_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "defines/oidc_values.h"
#include "defines/settings.h"
#include "ipc/cryptCommunicator.h"
#include "ipc/ipc.h"
#include "oidc-agent/oidc/device_code.h"
#include "oidc-gen/device_code.h"
#include "oidc-gen/gen_consenter.h"
Expand Down Expand Up @@ -321,7 +322,8 @@ void handleCodeExchange(const struct arguments* arguments) {
#ifdef __MSYS__
socket_path = getRegistryValue(OIDC_SOCK_ENV_NAME);
#else
socket_path = oidc_strcopy(getenv(OIDC_SOCK_ENV_NAME));
socket_path =
oidc_strcopy(getenv(OIDC_SOCK_ENV_NAME)) ?: defaultSocketPath();
#endif
if (socket_path == NULL) {
printError("Socket path not encoded in url state and not available from "
Expand Down

0 comments on commit 862366e

Please sign in to comment.