inetd: make it NOMMU-capable and IPv6-friendly. Lots of renames

of variable/function names

Total: -2474 bytes
   text    data     bss     dec     hex filename
 802215     661    7452  810328   c5d58 busybox_old
 800120     661    7428  808209   c5511 busybox_unstripped
This commit is contained in:
Denis Vlasenko 2008-03-12 22:14:34 +00:00
parent 4e6c8120a5
commit 4e6d5117b8
10 changed files with 839 additions and 1061 deletions

View File

@ -1,7 +1,7 @@
# #
# Automatically generated make config: don't edit # Automatically generated make config: don't edit
# Busybox version: 1.10.0.svn # Busybox version: 1.10.0.svn
# Tue Mar 4 22:57:04 2008 # Thu Mar 6 20:18:05 2008
# #
CONFIG_HAVE_DOT_CONFIG=y CONFIG_HAVE_DOT_CONFIG=y
@ -653,13 +653,13 @@ CONFIG_IFUPDOWN_IFSTATE_PATH=""
# CONFIG_FEATURE_IFUPDOWN_IPV6 is not set # CONFIG_FEATURE_IFUPDOWN_IPV6 is not set
# CONFIG_FEATURE_IFUPDOWN_MAPPING is not set # CONFIG_FEATURE_IFUPDOWN_MAPPING is not set
# CONFIG_FEATURE_IFUPDOWN_EXTERNAL_DHCP is not set # CONFIG_FEATURE_IFUPDOWN_EXTERNAL_DHCP is not set
# CONFIG_INETD is not set CONFIG_INETD=y
# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_ECHO is not set CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_ECHO=y
# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_DISCARD is not set CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_DISCARD=y
# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_TIME is not set CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_TIME=y
# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_DAYTIME is not set CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_DAYTIME=y
# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_CHARGEN is not set CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_CHARGEN=y
# CONFIG_FEATURE_INETD_RPC is not set CONFIG_FEATURE_INETD_RPC=y
CONFIG_IP=y CONFIG_IP=y
CONFIG_FEATURE_IP_ADDRESS=y CONFIG_FEATURE_IP_ADDRESS=y
CONFIG_FEATURE_IP_LINK=y CONFIG_FEATURE_IP_LINK=y

View File

