Merge pull request #26269 from keszybz/sysusers-empty-etc-and-improved-messages
sysusers: improve messages and autocreate /etc
This commit is contained in:
@@ -519,17 +519,17 @@ char* path_extend_internal(char **x, ...) {
|
||||
va_list ap;
|
||||
bool slash;
|
||||
|
||||
/* Joins all listed strings until the sentinel and places a "/" between them unless the strings end/begin
|
||||
* already with one so that it is unnecessary. Note that slashes which are already duplicate won't be
|
||||
* removed. The string returned is hence always equal to or longer than the sum of the lengths of each
|
||||
* individual string.
|
||||
/* Joins all listed strings until the sentinel and places a "/" between them unless the strings
|
||||
* end/begin already with one so that it is unnecessary. Note that slashes which are already
|
||||
* duplicate won't be removed. The string returned is hence always equal to or longer than the sum of
|
||||
* the lengths of the individual strings.
|
||||
*
|
||||
* The first argument may be an already allocated string that is extended via realloc() if
|
||||
* non-NULL. path_extend() and path_join() are macro wrappers around this function, making use of the
|
||||
* first parameter to distinguish the two operations.
|
||||
*
|
||||
* Note: any listed empty string is simply skipped. This can be useful for concatenating strings of which some
|
||||
* are optional.
|
||||
* Note: any listed empty string is simply skipped. This can be useful for concatenating strings of
|
||||
* which some are optional.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
|
||||
+14
-22
@@ -19,6 +19,7 @@
|
||||
#include "fileio.h"
|
||||
#include "format-util.h"
|
||||
#include "macro.h"
|
||||
#include "mkdir.h"
|
||||
#include "parse-util.h"
|
||||
#include "path-util.h"
|
||||
#include "path-util.h"
|
||||
@@ -670,7 +671,6 @@ int reset_uid_gid(void) {
|
||||
}
|
||||
|
||||
int take_etc_passwd_lock(const char *root) {
|
||||
|
||||
struct flock flock = {
|
||||
.l_type = F_WRLCK,
|
||||
.l_whence = SEEK_SET,
|
||||
@@ -678,35 +678,27 @@ int take_etc_passwd_lock(const char *root) {
|
||||
.l_len = 0,
|
||||
};
|
||||
|
||||
const char *path;
|
||||
int fd, r;
|
||||
|
||||
/* This is roughly the same as lckpwdf(), but not as awful. We
|
||||
* don't want to use alarm() and signals, hence we implement
|
||||
* our own trivial version of this.
|
||||
/* This is roughly the same as lckpwdf(), but not as awful. We don't want to use alarm() and signals,
|
||||
* hence we implement our own trivial version of this.
|
||||
*
|
||||
* Note that shadow-utils also takes per-database locks in
|
||||
* addition to lckpwdf(). However, we don't given that they
|
||||
* are redundant as they invoke lckpwdf() first and keep
|
||||
* it during everything they do. The per-database locks are
|
||||
* awfully racy, and thus we just won't do them. */
|
||||
* Note that shadow-utils also takes per-database locks in addition to lckpwdf(). However, we don't,
|
||||
* given that they are redundant: they invoke lckpwdf() first and keep it during everything they do.
|
||||
* The per-database locks are awfully racy, and thus we just won't do them. */
|
||||
|
||||
if (root)
|
||||
path = prefix_roota(root, ETC_PASSWD_LOCK_PATH);
|
||||
else
|
||||
path = ETC_PASSWD_LOCK_PATH;
|
||||
_cleanup_free_ char *path = path_join(root, ETC_PASSWD_LOCK_PATH);
|
||||
if (!path)
|
||||
return log_oom_debug();
|
||||
|
||||
fd = open(path, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW, 0600);
|
||||
(void) mkdir_parents(path, 0755);
|
||||
|
||||
_cleanup_close_ int fd = open(path, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW, 0600);
|
||||
if (fd < 0)
|
||||
return log_debug_errno(errno, "Cannot open %s: %m", path);
|
||||
|
||||
r = fcntl(fd, F_SETLKW, &flock);
|
||||
if (r < 0) {
|
||||
safe_close(fd);
|
||||
if (fcntl(fd, F_SETLKW, &flock) < 0)
|
||||
return log_debug_errno(errno, "Locking %s failed: %m", path);
|
||||
}
|
||||
|
||||
return fd;
|
||||
return TAKE_FD(fd);
|
||||
}
|
||||
|
||||
bool valid_user_group_name(const char *u, ValidUserFlags flags) {
|
||||
|
||||
Reference in New Issue
Block a user