mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 08:25:20 +09:00
nspawn: Generalize parse_bind_user_shell()
Preparation for reuse in vmspawn.
This commit is contained in:
committed by
Lennart Poettering
parent
5b94f463f0
commit
dbbbdde266
@@ -13,6 +13,7 @@
|
||||
#include "log.h"
|
||||
#include "missing-network.h"
|
||||
#include "parse-util.h"
|
||||
#include "path-util.h"
|
||||
#include "process-util.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
@@ -369,6 +370,29 @@ int parse_fd(const char *t) {
|
||||
return fd;
|
||||
}
|
||||
|
||||
int parse_user_shell(const char *s, char **ret_sh, bool *ret_copy) {
|
||||
char *sh;
|
||||
int r;
|
||||
|
||||
if (path_is_absolute(s) && path_is_normalized(s)) {
|
||||
sh = strdup(s);
|
||||
if (!sh)
|
||||
return -ENOMEM;
|
||||
|
||||
*ret_sh = sh;
|
||||
*ret_copy = false;
|
||||
} else {
|
||||
r = parse_boolean(s);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
*ret_sh = NULL;
|
||||
*ret_copy = r;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char *mangle_base(const char *s, unsigned *base) {
|
||||
const char *k;
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ int parse_sector_size(const char *t, uint64_t *ret);
|
||||
int parse_range(const char *t, unsigned *lower, unsigned *upper);
|
||||
int parse_errno(const char *t);
|
||||
int parse_fd(const char *t);
|
||||
int parse_user_shell(const char *s, char **ret_sh, bool *ret_copy);
|
||||
|
||||
#define SAFE_ATO_REFUSE_PLUS_MINUS (1U << 30)
|
||||
#define SAFE_ATO_REFUSE_LEADING_ZERO (1U << 29)
|
||||
|
||||
@@ -1003,29 +1003,6 @@ int config_parse_bind_user(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parse_bind_user_shell(const char *s, char **ret_sh, bool *ret_copy) {
|
||||
char *sh;
|
||||
int r;
|
||||
|
||||
if (path_is_absolute(s) && path_is_normalized(s)) {
|
||||
sh = strdup(s);
|
||||
if (!sh)
|
||||
return -ENOMEM;
|
||||
|
||||
*ret_sh = sh;
|
||||
*ret_copy = false;
|
||||
} else {
|
||||
r = parse_boolean(s);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
*ret_sh = NULL;
|
||||
*ret_copy = r;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_bind_user_shell(
|
||||
const char *unit,
|
||||
const char *filename,
|
||||
@@ -1053,7 +1030,7 @@ int config_parse_bind_user_shell(
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = parse_bind_user_shell(rvalue, &sh, ©);
|
||||
r = parse_user_shell(rvalue, &sh, ©);
|
||||
if (r == -ENOMEM)
|
||||
return log_oom();
|
||||
if (r < 0) {
|
||||
|
||||
@@ -276,8 +276,6 @@ CONFIG_PARSER_PROTOTYPE(config_parse_userns_ownership);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_bind_user);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_bind_user_shell);
|
||||
|
||||
int parse_bind_user_shell(const char *s, char **ret_sh, bool *ret_copy);
|
||||
|
||||
const char* resolv_conf_mode_to_string(ResolvConfMode a) _const_;
|
||||
ResolvConfMode resolv_conf_mode_from_string(const char *s) _pure_;
|
||||
|
||||
|
||||
@@ -1542,7 +1542,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
case ARG_BIND_USER_SHELL: {
|
||||
bool copy = false;
|
||||
char *sh = NULL;
|
||||
r = parse_bind_user_shell(optarg, &sh, ©);
|
||||
r = parse_user_shell(optarg, &sh, ©);
|
||||
if (r == -ENOMEM)
|
||||
return log_oom();
|
||||
if (r < 0)
|
||||
|
||||
Reference in New Issue
Block a user