aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/man/Makefile.am1
-rw-r--r--doc/man/gnunet-gns.134
-rw-r--r--src/gns/Makefile.am16
-rw-r--r--src/gns/gnunet-gns.c151
4 files changed, 200 insertions, 2 deletions
diff --git a/doc/man/Makefile.am b/doc/man/Makefile.am
index 5b6f08ab5..2a63b1f36 100644
--- a/doc/man/Makefile.am
+++ b/doc/man/Makefile.am
@@ -4,6 +4,7 @@ man_MANS = \
4 gnunet-download.1 \ 4 gnunet-download.1 \
5 gnunet-download-manager.1 \ 5 gnunet-download-manager.1 \
6 gnunet-fs.1 \ 6 gnunet-fs.1 \
7 gnunet-gns.1 \
7 gnunet-nat-server.1 \ 8 gnunet-nat-server.1 \
8 gnunet-peerinfo.1 \ 9 gnunet-peerinfo.1 \
9 gnunet-pseudonym.1 \ 10 gnunet-pseudonym.1 \
diff --git a/doc/man/gnunet-gns.1 b/doc/man/gnunet-gns.1
new file mode 100644
index 000000000..12fd5e316
--- /dev/null
+++ b/doc/man/gnunet-gns.1
@@ -0,0 +1,34 @@
1.TH GNUNET\-GNS 1 "Jan 4, 2012" "GNUnet"
2
3.SH NAME
4gnunet\-gns \- manipulate GNUnet GNS zones
5
6.SH SYNOPSIS
7.B gnunet\-gns
8.RI [ options ] -z ZONEFILE
9.br
10
11.SH DESCRIPTION
12\fBgnunet\-gns\fP can be used to create and manipulate a GNS zone.
13
14.SH OPTIONS
15.B
16.IP "\-z FILENAME, \-\-zonekey=FILENAME"
17Specifies the filename with the private key for the zone (mandatory option)
18.B
19.IP "\-c FILENAME, \-\-config=FILENAME"
20Use the configuration file FILENAME.
21.B
22.IP "\-h, \-\-help"
23Print short help on options.
24.B
25.IP "\-L LOGLEVEL, \-\-loglevel=LOGLEVEL"
26Use LOGLEVEL for logging. Valid values are DEBUG, INFO, WARNING and ERROR.
27.B
28.IP "\-v, \-\-version"
29Print GNUnet version number.
30
31
32.SH BUGS
33Report bugs by using Mantis <https://gnunet.org/bugs/> or by sending electronic mail to <gnunet\-developers@gnu.org>
34
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am
index e35116cc9..64484dbf3 100644
--- a/src/gns/Makefile.am
+++ b/src/gns/Makefile.am
@@ -20,7 +20,8 @@ lib_LTLIBRARIES = \
20 20
21bin_PROGRAMS = \ 21bin_PROGRAMS = \
22 gnunet-service-gns \ 22 gnunet-service-gns \
23 gnunet-gns-fcfsd 23 gnunet-gns-fcfsd \
24 gnunet-gns
24 25
25#noinst_PROGRAMS = \ 26#noinst_PROGRAMS = \
26# gnunet-gns-lookup 27# gnunet-gns-lookup
@@ -118,7 +119,18 @@ gnunet_gns_fcfsd_LDADD = -lmicrohttpd \
118 $(top_builddir)/src/util/libgnunetutil.la \ 119 $(top_builddir)/src/util/libgnunetutil.la \
119 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 120 $(top_builddir)/src/namestore/libgnunetnamestore.la \
120 $(GN_LIBINTL) 121 $(GN_LIBINTL)
121gnunet_service_gns_DEPENDENCIES = \ 122gnunet_gns_fcfsd_DEPENDENCIES = \
123 $(top_builddir)/src/util/libgnunetutil.la \
124 $(top_builddir)/src/namestore/libgnunetnamestore.la
125
126
127gnunet_gns_SOURCES = \
128 gnunet-gns.c
129gnunet_gns_LDADD = \
130 $(top_builddir)/src/util/libgnunetutil.la \
131 $(top_builddir)/src/namestore/libgnunetnamestore.la \
132 $(GN_LIBINTL)
133gnunet_gns_DEPENDENCIES = \
122 $(top_builddir)/src/util/libgnunetutil.la \ 134 $(top_builddir)/src/util/libgnunetutil.la \
123 $(top_builddir)/src/namestore/libgnunetnamestore.la 135 $(top_builddir)/src/namestore/libgnunetnamestore.la
124 136
diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c
new file mode 100644
index 000000000..a56b229b5
--- /dev/null
+++ b/src/gns/gnunet-gns.c
@@ -0,0 +1,151 @@
1/*
2 This file is part of GNUnet.
3 (C) 2012 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20/**
21 * @file gnunet-gns.c
22 * @brief command line tool to manipulate the local zone
23 * @author Christian Grothoff
24 *
25 * TODO:
26 * - everything
27 */
28#include "platform.h"
29#include <gnunet_util_lib.h>
30#include <gnunet_namestore_service.h>
31
32/**
33 * Handle to the namestore.
34 */
35static struct GNUNET_NAMESTORE_Handle *ns;
36
37/**
38 * Hash of the public key of our zone.
39 */
40static GNUNET_HashCode zone;
41
42/**
43 * Private key for the our zone.
44 */
45static struct GNUNET_CRYPTO_RsaPrivateKey *zone_pkey;
46
47/**
48 * Keyfile to manipulate.
49 */
50static char *keyfile;
51
52
53/**
54 * Task run on shutdown. Cleans up everything.
55 *
56 * @param cls unused
57 * @param tc scheduler context
58 */
59static void
60do_shutdown (void *cls,
61 const struct GNUNET_SCHEDULER_TaskContext *tc)
62{
63 if (NULL != ns)
64 {
65 GNUNET_NAMESTORE_disconnect (ns, GNUNET_NO);
66 ns = NULL;
67 }
68 if (NULL != zone_pkey)
69 {
70 GNUNET_CRYPTO_rsa_key_free (zone_pkey);
71 zone_pkey = NULL;
72 }
73}
74
75
76/**
77 * Main function that will be run.
78 *
79 * @param cls closure
80 * @param args remaining command-line arguments
81 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
82 * @param cfg configuration
83 */
84static void
85run (void *cls, char *const *args, const char *cfgfile,
86 const struct GNUNET_CONFIGURATION_Handle *cfg)
87{
88 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub;
89
90 if (NULL == keyfile)
91 {
92 fprintf (stderr,
93 _("Option `%s' not given, but I need a zone key file!\n"),
94 "z");
95 return;
96 }
97 zone_pkey = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
98 GNUNET_free (keyfile);
99 keyfile = NULL;
100 if (NULL == zone_pkey)
101 {
102 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
103 _("Failed to read or create private zone key\n"));
104 return;
105 }
106 GNUNET_CRYPTO_rsa_key_get_public (zone_pkey,
107 &pub);
108 GNUNET_CRYPTO_hash (&pub, sizeof (pub), &zone);
109 ns = GNUNET_NAMESTORE_connect (cfg);
110 if (NULL == ns)
111 {
112 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
113 _("Failed to connect to namestore\n"));
114 return;
115 }
116 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
117 &do_shutdown, NULL);
118}
119
120
121/**
122 * The main function for gnunet-gns.
123 *
124 * @param argc number of arguments from the command line
125 * @param argv command line arguments
126 * @return 0 ok, 1 on error
127 */
128int
129main (int argc, char *const *argv)
130{
131 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
132 {'z', "zonekey", "FILENAME",
133 gettext_noop ("filename with the zone key"), 1,
134 &GNUNET_GETOPT_set_string, &keyfile},
135 GNUNET_GETOPT_OPTION_END
136 };
137
138 int ret;
139
140 GNUNET_log_setup ("gnunet-gns", "WARNING", NULL);
141 ret =
142 (GNUNET_OK ==
143 GNUNET_PROGRAM_run (argc, argv, "gnunet-gns",
144 _("GNUnet GNS zone manipulation tool"),
145 options,
146 &run, NULL)) ? 0 : 1;
147
148 return ret;
149}
150
151/* end of gnunet-gns.c */