ADD-SP / ngx_waf

Handy, High performance, ModSecurity compatible Nginx firewall module & 方便、高性能、兼容 ModSecurity 的 Nginx 防火墙模块
https://add-sp.github.io/ngx_waf-docs/
BSD 3-Clause "New" or "Revised" License
1.48k stars 187 forks source link

Failure to compile in CentOS/RHEL 7 #41

Closed FlyBirdF closed 3 years ago

FlyBirdF commented 3 years ago

Error

checking for uthash library ... not found
./configure: error: the ngx_http_waf_module module requires the uthash library.

Please run:
    On Ubuntu or Debian: 
            apt-get update && apt-get install --yes uthash-dev
    On Alpine: 
            apk update && apk add uthash-dev
    On other OS:
            cd /usr/local/src \
        &&  git clone https://github.com/troydhanson/uthash.git \
        &&  export LIB_UTHASH=/usr/local/src/uthash \
        &&  cd /usr/local/src/nginx-1.18.0

Run the following commands

I run the following commands when i first saw this error, but noting was changed, the error shows again.

    On other OS:
            cd /usr/local/src \
        &&  git clone https://github.com/troydhanson/uthash.git \
        &&  export LIB_UTHASH=/usr/local/src/uthash \
        &&  cd /usr/local/src/nginx-1.18.0
ADD-SP commented 3 years ago

Make sure the following files exist in /usr/local/src/uthash/include.

utarray.h
uthash.h
utlist.h
utringbuffer.h
utstack.h
utstring.h

If the above file does not exist, please download it.


Make sure the value of $LIB_UTHASH is /usr/local/src/uthash.


Are the access permissions for the /usr/local/src/uthash correct?


Before executing ./configure, the above three conditions need to be met.

FlyBirdF commented 3 years ago

Make sure the following files exist in /usr/local/src/uthash/include.

utarray.h
uthash.h
utlist.h
utringbuffer.h
utstack.h
utstring.h

If the above file does not exist, please download it.

Make sure the value of $LIB_UTHASH is /usr/local/src/uthash.

Are the access permissions for the /usr/local/src/uthash correct?

Before executing ./configure, the above three conditions need to be met.

I have checked the above three needs, seem everything is ok, but when i run "./configure" the same error shows again.

[root@cobbler nginx-1.18.0]# ls /usr/local/src/uthash/include/
utarray.h  uthash.h  utlist.h  utringbuffer.h  utstack.h  utstring.h
[root@cobbler nginx-1.18.0]# echo $LIB_UTHASH
/usr/local/src/uthash
[root@cobbler nginx-1.18.0]# w
 10:53:00 up 25 days, 22:20,  1 user,  load average: 0.00, 0.01, 0.05
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    192.168.13.111   Tue17    4.00s  0.21s  0.08s -bash
[root@cobbler nginx-1.18.0]# getfacl /usr/local/src/uthash/
getfacl: Removing leading '/' from absolute path names
# file: usr/local/src/uthash/
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
ADD-SP commented 3 years ago

Please provide the contents of /usr/local/src/nginx-1.18.0/objs/autoconf.err.

FlyBirdF commented 3 years ago

Here is the autoconf.err file.


----------------------------------------
checking for C compiler

----------------------------------------
checking for gcc -pipe switch

----------------------------------------
checking for --with-ld-opt="-Wl,-z,relro -Wl,-z,now -pie"

----------------------------------------
checking for -Wl,-E switch

----------------------------------------
checking for gcc builtin atomic operations

----------------------------------------
checking for C99 variadic macros

----------------------------------------
checking for gcc variadic macros

----------------------------------------
checking for gcc builtin 64 bit byteswap

----------------------------------------
checking for unistd.h

----------------------------------------
checking for inttypes.h

----------------------------------------
checking for limits.h

----------------------------------------
checking for sys/filio.h

objs/autotest.c:3:10: fatal error: sys/filio.h: No such file or directory
 #include <sys/filio.h>
          ^~~~~~~~~~~~~
compilation terminated.
----------

#include <sys/filio.h>

int main(void) {
    return 0;
}

----------
cc -o objs/autotest objs/autotest.c
----------

