1 /* source: xio-process.c */
2 /* Copyright Gerhard Rieger 2001-2009 */
3 /* Published under the GNU General Public License V.2, see file COPYING */
5 /* this file handles process related addresses options */
7 #include "xiosysincludes.h"
10 #include "xio-process.h"
12 /****** process related options ******/
13 const struct optdesc opt_setgid_early
= { "setgid-early",NULL
, OPT_SETGID_EARLY
,GROUP_PROCESS
, PH_EARLY
, TYPE_GIDT
, OFUNC_SPEC
};
14 const struct optdesc opt_setgid
= { "setgid", NULL
, OPT_SETGID
, GROUP_PROCESS
, PH_LATE2
, TYPE_GIDT
, OFUNC_SPEC
};
15 const struct optdesc opt_setuid_early
= { "setuid-early",NULL
, OPT_SETUID_EARLY
,GROUP_PROCESS
, PH_EARLY
, TYPE_UIDT
, OFUNC_SPEC
};
16 const struct optdesc opt_setuid
= { "setuid", NULL
, OPT_SETUID
, GROUP_PROCESS
, PH_LATE2
, TYPE_UIDT
, OFUNC_SPEC
};
17 const struct optdesc opt_substuser_early
= { "substuser-early", "su-e", OPT_SUBSTUSER_EARLY
, GROUP_PROCESS
, PH_EARLY
, TYPE_UIDT
, OFUNC_SPEC
};
18 const struct optdesc opt_substuser
= { "substuser", "su", OPT_SUBSTUSER
, GROUP_PROCESS
, PH_LATE2
, TYPE_UIDT
, OFUNC_SPEC
};
19 const struct optdesc opt_substuser_delayed
= { "substuser-delayed", "su-d", OPT_SUBSTUSER_DELAYED
, GROUP_PROCESS
, PH_INIT
, TYPE_UIDT
, OFUNC_SPEC
};
20 const struct optdesc opt_chroot_early
= { "chroot-early", NULL
, OPT_CHROOT_EARLY
, GROUP_PROCESS
, PH_EARLY
, TYPE_STRING
, OFUNC_SPEC
};
21 const struct optdesc opt_chroot
= { "chroot", NULL
, OPT_CHROOT
, GROUP_PROCESS
, PH_LATE
, TYPE_STRING
, OFUNC_SPEC
};
22 const struct optdesc opt_setsid
= { "setsid", "sid", OPT_SETSID
, GROUP_PROCESS
, PH_LATE
, TYPE_BOOL
, OFUNC_SPEC
};
23 const struct optdesc opt_setpgid
= { "setpgid", "pgid",OPT_SETPGID
, GROUP_FORK
, PH_LATE
, TYPE_INT
, OFUNC_SPEC
};
26 /* for option substuser-delayed, save info for later application */
27 bool delayeduser
= false;
28 uid_t delayeduser_uid
; /* numeric user id to switch to */
29 gid_t delayeduser_gid
; /* numeric group id to switch to */
30 gid_t delayeduser_gids
[NGROUPS
]; /* num.supplementary group ids */
31 size_t delayeduser_ngids
; /* number of suppl. gids */
32 char *delayeduser_name
; /* name of user to switch to */
33 char *delayeduser_dir
; /* home directory of user to switch to */
34 char *delayeduser_shell
; /* login shell of user to switch to */
37 int _xioopen_setdelayeduser(void) {
40 if ((Setgroups(delayeduser_ngids
, delayeduser_gids
)) != 0) {
41 Error3("setgroups("F_Zu
", %p): %s",
42 delayeduser_ngids
, delayeduser_gids
, strerror(errno
));
44 #endif /* HAVE_SETGROUPS */
45 if (Setgid(delayeduser_gid
) < 0) {
46 Error2("setgid("F_gid
"): %s", delayeduser_gid
,
49 if (Setuid(delayeduser_uid
) < 0) {
50 Error2("setuid("F_uid
"): %s", delayeduser_uid
,
54 if (setenv("USER", delayeduser_name
, 1) < 0)
55 Error1("setenv(\"USER\", \"%s\", 1): insufficient space",
57 if (setenv("LOGNAME", delayeduser_name
, 1) < 0)
58 Error1("setenv(\"LOGNAME\", \"%s\", 1): insufficient space",
60 if (setenv("HOME", delayeduser_dir
, 1) < 0)
61 Error1("setenv(\"HOME\", \"%s\", 1): insufficient space",
63 if (setenv("SHELL", delayeduser_shell
, 1) < 0)
64 Error1("setenv(\"SHELL\", \"%s\", 1): insufficient space",