mirror of the now-defunct rocklinux.org
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.

233 lines
6.3 KiB

  1. # --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  2. #
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. # Please add additional copyright information _after_ the line containing
  5. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  6. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  7. #
  8. # ROCK Linux: rock-src/package/base/dhcp/dhcp-3.0+paranoia.patch
  9. # ROCK Linux is Copyright (C) 1998 - 2003 Clifford Wolf
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; either version 2 of the License, or
  14. # (at your option) any later version. A copy of the GNU General Public
  15. # License can be found at Documentation/COPYING.
  16. #
  17. # Many people helped and are helping developing ROCK Linux. Please
  18. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  19. # file for details.
  20. #
  21. # --- ROCK-COPYRIGHT-NOTE-END ---
  22. borrowed from ari edelkind's site
  23. http://www.episec.com/people/edelkind/patches/dhcp/dhcp-3.0+paranoia.patch
  24. ---
  25. paranoia (non-root/chroot) patch for ISC dhcp 3.0
  26. file to patch: dhcp-3.0/server/dhcpd.c
  27. update from paranoia patch for ISC dhcp 2.0
  28. Adds 3 options:
  29. -user <user>
  30. -group <group>
  31. -chroot <chroot_dir>
  32. Notes:
  33. -DPARANOIA must be passed as an argument to the --copts option
  34. of configure. Otherwise, the paranoia code will not be compiled
  35. in. Example: ./configure --copts -DPARANOIA
  36. The chroot() call has been delayed in order to allow /dev/log to
  37. be reopened after the configuration file has been read. This is
  38. beneficial for systems on which /dev/log is a unix domain socket.
  39. The main side effect is that dhcpd.conf should be placed in /etc,
  40. instead of <chroot_dir>/etc.
  41. If dhcpd is to be run on a sysV-style architecture (or, more
  42. generally, if /dev/log is a character device), one may opt to
  43. create the <chroot_dir>/dev/log character device and add
  44. -DEARLY_CHROOT to the --copts option of configure (in addition to
  45. -DPARANOIA). This will perform the chroot() call at the earliest
  46. convenience (before reading the configuration file).
  47. If the -user option is used, the lease and pid file directories
  48. should be writable to the server process after it drops
  49. privileges.
  50. ari edelkind (12/10/2001)
  51. last modified 12/10/2001
  52. --- dhcp-3.0/server/dhcpd.c Thu Jun 21 22:12:58 2001
  53. +++ dhcp-3.0+paranoia/server/dhcpd.c Wed Oct 17 08:23:00 2001
  54. @@ -56,6 +56,16 @@
  55. #include "version.h"
  56. #include <omapip/omapip_p.h>
  57. +#if defined (PARANOIA)
  58. +# include <sys/types.h>
  59. +# include <unistd.h>
  60. +# include <pwd.h>
  61. +/* get around the ISC declaration of group */
  62. +# define group real_group
  63. +# include <grp.h>
  64. +# undef group
  65. +#endif /* PARANOIA */
  66. +
  67. static void usage PROTO ((void));
  68. TIME cur_time;
  69. @@ -204,6 +214,22 @@
  70. omapi_object_dereference (&listener, MDL);
  71. }
  72. +#if defined (PARANOIA)
  73. +/* to be used in one of two possible scenarios */
  74. +static void setup_chroot (char *chroot_dir) {
  75. + if (geteuid())
  76. + log_fatal ("you must be root to use chroot");
  77. +
  78. + if (chroot(chroot_dir)) {
  79. + log_fatal ("chroot(\"%s\"): %m", chroot_dir);
  80. + }
  81. + if (chdir ("/")) {
  82. + /* probably permission denied */
  83. + log_fatal ("chdir(\"/\"): %m");
  84. + }
  85. +}
  86. +#endif /* PARANOIA */
  87. +
  88. int main (argc, argv, envp)
  89. int argc;
  90. char **argv, **envp;
  91. @@ -236,6 +262,14 @@
  92. char *traceinfile = (char *)0;
  93. char *traceoutfile = (char *)0;
  94. #endif
  95. +#if defined (PARANOIA)
  96. + char *set_user = 0;
  97. + char *set_group = 0;
  98. + char *set_chroot = 0;
  99. +
  100. + uid_t set_uid = 0;
  101. + gid_t set_gid = 0;
  102. +#endif /* PARANOIA */
  103. /* Make sure we have stdin, stdout and stderr. */
  104. status = open ("/dev/null", O_RDWR);
  105. @@ -298,6 +332,20 @@
  106. if (++i == argc)
  107. usage ();
  108. server = argv [i];
  109. +#if defined (PARANOIA)
  110. + } else if (!strcmp (argv [i], "-user")) {
  111. + if (++i == argc)
  112. + usage ();
  113. + set_user = argv [i];
  114. + } else if (!strcmp (argv [i], "-group")) {
  115. + if (++i == argc)
  116. + usage ();
  117. + set_group = argv [i];
  118. + } else if (!strcmp (argv [i], "-chroot")) {
  119. + if (++i == argc)
  120. + usage ();
  121. + set_chroot = argv [i];
  122. +#endif /* PARANOIA */
  123. } else if (!strcmp (argv [i], "-cf")) {
  124. if (++i == argc)
  125. usage ();
  126. @@ -397,6 +445,44 @@
  127. trace_seed_stop, MDL);
  128. #endif
  129. +#if defined (PARANOIA)
  130. + /* get user and group info if those options were given */
  131. + if (set_user) {
  132. + struct passwd *tmp_pwd;
  133. +
  134. + if (geteuid())
  135. + log_fatal ("you must be root to set user");
  136. +
  137. + if (!(tmp_pwd = getpwnam(set_user)))
  138. + log_fatal ("no such user: %s", set_user);
  139. +
  140. + set_uid = tmp_pwd->pw_uid;
  141. +
  142. + /* use the user's group as the default gid */
  143. + if (!set_group)
  144. + set_gid = tmp_pwd->pw_gid;
  145. + }
  146. +
  147. + if (set_group) {
  148. +/* get around the ISC declaration of group */
  149. +#define group real_group
  150. + struct group *tmp_grp;
  151. +
  152. + if (geteuid())
  153. + log_fatal ("you must be root to set group");
  154. +
  155. + if (!(tmp_grp = getgrnam(set_group)))
  156. + log_fatal ("no such group: %s", set_group);
  157. +
  158. + set_gid = tmp_grp->gr_gid;
  159. +#undef group
  160. + }
  161. +
  162. +# if defined (EARLY_CHROOT)
  163. + if (set_chroot) setup_chroot (set_chroot);
  164. +# endif /* EARLY_CHROOT */
  165. +#endif /* PARANOIA */
  166. +
  167. /* Default to the DHCP/BOOTP port. */
  168. if (!local_port)
  169. {
  170. @@ -500,6 +586,10 @@
  171. postconf_initialization (quiet);
  172. +#if defined (PARANOIA) && !defined (EARLY_CHROOT)
  173. + if (set_chroot) setup_chroot (set_chroot);
  174. +#endif /* PARANOIA && !EARLY_CHROOT */
  175. +
  176. /* test option should cause an early exit */
  177. if (cftest && !lftest)
  178. exit(0);
  179. @@ -543,6 +633,22 @@
  180. exit (0);
  181. }
  182. +#if defined (PARANOIA)
  183. + /* change uid to the specified one */
  184. +
  185. + if (set_gid) {
  186. + if (setgroups (0, (void *)0))
  187. + log_fatal ("setgroups: %m");
  188. + if (setgid (set_gid))
  189. + log_fatal ("setgid(%d): %m", (int) set_gid);
  190. + }
  191. +
  192. + if (set_uid) {
  193. + if (setuid (set_uid))
  194. + log_fatal ("setuid(%d): %m", (int) set_uid);
  195. + }
  196. +#endif /* PARANOIA */
  197. +
  198. /* Read previous pid file. */
  199. if ((i = open (path_dhcpd_pid, O_RDONLY)) >= 0) {
  200. status = read (i, pbuf, (sizeof pbuf) - 1);
  201. @@ -888,6 +994,10 @@
  202. log_fatal ("Usage: dhcpd [-p <UDP port #>] [-d] [-f]%s%s%s%s",
  203. "\n [-cf config-file] [-lf lease-file]",
  204. +#if defined (PARANOIA)
  205. + /* meld into the following string */
  206. + "\n [-user user] [-group group] [-chroot dir]"
  207. +#endif /* PARANOIA */
  208. #if defined (TRACING)
  209. "\n [-tf trace-output-file]",
  210. "\n [-play trace-input-file]",