2 This file is part of GNUnet.
3 (C) 2012 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @brief command line tool to manipulate the local zone
23 * @author Christian Grothoff
29 #include <gnunet_util_lib.h>
30 #include <gnunet_namestore_service.h>
33 * Handle to the namestore.
35 static struct GNUNET_NAMESTORE_Handle *ns;
38 * Hash of the public key of our zone.
40 static GNUNET_HashCode zone;
43 * Private key for the our zone.
45 static struct GNUNET_CRYPTO_RsaPrivateKey *zone_pkey;
48 * Keyfile to manipulate.
54 * Task run on shutdown. Cleans up everything.
57 * @param tc scheduler context
60 do_shutdown (void *cls,
61 const struct GNUNET_SCHEDULER_TaskContext *tc)
65 GNUNET_NAMESTORE_disconnect (ns, GNUNET_NO);
68 if (NULL != zone_pkey)
70 GNUNET_CRYPTO_rsa_key_free (zone_pkey);
77 * Main function that will be run.
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
85 run (void *cls, char *const *args, const char *cfgfile,
86 const struct GNUNET_CONFIGURATION_Handle *cfg)
88 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub;
93 _("Option `%s' not given, but I need a zone key file!\n"),
97 zone_pkey = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
98 GNUNET_free (keyfile);
100 if (NULL == zone_pkey)
102 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
103 _("Failed to read or create private zone key\n"));
106 GNUNET_CRYPTO_rsa_key_get_public (zone_pkey,
108 GNUNET_CRYPTO_hash (&pub, sizeof (pub), &zone);
109 ns = GNUNET_NAMESTORE_connect (cfg);
112 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
113 _("Failed to connect to namestore\n"));
116 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
122 * The main function for gnunet-gns.
124 * @param argc number of arguments from the command line
125 * @param argv command line arguments
126 * @return 0 ok, 1 on error
129 main (int argc, char *const *argv)
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
140 GNUNET_log_setup ("gnunet-gns", "WARNING", NULL);
143 GNUNET_PROGRAM_run (argc, argv, "gnunet-gns",
144 _("GNUnet GNS zone manipulation tool"),
146 &run, NULL)) ? 0 : 1;
151 /* end of gnunet-gns.c */