if (!f)
return errno == ENOENT ? 0 : -errno;
- r = hashmap_ensure_allocated(&database_user, string_hash_func, string_compare_func);
+ r = hashmap_ensure_allocated(&database_user, &string_hash_ops);
if (r < 0)
return r;
- r = hashmap_ensure_allocated(&database_uid, trivial_hash_func, trivial_compare_func);
+ r = hashmap_ensure_allocated(&database_uid, NULL);
if (r < 0)
return r;
if (!f)
return errno == ENOENT ? 0 : -errno;
- r = hashmap_ensure_allocated(&database_group, string_hash_func, string_compare_func);
+ r = hashmap_ensure_allocated(&database_group, &string_hash_ops);
if (r < 0)
return r;
- r = hashmap_ensure_allocated(&database_gid, trivial_hash_func, trivial_compare_func);
+ r = hashmap_ensure_allocated(&database_gid, NULL);
if (r < 0)
return r;
_cleanup_fclose_ FILE *passwd = NULL, *group = NULL, *shadow = NULL, *gshadow = NULL;
_cleanup_free_ char *passwd_tmp = NULL, *group_tmp = NULL, *shadow_tmp = NULL, *gshadow_tmp = NULL;
const char *passwd_path = NULL, *group_path = NULL, *shadow_path = NULL, *gshadow_path = NULL;
+ struct stat st;
bool group_changed = false;
Iterator iterator;
Item *i;
if (r < 0)
goto finish;
- if (fchmod(fileno(group), 0644) < 0) {
- r = -errno;
- goto finish;
- }
-
original = fopen(group_path, "re");
if (original) {
struct group *gr;
+ if (fstat(fileno(original), &st) < 0 ||
+ fchmod(fileno(group), st.st_mode & 07777) < 0 ||
+ fchown(fileno(group), st.st_uid, st.st_gid) < 0) {
+ r = -errno;
+ goto finish;
+ }
+
errno = 0;
while ((gr = fgetgrent(original))) {
/* Safety checks against name and GID
} else if (errno != ENOENT) {
r = -errno;
goto finish;
+ } else if (fchmod(fileno(group), 0644) < 0) {
+ r = -errno;
+ goto finish;
}
HASHMAP_FOREACH(i, todo_gids, iterator) {
if (r < 0)
goto finish;
- if (fchmod(fileno(gshadow), 0000) < 0) {
- r = -errno;
- goto finish;
- }
-
original = fopen(gshadow_path, "re");
if (original) {
struct sgrp *sg;
+ if (fstat(fileno(original), &st) < 0 ||
+ fchmod(fileno(gshadow), st.st_mode & 07777) < 0 ||
+ fchown(fileno(gshadow), st.st_uid, st.st_gid) < 0) {
+ r = -errno;
+ goto finish;
+ }
+
errno = 0;
while ((sg = fgetsgent(original))) {
} else if (errno != ENOENT) {
r = -errno;
goto finish;
+ } else if (fchmod(fileno(gshadow), 0000) < 0) {
+ r = -errno;
+ goto finish;
}
HASHMAP_FOREACH(i, todo_gids, iterator) {
if (r < 0)
goto finish;
- if (fchmod(fileno(passwd), 0644) < 0) {
- r = -errno;
- goto finish;
- }
-
original = fopen(passwd_path, "re");
if (original) {
struct passwd *pw;
+ if (fstat(fileno(original), &st) < 0 ||
+ fchmod(fileno(passwd), st.st_mode & 07777) < 0 ||
+ fchown(fileno(passwd), st.st_uid, st.st_gid) < 0) {
+ r = -errno;
+ goto finish;
+ }
+
errno = 0;
while ((pw = fgetpwent(original))) {
} else if (errno != ENOENT) {
r = -errno;
goto finish;
+ } else if (fchmod(fileno(passwd), 0644) < 0) {
+ r = -errno;
+ goto finish;
}
HASHMAP_FOREACH(i, todo_uids, iterator) {
if (r < 0)
goto finish;
- if (fchmod(fileno(shadow), 0000) < 0) {
- r = -errno;
- goto finish;
- }
-
original = fopen(shadow_path, "re");
if (original) {
struct spwd *sp;
+ if (fstat(fileno(original), &st) < 0 ||
+ fchmod(fileno(shadow), st.st_mode & 07777) < 0 ||
+ fchown(fileno(shadow), st.st_uid, st.st_gid) < 0) {
+ r = -errno;
+ goto finish;
+ }
+
errno = 0;
while ((sp = fgetspent(original))) {
} else if (errno != ENOENT) {
r = -errno;
goto finish;
+ } else if (fchmod(fileno(shadow), 0000) < 0) {
+ r = -errno;
+ goto finish;
}
lstchg = (long) (now(CLOCK_REALTIME) / USEC_PER_DAY);
static int read_id_from_file(Item *i, uid_t *_uid, gid_t *_gid) {
struct stat st;
bool found_uid = false, found_gid = false;
- uid_t uid;
- gid_t gid;
+ uid_t uid = 0;
+ gid_t gid = 0;
assert(i);
i->uid = search_uid;
}
- r = hashmap_ensure_allocated(&todo_uids, trivial_hash_func, trivial_compare_func);
+ r = hashmap_ensure_allocated(&todo_uids, NULL);
if (r < 0)
return log_oom();
i->gid = search_uid;
}
- r = hashmap_ensure_allocated(&todo_gids, trivial_hash_func, trivial_compare_func);
+ r = hashmap_ensure_allocated(&todo_gids, NULL);
if (r < 0)
return log_oom();
if (!i) {
_cleanup_(item_freep) Item *j = NULL;
- r = hashmap_ensure_allocated(&groups, string_hash_func, string_compare_func);
+ r = hashmap_ensure_allocated(&groups, &string_hash_ops);
if (r < 0)
return log_oom();
if (!i) {
_cleanup_(item_freep) Item *j = NULL;
- r = hashmap_ensure_allocated(&users, string_hash_func, string_compare_func);
+ r = hashmap_ensure_allocated(&users, &string_hash_ops);
if (r < 0)
return log_oom();
return -EINVAL;
}
- r = hashmap_ensure_allocated(&members, string_hash_func, string_compare_func);
+ r = hashmap_ensure_allocated(&members, &string_hash_ops);
if (r < 0)
return log_oom();
return -EINVAL;
}
- r = hashmap_ensure_allocated(&users, string_hash_func, string_compare_func);
+ r = hashmap_ensure_allocated(&users, &string_hash_ops);
if (r < 0)
return log_oom();
return -EINVAL;
}
- r = hashmap_ensure_allocated(&groups, string_hash_func, string_compare_func);
+ r = hashmap_ensure_allocated(&groups, &string_hash_ops);
if (r < 0)
return log_oom();
umask(0022);
- r = label_init(NULL);
+ r = mac_selinux_init(NULL);
if (r < 0) {
log_error("SELinux setup failed: %s", strerror(-r));
goto finish;