Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use default sock path if $OIDC_SOCK not set #585

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading