X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fgns%2Fgnunet-dns2gns.c;h=3d55bc04556f1a4d8dd4868510d0d8ebf3b410cb;hb=ea8c85c55b9df1b491713b79bb221b7476949742;hp=509321ebad6a75a90242ffea1a65b28b23f7c5f0;hpb=18cfab3eac50d8a151b377ec8870c89816dd12fc;p=oweals%2Fgnunet.git diff --git a/src/gns/gnunet-dns2gns.c b/src/gns/gnunet-dns2gns.c index 509321eba..3d55bc045 100644 --- a/src/gns/gnunet-dns2gns.c +++ b/src/gns/gnunet-dns2gns.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include "gns.h" @@ -64,7 +65,7 @@ struct Request * converted to the DNS response. */ struct GNUNET_DNSPARSER_Packet *packet; - + /** * Our GNS request handle. */ @@ -83,7 +84,7 @@ struct Request /** * Number of bytes in 'addr'. - */ + */ size_t addr_len; }; @@ -142,13 +143,28 @@ static unsigned int listen_port = 53; /** * Which GNS zone do we translate incoming DNS requests to? */ -static struct GNUNET_CRYPTO_EccPublicKey my_zone; +static struct GNUNET_CRYPTO_EcdsaPublicKey my_zone; /** * '-z' option with the main zone to use. */ static char *gns_zone_str; +/** + * Configuration to use. + */ +static const struct GNUNET_CONFIGURATION_Handle *cfg; + +/** + * Connection to identity service. + */ +static struct GNUNET_IDENTITY_Handle *identity; + +/** + * Request for our ego. + */ +static struct GNUNET_IDENTITY_Operation *id_op; + /** * Task run on shutdown. Cleans up everything. @@ -174,6 +190,16 @@ do_shutdown (void *cls, GNUNET_NETWORK_socket_close (listen_socket6); listen_socket6 = NULL; } + if (NULL != id_op) + { + GNUNET_IDENTITY_cancel (id_op); + id_op = NULL; + } + if (NULL != identity) + { + GNUNET_IDENTITY_disconnect (identity); + identity = NULL; + } GNUNET_GNS_disconnect (gns); gns = NULL; GNUNET_DNSSTUB_stop (dns_stub); @@ -191,7 +217,7 @@ send_response (struct Request *request) { char *buf; size_t size; - + if (GNUNET_SYSERR == GNUNET_DNSPARSER_pack (request->packet, UINT16_MAX /* is this not too much? */, @@ -270,7 +296,7 @@ dns_result_processor (void *cls, static void result_processor (void *cls, uint32_t rd_count, - const struct GNUNET_NAMESTORE_RecordData *rd) + const struct GNUNET_GNSRECORD_Data *rd) { struct Request *request = cls; struct GNUNET_DNSPARSER_Packet *packet; @@ -290,7 +316,7 @@ result_processor (void *cls, //packet->flags.opcode = GNUNET_TUN_DNS_OPCODE_STATUS; // ??? for (i=0;iqueries[0].name); - rec.class = GNUNET_TUN_DNS_CLASS_INTERNET; + rec.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; rec.type = GNUNET_DNSPARSER_TYPE_A; rec.data.raw.data = GNUNET_new (struct in_addr); memcpy (rec.data.raw.data, @@ -313,7 +339,7 @@ result_processor (void *cls, GNUNET_assert (sizeof (struct in6_addr) == rd[i].data_size); rec.name = GNUNET_strdup (packet->queries[0].name); rec.data.raw.data = GNUNET_malloc (sizeof (struct in6_addr)); - rec.class = GNUNET_TUN_DNS_CLASS_INTERNET; + rec.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; rec.type = GNUNET_DNSPARSER_TYPE_AAAA; memcpy (rec.data.raw.data, rd[i].data, @@ -326,7 +352,7 @@ result_processor (void *cls, case GNUNET_DNSPARSER_TYPE_CNAME: rec.name = GNUNET_strdup (packet->queries[0].name); rec.data.hostname = strdup (rd[i].data); - rec.class = GNUNET_TUN_DNS_CLASS_INTERNET; + rec.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET; rec.type = GNUNET_DNSPARSER_TYPE_CNAME; memcpy (rec.data.hostname, rd[i].data, @@ -351,7 +377,7 @@ result_processor (void *cls, * @param addr address to use for sending the reply * @param addr_len number of bytes in @a addr * @param udp_msg DNS request payload - * @param udp_msg_size number of bytes in @a udp_msg + * @param udp_msg_size number of bytes in @a udp_msg */ static void handle_request (struct GNUNET_NETWORK_Handle *lsock, @@ -382,7 +408,7 @@ handle_request (struct GNUNET_NETWORK_Handle *lsock, (int) packet->num_answers, (int) packet->num_authority_records, (int) packet->num_additional_records); - if ( (0 != packet->flags.query_or_response) || + if ( (0 != packet->flags.query_or_response) || (0 != packet->num_answers) || (0 != packet->num_authority_records)) { @@ -413,7 +439,7 @@ handle_request (struct GNUNET_NETWORK_Handle *lsock, name_len = strlen (name); use_gns = GNUNET_NO; - + if ( (name_len > strlen (fcfs_suffix)) && (0 == strcasecmp (fcfs_suffix, &name[name_len - strlen (fcfs_suffix)])) ) @@ -455,7 +481,7 @@ handle_request (struct GNUNET_NETWORK_Handle *lsock, else { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Using DNS resolver IP `%s' to resolve `%s'\n", + "Using DNS resolver IP `%s' to resolve `%s'\n", dns_ip, name); GNUNET_DNSPARSER_free_packet (request->packet); @@ -475,7 +501,7 @@ handle_request (struct GNUNET_NETWORK_Handle *lsock, * * @param cls the 'listen_socket4' * @param tc scheduler context - */ + */ static void read_dns4 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) @@ -499,9 +525,9 @@ read_dns4 (void *cls, } { char buf[size]; - + addrlen = sizeof (v4); - GNUNET_break (size == + GNUNET_break (size == GNUNET_NETWORK_socket_recvfrom (listen_socket4, buf, size, @@ -518,7 +544,7 @@ read_dns4 (void *cls, * * @param cls the 'listen_socket6' * @param tc scheduler context - */ + */ static void read_dns6 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) @@ -542,9 +568,9 @@ read_dns6 (void *cls, } { char buf[size]; - + addrlen = sizeof (v6); - GNUNET_break (size == + GNUNET_break (size == GNUNET_NETWORK_socket_recvfrom (listen_socket6, buf, size, @@ -557,34 +583,11 @@ read_dns6 (void *cls, /** - * Main function that will be run. - * - * @param cls closure - * @param args remaining command-line arguments - * @param cfgfile name of the configuration file used (for saving, can be NULL!) - * @param cfg configuration + * Start DNS daemon. */ static void -run (void *cls, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) +run_dnsd () { - if (NULL == dns_ip) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("No DNS server specified!\n")); - return; - } - if ( (NULL == gns_zone_str) || - (GNUNET_OK != - GNUNET_CRYPTO_ecc_public_key_from_string (gns_zone_str, - strlen (gns_zone_str), - &my_zone)) ) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("No valid GNS zone specified!\n")); - return; - } - if (NULL == dns_suffix) dns_suffix = DNS_SUFFIX; if (NULL == fcfs_suffix) @@ -598,7 +601,7 @@ run (void *cls, char *const *args, const char *cfgfile, return; } listen_socket4 = GNUNET_NETWORK_socket_create (PF_INET, - SOCK_DGRAM, + SOCK_DGRAM, IPPROTO_UDP); if (NULL != listen_socket4) { @@ -613,8 +616,7 @@ run (void *cls, char *const *args, const char *cfgfile, if (GNUNET_OK != GNUNET_NETWORK_socket_bind (listen_socket4, (struct sockaddr *) &v4, - sizeof (v4), - 0)) + sizeof (v4))) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); GNUNET_NETWORK_socket_close (listen_socket4); @@ -622,7 +624,7 @@ run (void *cls, char *const *args, const char *cfgfile, } } listen_socket6 = GNUNET_NETWORK_socket_create (PF_INET6, - SOCK_DGRAM, + SOCK_DGRAM, IPPROTO_UDP); if (NULL != listen_socket6) { @@ -637,8 +639,7 @@ run (void *cls, char *const *args, const char *cfgfile, if (GNUNET_OK != GNUNET_NETWORK_socket_bind (listen_socket6, (struct sockaddr *) &v6, - sizeof (v6), - 0)) + sizeof (v6))) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); GNUNET_NETWORK_socket_close (listen_socket6); @@ -665,20 +666,103 @@ run (void *cls, char *const *args, const char *cfgfile, &read_dns6, listen_socket6); +} + + +/** + * Method called to inform about the egos of this peer. + * + * When used with #GNUNET_IDENTITY_create or #GNUNET_IDENTITY_get, + * this function is only called ONCE, and 'NULL' being passed in + * @a ego does indicate an error (i.e. name is taken or no default + * value is known). If @a ego is non-NULL and if '*ctx' + * is set in those callbacks, the value WILL be passed to a subsequent + * call to the identity callback of #GNUNET_IDENTITY_connect (if + * that one was not NULL). + * + * @param cls closure, NULL + * @param ego ego handle + * @param ctx context for application to store data for this ego + * (during the lifetime of this process, initially NULL) + * @param name name assigned by the user for this ego, + * NULL if the user just deleted the ego and it + * must thus no longer be used + */ +static void +identity_cb (void *cls, + struct GNUNET_IDENTITY_Ego *ego, + void **ctx, + const char *name) +{ + id_op = NULL; + if (NULL == ego) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("No ego configured for `dns2gns` subsystem\n")); + return; + } + GNUNET_IDENTITY_ego_get_public_key (ego, + &my_zone); + run_dnsd (); +} + + +/** + * Main function that will be run. + * + * @param cls closure + * @param args remaining command-line arguments + * @param cfgfile name of the configuration file used (for saving, can be NULL!) + * @param c configuration + */ +static void +run (void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *c) +{ + cfg = c; + + if (NULL == dns_ip) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("No DNS server specified!\n")); + return; + } GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_shutdown, NULL); + if (NULL == gns_zone_str) + { + identity = GNUNET_IDENTITY_connect (cfg, + NULL, NULL); + id_op = GNUNET_IDENTITY_get (identity, + "dns2gns", + &identity_cb, + NULL); + return; + } + if ( (NULL == gns_zone_str) || + (GNUNET_OK != + GNUNET_CRYPTO_ecdsa_public_key_from_string (gns_zone_str, + strlen (gns_zone_str), + &my_zone)) ) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("No valid GNS zone specified!\n")); + GNUNET_SCHEDULER_shutdown (); + return; + } + run_dnsd (); } /** - * The main function for the fcfs daemon. + * The main function for the dns2gns daemon. * * @param argc number of arguments from the command line * @param argv command line arguments * @return 0 ok, 1 on error */ int -main (int argc, +main (int argc, char *const *argv) { static const struct GNUNET_GETOPT_CommandLineOption options[] = { @@ -695,7 +779,7 @@ main (int argc, gettext_noop ("UDP port to listen on for inbound DNS requests; default: 53"), 1, &GNUNET_GETOPT_set_uint, &listen_port}, {'z', "zone", "PUBLICKEY", - gettext_noop ("Public key of the GNS zone to use (required)"), 1, + gettext_noop ("Public key of the GNS zone to use (overrides default)"), 1, &GNUNET_GETOPT_set_string, &gns_zone_str}, GNUNET_GETOPT_OPTION_END }; @@ -708,7 +792,7 @@ main (int argc, ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc, argv, "gnunet-dns2gns", - _("GNUnet DNS-to-GNS proxy (a DNS server)"), + _("GNUnet DNS-to-GNS proxy (a DNS server)"), options, &run, NULL)) ? 0 : 1; GNUNET_free ((void*) argv);