v6-ify
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@6754 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -69,25 +69,46 @@ loop(int s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
get_socket (char *host, int port)
|
get_socket (const char *hostname, int port)
|
||||||
{
|
{
|
||||||
struct sockaddr_in sa;
|
struct hostent *hostent = NULL;
|
||||||
struct hostent *hp;
|
char **h;
|
||||||
int s;
|
int error;
|
||||||
|
int af;
|
||||||
|
|
||||||
hp = roken_gethostbyname(host);
|
#ifdef HAVE_IPV6
|
||||||
if(hp == NULL)
|
if (hostent == NULL)
|
||||||
err(1, "%s", host);
|
hostent = getipnodebyname (hostname, AF_INET6, 0, &error);
|
||||||
s = socket(AF_INET, SOCK_STREAM, 0);
|
#endif
|
||||||
if (s < 0)
|
if (hostent == NULL)
|
||||||
err(1, "socket");
|
hostent = getipnodebyname (hostname, AF_INET, 0, &error);
|
||||||
memset(&sa, 0, sizeof(sa));
|
|
||||||
sa.sin_family = AF_INET;
|
if (hostent == NULL)
|
||||||
sa.sin_port = port;
|
errx(1, "gethostbyname '%s' failed: %s", hostname, hstrerror(error));
|
||||||
memcpy(&sa.sin_addr, hp->h_addr, sizeof(sa.sin_addr));
|
|
||||||
if(connect(s, (struct sockaddr*)&sa, sizeof(sa)) < 0)
|
af = hostent->h_addrtype;
|
||||||
err(1, "connect");
|
|
||||||
return s;
|
for (h = hostent->h_addr_list; *h != NULL; ++h) {
|
||||||
|
struct sockaddr_storage sa_ss;
|
||||||
|
struct sockaddr *sa = (struct sockaddr *)&sa_ss;
|
||||||
|
int s;
|
||||||
|
|
||||||
|
sa->sa_family = af;
|
||||||
|
socket_set_address_and_port (sa, *h, port);
|
||||||
|
|
||||||
|
s = socket (af, SOCK_STREAM, 0);
|
||||||
|
if (s < 0)
|
||||||
|
err (1, "socket");
|
||||||
|
if (connect (s, sa, socket_sockaddr_size(sa)) < 0) {
|
||||||
|
warn ("connect(%s)", hostname);
|
||||||
|
close (s);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
freehostent (hostent);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
freehostent (hostent);
|
||||||
|
exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef KRB4
|
#ifdef KRB4
|
||||||
|
@@ -23,7 +23,7 @@ pop_net_read(POP *p, int fd, void *buf, size_t len)
|
|||||||
|
|
||||||
#ifdef KRB4
|
#ifdef KRB4
|
||||||
static int
|
static int
|
||||||
krb4_authenticate (POP *p, int s, u_char *buf, struct sockaddr_in *addr)
|
krb4_authenticate (POP *p, int s, u_char *buf, struct sockaddr *addr)
|
||||||
{
|
{
|
||||||
Key_schedule schedule;
|
Key_schedule schedule;
|
||||||
KTEXT_ST ticket;
|
KTEXT_ST ticket;
|
||||||
@@ -45,7 +45,7 @@ krb4_authenticate (POP *p, int s, u_char *buf, struct sockaddr_in *addr)
|
|||||||
&ticket,
|
&ticket,
|
||||||
"pop",
|
"pop",
|
||||||
instance,
|
instance,
|
||||||
addr,
|
(struct sockaddr_in *)addr,
|
||||||
(struct sockaddr_in *) NULL,
|
(struct sockaddr_in *) NULL,
|
||||||
&p->kdata,
|
&p->kdata,
|
||||||
"",
|
"",
|
||||||
@@ -63,7 +63,7 @@ krb4_authenticate (POP *p, int s, u_char *buf, struct sockaddr_in *addr)
|
|||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
pop_log(p, POP_DEBUG, "%s.%s@%s (%s): ok", p->kdata.pname,
|
pop_log(p, POP_DEBUG, "%s.%s@%s (%s): ok", p->kdata.pname,
|
||||||
p->kdata.pinst, p->kdata.prealm, inet_ntoa(addr->sin_addr));
|
p->kdata.pinst, p->kdata.prealm, p->ipaddr);
|
||||||
#endif /* DEBUG */
|
#endif /* DEBUG */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -71,7 +71,7 @@ krb4_authenticate (POP *p, int s, u_char *buf, struct sockaddr_in *addr)
|
|||||||
|
|
||||||
#ifdef KRB5
|
#ifdef KRB5
|
||||||
static int
|
static int
|
||||||
krb5_authenticate (POP *p, int s, u_char *buf, struct sockaddr_in *addr)
|
krb5_authenticate (POP *p, int s, u_char *buf, struct sockaddr *addr)
|
||||||
{
|
{
|
||||||
krb5_error_code ret;
|
krb5_error_code ret;
|
||||||
krb5_auth_context auth_context = NULL;
|
krb5_auth_context auth_context = NULL;
|
||||||
@@ -121,7 +121,7 @@ krb5_authenticate (POP *p, int s, u_char *buf, struct sockaddr_in *addr)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int
|
static int
|
||||||
krb_authenticate(POP *p, struct sockaddr_in *addr)
|
krb_authenticate(POP *p, struct sockaddr *addr)
|
||||||
{
|
{
|
||||||
#if defined(KRB4) || defined(KRB5)
|
#if defined(KRB4) || defined(KRB5)
|
||||||
u_char buf[BUFSIZ];
|
u_char buf[BUFSIZ];
|
||||||
@@ -151,7 +151,7 @@ krb_authenticate(POP *p, struct sockaddr_in *addr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
plain_authenticate (POP *p, struct sockaddr_in *addr)
|
plain_authenticate (POP *p, struct sockaddr *addr)
|
||||||
{
|
{
|
||||||
return(POP_SUCCESS);
|
return(POP_SUCCESS);
|
||||||
}
|
}
|
||||||
@@ -202,13 +202,14 @@ pop_getportbyname(POP *p, const char *service,
|
|||||||
int
|
int
|
||||||
pop_init(POP *p,int argcount,char **argmessage)
|
pop_init(POP *p,int argcount,char **argmessage)
|
||||||
{
|
{
|
||||||
|
struct sockaddr_storage cs_ss;
|
||||||
struct sockaddr_in cs; /* Communication parameters */
|
struct sockaddr *cs = (struct sockaddr *)&cs_ss;
|
||||||
struct hostent * ch; /* Client host information */
|
struct hostent * ch; /* Client host information */
|
||||||
int len;
|
int len;
|
||||||
char * trace_file_name = "/tmp/popper-trace";
|
char * trace_file_name = "/tmp/popper-trace";
|
||||||
int portnum = 0;
|
int portnum = 0;
|
||||||
int optind = 0;
|
int optind = 0;
|
||||||
|
int error;
|
||||||
|
|
||||||
/* Initialize the POP parameter block */
|
/* Initialize the POP parameter block */
|
||||||
memset (p, 0, sizeof(POP));
|
memset (p, 0, sizeof(POP));
|
||||||
@@ -295,8 +296,8 @@ pop_init(POP *p,int argcount,char **argmessage)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Get the address and socket of the client to whom I am speaking */
|
/* Get the address and socket of the client to whom I am speaking */
|
||||||
len = sizeof(cs);
|
len = sizeof(cs_ss);
|
||||||
if (getpeername(STDIN_FILENO, (struct sockaddr *)&cs, &len) < 0){
|
if (getpeername(STDIN_FILENO, cs, &len) < 0) {
|
||||||
pop_log(p,POP_PRIORITY,
|
pop_log(p,POP_PRIORITY,
|
||||||
"Unable to obtain socket and address of client, err = %d",errno);
|
"Unable to obtain socket and address of client, err = %d",errno);
|
||||||
exit (1);
|
exit (1);
|
||||||
@@ -304,18 +305,20 @@ pop_init(POP *p,int argcount,char **argmessage)
|
|||||||
|
|
||||||
/* Save the dotted decimal form of the client's IP address
|
/* Save the dotted decimal form of the client's IP address
|
||||||
in the POP parameter block */
|
in the POP parameter block */
|
||||||
strcpy_truncate (p->ipaddr, inet_ntoa(cs.sin_addr), sizeof(p->ipaddr));
|
inet_ntop (cs->sa_family, socket_get_address (cs),
|
||||||
|
p->ipaddr, sizeof(p->ipaddr));
|
||||||
|
|
||||||
/* Save the client's port */
|
/* Save the client's port */
|
||||||
p->ipport = ntohs(cs.sin_port);
|
p->ipport = ntohs(socket_get_port (cs));
|
||||||
|
|
||||||
/* Get the canonical name of the host to whom I am speaking */
|
/* Get the canonical name of the host to whom I am speaking */
|
||||||
ch = roken_gethostbyaddr((const char *)&cs.sin_addr,
|
ch = getipnodebyaddr (socket_get_address (cs),
|
||||||
sizeof(cs.sin_addr),
|
socket_addr_size (cs),
|
||||||
AF_INET);
|
cs->sa_family,
|
||||||
|
&error);
|
||||||
if (ch == NULL){
|
if (ch == NULL){
|
||||||
pop_log(p,POP_PRIORITY,
|
pop_log(p,POP_PRIORITY,
|
||||||
"Unable to get canonical name of client, err = %d",errno);
|
"Unable to get canonical name of client, err = %d",error);
|
||||||
strcpy_truncate (p->client, p->ipaddr, sizeof(p->client));
|
strcpy_truncate (p->client, p->ipaddr, sizeof(p->client));
|
||||||
}
|
}
|
||||||
/* Save the cannonical name of the client host in
|
/* Save the cannonical name of the client host in
|
||||||
@@ -327,7 +330,12 @@ pop_init(POP *p,int argcount,char **argmessage)
|
|||||||
|
|
||||||
/* See if the name obtained for the client's IP
|
/* See if the name obtained for the client's IP
|
||||||
address returns an address */
|
address returns an address */
|
||||||
if ((ch_again = roken_gethostbyname(ch->h_name)) == NULL) {
|
ch_again = getipnodebyname (ch->h_name,
|
||||||
|
cs->sa_family,
|
||||||
|
0,
|
||||||
|
&error);
|
||||||
|
|
||||||
|
if (ch_again == NULL) {
|
||||||
pop_log(p,POP_PRIORITY,
|
pop_log(p,POP_PRIORITY,
|
||||||
"Client at \"%s\" resolves to an unknown host name \"%s\"",
|
"Client at \"%s\" resolves to an unknown host name \"%s\"",
|
||||||
p->ipaddr,ch->h_name);
|
p->ipaddr,ch->h_name);
|
||||||
@@ -336,14 +344,15 @@ pop_init(POP *p,int argcount,char **argmessage)
|
|||||||
else {
|
else {
|
||||||
/* Save the host name (the previous value was
|
/* Save the host name (the previous value was
|
||||||
destroyed by gethostbyname) */
|
destroyed by gethostbyname) */
|
||||||
strcpy_truncate (p->client, ch_again->h_name, sizeof(p->client));
|
strcpy_truncate (p->client, ch->h_name, sizeof(p->client));
|
||||||
|
|
||||||
/* Look for the client's IP address in the list returned
|
/* Look for the client's IP address in the list returned
|
||||||
for its name */
|
for its name */
|
||||||
for (addrp=ch_again->h_addr_list; *addrp; ++addrp)
|
for (addrp=ch_again->h_addr_list; *addrp; ++addrp)
|
||||||
if (memcmp(*addrp, &cs.sin_addr, sizeof(cs.sin_addr))
|
if (memcmp(*addrp,
|
||||||
== 0)
|
socket_get_address (cs),
|
||||||
break;
|
socket_addr_size (cs)) == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
if (!*addrp) {
|
if (!*addrp) {
|
||||||
pop_log (p,POP_PRIORITY,
|
pop_log (p,POP_PRIORITY,
|
||||||
@@ -352,7 +361,9 @@ pop_init(POP *p,int argcount,char **argmessage)
|
|||||||
strcpy_truncate (p->client, p->ipaddr, sizeof(p->client));
|
strcpy_truncate (p->client, p->ipaddr, sizeof(p->client));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
freehostent (ch_again);
|
||||||
}
|
}
|
||||||
|
freehostent (ch);
|
||||||
|
|
||||||
/* Create input file stream for TCP/IP communication */
|
/* Create input file stream for TCP/IP communication */
|
||||||
if ((p->input = fdopen(STDIN_FILENO,"r")) == NULL){
|
if ((p->input = fdopen(STDIN_FILENO,"r")) == NULL){
|
||||||
@@ -382,5 +393,5 @@ pop_init(POP *p,int argcount,char **argmessage)
|
|||||||
#endif /* DEBUG */
|
#endif /* DEBUG */
|
||||||
|
|
||||||
|
|
||||||
return((p->kerberosp ? krb_authenticate : plain_authenticate)(p, &cs));
|
return((p->kerberosp ? krb_authenticate : plain_authenticate)(p, cs));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user