pkg

Check-in [876c8a2b4a]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Support libldns. We want to avoid hardcoded dependencies on FreeBSD. DNS functions should have some alternative to FreeBSD specific resolver.
Timelines: family | ancestors | descendants | both | trunk | gsoc2013
Files: files | file ages | folders
SHA1: 876c8a2b4a3b458a498e07452bb6138be468b2cb
User & Date: vsevolod@highsecure.ru 2014-05-30 22:04:05
Context
2014-05-31
14:52
Some more steps to portability. check-in: 7252603191 user: vsevolod@highsecure.ru tags: trunk, gsoc2013
2014-05-30
22:04
Support libldns. We want to avoid hardcoded dependencies on FreeBSD. DNS functions should have some alternative to FreeBSD specific resolver. check-in: 876c8a2b4a user: vsevolod@highsecure.ru tags: trunk, gsoc2013
11:44
Prepare != run. check-in: 1d39bc7cc4 user: vsevolod@highsecure.ru tags: trunk, gsoc2013
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to configure.ac.

188
189
190
191
192
193
194






195
196
197
198
199
200
201
AC_CHECK_HEADER([execinfo.h], [
	AC_DEFINE(HAVE_EXECINFO_H, 1, [Define to 1 if you have the <execinfo.h> header file.])
	AC_CHECK_LIB(execinfo, backtrace, [
		AC_DEFINE(HAVE_LIBEXECINFO, 1, [Define to 1 if you have the 'execinfo' library (-lexecinfo).])
		LIBEXECINFO_LIB="-lexecinfo"
	])
],)







AC_CHECK_HEADER([atf-c.h], [
	 TESTS="\$(test_program)"
 ])

