Fixed compilation failure on 32bit FreeBSD and other due to int64_t being long long
[socat.git] / xio-process.c
blobb43a480470f429a8eb5e12d1f4fcbbc47b3aa46b
1 /* source: xio-process.c */
2 /* Copyright Gerhard Rieger and contributors (see file CHANGES) */
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"
8 #include "xioopen.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 #if defined(HAVE_SETGRENT) && defined(HAVE_GETGRENT) && defined(HAVE_ENDGRENT)
20 const struct optdesc opt_substuser_delayed = { "substuser-delayed", "su-d", OPT_SUBSTUSER_DELAYED, GROUP_PROCESS, PH_INIT, TYPE_UIDT, OFUNC_SPEC };
21 #endif
22 const struct optdesc opt_chroot_early = { "chroot-early", NULL, OPT_CHROOT_EARLY, GROUP_PROCESS, PH_EARLY, TYPE_STRING, OFUNC_SPEC };
23 const struct optdesc opt_chroot = { "chroot", NULL, OPT_CHROOT, GROUP_PROCESS, PH_LATE, TYPE_STRING, OFUNC_SPEC };
24 const struct optdesc opt_setsid = { "setsid", "sid", OPT_SETSID, GROUP_PROCESS, PH_LATE, TYPE_BOOL, OFUNC_SPEC };
25 const struct optdesc opt_setpgid = { "setpgid", "pgid",OPT_SETPGID, GROUP_FORK, PH_LATE, TYPE_INT, OFUNC_SPEC };
28 /* for option substuser-delayed, save info for later application */
29 bool delayeduser = false;
30 uid_t delayeduser_uid; /* numeric user id to switch to */
31 gid_t delayeduser_gid; /* numeric group id to switch to */
32 gid_t delayeduser_gids[NGROUPS]; /* num.supplementary group ids */
33 int delayeduser_ngids; /* number of suppl. gids */
34 char *delayeduser_name; /* name of user to switch to */
35 char *delayeduser_dir; /* home directory of user to switch to */
36 char *delayeduser_shell; /* login shell of user to switch to */
39 int _xioopen_setdelayeduser(void) {
40 if (delayeduser) {
41 #if HAVE_SETGROUPS
42 if ((Setgroups(delayeduser_ngids, delayeduser_gids)) != 0) {
43 Error3("setgroups(%d, %p): %s",
44 delayeduser_ngids, delayeduser_gids, strerror(errno));
46 #endif /* HAVE_SETGROUPS */
47 if (Setgid(delayeduser_gid) < 0) {
48 Error2("setgid("F_gid"): %s", delayeduser_gid,
49 strerror(errno));
51 if (Setuid(delayeduser_uid) < 0) {
52 Error2("setuid("F_uid"): %s", delayeduser_uid,
53 strerror(errno));
55 #if 1
56 if (setenv("USER", delayeduser_name, 1) < 0)
57 Error1("setenv(\"USER\", \"%s\", 1): insufficient space",
58 delayeduser_name);
59 if (setenv("LOGNAME", delayeduser_name, 1) < 0)
60 Error1("setenv(\"LOGNAME\", \"%s\", 1): insufficient space",
61 delayeduser_name);
62 if (setenv("HOME", delayeduser_dir, 1) < 0)
63 Error1("setenv(\"HOME\", \"%s\", 1): insufficient space",
64 delayeduser_dir);
65 if (setenv("SHELL", delayeduser_shell, 1) < 0)
66 Error1("setenv(\"SHELL\", \"%s\", 1): insufficient space",
67 delayeduser_shell);
68 #endif
69 delayeduser = false;
71 return 0;