はてなの中の人が作った mod_dosdetector を Vine 3.2 上の Apache 2.0.55 で利用しようと思ったら、
$ make /usr/bin/apxs -c mod_dosdetector.c /usr/bin/libtool --silent --mode=compile gcc -prefer-pic -DAP_HAVE_DESIGNATED_INITIALIZER -DLINUX=2 -D_REENTRANT -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -D_SVID_SOURCE -D_GNU_SOURCE -g -O2 -pthread -I/usr/include/apache2 -I/usr/include/apache2 -I/usr/include/apache2 -I/usr/include -c -o mod_dosdetector.lo mod_dosdetector.c && touch mod_dosdetector.slo In file included from /usr/include/apache2/httpd.h:44, from mod_dosdetector.c:32: /usr/include/apache2/pcreposix.h:26:1: warning: "REG_ICASE" redefined In file included from mod_dosdetector.c:31: /usr/include/regex.h:277:1: warning: this is the location of the previous definition In file included from /usr/include/apache2/httpd.h:44, from mod_dosdetector.c:32: /usr/include/apache2/pcreposix.h:27:1: warning: "REG_NEWLINE" redefined In file included from mod_dosdetector.c:31: /usr/include/regex.h:282:1: warning: this is the location of the previous definition In file included from /usr/include/apache2/httpd.h:44, from mod_dosdetector.c:32: /usr/include/apache2/pcreposix.h:28:1: warning: "REG_NOTBOL" redefined In file included from mod_dosdetector.c:31: /usr/include/regex.h:296:1: warning: this is the location of the previous definition In file included from /usr/include/apache2/httpd.h:44, from mod_dosdetector.c:32: /usr/include/apache2/pcreposix.h:29:1: warning: "REG_NOTEOL" redefined In file included from mod_dosdetector.c:31: /usr/include/regex.h:299:1: warning: this is the location of the previous definition In file included from /usr/include/apache2/httpd.h:44, from mod_dosdetector.c:32: /usr/include/apache2/pcreposix.h:34:1: warning: "REG_EXTENDED" redefined In file included from mod_dosdetector.c:31: /usr/include/regex.h:273:1: warning: this is the location of the previous definition In file included from /usr/include/apache2/httpd.h:44, from mod_dosdetector.c:32: /usr/include/apache2/pcreposix.h:35:1: warning: "REG_NOSUB" redefined In file included from mod_dosdetector.c:31: /usr/include/regex.h:286:1: warning: this is the location of the previous definition In file included from /usr/include/apache2/httpd.h:44, from mod_dosdetector.c:32: /usr/include/apache2/pcreposix.h:41: error: redefinition of `REG_BADBR' /usr/include/regex.h:323: error: `REG_BADBR' previously defined here /usr/include/apache2/pcreposix.h:42: error: redefinition of `REG_BADPAT' /usr/include/regex.h:315: error: `REG_BADPAT' previously defined here /usr/include/apache2/pcreposix.h:43: error: redefinition of `REG_BADRPT' /usr/include/regex.h:326: error: `REG_BADRPT' previously defined here /usr/include/apache2/pcreposix.h:44: error: redefinition of `REG_EBRACE' /usr/include/regex.h:322: error: `REG_EBRACE' previously defined here /usr/include/apache2/pcreposix.h:45: error: redefinition of `REG_EBRACK' /usr/include/regex.h:320: error: `REG_EBRACK' previously defined here /usr/include/apache2/pcreposix.h:46: error: redefinition of `REG_ECOLLATE' /usr/include/regex.h:316: error: `REG_ECOLLATE' previously defined here /usr/include/apache2/pcreposix.h:47: error: redefinition of `REG_ECTYPE' /usr/include/regex.h:317: error: `REG_ECTYPE' previously defined here /usr/include/apache2/pcreposix.h:48: error: redefinition of `REG_EESCAPE' /usr/include/regex.h:318: error: `REG_EESCAPE' previously defined here /usr/include/apache2/pcreposix.h:50: error: redefinition of `REG_EPAREN' /usr/include/regex.h:321: error: `REG_EPAREN' previously defined here /usr/include/apache2/pcreposix.h:51: error: redefinition of `REG_ERANGE' /usr/include/regex.h:324: error: `REG_ERANGE' previously defined here /usr/include/apache2/pcreposix.h:52: error: redefinition of `REG_ESIZE' /usr/include/regex.h:330: error: `REG_ESIZE' previously defined here /usr/include/apache2/pcreposix.h:53: error: redefinition of `REG_ESPACE' /usr/include/regex.h:325: error: `REG_ESPACE' previously defined here /usr/include/apache2/pcreposix.h:54: error: redefinition of `REG_ESUBREG' /usr/include/regex.h:319: error: `REG_ESUBREG' previously defined here /usr/include/apache2/pcreposix.h:57: error: redefinition of `REG_NOMATCH' /usr/include/regex.h:311: error: `REG_NOMATCH' previously defined here /usr/include/apache2/pcreposix.h:66: error: conflicting types for `regex_t' /usr/include/regex.h:412: error: previous declaration of `regex_t' /usr/include/apache2/pcreposix.h:70: warning: redefinition of `regoff_t' /usr/include/regex.h:415: warning: `regoff_t' previously declared here /usr/include/apache2/pcreposix.h:75: error: conflicting types for `regmatch_t' /usr/include/regex.h:443: error: previous declaration of `regmatch_t' /usr/include/apache2/pcreposix.h:79: error: conflicting types for `regcomp' /usr/include/regex.h:558: error: previous declaration of `regcomp' /usr/include/apache2/pcreposix.h:80: error: conflicting types for `regexec' /usr/include/regex.h:562: error: previous declaration of `regexec' /usr/include/apache2/pcreposix.h:81: error: conflicting types for `regerror' /usr/include/regex.h:567: error: previous declaration of `regerror' /usr/include/apache2/pcreposix.h:82: error: conflicting types for `regfree' /usr/include/regex.h:570: error: previous declaration of `regfree' mod_dosdetector.c: In function `dosdetector_handler': mod_dosdetector.c:264: error: `ap_regmatch_t' undeclared (first use in this function) mod_dosdetector.c:264: error: (Each undeclared identifier is reported only once mod_dosdetector.c:264: error: for each function it appears in.) mod_dosdetector.c:264: error: syntax error before "regmatch" mod_dosdetector.c:265: error: `ap_regex_t' undeclared (first use in this function) mod_dosdetector.c:265: error: `contenttype_regexp' undeclared (first use in this function) mod_dosdetector.c:265: error: syntax error before ')' token mod_dosdetector.c:267: error: `regmatch' undeclared (first use in this function) apxs:Error: Command failed with rc=65536 . make: *** [mod_dosdetector.so] エラー 1
とステキな量のエラーが出てしまったので諦めていたのですが、今日検索したら、mizzy.org : mod_dosdetector を Apache 2.0 系で動かすパッチ というぐれぇとなパッチが提供されていたので、早速テスト。
$ patch < mod_dosdetector.patch (Stripping trailing CRs from patch.) patching file mod_dosdetector.c Hunk #1 FAILED at 28. Hunk #2 FAILED at 40. Hunk #3 succeeded at 351 with fuzz 2 (offset 249 lines). Hunk #4 FAILED at 593. patch unexpectedly ends in middle of line Hunk #5 FAILED at 722. 4 out of 5 hunks FAILED -- saving rejects to file mod_dosdetector.c.rej[/code] orz 仕方ないので手パッチを行い、インストール。 [code]$ make /usr/bin/apxs -c mod_dosdetector.c /usr/bin/libtool --silent --mode=compile gcc -prefer-pic -DAP_HAVE_DESIGNATED_INITIALIZER -DLINUX=2 -D_REENTRANT -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -D_SVID_SOURCE -D_GNU_SOURCE -g -O2 -pthread -I/usr/include/apache2 -I/usr/include/apache2 -I/usr/include/apache2 -I/usr/include -c -o mod_dosdetector.lo mod_dosdetector.c && touch mod_dosdetector.slo /usr/bin/libtool --silent --mode=link gcc -o mod_dosdetector.la -rpath /usr/lib/apache2/modules -module -avoid-version mod_dosdetector.lo $ su Password: # make install /usr/bin/apxs -c mod_dosdetector.c /usr/bin/libtool --silent --mode=compile gcc -prefer-pic -DAP_HAVE_DESIGNATED_INITIALIZER -DLINUX=2 -D_REENTRANT -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -D_SVID_SOURCE -D_GNU_SOURCE -g -O2 -pthread -I/usr/include/apache2 -I/usr/include/apache2 -I/usr/include/apache2 -I/usr/include -c -o mod_dosdetector.lo mod_dosdetector.c && touch mod_dosdetector.slo /usr/bin/libtool --silent --mode=link gcc -o mod_dosdetector.la -rpath /usr/lib/apache2/modules -module -avoid-version mod_dosdetector.lo /usr/bin/apxs -c -i -a -n 'dosdetector' mod_dosdetector.c /usr/bin/libtool --silent --mode=compile gcc -prefer-pic -DAP_HAVE_DESIGNATED_INITIALIZER -DLINUX=2 -D_REENTRANT -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -D_SVID_SOURCE -D_GNU_SOURCE -g -O2 -pthread -I/usr/include/apache2 -I/usr/include/apache2 -I/usr/include/apache2 -I/usr/include -c -o mod_dosdetector.lo mod_dosdetector.c && touch mod_dosdetector.slo /usr/bin/libtool --silent --mode=link gcc -o mod_dosdetector.la -rpath /usr/lib/apache2/modules -module -avoid-version mod_dosdetector.lo /etc/apache2/build/instdso.sh SH_LIBTOOL='/usr/bin/libtool' mod_dosdetector.la /usr/lib/apache2/modules /usr/bin/libtool --mode=install cp mod_dosdetector.la /usr/lib/apache2/modules/ cp .libs/mod_dosdetector.so /usr/lib/apache2/modules/mod_dosdetector.so cp .libs/mod_dosdetector.lai /usr/lib/apache2/modules/mod_dosdetector.la cp .libs/mod_dosdetector.a /usr/lib/apache2/modules/mod_dosdetector.a ranlib /usr/lib/apache2/modules/mod_dosdetector.a chmod 644 /usr/lib/apache2/modules/mod_dosdetector.a PATH="$PATH:/sbin" ldconfig -n /usr/lib/apache2/modules ---------------------------------------------------------------------- Libraries have been installed in: /usr/lib/apache2/modules If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the `-LLIBDIR' flag during linking and do at least one of the following: - add LIBDIR to the `LD_LIBRARY_PATH' environment variable during execution - add LIBDIR to the `LD_RUN_PATH' environment variable during linking - use the `-Wl,--rpath -Wl,LIBDIR' linker flag - have your system administrator add LIBDIR to `/etc/ld.so.conf' See any operating system documentation about shared libraries for more information, such as the ld(1) and ld.so(8) manual pages. ---------------------------------------------------------------------- chmod 755 /usr/lib/apache2/modules/mod_dosdetector.so [activating module `dosdetector' in /etc/apache2/conf/apache2.conf] [/code] とりあえずインストール完了まではこぎ着けました。あとは設定を詰めてテストしよう。 <h4>パッチ内容</h4> 手パッチしたのを diff した結果。Makefile も書き換え必要だったので一緒に。 [code] $ diff -u Makefile.org Makefile --- Makefile.org 2007-09-19 10:53:39.000000000 +0900 +++ Makefile 2007-09-19 10:53:45.000000000 +0900 @@ -4,7 +4,7 @@ ## # the used tools -APXS=/usr/sbin/apxs +APXS=/usr/bin/apxs APACHECTL=apachectl # additional user defines, includes and libraries
$ diff -u mod_dosdetector.c.org mod_dosdetector.c --- mod_dosdetector.c.org 2007-09-19 10:53:15.000000000 +0900 +++ mod_dosdetector.c 2007-09-19 10:53:31.000000000 +0900 @@ -28,7 +28,6 @@ #include <arpa/inet.h> //#include <netinet/in.h> #include <time.h> -#include <regex.h> #include "httpd.h" #include "http_config.h" #include "http_request.h" @@ -41,6 +40,7 @@ #include "apr_strings.h" #include "apr_shm.h" #include "apr_thread_mutex.h" +#include "apr_version.h" //#define _DEBUG @@ -102,6 +102,90 @@ static apr_global_mutex_t *lock = NULL; static apr_shm_t *shm = NULL; +/* apr version 0.x not support apr_shm_remove, I have to copy it from apr version 1.x */ +#if (APR_MAJOR_VERSION < 1) +#ifdef HAVE_SYS_MMAN_H +#include <sys/mman.h> +#endif +#ifdef HAVE_SYS_IPC_H +#include <sys/ipc.h> +#endif +#ifdef HAVE_SYS_MUTEX_H +#include <sys/mutex.h> +#endif +#ifdef HAVE_SYS_SHM_H +#include <sys/shm.h> +#endif +#if !defined(SHM_R) +#define SHM_R 0400 +#endif +#if !defined(SHM_W) +#define SHM_W 0200 +#endif +#ifdef HAVE_SYS_FILE_H +#include <sys/file.h> +#endif + +static apr_status_t apr_shm_remove(const char *filename, apr_pool_t * pool) +{ +#if APR_USE_SHMEM_SHMGET + apr_status_t status; + apr_file_t *file; + key_t shmkey; + int shmid; +#endif + +#if APR_USE_SHMEM_MMAP_TMP + return apr_file_remove(filename, pool); +#endif +#if APR_USE_SHMEM_MMAP_SHM + if (shm_unlink(filename) == -1) { + return errno; + } + return APR_SUCCESS; +#endif +#if APR_USE_SHMEM_SHMGET + /* Presume that the file already exists; just open for writing */ + status = apr_file_open(&file, filename, APR_WRITE, + APR_OS_DEFAULT, pool); + if (status) { + return status; + } + + /* ftok() (on solaris at least) requires that the file actually + * exist before calling ftok(). */ + shmkey = ftok(filename, 1); + if (shmkey == (key_t) - 1) { + goto shm_remove_failed; + } + + apr_file_close(file); + + if ((shmid = shmget(shmkey, 0, SHM_R | SHM_W)) < 0) { + goto shm_remove_failed; + } + + /* Indicate that the segment is to be destroyed as soon + * as all processes have detached. This also disallows any + * new attachments to the segment. */ + if (shmctl(shmid, IPC_RMID, NULL) == -1) { + goto shm_remove_failed; + } + return apr_file_remove(filename, pool); + + shm_remove_failed: + status = errno; + /* ensure the file has been removed anyway. */ + apr_file_remove(filename, pool); + return status; +#endif + + /* No support for anonymous shm */ + return APR_ENOTIMPL; +} +#endif /* APR_MAJOR_VERSION<1 */ + + static apr_status_t cleanup_shm(void *not_used) { @@ -261,8 +345,9 @@ address = r->connection->remote_ip; - ap_regmatch_t regmatch[AP_MAX_REG_MATCH]; - ap_regex_t **contenttype_regexp = (ap_regex_t **) cfg->contenttype_regexp->elts; + regmatch_t regmatch[AP_MAX_REG_MATCH]; + regex_t **contenttype_regexp = (regex_t **) cfg->contenttype_regexp->elts; + for (i = 0; i < cfg->contenttype_regexp->nelts; i++) { if(!ap_regexec(contenttype_regexp[i], content_type, AP_MAX_REG_MATCH, regmatch, 0)){ //ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, 0, "ignoring content-type: %s", content_type); @@ -390,14 +475,12 @@ const char *arg) { dosdetector_dir_config *cfg = (dosdetector_dir_config *) mconfig; - char **ignore_contenttype = (char **) cfg->ignore_contenttype->elts; - - *(char **) apr_array_push(cfg->ignore_contenttype) = apr_pstrdup(parms->pool, arg); - - int i; regex_t *regexp; - for (i = 0; i < cfg->ignore_contenttype->nelts; i++) { - regexp = (regex_t *)ap_pregcomp(parms->pool, (char *)ignore_contenttype[i], REG_EXTENDED|REG_ICASE); + char *type; + + while (*arg) { + type = ap_getword_conf(parms->pool, &arg); + regexp = ap_pregcomp(parms->pool, type, REG_EXTENDED|REG_ICASE); *(regex_t **)apr_array_push(cfg->contenttype_regexp) = regexp; }
あれ? でも内容一緒だな。パッチの当て方ミスってたのかなorz
設定の仕方がわからない
どうにも設定のコツがわからないので、作者手ずからの説明が書かれているという Software Design 2007年 09月号 を注文。Apache モジュールの使い方特集らしいので、役に立ちそう。
Software Design (ソフトウエア デザイン) 2007年 09月号 [雑誌] | |
技術評論社 2007-08-18 売り上げランキング : by G-Tools |
コメント