----------------------------------------
checking for sys/param.h

----------------------------------------
checking for sys/mount.h

----------------------------------------
checking for sys/statvfs.h

----------------------------------------
checking for crypt.h

----------------------------------------
checking for epoll

----------------------------------------
checking for EPOLLRDHUP

----------------------------------------
checking for EPOLLEXCLUSIVE

objs/autotest.c: In function 'main':
objs/autotest.c:9:43: error: 'EPOLLEXCLUSIVE' undeclared (first use in this function); did you mean 'EPOLL_CLOEXEC'?
                       ee.events = EPOLLIN|EPOLLEXCLUSIVE;
                                           ^~~~~~~~~~~~~~
                                           EPOLL_CLOEXEC
objs/autotest.c:9:43: note: each undeclared identifier is reported only once for each function it appears in
----------

#include <sys/types.h>
#include <unistd.h>
#include <sys/epoll.h>

int main(void) {
    int efd = 0, fd = 0;
                      struct epoll_event ee;
                      ee.events = EPOLLIN|EPOLLEXCLUSIVE;
                      ee.data.ptr = NULL;
                      epoll_ctl(efd, EPOLL_CTL_ADD, fd, &ee);
    return 0;
}

----------
cc -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -o objs/autotest objs/autotest.c -Wl,-z,relro -Wl,-z,now -pie
----------

----------------------------------------
checking for O_PATH

----------------------------------------
checking for sendfile()

----------------------------------------
checking for sendfile64()

----------------------------------------
checking for sys/prctl.h

----------------------------------------
checking for prctl(PR_SET_DUMPABLE)

----------------------------------------
checking for prctl(PR_SET_KEEPCAPS)

----------------------------------------
checking for capabilities

----------------------------------------
checking for crypt_r()

----------------------------------------
checking for sys/vfs.h

----------------------------------------
checking for poll()

----------------------------------------
checking for /dev/poll

objs/autotest.c:4:10: fatal error: sys/devpoll.h: No such file or directory
 #include <sys/devpoll.h>
          ^~~~~~~~~~~~~~~
compilation terminated.
----------

#include <sys/types.h>
#include <unistd.h>
#include <sys/devpoll.h>

int main(void) {
    int  n, dp; struct dvpoll  dvp;
                  dp = 0;
                  dvp.dp_fds = NULL;
                  dvp.dp_nfds = 0;
                  dvp.dp_timeout = 0;
                  n = ioctl(dp, DP_POLL, &dvp);
                  if (n == -1) return 1;
    return 0;
}

----------
cc -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -o objs/autotest objs/autotest.c -Wl,-z,relro -Wl,-z,now -pie
----------

----------------------------------------
checking for kqueue

objs/autotest.c:4:10: fatal error: sys/event.h: No such file or directory
 #include <sys/event.h>
          ^~~~~~~~~~~~~
compilation terminated.
----------

#include <sys/types.h>
#include <unistd.h>
#include <sys/event.h>

int main(void) {
    (void) kqueue();
    return 0;
}

----------
cc -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -o objs/autotest objs/autotest.c -Wl,-z,relro -Wl,-z,now -pie
----------

----------------------------------------
checking for crypt()

/tmp/cckrt9L2.o: In function `main':
/usr/local/src/nginx-1.18.0/objs/autotest.c:7: undefined reference to `crypt'
collect2: error: ld returned 1 exit status
----------

#include <sys/types.h>
#include <unistd.h>

int main(void) {
    crypt("test", "salt");;
    return 0;
}

----------
cc -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -o objs/autotest objs/autotest.c -Wl,-z,relro -Wl,-z,now -pie
----------

----------------------------------------
checking for crypt() in libcrypt

----------------------------------------
checking for F_READAHEAD

objs/autotest.c: In function 'main':
objs/autotest.c:7:14: error: 'F_READAHEAD' undeclared (first use in this function)
     fcntl(0, F_READAHEAD, 1);;
              ^~~~~~~~~~~
objs/autotest.c:7:14: note: each undeclared identifier is reported only once for each function it appears in
----------

#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>

int main(void) {
    fcntl(0, F_READAHEAD, 1);;
    return 0;
}