AC_CHECK_HEADER([sys/capability.h], [
        AC_CHECK_LIB(c, cap_sandboxed, [







>
>
>
>
>
>







188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
AC_CHECK_HEADER([execinfo.h], [
	AC_DEFINE(HAVE_EXECINFO_H, 1, [Define to 1 if you have the <execinfo.h> header file.])
	AC_CHECK_LIB(execinfo, backtrace, [
		AC_DEFINE(HAVE_LIBEXECINFO, 1, [Define to 1 if you have the 'execinfo' library (-lexecinfo).])
		LIBEXECINFO_LIB="-lexecinfo"
	])
],)

AC_ARG_WITH([ldns], AS_HELP_STRING([--with-ldns], [Build with ldns for name resolving]))

AS_IF([test "x$with_ldns" = "xyes"], [
   PKG_CHECK_MODULES([LDNS], [libldns], [AC_DEFINE([HAVE_LDNS], [1], [Use ldns])])
])

AC_CHECK_HEADER([atf-c.h], [
	 TESTS="\$(test_program)"
 ])

AC_CHECK_HEADER([sys/capability.h], [
        AC_CHECK_LIB(c, cap_sandboxed, [

Changes to libpkg/Makefile.am.

1
2
3

4
5
6
7
8
9
10
..
50
51
52
53
54
55
56

57
58
59
60
61
62
63
pkg_common_cflags=	-I$(top_srcdir)/libpkg \
			@LIBELF_INCLUDE@ \
			@LIBSBUF_INCLUDE@ \

			-I$(top_srcdir)/external/expat/lib \
			-I$(top_srcdir)/external/libucl/include \
			-I$(top_srcdir)/external/uthash \
			-I$(top_srcdir)/external/sqlite \
			-I$(top_srcdir)/external/libyaml/include \
			-DPREFIX=\"$(prefix)\" \
			-Wno-pointer-sign
................................................................................
libpkg_la_LIBADD=	$(top_builddir)/external/libucl.la \
			$(top_builddir)/external/libsqlite.la \
			$(top_builddir)/external/libyaml.la \
			$(top_builddir)/external/libexpat.la \
			@LIBELF_LIB@ \
			@LIBSBUF_LIB@ \
			@LIBEXECINFO_LIB@ \

			-larchive \
			-lfetch \
			-lutil \
			-lcrypto \
			-lm

libpkg_la_LDFLAGS=	-version-info @LIBPKG_SO_VERSION@ -pthread



>







 







>







1
2
3
4
5
6
7
8
9
10
11
..
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
pkg_common_cflags=	-I$(top_srcdir)/libpkg \
			@LIBELF_INCLUDE@ \
			@LIBSBUF_INCLUDE@ \
			@LDNS_CFLAGS@ \
			-I$(top_srcdir)/external/expat/lib \
			-I$(top_srcdir)/external/libucl/include \
			-I$(top_srcdir)/external/uthash \
			-I$(top_srcdir)/external/sqlite \
			-I$(top_srcdir)/external/libyaml/include \
			-DPREFIX=\"$(prefix)\" \
			-Wno-pointer-sign
................................................................................
libpkg_la_LIBADD=	$(top_builddir)/external/libucl.la \
			$(top_builddir)/external/libsqlite.la \
			$(top_builddir)/external/libyaml.la \
			$(top_builddir)/external/libexpat.la \
			@LIBELF_LIB@ \
			@LIBSBUF_LIB@ \
			@LIBEXECINFO_LIB@ \
			@LDNS_LIBS@ \
			-larchive \
			-lfetch \
			-lutil \
			-lcrypto \
			-lm

libpkg_la_LDFLAGS=	-version-info @LIBPKG_SO_VERSION@ -pthread

Changes to libpkg/dns_utils.c.

1
2

3
4
5
6
7
8
9
..
19
20
21
22
23
24
25


26
27
28
29
30
31
32



33

34
35
36
37

38
39
40
41

42
43
44
45
46
47
48
..
95
96
97
98
99
100
101

102
103
104
105
106
107
108
...
254
255
256
257
258
259
260










































































/*-
 * Copyright (c) 2012-2013 Baptiste Daroussin <bapt@FreeBSD.org>

 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer,
................................................................................
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */



#include <sys/stat.h> /* for private.utils.h */

#include <stdbool.h> /* for private/utils.h */
#include <stdlib.h>
#include <string.h>
#include <netinet/in.h>



#include <resolv.h>

#include <netdb.h>

#include "private/utils.h"


typedef union {
	HEADER hdr;
	unsigned char buf[1024];
} query_t;


static int
srv_priority_cmp(const void *a, const void *b)
{
	const struct dns_srvinfo *da, *db;
	
	da = *(struct dns_srvinfo * const *)a;
................................................................................
			}
		}
	}

	free(chosen);
}


struct dns_srvinfo *
dns_getsrvinfo(const char *zone)
{
	char host[MAXHOSTNAMELEN];
	query_t q;
	int len, qdcount, ancount, n, i;
	struct dns_srvinfo **res, *first;
................................................................................
	if (nscount == 0)
		return (-1);

	_res = res;

	return (0);
}












































































>







 







>
>







>
>
>

>




>




>







 







>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
..
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
...
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
...
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
/*-
 * Copyright (c) 2012-2013 Baptiste Daroussin <bapt@FreeBSD.org>
 * Copyright (c) 2014 Vsevolod Stakhov <vsevolod@FreeBSD.org>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer,
................................................................................
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <pkg_config.h>

#include <sys/stat.h> /* for private.utils.h */

#include <stdbool.h> /* for private/utils.h */
#include <stdlib.h>
#include <string.h>
#include <netinet/in.h>
#ifdef HAVE_LDNS
#include <ldns/ldns.h>
#else
#include <resolv.h>
#endif
#include <netdb.h>

#include "private/utils.h"

#ifndef HAVE_LDNS
typedef union {
	HEADER hdr;
	unsigned char buf[1024];
} query_t;
#endif

static int
srv_priority_cmp(const void *a, const void *b)
{
	const struct dns_srvinfo *da, *db;
	
	da = *(struct dns_srvinfo * const *)a;
................................................................................
			}
		}
	}

	free(chosen);
}

#ifndef HAVE_LDNS
struct dns_srvinfo *
dns_getsrvinfo(const char *zone)
{
	char host[MAXHOSTNAMELEN];
	query_t q;
	int len, qdcount, ancount, n, i;
	struct dns_srvinfo **res, *first;
................................................................................
	if (nscount == 0)
		return (-1);

	_res = res;

	return (0);
}
#else

static ldns_resolver *lres = NULL;

struct dns_srvinfo *
dns_getsrvinfo(const char *zone)
{
	ldns_rdf *domain;
	ldns_pkt *p;
	ldns_rr_list *srv;
	struct dns_srvinfo *res;
	int ancount, i;

	if (lres == NULL)
		if (ldns_resolver_new_frm_file(&lres, NULL) != LDNS_STATUS_OK)
			return (NULL);

	domain = ldns_dname_new_frm_str(zone);
	if (domain == NULL)
		return (NULL);

	p = ldns_resolver_query(lres, domain,
	    LDNS_RR_TYPE_SRV,
	    LDNS_RR_CLASS_IN,
	    LDNS_RD);

	ldns_rdf_deep_free(domain);

	if (p == NULL)
		return (NULL);

	srv = ldns_pkt_rr_list_by_type(p, LDNS_RR_TYPE_SRV, LDNS_SECTION_ANSWER);
	ldns_pkt_free(p);

	if (srv == NULL)
		return (NULL);

	ancount = ldns_rr_list_rr_count(srv);
	res = calloc(ancount, sizeof(struct dns_srvinfo));
	if (res == NULL)
		return (NULL);

	for (i = 0; i < ancount; i ++) {
		ldns_rr *rr;

		rr = ldns_rr_list_rr(srv, i);
		if (rr != NULL) {
			char *host;
			res[i].class = ldns_rr_get_class(rr);
			res[i].ttl = ldns_rr_ttl(rr);
			res[i].priority = ldns_rdf2native_int16(ldns_rr_rdf(rr, 0));
			res[i].weight = ldns_rdf2native_int16(ldns_rr_rdf(rr, 1));
			res[i].port = ldns_rdf2native_int16(ldns_rr_rdf(rr, 2));
			host = ldns_rdf2str(ldns_rr_rdf(rr, 3));
			strlcpy(res[i].host, host, sizeof(res[i].host));
			free(host);
		}
	}

	ldns_rr_list_deep_free(srv);

	return (res);
}

int
set_nameserver(const char *nsname)
{
	/*
	 * XXX: can we use the system resolver to resolve this name ??
	 * The current code does this, but it is unlikely a good solution
	 */
	return (0);
}
#endif