mirror of
https://github.com/systemd/systemd
synced 2024-09-06 16:56:43 +00:00
Merge pull request #27408 from keszybz/creds-missing-message
Adjust messages when credentials are missing
This commit is contained in:
commit
947579e5e2
|
@ -476,16 +476,15 @@ static void read_credentials(Manager *m) {
|
|||
if (!m->read_resolv_conf)
|
||||
return;
|
||||
|
||||
r = read_credential_strings_many(
|
||||
"network.dns", &dns,
|
||||
"network.search_domains", &domains);
|
||||
if (r < 0 && !IN_SET(r, -ENXIO, -ENOENT))
|
||||
r = read_credential_strings_many("network.dns", &dns,
|
||||
"network.search_domains", &domains);
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "Failed to read credentials, ignoring: %m");
|
||||
|
||||
if (dns) {
|
||||
r = manager_parse_dns_server_string_and_warn(m, DNS_SERVER_SYSTEM, dns);
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "Failed to parse credential provided DNS server string '%s', ignoring.", dns);
|
||||
log_warning_errno(r, "Failed to parse credential network.dns '%s', ignoring.", dns);
|
||||
|
||||
m->read_resolv_conf = false;
|
||||
}
|
||||
|
@ -493,7 +492,7 @@ static void read_credentials(Manager *m) {
|
|||
if (domains) {
|
||||
r = manager_parse_search_domains_and_warn(m, domains);
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "Failed to parse credential provided search domain string '%s', ignoring.", domains);
|
||||
log_warning_errno(r, "Failed to parse credential network.search_domains '%s', ignoring.", domains);
|
||||
|
||||
m->read_resolv_conf = false;
|
||||
}
|
||||
|
|
|
@ -96,17 +96,21 @@ int read_credential_strings_many_internal(
|
|||
|
||||
/* Reads a bunch of credentials into the specified buffers. If the specified buffers are already
|
||||
* non-NULL frees them if a credential is found. Only supports string-based credentials
|
||||
* (i.e. refuses embedded NUL bytes) */
|
||||
* (i.e. refuses embedded NUL bytes).
|
||||
*
|
||||
* 0 is returned when some or all credentials are missing.
|
||||
*/
|
||||
|
||||
if (!first_name)
|
||||
return 0;
|
||||
|
||||
r = read_credential(first_name, &b, NULL);
|
||||
if (r == -ENXIO) /* no creds passed at all? propagate this */
|
||||
return r;
|
||||
if (r < 0)
|
||||
ret = r;
|
||||
else
|
||||
if (r == -ENXIO) /* No creds passed at all? Bail immediately. */
|
||||
return 0;
|
||||
if (r < 0) {
|
||||
if (r != -ENOENT)
|
||||
ret = r;
|
||||
} else
|
||||
free_and_replace(*first_value, b);
|
||||
|
||||
va_list ap;
|
||||
|
@ -127,7 +131,7 @@ int read_credential_strings_many_internal(
|
|||
|
||||
r = read_credential(name, &bb, NULL);
|
||||
if (r < 0) {
|
||||
if (ret >= 0)
|
||||
if (ret >= 0 && r != -ENOENT)
|
||||
ret = r;
|
||||
} else
|
||||
free_and_replace(*value, bb);
|
||||
|
|
|
@ -16,7 +16,7 @@ TEST(read_credential_strings) {
|
|||
if (e)
|
||||
assert_se(saved = strdup(e));
|
||||
|
||||
assert_se(read_credential_strings_many("foo", &x, "bar", &y) == -ENXIO);
|
||||
assert_se(read_credential_strings_many("foo", &x, "bar", &y) == 0);
|
||||
assert_se(x == NULL);
|
||||
assert_se(y == NULL);
|
||||
|
||||
|
@ -24,20 +24,20 @@ TEST(read_credential_strings) {
|
|||
|
||||
assert_se(setenv("CREDENTIALS_DIRECTORY", tmp, /* override= */ true) >= 0);
|
||||
|
||||
assert_se(read_credential_strings_many("foo", &x, "bar", &y) == -ENOENT);
|
||||
assert_se(read_credential_strings_many("foo", &x, "bar", &y) == 0);
|
||||
assert_se(x == NULL);
|
||||
assert_se(y == NULL);
|
||||
|
||||
assert_se(p = path_join(tmp, "bar"));
|
||||
assert_se(write_string_file(p, "piff", WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_AVOID_NEWLINE) >= 0);
|
||||
|
||||
assert_se(read_credential_strings_many("foo", &x, "bar", &y) == -ENOENT);
|
||||
assert_se(read_credential_strings_many("foo", &x, "bar", &y) == 0);
|
||||
assert_se(x == NULL);
|
||||
assert_se(streq(y, "piff"));
|
||||
|
||||
assert_se(write_string_file(p, "paff", WRITE_STRING_FILE_TRUNCATE|WRITE_STRING_FILE_AVOID_NEWLINE) >= 0);
|
||||
|
||||
assert_se(read_credential_strings_many("foo", &x, "bar", &y) == -ENOENT);
|
||||
assert_se(read_credential_strings_many("foo", &x, "bar", &y) == 0);
|
||||
assert_se(x == NULL);
|
||||
assert_se(streq(y, "piff"));
|
||||
|
||||
|
|
|
@ -117,11 +117,8 @@ static int context_read_creds(Context *c) {
|
|||
vc_meta_names[VC_FONT], &v.config[VC_FONT],
|
||||
vc_meta_names[VC_FONT_MAP], &v.config[VC_FONT_MAP],
|
||||
vc_meta_names[VC_FONT_UNIMAP], &v.config[VC_FONT_UNIMAP]);
|
||||
if (r < 0) {
|
||||
if (r != -ENXIO)
|
||||
log_warning_errno(r, "Failed to import credentials, ignoring: %m");
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "Failed to import credentials, ignoring: %m");
|
||||
|
||||
context_merge_config(c, &v, NULL);
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue