| diff -Naur ldns-1.6.17-orig/configure.ac ldns-1.6.17/configure.ac |
| --- ldns-1.6.17-orig/configure.ac 2014-01-11 01:04:41.000000000 +0400 |
| +++ ldns-1.6.17/configure.ac 2014-12-29 10:02:35.502800000 +0300 |
| @@ -2,6 +2,7 @@ |
| # Process this file with autoconf to produce a configure script. |
| AC_PREREQ(2.56) |
| sinclude(acx_nlnetlabs.m4) |
| +sinclude(varexpand.m4) |
| |
| # must be numbers. ac_defun because of later processing. |
| m4_define([VERSION_MAJOR],[1]) |
| @@ -642,6 +642,9 @@ |
| AC_SUBST(LDNS_TRUST_ANCHOR_FILE) |
| AC_MSG_NOTICE([Default trust anchor: $LDNS_TRUST_ANCHOR_FILE]) |
| |
| +FULL_EXPAND_VARIABLE(ldns_bindir, "$bindir") |
| +AC_DEFINE_UNQUOTED(LDNS_BINDIR, "$ldns_bindir", [Runtime executables location]) |
| + |
| AC_ARG_WITH(ca-file, AC_HELP_STRING([--with-ca-file=CAFILE], [File containing CA certificates for ldns-dane]), [ |
| AC_DEFINE([HAVE_DANE_CA_FILE], [1], [Is a CAFILE given at configure time]) |
| AC_DEFINE_UNQUOTED([LDNS_DANE_CA_FILE], ["$withval"], [Is a CAFILE given at configure time]) |
| diff -Naur ldns-1.6.17-orig/drill/drill.c ldns-1.6.17/drill/drill.c |
| --- ldns-1.6.17-orig/drill/drill.c 2014-01-11 01:04:41.000000000 +0400 |
| +++ ldns-1.6.17/drill/drill.c 2014-12-29 10:03:20.836400000 +0300 |
| @@ -22,6 +24,7 @@ |
| static void |
| usage(FILE *stream, const char *progname) |
| { |
| + const char * _trust_file = ldns_path_relocation(LDNS_BINDIR, LDNS_TRUST_ANCHOR_FILE); |
| fprintf(stream, " Usage: %s name [@server] [type] [class]\n", progname); |
| fprintf(stream, "\t<name> can be a domain name or an IP address (-x lookups)\n"); |
| fprintf(stream, "\t<type> defaults to A\n"); |
| @@ -58,7 +58,7 @@ |
| fprintf(stream, "\t\t\tWhen DNSSEC enabled tracing (-TD) or signature\n" |
| "\t\t\tchasing (-S) and no key files are given, keys are read\n" |
| "\t\t\tfrom: %s\n", |
| - LDNS_TRUST_ANCHOR_FILE); |
| + _trust_file); |
| fprintf(stream, "\t-o <mnemonic>\tset flags to:" |
| "\n\t\t\t[QR|qr][AA|aa][TC|tc][RD|rd][CD|cd][RA|ra][AD|ad]\n"); |
| fprintf(stream, "\t\t\tlowercase: unset bit, uppercase: set bit\n"); |
| @@ -410,7 +413,8 @@ |
| if ((PURPOSE == DRILL_CHASE || (PURPOSE == DRILL_TRACE && qdnssec)) && |
| ldns_rr_list_rr_count(key_list) == 0) { |
| |
| - (void) read_key_file(LDNS_TRUST_ANCHOR_FILE, key_list, true); |
| + const char * _trust_file = ldns_path_relocation(LDNS_BINDIR, LDNS_TRUST_ANCHOR_FILE); |
| + (void) read_key_file(_trust_file, key_list, true); |
| } |
| if (ldns_rr_list_rr_count(key_list) > 0) { |
| printf(";; Number of trusted keys: %d\n", |
| diff -Naur ldns-1.6.17-orig/examples/ldns-dane.c ldns-1.6.17/examples/ldns-dane.c |
| --- ldns-1.6.17-orig/examples/ldns-dane.c 2014-01-11 01:04:41.000000000 +0400 |
| +++ ldns-1.6.17/examples/ldns-dane.c 2014-12-29 09:59:32.063000000 +0300 |
| @@ -65,7 +65,8 @@ |
| "use DNSKEY/DS rr(s) in <keyfile> to validate TLSAs\n" |
| "\t\t\twhen signature chasing (i.e. -S)\n" |
| ); |
| - printf("\t\t\tDefault is %s\n", LDNS_TRUST_ANCHOR_FILE); |
| + const char * _trust_file = ldns_path_relocation(LDNS_BINDIR, LDNS_TRUST_ANCHOR_FILE); |
| + printf("\t\t\tDefault is %s\n", _trust_file); |
| printf("\t-n\t\tdo *not* verify server name in certificate\n"); |
| printf("\t-o <offset>\t" |
| "select <offset>th certificate from the end of\n" |
| @@ -1310,7 +1310,8 @@ |
| |
| if (do_sigchase) { |
| if (nkeys == 0) { |
| - (void) read_key_file(LDNS_TRUST_ANCHOR_FILE, keys); |
| + const char * _trust_file = ldns_path_relocation(LDNS_BINDIR, LDNS_TRUST_ANCHOR_FILE); |
| + (void) read_key_file(_trust_file, keys); |
| nkeys = ldns_rr_list_rr_count(keys); |
| |
| if (nkeys == 0) { |
| diff -Naur ldns-1.6.17-orig/examples/ldns-verify-zone.c ldns-1.6.17/examples/ldns-verify-zone.c |
| --- ldns-1.6.17-orig/examples/ldns-verify-zone.c 2014-01-11 01:04:41.000000000 +0400 |
| +++ ldns-1.6.17/examples/ldns-verify-zone.c 2014-12-29 09:59:32.063000000 +0300 |
| @@ -657,6 +657,7 @@ |
| |
| static void print_usage(FILE *out, const char *progname) |
| { |
| + const char * _trust_file = ldns_path_relocation(LDNS_BINDIR, LDNS_TRUST_ANCHOR_FILE); |
| fprintf(out, "Usage: %s [OPTIONS] <zonefile>\n", progname); |
| fprintf(out, "\tReads the zonefile and checks for DNSSEC errors.\n"); |
| fprintf(out, "\nIt checks whether NSEC(3)s are present, " |
| @@ -675,7 +675,7 @@ |
| fprintf(out, "\t-k <file>\tspecify a file that contains a " |
| "trusted DNSKEY or DS rr.\n\t\t\t" |
| "This option may be given more than once.\n" |
| - "\t\t\tDefault is %s\n", LDNS_TRUST_ANCHOR_FILE); |
| + "\t\t\tDefault is %s\n", _trust_file); |
| fprintf(out, "\t-p [0-100]\tonly checks this percentage of " |
| "the zone.\n\t\t\tDefaults to 100\n"); |
| fprintf(out, "\t-S\t\tchase signature(s) to a known key. " |
| @@ -816,7 +816,8 @@ |
| } |
| } |
| if (do_sigchase && nkeys == 0) { |
| - (void) read_key_file(LDNS_TRUST_ANCHOR_FILE, keys); |
| + const char * _trust_file = ldns_path_relocation(LDNS_BINDIR, LDNS_TRUST_ANCHOR_FILE); |
| + (void) read_key_file(_trust_file, keys); |
| nkeys = ldns_rr_list_rr_count(keys); |
| |
| if (nkeys == 0) { |
| diff -Naur ldns-1.6.17-orig/pathtools.c ldns-1.6.17/pathtools.c |
| --- ldns-1.6.17-orig/pathtools.c 1970-01-01 03:00:00.000000000 +0300 |
| +++ ldns-1.6.17/pathtools.c 1970-01-01 03:00:00.000000000 +0300 |
| @@ -0,0 +1,538 @@ |
| +/* |
| + .Some useful path tools. |
| + .ASCII only for now. |
| + .Written by Ray Donnelly in 2014. |
| + .Licensed under CC0 (and anything. |
| + .else you need to license it under). |
| + .No warranties whatsoever. |
| + .email: <mingw.android@gmail.com>. |
| + */ |
| + |
| +#if defined(__APPLE__) |
| +#include <stdlib.h> |
| +#else |
| +#include <malloc.h> |
| +#endif |
| +#include <limits.h> |
| +#include <stdio.h> |
| +#include <string.h> |
| +#if defined(__linux__) || defined(__CYGWIN__) || defined(__MSYS__) |
| +#include <alloca.h> |
| +#endif |
| +#include <unistd.h> |
| + |
| +/* If you don't define this, then get_executable_path() |
| + can only use argv[0] which will often not work well */ |
| +#define IMPLEMENT_SYS_GET_EXECUTABLE_PATH |
| + |
| +#if defined(IMPLEMENT_SYS_GET_EXECUTABLE_PATH) |
| +#if defined(__linux__) || defined(__CYGWIN__) || defined(__MSYS__) |
| +/* Nothing needed, unistd.h is enough. */ |
| +#elif defined(__APPLE__) |
| +#include <mach-o/dyld.h> |
| +#elif defined(_WIN32) |
| +#define WIN32_MEAN_AND_LEAN |
| +#include <windows.h> |
| +#include <psapi.h> |
| +#endif |
| +#endif /* defined(IMPLEMENT_SYS_GET_EXECUTABLE_PATH) */ |
| + |
| +#include "pathtools.h" |
| + |
| +char * |
| +malloc_copy_string(char const * original) |
| +{ |
| + char * result = (char *) malloc (sizeof (char*) * strlen (original)+1); |
| + if (result != NULL) |
| + { |
| + strcpy (result, original); |
| + } |
| + return result; |
| +} |
| + |
| +void |
| +sanitise_path(char * path) |
| +{ |
| + size_t path_size = strlen (path); |
| + |
| + /* Replace any '\' with '/' */ |
| + char * path_p = path; |
| + while ((path_p = strchr (path_p, '\\')) != NULL) |
| + { |
| + *path_p = '/'; |
| + } |
| + /* Replace any '//' with '/' */ |
| + path_p = path; |
| + while ((path_p = strstr (path_p, "//")) != NULL) |
| + { |
| + memmove (path_p, path_p + 1, path_size--); |
| + } |
| + return; |
| +} |
| + |
| +char * |
| +get_relative_path(char const * from_in, char const * to_in) |
| +{ |
| + size_t from_size = (from_in == NULL) ? 0 : strlen (from_in); |
| + size_t to_size = (to_in == NULL) ? 0 : strlen (to_in); |
| + size_t max_size = (from_size + to_size) * 2 + 4; |
| + char * scratch_space = (char *) alloca (from_size + 1 + to_size + 1 + max_size + max_size); |
| + char * from; |
| + char * to; |
| + char * common_part; |
| + char * result; |
| + size_t count; |
| + |
| + /* No to, return "./" */ |
| + if (to_in == NULL) |
| + { |
| + return malloc_copy_string ("./"); |
| + } |
| + |
| + /* If alloca failed or no from was given return a copy of to */ |
| + if ( from_in == NULL |
| + || scratch_space == NULL ) |
| + { |
| + return malloc_copy_string (to_in); |
| + } |
| + |
| + from = scratch_space; |
| + strcpy (from, from_in); |
| + to = from + from_size + 1; |
| + strcpy (to, to_in); |
| + common_part = to + to_size + 1; |
| + result = common_part + max_size; |
| + simplify_path (from); |
| + simplify_path (to); |
| + |
| + result[0] = '\0'; |
| + |
| + size_t match_size_dirsep = 0; /* The match size up to the last /. Always wind back to this - 1 */ |
| + size_t match_size = 0; /* The running (and final) match size. */ |
| + size_t largest_size = (from_size > to_size) ? from_size : to_size; |
| + int to_final_is_slash = (to[to_size-1] == '/') ? 1 : 0; |
| + char from_c; |
| + char to_c; |
| + for (match_size = 0; match_size < largest_size; ++match_size) |
| + { |
| + /* To simplify the logic, always pretend the strings end with '/' */ |
| + from_c = (match_size < from_size) ? from[match_size] : '/'; |
| + to_c = (match_size < to_size) ? to[match_size] : '/'; |
| + |
| + if (from_c != to_c) |
| + { |
| + if (from_c != '\0' || to_c != '\0') |
| + { |
| + match_size = match_size_dirsep; |
| + } |
| + break; |
| + } |
| + else if (from_c == '/') |
| + { |
| + match_size_dirsep = match_size; |
| + } |
| + } |
| + strncpy (common_part, from, match_size); |
| + common_part[match_size] = '\0'; |
| + from += match_size; |
| + to += match_size; |
| + size_t ndotdots = 0; |
| + char const* from_last = from + strlen(from) - 1; |
| + while ((from = strchr (from, '/')) && from != from_last) |
| + { |
| + ++ndotdots; |
| + ++from; |
| + } |
| + for (count = 0; count < ndotdots; ++count) |
| + { |
| + strcat(result, "../"); |
| + } |
| + if (strlen(to) > 0) |
| + { |
| + strcat(result, to+1); |
| + } |
| + /* Make sure that if to ends with '/' result does the same, and |
| + vice-versa. */ |
| + size_t size_result = strlen(result); |
| + if ((to_final_is_slash == 1) |
| + && (!size_result || result[size_result-1] != '/')) |
| + { |
| + strcat (result, "/"); |
| + } |
| + else if (!to_final_is_slash |
| + && size_result && result[size_result-1] == '/') |
| + { |
| + result[size_result-1] = '\0'; |
| + } |
| + |
| + return malloc_copy_string (result); |
| +} |
| + |
| +void |
| +simplify_path(char * path) |
| +{ |
| + ssize_t n_toks = 1; /* in-case we need an empty initial token. */ |
| + ssize_t i, j; |
| + size_t tok_size; |
| + size_t in_size = strlen (path); |
| + int it_ended_with_a_slash = (path[in_size - 1] == '/') ? 1 : 0; |
| + char * result = path; |
| + sanitise_path(result); |
| + char * result_p = result; |
| + |
| + do |
| + { |
| + ++n_toks; |
| + ++result_p; |
| + } while ((result_p = strchr (result_p, '/')) != NULL); |
| + |
| + result_p = result; |
| + char const ** toks = (char const **) alloca (sizeof (char const*) * n_toks); |
| + n_toks = 0; |
| + do |
| + { |
| + if (result_p > result) |
| + { |
| + *result_p++ = '\0'; |
| + } |
| + else if (*result_p == '/') |
| + { |
| + /* A leading / creates an empty initial token. */ |
| + toks[n_toks++] = result_p; |
| + *result_p++ = '\0'; |
| + } |
| + toks[n_toks++] = result_p; |
| + } while ((result_p = strchr (result_p, '/')) != NULL); |
| + |
| + /* Remove all non-leading '.' and any '..' we can match |
| + with an earlier forward path (i.e. neither '.' nor '..') */ |
| + for (i = 1; i < n_toks; ++i) |
| + { |
| + int removals[2] = { -1, -1 }; |
| + if ( strcmp (toks[i], "." ) == 0) |
| + { |
| + removals[0] = i; |
| + } |
| + else if ( strcmp (toks[i], ".." ) == 0) |
| + { |
| + /* Search backwards for a forward path to collapse. |
| + If none are found then the .. also stays. */ |
| + for (j = i - 1; j > -1; --j) |
| + { |
| + if ( strcmp (toks[j], "." ) |
| + && strcmp (toks[j], ".." ) ) |
| + { |
| + removals[0] = j; |
| + removals[1] = i; |
| + break; |
| + } |
| + } |
| + } |
| + for (j = 0; j < 2; ++j) |
| + { |
| + if (removals[j] >= 0) /* Can become -2 */ |
| + { |
| + --n_toks; |
| + memmove (&toks[removals[j]], &toks[removals[j]+1], (n_toks - removals[j])*sizeof (char*)); |
| + --i; |
| + if (!j) |
| + { |
| + --removals[1]; |
| + } |
| + } |
| + } |
| + } |
| + result_p = result; |
| + for (i = 0; i < n_toks; ++i) |
| + { |
| + tok_size = strlen(toks[i]); |
| + memmove (result_p, toks[i], tok_size); |
| + result_p += tok_size; |
| + if ((!i || tok_size) && ((i < n_toks - 1) || it_ended_with_a_slash == 1)) |
| + { |
| + *result_p = '/'; |
| + ++result_p; |
| + } |
| + } |
| + *result_p = '\0'; |
| +} |
| + |
| +/* Returns actual_to by calculating the relative path from -> to and |
| + applying that to actual_from. An assumption that actual_from is a |
| + dir is made, and it may or may not end with a '/' */ |
| +char const * |
| +get_relocated_path (char const * from, char const * to, char const * actual_from) |
| +{ |
| + char const * relative_from_to = get_relative_path (from, to); |
| + char * actual_to = (char *) malloc (strlen(actual_from) + 2 + strlen(relative_from_to)); |
| + return actual_to; |
| +} |
| + |
| +int |
| +get_executable_path(char const * argv0, char * result, ssize_t max_size) |
| +{ |
| + char * system_result = (char *) alloca (max_size); |
| + ssize_t system_result_size = -1; |
| + ssize_t result_size = -1; |
| + |
| + if (system_result != NULL) |
| + { |
| +#if defined(IMPLEMENT_SYS_GET_EXECUTABLE_PATH) |
| +#if defined(__linux__) || defined(__CYGWIN__) || defined(__MSYS__) |
| + system_result_size = readlink("/proc/self/exe", system_result, max_size); |
| +#elif defined(__APPLE__) |
| + uint32_t bufsize = (uint32_t)max_size; |
| + if (_NSGetExecutablePath(system_result, &bufsize) == 0) |
| + { |
| + system_result_size = (ssize_t)bufsize; |
| + } |
| +#elif defined(_WIN32) |
| + unsigned long bufsize = (unsigned long)max_size; |
| + system_result_size = GetModuleFileNameA(NULL, system_result, bufsize); |
| + if (system_result_size == 0 || system_result_size == (ssize_t)bufsize) |
| + { |
| + /* Error, possibly not enough space. */ |
| + system_result_size = -1; |
| + } |
| + else |
| + { |
| + /* Early conversion to unix slashes instead of more changes |
| + everywhere else .. */ |
| + char * winslash; |
| + system_result[system_result_size] = '\0'; |
| + while ((winslash = strchr (system_result, '\\')) != NULL) |
| + { |
| + *winslash = '/'; |
| + } |
| + } |
| +#else |
| +#warning "Don't know how to get executable path on this system" |
| +#endif |
| +#endif /* defined(IMPLEMENT_SYS_GET_EXECUTABLE_PATH) */ |
| + } |
| + /* Use argv0 as a default in-case of failure */ |
| + if (system_result_size != -1) |
| + { |
| + strncpy (result, system_result, system_result_size); |
| + result[system_result_size] = '\0'; |
| + } |
| + else |
| + { |
| + if (argv0 != NULL) |
| + { |
| + strncpy (result, argv0, max_size); |
| + result[max_size-1] = '\0'; |
| + } |
| + else |
| + { |
| + result[0] = '\0'; |
| + } |
| + } |
| + result_size = strlen (result); |
| + return result_size; |
| +} |
| + |
| +char const * |
| +strip_n_prefix_folders(char const * path, size_t n) |
| +{ |
| + if (path == NULL) |
| + { |
| + return NULL; |
| + } |
| + |
| + if (path[0] != '/') |
| + { |
| + return path; |
| + } |
| + |
| + char const * last = path; |
| + while (n-- && path != NULL) |
| + { |
| + last = path; |
| + path = strchr (path + 1, '/'); |
| + } |
| + return (path == NULL) ? last : path; |
| +} |
| + |
| +void |
| +strip_n_suffix_folders(char * path, size_t n) |
| +{ |
| + if (path == NULL) |
| + { |
| + return; |
| + } |
| + while (n--) |
| + { |
| + if (strrchr (path + 1, '/')) |
| + { |
| + *strrchr (path + 1, '/') = '\0'; |
| + } |
| + else |
| + { |
| + return; |
| + } |
| + } |
| + return; |
| +} |
| + |
| +size_t |
| +split_path_list(char const * path_list, char split_char, char *** arr) |
| +{ |
| + size_t path_count; |
| + size_t path_list_size; |
| + char const * path_list_p; |
| + |
| + path_list_p = path_list; |
| + if (path_list == NULL || path_list[0] == '\0') |
| + { |
| + return 0; |
| + } |
| + path_list_size = strlen (path_list); |
| + |
| + path_count = 0; |
| + do |
| + { |
| + ++path_count; |
| + ++path_list_p; |
| + } |
| + while ((path_list_p = strchr (path_list_p, split_char)) != NULL); |
| + |
| + /* allocate everything in one go. */ |
| + char * all_memory = (char *) malloc (sizeof (char *) * path_count + strlen(path_list) + 1); |
| + if (all_memory == NULL) |
| + return 0; |
| + *arr = (char **)all_memory; |
| + all_memory += sizeof (char *) * path_count; |
| + |
| + path_count = 0; |
| + path_list_p = path_list; |
| + char const * next_path_list_p = 0; |
| + do |
| + { |
| + next_path_list_p = strchr (path_list_p, split_char); |
| + if (next_path_list_p != NULL) |
| + { |
| + ++next_path_list_p; |
| + } |
| + size_t this_size = (next_path_list_p != NULL) |
| + ? next_path_list_p - path_list_p - 1 |
| + : &path_list[path_list_size] - path_list_p; |
| + memcpy (all_memory, path_list_p, this_size); |
| + all_memory[this_size] = '\0'; |
| + (*arr)[path_count++] = all_memory; |
| + all_memory += this_size + 1; |
| + } while ((path_list_p = next_path_list_p) != NULL); |
| + |
| + return path_count; |
| +} |
| + |
| +char * |
| +get_relocated_path_list(char const * from, char const * to_path_list) |
| +{ |
| + char exe_path[MAX_PATH]; |
| + char * temp; |
| + get_executable_path (NULL, &exe_path[0], sizeof (exe_path) / sizeof (exe_path[0])); |
| + if ((temp = strrchr (exe_path, '/')) != NULL) |
| + { |
| + temp[1] = '\0'; |
| + } |
| + |
| + char **arr = NULL; |
| + /* Ask Alexey why he added this. Are we not 100% sure |
| + that we're dealing with unix paths here? */ |
| + char split_char = ':'; |
| + if (strchr (to_path_list, ';')) |
| + { |
| + split_char = ';'; |
| + } |
| + size_t count = split_path_list (to_path_list, split_char, &arr); |
| + int result_size = 1 + (count - 1); /* count - 1 is for ; delim. */ |
| + size_t exe_path_size = strlen (exe_path); |
| + size_t i; |
| + /* Space required is: |
| + count * (exe_path_size + strlen (rel_to_datadir)) |
| + rel_to_datadir upper bound is: |
| + (count * strlen (from)) + (3 * num_slashes (from)) |
| + + strlen(arr[i]) + 1. |
| + .. pathalogically num_slashes (from) is strlen (from) |
| + (from = ////////) */ |
| + size_t space_required = (count * (exe_path_size + 4 * strlen (from))) + count - 1; |
| + for (i = 0; i < count; ++i) |
| + { |
| + space_required += strlen (arr[i]); |
| + } |
| + char * scratch = (char *) alloca (space_required); |
| + if (scratch == NULL) |
| + return NULL; |
| + for (i = 0; i < count; ++i) |
| + { |
| + char * rel_to_datadir = get_relative_path (from, arr[i]); |
| + scratch[0] = '\0'; |
| + arr[i] = scratch; |
| + strcat (scratch, exe_path); |
| + strcat (scratch, rel_to_datadir); |
| + simplify_path (arr[i]); |
| + size_t arr_i_size = strlen (arr[i]); |
| + result_size += arr_i_size; |
| + scratch = arr[i] + arr_i_size + 1; |
| + } |
| + char * result = (char *) malloc (result_size); |
| + if (result == NULL) |
| + { |
| + return NULL; |
| + } |
| + result[0] = '\0'; |
| + for (i = 0; i < count; ++i) |
| + { |
| + strcat (result, arr[i]); |
| + if (i != count-1) |
| + { |
| +#if defined(_WIN32) |
| + strcat (result, ";"); |
| +#else |
| + strcat (result, ":"); |
| +#endif |
| + } |
| + } |
| + free ((void*)arr); |
| + return result; |
| +} |
| + |
| +char * |
| +single_path_relocation(const char *from, const char *to) |
| +{ |
| +#if defined(__MINGW32__) |
| + char exe_path[PATH_MAX]; |
| + get_executable_path (NULL, &exe_path[0], sizeof(exe_path)/sizeof(exe_path[0])); |
| + if (strrchr (exe_path, '/') != NULL) |
| + { |
| + strrchr (exe_path, '/')[1] = '\0'; |
| + } |
| + char * rel_to_datadir = get_relative_path (from, to); |
| + strcat (exe_path, rel_to_datadir); |
| + simplify_path (&exe_path[0]); |
| + return malloc_copy_string(exe_path); |
| +#else |
| + return malloc_copy_string(to); |
| +#endif |
| +} |
| + |
| +char * |
| +pathlist_relocation(const char *from_path, const char *to_path_list) |
| +{ |
| +#if defined(__MINGW32__) |
| + static char stored_path[PATH_MAX]; |
| + static int stored = 0; |
| + if (stored == 0) |
| + { |
| + char const * relocated = get_relocated_path_list(from_path, to_path_list); |
| + strncpy (stored_path, relocated, PATH_MAX); |
| + stored_path[PATH_MAX-1] = '\0'; |
| + free ((void *)relocated); |
| + stored = 1; |
| + } |
| + return stored_path; |
| +#else |
| + return (to_path_list); |
| +#endif |
| +} |
| diff -Naur ldns-1.6.17-orig/pathtools.h ldns-1.6.17/pathtools.h |
| --- ldns-1.6.17-orig/pathtools.h 1970-01-01 03:00:00.000000000 +0300 |
| +++ ldns-1.6.17/pathtools.h 1970-01-01 03:00:00.000000000 +0300 |
| @@ -0,0 +1,53 @@ |
| +/* |
| + .Some useful path tools. |
| + .ASCII only for now. |
| + .Written by Ray Donnelly in 2014. |
| + .Licensed under CC0 (and anything. |
| + .else you need to license it under). |
| + .No warranties whatsoever. |
| + .email: <mingw.android@gmail.com>. |
| + */ |
| + |
| +#ifndef PATHTOOLS_H |
| +#define PATHTOOLS_H |
| + |
| +#include <unistd.h> |
| +#if defined(__APPLE__) |
| +#include <stdlib.h> |
| +#else |
| +#include <malloc.h> |
| +#endif |
| +#include <stdio.h> |
| + |
| +char * malloc_copy_string(char const * original); |
| + |
| +/* In-place replaces any '\' with '/' and any '//' with '/' */ |
| +void sanitise_path(char * path); |
| + |
| +/* Uses a host OS specific function to determine the path of the executable, |
| + if IMPLEMENT_SYS_GET_EXECUTABLE_PATH is defined, otherwise uses argv0. */ |
| +int get_executable_path(char const * argv0, char * result, ssize_t max_size); |
| + |
| +/* Where possible, in-place removes occourances of '.' and 'path/..' */ |
| +void simplify_path(char * path); |
| + |
| +/* Allocates (via malloc) and returns the path to get from from to to. */ |
| +char * get_relative_path(char const * from, char const * to); |
| + |
| +size_t split_path_list(char const * path_list, char split_char, char *** arr); |
| + |
| +/* Advances path along by the amount that removes n prefix folders. */ |
| +char const * |
| +strip_n_prefix_folders(char const * path, size_t n); |
| + |
| +/* NULL terminates path to remove n suffix folders. */ |
| +void |
| +strip_n_suffix_folders(char * path, size_t n); |
| + |
| +char const * get_relocated_path (char const * from, char const * to, char const * actual_from); |
| +char * get_relocated_path_list(char const * from, char const * to_path_list); |
| + |
| +char * single_path_relocation(const char *from, const char *to); |
| +char * pathlist_relocation(const char *from_path, const char *to_path_list); |
| + |
| +#endif /* PATHTOOLS_H */ |
| diff -Naur ldns-1.6.17-orig/varexpand.m4 ldns-1.6.17/varexpand.m4 |
| --- ldns-1.6.17-orig/varexpand.m4 1970-01-01 03:00:00.000000000 +0300 |
| +++ ldns-1.6.17/varexpand.m4 2014-12-29 09:55:37.933600000 +0300 |
| @@ -0,0 +1,8 @@ |
| +AC_DEFUN([FULL_EXPAND_VARIABLE], [ |
| + $1=$2 |
| + $1=`( |
| + test "x$prefix" = xNONE && prefix="$ac_default_prefix" |
| + test "x$exec_prefix" = xNONE && exec_prefix="${prefix}" |
| + eval echo \""[$]$1"\" |
| + )` |
| +]) |
| diff -Naur ldns-1.6.17-orig/Makefile.in ldns-1.6.17/Makefile.in |
| --- ldns-1.6.17-orig/Makefile.in 2014-01-11 01:04:41.000000000 +0400 |
| +++ ldns-1.6.17/Makefile.in 2014-12-29 09:59:32.063000000 +0300 |
| @@ -65,7 +65,7 @@ |
| INSTALL = $(srcdir)/install-sh |
| |
| LIBLOBJS = $(LIBOBJS:.o=.lo) |
| -LDNS_LOBJS = buffer.lo dane.lo dname.lo dnssec.lo dnssec_sign.lo dnssec_verify.lo dnssec_zone.lo duration.lo error.lo higher.lo host2str.lo host2wire.lo keys.lo net.lo packet.lo parse.lo radix.lo rbtree.lo rdata.lo resolver.lo rr.lo rr_functions.lo sha1.lo sha2.lo str2host.lo tsig.lo update.lo util.lo wire2host.lo zone.lo |
| +LDNS_LOBJS = buffer.lo dane.lo dname.lo dnssec.lo dnssec_sign.lo dnssec_verify.lo dnssec_zone.lo duration.lo error.lo higher.lo host2str.lo host2wire.lo keys.lo net.lo packet.lo parse.lo pathtools.lo radix.lo rbtree.lo rdata.lo resolver.lo rr.lo rr_functions.lo sha1.lo sha2.lo str2host.lo tsig.lo update.lo util.lo wire2host.lo zone.lo |
| LDNS_LOBJS_EX = ^linktest\.c$$ |
| LDNS_ALL_LOBJS = $(LDNS_LOBJS) $(LIBLOBJS) |
| LIB = libldns.la |
| @@ -118,6 +118,7 @@ |
| @if test ! -d drill ; then mkdir drill ; fi |
| @if test ! -d examples ; then mkdir examples ; fi |
| @if test ! -h config.h ; then ln -s ldns/config.h . ; fi |
| + @if test ! -d .libs ; then mkdir .libs ; fi |
| @if test ! -h lib ; then ln -s .libs lib ; fi ; |
| @if test ! -d include ; then $(INSTALL) -d include; fi |
| @if test ! -h include/ldns ; then ln -s ../ldns include/ldns || echo "include/ldns exists"; fi |
| @@ -216,7 +216,7 @@ |
| lib-export-all: libldns.la-export-all |
| |
| libldns.la: $(LDNS_ALL_LOBJS) |
| - $(LINK_LIB) $(LIBSSL_LDFLAGS) $(LIBSSL_LIBS) -export-symbols-regex '^(ldns_|b32_[pn]to[pn]|mktime_from_utc|qsort_rr_compare_nsec3)' -o libldns.la $(LDNS_ALL_LOBJS) -rpath $(libdir) $(RUNTIME_PATH) |
| + $(LINK_LIB) $(LIBSSL_LDFLAGS) $(LIBSSL_LIBS) -export-symbols-regex '^(ldns_|inet_[anp]to[pn]|b64_[pn]to[pn]|b32_[pn]to[pn]|mktime_from_utc|qsort_rr_compare_nsec3)' -o libldns.la $(LDNS_ALL_LOBJS) -rpath $(libdir) $(RUNTIME_PATH) |
| |
| libldns.la-export-all: $(LDNS_ALL_LOBJS) |
| $(LINK_LIB) -o libldns.la $(LDNS_ALL_LOBJS) -rpath $(libdir) $(RUNTIME_PATH) |
| --- ldns-1.6.17/util.c.orig 2014-12-29 12:10:20.441600000 +0300 |
| +++ ldns-1.6.17/util.c 2014-12-29 12:11:18.856000000 +0300 |
| @@ -22,10 +22,31 @@ |
| #include <time.h> |
| #include <ctype.h> |
| |
| +#include "pathtools.h" |
| + |
| #ifdef HAVE_SSL |
| #include <openssl/rand.h> |
| #endif |
| |
| +char * |
| +ldns_path_relocation(const char *from, const char *to) |
| +{ |
| +#if defined(__MINGW32__) |
| + char exe_path[PATH_MAX]; |
| + get_executable_path (NULL, &exe_path[0], sizeof(exe_path)/sizeof(exe_path[0])); |
| + if (strrchr (exe_path, '/') != NULL) |
| + { |
| + strrchr (exe_path, '/')[1] = '\0'; |
| + } |
| + char * rel_to_datadir = get_relative_path (from, to); |
| + strcat (exe_path, rel_to_datadir); |
| + simplify_path (&exe_path[0]); |
| + return malloc_copy_string(exe_path); |
| +#else |
| + return malloc_copy_string(to); |
| +#endif |
| +} |
| + |
| ldns_lookup_table * |
| ldns_lookup_by_name(ldns_lookup_table *table, const char *name) |
| { |
| --- ldns-1.6.17/ldns/util.h.in.orig 2014-12-29 12:08:51.581000000 +0300 |
| +++ ldns-1.6.17/ldns/util.h.in 2014-12-29 12:11:09.152800000 +0300 |
| @@ -385,6 +385,7 @@ |
| |
| #endif /* ! LDNS_BUILD_CONFIG_HAVE_B32_PTON */ |
| |
| +char * ldns_path_relocation(const char *from, const char *to); |
| |
| #ifdef __cplusplus |
| } |