mirror of
https://github.com/topjohnwu/selinux.git
synced 2024-12-12 22:05:58 +00:00
libselinux: maintain mode even if umask is tighter
When certain programs were run which created new files they would get default permissions based on the current users umask. However these files should get the same permissions as those files which they replaced. Do that. Patch from: Stephen Smalley Signed-off-by: Eric Paris <eparis@redhat.com> Acked-by: Dan Walsh <dwalsh@redhat.com>
This commit is contained in:
parent
023c9c1fde
commit
86e8daafc3
@ -495,6 +495,7 @@ static int semanage_copy_file(const char *src, const char *dst, mode_t mode)
|
||||
int in, out, retval = 0, amount_read, n, errsv = errno;
|
||||
char tmp[PATH_MAX];
|
||||
char buf[4192];
|
||||
mode_t mask;
|
||||
|
||||
n = snprintf(tmp, PATH_MAX, "%s.tmp", dst);
|
||||
if (n < 0 || n >= PATH_MAX)
|
||||
@ -506,13 +507,16 @@ static int semanage_copy_file(const char *src, const char *dst, mode_t mode)
|
||||
|
||||
if (!mode)
|
||||
mode = S_IRUSR | S_IWUSR;
|
||||
|
||||
|
||||
mask = umask(0);
|
||||
if ((out = open(tmp, O_WRONLY | O_CREAT | O_TRUNC, mode)) == -1) {
|
||||
umask(mask);
|
||||
errsv = errno;
|
||||
close(in);
|
||||
retval = -1;
|
||||
goto out;
|
||||
}
|
||||
umask(mask);
|
||||
while (retval == 0 && (amount_read = read(in, buf, sizeof(buf))) > 0) {
|
||||
if (write(out, buf, amount_read) < 0) {
|
||||
errsv = errno;
|
||||
|
Loading…
Reference in New Issue
Block a user