File: xio-process.c

package info (click to toggle)
socat 1.4.2.0-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,144 kB
  • ctags: 3,624
  • sloc: ansic: 18,730; sh: 3,319; makefile: 153
file content (70 lines) | stat: -rw-r--r-- 3,316 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* $Id: xio-process.c,v 1.9 2003/05/21 05:16:38 gerhard Exp $ */
/* Copyright Gerhard Rieger 2001-2003 */
/* Published under the GNU General Public License V.2, see file COPYING */

/* this file handles process related addresses options */

#include "xiosysincludes.h"
#include "xioopen.h"

#include "xio-process.h"

/****** process related options ******/
const struct optdesc opt_setgid_early= { "setgid-early",NULL,  OPT_SETGID_EARLY,GROUP_PROCESS, PH_EARLY,   TYPE_GIDT, OFUNC_SPEC };
const struct optdesc opt_setgid      = { "setgid",      NULL,  OPT_SETGID,      GROUP_PROCESS, PH_LATE2,    TYPE_GIDT, OFUNC_SPEC };
const struct optdesc opt_setuid_early= { "setuid-early",NULL,  OPT_SETUID_EARLY,GROUP_PROCESS, PH_EARLY,   TYPE_UIDT, OFUNC_SPEC };
const struct optdesc opt_setuid      = { "setuid",      NULL,  OPT_SETUID,      GROUP_PROCESS, PH_LATE2,    TYPE_UIDT, OFUNC_SPEC };
const struct optdesc opt_substuser   = { "substuser", "su",  OPT_SUBSTUSER,   GROUP_PROCESS, PH_LATE2,  TYPE_UIDT, OFUNC_SPEC };
const struct optdesc opt_substuser_delayed = { "substuser-delayed", "su-d", OPT_SUBSTUSER_DELAYED,   GROUP_PROCESS, PH_INIT,  TYPE_UIDT, OFUNC_SPEC };
const struct optdesc opt_chroot_early = { "chroot-early", NULL, OPT_CHROOT_EARLY, GROUP_PROCESS, PH_EARLY, TYPE_STRING, OFUNC_SPEC };
const struct optdesc opt_chroot       = { "chroot",       NULL, OPT_CHROOT,       GROUP_PROCESS, PH_LATE, TYPE_STRING, OFUNC_SPEC };
const struct optdesc opt_setsid  = { "setsid",    "sid", OPT_SETSID,     GROUP_PROCESS,   PH_LATE, TYPE_BOOL,     OFUNC_SPEC };
const struct optdesc opt_setpgid = { "setpgid",   "pgid",OPT_SETPGID,    GROUP_FORK,   PH_LATE, TYPE_INT,      OFUNC_SPEC };


/* for option substuser-delayed, save info for later application */
bool delayeduser = false;
uid_t delayeduser_uid;	/* numeric user id to switch to */
gid_t delayeduser_gid;	/* numeric group id to switch to */
gid_t delayeduser_gids[NGROUPS];	/* num.supplementary group ids */
size_t delayeduser_ngids;	/* number of suppl. gids */
char *delayeduser_name;	/* name of user to switch to */
char *delayeduser_dir;	/* home directory of user to switch to */
char *delayeduser_shell;	/* login shell of user to switch to */


int _xioopen_setdelayeduser(void) {
   if (delayeduser) {
#if HAVE_SETGROUPS
      if ((Setgroups(delayeduser_ngids, delayeduser_gids)) != 0) {
	 Error3("setgroups("F_Zu", %p): %s",
		delayeduser_ngids, delayeduser_gids, strerror(errno));
      }
#endif /* HAVE_SETGROUPS */
      if (Setgid(delayeduser_gid) < 0) {
	 Error2("setgid("F_gid"): %s", delayeduser_gid,
		strerror(errno));
      }
      if (Setuid(delayeduser_uid) < 0) {
	 Error2("setuid("F_uid"): %s", delayeduser_uid,
		strerror(errno));
      }
#if 1
      if (setenv("USER", delayeduser_name, 1) < 0)
	 Error1("setenv(\"USER\", \"%s\", 1): insufficient space",
		delayeduser_name);
      if (setenv("LOGNAME", delayeduser_name, 1) < 0)
	 Error1("setenv(\"LOGNAME\", \"%s\", 1): insufficient space",
		delayeduser_name);
      if (setenv("HOME", delayeduser_dir, 1) < 0)
	 Error1("setenv(\"HOME\", \"%s\", 1): insufficient space",
		delayeduser_dir);
      if (setenv("SHELL", delayeduser_shell, 1) < 0)
	 Error1("setenv(\"SHELL\", \"%s\", 1): insufficient space",
		delayeduser_shell);
#endif
      delayeduser = false;
   }
   return 0;
}