dhcp-CLOEXEC.patch 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. Index: dhcp-4.4.3/client/clparse.c
  2. ===================================================================
  3. --- dhcp-4.4.3.orig/client/clparse.c
  4. +++ dhcp-4.4.3/client/clparse.c
  5. @@ -265,7 +265,7 @@ int read_client_conf_file (const char *n
  6. int token;
  7. isc_result_t status;
  8. - if ((file = open (name, O_RDONLY)) < 0)
  9. + if ((file = open (name, O_RDONLY | O_CLOEXEC)) < 0)
  10. return uerr2isc (errno);
  11. cfile = NULL;
  12. @@ -341,7 +341,7 @@ void read_client_leases ()
  13. /* Open the lease file. If we can't open it, just return -
  14. we can safely trust the server to remember our state. */
  15. - if ((file = open (path_dhclient_db, O_RDONLY)) < 0)
  16. + if ((file = open (path_dhclient_db, O_RDONLY | O_CLOEXEC)) < 0)
  17. return;
  18. cfile = NULL;
  19. Index: dhcp-4.4.3/client/dhclient.c
  20. ===================================================================
  21. --- dhcp-4.4.3.orig/client/dhclient.c
  22. +++ dhcp-4.4.3/client/dhclient.c
  23. @@ -255,11 +255,11 @@ main(int argc, char **argv) {
  24. /* Make sure that file descriptors 0 (stdin), 1, (stdout), and
  25. 2 (stderr) are open. To do this, we assume that when we
  26. open a file the lowest available file descriptor is used. */
  27. - fd = open("/dev/null", O_RDWR);
  28. + fd = open("/dev/null", O_RDWR | O_CLOEXEC);
  29. if (fd == 0)
  30. - fd = open("/dev/null", O_RDWR);
  31. + fd = open("/dev/null", O_RDWR | O_CLOEXEC);
  32. if (fd == 1)
  33. - fd = open("/dev/null", O_RDWR);
  34. + fd = open("/dev/null", O_RDWR | O_CLOEXEC);
  35. if (fd == 2)
  36. log_perror = 0; /* No sense logging to /dev/null. */
  37. else if (fd != -1)
  38. @@ -664,7 +664,7 @@ main(int argc, char **argv) {
  39. long temp;
  40. int e;
  41. - if ((pidfd = fopen(path_dhclient_pid, "r")) != NULL) {
  42. + if ((pidfd = fopen(path_dhclient_pid, "re")) != NULL) {
  43. e = fscanf(pidfd, "%ld\n", &temp);
  44. oldpid = (pid_t)temp;
  45. @@ -3721,7 +3721,7 @@ void rewrite_client_leases ()
  46. if (leaseFile != NULL)
  47. fclose (leaseFile);
  48. - leaseFile = fopen (path_dhclient_db, "w");
  49. + leaseFile = fopen (path_dhclient_db, "we");
  50. if (leaseFile == NULL) {
  51. log_error ("can't create %s: %m", path_dhclient_db);
  52. return;
  53. @@ -3916,7 +3916,7 @@ write_duid(struct data_string *duid)
  54. return DHCP_R_INVALIDARG;
  55. if (leaseFile == NULL) { /* XXX? */
  56. - leaseFile = fopen(path_dhclient_db, "w");
  57. + leaseFile = fopen(path_dhclient_db, "we");
  58. if (leaseFile == NULL) {
  59. log_error("can't create %s: %m", path_dhclient_db);
  60. return ISC_R_IOERROR;
  61. @@ -3961,7 +3961,7 @@ write_client6_lease(struct client_state
  62. return DHCP_R_INVALIDARG;
  63. if (leaseFile == NULL) { /* XXX? */
  64. - leaseFile = fopen(path_dhclient_db, "w");
  65. + leaseFile = fopen(path_dhclient_db, "we");
  66. if (leaseFile == NULL) {
  67. log_error("can't create %s: %m", path_dhclient_db);
  68. return ISC_R_IOERROR;
  69. @@ -4120,7 +4120,7 @@ int write_client_lease (client, lease, r
  70. return 1;
  71. if (leaseFile == NULL) { /* XXX */
  72. - leaseFile = fopen (path_dhclient_db, "w");
  73. + leaseFile = fopen (path_dhclient_db, "we");
  74. if (leaseFile == NULL) {
  75. log_error ("can't create %s: %m", path_dhclient_db);
  76. return 0;
  77. @@ -4706,9 +4706,9 @@ void detach ()
  78. (void) close(2);
  79. /* Reopen them on /dev/null. */
  80. - (void) open("/dev/null", O_RDWR);
  81. - (void) open("/dev/null", O_RDWR);
  82. - (void) open("/dev/null", O_RDWR);
  83. + (void) open("/dev/null", O_RDWR | O_CLOEXEC);
  84. + (void) open("/dev/null", O_RDWR | O_CLOEXEC);
  85. + (void) open("/dev/null", O_RDWR | O_CLOEXEC);
  86. write_client_pid_file ();
  87. @@ -4726,14 +4726,14 @@ void write_client_pid_file ()
  88. return;
  89. }
  90. - pfdesc = open (path_dhclient_pid, O_CREAT | O_TRUNC | O_WRONLY, 0644);
  91. + pfdesc = open (path_dhclient_pid, O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC, 0644);
  92. if (pfdesc < 0) {
  93. log_error ("Can't create %s: %m", path_dhclient_pid);
  94. return;
  95. }
  96. - pf = fdopen (pfdesc, "w");
  97. + pf = fdopen (pfdesc, "we");
  98. if (!pf) {
  99. close(pfdesc);
  100. log_error ("Can't fdopen %s: %m", path_dhclient_pid);
  101. Index: dhcp-4.4.3/common/bpf.c
  102. ===================================================================
  103. --- dhcp-4.4.3.orig/common/bpf.c
  104. +++ dhcp-4.4.3/common/bpf.c
  105. @@ -94,7 +94,7 @@ int if_register_bpf (info)
  106. for (b = 0; 1; b++) {
  107. /* %Audit% 31 bytes max. %2004.06.17,Safe% */
  108. sprintf(filename, BPF_FORMAT, b);
  109. - sock = open (filename, O_RDWR, 0);
  110. + sock = open (filename, O_RDWR | O_CLOEXEC, 0);
  111. if (sock < 0) {
  112. if (errno == EBUSY) {
  113. continue;
  114. Index: dhcp-4.4.3/common/dlpi.c
  115. ===================================================================
  116. --- dhcp-4.4.3.orig/common/dlpi.c
  117. +++ dhcp-4.4.3/common/dlpi.c
  118. @@ -817,7 +817,7 @@ dlpiopen(const char *ifname) {
  119. }
  120. *dp = '\0';
  121. - return open (devname, O_RDWR, 0);
  122. + return open (devname, O_RDWR | O_CLOEXEC, 0);
  123. }
  124. /*
  125. Index: dhcp-4.4.3/common/nit.c
  126. ===================================================================
  127. --- dhcp-4.4.3.orig/common/nit.c
  128. +++ dhcp-4.4.3/common/nit.c
  129. @@ -75,7 +75,7 @@ int if_register_nit (info)
  130. struct strioctl sio;
  131. /* Open a NIT device */
  132. - sock = open ("/dev/nit", O_RDWR);
  133. + sock = open ("/dev/nit", O_RDWR | O_CLOEXEC);
  134. if (sock < 0)
  135. log_fatal ("Can't open NIT device for %s: %m", info -> name);
  136. Index: dhcp-4.4.3/common/resolv.c
  137. ===================================================================
  138. --- dhcp-4.4.3.orig/common/resolv.c
  139. +++ dhcp-4.4.3/common/resolv.c
  140. @@ -43,7 +43,7 @@ void read_resolv_conf (parse_time)
  141. struct domain_search_list *dp, *dl, *nd;
  142. isc_result_t status;
  143. - if ((file = open (path_resolv_conf, O_RDONLY)) < 0) {
  144. + if ((file = open (path_resolv_conf, O_RDONLY | O_CLOEXEC)) < 0) {
  145. log_error ("Can't open %s: %m", path_resolv_conf);
  146. return;
  147. }
  148. Index: dhcp-4.4.3/common/upf.c
  149. ===================================================================
  150. --- dhcp-4.4.3.orig/common/upf.c
  151. +++ dhcp-4.4.3/common/upf.c
  152. @@ -71,7 +71,7 @@ int if_register_upf (info)
  153. /* %Audit% Cannot exceed 36 bytes. %2004.06.17,Safe% */
  154. sprintf(filename, "/dev/pf/pfilt%d", b);
  155. - sock = open (filename, O_RDWR, 0);
  156. + sock = open (filename, O_RDWR | O_CLOEXEC, 0);
  157. if (sock < 0) {
  158. if (errno == EBUSY) {
  159. continue;
  160. Index: dhcp-4.4.3/omapip/trace.c
  161. ===================================================================
  162. --- dhcp-4.4.3.orig/omapip/trace.c
  163. +++ dhcp-4.4.3/omapip/trace.c
  164. @@ -136,10 +136,10 @@ isc_result_t trace_begin (const char *fi
  165. return DHCP_R_INVALIDARG;
  166. }
  167. - traceoutfile = open (filename, O_CREAT | O_WRONLY | O_EXCL, 0600);
  168. + traceoutfile = open (filename, O_CREAT | O_WRONLY | O_EXCL | O_CLOEXEC, 0600);
  169. if (traceoutfile < 0 && errno == EEXIST) {
  170. log_error ("WARNING: Overwriting trace file \"%s\"", filename);
  171. - traceoutfile = open (filename, O_WRONLY | O_EXCL | O_TRUNC,
  172. + traceoutfile = open (filename, O_WRONLY | O_EXCL | O_TRUNC | O_CLOEXEC,
  173. 0600);
  174. }
  175. @@ -427,7 +427,7 @@ void trace_file_replay (const char *file
  176. isc_result_t result;
  177. int len;
  178. - traceinfile = fopen (filename, "r");
  179. + traceinfile = fopen (filename, "re");
  180. if (!traceinfile) {
  181. log_error("Can't open tracefile %s: %m", filename);
  182. return;
  183. Index: dhcp-4.4.3/relay/dhcrelay.c
  184. ===================================================================
  185. --- dhcp-4.4.3.orig/relay/dhcrelay.c
  186. +++ dhcp-4.4.3/relay/dhcrelay.c
  187. @@ -305,11 +305,11 @@ main(int argc, char **argv) {
  188. /* Make sure that file descriptors 0(stdin), 1,(stdout), and
  189. 2(stderr) are open. To do this, we assume that when we
  190. open a file the lowest available file descriptor is used. */
  191. - fd = open("/dev/null", O_RDWR);
  192. + fd = open("/dev/null", O_RDWR | O_CLOEXEC);
  193. if (fd == 0)
  194. - fd = open("/dev/null", O_RDWR);
  195. + fd = open("/dev/null", O_RDWR | O_CLOEXEC);
  196. if (fd == 1)
  197. - fd = open("/dev/null", O_RDWR);
  198. + fd = open("/dev/null", O_RDWR | O_CLOEXEC);
  199. if (fd == 2)
  200. log_perror = 0; /* No sense logging to /dev/null. */
  201. else if (fd != -1)
  202. @@ -800,13 +800,13 @@ main(int argc, char **argv) {
  203. /* Create the pid file. */
  204. if (no_pid_file == ISC_FALSE) {
  205. pfdesc = open(path_dhcrelay_pid,
  206. - O_CREAT | O_TRUNC | O_WRONLY, 0644);
  207. + O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC, 0644);
  208. if (pfdesc < 0) {
  209. log_error("Can't create %s: %m",
  210. path_dhcrelay_pid);
  211. } else {
  212. - pf = fdopen(pfdesc, "w");
  213. + pf = fdopen(pfdesc, "we");
  214. if (!pf)
  215. log_error("Can't fdopen %s: %m",
  216. path_dhcrelay_pid);
  217. Index: dhcp-4.4.3/server/confpars.c
  218. ===================================================================
  219. --- dhcp-4.4.3.orig/server/confpars.c
  220. +++ dhcp-4.4.3/server/confpars.c
  221. @@ -118,7 +118,7 @@ isc_result_t read_conf_file (const char
  222. }
  223. #endif
  224. - if ((file = open (filename, O_RDONLY)) < 0) {
  225. + if ((file = open (filename, O_RDONLY | O_CLOEXEC)) < 0) {
  226. if (leasep) {
  227. log_error ("Can't open lease database %s: %m --",
  228. path_dhcpd_db);
  229. Index: dhcp-4.4.3/server/db.c
  230. ===================================================================
  231. --- dhcp-4.4.3.orig/server/db.c
  232. +++ dhcp-4.4.3/server/db.c
  233. @@ -1105,7 +1105,7 @@ void db_startup (int test_mode)
  234. * Therefore, in test mode we need to point db_file to a disposable
  235. * file to protect the original lease file. */
  236. current_db_path = (test_mode ? "/dev/null" : path_dhcpd_db);
  237. - db_file = fopen (current_db_path, "a");
  238. + db_file = fopen (current_db_path, "ae");
  239. if (!db_file) {
  240. log_fatal ("Can't open %s for append.", current_db_path);
  241. }
  242. @@ -1154,7 +1154,7 @@ int new_lease_file (int test_mode)
  243. path_dhcpd_db, (int)t) >= sizeof newfname)
  244. log_fatal("new_lease_file: lease file path too long");
  245. - db_fd = open (newfname, O_WRONLY | O_TRUNC | O_CREAT, 0664);
  246. + db_fd = open (newfname, O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, 0664);
  247. if (db_fd < 0) {
  248. log_error ("Can't create new lease file: %m");
  249. return 0;
  250. @@ -1175,7 +1175,7 @@ int new_lease_file (int test_mode)
  251. }
  252. #endif /* PARANOIA */
  253. - if ((new_db_file = fdopen(db_fd, "w")) == NULL) {
  254. + if ((new_db_file = fdopen(db_fd, "we")) == NULL) {
  255. log_error("Can't fdopen new lease file: %m");
  256. close(db_fd);
  257. goto fdfail;
  258. Index: dhcp-4.4.3/server/dhcpd.c
  259. ===================================================================
  260. --- dhcp-4.4.3.orig/server/dhcpd.c
  261. +++ dhcp-4.4.3/server/dhcpd.c
  262. @@ -300,11 +300,11 @@ main(int argc, char **argv) {
  263. /* Make sure that file descriptors 0 (stdin), 1, (stdout), and
  264. 2 (stderr) are open. To do this, we assume that when we
  265. open a file the lowest available file descriptor is used. */
  266. - fd = open("/dev/null", O_RDWR);
  267. + fd = open("/dev/null", O_RDWR | O_CLOEXEC);
  268. if (fd == 0)
  269. - fd = open("/dev/null", O_RDWR);
  270. + fd = open("/dev/null", O_RDWR | O_CLOEXEC);
  271. if (fd == 1)
  272. - fd = open("/dev/null", O_RDWR);
  273. + fd = open("/dev/null", O_RDWR | O_CLOEXEC);
  274. if (fd == 2)
  275. log_perror = 0; /* No sense logging to /dev/null. */
  276. else if (fd != -1)
  277. @@ -865,7 +865,7 @@ main(int argc, char **argv) {
  278. */
  279. if ((lftest == 0) && (no_pid_file == ISC_FALSE)) {
  280. /*Read previous pid file. */
  281. - if ((i = open(path_dhcpd_pid, O_RDONLY)) >= 0) {
  282. + if ((i = open(path_dhcpd_pid, O_RDONLY|O_CLOEXEC)) >= 0) {
  283. status = read(i, pbuf, (sizeof pbuf) - 1);
  284. close(i);
  285. if (status > 0) {
  286. @@ -975,7 +975,7 @@ main(int argc, char **argv) {
  287. * appropriate.
  288. */
  289. if (no_pid_file == ISC_FALSE) {
  290. - i = open(path_dhcpd_pid, O_WRONLY|O_CREAT|O_TRUNC, 0644);
  291. + i = open(path_dhcpd_pid, O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0644);
  292. if (i >= 0) {
  293. sprintf(pbuf, "%d\n", (int) getpid());
  294. IGNORE_RET(write(i, pbuf, strlen(pbuf)));
  295. @@ -1028,9 +1028,9 @@ main(int argc, char **argv) {
  296. (void) close(2);
  297. /* Reopen them on /dev/null. */
  298. - (void) open("/dev/null", O_RDWR);
  299. - (void) open("/dev/null", O_RDWR);
  300. - (void) open("/dev/null", O_RDWR);
  301. + (void) open("/dev/null", O_RDWR | O_CLOEXEC);
  302. + (void) open("/dev/null", O_RDWR | O_CLOEXEC);
  303. + (void) open("/dev/null", O_RDWR | O_CLOEXEC);
  304. log_perror = 0; /* No sense logging to /dev/null. */
  305. IGNORE_RET (chdir("/"));
  306. Index: dhcp-4.4.3/server/ldap.c
  307. ===================================================================
  308. --- dhcp-4.4.3.orig/server/ldap.c
  309. +++ dhcp-4.4.3/server/ldap.c
  310. @@ -1447,7 +1447,7 @@ ldap_start (void)
  311. if (ldap_debug_file != NULL && ldap_debug_fd == -1)
  312. {
  313. - if ((ldap_debug_fd = open (ldap_debug_file, O_CREAT | O_TRUNC | O_WRONLY,
  314. + if ((ldap_debug_fd = open (ldap_debug_file, O_CREAT | O_TRUNC | O_WRONLY | O_CLOEXEC,
  315. S_IRUSR | S_IWUSR)) < 0)
  316. log_error ("Error opening debug LDAP log file %s: %s", ldap_debug_file,
  317. strerror (errno));