pam-systemd: normalize return values of append_session_xyz()
Let's propagate the PAM errors we got.
This commit is contained in:
+23
-25
@@ -307,14 +307,14 @@ static int append_session_memory_max(pam_handle_t *handle, sd_bus_message *m, co
|
||||
int r;
|
||||
|
||||
if (isempty(limit))
|
||||
return 0;
|
||||
return PAM_SUCCESS;
|
||||
|
||||
if (streq(limit, "infinity")) {
|
||||
r = sd_bus_message_append(m, "(sv)", "MemoryMax", "t", (uint64_t)-1);
|
||||
if (r < 0)
|
||||
return pam_bus_log_create_error(handle, r);
|
||||
|
||||
return 0;
|
||||
return PAM_SUCCESS;
|
||||
}
|
||||
|
||||
r = parse_permille(limit);
|
||||
@@ -323,7 +323,7 @@ static int append_session_memory_max(pam_handle_t *handle, sd_bus_message *m, co
|
||||
if (r < 0)
|
||||
return pam_bus_log_create_error(handle, r);
|
||||
|
||||
return 0;
|
||||
return PAM_SUCCESS;
|
||||
}
|
||||
|
||||
r = parse_size(limit, 1024, &val);
|
||||
@@ -332,11 +332,11 @@ static int append_session_memory_max(pam_handle_t *handle, sd_bus_message *m, co
|
||||
if (r < 0)
|
||||
return pam_bus_log_create_error(handle, r);
|
||||
|
||||
return 0;
|
||||
return PAM_SUCCESS;
|
||||
}
|
||||
|
||||
pam_syslog(handle, LOG_WARNING, "Failed to parse systemd.memory_max, ignoring: %s", limit);
|
||||
return 0;
|
||||
return PAM_SUCCESS;
|
||||
}
|
||||
|
||||
static int append_session_runtime_max_sec(pam_handle_t *handle, sd_bus_message *m, const char *limit) {
|
||||
@@ -345,19 +345,17 @@ static int append_session_runtime_max_sec(pam_handle_t *handle, sd_bus_message *
|
||||
|
||||
/* No need to parse "infinity" here, it will be set by default later in scope_init() */
|
||||
if (isempty(limit) || streq(limit, "infinity"))
|
||||
return 0;
|
||||
return PAM_SUCCESS;
|
||||
|
||||
r = parse_sec(limit, &val);
|
||||
if (r >= 0) {
|
||||
r = sd_bus_message_append(m, "(sv)", "RuntimeMaxUSec", "t", (uint64_t) val);
|
||||
if (r < 0) {
|
||||
pam_syslog(handle, LOG_ERR, "Failed to append to bus message: %s", strerror_safe(r));
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return pam_bus_log_create_error(handle, r);
|
||||
} else
|
||||
pam_syslog(handle, LOG_WARNING, "Failed to parse systemd.runtime_max_sec: %s, ignoring.", limit);
|
||||
|
||||
return 0;
|
||||
return PAM_SUCCESS;
|
||||
}
|
||||
|
||||
static int append_session_tasks_max(pam_handle_t *handle, sd_bus_message *m, const char *limit) {
|
||||
@@ -366,7 +364,7 @@ static int append_session_tasks_max(pam_handle_t *handle, sd_bus_message *m, con
|
||||
|
||||
/* No need to parse "infinity" here, it will be set unconditionally later in manager_start_scope() */
|
||||
if (isempty(limit) || streq(limit, "infinity"))
|
||||
return 0;
|
||||
return PAM_SUCCESS;
|
||||
|
||||
r = safe_atou64(limit, &val);
|
||||
if (r >= 0) {
|
||||
@@ -376,7 +374,7 @@ static int append_session_tasks_max(pam_handle_t *handle, sd_bus_message *m, con
|
||||
} else
|
||||
pam_syslog(handle, LOG_WARNING, "Failed to parse systemd.tasks_max, ignoring: %s", limit);
|
||||
|
||||
return 0;
|
||||
return PAM_SUCCESS;
|
||||
}
|
||||
|
||||
static int append_session_cg_weight(pam_handle_t *handle, sd_bus_message *m, const char *limit, const char *field) {
|
||||
@@ -384,7 +382,7 @@ static int append_session_cg_weight(pam_handle_t *handle, sd_bus_message *m, con
|
||||
int r;
|
||||
|
||||
if (isempty(limit))
|
||||
return 0;
|
||||
return PAM_SUCCESS;
|
||||
|
||||
r = cg_weight_parse(limit, &val);
|
||||
if (r >= 0) {
|
||||
@@ -396,7 +394,7 @@ static int append_session_cg_weight(pam_handle_t *handle, sd_bus_message *m, con
|
||||
else
|
||||
pam_syslog(handle, LOG_WARNING, "Failed to parse systemd.io_weight, ignoring: %s", limit);
|
||||
|
||||
return 0;
|
||||
return PAM_SUCCESS;
|
||||
}
|
||||
|
||||
static const char* getenv_harder(pam_handle_t *handle, const char *key, const char *fallback) {
|
||||
@@ -674,24 +672,24 @@ _public_ PAM_EXTERN int pam_sm_open_session(
|
||||
return pam_bus_log_create_error(handle, r);
|
||||
|
||||
r = append_session_memory_max(handle, m, memory_max);
|
||||
if (r < 0)
|
||||
return PAM_SESSION_ERR;
|
||||
if (r != PAM_SUCCESS)
|
||||
return r;
|
||||
|
||||
r = append_session_runtime_max_sec(handle, m, runtime_max_sec);
|
||||
if (r < 0)
|
||||
return PAM_SESSION_ERR;
|
||||
if (r != PAM_SUCCESS)
|
||||
return r;
|
||||
|
||||
r = append_session_tasks_max(handle, m, tasks_max);
|
||||
if (r < 0)
|
||||
return PAM_SESSION_ERR;
|
||||
if (r != PAM_SUCCESS)
|
||||
return r;
|
||||
|
||||
r = append_session_cg_weight(handle, m, cpu_weight, "CPUWeight");
|
||||
if (r < 0)
|
||||
return PAM_SESSION_ERR;
|
||||
if (r != PAM_SUCCESS)
|
||||
return r;
|
||||
|
||||
r = append_session_cg_weight(handle, m, io_weight, "IOWeight");
|
||||
if (r < 0)
|
||||
return PAM_SESSION_ERR;
|
||||
if (r != PAM_SUCCESS)
|
||||
return r;
|
||||
|
||||
r = sd_bus_message_close_container(m);
|
||||
if (r < 0)
|
||||
|
||||
Reference in New Issue
Block a user