├── src ├── xgetloadavg.h ├── init.h ├── includedir.h ├── reconfig.h ├── inet.h ├── confparse.h ├── redirect.h ├── retry.h ├── ident.h ├── internals.h ├── logctl.h ├── tcpint.h ├── udpint.h ├── env.h ├── special.h ├── parsesup.h ├── main.h ├── nvlists.h ├── timex.h ├── sensor.h ├── child.h ├── msg.h ├── signals.h ├── xtimer.h ├── str │ ├── strparse.h │ ├── str.h │ ├── strutil.c │ ├── strprint.c │ └── strparse.c ├── options.h ├── xpoll.h ├── xlog │ ├── slog.h │ ├── util.c │ ├── filelog.h │ ├── xlog.h │ ├── impl.h │ └── slog.c ├── sconst.h ├── addr.h ├── intcommon.h ├── conf.h ├── util.h ├── portable │ ├── libportable.h │ └── cvt.c ├── misc │ ├── m_env.h │ └── m_env.c ├── mask.h ├── builtins.h ├── parse.h ├── pset │ ├── ops.c │ ├── pset.h │ └── pset.c ├── access.h ├── log.h ├── int.h ├── attr.h ├── connection.h ├── xgetloadavg.c ├── state.h ├── server.h ├── special.c ├── xconv.pl ├── parsers.h ├── sio │ ├── impl.h │ ├── sioconf.h │ └── sio.h ├── time.c ├── xtimer.c ├── includedir.c ├── nvlists.c ├── options.c ├── logctl.c ├── env.c └── parsesup.c ├── autogen.sh ├── contrib ├── xinetd.d │ ├── echo │ ├── chargen │ ├── daytime │ ├── discard │ ├── echo-udp │ ├── servers │ ├── services │ ├── chargen-udp │ ├── daytime-udp │ ├── discard-udp │ ├── time │ └── time-udp ├── xinetd.service ├── empty.conf ├── xinetd.conf └── xinetd ├── .editorconfig ├── .travis.yml ├── .github └── workflows │ ├── coverity.yml │ └── build-ci.yml ├── man ├── itox.8 ├── strutil.3 ├── psi.3 ├── m_env.3 ├── xinetd.log.5 ├── strprint.3 ├── strparse.3 ├── xconv.pl.8 └── Sprint.3 ├── .gitignore ├── COPYRIGHT ├── README.md ├── m4 ├── ax_check_link_flag.m4 └── ax_check_compile_flag.m4 └── Makefile.am /src/xgetloadavg.h: -------------------------------------------------------------------------------- 1 | #ifndef XGETLOADAVG_H 2 | #define XGETLOADAVG_H 3 | 4 | 5 | double xgetloadavg(void); 6 | 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/init.h: -------------------------------------------------------------------------------- 1 | #ifndef INIT_H 2 | #define INIT_H 3 | 4 | 5 | void init_daemon(int argc,char *argv[]); 6 | void init_services(void); 7 | 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | CURDIR=$(pwd) 6 | SCRIPT_DIR=$(cd $(dirname $0); pwd) 7 | 8 | cd $SCRIPT_DIR 9 | 10 | autoreconf -v -i -f 11 | -------------------------------------------------------------------------------- /src/includedir.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDEDIR_H 2 | #define INCLUDEDIR_H 3 | 4 | #include "conf.h" 5 | 6 | void handle_includedir(const char *service_name,struct configuration *confp); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/reconfig.h: -------------------------------------------------------------------------------- 1 | #ifndef RECONFIG_H 2 | #define RECONFIG_H 3 | 4 | #include "defs.h" 5 | 6 | void hard_reconfig(void); 7 | void terminate_servers(struct service *sp); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /src/inet.h: -------------------------------------------------------------------------------- 1 | #ifndef X_INET_H 2 | #define X_INET_H 3 | 4 | #include "pset.h" 5 | #include "sconf.h" 6 | #include "conf.h" 7 | 8 | void parse_inet_conf_file(int fd,struct configuration *confp); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/confparse.h: -------------------------------------------------------------------------------- 1 | #ifndef CONFPARSE_H 2 | #define CONFPARSE_H 3 | 4 | #include "defs.h" 5 | #include "conf.h" 6 | #include "xconfig.h" 7 | 8 | status_e cnf_get(struct configuration *confp); 9 | 10 | #endif 11 | 12 | -------------------------------------------------------------------------------- /src/redirect.h: -------------------------------------------------------------------------------- 1 | #ifndef REDIRECT_H 2 | #define REDIRECT_H 3 | 4 | #include "server.h" 5 | 6 | #ifdef __GNUC__ 7 | __attribute__ ((noreturn)) 8 | #endif 9 | void redir_handler(struct server *serp); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /src/retry.h: -------------------------------------------------------------------------------- 1 | #ifndef RETRY_H 2 | #define RETRY_H 3 | 4 | #include "config.h" 5 | #include "defs.h" 6 | 7 | status_e schedule_retry(struct server *serp); 8 | void cancel_service_retries(struct service *sp); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /src/ident.h: -------------------------------------------------------------------------------- 1 | #ifndef IDENT_H 2 | #define IDENT_H 3 | 4 | #include "defs.h" 5 | 6 | idresult_e log_remote_user(const struct server *serp,unsigned timeout); 7 | const char *idresult_explain(idresult_e result); 8 | 9 | #endif 10 | 11 | -------------------------------------------------------------------------------- /src/internals.h: -------------------------------------------------------------------------------- 1 | #ifndef INTERNALS_H 2 | #define INTERNALS_H 3 | 4 | #include "config.h" 5 | #include "defs.h" 6 | 7 | void dump_internal_state(void); 8 | void user_requested_check(void); 9 | void enable_periodic_check( unsigned ); 10 | #endif 11 | -------------------------------------------------------------------------------- /src/logctl.h: -------------------------------------------------------------------------------- 1 | #ifndef LOGCTL_H 2 | #define LOGCTL_H 3 | 4 | #include "defs.h" 5 | #include "xlog.h" 6 | #include "log.h" 7 | 8 | status_e log_start(struct service *sp,xlog_h *xhp); 9 | void log_end(struct log *lp,xlog_h xh); 10 | 11 | #endif 12 | 13 | -------------------------------------------------------------------------------- /src/tcpint.h: -------------------------------------------------------------------------------- 1 | #ifndef TCPINT_H 2 | #define TCPINT_H 3 | 4 | #include "defs.h" 5 | #include "int.h" 6 | 7 | #ifdef __GNUC__ 8 | __attribute__ ((noreturn)) 9 | #endif 10 | void si_exit(void); 11 | struct intercept_s *si_init(struct server *serp); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /src/udpint.h: -------------------------------------------------------------------------------- 1 | #ifndef UDPINT_H 2 | #define UDPINT_H 3 | 4 | #include "defs.h" 5 | #include "int.h" 6 | 7 | #ifdef __GNUC__ 8 | __attribute__ ((noreturn)) 9 | #endif 10 | void di_exit(void); 11 | struct intercept_s *di_init(struct server *serp); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /src/env.h: -------------------------------------------------------------------------------- 1 | #ifndef X_ENV_H 2 | #define X_ENV_H 3 | 4 | #include "m_env.h" 5 | #include "defs.h" 6 | #include "sconf.h" 7 | 8 | extern env_h std_env; 9 | status_e initenv(void); 10 | status_e setup_environ(struct service_config *scp,struct service_config *def); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /src/special.h: -------------------------------------------------------------------------------- 1 | #ifndef SPECIAL_H 2 | #define SPECIAL_H 3 | 4 | #include "defs.h" 5 | #include "builtins.h" 6 | 7 | const builtin_s *spec_find(const char *service_name,int type); 8 | status_e spec_service_handler( struct service *sp, connection_s *cp ); 9 | void spec_include(void); 10 | 11 | #endif 12 | 13 | -------------------------------------------------------------------------------- /src/parsesup.h: -------------------------------------------------------------------------------- 1 | #ifndef PARSESUP_H 2 | #define PARSESUP_H 3 | 4 | #include "parse.h" 5 | 6 | char *next_line(int fd); 7 | status_e parse_line( char *line, char **namep, enum assign_op *opp, 8 | pset_h values); 9 | void skip_entry(int fd); 10 | int line_has_only_1_char(const char *line, char ch); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /contrib/xinetd.d/echo: -------------------------------------------------------------------------------- 1 | # default: off 2 | # description: An echo server. This is the tcp version. 3 | 4 | service echo 5 | { 6 | type = INTERNAL 7 | id = echo-stream 8 | socket_type = stream 9 | protocol = tcp 10 | user = root 11 | wait = no 12 | disable = yes 13 | } 14 | -------------------------------------------------------------------------------- /contrib/xinetd.d/chargen: -------------------------------------------------------------------------------- 1 | # default: off 2 | # description: A chargen server. This is the tcp version. 3 | 4 | service chargen 5 | { 6 | type = INTERNAL 7 | id = chargen-stream 8 | socket_type = stream 9 | protocol = tcp 10 | user = root 11 | wait = no 12 | disable = yes 13 | } 14 | -------------------------------------------------------------------------------- /contrib/xinetd.d/daytime: -------------------------------------------------------------------------------- 1 | # default: off 2 | # description: A daytime server. This is the tcp version. 3 | 4 | service daytime 5 | { 6 | type = INTERNAL 7 | id = daytime-stream 8 | socket_type = stream 9 | protocol = tcp 10 | user = root 11 | wait = no 12 | disable = yes 13 | } 14 | -------------------------------------------------------------------------------- /contrib/xinetd.d/discard: -------------------------------------------------------------------------------- 1 | # default: off 2 | # description: A discard server. This is the tcp version. 3 | 4 | service discard 5 | { 6 | type = INTERNAL 7 | id = discard-stream 8 | socket_type = stream 9 | protocol = tcp 10 | user = root 11 | wait = no 12 | disable = yes 13 | } 14 | -------------------------------------------------------------------------------- /contrib/xinetd.d/echo-udp: -------------------------------------------------------------------------------- 1 | # default: off 2 | # description: An echo server. This is the udp version. 3 | 4 | service echo 5 | { 6 | type = INTERNAL UNLISTED 7 | id = echo-dgram 8 | socket_type = dgram 9 | protocol = udp 10 | user = root 11 | wait = yes 12 | disable = yes 13 | port = 7 14 | } 15 | -------------------------------------------------------------------------------- /contrib/xinetd.d/servers: -------------------------------------------------------------------------------- 1 | # default: off 2 | # description: An internal xinetd service, listing active servers. 3 | 4 | service servers 5 | { 6 | type = INTERNAL UNLISTED 7 | port = 9099 8 | socket_type = stream 9 | protocol = tcp 10 | wait = no 11 | disable = yes 12 | only_from = 127.0.0.1 13 | } 14 | -------------------------------------------------------------------------------- /contrib/xinetd.d/services: -------------------------------------------------------------------------------- 1 | # default: off 2 | # description: An internal xinetd service, listing active services. 3 | 4 | service services 5 | { 6 | type = INTERNAL UNLISTED 7 | port = 9098 8 | socket_type = stream 9 | protocol = tcp 10 | wait = no 11 | disable = yes 12 | only_from = 127.0.0.1 13 | } 14 | -------------------------------------------------------------------------------- /contrib/xinetd.d/chargen-udp: -------------------------------------------------------------------------------- 1 | # default: off 2 | # description: A chargen server. This is the udp version. 3 | 4 | service chargen 5 | { 6 | type = INTERNAL UNLISTED 7 | id = chargen-dgram 8 | socket_type = dgram 9 | protocol = udp 10 | user = root 11 | wait = yes 12 | disable = yes 13 | port = 19 14 | } 15 | -------------------------------------------------------------------------------- /contrib/xinetd.d/daytime-udp: -------------------------------------------------------------------------------- 1 | # default: off 2 | # description: A daytime server. This is the udp version. 3 | 4 | service daytime 5 | { 6 | type = INTERNAL UNLISTED 7 | id = daytime-dgram 8 | socket_type = dgram 9 | protocol = udp 10 | user = root 11 | wait = yes 12 | disable = yes 13 | port = 13 14 | } 15 | -------------------------------------------------------------------------------- /contrib/xinetd.d/discard-udp: -------------------------------------------------------------------------------- 1 | # default: off 2 | # description: A discard server. This is the udp version. 3 | 4 | service discard 5 | { 6 | type = INTERNAL UNLISTED 7 | id = discard-dgram 8 | socket_type = dgram 9 | protocol = udp 10 | user = root 11 | wait = yes 12 | disable = yes 13 | port = 9 14 | } 15 | -------------------------------------------------------------------------------- /contrib/xinetd.d/time: -------------------------------------------------------------------------------- 1 | # default: off 2 | # description: An RFC 868 time server. This is the tcp version, 3 | # which is used by rdate. 4 | 5 | service time 6 | { 7 | type = INTERNAL 8 | id = time-stream 9 | socket_type = stream 10 | protocol = tcp 11 | user = root 12 | wait = no 13 | disable = yes 14 | } 15 | -------------------------------------------------------------------------------- /contrib/xinetd.d/time-udp: -------------------------------------------------------------------------------- 1 | # default: off 2 | # description: An RFC 868 time server. This is the udp version. 3 | 4 | service time 5 | { 6 | type = INTERNAL UNLISTED 7 | id = time-dgram 8 | socket_type = dgram 9 | protocol = udp 10 | user = root 11 | wait = yes 12 | disable = yes 13 | port = 37 14 | } 15 | -------------------------------------------------------------------------------- /src/main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H 2 | #define MAIN_H 3 | 4 | #include "state.h" 5 | #include "defs.h" 6 | 7 | extern char program_version[]; 8 | extern struct program_state ps; 9 | extern int signals_pending[2]; 10 | #ifdef __GNUC__ 11 | __attribute__ ((noreturn)) 12 | #endif 13 | void quit_program(void); 14 | #ifdef __GNUC__ 15 | __attribute__ ((noreturn)) 16 | #endif 17 | void terminate_program(void); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /contrib/xinetd.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Xinetd A Powerful Replacement For Inetd 3 | After=network.target 4 | Documentation=man:xinetd 5 | Documentation=man:xinetd.conf 6 | Documentation=man:xinetd.log 7 | 8 | [Service] 9 | Type=simple 10 | ExecStart=/usr/sbin/xinetd -stayalive -dontfork 11 | ExecReload=/usr/bin/kill -HUP $MAINPID 12 | Restart=on-failure 13 | RestartSec=2 14 | 15 | [Install] 16 | WantedBy=multi-user.target 17 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: https://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | [*] 7 | end_of_line = lf 8 | insert_final_newline = true 9 | 10 | [*.{c,h}] 11 | indent_style = space 12 | indent_size = 3 13 | 14 | [*.yml] 15 | indent_style = space 16 | indent_size = 2 17 | 18 | [Makefile*] 19 | indent_style = tab 20 | indent_size = 8 21 | 22 | [configure.ac] 23 | indent_style = space 24 | indent_size = 4 25 | -------------------------------------------------------------------------------- /src/nvlists.h: -------------------------------------------------------------------------------- 1 | #ifndef NVLISTS_H 2 | #define NVLISTS_H 3 | 4 | #include "defs.h" 5 | 6 | extern const struct name_value service_types[]; 7 | extern const struct name_value service_flags[]; 8 | extern const struct name_value socket_types[]; 9 | extern const struct name_value success_log_options[]; 10 | extern const struct name_value failure_log_options[]; 11 | extern const struct name_value syslog_facilities[]; 12 | extern const struct name_value syslog_levels[]; 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/timex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1998-2001 by Rob Braun 3 | * All rights reserved. The file named COPYRIGHT specifies the terms 4 | * and conditions for redistribution. 5 | */ 6 | #ifndef _X_TIME 7 | #define _X_TIME 8 | 9 | #include "pset.h" 10 | #include "defs.h" 11 | 12 | bool_int ti_current_time_check(const pset_h intervals); 13 | status_e ti_add(pset_h iset,const char *interval_str); 14 | void ti_dump(pset_h iset,int fd); 15 | void ti_free(pset_h iset); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | arch: 3 | - ppc64le 4 | 5 | language: c 6 | 7 | os: 8 | - linux 9 | 10 | compiler: 11 | - clang 12 | - gcc 13 | 14 | before_install: 15 | - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install -y libtirpc-dev libwrap0-dev libselinux-dev ; fi 16 | 17 | script: 18 | - sh autogen.sh 19 | - ./configure --without-libwrap --without-labeled-networking --without-loadavg 20 | - make 21 | - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then make distcheck ; fi 22 | -------------------------------------------------------------------------------- /src/sensor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 2001-2002 by Steve Grubb 3 | * All rights reserved. The file named COPYRIGHT specifies the terms 4 | * and conditions for redistribution. 5 | */ 6 | 7 | #ifndef SENSOR_H 8 | #define SENSOR_H 9 | 10 | #include "defs.h" 11 | #include "service.h" 12 | 13 | void init_sensor( void ); 14 | void process_sensor( const struct service *, const union xsockaddr *); 15 | status_e check_sensor( const union xsockaddr * ); 16 | void destroy_global_access_list( void ); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /src/child.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1998-2001 by Rob Braun 3 | * All rights reserved. The file named COPYRIGHT specifies the terms 4 | * and conditions for redistribution. 5 | */ 6 | #ifndef _X_CHILD 7 | #define _X_CHILD 8 | 9 | #include "defs.h" 10 | 11 | #ifdef __GNUC__ 12 | __attribute__ ((noreturn)) 13 | #endif 14 | void child_process(struct server *serp); 15 | void child_exit(void); 16 | #ifdef __GNUC__ 17 | __attribute__ ((noreturn)) 18 | #endif 19 | void exec_server( const struct server *serp ); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/msg.h: -------------------------------------------------------------------------------- 1 | #ifndef MSG_H 2 | #define MSG_H 3 | 4 | #include 5 | 6 | const char *msg_init(void); 7 | void msg_suspend(void); 8 | void msg_resume(void); 9 | void msg(int level,const char *func,const char *fmt,...) 10 | #ifdef __GNUC__ 11 | __attribute__ ((format (printf, 3, 4))); 12 | #else 13 | ; 14 | #endif 15 | void parsemsg(int msg_level,const char *func,const char *fmt,...) 16 | #ifdef __GNUC__ 17 | __attribute__ ((format (printf, 3, 4))); 18 | #else 19 | ; 20 | #endif 21 | #endif 22 | -------------------------------------------------------------------------------- /src/signals.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1998-2001 by Rob Braun 3 | * All rights reserved. The file named COPYRIGHT specifies the terms 4 | * and conditions for redistribution. 5 | */ 6 | #ifndef _X_SIGNALS 7 | #define _X_SIGNALS 8 | 9 | #include "defs.h" 10 | 11 | #if defined(NO_POSIX_SIGS) 12 | int sigprocmask(int how,sigset_t *set,sigset_t *oset); 13 | int sigaction(int sig,struct sigaction *sap,struct sigaction *osap); 14 | #endif 15 | status_e signal_init(void); 16 | char *sig_name(int sig); 17 | void signal_default_state(void); 18 | void check_pipe(void); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /src/xtimer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1998-2001 by Rob Braun 3 | * All rights reserved. The file named COPYRIGHT specifies the terms 4 | * and conditions for redistribution. 5 | */ 6 | 7 | #ifndef _X_TIMER_H 8 | #define _X_TIMER_H 9 | 10 | #include 11 | #include 12 | 13 | struct xtime { 14 | void (*timerfunc)(void); 15 | time_t when; 16 | int xtid; 17 | }; 18 | typedef struct xtime xtime_h; 19 | 20 | int xtimer_add( void (*func)(void), time_t ); 21 | int xtimer_poll(void); 22 | int xtimer_remove(int); 23 | time_t xtimer_nexttime(void); 24 | 25 | #endif /* _X_TIMER_H */ 26 | -------------------------------------------------------------------------------- /src/str/strparse.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis 3 | * All rights reserved. The file named COPYRIGHT specifies the terms 4 | * and conditions for redistribution. 5 | */ 6 | 7 | #ifndef __STRPARSE_H 8 | #define __STRPARSE_H 9 | 10 | /* 11 | * $Id$ 12 | */ 13 | 14 | struct str_handle 15 | { 16 | char *string ; 17 | char *separator ; 18 | char *pos ; 19 | int flags ; 20 | int *errnop ; 21 | int no_more ; 22 | } ; 23 | 24 | 25 | #ifndef NULL 26 | #define NULL 0 27 | #endif 28 | 29 | #ifndef FALSE 30 | #define FALSE 0 31 | #define TRUE 1 32 | #endif 33 | 34 | #endif /* __STRPARSE_H */ 35 | 36 | -------------------------------------------------------------------------------- /src/options.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992 by Panagiotis Tsirigotis 3 | * (c) Sections Copyright 1998-2001 by Rob Braun 4 | * All rights reserved. The file named COPYRIGHT specifies the terms 5 | * and conditions for redistribution. 6 | */ 7 | 8 | #ifndef OPTIONS_H 9 | #define OPTIONS_H 10 | 11 | 12 | 13 | extern int filelog_option; 14 | extern char *filelog_option_arg; 15 | extern int syslog_option; 16 | extern char *syslog_option_arg; 17 | extern int logprocs_option; 18 | extern unsigned logprocs_option_arg; 19 | extern int stayalive_option; 20 | extern char *program_name; 21 | extern int dont_fork; 22 | 23 | int opt_recognize(int argc,char *argv[]); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /src/xpoll.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 2009 by Red Hat Inc. 3 | * All rights reserved. The file named COPYRIGHT specifies the terms 4 | * and conditions for redistribution. 5 | */ 6 | #include "config.h" 7 | #ifdef HAVE_POLL 8 | #ifndef _X_POLL_H 9 | #define _X_POLL_H 10 | 11 | #include 12 | #include "defs.h" 13 | 14 | 15 | /* Field accessor methods for pollfd in defined in poll.h */ 16 | #define POLLFD_FD( pfd ) ( (pfd)->fd ) 17 | #define POLLFD_EVENTS( pfd ) ( (pfd)->events ) 18 | #define POLLFD_REVENTS( pfd ) ( (pfd)->revents ) 19 | 20 | /* TODO: write memory management stuff in xpoll.c if needed */ 21 | 22 | #endif /* _X_POLL_H */ 23 | #endif /* HAVE_POLL */ 24 | -------------------------------------------------------------------------------- /.github/workflows/coverity.yml: -------------------------------------------------------------------------------- 1 | # GitHub actions workflow. 2 | # https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions 3 | 4 | # https://scan.coverity.com/projects/opensuse-xinetd 5 | name: Coverity Scan 6 | 7 | on: 8 | push: 9 | branches: [master, gh-actions] 10 | 11 | jobs: 12 | coverity: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v3 16 | - run: ./autogen.sh 17 | - run: ./configure --disable-silent-rules --without-libwrap --without-labeled-networking --without-loadavg 18 | 19 | - uses: vapier/coverity-scan-action@v1 20 | with: 21 | email: ${{ secrets.COVERITY_SCAN_EMAIL }} 22 | token: ${{ secrets.COVERITY_SCAN_TOKEN }} 23 | -------------------------------------------------------------------------------- /src/xlog/slog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis 3 | * All rights reserved. The file named COPYRIGHT specifies the terms 4 | * and conditions for redistribution. 5 | */ 6 | 7 | 8 | /* 9 | * $Id$ 10 | */ 11 | #ifndef __SLOG_H 12 | #define __SLOG_H 13 | 14 | struct syslog_s 15 | { 16 | int sl_facility ; 17 | int sl_default_level ; 18 | } ; 19 | 20 | 21 | struct syslog_parms 22 | { 23 | int slp_n_xlogs ; /* # of xlogs using syslog */ 24 | int slp_logopts ; /* used at openlog */ 25 | int slp_facility ; 26 | const char *slp_ident ; /* used at openlog */ 27 | /* bool_int slp_ident_is_malloced ; */ 28 | } ; 29 | 30 | #define SYSLOG( xp ) ((struct syslog_s *)xp->xl_data) 31 | 32 | #endif 33 | 34 | -------------------------------------------------------------------------------- /src/sconst.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992 by Panagiotis Tsirigotis 3 | * (c) Sections Copyright 1998-2001 by Rob Braun 4 | * All rights reserved. The file named COPYRIGHT specifies the terms 5 | * and conditions for redistribution. 6 | */ 7 | 8 | #ifndef SCONST_H 9 | #define SCONST_H 10 | 11 | /* 12 | * $Id$ 13 | */ 14 | 15 | /* 16 | * Names of internal non-visible services 17 | */ 18 | #define INTERCEPT_SERVICE_NAME "intercept" 19 | #define LOG_SERVICE_NAME "logging" 20 | 21 | 22 | /* 23 | * Log entry ids 24 | */ 25 | #define START_ENTRY "START" 26 | #define FAIL_ENTRY "FAIL" 27 | #define EXIT_ENTRY "EXIT" 28 | #define USERID_ENTRY "USERID" 29 | #define NOID_ENTRY "NOID" 30 | 31 | #endif /* SCONST_H */ 32 | 33 | -------------------------------------------------------------------------------- /man/itox.8: -------------------------------------------------------------------------------- 1 | .TH ITOX 8 "March 2005" "xinetd" 2 | .SH NAME 3 | itox \- converts inetd.conf style configuration files to xinetd.conf 4 | .SH SYNOPSIS 5 | itox [\-daemon_dir ] 6 | .SH DESCRIPTION 7 | .B itox 8 | takes on its standard input inetd.conf style entries and dumps to 9 | standard output the corresponding xinetd.conf style entries. 10 | .SH OPTIONS 11 | .TP 12 | .I \-daemon_dir 13 | If you use tcpd, this option specifies the directory where all the daemons are. 14 | You must specify this option if you use tcpd and the daemon file names are not 15 | absolute. 16 | .SH EXAMPLES 17 | itox \-daemon_dir /usr/sbin < inetd.conf > xinetd.conf 18 | .SH AUTHOR 19 | xinetd and itox were written by Panagiotis Tsirigotis. 20 | .sp 21 | This man page was written by Norbert Veber and Thomas Seyrat 22 | 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | *.orig 3 | *.rej 4 | *.o 5 | *.lo 6 | *.la 7 | *~ 8 | *.swp 9 | 10 | # Makefiles 11 | 12 | Makefile 13 | Makefile.in 14 | .deps 15 | .dirstamp 16 | 17 | # http://www.gnu.org/software/autoconf 18 | 19 | /autom4te.cache 20 | /autoscan.log 21 | /autoscan-*.log 22 | /aclocal.m4 23 | /compile 24 | /config.guess 25 | /config.h.in 26 | /config.h 27 | /config.status 28 | /config.sub 29 | /config.log 30 | /configure 31 | /configure.scan 32 | /depcomp 33 | /install-sh 34 | /missing 35 | /stamp-h1 36 | 37 | # https://www.gnu.org/software/libtool/ 38 | 39 | .libs 40 | /ltmain.sh 41 | /libtool 42 | m4/libtool.m4 43 | m4/ltoptions.m4 44 | m4/ltsugar.m4 45 | m4/ltversion.m4 46 | m4/lt~obsolete.m4 47 | 48 | # http://www.gnu.org/software/texinfo 49 | 50 | /texinfo.tex 51 | 52 | # output binaries 53 | xinetd 54 | itox 55 | 56 | # tarballs 57 | *.tar.* 58 | -------------------------------------------------------------------------------- /src/addr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992 by Panagiotis Tsirigotis 3 | * (c) Copyright 1998-2001 by Rob Braun 4 | * All rights reserved. The file named COPYRIGHT specifies the terms 5 | * and conditions for redistribution. 6 | */ 7 | 8 | #ifndef ADDR_H 9 | #define ADDR_H 10 | 11 | /* 12 | * $Id$ 13 | */ 14 | 15 | 16 | #include "pset.h" 17 | #include "defs.h" 18 | #ifdef HAVE_STDINT_H 19 | #include 20 | #endif 21 | 22 | int addrlist_match(const pset_h addr_list, const struct sockaddr *addr); 23 | void addrlist_dump(const pset_h addr_list, int fd); 24 | void addrlist_free(pset_h addr_list); 25 | status_e addrlist_add(pset_h addr_list, const char *str_addr); 26 | status_e addrlist_remove(pset_h addr_list, const char *str_addr); 27 | status_e addrlist_copy(const pset_h from, pset_h *to); 28 | int check_hostname(const char *addr); 29 | 30 | #endif /* ADDR_H */ 31 | 32 | -------------------------------------------------------------------------------- /src/intcommon.h: -------------------------------------------------------------------------------- 1 | #ifndef INTCOMMON_H 2 | #define INTCOMMON_H 3 | 4 | #include "config.h" 5 | #include 6 | #ifdef HAVE_POLL 7 | #include 8 | #endif 9 | #include "int.h" 10 | 11 | #ifdef __GNUC__ 12 | __attribute__ ((noreturn)) 13 | #endif 14 | void int_fail(const struct intercept_s *ip,const char *lsyscall); 15 | #ifdef HAVE_POLL 16 | int int_poll(int pfds_last, struct pollfd *pfd_array); 17 | #else 18 | int int_select(int max,fd_set *read_mask); 19 | #endif 20 | #ifdef __GNUC__ 21 | __attribute__ ((noreturn)) 22 | #endif 23 | void int_exit(struct intercept_s *ip); 24 | void int_init(struct intercept_s *ip,struct server *serp); 25 | 26 | channel_s *int_newconn( struct intercept_s *ip, union xsockaddr *sinp, 27 | int remote_socket ); 28 | channel_s *int_lookupconn( struct intercept_s *ip, union xsockaddr *sinp, 29 | bool_int *addr_checked ); 30 | #endif 31 | 32 | -------------------------------------------------------------------------------- /src/conf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992 by Panagiotis Tsirigotis 3 | * (c) Sections Copyright 1998-2001 by Rob Braun 4 | * All rights reserved. The file named COPYRIGHT specifies the terms 5 | * and conditions for redistribution. 6 | */ 7 | 8 | #ifndef CONF_H 9 | #define CONF_H 10 | 11 | /* 12 | * $Id$ 13 | */ 14 | 15 | 16 | #include "pset.h" 17 | #include "sconf.h" 18 | 19 | 20 | struct configuration 21 | { 22 | pset_h cnf_service_confs ; 23 | struct service_config *cnf_defaults ; 24 | } ; 25 | 26 | #define CNF_DEFAULTS( confp ) (confp)->cnf_defaults 27 | #define CNF_SERVICE_CONFS( confp ) (confp)->cnf_service_confs 28 | 29 | void cnf_free(struct configuration *confp); 30 | struct service_config *cnf_extract(struct configuration *confp,struct service_config *scp); 31 | void cnf_dump(struct configuration *confp,int fd); 32 | status_e cnf_init(struct configuration *confp,int *fdp,psi_h *iterp); 33 | unsigned cnf_start_services(struct configuration *confp); 34 | 35 | 36 | #endif /* CONF_H */ 37 | 38 | -------------------------------------------------------------------------------- /src/util.h: -------------------------------------------------------------------------------- 1 | #ifndef UTIL_H 2 | #define UTIL_H 3 | 4 | #include "pset.h" 5 | #include "defs.h" 6 | 7 | void out_of_memory(const char *func); 8 | const struct name_value *nv_find_value(const struct name_value nv_array[],const char *name); 9 | const struct name_value *nv_find_name(const struct name_value nv_array[],int value); 10 | const char *nv_get_name(const struct name_value nv_array[],int value); 11 | char **argv_alloc(unsigned count); 12 | status_e copy_pset(const pset_h from,pset_h *to,unsigned size); 13 | void no_control_tty(void); 14 | status_e write_buf(int fd,const char *buf,int len); 15 | void tabprint(int fd, int tab_level, const char *fmt, ...) 16 | #ifdef __GNUC__ 17 | __attribute__ ((format (printf, 3, 4))); 18 | #else 19 | ; 20 | #endif 21 | void drain(int sd); 22 | int parse_int(const char *, int , int , int *); 23 | int parse_uint(const char *, int , int , unsigned int *); 24 | int parse_ull(const char *, int , int , unsigned long long *); 25 | int parse_base10(const char *, int *); 26 | int parse_ubase10(const char *, unsigned int *); 27 | bool_int parse_all_digits(const char *ptr); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /src/portable/libportable.h: -------------------------------------------------------------------------------- 1 | #ifndef _XINETD_LIBPORTABLE 2 | #define _XINETD_LIBPORTABLE 1 3 | 4 | #include "config.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #ifndef IPV6_ADDRFORM 11 | #define IPV6_ADDRFORM 1 12 | #endif 13 | 14 | #ifndef NI_MAXHOST 15 | #define NI_MAXHOST 1025 16 | #endif 17 | 18 | #ifndef APPEND 19 | #define APPEND(a, b) APPEND2 (a, b) 20 | #endif 21 | 22 | #ifndef APPEND2 23 | #define APPEND2(a, b) a##b 24 | #endif 25 | 26 | #ifndef FLOAT_TYPE 27 | #define FLOAT_TYPE double 28 | #endif 29 | 30 | #ifndef FUNC_PREFIX 31 | #define FUNC_PREFIX 32 | #endif 33 | 34 | /* from OpenSSH's fake-socket.h */ 35 | 36 | #ifndef IN6_IS_ADDR_LOOPBACK 37 | # define IN6_IS_ADDR_LOOPBACK(a) \ 38 | (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ 39 | ((uint32_t *) (a))[2] == 0 && ((uint32_t *) (a))[3] == htonl (1)) 40 | #endif /* !IN6_IS_ADDR_LOOPBACK */ 41 | 42 | #ifndef AF_INET6 43 | /* Define it to something that should never appear */ 44 | #define AF_INET6 AF_MAX 45 | #endif 46 | 47 | 48 | #endif /* _XINETD_LIBPORTABLE */ 49 | -------------------------------------------------------------------------------- /src/misc/m_env.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992 by Panagiotis Tsirigotis 3 | * All rights reserved. The file named COPYRIGHT specifies the terms 4 | * and conditions for redistribution. 5 | */ 6 | 7 | #ifndef __M_ENV_H 8 | #define __M_ENV_H 9 | 10 | /* 11 | * $Id$ 12 | */ 13 | 14 | struct __env 15 | { 16 | unsigned max_vars ; 17 | unsigned n_vars ; 18 | char **vars ; 19 | } ; 20 | 21 | typedef struct __env *env_h ; 22 | 23 | #define ENV_NULL ((env_h)0) 24 | 25 | /* 26 | * Return values 27 | */ 28 | #define ENV_ERR (-1) 29 | #define ENV_OK 0 30 | 31 | /* 32 | * Error codes 33 | */ 34 | #define ENV_ENOMEM 1 35 | #define ENV_EBADVAR 2 36 | #define ENV_EBADSTRING 3 37 | 38 | 39 | env_h env_create ( const env_h ) ; 40 | void env_destroy ( env_h ) ; 41 | env_h env_make ( char **env_strings ) ; 42 | int env_addvar ( env_h, env_h from_env, char *var ) ; 43 | int env_addstr ( env_h, char *str ) ; 44 | char *env_lookup ( env_h, const char *var ) ; 45 | 46 | #define env_getvars( env ) (env)->vars 47 | 48 | extern int env_errno ; 49 | 50 | #endif /* __M_ENV_H */ 51 | 52 | -------------------------------------------------------------------------------- /src/mask.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992 by Panagiotis Tsirigotis 3 | * (c) Sections Copyright 1998-2001 by Rob Braun 4 | * All rights reserved. The file named COPYRIGHT specifies the terms 5 | * and conditions for redistribution. 6 | */ 7 | 8 | #ifndef MASK_H 9 | #define MASK_H 10 | 11 | /* 12 | * $Id$ 13 | */ 14 | 15 | #include "config.h" 16 | #ifdef HAVE_STDINT_H 17 | #include 18 | #endif 19 | 20 | /* 21 | * Macros about masks - Note: 64 bits is needed because of attr.h 22 | */ 23 | 24 | typedef uint64_t mask_t; 25 | 26 | #define MASK_NULL ((mask_t *)0) 27 | 28 | #define XMASK( v ) ( (mask_t)1 << ( (v)-1 ) ) 29 | 30 | #define M_CLEAR_ALL( mask ) (mask) = 0 31 | #define M_ASSIGN( mask1, mask2 ) (mask1) = (mask2) 32 | #define M_ARE_ALL_CLEAR( mask ) ( (mask) == 0 ) 33 | #define M_SET( mask, v ) (mask) |= XMASK(v) 34 | #define M_CLEAR( mask, v ) (mask) &= ~XMASK(v) 35 | #define M_IS_SET( mask, v ) ( (mask) & XMASK(v) ) 36 | #define M_IS_CLEAR( mask, v ) ( ! M_IS_SET( mask, v ) ) 37 | 38 | #define M_AND( mres, m1, m2 ) ( (mres) = (m1) & (m2) ) 39 | #define M_OR( mres, m1, m2 ) ( (mres) = (m1) | (m2) ) 40 | #define M_XOR( mres, m1, m2 ) ( (mres) = (m1) ^ (m2) ) 41 | 42 | #endif /* MASK_H */ 43 | -------------------------------------------------------------------------------- /.github/workflows/build-ci.yml: -------------------------------------------------------------------------------- 1 | # GitHub actions workflow. 2 | # https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions 3 | 4 | name: Build CI 5 | 6 | on: 7 | push: 8 | branches: [master, gh-actions] 9 | tags: [v*] 10 | pull_request: 11 | types: [opened] 12 | branches: [master] 13 | 14 | jobs: 15 | Linux: 16 | strategy: 17 | matrix: 18 | os: [ubuntu-latest] 19 | cc: [gcc, clang] 20 | runs-on: ${{ matrix.os }} 21 | env: 22 | CC: ${{ matrix.cc }} 23 | steps: 24 | - uses: actions/checkout@v3 25 | - run: ./autogen.sh 26 | - run: ./configure --disable-silent-rules --without-libwrap --without-labeled-networking --without-loadavg 27 | - run: make 28 | - run: make install DESTDIR="${PWD}/root/" 29 | - run: make distcheck 30 | 31 | macOS: 32 | strategy: 33 | matrix: 34 | os: [macos-latest] 35 | cc: [clang] 36 | runs-on: ${{ matrix.os }} 37 | env: 38 | CC: ${{ matrix.cc }} 39 | steps: 40 | - uses: actions/checkout@v3 41 | - run: brew install autoconf automake libtool 42 | - run: ./autogen.sh 43 | - run: ./configure --disable-silent-rules --without-libwrap --without-labeled-networking --without-loadavg 44 | - run: make 45 | - run: make install DESTDIR="${PWD}/root/" 46 | -------------------------------------------------------------------------------- /src/xlog/util.c: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis 3 | * All rights reserved. The file named COPYRIGHT specifies the terms 4 | * and conditions for redistribution. 5 | */ 6 | 7 | 8 | #include "config.h" 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "str.h" 15 | #include "libportable.h" 16 | 17 | /* 18 | * Search the given buffer for an occurrence of "%m" 19 | */ 20 | int __xlog_add_errno( const char *buf, int len ) 21 | { 22 | int i; 23 | 24 | for ( i = 0 ; i < len-1 ; i++ ) 25 | if ( (buf[i] == '%') && (buf[i+1] == 'm') ) 26 | return( i ) ; 27 | return( -1 ) ; 28 | } 29 | 30 | /* __xlog_explain_errno: 31 | * Description: generates a string to explain the value of errno. 32 | * On entry: buf must point to space already allocated by the caller, 33 | * and size points to the amount of memory buf is allocated. 34 | * On exit: buf contains the NULL terminated string, size now points 35 | * to the length of the string, and the return value is buf. 36 | */ 37 | char *__xlog_explain_errno( char *buf, unsigned *size ) 38 | { 39 | strx_print((int *)size, buf, *size, "%s (errno = %d)", 40 | strerror(errno), errno); 41 | return( buf ) ; 42 | } 43 | 44 | 45 | char *__xlog_new_string( const char *s ) 46 | { 47 | if ( s ) 48 | return strdup( s ) ; 49 | else 50 | return 0; 51 | } 52 | 53 | 54 | -------------------------------------------------------------------------------- /src/builtins.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992 by Panagiotis Tsirigotis 3 | * (c) Sections Copyright 1998-2001 by Rob Braun 4 | * All rights reserved. The file named COPYRIGHT specifies the terms 5 | * and conditions for redistribution. 6 | */ 7 | 8 | #ifndef BUILTINS_H 9 | #define BUILTINS_H 10 | 11 | /* 12 | * $Id$ 13 | */ 14 | 15 | #include "defs.h" 16 | 17 | 18 | #define FORK YES 19 | #define NO_FORK NO 20 | 21 | struct builtin 22 | { 23 | voidfunc b_handler ; /* builtin service handler */ 24 | boolean_e b_fork_server ; /* whether a server must be forked */ 25 | } ; 26 | 27 | typedef struct builtin builtin_s ; 28 | 29 | /* 30 | * All builtins are invoked with a struct server argument 31 | */ 32 | #define BUILTIN_HANDLER( bp ) ( (bp)->b_handler ) 33 | #define BUILTIN_INVOKE( bp, serp ) (*(bp)->b_handler)( serp ) 34 | #define BUILTIN_FORKS( bp ) ( (bp)->b_fork_server == YES ) 35 | 36 | 37 | struct builtin_service 38 | { 39 | const char *bs_name ; /* for identification purposes */ 40 | int bs_socket_type ; /* for identification purposes */ 41 | builtin_s bs_handle ; 42 | } ; 43 | 44 | const builtin_s *builtin_find(const char *service_name,int type); 45 | const builtin_s *builtin_lookup(const struct builtin_service services[],const char *service_name,int type); 46 | 47 | #endif /* BUILTIN_H */ 48 | -------------------------------------------------------------------------------- /src/xlog/filelog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis 3 | * All rights reserved. The file named COPYRIGHT specifies the terms 4 | * and conditions for redistribution. 5 | */ 6 | 7 | 8 | /* 9 | * $Id$ 10 | */ 11 | 12 | #ifndef __FILELOG_H 13 | #define __FILELOG_H 14 | 15 | #include "impl.h" 16 | 17 | /* 18 | * The file can be either open or closed. 19 | * When the file is closed, the state is always FL_CLOSED. 20 | * When the file is open, the state is: 21 | * FL_OPEN: if everything is ok 22 | * FL_SIZE: if the hard limit was exceeded 23 | * FL_ERROR: if an error occured 24 | */ 25 | typedef enum { FL_CLOSED = 0, FL_OPEN, FL_SIZE, FL_ERROR } filelog_state_e ; 26 | 27 | struct filelog_s 28 | { 29 | int fl_fd ; 30 | filelog_state_e fl_state ; 31 | int fl_error ; /* error code when in FL_ERROR */ 32 | bool_int fl_size_control ; /* enabled or not */ 33 | bool_int fl_issued_warning ; /* when the soft limit was exceeded */ 34 | unsigned fl_size ; /* current size */ 35 | unsigned fl_soft_limit ; 36 | unsigned fl_hard_limit ; 37 | } ; 38 | 39 | #define FILELOG_ENABLE_SIZE_CONTROL( flp ) (flp)->fl_size_control = TRUE 40 | #define FILELOG_DISABLE_SIZE_CONTROL( flp ) (flp)->fl_size_control = FALSE 41 | #define FILELOG_SIZE_CONTROL( flp ) ( (flp)->fl_size_control ) 42 | 43 | #define FILELOG( xp ) ((struct filelog_s *)xp->xl_data) 44 | 45 | #endif 46 | 47 | -------------------------------------------------------------------------------- /src/parse.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992 by Panagiotis Tsirigotis 3 | * (c) Sections Copyright 1998-2001 by Rob Braun 4 | * All rights reserved. The file named COPYRIGHT specifies the terms 5 | * and conditions for redistribution. 6 | */ 7 | 8 | #ifndef PARSE_H 9 | #define PARSE_H 10 | 11 | #include "defs.h" 12 | #include "conf.h" 13 | 14 | 15 | /* 16 | * $Id$ 17 | */ 18 | 19 | typedef enum { NO_ENTRY, 20 | BAD_ENTRY, 21 | SERVICE_ENTRY, 22 | DEFAULTS_ENTRY, 23 | INCLUDE_ENTRY, 24 | INCLUDEDIR_ENTRY 25 | } entry_e ; 26 | 27 | enum assign_op { SET_EQ, PLUS_EQ, MINUS_EQ } ; 28 | 29 | struct attribute 30 | { 31 | const char *a_name ; /* name of attribute */ 32 | unsigned a_id ; /* attribute id */ 33 | int a_nvalues ; /* number of values */ 34 | status_e (*a_parser)() ; /* function that parses the attribute */ 35 | } ; 36 | 37 | 38 | #define ENTRY_BEGIN '{' 39 | #define ENTRY_END '}' 40 | #define COMMENT_BEGIN '#' 41 | #define KW_SERVICE "service" 42 | #define KW_DEFAULTS "defaults" 43 | #define KW_INCLUDE "include" 44 | #define KW_INCLUDEDIR "includedir" 45 | 46 | extern int line_count; 47 | extern const char *current_file; 48 | 49 | const char *attr_name_lookup(unsigned int id); 50 | void parse_end(void); 51 | void parse_conf_file(int fd,struct configuration *confp, const char *filename); 52 | 53 | #endif /* PARSE_H */ 54 | -------------------------------------------------------------------------------- /man/strutil.3: -------------------------------------------------------------------------------- 1 | .\"(c) Copyright 1992, 1993 by Panagiotis Tsirigotis 2 | .\"All rights reserved. The file named COPYRIGHT specifies the terms 3 | .\"and conditions for redistribution. 4 | .\" 5 | .\" $Id$ 6 | .TH STRUTIL 3X "30 September 1992" 7 | .SH NAME 8 | str_find, str_casefind, str_fill, str_lower, str_upper -- string utility functions 9 | .SH SYNOPSIS 10 | .LP 11 | .nf 12 | .ft B 13 | #include "str.h" 14 | .LP 15 | .ft B 16 | char *str_find( s1, s2 ) 17 | char *s1, *s2 ; 18 | .LP 19 | .ft B 20 | char *str_casefind( s1, s2 ) 21 | char *s1, *s2 ; 22 | .LP 23 | .ft B 24 | void str_fill( s, c ) 25 | char *s ; 26 | char c ; 27 | .LP 28 | .ft B 29 | char *str_lower( s ) 30 | char *s ; 31 | .LP 32 | .ft B 33 | char *str_upper( s ) 34 | char *s ; 35 | .SH DESCRIPTION 36 | .B str_find() 37 | returns a pointer to the first instance of string \fIs2\fR in string \fIs1\fR. 38 | If \fIs2\fR is the empty string a pointer to \fIs1\fR is returned. 39 | .LP 40 | .B str_casefind() 41 | performs the same function as 42 | .B str_find() 43 | except that it performs case insensitive character comparisons. 44 | .LP 45 | .B str_fill() 46 | fills the string \fIs\fR with the character \fIc\fR. 47 | .LP 48 | .B str_lower() 49 | and 50 | .B str_upper() 51 | convert their argument in place to a lower or upper case string respectively. 52 | .SH "RETURN VALUES" 53 | .LP 54 | \fBstr_find()\fR 55 | and 56 | .B str_casefind() 57 | return a pointer to the first occurrence of \fIs2\fR 58 | in \fIs1\fR or 59 | .SM NULL 60 | if \fIs2\fR does not exist in \fIs1\fR. 61 | .LP 62 | \fBstr_lower()\fR and \fBstr_upper()\fR return \fIs\fR. 63 | -------------------------------------------------------------------------------- /contrib/empty.conf: -------------------------------------------------------------------------------- 1 | # This is an empty xinetd service configuration. To add a service to 2 | # xinetd copy this file to /etc/xinetd.d giving it a name similar to the 3 | # service you are adding. Next change the service name before the curly 4 | # brace to match the name found in /etc/services. Then modify the following 5 | # attributes 6 | 7 | service empty 8 | { 9 | # This is for quick on or off of the service 10 | disable = no 11 | 12 | # The next attributes are mandatory for all services 13 | id = 14 | type = 15 | wait = 16 | socket_type = 17 | # protocol = socket type is usually enough 18 | 19 | # External services must fill out the following 20 | user = 21 | group = 22 | server = 23 | server_args = 24 | 25 | # External services not listed in /etc/services must fill out the next one 26 | port = 27 | 28 | # RPC based services must fill out these 29 | rpc_version = 30 | rpc_number = 31 | 32 | # Logging options 33 | log_type = 34 | log_on_success = 35 | log_on_failure = 36 | 37 | # Networking options 38 | flags = 39 | bind = 40 | redirect = 41 | v6only = 42 | 43 | # Access restrictions 44 | only_from = 45 | no_access = 46 | access_times = 47 | cps = 48 | instances = 49 | per_source = 50 | max_load = 51 | deny_time = 52 | mdns = 53 | 54 | # Environmental options 55 | env = 56 | passenv = 57 | nice = 58 | umask = 59 | groups = 60 | rlimit_as = 61 | rlimit_cpu = 62 | rlimit_data = 63 | rlimit_rss = 64 | rlimit_stack = 65 | 66 | # Banner options. (Banners aren't normally used) 67 | # banner = 68 | # banner_success = 69 | # banner_fail = 70 | } 71 | 72 | -------------------------------------------------------------------------------- /src/pset/ops.c: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis 3 | * All rights reserved. The file named COPYRIGHT specifies the terms 4 | * and conditions for redistribution. 5 | */ 6 | 7 | 8 | #include "config.h" 9 | #include "pset.h" 10 | #include 11 | 12 | #define POINTER __pset_pointer 13 | 14 | 15 | /* 16 | * Remove all NULL pointers from a pset 17 | */ 18 | void pset_compact( register pset_h pset ) 19 | { 20 | register unsigned u ; 21 | 22 | for ( u = 0 ; u < pset_count( pset ) ; ) 23 | { 24 | POINTER ptr = pset_pointer( pset, u ); 25 | if ( ptr != NULL ) 26 | u++ ; 27 | else 28 | pset_delete( pset, ptr ) ; 29 | } 30 | 31 | /* See if we can reclaim some memory, make sure we are 2 below for some hysteresis */ 32 | if ((int)( pset->max - pset->alloc_step - 2) > (int)pset_count( pset )) 33 | { /* This rounds up to the next unit of steps */ 34 | POINTER *new_ptrs ; 35 | unsigned new_max = ((pset_count( pset ) / pset->alloc_step) + 1)*pset->alloc_step; 36 | 37 | new_ptrs = (POINTER *) realloc( 38 | (char *)pset->ptrs, new_max * sizeof( POINTER ) ) ; 39 | if ( new_ptrs == NULL ) 40 | return; 41 | pset->max = new_max ; 42 | pset->ptrs = new_ptrs ; 43 | } 44 | } 45 | 46 | 47 | /* 48 | * Apply a function to all pointers of a pset 49 | */ 50 | void pset_apply( register pset_h pset, void (*func)(), register void *arg ) 51 | { 52 | register unsigned u ; 53 | 54 | for ( u = 0 ; u < pset_count( pset ) ; u++ ) 55 | if ( arg ) 56 | (*func)( arg, pset_pointer( pset, u ) ) ; 57 | else 58 | (*func)( pset_pointer( pset, u ) ) ; 59 | } 60 | 61 | -------------------------------------------------------------------------------- /contrib/xinetd.conf: -------------------------------------------------------------------------------- 1 | # 2 | # This is the master xinetd configuration file. Settings in the 3 | # default section will be inherited by all service configurations 4 | # unless explicitly overridden in the service configuration. See 5 | # xinetd.conf in the man pages for a more detailed explanation of 6 | # these attributes. 7 | 8 | defaults 9 | { 10 | # The next two items are intended to be a quick access place to 11 | # temporarily enable or disable services. 12 | # 13 | # enabled = 14 | # disabled = 15 | 16 | # Previous default in SUSE - please don't forget to use the logrotate. The 17 | # sample configuration is in /usr/share/packages/doc/xinetd/logrotate 18 | # log_type = FILE /var/log/xinetd.log 19 | 20 | # Define general logging characteristics. 21 | log_type = SYSLOG daemon info 22 | log_on_failure = HOST ATTEMPT 23 | log_on_success = HOST EXIT DURATION 24 | 25 | # Define access restriction defaults 26 | # 27 | # no_access = 28 | # only_from = localhost 29 | # max_load = 0 30 | cps = 50 10 31 | instances = 30 32 | per_source = 10 33 | 34 | # 35 | # The specification of an interface is interesting, if we are on a firewall. 36 | # For example, if you only want to provide services from an internal 37 | # network interface, you may specify your internal interfaces IP-Address. 38 | # 39 | # bind = 127.0.0.1 40 | 41 | # Address and networking defaults 42 | # 43 | # bind = 44 | # mdns = yes 45 | v6only = no 46 | 47 | # setup environmental attributes 48 | # 49 | # passenv = 50 | groups = yes 51 | umask = 002 52 | 53 | # Generally, banners are not used. This sets up their global defaults 54 | # 55 | # banner = 56 | # banner_fail = 57 | # banner_success = 58 | } 59 | 60 | includedir /etc/xinetd.d 61 | 62 | -------------------------------------------------------------------------------- /src/portable/cvt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1998-2001 by Rob Braun 3 | * All rights reserved. The file named COPYRIGHT specifies the terms 4 | * and conditions for redistribution. 5 | */ 6 | 7 | #include "config.h" 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #ifndef FLOAT_TYPE 17 | #define FLOAT_TYPE double 18 | #define FUNC_PREFIX 19 | #define FLOAT_FMT_FLAG 20 | #define FLOAT_NAME_EXT 21 | #endif 22 | 23 | #ifndef MAXDIG 24 | #define MAXDIG 120 25 | #endif 26 | 27 | #ifndef APPEND 28 | #define APPEND(a, b) APPEND2 (a, b) 29 | #endif 30 | 31 | #ifndef APPEND2 32 | #define APPEND2(a, b) a##b 33 | #endif 34 | 35 | #ifndef FLOOR 36 | #define FLOOR APPEND(floor, FLOAT_NAME_EXT) 37 | #endif 38 | #ifndef FABS 39 | #define FABS APPEND(fabs, FLOAT_NAME_EXT) 40 | #endif 41 | #ifndef LOG10 42 | #define LOG10 APPEND(log10, FLOAT_NAME_EXT) 43 | #endif 44 | #ifndef EXP 45 | #define EXP APPEND(exp, FLOAT_NAME_EXT) 46 | #endif 47 | #ifndef ISINF 48 | #define ISINF APPEND(isinf, FLOAT_NAME_EXT) 49 | #endif 50 | #ifndef ISNAN 51 | #define ISNAN APPEND(isnan, FLOAT_NAME_EXT) 52 | #endif 53 | 54 | #ifndef EINVAL 55 | #define EINVAL 22 56 | #endif 57 | 58 | #ifndef MAX 59 | #define MAX(a,b) ((a)>(b)?(a):(b)) 60 | #endif 61 | 62 | #ifndef __set_errno 63 | #define __set_errno(x) errno = (x) 64 | #endif 65 | 66 | #define weak_extern2(name) 67 | weak_extern2 (FLOOR) weak_extern2 (LOG10) weak_extern2 (FABS) 68 | weak_extern2 (EXP) 69 | 70 | #ifndef HAVE_GCVT 71 | char * 72 | APPEND (FUNC_PREFIX, gcvt) (FLOAT_TYPE value, 73 | int ndigit, 74 | char *buf) 75 | { 76 | sprintf (buf, "%.*" FLOAT_FMT_FLAG "g", ndigit, value); 77 | return buf; 78 | } 79 | #endif /* HAVE_GCVT */ 80 | -------------------------------------------------------------------------------- /src/access.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992 by Panagiotis Tsirigotis 3 | * (c) Sections Copyright 1998-2001 by Rob Braun 4 | * All rights reserved. The file named COPYRIGHT specifies the terms 5 | * and conditions for redistribution. 6 | */ 7 | 8 | #ifndef ACCESS_H 9 | #define ACCESS_H 10 | 11 | /* 12 | * $Id$ 13 | */ 14 | 15 | 16 | #include "util.h" /* for nv_get_name() */ 17 | #include "defs.h" /* bool_int */ 18 | #include "connection.h" 19 | 20 | 21 | /* 22 | * These flags are used to form a mask for access_control. 23 | * The mask determines which checks will be performed. 24 | */ 25 | #define CF_ADDRESS 1 26 | #define CF_TIME 2 27 | #define CF_SERVICE_LIMIT 3 28 | 29 | typedef enum 30 | { 31 | AC_OK, /* ok to start a server */ 32 | AC_FORK, /* tried to start a server but fork failed */ 33 | AC_ADDRESS, /* we do not accept requests from that address */ 34 | AC_TIME, /* we do not accept requests at this time */ 35 | AC_SERVICE_LIMIT, /* server limit would be exceeded for this */ 36 | /* service */ 37 | AC_PER_SOURCE_LIMIT, /* server limit would be exceeded for this */ 38 | /* service and source address */ 39 | AC_PROCESS_LIMIT, /* total process limit would be exceeded */ 40 | AC_LIBWRAP, 41 | AC_LOAD, 42 | AC_CPS 43 | } access_e ; 44 | 45 | 46 | #define ACCESS_EXPLAIN( code ) nv_get_name( access_code_names, (int) (code) ) 47 | 48 | 49 | extern const struct name_value access_code_names[]; 50 | void cps_service_stop(struct service *sp, const char *reason); 51 | access_e access_control(struct service *sp, 52 | const connection_s *cp,const mask_t *check_mask); 53 | access_e parent_access_control(struct service *sp,const connection_s *cp); 54 | 55 | 56 | #endif /* ACCESS_H */ 57 | 58 | -------------------------------------------------------------------------------- /src/xlog/xlog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis 3 | * All rights reserved. The file named COPYRIGHT specifies the terms 4 | * and conditions for redistribution. 5 | */ 6 | 7 | #ifndef __XLOG_H 8 | #define __XLOG_H 9 | 10 | /* 11 | * $Id$ 12 | */ 13 | 14 | /* 15 | * Flags 16 | */ 17 | #define XLOG_NOFLAGS 0x0 18 | #define XLOG_SET_LEVEL 0x1 19 | #define XLOG_NO_SIZECHECK 0x2 20 | #define XLOG_NO_ERRNO 0x4 21 | /* #define XLOG_PRINT_TIMESTAMP 0x8 */ 22 | #define XLOG_PRINT_ID 0x10 23 | #define XLOG_PRINT_PID 0x20 24 | 25 | /* 26 | * Errors 27 | */ 28 | #define XLOG_ENOERROR 0 29 | #define XLOG_ESIZE 1 30 | #define XLOG_EOPEN 2 31 | #define XLOG_EFSTAT 3 32 | #define XLOG_ENOMEM 4 33 | #define XLOG_EWRITE 5 34 | 35 | /* 36 | * Interface 37 | */ 38 | 39 | typedef enum { XLOG_SYSLOG, XLOG_FILELOG } xlog_e ; 40 | 41 | typedef enum 42 | { 43 | XLOG_LINK, /* generic: link this log to another log */ 44 | XLOG_CALLBACK, /* generic: call this function in case of error */ 45 | XLOG_GETFLAG, /* generic: get value of specified flag */ 46 | XLOG_SETFLAG, /* generic: set value of specified flag */ 47 | XLOG_LEVEL, /* syslog: set the default syslog level */ 48 | XLOG_FACILITY, /* syslog: set the default syslog facility */ 49 | XLOG_PREEXEC, /* syslog: prepare the log for an exec(2) */ 50 | XLOG_POSTEXEC, /* syslog: exec(2) failed */ 51 | XLOG_SIZECHECK, /* filelog: check file size */ 52 | XLOG_GETFD, /* filelog: get file descriptor of log file */ 53 | XLOG_LIMITS /* filelog: set (new) soft/hard limits */ 54 | } xlog_cmd_e ; 55 | 56 | typedef void *xlog_h ; 57 | 58 | xlog_h xlog_create ( xlog_e type, const char *id, int flags, ... ) ; 59 | void xlog_destroy ( xlog_h ) ; 60 | void xlog_write ( xlog_h, const char *buf, int len, int flags, ... ) ; 61 | int xlog_control ( xlog_h, xlog_cmd_e, ... ) ; 62 | int xlog_parms ( xlog_e type, ... ) ; 63 | 64 | #endif /* __XLOG_H */ 65 | -------------------------------------------------------------------------------- /src/log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992 by Panagiotis Tsirigotis 3 | * (c) Sections Copyright 1998-2001 by Rob Braun 4 | * All rights reserved. The file named COPYRIGHT specifies the terms 5 | * and conditions for redistribution. 6 | */ 7 | 8 | #ifndef LOG_H 9 | #define LOG_H 10 | 11 | #include 12 | 13 | #include "defs.h" 14 | #include "access.h" 15 | 16 | /* 17 | * $Id$ 18 | */ 19 | 20 | /* 21 | * Meaning of logtype flags: 22 | * 23 | * L_NONE: no logging 24 | * L_FILE: log output goes to a file 25 | * L_SYSLOG: log output goes to syslog(3) 26 | * L_COMMON_FILE: log output goes to the file specified in defaults 27 | */ 28 | typedef enum { L_NONE = 0, L_FILE, L_SYSLOG, L_COMMON_FILE } logtype_e ; 29 | 30 | struct filelog 31 | { 32 | char *fl_filename ; /* always malloc'ed */ 33 | unsigned fl_soft_limit ; 34 | unsigned fl_hard_limit ; 35 | } ; 36 | 37 | #define FILELOG_SIZE_CONTROL( flp ) ( flp->fl_soft_limit != 0 ) 38 | 39 | 40 | struct syslog 41 | { 42 | int sl_facility ; 43 | int sl_level ; 44 | } ; 45 | 46 | struct log 47 | { 48 | logtype_e l_type ; 49 | struct filelog l_fl ; 50 | struct syslog l_sl ; 51 | } ; 52 | 53 | #define LOG_GET_TYPE( lp ) (lp)->l_type 54 | #define LOG_SET_TYPE( lp, type ) (lp)->l_type = (type) 55 | 56 | #define LOG_GET_FILELOG( lp ) (&(lp)->l_fl) 57 | #define LOG_GET_SYSLOG( lp ) (&(lp)->l_sl) 58 | 59 | const char *xaddrname(const union xsockaddr *inaddr); 60 | uint16_t xaddrport(const union xsockaddr *inaddr); 61 | void svc_log_success(struct service *sp, const connection_s *cp,pid_t pid); 62 | void svc_log_failure(struct service *sp, const connection_s *cp,access_e access_failure); 63 | void svc_log_exit(struct service *sp,const struct server *serp); 64 | void svc_logprint(struct service *sp,const char *line_id,const char *fmt,...) 65 | #ifdef __GNUC__ 66 | __attribute__ ((format (printf, 3, 4))); 67 | #else 68 | ; 69 | #endif 70 | #endif /* LOG_H */ 71 | 72 | -------------------------------------------------------------------------------- /src/str/str.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis 3 | * All rights reserved. The file named COPYRIGHT specifies the terms 4 | * and conditions for redistribution. 5 | */ 6 | 7 | 8 | #ifndef __STR_H 9 | #define __STR_H 10 | 11 | /* 12 | * $Id$ 13 | */ 14 | 15 | #include 16 | 17 | #ifdef __GNUC__ 18 | #define PRINTF_FORMAT(n, m) \ 19 | __attribute__ ((format (printf, n, m))) 20 | #else 21 | #define PRINTF_FORMAT(n, m) 22 | #endif 23 | 24 | typedef void *str_h ; 25 | 26 | /* 27 | * strprint(3) functions 28 | */ 29 | char *strx_sprint ( char *buf, int len, const char *fmt, ... ) 30 | PRINTF_FORMAT(3, 4); 31 | int strx_nprint ( char *buf, int len, const char *fmt, ... ) 32 | PRINTF_FORMAT(3, 4); 33 | void strx_print ( int *count, char *buf, int len, const char *fmt, ... ) 34 | PRINTF_FORMAT(4, 5); 35 | 36 | int strx_nprintv ( char *buf, int len, const char *fmt, va_list ) 37 | PRINTF_FORMAT(3, 0); 38 | void strx_printv ( int *cnt, char *buf, int len, const char *fmt, va_list ) 39 | PRINTF_FORMAT(4, 0); 40 | 41 | 42 | /* 43 | * strparse(3) functions 44 | */ 45 | int str_setstr( str_h handle, char *newstr ); 46 | 47 | /* 48 | * Return values 49 | */ 50 | #define STR_OK 0 51 | #define STR_ERR (-1) 52 | 53 | 54 | /* 55 | * Flags for the string parsing functions 56 | */ 57 | #define STR_NOFLAGS 0x0 58 | #define STR_RETURN_ERROR 0x1 59 | #define STR_NULL_START 0x2 60 | #define STR_NULL_END 0x4 61 | #define STR_MALLOC 0x8 62 | 63 | /* 64 | * Error values 65 | */ 66 | #define STR_ENULLSEPAR 1 67 | #define STR_ENULLSTRING 2 68 | #define STR_ENOMEM 3 69 | 70 | char *new_string(const char *) ; 71 | str_h str_parse ( char *str, const char *separ, int flags, int *errnop ) ; 72 | void str_endparse ( str_h handle ) ; 73 | char *str_component ( str_h handle ) ; 74 | 75 | 76 | /* 77 | * strutil(3) functions 78 | */ 79 | char *str_casefind ( char *s1, const char *s2 ) ; 80 | void str_fill ( char *s, char c ) ; 81 | 82 | 83 | #endif /* __STR_H */ 84 | 85 | -------------------------------------------------------------------------------- /man/psi.3: -------------------------------------------------------------------------------- 1 | .\"(c) Copyright 1992, 1993 by Panagiotis Tsirigotis 2 | .\"All rights reserved. The file named COPYRIGHT specifies the terms 3 | .\"and conditions for redistribution. 4 | .\" 5 | .\" $Id$ 6 | .TH PSET 3X "25 September 1992" 7 | .SH NAME 8 | psi_create, psi_destroy, psi_reset, psi_start, psi_next, psi_remove - pointer set iterator functions 9 | .SH SYNOPSIS 10 | .LP 11 | .nf 12 | .ft B 13 | #include "pset.h" 14 | .LP 15 | .ft B 16 | psi_h psi_create( pset ) 17 | pset_h pset ; 18 | .LP 19 | .ft B 20 | void psi_destroy( iter ) 21 | psi_h iter ; 22 | .LP 23 | .ft B 24 | void psi_reset( iter, pset ) 25 | psi_h iter ; 26 | pset_h pset ; 27 | .LP 28 | .ft B 29 | void *psi_start( iter ) 30 | psi_h iter ; 31 | .LP 32 | .ft B 33 | void *psi_next( iter ) 34 | psi_h iter ; 35 | .LP 36 | .ft B 37 | void psi_remove( iter ) 38 | psi_h iter ; 39 | .SH DESCRIPTION 40 | These functions provide a means to iterate over psets (pointer sets). 41 | .LP 42 | .B psi_create() 43 | creates an iterator. The only operation that should be applied to 44 | an iterator after it is created is 45 | .B psi_start(). 46 | .LP 47 | .B psi_destroy() 48 | destroys the iterator. 49 | .LP 50 | .B psi_reset() 51 | changes the pset that is being iterated to 52 | .I pset. 53 | .LP 54 | .B psi_start() 55 | starts an iteration and returns the first pointer 56 | in the pointer set. 57 | .LP 58 | .B psi_next() 59 | returns the next pointer in the set. 60 | .LP 61 | .B psi_remove() 62 | removes the current pointer from the set. The current pointer is 63 | the one returned most recently from either 64 | .B psi_start() 65 | or 66 | .B psi_next(). 67 | .SH "RETURN VALUES" 68 | .LP 69 | .B psi_create() 70 | returns an iterator handle on success or 71 | .SM NULL 72 | on failure. 73 | .LP 74 | .B psi_start() 75 | returns the first pointer from the set or 76 | .SM NULL 77 | if the set is empty. 78 | .LP 79 | .B psi_next() 80 | returns a pointer or 81 | .SM NULL 82 | if the end of the set is reached. 83 | .SH WARNINGS 84 | .B psi_create() 85 | is the only function in this library. The rest of the interface is macros. 86 | .LP 87 | This interface may be eliminated in a future release of the 88 | .I pset 89 | library. 90 | -------------------------------------------------------------------------------- /src/int.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992 by Panagiotis Tsirigotis 3 | * (c) Sections Copyright 1998-2001 by Rob Braun 4 | * All rights reserved. The file named COPYRIGHT specifies the terms 5 | * and conditions for redistribution. 6 | */ 7 | 8 | #ifndef INT_H 9 | #define INT_H 10 | 11 | /* 12 | * $Id$ 13 | */ 14 | 15 | #include 16 | #include 17 | 18 | #include "pset.h" 19 | #include "defs.h" 20 | #include "server.h" 21 | 22 | typedef enum { GOOD_CHANNEL, BAD_CHANNEL } channel_state_e ; 23 | 24 | struct channel 25 | { 26 | channel_state_e ch_state ; 27 | union xsockaddr ch_from ; 28 | int ch_local_socket ; 29 | int ch_remote_socket ; 30 | } ; 31 | 32 | typedef struct channel channel_s ; 33 | 34 | #define CHP( p ) ((struct channel *)(p)) 35 | 36 | #define CHANNEL_NULL CHP( NULL ) 37 | 38 | #define NEW_CHANNEL() NEW( channel_s ) 39 | #define FREE_CHANNEL( chp ) FREE( chp ) 40 | 41 | 42 | struct intercept_common 43 | { 44 | bool_int ic_intercept ; 45 | int ic_remote_socket ; 46 | union xsockaddr ic_local_addr ; 47 | pset_h ic_connections ; 48 | struct server ic_server ; 49 | } ; 50 | 51 | 52 | struct intercept_ops 53 | { 54 | void (*mux)() ; 55 | #ifdef __GNUC__ 56 | __attribute__ ((noreturn)) 57 | #endif 58 | void (*exit)() ; 59 | } ; 60 | 61 | 62 | struct intercept_s 63 | { 64 | int int_socket_type ; 65 | struct intercept_common int_common ; 66 | void *int_priv ; 67 | const struct intercept_ops *int_ops ; 68 | } ; 69 | 70 | #define INT_SERVER( p ) (&(p)->int_common.ic_server) 71 | #define INT_LOCALADDR( p ) (&(p)->int_common.ic_local_addr) 72 | #define INT_REMOTE( p ) ((p)->int_common.ic_remote_socket) 73 | #define INT_CONNECTIONS( p ) ((p)->int_common.ic_connections) 74 | #define INTERCEPT( p ) ((p)->int_common.ic_intercept) 75 | 76 | void intercept(struct server *serp); 77 | void int_sighandler(int sig); 78 | 79 | #endif /* INT_H */ 80 | -------------------------------------------------------------------------------- /COPYRIGHT: -------------------------------------------------------------------------------- 1 | ORIGINAL LICENSE: 2 | This software is 3 | 4 | (c) Copyright 1992 by Panagiotis Tsirigotis 5 | 6 | The author (Panagiotis Tsirigotis) grants permission to use, copy, 7 | and distribute this software and its documentation for any purpose 8 | and without fee, provided that the above copyright notice extant in 9 | files in this distribution is not removed from files included in any 10 | redistribution and that this copyright notice is also included in any 11 | redistribution. 12 | 13 | Modifications to this software may be distributed, either by distributing 14 | the modified software or by distributing patches to the original software, 15 | under the following additional terms: 16 | 17 | 1. The version number will be modified as follows: 18 | a. The first 3 components of the version number 19 | (i.e ..) will remain unchanged. 20 | b. A new component will be appended to the version number to indicate 21 | the modification level. The form of this component is up to the 22 | author of the modifications. 23 | 24 | 2. The author of the modifications will include his/her name by appending it 25 | along with the new version number to this file and will be responsible for 26 | any wrong behavior of the modified software. 27 | 28 | The author makes no representations about the suitability of this 29 | software for any purpose. It is provided "as is" without any express 30 | or implied warranty. 31 | 32 | Modifications: 33 | Version 2.3.15.x 34 | Copyright 2017 SUSE LINUX GmbH and other parties 35 | 36 | Modifications: 37 | Version: 2.1.8.7-current 38 | Copyright 1998-2001 by Rob Braun 39 | 40 | Sensor Addition 41 | Version: 2.1.8.9pre14a 42 | Copyright 2001 by Steve Grubb 43 | 44 | This is an exerpt from an email I recieved from the original author, allowing 45 | xinetd as maintained by me, to use the higher version numbers: 46 | 47 | I appreciate your maintaining the version string guidelines as specified 48 | in the copyright. But I did not mean them to last as long as they did. 49 | 50 | So, if you want, you may use any 2.N.* (N >= 3) version string for future 51 | xinetd versions that you release. Note that I am excluding the 2.2.* line; 52 | using that would only create confusion. Naming the next release 2.3.0 53 | would put to rest the confusion about 2.2.1 and 2.1.8.*. 54 | 55 | -------------------------------------------------------------------------------- /src/attr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992 by Panagiotis Tsirigotis 3 | * (c) Sections Copyright 1998-2001 by Rob Braun 4 | * All rights reserved. The file named COPYRIGHT specifies the terms 5 | * and conditions for redistribution. 6 | */ 7 | 8 | #ifndef ATTR_H 9 | #define ATTR_H 10 | 11 | /* 12 | * $Id$ 13 | */ 14 | 15 | /* 16 | * Attribute IDs 17 | */ 18 | #define A_NONE 0 19 | #define A_WAIT 1 20 | #define A_SOCKET_TYPE 2 21 | #define A_PROTOCOL 3 22 | #define A_USER 4 23 | #define A_GROUP 5 24 | #define A_SERVER 6 25 | #define A_SERVER_ARGS 7 26 | #define A_INSTANCES 8 27 | #define A_ID 9 28 | #define A_ONLY_FROM 10 29 | #define A_ACCESS_TIMES 11 30 | #define A_RPC_VERSION 12 31 | #define A_LOG_TYPE 13 32 | #define A_NO_ACCESS 14 33 | #define A_TYPE 15 34 | #define A_LOG_ON_FAILURE 16 35 | #define A_LOG_ON_SUCCESS 17 36 | #define A_ENV 18 37 | #define A_PORT 19 38 | #define A_PASSENV 20 39 | #define A_FLAGS 21 40 | #define A_RPC_NUMBER 22 41 | #define A_NICE 23 42 | #define A_REDIR 24 43 | #define A_BIND 25 44 | #define A_BANNER 26 45 | #define A_PER_SOURCE 27 46 | #define A_GROUPS 28 47 | #define A_BANNER_SUCCESS 29 48 | #define A_BANNER_FAIL 30 49 | #define A_MAX_LOAD 31 50 | #define A_CPS 32 51 | #define A_SVCDISABLE 33 52 | #define A_RLIMIT_AS 34 53 | #define A_RLIMIT_CPU 35 54 | #define A_RLIMIT_DATA 36 55 | #define A_RLIMIT_RSS 37 56 | #define A_RLIMIT_STACK 38 57 | #define A_V6ONLY 39 58 | #define A_DENY_TIME 40 59 | #define A_UMASK 41 60 | #define A_ENABLED 42 61 | #define A_DISABLED 43 62 | #define A_MDNS 44 63 | #define A_LIBWRAP 45 64 | #define A_RLIMIT_FILES 46 65 | 66 | /* 67 | * SERVICE_ATTRIBUTES is the number of service attributes and also 68 | * the number from which defaults-only attributes start. 69 | */ 70 | #define SERVICE_ATTRIBUTES ( A_MDNS + 2 ) 71 | 72 | /* 73 | * Mask of attributes that must be specified. 74 | */ 75 | #define NECESSARY_ATTRS ( XMASK( A_SOCKET_TYPE ) + XMASK( A_WAIT ) ) 76 | #define NECESSARY_ATTRS_EXTERNAL ( XMASK( A_SERVER ) + XMASK( A_USER ) ) 77 | #define NECESSARY_ATTRS_UNLISTED ( XMASK( A_PROTOCOL ) + XMASK( A_PORT ) ) 78 | #define NECESSARY_ATTRS_UNLISTED_MUX ( XMASK( A_PROTOCOL ) ) 79 | #define NECESSARY_ATTRS_RPC ( XMASK( A_PROTOCOL ) + \ 80 | XMASK( A_RPC_VERSION ) ) 81 | #define NECESSARY_ATTRS_RPC_UNLISTED XMASK( A_RPC_NUMBER ) 82 | 83 | #endif /* ATTR_H */ 84 | -------------------------------------------------------------------------------- /src/str/strutil.c: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis 3 | * All rights reserved. The file named COPYRIGHT specifies the terms 4 | * and conditions for redistribution. 5 | */ 6 | 7 | #include "config.h" 8 | #include 9 | #include 10 | 11 | #ifndef NULL 12 | #define NULL 0 13 | #endif 14 | 15 | #define TRIVIAL_STR_FIND 1 16 | 17 | #ifndef TRIVIAL_STR_FIND 18 | 19 | #define LOWER_CASE( c ) ( (c) + 'a' - 'A' ) 20 | 21 | /* 22 | * look for an instance of sstr in str 23 | * Returns a pointer to the beginning of sstr in str. 24 | * It ignores the case of the alphabetic characters 25 | */ 26 | char *str_casefind( register char *str, char *sstr ) 27 | { 28 | register int ssfc = *sstr++ ; /* sub-string first char */ 29 | 30 | if ( ssfc == 0 ) 31 | return( str ) ; 32 | 33 | if ( isalpha( ssfc ) && isupper( ssfc ) ) 34 | ssfc = LOWER_CASE( ssfc ) ; 35 | 36 | while ( *str ) 37 | { 38 | char *current = str ; 39 | register int strc = *str++ ; 40 | char *sp ; /* string pointer */ 41 | char *ssp ; /* sub-string pointer */ 42 | 43 | if ( isalpha( strc ) && isupper( strc ) ) 44 | strc = LOWER_CASE( strc ) ; 45 | if ( strc != ssfc ) 46 | continue ; 47 | 48 | for ( sp = str, ssp = sstr ;; sp++, ssp++ ) 49 | { 50 | register int sc = *sp ; /* string char */ 51 | register int ssc = *ssp ; /* substring char */ 52 | 53 | /* 54 | * End-of-substring means we got a match 55 | */ 56 | if ( ssc == 0 ) 57 | return( current ) ; 58 | 59 | /* 60 | * Convert to lower case if alphanumeric 61 | */ 62 | if ( isalpha( sc ) && isupper( sc ) ) 63 | sc = LOWER_CASE( sc ) ; 64 | if ( isalpha( ssc ) && isupper( ssc ) ) 65 | ssc = LOWER_CASE( ssc ) ; 66 | if ( sc != ssc ) 67 | break ; 68 | } 69 | } 70 | 71 | return( 0 ) ; 72 | } 73 | 74 | 75 | #else /* defined( TRIVIAL_STR_FIND ) */ 76 | 77 | /* 78 | * look for an instance of s2 in s1 79 | * Returns a pointer to the beginning of s2 in s1. 80 | * It ignores the case of the alphabetic characters 81 | */ 82 | char *str_casefind( char *s1, const char *s2 ) 83 | { 84 | unsigned int i ; 85 | unsigned long l1 = strlen( s1 ) ; 86 | unsigned long l2 = strlen( s2 ) ; 87 | 88 | if ( l2 > l1 ) 89 | return( NULL ) ; 90 | 91 | for ( i = 0 ; i < l1 - l2 + 1 ; i++ ) 92 | if ( strncasecmp( &s1[ i ], s2, l2 ) == 0 ) 93 | return( (char *) &s1[ i ] ) ; 94 | return( NULL ) ; 95 | } 96 | 97 | #endif /* TRIVIAL_STR_FIND */ 98 | 99 | 100 | /* 101 | * Fill string s with character c 102 | */ 103 | void str_fill( char *s, char c ) 104 | { 105 | while ( *s ) *s++ = c ; 106 | } 107 | 108 | -------------------------------------------------------------------------------- /src/pset/pset.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis 3 | * All rights reserved. The file named COPYRIGHT specifies the terms 4 | * and conditions for redistribution. 5 | */ 6 | 7 | #ifndef __PSET_H 8 | #define __PSET_H 9 | 10 | /* 11 | * $Id$ 12 | */ 13 | 14 | #include 15 | 16 | typedef void *__pset_pointer ; 17 | 18 | struct __pset 19 | { 20 | unsigned alloc_step ; 21 | __pset_pointer *ptrs ; /* void Pointer to a Pointer */ 22 | unsigned max ; 23 | unsigned count ; 24 | } ; 25 | 26 | 27 | /* 28 | * INTERFACE 29 | */ 30 | 31 | typedef struct __pset *pset_h ; 32 | 33 | pset_h pset_create( unsigned alloc_start, unsigned alloc_step ); 34 | void pset_destroy( pset_h pset ); 35 | 36 | void pset_delete( pset_h pset, const __pset_pointer ptr ); 37 | __pset_pointer pset_add( pset_h pset, const __pset_pointer ptr ); 38 | 39 | /* These 2 are in ops.c */ 40 | void pset_compact( pset_h pset ); 41 | void pset_apply( pset_h pset, void (*func)(), void *arg ); 42 | 43 | /* 44 | * Macros 45 | */ 46 | 47 | #define pset_remove( pset, ptr ) pset_delete( pset, (__pset_pointer)(ptr) ) 48 | 49 | #define pset_remove_index( pset, i ) \ 50 | { \ 51 | if ( ((unsigned)i) < (pset)->count ) \ 52 | pset_delete(pset, (pset)->ptrs[ (unsigned)(i) ]); \ 53 | } 54 | 55 | #define pset_clear( pset ) (pset)->count = 0 56 | #define pset_count( pset ) (pset)->count 57 | #define pset_pointer( pset, i ) (pset)->ptrs[ (unsigned)(i) ] 58 | 59 | #define pset_sort( pset, compfunc ) \ 60 | (void) qsort( (char *) &pset_pointer( pset, 0 ), \ 61 | pset_count( pset ), sizeof( __pset_pointer ), compfunc ) 62 | 63 | /* 64 | * PSET iterators 65 | * 66 | * Note that the iterators do NOT use any knowledge about the internals 67 | * of pset's. 68 | */ 69 | struct __pset_iterator 70 | { 71 | pset_h pset ; 72 | unsigned current ; 73 | int step ; 74 | } ; 75 | 76 | typedef struct __pset_iterator *psi_h ; 77 | void psi_remove( psi_h iter ); 78 | 79 | #define __psi_current( iter ) \ 80 | ( (iter)->current < pset_count( (iter)->pset ) \ 81 | ? pset_pointer( (iter)->pset, (iter)->current ) \ 82 | : NULL ) 83 | 84 | #define psi_start( iter ) \ 85 | ( (iter)->current = 0, (iter)->step = 1, \ 86 | __psi_current( iter ) ) 87 | 88 | #define psi_next( iter ) \ 89 | ( (iter)->current += (iter)->step, (iter)->step = 1, \ 90 | __psi_current( iter ) ) 91 | 92 | #define psi_destroy( iter ) free( (char *) iter ) 93 | 94 | psi_h psi_create( pset_h pset ); 95 | 96 | #endif /* __PSET_H */ 97 | -------------------------------------------------------------------------------- /src/connection.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992 by Panagiotis Tsirigotis 3 | * (c) Sections Copyright 1998-2001 by Rob Braun 4 | * All rights reserved. The file named COPYRIGHT specifies the terms 5 | * and conditions for redistribution. 6 | */ 7 | 8 | #ifndef CONNECTION_H 9 | #define CONNECTION_H 10 | 11 | /* 12 | * $Id$ 13 | */ 14 | 15 | #include "config.h" 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include "mask.h" 22 | #include "service.h" 23 | #include "defs.h" 24 | #include "msg.h" 25 | #include "sio.h" 26 | 27 | #ifndef IN6_IS_ADDR_V4MAPPED 28 | #define IN6_IS_ADDR_V4MAPPED(a) \ 29 | ((((uint32_t *) (a))[0] == 0) && (((uint32_t *) (a))[1] == 0) && \ 30 | (((uint32_t *) (a))[2] == htonl (0xffff))) 31 | #endif 32 | #ifndef IN6_IS_ADDR_V4COMPAT 33 | #define IN6_IS_ADDR_V4COMPAT(a) \ 34 | ((((uint32_t *) (a))[0] == 0) && (((uint32_t *) (a))[1] == 0) && \ 35 | (((uint32_t *) (a))[2] == 0) && (ntohl (((uint32_t *) (a))[3]) > 1)) 36 | #endif 37 | 38 | #define MAX_ALTERNATIVES 3 39 | 40 | /* Connection flags */ 41 | #define COF_HAVE_ADDRESS 1 42 | #define COF_NEW_DESCRIPTOR 2 43 | 44 | struct connection 45 | { 46 | struct service *co_sp ; 47 | int co_descriptor ; 48 | mask_t co_flags ; 49 | union xsockaddr co_remote_address ; 50 | } ; 51 | 52 | #define CONN_CLOSE( cp ) { Sclose( (cp)->co_descriptor ); (cp)->co_descriptor = -1; } 53 | 54 | #define COP( p ) ((connection_s *)(p)) 55 | #define CONN_NULL COP( NULL ) 56 | 57 | /* 58 | * Field access macros 59 | */ 60 | #define CONN_DESCRIPTOR( cp ) (cp)->co_descriptor 61 | #define CONN_SERVICE( cp ) (cp)->co_sp 62 | #define CONN_SET_FLAG( cp, flag ) M_SET( (cp)->co_flags, flag ) 63 | #define CONN_SET_DESCRIPTOR( cp, fd ) (cp)->co_descriptor = (fd) 64 | 65 | #define CONN_SETADDR( cp, sinp ) \ 66 | { \ 67 | CONN_SET_FLAG( cp, COF_HAVE_ADDRESS ) ; \ 68 | memcpy(((cp)->co_remote_address.pad), sinp, sizeof(*sinp) ); \ 69 | } 70 | 71 | #define CONN_ADDRESS( cp ) \ 72 | ( \ 73 | M_IS_SET( (cp)->co_flags, COF_HAVE_ADDRESS ) \ 74 | ? &((cp)->co_remote_address.sa) \ 75 | : SA(NULL) \ 76 | ) 77 | #define CONN_XADDRESS( cp ) \ 78 | ( \ 79 | M_IS_SET( (cp)->co_flags, COF_HAVE_ADDRESS ) \ 80 | ? &((cp)->co_remote_address) \ 81 | : NULL \ 82 | ) 83 | 84 | connection_s *conn_new(struct service *sp); 85 | void conn_free(connection_s *cp, int); 86 | void conn_dump(const connection_s *cp,int fd); 87 | const char *conn_addrstr( const connection_s *cp ); 88 | 89 | #endif /* CONNECTION_H */ 90 | 91 | -------------------------------------------------------------------------------- /src/str/strprint.c: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis 3 | * All rights reserved. The file named COPYRIGHT specifies the terms 4 | * and conditions for redistribution. 5 | */ 6 | 7 | 8 | #include "config.h" 9 | #ifndef NO_SIO 10 | #include "sio.h" 11 | #endif 12 | 13 | #include "str.h" 14 | #include "strparse.h" 15 | 16 | #define INT_NULL ((int *)0) 17 | 18 | /* 19 | * The strx_* functions will never over-run the buffer 20 | * The str_* functions may over-run the buffer 21 | */ 22 | 23 | /* 24 | * Group 1: the strx_* functions 25 | */ 26 | 27 | /* 28 | * This is the general purpose conversion function. It is invoked 29 | * by all the other str[x]_* functions 30 | */ 31 | void strx_printv( int *ccp, char *buf, int len, const char *format, va_list ap ) 32 | { 33 | #ifndef NO_SIO 34 | __sio_od_t od ; 35 | int cc ; 36 | 37 | /* 38 | * First initialize the descriptor 39 | * Notice that if no length is given, we initialize buf_end to the 40 | * highest possible address. 41 | */ 42 | od.buf = buf ; /* NOT NEEDED */ 43 | od.buf_end = len ? &buf[ len ] : (char *) ~0 ; /* NEEDED */ 44 | od.buffer_size = 0 ; /* NOT NEEDED */ 45 | od.start = buf ; /* NOT NEEDED */ 46 | od.nextb = buf ; /* NEEDED */ 47 | od.buftype = 0 ; /* NOT NEEDED */ 48 | 49 | /* 50 | * Do the conversion 51 | */ 52 | cc = __sio_converter( &od, -1, format, ap ) ; 53 | if ( len == 0 || od.nextb < od.buf_end ) 54 | *(od.nextb) = '\0' ; 55 | if ( ccp ) 56 | *ccp = cc ; 57 | #endif /* ! NO_SIO */ 58 | } 59 | 60 | 61 | void strx_print( int *ccp, char *buf, int len, const char *format, ... ) 62 | { 63 | va_list ap ; 64 | 65 | if (len <= 0) { 66 | if( ccp ) 67 | *ccp = 0; 68 | return; 69 | } 70 | 71 | va_start( ap, format ) ; 72 | strx_printv( ccp, buf, len, format, ap ) ; 73 | va_end( ap ) ; 74 | } 75 | 76 | 77 | char *strx_sprint( char *buf, int len, const char *format, ... ) 78 | { 79 | va_list ap ; 80 | 81 | if (len <= 0) { 82 | return buf; 83 | } 84 | va_start( ap, format ) ; 85 | strx_printv( INT_NULL, buf, len, format, ap ) ; 86 | va_end( ap ) ; 87 | return( buf ) ; 88 | } 89 | 90 | 91 | int strx_nprint( char *buf, int len, const char *format, ...) 92 | { 93 | int cc ; 94 | va_list ap ; 95 | 96 | if (len <= 0) { 97 | return 0; 98 | } 99 | va_start( ap, format ) ; 100 | strx_printv( &cc, buf, len, format, ap ) ; 101 | va_end( ap ) ; 102 | return( cc ) ; 103 | } 104 | 105 | 106 | int strx_nprintv( char *buf, int len, const char *format, va_list ap ) 107 | { 108 | int cc ; 109 | 110 | if (len <= 0) { 111 | return 0; 112 | } 113 | strx_printv( &cc, buf, len, format, ap ) ; 114 | return( cc ) ; 115 | } 116 | 117 | 118 | -------------------------------------------------------------------------------- /src/xgetloadavg.c: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1998-2001 by Rob Braun 3 | * All rights reserved. The file named COPYRIGHT specifies the terms 4 | * and conditions for redistribution. 5 | */ 6 | /* This file contains OS dependant implementations of xgetloadavg(). 7 | * xgetloadavg takes no arguments and simply returns the 1 minute 8 | * load average of the machine as a double. 9 | * Feel free to add implementations here, please update configure.in 10 | * to define HAVE_LOADAVG. Defining this macro enables the option 11 | * in the rest of the code. 12 | * --Rob 13 | */ 14 | 15 | #include "config.h" 16 | #ifdef HAVE_LOADAVG 17 | 18 | #ifdef linux 19 | #include 20 | #include "xgetloadavg.h" 21 | 22 | #define LFILE "/proc/loadavg" 23 | #define MAX 32 24 | 25 | double xgetloadavg(void) 26 | { 27 | FILE *fd; 28 | double ret = 0; 29 | 30 | fd = fopen(LFILE, "r"); 31 | if( fd == NULL ) { 32 | return -1; 33 | } 34 | 35 | if( fscanf(fd, "%lf", &ret) != 1 ) { 36 | perror("fscanf"); 37 | ret = -1; 38 | } 39 | 40 | fclose(fd); 41 | 42 | return ret; 43 | } 44 | #endif /* linux */ 45 | 46 | 47 | #ifdef solaris 48 | #ifdef HAVE_KSTAT_H 49 | #include 50 | 51 | double xgetloadavg(void) 52 | { 53 | kstat_ctl_t *kc = NULL; 54 | kstat_t *ks = NULL; 55 | kstat_named_t *kn = NULL; 56 | 57 | kc = kstat_open(); 58 | if( kc == NULL ) { 59 | return -1; 60 | } 61 | 62 | ks = kstat_lookup(kc, "unix", 0, "system_misc"); 63 | if( ks == NULL ) { 64 | return -1; 65 | } 66 | 67 | if( kstat_read(kc, ks, 0) == -1 ) { 68 | return -1; 69 | } 70 | 71 | kn = kstat_data_lookup(ks, "avenrun_1min"); 72 | if( kn == NULL ) { 73 | return -1; 74 | } 75 | 76 | if( ks->ks_type == KSTAT_TYPE_NAMED ) { 77 | kn = ks->ks_data; 78 | if( kn == NULL ) { 79 | return -1; 80 | } 81 | 82 | return (double)(kn->value.ui32)/100; 83 | } 84 | 85 | kstat_close(kc); 86 | } 87 | #endif /* HAVE_KSTAT */ 88 | #endif /* solaris */ 89 | 90 | 91 | #if defined(bsdi) || defined(__APPLE__) 92 | #include 93 | 94 | double xgetloadavg(void) 95 | { 96 | double loadavg[3]; 97 | 98 | if (getloadavg(loadavg, 1) == -1) 99 | { 100 | return -1; 101 | } 102 | else 103 | { 104 | return loadavg[0]; 105 | } 106 | } 107 | #endif /* bsdi || __APPLE__ */ 108 | 109 | 110 | #ifdef __osf__ 111 | #include 112 | 113 | double xgetloadavg(void) 114 | { 115 | struct tbl_loadavg labuf; 116 | 117 | if (table(TBL_LOADAVG, 0, &labuf, 1, sizeof(labuf)) < 0) { 118 | perror("TBL_LOADAVG"); 119 | return (-1); 120 | } 121 | 122 | if (labuf.tl_lscale) { 123 | return ((double)labuf.tl_avenrun.l[2] / 124 | (double)labuf.tl_lscale); 125 | } 126 | 127 | return (labuf.tl_avenrun.d[2]); 128 | } 129 | #endif /* __osf__ */ 130 | 131 | #endif /* HAVE_LOADAVG */ 132 | 133 | -------------------------------------------------------------------------------- /src/state.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992 by Panagiotis Tsirigotis 3 | * (c) Sections Copyright 1998-2001 by Rob Braun 4 | * All rights reserved. The file named COPYRIGHT specifies the terms 5 | * and conditions for redistribution. 6 | */ 7 | 8 | #ifndef STATE_H 9 | #define STATE_H 10 | 11 | /* 12 | * $Id$ 13 | */ 14 | 15 | #include "config.h" 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include "libportable.h" 21 | #include 22 | #ifdef HAVE_POLL 23 | #include 24 | #endif 25 | 26 | #include "xlog.h" 27 | #include "pset.h" 28 | #include "defs.h" 29 | #include "mask.h" 30 | 31 | struct read_only_state 32 | { 33 | rlim_t max_descriptors ; /* original hard rlimit or OPEN_MAX */ 34 | rlim_t process_limit ; /* if 0, there is no limit */ 35 | int cc_interval ; /* # of seconds the cc gets invoked. */ 36 | const char *pid_file ; /* where the pidfile is located */ 37 | const char *config_file ; 38 | int is_superuser ; 39 | char **Argv ; 40 | int Argc ; 41 | } ; 42 | 43 | 44 | struct defaults 45 | { 46 | struct service_config *def_settings ; 47 | xlog_h def_log ; 48 | bool_int def_log_creation_failed ; 49 | } ; 50 | 51 | 52 | struct read_write_state 53 | { 54 | int descriptors_free ; /* may be negative (reserved) */ 55 | int available_services ; /* # of available services */ 56 | int active_services ; /* services with descriptors set */ 57 | /* in socket mask */ 58 | #ifdef HAVE_POLL 59 | struct pollfd *pfd_array; /* array passed to poll(2) */ 60 | int pfds_last; /* index of last fd in the array */ 61 | int pfds_allocated; /* size of the array */ 62 | #else 63 | fd_set socket_mask ; 64 | int mask_max ; 65 | #endif /* HAVE_POLL */ 66 | 67 | pset_h servers ; /* table of running servers */ 68 | pset_h retries ; /* table of servers to retry */ 69 | pset_h services ; /* table of services */ 70 | struct service *logging ; 71 | struct defaults defs ; 72 | xlog_h program_log ; 73 | sigjmp_buf env ; 74 | bool_int env_is_valid ; 75 | } ; 76 | 77 | struct program_state 78 | { 79 | struct read_only_state ros ; 80 | struct read_write_state rws ; 81 | } ; 82 | 83 | #define DEFAULTS( ps ) (ps).rws.defs.def_settings 84 | #define DEFAULT_LOG( ps ) (ps).rws.defs.def_log 85 | #define DEFAULT_LOG_ERROR( ps ) (ps).rws.defs.def_log_creation_failed 86 | #define LOG_SERVICE( ps ) (ps).rws.logging 87 | #define SERVICES( ps ) (ps).rws.services 88 | #define SERVERS( ps ) (ps).rws.servers 89 | #define RETRIES( ps ) (ps).rws.retries 90 | 91 | 92 | #endif /* STATE_H */ 93 | -------------------------------------------------------------------------------- /src/xlog/impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis 3 | * All rights reserved. The file named COPYRIGHT specifies the terms 4 | * and conditions for redistribution. 5 | */ 6 | 7 | 8 | /* 9 | * $Id$ 10 | */ 11 | 12 | #ifndef __XLOG_IMPL_H 13 | #define __XLOG_IMPL_H 14 | 15 | #include /* For malloc() & free() prototypes */ 16 | #include 17 | #define DEFINE_LINK_TYPE( type, name ) struct { type *next, *prev ; } name 18 | 19 | 20 | #define NEXT( obj, field ) (obj)->field.next 21 | #define PREV( obj, field ) (obj)->field.prev 22 | 23 | #define INIT_LINKS( obj, field ) \ 24 | { \ 25 | NEXT( obj, field ) = obj ; \ 26 | PREV( obj, field ) = obj ; \ 27 | } 28 | 29 | /* 30 | * Link new object after object using the specified field 31 | */ 32 | #define LINK( obj, new_obj, field ) \ 33 | { \ 34 | NEXT( new_obj, field ) = NEXT( obj, field ) ; \ 35 | PREV( new_obj, field ) = obj ; \ 36 | NEXT( obj, field ) = new_obj ; \ 37 | PREV( NEXT( obj, field ), field ) = new_obj ; \ 38 | } 39 | 40 | #define UNLINK( obj, field ) \ 41 | { \ 42 | NEXT( PREV( obj, field ), field ) = NEXT( obj, field ) ; \ 43 | PREV( NEXT( obj, field ), field ) = PREV( obj, field ) ; \ 44 | } 45 | 46 | 47 | /* 48 | * xlog linking: 49 | * When xlog1 is linked to xlog2 (i.e. errors on xlog1 are reported to 50 | * xlog2) we use the xl_clients field on xlog2 and the xl_other_users 51 | * field on xlog1 52 | */ 53 | struct xlog 54 | { 55 | xlog_e xl_type ; 56 | char *xl_id ; 57 | int xl_flags ; 58 | void (*xl_callback)() ; 59 | void *xl_callback_arg ; 60 | struct xlog *xl_use ; /* xlog we report errors to */ 61 | struct xlog *xl_clients ; /* linked list of xlogs that use */ 62 | /* this xlog to report errors */ 63 | DEFINE_LINK_TYPE( struct xlog, xl_other_users ) ; 64 | struct xlog_ops 65 | { 66 | int (*init) ( struct xlog *, va_list ) ; 67 | void (*fini) ( struct xlog * ) ; 68 | int (*write) ( struct xlog *, const char *, int, int, va_list ) ; 69 | int (*control) ( struct xlog *, xlog_cmd_e, va_list ) ; 70 | int (*parms) ( xlog_e, va_list ) ; 71 | } *xl_ops ; 72 | void *xl_data ; 73 | } ; 74 | 75 | #define XL_INIT( xp, ap ) (*(xp)->xl_ops->init)( (xp), (ap) ) 76 | #define XL_FINI( xp ) (*(xp)->xl_ops->fini)( xp ) 77 | #define XL_WRITE( xp, buf, size, flags, ap ) \ 78 | (*(xp)->xl_ops->write)( (xp), (buf), (size), (flags), (ap ) ) 79 | #define XL_CONTROL( xp, cmd, ap ) \ 80 | (*(xp)->xl_ops->control)( (xp), (cmd), (ap) ) 81 | 82 | typedef struct xlog xlog_s ; 83 | 84 | typedef void (*voidfunc)() ; 85 | typedef int bool_int ; 86 | 87 | #define XP( p ) ((struct xlog *)(p)) 88 | 89 | #define XLOG_NULL XP( NULL ) 90 | 91 | #ifndef FALSE 92 | #define FALSE 0 93 | #define TRUE 1 94 | #endif 95 | 96 | #ifndef NULL 97 | #define NULL 0 98 | #endif 99 | 100 | #define NEW( type ) (type *) malloc( sizeof( type ) ) 101 | 102 | int __xlog_add_errno(const char *, int) ; 103 | char *__xlog_explain_errno(char *, unsigned *) ; 104 | char *__xlog_new_string(const char *) ; 105 | 106 | #endif 107 | 108 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # xinetd # 2 | 3 | [![Build Status](https://travis-ci.org/openSUSE/xinetd.svg?branch=master)](https://travis-ci.org/openSUSE/xinetd) 4 | 5 | xinetd is a powerful replacement for inetd. 6 | 7 | If you are planning to use xinetd on recent linux distribution also consider using [systemd socket activation](http://0pointer.de/blog/projects/socket-activation.html) instead. 8 | 9 | Original site (DEAD): http://www.xinetd.org 10 | 11 | xinetd has access control mechanisms, extensive logging capabilities, 12 | the ability to make services available based on time, can place 13 | limits on the number of servers that can be started, and has deployable 14 | defence mechanisms to protect against port scanners, among other things. 15 | 16 | There are a number of differences between xinetd and inetd. The 17 | largest difference to the end user is the config file. xinetd's 18 | config file format is more C like, and somewhat similar to bind 8's. 19 | 20 | # Access Control 21 | 22 | xinetd keeps all the names you specify on the 23 | access control directives. When a client attempts to connect to 24 | a service, a reverse lookup is performed on the client's IP address. 25 | The canonical name returned is compared with the specified names. 26 | If the first character of the name being specified in the config 27 | file is a '.', then all hosts within that domain are matched. 28 | For example, if I put .synack.net, all hosts with a reverse mapping 29 | that are in .synack.net domain, are matched. 30 | 31 | # libwrap support 32 | 33 | For libwrap access control, the access control is done by the 34 | server name for the service. So, if you have an entry like this: 35 | service telnet 36 | ~~~ 37 | { 38 | ... 39 | server = /usr/sbin/in.telnetd 40 | ... 41 | } 42 | ~~~ 43 | Your corresponding `hosts.{allow|deny}` entry would look something 44 | like this: 45 | ~~~ 46 | in.telnetd: ALL 47 | ~~~ 48 | 49 | However, many services don't have a "server". Internal services 50 | and redirection services don't have a "server" line in the configuration 51 | file. Fma these services, the service name is used. For example: 52 | ~~~ 53 | server telnet 54 | { 55 | ... 56 | redirect = 10.0.0.1 23 57 | ... 58 | } 59 | ~~~ 60 | Your `hosts.{allow|deny}` entry would look something like this: 61 | telnet: ALL 62 | 63 | So, in general, if a service has a "server" attribute to it, access 64 | control is performed based on that entry. If a service does not have 65 | a "server" attribute, (internal and redirection services) then access 66 | control is based on the service name. 67 | This is only for libwrap access control. 68 | 69 | # History 70 | 71 | xinetd was originally written by panos@cs.colorado.edu. At least one other 72 | version of xinetd has been seen floating around the net. Another version is 73 | maintained by Rob Braun (bbraun@synack.net) and bug reports for that 74 | version should be directed to https://github.com/xinetd-org/xinetd/. 75 | 76 | This version is simple collection of patches contained over Rob Brauns version that were present in all major distributions. 77 | Plans are to include fixes as required for keeping it workable in openSUSE and also to merge commits from the above github branch. 78 | 79 | # Issues 80 | 81 | Bug reports/comments/suggestions/flames for this version should be sent 82 | to https://github.com/openSUSE/xinetd/issues/ 83 | -------------------------------------------------------------------------------- /m4/ax_check_link_flag.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # http://www.gnu.org/software/autoconf-archive/ax_check_link_flag.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_CHECK_LINK_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # Check whether the given FLAG works with the linker or gives an error. 12 | # (Warnings, however, are ignored) 13 | # 14 | # ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on 15 | # success/failure. 16 | # 17 | # If EXTRA-FLAGS is defined, it is added to the linker's default flags 18 | # when the check is done. The check is thus made with the flags: "LDFLAGS 19 | # EXTRA-FLAGS FLAG". This can for example be used to force the linker to 20 | # issue an error when a bad flag is given. 21 | # 22 | # NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this 23 | # macro in sync with AX_CHECK_{PREPROC,COMPILE}_FLAG. 24 | # 25 | # LICENSE 26 | # 27 | # Copyright (c) 2008 Guido U. Draheim 28 | # Copyright (c) 2011 Maarten Bosmans 29 | # 30 | # This program is free software: you can redistribute it and/or modify it 31 | # under the terms of the GNU General Public License as published by the 32 | # Free Software Foundation, either version 3 of the License, or (at your 33 | # option) any later version. 34 | # 35 | # This program is distributed in the hope that it will be useful, but 36 | # WITHOUT ANY WARRANTY; without even the implied warranty of 37 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 38 | # Public License for more details. 39 | # 40 | # You should have received a copy of the GNU General Public License along 41 | # with this program. If not, see . 42 | # 43 | # As a special exception, the respective Autoconf Macro's copyright owner 44 | # gives unlimited permission to copy, distribute and modify the configure 45 | # scripts that are the output of Autoconf when processing the Macro. You 46 | # need not follow the terms of the GNU General Public License when using 47 | # or distributing such scripts, even though portions of the text of the 48 | # Macro appear in them. The GNU General Public License (GPL) does govern 49 | # all other use of the material that constitutes the Autoconf Macro. 50 | # 51 | # This special exception to the GPL applies to versions of the Autoconf 52 | # Macro released by the Autoconf Archive. When you make and distribute a 53 | # modified version of the Autoconf Macro, you may extend this special 54 | # exception to the GPL to apply to your modified version as well. 55 | 56 | #serial 2 57 | 58 | AC_DEFUN([AX_CHECK_LINK_FLAG], 59 | [AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_ldflags_$4_$1])dnl 60 | AC_CACHE_CHECK([whether the linker accepts $1], CACHEVAR, [ 61 | ax_check_save_flags=$LDFLAGS 62 | LDFLAGS="$LDFLAGS $4 $1" 63 | AC_LINK_IFELSE([AC_LANG_PROGRAM()], 64 | [AS_VAR_SET(CACHEVAR,[yes])], 65 | [AS_VAR_SET(CACHEVAR,[no])]) 66 | LDFLAGS=$ax_check_save_flags]) 67 | AS_IF([test x"AS_VAR_GET(CACHEVAR)" = xyes], 68 | [m4_default([$2], :)], 69 | [m4_default([$3], :)]) 70 | AS_VAR_POPDEF([CACHEVAR])dnl 71 | ])dnl AX_CHECK_LINK_FLAGS 72 | -------------------------------------------------------------------------------- /contrib/xinetd: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # xinetd This starts and stops xinetd. 4 | # 5 | # chkconfig: 345 65 50 6 | # description: xinetd is a powerful replacement for inetd. \ 7 | # xinetd has access control machanisms, extensive \ 8 | # logging capabilities, the ability to make services \ 9 | # available based on time, and can place \ 10 | # limits on the number of servers that can be started, \ 11 | # among other things. 12 | # 13 | # processname: /usr/sbin/xinetd 14 | # config: /etc/sysconfig/network 15 | # config: /etc/xinetd.conf 16 | # pidfile: /var/run/xinetd.pid 17 | 18 | PATH=/sbin:/bin:/usr/bin:/usr/sbin 19 | 20 | # Source function library. 21 | . /etc/init.d/functions 22 | 23 | # Get config. 24 | test -f /etc/sysconfig/network && . /etc/sysconfig/network 25 | 26 | # More config 27 | 28 | test -f /etc/sysconfig/xinetd && . /etc/sysconfig/xinetd 29 | 30 | # Check that networking is up. 31 | [ ${NETWORKING} = "yes" ] || exit 0 32 | 33 | [ -f /usr/sbin/xinetd ] || exit 1 34 | [ -f /etc/xinetd.conf ] || exit 1 35 | 36 | RETVAL=0 37 | 38 | if [ "$NETWORKING_IPV6" = "yes" ] && [ -x /usr/sbin/xinetd6 ]; then 39 | prog="xinetd6" 40 | else 41 | prog="xinetd" 42 | fi 43 | 44 | start(){ 45 | echo -n $"Starting $prog: " 46 | # Need to get rid of localization for external services - 47 | # it doesn't make much sense to have i18n on the server side here 48 | 49 | LANG=en_US 50 | LC_TIME=en_US 51 | LC_ALL=en_US 52 | LC_MESSAGES=en_US 53 | LC_NUMERIC=en_US 54 | LC_MONETARY=en_US 55 | LC_COLLATE=en_US 56 | export LANG LC_TIME LC_ALL LC_MESSAGES LC_NUMERIC LC_MONETARY LC_COLLATE 57 | unset HOME MAIL USER USERNAME 58 | daemon $prog -stayalive -reuse -pidfile /var/run/xinetd.pid "$EXTRAOPTIONS" 59 | RETVAL=$? 60 | echo 61 | touch /var/lock/subsys/xinetd 62 | return $RETVAL 63 | } 64 | 65 | stop(){ 66 | echo -n $"Stopping $prog: " 67 | killproc $prog 68 | RETVAL=$? 69 | echo 70 | rm -f /var/lock/subsys/xinetd 71 | return $RETVAL 72 | 73 | } 74 | 75 | reload(){ 76 | echo -n $"Reloading configuration: " 77 | killproc $prog -HUP 78 | RETVAL=$? 79 | echo 80 | return $RETVAL 81 | } 82 | 83 | restart(){ 84 | stop 85 | start 86 | } 87 | 88 | condrestart(){ 89 | [ -e /var/lock/subsys/xinetd ] && restart 90 | return 0 91 | } 92 | 93 | dump(){ 94 | echo -n $"Dumping configuration: " 95 | killproc $prog -USR1 96 | RETVAL=$? 97 | echo 98 | return $RETVAL 99 | } 100 | 101 | check(){ 102 | echo -n $"Performing Consistency Check: " 103 | /bin/kill -s IOT $prog 104 | RETVAL=$? 105 | echo 106 | return $RETVAL 107 | } 108 | 109 | # See how we were called. 110 | case "$1" in 111 | start) 112 | start 113 | ;; 114 | stop) 115 | stop 116 | ;; 117 | status) 118 | status $prog 119 | ;; 120 | restart) 121 | restart 122 | ;; 123 | reload) 124 | reload 125 | ;; 126 | condrestart) 127 | condrestart 128 | ;; 129 | dump) 130 | dump 131 | ;; 132 | check) 133 | check 134 | ;; 135 | *) 136 | echo $"Usage: $0 {start|stop|status|restart|condrestart|reload|dump|check}" 137 | RETVAL=1 138 | esac 139 | 140 | exit $RETVAL 141 | -------------------------------------------------------------------------------- /src/pset/pset.c: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis 3 | * All rights reserved. The file named COPYRIGHT specifies the terms 4 | * and conditions for redistribution. 5 | */ 6 | 7 | 8 | #include "config.h" 9 | #include 10 | #include "pset.h" 11 | 12 | 13 | #define ALLOC_START 20 14 | #define ALLOC_STEP 10 15 | 16 | 17 | static __pset_pointer pset_insert( pset_h pset, const __pset_pointer p ); 18 | 19 | 20 | /* 21 | * Create a pointer set and return a handle to it. 22 | * Some space is initially allocated for the set. 23 | */ 24 | pset_h pset_create( unsigned alloc_start, unsigned alloc_step ) 25 | { 26 | pset_h pset ; 27 | unsigned start ; 28 | 29 | pset = (pset_h) malloc( sizeof( struct __pset ) ) ; 30 | if ( pset == NULL ) 31 | return( NULL ) ; 32 | 33 | start = ( alloc_start == 0 ) ? ALLOC_START : alloc_start ; 34 | pset->ptrs = (__pset_pointer *) malloc( start * sizeof( __pset_pointer ) ) ; 35 | if ( pset->ptrs == NULL ) 36 | { 37 | free( (char *) pset ) ; 38 | return( NULL ) ; 39 | } 40 | 41 | pset->max = start ; 42 | pset->count = 0 ; 43 | pset->alloc_step = ( alloc_step == 0 ) ? ALLOC_STEP : alloc_step ; 44 | return( pset ) ; 45 | } 46 | 47 | 48 | /* 49 | * Destroy a pset 50 | */ 51 | void pset_destroy( pset_h pset ) 52 | { 53 | if ( pset == NULL ) 54 | return; 55 | free( (char *) pset->ptrs ) ; 56 | free( (char *) pset ) ; 57 | } 58 | 59 | __pset_pointer pset_add( pset_h pset, const __pset_pointer ptr ) 60 | { 61 | return (pset->count < pset->max ) 62 | ? (pset->ptrs[ pset->count++ ] = ptr) 63 | : pset_insert( pset, ptr) ; 64 | } 65 | 66 | /* 67 | * Append a pointer to a pset 68 | */ 69 | static __pset_pointer pset_insert( pset_h pset, const __pset_pointer p ) 70 | { 71 | if ( pset->count >= pset->max ) 72 | { 73 | unsigned new_max = pset->max + pset->alloc_step ; 74 | __pset_pointer *new_ptrs ; 75 | 76 | new_ptrs = (__pset_pointer *) realloc( 77 | (char *)pset->ptrs, new_max * sizeof( __pset_pointer ) ) ; 78 | if ( new_ptrs == NULL ) 79 | return( NULL ) ; 80 | pset->max = new_max ; 81 | pset->ptrs = new_ptrs ; 82 | } 83 | return( pset->ptrs[ pset->count++ ] = p ) ; 84 | } 85 | 86 | 87 | /* 88 | * Remove a pointer from a pset by moving every thing above it down 1 spot. 89 | */ 90 | void pset_delete( register pset_h pset, register const __pset_pointer ptr ) 91 | { 92 | register unsigned u = 0; 93 | register int found_it = 0; 94 | 95 | if ( pset->count == 0 ) 96 | return ; 97 | 98 | while ( u < pset->count ) 99 | { 100 | if ( pset->ptrs[ u ] == ptr ) 101 | found_it = 1; 102 | if ( found_it ) 103 | { /* If not the last one, copy it */ 104 | if ( (u+1) < pset->count ) 105 | pset->ptrs[ u ] = pset->ptrs[ u+1 ]; 106 | } 107 | u++; 108 | } 109 | pset->count--; 110 | } 111 | 112 | 113 | /* 114 | * Create a pset iterator 115 | */ 116 | psi_h psi_create( pset_h pset ) 117 | { 118 | psi_h iter = (psi_h) malloc( sizeof( struct __pset_iterator ) ) ; 119 | 120 | if ( iter == NULL ) 121 | return( NULL ) ; 122 | iter->pset = pset ; 123 | return( iter ) ; 124 | } 125 | 126 | /* 127 | * Remove an element from a pset 128 | */ 129 | void psi_remove( psi_h iter ) 130 | { 131 | if ( iter->current < pset_count( iter->pset ) ) 132 | { 133 | pset_remove_index( iter->pset, iter->current ) ; 134 | iter->step = 0; 135 | } 136 | } 137 | 138 | -------------------------------------------------------------------------------- /src/server.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992 by Panagiotis Tsirigotis 3 | * (c) Sections Copyright 1998-2001 by Rob Braun 4 | * All rights reserved. The file named COPYRIGHT specifies the terms 5 | * and conditions for redistribution. 6 | */ 7 | 8 | #ifndef SERVER_H 9 | #define SERVER_H 10 | 11 | /* 12 | * $Id$ 13 | */ 14 | 15 | #include "config.h" 16 | #include 17 | #include 18 | #include 19 | 20 | #include "defs.h" 21 | #include "pset.h" 22 | 23 | #ifdef NO_POSIX_TYPES 24 | typedef int pid_t ; 25 | #endif 26 | 27 | 28 | /* 29 | * This struct describes running servers 30 | */ 31 | struct server 32 | { 33 | pid_t svr_pid ; 34 | time_t svr_start_time ; 35 | connection_s *svr_conn ; 36 | struct service *svr_sp ; /* service that owns this server */ 37 | int svr_fork_failures ; /* number of fork(2) failures */ 38 | int svr_exit_status ; 39 | bool_int svr_log_remote_user ; 40 | bool_int svr_writes_to_log ; /* needed because a service may be */ 41 | /* reconfigured between server */ 42 | /* forking and exit */ 43 | } ; 44 | 45 | #define SERP( p ) ((struct server *)(p)) 46 | 47 | #define SERVER_SERVICE( serp ) (serp)->svr_sp 48 | #define SERVER_CONNECTION( serp) (connection_s *)(serp)->svr_conn 49 | #define SERVER_CONNSERVICE( serp ) CONN_SERVICE( SERVER_CONNECTION( serp ) ) 50 | #define SERVER_FD( serp ) CONN_DESCRIPTOR( (serp)->svr_conn ) 51 | #define SERVER_PID( serp ) (serp)->svr_pid 52 | #define SERVER_EXITSTATUS( serp ) (serp)->svr_exit_status 53 | #define SERVER_STARTTIME( serp ) (serp)->svr_start_time 54 | #define SERVER_LOGUSER( serp ) (serp)->svr_log_remote_user 55 | #define SERVER_FORK_FAILURES( serp ) (serp)->svr_fork_failures 56 | #define SERVER_WRITES_TO_LOG( serp ) (serp)->svr_writes_to_log 57 | 58 | #define SERVER_FORKLIMIT( serp ) \ 59 | ( (serp)->svr_fork_failures >= MAX_FORK_FAILURES ) 60 | 61 | #define SERVER_SET_PID( serp, pid ) (serp)->svr_pid = (pid) 62 | #define SERVER_SET_EXIT_STATUS( serp, status ) \ 63 | (serp)->svr_exit_status = (status) 64 | 65 | 66 | /* 67 | * Macros for compatibility 68 | */ 69 | #ifndef OLD_WAIT 70 | #define PROC_EXITED( s ) WIFEXITED( s ) 71 | #define PROC_SIGNALED( s ) WIFSIGNALED( s ) 72 | #define PROC_STOPPED( s ) WIFSTOPPED( s ) 73 | #define PROC_EXITSTATUS( s ) WEXITSTATUS( s ) 74 | #define PROC_TERMSIG( s ) WTERMSIG( s ) 75 | #else 76 | #define PROC_EXITED( s ) WIFEXITED( *(union wait *)&(s) ) 77 | #define PROC_SIGNALED( s ) WIFSIGNALED( *(union wait *)&(s) ) 78 | #define PROC_STOPPED( s ) WIFSTOPPED( *(union wait *)&(s) ) 79 | #define PROC_EXITSTATUS( s ) (((union wait *)&(s))->w_T.w_Retcode) 80 | #define PROC_TERMSIG( s ) (((union wait *)&(s))->w_T.w_Termsig) 81 | #endif /* OLD_WAIT */ 82 | 83 | void server_release(struct server *serp); 84 | status_e server_run(struct service *sp,connection_s *cp); 85 | status_e server_start(struct server *serp); 86 | void server_dump(const struct server *serp,int fd); 87 | void server_end(struct server *serp); 88 | struct server *server_lookup(pid_t pid); 89 | struct server *server_alloc( const struct server *init_serp ); 90 | 91 | #endif /* SERVER_H */ 92 | 93 | -------------------------------------------------------------------------------- /m4/ax_check_compile_flag.m4: -------------------------------------------------------------------------------- 1 | # =========================================================================== 2 | # http://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html 3 | # =========================================================================== 4 | # 5 | # SYNOPSIS 6 | # 7 | # AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS]) 8 | # 9 | # DESCRIPTION 10 | # 11 | # Check whether the given FLAG works with the current language's compiler 12 | # or gives an error. (Warnings, however, are ignored) 13 | # 14 | # ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on 15 | # success/failure. 16 | # 17 | # If EXTRA-FLAGS is defined, it is added to the current language's default 18 | # flags (e.g. CFLAGS) when the check is done. The check is thus made with 19 | # the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to 20 | # force the compiler to issue an error when a bad flag is given. 21 | # 22 | # NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this 23 | # macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG. 24 | # 25 | # LICENSE 26 | # 27 | # Copyright (c) 2008 Guido U. Draheim 28 | # Copyright (c) 2011 Maarten Bosmans 29 | # 30 | # This program is free software: you can redistribute it and/or modify it 31 | # under the terms of the GNU General Public License as published by the 32 | # Free Software Foundation, either version 3 of the License, or (at your 33 | # option) any later version. 34 | # 35 | # This program is distributed in the hope that it will be useful, but 36 | # WITHOUT ANY WARRANTY; without even the implied warranty of 37 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 38 | # Public License for more details. 39 | # 40 | # You should have received a copy of the GNU General Public License along 41 | # with this program. If not, see . 42 | # 43 | # As a special exception, the respective Autoconf Macro's copyright owner 44 | # gives unlimited permission to copy, distribute and modify the configure 45 | # scripts that are the output of Autoconf when processing the Macro. You 46 | # need not follow the terms of the GNU General Public License when using 47 | # or distributing such scripts, even though portions of the text of the 48 | # Macro appear in them. The GNU General Public License (GPL) does govern 49 | # all other use of the material that constitutes the Autoconf Macro. 50 | # 51 | # This special exception to the GPL applies to versions of the Autoconf 52 | # Macro released by the Autoconf Archive. When you make and distribute a 53 | # modified version of the Autoconf Macro, you may extend this special 54 | # exception to the GPL to apply to your modified version as well. 55 | 56 | #serial 2 57 | 58 | AC_DEFUN([AX_CHECK_COMPILE_FLAG], 59 | [AC_PREREQ(2.59)dnl for _AC_LANG_PREFIX 60 | AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl 61 | AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [ 62 | ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS 63 | _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1" 64 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], 65 | [AS_VAR_SET(CACHEVAR,[yes])], 66 | [AS_VAR_SET(CACHEVAR,[no])]) 67 | _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags]) 68 | AS_IF([test x"AS_VAR_GET(CACHEVAR)" = xyes], 69 | [m4_default([$2], :)], 70 | [m4_default([$3], :)]) 71 | AS_VAR_POPDEF([CACHEVAR])dnl 72 | ])dnl AX_CHECK_COMPILE_FLAGS 73 | -------------------------------------------------------------------------------- /src/special.c: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992 by Panagiotis Tsirigotis 3 | * (c) Sections Copyright 1998-2001 by Rob Braun 4 | * All rights reserved. The file named COPYRIGHT specifies the terms 5 | * and conditions for redistribution. 6 | */ 7 | 8 | #include "config.h" 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "special.h" 16 | #include "server.h" 17 | #include "msg.h" 18 | #include "sconst.h" 19 | #include "int.h" 20 | #include "util.h" 21 | #include "nvlists.h" 22 | #include "service.h" 23 | #include "state.h" 24 | #include "main.h" 25 | #include "connection.h" 26 | #include "sconf.h" 27 | #include "options.h" 28 | #include "xconfig.h" 29 | #include "ident.h" 30 | 31 | 32 | static void stream_logging( struct server *) ; 33 | 34 | static const struct builtin_service special_services[] = 35 | { 36 | { LOG_SERVICE_NAME, SOCK_STREAM, { stream_logging, FORK } }, 37 | { INTERCEPT_SERVICE_NAME, SOCK_STREAM, { intercept, FORK } }, 38 | { INTERCEPT_SERVICE_NAME, SOCK_DGRAM, { intercept, FORK } }, 39 | { NULL, 0, { NULL, 0 } } 40 | } ; 41 | 42 | 43 | const builtin_s *spec_find( const char *service_name, int type ) 44 | { 45 | const builtin_s *bp ; 46 | const struct name_value *nvp ; 47 | const char *func = "spec_find" ; 48 | 49 | if ( (bp = builtin_lookup( special_services, service_name, type )) ) 50 | return( bp ) ; 51 | 52 | nvp = nv_find_name( socket_types, type ) ; 53 | if ( nvp == NULL ) 54 | { 55 | msg( LOG_ERR, func, "unknown socket type: %d", type ) ; 56 | return( NULL ) ; 57 | } 58 | 59 | msg( LOG_ERR, func, 60 | "special service %s,%s not supported", service_name, nvp->name ) ; 61 | return( NULL ) ; 62 | } 63 | 64 | 65 | status_e spec_service_handler( struct service *sp, connection_s *cp ) 66 | { 67 | return(server_run( sp, cp )); 68 | } 69 | 70 | 71 | static struct service *spec_setup( const char *name, int socket_type, 72 | int instances ) 73 | { 74 | const builtin_s *bp ; 75 | struct service_config *scp ; 76 | 77 | bp = spec_find( name, socket_type ) ; 78 | if ( bp == NULL ) 79 | return( NULL ) ; 80 | 81 | if ( ( scp = sc_make_special( name, bp, instances ) ) == NULL ) 82 | return( NULL ) ; 83 | 84 | return( svc_make_special( scp ) ) ; 85 | } 86 | 87 | 88 | /* 89 | * Initialize the special services and the corresponding entries in 90 | * the program state structure. 91 | */ 92 | void spec_include(void) 93 | { 94 | int instances ; 95 | 96 | instances = logprocs_option ? logprocs_option_arg : DEFAULT_LOGPROCS ; 97 | LOG_SERVICE( ps ) = spec_setup( LOG_SERVICE_NAME, SOCK_STREAM, instances ) ; 98 | } 99 | 100 | 101 | static void stream_logging( struct server *serp ) 102 | { 103 | const char *func = "stream_logging" ; 104 | idresult_e result ; 105 | 106 | #ifdef DEBUG_LOGGING 107 | if ( debug.on ) 108 | { 109 | msg( LOG_DEBUG, func, "%d is sleeping", getpid() ) ; 110 | sleep( 10 ) ; 111 | } 112 | #endif 113 | 114 | result = log_remote_user( serp, LOGUSER_FAILURE_TIMEOUT ) ; 115 | if ( (result != IDR_OK) && (result != IDR_NOSERVER) ) 116 | msg( LOG_ERR, func, "Failed to contact identity server at %s: %s", conn_addrstr( SERVER_CONNECTION( serp ) ), idresult_explain( result ) ) ; 117 | } 118 | 119 | -------------------------------------------------------------------------------- /src/xconv.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | #/* 3 | # * (c) Copyright 1998-2001 by Rob Braun 4 | # * All rights reserved. The file named COPYRIGHT specifies the terms 5 | # * and conditions for redistribution. 6 | # */ 7 | 8 | # $RCSid = "$Id$"; 9 | 10 | sub print_header; 11 | sub print_defaults; 12 | 13 | 14 | print_header; 15 | print_defaults; 16 | 17 | while( ) { 18 | 19 | chomp; 20 | 21 | # Remove comment lines 22 | if( grep /^#/, $_ ) { 23 | next; 24 | } 25 | 26 | @command = split ; 27 | 28 | if( !defined $command[0] ) { 29 | next; 30 | } 31 | 32 | if( grep /rpc/, $command[2] ) { 33 | print STDERR "Warning: Service $command[0] not added because\n"; 34 | print STDERR "xinetd does not handle rpc services well\n"; 35 | next; 36 | } 37 | 38 | print "service $command[0]\n"; 39 | print "{\n"; 40 | print "\tflags = NAMEINARGS\n"; 41 | print "\tsocket_type = $command[1]\n"; 42 | print "\tprotocol = $command[2]\n"; 43 | if( grep /no/, $command[3] ) { 44 | print "\twait = no\n"; 45 | } else { 46 | print "\twait = yes\n"; 47 | } 48 | @user = split /[:\.]/, $command[4]; 49 | print "\tuser = $user[0]\n"; 50 | if( defined $user[1] ) { 51 | print "\tgroup = $user[1]\n"; 52 | } 53 | if( grep /internal/, $command[5] ) { 54 | print "\ttype = INTERNAL\n"; 55 | print "\tid = $command[0]-$command[1]\n"; 56 | } else { 57 | print "\tserver = $command[5]\n"; 58 | print "\tserver_args = "; 59 | 60 | $i = 6; 61 | while( defined $command[$i] ) { 62 | print "$command[$i] "; 63 | $i++; 64 | } 65 | 66 | print "\n"; 67 | } 68 | print "}\n"; 69 | print "\n"; 70 | } 71 | 72 | sub print_defaults 73 | { 74 | print "# The defaults section sets some information for all services\n"; 75 | print "defaults\n"; 76 | print "{\n"; 77 | print "\t#The maximum number of requests a particular service may handle\n"; 78 | print "\t# at once.\n"; 79 | print "\tinstances = 25\n"; 80 | print "\n"; 81 | print "\t# The type of logging. This logs to a file that is specified.\n"; 82 | print "\t# Another option is: SYSLOG syslog_facility [syslog_level]\n"; 83 | print "\tlog_type = FILE /var/log/servicelog\n"; 84 | print "\n"; 85 | print "\t# What to log when the connection succeeds.\n"; 86 | print "\t# PID logs the pid of the server processing the request.\n"; 87 | print "\t# HOST logs the remote host's ip address.\n"; 88 | print "\t# USERID logs the remote user (using RFC 1413)\n"; 89 | print "\t# EXIT logs the exit status of the server.\n"; 90 | print "\t# DURATION logs the duration of the session.\n"; 91 | print "\tlog_on_success = HOST PID\n"; 92 | print "\n"; 93 | print "\t# What to log when the connection fails. Same options as above\n"; 94 | print "\tlog_on_failure = HOST\n"; 95 | print "\n"; 96 | print "\t# The maximum number of connections a specific IP address can\n"; 97 | print "\t# have to a specific service. \n"; 98 | print "\tper_source = 5\n"; 99 | 100 | print "}\n"; 101 | print "\n"; 102 | } 103 | 104 | sub print_header 105 | { 106 | print "# This file generated by xconv.pl, included with the xinetd\n"; 107 | print "# package. xconv.pl was written by Rob Braun (bbraun\@synack.net)\n"; 108 | print "#\n"; 109 | print "# The file is merely a translation of your inetd.conf file into\n"; 110 | print "# the equivalent in xinetd.conf syntax. xinetd has many \n"; 111 | print "# features that may not be taken advantage of with this translation.\n"; 112 | print "# Please refer to the xinetd.conf man page for more information \n"; 113 | print "# on how to properly configure xinetd.\n"; 114 | print "\n"; 115 | print "\n"; 116 | } 117 | -------------------------------------------------------------------------------- /man/m_env.3: -------------------------------------------------------------------------------- 1 | .\"(c) Copyright 1992 by Panagiotis Tsirigotis 2 | .\"All rights reserved. The file named COPYRIGHT specifies the terms 3 | .\"and conditions for redistribution. 4 | .\" 5 | .\" $Id$ 6 | .TH ENV 3L "20 October 1992" 7 | .SH NAME 8 | env_create, env_destroy, env_make, env_addvar, env_addstr, env_remvar, env_lookup, env_getvars -- environment manipulation functions 9 | .SH SYNOPSIS 10 | .LP 11 | .nf 12 | .ft B 13 | #include "m_env.h" 14 | .LP 15 | .ft B 16 | env_h env_create( env ) 17 | env_h env ; 18 | .LP 19 | .ft B 20 | void env_destroy( env ) 21 | env_h env ; 22 | .LP 23 | .ft B 24 | env_h env_make( env_strings ) 25 | char **env_strings ; 26 | .LP 27 | .ft B 28 | int env_addvar( env, from_env, var ) 29 | env_h env ; 30 | env_h from_env ; 31 | char *var ; 32 | .LP 33 | .ft B 34 | int env_addstr( env, str ) 35 | env_h env ; 36 | char *str ; 37 | .LP 38 | .ft B 39 | int env_remvar( env, var ) 40 | env_h env ; 41 | char *var ; 42 | .LP 43 | .ft B 44 | char **env_getvars( env ) 45 | env_h env ; 46 | .SH DESCRIPTION 47 | This library handles environments. An environment is a set of strings 48 | of the form 49 | .I "name=value". 50 | In the following, we will use the term string as a synonym of 51 | NUL-terminated array of 52 | .I char. 53 | .LP 54 | .B env_create() 55 | creates a new environment. The new environment will be empty unless 56 | the argument 57 | .I env 58 | is not 59 | .SB ENV_NULL. 60 | In that case, the new environment will be a duplicate of 61 | .I env 62 | (i.e. they will contain the same strings). 63 | .LP 64 | .B env_destroy() 65 | destroys the specified environment. 66 | .LP 67 | .B env_make() 68 | creates a new environment which includes the 69 | .I env_strings. 70 | .I env_strings 71 | should be a NULL-terminated array of strings. 72 | .LP 73 | .B env_addvar() 74 | adds the specified variable 75 | .I var 76 | to 77 | .I env. 78 | The variable value is obtained from the environment 79 | .I from_env. 80 | If the variable exists already in 81 | .I env 82 | the old value is replaced with the new value. 83 | .LP 84 | .B env_addstr() 85 | adds a string of the form 86 | .I "name=value" 87 | to 88 | .I env. 89 | .LP 90 | .B env_remvar() 91 | removes the specified variable 92 | .I var 93 | from the environment 94 | .I env. 95 | .LP 96 | .B env_lookup() 97 | searches 98 | .I env 99 | for variable 100 | .I var. 101 | It returns a string of the form 102 | .I "name=value" 103 | where 104 | .I name 105 | is the name of the variable 106 | (i.e. it is equal to 107 | .I var). 108 | .LP 109 | .B env_getvars 110 | returns a NULL-terminated array of strings of the form 111 | .I "name=value". 112 | .SH "RETURN VALUES" 113 | In case of error, all calls will place an error code in the global variable 114 | .I env_errno. 115 | Possible error codes: 116 | .TP 15 117 | .SB ENV_ENOMEM 118 | out of memory 119 | .TP 120 | .SB ENV_EBADVAR 121 | variable is not in environment 122 | .TP 123 | .SB ENV_EBADSTRING 124 | string is not well-formed (i.e. is not of the form \fIname=value\fR). 125 | .LP 126 | .B env_create() 127 | returns a handle or 128 | .SM ENV_NULL 129 | if it fails. 130 | .LP 131 | .B env_make() 132 | returns a handle or 133 | .SM ENV_NULL 134 | if it fails. 135 | .LP 136 | .B env_addvar() 137 | returns 138 | .SM ENV_OK 139 | on success or 140 | .SM ENV_ERR 141 | on failure. 142 | .LP 143 | .B env_addstr() 144 | returns 145 | .SM ENV_OK 146 | on success or 147 | .SM ENV_ERR 148 | on failure. 149 | .LP 150 | .B env_remvar() 151 | returns 152 | .SM ENV_OK 153 | on success or 154 | .SM ENV_ERR 155 | if the variable is not part of the environment. 156 | .LP 157 | .B env_loopkup() 158 | returns a string on success or 159 | .SM NULL 160 | on failure. 161 | .SH "SEE ALSO" 162 | environ(5) 163 | -------------------------------------------------------------------------------- /man/xinetd.log.5: -------------------------------------------------------------------------------- 1 | .\"(c) Copyright 1992 by Panagiotis Tsirigotis 2 | .\"(c) Sections Copyright 1998-2001 by Rob Braun 3 | .\"All rights reserved. The file named COPYRIGHT specifies the terms 4 | .\"and conditions for redistribution. 5 | .\" 6 | .\" $Id$ 7 | .TH XINETD.LOG 5 "28 April 1993" 8 | .SH NAME 9 | xinetd.log \- xinetd service log format 10 | .\" *********************** DESCRIPTION **************************** 11 | .SH "DESCRIPTION" 12 | A service configuration may specify various degrees of logging when 13 | attempts are made to access the service. When logging for a service 14 | is enabled, 15 | .B xinetd 16 | will generate one-line log entries which have the following format 17 | (all entries have a timestamp as a prefix): 18 | .sp 1 19 | .RS 20 | \fIentry\fP: \fIservice-id\fP \fIdata\fP 21 | .RE 22 | .LP 23 | The \fIdata\fP depends on the \fIentry\fP. 24 | Possible \fIentry\fP types include: 25 | .RS 26 | .TP 12 27 | .B START 28 | generated when a server is started 29 | .TP 30 | .B EXIT 31 | generated when a server exits 32 | .TP 33 | .B FAIL 34 | generated when it is not possible to start a server 35 | .TP 36 | .B USERID 37 | generated if the \fIUSERID\fP log option is used. 38 | .TP 39 | .B NOID 40 | generated if the 41 | .I USERID 42 | log option is used, 43 | and the 44 | .I IDONLY 45 | service flag is used, 46 | and the remote end does not identify who is trying to access the service. 47 | .RE 48 | .LP 49 | In the following, the information enclosed in brackets appears 50 | if the appropriate log option is used. 51 | .LP 52 | A \fISTART\fP entry has the format: 53 | .sp 1 54 | .RS 55 | START: \fIservice-id\fP [pid=%d] [from=%d.%d.%d.%d] 56 | .RE 57 | .LP 58 | An \fIEXIT\fP entry has the format: 59 | .sp 1 60 | .RS 61 | EXIT: \fIservice-id\fP [\fItype\fP=%d] [pid=%d] [duration=%d(sec)] 62 | .RE 63 | .sp 1 64 | .I type 65 | can be either 66 | .B status 67 | or 68 | .B signal. 69 | The number is either the exit status or the signal that caused process 70 | termination. 71 | .LP 72 | A \fIFAIL\fP entry has the format: 73 | .sp 1 74 | .RS 75 | FAIL: \fIservice-id\fP \fIreason\fP [from=%d.%d.%d.%d] 76 | .RE 77 | .sp 1 78 | Possible \fIreasons\fP are: 79 | .RS 80 | .TP 15 81 | .B fork 82 | a certain number of consecutive fork attempts failed (this number is 83 | a configurable parameter) 84 | .TP 85 | .B time 86 | the time check failed 87 | .TP 88 | .B address 89 | the address check failed 90 | .TP 91 | .B service_limit 92 | the allowed number of server instances for this service would be exceeded 93 | .TP 94 | .B process_limit 95 | a limit on the number of forked processes was specified and it would 96 | be exceeded 97 | .RE 98 | .LP 99 | A \fIDATA\fP entry has the format: 100 | .sp 1 101 | .RS 102 | DATA: \fIservice-id\fP \fIdata\fP 103 | .RE 104 | .sp 1 105 | The \fIdata\fP logged depends on the service. 106 | .RS 107 | .TP 12 108 | .B login 109 | remote_user=%s local_user=%s tty=%s 110 | .TP 111 | .B exec 112 | remote_user=%s verify=\fIstatus\fP command=%s 113 | .br 114 | Possible 115 | .I status 116 | values: 117 | .RS 118 | .TP 10 119 | .I ok 120 | the password was correct 121 | .TP 122 | .I failed 123 | the password was incorrect 124 | .TP 125 | .I baduser 126 | no such user 127 | .RE 128 | .TP 129 | .B shell 130 | remote_user=%s local_user=%s command=%s 131 | .TP 132 | .B finger 133 | \fIreceived string\fP or 134 | .I EMPTY-LINE 135 | .RE 136 | .LP 137 | A \fIUSERID\fP entry has the format: 138 | .sp 1 139 | .RS 140 | USERID: \fIservice-id\fP \fItext\fP 141 | .RE 142 | .sp 1 143 | The \fItext\fP is the response of the identification daemon at the remote end 144 | excluding the port numbers (which are included in the response). 145 | .LP 146 | A \fINOID\fP entry has the format: 147 | .sp 1 148 | .RS 149 | NOID: \fIservice-id\fP \fIIP-address\fP \fIreason\fP 150 | .RE 151 | .\" *********************** SEE ALSO **************************** 152 | .SH "SEE ALSO" 153 | .BR xinetd "(1L), " xinetd.conf (5) 154 | -------------------------------------------------------------------------------- /man/strprint.3: -------------------------------------------------------------------------------- 1 | .\"(c) Copyright 1992, 1993 by Panagiotis Tsirigotis 2 | .\"All rights reserved. The file named COPYRIGHT specifies the terms 3 | .\"and conditions for redistribution. 4 | .\" 5 | .\" $Id$ 6 | .TH STRPRINT 3X "30 September 1992" 7 | .SH NAME 8 | str_sprint, tr_sprintv, str_nprint, str_nprintv, str_print, str_printv, strx_sprint, strx_sprintv, strx_nprint, strx_nprintv, strx_print, strx_printv -- formatted conversion to string 9 | .SH SYNOPSIS 10 | .LP 11 | .nf 12 | .ft B 13 | #include "str.h" 14 | .LP 15 | .ft B 16 | char *str_sprint( buf, format, ... ) 17 | char *buf ; 18 | char *format ; 19 | .LP 20 | .ft B 21 | char *str_sprintv( buf, format, ap ) 22 | char *buf ; 23 | char *format ; 24 | va_list ap ; 25 | .LP 26 | .ft B 27 | int str_nprint( buf, format, ... ) 28 | char *buf ; 29 | char *format ; 30 | .LP 31 | .ft B 32 | int str_nprintv( buf, format, ap ) 33 | char *buf ; 34 | char *format ; 35 | va_list ap ; 36 | .LP 37 | .ft B 38 | void str_print( countp, buf, format, ... ) 39 | int *countp ; 40 | char *buf ; 41 | char *format ; 42 | .LP 43 | .ft B 44 | void str_printv( countp, buf, format, ap ) 45 | int *countp ; 46 | char *buf ; 47 | char *format ; 48 | va_list ap ; 49 | .LP 50 | .ft B 51 | char *strx_sprint( buf, len, format, ... ) 52 | char *buf ; 53 | int len ; 54 | char *format ; 55 | .LP 56 | .ft B 57 | char *strx_sprintv( buf, len, format, ap ) 58 | char *buf ; 59 | int len ; 60 | char *format ; 61 | va_list ap ; 62 | .LP 63 | .ft B 64 | int strx_nprint( buf, len, format, ... ) 65 | char *buf ; 66 | int len ; 67 | char *format ; 68 | .LP 69 | .ft B 70 | int strx_nprintv( buf, len, format, ap ) 71 | char *buf ; 72 | int len ; 73 | char *format ; 74 | va_list ap ; 75 | .LP 76 | .ft B 77 | void strx_print( countp, buf, len, format, ... ) 78 | int *countp ; 79 | char *buf ; 80 | int len ; 81 | char *format ; 82 | .LP 83 | .ft B 84 | void strx_printv( countp, buf, len, format, ap ) 85 | int *countp ; 86 | char *buf ; 87 | int len ; 88 | char *format ; 89 | va_list ap ; 90 | .SH DESCRIPTION 91 | .LP 92 | All functions are similar in functionality to \fIsprintf()\fR. 93 | Their only difference is in their return values. For information about their 94 | conversion capabilities, check \fISprint(3)\fR. 95 | .LP 96 | The difference between the \fIstr_*\fR and the \fIstrx_*\fR functions 97 | is that the latter take an extra argument, the size of the buffer, so 98 | that they will never write beyond the end of the buffer. Writing 99 | beyond the end of the buffer is possible with the \fIstr_*\fR functions. 100 | Previously, invoking any of the \fIstrx_*\fR functions with the 101 | .I len 102 | argument set to 0 103 | used to be the same as calling the equivalent \fIstr_*\fR function. 104 | This dangerous behavior has since been changed and now the \fIstrx_*\fR 105 | functions don't touch the buffer when 106 | .I len 107 | is 0 or negative. 108 | .LP 109 | All functions will append a 110 | .SM NUL 111 | at the end of 112 | .I buf 113 | (the \fIstrx_*\fR functions will not do this if it would cause 114 | a buffer overrun). 115 | .LP 116 | .B str_print(), 117 | .B str_printv(), 118 | .B strx_print(), 119 | and 120 | .B strx_printv() 121 | will put in 122 | .I "*countp" 123 | the number of characters placed in 124 | .I buf 125 | excluding the ending 126 | .SM NUL 127 | (this happens only if 128 | .I "*countp" 129 | is not 130 | .SM NULL 131 | ). 132 | .LP 133 | The functions that have a name ending in 'v' are similar to those without 134 | the 'v' at the end of their name 135 | except that instead of accepting a variable number of arguments, they 136 | expect a \fIstdarg(3)\fR argument list. 137 | .SH "RETURN VALUES" 138 | .LP 139 | .B str_sprint(), 140 | .B str_sprintv(), 141 | .B strx_sprint(), 142 | and 143 | .B strx_sprintv() 144 | return 145 | .I buf. 146 | .LP 147 | .B str_nprint(), 148 | .B str_nprintv(), 149 | .B strx_nprint(), 150 | and 151 | .B strx_nprintv() 152 | return the number of characters placed in 153 | .I buf 154 | excluding the ending 155 | .SM NUL. 156 | .SH "SEE ALSO" 157 | Sprint(3) 158 | -------------------------------------------------------------------------------- /src/parsers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1998-2001 by Rob Braun 3 | * All rights reserved. The file named COPYRIGHT specifies the terms 4 | * and conditions for redistribution. 5 | */ 6 | #ifndef _X_PARSERS 7 | #define _X_PARSERS 8 | 9 | #include "config.h" 10 | #include "pset.h" 11 | #include "defs.h" 12 | #include "parse.h" 13 | 14 | status_e socket_type_parser(pset_h, struct service_config *, enum assign_op) ; 15 | status_e protocol_parser(pset_h, struct service_config *, enum assign_op) ; 16 | status_e wait_parser(pset_h, struct service_config *, enum assign_op) ; 17 | status_e user_parser(pset_h, struct service_config *, enum assign_op) ; 18 | status_e group_parser(pset_h, struct service_config *, enum assign_op) ; 19 | status_e server_parser(pset_h, struct service_config *, enum assign_op) ; 20 | status_e server_args_parser(pset_h, struct service_config *, enum assign_op) ; 21 | status_e instances_parser(pset_h, struct service_config *, enum assign_op) ; 22 | status_e log_on_success_parser(pset_h, struct service_config *, enum assign_op) ; 23 | status_e log_on_failure_parser(pset_h, struct service_config *, enum assign_op) ; 24 | status_e log_type_parser(pset_h, struct service_config *, enum assign_op) ; 25 | status_e only_from_parser(pset_h, struct service_config *, enum assign_op) ; 26 | status_e no_access_parser(pset_h, struct service_config *, enum assign_op) ; 27 | status_e access_times_parser(pset_h, struct service_config *, enum assign_op) ; 28 | status_e type_parser(pset_h, struct service_config *, enum assign_op) ; 29 | status_e id_parser(pset_h, struct service_config *, enum assign_op) ; 30 | status_e env_parser(pset_h, struct service_config *, enum assign_op) ; 31 | status_e port_parser(pset_h, struct service_config *, enum assign_op) ; 32 | status_e rpc_version_parser(pset_h, struct service_config *, enum assign_op) ; 33 | status_e passenv_parser(pset_h, struct service_config *, enum assign_op) ; 34 | status_e flags_parser(pset_h, struct service_config *, enum assign_op) ; 35 | status_e disabled_parser(pset_h, struct service_config *, enum assign_op) ; 36 | status_e rpc_number_parser(pset_h, struct service_config *, enum assign_op) ; 37 | status_e nice_parser(pset_h, struct service_config *, enum assign_op) ; 38 | status_e redir_parser(pset_h, struct service_config *, enum assign_op) ; 39 | status_e bind_parser(pset_h, struct service_config *, enum assign_op) ; 40 | status_e banner_parser(pset_h, struct service_config *, enum assign_op) ; 41 | status_e per_source_parser(pset_h, struct service_config *, enum assign_op) ; 42 | status_e groups_parser(pset_h, struct service_config *, enum assign_op) ; 43 | status_e banner_success_parser(pset_h, struct service_config *, enum assign_op) ; 44 | status_e banner_fail_parser(pset_h, struct service_config *, enum assign_op) ; 45 | status_e cps_parser(pset_h, struct service_config *, enum assign_op) ; 46 | status_e enabled_parser(pset_h, struct service_config *, enum assign_op) ; 47 | status_e svcdisable_parser(pset_h, struct service_config *, enum assign_op); 48 | #ifdef HAVE_LOADAVG 49 | status_e max_load_parser(pset_h, struct service_config *, enum assign_op) ; 50 | #endif 51 | #ifdef RLIMIT_AS 52 | status_e rlim_as_parser(pset_h, struct service_config *, enum assign_op) ; 53 | #endif 54 | #ifdef RLIMIT_CPU 55 | status_e rlim_cpu_parser(pset_h, struct service_config *, enum assign_op) ; 56 | #endif 57 | #ifdef RLIMIT_DATA 58 | status_e rlim_data_parser(pset_h, struct service_config *, enum assign_op) ; 59 | #endif 60 | #ifdef RLIMIT_NOFILE 61 | status_e rlim_files_parser(pset_h, struct service_config *, enum assign_op) ; 62 | #endif 63 | #ifdef RLIMIT_RSS 64 | status_e rlim_rss_parser(pset_h, struct service_config *, enum assign_op) ; 65 | #endif 66 | #ifdef RLIMIT_STACK 67 | status_e rlim_stack_parser(pset_h, struct service_config *, enum assign_op) ; 68 | #endif 69 | status_e v6only_parser(pset_h, struct service_config *, enum assign_op); 70 | status_e deny_time_parser(pset_h, struct service_config *, enum assign_op) ; 71 | status_e umask_parser(pset_h, struct service_config *, enum assign_op) ; 72 | status_e mdns_parser(pset_h, struct service_config *, enum assign_op) ; 73 | #ifdef LIBWRAP 74 | status_e libwrap_parser(pset_h, struct service_config *, enum assign_op) ; 75 | #endif 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /src/sio/impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis 3 | * All rights reserved. The file named COPYRIGHT specifies the terms 4 | * and conditions for redistribution. 5 | */ 6 | 7 | /* 8 | * $Id$ 9 | */ 10 | 11 | #ifndef SIO_BUFFER_SIZE 12 | 13 | #include "sioconf.h" 14 | #include "sio.h" 15 | 16 | #ifdef HAVE_MMAP 17 | #include 18 | 19 | 20 | /* 21 | * A struct map_unit describes a memory mapped area of a file. 22 | * 23 | * addr is the address where the file is mapped. If addr is NULL 24 | * the other fields are meaningless. 25 | * valid_bytes indicates how many bytes are _valid_ in that unit 26 | * mapped_bytes of a unit is how many bytes are mapped in that 27 | * unit ( valid <= mapped ). 28 | * Normally mapped_bytes will be equal to valid_bytes until 29 | * we reach the end of the file. Then if the file size is not a multiple 30 | * of the unit size, only the rest of the file will be mapped at the 31 | * unit, leaving part of what was mapped at the unit before still 32 | * visible (this happens because I chose not to unmap a unit before 33 | * remapping it). In that case valid_bytes shows the size of the "new" 34 | * mapping and mapped_bytes shows how many bytes are really mapped. 35 | * mapped_bytes is used in Sdone() to unmap the units. 36 | */ 37 | struct map_unit 38 | { 39 | caddr_t addr ; 40 | size_t valid_bytes ; 41 | size_t mapped_bytes ; 42 | } ; 43 | 44 | 45 | /* 46 | * Meaning of fields used when memory mapping: 47 | * 48 | * file_offset: it is the offset in the file where the next 49 | * mapping should be done 50 | * 51 | * file_size: size of the file (obtained from stat(2)) 52 | */ 53 | struct mmap_descriptor 54 | { 55 | off_t file_offset ; 56 | off_t file_size ; 57 | struct map_unit first_unit ; 58 | struct map_unit second_unit ; 59 | } ; 60 | 61 | typedef struct mmap_descriptor mapd_s ; 62 | 63 | #endif /* HAVE_MMAP */ 64 | 65 | typedef enum { FAILURE, SUCCESS } sio_status_e ; 66 | 67 | /* 68 | * Descriptor management: convert a descriptor pointer to an input or 69 | * output descriptor pointer 70 | */ 71 | #define IDP( dp ) (&(dp)->descriptor.input_descriptor) 72 | #define ODP( dp ) (&(dp)->descriptor.output_descriptor) 73 | 74 | #define DESCRIPTOR_INITIALIZED( dp ) ((dp)->initialized) 75 | 76 | /* 77 | * Internal constants 78 | */ 79 | #define SIO_BUFFER_SIZE 8192 80 | #define SIO_NO_TIED_FD (-1) 81 | 82 | typedef enum { NO = 0, YES = 1 } boolean_e ; 83 | 84 | #ifndef FALSE 85 | #define FALSE 0 86 | #define TRUE 1 87 | #endif 88 | 89 | #ifndef NULL 90 | #define NULL 0 91 | #endif 92 | 93 | #ifdef MIN 94 | #undef MIN 95 | #endif 96 | #define MIN( a, b ) ( (a) < (b) ? (a) : (b) ) 97 | 98 | #define NUL '\0' 99 | 100 | #ifdef DEBUG 101 | 102 | static char *itoa( num ) 103 | unsigned num ; 104 | { 105 | #define NUMBUF_SIZE 15 106 | static char numbuf[ NUMBUF_SIZE ] ; 107 | char *p = &numbuf[ NUMBUF_SIZE ] ; 108 | 109 | *--p = '\0' ; 110 | do 111 | { 112 | *--p = num % 10 + '0' ; 113 | num /= 10 ; 114 | } 115 | while ( num ) ; 116 | return( p ) ; 117 | } 118 | 119 | # define ASSERT( expr ) \ 120 | if ( ! (expr) ) \ 121 | { \ 122 | char *s1 = "SIO assertion << expr >> failed: File: " ; \ 123 | char *s2 = __FILE__ ; \ 124 | char *s3 = ", line: " ; \ 125 | char *s4 = itoa( __LINE__ ) ; \ 126 | char *s5 = "\n" ; \ 127 | (void) write( 2, s1, strlen( s1 ) ) ; \ 128 | (void) write( 2, s2, strlen( s2 ) ) ; \ 129 | (void) write( 2, s3, strlen( s3 ) ) ; \ 130 | (void) write( 2, s4, strlen( s4 ) ) ; \ 131 | (void) write( 2, s5, strlen( s5 ) ) ; \ 132 | exit ( 1 ) ; \ 133 | } 134 | #else 135 | # define ASSERT( expr ) 136 | #endif 137 | 138 | 139 | #include 140 | 141 | /* 142 | * Internal functions that are visible 143 | */ 144 | int __sio_writef( __sio_od_t *odp, int fd ) ; 145 | ssize_t __sio_extend_buffer( __sio_id_t *idp, int fd, size_t b_left ) ; 146 | int __sio_init( __sio_descriptor_t *dp, int fd, enum __sio_stream stream_type ); 147 | ssize_t __sio_more( __sio_id_t *idp, int fd ) ; 148 | sio_status_e __sio_switch( __sio_id_t *idp, int fd ) ; 149 | 150 | 151 | #include 152 | #define sio_memcopy( from, to, nbytes ) (void) memcpy( to, from, nbytes ) 153 | #define sio_memscan( from, nbytes, ch ) memchr( from, ch, nbytes ) 154 | 155 | #endif /* SIO_BUFFER_SIZE */ 156 | 157 | -------------------------------------------------------------------------------- /src/sio/sioconf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis 3 | * All rights reserved. The file named COPYRIGHT specifies the terms 4 | * and conditions for redistribution. 5 | */ 6 | 7 | 8 | /* 9 | * $Id$ 10 | */ 11 | 12 | /* 13 | * This file has 2 sections: 14 | * 1. a OS-specific section 15 | * 2. a CPU/compiler-specific section 16 | * 17 | * You can override/redefine any of the constants/macros in this file. 18 | * by uncommenting the inclusion of customconf.h and placing your own 19 | * definitions in that file. 20 | */ 21 | 22 | /* #include "customconf.h" */ 23 | 24 | 25 | 26 | /* 27 | * OS-specific section. 28 | * 29 | * Features here use the flag HAVE_. 30 | * List of flags (check the following for macros that can be overridden): 31 | * 32 | * HAVE_MMAP (overridable macros) 33 | * 34 | * HAVE_ATEXIT 35 | * HAVE_ONEXIT 36 | * HAVE_OTHER_FINALIZER (must define macros) 37 | */ 38 | 39 | /* 40 | * Memory mapping. 41 | * The library requires 3 macros: SIO_MMAP, SIO_MUNMAP, SIO_MNEED. 42 | * You can selectively override any of them. 43 | * Notice that the SIO_MNEED macro is not required. If your system 44 | * does not have madvise, you can define the macro as: 45 | * #define SIO_MNEED( addr, len ) 46 | */ 47 | #ifdef HAVE_MMAP 48 | 49 | #if !defined( SIO_MMAP ) || !defined( SIO_MUNMAP ) || !defined( SIO_MNEED ) 50 | #include 51 | #include 52 | #endif 53 | 54 | #ifndef SIO_MMAP 55 | #define SIO_MMAP( addr, len, fd, off ) \ 56 | mmap( addr, len, PROT_READ, \ 57 | ( addr == 0 ) ? MAP_PRIVATE : MAP_PRIVATE + MAP_FIXED, \ 58 | fd, off ) 59 | #endif 60 | 61 | #ifndef SIO_MUNMAP 62 | #define SIO_MUNMAP( addr, len ) munmap( addr, len ) 63 | #endif 64 | 65 | #ifndef SIO_MNEED 66 | #if defined(linux) 67 | #define SIO_MNEED( addr, len ) 68 | #else 69 | #define SIO_MNEED( addr, len ) (void) madvise( addr, len, MADV_WILLNEED ) 70 | #endif 71 | #endif 72 | 73 | #endif /* HAVE_MMAP */ 74 | 75 | /* 76 | * N_SIO_DESCRIPTORS is the maximum number of file descriptors 77 | * supported by the OS 78 | */ 79 | #include 80 | #ifdef OPEN_MAX 81 | #define N_SIO_DESCRIPTORS OPEN_MAX 82 | #else 83 | #define N_SIO_DESCRIPTORS NOFILE 84 | #endif 85 | 86 | 87 | 88 | /* 89 | * Finalization function. 90 | * 91 | * The purpose of this function is to do work after your program has 92 | * called exit(3). In the case of SIO, this means flushing the SIO 93 | * output buffers. 94 | * 95 | * If your system does not support atexit or onexit but has some other 96 | * way of installing a finalization function, you define the flag 97 | * HAVE_FINALIZER. Then you must define the macros 98 | * SIO_FINALIZE and SIO_DEFINE_FIN 99 | * 100 | * SIO_FINALIZE attempts to install a finalization function and returns TRUE 101 | * if successful, FALSE if unsuccessful. 102 | * SIO_DEFINE_FIN defines the finalization function (the reason for this macro 103 | * s that different systems pass different number/type of arguments to the 104 | * finalization function; the SIO finalization function does not use any 105 | * arguments). 106 | */ 107 | #if defined(HAVE_ONEXIT) || defined(HAVE_ATEXIT) || defined(HAVE_FINALIZER) 108 | 109 | #define HAVE_FINALIZATION_FUNCTION 110 | 111 | #if defined( HAVE_ONEXIT ) && defined( HAVE_ATEXIT ) 112 | #undef HAVE_ONEXIT 113 | #endif 114 | 115 | #ifdef HAVE_ONEXIT 116 | #define SIO_FINALIZE( func ) ( on_exit( func, (caddr_t) 0 ) == 0 ) 117 | #define SIO_DEFINE_FIN( func ) static void func ( exit_status, arg ) \ 118 | int exit_status ; \ 119 | caddr_t arg ; 120 | #endif /* HAVE_ONEXIT */ 121 | 122 | #ifdef HAVE_ATEXIT 123 | #define SIO_FINALIZE( func ) ( atexit( func ) == 0 ) 124 | #define SIO_DEFINE_FIN( func ) static void func () 125 | #endif /* HAVE_ATEXIT */ 126 | 127 | #endif /* HAVE_ONEXIT || HAVE_ATEXIT || HAVE_FINALIZER */ 128 | 129 | 130 | /* 131 | * CPU/compiler-specific section. 132 | * 133 | * The following constant affects the behavior of Sprint. 134 | * 135 | * Sprint performs integer->string conversions by first converting 136 | * the integer to the widest int type supported by the CPU/compiler. 137 | * By default, this is the "long int" type. If your machine has 138 | * a wider type, you can specify it by defining the WIDE_INT constant. 139 | * For example: 140 | * #define WIDE_INT long long 141 | */ 142 | 143 | -------------------------------------------------------------------------------- /src/time.c: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992 by Panagiotis Tsirigotis 3 | * (c) Sections Copyright 1998-2001 by Rob Braun 4 | * All rights reserved. The file named COPYRIGHT specifies the terms 5 | * and conditions for redistribution. 6 | */ 7 | 8 | 9 | #include "config.h" 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "sio.h" 16 | #include "timex.h" 17 | #include "msg.h" 18 | #include "util.h" 19 | 20 | 21 | #define IN_RANGE( val, low, high ) ( (low) <= (val) && (val) <= (high) ) 22 | 23 | struct time_interval 24 | { 25 | int16_t min_start ; 26 | int16_t min_end ; 27 | } ; 28 | 29 | #define TIP( p ) ( (struct time_interval *) (p) ) 30 | #define NEW_TI() NEW( struct time_interval ) 31 | #define FREE_TI( tip ) FREE( tip ) 32 | 33 | 34 | /* 35 | * Returns TRUE if the current time is within at least one of the intervals 36 | */ 37 | bool_int ti_current_time_check( const pset_h intervals ) 38 | { 39 | time_t current_time ; 40 | unsigned u ; 41 | int16_t min_current ; 42 | struct tm *tmp ; 43 | 44 | (void) time( ¤t_time ) ; 45 | tmp = localtime( ¤t_time ) ; 46 | min_current = tmp->tm_hour * 60 + tmp->tm_min ; 47 | 48 | for ( u = 0 ; u < pset_count( intervals ) ; u++ ) 49 | { 50 | struct time_interval *tip ; 51 | 52 | tip = TIP( pset_pointer( intervals, u ) ) ; 53 | if ( IN_RANGE( min_current, tip->min_start, tip->min_end ) ) 54 | return( TRUE ) ; 55 | } 56 | return( FALSE ) ; 57 | } 58 | 59 | 60 | static int get_num( int *nump, 61 | int min_val, 62 | int max_val, 63 | const char *s, 64 | char stop_char ) 65 | { 66 | const char *func = "get_num" ; 67 | int i = 0; 68 | 69 | for ( *nump = 0 ; isdigit( s[i] ) ; i++ ) 70 | { 71 | *nump *= 10 ; 72 | *nump += s[i] - '0' ; 73 | } 74 | 75 | if ( s[i] != stop_char ) 76 | { 77 | parsemsg( LOG_ERR, func, "incorrect time interval" ) ; 78 | return( -1 ); 79 | } 80 | 81 | if ( ! IN_RANGE( *nump, min_val, max_val ) ) 82 | { 83 | parsemsg( LOG_ERR, func, "invalid time interval" ) ; 84 | return( -1 ) ; 85 | } 86 | return( i ) ; 87 | } 88 | 89 | 90 | /* 91 | * Each interval should have the form: 92 | * hour:min-hour:min 93 | * Example: 2:30-4:15 94 | */ 95 | status_e ti_add( pset_h iset, const char *interval_str ) 96 | { 97 | struct time_interval *tip ; 98 | int hours ; 99 | int minutes ; 100 | int min_start ; 101 | int min_end ; 102 | int p, r = 0 ; 103 | const char *func = "add_interval" ; 104 | 105 | while (interval_str[r] == ' ') 106 | r++; /* Eat white space */ 107 | if ( ( p = get_num( &hours, 0, 23, interval_str+r, ':' ) ) == -1 ) 108 | return( FAILED ) ; 109 | r += p; 110 | r++; /* Get past : */ 111 | if ( ( p = get_num( &minutes, 0, 59, interval_str+r, '-' ) ) == -1 ) 112 | return( FAILED ) ; 113 | min_start = hours * 60 + minutes ; 114 | 115 | r += p; 116 | r++; /* Get past - */ 117 | if ( ( p = get_num( &hours, 0, 23, interval_str+r, ':' ) ) == -1 ) 118 | return( FAILED ) ; 119 | r += p; 120 | r++; /* Get past : */ 121 | if ( get_num( &minutes, 0, 59, interval_str+r, NUL ) == -1 ) 122 | return( FAILED ) ; 123 | min_end = hours * 60 + minutes ; 124 | if ( min_start >= min_end ) 125 | { 126 | parsemsg( LOG_ERR, func, "invalid time interval: %s", interval_str ) ; 127 | return( FAILED ) ; 128 | } 129 | 130 | tip = NEW_TI() ; 131 | if ( tip == NULL ) 132 | { 133 | out_of_memory( func ) ; 134 | return( FAILED ) ; 135 | } 136 | tip->min_start = min_start ; 137 | tip->min_end = min_end ; 138 | if ( pset_add( iset, tip ) == NULL ) 139 | { 140 | FREE_TI( tip ) ; 141 | out_of_memory( func ) ; 142 | return( FAILED ) ; 143 | } 144 | return( OK ) ; 145 | } 146 | 147 | 148 | void ti_dump( pset_h iset, int fd ) 149 | { 150 | unsigned u ; 151 | 152 | for ( u = 0 ; u < pset_count( iset ) ; u++ ) 153 | { 154 | struct time_interval *tip = TIP( pset_pointer( iset, u ) ) ; 155 | 156 | Sprint( fd, " %02d:%02d-%02d:%02d", 157 | tip->min_start / 60, tip->min_start % 60, 158 | tip->min_end / 60, tip->min_end % 60 ) ; 159 | } 160 | } 161 | 162 | 163 | void ti_free( pset_h iset ) 164 | { 165 | pset_apply( iset, free, NULL ) ; 166 | } 167 | 168 | -------------------------------------------------------------------------------- /src/xtimer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1998-2001 by Rob Braun 3 | * All rights reserved. The file named COPYRIGHT specifies the terms 4 | * and conditions for redistribution. 5 | */ 6 | 7 | #include 8 | 9 | #include "config.h" 10 | #include "xtimer.h" 11 | #include "pset.h" 12 | #include "msg.h" 13 | 14 | /* A note on the usage of timers in these functions: 15 | * The timers are composed of 3 elements, a pointer to a callback function, 16 | * the expire time of the timer, and a unique (pseudo-monotomically increasing) 17 | * identifier for the timer. 18 | * Timers are kept in a pset_h (linked list) and are sorted at insertion 19 | * time, with the nearest expire time first. The sort at insertion is to 20 | * avoid examining non-expired timers in the xtimer_poll() function, and 21 | * to be able to easily retrieve the next expiring timer. 22 | * The timers are set in the main event loop, using select() as the 23 | * timing device. select() sleeps until the next timer is set to expire 24 | * (or until an FD is ready, in which case it also examines the timer list). 25 | */ 26 | 27 | static pset_h xtimer_list = NULL; 28 | 29 | static int xtimer_init( void ) 30 | { 31 | if( xtimer_list != NULL ) 32 | return 0; 33 | 34 | xtimer_list = pset_create( 0, 0 ); 35 | if( xtimer_list == NULL ) 36 | return -1; 37 | 38 | return 0; 39 | } 40 | 41 | static int xtimer_compfunc( const void *_a, const void *_b ) 42 | { 43 | xtime_h * const *a = (xtime_h * const *)_a; 44 | xtime_h * const *b = (xtime_h * const *)_b; 45 | return ((*a)->when - (*b)->when); 46 | } 47 | 48 | /* xtimer_add: 49 | * Adds a timer to the pset_h of timers, and sorts the timer list (least time 50 | * remaining first). 51 | * Return values: 52 | * Success: the timer ID which can be used to later remove the timer (>0) 53 | * Failure: -1 54 | */ 55 | int xtimer_add( void (*func)(void), time_t secs ) 56 | { 57 | xtime_h *new_xtimer = NULL; 58 | time_t tmptime; 59 | unsigned count; 60 | 61 | if( xtimer_list == NULL ) { 62 | if( xtimer_init() < 0 ) 63 | return -1; 64 | } 65 | 66 | new_xtimer = (xtime_h *)malloc(sizeof(xtime_h)); 67 | if( new_xtimer == NULL ) { 68 | return -1; 69 | } 70 | 71 | tmptime = time(NULL); 72 | if( tmptime == -1 ) { 73 | free( new_xtimer ); 74 | return -1; 75 | } 76 | 77 | new_xtimer->timerfunc = func; 78 | new_xtimer->when = tmptime + secs; 79 | 80 | if( (count = pset_count( xtimer_list )) == 0 ) { 81 | new_xtimer->xtid = 1; 82 | } else { 83 | new_xtimer->xtid = ((xtime_h *)(pset_pointer(xtimer_list, count-1)))->xtid + 1; 84 | } 85 | 86 | if( pset_add( xtimer_list, new_xtimer ) == NULL ) { 87 | free( new_xtimer ); 88 | return -1; 89 | } 90 | 91 | pset_sort( xtimer_list, xtimer_compfunc ); 92 | 93 | return(new_xtimer->xtid); 94 | } 95 | 96 | /* xtimer_poll: 97 | * Traverses the pset_h of timers, and executes the callback for expired 98 | * timers. Timers that are expired, and have their callback executed 99 | * are removed from the list of timers. 100 | */ 101 | int xtimer_poll(void) 102 | { 103 | unsigned int i; 104 | 105 | if( xtimer_list == NULL ) 106 | return(0); 107 | 108 | for( i = 0; i < pset_count( xtimer_list ); i++ ) { 109 | xtime_h *cur_timer = pset_pointer( xtimer_list, i ); 110 | time_t cur_time = time(NULL); 111 | 112 | /* The list is sorted, low to high. If there's no 113 | * timers left, return. 114 | */ 115 | if( cur_timer->when > cur_time ) { 116 | return(0); 117 | } 118 | cur_timer->timerfunc(); 119 | pset_delete( xtimer_list, cur_timer ); 120 | free(cur_timer); 121 | i--; 122 | cur_timer = NULL; 123 | } 124 | 125 | return(0); 126 | } 127 | 128 | /* xtimer_remove: 129 | * Removes a timer from the list of timers. Takes the timer id as an argument 130 | * Returns: 131 | * Success: 0 132 | * Failure: -1 133 | */ 134 | int xtimer_remove(int xtid) 135 | { 136 | unsigned int i; 137 | int ret = -1; 138 | 139 | for( i = 0; i < pset_count( xtimer_list ); i++ ) { 140 | xtime_h *cur_timer = pset_pointer( xtimer_list, i ); 141 | if( cur_timer->xtid == xtid ) { 142 | pset_delete( xtimer_list, cur_timer ); 143 | free( cur_timer ); 144 | cur_timer = NULL; 145 | ret = 0; 146 | } 147 | } 148 | 149 | return(ret); 150 | } 151 | 152 | /* xtimer_nexttime: 153 | * Returns the number of seconds until the next timer expires. 154 | * Returns -1 when no timers are active. 155 | */ 156 | time_t xtimer_nexttime(void) 157 | { 158 | time_t ret; 159 | 160 | if(xtimer_list == NULL) 161 | return -1; 162 | 163 | if( pset_count(xtimer_list) == 0 ) 164 | return -1; 165 | 166 | ret = ((xtime_h *)pset_pointer(xtimer_list, 0))->when - time(NULL) ; 167 | if( ret < 0 ) 168 | ret = 0; 169 | return( ret ); 170 | } 171 | 172 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | ACLOCAL_AMFLAGS = -I m4 2 | 3 | EXTRA_DIST = \ 4 | contrib/empty.conf \ 5 | contrib/xinetd \ 6 | contrib/xinetd.service \ 7 | README.md \ 8 | CHANGELOG \ 9 | COPYRIGHT \ 10 | $(bin_SCRIPTS) \ 11 | $(man_MANS) \ 12 | man/m_env.3 \ 13 | man/pset.3 \ 14 | man/psi.3 \ 15 | man/sio.3 \ 16 | man/xlog.3 \ 17 | man/Sprint.3 \ 18 | man/strparse.3 \ 19 | man/strprint.3 \ 20 | man/strutil.3 \ 21 | $(sysconf_DATA) \ 22 | $(xinetconf_DATA) 23 | 24 | sysconf_DATA = \ 25 | contrib/xinetd.conf 26 | 27 | xinetconfdir=$(sysconfdir)/xinetd.d 28 | xinetconf_DATA = \ 29 | contrib/xinetd.d/daytime \ 30 | contrib/xinetd.d/daytime-udp \ 31 | contrib/xinetd.d/discard \ 32 | contrib/xinetd.d/discard-udp \ 33 | contrib/xinetd.d/echo \ 34 | contrib/xinetd.d/echo-udp \ 35 | contrib/xinetd.d/chargen \ 36 | contrib/xinetd.d/chargen-udp \ 37 | contrib/xinetd.d/servers \ 38 | contrib/xinetd.d/services \ 39 | contrib/xinetd.d/time \ 40 | contrib/xinetd.d/time-udp 41 | 42 | man_MANS = \ 43 | man/itox.8 \ 44 | man/xconv.pl.8 \ 45 | man/xinetd.conf.5 \ 46 | man/xinetd.log.5 \ 47 | man/xinetd.8 48 | 49 | AM_LDFLAGS = $(LDFLAGS) $(HARDEN_LDFLAGS) 50 | AM_CFLAGS = $(CFLAGS) $(HARDEN_CFLAGS) 51 | AM_CPPFLAGS = \ 52 | -I$(top_srcdir)/src \ 53 | -I$(top_srcdir)/src/misc \ 54 | -I$(top_srcdir)/src/portable \ 55 | -I$(top_srcdir)/src/pset \ 56 | -I$(top_srcdir)/src/sio \ 57 | -I$(top_srcdir)/src/str \ 58 | -I$(top_srcdir)/src/xlog 59 | 60 | noinst_LTLIBRARIES = \ 61 | libmisc.la \ 62 | libportable.la \ 63 | libpset.la \ 64 | libsio.la \ 65 | libstr.la \ 66 | libxlog.la 67 | libmisc_la_SOURCES = \ 68 | src/misc/m_env.c \ 69 | src/misc/m_env.h 70 | libportable_la_SOURCES = \ 71 | src/portable/cvt.c \ 72 | src/portable/libportable.h 73 | libpset_la_SOURCES = \ 74 | src/pset/ops.c \ 75 | src/pset/pset.c \ 76 | src/pset/pset.h 77 | libsio_la_SOURCES = \ 78 | src/sio/impl.h \ 79 | src/sio/sio.c \ 80 | src/sio/sioconf.h \ 81 | src/sio/sio.h \ 82 | src/sio/siosup.c \ 83 | src/sio/sprint.c 84 | libstr_la_SOURCES = \ 85 | src/str/str.h \ 86 | src/str/strparse.c \ 87 | src/str/strparse.h \ 88 | src/str/strprint.c \ 89 | src/str/strutil.c 90 | libxlog_la_SOURCES = \ 91 | src/xgetloadavg.c \ 92 | src/xgetloadavg.h \ 93 | src/xlog/filelog.c \ 94 | src/xlog/filelog.h \ 95 | src/xlog/impl.h \ 96 | src/xlog/slog.c \ 97 | src/xlog/slog.h \ 98 | src/xlog/util.c \ 99 | src/xlog/xlog.c \ 100 | src/xlog/xlog.h 101 | 102 | bin_PROGRAMS = itox 103 | itox_SOURCES = src/itox.c 104 | itox_LDADD = \ 105 | libsio.la \ 106 | libstr.la 107 | 108 | bin_SCRIPTS = src/xconv.pl 109 | 110 | sbin_PROGRAMS = xinetd 111 | xinetd_CFLAGS = \ 112 | $(HARDEN_CFLAGS) \ 113 | $(SELINUX_CFLAGS) \ 114 | $(RPC_CFLAGS) 115 | xinetd_SOURCES = \ 116 | src/access.c \ 117 | src/access.h \ 118 | src/addr.c \ 119 | src/addr.h \ 120 | src/attr.h \ 121 | src/builtins.c \ 122 | src/builtins.h \ 123 | src/conf.c \ 124 | src/conf.h \ 125 | src/confparse.c \ 126 | src/confparse.h \ 127 | src/connection.c \ 128 | src/connection.h \ 129 | src/defs.h \ 130 | src/env.c \ 131 | src/env.h \ 132 | src/child.c \ 133 | src/child.h \ 134 | src/ident.c \ 135 | src/ident.h \ 136 | src/includedir.c \ 137 | src/includedir.h \ 138 | src/inet.c \ 139 | src/inet.h \ 140 | src/init.c \ 141 | src/init.h \ 142 | src/int.c \ 143 | src/intcommon.c \ 144 | src/intcommon.h \ 145 | src/internals.c \ 146 | src/internals.h \ 147 | src/int.h \ 148 | src/log.c \ 149 | src/logctl.c \ 150 | src/logctl.h \ 151 | src/log.h \ 152 | src/main.c \ 153 | src/main.h \ 154 | src/mask.h \ 155 | src/msg.c \ 156 | src/msg.h \ 157 | src/nvlists.c \ 158 | src/nvlists.h \ 159 | src/options.c \ 160 | src/options.h \ 161 | src/parse.c \ 162 | src/parse.h \ 163 | src/parsers.c \ 164 | src/parsers.h \ 165 | src/parsesup.c \ 166 | src/parsesup.h \ 167 | src/reconfig.c \ 168 | src/reconfig.h \ 169 | src/redirect.c \ 170 | src/redirect.h \ 171 | src/retry.c \ 172 | src/retry.h \ 173 | src/sconf.c \ 174 | src/sconf.h \ 175 | src/sconst.h \ 176 | src/sensor.c \ 177 | src/sensor.h \ 178 | src/server.c \ 179 | src/server.h \ 180 | src/service.c \ 181 | src/service.h \ 182 | src/signals.c \ 183 | src/signals.h \ 184 | src/special.c \ 185 | src/special.h \ 186 | src/state.h \ 187 | src/tcpint.c \ 188 | src/tcpint.h \ 189 | src/time.c \ 190 | src/timex.h \ 191 | src/udpint.c \ 192 | src/udpint.h \ 193 | src/util.c \ 194 | src/util.h \ 195 | src/xconfig.h \ 196 | src/xpoll.h \ 197 | src/xtimer.c \ 198 | src/xtimer.h 199 | xinetd_LDADD = \ 200 | libmisc.la \ 201 | libportable.la \ 202 | libpset.la \ 203 | libsio.la \ 204 | libstr.la \ 205 | libxlog.la \ 206 | $(WRAP_LIBS) \ 207 | $(SELINUX_LIBS) \ 208 | $(RPC_LIBS) 209 | 210 | distclean-local: 211 | rm -rf *.cache *~ 212 | -------------------------------------------------------------------------------- /man/strparse.3: -------------------------------------------------------------------------------- 1 | .\"(c) Copyright 1992, 1993 by Panagiotis Tsirigotis 2 | .\"All rights reserved. The file named COPYRIGHT specifies the terms 3 | .\"and conditions for redistribution. 4 | .\" 5 | .\" $Id$ 6 | .TH STRPARSE 3X "30 September 1992" 7 | .SH NAME 8 | str_parse, str_endparse, str_component, str_separator, str_nextpos 9 | .SH SYNOPSIS 10 | .LP 11 | .nf 12 | .ft B 13 | #include "str.h" 14 | .LP 15 | .ft B 16 | str_h str_parse( str, separ, flags, errnop ) 17 | char *str ; 18 | char *separ ; 19 | int flags ; 20 | int *errnop ; 21 | .LP 22 | .ft B 23 | void str_endparse( handle ) 24 | str_h handle ; 25 | .LP 26 | .ft B 27 | char *str_component( handle ) 28 | str_h handle ; 29 | .LP 30 | .ft B 31 | int str_setstr( handle, newstr ) 32 | str_h handle ; 33 | char *newstr ; 34 | .LP 35 | .ft B 36 | int str_separator( handle, separ ) 37 | str_h handle ; 38 | char *separ ; 39 | .LP 40 | .ft B 41 | char *str_nextpos( handle ) 42 | str_h handle ; 43 | .LP 44 | extern int str_errno ; 45 | .SH DESCRIPTION 46 | .LP 47 | These functions are useful for parsing strings. In this context 48 | parsing means breaking the string into substrings. The substrings are 49 | separated by a list of possible separator characters. 50 | .LP 51 | .B str_component() 52 | returns successive substrings of the string. 53 | .B str_parse() 54 | creates and initializes a string parser with the string 55 | that will be processed, \fIstr\fR, the list of possible separator 56 | characters, \fIsepar\fR, and flags that control how the parser 57 | works. The \fIflags\fR argument is formed by ORing one or more of 58 | the following constants: 59 | .TP 20 60 | .SB STR_RETURN_ERROR 61 | If something goes wrong return a value that indicates that an error occurred 62 | (e.g. out of memory). The default is for the program to be terminated 63 | with an appropriate error message. 64 | .TP 65 | .SB STR_NULL_START 66 | If \fIstr\fR starts with a separator then a zero-length string will be returned 67 | the first time \fBstr_component()\fR is called. 68 | .TP 69 | .SB STR_NULL_END 70 | If \fIstr\fR ends with a separator then a zero-length string will be returned 71 | by \fBstr_component()\fR when the substrings of \fIstr\fR are exhausted. 72 | .TP 73 | .SB STR_MALLOC 74 | The strings returned by \fBstr_component()\fR will be in malloc'ed memory. 75 | By default the substrings are part of \fIstr\fR. 76 | If this option is not used \fIstr\fR will be modified 77 | by \fBstr_component()\fR. 78 | .LP 79 | Finally, \fBSTR_NOFLAGS\fR may be used to specify no flags. 80 | The \fIerrnop\fR argument points to an integer where the string processing 81 | functions will deposit an error code if an error occurs. 82 | If \fIerrnop\fR 83 | is 84 | .SM NULL 85 | the error codes will be placed in \fIstr_errno\fR. 86 | This is useful only if \fBSTR_RETURN_ERROR\fR is used in \fIflags\fR. 87 | It is possible that \fIstr\fP is 88 | .SM NULL. 89 | In this case, a subsequent 90 | .B str_setstr() 91 | should be used to specify the string to be processed. 92 | .LP 93 | .B str_component() 94 | returns successive substrings from the string associated with the 95 | parser specified by \fIhandle\fR. 96 | .LP 97 | .B str_endparse() 98 | destroys the parser specified by \fIhandle\fR. 99 | .LP 100 | .B str_setstr() 101 | changes the processed string to \fInewstr\fP. 102 | .LP 103 | .B str_separator() 104 | replaces the list of separator characters with \fIsepar\fR. 105 | Processing continues from the current position. 106 | .LP 107 | .B str_nextpos() 108 | returns a pointer to the rest of the string. The previous character 109 | is a separator character (if \fBSTR_MALLOC\fR is not set, then the 110 | previous character is 111 | .SM NUL 112 | ). 113 | .SH "RETURN VALUES" 114 | .LP 115 | .B str_parse() 116 | returns a parser handle or 117 | .SM NULL 118 | if something goes wrong and \fIflags\fR & \fBSTR_RETURN_ERROR\fR is true. 119 | Possible \fIstr_errno\fR values: 120 | .RS 121 | .TP 20 122 | .SB STR_ENULLSEPAR 123 | \fIsepar\fR is 124 | .SM NULL 125 | .TP 126 | .SB STR_ENOMEM 127 | the program ran out of memory 128 | .RE 129 | .LP 130 | .B str_component() 131 | returns a pointer to the next substring or 132 | .SM NULL 133 | if something goes wrong and \fIflags\fR & \fBSTR_RETURN_ERROR\fR is true. 134 | .LP 135 | .B str_setstr() 136 | returns 137 | .SB STR_OK 138 | on success or 139 | .SB STR_ERR 140 | on failure. 141 | .LP 142 | .B str_separator() 143 | returns 144 | .SB STR_OK 145 | on success or 146 | .SB STR_ERR 147 | on failure. 148 | .LP 149 | .B str_nextpos() 150 | returns a pointer or 151 | .SM NULL 152 | if the end of string has been reached. 153 | .SH BUGS 154 | .B str_component() 155 | modifies the string unless \fBSTR_MALLOC\fR is 156 | set in the parser. 157 | .LP 158 | There should be only one parser active on a specific string. If there 159 | is more than 160 | one, they all must use the \fBSTR_MALLOC\fR option. 161 | 162 | -------------------------------------------------------------------------------- /src/includedir.c: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1998-2001 by Rob Braun 3 | * All rights reserved. The file named COPYRIGHT specifies the terms 4 | * and conditions for redistribution. 5 | */ 6 | #include "config.h" 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "pset.h" 19 | #include "str.h" 20 | #include "includedir.h" 21 | #include "msg.h" 22 | #include "parse.h" 23 | #include "sio.h" 24 | 25 | #ifndef NAME_MAX 26 | #define NAME_MAX 256 27 | #endif 28 | 29 | static int compfunc( const void *_a, const void *_b ) 30 | { 31 | const char * const *a = (const char * const *)_a; 32 | const char * const *b = (const char * const *)_b; 33 | 34 | if( a == NULL || a[0] == NULL ) 35 | return -1; 36 | if( b == NULL || b[0] == NULL ) 37 | return 1; 38 | return strcmp(a[0], b[0]); 39 | } 40 | 41 | void handle_includedir(const char *service_name, struct configuration *confp) 42 | { 43 | char *filename; 44 | pset_h dir_list; 45 | DIR *dirfp; 46 | struct dirent *direntry; 47 | char *storename; 48 | struct stat sb; 49 | int u, incfd, len_sn; 50 | const char *func = "handle_includedir"; 51 | 52 | if( service_name == NULL ) 53 | return; 54 | 55 | dir_list = pset_create(0, 0); 56 | if( dir_list == NULL ) 57 | return; 58 | 59 | len_sn = strlen(service_name); 60 | filename = (char *)malloc(len_sn + NAME_MAX + 2); 61 | if (! filename) { 62 | parsemsg( LOG_ERR, func, ES_NOMEM ); 63 | return; 64 | } 65 | errno = 0; 66 | dirfp = opendir(service_name); 67 | if (! dirfp) { 68 | parsemsg( LOG_ERR, func, "Unable to read included directory: %s", service_name); 69 | free(filename); 70 | return; 71 | } 72 | /* Get the list of files in the directory */ 73 | while ((direntry = readdir(dirfp)) != 0) { 74 | storename = new_string(direntry->d_name); 75 | if( storename == NULL ) { 76 | parsemsg( LOG_ERR, func, ES_NOMEM ); 77 | free( filename ); 78 | return; 79 | } 80 | pset_add(dir_list, storename); 81 | } 82 | closedir(dirfp); 83 | 84 | /* Sort the list using "compfunc" */ 85 | pset_sort(dir_list, compfunc); 86 | 87 | /* Now, traverse the list in alphabetic order 88 | * (as determined by strcmp). 89 | */ 90 | for( u = 0; (unsigned)u < pset_count(dir_list); u++ ) { 91 | storename = pset_pointer(dir_list, u); 92 | 93 | /* Don't try to parse any files containing a dot ('.') 94 | * or ending with a tilde ('~'). This catches the case of 95 | * '.' and '..', as well as preventing the parsing of 96 | * many editor files, temporary files and those saved by RPM 97 | * package upgrades. 98 | */ 99 | if ( !storename[0] /* Shouldn't happen */ || 100 | strchr(storename, '.') || 101 | storename[strlen(storename)-1] == '~') { 102 | pset_remove(dir_list, storename); 103 | free(storename); 104 | u--; 105 | continue; 106 | } 107 | 108 | strx_sprint(filename, len_sn+NAME_MAX+1, "%s/%s", 109 | service_name, storename); 110 | 111 | if( stat(filename, &sb) < 0 ) { 112 | parsemsg( LOG_ERR, func, "Unable to stat includedir file %s", filename); 113 | pset_remove(dir_list, storename); 114 | free(storename); 115 | u--; 116 | continue; 117 | } 118 | 119 | /* Only open it if it's a regular file. */ 120 | if( !S_ISREG(sb.st_mode) ) { 121 | msg( LOG_ERR, func, 122 | "%s is not a regular file. It is being skipped.", 123 | filename ); 124 | pset_remove(dir_list, storename); 125 | free(storename); 126 | u--; 127 | continue; 128 | } 129 | incfd = open(filename, O_RDONLY); 130 | if( incfd < 0 ) { 131 | parsemsg( LOG_ERR, func, "Unable to open included configuration file: %s", filename); 132 | pset_remove(dir_list, storename); 133 | free(storename); 134 | u--; 135 | continue; 136 | } 137 | parsemsg( LOG_DEBUG,func,"Reading included configuration file: %s",filename); 138 | parse_conf_file(incfd, confp, filename); 139 | 140 | /* 141 | * parse_conf_file eventually calls Srdline, try Sclosing to 142 | * unmmap memory. 143 | */ 144 | Sclose(incfd); 145 | pset_remove(dir_list, storename); 146 | free(storename); 147 | u--; 148 | } 149 | if ( errno != 0) { 150 | parsemsg( LOG_ERR, func, "Error reading included directory: %s", service_name); 151 | } 152 | pset_destroy(dir_list); 153 | free(filename); 154 | } 155 | -------------------------------------------------------------------------------- /src/nvlists.c: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992 by Panagiotis Tsirigotis 3 | * (c) Sections Copyright 1998-2001 by Rob Braun 4 | * All rights reserved. The file named COPYRIGHT specifies the terms 5 | * and conditions for redistribution. 6 | */ 7 | 8 | 9 | #include "config.h" 10 | #include 11 | #include 12 | #include 13 | 14 | #include "nvlists.h" 15 | #include "sconf.h" 16 | 17 | 18 | /* 19 | * A NULL value for the name field marks the end of the table 20 | */ 21 | 22 | const struct name_value service_types[] = 23 | { 24 | #ifndef NO_RPC 25 | { "RPC", ST_RPC }, 26 | #endif 27 | { "INTERNAL", ST_INTERNAL }, 28 | { "UNLISTED", ST_UNLISTED }, 29 | { "SPECIAL", ST_SPECIAL }, 30 | { "TCPMUX", ST_TCPMUX }, 31 | { "TCPMUXPLUS", ST_TCPMUXPLUS }, 32 | { CHAR_NULL, 0 } 33 | } ; 34 | 35 | 36 | /* REUSE is only used for backward compatibility. All services are now reuse */ 37 | const struct name_value service_flags[] = 38 | { 39 | { "REUSE", SF_REUSE }, 40 | { "INTERCEPT", SF_INTERCEPT }, 41 | { "NORETRY", SF_NORETRY }, 42 | { "IDONLY", SF_IDONLY }, 43 | { "NAMEINARGS", SF_NAMEINARGS }, 44 | { "NODELAY", SF_NODELAY }, 45 | { "KEEPALIVE", SF_KEEPALIVE }, 46 | { "NOLIBWRAP", SF_NOLIBWRAP }, 47 | { "SENSOR", SF_SENSOR }, 48 | { "IPv4", SF_IPV4 }, 49 | { "IPv6", SF_IPV6 }, 50 | { "LABELED", SF_LABELED }, 51 | { CHAR_NULL, 0 } 52 | } ; 53 | 54 | 55 | const struct name_value socket_types[] = 56 | { 57 | { "stream", SOCK_STREAM }, 58 | { "dgram", SOCK_DGRAM }, 59 | { "raw", SOCK_RAW }, 60 | { "seqpacket", SOCK_SEQPACKET }, 61 | { CHAR_NULL, 1 }, 62 | { "BAD SOCKET TYPE", 0 } 63 | } ; 64 | 65 | 66 | const struct name_value success_log_options[] = 67 | { 68 | { "HOST", LO_HOST }, 69 | { "DURATION", LO_DURATION }, 70 | { "EXIT", LO_EXIT }, 71 | { "PID", LO_PID }, 72 | { "USERID", LO_USERID }, 73 | { "TRAFFIC", LO_TRAFFIC }, 74 | { CHAR_NULL, 0 } 75 | } ; 76 | 77 | 78 | const struct name_value failure_log_options[] = 79 | { 80 | { "HOST", LO_HOST }, 81 | { "ATTEMPT", LO_ATTEMPT }, 82 | { "USERID", LO_USERID }, 83 | { CHAR_NULL, 0 } 84 | } ; 85 | 86 | 87 | 88 | const struct name_value syslog_facilities[] = 89 | { 90 | { "daemon", LOG_DAEMON }, 91 | { "auth", LOG_AUTH }, 92 | #ifdef linux 93 | { "authpriv", LOG_AUTHPRIV }, 94 | #endif 95 | { "user", LOG_USER }, 96 | #ifdef LOG_MAIL 97 | { "mail", LOG_MAIL }, 98 | #endif 99 | #ifdef LOG_LPR 100 | { "lpr", LOG_LPR }, 101 | #endif 102 | #ifdef LOG_NEWS 103 | { "news", LOG_NEWS }, 104 | #endif 105 | #ifdef LOG_UUCP 106 | { "uucp", LOG_UUCP }, 107 | #endif 108 | #ifdef LOG_FTP 109 | { "ftp", LOG_FTP }, 110 | #endif 111 | { "local0", LOG_LOCAL0 }, 112 | { "local1", LOG_LOCAL1 }, 113 | { "local2", LOG_LOCAL2 }, 114 | { "local3", LOG_LOCAL3 }, 115 | { "local4", LOG_LOCAL4 }, 116 | { "local5", LOG_LOCAL5 }, 117 | { "local6", LOG_LOCAL6 }, 118 | { "local7", LOG_LOCAL7 }, 119 | { CHAR_NULL, 1 }, 120 | { "BAD FACILITY", 0 } 121 | } ; 122 | 123 | 124 | const struct name_value syslog_levels[] = 125 | { 126 | { "emerg", LOG_EMERG }, 127 | { "alert", LOG_ALERT }, 128 | { "crit", LOG_CRIT }, 129 | { "err", LOG_ERR }, 130 | { "warning", LOG_WARNING }, 131 | { "notice", LOG_NOTICE }, 132 | { "info", LOG_INFO }, 133 | { "debug", LOG_DEBUG }, 134 | { CHAR_NULL, 1 }, 135 | { "BAD LEVEL", 0 } 136 | } ; 137 | 138 | -------------------------------------------------------------------------------- /src/str/strparse.c: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis 3 | * All rights reserved. The file named COPYRIGHT specifies the terms 4 | * and conditions for redistribution. 5 | */ 6 | 7 | #include "config.h" 8 | #include 9 | #include 10 | #include 11 | 12 | #include "str.h" 13 | #include "strparse.h" 14 | #include "sio.h" 15 | 16 | static int str_errno ; 17 | 18 | #define HANDLE_ERROR( flags, retval, errp, errval, msg ) \ 19 | if ( flags & STR_RETURN_ERROR ) \ 20 | { \ 21 | *errp = errval ; \ 22 | return( retval ) ; \ 23 | } \ 24 | else \ 25 | terminate( msg ); 26 | 27 | 28 | char *new_string( const char *s ) 29 | { 30 | if ( s ) 31 | return strdup( s ) ; 32 | else 33 | return 0; 34 | } 35 | 36 | str_h str_parse( register char *str, const char *separ, int flags, int *errnop ) 37 | { 38 | register struct str_handle *hp ; 39 | int *errp = ( errnop == NULL ) ? &str_errno : errnop ; 40 | 41 | if ( separ == NULL ) { 42 | HANDLE_ERROR( flags, NULL, errp, STR_ENULLSEPAR, 43 | "STR str_parse: NULL separator" ) ; 44 | } 45 | 46 | hp = (struct str_handle *) malloc( sizeof( struct str_handle ) ) ; 47 | if ( hp == NULL ) { 48 | HANDLE_ERROR( flags, NULL, errp, STR_ENOMEM, 49 | "STR str_parse: malloc failed" ) ; 50 | } 51 | 52 | hp->string = str ; 53 | hp->pos = str ; 54 | hp->separator = new_string( separ ) ; 55 | if ( hp->separator == NULL ) { 56 | if ( flags & STR_RETURN_ERROR ) 57 | { 58 | free( (char *) hp ) ; 59 | *errp = STR_ENOMEM ; 60 | return( NULL ) ; 61 | } else { 62 | terminate( "STR str_parse: malloc failed" ) ; 63 | } 64 | } 65 | 66 | hp->flags = flags ; 67 | hp->errnop = errp ; 68 | hp->no_more = ( str == NULL ) ; 69 | return( (str_h) hp ) ; 70 | } 71 | 72 | 73 | void str_endparse( str_h handle ) 74 | { 75 | register struct str_handle *hp = (struct str_handle *) handle ; 76 | 77 | if( hp->separator != NULL ) 78 | free( hp->separator ) ; 79 | free( (char *) handle ) ; 80 | } 81 | 82 | 83 | /* 84 | * Change the string 85 | */ 86 | int str_setstr( str_h handle, char *newstr ) 87 | { 88 | register struct str_handle *hp = (struct str_handle *) handle ; 89 | 90 | if ( newstr == NULL ) { 91 | HANDLE_ERROR( hp->flags, STR_ERR, hp->errnop, STR_ENULLSTRING, 92 | "STR str_setstr: NULL string" ) ; 93 | } 94 | 95 | hp->string = newstr ; 96 | hp->pos = newstr ; 97 | hp->no_more = FALSE ; 98 | return( STR_OK ) ; 99 | } 100 | 101 | 102 | char *str_component( str_h handle ) 103 | { 104 | register char *start ; 105 | register char *last ; 106 | register unsigned int sep_count ; 107 | char *retval ; 108 | int last_char ; 109 | register struct str_handle *hp = (struct str_handle *) handle ; 110 | register int first_call = ( hp->pos == hp->string ) ; 111 | 112 | if ( hp->no_more ) 113 | return( NULL ) ; 114 | 115 | /* 116 | * Get number of separator characters. 117 | * Find beginning of component. 118 | */ 119 | sep_count = strspn( hp->pos, hp->separator ) ; 120 | 121 | /* 122 | * If this is the first call, and there are separator characters 123 | * at the beginning of the string and the STR_NULL_START flag is set 124 | * we return a 0-length string. 125 | */ 126 | if ( first_call && ( sep_count > 0 ) && ( hp->flags & STR_NULL_START )) 127 | { 128 | start = hp->pos ; 129 | last = hp->pos ; 130 | } 131 | else 132 | { 133 | start = hp->pos + sep_count ; 134 | 135 | if ( *start == '\0' ) 136 | { 137 | last = start ; 138 | hp->no_more = TRUE ; 139 | if ( ! ( hp->flags & STR_NULL_END ) ) 140 | return( NULL ) ; 141 | } 142 | else 143 | { 144 | last = strpbrk( start, hp->separator ) ; 145 | if ( last == NULL ) 146 | last = start + strlen( start ) ; 147 | } 148 | } 149 | 150 | /* 151 | * At this point, the following variables must be set: 152 | * start: beginning of component 153 | * last: end of component + 1 154 | * 155 | * If STR_MALLOC is set, allocate space for the new string. 156 | * 157 | * NOTE: If STR_MALLOC is not set, the processed string is trashed. 158 | */ 159 | last_char = *last ; 160 | if ( hp->flags & STR_MALLOC ) 161 | { 162 | int len = last - start ; 163 | 164 | retval = malloc( (unsigned)len + 1 ) ; 165 | if ( retval == NULL ) { 166 | HANDLE_ERROR( hp->flags, NULL, hp->errnop, STR_ENOMEM, 167 | "STR str_component: malloc failed" ) ; 168 | } 169 | strncpy( retval, start, (size_t)len )[ len ] = '\0' ; 170 | } 171 | else 172 | { 173 | retval = start ; 174 | *last = '\0' ; 175 | } 176 | 177 | /* 178 | * Check if last_char is NUL to avoid setting hp->pos past the 179 | * end of the string 180 | */ 181 | hp->pos = ( last_char == '\0' ) ? last : last+1 ; 182 | return( retval ) ; 183 | } 184 | 185 | -------------------------------------------------------------------------------- /src/options.c: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992 by Panagiotis Tsirigotis 3 | * (c) Sections Copyright 1998-2001 by Rob Braun 4 | * All rights reserved. The file named COPYRIGHT specifies the terms 5 | * and conditions for redistribution. 6 | */ 7 | 8 | #include "config.h" 9 | #include 10 | #include 11 | #include 12 | 13 | #include "str.h" 14 | #include "sio.h" 15 | #include "options.h" 16 | #include "main.h" 17 | #include "util.h" 18 | #include "internals.h" /* for enable_periodic_check() */ 19 | 20 | /* 21 | * $Id$ 22 | */ 23 | 24 | 25 | int filelog_option ; 26 | char * filelog_option_arg ; 27 | int syslog_option ; 28 | char * syslog_option_arg ; 29 | int logprocs_option ; 30 | unsigned logprocs_option_arg ; 31 | int stayalive_option=0; 32 | char *program_name ; 33 | int inetd_compat = 0 ; 34 | int dont_fork = 0; 35 | 36 | #ifdef __GNUC__ 37 | __attribute__ ((noreturn)) 38 | #endif 39 | static void usage(void); 40 | 41 | int opt_recognize( int argc, char *argv[] ) 42 | { 43 | int arg, arg_1 ; 44 | unsigned int uarg_1; 45 | unsigned long long ullarg_1; 46 | 47 | program_name = strrchr( argv[ 0 ], '/' ) ; 48 | program_name = ( program_name == NULL ) ? argv[ 0 ] : program_name + 1 ; 49 | 50 | for ( arg = 1 ; arg < argc ; arg++ ) 51 | if ( argv[ arg ][ 0 ] == '-' && argv[ arg ][ 1 ] != 0 ) 52 | { 53 | if ( strcmp( &argv[ arg ][ 1 ], "d" ) == 0 ) 54 | debug.on = 1 ; 55 | else if ( strcmp( &argv[ arg ][ 1 ], "f" ) == 0 ) 56 | { 57 | if ( ++arg == argc ) 58 | usage() ; 59 | ps.ros.config_file = argv[ arg ]; 60 | } 61 | else if ( strcmp( &argv[ arg ][ 1 ], "filelog" ) == 0 ) 62 | { 63 | if ( ++arg == argc ) 64 | usage() ; 65 | filelog_option_arg = ( argv[ arg ] ) ; 66 | filelog_option = 1 ; 67 | } 68 | else if ( strcmp( &argv[ arg ][ 1 ], "syslog" ) == 0 ) 69 | { 70 | if ( ++arg == argc ) 71 | usage() ; 72 | syslog_option_arg = ( argv[ arg ] ) ; 73 | syslog_option = 1 ; 74 | } 75 | else if ( strcmp( &argv[ arg ][ 1 ], "reuse" ) == 0 ) 76 | ; /* This is now a null option, kept for compatibility */ 77 | else if ( strcmp( &argv[ arg ][ 1 ], "limit" ) == 0 ) 78 | { 79 | if ( ++arg == argc ) 80 | usage() ; 81 | if ( parse_ull( argv[ arg ], 10, NUL, &ullarg_1 ) < 0 ) 82 | usage() ; 83 | ps.ros.process_limit = (rlim_t)ullarg_1 ; 84 | if( ps.ros.process_limit != ullarg_1 ) 85 | usage() ; 86 | } 87 | else if ( strcmp( &argv[ arg ][ 1 ], "pidfile" ) == 0 ) { 88 | if( ++arg ==argc ) 89 | usage () ; 90 | ps.ros.pid_file = (char *)new_string( argv[arg] ); 91 | } 92 | else if ( strcmp( &argv[ arg ][ 1 ], "stayalive" )==0) 93 | stayalive_option = 1; 94 | else if ( strcmp( &argv[ arg ][ 1 ], "dontfork" )==0) { 95 | dont_fork = 1; 96 | stayalive_option = 1; 97 | } 98 | else if ( strcmp( &argv[ arg ][ 1 ], "logprocs" ) == 0 ) { 99 | if ( ++arg == argc ) 100 | usage() ; 101 | if ( parse_uint( argv[ arg ], 10, NUL, &uarg_1 ) < 0 ) 102 | usage() ; 103 | logprocs_option_arg = uarg_1 ; 104 | logprocs_option = 1 ; 105 | } 106 | else if ( strcmp( &argv[ arg ][ 1 ], "shutdownprocs" ) == 0 ) 107 | { 108 | if ( ++arg == argc ) 109 | usage() ; 110 | Sprint(2, "The shutdownprocs option has been deprecated.\n"); 111 | } 112 | else if ( strcmp( &argv[ arg ][ 1 ], "cc" ) == 0 ) { 113 | if ( ++arg == argc ) 114 | usage() ; 115 | if ( parse_int( argv[ arg ], 10, NUL, &arg_1 ) || arg_1 < 0 ) 116 | usage() ; 117 | ps.ros.cc_interval = arg_1; 118 | enable_periodic_check( arg_1 ) ; 119 | } 120 | else if ( strcmp( &argv[ arg ][ 1 ], "version" ) == 0 ) { 121 | fprintf(stderr, "%s", program_version); 122 | #ifdef LIBWRAP 123 | fprintf(stderr, " libwrap"); 124 | #endif 125 | #ifdef HAVE_LOADAVG 126 | fprintf(stderr, " loadavg"); 127 | #endif 128 | fprintf(stderr, "\n"); 129 | exit(0); 130 | } 131 | else if ( strcmp ( &argv[ arg ][ 1 ], "inetd_compat" ) == 0 ) 132 | inetd_compat = 1; 133 | } 134 | else 135 | break ; 136 | 137 | if ( filelog_option + syslog_option > 1 ) 138 | usage() ; 139 | 140 | if ( argc - arg != 0 ) 141 | usage() ; 142 | return( arg ) ; 143 | } 144 | 145 | static void usage(void) 146 | { 147 | Sprint( 2, "Usage: %s [-d] [-f config_file] [-filelog filename] [-syslog facility] [-reuse] [-limit proc_limit] [-pidfile filename] [-logprocs limit] [-shutdownprocs limit] [-cc interval]\n", program_name ) ; 148 | exit( 1 ) ; 149 | } 150 | 151 | -------------------------------------------------------------------------------- /man/xconv.pl.8: -------------------------------------------------------------------------------- 1 | .\" Automatically generated by Pod::Man v1.3, Pod::Parser v1.13 2 | .\" 3 | .\" Standard preamble: 4 | .\" ======================================================================== 5 | .de Sh \" Subsection heading 6 | .br 7 | .if t .Sp 8 | .ne 5 9 | .PP 10 | \fB\\$1\fR 11 | .PP 12 | .. 13 | .de Sp \" Vertical space (when we can't use .PP) 14 | .if t .sp .5v 15 | .if n .sp 16 | .. 17 | .de Vb \" Begin verbatim text 18 | .ft CW 19 | .nf 20 | .ne \\$1 21 | .. 22 | .de Ve \" End verbatim text 23 | .ft R 24 | 25 | .fi 26 | .. 27 | .\" Set up some character translations and predefined strings. \*(-- will 28 | .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left 29 | .\" double quote, and \*(R" will give a right double quote. | will give a 30 | .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to 31 | .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C' 32 | .\" expand to `' in nroff, nothing in troff, for use with C<>. 33 | .tr \(*W-|\(bv\*(Tr 34 | .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' 35 | .ie n \{\ 36 | . ds -- \(*W- 37 | . ds PI pi 38 | . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch 39 | . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch 40 | . ds L" "" 41 | . ds R" "" 42 | . ds C` "" 43 | . ds C' "" 44 | 'br\} 45 | .el\{\ 46 | . ds -- \|\(em\| 47 | . ds PI \(*p 48 | . ds L" `` 49 | . ds R" '' 50 | 'br\} 51 | .\" 52 | .\" If the F register is turned on, we'll generate index entries on stderr for 53 | .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index 54 | .\" entries marked with X<> in POD. Of course, you'll have to process the 55 | .\" output yourself in some meaningful fashion. 56 | .if \nF \{\ 57 | . de IX 58 | . tm Index:\\$1\t\\n%\t"\\$2" 59 | .. 60 | . nr % 0 61 | . rr F 62 | .\} 63 | .\" 64 | .\" For nroff, turn off justification. Always turn off hyphenation; it makes 65 | .\" way too many mistakes in technical documents. 66 | .hy 0 67 | .if n .na 68 | .\" 69 | .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). 70 | .\" Fear. Run. Save yourself. No user-serviceable parts. 71 | . \" fudge factors for nroff and troff 72 | .if n \{\ 73 | . ds #H 0 74 | . ds #V .8m 75 | . ds #F .3m 76 | . ds #[ \f1 77 | . ds #] \fP 78 | .\} 79 | .if t \{\ 80 | . ds #H ((1u-(\\\\n(.fu%2u))*.13m) 81 | . ds #V .6m 82 | . ds #F 0 83 | . ds #[ \& 84 | . ds #] \& 85 | .\} 86 | . \" simple accents for nroff and troff 87 | .if n \{\ 88 | . ds ' \& 89 | . ds ` \& 90 | . ds ^ \& 91 | . ds , \& 92 | . ds ~ ~ 93 | . ds / 94 | .\} 95 | .if t \{\ 96 | . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" 97 | . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' 98 | . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' 99 | . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' 100 | . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' 101 | . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' 102 | .\} 103 | . \" troff and (daisy-wheel) nroff accents 104 | .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' 105 | .ds 8 \h'\*(#H'\(*b\h'-\*(#H' 106 | .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] 107 | .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' 108 | .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' 109 | .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] 110 | .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] 111 | .ds ae a\h'-(\w'a'u*4/10)'e 112 | .ds Ae A\h'-(\w'A'u*4/10)'E 113 | . \" corrections for vroff 114 | .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' 115 | .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' 116 | . \" for low resolution devices (crt and lpr) 117 | .if \n(.H>23 .if \n(.V>19 \ 118 | \{\ 119 | . ds : e 120 | . ds 8 ss 121 | . ds o a 122 | . ds d- d\h'-1'\(ga 123 | . ds D- D\h'-1'\(hy 124 | . ds th \o'bp' 125 | . ds Th \o'LP' 126 | . ds ae ae 127 | . ds Ae AE 128 | .\} 129 | .rm #[ #] #H #V #F C 130 | .\" ======================================================================== 131 | .\" 132 | .IX Title "XCONV 8" 133 | .TH XCONV 8 "July 31 2002" " " "xinetd" 134 | .UC 135 | .SH "NAME" 136 | \&\fBxconv.pl\fR \- inetd.conf to xinetd.conf converter 137 | .SH "SYNOPSIS" 138 | .IX Header "SYNOPSIS" 139 | xconv.pl can convert existing inetd.conf files (configuration 140 | for the \fBinetd\fR program) into xinetd.conf files (configuration 141 | for the \fBxinetd\fR program) 142 | .SH "USAGE" 143 | .IX Header "USAGE" 144 | \&\fBxconv.pl\fR < /etc/inetd.conf > /etc/xinetd.conf 145 | .SH "DESCRIPTION / PURPOSE" 146 | .IX Header "DESCRIPTION / PURPOSE" 147 | \&\fBxconv.pl\fR is provided by the xinetd package to assist in the 148 | migration from \fBinetd\fR based systems to ones based on \fBxinetd\fR. 149 | .PP 150 | Functionality is similar to the \fBitox\fR program, so reading \fIitox\fR\|(8) 151 | is recommended. An important note here is that \fBxconv.pl\fR does not 152 | support the \-daemon_dir argument. 153 | .SH "AUTHOR" 154 | .IX Header "AUTHOR" 155 | xconv was written by Rob Braun and xinetd was written by 156 | Panagiotis Tsirigotis. 157 | 158 | -------------------------------------------------------------------------------- /src/xlog/slog.c: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis 3 | * All rights reserved. The file named COPYRIGHT specifies the terms 4 | * and conditions for redistribution. 5 | */ 6 | 7 | 8 | #include "config.h" 9 | #ifndef NO_SYSLOG 10 | #include 11 | #endif 12 | 13 | #include "xlog.h" 14 | #include "impl.h" 15 | #include "slog.h" 16 | #include "str.h" 17 | #include 18 | 19 | #define MSGBUFSIZE 2048 20 | 21 | 22 | static int syslog_init(xlog_s *, va_list) ; 23 | static void syslog_fini(xlog_s *) ; 24 | static int syslog_control(xlog_s *, xlog_cmd_e, va_list ) ; 25 | static int syslog_write(xlog_s *, const char buf[], int , int , va_list ) ; 26 | static int syslog_parms(xlog_e, va_list) ; 27 | 28 | static struct syslog_parms parms = 29 | { 30 | 0, 31 | #ifndef NO_SYSLOG 32 | LOG_PID + LOG_NOWAIT, 33 | LOG_USER, 34 | #else 35 | 0, 36 | 0, 37 | #endif 38 | "XLOG", 39 | } ; 40 | 41 | 42 | struct xlog_ops __xlog_syslog_ops = 43 | { 44 | syslog_init, 45 | syslog_fini, 46 | syslog_write, 47 | syslog_control, 48 | syslog_parms 49 | } ; 50 | 51 | #ifdef NO_SYSLOG 52 | 53 | /* 54 | * Notice that the following functions will never be invoked since 55 | * the xlog_* functions will not call them. However, we need to define 56 | * them so that we don't have any unresolved references; and we define 57 | * them without any arguments. 58 | */ 59 | static void syslog() 60 | { 61 | } 62 | 63 | static void openlog() 64 | { 65 | } 66 | 67 | static void closelog() 68 | { 69 | } 70 | 71 | #endif /* NO_SYSLOG */ 72 | 73 | 74 | /* 75 | * Expected arguments: 76 | * facility, level 77 | */ 78 | static int syslog_init( xlog_s *xp, va_list ap ) 79 | { 80 | struct syslog_parms *slp = &parms ; 81 | struct syslog_s *sp ; 82 | 83 | sp = NEW( struct syslog_s ) ; 84 | if ( sp == NULL ) 85 | return( XLOG_ENOMEM ) ; 86 | sp->sl_facility = va_arg( ap, int ) ; 87 | sp->sl_default_level = va_arg( ap, int ) ; 88 | if ( slp->slp_n_xlogs++ == 0 ) 89 | openlog( slp->slp_ident, slp->slp_logopts, slp->slp_facility ) ; 90 | xp->xl_data = sp ; 91 | return( XLOG_ENOERROR ) ; 92 | } 93 | 94 | 95 | static void syslog_fini( xlog_s *xp ) 96 | { 97 | if ( --parms.slp_n_xlogs == 0 ) 98 | closelog() ; 99 | free( SYSLOG( xp ) ) ; 100 | xp->xl_data = NULL ; 101 | } 102 | 103 | 104 | static int syslog_control( xlog_s *xp, xlog_cmd_e cmd, va_list ap ) 105 | { 106 | switch ( cmd ) 107 | { 108 | case XLOG_LEVEL: 109 | SYSLOG( xp )->sl_default_level = va_arg( ap, int ) ; 110 | break ; 111 | 112 | case XLOG_FACILITY: 113 | SYSLOG( xp )->sl_facility = va_arg( ap, int ) ; 114 | break ; 115 | 116 | case XLOG_PREEXEC: 117 | closelog() ; 118 | break ; 119 | 120 | case XLOG_POSTEXEC: 121 | if ( parms.slp_n_xlogs ) 122 | openlog( parms.slp_ident, parms.slp_logopts, parms.slp_facility ) ; 123 | break ; 124 | 125 | /* These fall through ? */ 126 | case XLOG_LINK: 127 | case XLOG_CALLBACK: 128 | case XLOG_GETFLAG: 129 | case XLOG_SETFLAG: 130 | case XLOG_SIZECHECK: 131 | case XLOG_GETFD: 132 | case XLOG_LIMITS: 133 | break ; 134 | } 135 | return( XLOG_ENOERROR ) ; 136 | } 137 | 138 | 139 | static int syslog_write( xlog_s *xp, const char buf[], int len, int flags, va_list ap ) 140 | { 141 | int level ; 142 | int syslog_arg ; 143 | char prefix[ MSGBUFSIZE ] ; 144 | int prefix_size = sizeof( prefix ) ; 145 | int prefix_len = 0 ; 146 | int cc ; 147 | int percent_m_pos ; 148 | int action_flags = ( flags | xp->xl_flags ) ; 149 | 150 | if ( flags & XLOG_SET_LEVEL ) 151 | level = va_arg( ap, int ) ; 152 | else 153 | level = SYSLOG( xp )->sl_default_level ; 154 | syslog_arg = SYSLOG( xp )->sl_facility + level ; 155 | 156 | if ( action_flags & XLOG_PRINT_ID ) 157 | { 158 | cc = strx_nprint( &prefix[ prefix_len ], prefix_size, "%s: ", 159 | xp->xl_id ) ; 160 | prefix_len += cc ; 161 | prefix_size -= cc ; 162 | } 163 | 164 | if ( ( action_flags & XLOG_NO_ERRNO ) || 165 | ( percent_m_pos = __xlog_add_errno( buf, len ) ) == -1 ) 166 | syslog( syslog_arg, "%.*s%.*s", prefix_len, prefix, len, buf ) ; 167 | else 168 | { 169 | char *ep ; 170 | char errno_buf[ 100 ] ; 171 | unsigned size = sizeof( errno_buf ) ; 172 | 173 | ep = __xlog_explain_errno( errno_buf, &size ) ; 174 | syslog( syslog_arg, "%.*s%.*s%.*s%.*s", 175 | prefix_len, prefix, 176 | percent_m_pos, buf, 177 | (int)size, ep, 178 | len - percent_m_pos - 2, buf + percent_m_pos + 2 ) ; 179 | } 180 | return( XLOG_ENOERROR ) ; 181 | } 182 | 183 | 184 | static int syslog_parms( xlog_e type, va_list ap ) 185 | { 186 | char *id = NULL; 187 | 188 | id = __xlog_new_string( va_arg( ap, char * ) ); 189 | if ( id == NULL ) 190 | return( XLOG_ENOMEM ) ; 191 | parms.slp_ident = id ; 192 | parms.slp_logopts = va_arg( ap, int ) ; 193 | parms.slp_facility = va_arg( ap, int ) ; 194 | return( XLOG_ENOERROR ) ; 195 | } 196 | 197 | -------------------------------------------------------------------------------- /src/logctl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992 by Panagiotis Tsirigotis 3 | * (c) Copyright 1998-2001 by Rob Braun 4 | * All rights reserved. The file named COPYRIGHT specifies the terms 5 | * and conditions for redistribution. 6 | */ 7 | 8 | 9 | #include "config.h" 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "logctl.h" 16 | #include "msg.h" 17 | #include "xconfig.h" 18 | #include "main.h" 19 | #include "sconf.h" 20 | 21 | 22 | static xlog_h start_filelog( const char *id, struct filelog *flp ) 23 | { 24 | xlog_h xh ; 25 | int fd ; 26 | int log_file_mode = ( debug.on ) ? 0644 : LOG_FILE_MODE ; 27 | const char *func = "start_filelog" ; 28 | 29 | xh = xlog_create( XLOG_FILELOG, id, XLOG_NOFLAGS, 30 | flp->fl_filename, LOG_OPEN_FLAGS, log_file_mode ) ; 31 | if ( xh == NULL ) 32 | { 33 | msg( LOG_ERR, func, "creation of %s log failed", id ) ; 34 | return( NULL ) ; 35 | } 36 | 37 | if ( xlog_control( xh, XLOG_GETFD, &fd ) != XLOG_ENOERROR || 38 | fcntl( fd, F_SETFD, FD_CLOEXEC ) == -1 ) 39 | { 40 | msg( LOG_ERR, func, "Failed to set close-on-exec flag for log file" ) ; 41 | xlog_destroy( xh ) ; 42 | return( NULL ) ; 43 | } 44 | 45 | ps.rws.descriptors_free-- ; 46 | 47 | if ( FILELOG_SIZE_CONTROL( flp ) ) 48 | (void) xlog_control( xh, 49 | XLOG_LIMITS, flp->fl_soft_limit, flp->fl_hard_limit ) ; 50 | 51 | return( xh ) ; 52 | } 53 | 54 | 55 | /* 56 | * This function is invoked when a xlog detects an error (for example, 57 | * exceeding the file size limit). 58 | * The function just enters a log message. 59 | * 60 | * NOTE: We could destroy the xlog at this point but we choose not to. 61 | */ 62 | static void log_in_error( xlog_h xh, int error_code, void *arg ) 63 | { 64 | struct service *sp = SP( arg ) ; 65 | const char *log_id = ( sp == NULL ) ? "common" : SVC_ID( sp ) ; 66 | const char *func = "log_in_error" ; 67 | 68 | #ifdef lint 69 | xh = xh ; 70 | #endif 71 | if ( error_code == XLOG_ESIZE ) 72 | msg( LOG_ERR, func, "Size of %s log exceeded hard limit", log_id ) ; 73 | else 74 | msg( LOG_ERR, func, "Error in %s log: %d", log_id, error_code ) ; 75 | } 76 | 77 | /* 78 | * Start logging for the specified service. 79 | * The current configuration is used to determine the common log file. 80 | */ 81 | status_e log_start( struct service *sp, xlog_h *xhp ) 82 | { 83 | xlog_h xh ; 84 | const char *sid = SVC_ID( sp ) ; 85 | struct log *lp = SC_LOG( SVC_CONF( sp ) ) ; 86 | const char *func = "log_start" ; 87 | 88 | switch ( lp->l_type ) 89 | { 90 | case L_NONE: 91 | xh = NULL ; 92 | break ; 93 | 94 | case L_SYSLOG: 95 | xh = xlog_create( XLOG_SYSLOG, sid, XLOG_NOFLAGS, 96 | LOG_GET_SYSLOG( lp )->sl_facility, 97 | LOG_GET_SYSLOG( lp )->sl_level ) ; 98 | if ( xh == NULL ) 99 | { 100 | msg( LOG_ERR, func, "failed to create a log for service %s", sid ) ; 101 | return( FAILED ) ; 102 | } 103 | xlog_control( xh, XLOG_CALLBACK, log_in_error, (void *)sp ) ; 104 | break ; 105 | 106 | case L_FILE: 107 | /* 108 | * NOTE: if the same file is specified for more than one service, 109 | * it will be opened as many times. 110 | * Furthermore, size control will not be accurate. 111 | */ 112 | xh = start_filelog( sid, LOG_GET_FILELOG( lp ) ) ; 113 | if ( xh == NULL ) 114 | return( FAILED ) ; 115 | (void) xlog_control( xh, XLOG_CALLBACK, log_in_error, (void *)sp ) ; 116 | break ; 117 | 118 | case L_COMMON_FILE: 119 | if ( DEFAULT_LOG( ps ) == NULL ) 120 | if ( DEFAULT_LOG_ERROR( ps ) ) 121 | return( FAILED ) ; 122 | else 123 | { 124 | xh = start_filelog( "default", 125 | LOG_GET_FILELOG( SC_LOG( DEFAULTS( ps ) ) ) ) ; 126 | if ( xh == NULL ) 127 | { 128 | DEFAULT_LOG_ERROR( ps ) = TRUE ; 129 | return( FAILED ) ; 130 | } 131 | DEFAULT_LOG( ps ) = xh ; 132 | (void) xlog_control( xh, 133 | XLOG_CALLBACK, log_in_error, VOID_NULL ) ; 134 | } 135 | else 136 | xh = DEFAULT_LOG( ps ) ; 137 | break ; 138 | 139 | default: /* SHOULDN'T HAPPEN */ 140 | msg( LOG_ERR, func, "bad log type (%d) for service %s", 141 | (int) LOG_GET_TYPE( lp ), sid ) ; 142 | return( FAILED ) ; 143 | } 144 | *xhp = xh ; 145 | return( OK ) ; 146 | } 147 | 148 | 149 | void log_end( struct log *lp, xlog_h xh ) 150 | { 151 | const char *func = "log_end" ; 152 | 153 | if ( xh == NULL ) /* shouldn't be NULL but just in case */ 154 | { 155 | msg( LOG_NOTICE, func, "called with NULL handle" ) ; 156 | return ; 157 | } 158 | 159 | switch ( LOG_GET_TYPE( lp ) ) 160 | { 161 | case L_FILE: 162 | ps.rws.descriptors_free++ ; 163 | /* FALL THROUGH */ 164 | 165 | case L_SYSLOG: 166 | xlog_destroy( xh ) ; 167 | case L_NONE: 168 | case L_COMMON_FILE: 169 | ; 170 | } 171 | } 172 | 173 | -------------------------------------------------------------------------------- /src/sio/sio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis 3 | * All rights reserved. The file named COPYRIGHT specifies the terms 4 | * and conditions for redistribution. 5 | */ 6 | 7 | /* 8 | * $Id$ 9 | */ 10 | 11 | #ifndef __SIO_H 12 | #define __SIO_H 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | /* 20 | * Naming conventions: 21 | * 1) SIO functions and macros have names starting with a capital S 22 | * 2) SIO constants meant to be used by user programs have 23 | * names starting with SIO_ 24 | * 3) Internal functions, struct identifiers, enum identifiers 25 | * etc. have names starting with __sio 26 | * 4) Internal constants and macros have names starting with __SIO 27 | */ 28 | 29 | 30 | /* 31 | * external constants 32 | * 33 | * SIO_FLUSH_ALL: flush all output streams 34 | * SIO_ERR: operation failed 35 | * SIO_EOF: eof on stream 36 | * #define SIO_EOF (-2) 37 | */ 38 | #define SIO_FLUSH_ALL (-1) 39 | #define SIO_ERR (-1) 40 | 41 | /* 42 | * Buffering types 43 | */ 44 | #define SIO_FULLBUF 0 45 | #define SIO_LINEBUF 1 46 | #define SIO_NOBUF 2 47 | 48 | /* 49 | * Descriptor for an input stream 50 | */ 51 | struct __sio_input_descriptor 52 | { 53 | /* 54 | * buf: points to the buffer area. 55 | * When doing memory mapping, it is equal to the unit 56 | * from which we are reading. When doing buffered I/O 57 | * it points to the primary buffer. The auxiliary 58 | * buffer is right below buf and is of the same size. 59 | */ 60 | char *buf ; 61 | size_t buffer_size ; 62 | 63 | char *start ; /* start of valid buffer contents */ 64 | char *end ; /* end of valid buffer contents + 1 */ 65 | char *nextb ; /* pointer to next byte to read/write */ 66 | /* Always: start <= nextb < end */ 67 | 68 | unsigned line_length ; 69 | int max_line_length ; 70 | int tied_fd ; 71 | 72 | int memory_mapped ; /* flag to denote if we use */ 73 | /* memory mapping */ 74 | } ; 75 | 76 | typedef struct __sio_input_descriptor __sio_id_t ; 77 | 78 | 79 | /* 80 | * Descriptor for an output stream 81 | */ 82 | struct __sio_output_descriptor 83 | { 84 | /* 85 | * buf: points to the buffer area. 86 | * buf_end: is equal to buf + buffer_size 87 | */ 88 | char *buf ; 89 | char *buf_end ; 90 | 91 | unsigned buffer_size ; 92 | 93 | char *start ; /* start of valid buffer contents */ 94 | /* (used by the R and W functions) */ 95 | char *nextb ; /* pointer to next byte to read/write */ 96 | /* Always: start <= nextb < buf_end */ 97 | int buftype ; /* type of buffering */ 98 | } ; 99 | 100 | typedef struct __sio_output_descriptor __sio_od_t ; 101 | 102 | 103 | 104 | /* 105 | * Stream types 106 | */ 107 | enum __sio_stream { __SIO_INPUT_STREAM, __SIO_OUTPUT_STREAM } ; 108 | 109 | 110 | /* 111 | * General descriptor 112 | */ 113 | struct __sio_descriptor 114 | { 115 | union 116 | { 117 | __sio_id_t input_descriptor ; 118 | __sio_od_t output_descriptor ; 119 | } descriptor ; 120 | enum __sio_stream stream_type ; 121 | int initialized ; 122 | } ; 123 | 124 | typedef struct __sio_descriptor __sio_descriptor_t ; 125 | 126 | 127 | /* 128 | * The array of descriptors (as many as available file descriptors) 129 | */ 130 | extern int __sio_n_descriptors ; 131 | extern __sio_descriptor_t *__sio_descriptors ; 132 | 133 | 134 | /* 135 | * Internally used macros 136 | */ 137 | #define __SIO_FD_INITIALIZED( fd ) \ 138 | (fd >= 0 && fd < __sio_n_descriptors && __sio_descriptors[ fd ].initialized) 139 | #define __SIO_ID( fd ) (__sio_descriptors[ fd ].descriptor.input_descriptor) 140 | #define __SIO_OD( fd ) (__sio_descriptors[ fd ].descriptor.output_descriptor) 141 | #define __SIO_MUST_FLUSH( od, ch ) \ 142 | ( (od).buftype != SIO_FULLBUF && \ 143 | ( (od).buftype == SIO_NOBUF || ch == '\n' ) ) 144 | 145 | 146 | /* 147 | * SIO Macros: 148 | * 149 | * SIOLINELEN( fd ) 150 | * 151 | * NOTE: The maximum line size depends on whether the descriptor 152 | * was originally memory mapped. If it was, then the maximum 153 | * line size will be the map_unit_size (a function of the system 154 | * page size and PAGES_MAPPED). Otherwise, it will be either the 155 | * optimal block size as reported by stat(2) or SIO_BUFFER_SIZE. 156 | */ 157 | 158 | #define SIOLINELEN( fd ) __SIO_ID( fd ).line_length 159 | 160 | /* 161 | * The Read functions 162 | */ 163 | char *Srdline ( int fd ) ; 164 | 165 | /* 166 | * The Write functions 167 | */ 168 | ssize_t Swrite ( int fd, const char *buf, size_t ); 169 | ssize_t Sprint ( int fd, const char *format, ... ) 170 | #ifdef __GNUC__ 171 | __attribute__ ((format (printf, 2, 3))); 172 | #else 173 | ; 174 | #endif 175 | int Sputchar( int fd, char c ); 176 | ssize_t Sprintv ( int fd, const char *format, va_list ap ) 177 | #ifdef __GNUC__ 178 | __attribute__ ((format (printf, 2, 0))); 179 | #else 180 | ; 181 | #endif 182 | 183 | /* 184 | * other functions 185 | */ 186 | int Sdone ( int fd ) ; 187 | int Sflush ( int fd ) ; 188 | int Sclose ( int fd ) ; 189 | int Sbuftype ( int fd, int type ) ; 190 | int Smorefds ( int ) ; 191 | ssize_t __sio_converter( __sio_od_t *, int , const char *, va_list ); 192 | int sio_setup(int fd, __sio_descriptor_t **dp, unsigned int type ); 193 | 194 | #ifdef __GNUC__ 195 | __attribute__ ((noreturn)) 196 | #endif 197 | void terminate(const char *); 198 | 199 | #endif /* __SIO_H */ 200 | 201 | -------------------------------------------------------------------------------- /src/env.c: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992 by Panagiotis Tsirigotis 3 | * (c) Sections Copyright 1998-2001 by Rob Braun 4 | * All rights reserved. The file named COPYRIGHT specifies the terms 5 | * and conditions for redistribution. 6 | */ 7 | 8 | 9 | #include "config.h" 10 | #include 11 | #include 12 | #include 13 | 14 | #include "pset.h" 15 | #include "env.h" 16 | #include "msg.h" 17 | 18 | extern char **environ ; 19 | env_h std_env ; /* created from environ */ 20 | 21 | status_e initenv(void) 22 | { 23 | std_env = env_make( environ ) ; 24 | return( ( std_env == NULL ) ? FAILED : OK ) ; 25 | } 26 | 27 | static status_e make_env_with_strings(struct environment *, env_h, pset_h); 28 | static status_e make_env_from_vars(struct environment *, env_h, pset_h) ; 29 | static status_e update_env_with_strings(env_h, pset_h) ; 30 | 31 | 32 | status_e setup_environ( struct service_config *scp, struct service_config *def ) 33 | { 34 | struct environment *ep = SC_ENV( scp ) ; 35 | 36 | if ( ! SC_SPECIFIED( scp, A_PASSENV ) ) 37 | { 38 | if ( ! SC_SPECIFIED( def, A_PASSENV ) ) 39 | { 40 | if ( ! SC_SPECIFIED( scp, A_ENV ) ) 41 | { 42 | ep->env_type = STD_ENV ; 43 | ep->env_handle = std_env ; 44 | return( OK ) ; 45 | } 46 | else 47 | return( 48 | make_env_with_strings( ep, std_env, SC_ENV_VAR_DEFS(scp) ) ) ; 49 | } 50 | else /* SC_SPECIFIED( def, A_PASSENV ) */ 51 | { 52 | struct environment *dep = SC_ENV( def ) ; 53 | 54 | if ( dep->env_type == NO_ENV && 55 | make_env_from_vars( dep, std_env, 56 | SC_PASS_ENV_VARS(def) ) == FAILED ) 57 | return( FAILED ) ; 58 | 59 | if ( ! SC_SPECIFIED( scp, A_ENV ) ) 60 | { 61 | ep->env_type = DEF_ENV ; 62 | ep->env_handle = dep->env_handle ; 63 | return( OK ) ; 64 | } 65 | else 66 | return( make_env_with_strings( ep, 67 | dep->env_handle, SC_ENV_VAR_DEFS(scp) ) ) ; 68 | } 69 | } 70 | else /* SC_SPECIFIED( scp, A_PASSENV ) */ 71 | { 72 | if ( make_env_from_vars( ep, std_env, SC_PASS_ENV_VARS(scp) ) == FAILED ) 73 | return( FAILED ) ; 74 | 75 | if ( ! SC_SPECIFIED( scp, A_ENV ) ) 76 | return( OK ) ; 77 | else 78 | { 79 | if ( update_env_with_strings( 80 | ep->env_handle, SC_ENV_VAR_DEFS(scp) ) == FAILED ) 81 | { 82 | env_destroy( ep->env_handle ) ; 83 | return( FAILED ) ; 84 | } 85 | return( OK ) ; 86 | } 87 | } 88 | } 89 | 90 | 91 | /* 92 | * Create a new environment from environ and env_strings 93 | * env_strings contains strings of the form "var=value" 94 | */ 95 | static status_e make_env_with_strings( struct environment *ep, 96 | env_h env, 97 | pset_h env_strings ) 98 | { 99 | env_h new_env ; 100 | const char *func = "make_env_with_strings" ; 101 | 102 | if ( ( new_env = env_create( env ) ) == ENV_NULL ) 103 | { 104 | out_of_memory( func ) ; 105 | return( FAILED ) ; 106 | } 107 | 108 | if ( update_env_with_strings( new_env, env_strings ) == FAILED ) 109 | { 110 | env_destroy( new_env ) ; 111 | return( FAILED ) ; 112 | } 113 | 114 | ep->env_type = CUSTOM_ENV ; 115 | ep->env_handle = new_env ; 116 | return( OK ) ; 117 | } 118 | 119 | 120 | static status_e make_env_from_vars( struct environment *ep, 121 | env_h env, 122 | pset_h vars ) 123 | { 124 | env_h new_env ; 125 | char *varname ; 126 | unsigned u ; 127 | const char *func = "make_env_from_vars" ; 128 | 129 | if ( ( new_env = env_create( ENV_NULL ) ) == ENV_NULL ) 130 | { 131 | out_of_memory( func ) ; 132 | return( FAILED ) ; 133 | } 134 | 135 | for ( u = 0 ; u < pset_count( vars ) ; u++ ) 136 | { 137 | varname = (char *) pset_pointer( vars, u ) ; 138 | if ( env_addvar( new_env, env, varname ) == ENV_ERR ) 139 | switch ( env_errno ) 140 | { 141 | case ENV_EBADVAR: 142 | msg( LOG_ERR, func, "Unknown variable %s", varname ) ; 143 | break ; 144 | 145 | case ENV_ENOMEM: 146 | out_of_memory( func ) ; 147 | env_destroy( new_env ) ; 148 | return( FAILED ) ; 149 | } 150 | } 151 | 152 | ep->env_type = CUSTOM_ENV ; 153 | ep->env_handle = new_env ; 154 | return( OK ) ; 155 | } 156 | 157 | 158 | static status_e update_env_with_strings( env_h env, pset_h strings ) 159 | { 160 | unsigned u ; 161 | const char *func = "update_env_with_strings" ; 162 | 163 | for ( u = 0 ; u < pset_count( strings ) ; u++ ) 164 | { 165 | char *p = (char *) pset_pointer( strings, u ) ; 166 | 167 | if ( env_addstr( env, p ) == ENV_ERR ) 168 | switch ( env_errno ) 169 | { 170 | case ENV_ENOMEM: 171 | out_of_memory( func ) ; 172 | return( FAILED ) ; 173 | 174 | case ENV_EBADSTRING: 175 | msg( LOG_ERR, func, "Bad environment string: %s", p ) ; 176 | break ; 177 | } 178 | } 179 | return( OK ) ; 180 | } 181 | 182 | -------------------------------------------------------------------------------- /src/misc/m_env.c: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992 by Panagiotis Tsirigotis 3 | * All rights reserved. The file named COPYRIGHT specifies the terms 4 | * and conditions for redistribution. 5 | */ 6 | 7 | 8 | #include "config.h" 9 | #include 10 | #include 11 | #include 12 | 13 | #include "m_env.h" 14 | #include "str.h" 15 | 16 | 17 | typedef struct __env env_s ; 18 | 19 | #define INITIAL_VARS 20 20 | #define INCREASE 10 21 | 22 | 23 | int env_errno ; 24 | 25 | static char **lookup( const env_h env, const char *var, 26 | register unsigned int len ); 27 | 28 | static env_s *alloc_env( unsigned max_vars ) 29 | { 30 | env_s *ep ; 31 | unsigned size ; 32 | char **pointers ; 33 | 34 | ep = (env_s *) malloc( sizeof( env_s ) ) ; 35 | if ( ep == ENV_NULL ) 36 | { 37 | env_errno = ENV_ENOMEM ; 38 | return( ENV_NULL ) ; 39 | } 40 | 41 | memset( ep, 0, sizeof( env_s ) ); 42 | size = ( max_vars + 1 ) * sizeof( char * ) ; 43 | pointers = (char **) malloc( size ) ; 44 | if ( pointers == NULL ) 45 | { 46 | free( (char *)ep ) ; 47 | env_errno = ENV_ENOMEM ; 48 | return( ENV_NULL ) ; 49 | } 50 | (void) memset( (char *)pointers, 0, size ) ; 51 | 52 | ep->vars = pointers ; 53 | ep->max_vars = max_vars ; 54 | ep->n_vars = 0 ; 55 | return( ep ) ; 56 | } 57 | 58 | 59 | env_h env_create( const env_h init_env ) 60 | { 61 | unsigned u ; 62 | env_s *ep ; 63 | unsigned max_vars ; 64 | 65 | if ( init_env == ENV_NULL ) 66 | max_vars = INITIAL_VARS ; 67 | else 68 | max_vars = init_env->n_vars + 5 ; 69 | 70 | ep = alloc_env( max_vars ) ; 71 | if ( ep == NULL ) 72 | { 73 | env_errno = ENV_ENOMEM ; 74 | return( ENV_NULL ) ; 75 | } 76 | 77 | if ( init_env == ENV_NULL ) 78 | return( ep ) ; 79 | 80 | for ( u = 0, ep->n_vars = 0 ; u < init_env->n_vars ; u++, ep->n_vars++ ) 81 | { 82 | ep->vars[ ep->n_vars ] = new_string( init_env->vars[ u ] ) ; 83 | if ( ep->vars[ ep->n_vars ] == NULL ) 84 | { 85 | env_destroy( ep ) ; 86 | env_errno = ENV_ENOMEM ; 87 | return( ENV_NULL ) ; 88 | } 89 | } 90 | return( ep ) ; 91 | } 92 | 93 | 94 | void env_destroy( env_h env ) 95 | { 96 | unsigned u ; 97 | 98 | for ( u = 0 ; u < env->n_vars ; u++ ) 99 | free( env->vars[ u ] ) ; 100 | free( (char *)env->vars ) ; 101 | free( (char *)env ) ; 102 | } 103 | 104 | 105 | env_h env_make( char **env_strings ) 106 | { 107 | env_s *ep ; 108 | char **pp ; 109 | 110 | for ( pp = env_strings ; *pp ; pp++ ) ; 111 | 112 | ep = alloc_env( (unsigned) (pp-env_strings) ) ; 113 | if ( ep == NULL ) 114 | { 115 | env_errno = ENV_ENOMEM ; 116 | return( ENV_NULL ) ; 117 | } 118 | 119 | for ( pp = env_strings ; *pp ; pp++ ) 120 | { 121 | char *p = new_string( *pp ) ; 122 | 123 | if ( p == NULL ) 124 | { 125 | env_destroy( ep ) ; 126 | env_errno = ENV_ENOMEM ; 127 | return( ENV_NULL ) ; 128 | } 129 | ep->vars[ ep->n_vars++ ] = p ; 130 | } 131 | return( ep ) ; 132 | } 133 | 134 | 135 | char *env_lookup( env_h env, const char *var ) 136 | { 137 | char **pp = lookup( env, var, strlen( var ) ) ; 138 | 139 | return( ( pp == NULL ) ? NULL : *pp ) ; 140 | } 141 | 142 | 143 | static char **lookup( const env_h env, const char * var, 144 | register unsigned int len ) 145 | { 146 | char **pp ; 147 | 148 | for ( pp = env->vars ; *pp ; pp++ ) 149 | if ( strncmp( *pp, var, len ) == 0 && (*pp)[ len ] == '=' ) 150 | return( pp ) ; 151 | return( NULL ) ; 152 | } 153 | 154 | 155 | static int grow( env_s *ep ) 156 | { 157 | char **new_vars ; 158 | unsigned new_max_vars ; 159 | unsigned new_size ; 160 | new_max_vars = ep->max_vars + INCREASE ; 161 | new_size = ( new_max_vars+1 ) * sizeof( char * ) ; 162 | new_vars = (char **) realloc( (char *)ep->vars, new_size ) ; 163 | if ( new_vars == NULL ) 164 | return( ENV_ERR ) ; 165 | 166 | ep->vars = new_vars ; 167 | ep->max_vars = new_max_vars ; 168 | 169 | memset(&ep->vars[ep->n_vars], 0, new_size - (ep->n_vars * sizeof(char *))); 170 | return( ENV_OK ) ; 171 | } 172 | 173 | 174 | /* 175 | * Add the variable string to the given environment. 176 | */ 177 | static int addstring( env_s *ep, const char *var_string, unsigned int len ) 178 | { 179 | char **pp ; 180 | char *p ; 181 | 182 | p = new_string( var_string ) ; 183 | if ( p == NULL ) 184 | return( ENV_ERR ) ; 185 | 186 | pp = lookup( ep, var_string, len ) ; 187 | if ( pp == NULL ) 188 | { 189 | if ( ep->n_vars >= ep->max_vars && grow( ep ) == ENV_ERR ) 190 | { 191 | free( p ) ; 192 | env_errno = ENV_ENOMEM ; 193 | return( ENV_ERR ) ; 194 | } 195 | ep->vars[ ep->n_vars++ ] = p ; 196 | ep->vars[ ep->n_vars ] = NULL; 197 | } 198 | else 199 | { 200 | free( *pp ) ; 201 | *pp = p ; 202 | } 203 | return( ENV_OK ) ; 204 | } 205 | 206 | 207 | int env_addvar( env_h env, env_h from_env, char *var_name ) 208 | { 209 | char *var_string = env_lookup( from_env, var_name ) ; 210 | 211 | if ( var_string == NULL ) 212 | { 213 | env_errno = ENV_EBADVAR ; 214 | return( ENV_ERR ) ; 215 | } 216 | 217 | return( addstring( env, var_string, strlen( var_name ) ) ) ; 218 | } 219 | 220 | 221 | int env_addstr( env_h env, char *var_string ) 222 | { 223 | char *p = strchr( var_string, '=' ) ; 224 | 225 | if ( p == NULL ) 226 | { 227 | env_errno = ENV_EBADSTRING ; 228 | return( ENV_ERR ) ; 229 | } 230 | 231 | return( addstring( env, var_string, (unsigned int)(p-var_string) ) ) ; 232 | } 233 | -------------------------------------------------------------------------------- /src/parsesup.c: -------------------------------------------------------------------------------- 1 | /* 2 | * (c) Copyright 1992 by Panagiotis Tsirigotis 3 | * (c) Sections Copyright 1998-2001 by Rob Braun 4 | * All rights reserved. The file named COPYRIGHT specifies the terms 5 | * and conditions for redistribution. 6 | */ 7 | 8 | #include "config.h" 9 | #include 10 | #ifdef HAVE_STDINT_H 11 | #include 12 | #endif 13 | #include 14 | #include 15 | 16 | #include "sio.h" 17 | #include "str.h" 18 | #include "parsesup.h" 19 | #include "msg.h" 20 | 21 | 22 | /* 23 | * next_line returns the next line of the file or NULL if the end of file 24 | * is reached. 25 | * Comment lines and empty lines are skipped. 26 | */ 27 | char *next_line( int fd ) 28 | { 29 | for ( ;; ) 30 | { 31 | char *p ; 32 | char *line = Srdline( fd ) ; 33 | 34 | if ( line == NULL ) 35 | return( NULL ) ; 36 | 37 | line_count++ ; 38 | 39 | for ( p = line ;; p++ ) 40 | if ( *p == NUL || *p == COMMENT_BEGIN ) 41 | break ; /* skip this line */ 42 | else if ( isspace( *p ) ) 43 | continue ; /* skip white space */ 44 | else 45 | return( line ) ; 46 | } 47 | } 48 | 49 | 50 | /* 51 | * Input: 52 | * a line of the form 53 | * name [SPACE] OP [SPACE] value [SPACE] value ... 54 | * 55 | * Recognize the attribute name and operator and place them in *attrp, *opp 56 | * 57 | * Currently, we allow any non-space character to be used in the 58 | * attribute name. 59 | * 60 | * Return value: a pointer to the character after OP. 61 | */ 62 | static char *get_attr_op( char *line, char **attrp, enum assign_op *opp ) 63 | { 64 | char *p ; 65 | char *attr ; 66 | enum assign_op op ; 67 | const char *func = "get_attr_op" ; 68 | 69 | /* 70 | * First get the attribute name 71 | */ 72 | for ( p = line ; isspace( *p ) ; p++ ) ; /* skip spaces */ 73 | if ( *p == NUL ) 74 | { 75 | parsemsg( LOG_ERR, func, "Empty line" ) ; 76 | return( NULL ) ; 77 | } 78 | 79 | attr = p ; 80 | for ( ; ! isspace( *p ) && (*p != '='); p++ ) ; /* skip attribute name */ 81 | if ( *p == NUL ) 82 | { 83 | parsemsg( LOG_ERR, func, "Nothing after attribute: %s", attr ) ; 84 | return( NULL ) ; 85 | } 86 | if( *p == '=' ) { 87 | *p = NUL ; /* now attribute name is NUL terminated */ 88 | parsemsg( LOG_ERR, func, "Attribute %s needs a space before operator", attr); 89 | return( NULL ) ; 90 | } 91 | *p++ = NUL ; /* now attribute name is NUL terminated */ 92 | 93 | while ( isspace( *p ) ) p++ ; /* skip spaces */ 94 | 95 | switch ( *p ) 96 | { 97 | case NUL: 98 | parsemsg( LOG_ERR, func, "Nothing after attribute: %s", attr ) ; 99 | return( NULL ) ; 100 | 101 | case '=': 102 | op = SET_EQ ; 103 | break ; 104 | 105 | case '+': 106 | case '-': 107 | op = ( *p++ == '+' ) ? PLUS_EQ : MINUS_EQ ; 108 | if ( *p == '=' ) 109 | break ; 110 | 111 | /* FALL THROUGH if there is no '=' after the '+' or '-' */ 112 | 113 | default: 114 | parsemsg( LOG_ERR, func, "Bad operator for attribute: %s", attr ) ; 115 | return( NULL ) ; 116 | } 117 | *attrp = attr ; 118 | *opp = op ; 119 | return( ++p ) ; /* skip the '=' */ 120 | } 121 | 122 | 123 | /* 124 | * Parse a line of the form: 125 | * name OP value value value ... 126 | * where each value is a string and OP can be '=', '+=', '-=' 127 | * 128 | * NOTE: We do not allocate space for the name and values. Instead we keep 129 | * pointers to the line. 130 | */ 131 | status_e parse_line( char *line, 132 | char **namep, 133 | enum assign_op *opp, 134 | pset_h values ) 135 | { 136 | char *value ; 137 | char *values_string ; 138 | char *attribute ; 139 | str_h strp ; 140 | const char *func = "parse_line" ; 141 | 142 | if ( ( values_string = get_attr_op( line, &attribute, opp ) ) == NULL ) 143 | return( FAILED ) ; 144 | 145 | /* 146 | * Now grab the values 147 | */ 148 | strp = str_parse( values_string, " \t", STR_RETURN_ERROR, (int *)0 ) ; 149 | if ( strp == NULL ) 150 | { 151 | parsemsg( LOG_CRIT, func, ES_NOMEM ) ; 152 | return( FAILED ) ; 153 | } 154 | 155 | while ( (value = str_component( strp )) ) 156 | { 157 | if ( pset_add( values, value ) == NULL ) 158 | { 159 | parsemsg( LOG_CRIT, func, ES_NOMEM ) ; 160 | str_endparse( strp ) ; 161 | return( FAILED ) ; 162 | } 163 | } 164 | 165 | str_endparse( strp ) ; 166 | *namep = attribute ; 167 | return( OK ) ; 168 | } 169 | 170 | 171 | void skip_entry( int fd ) 172 | { 173 | for ( ;; ) 174 | { 175 | char *line = next_line( fd ) ; 176 | 177 | if ( line == NULL ) /* reached EOF ? */ 178 | { 179 | parsemsg( LOG_WARNING, "skip_entry", 180 | "missing %c in last service entry", ENTRY_END ) ; 181 | break ; 182 | } 183 | 184 | if ( line_has_only_1_char( line, ENTRY_END ) ) 185 | break ; 186 | } 187 | } 188 | 189 | 190 | 191 | /* 192 | * Returns TRUE if the given line contains a single instance of the 193 | * specified character and no other non-space characters 194 | */ 195 | int line_has_only_1_char( const char *line, char ch ) 196 | { 197 | const char *p ; 198 | char target_char = ch ; 199 | 200 | for ( p = line ; *p ; p++ ) 201 | if ( *p == target_char ) 202 | target_char = NUL ; 203 | else if ( ! isspace( *p ) ) 204 | return( FALSE ) ; 205 | return( target_char != ch ) ; 206 | } 207 | 208 | -------------------------------------------------------------------------------- /man/Sprint.3: -------------------------------------------------------------------------------- 1 | .\"(c) Copyright 1992, 1993 by Panagiotis Tsirigotis 2 | .\"All rights reserved. The file named COPYRIGHT specifies the terms 3 | .\"and conditions for redistribution. 4 | .\" 5 | .\" $Id$ 6 | .TH Sprint 3X "29 May 1992" 7 | .SH NAME 8 | Sprint -- formatted stream output 9 | .SH SYNOPSIS 10 | .LP 11 | .nf 12 | .ft B 13 | int Sprint( fd, format [ , ... ] ) 14 | int fd ; 15 | char *format ; 16 | .SH DESCRIPTION 17 | \fBSprint()\fR provides formatted output conversion. The formatting is 18 | controlled by the \fIformat\fR argument. All characters in 19 | \fIformat\fR that do not specify a conversion are printed. A conversion 20 | is specified by a '%' followed by a string that ends with a 21 | conversion type character. The string may contain flags, a field width, 22 | a precision, and a modifier. 23 | .LP 24 | Possible flags (more that one can be specified and they can be in any order) 25 | include: 26 | .TP 10 27 | .B \'-' 28 | specifies left adjustment of the converted argument. The default 29 | is right adjustment. This flag is meaningful only if a field width 30 | is specified. 31 | .TP 32 | .B \'+' 33 | specifies that a number will always have a sign as a prefix (this 34 | forces a '+' sign to appear if the number is positive). 35 | .TP 36 | .B \' ' 37 | prefixes a \fIspace\fR to the number if the number has not a sign 38 | (therefore the '+' flag overrides this flag). 39 | .TP 40 | .B \'#' 41 | The meaning of '#' depends on the conversion type character: for \fBo\fR 42 | conversions the first digit will be 0; for \fBx\fR or \fBX\fR conversions 43 | \fB0x\fR or \fB0X\fR respectively will be prefixed to the number (if it 44 | is not zero); for \fBe\fR, \fBE\fR, \fBf\fR, \fBg\fR, and \fBG\fR conversions 45 | the number will always have a decimal point. 46 | .TP 47 | .B \'0' 48 | specifies padding with zeros instead of spaces. 49 | .LP 50 | The field width is specified by a number. This number indicates the 51 | \fIminimum\fR width for the field. A '*' may be used instead of the number. 52 | In that case the width is the value of the next argument which should 53 | be an \fBint\fR. 54 | A negative width value specifies left adjustment with a width equal 55 | to the absolute width value. 56 | .LP 57 | A precision is specified by a '.' followed by a number. The meaning of 58 | the precision depends on the type conversion character. For a string 59 | conversion, precision determines how many characters are printed from 60 | the string. For integer conversions, precision determines the 61 | number of digits used to print the number (zero padding is done if 62 | the precision exceeds the length of the number). For floating point 63 | conversions, precision determines the number of digits after the 64 | decimal point (\fBe\fR, \fBE\fR, \fBf\fR) or the number of 65 | significant digits (\fBg\fR, \fBG\fR). 66 | A '*' may be used instead of a number to specify the precision. In that 67 | case the precision is the value of the next argument which should 68 | be an \fBint\fR. 69 | The behavior of \fBSprint()\fR is undefined if the precision is negative. 70 | .LP 71 | The length modifier is \fBl\fR and indicates that the argument is 72 | a \fBlong\fR integer. 73 | .LP 74 | The type conversion characters are: 75 | \fBd, i, o, x, X, u, c, s, f, e, E, g, G, p, n, %\fR. 76 | For floating point conversions the argument should be of type \fIdouble\fR. 77 | .TP 10 78 | .B d,i 79 | specify signed decimal conversion. 80 | .TP 81 | .B u 82 | specifies unsigned decimal conversion. 83 | .TP 84 | .B o 85 | specifies octal conversion. 86 | .TP 87 | .B x,X 88 | specify hexadecimal conversion. For 89 | .B x 90 | the hex digits used are 0123456789abcdef. For 91 | .B X 92 | the hex digits used are 0123456789ABCDEF. 93 | There is no leading 94 | .B 0x 95 | or 96 | .B 0X 97 | (use the '#' flag for that). 98 | .TP 99 | .B c 100 | specifies character conversion; the argument should be of type 101 | \fIchar\fR. 102 | .TP 103 | .B s 104 | specifies string conversion; the argument should be of type 105 | \fIchar *\fR. 106 | .TP 107 | .B f 108 | specifies conversion to the form [-]ddd.dddd. The number 109 | of digits after the decimal point depends on precision; the default is 6. 110 | If the precision is 0, the decimal point is not printed (this can 111 | be overridden with the '#' flag). 112 | .B e,E 113 | specify conversion to the form [-]ddd.dddd[eE][+-]ddd. 114 | The number of digits after the decimal point depends on precision; 115 | the default is 6. If the precision is 0, the decimal point is not printed 116 | (this can be overridden with the '#' flag). 117 | The exponent is at least 2 digit wide. 118 | .TP 119 | .B g,G 120 | specify a conversion using the 121 | .B e,E 122 | format respectively if the 123 | exponent is less than -4 or greater than or equal to the precision; 124 | otherwise the 125 | .B f 126 | format is used. 127 | .TP 128 | .B p 129 | is used to print pointers (type \fIvoid *\fR, 130 | or \fIchar *\fR if the compiler does not support the former). 131 | .TP 132 | .B n 133 | expects a \fIint *\fR argument and puts in that integer 134 | the number of characters already printed by this call. 135 | .TP 136 | .B % 137 | is used to print a \fI%\fR. 138 | .LP 139 | If an unknown conversion character is specified, the percent sign 140 | followed by that character will be printed. 141 | .SH RETURN VALUE 142 | .LP 143 | If no error occurred, \fBSprint()\fR returns the number of characters 144 | printed. In case of error, it returns \fBSIO_ERR\fR. 145 | .SH BUGS 146 | .LP 147 | This is a list of differences between \fBSprint()\fR and the ANSI C Standard 148 | \fBprintf()\fR: 149 | .LP 150 | \fBSprint()\fR does not support non-removal of trailing zeroes for 151 | \fBg\fR and \fBG\fR conversions when the '#' flag is used. 152 | .LP 153 | \fBSprint()\fR does not support the h and L modifiers. 154 | .LP 155 | The current implementation assumes that \fIsizeof(int)==sizeof(long)\fR. 156 | .LP 157 | \fBSprint()\fR supports "%p" only if \fIsizeof(pointer)<=sizeof(int)\fR. 158 | --------------------------------------------------------------------------------