aboutsummaryrefslogtreecommitdiff
path: root/ports-mgmt
diff options
context:
space:
mode:
authorBryan Drewery <bdrewery@FreeBSD.org>2013-11-19 17:30:14 +0000
committerBryan Drewery <bdrewery@FreeBSD.org>2013-11-19 17:30:14 +0000
commit5f801cfb4ad6b9665302c7a3758ae27301e136f1 (patch)
tree6589c2945656f192ef2b29f2f13461a4d4960165 /ports-mgmt
parent17b58bcf209acd5b13ab762a33dd3a803e3e2870 (diff)
downloadports-5f801cfb4ad6b9665302c7a3758ae27301e136f1.tar.gz
ports-5f801cfb4ad6b9665302c7a3758ae27301e136f1.zip
Notes
Diffstat (limited to 'ports-mgmt')
-rw-r--r--ports-mgmt/pkg/Makefile2
-rw-r--r--ports-mgmt/pkg/files/patch-libpkg__dns_utils.c108
-rw-r--r--ports-mgmt/pkg/files/patch-libpkg__fetch.c88
-rw-r--r--ports-mgmt/pkg/files/patch-libpkg__private__utils.h10
4 files changed, 207 insertions, 1 deletions
diff --git a/ports-mgmt/pkg/Makefile b/ports-mgmt/pkg/Makefile
index 4e762b0c64e0..375bb4b6f086 100644
--- a/ports-mgmt/pkg/Makefile
+++ b/ports-mgmt/pkg/Makefile
@@ -2,7 +2,7 @@
PORTNAME= pkg
DISTVERSION= 1.1.4
-PORTREVISION= 9
+PORTREVISION= 10
CATEGORIES= ports-mgmt
MASTER_SITES= http://files.etoilebsd.net/pkg/ \
http://mirror.shatow.net/freebsd/${PORTNAME}/ \
diff --git a/ports-mgmt/pkg/files/patch-libpkg__dns_utils.c b/ports-mgmt/pkg/files/patch-libpkg__dns_utils.c
new file mode 100644
index 000000000000..05381ce09625
--- /dev/null
+++ b/ports-mgmt/pkg/files/patch-libpkg__dns_utils.c
@@ -0,0 +1,108 @@
+--- ./libpkg/dns_utils.c.orig 2013-07-06 05:48:19.000000000 -0500
++++ ./libpkg/dns_utils.c 2013-11-19 11:13:45.349130754 -0600
+@@ -40,6 +40,65 @@
+ 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;
++ db = *(struct dns_srvinfo * const *)b;
++
++ return ((da->priority > db->priority) - (da->priority < db->priority));
++}
++
++static int
++srv_final_cmp(const void *a, const void *b)
++{
++ const struct dns_srvinfo *da, *db;
++ int res;
++
++ da = *(struct dns_srvinfo * const *)a;
++ db = *(struct dns_srvinfo * const *)b;
++
++ res = ((da->priority > db->priority) - (da->priority < db->priority));
++ if (res == 0)
++ res = ((db->finalweight > da->finalweight) - (db->finalweight < da->finalweight));
++
++ return (res);
++}
++
++static void
++compute_weight(struct dns_srvinfo **d, int first, int last)
++{
++ int i, j;
++ int totalweight = 0;
++ int *chosen;
++
++ for (i = 0; i <= last; i++)
++ totalweight += d[i]->weight;
++
++ if (totalweight == 0)
++ return;
++
++ chosen = malloc(sizeof(int) * (last - first + 1));
++
++ for (i = 0; i <= last; i++) {
++ for (;;) {
++ chosen[i] = random() % (d[i]->weight * 100 / totalweight);
++ for (j = 0; j < i; j++) {
++ if (chosen[i] == chosen[j])
++ break;
++ }
++ if (j == i) {
++ d[i]->finalweight = chosen[i];
++ break;
++ }
++ }
++ }
++
++ free(chosen);
++}
++
+ struct dns_srvinfo *
+ dns_getsrvinfo(const char *zone)
+ {
+@@ -49,6 +108,7 @@
+ struct dns_srvinfo **res, *first;
+ unsigned char *end, *p;
+ unsigned int type, class, ttl, priority, weight, port;
++ int f, l;
+
+ if ((len = res_query(zone, C_IN, T_SRV, q.buf, sizeof(q.buf))) == -1 ||
+ len < (int)sizeof(HEADER))
+@@ -120,12 +180,31 @@
+ res[n]->weight = weight;
+ res[n]->port = port;
+ res[n]->next = NULL;
++ res[n]->finalweight = 0;
+ strlcpy(res[n]->host, host, MAXHOSTNAMELEN);
+
+ p += len;
+ n++;
+ }
+
++ /* order by priority */
++ qsort(res, n, sizeof(res[0]), srv_priority_cmp);
++
++ priority = 0;
++ f = 0;
++ l = 0;
++ for (i = 0; i < n; i++) {
++ if (res[i]->priority != priority) {
++ if (f != l)
++ compute_weight(res, f, l);
++ f = i;
++ priority = res[i]->priority;
++ }
++ l = i;
++ }
++
++ qsort(res, n, sizeof(res[0]), srv_final_cmp);
++
+ for (i = 0; i < n - 1; i++)
+ res[i]->next = res[i + 1];
+
diff --git a/ports-mgmt/pkg/files/patch-libpkg__fetch.c b/ports-mgmt/pkg/files/patch-libpkg__fetch.c
new file mode 100644
index 000000000000..866a21b82ef2
--- /dev/null
+++ b/ports-mgmt/pkg/files/patch-libpkg__fetch.c
@@ -0,0 +1,88 @@
+--- ./libpkg/fetch.c.orig 2013-07-06 05:48:19.000000000 -0500
++++ ./libpkg/fetch.c 2013-11-19 11:13:45.352130038 -0600
+@@ -179,6 +179,8 @@
+ return (EPKG_FATAL);
+ }
+
++#define URL_SCHEME_PREFIX "pkg+"
++
+ int
+ pkg_fetch_file_to_fd(struct pkg_repo *repo, const char *url, int dest, time_t *t)
+ {
+@@ -204,6 +206,7 @@
+ int kq = -1, flags = 0;
+ struct kevent e, ev;
+ struct timespec ts;
++ bool pkg_url_scheme = false;
+
+ if (pkg_config_int64(PKG_CONFIG_FETCH_RETRY, &max_retry) == EPKG_FATAL)
+ max_retry = 3;
+@@ -215,6 +218,34 @@
+
+ retry = max_retry;
+
++ /* A URL of the form http://host.example.com/ where
++ * host.example.com does not resolve as a simple A record is
++ * not valid according to RFC 2616 Section 3.2.2. Our usage
++ * with SRV records is incorrect. However it is encoded into
++ * /usr/sbin/pkg in various releases so we can't just drop it.
++ *
++ * Instead, introduce new pkg+http://, pkg+https://,
++ * pkg+ssh://, pkg+ftp://, pkg+file:// to support the
++ * SRV-style server discovery, and also to allow eg. Firefox
++ * to run pkg-related stuff given a pkg+foo:// URL.
++ *
++ * Warn if using plain http://, https:// etc with SRV
++ */
++
++ if (strncmp(URL_SCHEME_PREFIX, url, strlen(URL_SCHEME_PREFIX)) == 0) {
++ if (repo->mirror_type != SRV) {
++ pkg_emit_error("packagesite URL error for %s -- "
++ URL_SCHEME_PREFIX
++ ":// implies SRV mirror type", url);
++
++ /* Too early for there to be anything to cleanup */
++ return(EPKG_FATAL);
++ }
++
++ url += strlen(URL_SCHEME_PREFIX);
++ pkg_url_scheme = true;
++ }
++
+ u = fetchParseURL(url);
+ if (t != NULL)
+ u->ims_time = *t;
+@@ -253,6 +284,12 @@
+ if (repo != NULL && repo->mirror_type == SRV &&
+ (strncmp(u->scheme, "http", 4) == 0
+ || strcmp(u->scheme, "ftp") == 0)) {
++
++ if (!pkg_url_scheme)
++ pkg_emit_notice(
++ "Warning: use of %s:// URL scheme with SRV records is deprecated: "
++ "switch to pkg+%s://", u->scheme, u->scheme);
++
+ snprintf(zone, sizeof(zone),
+ "_%s._tcp.%s", u->scheme, u->host);
+ if (repo->srv == NULL)
+@@ -268,8 +305,10 @@
+ }
+ }
+
+- if (repo != NULL && repo->mirror_type == SRV && repo->srv != NULL)
++ if (repo != NULL && repo->mirror_type == SRV && repo->srv != NULL) {
+ strlcpy(u->host, srv_current->host, sizeof(u->host));
++ u->port = srv_current->port;
++ }
+ else if (repo != NULL && repo->mirror_type == HTTP && repo->http != NULL) {
+ strlcpy(u->scheme, http_current->url->scheme, sizeof(u->scheme));
+ strlcpy(u->host, http_current->url->host, sizeof(u->host));
+@@ -366,7 +405,7 @@
+
+ cleanup:
+
+- if (strcmp(u->scheme, "ssh") != 0) {
++ if (u != NULL && strcmp(u->scheme, "ssh") != 0) {
+ if (remote != NULL)
+ fclose(remote);
+ } else {
diff --git a/ports-mgmt/pkg/files/patch-libpkg__private__utils.h b/ports-mgmt/pkg/files/patch-libpkg__private__utils.h
new file mode 100644
index 000000000000..a7e992134101
--- /dev/null
+++ b/ports-mgmt/pkg/files/patch-libpkg__private__utils.h
@@ -0,0 +1,10 @@
+--- ./libpkg/private/utils.h.orig 2013-07-06 05:48:19.000000000 -0500
++++ ./libpkg/private/utils.h 2013-11-19 11:13:45.354131958 -0600
+@@ -60,6 +60,7 @@
+ unsigned int priority;
+ unsigned int weight;
+ unsigned int port;
++ unsigned int finalweight;
+ char host[MAXHOSTNAMELEN];
+ struct dns_srvinfo *next;
+ };