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.

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