----------
cc -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -o objs/autotest objs/autotest.c -Wl,-z,relro -Wl,-z,now -pie
----------

----------------------------------------
checking for posix_fadvise()

----------------------------------------
checking for O_DIRECT

----------------------------------------
checking for F_NOCACHE

objs/autotest.c: In function 'main':
objs/autotest.c:7:14: error: 'F_NOCACHE' undeclared (first use in this function)
     fcntl(0, F_NOCACHE, 1);;
              ^~~~~~~~~
objs/autotest.c:7:14: note: each undeclared identifier is reported only once for each function it appears in
----------

#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>

int main(void) {
    fcntl(0, F_NOCACHE, 1);;
    return 0;
}

----------
cc -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -o objs/autotest objs/autotest.c -Wl,-z,relro -Wl,-z,now -pie
----------

----------------------------------------
checking for directio()

objs/autotest.c: In function 'main':
objs/autotest.c:8:5: warning: implicit declaration of function 'directio' [-Wimplicit-function-declaration]
     directio(0, DIRECTIO_ON);;
     ^~~~~~~~
objs/autotest.c:8:17: error: 'DIRECTIO_ON' undeclared (first use in this function)
     directio(0, DIRECTIO_ON);;
                 ^~~~~~~~~~~
objs/autotest.c:8:17: note: each undeclared identifier is reported only once for each function it appears in
----------

#include <sys/types.h>
#include <unistd.h>
#include <sys/types.h>
                  #include <sys/fcntl.h>

int main(void) {
    directio(0, DIRECTIO_ON);;
    return 0;
}

----------
cc -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -o objs/autotest objs/autotest.c -Wl,-z,relro -Wl,-z,now -pie
----------

----------------------------------------
checking for statfs()

----------------------------------------
checking for statvfs()

----------------------------------------
checking for dlopen()

