systemd: merge branch systemd into master

This commit is contained in:
Beniamino Galvani 2020-10-05 17:10:24 +02:00
commit fa7f83b26a
12 changed files with 119 additions and 42 deletions

View file

@ -946,6 +946,42 @@ int search_and_fopen_nulstr(const char *path, const char *mode, const char *root
return search_and_fopen_internal(path, mode, root, s, _f);
}
int chase_symlinks_and_fopen_unlocked(
const char *path,
const char *root,
unsigned chase_flags,
const char *open_flags,
FILE **ret_file,
char **ret_path) {
_cleanup_close_ int fd = -1;
_cleanup_free_ char *final_path = NULL;
int mode_flags, r;
FILE *f;
assert(path);
assert(open_flags);
assert(ret_file);
mode_flags = mode_to_flags(open_flags);
if (mode_flags < 0)
return mode_flags;
fd = chase_symlinks_and_open(path, root, chase_flags, mode_flags, ret_path ? &final_path : NULL);
if (fd < 0)
return fd;
r = fdopen_unlocked(fd, open_flags, &f);
if (r < 0)
return r;
TAKE_FD(fd);
*ret_file = f;
if (ret_path)
*ret_path = TAKE_PTR(final_path);
return 0;
}
#endif /* NM_IGNORED */
int fflush_and_check(FILE *f) {

View file

@ -81,6 +81,14 @@ int xfopenat(int dir_fd, const char *path, const char *mode, int flags, FILE **r
int search_and_fopen(const char *path, const char *mode, const char *root, const char **search, FILE **_f);
int search_and_fopen_nulstr(const char *path, const char *mode, const char *root, const char *search, FILE **_f);
int chase_symlinks_and_fopen_unlocked(
const char *path,
const char *root,
unsigned chase_flags,
const char *open_flags,
FILE **ret_file,
char **ret_path);
int fflush_and_check(FILE *f);
int fflush_sync_and_check(FILE *f);

View file

@ -317,6 +317,25 @@ int fchmod_opath(int fd, mode_t m) {
return 0;
}
int futimens_opath(int fd, const struct timespec ts[2]) {
char procfs_path[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int)];
/* Similar to fchmod_path() but for futimens() */
xsprintf(procfs_path, "/proc/self/fd/%i", fd);
if (utimensat(AT_FDCWD, procfs_path, ts, 0) < 0) {
if (errno != ENOENT)
return -errno;
if (proc_mounted() == 0)
return -ENOSYS; /* if we have no /proc/, the concept is not implementable */
return -ENOENT;
}
return 0;
}
int stat_warn_permissions(const char *path, const struct stat *st) {
assert(path);
assert(st);

View file

@ -38,6 +38,8 @@ int fchmod_and_chown(int fd, mode_t mode, uid_t uid, gid_t gid);
int fchmod_umask(int fd, mode_t mode);
int fchmod_opath(int fd, mode_t m);
int futimens_opath(int fd, const struct timespec ts[2]);
int fd_warn_permissions(const char *path, int fd);
int stat_warn_permissions(const char *path, const struct stat *st);
@ -79,7 +81,7 @@ enum {
CHASE_PREFIX_ROOT = 1 << 0, /* The specified path will be prefixed by the specified root before beginning the iteration */
CHASE_NONEXISTENT = 1 << 1, /* It's OK if the path doesn't actually exist. */
CHASE_NO_AUTOFS = 1 << 2, /* Return -EREMOTE if autofs mount point found */
CHASE_SAFE = 1 << 3, /* Return EPERM if we ever traverse from unprivileged to privileged files or directories */
CHASE_SAFE = 1 << 3, /* Return -EPERM if we ever traverse from unprivileged to privileged files or directories */
CHASE_TRAIL_SLASH = 1 << 4, /* Any trailing slash will be preserved */
CHASE_STEP = 1 << 5, /* Just execute a single step of the normalization */
CHASE_NOFOLLOW = 1 << 6, /* Do not follow the path's right-most component. With ret_fd, when the path's

View file

@ -30,7 +30,7 @@ typedef enum LogTarget{
LOG_TARGET_JOURNAL_OR_KMSG,
LOG_TARGET_SYSLOG,
LOG_TARGET_SYSLOG_OR_KMSG,
LOG_TARGET_AUTO, /* console if stderr is tty, JOURNAL_OR_KMSG otherwise */
LOG_TARGET_AUTO, /* console if stderr is not journal, JOURNAL_OR_KMSG otherwise */
LOG_TARGET_NULL,
_LOG_TARGET_MAX,
_LOG_TARGET_INVALID = -1
@ -61,10 +61,13 @@ void log_show_location(bool b);
bool log_get_show_location(void) _pure_;
void log_show_time(bool b);
bool log_get_show_time(void) _pure_;
void log_show_tid(bool b);
bool log_get_show_tid(void) _pure_;
int log_show_color_from_string(const char *e);
int log_show_location_from_string(const char *e);
int log_show_time_from_string(const char *e);
int log_show_tid_from_string(const char *e);
LogTarget log_get_target(void) _pure_;
#if 0 /* NM_IGNORED */

View file

@ -373,7 +373,7 @@ int strv_split_colon_pairs(char ***t, const char *s) {
}
#endif /* NM_IGNORED */
char *strv_join_prefix(char * const *l, const char *separator, const char *prefix) {
char *strv_join_full(char * const *l, const char *separator, const char *prefix, bool unescape_separators) {
char * const *s;
char *r, *e;
size_t n, k, m;
@ -384,11 +384,17 @@ char *strv_join_prefix(char * const *l, const char *separator, const char *prefi
k = strlen(separator);
m = strlen_ptr(prefix);
if (unescape_separators) /* If there separator is multi-char, we won't know how to escape it. */
assert(k == 1);
n = 0;
STRV_FOREACH(s, l) {
if (s != l)
n += k;
n += m + strlen(*s);
bool needs_escaping = unescape_separators && strchr(*s, separator[0]);
n += m + strlen(*s) * (1 + needs_escaping);
}
r = new(char, n+1);
@ -403,7 +409,16 @@ char *strv_join_prefix(char * const *l, const char *separator, const char *prefi
if (prefix)
e = stpcpy(e, prefix);
e = stpcpy(e, *s);
bool needs_escaping = unescape_separators && strchr(*s, separator[0]);
if (needs_escaping)
for (size_t i = 0; (*s)[i]; i++) {
if ((*s)[i] == separator[0])
*(e++) = '\\';
*(e++) = (*s)[i];
}
else
e = stpcpy(e, *s);
}
*e = 0;

View file

@ -91,9 +91,9 @@ static inline char **strv_split(const char *s, const char *separators) {
* string in the vector is an empty string. */
int strv_split_colon_pairs(char ***t, const char *s);
char *strv_join_prefix(char * const *l, const char *separator, const char *prefix);
char *strv_join_full(char * const *l, const char *separator, const char *prefix, bool escape_separtor);
static inline char *strv_join(char * const *l, const char *separator) {
return strv_join_prefix(l, separator, NULL);
return strv_join_full(l, separator, NULL, false);
}
char **strv_parse_nulstr(const char *s, size_t l);

View file

@ -3,7 +3,7 @@
#include <grp.h>
#if ENABLE_GSHADOW
#include <gshadow.h>
# include <gshadow.h>
#endif
#include <pwd.h>
#include <shadow.h>
@ -61,32 +61,6 @@ int take_etc_passwd_lock(const char *root);
#define ETC_PASSWD_LOCK_PATH "/etc/.pwd.lock"
#if 0 /* NM_ENABLED */
static inline bool uid_is_system(uid_t uid) {
return uid <= SYSTEM_UID_MAX;
}
static inline bool gid_is_system(gid_t gid) {
return gid <= SYSTEM_GID_MAX;
}
static inline bool uid_is_dynamic(uid_t uid) {
return DYNAMIC_UID_MIN <= uid && uid <= DYNAMIC_UID_MAX;
}
static inline bool gid_is_dynamic(gid_t gid) {
return uid_is_dynamic((uid_t) gid);
}
static inline bool uid_is_container(uid_t uid) {
return CONTAINER_UID_BASE_MIN <= uid && uid <= CONTAINER_UID_BASE_MAX;
}
static inline bool gid_is_container(gid_t gid) {
return uid_is_container((uid_t) gid);
}
#endif /* NM_ENABLED */
/* The following macros add 1 when converting things, since UID 0 is a valid UID, while the pointer
* NULL is special */
#define PTR_TO_UID(p) ((uid_t) (((uintptr_t) (p))-1))

View file

@ -45,8 +45,9 @@ int dns_label_unescape(const char **name, char *dest, size_t sz, DNSLabelFlags f
/* Trailing dash */
return -EINVAL;
if (*n == '.')
if (n[0] == '.' && (n[1] != 0 || !FLAGS_SET(flags, DNS_LABEL_LEAVE_TRAILING_DOT)))
n++;
break;
}
@ -143,7 +144,7 @@ int dns_label_unescape(const char **name, char *dest, size_t sz, DNSLabelFlags f
return -EINVAL;
/* More than one trailing dot? */
if (*n == '.')
if (n[0] == '.' && !FLAGS_SET(flags, DNS_LABEL_LEAVE_TRAILING_DOT))
return -EINVAL;
if (sz >= 1 && d)
@ -1383,4 +1384,20 @@ int dns_name_is_valid_or_address(const char *name) {
return dns_name_is_valid(name);
}
int dns_name_dot_suffixed(const char *name) {
const char *p = name;
int r;
for (;;) {
if (streq(p, "."))
return true;
r = dns_label_unescape(&p, NULL, DNS_LABEL_MAX, DNS_LABEL_LEAVE_TRAILING_DOT);
if (r < 0)
return r;
if (r == 0)
return false;
}
}
#endif /* NM_IGNORED */

View file

@ -25,8 +25,9 @@
#define DNS_N_LABELS_MAX 127
typedef enum DNSLabelFlags {
DNS_LABEL_LDH = 1 << 0, /* Follow the "LDH" rule — only letters, digits, and internal hyphens. */
DNS_LABEL_NO_ESCAPES = 1 << 1, /* Do not treat backslashes specially */
DNS_LABEL_LDH = 1 << 0, /* Follow the "LDH" rule — only letters, digits, and internal hyphens. */
DNS_LABEL_NO_ESCAPES = 1 << 1, /* Do not treat backslashes specially */
DNS_LABEL_LEAVE_TRAILING_DOT = 1 << 2, /* Leave trailing dot in place */
} DNSLabelFlags;
int dns_label_unescape(const char **name, char *dest, size_t sz, DNSLabelFlags flags);
@ -112,3 +113,5 @@ int dns_name_common_suffix(const char *a, const char *b, const char **ret);
int dns_name_apply_idna(const char *name, char **ret);
int dns_name_is_valid_or_address(const char *name);
int dns_name_dot_suffixed(const char *name);

View file

@ -781,7 +781,7 @@ int dhcp_lease_parse_search_domains(const uint8_t *option, size_t len, char ***d
return r;
n += r;
} else if ((c & 0xc0) == 0xc0) {
} else if (FLAGS_SET(c, 0xc0)) {
/* Pointer */
uint8_t d;

View file

@ -272,7 +272,7 @@ static int dhcp6_client_set_duid_internal(
assert_return(duid_len == 0 || duid != NULL, -EINVAL);
assert_return(IN_SET(client->state, DHCP6_STATE_STOPPED), -EBUSY);
if (duid != NULL) {
if (duid) {
r = dhcp_validate_duid_len(duid_type, duid_len, true);
if (r < 0) {
r = dhcp_validate_duid_len(duid_type, duid_len, false);
@ -734,7 +734,7 @@ static int client_send_message(sd_dhcp6_client *client, usec_t time_now) {
if (r < 0)
return r;
if (FLAGS_SET(client->request, DHCP6_REQUEST_IA_NA)) {
if (FLAGS_SET(client->request, DHCP6_REQUEST_IA_NA) && client->lease->ia.addresses) {
r = dhcp6_option_append_ia(&opt, &optlen,
&client->lease->ia);
if (r < 0)
@ -773,7 +773,7 @@ static int client_send_message(sd_dhcp6_client *client, usec_t time_now) {
return r;
}
if (FLAGS_SET(client->request, DHCP6_REQUEST_IA_PD)) {
if (FLAGS_SET(client->request, DHCP6_REQUEST_IA_PD) && client->lease->pd.addresses) {
r = dhcp6_option_append_pd(opt, optlen, &client->lease->pd, NULL);
if (r < 0)
return r;