mirror of
https://repo.or.cz/socat.git
synced 2025-07-14 15:23:24 +00:00
Restrict option umask to the address it is applied to
This commit is contained in:
parent
254958a34d
commit
e5cbf2feeb
10 changed files with 208 additions and 14 deletions
18
xioopen.c
18
xioopen.c
|
@ -621,6 +621,9 @@ int xioopen_single(xiofile_t *xfd, int xioflags) {
|
|||
struct single *sfd = &xfd->stream;
|
||||
const struct addrdesc *addrdesc;
|
||||
const char *modetext[4] = { "none", "read-only", "write-only", "read-write" } ;
|
||||
/* Values to be saved until xioopen() is finished */
|
||||
bool have_umask = false;
|
||||
mode_t orig_umask, tmp_umask;
|
||||
int result;
|
||||
/* Values to be saved until xioopen() is finished */
|
||||
#if WITH_RESOLVE && HAVE_RESOLV_H
|
||||
|
@ -633,6 +636,8 @@ int xioopen_single(xiofile_t *xfd, int xioflags) {
|
|||
#endif
|
||||
int rc;
|
||||
|
||||
/* Apply "temporary" process properties, save value for later restore */
|
||||
|
||||
if (applyopts_single(sfd, sfd->opts, PH_OFFSET) < 0)
|
||||
return -1;
|
||||
|
||||
|
@ -676,10 +681,23 @@ int xioopen_single(xiofile_t *xfd, int xioflags) {
|
|||
}
|
||||
xfd->stream.flags &= (~XIO_ACCMODE);
|
||||
xfd->stream.flags |= (xioflags & XIO_ACCMODE);
|
||||
|
||||
if (retropt_mode(xfd->stream.opts, OPT_UMASK, &tmp_umask) >= 0) {
|
||||
Info1("changing umask to 0%3o", tmp_umask);
|
||||
orig_umask = Umask(tmp_umask);
|
||||
have_umask = true;
|
||||
}
|
||||
|
||||
result = (*addrdesc->func)(xfd->stream.argc, xfd->stream.argv,
|
||||
xfd->stream.opts, xioflags, xfd,
|
||||
addrdesc);
|
||||
|
||||
/* Restore process properties */
|
||||
if (have_umask) {
|
||||
Info1("restoring umask to 0%3o", orig_umask);
|
||||
Umask(orig_umask);
|
||||
}
|
||||
|
||||
#if WITH_RESOLVE && HAVE_RESOLV_H
|
||||
if (do_res)
|
||||
xio_res_restore(&save_res);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue