nginxtra 1.0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (363) hide show
  1. data/VERSION +1 -0
  2. data/bin/nginxtra +5 -0
  3. data/lib/nginxtra.rb +12 -0
  4. data/lib/nginxtra/action.rb +36 -0
  5. data/lib/nginxtra/actions/compile.rb +60 -0
  6. data/lib/nginxtra/actions/install.rb +99 -0
  7. data/lib/nginxtra/actions/reload.rb +14 -0
  8. data/lib/nginxtra/actions/restart.rb +15 -0
  9. data/lib/nginxtra/actions/start.rb +53 -0
  10. data/lib/nginxtra/actions/status.rb +31 -0
  11. data/lib/nginxtra/actions/stop.rb +14 -0
  12. data/lib/nginxtra/cli.rb +77 -0
  13. data/lib/nginxtra/config.rb +339 -0
  14. data/lib/nginxtra/error.rb +13 -0
  15. data/lib/nginxtra/status.rb +57 -0
  16. data/src/nginx/CHANGES +5630 -0
  17. data/src/nginx/CHANGES.ru +5716 -0
  18. data/src/nginx/LICENSE +25 -0
  19. data/src/nginx/README +3 -0
  20. data/src/nginx/auto/cc/acc +15 -0
  21. data/src/nginx/auto/cc/bcc +72 -0
  22. data/src/nginx/auto/cc/ccc +46 -0
  23. data/src/nginx/auto/cc/conf +189 -0
  24. data/src/nginx/auto/cc/gcc +183 -0
  25. data/src/nginx/auto/cc/icc +121 -0
  26. data/src/nginx/auto/cc/msvc +138 -0
  27. data/src/nginx/auto/cc/name +101 -0
  28. data/src/nginx/auto/cc/owc +104 -0
  29. data/src/nginx/auto/cc/sunc +158 -0
  30. data/src/nginx/auto/define +12 -0
  31. data/src/nginx/auto/endianess +45 -0
  32. data/src/nginx/auto/feature +123 -0
  33. data/src/nginx/auto/have +12 -0
  34. data/src/nginx/auto/have_headers +12 -0
  35. data/src/nginx/auto/headers +13 -0
  36. data/src/nginx/auto/include +61 -0
  37. data/src/nginx/auto/init +51 -0
  38. data/src/nginx/auto/install +184 -0
  39. data/src/nginx/auto/lib/conf +83 -0
  40. data/src/nginx/auto/lib/geoip/conf +79 -0
  41. data/src/nginx/auto/lib/google-perftools/conf +45 -0
  42. data/src/nginx/auto/lib/libatomic/conf +43 -0
  43. data/src/nginx/auto/lib/libatomic/make +14 -0
  44. data/src/nginx/auto/lib/libgd/conf +83 -0
  45. data/src/nginx/auto/lib/libxslt/conf +156 -0
  46. data/src/nginx/auto/lib/make +32 -0
  47. data/src/nginx/auto/lib/md5/conf +103 -0
  48. data/src/nginx/auto/lib/md5/make +96 -0
  49. data/src/nginx/auto/lib/md5/makefile.bcc +22 -0
  50. data/src/nginx/auto/lib/md5/makefile.msvc +22 -0
  51. data/src/nginx/auto/lib/md5/makefile.owc +11 -0
  52. data/src/nginx/auto/lib/openssl/conf +74 -0
  53. data/src/nginx/auto/lib/openssl/make +67 -0
  54. data/src/nginx/auto/lib/openssl/makefile.bcc +18 -0
  55. data/src/nginx/auto/lib/openssl/makefile.msvc +14 -0
  56. data/src/nginx/auto/lib/pcre/conf +180 -0
  57. data/src/nginx/auto/lib/pcre/make +64 -0
  58. data/src/nginx/auto/lib/pcre/makefile.bcc +26 -0
  59. data/src/nginx/auto/lib/pcre/makefile.msvc +22 -0
  60. data/src/nginx/auto/lib/pcre/makefile.owc +24 -0
  61. data/src/nginx/auto/lib/perl/conf +60 -0
  62. data/src/nginx/auto/lib/perl/make +36 -0
  63. data/src/nginx/auto/lib/sha1/conf +79 -0
  64. data/src/nginx/auto/lib/sha1/make +96 -0
  65. data/src/nginx/auto/lib/sha1/makefile.bcc +22 -0
  66. data/src/nginx/auto/lib/sha1/makefile.msvc +22 -0
  67. data/src/nginx/auto/lib/sha1/makefile.owc +11 -0
  68. data/src/nginx/auto/lib/test +40 -0
  69. data/src/nginx/auto/lib/zlib/conf +76 -0
  70. data/src/nginx/auto/lib/zlib/make +114 -0
  71. data/src/nginx/auto/lib/zlib/makefile.bcc +15 -0
  72. data/src/nginx/auto/lib/zlib/makefile.msvc +14 -0
  73. data/src/nginx/auto/lib/zlib/makefile.owc +14 -0
  74. data/src/nginx/auto/lib/zlib/patch.zlib.h +10 -0
  75. data/src/nginx/auto/make +417 -0
  76. data/src/nginx/auto/modules +479 -0
  77. data/src/nginx/auto/nohave +12 -0
  78. data/src/nginx/auto/options +490 -0
  79. data/src/nginx/auto/os/conf +105 -0
  80. data/src/nginx/auto/os/darwin +116 -0
  81. data/src/nginx/auto/os/freebsd +136 -0
  82. data/src/nginx/auto/os/linux +152 -0
  83. data/src/nginx/auto/os/solaris +60 -0
  84. data/src/nginx/auto/os/win32 +29 -0
  85. data/src/nginx/auto/sources +518 -0
  86. data/src/nginx/auto/stubs +8 -0
  87. data/src/nginx/auto/summary +114 -0
  88. data/src/nginx/auto/types/sizeof +83 -0
  89. data/src/nginx/auto/types/typedef +77 -0
  90. data/src/nginx/auto/types/uintptr_t +42 -0
  91. data/src/nginx/auto/types/value +12 -0
  92. data/src/nginx/auto/unix +719 -0
  93. data/src/nginx/conf/fastcgi.conf +24 -0
  94. data/src/nginx/conf/fastcgi_params +23 -0
  95. data/src/nginx/conf/koi-utf +109 -0
  96. data/src/nginx/conf/koi-win +103 -0
  97. data/src/nginx/conf/mime.types +80 -0
  98. data/src/nginx/conf/nginx.conf +118 -0
  99. data/src/nginx/conf/scgi_params +15 -0
  100. data/src/nginx/conf/uwsgi_params +15 -0
  101. data/src/nginx/conf/win-utf +126 -0
  102. data/src/nginx/configure +108 -0
  103. data/src/nginx/contrib/README +15 -0
  104. data/src/nginx/contrib/geo2nginx.pl +58 -0
  105. data/src/nginx/contrib/unicode2nginx/koi-utf +131 -0
  106. data/src/nginx/contrib/unicode2nginx/unicode-to-nginx.pl +45 -0
  107. data/src/nginx/contrib/unicode2nginx/win-utf +130 -0
  108. data/src/nginx/html/50x.html +18 -0
  109. data/src/nginx/html/index.html +8 -0
  110. data/src/nginx/man/nginx.8 +202 -0
  111. data/src/nginx/src/core/nginx.c +1333 -0
  112. data/src/nginx/src/core/nginx.h +20 -0
  113. data/src/nginx/src/core/ngx_array.c +147 -0
  114. data/src/nginx/src/core/ngx_array.h +53 -0
  115. data/src/nginx/src/core/ngx_buf.c +218 -0
  116. data/src/nginx/src/core/ngx_buf.h +162 -0
  117. data/src/nginx/src/core/ngx_conf_file.c +1506 -0
  118. data/src/nginx/src/core/ngx_conf_file.h +348 -0
  119. data/src/nginx/src/core/ngx_config.h +134 -0
  120. data/src/nginx/src/core/ngx_connection.c +1074 -0
  121. data/src/nginx/src/core/ngx_connection.h +195 -0
  122. data/src/nginx/src/core/ngx_core.h +95 -0
  123. data/src/nginx/src/core/ngx_cpuinfo.c +139 -0
  124. data/src/nginx/src/core/ngx_crc.h +39 -0
  125. data/src/nginx/src/core/ngx_crc32.c +129 -0
  126. data/src/nginx/src/core/ngx_crc32.h +79 -0
  127. data/src/nginx/src/core/ngx_crypt.c +238 -0
  128. data/src/nginx/src/core/ngx_crypt.h +20 -0
  129. data/src/nginx/src/core/ngx_cycle.c +1379 -0
  130. data/src/nginx/src/core/ngx_cycle.h +142 -0
  131. data/src/nginx/src/core/ngx_file.c +993 -0
  132. data/src/nginx/src/core/ngx_file.h +151 -0
  133. data/src/nginx/src/core/ngx_hash.c +976 -0
  134. data/src/nginx/src/core/ngx_hash.h +122 -0
  135. data/src/nginx/src/core/ngx_inet.c +1008 -0
  136. data/src/nginx/src/core/ngx_inet.h +120 -0
  137. data/src/nginx/src/core/ngx_list.c +71 -0
  138. data/src/nginx/src/core/ngx_list.h +83 -0
  139. data/src/nginx/src/core/ngx_log.c +459 -0
  140. data/src/nginx/src/core/ngx_log.h +250 -0
  141. data/src/nginx/src/core/ngx_md5.c +289 -0
  142. data/src/nginx/src/core/ngx_md5.h +60 -0
  143. data/src/nginx/src/core/ngx_murmurhash.c +50 -0
  144. data/src/nginx/src/core/ngx_murmurhash.h +19 -0
  145. data/src/nginx/src/core/ngx_open_file_cache.c +882 -0
  146. data/src/nginx/src/core/ngx_open_file_cache.h +119 -0
  147. data/src/nginx/src/core/ngx_output_chain.c +673 -0
  148. data/src/nginx/src/core/ngx_palloc.c +433 -0
  149. data/src/nginx/src/core/ngx_palloc.h +95 -0
  150. data/src/nginx/src/core/ngx_parse.c +249 -0
  151. data/src/nginx/src/core/ngx_parse.h +24 -0
  152. data/src/nginx/src/core/ngx_queue.c +80 -0
  153. data/src/nginx/src/core/ngx_queue.h +112 -0
  154. data/src/nginx/src/core/ngx_radix_tree.c +291 -0
  155. data/src/nginx/src/core/ngx_radix_tree.h +46 -0
  156. data/src/nginx/src/core/ngx_rbtree.c +383 -0
  157. data/src/nginx/src/core/ngx_rbtree.h +84 -0
  158. data/src/nginx/src/core/ngx_regex.c +206 -0
  159. data/src/nginx/src/core/ngx_regex.h +56 -0
  160. data/src/nginx/src/core/ngx_resolver.c +2201 -0
  161. data/src/nginx/src/core/ngx_resolver.h +149 -0
  162. data/src/nginx/src/core/ngx_sha1.h +31 -0
  163. data/src/nginx/src/core/ngx_shmtx.c +284 -0
  164. data/src/nginx/src/core/ngx_shmtx.h +38 -0
  165. data/src/nginx/src/core/ngx_slab.c +701 -0
  166. data/src/nginx/src/core/ngx_slab.h +54 -0
  167. data/src/nginx/src/core/ngx_spinlock.c +53 -0
  168. data/src/nginx/src/core/ngx_string.c +1837 -0
  169. data/src/nginx/src/core/ngx_string.h +231 -0
  170. data/src/nginx/src/core/ngx_times.c +407 -0
  171. data/src/nginx/src/core/ngx_times.h +51 -0
  172. data/src/nginx/src/event/modules/ngx_aio_module.c +171 -0
  173. data/src/nginx/src/event/modules/ngx_devpoll_module.c +569 -0
  174. data/src/nginx/src/event/modules/ngx_epoll_module.c +833 -0
  175. data/src/nginx/src/event/modules/ngx_eventport_module.c +602 -0
  176. data/src/nginx/src/event/modules/ngx_kqueue_module.c +785 -0
  177. data/src/nginx/src/event/modules/ngx_poll_module.c +443 -0
  178. data/src/nginx/src/event/modules/ngx_rtsig_module.c +735 -0
  179. data/src/nginx/src/event/modules/ngx_select_module.c +435 -0
  180. data/src/nginx/src/event/modules/ngx_win32_select_module.c +400 -0
  181. data/src/nginx/src/event/ngx_event.c +1275 -0
  182. data/src/nginx/src/event/ngx_event.h +573 -0
  183. data/src/nginx/src/event/ngx_event_accept.c +428 -0
  184. data/src/nginx/src/event/ngx_event_busy_lock.c +286 -0
  185. data/src/nginx/src/event/ngx_event_busy_lock.h +65 -0
  186. data/src/nginx/src/event/ngx_event_connect.c +258 -0
  187. data/src/nginx/src/event/ngx_event_connect.h +76 -0
  188. data/src/nginx/src/event/ngx_event_mutex.c +70 -0
  189. data/src/nginx/src/event/ngx_event_openssl.c +2382 -0
  190. data/src/nginx/src/event/ngx_event_openssl.h +162 -0
  191. data/src/nginx/src/event/ngx_event_pipe.c +996 -0
  192. data/src/nginx/src/event/ngx_event_pipe.h +95 -0
  193. data/src/nginx/src/event/ngx_event_posted.c +173 -0
  194. data/src/nginx/src/event/ngx_event_posted.h +75 -0
  195. data/src/nginx/src/event/ngx_event_timer.c +159 -0
  196. data/src/nginx/src/event/ngx_event_timer.h +102 -0
  197. data/src/nginx/src/http/modules/ngx_http_access_module.c +384 -0
  198. data/src/nginx/src/http/modules/ngx_http_addition_filter_module.c +250 -0
  199. data/src/nginx/src/http/modules/ngx_http_auth_basic_module.c +478 -0
  200. data/src/nginx/src/http/modules/ngx_http_autoindex_module.c +701 -0
  201. data/src/nginx/src/http/modules/ngx_http_browser_module.c +713 -0
  202. data/src/nginx/src/http/modules/ngx_http_charset_filter_module.c +1681 -0
  203. data/src/nginx/src/http/modules/ngx_http_chunked_filter_module.c +242 -0
  204. data/src/nginx/src/http/modules/ngx_http_dav_module.c +1141 -0
  205. data/src/nginx/src/http/modules/ngx_http_degradation_module.c +243 -0
  206. data/src/nginx/src/http/modules/ngx_http_empty_gif_module.c +140 -0
  207. data/src/nginx/src/http/modules/ngx_http_fastcgi_module.c +2916 -0
  208. data/src/nginx/src/http/modules/ngx_http_flv_module.c +254 -0
  209. data/src/nginx/src/http/modules/ngx_http_geo_module.c +1441 -0
  210. data/src/nginx/src/http/modules/ngx_http_geoip_module.c +671 -0
  211. data/src/nginx/src/http/modules/ngx_http_gzip_filter_module.c +1206 -0
  212. data/src/nginx/src/http/modules/ngx_http_gzip_static_module.c +299 -0
  213. data/src/nginx/src/http/modules/ngx_http_headers_filter_module.c +616 -0
  214. data/src/nginx/src/http/modules/ngx_http_image_filter_module.c +1489 -0
  215. data/src/nginx/src/http/modules/ngx_http_index_module.c +516 -0
  216. data/src/nginx/src/http/modules/ngx_http_limit_req_module.c +809 -0
  217. data/src/nginx/src/http/modules/ngx_http_limit_zone_module.c +553 -0
  218. data/src/nginx/src/http/modules/ngx_http_log_module.c +1357 -0
  219. data/src/nginx/src/http/modules/ngx_http_map_module.c +575 -0
  220. data/src/nginx/src/http/modules/ngx_http_memcached_module.c +624 -0
  221. data/src/nginx/src/http/modules/ngx_http_mp4_module.c +3000 -0
  222. data/src/nginx/src/http/modules/ngx_http_not_modified_filter_module.c +143 -0
  223. data/src/nginx/src/http/modules/ngx_http_proxy_module.c +2831 -0
  224. data/src/nginx/src/http/modules/ngx_http_random_index_module.c +317 -0
  225. data/src/nginx/src/http/modules/ngx_http_range_filter_module.c +855 -0
  226. data/src/nginx/src/http/modules/ngx_http_realip_module.c +476 -0
  227. data/src/nginx/src/http/modules/ngx_http_referer_module.c +613 -0
  228. data/src/nginx/src/http/modules/ngx_http_rewrite_module.c +1019 -0
  229. data/src/nginx/src/http/modules/ngx_http_scgi_module.c +1714 -0
  230. data/src/nginx/src/http/modules/ngx_http_secure_link_module.c +355 -0
  231. data/src/nginx/src/http/modules/ngx_http_split_clients_module.c +242 -0
  232. data/src/nginx/src/http/modules/ngx_http_ssi_filter_module.c +2913 -0
  233. data/src/nginx/src/http/modules/ngx_http_ssi_filter_module.h +114 -0
  234. data/src/nginx/src/http/modules/ngx_http_ssl_module.c +652 -0
  235. data/src/nginx/src/http/modules/ngx_http_ssl_module.h +52 -0
  236. data/src/nginx/src/http/modules/ngx_http_static_module.c +278 -0
  237. data/src/nginx/src/http/modules/ngx_http_stub_status_module.c +144 -0
  238. data/src/nginx/src/http/modules/ngx_http_sub_filter_module.c +716 -0
  239. data/src/nginx/src/http/modules/ngx_http_upstream_ip_hash_module.c +237 -0
  240. data/src/nginx/src/http/modules/ngx_http_userid_filter_module.c +846 -0
  241. data/src/nginx/src/http/modules/ngx_http_uwsgi_module.c +1774 -0
  242. data/src/nginx/src/http/modules/ngx_http_xslt_filter_module.c +984 -0
  243. data/src/nginx/src/http/modules/perl/Makefile.PL +42 -0
  244. data/src/nginx/src/http/modules/perl/nginx.pm +137 -0
  245. data/src/nginx/src/http/modules/perl/nginx.xs +986 -0
  246. data/src/nginx/src/http/modules/perl/ngx_http_perl_module.c +1076 -0
  247. data/src/nginx/src/http/modules/perl/ngx_http_perl_module.h +67 -0
  248. data/src/nginx/src/http/modules/perl/typemap +3 -0
  249. data/src/nginx/src/http/ngx_http.c +2073 -0
  250. data/src/nginx/src/http/ngx_http.h +160 -0
  251. data/src/nginx/src/http/ngx_http_busy_lock.c +307 -0
  252. data/src/nginx/src/http/ngx_http_busy_lock.h +54 -0
  253. data/src/nginx/src/http/ngx_http_cache.h +148 -0
  254. data/src/nginx/src/http/ngx_http_config.h +75 -0
  255. data/src/nginx/src/http/ngx_http_copy_filter_module.c +300 -0
  256. data/src/nginx/src/http/ngx_http_core_module.c +4736 -0
  257. data/src/nginx/src/http/ngx_http_core_module.h +541 -0
  258. data/src/nginx/src/http/ngx_http_file_cache.c +1715 -0
  259. data/src/nginx/src/http/ngx_http_header_filter_module.c +623 -0
  260. data/src/nginx/src/http/ngx_http_parse.c +1734 -0
  261. data/src/nginx/src/http/ngx_http_parse_time.c +276 -0
  262. data/src/nginx/src/http/ngx_http_postpone_filter_module.c +178 -0
  263. data/src/nginx/src/http/ngx_http_request.c +3181 -0
  264. data/src/nginx/src/http/ngx_http_request.h +573 -0
  265. data/src/nginx/src/http/ngx_http_request_body.c +644 -0
  266. data/src/nginx/src/http/ngx_http_script.c +1752 -0
  267. data/src/nginx/src/http/ngx_http_script.h +257 -0
  268. data/src/nginx/src/http/ngx_http_special_response.c +789 -0
  269. data/src/nginx/src/http/ngx_http_upstream.c +4555 -0
  270. data/src/nginx/src/http/ngx_http_upstream.h +350 -0
  271. data/src/nginx/src/http/ngx_http_upstream_round_robin.c +791 -0
  272. data/src/nginx/src/http/ngx_http_upstream_round_robin.h +85 -0
  273. data/src/nginx/src/http/ngx_http_variables.c +2053 -0
  274. data/src/nginx/src/http/ngx_http_variables.h +115 -0
  275. data/src/nginx/src/http/ngx_http_write_filter_module.c +315 -0
  276. data/src/nginx/src/mail/ngx_mail.c +542 -0
  277. data/src/nginx/src/mail/ngx_mail.h +407 -0
  278. data/src/nginx/src/mail/ngx_mail_auth_http_module.c +1452 -0
  279. data/src/nginx/src/mail/ngx_mail_core_module.c +553 -0
  280. data/src/nginx/src/mail/ngx_mail_handler.c +773 -0
  281. data/src/nginx/src/mail/ngx_mail_imap_handler.c +457 -0
  282. data/src/nginx/src/mail/ngx_mail_imap_module.c +253 -0
  283. data/src/nginx/src/mail/ngx_mail_imap_module.h +39 -0
  284. data/src/nginx/src/mail/ngx_mail_parse.c +885 -0
  285. data/src/nginx/src/mail/ngx_mail_pop3_handler.c +500 -0
  286. data/src/nginx/src/mail/ngx_mail_pop3_module.c +264 -0
  287. data/src/nginx/src/mail/ngx_mail_pop3_module.h +38 -0
  288. data/src/nginx/src/mail/ngx_mail_proxy_module.c +1089 -0
  289. data/src/nginx/src/mail/ngx_mail_smtp_handler.c +872 -0
  290. data/src/nginx/src/mail/ngx_mail_smtp_module.c +308 -0
  291. data/src/nginx/src/mail/ngx_mail_smtp_module.h +45 -0
  292. data/src/nginx/src/mail/ngx_mail_ssl_module.c +491 -0
  293. data/src/nginx/src/mail/ngx_mail_ssl_module.h +52 -0
  294. data/src/nginx/src/misc/ngx_cpp_test_module.cpp +27 -0
  295. data/src/nginx/src/misc/ngx_google_perftools_module.c +126 -0
  296. data/src/nginx/src/os/unix/ngx_aio_read.c +109 -0
  297. data/src/nginx/src/os/unix/ngx_aio_read_chain.c +78 -0
  298. data/src/nginx/src/os/unix/ngx_aio_write.c +109 -0
  299. data/src/nginx/src/os/unix/ngx_aio_write_chain.c +100 -0
  300. data/src/nginx/src/os/unix/ngx_alloc.c +90 -0
  301. data/src/nginx/src/os/unix/ngx_alloc.h +45 -0
  302. data/src/nginx/src/os/unix/ngx_atomic.h +311 -0
  303. data/src/nginx/src/os/unix/ngx_channel.c +258 -0
  304. data/src/nginx/src/os/unix/ngx_channel.h +34 -0
  305. data/src/nginx/src/os/unix/ngx_daemon.c +69 -0
  306. data/src/nginx/src/os/unix/ngx_darwin.h +20 -0
  307. data/src/nginx/src/os/unix/ngx_darwin_config.h +96 -0
  308. data/src/nginx/src/os/unix/ngx_darwin_init.c +166 -0
  309. data/src/nginx/src/os/unix/ngx_darwin_sendfile_chain.c +366 -0
  310. data/src/nginx/src/os/unix/ngx_errno.c +87 -0
  311. data/src/nginx/src/os/unix/ngx_errno.h +68 -0
  312. data/src/nginx/src/os/unix/ngx_file_aio_read.c +208 -0
  313. data/src/nginx/src/os/unix/ngx_files.c +566 -0
  314. data/src/nginx/src/os/unix/ngx_files.h +343 -0
  315. data/src/nginx/src/os/unix/ngx_freebsd.h +24 -0
  316. data/src/nginx/src/os/unix/ngx_freebsd_config.h +119 -0
  317. data/src/nginx/src/os/unix/ngx_freebsd_init.c +259 -0
  318. data/src/nginx/src/os/unix/ngx_freebsd_rfork_thread.c +756 -0
  319. data/src/nginx/src/os/unix/ngx_freebsd_rfork_thread.h +122 -0
  320. data/src/nginx/src/os/unix/ngx_freebsd_sendfile_chain.c +436 -0
  321. data/src/nginx/src/os/unix/ngx_gcc_atomic_amd64.h +82 -0
  322. data/src/nginx/src/os/unix/ngx_gcc_atomic_ppc.h +155 -0
  323. data/src/nginx/src/os/unix/ngx_gcc_atomic_sparc64.h +82 -0
  324. data/src/nginx/src/os/unix/ngx_gcc_atomic_x86.h +127 -0
  325. data/src/nginx/src/os/unix/ngx_linux.h +18 -0
  326. data/src/nginx/src/os/unix/ngx_linux_aio_read.c +137 -0
  327. data/src/nginx/src/os/unix/ngx_linux_config.h +117 -0
  328. data/src/nginx/src/os/unix/ngx_linux_init.c +91 -0
  329. data/src/nginx/src/os/unix/ngx_linux_sendfile_chain.c +378 -0
  330. data/src/nginx/src/os/unix/ngx_os.h +84 -0
  331. data/src/nginx/src/os/unix/ngx_posix_config.h +153 -0
  332. data/src/nginx/src/os/unix/ngx_posix_init.c +124 -0
  333. data/src/nginx/src/os/unix/ngx_process.c +590 -0
  334. data/src/nginx/src/os/unix/ngx_process.h +87 -0
  335. data/src/nginx/src/os/unix/ngx_process_cycle.c +1390 -0
  336. data/src/nginx/src/os/unix/ngx_process_cycle.h +61 -0
  337. data/src/nginx/src/os/unix/ngx_pthread_thread.c +278 -0
  338. data/src/nginx/src/os/unix/ngx_readv_chain.c +258 -0
  339. data/src/nginx/src/os/unix/ngx_recv.c +180 -0
  340. data/src/nginx/src/os/unix/ngx_send.c +73 -0
  341. data/src/nginx/src/os/unix/ngx_setproctitle.c +135 -0
  342. data/src/nginx/src/os/unix/ngx_setproctitle.h +52 -0
  343. data/src/nginx/src/os/unix/ngx_shmem.c +126 -0
  344. data/src/nginx/src/os/unix/ngx_shmem.h +29 -0
  345. data/src/nginx/src/os/unix/ngx_socket.c +116 -0
  346. data/src/nginx/src/os/unix/ngx_socket.h +64 -0
  347. data/src/nginx/src/os/unix/ngx_solaris.h +16 -0
  348. data/src/nginx/src/os/unix/ngx_solaris_config.h +107 -0
  349. data/src/nginx/src/os/unix/ngx_solaris_init.c +75 -0
  350. data/src/nginx/src/os/unix/ngx_solaris_sendfilev_chain.c +251 -0
  351. data/src/nginx/src/os/unix/ngx_sunpro_amd64.il +43 -0
  352. data/src/nginx/src/os/unix/ngx_sunpro_atomic_sparc64.h +61 -0
  353. data/src/nginx/src/os/unix/ngx_sunpro_sparc64.il +36 -0
  354. data/src/nginx/src/os/unix/ngx_sunpro_x86.il +44 -0
  355. data/src/nginx/src/os/unix/ngx_thread.h +128 -0
  356. data/src/nginx/src/os/unix/ngx_time.c +104 -0
  357. data/src/nginx/src/os/unix/ngx_time.h +66 -0
  358. data/src/nginx/src/os/unix/ngx_udp_recv.c +115 -0
  359. data/src/nginx/src/os/unix/ngx_user.c +109 -0
  360. data/src/nginx/src/os/unix/ngx_user.h +24 -0
  361. data/src/nginx/src/os/unix/ngx_writev_chain.c +181 -0
  362. data/src/nginx/src/os/unix/rfork_thread.S +73 -0
  363. metadata +419 -0
