portmap-4.0-rpc_user.patch 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. diff -urN portmap_4/daemon.c portmap_4.new/daemon.c
  2. --- portmap_4/daemon.c Thu Aug 3 18:07:22 2000
  3. +++ portmap_4.new/daemon.c Fri Aug 4 08:45:25 2000
  4. @@ -35,6 +35,7 @@
  5. static char sccsid[] = "@(#)daemon.c 5.3 (Berkeley) 12/28/90";
  6. #endif /* LIBC_SCCS and not lint */
  7. +#include <stdlib.h>
  8. #include <sys/types.h>
  9. #include <fcntl.h>
  10. #include <unistd.h>
  11. diff -urN portmap_4/pmap_check.c portmap_4.new/pmap_check.c
  12. --- portmap_4/pmap_check.c Thu Aug 3 18:07:22 2000
  13. +++ portmap_4.new/pmap_check.c Thu Aug 3 18:29:51 2000
  14. @@ -40,6 +40,8 @@
  15. #include <rpc/pmap_prot.h>
  16. #include <syslog.h>
  17. #include <netdb.h>
  18. +#include <pwd.h>
  19. +#include <sys/types.h>
  20. #include <sys/signal.h>
  21. #ifdef SYSV40
  22. #include <netinet/in.h>
  23. @@ -149,11 +151,32 @@
  24. /*
  25. * Give up root privileges so that we can never allocate a privileged
  26. * port when forwarding an rpc request.
  27. + *
  28. + * Fix 8/3/00 Philipp Knirsch: First lookup our rpc user. If we find it,
  29. + * switch to that uid, otherwise simply resue the old bin user and print
  30. + * out a warning in syslog.
  31. */
  32. - if (setuid(1) == -1) {
  33. - syslog(LOG_ERR, "setuid(1) failed: %m");
  34. - exit(1);
  35. +
  36. + struct passwd *pwent;
  37. +
  38. + pwent = getpwnam("rpc");
  39. + if (pwent == NULL) {
  40. + syslog(LOG_WARNING, "user rpc not found, reverting to user bin");
  41. + if (setuid(1) == -1) {
  42. + syslog(LOG_ERR, "setuid(1) failed: %m");
  43. + exit(1);
  44. + }
  45. }
  46. + else {
  47. + if (setuid(pwent->pw_uid) == -1) {
  48. + syslog(LOG_WARNING, "setuid() to rpc user failed: %m");
  49. + if (setuid(1) == -1) {
  50. + syslog(LOG_ERR, "setuid(1) failed: %m");
  51. + exit(1);
  52. + }
  53. + }
  54. + }
  55. +
  56. (void) signal(SIGINT, toggle_verboselog);
  57. }