initgroups 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. diff -up tcp_wrappers_7.6/options.c.initgroups tcp_wrappers_7.6/options.c
  2. --- tcp_wrappers_7.6/options.c.initgroups 2011-08-11 23:10:43.610418714 +0200
  3. +++ tcp_wrappers_7.6/options.c 2011-08-12 05:51:17.748481294 +0200
  4. @@ -256,8 +256,12 @@ struct request_info *request;
  5. tcpd_jump("unknown group: \"%s\"", value);
  6. endgrent();
  7. - if (dry_run == 0 && setgid(grp->gr_gid))
  8. - tcpd_jump("setgid(%s): %m", value);
  9. + if (dry_run != 0) {
  10. + if (setgid(grp->gr_gid))
  11. + tcpd_jump("setgid(%s): %m", value);
  12. + if (setgroups(0, NULL))
  13. + tcpd_jump("setgroups(%s): %m", value);
  14. + }
  15. }
  16. /* user_option - switch user id */
  17. @@ -271,15 +275,26 @@ struct request_info *request;
  18. struct passwd *pwd;
  19. struct passwd *getpwnam();
  20. char *group;
  21. + int defaultgroup = 0;
  22. if ((group = split_at(value, '.')) != 0)
  23. group_option(group, request);
  24. + else
  25. + defaultgroup = 1;
  26. if ((pwd = getpwnam(value)) == 0)
  27. tcpd_jump("unknown user: \"%s\"", value);
  28. endpwent();
  29. - if (dry_run == 0 && setuid(pwd->pw_uid))
  30. - tcpd_jump("setuid(%s): %m", value);
  31. + if (dry_run != 0) {
  32. + if (setuid(pwd->pw_uid))
  33. + tcpd_jump("setuid(%s): %m", value);
  34. + if (defaultgroup) {
  35. + if (setgid(pwd->pw_gid))
  36. + tcpd_jump("setgid(%s): %m", value);
  37. + if (initgroups(value, pwd->pw_gid))
  38. + tcpd_jump("initgroups(%s): %m", value);
  39. + }
  40. + }
  41. }
  42. /* umask_option - set file creation mask */
  43. diff -up tcp_wrappers_7.6/safe_finger.c.initgroups tcp_wrappers_7.6/safe_finger.c
  44. --- tcp_wrappers_7.6/safe_finger.c.initgroups 2011-08-12 05:54:06.068606291 +0200
  45. +++ tcp_wrappers_7.6/safe_finger.c 2011-08-12 05:55:34.835483785 +0200
  46. @@ -66,9 +66,11 @@ char **argv;
  47. if (getuid() == 0 || geteuid() == 0) {
  48. if ((pwd = getpwnam(UNPRIV_NAME)) && pwd->pw_uid > 0) {
  49. setgid(pwd->pw_gid);
  50. + initgroups(UNPRIV_NAME, pwd->pw_gid);
  51. setuid(pwd->pw_uid);
  52. } else {
  53. setgid(UNPRIV_UGID);
  54. + setgroups(0, NULL);
  55. setuid(UNPRIV_UGID);
  56. }
  57. }