/tmp/ccrXxKdo.o: In function `main':
/usr/local/src/nginx-1.18.0/objs/autotest.c:7: undefined reference to `dlopen'
/usr/local/src/nginx-1.18.0/objs/autotest.c:7: undefined reference to `dlsym'
collect2: error: ld returned 1 exit status
----------

#include <sys/types.h>
#include <unistd.h>
#include <dlfcn.h>

int main(void) {
    dlopen(NULL, RTLD_NOW | RTLD_GLOBAL); dlsym(NULL, "");
    return 0;
}

----------
cc -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -o objs/autotest objs/autotest.c -Wl,-z,relro -Wl,-z,now -pie
----------

----------------------------------------
checking for dlopen() in libdl

----------------------------------------
checking for sched_yield()

----------------------------------------
checking for sched_setaffinity()

----------------------------------------
checking for SO_SETFIB

objs/autotest.c: In function 'main':
objs/autotest.c:7:31: error: 'SO_SETFIB' undeclared (first use in this function)
     setsockopt(0, SOL_SOCKET, SO_SETFIB, NULL, 0);
                               ^~~~~~~~~
objs/autotest.c:7:31: note: each undeclared identifier is reported only once for each function it appears in
----------

#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>

int main(void) {
    setsockopt(0, SOL_SOCKET, SO_SETFIB, NULL, 0);
    return 0;
}

----------
cc -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -o objs/autotest objs/autotest.c -Wl,-z,relro -Wl,-z,now -pie
----------

----------------------------------------
checking for SO_REUSEPORT

----------------------------------------
checking for SO_ACCEPTFILTER

objs/autotest.c: In function 'main':
objs/autotest.c:7:31: error: 'SO_ACCEPTFILTER' undeclared (first use in this function); did you mean 'SO_LOCK_FILTER'?
     setsockopt(0, SOL_SOCKET, SO_ACCEPTFILTER, NULL, 0);
                               ^~~~~~~~~~~~~~~
                               SO_LOCK_FILTER
objs/autotest.c:7:31: note: each undeclared identifier is reported only once for each function it appears in
----------

#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>

int main(void) {
    setsockopt(0, SOL_SOCKET, SO_ACCEPTFILTER, NULL, 0);
    return 0;
}

----------
cc -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -o objs/autotest objs/autotest.c -Wl,-z,relro -Wl,-z,now -pie
----------

----------------------------------------
checking for SO_BINDANY

objs/autotest.c: In function 'main':
objs/autotest.c:7:31: error: 'SO_BINDANY' undeclared (first use in this function); did you mean 'SO_LINGER'?
     setsockopt(0, SOL_SOCKET, SO_BINDANY, NULL, 0);
                               ^~~~~~~~~~
                               SO_LINGER
objs/autotest.c:7:31: note: each undeclared identifier is reported only once for each function it appears in
----------

#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>

int main(void) {
    setsockopt(0, SOL_SOCKET, SO_BINDANY, NULL, 0);
    return 0;
}

----------
cc -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -o objs/autotest objs/autotest.c -Wl,-z,relro -Wl,-z,now -pie
----------

----------------------------------------
checking for IP_TRANSPARENT

----------------------------------------
checking for IP_BINDANY

objs/autotest.c: In function 'main':
objs/autotest.c:8:31: error: 'IP_BINDANY' undeclared (first use in this function); did you mean 'IP_MINTTL'?
     setsockopt(0, IPPROTO_IP, IP_BINDANY, NULL, 0);
                               ^~~~~~~~~~
                               IP_MINTTL
objs/autotest.c:8:31: note: each undeclared identifier is reported only once for each function it appears in
----------

#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>
                  #include <netinet/in.h>

int main(void) {
    setsockopt(0, IPPROTO_IP, IP_BINDANY, NULL, 0);
    return 0;
}

----------
cc -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -o objs/autotest objs/autotest.c -Wl,-z,relro -Wl,-z,now -pie
----------

----------------------------------------
checking for IP_BIND_ADDRESS_NO_PORT

----------------------------------------
checking for IP_RECVDSTADDR

objs/autotest.c: In function 'main':
objs/autotest.c:8:31: error: 'IP_RECVDSTADDR' undeclared (first use in this function); did you mean 'IP_ORIGDSTADDR'?
     setsockopt(0, IPPROTO_IP, IP_RECVDSTADDR, NULL, 0);
                               ^~~~~~~~~~~~~~
                               IP_ORIGDSTADDR
objs/autotest.c:8:31: note: each undeclared identifier is reported only once for each function it appears in
----------

#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>
                  #include <netinet/in.h>

int main(void) {
    setsockopt(0, IPPROTO_IP, IP_RECVDSTADDR, NULL, 0);
    return 0;
}

----------
cc -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -o objs/autotest objs/autotest.c -Wl,-z,relro -Wl,-z,now -pie
----------

----------------------------------------
checking for IP_SENDSRCADDR

objs/autotest.c: In function 'main':
objs/autotest.c:8:31: error: 'IP_SENDSRCADDR' undeclared (first use in this function); did you mean 'IP_ORIGDSTADDR'?
     setsockopt(0, IPPROTO_IP, IP_SENDSRCADDR, NULL, 0);
                               ^~~~~~~~~~~~~~
                               IP_ORIGDSTADDR
objs/autotest.c:8:31: note: each undeclared identifier is reported only once for each function it appears in
----------

#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>
                  #include <netinet/in.h>

int main(void) {
    setsockopt(0, IPPROTO_IP, IP_SENDSRCADDR, NULL, 0);
    return 0;
}

----------
cc -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -o objs/autotest objs/autotest.c -Wl,-z,relro -Wl,-z,now -pie
----------

----------------------------------------
checking for IP_PKTINFO

----------------------------------------
checking for IPV6_RECVPKTINFO

----------------------------------------
checking for TCP_DEFER_ACCEPT

----------------------------------------
checking for TCP_KEEPIDLE

----------------------------------------
checking for TCP_FASTOPEN

----------------------------------------
checking for TCP_INFO

----------------------------------------
checking for accept4()

----------------------------------------
checking for kqueue AIO support

objs/autotest.c: In function 'main':
objs/autotest.c:8:56: error: 'SIGEV_KEVENT' undeclared (first use in this function); did you mean 'SIGEV_THREAD'?
                       iocb.aio_sigevent.sigev_notify = SIGEV_KEVENT;
                                                        ^~~~~~~~~~~~
                                                        SIGEV_THREAD
objs/autotest.c:8:56: note: each undeclared identifier is reported only once for each function it appears in
----------

#include <sys/types.h>
#include <unistd.h>
#include <aio.h>

int main(void) {
    struct aiocb  iocb;
                      iocb.aio_sigevent.sigev_notify = SIGEV_KEVENT;
                      (void) aio_read(&iocb);
    return 0;
}

----------
cc -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -o objs/autotest objs/autotest.c -Wl,-z,relro -Wl,-z,now -pie
----------

----------------------------------------
checking for Linux AIO support

----------------------------------------
checking for int size

----------------------------------------
checking for long size

----------------------------------------
checking for long long size

----------------------------------------
checking for void * size

----------------------------------------
checking for uint32_t

----------------------------------------
checking for uint64_t

----------------------------------------
checking for sig_atomic_t

----------------------------------------
checking for sig_atomic_t size

----------------------------------------
checking for socklen_t

----------------------------------------
checking for in_addr_t

----------------------------------------
checking for in_port_t

----------------------------------------
checking for rlim_t

----------------------------------------
checking for uintptr_t

----------------------------------------
checking for system byte ordering

----------------------------------------
checking for size_t size

----------------------------------------
checking for off_t size

----------------------------------------
checking for time_t size

----------------------------------------
checking for AF_INET6

----------------------------------------
checking for setproctitle()

objs/autotest.c: In function 'main':
objs/autotest.c:7:5: warning: implicit declaration of function 'setproctitle'; did you mean 'setstate'? [-Wimplicit-function-declaration]
     setproctitle("test");;
     ^~~~~~~~~~~~
     setstate
/tmp/ccXxbDFy.o: In function `main':
/usr/local/src/nginx-1.18.0/objs/autotest.c:7: undefined reference to `setproctitle'
collect2: error: ld returned 1 exit status
----------

#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>

int main(void) {
    setproctitle("test");;
    return 0;
}

----------
cc -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -o objs/autotest objs/autotest.c -Wl,-z,relro -Wl,-z,now -pie
----------

----------------------------------------
checking for pread()

----------------------------------------
checking for pwrite()

----------------------------------------
checking for pwritev()

----------------------------------------
checking for sys_nerr

/tmp/ccS1IL0E.o: In function `main':
/usr/local/src/nginx-1.18.0/objs/autotest.c:8: warning: `sys_nerr' is deprecated; use `strerror' or `strerror_r' instead
135
----------------------------------------
checking for localtime_r()

