(init_sockets): pay attention to explicit_addresses
some more comments. better error messages. git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@7906 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1997-1999 Kungliga Tekniska H<>gskolan
|
* Copyright (c) 1997-2000 Kungliga Tekniska H<>gskolan
|
||||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
@@ -35,15 +35,25 @@
|
|||||||
|
|
||||||
RCSID("$Id$");
|
RCSID("$Id$");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* a tuple describing on what to listen
|
||||||
|
*/
|
||||||
|
|
||||||
struct port_desc{
|
struct port_desc{
|
||||||
int family;
|
int family;
|
||||||
int type;
|
int type;
|
||||||
int port;
|
int port;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* the current ones */
|
||||||
|
|
||||||
static struct port_desc *ports;
|
static struct port_desc *ports;
|
||||||
static int num_ports;
|
static int num_ports;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* add `family, port, protocol' to the list with duplicate suppresion.
|
||||||
|
*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
add_port(int family, int port, const char *protocol)
|
add_port(int family, int port, const char *protocol)
|
||||||
{
|
{
|
||||||
@@ -63,12 +73,19 @@ add_port(int family, int port, const char *protocol)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ports = realloc(ports, (num_ports + 1) * sizeof(*ports));
|
ports = realloc(ports, (num_ports + 1) * sizeof(*ports));
|
||||||
|
if (ports == NULL)
|
||||||
|
krb5_err (context, 1, errno, "realloc");
|
||||||
ports[num_ports].family = family;
|
ports[num_ports].family = family;
|
||||||
ports[num_ports].type = type;
|
ports[num_ports].type = type;
|
||||||
ports[num_ports].port = port;
|
ports[num_ports].port = port;
|
||||||
num_ports++;
|
num_ports++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* add a triple but with service -> port lookup
|
||||||
|
* (this prints warnings for stuff that does not exist)
|
||||||
|
*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
add_port_service(int family, const char *service, int port,
|
add_port_service(int family, const char *service, int port,
|
||||||
const char *protocol)
|
const char *protocol)
|
||||||
@@ -77,6 +94,11 @@ add_port_service(int family, const char *service, int port,
|
|||||||
add_port (family, port, protocol);
|
add_port (family, port, protocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* add the port with service -> port lookup or string -> number
|
||||||
|
* (no warning is printed)
|
||||||
|
*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
add_port_string (int family, const char *port_str, const char *protocol)
|
add_port_string (int family, const char *port_str, const char *protocol)
|
||||||
{
|
{
|
||||||
@@ -96,6 +118,10 @@ add_port_string (int family, const char *port_str, const char *protocol)
|
|||||||
add_port (family, port, protocol);
|
add_port (family, port, protocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* add the standard collection of ports for `family'
|
||||||
|
*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
add_standard_ports (int family)
|
add_standard_ports (int family)
|
||||||
{
|
{
|
||||||
@@ -113,6 +139,12 @@ add_standard_ports (int family)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* parse the set of space-delimited ports in `str' and add them.
|
||||||
|
* "+" => all the standard ones
|
||||||
|
* otherwise it's port|service[/protocol]
|
||||||
|
*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
parse_ports(const char *str)
|
parse_ports(const char *str)
|
||||||
{
|
{
|
||||||
@@ -150,6 +182,10 @@ parse_ports(const char *str)
|
|||||||
free (str_copy);
|
free (str_copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* every socket we listen on
|
||||||
|
*/
|
||||||
|
|
||||||
struct descr {
|
struct descr {
|
||||||
int s;
|
int s;
|
||||||
int type;
|
int type;
|
||||||
@@ -176,7 +212,7 @@ init_socket(struct descr *d, krb5_address *a, int family, int type, int port)
|
|||||||
|
|
||||||
ret = krb5_addr2sockaddr (a, sa, &sa_size, port);
|
ret = krb5_addr2sockaddr (a, sa, &sa_size, port);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
krb5_warn(context, ret, "krb5_anyaddr");
|
krb5_warn(context, ret, "krb5_addr2sockaddr");
|
||||||
close(d->s);
|
close(d->s);
|
||||||
d->s = -1;
|
d->s = -1;
|
||||||
return;
|
return;
|
||||||
@@ -200,14 +236,23 @@ init_socket(struct descr *d, krb5_address *a, int family, int type, int port)
|
|||||||
d->type = type;
|
d->type = type;
|
||||||
|
|
||||||
if(bind(d->s, sa, sa_size) < 0){
|
if(bind(d->s, sa, sa_size) < 0){
|
||||||
krb5_warn(context, errno, "bind(%d)", ntohs(port));
|
char a_str[256];
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
krb5_print_address (a, a_str, sizeof(a_str), &len);
|
||||||
|
krb5_warn(context, errno, "bind %s/%d", a_str, ntohs(port));
|
||||||
close(d->s);
|
close(d->s);
|
||||||
d->s = -1;
|
d->s = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(type == SOCK_STREAM && listen(d->s, SOMAXCONN) < 0){
|
if(type == SOCK_STREAM && listen(d->s, SOMAXCONN) < 0){
|
||||||
krb5_warn(context, errno, "listen");
|
char a_str[256];
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
krb5_print_address (a, a_str, sizeof(a_str), &len);
|
||||||
|
krb5_warn(context, errno, "listen %s/%d", a_str, ntohs(port));
|
||||||
close(d->s);
|
close(d->s);
|
||||||
|
d->s = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -226,9 +271,13 @@ init_sockets(struct descr **desc)
|
|||||||
int num = 0;
|
int num = 0;
|
||||||
krb5_addresses addresses;
|
krb5_addresses addresses;
|
||||||
|
|
||||||
ret = krb5_get_all_server_addrs (context, &addresses);
|
if (explicit_addresses.len) {
|
||||||
if (ret)
|
addresses = explicit_addresses;
|
||||||
krb5_err (context, 1, ret, "krb5_get_all_server_addrs");
|
} else {
|
||||||
|
ret = krb5_get_all_server_addrs (context, &addresses);
|
||||||
|
if (ret)
|
||||||
|
krb5_err (context, 1, ret, "krb5_get_all_server_addrs");
|
||||||
|
}
|
||||||
parse_ports(port_str);
|
parse_ports(port_str);
|
||||||
d = malloc(addresses.len * num_ports * sizeof(*d));
|
d = malloc(addresses.len * num_ports * sizeof(*d));
|
||||||
if (d == NULL)
|
if (d == NULL)
|
||||||
@@ -262,7 +311,11 @@ init_sockets(struct descr **desc)
|
|||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* handle the request in `buf, len', from `addr' (or `from' as a string),
|
||||||
|
* sending a reply in `reply'.
|
||||||
|
*/
|
||||||
|
|
||||||
static int
|
static int
|
||||||
process_request(unsigned char *buf,
|
process_request(unsigned char *buf,
|
||||||
size_t len,
|
size_t len,
|
||||||
@@ -711,7 +764,8 @@ loop(void)
|
|||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
case -1:
|
case -1:
|
||||||
krb5_warn(context, errno, "select");
|
if (errno != EINTR)
|
||||||
|
krb5_warn(context, errno, "select");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
for(i = 0; i < ndescr; i++)
|
for(i = 0; i < ndescr; i++)
|
||||||
|
Reference in New Issue
Block a user