1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-23 17:34:00 +03:00

fileio: Refactor sync_rights to take fds as arguments

This commit is contained in:
Daan De Meyer 2020-05-26 20:00:45 +02:00
parent 494735f3d0
commit 90c81688ff
3 changed files with 8 additions and 8 deletions

View File

@ -1188,13 +1188,13 @@ int warn_file_is_world_accessible(const char *filename, struct stat *st, const c
return 0;
}
int sync_rights(FILE *from, const char *to) {
int sync_rights(int from, int to) {
struct stat st;
if (fstat(fileno(from), &st) < 0)
if (fstat(from, &st) < 0)
return -errno;
return chmod_and_chown_unsafe(to, st.st_mode & 07777, st.st_uid, st.st_gid);
return fchmod_and_chown(to, st.st_mode & 07777, st.st_uid, st.st_gid);
}
int rename_and_apply_smack(const char *from, const char *to) {

View File

@ -107,6 +107,6 @@ int safe_fgetc(FILE *f, char *ret);
int warn_file_is_world_accessible(const char *filename, struct stat *st, const char *unit, unsigned line);
int sync_rights(FILE *from, const char *to);
int sync_rights(int from, int to);
int rename_and_apply_smack(const char *temp_path, const char *dest_path);

View File

@ -367,7 +367,7 @@ static int write_temporary_passwd(const char *passwd_path, FILE **tmpfile, char
original = fopen(passwd_path, "re");
if (original) {
r = sync_rights(original, passwd_tmp);
r = sync_rights(fileno(original), fileno(passwd));
if (r < 0)
return r;
@ -469,7 +469,7 @@ static int write_temporary_shadow(const char *shadow_path, FILE **tmpfile, char
original = fopen(shadow_path, "re");
if (original) {
r = sync_rights(original, shadow_tmp);
r = sync_rights(fileno(original), fileno(shadow));
if (r < 0)
return r;
@ -566,7 +566,7 @@ static int write_temporary_group(const char *group_path, FILE **tmpfile, char **
original = fopen(group_path, "re");
if (original) {
r = sync_rights(original, group_tmp);
r = sync_rights(fileno(original), fileno(group));
if (r < 0)
return r;
@ -665,7 +665,7 @@ static int write_temporary_gshadow(const char * gshadow_path, FILE **tmpfile, ch
if (original) {
struct sgrp *sg;
r = sync_rights(original, gshadow_tmp);
r = sync_rights(fileno(original), fileno(gshadow));
if (r < 0)
return r;