From 5f053019288e571895741dcfcd8885d81deb491c Mon Sep 17 00:00:00 2001 From: iratqq Date: Fri, 1 Feb 2008 04:37:40 +0000 Subject: [PATCH] remove networking code. sj3serv communicates only unix domain socket. --- trunk/src/sj3serv/Makefile.am | 3 +- trunk/src/sj3serv/comuni.c | 153 +---------------------- trunk/src/sj3serv/setup.c | 22 +--- trunk/src/sj3serv/sj3serv.h | 5 - trunk/src/sj3serv/sj3serv.lua.example.in | 22 ---- 5 files changed, 4 insertions(+), 201 deletions(-) diff --git a/trunk/src/sj3serv/Makefile.am b/trunk/src/sj3serv/Makefile.am index 090d9b9..ed6b816 100644 --- a/trunk/src/sj3serv/Makefile.am +++ b/trunk/src/sj3serv/Makefile.am @@ -14,8 +14,7 @@ INCLUDES = \ LDADD = \ $(top_srcdir)/lib/sj3core/libsj3core.la \ - $(top_srcdir)/lib/sj3compat/libsj3compat.la \ - @WRAP_LIB@ + $(top_srcdir)/lib/sj3compat/libsj3compat.la if SJ3_INTERNAL_LUA AM_CFLAGS += -I$(top_builddir)/lib/lua/src diff --git a/trunk/src/sj3serv/comuni.c b/trunk/src/sj3serv/comuni.c index 128e605..cae9cbb 100644 --- a/trunk/src/sj3serv/comuni.c +++ b/trunk/src/sj3serv/comuni.c @@ -79,8 +79,6 @@ jmp_buf client_dead; int client_fd; static int fd_unix = -1; -static int fd_inets[MAX_LISTEN_SOCKS]; -static int num_inets = 0; static char putbuf[BUFSIZ]; static char getbuf[BUFSIZ]; @@ -161,100 +159,10 @@ open_af_unix() set_fd(fd_unix); } -void -open_af_inet() -{ - struct addrinfo hints; - struct addrinfo *res, *res0; - int error; - int true = 1; - - /* - * getaddrinfo() case. You can get IPv6 address and IPv4 address - * at the same time. - */ - memset(&hints, 0, sizeof(hints)); - /* set-up hints structure */ - hints.ai_family = address_family; - hints.ai_flags = AI_PASSIVE; - hints.ai_socktype = SOCK_STREAM; - - error = getaddrinfo(inet_host_name, inet_port_name, &hints, &res); - if (error) { - fprintf(stderr, gai_strerror(error)); - exit(1); - } - - res0 = res; - - for ( ; res; res = res->ai_next) { - struct sockaddr *sa = res->ai_addr; - u_int8_t salen = res->ai_addrlen; - char ntop[NI_MAXHOST], strport[NI_MAXSERV]; - int listen_sock; - - if (res->ai_family != AF_INET && res->ai_family != AF_INET6) - continue; - - if (num_inets >= MAX_LISTEN_SOCKS) { - fprintf(stderr, - "Too many listen sockets. " - "Enlarge MAX_LISTEN_SOCKS\n"); - exit(1); - } - - if (getnameinfo(sa, salen, - ntop, sizeof(ntop), strport, sizeof(strport), - NI_NUMERICHOST | NI_NUMERICSERV) != 0) { - fprintf(stderr, "getnameinfo failed\n"); - continue; - } - - listen_sock = socket(res->ai_family, res->ai_socktype, - res->ai_protocol); - - if (listen_sock < 0) { - fprintf(stderr, "socket: %.100s\n", strerror(errno)); - exit(1); - } - - if (setsockopt(listen_sock, SOL_SOCKET, SO_REUSEADDR, - &true, sizeof(true)) == -1) - fprintf(stderr, "setsockopt SO_REUSEADDR: %s\n", strerror(errno)); - - if (bind(listen_sock, sa, salen) < 0) { - fprintf(stderr, "Bind to port %s on %s failed: %.200s.\n", - strport, ntop, strerror(errno)); - close(listen_sock); - continue; - } - - if (listen(listen_sock, SOMAXCONN) < 0) { - fprintf(stderr, "listen: %.100s\n", strerror(errno)); - close(listen_sock); - exit(1); - } - - set_fd(listen_sock); - - fd_inets[num_inets] = listen_sock; - num_inets++; - } - freeaddrinfo(res0); - - if (num_inets < 0) { - fprintf(stderr, "Cannot bind any address."); - exit(1); - } -} - void open_socket() { - if (inet_enable) - open_af_inet(); - if (domain_enable) - open_af_unix(); + open_af_unix(); } static int @@ -269,34 +177,6 @@ connect_af_unix() return fd; } -static int -connect_af_inet(int fd_inet) -{ - struct sockaddr_in sin; - int i = sizeof(sin); - int fd = 0; - - if ((fd = accept(fd_inet, (struct sockaddr *)&sin, &i)) == ERROR) - warning_out("Can't accept AF_INET socket"); - -#ifdef USE_LIBWRAP - { - struct request_info req; - - request_init(&req, RQ_DAEMON, "sj3", RQ_FILE, fd_inets[i], NULL); - fromhost(&req); - - if (!hosts_access(&req)) { - warning_out("connection refused from %s", - eval_client(&req)); - close(fd); - fd = -1; - } - } -#endif - return fd; -} - static void close_af_unix() { @@ -316,33 +196,10 @@ close_af_unix() clr_fd(fd_unix); } -static void -close_af_inet() -{ - struct sockaddr_in sin; - int true = 1; - int i, j; - - for (j = 0; j < num_inets; j++) { - ioctl(fd_inets[j], FIONBIO, &true); - for ( ; ; ) { - i = sizeof(sin); - if (accept(fd_inets[j], (struct sockaddr *)&sin, &i) < 0) - break; - } - shutdown(fd_inets[j], 2); - close(fd_inets[j]); - clr_fd(fd_inets[j]); - } -} - void close_socket() { - if (inet_enable) - close_af_unix(); - if (domain_enable) - close_af_inet(); + close_af_unix(); } static void @@ -352,12 +209,6 @@ connect_client(fd_set *readfds) Client *client_tmp; int i; - for (i = 0; i < num_inets; i++) { - if (FD_ISSET(fd_inets[i], readfds)) { - fd = connect_af_inet(fd_inets[i]); - break; - } - } if (fd < 0 && FD_ISSET(fd_unix, readfds)) fd = connect_af_unix(); if (fd == ERROR) diff --git a/trunk/src/sj3serv/setup.c b/trunk/src/sj3serv/setup.c index a46fb34..6f6dd20 100644 --- a/trunk/src/sj3serv/setup.c +++ b/trunk/src/sj3serv/setup.c @@ -74,7 +74,6 @@ int address_family = AF_UNSPEC; char inet_host_name[MAXHOSTNAMELEN]; char inet_port_name[256]; -int domain_enable = -1; char domain_socket_name[MAXPATHLEN]; char dict_dir[MAXPATHLEN]; @@ -113,8 +112,6 @@ struct allow_user_entry { } *allow_user; static int opt_daemon_disable = 0; -static int opt_ipv4 = 0; -static int opt_ipv6 = 0; static lua_State *lua_state; static int @@ -265,7 +262,6 @@ set_domain(lua_State *lstate) { if (!check_table(lstate)) return 0; - lua2sj_boolean(lstate, "enable", 1, 0, &domain_enable); lua2sj_string(lstate, "socket_name", 1, SOCKETNAME, domain_socket_name, sizeof(domain_socket_name)); return 0; @@ -274,7 +270,6 @@ set_domain(lua_State *lstate) static int get_domain(lua_State *lstate) { - sj2lua_boolean(lstate, "enable", domain_enable); sj2lua_string(lstate, "socket_name", domain_socket_name); return 1; @@ -421,15 +416,6 @@ read_runcmd() else daemon_enable = 1; - if (opt_ipv4) - address_family = AF_INET; - else if (opt_ipv6) - address_family = AF_INET6; - else if (strcmp(inet_address_family, "inet") == 0) - address_family = AF_INET; - else if (strcmp(inet_address_family, "inet6") == 0) - address_family = AF_INET6; - #if 0 /* DON'T LEAVE */ lua_close(lua_state); lua_state = NULL; @@ -490,14 +476,8 @@ parse_arg(int argc, char **argv) strlcpy(program_name, p, sizeof(program_name)); strlcpy(runcmd_file, RUNCMDFILE, sizeof(runcmd_file)); - while ((c = getopt(argc, argv, "46f:d")) != EOF) { + while ((c = getopt(argc, argv, "f:d")) != EOF) { switch (c) { - case '4': - opt_ipv4 = 1; - break; - case '6': - opt_ipv6 = 1; - break; case 'f': ret = strlcpy(runcmd_file, optarg, sizeof(runcmd_file)); if (ret > sizeof(runcmd_file)) diff --git a/trunk/src/sj3serv/sj3serv.h b/trunk/src/sj3serv/sj3serv.h index fe197dd..9e972c2 100644 --- a/trunk/src/sj3serv/sj3serv.h +++ b/trunk/src/sj3serv/sj3serv.h @@ -118,12 +118,7 @@ extern char pid_file[MAXPATHLEN]; extern char chuser_name[BUFSIZ]; extern int chroot_enable; extern char chroot_dir[MAXPATHLEN]; -extern int inet_enable; -extern char inet_address_family[256]; extern int address_family; -extern char inet_host_name[MAXHOSTNAMELEN]; -extern char inet_port_name[256]; -extern int domain_enable; extern char domain_socket_name[MAXPATHLEN]; extern char dict_dir[MAXPATHLEN]; extern char dict_file[FILENAME_MAX]; diff --git a/trunk/src/sj3serv/sj3serv.lua.example.in b/trunk/src/sj3serv/sj3serv.lua.example.in index 17380c7..3e847b4 100644 --- a/trunk/src/sj3serv/sj3serv.lua.example.in +++ b/trunk/src/sj3serv/sj3serv.lua.example.in @@ -43,29 +43,7 @@ sj3.set_server { dict_dir = "/spool/sj3", } -sj3.set_inet { - -- enable: Boolean - -- allow acccess via internet connection - enable = false, - - -- family: String "unspec" or "inet4" or "inet6" - -- address family - address_family = "unspec", - - -- host_name: String - -- listening address - host_name = "localhost", - - -- port_name: String - -- binding port name, man services - port_name = "3086", -} - sj3.set_domain { - -- enable: Boolean - -- allow acccess via unix domain socket - enable = true, - -- socket_name: String -- binding filename of unix domain socket socket_name = prefix .. "/run/sj3serv.socket",