@ -390,6 +390,7 @@ typedef struct len_and_sockaddr {
} u; } u;
} len_and_sockaddr; } len_and_sockaddr;
enum { enum {
LSA_LEN_SIZE = offsetof(len_and_sockaddr, u),
LSA_SIZEOF_SA = sizeof( LSA_SIZEOF_SA = sizeof(
union { union {
struct sockaddr sa; struct sockaddr sa;
@ -405,7 +406,12 @@ enum {
* af == AF_UNSPEC will result in trying to create IPv6 socket, * af == AF_UNSPEC will result in trying to create IPv6 socket,
* and if kernel doesn't support it, IPv4. * and if kernel doesn't support it, IPv4.
*/ */
int xsocket_type(len_and_sockaddr **lsap, USE_FEATURE_IPV6(int af,) int sock_type); #if ENABLE_FEATURE_IPV6
int xsocket_type(len_and_sockaddr **lsap, int af, int sock_type);
#else
int xsocket_type(len_and_sockaddr **lsap, int sock_type);
#define xsocket_type(lsap, af, sock_type) xsocket_type((lsap), (sock_type))
#endif
int xsocket_stream(len_and_sockaddr **lsap); int xsocket_stream(len_and_sockaddr **lsap);
/* Create server socket bound to bindaddr:port. bindaddr can be NULL, /* Create server socket bound to bindaddr:port. bindaddr can be NULL,
* numeric IP ("N.N.N.N") or numeric IPv6 address, * numeric IP ("N.N.N.N") or numeric IPv6 address,
@ -430,14 +436,13 @@ len_and_sockaddr* host2sockaddr(const char *host, int port);
/* Version which dies on error */ /* Version which dies on error */
len_and_sockaddr* xhost2sockaddr(const char *host, int port); len_and_sockaddr* xhost2sockaddr(const char *host, int port);
len_and_sockaddr* xdotted2sockaddr(const char *host, int port); len_and_sockaddr* xdotted2sockaddr(const char *host, int port);
#if ENABLE_FEATURE_IPV6
/* Same, useful if you want to force family (e.g. IPv6) */ /* Same, useful if you want to force family (e.g. IPv6) */
#if !ENABLE_FEATURE_IPV6
#define host_and_af2sockaddr(host, port, af) host2sockaddr((host), (port))
#define xhost_and_af2sockaddr(host, port, af) xhost2sockaddr((host), (port))
#else
len_and_sockaddr* host_and_af2sockaddr(const char *host, int port, sa_family_t af); len_and_sockaddr* host_and_af2sockaddr(const char *host, int port, sa_family_t af);
len_and_sockaddr* xhost_and_af2sockaddr(const char *host, int port, sa_family_t af); len_and_sockaddr* xhost_and_af2sockaddr(const char *host, int port, sa_family_t af);
#else
/* [we evaluate af: think about "host_and_af2sockaddr(..., af++)"] */
#define host_and_af2sockaddr(host, port, af) ((void)(af), host2sockaddr((host), (port)))
#define xhost_and_af2sockaddr(host, port, af) ((void)(af), xhost2sockaddr((host), (port)))
#endif #endif
/* Assign sin[6]_port member if the socket is an AF_INET[6] one, /* Assign sin[6]_port member if the socket is an AF_INET[6] one,
* otherwise no-op. Useful for ftp. * otherwise no-op. Useful for ftp.

View File

@ -1597,7 +1597,7 @@ USE_FEATURE_BRCTL_FANCY("\n" \
" -a De/configure all interfaces automatically\n" \ " -a De/configure all interfaces automatically\n" \
" -i FILE Use FILE for interface definitions\n" \ " -i FILE Use FILE for interface definitions\n" \
" -n Print out what would happen, but don't do it\n" \ " -n Print out what would happen, but don't do it\n" \
" (note that this option doesn't disable mappings)\n" \ " (note: doesn't disable mappings)\n" \
" -v Print out what would happen before doing it\n" \ " -v Print out what would happen before doing it\n" \
" -m Don't run any mappings\n" \ " -m Don't run any mappings\n" \
" -f Force de/configuration" " -f Force de/configuration"
@ -1609,19 +1609,21 @@ USE_FEATURE_BRCTL_FANCY("\n" \
" -a De/configure all interfaces automatically\n" \ " -a De/configure all interfaces automatically\n" \
" -i FILE Use FILE for interface definitions\n" \ " -i FILE Use FILE for interface definitions\n" \
" -n Print out what would happen, but don't do it\n" \ " -n Print out what would happen, but don't do it\n" \
" (note that this option doesn't disable mappings)\n" \ " (note: doesn't disable mappings)\n" \
" -v Print out what would happen before doing it\n" \ " -v Print out what would happen before doing it\n" \
" -m Don't run any mappings\n" \ " -m Don't run any mappings\n" \
" -f Force de/configuration" " -f Force de/configuration"
#define inetd_trivial_usage \ #define inetd_trivial_usage \
"[-f] [-q len] [conf]" "[-fe] [-q N] [-R N] [CONFFILE]"
#define inetd_full_usage \ #define inetd_full_usage \
"Listen for network connections and launch programs" \ "Listen for network connections and launch programs\n" \
"\n\nOptions:\n" \ "\nOptions:" \
" -f Run in foreground\n" \ "\n -f Run in foreground" \
" -q N Set the size of the socket listen queue to N\n" \ "\n -e Log to stderr" \
" (default: 128)" "\n -q N Socket listen queue (default: 128)" \
"\n -R N Pause services after N connects/min" \
"\n (default: 0 - disabled)"
#define init_trivial_usage \ #define init_trivial_usage \
"" ""

View File

@ -2,27 +2,26 @@
/* /*
* Utility routines. * Utility routines.
* *
* create raw socket for icmp (IPv6 version) protocol test permission * create raw socket for icmp (IPv6 version) protocol
* and drop root privileges if running setuid * and drop root privileges if running setuid
*
*/ */
//#include <sys/types.h>
//#include <netdb.h>
//#include <sys/socket.h>
#include "libbb.h" #include "libbb.h"
#if ENABLE_FEATURE_IPV6 #if ENABLE_FEATURE_IPV6
int create_icmp6_socket(void) int create_icmp6_socket(void)
{ {
struct protoent *proto;
int sock; int sock;
#if 0
struct protoent *proto;
proto = getprotobyname("ipv6-icmp"); proto = getprotobyname("ipv6-icmp");
/* if getprotobyname failed, just silently force /* if getprotobyname failed, just silently force
* proto->p_proto to have the correct value for "ipv6-icmp" */ * proto->p_proto to have the correct value for "ipv6-icmp" */
sock = socket(AF_INET6, SOCK_RAW, sock = socket(AF_INET6, SOCK_RAW,
(proto ? proto->p_proto : IPPROTO_ICMPV6)); (proto ? proto->p_proto : IPPROTO_ICMPV6));
#else
sock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
#endif
if (sock < 0) { if (sock < 0) {
if (errno == EPERM) if (errno == EPERM)
bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);

View File

@ -2,26 +2,25 @@
/* /*
* Utility routines. * Utility routines.
* *
* create raw socket for icmp protocol test permission * create raw socket for icmp protocol
* and drop root privileges if running setuid * and drop root privileges if running setuid
*
*/ */
//#include <sys/types.h>
//#include <netdb.h>
//#include <sys/socket.h>
#include "libbb.h" #include "libbb.h"
int create_icmp_socket(void) int create_icmp_socket(void)
{ {
struct protoent *proto;
int sock; int sock;
#if 0
struct protoent *proto;
proto = getprotobyname("icmp"); proto = getprotobyname("icmp");
/* if getprotobyname failed, just silently force /* if getprotobyname failed, just silently force
* proto->p_proto to have the correct value for "icmp" */ * proto->p_proto to have the correct value for "icmp" */
sock = socket(AF_INET, SOCK_RAW, sock = socket(AF_INET, SOCK_RAW,
(proto ? proto->p_proto : 1)); /* 1 == ICMP */ (proto ? proto->p_proto : 1)); /* 1 == ICMP */
#else
sock = socket(AF_INET, SOCK_RAW, 1); /* 1 == ICMP */
#endif
if (sock < 0) { if (sock < 0) {
if (errno == EPERM) if (errno == EPERM)
bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);

View File

@ -132,11 +132,15 @@ USE_FEATURE_IPV6(sa_family_t af,)
/* Ugly parsing of host:addr */ /* Ugly parsing of host:addr */
if (ENABLE_FEATURE_IPV6 && host[0] == '[') { if (ENABLE_FEATURE_IPV6 && host[0] == '[') {
/* Even uglier parsing of [xx]:nn */
host++; host++;
cp = strchr(host, ']'); cp = strchr(host, ']');
if (!cp || cp[1] != ':') /* Malformed: must have [xx]:nn */ if (!cp || cp[1] != ':') { /* Malformed: must have [xx]:nn */
bb_error_msg_and_die("bad address '%s'", org_host); bb_error_msg("bad address '%s'", org_host);
//return r; /* return NULL */ if (ai_flags & DIE_ON_ERROR)
xfunc_die();
return NULL;
}
} else { } else {
cp = strrchr(host, ':'); cp = strrchr(host, ':');
if (ENABLE_FEATURE_IPV6 && cp && strchr(host, ':') != cp) { if (ENABLE_FEATURE_IPV6 && cp && strchr(host, ':') != cp) {
@ -144,13 +148,19 @@ USE_FEATURE_IPV6(sa_family_t af,)
cp = NULL; /* it's not a port spec */ cp = NULL; /* it's not a port spec */
} }
} }
if (cp) { if (cp) { /* points to ":" or "]:" */
int sz = cp - host + 1; int sz = cp - host + 1;
host = safe_strncpy(alloca(sz), host, sz); host = safe_strncpy(alloca(sz), host, sz);
if (ENABLE_FEATURE_IPV6 && *cp != ':') if (ENABLE_FEATURE_IPV6 && *cp != ':')
cp++; /* skip ']' */ cp++; /* skip ']' */
cp++; /* skip ':' */ cp++; /* skip ':' */
port = xatou16(cp); port = bb_strtou(cp, NULL, 10);
if (errno || (unsigned)port > 0xffff) {
bb_error_msg("bad port spec '%s'", org_host);
if (ai_flags & DIE_ON_ERROR)
xfunc_die();
return NULL;
}
} }
memset(&hint, 0 , sizeof(hint)); memset(&hint, 0 , sizeof(hint));
@ -221,6 +231,7 @@ len_and_sockaddr* xdotted2sockaddr(const char *host, int port)
return str2sockaddr(host, port, AF_UNSPEC, AI_NUMERICHOST | DIE_ON_ERROR); return str2sockaddr(host, port, AF_UNSPEC, AI_NUMERICHOST | DIE_ON_ERROR);
} }
#undef xsocket_type
int xsocket_type(len_and_sockaddr **lsap, USE_FEATURE_IPV6(int family,) int sock_type) int xsocket_type(len_and_sockaddr **lsap, USE_FEATURE_IPV6(int family,) int sock_type)
{ {
SKIP_FEATURE_IPV6(enum { family = AF_INET };) SKIP_FEATURE_IPV6(enum { family = AF_INET };)

File diff suppressed because it is too large Load Diff

View File

@ -756,7 +756,7 @@ int nc_main(int argc, char **argv)
/* We try IPv6, then IPv4, unless addr family is /* We try IPv6, then IPv4, unless addr family is
* implicitly set by way of remote addr/port spec */ * implicitly set by way of remote addr/port spec */
x = xsocket_type(&ouraddr, x = xsocket_type(&ouraddr,
USE_FEATURE_IPV6((themaddr ? themaddr->u.sa.sa_family : AF_UNSPEC),) (themaddr ? themaddr->u.sa.sa_family : AF_UNSPEC),
x); x);
if (o_lport) if (o_lport)
set_nport(ouraddr, htons(o_lport)); set_nport(ouraddr, htons(o_lport));

View File

@ -127,7 +127,7 @@ static int tftp( USE_GETPUT(const int cmd,)
char *cp; char *cp;
unsigned org_port; unsigned org_port;
len_and_sockaddr *const from = alloca(offsetof(len_and_sockaddr, u.sa) + peer_lsa->len); len_and_sockaddr *const from = alloca(LSA_LEN_SIZE + peer_lsa->len);
/* Can't use RESERVE_CONFIG_BUFFER here since the allocation /* Can't use RESERVE_CONFIG_BUFFER here since the allocation
* size varies meaning BUFFERS_GO_ON_STACK would fail */ * size varies meaning BUFFERS_GO_ON_STACK would fail */

View File

@ -171,8 +171,8 @@ static void limit(int what, long l)
{ {
struct rlimit r; struct rlimit r;
if (getrlimit(what, &r) == -1) /* Never fails under Linux (except if you pass it bad arguments) */
bb_perror_msg_and_die("getrlimit"); getrlimit(what, &r);
if ((l < 0) || (l > r.rlim_max)) if ((l < 0) || (l > r.rlim_max))
r.rlim_cur = r.rlim_max; r.rlim_cur = r.rlim_max;
else else