@@ -0,0 +1,407 @@
1
+
2
+ /*
3
+ * Copyright (C) Igor Sysoev
4
+ * Copyright (C) Nginx, Inc.
5
+ */
6
+
7
+
8
+ #ifndef _NGX_MAIL_H_INCLUDED_
9
+ #define _NGX_MAIL_H_INCLUDED_
10
+
11
+
12
+ #include <ngx_config.h>
13
+ #include <ngx_core.h>
14
+ #include <ngx_event.h>
15
+ #include <ngx_event_connect.h>
16
+
17
+ #if (NGX_MAIL_SSL)
18
+ #include <ngx_mail_ssl_module.h>
19
+ #endif
20
+
21
+
22
+
23
+ typedef struct {
24
+ void **main_conf;
25
+ void **srv_conf;
26
+ } ngx_mail_conf_ctx_t;
27
+
28
+
29
+ typedef struct {
30
+ u_char sockaddr[NGX_SOCKADDRLEN];
31
+ socklen_t socklen;
32
+
33
+ /* server ctx */
34
+ ngx_mail_conf_ctx_t *ctx;
35
+
36
+ unsigned bind:1;
37
+ unsigned wildcard:1;
38
+ #if (NGX_MAIL_SSL)
39
+ unsigned ssl:1;
40
+ #endif
41
+ #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
42
+ unsigned ipv6only:2;
43
+ #endif
44
+ } ngx_mail_listen_t;
45
+
46
+
47
+ typedef struct {
48
+ ngx_mail_conf_ctx_t *ctx;
49
+ ngx_str_t addr_text;
50
+ #if (NGX_MAIL_SSL)
51
+ ngx_uint_t ssl; /* unsigned ssl:1; */
52
+ #endif
53
+ } ngx_mail_addr_conf_t;
54
+
55
+ typedef struct {
56
+ in_addr_t addr;
57
+ ngx_mail_addr_conf_t conf;
58
+ } ngx_mail_in_addr_t;
59
+
60
+
61
+ #if (NGX_HAVE_INET6)
62
+
63
+ typedef struct {
64
+ struct in6_addr addr6;
65
+ ngx_mail_addr_conf_t conf;
66
+ } ngx_mail_in6_addr_t;
67
+
68
+ #endif
69
+
70
+
71
+ typedef struct {
72
+ /* ngx_mail_in_addr_t or ngx_mail_in6_addr_t */
73
+ void *addrs;
74
+ ngx_uint_t naddrs;
75
+ } ngx_mail_port_t;
76
+
77
+
78
+ typedef struct {
79
+ int family;
80
+ in_port_t port;
81
+ ngx_array_t addrs; /* array of ngx_mail_conf_addr_t */
82
+ } ngx_mail_conf_port_t;
83
+
84
+
85
+ typedef struct {
86
+ struct sockaddr *sockaddr;
87
+ socklen_t socklen;
88
+
89
+ ngx_mail_conf_ctx_t *ctx;
90
+
91
+ unsigned bind:1;
92
+ unsigned wildcard:1;
93
+ #if (NGX_MAIL_SSL)
94
+ unsigned ssl:1;
95
+ #endif
96
+ #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
97
+ unsigned ipv6only:2;
98
+ #endif
99
+ } ngx_mail_conf_addr_t;
100
+
101
+
102
+ typedef struct {
103
+ ngx_array_t servers; /* ngx_mail_core_srv_conf_t */
104
+ ngx_array_t listen; /* ngx_mail_listen_t */
105
+ } ngx_mail_core_main_conf_t;
106
+
107
+
108
+ #define NGX_MAIL_POP3_PROTOCOL 0
109
+ #define NGX_MAIL_IMAP_PROTOCOL 1
110
+ #define NGX_MAIL_SMTP_PROTOCOL 2
111
+
112
+
113
+ typedef struct ngx_mail_protocol_s ngx_mail_protocol_t;
114
+
115
+
116
+ typedef struct {
117
+ ngx_mail_protocol_t *protocol;
118
+
119
+ ngx_msec_t timeout;
120
+ ngx_msec_t resolver_timeout;
121
+
122
+ ngx_flag_t so_keepalive;
123
+
124
+ ngx_str_t server_name;
125
+
126
+ u_char *file_name;
127
+ ngx_int_t line;
128
+
129
+ ngx_resolver_t *resolver;
130
+
131
+ /* server ctx */
132
+ ngx_mail_conf_ctx_t *ctx;
133
+ } ngx_mail_core_srv_conf_t;
134
+
135
+
136
+ typedef enum {
137
+ ngx_pop3_start = 0,
138
+ ngx_pop3_user,
139
+ ngx_pop3_passwd,
140
+ ngx_pop3_auth_login_username,
141
+ ngx_pop3_auth_login_password,
142
+ ngx_pop3_auth_plain,
143
+ ngx_pop3_auth_cram_md5
144
+ } ngx_pop3_state_e;
145
+
146
+
147
+ typedef enum {
148
+ ngx_imap_start = 0,
149
+ ngx_imap_auth_login_username,
150
+ ngx_imap_auth_login_password,
151
+ ngx_imap_auth_plain,
152
+ ngx_imap_auth_cram_md5,
153
+ ngx_imap_login,
154
+ ngx_imap_user,
155
+ ngx_imap_passwd
156
+ } ngx_imap_state_e;
157
+
158
+
159
+ typedef enum {
160
+ ngx_smtp_start = 0,
161
+ ngx_smtp_auth_login_username,
162
+ ngx_smtp_auth_login_password,
163
+ ngx_smtp_auth_plain,
164
+ ngx_smtp_auth_cram_md5,
165
+ ngx_smtp_helo,
166
+ ngx_smtp_helo_xclient,
167
+ ngx_smtp_helo_from,
168
+ ngx_smtp_xclient,
169
+ ngx_smtp_xclient_from,
170
+ ngx_smtp_xclient_helo,
171
+ ngx_smtp_from,
172
+ ngx_smtp_to
173
+ } ngx_smtp_state_e;
174
+
175
+
176
+ typedef struct {
177
+ ngx_peer_connection_t upstream;
178
+ ngx_buf_t *buffer;
179
+ } ngx_mail_proxy_ctx_t;
180
+
181
+
182
+ typedef struct {
183
+ uint32_t signature; /* "MAIL" */
184
+
185
+ ngx_connection_t *connection;
186
+
187
+ ngx_str_t out;
188
+ ngx_buf_t *buffer;
189
+
190
+ void **ctx;
191
+ void **main_conf;
192
+ void **srv_conf;
193
+
194
+ ngx_resolver_ctx_t *resolver_ctx;
195
+
196
+ ngx_mail_proxy_ctx_t *proxy;
197
+
198
+ ngx_uint_t mail_state;
199
+
200
+ unsigned protocol:3;
201
+ unsigned blocked:1;
202
+ unsigned quit:1;
203
+ unsigned quoted:1;
204
+ unsigned backslash:1;
205
+ unsigned no_sync_literal:1;
206
+ unsigned starttls:1;
207
+ unsigned esmtp:1;
208
+ unsigned auth_method:3;
209
+ unsigned auth_wait:1;
210
+
211
+ ngx_str_t login;
212
+ ngx_str_t passwd;
213
+
214
+ ngx_str_t salt;
215
+ ngx_str_t tag;
216
+ ngx_str_t tagged_line;
217
+ ngx_str_t text;
218
+
219
+ ngx_str_t *addr_text;
220
+ ngx_str_t host;
221
+ ngx_str_t smtp_helo;
222
+ ngx_str_t smtp_from;
223
+ ngx_str_t smtp_to;
224
+
225
+ ngx_uint_t command;
226
+ ngx_array_t args;
227
+
228
+ ngx_uint_t login_attempt;
229
+
230
+ /* used to parse POP3/IMAP/SMTP command */
231
+
232
+ ngx_uint_t state;
233
+ u_char *cmd_start;
234
+ u_char *arg_start;
235
+ u_char *arg_end;
236
+ ngx_uint_t literal_len;
237
+ } ngx_mail_session_t;
238
+
239
+
240
+ typedef struct {
241
+ ngx_str_t *client;
242
+ ngx_mail_session_t *session;
243
+ } ngx_mail_log_ctx_t;
244
+
245
+
246
+ #define NGX_POP3_USER 1
247
+ #define NGX_POP3_PASS 2
248
+ #define NGX_POP3_CAPA 3
249
+ #define NGX_POP3_QUIT 4
250
+ #define NGX_POP3_NOOP 5
251
+ #define NGX_POP3_STLS 6
252
+ #define NGX_POP3_APOP 7
253
+ #define NGX_POP3_AUTH 8
254
+ #define NGX_POP3_STAT 9
255
+ #define NGX_POP3_LIST 10
256
+ #define NGX_POP3_RETR 11
257
+ #define NGX_POP3_DELE 12
258
+ #define NGX_POP3_RSET 13
259
+ #define NGX_POP3_TOP 14
260
+ #define NGX_POP3_UIDL 15
261
+
262
+
263
+ #define NGX_IMAP_LOGIN 1
264
+ #define NGX_IMAP_LOGOUT 2
265
+ #define NGX_IMAP_CAPABILITY 3
266
+ #define NGX_IMAP_NOOP 4
267
+ #define NGX_IMAP_STARTTLS 5
268
+
269
+ #define NGX_IMAP_NEXT 6
270
+
271
+ #define NGX_IMAP_AUTHENTICATE 7
272
+
273
+
274
+ #define NGX_SMTP_HELO 1
275
+ #define NGX_SMTP_EHLO 2
276
+ #define NGX_SMTP_AUTH 3
277
+ #define NGX_SMTP_QUIT 4
278
+ #define NGX_SMTP_NOOP 5
279
+ #define NGX_SMTP_MAIL 6
280
+ #define NGX_SMTP_RSET 7
281
+ #define NGX_SMTP_RCPT 8
282
+ #define NGX_SMTP_DATA 9
283
+ #define NGX_SMTP_VRFY 10
284
+ #define NGX_SMTP_EXPN 11
285
+ #define NGX_SMTP_HELP 12
286
+ #define NGX_SMTP_STARTTLS 13
287
+
288
+
289
+ #define NGX_MAIL_AUTH_PLAIN 0
290
+ #define NGX_MAIL_AUTH_LOGIN 1
291
+ #define NGX_MAIL_AUTH_LOGIN_USERNAME 2
292
+ #define NGX_MAIL_AUTH_APOP 3
293
+ #define NGX_MAIL_AUTH_CRAM_MD5 4
294
+ #define NGX_MAIL_AUTH_NONE 5
295
+
296
+
297
+ #define NGX_MAIL_AUTH_PLAIN_ENABLED 0x0002
298
+ #define NGX_MAIL_AUTH_LOGIN_ENABLED 0x0004
299
+ #define NGX_MAIL_AUTH_APOP_ENABLED 0x0008
300
+ #define NGX_MAIL_AUTH_CRAM_MD5_ENABLED 0x0010
301
+ #define NGX_MAIL_AUTH_NONE_ENABLED 0x0020
302
+
303
+
304
+ #define NGX_MAIL_PARSE_INVALID_COMMAND 20
305
+
306
+
307
+ typedef void (*ngx_mail_init_session_pt)(ngx_mail_session_t *s,
308
+ ngx_connection_t *c);
309
+ typedef void (*ngx_mail_init_protocol_pt)(ngx_event_t *rev);
310
+ typedef void (*ngx_mail_auth_state_pt)(ngx_event_t *rev);
311
+ typedef ngx_int_t (*ngx_mail_parse_command_pt)(ngx_mail_session_t *s);
312
+
313
+
314
+ struct ngx_mail_protocol_s {
315
+ ngx_str_t name;
316
+ in_port_t port[4];
317
+ ngx_uint_t type;
318
+
319
+ ngx_mail_init_session_pt init_session;
320
+ ngx_mail_init_protocol_pt init_protocol;
321
+ ngx_mail_parse_command_pt parse_command;
322
+ ngx_mail_auth_state_pt auth_state;
323
+
324
+ ngx_str_t internal_server_error;
325
+ };
326
+
327
+
328
+ typedef struct {
329
+ ngx_mail_protocol_t *protocol;
330
+
331
+ void *(*create_main_conf)(ngx_conf_t *cf);
332
+ char *(*init_main_conf)(ngx_conf_t *cf, void *conf);
333
+
334
+ void *(*create_srv_conf)(ngx_conf_t *cf);
335
+ char *(*merge_srv_conf)(ngx_conf_t *cf, void *prev,
336
+ void *conf);
337
+ } ngx_mail_module_t;
338
+
339
+
340
+ #define NGX_MAIL_MODULE 0x4C49414D /* "MAIL" */
341
+
342
+ #define NGX_MAIL_MAIN_CONF 0x02000000
343
+ #define NGX_MAIL_SRV_CONF 0x04000000
344
+
345
+
346
+ #define NGX_MAIL_MAIN_CONF_OFFSET offsetof(ngx_mail_conf_ctx_t, main_conf)
347
+ #define NGX_MAIL_SRV_CONF_OFFSET offsetof(ngx_mail_conf_ctx_t, srv_conf)
348
+
349
+
350
+ #define ngx_mail_get_module_ctx(s, module) (s)->ctx[module.ctx_index]
351
+ #define ngx_mail_set_ctx(s, c, module) s->ctx[module.ctx_index] = c;
352
+ #define ngx_mail_delete_ctx(s, module) s->ctx[module.ctx_index] = NULL;
353
+
354
+
355
+ #define ngx_mail_get_module_main_conf(s, module) \
356
+ (s)->main_conf[module.ctx_index]
357
+ #define ngx_mail_get_module_srv_conf(s, module) (s)->srv_conf[module.ctx_index]
358
+
359
+ #define ngx_mail_conf_get_module_main_conf(cf, module) \
360
+ ((ngx_mail_conf_ctx_t *) cf->ctx)->main_conf[module.ctx_index]
361
+ #define ngx_mail_conf_get_module_srv_conf(cf, module) \
362
+ ((ngx_mail_conf_ctx_t *) cf->ctx)->srv_conf[module.ctx_index]
363
+
364
+
365
+ #if (NGX_MAIL_SSL)
366
+ void ngx_mail_starttls_handler(ngx_event_t *rev);
367
+ ngx_int_t ngx_mail_starttls_only(ngx_mail_session_t *s, ngx_connection_t *c);
368
+ #endif
369
+
370
+
371
+ void ngx_mail_init_connection(ngx_connection_t *c);
372
+
373
+ ngx_int_t ngx_mail_salt(ngx_mail_session_t *s, ngx_connection_t *c,
374
+ ngx_mail_core_srv_conf_t *cscf);
375
+ ngx_int_t ngx_mail_auth_plain(ngx_mail_session_t *s, ngx_connection_t *c,
376
+ ngx_uint_t n);
377
+ ngx_int_t ngx_mail_auth_login_username(ngx_mail_session_t *s,
378
+ ngx_connection_t *c, ngx_uint_t n);
379
+ ngx_int_t ngx_mail_auth_login_password(ngx_mail_session_t *s,
380
+ ngx_connection_t *c);
381
+ ngx_int_t ngx_mail_auth_cram_md5_salt(ngx_mail_session_t *s,
382
+ ngx_connection_t *c, char *prefix, size_t len);
383
+ ngx_int_t ngx_mail_auth_cram_md5(ngx_mail_session_t *s, ngx_connection_t *c);
384
+ ngx_int_t ngx_mail_auth_parse(ngx_mail_session_t *s, ngx_connection_t *c);
385
+
386
+ void ngx_mail_send(ngx_event_t *wev);
387
+ ngx_int_t ngx_mail_read_command(ngx_mail_session_t *s, ngx_connection_t *c);
388
+ void ngx_mail_auth(ngx_mail_session_t *s, ngx_connection_t *c);
389
+ void ngx_mail_close_connection(ngx_connection_t *c);
390
+ void ngx_mail_session_internal_server_error(ngx_mail_session_t *s);
391
+ u_char *ngx_mail_log_error(ngx_log_t *log, u_char *buf, size_t len);
392
+
393
+
394
+ char *ngx_mail_capabilities(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
395
+
396
+
397
+ /* STUB */
398
+ void ngx_mail_proxy_init(ngx_mail_session_t *s, ngx_addr_t *peer);
399
+ void ngx_mail_auth_http_init(ngx_mail_session_t *s);
400
+ /**/
401
+
402
+
403
+ extern ngx_uint_t ngx_mail_max_module;
404
+ extern ngx_module_t ngx_mail_core_module;
405
+
406
+
407
+ #endif /* _NGX_MAIL_H_INCLUDED_ */
@@ -0,0 +1,1452 @@
1
+
2
+ /*
3
+ * Copyright (C) Igor Sysoev
4
+ * Copyright (C) Nginx, Inc.
5
+ */
6
+
7
+
8
+ #include <ngx_config.h>
9
+ #include <ngx_core.h>
10
+ #include <ngx_event.h>
11
+ #include <ngx_event_connect.h>
12
+ #include <ngx_mail.h>
13
+
14
+
15
+ typedef struct {
16
+ ngx_addr_t *peer;
17
+
18
+ ngx_msec_t timeout;
19
+
20
+ ngx_str_t host_header;
21
+ ngx_str_t uri;
22
+ ngx_str_t header;
23
+
24
+ ngx_array_t *headers;
25
+
26
+ u_char *file;
27
+ ngx_uint_t line;
28
+ } ngx_mail_auth_http_conf_t;
29
+
30
+
31
+ typedef struct ngx_mail_auth_http_ctx_s ngx_mail_auth_http_ctx_t;
32
+
33
+ typedef void (*ngx_mail_auth_http_handler_pt)(ngx_mail_session_t *s,
34
+ ngx_mail_auth_http_ctx_t *ctx);
35
+
36
+ struct ngx_mail_auth_http_ctx_s {
37
+ ngx_buf_t *request;
38
+ ngx_buf_t *response;
39
+ ngx_peer_connection_t peer;
40
+
41
+ ngx_mail_auth_http_handler_pt handler;
42
+
43
+ ngx_uint_t state;
44
+
45
+ u_char *header_name_start;
46
+ u_char *header_name_end;
47
+ u_char *header_start;
48
+ u_char *header_end;
49
+
50
+ ngx_str_t addr;
51
+ ngx_str_t port;
52
+ ngx_str_t err;
53
+ ngx_str_t errmsg;
54
+ ngx_str_t errcode;
55
+
56
+ time_t sleep;
57
+
58
+ ngx_pool_t *pool;
59
+ };
60
+
61
+
62
+ static void ngx_mail_auth_http_write_handler(ngx_event_t *wev);
63
+ static void ngx_mail_auth_http_read_handler(ngx_event_t *rev);
64
+ static void ngx_mail_auth_http_ignore_status_line(ngx_mail_session_t *s,
65
+ ngx_mail_auth_http_ctx_t *ctx);
66
+ static void ngx_mail_auth_http_process_headers(ngx_mail_session_t *s,
67
+ ngx_mail_auth_http_ctx_t *ctx);
68
+ static void ngx_mail_auth_sleep_handler(ngx_event_t *rev);
69
+ static ngx_int_t ngx_mail_auth_http_parse_header_line(ngx_mail_session_t *s,
70
+ ngx_mail_auth_http_ctx_t *ctx);
71
+ static void ngx_mail_auth_http_block_read(ngx_event_t *rev);
72
+ static void ngx_mail_auth_http_dummy_handler(ngx_event_t *ev);
73
+ static ngx_buf_t *ngx_mail_auth_http_create_request(ngx_mail_session_t *s,
74
+ ngx_pool_t *pool, ngx_mail_auth_http_conf_t *ahcf);
75
+ static ngx_int_t ngx_mail_auth_http_escape(ngx_pool_t *pool, ngx_str_t *text,
76
+ ngx_str_t *escaped);
77
+
78
+ static void *ngx_mail_auth_http_create_conf(ngx_conf_t *cf);
79
+ static char *ngx_mail_auth_http_merge_conf(ngx_conf_t *cf, void *parent,
80
+ void *child);
81
+ static char *ngx_mail_auth_http(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
82
+ static char *ngx_mail_auth_http_header(ngx_conf_t *cf, ngx_command_t *cmd,
83
+ void *conf);
84
+
85
+
86
+ static ngx_command_t ngx_mail_auth_http_commands[] = {
87
+
88
+ { ngx_string("auth_http"),
89
+ NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
90
+ ngx_mail_auth_http,
91
+ NGX_MAIL_SRV_CONF_OFFSET,
92
+ 0,
93
+ NULL },
94
+
95
+ { ngx_string("auth_http_timeout"),
96
+ NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
97
+ ngx_conf_set_msec_slot,
98
+ NGX_MAIL_SRV_CONF_OFFSET,
99
+ offsetof(ngx_mail_auth_http_conf_t, timeout),
100
+ NULL },
101
+
102
+ { ngx_string("auth_http_header"),
103
+ NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE2,
104
+ ngx_mail_auth_http_header,
105
+ NGX_MAIL_SRV_CONF_OFFSET,
106
+ 0,
107
+ NULL },
108
+
109
+ ngx_null_command
110
+ };
111
+
112
+
113
+ static ngx_mail_module_t ngx_mail_auth_http_module_ctx = {
114
+ NULL, /* protocol */
115
+
116
+ NULL, /* create main configuration */
117
+ NULL, /* init main configuration */
118
+
119
+ ngx_mail_auth_http_create_conf, /* create server configuration */
120
+ ngx_mail_auth_http_merge_conf /* merge server configuration */
121
+ };
122
+
123
+
124
+ ngx_module_t ngx_mail_auth_http_module = {
125
+ NGX_MODULE_V1,
126
+ &ngx_mail_auth_http_module_ctx, /* module context */
127
+ ngx_mail_auth_http_commands, /* module directives */
128
+ NGX_MAIL_MODULE, /* module type */
129
+ NULL, /* init master */
130
+ NULL, /* init module */
131
+ NULL, /* init process */
132
+ NULL, /* init thread */
133
+ NULL, /* exit thread */
134
+ NULL, /* exit process */
135
+ NULL, /* exit master */
136
+ NGX_MODULE_V1_PADDING
137
+ };
138
+
139
+
140
+ static ngx_str_t ngx_mail_auth_http_method[] = {
141
+ ngx_string("plain"),
142
+ ngx_string("plain"),
143
+ ngx_string("plain"),
144
+ ngx_string("apop"),
145
+ ngx_string("cram-md5"),
146
+ ngx_string("none")
147
+ };
148
+
149
+ static ngx_str_t ngx_mail_smtp_errcode = ngx_string("535 5.7.0");
150
+
151
+
152
+ void
153
+ ngx_mail_auth_http_init(ngx_mail_session_t *s)
154
+ {
155
+ ngx_int_t rc;
156
+ ngx_pool_t *pool;
157
+ ngx_mail_auth_http_ctx_t *ctx;
158
+ ngx_mail_auth_http_conf_t *ahcf;
159
+
160
+ s->connection->log->action = "in http auth state";
161
+
162
+ pool = ngx_create_pool(2048, s->connection->log);
163
+ if (pool == NULL) {
164
+ ngx_mail_session_internal_server_error(s);
165
+ return;
166
+ }
167
+
168
+ ctx = ngx_pcalloc(pool, sizeof(ngx_mail_auth_http_ctx_t));
169
+ if (ctx == NULL) {
170
+ ngx_destroy_pool(pool);
171
+ ngx_mail_session_internal_server_error(s);
172
+ return;
173
+ }
174
+
175
+ ctx->pool = pool;
176
+
177
+ ahcf = ngx_mail_get_module_srv_conf(s, ngx_mail_auth_http_module);
178
+
179
+ ctx->request = ngx_mail_auth_http_create_request(s, pool, ahcf);
180
+ if (ctx->request == NULL) {
181
+ ngx_destroy_pool(ctx->pool);
182
+ ngx_mail_session_internal_server_error(s);
183
+ return;
184
+ }
185
+
186
+ ngx_mail_set_ctx(s, ctx, ngx_mail_auth_http_module);
187
+
188
+ ctx->peer.sockaddr = ahcf->peer->sockaddr;
189
+ ctx->peer.socklen = ahcf->peer->socklen;
190
+ ctx->peer.name = &ahcf->peer->name;
191
+ ctx->peer.get = ngx_event_get_peer;
192
+ ctx->peer.log = s->connection->log;
193
+ ctx->peer.log_error = NGX_ERROR_ERR;
194
+
195
+ rc = ngx_event_connect_peer(&ctx->peer);
196
+
197
+ if (rc == NGX_ERROR || rc == NGX_BUSY || rc == NGX_DECLINED) {
198
+ if (ctx->peer.connection) {
199
+ ngx_close_connection(ctx->peer.connection);
200
+ }
201
+
202
+ ngx_destroy_pool(ctx->pool);
203
+ ngx_mail_session_internal_server_error(s);
204
+ return;
205
+ }
206
+
207
+ ctx->peer.connection->data = s;
208
+ ctx->peer.connection->pool = s->connection->pool;
209
+
210
+ s->connection->read->handler = ngx_mail_auth_http_block_read;
211
+ ctx->peer.connection->read->handler = ngx_mail_auth_http_read_handler;
212
+ ctx->peer.connection->write->handler = ngx_mail_auth_http_write_handler;
213
+
214
+ ctx->handler = ngx_mail_auth_http_ignore_status_line;
215
+
216
+ ngx_add_timer(ctx->peer.connection->read, ahcf->timeout);
217
+ ngx_add_timer(ctx->peer.connection->write, ahcf->timeout);
218
+
219
+ if (rc == NGX_OK) {
220
+ ngx_mail_auth_http_write_handler(ctx->peer.connection->write);
221
+ return;
222
+ }
223
+ }
224
+
225
+
226
+ static void
227
+ ngx_mail_auth_http_write_handler(ngx_event_t *wev)
228
+ {
229
+ ssize_t n, size;
230
+ ngx_connection_t *c;
231
+ ngx_mail_session_t *s;
232
+ ngx_mail_auth_http_ctx_t *ctx;
233
+ ngx_mail_auth_http_conf_t *ahcf;
234
+
235
+ c = wev->data;
236
+ s = c->data;
237
+
238
+ ctx = ngx_mail_get_module_ctx(s, ngx_mail_auth_http_module);
239
+
240
+ ngx_log_debug0(NGX_LOG_DEBUG_MAIL, wev->log, 0,
241
+ "mail auth http write handler");
242
+
243
+ if (wev->timedout) {
244
+ ngx_log_error(NGX_LOG_ERR, wev->log, NGX_ETIMEDOUT,
245
+ "auth http server %V timed out", ctx->peer.name);
246
+ ngx_close_connection(c);
247
+ ngx_destroy_pool(ctx->pool);
248
+ ngx_mail_session_internal_server_error(s);
249
+ return;
250
+ }
251
+
252
+ size = ctx->request->last - ctx->request->pos;
253
+
254
+ n = ngx_send(c, ctx->request->pos, size);
255
+
256
+ if (n == NGX_ERROR) {
257
+ ngx_close_connection(c);
258
+ ngx_destroy_pool(ctx->pool);
259
+ ngx_mail_session_internal_server_error(s);
260
+ return;
261
+ }
262
+
263
+ if (n > 0) {
264
+ ctx->request->pos += n;
265
+
266
+ if (n == size) {
267
+ wev->handler = ngx_mail_auth_http_dummy_handler;
268
+
269
+ if (wev->timer_set) {
270
+ ngx_del_timer(wev);
271
+ }
272
+
273
+ if (ngx_handle_write_event(wev, 0) != NGX_OK) {
274
+ ngx_close_connection(c);
275
+ ngx_destroy_pool(ctx->pool);
276
+ ngx_mail_session_internal_server_error(s);
277
+ }
278
+
279
+ return;
280
+ }
281
+ }
282
+
283
+ if (!wev->timer_set) {
284
+ ahcf = ngx_mail_get_module_srv_conf(s, ngx_mail_auth_http_module);
285
+ ngx_add_timer(wev, ahcf->timeout);
286
+ }
287
+ }
288
+
289
+
290
+ static void
291
+ ngx_mail_auth_http_read_handler(ngx_event_t *rev)
292
+ {
293
+ ssize_t n, size;
294
+ ngx_connection_t *c;
295
+ ngx_mail_session_t *s;
296
+ ngx_mail_auth_http_ctx_t *ctx;
297
+
298
+ c = rev->data;
299
+ s = c->data;
300
+
301
+ ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0,
302
+ "mail auth http read handler");
303
+
304
+ ctx = ngx_mail_get_module_ctx(s, ngx_mail_auth_http_module);
305
+
306
+ if (rev->timedout) {
307
+ ngx_log_error(NGX_LOG_ERR, rev->log, NGX_ETIMEDOUT,
308
+ "auth http server %V timed out", ctx->peer.name);
309
+ ngx_close_connection(c);
310
+ ngx_destroy_pool(ctx->pool);
311
+ ngx_mail_session_internal_server_error(s);
312
+ return;
313
+ }
314
+
315
+ if (ctx->response == NULL) {
316
+ ctx->response = ngx_create_temp_buf(ctx->pool, 1024);
317
+ if (ctx->response == NULL) {
318
+ ngx_close_connection(c);
319
+ ngx_destroy_pool(ctx->pool);
320
+ ngx_mail_session_internal_server_error(s);
321
+ return;
322
+ }
323
+ }
324
+
325
+ size = ctx->response->end - ctx->response->last;
326
+
327
+ n = ngx_recv(c, ctx->response->pos, size);
328
+
329
+ if (n > 0) {
330
+ ctx->response->last += n;
331
+
332
+ ctx->handler(s, ctx);
333
+ return;
334
+ }
335
+
336
+ if (n == NGX_AGAIN) {
337
+ return;
338
+ }
339
+
340
+ ngx_close_connection(c);
341
+ ngx_destroy_pool(ctx->pool);
342
+ ngx_mail_session_internal_server_error(s);
343
+ }
344
+
345
+
346
+ static void
347
+ ngx_mail_auth_http_ignore_status_line(ngx_mail_session_t *s,
348
+ ngx_mail_auth_http_ctx_t *ctx)
349
+ {
350
+ u_char *p, ch;
351
+ enum {
352
+ sw_start = 0,
353
+ sw_H,
354
+ sw_HT,
355
+ sw_HTT,
356
+ sw_HTTP,
357
+ sw_skip,
358
+ sw_almost_done
359
+ } state;
360
+
361
+ ngx_log_debug0(NGX_LOG_DEBUG_MAIL, s->connection->log, 0,
362
+ "mail auth http process status line");
363
+
364
+ state = ctx->state;
365
+
366
+ for (p = ctx->response->pos; p < ctx->response->last; p++) {
367
+ ch = *p;
368
+
369
+ switch (state) {
370
+
371
+ /* "HTTP/" */
372
+ case sw_start:
373
+ if (ch == 'H') {
374
+ state = sw_H;
375
+ break;
376
+ }
377
+ goto next;
378
+
379
+ case sw_H:
380
+ if (ch == 'T') {
381
+ state = sw_HT;
382
+ break;
383
+ }
384
+ goto next;
385
+
386
+ case sw_HT:
387
+ if (ch == 'T') {
388
+ state = sw_HTT;
389
+ break;
390
+ }
391
+ goto next;
392
+
393
+ case sw_HTT:
394
+ if (ch == 'P') {
395
+ state = sw_HTTP;
396
+ break;
397
+ }
398
+ goto next;
399
+
400
+ case sw_HTTP:
401
+ if (ch == '/') {
402
+ state = sw_skip;
403
+ break;
404
+ }
405
+ goto next;
406
+
407
+ /* any text until end of line */
408
+ case sw_skip:
409
+ switch (ch) {
410
+ case CR:
411
+ state = sw_almost_done;
412
+
413
+ break;
414
+ case LF:
415
+ goto done;
416
+ }
417
+ break;
418
+
419
+ /* end of status line */
420
+ case sw_almost_done:
421
+ if (ch == LF) {
422
+ goto done;
423
+ }
424
+
425
+ ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
426
+ "auth http server &V sent invalid response",
427
+ ctx->peer.name);
428
+ ngx_close_connection(ctx->peer.connection);
429
+ ngx_destroy_pool(ctx->pool);
430
+ ngx_mail_session_internal_server_error(s);
431
+ return;
432
+ }
433
+ }
434
+
435
+ ctx->response->pos = p;
436
+ ctx->state = state;
437
+
438
+ return;
439
+
440
+ next:
441
+
442
+ p = ctx->response->start - 1;
443
+
444
+ done:
445
+
446
+ ctx->response->pos = p + 1;
447
+ ctx->state = 0;
448
+ ctx->handler = ngx_mail_auth_http_process_headers;
449
+ ctx->handler(s, ctx);
450
+ }
451
+
452
+
453
+ static void
454
+ ngx_mail_auth_http_process_headers(ngx_mail_session_t *s,
455
+ ngx_mail_auth_http_ctx_t *ctx)
456
+ {
457
+ u_char *p;
458
+ time_t timer;
459
+ size_t len, size;
460
+ ngx_int_t rc, port, n;
461
+ ngx_addr_t *peer;
462
+ struct sockaddr_in *sin;
463
+
464
+ ngx_log_debug0(NGX_LOG_DEBUG_MAIL, s->connection->log, 0,
465
+ "mail auth http process headers");
466
+
467
+ for ( ;; ) {
468
+ rc = ngx_mail_auth_http_parse_header_line(s, ctx);
469
+
470
+ if (rc == NGX_OK) {
471
+
472
+ #if (NGX_DEBUG)
473
+ {
474
+ ngx_str_t key, value;
475
+
476
+ key.len = ctx->header_name_end - ctx->header_name_start;
477
+ key.data = ctx->header_name_start;
478
+ value.len = ctx->header_end - ctx->header_start;
479
+ value.data = ctx->header_start;
480
+
481
+ ngx_log_debug2(NGX_LOG_DEBUG_MAIL, s->connection->log, 0,
482
+ "mail auth http header: \"%V: %V\"",
483
+ &key, &value);
484
+ }
485
+ #endif
486
+
487
+ len = ctx->header_name_end - ctx->header_name_start;
488
+
489
+ if (len == sizeof("Auth-Status") - 1
490
+ && ngx_strncasecmp(ctx->header_name_start,
491
+ (u_char *) "Auth-Status",
492
+ sizeof("Auth-Status") - 1)
493
+ == 0)
494
+ {
495
+ len = ctx->header_end - ctx->header_start;
496
+
497
+ if (len == 2
498
+ && ctx->header_start[0] == 'O'
499
+ && ctx->header_start[1] == 'K')
500
+ {
501
+ continue;
502
+ }
503
+
504
+ if (len == 4
505
+ && ctx->header_start[0] == 'W'
506
+ && ctx->header_start[1] == 'A'
507
+ && ctx->header_start[2] == 'I'
508
+ && ctx->header_start[3] == 'T')
509
+ {
510
+ s->auth_wait = 1;
511
+ continue;
512
+ }
513
+
514
+ ctx->errmsg.len = len;
515
+ ctx->errmsg.data = ctx->header_start;
516
+
517
+ switch (s->protocol) {
518
+
519
+ case NGX_MAIL_POP3_PROTOCOL:
520
+ size = sizeof("-ERR ") - 1 + len + sizeof(CRLF) - 1;
521
+ break;
522
+
523
+ case NGX_MAIL_IMAP_PROTOCOL:
524
+ size = s->tag.len + sizeof("NO ") - 1 + len
525
+ + sizeof(CRLF) - 1;
526
+ break;
527
+
528
+ default: /* NGX_MAIL_SMTP_PROTOCOL */
529
+ ctx->err = ctx->errmsg;
530
+ continue;
531
+ }
532
+
533
+ p = ngx_pnalloc(s->connection->pool, size);
534
+ if (p == NULL) {
535
+ ngx_close_connection(ctx->peer.connection);
536
+ ngx_destroy_pool(ctx->pool);
537
+ ngx_mail_session_internal_server_error(s);
538
+ return;
539
+ }
540
+
541
+ ctx->err.data = p;
542
+
543
+ switch (s->protocol) {
544
+
545
+ case NGX_MAIL_POP3_PROTOCOL:
546
+ *p++ = '-'; *p++ = 'E'; *p++ = 'R'; *p++ = 'R'; *p++ = ' ';
547
+ break;
548
+
549
+ case NGX_MAIL_IMAP_PROTOCOL:
550
+ p = ngx_cpymem(p, s->tag.data, s->tag.len);
551
+ *p++ = 'N'; *p++ = 'O'; *p++ = ' ';
552
+ break;
553
+
554
+ default: /* NGX_MAIL_SMTP_PROTOCOL */
555
+ break;
556
+ }
557
+
558
+ p = ngx_cpymem(p, ctx->header_start, len);
559
+ *p++ = CR; *p++ = LF;
560
+
561
+ ctx->err.len = p - ctx->err.data;
562
+
563
+ continue;
564
+ }
565
+
566
+ if (len == sizeof("Auth-Server") - 1
567
+ && ngx_strncasecmp(ctx->header_name_start,
568
+ (u_char *) "Auth-Server",
569
+ sizeof("Auth-Server") - 1)
570
+ == 0)
571
+ {
572
+ ctx->addr.len = ctx->header_end - ctx->header_start;
573
+ ctx->addr.data = ctx->header_start;
574
+
575
+ continue;
576
+ }
577
+
578
+ if (len == sizeof("Auth-Port") - 1
579
+ && ngx_strncasecmp(ctx->header_name_start,
580
+ (u_char *) "Auth-Port",
581
+ sizeof("Auth-Port") - 1)
582
+ == 0)
583
+ {
584
+ ctx->port.len = ctx->header_end - ctx->header_start;
585
+ ctx->port.data = ctx->header_start;
586
+
587
+ continue;
588
+ }
589
+
590
+ if (len == sizeof("Auth-User") - 1
591
+ && ngx_strncasecmp(ctx->header_name_start,
592
+ (u_char *) "Auth-User",
593
+ sizeof("Auth-User") - 1)
594
+ == 0)
595
+ {
596
+ s->login.len = ctx->header_end - ctx->header_start;
597
+
598
+ s->login.data = ngx_pnalloc(s->connection->pool, s->login.len);
599
+ if (s->login.data == NULL) {
600
+ ngx_close_connection(ctx->peer.connection);
601
+ ngx_destroy_pool(ctx->pool);
602
+ ngx_mail_session_internal_server_error(s);
603
+ return;
604
+ }
605
+
606
+ ngx_memcpy(s->login.data, ctx->header_start, s->login.len);
607
+
608
+ continue;
609
+ }
610
+
611
+ if (len == sizeof("Auth-Pass") - 1
612
+ && ngx_strncasecmp(ctx->header_name_start,
613
+ (u_char *) "Auth-Pass",
614
+ sizeof("Auth-Pass") - 1)
615
+ == 0)
616
+ {
617
+ s->passwd.len = ctx->header_end - ctx->header_start;
618
+
619
+ s->passwd.data = ngx_pnalloc(s->connection->pool,
620
+ s->passwd.len);
621
+ if (s->passwd.data == NULL) {
622
+ ngx_close_connection(ctx->peer.connection);
623
+ ngx_destroy_pool(ctx->pool);
624
+ ngx_mail_session_internal_server_error(s);
625
+ return;
626
+ }
627
+
628
+ ngx_memcpy(s->passwd.data, ctx->header_start, s->passwd.len);
629
+
630
+ continue;
631
+ }
632
+
633
+ if (len == sizeof("Auth-Wait") - 1
634
+ && ngx_strncasecmp(ctx->header_name_start,
635
+ (u_char *) "Auth-Wait",
636
+ sizeof("Auth-Wait") - 1)
637
+ == 0)
638
+ {
639
+ n = ngx_atoi(ctx->header_start,
640
+ ctx->header_end - ctx->header_start);
641
+
642
+ if (n != NGX_ERROR) {
643
+ ctx->sleep = n;
644
+ }
645
+
646
+ continue;
647
+ }
648
+
649
+ if (len == sizeof("Auth-Error-Code") - 1
650
+ && ngx_strncasecmp(ctx->header_name_start,
651
+ (u_char *) "Auth-Error-Code",
652
+ sizeof("Auth-Error-Code") - 1)
653
+ == 0)
654
+ {
655
+ ctx->errcode.len = ctx->header_end - ctx->header_start;
656
+
657
+ ctx->errcode.data = ngx_pnalloc(s->connection->pool,
658
+ ctx->errcode.len);
659
+ if (ctx->errcode.data == NULL) {
660
+ ngx_close_connection(ctx->peer.connection);
661
+ ngx_destroy_pool(ctx->pool);
662
+ ngx_mail_session_internal_server_error(s);
663
+ return;
664
+ }
665
+
666
+ ngx_memcpy(ctx->errcode.data, ctx->header_start,
667
+ ctx->errcode.len);
668
+
669
+ continue;
670
+ }
671
+
672
+ /* ignore other headers */
673
+
674
+ continue;
675
+ }
676
+
677
+ if (rc == NGX_DONE) {
678
+ ngx_log_debug0(NGX_LOG_DEBUG_MAIL, s->connection->log, 0,
679
+ "mail auth http header done");
680
+
681
+ ngx_close_connection(ctx->peer.connection);
682
+
683
+ if (ctx->err.len) {
684
+
685
+ ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,
686
+ "client login failed: \"%V\"", &ctx->errmsg);
687
+
688
+ if (s->protocol == NGX_MAIL_SMTP_PROTOCOL) {
689
+
690
+ if (ctx->errcode.len == 0) {
691
+ ctx->errcode = ngx_mail_smtp_errcode;
692
+ }
693
+
694
+ ctx->err.len = ctx->errcode.len + ctx->errmsg.len
695
+ + sizeof(" " CRLF) - 1;
696
+
697
+ p = ngx_pnalloc(s->connection->pool, ctx->err.len);
698
+ if (p == NULL) {
699
+ ngx_close_connection(ctx->peer.connection);
700
+ ngx_destroy_pool(ctx->pool);
701
+ ngx_mail_session_internal_server_error(s);
702
+ return;
703
+ }
704
+
705
+ ctx->err.data = p;
706
+
707
+ p = ngx_cpymem(p, ctx->errcode.data, ctx->errcode.len);
708
+ *p++ = ' ';
709
+ p = ngx_cpymem(p, ctx->errmsg.data, ctx->errmsg.len);
710
+ *p++ = CR; *p = LF;
711
+ }
712
+
713
+ s->out = ctx->err;
714
+ timer = ctx->sleep;
715
+
716
+ ngx_destroy_pool(ctx->pool);
717
+
718
+ if (timer == 0) {
719
+ s->quit = 1;
720
+ ngx_mail_send(s->connection->write);
721
+ return;
722
+ }
723
+
724
+ ngx_add_timer(s->connection->read, (ngx_msec_t) (timer * 1000));
725
+
726
+ s->connection->read->handler = ngx_mail_auth_sleep_handler;
727
+
728
+ return;
729
+ }
730
+
731
+ if (s->auth_wait) {
732
+ timer = ctx->sleep;
733
+
734
+ ngx_destroy_pool(ctx->pool);
735
+
736
+ if (timer == 0) {
737
+ ngx_mail_auth_http_init(s);
738
+ return;
739
+ }
740
+
741
+ ngx_add_timer(s->connection->read, (ngx_msec_t) (timer * 1000));
742
+
743
+ s->connection->read->handler = ngx_mail_auth_sleep_handler;
744
+
745
+ return;
746
+ }
747
+
748
+ if (ctx->addr.len == 0 || ctx->port.len == 0) {
749
+ ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
750
+ "auth http server %V did not send server or port",
751
+ ctx->peer.name);
752
+ ngx_destroy_pool(ctx->pool);
753
+ ngx_mail_session_internal_server_error(s);
754
+ return;
755
+ }
756
+
757
+ if (s->passwd.data == NULL
758
+ && s->protocol != NGX_MAIL_SMTP_PROTOCOL)
759
+ {
760
+ ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
761
+ "auth http server %V did not send password",
762
+ ctx->peer.name);
763
+ ngx_destroy_pool(ctx->pool);
764
+ ngx_mail_session_internal_server_error(s);
765
+ return;
766
+ }
767
+
768
+ peer = ngx_pcalloc(s->connection->pool, sizeof(ngx_addr_t));
769
+ if (peer == NULL) {
770
+ ngx_destroy_pool(ctx->pool);
771
+ ngx_mail_session_internal_server_error(s);
772
+ return;
773
+ }
774
+
775
+ /* AF_INET only */
776
+
777
+ sin = ngx_pcalloc(s->connection->pool, sizeof(struct sockaddr_in));
778
+ if (sin == NULL) {
779
+ ngx_destroy_pool(ctx->pool);
780
+ ngx_mail_session_internal_server_error(s);
781
+ return;
782
+ }
783
+
784
+ sin->sin_family = AF_INET;
785
+
786
+ port = ngx_atoi(ctx->port.data, ctx->port.len);
787
+ if (port == NGX_ERROR || port < 1 || port > 65535) {
788
+ ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
789
+ "auth http server %V sent invalid server "
790
+ "port:\"%V\"",
791
+ ctx->peer.name, &ctx->port);
792
+ ngx_destroy_pool(ctx->pool);
793
+ ngx_mail_session_internal_server_error(s);
794
+ return;
795
+ }
796
+
797
+ sin->sin_port = htons((in_port_t) port);
798
+
799
+ sin->sin_addr.s_addr = ngx_inet_addr(ctx->addr.data, ctx->addr.len);
800
+ if (sin->sin_addr.s_addr == INADDR_NONE) {
801
+ ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
802
+ "auth http server %V sent invalid server "
803
+ "address:\"%V\"",
804
+ ctx->peer.name, &ctx->addr);
805
+ ngx_destroy_pool(ctx->pool);
806
+ ngx_mail_session_internal_server_error(s);
807
+ return;
808
+ }
809
+
810
+ peer->sockaddr = (struct sockaddr *) sin;
811
+ peer->socklen = sizeof(struct sockaddr_in);
812
+
813
+ len = ctx->addr.len + 1 + ctx->port.len;
814
+
815
+ peer->name.len = len;
816
+
817
+ peer->name.data = ngx_pnalloc(s->connection->pool, len);
818
+ if (peer->name.data == NULL) {
819
+ ngx_destroy_pool(ctx->pool);
820
+ ngx_mail_session_internal_server_error(s);
821
+ return;
822
+ }
823
+
824
+ len = ctx->addr.len;
825
+
826
+ ngx_memcpy(peer->name.data, ctx->addr.data, len);
827
+
828
+ peer->name.data[len++] = ':';
829
+
830
+ ngx_memcpy(peer->name.data + len, ctx->port.data, ctx->port.len);
831
+
832
+ ngx_destroy_pool(ctx->pool);
833
+ ngx_mail_proxy_init(s, peer);
834
+
835
+ return;
836
+ }
837
+
838
+ if (rc == NGX_AGAIN ) {
839
+ return;
840
+ }
841
+
842
+ /* rc == NGX_ERROR */
843
+
844
+ ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
845
+ "auth http server %V sent invalid header in response",
846
+ ctx->peer.name);
847
+ ngx_close_connection(ctx->peer.connection);
848
+ ngx_destroy_pool(ctx->pool);
849
+ ngx_mail_session_internal_server_error(s);
850
+
851
+ return;
852
+ }
853
+ }
854
+
855
+
856
+ static void
857
+ ngx_mail_auth_sleep_handler(ngx_event_t *rev)
858
+ {
859
+ ngx_connection_t *c;
860
+ ngx_mail_session_t *s;
861
+ ngx_mail_core_srv_conf_t *cscf;
862
+
863
+ ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, "mail auth sleep handler");
864
+
865
+ c = rev->data;
866
+ s = c->data;
867
+
868
+ if (rev->timedout) {
869
+
870
+ rev->timedout = 0;
871
+
872
+ if (s->auth_wait) {
873
+ s->auth_wait = 0;
874
+ ngx_mail_auth_http_init(s);
875
+ return;
876
+ }
877
+
878
+ cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
879
+
880
+ rev->handler = cscf->protocol->auth_state;
881
+
882
+ s->mail_state = 0;
883
+ s->auth_method = NGX_MAIL_AUTH_PLAIN;
884
+
885
+ c->log->action = "in auth state";
886
+
887
+ ngx_mail_send(c->write);
888
+
889
+ if (c->destroyed) {
890
+ return;
891
+ }
892
+
893
+ ngx_add_timer(rev, cscf->timeout);
894
+
895
+ if (rev->ready) {
896
+ rev->handler(rev);
897
+ return;
898
+ }
899
+
900
+ if (ngx_handle_read_event(rev, 0) != NGX_OK) {
901
+ ngx_mail_close_connection(c);
902
+ }
903
+
904
+ return;
905
+ }
906
+
907
+ if (rev->active) {
908
+ if (ngx_handle_read_event(rev, 0) != NGX_OK) {
909
+ ngx_mail_close_connection(c);
910
+ }
911
+ }
912
+ }
913
+
914
+
915
+ static ngx_int_t
916
+ ngx_mail_auth_http_parse_header_line(ngx_mail_session_t *s,
917
+ ngx_mail_auth_http_ctx_t *ctx)
918
+ {
919
+ u_char c, ch, *p;
920
+ enum {
921
+ sw_start = 0,
922
+ sw_name,
923
+ sw_space_before_value,
924
+ sw_value,
925
+ sw_space_after_value,
926
+ sw_almost_done,
927
+ sw_header_almost_done
928
+ } state;
929
+
930
+ state = ctx->state;
931
+
932
+ for (p = ctx->response->pos; p < ctx->response->last; p++) {
933
+ ch = *p;
934
+
935
+ switch (state) {
936
+
937
+ /* first char */
938
+ case sw_start:
939
+
940
+ switch (ch) {
941
+ case CR:
942
+ ctx->header_end = p;
943
+ state = sw_header_almost_done;
944
+ break;
945
+ case LF:
946
+ ctx->header_end = p;
947
+ goto header_done;
948
+ default:
949
+ state = sw_name;
950
+ ctx->header_name_start = p;
951
+
952
+ c = (u_char) (ch | 0x20);
953
+ if (c >= 'a' && c <= 'z') {
954
+ break;
955
+ }
956
+
957
+ if (ch >= '0' && ch <= '9') {
958
+ break;
959
+ }
960
+
961
+ return NGX_ERROR;
962
+ }
963
+ break;
964
+
965
+ /* header name */
966
+ case sw_name:
967
+ c = (u_char) (ch | 0x20);
968
+ if (c >= 'a' && c <= 'z') {
969
+ break;
970
+ }
971
+
972
+ if (ch == ':') {
973
+ ctx->header_name_end = p;
974
+ state = sw_space_before_value;
975
+ break;
976
+ }
977
+
978
+ if (ch == '-') {
979
+ break;
980
+ }
981
+
982
+ if (ch >= '0' && ch <= '9') {
983
+ break;
984
+ }
985
+
986
+ if (ch == CR) {
987
+ ctx->header_name_end = p;
988
+ ctx->header_start = p;
989
+ ctx->header_end = p;
990
+ state = sw_almost_done;
991
+ break;
992
+ }
993
+
994
+ if (ch == LF) {
995
+ ctx->header_name_end = p;
996
+ ctx->header_start = p;
997
+ ctx->header_end = p;
998
+ goto done;
999
+ }
1000
+
1001
+ return NGX_ERROR;
1002
+
1003
+ /* space* before header value */
1004
+ case sw_space_before_value:
1005
+ switch (ch) {
1006
+ case ' ':
1007
+ break;
1008
+ case CR:
1009
+ ctx->header_start = p;
1010
+ ctx->header_end = p;
1011
+ state = sw_almost_done;
1012
+ break;
1013
+ case LF:
1014
+ ctx->header_start = p;
1015
+ ctx->header_end = p;
1016
+ goto done;
1017
+ default:
1018
+ ctx->header_start = p;
1019
+ state = sw_value;
1020
+ break;
1021
+ }
1022
+ break;
1023
+
1024
+ /* header value */
1025
+ case sw_value:
1026
+ switch (ch) {
1027
+ case ' ':
1028
+ ctx->header_end = p;
1029
+ state = sw_space_after_value;
1030
+ break;
1031
+ case CR:
1032
+ ctx->header_end = p;
1033
+ state = sw_almost_done;
1034
+ break;
1035
+ case LF:
1036
+ ctx->header_end = p;
1037
+ goto done;
1038
+ }
1039
+ break;
1040
+
1041
+ /* space* before end of header line */
1042
+ case sw_space_after_value:
1043
+ switch (ch) {
1044
+ case ' ':
1045
+ break;
1046
+ case CR:
1047
+ state = sw_almost_done;
1048
+ break;
1049
+ case LF:
1050
+ goto done;
1051
+ default:
1052
+ state = sw_value;
1053
+ break;
1054
+ }
1055
+ break;
1056
+
1057
+ /* end of header line */
1058
+ case sw_almost_done:
1059
+ switch (ch) {
1060
+ case LF:
1061
+ goto done;
1062
+ default:
1063
+ return NGX_ERROR;
1064
+ }
1065
+
1066
+ /* end of header */
1067
+ case sw_header_almost_done:
1068
+ switch (ch) {
1069
+ case LF:
1070
+ goto header_done;
1071
+ default:
1072
+ return NGX_ERROR;
1073
+ }
1074
+ }
1075
+ }
1076
+
1077
+ ctx->response->pos = p;
1078
+ ctx->state = state;
1079
+
1080
+ return NGX_AGAIN;
1081
+
1082
+ done:
1083
+
1084
+ ctx->response->pos = p + 1;
1085
+ ctx->state = sw_start;
1086
+
1087
+ return NGX_OK;
1088
+
1089
+ header_done:
1090
+
1091
+ ctx->response->pos = p + 1;
1092
+ ctx->state = sw_start;
1093
+
1094
+ return NGX_DONE;
1095
+ }
1096
+
1097
+
1098
+ static void
1099
+ ngx_mail_auth_http_block_read(ngx_event_t *rev)
1100
+ {
1101
+ ngx_connection_t *c;
1102
+ ngx_mail_session_t *s;
1103
+ ngx_mail_auth_http_ctx_t *ctx;
1104
+
1105
+ ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0,
1106
+ "mail auth http block read");
1107
+
1108
+ if (ngx_handle_read_event(rev, 0) != NGX_OK) {
1109
+ c = rev->data;
1110
+ s = c->data;
1111
+
1112
+ ctx = ngx_mail_get_module_ctx(s, ngx_mail_auth_http_module);
1113
+
1114
+ ngx_close_connection(ctx->peer.connection);
1115
+ ngx_destroy_pool(ctx->pool);
1116
+ ngx_mail_session_internal_server_error(s);
1117
+ }
1118
+ }
1119
+
1120
+
1121
+ static void
1122
+ ngx_mail_auth_http_dummy_handler(ngx_event_t *ev)
1123
+ {
1124
+ ngx_log_debug0(NGX_LOG_DEBUG_MAIL, ev->log, 0,
1125
+ "mail auth http dummy handler");
1126
+ }
1127
+
1128
+
1129
+ static ngx_buf_t *
1130
+ ngx_mail_auth_http_create_request(ngx_mail_session_t *s, ngx_pool_t *pool,
1131
+ ngx_mail_auth_http_conf_t *ahcf)
1132
+ {
1133
+ size_t len;
1134
+ ngx_buf_t *b;
1135
+ ngx_str_t login, passwd;
1136
+ ngx_mail_core_srv_conf_t *cscf;
1137
+
1138
+ if (ngx_mail_auth_http_escape(pool, &s->login, &login) != NGX_OK) {
1139
+ return NULL;
1140
+ }
1141
+
1142
+ if (ngx_mail_auth_http_escape(pool, &s->passwd, &passwd) != NGX_OK) {
1143
+ return NULL;
1144
+ }
1145
+
1146
+ cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
1147
+
1148
+ len = sizeof("GET ") - 1 + ahcf->uri.len + sizeof(" HTTP/1.0" CRLF) - 1
1149
+ + sizeof("Host: ") - 1 + ahcf->host_header.len + sizeof(CRLF) - 1
1150
+ + sizeof("Auth-Method: ") - 1
1151
+ + ngx_mail_auth_http_method[s->auth_method].len
1152
+ + sizeof(CRLF) - 1
1153
+ + sizeof("Auth-User: ") - 1 + login.len + sizeof(CRLF) - 1
1154
+ + sizeof("Auth-Pass: ") - 1 + passwd.len + sizeof(CRLF) - 1
1155
+ + sizeof("Auth-Salt: ") - 1 + s->salt.len
1156
+ + sizeof("Auth-Protocol: ") - 1 + cscf->protocol->name.len
1157
+ + sizeof(CRLF) - 1
1158
+ + sizeof("Auth-Login-Attempt: ") - 1 + NGX_INT_T_LEN
1159
+ + sizeof(CRLF) - 1
1160
+ + sizeof("Client-IP: ") - 1 + s->connection->addr_text.len
1161
+ + sizeof(CRLF) - 1
1162
+ + sizeof("Client-Host: ") - 1 + s->host.len + sizeof(CRLF) - 1
1163
+ + sizeof("Auth-SMTP-Helo: ") - 1 + s->smtp_helo.len
1164
+ + sizeof("Auth-SMTP-From: ") - 1 + s->smtp_from.len
1165
+ + sizeof("Auth-SMTP-To: ") - 1 + s->smtp_to.len
1166
+ + ahcf->header.len
1167
+ + sizeof(CRLF) - 1;
1168
+
1169
+ b = ngx_create_temp_buf(pool, len);
1170
+ if (b == NULL) {
1171
+ return NULL;
1172
+ }
1173
+
1174
+ b->last = ngx_cpymem(b->last, "GET ", sizeof("GET ") - 1);
1175
+ b->last = ngx_copy(b->last, ahcf->uri.data, ahcf->uri.len);
1176
+ b->last = ngx_cpymem(b->last, " HTTP/1.0" CRLF,
1177
+ sizeof(" HTTP/1.0" CRLF) - 1);
1178
+
1179
+ b->last = ngx_cpymem(b->last, "Host: ", sizeof("Host: ") - 1);
1180
+ b->last = ngx_copy(b->last, ahcf->host_header.data,
1181
+ ahcf->host_header.len);
1182
+ *b->last++ = CR; *b->last++ = LF;
1183
+
1184
+ b->last = ngx_cpymem(b->last, "Auth-Method: ",
1185
+ sizeof("Auth-Method: ") - 1);
1186
+ b->last = ngx_cpymem(b->last,
1187
+ ngx_mail_auth_http_method[s->auth_method].data,
1188
+ ngx_mail_auth_http_method[s->auth_method].len);
1189
+ *b->last++ = CR; *b->last++ = LF;
1190
+
1191
+ b->last = ngx_cpymem(b->last, "Auth-User: ", sizeof("Auth-User: ") - 1);
1192
+ b->last = ngx_copy(b->last, login.data, login.len);
1193
+ *b->last++ = CR; *b->last++ = LF;
1194
+
1195
+ b->last = ngx_cpymem(b->last, "Auth-Pass: ", sizeof("Auth-Pass: ") - 1);
1196
+ b->last = ngx_copy(b->last, passwd.data, passwd.len);
1197
+ *b->last++ = CR; *b->last++ = LF;
1198
+
1199
+ if (s->auth_method != NGX_MAIL_AUTH_PLAIN && s->salt.len) {
1200
+ b->last = ngx_cpymem(b->last, "Auth-Salt: ", sizeof("Auth-Salt: ") - 1);
1201
+ b->last = ngx_copy(b->last, s->salt.data, s->salt.len);
1202
+
1203
+ s->passwd.data = NULL;
1204
+ }
1205
+
1206
+ b->last = ngx_cpymem(b->last, "Auth-Protocol: ",
1207
+ sizeof("Auth-Protocol: ") - 1);
1208
+ b->last = ngx_cpymem(b->last, cscf->protocol->name.data,
1209
+ cscf->protocol->name.len);
1210
+ *b->last++ = CR; *b->last++ = LF;
1211
+
1212
+ b->last = ngx_sprintf(b->last, "Auth-Login-Attempt: %ui" CRLF,
1213
+ s->login_attempt);
1214
+
1215
+ b->last = ngx_cpymem(b->last, "Client-IP: ", sizeof("Client-IP: ") - 1);
1216
+ b->last = ngx_copy(b->last, s->connection->addr_text.data,
1217
+ s->connection->addr_text.len);
1218
+ *b->last++ = CR; *b->last++ = LF;
1219
+
1220
+ if (s->host.len) {
1221
+ b->last = ngx_cpymem(b->last, "Client-Host: ",
1222
+ sizeof("Client-Host: ") - 1);
1223
+ b->last = ngx_copy(b->last, s->host.data, s->host.len);
1224
+ *b->last++ = CR; *b->last++ = LF;
1225
+ }
1226
+
1227
+ if (s->auth_method == NGX_MAIL_AUTH_NONE) {
1228
+
1229
+ /* HELO, MAIL FROM, and RCPT TO can't contain CRLF, no need to escape */
1230
+
1231
+ b->last = ngx_cpymem(b->last, "Auth-SMTP-Helo: ",
1232
+ sizeof("Auth-SMTP-Helo: ") - 1);
1233
+ b->last = ngx_copy(b->last, s->smtp_helo.data, s->smtp_helo.len);
1234
+ *b->last++ = CR; *b->last++ = LF;
1235
+
1236
+ b->last = ngx_cpymem(b->last, "Auth-SMTP-From: ",
1237
+ sizeof("Auth-SMTP-From: ") - 1);
1238
+ b->last = ngx_copy(b->last, s->smtp_from.data, s->smtp_from.len);
1239
+ *b->last++ = CR; *b->last++ = LF;
1240
+
1241
+ b->last = ngx_cpymem(b->last, "Auth-SMTP-To: ",
1242
+ sizeof("Auth-SMTP-To: ") - 1);
1243
+ b->last = ngx_copy(b->last, s->smtp_to.data, s->smtp_to.len);
1244
+ *b->last++ = CR; *b->last++ = LF;
1245
+
1246
+ }
1247
+
1248
+ if (ahcf->header.len) {
1249
+ b->last = ngx_copy(b->last, ahcf->header.data, ahcf->header.len);
1250
+ }
1251
+
1252
+ /* add "\r\n" at the header end */
1253
+ *b->last++ = CR; *b->last++ = LF;
1254
+
1255
+ #if (NGX_DEBUG_MAIL_PASSWD)
1256
+ {
1257
+ ngx_str_t l;
1258
+
1259
+ l.len = b->last - b->pos;
1260
+ l.data = b->pos;
1261
+ ngx_log_debug1(NGX_LOG_DEBUG_MAIL, s->connection->log, 0,
1262
+ "mail auth http header:\n\"%V\"", &l);
1263
+ }
1264
+ #endif
1265
+
1266
+ return b;
1267
+ }
1268
+
1269
+
1270
+ static ngx_int_t
1271
+ ngx_mail_auth_http_escape(ngx_pool_t *pool, ngx_str_t *text, ngx_str_t *escaped)
1272
+ {
1273
+ u_char *p;
1274
+ uintptr_t n;
1275
+
1276
+ n = ngx_escape_uri(NULL, text->data, text->len, NGX_ESCAPE_MAIL_AUTH);
1277
+
1278
+ if (n == 0) {
1279
+ *escaped = *text;
1280
+ return NGX_OK;
1281
+ }
1282
+
1283
+ escaped->len = text->len + n * 2;
1284
+
1285
+ p = ngx_pnalloc(pool, escaped->len);
1286
+ if (p == NULL) {
1287
+ return NGX_ERROR;
1288
+ }
1289
+
1290
+ (void) ngx_escape_uri(p, text->data, text->len, NGX_ESCAPE_MAIL_AUTH);
1291
+
1292
+ escaped->data = p;
1293
+
1294
+ return NGX_OK;
1295
+ }
1296
+
1297
+
1298
+ static void *
1299
+ ngx_mail_auth_http_create_conf(ngx_conf_t *cf)
1300
+ {
1301
+ ngx_mail_auth_http_conf_t *ahcf;
1302
+
1303
+ ahcf = ngx_pcalloc(cf->pool, sizeof(ngx_mail_auth_http_conf_t));
1304
+ if (ahcf == NULL) {
1305
+ return NULL;
1306
+ }
1307
+
1308
+ ahcf->timeout = NGX_CONF_UNSET_MSEC;
1309
+
1310
+ ahcf->file = cf->conf_file->file.name.data;
1311
+ ahcf->line = cf->conf_file->line;
1312
+
1313
+ return ahcf;
1314
+ }
1315
+
1316
+
1317
+ static char *
1318
+ ngx_mail_auth_http_merge_conf(ngx_conf_t *cf, void *parent, void *child)
1319
+ {
1320
+ ngx_mail_auth_http_conf_t *prev = parent;
1321
+ ngx_mail_auth_http_conf_t *conf = child;
1322
+
1323
+ u_char *p;
1324
+ size_t len;
1325
+ ngx_uint_t i;
1326
+ ngx_table_elt_t *header;
1327
+
1328
+ if (conf->peer == NULL) {
1329
+ conf->peer = prev->peer;
1330
+ conf->host_header = prev->host_header;
1331
+ conf->uri = prev->uri;
1332
+
1333
+ if (conf->peer == NULL) {
1334
+ ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
1335
+ "no \"http_auth\" is defined for server in %s:%ui",
1336
+ conf->file, conf->line);
1337
+
1338
+ return NGX_CONF_ERROR;
1339
+ }
1340
+ }
1341
+
1342
+ ngx_conf_merge_msec_value(conf->timeout, prev->timeout, 60000);
1343
+
1344
+ if (conf->headers == NULL) {
1345
+ conf->headers = prev->headers;
1346
+ conf->header = prev->header;
1347
+ }
1348
+
1349
+ if (conf->headers && conf->header.len == 0) {
1350
+ len = 0;
1351
+ header = conf->headers->elts;
1352
+ for (i = 0; i < conf->headers->nelts; i++) {
1353
+ len += header[i].key.len + 2 + header[i].value.len + 2;
1354
+ }
1355
+
1356
+ p = ngx_pnalloc(cf->pool, len);
1357
+ if (p == NULL) {
1358
+ return NGX_CONF_ERROR;
1359
+ }
1360
+
1361
+ conf->header.len = len;
1362
+ conf->header.data = p;
1363
+
1364
+ for (i = 0; i < conf->headers->nelts; i++) {
1365
+ p = ngx_cpymem(p, header[i].key.data, header[i].key.len);
1366
+ *p++ = ':'; *p++ = ' ';
1367
+ p = ngx_cpymem(p, header[i].value.data, header[i].value.len);
1368
+ *p++ = CR; *p++ = LF;
1369
+ }
1370
+ }
1371
+
1372
+ return NGX_CONF_OK;
1373
+ }
1374
+
1375
+
1376
+ static char *
1377
+ ngx_mail_auth_http(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
1378
+ {
1379
+ ngx_mail_auth_http_conf_t *ahcf = conf;
1380
+
1381
+ ngx_str_t *value;
1382
+ ngx_url_t u;
1383
+
1384
+ value = cf->args->elts;
1385
+
1386
+ ngx_memzero(&u, sizeof(ngx_url_t));
1387
+
1388
+ u.url = value[1];
1389
+ u.default_port = 80;
1390
+ u.uri_part = 1;
1391
+ u.one_addr = 1;
1392
+
1393
+ if (ngx_strncmp(u.url.data, "http://", 7) == 0) {
1394
+ u.url.len -= 7;
1395
+ u.url.data += 7;
1396
+ }
1397
+
1398
+ if (ngx_parse_url(cf->pool, &u) != NGX_OK) {
1399
+ if (u.err) {
1400
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1401
+ "%s in auth_http \"%V\"", u.err, &u.url);
1402
+ }
1403
+
1404
+ return NGX_CONF_ERROR;
1405
+ }
1406
+
1407
+ ahcf->peer = u.addrs;
1408
+
1409
+ if (u.family != AF_UNIX) {
1410
+ ahcf->host_header = u.host;
1411
+
1412
+ } else {
1413
+ ngx_str_set(&ahcf->host_header, "localhost");
1414
+ }
1415
+
1416
+ ahcf->uri = u.uri;
1417
+
1418
+ if (ahcf->uri.len == 0) {
1419
+ ngx_str_set(&ahcf->uri, "/");
1420
+ }
1421
+
1422
+ return NGX_CONF_OK;
1423
+ }
1424
+
1425
+
1426
+ static char *
1427
+ ngx_mail_auth_http_header(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
1428
+ {
1429
+ ngx_mail_auth_http_conf_t *ahcf = conf;
1430
+
1431
+ ngx_str_t *value;
1432
+ ngx_table_elt_t *header;
1433
+
1434
+ if (ahcf->headers == NULL) {
1435
+ ahcf->headers = ngx_array_create(cf->pool, 1, sizeof(ngx_table_elt_t));
1436
+ if (ahcf->headers == NULL) {
1437
+ return NGX_CONF_ERROR;
1438
+ }
1439
+ }
1440
+
1441
+ header = ngx_array_push(ahcf->headers);
1442
+ if (header == NULL) {
1443
+ return NGX_CONF_ERROR;
1444
+ }
1445
+
1446
+ value = cf->args->elts;
1447
+
1448
+ header->key = value[1];
1449
+ header->value = value[2];
1450
+
1451
+ return NGX_CONF_OK;
1452
+ }