----------------------------------------
checking for clock_gettime(CLOCK_MONOTONIC)

----------------------------------------
checking for posix_memalign()

----------------------------------------
checking for memalign()

----------------------------------------
checking for mmap(MAP_ANON|MAP_SHARED)

----------------------------------------
checking for mmap("/dev/zero", MAP_SHARED)

----------------------------------------
checking for System V shared memory

----------------------------------------
checking for POSIX semaphores

/tmp/cc57Wbma.o: In function `main':
/usr/local/src/nginx-1.18.0/objs/autotest.c:8: undefined reference to `sem_init'
/usr/local/src/nginx-1.18.0/objs/autotest.c:9: undefined reference to `sem_destroy'
collect2: error: ld returned 1 exit status
----------

#include <sys/types.h>
#include <unistd.h>
#include <semaphore.h>

int main(void) {
    sem_t  sem;
                  if (sem_init(&sem, 1, 0) == -1) return 1;
                  sem_destroy(&sem);;
    return 0;
}

----------
cc -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -o objs/autotest objs/autotest.c -Wl,-z,relro -Wl,-z,now -pie
----------

----------------------------------------
checking for POSIX semaphores in libpthread

----------------------------------------
checking for struct msghdr.msg_control

----------------------------------------
checking for ioctl(FIONBIO)

----------------------------------------
checking for ioctl(FIONREAD)

----------------------------------------
checking for struct tm.tm_gmtoff

----------------------------------------
checking for struct dirent.d_namlen

objs/autotest.c: In function 'main':
objs/autotest.c:8:29: error: 'struct dirent' has no member named 'd_namlen'; did you mean 'd_name'?
     struct dirent  dir; dir.d_namlen = 0;
                             ^~~~~~~~
                             d_name
objs/autotest.c:9:42: error: 'struct dirent' has no member named 'd_namlen'; did you mean 'd_name'?
                   printf("%d", (int) dir.d_namlen);
                                          ^~~~~~~~
                                          d_name
objs/autotest.c:8:20: warning: variable 'dir' set but not used [-Wunused-but-set-variable]
     struct dirent  dir; dir.d_namlen = 0;
                    ^~~
----------

#include <sys/types.h>
#include <unistd.h>
#include <dirent.h>
                  #include <stdio.h>

int main(void) {
    struct dirent  dir; dir.d_namlen = 0;
                  printf("%d", (int) dir.d_namlen);
    return 0;
}

----------
cc -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -o objs/autotest objs/autotest.c -Wl,-z,relro -Wl,-z,now -pie
----------

----------------------------------------
checking for struct dirent.d_type

----------------------------------------
checking for sysconf(_SC_NPROCESSORS_ONLN)

----------------------------------------
checking for sysconf(_SC_LEVEL1_DCACHE_LINESIZE)

----------------------------------------
checking for openat(), fstatat()

----------------------------------------
checking for getaddrinfo()

----------------------------------------
checking for uthash library

/opt/rh/devtoolset-8/root/usr/libexec/gcc/x86_64-redhat-linux/8/ld: cannot find -lsodium
collect2: error: ld returned 1 exit status
----------

#include <sys/types.h>
#include <unistd.h>
#include <uthash.h>

int main(void) {
    ;
    return 0;
}

----------
cc -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -o objs/autotest objs/autotest.c -Wl,-z,relro -Wl,-z,now -pie -I /usr/local/src/ngx_waf/inc -fstack-protector -l sodium -I /usr/local/src/uthash/include
----------
ADD-SP commented 3 years ago

There is a bug in the file config of this module, which has been fixed in the branch hotfix-compile, please retry with the code from this branch.

FlyBirdF commented 3 years ago

There is a bug in the file config of this module, which has been fixed in the branch hotfix-compile, please retry with the code from this branch.

Thank you for your help, it works.But it raises another problem when i run the make modules command. There is the error:

[root@cobbler nginx-1.18.0]# make modules
make -f objs/Makefile modules
make[1]: Entering directory `/usr/local/src/nginx-1.18.0'
cc -c -fPIC -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC -I src/core -I src/event -I src/event/modules -I src/os/unix -I /usr/local/src/ngx_waf/inc -I objs -I src/http -I src/http/modules -I src/http/v2 -I src/mail -I src/stream \
    -o objs/addon/src/ngx_http_waf_module_core.o \
    /usr/local/src/ngx_waf/src/ngx_http_waf_module_core.c
