diff options
Diffstat (limited to 'rfc1035')
| -rw-r--r-- | rfc1035/Makefile.am | 8 | ||||
| -rw-r--r-- | rfc1035/configure.ac | 14 | ||||
| -rw-r--r-- | rfc1035/rfc1035dump.c | 8 | ||||
| -rw-r--r-- | rfc1035/rfc1035reply.c | 22 | ||||
| -rw-r--r-- | rfc1035/rfc1035resolve.c | 99 | 
5 files changed, 115 insertions, 36 deletions
| diff --git a/rfc1035/Makefile.am b/rfc1035/Makefile.am index 759ac78..ee18cbe 100644 --- a/rfc1035/Makefile.am +++ b/rfc1035/Makefile.am @@ -1,9 +1,10 @@  # -# Copyright 1998 - 2011 Double Precision, Inc.  See COPYING for +# Copyright 1998 - 2018 Double Precision, Inc.  See COPYING for  # distribution information.  noinst_LIBRARIES=librfc1035.a +AM_CFLAGS=@LIBIDN_CFLAGS@  librfc1035_a_SOURCES= \  		rfc1035.c rfc1035.h rfc1035an.c \ @@ -16,7 +17,6 @@ librfc1035_a_SOURCES= \  		rfc1035str.c rfc1035tcp.c rfc1035udp.c rfc1035bindsource.c \  \  		spf.c spf.h -  noinst_PROGRAMS=testlookup testspf  testlookup_SOURCES=testlookup.c @@ -24,7 +24,7 @@ testlookup_DEPENDENCIES=librfc1035.a ../rfc822/libencode.la ../md5/libmd5.la \  	../random128/librandom128.la ../soxwrap/libsoxwrap.a \  	../soxwrap/soxlibs.dep  testlookup_LDADD=librfc1035.a ../rfc822/libencode.la ../soxwrap/libsoxwrap.a ../md5/libmd5.la \ -	../random128/librandom128.la `cat ../soxwrap/soxlibs.dep` +	../random128/librandom128.la `cat ../soxwrap/soxlibs.dep` @LIBIDN_LIBS@  testlookup_LDFLAGS=-static  EXTRA_DIST=testsuite.txt @@ -35,7 +35,7 @@ testspf_DEPENDENCIES=librfc1035.a ../rfc822/libencode.la ../md5/libmd5.la \  	../soxwrap/soxlibs.dep  testspf_LDADD=librfc1035.a ../rfc822/libencode.la ../md5/libmd5.la \  	../random128/librandom128.la ../soxwrap/libsoxwrap.a \ -	`cat ../soxwrap/soxlibs.dep` +	`cat ../soxwrap/soxlibs.dep` @LIBIDN_LIBS@  testspf_LDFLAGS=-static  mycheck: diff --git a/rfc1035/configure.ac b/rfc1035/configure.ac index f4243f9..efae100 100644 --- a/rfc1035/configure.ac +++ b/rfc1035/configure.ac @@ -23,6 +23,12 @@ AC_PROG_LIBTOOL  dnl Checks for libraries. +PKG_CHECK_MODULES(LIBIDN, libidn >= 0.0.0, [libidn=yes], [libidn=no]) + +if test "$libidn" = "no" +then +	AC_MSG_ERROR(libidn not found) +fi  dnl Checks for header files.  AC_HEADER_STDC  AC_CHECK_HEADERS(sys/types.h sys/time.h unistd.h arpa/inet.h netinet/in.h) @@ -174,12 +180,12 @@ UINT16="$int16"  AC_CACHE_CHECK([for socklen_t],  	courier_cv_hassocklen_t, -  +  AC_COMPILE_IFELSE([  AC_LANG_SOURCE( [  #include <sys/types.h>  #include <sys/socket.h> -  +  socklen_t sl_t;  ],[  	accept(0, 0, &sl_t); @@ -187,9 +193,9 @@ socklen_t sl_t;  	courier_cv_hassocklen_t=yes,  	courier_cv_hassocklen_t=no)  ) -  +  socklen_t="int" -  +  if test $courier_cv_hassocklen_t = yes  then  	: diff --git a/rfc1035/rfc1035dump.c b/rfc1035/rfc1035dump.c index 6b62a5e..0ee8639 100644 --- a/rfc1035/rfc1035dump.c +++ b/rfc1035/rfc1035dump.c @@ -1,5 +1,5 @@  /* -** Copyright 1998 - 2000 Double Precision, Inc. +** Copyright 1998 - 2018 Double Precision, Inc.  ** See COPYING for distribution information.  */ @@ -12,7 +12,7 @@ static void print_hostname(FILE *f, const char *p)  {  	for ( ; *p; p++)  	{ -		if (*p < ' ' || *p >= 127) +		if ((unsigned char)*p < ' ')  		{  			fprintf(f, "\\%03o", (int)(unsigned char)*p);  			continue; @@ -48,10 +48,10 @@ struct	rfc1035_reply *qr;  	fprintf(f, " (server %s)", ipbuf); -	fprintf(f, ":\n;;  Bytes: %ld\n",  +	fprintf(f, ":\n;;  Bytes: %ld\n",  		(long)r->replylen); -	fprintf(f, ";;  Opcode: %s\n",  +	fprintf(f, ";;  Opcode: %s\n",  		rfc1035_opcode_itostr(r->opcode));  	fprintf(f, ";;  Flags:");  	if (r->qr) diff --git a/rfc1035/rfc1035reply.c b/rfc1035/rfc1035reply.c index 98c3766..ac1e87e 100644 --- a/rfc1035/rfc1035reply.c +++ b/rfc1035/rfc1035reply.c @@ -1,5 +1,5 @@  /* -** Copyright 1998 - 1999 Double Precision, Inc. +** Copyright 1998 - 2018 Double Precision, Inc.  ** See COPYING for distribution information.  */ @@ -7,7 +7,7 @@  #include	<stdlib.h>  #include	<string.h>  #include	<errno.h> - +#include	<idna.h>  void rfc1035_replyfree(struct rfc1035_reply *p)  { @@ -71,7 +71,23 @@ int	cnt=0;  		*ptr += l;  	} -	if (namebuf)	namebuf[i]=0; +	if (namebuf) +	{ +		char *p; + +		namebuf[i]=0; + +		if (idna_to_unicode_8z8z(namebuf, &p, 0) != IDNA_SUCCESS) +			return (0); + +		if (strlen(p) >= RFC1035_MAXNAMESIZE) +		{ +			free(p); +			return (0); +		} +		strcpy(namebuf, p); +		free(p); +	}  	return (namebuf ? namebuf:"");  } diff --git a/rfc1035/rfc1035resolve.c b/rfc1035/rfc1035resolve.c index d772eb0..b8bb91f 100644 --- a/rfc1035/rfc1035resolve.c +++ b/rfc1035/rfc1035resolve.c @@ -1,5 +1,5 @@  /* -** Copyright 1998 - 2000 Double Precision, Inc. +** Copyright 1998 - 2018 Double Precision, Inc.  ** See COPYING for distribution information.  */ @@ -13,7 +13,7 @@  #endif  #include	<stdlib.h>  #include	<string.h> - +#include	<idna.h>  struct querybuf {  	char qbuf[512]; @@ -30,25 +30,82 @@ struct querybuf *qp=(struct querybuf *)q;  	qp->qbuflen += l;  } -struct rfc1035_reply *rfc1035_resolve_multiple( -			struct rfc1035_res *res, -			int opcode, -			const struct rfc1035_query *queries, -			unsigned nqueries) + +static struct rfc1035_reply +*rfc1035_resolve_multiple_idna(struct rfc1035_res *res, +			       int opcode, +			       const struct rfc1035_query *queries, +			       unsigned nqueries); + +struct rfc1035_reply +*rfc1035_resolve_multiple(struct rfc1035_res *res, +			  int opcode, +			  const struct rfc1035_query *queries, +			  unsigned nqueries)  { -struct	querybuf qbuf; -int	udpfd; -int	attempt; -const RFC1035_ADDR *ns; -unsigned nscount; -unsigned current_timeout, timeout_backoff; -unsigned nbackoff, backoff_num; -int	af; -static const char fakereply[]={0, 0, 0, RFC1035_RCODE_SERVFAIL, -		0, 0, -		0, 0, -		0, 0, -		0, 0}; +	struct rfc1035_query *idna_queries= +		(struct rfc1035_query *)malloc(nqueries * sizeof(*queries)); +	struct rfc1035_reply *r; +	unsigned n; +	char **buffers; + +	/* +	** Translate each label from UTF8 to IDNA. +	*/ + +	if (!idna_queries) +		return NULL; +	if ((buffers=(char **)malloc(nqueries * sizeof(char *))) == NULL) +	{ +		free(idna_queries); +		return NULL; +	} +	for (n=0; n<nqueries; ++n) +	{ +		idna_queries[n]=queries[n]; +		if (idna_to_ascii_8z(idna_queries[n].name, &buffers[n], 0) +		    != IDNA_SUCCESS) +		{ +			errno=EINVAL; +			while (n) +			{ +				free(buffers[--n]); +			} +			free(idna_queries); +			free(buffers[n]); +			return NULL; +		} + +		idna_queries[n].name=buffers[n]; +	} + +	r=rfc1035_resolve_multiple_idna(res, opcode, idna_queries, nqueries); +	for (n=0; n<nqueries; ++n) +		free(buffers[n]); +	free(idna_queries); +	free(buffers); +	return r; +} + +static struct rfc1035_reply +*rfc1035_resolve_multiple_idna(struct rfc1035_res *res, +			       int opcode, +			       const struct rfc1035_query *queries, +			       unsigned nqueries) +{ +	struct	querybuf qbuf; +	int	udpfd; +	int	attempt; +	const RFC1035_ADDR *ns; +	unsigned nscount; +	unsigned current_timeout, timeout_backoff; +	unsigned nbackoff, backoff_num; +	int	af; +	static const char fakereply[]={0, 0, 0, RFC1035_RCODE_SERVFAIL, +				       0, 0, +				       0, 0, +				       0, 0, +				       0, 0};  	nscount=res->rfc1035_nnameservers;  	ns=res->nameservers; @@ -184,7 +241,7 @@ static const char fakereply[]={0, 0, 0, RFC1035_RCODE_SERVFAIL,  				if ((reply=rfc1035_recv_tcp(res,  					tcpfd, &nbytes, current_timeout))==0)  					break; -				 +  				rfcreply=rfc1035_replyparse(reply, nbytes);  				if (!rfcreply)  				{ | 
