Re: Perdition make error
Martin Hochreiter <[email protected]>
| Newsgroups | gmane.mail.perdition.user |
|---|---|
| Message-ID | <[email protected]> |
> Possibly. Could you send me a copy of your perdition.c file as > an attachment? Off-list is fine. > > >> Or - another solution for us ... do you plan to integrate the patch in >> the CentOS RPMs? >> (we use ldap as database and need the mailhost field ...) >> > Yes, but it may be faster for you to sort the build problem out. > > Hi Simon, please find the files enclosed Thank you for your help! regards Martin ______________________________________________ Perdition-users mailing list [email protected] http://lists.vergenet.net/listinfo/perdition-users
configure.log
(text/x-log, 9.8 KB)
checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /bin/mkdir -p checking for gawk... gawk checking whether make sets $(MAKE)... yes checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking for style of include used by make... GNU checking dependency style of gcc... gcc3 checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking for a sed that does not truncate output... /bin/sed checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking for fgrep... /bin/grep -F checking for ld used by gcc... /usr/bin/ld checking if the linker (/usr/bin/ld) is GNU ld... yes checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B checking the name lister (/usr/bin/nm -B) interface... BSD nm checking whether ln -s works... yes checking the maximum length of command line arguments... 98304 checking whether the shell understands some XSI constructs... yes checking whether the shell understands "+="... yes checking for /usr/bin/ld option to reload object files... -r checking for objdump... objdump checking how to recognize dependent libraries... pass_all checking for ar... ar checking for strip... strip checking for ranlib... ranlib checking command to parse /usr/bin/nm -B output from gcc object... ok checking how to run the C preprocessor... gcc -E checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking for dlfcn.h... yes checking for objdir... .libs checking if gcc supports -fno-rtti -fno-exceptions... no checking for gcc option to produce PIC... -fPIC -DPIC checking if gcc PIC flag -fPIC -DPIC works... yes checking if gcc static flag -static works... yes checking if gcc supports -c -o file.o... yes checking if gcc supports -c -o file.o... (cached) yes checking whether the gcc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes checking whether -lc should be explicitly linked in... no checking dynamic linker characteristics... GNU/Linux ld.so checking how to hardcode library paths into programs... immediate checking whether stripping libraries is possible... yes checking if libtool supports shared libraries... yes checking whether to build shared libraries... yes checking whether to build static libraries... yes checking whether ln -s works... yes checking whether make sets $(MAKE)... (cached) yes checking for struct sockaddr.sa_len... no checking for dlopen in -ldl... yes checking for yp_match in -lnsl... yes checking for socket in -lsocket... no checking for gethostbyname in -lnsl... yes checking for crypt in -lcrypt... yes checking for poptGetContext in -lpopt... yes checking for vanessa_logger_closelog in -lvanessa_logger... yes checking for vanessa_queue_create in -lvanessa_adt... yes checking for vanessa_socket_client_open in -lvanessa_socket... yes checking for ANSI C header files... (cached) yes checking for sys/wait.h that is POSIX.1 compatible... yes checking sys/param.h usability... yes checking sys/param.h presence... yes checking for sys/param.h... yes checking if SSL/TLS support has been disabled... "no" checking OpenSSL include path... /usr/include checking OpenSSL library path... /usr/lib64 checking for /usr/include/openssl/ssl.h... yes checking for ERR_error_string in -lssl... yes checking if MySQL support has been disabled... "no" checking MySQL include path... /usr/local/include checking MySQL include path... /usr/local/lib checking for /usr/local/include/mysql.h... no configure: WARNING: "" "**********************************************************************" "* perditiondb_mysql will not be built" "**********************************************************************" checking for mysql_real_connect in -lmysqlclient... no configure: WARNING: "" "**********************************************************************" "* perditiondb_mysql will not be built: " "**********************************************************************" checking if ODBC support has been disabled... "no" checking ODBC include path... /usr/local/include checking ODBC include path... /usr/local/lib checking for /usr/local/include/sql.h... no checking for /usr/local/include/sqlext.h... no checking for /usr/local/include/sqltypes.h... no configure: WARNING: "" "**********************************************************************" "* perditiondb_odbc will not be built: " "* There a many ODBC Managers available including UnixODBC" "* which is available from www.unixodbc.org" "**********************************************************************" checking if PostgreSQL support has been disabled... "no" checking for pg_config... no configure: WARNING: "" "**********************************************************************" "* perditiondb_postgresql will not be built" "**********************************************************************" checking if CDB support has been disabled... "no" checking cdb.h usability... no checking cdb.h presence... no checking for cdb.h... no configure: WARNING: "" "**********************************************************************" "* perditiondb_cdb will not be built" "**********************************************************************" checking if GDBM support has been disabled... "no" checking gdbm.h usability... no checking gdbm.h presence... no checking for gdbm.h... no configure: WARNING: "" "**********************************************************************" "* perditiondb_gdbm and makegdbm will not be built" "**********************************************************************" checking if Berkeley DB support has been disabled... "no" checking db.h usability... no checking db.h presence... no checking for db.h... no configure: WARNING: "" "**********************************************************************" "* perditiondb_bdb and makebdb will not be built" "**********************************************************************" checking if NIS support has been disabled... "no" checking if Posix Regular Expression support has been disabled... "no" checking if LDAP support has been disabled... "no" checking OpenLDAP include path... /usr/include checking OpenLDAP library path... /usr/lib64 checking for /usr/include/ldap.h... yes checking for ldap_url_parse in -lldap... yes checking OpenLDAP lud_exts in LDAPURLDesc... "yes" checking for ldap_set_option in -lldap... yes checking OpenLDAP schema path... /etc/openldap/schema checking if deamon map has been disabled... "no" checking security/pam_appl.h usability... no checking security/pam_appl.h presence... no checking for security/pam_appl.h... no configure: WARNING: "" "**********************************************************************" "* pam support will not be built" "**********************************************************************" checking if ldap (latex) documentation is disabled... "no" checking for setproctitle... no checking libutil.h usability... no checking libutil.h presence... no checking for libutil.h... no checking for setproctitle in -lutil... no checking sys/pstat.h usability... no checking sys/pstat.h presence... no checking for sys/pstat.h... no checking whether __progname and __progname_full are available... yes checking which argv replacement method to use... writeable checking size of char... 1 checking size of short... 2 checking size of int... 4 checking size of long... 8 checking for an ANSI C-conforming const... yes checking for uid_t in sys/types.h... yes checking for size_t... yes checking return type of signal handlers... void checking for wait3 that fills in rusage... yes checking for select... yes checking for socket... yes checking for strdup... yes checking for strerror... yes checking for parse_printf_format... yes checking for flim... no configure: creating ./config.status config.status: creating debian/Makefile config.status: creating perdition.spec config.status: creating perdition/Makefile config.status: creating perdition/db/Makefile config.status: creating perdition/db/cdb/Makefile config.status: creating perdition/db/gdbm/Makefile config.status: creating perdition/db/bdb/Makefile config.status: creating perdition/db/posix_regex/Makefile config.status: creating perdition/db/mysql/Makefile config.status: creating perdition/db/nis/Makefile config.status: creating perdition/db/postgresql/Makefile config.status: creating perdition/db/ldap/Makefile config.status: creating perdition/db/ldap/doc/Makefile config.status: creating perdition/db/odbc/Makefile config.status: creating perdition/db/daemon/Makefile config.status: creating perdition/db/daemon/lib/Makefile config.status: creating makegdbm/Makefile config.status: creating makebdb/Makefile config.status: creating etc/Makefile config.status: creating etc/pam.d/Makefile config.status: creating etc/perdition/Makefile config.status: creating etc/perdition/Makefile.popmap config.status: creating etc/rc.d/Makefile config.status: creating etc/rc.d/init.d/Makefile config.status: creating etc/rc.d/init.d/perdition.debian config.status: creating etc/rc.d/init.d/perdition.rh config.status: creating etc/sysconfig/Makefile config.status: creating Makefile config.status: creating INSTALL config.status: creating CODING_LOCATIONS config.status: creating config.h config.status: executing depfiles commands config.status: executing libtool commands
make.log
(text/x-log, 17.2 KB)
make all-recursive make[1]: Entering directory `/root/perdition-1.18' Making all in perdition make[2]: Entering directory `/root/perdition-1.18/perdition' Making all in db make[3]: Entering directory `/root/perdition-1.18/perdition/db' Making all in ldap make[4]: Entering directory `/root/perdition-1.18/perdition/db/ldap' make[5]: Entering directory `/root/perdition-1.18/perdition/db/ldap' /bin/sh ../../../libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I../../.. -I../../../ -I../../../perdition -I/usr/include -g -O2 -MT perditiondb_ldap.lo -MD -MP -MF .deps/perditiondb_ldap.Tpo -c -o perditiondb_ldap.lo perditiondb_ldap.c libtool: compile: gcc -DHAVE_CONFIG_H -I. -I../../.. -I../../../ -I../../../perdition -I/usr/include -g -O2 -MT perditiondb_ldap.lo -MD -MP -MF .deps/perditiondb_ldap.Tpo -c perditiondb_ldap.c -fPIC -DPIC -o .libs/perditiondb_ldap.o libtool: compile: gcc -DHAVE_CONFIG_H -I. -I../../.. -I../../../ -I../../../perdition -I/usr/include -g -O2 -MT perditiondb_ldap.lo -MD -MP -MF .deps/perditiondb_ldap.Tpo -c perditiondb_ldap.c -o perditiondb_ldap.o >/dev/null 2>&1 mv -f .deps/perditiondb_ldap.Tpo .deps/perditiondb_ldap.Plo /bin/sh ../../../libtool --tag=CC --mode=link gcc -g -O2 -version-info 0:0:0 -o libperditiondb_ldap.la -rpath /opt/perdition180/lib perditiondb_ldap.lo -L/usr/lib64 -lldap -llber -lvanessa_logger libtool: link: gcc -shared .libs/perditiondb_ldap.o -L/usr/lib64 -lldap -llber -lvanessa_logger -Wl,-soname -Wl,libperditiondb_ldap.so.0 -o .libs/libperditiondb_ldap.so.0.0.0 libtool: link: (cd ".libs" && rm -f "libperditiondb_ldap.so.0" && ln -s "libperditiondb_ldap.so.0.0.0" "libperditiondb_ldap.so.0") libtool: link: (cd ".libs" && rm -f "libperditiondb_ldap.so" && ln -s "libperditiondb_ldap.so.0.0.0" "libperditiondb_ldap.so") libtool: link: ar cru .libs/libperditiondb_ldap.a perditiondb_ldap.o libtool: link: ranlib .libs/libperditiondb_ldap.a libtool: link: ( cd ".libs" && rm -f "libperditiondb_ldap.la" && ln -s "../libperditiondb_ldap.la" "libperditiondb_ldap.la" ) make[5]: Leaving directory `/root/perdition-1.18/perdition/db/ldap' make[4]: Leaving directory `/root/perdition-1.18/perdition/db/ldap' Making all in nis make[4]: Entering directory `/root/perdition-1.18/perdition/db/nis' /bin/sh ../../../libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I../../.. -I../../../ -I../../../perdition -g -O2 -MT perditiondb_nis.lo -MD -MP -MF .deps/perditiondb_nis.Tpo -c -o perditiondb_nis.lo perditiondb_nis.c libtool: compile: gcc -DHAVE_CONFIG_H -I. -I../../.. -I../../../ -I../../../perdition -g -O2 -MT perditiondb_nis.lo -MD -MP -MF .deps/perditiondb_nis.Tpo -c perditiondb_nis.c -fPIC -DPIC -o .libs/perditiondb_nis.o libtool: compile: gcc -DHAVE_CONFIG_H -I. -I../../.. -I../../../ -I../../../perdition -g -O2 -MT perditiondb_nis.lo -MD -MP -MF .deps/perditiondb_nis.Tpo -c perditiondb_nis.c -o perditiondb_nis.o >/dev/null 2>&1 mv -f .deps/perditiondb_nis.Tpo .deps/perditiondb_nis.Plo /bin/sh ../../../libtool --tag=CC --mode=link gcc -g -O2 -version-info 0:0:0 -o libperditiondb_nis.la -rpath /opt/perdition180/lib perditiondb_nis.lo -lnsl -lvanessa_logger libtool: link: gcc -shared .libs/perditiondb_nis.o -lnsl -lvanessa_logger -Wl,-soname -Wl,libperditiondb_nis.so.0 -o .libs/libperditiondb_nis.so.0.0.0 libtool: link: (cd ".libs" && rm -f "libperditiondb_nis.so.0" && ln -s "libperditiondb_nis.so.0.0.0" "libperditiondb_nis.so.0") libtool: link: (cd ".libs" && rm -f "libperditiondb_nis.so" && ln -s "libperditiondb_nis.so.0.0.0" "libperditiondb_nis.so") libtool: link: ar cru .libs/libperditiondb_nis.a perditiondb_nis.o libtool: link: ranlib .libs/libperditiondb_nis.a libtool: link: ( cd ".libs" && rm -f "libperditiondb_nis.la" && ln -s "../libperditiondb_nis.la" "libperditiondb_nis.la" ) make[4]: Leaving directory `/root/perdition-1.18/perdition/db/nis' Making all in posix_regex make[4]: Entering directory `/root/perdition-1.18/perdition/db/posix_regex' /bin/sh ../../../libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I../../.. -I../../../ -I../../../perdition -DPERDITIONDB_POSIX_REGEX_SYSCONFDIR=\"/opt/perdition180/etc/perdition\" -g -O2 -MT perditiondb_posix_regex.lo -MD -MP -MF .deps/perditiondb_posix_regex.Tpo -c -o perditiondb_posix_regex.lo perditiondb_posix_regex.c libtool: compile: gcc -DHAVE_CONFIG_H -I. -I../../.. -I../../../ -I../../../perdition -DPERDITIONDB_POSIX_REGEX_SYSCONFDIR=\"/opt/perdition180/etc/perdition\" -g -O2 -MT perditiondb_posix_regex.lo -MD -MP -MF .deps/perditiondb_posix_regex.Tpo -c perditiondb_posix_regex.c -fPIC -DPIC -o .libs/perditiondb_posix_regex.o libtool: compile: gcc -DHAVE_CONFIG_H -I. -I../../.. -I../../../ -I../../../perdition -DPERDITIONDB_POSIX_REGEX_SYSCONFDIR=\"/opt/perdition180/etc/perdition\" -g -O2 -MT perditiondb_posix_regex.lo -MD -MP -MF .deps/perditiondb_posix_regex.Tpo -c perditiondb_posix_regex.c -o perditiondb_posix_regex.o >/dev/null 2>&1 mv -f .deps/perditiondb_posix_regex.Tpo .deps/perditiondb_posix_regex.Plo /bin/sh ../../../libtool --tag=CC --mode=link gcc -g -O2 -version-info 0:0:0 -o libperditiondb_posix_regex.la -rpath /opt/perdition180/lib perditiondb_posix_regex.lo -lvanessa_logger -lvanessa_adt libtool: link: gcc -shared .libs/perditiondb_posix_regex.o -lvanessa_logger -lvanessa_adt -Wl,-soname -Wl,libperditiondb_posix_regex.so.0 -o .libs/libperditiondb_posix_regex.so.0.0.0 libtool: link: (cd ".libs" && rm -f "libperditiondb_posix_regex.so.0" && ln -s "libperditiondb_posix_regex.so.0.0.0" "libperditiondb_posix_regex.so.0") libtool: link: (cd ".libs" && rm -f "libperditiondb_posix_regex.so" && ln -s "libperditiondb_posix_regex.so.0.0.0" "libperditiondb_posix_regex.so") libtool: link: ar cru .libs/libperditiondb_posix_regex.a perditiondb_posix_regex.o libtool: link: ranlib .libs/libperditiondb_posix_regex.a libtool: link: ( cd ".libs" && rm -f "libperditiondb_posix_regex.la" && ln -s "../libperditiondb_posix_regex.la" "libperditiondb_posix_regex.la" ) make[4]: Leaving directory `/root/perdition-1.18/perdition/db/posix_regex' Making all in daemon make[4]: Entering directory `/root/perdition-1.18/perdition/db/daemon' Making all in lib make[5]: Entering directory `/root/perdition-1.18/perdition/db/daemon/lib' /bin/sh ../../../../libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I../../../.. -I../../../../perdition -g -O2 -MT packet.lo -MD -MP -MF .deps/packet.Tpo -c -o packet.lo packet.c libtool: compile: gcc -DHAVE_CONFIG_H -I. -I../../../.. -I../../../../perdition -g -O2 -MT packet.lo -MD -MP -MF .deps/packet.Tpo -c packet.c -fPIC -DPIC -o .libs/packet.o libtool: compile: gcc -DHAVE_CONFIG_H -I. -I../../../.. -I../../../../perdition -g -O2 -MT packet.lo -MD -MP -MF .deps/packet.Tpo -c packet.c -o packet.o >/dev/null 2>&1 mv -f .deps/packet.Tpo .deps/packet.Plo /bin/sh ../../../../libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I../../../.. -I../../../../perdition -g -O2 -MT unix_socket.lo -MD -MP -MF .deps/unix_socket.Tpo -c -o unix_socket.lo unix_socket.c libtool: compile: gcc -DHAVE_CONFIG_H -I. -I../../../.. -I../../../../perdition -g -O2 -MT unix_socket.lo -MD -MP -MF .deps/unix_socket.Tpo -c unix_socket.c -fPIC -DPIC -o .libs/unix_socket.o libtool: compile: gcc -DHAVE_CONFIG_H -I. -I../../../.. -I../../../../perdition -g -O2 -MT unix_socket.lo -MD -MP -MF .deps/unix_socket.Tpo -c unix_socket.c -o unix_socket.o >/dev/null 2>&1 mv -f .deps/unix_socket.Tpo .deps/unix_socket.Plo /bin/sh ../../../../libtool --tag=CC --mode=link gcc -g -O2 -version-info 0:0:0 -o libperditiondb_daemon_base.la -rpath /opt/perdition180/lib packet.lo unix_socket.lo -lvanessa_logger -lvanessa_socket libtool: link: gcc -shared .libs/packet.o .libs/unix_socket.o -lvanessa_logger -lvanessa_socket -Wl,-soname -Wl,libperditiondb_daemon_base.so.0 -o .libs/libperditiondb_daemon_base.so.0.0.0 libtool: link: (cd ".libs" && rm -f "libperditiondb_daemon_base.so.0" && ln -s "libperditiondb_daemon_base.so.0.0.0" "libperditiondb_daemon_base.so.0") libtool: link: (cd ".libs" && rm -f "libperditiondb_daemon_base.so" && ln -s "libperditiondb_daemon_base.so.0.0.0" "libperditiondb_daemon_base.so") libtool: link: ar cru .libs/libperditiondb_daemon_base.a packet.o unix_socket.o libtool: link: ranlib .libs/libperditiondb_daemon_base.a libtool: link: ( cd ".libs" && rm -f "libperditiondb_daemon_base.la" && ln -s "../libperditiondb_daemon_base.la" "libperditiondb_daemon_base.la" ) make[5]: Leaving directory `/root/perdition-1.18/perdition/db/daemon/lib' make[5]: Entering directory `/root/perdition-1.18/perdition/db/daemon' /bin/sh ../../../libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I../../.. -I../../../perdition -g -O2 -MT perditiondb_daemon.lo -MD -MP -MF .deps/perditiondb_daemon.Tpo -c -o perditiondb_daemon.lo perditiondb_daemon.c libtool: compile: gcc -DHAVE_CONFIG_H -I. -I../../.. -I../../../perdition -g -O2 -MT perditiondb_daemon.lo -MD -MP -MF .deps/perditiondb_daemon.Tpo -c perditiondb_daemon.c -fPIC -DPIC -o .libs/perditiondb_daemon.o libtool: compile: gcc -DHAVE_CONFIG_H -I. -I../../.. -I../../../perdition -g -O2 -MT perditiondb_daemon.lo -MD -MP -MF .deps/perditiondb_daemon.Tpo -c perditiondb_daemon.c -o perditiondb_daemon.o >/dev/null 2>&1 mv -f .deps/perditiondb_daemon.Tpo .deps/perditiondb_daemon.Plo /bin/sh ../../../libtool --tag=CC --mode=link gcc -g -O2 -version-info 0:0:0 -o libperditiondb_daemon.la -rpath /opt/perdition180/lib perditiondb_daemon.lo -lvanessa_logger -lvanessa_adt -lvanessa_socket -L./lib -lperditiondb_daemon_base libtool: link: gcc -shared .libs/perditiondb_daemon.o -Wl,-rpath -Wl,/root/perdition-1.18/perdition/db/daemon/lib/.libs -Wl,-rpath -Wl,/opt/perdition180/lib -lvanessa_logger -lvanessa_adt -lvanessa_socket -L/root/perdition-1.18/perdition/db/daemon/lib /root/perdition-1.18/perdition/db/daemon/lib/.libs/libperditiondb_daemon_base.so -Wl,-soname -Wl,libperditiondb_daemon.so.0 -o .libs/libperditiondb_daemon.so.0.0.0 libtool: link: (cd ".libs" && rm -f "libperditiondb_daemon.so.0" && ln -s "libperditiondb_daemon.so.0.0.0" "libperditiondb_daemon.so.0") libtool: link: (cd ".libs" && rm -f "libperditiondb_daemon.so" && ln -s "libperditiondb_daemon.so.0.0.0" "libperditiondb_daemon.so") libtool: link: ar cru .libs/libperditiondb_daemon.a perditiondb_daemon.o libtool: link: ranlib .libs/libperditiondb_daemon.a libtool: link: ( cd ".libs" && rm -f "libperditiondb_daemon.la" && ln -s "../libperditiondb_daemon.la" "libperditiondb_daemon.la" ) gcc -DHAVE_CONFIG_H -I. -I../../.. -I../../../perdition -g -O2 -MT client.o -MD -MP -MF .deps/client.Tpo -c -o client.o client.c mv -f .deps/client.Tpo .deps/client.Po /bin/sh ../../../libtool --tag=CC --mode=link gcc -g -O2 -o client client.o -lvanessa_logger -lvanessa_adt -lvanessa_socket -L./lib -lperditiondb_daemon_base libtool: link: gcc -g -O2 -o .libs/client client.o -lvanessa_logger -lvanessa_adt -lvanessa_socket -L/root/perdition-1.18/perdition/db/daemon/lib /root/perdition-1.18/perdition/db/daemon/lib/.libs/libperditiondb_daemon_base.so -Wl,-rpath -Wl,/opt/perdition180/lib gcc -DHAVE_CONFIG_H -I. -I../../.. -I../../../perdition -g -O2 -MT server.o -MD -MP -MF .deps/server.Tpo -c -o server.o server.c mv -f .deps/server.Tpo .deps/server.Po /bin/sh ../../../libtool --tag=CC --mode=link gcc -g -O2 -o server server.o -lvanessa_logger -lvanessa_adt -lvanessa_socket -L./lib -lperditiondb_daemon_base libtool: link: gcc -g -O2 -o .libs/server server.o -lvanessa_logger -lvanessa_adt -lvanessa_socket -L/root/perdition-1.18/perdition/db/daemon/lib /root/perdition-1.18/perdition/db/daemon/lib/.libs/libperditiondb_daemon_base.so -Wl,-rpath -Wl,/opt/perdition180/lib make[5]: Leaving directory `/root/perdition-1.18/perdition/db/daemon' make[4]: Leaving directory `/root/perdition-1.18/perdition/db/daemon' make[4]: Entering directory `/root/perdition-1.18/perdition/db' make[4]: Für das Ziel »all-am« ist nichts zu tun. make[4]: Leaving directory `/root/perdition-1.18/perdition/db' make[3]: Leaving directory `/root/perdition-1.18/perdition/db' make[3]: Entering directory `/root/perdition-1.18/perdition' gcc -DHAVE_CONFIG_H -I. -I.. -DPERDITION_LIBDIR=\"/opt/perdition180/lib\" -DPERDITION_SYSCONFDIR=\"/opt/perdition180/etc/perdition\" -DPERDITION_LOCALSTATEDIR=\"/opt/perdition180/var\" -I/usr/include -g -O2 -MT config_file.o -MD -MP -MF .deps/config_file.Tpo -c -o config_file.o config_file.c mv -f .deps/config_file.Tpo .deps/config_file.Po gcc -DHAVE_CONFIG_H -I. -I.. -DPERDITION_LIBDIR=\"/opt/perdition180/lib\" -DPERDITION_SYSCONFDIR=\"/opt/perdition180/etc/perdition\" -DPERDITION_LOCALSTATEDIR=\"/opt/perdition180/var\" -I/usr/include -g -O2 -MT getserver.o -MD -MP -MF .deps/getserver.Tpo -c -o getserver.o getserver.c mv -f .deps/getserver.Tpo .deps/getserver.Po gcc -DHAVE_CONFIG_H -I. -I.. -DPERDITION_LIBDIR=\"/opt/perdition180/lib\" -DPERDITION_SYSCONFDIR=\"/opt/perdition180/etc/perdition\" -DPERDITION_LOCALSTATEDIR=\"/opt/perdition180/var\" -I/usr/include -g -O2 -MT greeting.o -MD -MP -MF .deps/greeting.Tpo -c -o greeting.o greeting.c mv -f .deps/greeting.Tpo .deps/greeting.Po gcc -DHAVE_CONFIG_H -I. -I.. -DPERDITION_LIBDIR=\"/opt/perdition180/lib\" -DPERDITION_SYSCONFDIR=\"/opt/perdition180/etc/perdition\" -DPERDITION_LOCALSTATEDIR=\"/opt/perdition180/var\" -I/usr/include -g -O2 -MT imap4.o -MD -MP -MF .deps/imap4.Tpo -c -o imap4.o imap4.c mv -f .deps/imap4.Tpo .deps/imap4.Po gcc -DHAVE_CONFIG_H -I. -I.. -DPERDITION_LIBDIR=\"/opt/perdition180/lib\" -DPERDITION_SYSCONFDIR=\"/opt/perdition180/etc/perdition\" -DPERDITION_LOCALSTATEDIR=\"/opt/perdition180/var\" -I/usr/include -g -O2 -MT imap4s.o -MD -MP -MF .deps/imap4s.Tpo -c -o imap4s.o imap4s.c mv -f .deps/imap4s.Tpo .deps/imap4s.Po gcc -DHAVE_CONFIG_H -I. -I.. -DPERDITION_LIBDIR=\"/opt/perdition180/lib\" -DPERDITION_SYSCONFDIR=\"/opt/perdition180/etc/perdition\" -DPERDITION_LOCALSTATEDIR=\"/opt/perdition180/var\" -I/usr/include -g -O2 -MT imap4_in.o -MD -MP -MF .deps/imap4_in.Tpo -c -o imap4_in.o imap4_in.c mv -f .deps/imap4_in.Tpo .deps/imap4_in.Po gcc -DHAVE_CONFIG_H -I. -I.. -DPERDITION_LIBDIR=\"/opt/perdition180/lib\" -DPERDITION_SYSCONFDIR=\"/opt/perdition180/etc/perdition\" -DPERDITION_LOCALSTATEDIR=\"/opt/perdition180/var\" -I/usr/include -g -O2 -MT imap4_out.o -MD -MP -MF .deps/imap4_out.Tpo -c -o imap4_out.o imap4_out.c mv -f .deps/imap4_out.Tpo .deps/imap4_out.Po gcc -DHAVE_CONFIG_H -I. -I.. -DPERDITION_LIBDIR=\"/opt/perdition180/lib\" -DPERDITION_SYSCONFDIR=\"/opt/perdition180/etc/perdition\" -DPERDITION_LOCALSTATEDIR=\"/opt/perdition180/var\" -I/usr/include -g -O2 -MT imap4_tag.o -MD -MP -MF .deps/imap4_tag.Tpo -c -o imap4_tag.o imap4_tag.c mv -f .deps/imap4_tag.Tpo .deps/imap4_tag.Po gcc -DHAVE_CONFIG_H -I. -I.. -DPERDITION_LIBDIR=\"/opt/perdition180/lib\" -DPERDITION_SYSCONFDIR=\"/opt/perdition180/etc/perdition\" -DPERDITION_LOCALSTATEDIR=\"/opt/perdition180/var\" -I/usr/include -g -O2 -MT imap4_write.o -MD -MP -MF .deps/imap4_write.Tpo -c -o imap4_write.o imap4_write.c mv -f .deps/imap4_write.Tpo .deps/imap4_write.Po gcc -DHAVE_CONFIG_H -I. -I.. -DPERDITION_LIBDIR=\"/opt/perdition180/lib\" -DPERDITION_SYSCONFDIR=\"/opt/perdition180/etc/perdition\" -DPERDITION_LOCALSTATEDIR=\"/opt/perdition180/var\" -I/usr/include -g -O2 -MT io.o -MD -MP -MF .deps/io.Tpo -c -o io.o io.c io.c: In function »io_pipe«: io.c:751: Warnung: Übergabe des Arguments 10 von »vanessa_socket_pipe_func« von inkompatiblem Zeigertyp io.c:751: Warnung: Übergabe des Arguments 11 von »vanessa_socket_pipe_func« von inkompatiblem Zeigertyp mv -f .deps/io.Tpo .deps/io.Po gcc -DHAVE_CONFIG_H -I. -I.. -DPERDITION_LIBDIR=\"/opt/perdition180/lib\" -DPERDITION_SYSCONFDIR=\"/opt/perdition180/etc/perdition\" -DPERDITION_LOCALSTATEDIR=\"/opt/perdition180/var\" -I/usr/include -g -O2 -MT io_select.o -MD -MP -MF .deps/io_select.Tpo -c -o io_select.o io_select.c mv -f .deps/io_select.Tpo .deps/io_select.Po gcc -DHAVE_CONFIG_H -I. -I.. -DPERDITION_LIBDIR=\"/opt/perdition180/lib\" -DPERDITION_SYSCONFDIR=\"/opt/perdition180/etc/perdition\" -DPERDITION_LOCALSTATEDIR=\"/opt/perdition180/var\" -I/usr/include -g -O2 -MT options.o -MD -MP -MF .deps/options.Tpo -c -o options.o options.c mv -f .deps/options.Tpo .deps/options.Po gcc -DHAVE_CONFIG_H -I. -I.. -DPERDITION_LIBDIR=\"/opt/perdition180/lib\" -DPERDITION_SYSCONFDIR=\"/opt/perdition180/etc/perdition\" -DPERDITION_LOCALSTATEDIR=\"/opt/perdition180/var\" -I/usr/include -g -O2 -MT pam.o -MD -MP -MF .deps/pam.Tpo -c -o pam.o pam.c mv -f .deps/pam.Tpo .deps/pam.Po gcc -DHAVE_CONFIG_H -I. -I.. -DPERDITION_LIBDIR=\"/opt/perdition180/lib\" -DPERDITION_SYSCONFDIR=\"/opt/perdition180/etc/perdition\" -DPERDITION_LOCALSTATEDIR=\"/opt/perdition180/var\" -I/usr/include -g -O2 -MT perdition.o -MD -MP -MF .deps/perdition.Tpo -c -o perdition.o perdition.c perdition.c: In function »main«: perdition.c:547: Warnung: Zuweisung erzeugt Zeiger von Ganzzahl ohne Typkonvertierung perdition.c:712: Fehler: expected expression before »else« perdition.c:950: Fehler: expected expression before »else« perdition.c:998: Fehler: expected expression before »else« make[3]: *** [perdition.o] Fehler 1 make[3]: Leaving directory `/root/perdition-1.18/perdition' make[2]: *** [all-recursive] Fehler 1 make[2]: Leaving directory `/root/perdition-1.18/perdition' make[1]: *** [all-recursive] Fehler 1 make[1]: Leaving directory `/root/perdition-1.18' make: *** [all] Fehler 2
perdition.c
(text/x-csrc, 38.8 KB)
/********************************************************************** * perdition.c September 1999 * Horms [email protected] * * Perdition, POP3 and IMAP4 proxy daemon * * perdition * Mail retrieval proxy server * Copyright (C) 1999-2005 Horms * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * **********************************************************************/ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <sys/utsname.h> #include <sys/types.h> #include <netdb.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <vanessa_socket.h> #include <time.h> #include <stdio.h> #include <unistd.h> #include <grp.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <libgen.h> #include "protocol.h" #include "log.h" #include "options.h" #include "getserver.h" #include "perdition_types.h" #include "greeting.h" #include "quit.h" #include "config_file.h" #include "config_file.h" #include "server_port.h" #include "username.h" #include "ssl.h" #include "sock.h" #include "setproctitle.h" #include "imap4_tag.h" #include "perdition_globals.h" /* limits.h should be sufficient on most systems * http://www.opengroup.org/onlinepubs/007908799/headix.html */ #include <limits.h> #if 0 #ifdef HAVE_SYS_PARAM_H #include <sys/param.h> #ifdef __FreeBSD__ #if __FreeBSD_version < 500112 #include <machine/limits.h> /* For ULONG_MAX on FreeBSD */ #else #include <sys/limits.h> #endif #endif #endif #endif #ifdef DMALLOC #include <dmalloc.h> #endif /*Use uname information here and there to identify this system*/ struct utsname *system_uname; /* Local and Peer address information is global so perditiondb * libraries can access this information */ struct sockaddr_storage *peername; struct sockaddr_storage *sockname; /* PID file that has been created */ static char *pid_file; /* * Used for opening dynamic server lookup library * Kept global so they can be used in signal handlers */ static int (*dbserver_get)(const char *, const char *, char **, size_t *); static int (*dbserver_get2)(const char *, const char *, char **, char **, char**); static void *handle; static void perdition_reread_handler(int sig); static void perdition_exit_cleanly(int i); static int write_pid_file(const char *pidfilename, const char *username, const char *group); static int perdition_chown(const char *path, const char *username, const char *group); /* Macro to clean things up when we jump around in the main loop*/ #define PERDITION_CLEAN_UP_MAIN \ if(username!=NULL && username!=pw.pw_name && username!=pw2.pw_name){ \ free(username); \ } \ username=NULL; \ if(pw2.pw_name!=NULL && pw2.pw_name!=pw.pw_name){ \ free(pw2.pw_name); \ } \ pw2.pw_name=NULL; \ pw2.pw_passwd=NULL; \ if(pw.pw_name!=NULL){ \ free(pw.pw_name); \ pw.pw_name=NULL; \ } \ if(pw.pw_passwd!=NULL){ \ free(pw.pw_passwd); \ pw.pw_passwd=NULL;\ } \ if(pw2.pw_name!=NULL){ \ free(pw2.pw_name); \ pw2.pw_name=NULL; \ } \ pw2.pw_passwd=NULL; \ if (!round_robin_server){ \ user_server_port_destroy(usp); \ } \ round_robin_server=0; \ servername=NULL; \ if(server_io!=NULL) { \ io_close(server_io); \ io_destroy(server_io); \ } \ server_io=NULL; \ usp=NULL; \ token_destroy(&client_tag); \ tls_state=0; \ opt.capability = protocol->capability(opt.capability, \ &(opt.mangled_capability), opt.ssl_mode, tls_state); /* Macro to set the uid and gid */ #define PERDITION_SET_UID_AND_GID \ if(!geteuid() && vanessa_socket_daemon_setid(opt.username, opt.group)){ \ VANESSA_LOGGER_ERR("Fatal error setting group and userid. Exiting.");\ perdition_exit_cleanly(-1); \ } static void perdition_log_auth(timed_log_t *auth_log, const char *from_to_host_str, struct passwd *pw, const char *servername, const char *port, const char *progname, const char *reason) { char *passwd; if (!strcmp(reason, "ok")) { if (opt.log_passwd & LOG_PASSWD_OK) passwd = pw->pw_passwd; else passwd = "XXXXXX"; } else { if (opt.log_passwd & LOG_PASSWD_FAIL) passwd = pw->pw_passwd; else passwd = "XXXXXX"; } memset(auth_log->log_str, 0, sizeof(auth_log->log_str)); snprintf(auth_log->log_str, sizeof(auth_log->log_str), "Auth:%s user=\"%s\" passwd=\"%s\" " "server=\"%s\" port=\"%s\" status=\"%s\"", from_to_host_str, str_null_safe(pw->pw_name), str_null_safe(passwd), str_null_safe(servername), str_null_safe(port), str_null_safe(reason)); auth_log->log_time = time(NULL) + opt.connect_relog; VANESSA_LOGGER_LOG(LOG_NOTICE, auth_log->log_str); set_proc_title("%s: auth %s", progname, str_null_safe(reason)); } #define PERDITION_LOG_AUTH(_reason) \ do { \ perdition_log_auth(&auth_log, from_to_host_str, &pw, servername, \ port, progname, _reason); \ } while(0) static void login_failed_protocol(protocol_t *protocol, int protocol_type, io_t *io, token_t *tag, timed_log_t *auth_log, const char *from_to_host_str, struct passwd *pw, const char *servername, const char *port, const char *progname, const char *reason) { sleep(PERDITION_AUTH_FAIL_SLEEP); if (protocol->write(io, NULL_FLAG, tag, protocol->type[protocol_type], 0, reason) < 0) { VANESSA_LOGGER_DEBUG("protocol->write"); VANESSA_LOGGER_ERR("Fatal error writing to client. " "Exiting child."); perdition_exit_cleanly(-1); } perdition_log_auth(auth_log, from_to_host_str, pw, servername, port, progname, reason); } #define LOGIN_FAILED_PROTOCOL(_type, _reason) \ do { \ login_failed_protocol(protocol, _type, client_io, client_tag, \ &auth_log, from_to_host_str, &pw, servername, \ port, progname, "failed: " _reason); \ } while(0) /********************************************************************** * Muriel the main function **********************************************************************/ int main (int argc, char **argv, char **envp){ vanessa_logger_t *vl; struct passwd pw = {NULL, NULL}; struct passwd pw2 = {NULL, NULL}; unsigned char *server_resp_buf=NULL; unsigned char *buffer; user_server_port_t *usp=NULL; protocol_t *protocol=NULL; token_t *our_tag=NULL; token_t *client_tag=NULL; size_t server_resp_buf_size=0; flag_t tls_state=0; timed_log_t auth_log; char from_to_host_str[(NI_MAXHOST*2)+2]; char from_host_str[NI_MAXHOST]; char to_host_str[NI_MAXHOST]; char from_serv_str[NI_MAXSERV]; char to_serv_str[NI_MAXSERV]; char *servername=NULL; char *username=NULL; char *port=NULL; char *progname=NULL; io_t *client_io=NULL; io_t *server_io=NULL; FILE *fh; int bytes_written=0; int bytes_read=0; int status; int round_robin_server=0; int rnd; int s=-1; int *g = NULL; int rc; #ifdef WITH_SSL_SUPPORT SSL_CTX *ssl_ctx=NULL; #endif /* WITH_SSL_SUPPORT */ /* * Create Logger */ vl=vanessa_logger_openlog_filehandle(stderr, LOG_IDENT, LOG_DEBUG, VANESSA_LOGGER_F_CONS|VANESSA_LOGGER_F_NO_IDENT_PID); if(!vl) { fprintf(stderr, "main: vanessa_logger_openlog_syslog\n" "Fatal error opening logger. Exiting.\n"); perdition_exit_cleanly(-1); } vanessa_logger_set(vl); /*Parse options*/ options(argc, argv, OPT_FIRST_CALL); /* Initialise setting of proctitle */ init_set_proc_title(argc, argv, envp); progname = strdup(get_progname(argv[0])); if (!progname) { VANESSA_LOGGER_DEBUG_ERRNO("strdup"); VANESSA_LOGGER_ERR("Error initialising process title\n"); perdition_exit_cleanly(-1); } set_proc_title(progname); /* * Update Logger */ if(!opt.debug){ vanessa_logger_change_max_priority(vl, opt.quiet?LOG_ERR:LOG_INFO); } /*Read config file*/ if(opt.config_file!=NULL){ config_file_to_opt(opt.config_file); } /*Open the dbserver_get library, if we have a library*/ if(getserver_openlib(opt.map_library, opt.map_library_opt, &handle, &dbserver_get, &dbserver_get2)<0){ VANESSA_LOGGER_ERR_UNSAFE("dlopen of \"%s\" failed", str_null_safe(opt.map_library)); usage(-1); perdition_exit_cleanly(-1); } /*Set signal handlers*/ signal(SIGHUP, perdition_reread_handler); signal(SIGINT, perdition_exit_cleanly); signal(SIGQUIT, perdition_exit_cleanly); signal(SIGILL, perdition_exit_cleanly); signal(SIGTRAP, perdition_exit_cleanly); signal(SIGIOT, perdition_exit_cleanly); signal(SIGBUS, perdition_exit_cleanly); signal(SIGFPE, perdition_exit_cleanly); signal(SIGUSR1, vanessa_socket_handler_noop); signal(SIGSEGV, perdition_exit_cleanly); signal(SIGUSR2, vanessa_socket_handler_noop); signal(SIGPIPE, SIG_IGN); signal(SIGALRM, perdition_exit_cleanly); signal(SIGTERM, perdition_exit_cleanly); signal(SIGCHLD, vanessa_socket_handler_reaper); signal(SIGURG, perdition_exit_cleanly); signal(SIGXCPU, perdition_exit_cleanly); signal(SIGXFSZ, perdition_exit_cleanly); signal(SIGVTALRM, perdition_exit_cleanly); signal(SIGPROF, perdition_exit_cleanly); signal(SIGWINCH, perdition_exit_cleanly); signal(SIGIO, perdition_exit_cleanly); /* Set file descriptor to log to, if any */ fh = NULL; if(opt.log_facility!=NULL) { if(*(opt.log_facility) == '-') { fh = stdout; } else if(*(opt.log_facility) == '+') { fh = stderr; } } /*Close file descriptors and detach process from shell as necessary*/ if(opt.inetd_mode || opt.no_daemon || fh != NULL){ vanessa_socket_daemon_inetd_process(); } else{ vanessa_socket_daemon_process(); } /* * Re-create logger now process is detached (unless in inetd mode) * and configuration file has been read. */ if(fh != NULL) { vl=vanessa_logger_openlog_filehandle(fh, LOG_IDENT, opt.debug?LOG_DEBUG:(opt.quiet?LOG_ERR:LOG_INFO), VANESSA_LOGGER_F_CONS|VANESSA_LOGGER_F_TIMESTAMP); } else if(opt.log_facility!=NULL && *(opt.log_facility)=='/'){ vl=vanessa_logger_openlog_filename(opt.log_facility, LOG_IDENT, opt.debug?LOG_DEBUG:(opt.quiet?LOG_ERR:LOG_INFO), VANESSA_LOGGER_F_CONS|VANESSA_LOGGER_F_TIMESTAMP); } else { vl=vanessa_logger_openlog_syslog_byname(opt.log_facility, LOG_IDENT, opt.debug?LOG_DEBUG:(opt.quiet?LOG_ERR:LOG_INFO), LOG_CONS); } if(vl == NULL) { VANESSA_LOGGER_DEBUG("vanessa_logger_openlog"); VANESSA_LOGGER_ERR("Fatal error opening logger. Exiting."); perdition_exit_cleanly(-1); } vanessa_logger_closelog(vanessa_logger_get()); vanessa_logger_set(vl); /* Create a PID file */ /*Seed the uname structure*/ if((system_uname=(struct utsname *)malloc(sizeof(struct utsname)))==NULL){ VANESSA_LOGGER_DEBUG_ERRNO("malloc system_uname"); VANESSA_LOGGER_ERR("Fatal error allocating memory. Exiting."); perdition_exit_cleanly(-1); } if(uname(system_uname)<0){ VANESSA_LOGGER_DEBUG("uname"); VANESSA_LOGGER_ERR("Fatal error finding uname for system. Exiting"); perdition_exit_cleanly(-1); } /*Set up protocol structure*/ if((protocol=protocol_initialise(opt.protocol, protocol))==NULL){ VANESSA_LOGGER_DEBUG("protocol_initialise"); VANESSA_LOGGER_ERR("Fatal error initialising protocol. Exiting."); perdition_exit_cleanly(-1); } /*Set listen and outgoing port now the protocol structure is accessable*/ if((opt.listen_port=protocol->port(opt.listen_port))==NULL){ VANESSA_LOGGER_DEBUG("protocol->port 1"); VANESSA_LOGGER_ERR("Fatal error finding port to listen on. Exiting."); perdition_exit_cleanly(-1); } if((opt.outgoing_port=protocol->port(opt.outgoing_port))==NULL){ VANESSA_LOGGER_DEBUG("protocol->port 2"); VANESSA_LOGGER_ERR("Fatal error finding port to connect to. Exiting."); perdition_exit_cleanly(-1); } /* * Set up a tag to use. * Only used for IMAP based protocols, but it is harmless to have it * lying about */ if(opt.protocol == PROTOCOL_IMAP4 || opt.protocol == PROTOCOL_IMAP4S) { our_tag = imap4_tag_create(); if(!our_tag) { VANESSA_LOGGER_DEBUG("imap4_tag_create"); VANESSA_LOGGER_ERR("Fatal error allocating memory. Exiting."); perdition_exit_cleanly(-1); } } else { our_tag = NULL; } #ifdef WITH_SSL_SUPPORT /*Set up the ssl mode */ opt.ssl_mode=protocol->encryption(opt.ssl_mode); opt.capability = protocol->capability(opt.capability, &(opt.mangled_capability), opt.ssl_mode, tls_state); if(opt.ssl_mode & SSL_LISTEN_MASK) { ssl_ctx = perdition_ssl_ctx(opt.ssl_ca_file, opt.ssl_ca_path, opt.ssl_cert_file, opt.ssl_key_file, opt.ssl_ca_chain_file, opt.ssl_listen_ciphers); if(!ssl_ctx) { PERDITION_DEBUG_SSL_ERR("perdition_ssl_ctx"); VANESSA_LOGGER_ERR("Fatal error establishing SSL context for listening"); perdition_exit_cleanly(-1); } } #else opt.capability = protocol->capability(opt.capability, &(opt.mangled_capability), SSL_MODE_NONE, SSL_MODE_NONE); #endif /* WITH_SSL_SUPPORT */ /* * Log the options we will be running with. * If we are in inetd mode then only do this if debugging is turned on, * else debugging is a bit too verbose. */ if((!opt.quiet && !opt.inetd_mode && !opt.no_daemon && !fh) || opt.debug){ if(log_options()){ VANESSA_LOGGER_DEBUG("log_options"); VANESSA_LOGGER_ERR("Fatal error logging options. Exiting."); perdition_exit_cleanly(-1); } } /* Create PID file */ if (!opt.inetd_mode && opt.pid_file && *opt.pid_file) { if(write_pid_file(opt.pid_file, opt.username, opt.group) < 0) { VANESSA_LOGGER_DEBUG("write_pid_file"); VANESSA_LOGGER_ERR("Could not write pid file"); perdition_exit_cleanly(1); } pid_file = opt.pid_file; } /* * If we are using the server's ok line then allocate a buffer to store it */ if(opt.server_resp_line){ if((server_resp_buf=(unsigned char *)malloc( sizeof(unsigned char)*MAX_LINE_LENGTH ))==NULL){ VANESSA_LOGGER_DEBUG_ERRNO("malloc server_resp_buf"); VANESSA_LOGGER_ERR("Fatal error allocating memory. Exiting."); perdition_exit_cleanly(-1); } } /* * Allocate the peername and sockname structures */ sockname = malloc(sizeof(*sockname)); if (!sockname) { VANESSA_LOGGER_DEBUG_ERRNO("malloc sockname"); VANESSA_LOGGER_ERR("Fatal error allocating memory. Exiting."); perdition_exit_cleanly(-1); } peername = malloc(sizeof(*peername)); if (!peername) { VANESSA_LOGGER_DEBUG_ERRNO("malloc peername"); VANESSA_LOGGER_ERR("Fatal error allocating memory. Exiting."); perdition_exit_cleanly(-1); } /* Open incoming socket as required */ if(!opt.inetd_mode) { size_t nfrom; char **fromv; if (opt.bind_address) nfrom = vanessa_dynamic_array_get_count(opt.bind_address); else nfrom = 1; fromv = (char **)malloc(((nfrom * 2) + 1) * sizeof(char *)); if (!fromv) { VANESSA_LOGGER_DEBUG_ERRNO("malloc fromv"); VANESSA_LOGGER_ERR("Fatal error allocating memory. Exiting."); perdition_exit_cleanly(-1); } if (opt.bind_address) { size_t i; user_server_port_t *from_usp; for (i = 0; i < nfrom; i++) { from_usp = vanessa_dynamic_array_get_element( opt.bind_address, i); fromv[i * 2] = user_server_port_get_server(from_usp); fromv[(i * 2) + 1] = user_server_port_get_port( from_usp); if (!fromv[(i * 2) + 1]) fromv[(i * 2) + 1] = opt.listen_port; } } else { fromv[0] = "0.0.0.0"; fromv[1] = opt.listen_port; } fromv[nfrom * 2] = NULL; g = vanessa_socket_server_bindv(fromv, opt.no_lookup?VANESSA_SOCKET_NO_LOOKUP:0); free(fromv); if(!g) { VANESSA_LOGGER_DEBUG("vanessa_socket_server_bindv"); VANESSA_LOGGER_ERR("Fatal error listening for connections." "Exiting."); perdition_exit_cleanly(-1); } } /* * Become someone else * NB: We do this later if we are going to authenticate locally */ #ifdef WITH_PAM_SUPPORT if(opt.authenticate_in) { if(geteuid()){ VANESSA_LOGGER_INFO("Warning: not invoked as root, " "local authentication may fail"); } } else #endif PERDITION_SET_UID_AND_GID; /* Get an incoming connection */ if(opt.inetd_mode){ socklen_t namelen; if((client_io=io_create_fd(0, 1, PERDITION_LOG_STR_CLIENT))==NULL){ VANESSA_LOGGER_DEBUG("io_create_fd 1"); VANESSA_LOGGER_ERR("Fatal error setting IO. Exiting."); perdition_exit_cleanly(-1); } io_set_timeout(client_io, opt.authenticate_timeout); namelen = sizeof(*peername); if (getpeername(0, (struct sockaddr *)peername, &namelen)) { free(peername); peername=NULL; } namelen = sizeof(*sockname); if (getsockname(1, (struct sockaddr *)sockname, &namelen)) { free(sockname); sockname=NULL; } } else{ s = vanessa_socket_server_acceptv(g, opt.connection_limit, (struct sockaddr *) peername, (struct sockaddr *) sockname, 0); if(s < 0){ VANESSA_LOGGER_DEBUG("vanessa_socket_server_accept"); VANESSA_LOGGER_ERR("Fatal error accepting child connection. Exiting."); perdition_exit_cleanly(-1); } /* Child processes don't clean up the pid file */ pid_file = NULL; /* Reopen the logger, the child gets its own FDs */ vanessa_logger_reopen(vanessa_logger_get()); if((client_io=io_create_fd(s, s, PERDITION_LOG_STR_CLIENT))==NULL){ VANESSA_LOGGER_DEBUG("io_create_fd 2"); VANESSA_LOGGER_ERR("Fatal error setting IO. Exiting."); perdition_exit_cleanly(-1); } io_set_timeout(client_io, opt.authenticate_timeout); } /* A child process, or process handling an inetd connection * should exit on receipt of a SIG PIPE. */ signal(SIGPIPE, perdition_exit_cleanly); /* Get the source and destination ip address as a string */ if (peername!=NULL) { rc = getnameinfo((struct sockaddr *)peername, perdition_get_salen((struct sockaddr *)peername), from_host_str, NI_MAXHOST, from_serv_str, NI_MAXSERV, NI_NUMERICHOST|NI_NUMERICSERV); if (rc) { VANESSA_LOGGER_DEBUG_UNSAFE("getnameinfo peername: %s", gai_strerror(rc)); VANESSA_LOGGER_ERR("Fatal error formatting peername"); perdition_exit_cleanly(-1); } } else { *from_host_str='\0'; *from_serv_str='\0'; } if (sockname!=NULL) { rc = getnameinfo((struct sockaddr *)sockname, perdition_get_salen((struct sockaddr *)sockname), to_host_str, NI_MAXHOST, to_serv_str, NI_MAXSERV, NI_NUMERICHOST|NI_NUMERICSERV); if (rc) { VANESSA_LOGGER_DEBUG_UNSAFE("getnameinfo sockname: %s", gai_strerror(rc)); VANESSA_LOGGER_ERR("Fatal error formatting sockname"); perdition_exit_cleanly(-1); } } else { *to_host_str='\0'; *from_host_str='\0'; } *from_to_host_str='\0'; if(peername!=NULL && sockname!=NULL){ strcat(from_to_host_str, " "); strcat(from_to_host_str, from_host_str); strcat(from_to_host_str, "->"); strcat(from_to_host_str, to_host_str); } /*Seed rand*/ srand(time(NULL)*getpid()); rnd=rand(); /*Log the session and change the proctitle*/ if(opt.inetd_mode) { VANESSA_LOGGER_INFO_UNSAFE("Connect:%s inetd_pid=%d", from_to_host_str, getppid()); } else { VANESSA_LOGGER_INFO_UNSAFE("Connect:%s", from_to_host_str); } set_proc_title("%s: connect", progname); #ifdef WITH_SSL_SUPPORT if(opt.ssl_mode & SSL_MODE_SSL_LISTEN) { client_io = perdition_ssl_server_connection(client_io, ssl_ctx); if(!client_io) { VANESSA_LOGGER_DEBUG("perdition_ssl_server_connection SSL"); VANESSA_LOGGER_ERR("Fatal error establishing SSL connection to client"); perdition_exit_cleanly(-1); } } #endif /* WITH_SSL_SUPPORT */ /*Speak to our client*/ if(greeting(client_io, protocol, GREETING_ADD_NODENAME)){ VANESSA_LOGGER_DEBUG("greeting"); VANESSA_LOGGER_ERR_UNSAFE("Fatal error writing to client%s." "Exiting child.", from_to_host_str); perdition_exit_cleanly(-1); } pw.pw_name=NULL; pw.pw_passwd=NULL; /* Authenticate the user*/ for(;;){ /*Read the USER and PASS lines from the client */ status=(*(protocol->in_get_pw))(client_io, &pw, &client_tag); token_flush(); if(status<0){ VANESSA_LOGGER_DEBUG("protocol->in_get_pw"); if (io_get_err(client_io) == io_err_timeout) VANESSA_LOGGER_ERR_UNSAFE("Fatal Error: Timeout reading " "authentication information from " "client%s: Exiting child", from_to_host_str); else VANESSA_LOGGER_ERR_UNSAFE("Fatal Error reading authentication " "information from client%s: " "Exiting child", from_to_host_str); perdition_exit_cleanly(-1); } else if(status == 1){ VANESSA_LOGGER_ERR_UNSAFE("Closing NULL session:%s username=%s", from_to_host_str, str_null_safe(pw.pw_name)); perdition_exit_cleanly(0); } #ifdef WITH_SSL_SUPPORT else if((status == 2) && (opt.ssl_mode & SSL_MODE_TLS_LISTEN)){ /* We have received a STLS */ client_io = perdition_ssl_server_connection(client_io, ssl_ctx); if(!client_io) { VANESSA_LOGGER_DEBUG("perdition_ssl_server_connection TLS"); VANESSA_LOGGER_ERR("Fatal error establishing TLS connection"); perdition_exit_cleanly(-1); } tls_state |= SSL_MODE_TLS_LISTEN; opt.capability = protocol->capability(opt.capability, &(opt.mangled_capability), opt.ssl_mode, tls_state); continue; } else if(opt.login_disabled || ((status == 0) && (opt.ssl_mode & SSL_MODE_TLS_LISTEN) && (opt.ssl_mode & SSL_MODE_TLS_LISTEN_FORCE) && !(tls_state & SSL_MODE_TLS_LISTEN))) { LOGIN_FAILED_PROTOCOL(PROTOCOL_NO, "Login Disabled"); PERDITION_CLEAN_UP_MAIN; continue; } #endif /* WITH_SSL_SUPPORT */ username = username_mangle(pw.pw_name, STATE_GET_SERVER); if (!username) { VANESSA_LOGGER_DEBUG("username_mangle STATE_GET_SERVER"); VANESSA_LOGGER_ERR_UNSAFE("Fatal error manipulating username " "for client \"%s\": Exiting child", from_host_str); perdition_exit_cleanly(-1); } /*Read the server from the map, if we have a map*/ if(dbserver_get || dbserver_get2 || opt.client_server_specification) { usp = getserver(username, from_host_str, to_host_str, from_serv_str, to_serv_str, dbserver_get, dbserver_get2); } if(usp){ port = usp->port; servername = usp->server; if(opt.username_from_database && usp->user){ if (pw.pw_name != username && pw.pw_name != NULL) { free(pw.pw_name); pw.pw_name = NULL; } if((pw.pw_name=strdup(usp->user))==NULL){ VANESSA_LOGGER_DEBUG_ERRNO("strdup"); VANESSA_LOGGER_ERR_UNSAFE("Fatal error manipulating username " "for client \"%s\": Exiting child", from_host_str); } } } /*Use the default server if we have one and the servername is not set*/ if((!servername || !*servername || round_robin_server) && opt.outgoing_server!=NULL){ round_robin_server=1; rnd=(rnd+1)%vanessa_dynamic_array_get_count(opt.outgoing_server); usp=vanessa_dynamic_array_get_element(opt.outgoing_server,rnd); servername=user_server_port_get_server(usp); port=user_server_port_get_port(usp); } /*Use the default port if the port is not set*/ if(!port || !*port) { port=opt.outgoing_port; } /*Try again if we didn't get anything useful*/ if(!servername || !*servername) { LOGIN_FAILED_PROTOCOL(PROTOCOL_ERR, "Could not determine server"); PERDITION_CLEAN_UP_MAIN; continue; } #ifdef WITH_PAM_SUPPORT if(opt.authenticate_in){ pw2.pw_name = username_mangle(pw.pw_name, STATE_LOCAL_AUTH); if (!pw2.pw_name) { VANESSA_LOGGER_DEBUG("username_mangle STATE_LOCAL_AUTH"); VANESSA_LOGGER_ERR_UNSAFE("Fatal error manipulating username for " "client \"%s\": Exiting child", from_host_str); perdition_exit_cleanly(-1); } pw2.pw_passwd=pw.pw_passwd; if((status=protocol->in_authenticate(&pw2, client_io, client_tag))==0){ VANESSA_LOGGER_DEBUG("protocol->in_authenticate"); VANESSA_LOGGER_INFO( "Local authentication failure for client: Allowing retry." ); PERDITION_LOG_AUTH("failed: local authentication failure"); PERDITION_CLEAN_UP_MAIN; continue; } else if(status<0){ VANESSA_LOGGER_DEBUG("pop3_in_authenticate"); VANESSA_LOGGER_ERR( "Fatal error authenticating to client locally. Exiting child." ); perdition_exit_cleanly(-1); } /* * If local authentication is used then now is the time to * Become someone else */ PERDITION_SET_UID_AND_GID; } #endif /* WITH_PAM_SUPPORT */ /* Talk to the real pop server for the client*/ s = vanessa_socket_client_src_open(NULL, NULL, servername, port, opt.no_lookup ? VANESSA_SOCKET_NO_LOOKUP : 0); if(s < 0) { VANESSA_LOGGER_DEBUG("vanessa_socket_client_open"); LOGIN_FAILED_PROTOCOL(PROTOCOL_ERR, "Could not connect to server"); PERDITION_CLEAN_UP_MAIN; continue; } if((server_io=io_create_fd(s, s, PERDITION_LOG_STR_REAL))==NULL){ VANESSA_LOGGER_DEBUG("io_create_fd 3"); VANESSA_LOGGER_ERR("Fatal error setting IO. Exiting."); perdition_exit_cleanly(-1); } io_set_timeout(server_io, opt.authenticate_timeout); #ifdef WITH_SSL_SUPPORT if(opt.ssl_mode & SSL_MODE_SSL_OUTGOING) { server_io=perdition_ssl_client_connection(server_io, opt.ssl_ca_file, opt.ssl_ca_path, opt.ssl_outgoing_ciphers, servername); if(!server_io) { VANESSA_LOGGER_DEBUG("perdition_ssl_connection outgoing"); VANESSA_LOGGER_ERR("Fatal error establishing SSL connection"); perdition_exit_cleanly(-1); } } #endif /* WITH_SSL_SUPPORT */ /* Authenticate the user with the pop server */ pw2.pw_name = username_mangle(pw.pw_name, STATE_REMOTE_LOGIN); if(!pw2.pw_name) { VANESSA_LOGGER_DEBUG("username_mangle STATE_REMOTE_LOGIN"); VANESSA_LOGGER_ERR_UNSAFE("Fatal error manipulating username " "for client \"%s\": Exiting child", from_host_str); perdition_exit_cleanly(-1); } pw2.pw_passwd=pw.pw_passwd; status = (*(protocol->out_setup))(server_io, client_io, &pw2, our_tag, protocol); if(status==0){ quit(server_io, protocol, our_tag); LOGIN_FAILED_PROTOCOL(PROTOCOL_NO, "Connection Negotiation Failure"); PERDITION_CLEAN_UP_MAIN; continue; } else if(status<0){ VANESSA_LOGGER_DEBUG_UNSAFE("protocol->out_setup %d", status); VANESSA_LOGGER_ERR("Fatal error negotiating setup. Exiting child."); perdition_exit_cleanly(-1); } #ifdef WITH_SSL_SUPPORT else if((opt.ssl_mode & SSL_MODE_TLS_OUTGOING) && (status & PROTOCOL_S_STARTTLS)) { server_io=perdition_ssl_client_connection(server_io, opt.ssl_ca_file, opt.ssl_ca_path, opt.ssl_listen_ciphers, servername); if(!server_io) { VANESSA_LOGGER_DEBUG("perdition_ssl_connection outgoing"); VANESSA_LOGGER_ERR("Fatal error establishing SSL connection"); perdition_exit_cleanly(-1); } tls_state |= SSL_MODE_TLS_OUTGOING; } else if((opt.ssl_mode & SSL_MODE_TLS_OUTGOING) && (opt.ssl_mode & SSL_MODE_TLS_OUTGOING_FORCE) && !(status & PROTOCOL_S_STARTTLS)) { quit(server_io, protocol, our_tag); LOGIN_FAILED_PROTOCOL(PROTOCOL_NO, "TLS not present"); PERDITION_CLEAN_UP_MAIN; continue; } #endif /* WITH_SSL_SUPPORT */ if(opt.server_resp_line){ server_resp_buf_size=MAX_LINE_LENGTH-1; } token_flush(); status = (*(protocol->out_authenticate))(server_io, client_io, &pw2, our_tag, protocol, server_resp_buf, &server_resp_buf_size); if(status==0) { quit(server_io, protocol, our_tag); if(opt.server_resp_line){ sleep(PERDITION_AUTH_FAIL_SLEEP); *(server_resp_buf+server_resp_buf_size)='\0'; if(protocol->write(client_io, WRITE_STR_NO_CLLF, client_tag, NULL, 1, "%s", server_resp_buf)<0){ VANESSA_LOGGER_DEBUG("protocol->write"); VANESSA_LOGGER_ERR("Fatal error writing to client. Exiting child."); perdition_exit_cleanly(-1); } PERDITION_LOG_AUTH("failed: Re-Authentication Failure"); } else LOGIN_FAILED_PROTOCOL(PROTOCOL_NO, "Re-Authentication Failure"); PERDITION_CLEAN_UP_MAIN; continue; } if(status==2){ sleep(VANESSA_LOGGER_ERR_SLEEP); LOGIN_FAILED_PROTOCOL(PROTOCOL_NO, "Login Disabled"); PERDITION_CLEAN_UP_MAIN; continue; } else if(status<0){ VANESSA_LOGGER_DEBUG_UNSAFE("protocol->out_authenticate %d", status); if (io_get_err(client_io) == io_err_timeout) VANESSA_LOGGER_ERR("Fatal error: Timeout authenticating user. " "Exiting child."); else VANESSA_LOGGER_ERR("Fatal error authenticating user. Exiting child."); perdition_exit_cleanly(-1); } if(opt.server_resp_line){ *(server_resp_buf+server_resp_buf_size)='\0'; if(protocol->write(client_io, WRITE_STR_NO_CLLF, client_tag, NULL, 1, "%s", server_resp_buf)<0){ VANESSA_LOGGER_DEBUG("protocol->write"); VANESSA_LOGGER_ERR("Fatal error writing to client. Exiting child."); perdition_exit_cleanly(-1); } } else{ if(protocol->write(client_io, NULL_FLAG, client_tag, protocol->type[PROTOCOL_OK], 0, opt.ok_line)<0){ VANESSA_LOGGER_DEBUG("protocol->write"); VANESSA_LOGGER_ERR("Fatal error writing to client. Exiting child."); perdition_exit_cleanly(-1); } } break; } PERDITION_LOG_AUTH("ok"); if(opt.server_resp_line){ free(server_resp_buf); } /*We need a buffer for reads and writes to the server*/ if((buffer=(unsigned char *)malloc(BUFFER_SIZE*sizeof(unsigned char)))==NULL){ VANESSA_LOGGER_DEBUG_ERRNO("malloc"); VANESSA_LOGGER_ERR("Fatal error allocating memory. Exiting child."); perdition_exit_cleanly(-1); } /*Let the client talk to the real server*/ io_set_timeout(client_io, opt.timeout); io_set_timeout(server_io, opt.timeout); if(io_pipe(server_io, client_io, buffer, BUFFER_SIZE, &bytes_written, &bytes_read, &auth_log)<0){ VANESSA_LOGGER_DEBUG("vanessa_socket_pipe"); if (io_get_err(client_io) == io_err_timeout) VANESSA_LOGGER_ERR("Fatal error: Timeout piping data. " "Exiting child."); else VANESSA_LOGGER_ERR("Fatal error piping data. Exiting child."); perdition_exit_cleanly(-1); } /*Time to leave*/ VANESSA_LOGGER_INFO_UNSAFE("Close:%s user=\"%s\" received=%d sent=%d", str_null_safe(from_to_host_str), str_null_safe(pw.pw_name), bytes_read, bytes_written); set_proc_title("%s: close", progname); getserver_closelib(handle); perdition_exit_cleanly(0); /*Here so compilers won't barf*/ return(0); } /********************************************************************** * perdition_reread_handler * A signal handler that closes and opens the map library, * reinitialising as necessary. * pre: sig: signal received by the process * post: signal handler reset for signal * map library closed and opened * This may cause shutdown and initialisation of map to * take place if appropriate symbols are defined in * the library. See getserver.c for details. **********************************************************************/ static void perdition_reread_handler(int sig){ if(vanessa_logger_reopen(vanessa_logger_get()) < 0) { fprintf(stderr, "Fatal error reopening logger. Exiting."); perdition_exit_cleanly(-1); } VANESSA_LOGGER_INFO("Reopened logger"); VANESSA_LOGGER_INFO_UNSAFE("Reloading map library \"%s\" with options \"%s\"", opt.map_library, opt.map_library_opt); getserver_closelib(handle); if( opt.map_library!=NULL && getserver_openlib( opt.map_library, opt.map_library_opt, &handle, &dbserver_get, &dbserver_get2 )<0 ){ VANESSA_LOGGER_DEBUG("getserver_openlib"); VANESSA_LOGGER_ERR_UNSAFE("Fatal error reopening: %s. Exiting child.", opt.map_library); perdition_exit_cleanly(-1); } signal(sig, (void(*)(int))perdition_reread_handler); } /********************************************************************** * perdition_exit_cleanly * Exit perdition, cleaning up as necessary * pre: sig: signal received by the process * post: pid file is removed * process exits **********************************************************************/ static void perdition_exit_cleanly(int i) { if (pid_file && (unlink(opt.pid_file) < 0)) { VANESSA_LOGGER_INFO_UNSAFE("Could not remove pid file " "[%s]: %s\n", opt.pid_file, strerror(errno)); } vanessa_socket_daemon_exit_cleanly(i); } /* XXX: Should be in libvanessa_socket */ static int perdition_chown(const char *path, const char *username, const char *group) { uid_t uid; gid_t gid; struct passwd *pw; struct group *gr; if (vanessa_socket_str_is_digit(group)) { gid = (gid_t) atoi(group); } else { if ((gr = getgrnam(group)) == NULL) { switch (errno) { case 0: case ENOENT: case ESRCH: case EBADF: case EPERM: VANESSA_LOGGER_DEBUG_UNSAFE("getgrnam: " "\"%s\": " "not found", group); break; default: VANESSA_LOGGER_DEBUG_UNSAFE("getgrnam: " "\"%s\": %s", group, strerror(errno)); break; } return (-1); } gid = gr->gr_gid; /*free(gr); */ } if (setgid(gid)) { VANESSA_LOGGER_DEBUG_ERRNO("setgid"); return (-1); } if (vanessa_socket_str_is_digit(username)) { uid = (uid_t) atoi(username); } else { if ((pw = getpwnam(username)) == NULL) { VANESSA_LOGGER_DEBUG_ERRNO("getpwnam"); return (-1); } uid = pw->pw_uid; /*free(pw); */ } if(chown(path, uid, gid) < 0) { VANESSA_LOGGER_DEBUG_ERRNO("chown"); return -1; } return (0); } int create_pid_directory(const char *pidfilename, const char *username, const char *group) { int status; struct stat stat_buf; char *pidfilename_cpy; char *dir; pidfilename_cpy = strdup(pidfilename); if (!pidfilename_cpy) { VANESSA_LOGGER_DEBUG_ERRNO("strdup"); return -1; } dir = dirname(pidfilename_cpy); status = stat(dir, &stat_buf); if (status < 0 && errno != ENOENT && errno != ENOTDIR) { VANESSA_LOGGER_DEBUG_UNSAFE("Could not stat pid-file " "directory [%s]: %s", dir, strerror(errno)); free(pidfilename_cpy); return -1; } if (!status) { if (S_ISDIR(stat_buf.st_mode)) { return 0; } VANESSA_LOGGER_DEBUG_UNSAFE("Pid-File directory exists but is " "not a directory [%s]", dir); free(pidfilename_cpy); return -1; } if (mkdir(dir, S_IRUSR|S_IWUSR|S_IXUSR | S_IRGRP|S_IWGRP|S_IXGRP) < 0) { VANESSA_LOGGER_DEBUG_UNSAFE("Could not create pid-file " "directory [%s]: %s", dir, strerror(errno)); free(pidfilename_cpy); return -1; } if (!geteuid() && perdition_chown(dir, username, group) < 0) { VANESSA_LOGGER_DEBUG("perdition_chown"); free(pidfilename_cpy); return -1; } free(pidfilename_cpy); return 0; } int write_pid_file(const char *pidfilename, const char *username, const char *group) { int pidfilefd; char pidbuf[11]; pid_t pid; size_t bytes; if (create_pid_directory(pidfilename, username, group) < 0) { return -1; } while (1) { pidfilefd = open(pidfilename, O_CREAT|O_EXCL|O_RDWR, S_IRUSR|S_IWUSR); if (pidfilefd < 0) { if (errno != EEXIST) { /* Old PID file */ VANESSA_LOGGER_DEBUG_UNSAFE( "Could not open pid-file " "[%s]: %s", pidfilename, strerror(errno)); return -1; } } else { break; } pidfilefd = open(pidfilename, O_RDONLY, S_IRUSR|S_IWUSR); if (pidfilefd < 0) { VANESSA_LOGGER_DEBUG_UNSAFE("Could not open pid-file " "[%s]: %s", pidfilename, strerror(errno)); return -1; } while (1) { bytes = read(pidfilefd, pidbuf, sizeof(pidbuf)-1); if (bytes < 0) { if (errno == EINTR) { continue; } VANESSA_LOGGER_DEBUG_UNSAFE( "Could not read pid-file " "[%s]: %s", pidfilename, strerror(errno)); close(pidfilefd); return -1; } pidbuf[bytes] = '\0'; break; } close(pidfilefd); if (!bytes) { VANESSA_LOGGER_DEBUG_UNSAFE("Invalid pid in pid-file " "[%s]: %s", pidfilename, strerror(errno)); return -1; } pid = strtoul(pidbuf, NULL, 10); if (pid == ULONG_MAX && errno == ERANGE) { VANESSA_LOGGER_DEBUG_UNSAFE("Invalid pid in pid-file " "[%s]: %s", pidfilename, strerror(errno)); return -1; } if (!kill(pid, 0)) { VANESSA_LOGGER_ERR_UNSAFE("Fatal error: " "Pid file [%s] exists for " "process [%u] which appears to be " "running, exiting", pidfilename, pid); return -1; } else if (errno != ESRCH) { VANESSA_LOGGER_DEBUG_UNSAFE("Error signaling old " "process [%u] from pid-file [%s]: %s", pid, pidfilename, strerror(errno)); return -1; } if(unlink(pidfilename) < 0) { VANESSA_LOGGER_DEBUG_UNSAFE("Could not delete " "pid-file [%s]: %s", pidfilename, strerror(errno)); return -1; } VANESSA_LOGGER_INFO_UNSAFE("Removed stale pid-file [%s]", pidfilename); } if (!geteuid() && perdition_chown(pidfilename, username, group) < 0) { VANESSA_LOGGER_DEBUG("perdition_chown"); goto unlink; } if (chmod(pidfilename, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) < 0) { VANESSA_LOGGER_DEBUG_ERRNO("chmod"); goto unlink; } if (snprintf(pidbuf, sizeof(pidbuf), "%u", getpid()) >= sizeof(pidbuf)) { VANESSA_LOGGER_DEBUG_UNSAFE("Pid too long for buffer [%u]", getpid()); goto unlink; } while (1) { bytes = write(pidfilefd, pidbuf, strlen(pidbuf)); if (bytes != strlen(pidbuf)) { if (bytes < 0 && errno == EINTR) { continue; } VANESSA_LOGGER_DEBUG_UNSAFE("Could not write pid-file " "[%s]: %s", pidfilename, strerror(errno)); goto unlink; } break; } close(pidfilefd); return 0; unlink: close(pidfilefd); if(unlink(pidfilename) < 0) VANESSA_LOGGER_DEBUG_ERRNO("unlink"); return -1; }