Commit 318535db authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

fowners: Restore for regular files and pipes

The base idea is trivial, once file descriptor
created the owner is read and set up.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 44492851
......@@ -101,6 +101,50 @@ void show_saved_files(void)
}
}
int restore_fown(int fd, fown_t *fown)
{
struct f_owner_ex owner;
uid_t uids[3];
pid_t pid = getpid();
if (fown->signum) {
if (fcntl(fd, F_SETSIG, fown->signum)) {
pr_perror("%d: Can't set signal", pid);
return -1;
}
}
/* May be untouched */
if (!fown->pid)
return 0;
if (getresuid(&uids[0], &uids[1], &uids[2])) {
pr_perror("%d: Can't get current UIDs", pid);
return -1;
}
if (setresuid(fown->uid, fown->euid, uids[2])) {
pr_perror("%d: Can't set UIDs", pid);
return -1;
}
owner.type = fown->pid_type;
owner.pid = fown->pid;
if (fcntl(fd, F_SETOWN_EX, &owner)) {
pr_perror("%d: Can't setup %d file owner pid",
pid, fd);
return -1;
}
if (setresuid(uids[0], uids[1], uids[2])) {
pr_perror("%d: Can't revert UIDs back", pid);
return -1;
}
return 0;
}
static int open_fe_fd(struct file_desc *d);
static struct file_desc_ops reg_desc_ops = {
......@@ -233,6 +277,9 @@ static int open_fe_fd(struct file_desc *d)
lseek(tmp, rfi->rfe.pos, SEEK_SET);
if (restore_fown(tmp, &rfi->rfe.fown))
return -1;
return tmp;
}
int open_reg_by_id(u32 id)
......
......@@ -55,6 +55,7 @@ extern void file_desc_add(struct file_desc *d, int type, u32 id,
extern struct fdinfo_list_entry *file_master(struct file_desc *d);
extern struct file_desc *find_file_desc_raw(int type, u32 id);
extern int send_fd_to_peer(int fd, struct fdinfo_list_entry *, int transport);
extern int restore_fown(int fd, fown_t *fown);
void show_saved_files(void);
extern int collect_reg_files(void);
......
......@@ -301,5 +301,8 @@ out:
if (ret < 0)
return -1;
if (restore_fown(tmp, &pi->pe.fown))
return -1;
return tmp;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment