#include <stdio.h>
#include <stdlib.h>
-#include "query.h"
+#include "nss_gns_query.h"
#include <arpa/inet.h>
+/** macro to align idx to 32bit boundary */
#define ALIGN(idx) do { \
if (idx % sizeof(void*)) \
idx += (sizeof(void*) - idx % sizeof(void*)); /* Align on 32 bit boundary */ \
} while(0)
-#ifndef NSS_IPV6_ONLY
-static void ipv4_callback(const ipv4_address_t *ipv4, void *userdata) {
- struct userdata *u = userdata;
-
- /*test!*/
- ipv4_address_t *ipv4_test;
- struct in_addr testaddr;
- inet_pton(AF_INET, "5.5.5.5", &testaddr);
- ipv4_test = (ipv4_address_t *)&testaddr;
- /*test!*/
- /*assert(ipv4 && userdata);*/
-
- if (u->count >= MAX_ENTRIES)
- return;
-
- u->data.ipv4[u->count++] = *ipv4_test;
- u->data_len += sizeof(ipv4_address_t);
-}
-#endif
-
-#ifndef NSS_IPV4_ONLY
-static void ipv6_callback(const ipv6_address_t *ipv6, void *userdata) {
- struct userdata *u = userdata;
- assert(ipv6 && userdata);
-
- if (u->count >= MAX_ENTRIES)
- return;
-
- u->data.ipv6[u->count++] = *ipv6;
- u->data_len += sizeof(ipv6_address_t);
-}
-#endif
-
-static void name_callback(const char*name, void *userdata) {
- struct userdata *u = userdata;
- assert(name && userdata);
-
- if (u->count >= MAX_ENTRIES)
- return;
-
- u->data.name[u->count++] = strdup(name);
- u->data_len += strlen(name)+1;
-}
+/**
+ * function to check if name ends with a specific suffix
+ *
+ * @param name the name to check
+ * @param suffix the suffix to check for
+ * @return 1 if true
+ */
static int ends_with(const char *name, const char* suffix) {
size_t ln, ls;
assert(name);
return strcasecmp(name+ln-ls, suffix) == 0;
}
+
+/**
+ * Check if name is inside .gads or .zkey TLD
+ *
+ * @param name name to check
+ * @return 1 if true
+ */
static int verify_name_allowed(const char *name) {
- return ends_with(name, ".gnunet") || ends_with(name, ".zkey");
+ return ends_with(name, ".gads") || ends_with(name, ".zkey");
}
+/**
+ * The gethostbyname hook executed by nsswitch
+ *
+ * @param name the name to resolve
+ * @param af the address family to resolve
+ * @param result the result hostent
+ * @param buffer the result buffer
+ * @param buflen length of the buffer
+ * @param errnop idk
+ * @param h_errnop idk
+ * @return a nss_status code
+ */
enum nss_status _nss_gns_gethostbyname2_r(
const char *name,
int af,
size_t address_length, l, idx, astart;
int name_allowed;
- printf("v6: %d\n", af == AF_INET6);
-
if (af == AF_UNSPEC)
#ifdef NSS_IPV6_ONLY
af = AF_INET6;
if (name_allowed) {
- if (gns_resolve_name(af, name, &u) == 0)
+ if (!gns_resolve_name(af, name, &u) == 0)
{
- printf("GNS success\n");
- } else
- status = NSS_STATUS_NOTFOUND;
+ status = NSS_STATUS_NOTFOUND;
+ goto finish;
+ }
+ }
+ else
+ {
+ status = NSS_STATUS_UNAVAIL;
+ goto finish;
}
if (u.count == 0) {
*errnop = ETIMEDOUT;
*h_errnop = HOST_NOT_FOUND;
- printf("not found\n");
+ status = NSS_STATUS_NOTFOUND;
goto finish;
}
return status;
}
+/**
+ * The gethostbyname hook executed by nsswitch
+ *
+ * @param name the name to resolve
+ * @param result the result hostent
+ * @param buffer the result buffer
+ * @param buflen length of the buffer
+ * @param errnop idk
+ * @param h_errnop idk
+ * @return a nss_status code
+ */
enum nss_status _nss_gns_gethostbyname_r (
const char *name,
struct hostent *result,
h_errnop);
}
+/**
+ * The gethostbyaddr hook executed by nsswitch
+ * We can't do this so we always return NSS_STATUS_UNAVAIL
+ *
+ * @param addr the address to resolve
+ * @param len the length of the address
+ * @param af the address family of the address
+ * @param result the result hostent
+ * @param buffer the result buffer
+ * @param buflen length of the buffer
+ * @param errnop idk
+ * @param h_errnop idk
+ * @return NSS_STATUS_UNAVAIL
+ */
enum nss_status _nss_gns_gethostbyaddr_r(
const void* addr,
int len,