Skip to content

Commit 2105f79

Browse files
committed
machine-credential: tweak --load-credential= use a bit
Let's try to recognize paths (i.e. those with a "/") as source for credentials to load, and then read them from the file system. Also, only read credentials from an inbound credentials directory if the source qualifies as valid credential name. Otherwise print a nice error.
1 parent 1311946 commit 2105f79

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/shared/machine-credential.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ int machine_credential_load(MachineCredential **credentials, size_t *n_credentia
9090
if (streq(cred->id, word))
9191
return log_error_errno(SYNTHETIC_ERRNO(EEXIST), "Duplicate credential '%s', refusing.", word);
9292

93-
if (path_is_absolute(p))
93+
if (is_path(p) && path_is_valid(p))
9494
flags |= READ_FULL_FILE_CONNECT_SOCKET;
95-
else {
95+
else if (credential_name_valid(p)) {
9696
const char *e;
9797

9898
r = get_credentials_dir(&e);
@@ -104,7 +104,8 @@ int machine_credential_load(MachineCredential **credentials, size_t *n_credentia
104104
return log_oom();
105105

106106
p = j;
107-
}
107+
} else
108+
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Credential source appears to be neither a valid path nor a credential name: %s", p);
108109

109110
r = read_full_file_full(AT_FDCWD, p, UINT64_MAX, SIZE_MAX,
110111
flags,

0 commit comments

Comments
 (0)