You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
3.5 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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 */
  4. /* this file handles process related addresses options */
  5. #include "xiosysincludes.h"
  6. #include "xioopen.h"
  7. #include "xio-process.h"
  8. /****** process related options ******/
  9. const struct optdesc opt_setgid_early= { "setgid-early",NULL, OPT_SETGID_EARLY,GROUP_PROCESS, PH_EARLY, TYPE_GIDT, OFUNC_SPEC };
  10. const struct optdesc opt_setgid = { "setgid", NULL, OPT_SETGID, GROUP_PROCESS, PH_LATE2, TYPE_GIDT, OFUNC_SPEC };
  11. const struct optdesc opt_setuid_early= { "setuid-early",NULL, OPT_SETUID_EARLY,GROUP_PROCESS, PH_EARLY, TYPE_UIDT, OFUNC_SPEC };
  12. const struct optdesc opt_setuid = { "setuid", NULL, OPT_SETUID, GROUP_PROCESS, PH_LATE2, TYPE_UIDT, OFUNC_SPEC };
  13. const struct optdesc opt_substuser_early = { "substuser-early", "su-e", OPT_SUBSTUSER_EARLY, GROUP_PROCESS, PH_EARLY, TYPE_UIDT, OFUNC_SPEC };
  14. const struct optdesc opt_substuser = { "substuser", "su", OPT_SUBSTUSER, GROUP_PROCESS, PH_LATE2, TYPE_UIDT, OFUNC_SPEC };
  15. #if defined(HAVE_SETGRENT) && defined(HAVE_GETGRENT) && defined(HAVE_ENDGRENT)
  16. const struct optdesc opt_substuser_delayed = { "substuser-delayed", "su-d", OPT_SUBSTUSER_DELAYED, GROUP_PROCESS, PH_INIT, TYPE_UIDT, OFUNC_SPEC };
  17. #endif
  18. const struct optdesc opt_chroot_early = { "chroot-early", NULL, OPT_CHROOT_EARLY, GROUP_PROCESS, PH_EARLY, TYPE_STRING, OFUNC_SPEC };
  19. const struct optdesc opt_chroot = { "chroot", NULL, OPT_CHROOT, GROUP_PROCESS, PH_LATE, TYPE_STRING, OFUNC_SPEC };
  20. const struct optdesc opt_setsid = { "setsid", "sid", OPT_SETSID, GROUP_PROCESS, PH_LATE, TYPE_BOOL, OFUNC_SPEC };
  21. const struct optdesc opt_setpgid = { "setpgid", "pgid",OPT_SETPGID, GROUP_FORK, PH_LATE, TYPE_INT, OFUNC_SPEC };
  22. /* for option substuser-delayed, save info for later application */
  23. bool delayeduser = false;
  24. uid_t delayeduser_uid; /* numeric user id to switch to */
  25. gid_t delayeduser_gid; /* numeric group id to switch to */
  26. gid_t delayeduser_gids[NGROUPS]; /* num.supplementary group ids */
  27. int delayeduser_ngids; /* number of suppl. gids */
  28. char *delayeduser_name; /* name of user to switch to */
  29. char *delayeduser_dir; /* home directory of user to switch to */
  30. char *delayeduser_shell; /* login shell of user to switch to */
  31. int _xioopen_setdelayeduser(void) {
  32. if (delayeduser) {
  33. #if HAVE_SETGROUPS
  34. if ((Setgroups(delayeduser_ngids, delayeduser_gids)) != 0) {
  35. Error3("setgroups(%d, %p): %s",
  36. delayeduser_ngids, delayeduser_gids, strerror(errno));
  37. }
  38. #endif /* HAVE_SETGROUPS */
  39. if (Setgid(delayeduser_gid) < 0) {
  40. Error2("setgid("F_gid"): %s", delayeduser_gid,
  41. strerror(errno));
  42. }
  43. if (Setuid(delayeduser_uid) < 0) {
  44. Error2("setuid("F_uid"): %s", delayeduser_uid,
  45. strerror(errno));
  46. }
  47. #if 1
  48. if (setenv("USER", delayeduser_name, 1) < 0)
  49. Error1("setenv(\"USER\", \"%s\", 1): insufficient space",
  50. delayeduser_name);
  51. if (setenv("LOGNAME", delayeduser_name, 1) < 0)
  52. Error1("setenv(\"LOGNAME\", \"%s\", 1): insufficient space",
  53. delayeduser_name);
  54. if (setenv("HOME", delayeduser_dir, 1) < 0)
  55. Error1("setenv(\"HOME\", \"%s\", 1): insufficient space",
  56. delayeduser_dir);
  57. if (setenv("SHELL", delayeduser_shell, 1) < 0)
  58. Error1("setenv(\"SHELL\", \"%s\", 1): insufficient space",
  59. delayeduser_shell);
  60. #endif
  61. delayeduser = false;
  62. }
  63. return 0;
  64. }