In file included from /usr/local/src/ngx_waf/inc/ngx_http_waf_module_check.h:15,
                 from /usr/local/src/ngx_waf/inc/ngx_http_waf_module_core.h:17,
                 from /usr/local/src/ngx_waf/src/ngx_http_waf_module_core.c:1:
/usr/local/src/ngx_waf/inc/ngx_http_waf_module_util.h:12:10: fatal error: sodium.h: No such file or directory
 #include <sodium.h>
          ^~~~~~~~~~
compilation terminated.
make[1]: *** [objs/addon/src/ngx_http_waf_module_core.o] Error 1
make[1]: Leaving directory `/usr/local/src/nginx-1.18.0'
make: *** [modules] Error 2
FlyBirdF commented 3 years ago

And i can find the sodium.h header file at /usr/local/libsodium , the env variables contains LIB_SODIUM="/usr/local/libsodium" and LIB_UTHASH="/usr/local/src/uthash".

ADD-SP commented 3 years ago

Fixed in branch hotfix-compile.

ADD-SP commented 3 years ago

Fixed in v5.3.1.

FlyBirdF commented 3 years ago

Thanks, it works. But it shows a error after i copy the ngx_http_waf_module.so file to my module folder of nginx and run nginx -t command.

Error:

[root@nginx libsodium]# nginx -t
nginx: [emerg] dlopen() "/usr/lib64/nginx/modules/ngx_http_waf_module.so" failed (libsodium.so.23: cannot open shared object file: No such file or directory) in /etc/nginx/nginx.conf:1
nginx: configuration file /etc/nginx/nginx.conf test failed
[root@nginx libsodium]# find / -name libsodium.so.23
/usr/local/src/libsodium/src/libsodium/.libs/libsodium.so.23
/usr/local/libsodium/lib/libsodium.so.23
[root@nginx libsodium]# export
declare -x HISTCONTROL="ignoredups"
declare -x HISTSIZE="1000"
declare -x HOME="/root"
declare -x HOSTNAME="nginx"
declare -x LANG="en_US.UTF-8"
declare -x LESSOPEN="||/usr/bin/lesspipe.sh %s"
declare -x LIB_SODIUM="/usr/local/libsodium"
declare -x LOGNAME="root"
declare -x LS_COLORS="rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:"
declare -x MAIL="/var/spool/mail/root"
declare -x OLDPWD="/usr/local/src"
declare -x PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/libsodium/lib/"
declare -x PWD="/usr/local/src/libsodium"
declare -x SELINUX_LEVEL_REQUESTED=""
declare -x SELINUX_ROLE_REQUESTED=""
declare -x SELINUX_USE_CURRENT_RANGE=""
declare -x SHELL="/bin/bash"
declare -x SHLVL="1"
declare -x SSH_CLIENT="192.168.13.111 12729 222"
declare -x SSH_CONNECTION="192.168.13.111 12729 192.168.18.36 222"
declare -x SSH_TTY="/dev/pts/0"
declare -x TERM="xterm"
declare -x USER="root"
declare -x XDG_RUNTIME_DIR="/run/user/0"
declare -x XDG_SESSION_ID="1014"
ADD-SP commented 3 years ago

Do not change /usr/local/libsodium after compilation, and make sure that the nginx process can read all the contents of this directory. This directory contains the dynamic libraries needed to run the module, and errors will occur if the path or contents change.

ADD-SP commented 3 years ago

Try to run the following command and then retry.

export LD_LIBRARY_PATH=/usr/local/libsodium/lib:$LD_LIBRARY_PATH

It may be a problem with the search path of dynamic libraries, I am considering whether to link these libraries statically or not.

ADD-SP commented 3 years ago

This should also be solved by creating a symbolic link under /usr/lib or /lib.

ln -s /usr/local/libsodium/lib/libsodium.so.23 /usr/lib/libsodium.so.23
# or
ln -s /usr/local/libsodium/lib/libsodium.so.23 /lib/libsodium.so.23
FlyBirdF commented 3 years ago

Thanks a lot. I run the following commands and the problem have been solved.

[root@cobbler nginx-1.18.0]# ldd $(which /usr/sbin/nginx) 
    linux-vdso.so.1 =>  (0x00007fff89b95000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007fcdbca31000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fcdbc815000)
    libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007fcdbc5de000)
    libsodium.so.23 => not found
    libpcre.so.1 => /lib64/libpcre.so.1 (0x00007fcdbc126000)
    libssl.so.10 => /lib64/libssl.so.10 (0x00007fcdbbeb4000)
    libcrypto.so.10 => /lib64/libcrypto.so.10 (0x00007fcdbba51000)
    libz.so.1 => /lib64/libz.so.1 (0x00007fcdbb83b000)
    libc.so.6 => /lib64/libc.so.6 (0x00007fcdbb46d000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fcdbd019000)
    libfreebl3.so => /lib64/libfreebl3.so (0x00007fcdbb26a000)
    libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007fcdbb01d000)
    libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007fcdbad34000)
    libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007fcdbab30000)
    libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007fcdba8fd000)
    libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007fcdba6ed000)
    libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007fcdba4e9000)
    libresolv.so.2 => /lib64/libresolv.so.2 (0x00007fcdba2cf000)
    libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fcdba0a8000)
[root@cobbler nginx-1.18.0]# ln -s /usr/local/libsodium/lib/libsodium.so.23 /lib64/libsodium.so.23

By the way, the hostname cobbler is my compile machine, the nginx is my prod host, i use the dynamic method in my cobbler host and the static method in my nginx host, both of them are works well.