aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-07-16 08:40:53 +0000
committerChristian Grothoff <christian@grothoff.org>2013-07-16 08:40:53 +0000
commit54a298da897504c59b7eb334357a6626b2e81406 (patch)
tree8bd782652623ba247ca92d3a9742f773cbb41b71
parent987795c6c7d4a0f04f989688341d93d684039a62 (diff)
downloadgnunet-54a298da897504c59b7eb334357a6626b2e81406.tar.gz
gnunet-54a298da897504c59b7eb334357a6626b2e81406.zip
initial version of gnunet-identity command-line tool
-rw-r--r--doc/man/Makefile.am1
-rw-r--r--doc/man/gnunet-identity.144
-rw-r--r--src/identity/gnunet-identity.c174
-rw-r--r--src/identity/gnunet-service-identity.c4
-rw-r--r--src/include/gnunet_disk_lib.h4
5 files changed, 218 insertions, 9 deletions
diff --git a/doc/man/Makefile.am b/doc/man/Makefile.am
index 4f4d736d6..db26f0d6a 100644
--- a/doc/man/Makefile.am
+++ b/doc/man/Makefile.am
@@ -15,6 +15,7 @@ man_MANS = \
15 gnunet-gns.1 \ 15 gnunet-gns.1 \
16 gnunet-gns-fcfsd.1 \ 16 gnunet-gns-fcfsd.1 \
17 gnunet-gns-proxy.1 \ 17 gnunet-gns-proxy.1 \
18 gnunet-identity.1 \
18 gnunet-namestore.1 \ 19 gnunet-namestore.1 \
19 gnunet-nat-server.1 \ 20 gnunet-nat-server.1 \
20 gnunet-peerinfo.1 \ 21 gnunet-peerinfo.1 \
diff --git a/doc/man/gnunet-identity.1 b/doc/man/gnunet-identity.1
new file mode 100644
index 000000000..6c48c8e2a
--- /dev/null
+++ b/doc/man/gnunet-identity.1
@@ -0,0 +1,44 @@
1.TH GNUNET-IDENTITY "1" "16 Jul 2013" "GNUnet"
2.SH NAME
3gnunet\-identity \- create, delete or list egos
4.SH SYNOPSIS
5.B gnunet\-identity
6[options]
7.SH DESCRIPTION
8.PP
9gnunet\-identity is a tool for managing egos. An ego is the persona that controls a namespace. It is identical to a public\-private ECC key pair.
10
11gnunet\-identity can be used to list all of the egos that were created locally, to create new egos, and to delete existing egos (the namespace will continue to exist, but it will be impossible to add additional data to it).
12
13Creating a new ego requires using the \-C option together with an identifier (name) that is to be used for the new ego. This identifier is only used locally for this peer and not shared with other peers.
14
15.TP
16\fB\-C NAME\fR, \fB\-\-create=NAME\fR
17Creates a new ego with the given NAME.
18
19.TP
20\fB\-D NAME\fR, \fB\-\-delete=NAME\fR
21Delete the ego with the given NAME.
22
23.TP
24\fB\-h\fR, \fB\-\-help\fR
25Print help page.
26
27.TP
28\fB\-L\fR, \fB\-\-list\fR
29list all ouf our egos
30
31.TP
32\fB\-m\fR, \fB\-\-monitor\fR
33run in monitor mode, listing all ouf our egos until CTRL-C is pressed
34
35
36.SH FILES
37.TP
38~/.gnunet/egos/
39Directory where the egos are stored (by default)
40
41.SH "REPORTING BUGS"
42Report bugs by using Mantis <https://gnunet.org/bugs/> or by sending electronic mail to <gnunet\-developers@gnu.org>
43.SH "SEE ALSO"
44\fBgnunet\-pseudonym\fP(1), \fBgnunet\-gns\fP(1)
diff --git a/src/identity/gnunet-identity.c b/src/identity/gnunet-identity.c
index 77ba6c2cd..15cb17d1b 100644
--- a/src/identity/gnunet-identity.c
+++ b/src/identity/gnunet-identity.c
@@ -19,7 +19,7 @@
19*/ 19*/
20/** 20/**
21 * @file identity/gnunet-identity.c 21 * @file identity/gnunet-identity.c
22 * @brief IDENTITY monitoring command line tool 22 * @brief IDENTITY management command line tool
23 * @author Christian Grothoff 23 * @author Christian Grothoff
24 */ 24 */
25#include "platform.h" 25#include "platform.h"
@@ -32,9 +32,34 @@
32static struct GNUNET_IDENTITY_Handle *sh; 32static struct GNUNET_IDENTITY_Handle *sh;
33 33
34/** 34/**
35 * Was verbose specified? 35 * Was "list" specified?
36 */ 36 */
37static int verbose; 37static int list;
38
39/**
40 * Was "monitor" specified?
41 */
42static int monitor;
43
44/**
45 * -C option
46 */
47static char *create_ego;
48
49/**
50 * -D option
51 */
52static char *delete_ego;
53
54/**
55 * Handle for create operation.
56 */
57static struct GNUNET_IDENTITY_Operation *create_op;
58
59/**
60 * Handle for delete operation.
61 */
62static struct GNUNET_IDENTITY_Operation *delete_op;
38 63
39 64
40/** 65/**
@@ -52,6 +77,119 @@ shutdown_task (void *cls,
52} 77}
53 78
54 79
80
81/**
82 * Test if we are finished yet.
83 */
84static void
85test_finished ()
86{
87 if ( (NULL == create_op) &&
88 (NULL == delete_op) &&
89 (! list) &&
90 (! monitor) )
91 GNUNET_SCHEDULER_shutdown ();
92}
93
94
95/**
96 * Deletion operation finished.
97 *
98 * @param cls pointer to operation handle
99 * @param emsg NULL on success, otherwise an error message
100 */
101static void
102delete_finished (void *cls,
103 const char *emsg)
104{
105 struct GNUNET_IDENTITY_Operation **op = cls;
106
107 *op = NULL;
108 if (NULL != emsg)
109 fprintf (stderr,
110 "%s\n",
111 gettext (emsg));
112 test_finished ();
113}
114
115
116/**
117 * Creation operation finished.
118 *
119 * @param cls pointer to operation handle
120 * @param ego ego handle
121 * @param ego_ctx context for application to store data for this ego
122 * (during the lifetime of this process, initially NULL)
123 * @param identifier identifier assigned by the user for this ego
124 */
125static void
126create_finished (void *cls,
127 struct GNUNET_IDENTITY_Ego *ego,
128 void **ctx,
129 const char *identifier)
130{
131 struct GNUNET_IDENTITY_Operation **op = cls;
132
133 *op = NULL;
134 if (NULL == ego)
135 fprintf (stderr,
136 "%s\n",
137 _("Failed to create ego\n"));
138 test_finished ();
139}
140
141
142/**
143 * If listing is enabled, prints information about the egos.
144 *
145 * This function is initially called for all egos and then again
146 * whenever a ego's identifier changes or if it is deleted. At the
147 * end of the initial pass over all egos, the function is once called
148 * with 'NULL' for 'ego'. That does NOT mean that the callback won't
149 * be invoked in the future or that there was an error.
150 *
151 * When used with 'GNUNET_IDENTITY_create' or 'GNUNET_IDENTITY_get',
152 * this function is only called ONCE, and 'NULL' being passed in
153 * 'ego' does indicate an error (i.e. name is taken or no default
154 * value is known). If 'ego' is non-NULL and if '*ctx'
155 * is set in those callbacks, the value WILL be passed to a subsequent
156 * call to the identity callback of 'GNUNET_IDENTITY_connect' (if
157 * that one was not NULL).
158 *
159 * When an identity is renamed, this function is called with the
160 * (known) ego but the NEW identifier.
161 *
162 * When an identity is deleted, this function is called with the
163 * (known) ego and "NULL" for the 'identifier'. In this case,
164 * the 'ego' is henceforth invalid (and the 'ctx' should also be
165 * cleaned up).
166 *
167 * @param cls closure
168 * @param ego ego handle
169 * @param ego_ctx context for application to store data for this ego
170 * (during the lifetime of this process, initially NULL)
171 * @param identifier identifier assigned by the user for this ego,
172 * NULL if the user just deleted the ego and it
173 * must thus no longer be used
174*/
175static void
176print_ego (void *cls,
177 struct GNUNET_IDENTITY_Ego *ego,
178 void **ctx,
179 const char *identifier)
180{
181
182 if (! (list | monitor))
183 return;
184 if ( (NULL == ego) && (! monitor) )
185 {
186 GNUNET_SCHEDULER_shutdown ();
187 return;
188 }
189 fprintf (stderr, "%s\n", identifier);
190}
191
192
55/** 193/**
56 * Main function that will be run by the scheduler. 194 * Main function that will be run by the scheduler.
57 * 195 *
@@ -64,9 +202,20 @@ static void
64run (void *cls, char *const *args, const char *cfgfile, 202run (void *cls, char *const *args, const char *cfgfile,
65 const struct GNUNET_CONFIGURATION_Handle *cfg) 203 const struct GNUNET_CONFIGURATION_Handle *cfg)
66{ 204{
67 sh = GNUNET_IDENTITY_connect (cfg, NULL, NULL); 205 sh = GNUNET_IDENTITY_connect (cfg, &print_ego, NULL);
206 if (NULL != delete_ego)
207 delete_op = GNUNET_IDENTITY_delete (sh,
208 delete_ego,
209 &delete_finished,
210 &delete_op);
211 if (NULL != create_ego)
212 create_op = GNUNET_IDENTITY_create (sh,
213 create_ego,
214 &create_finished,
215 &create_op);
68 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 216 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
69 &shutdown_task, NULL); 217 &shutdown_task, NULL);
218 test_finished ();
70} 219}
71 220
72 221
@@ -83,9 +232,18 @@ main (int argc, char *const *argv)
83 int res; 232 int res;
84 233
85 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 234 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
86 {'V', "verbose", NULL, 235 {'C', "create", "NAME",
87 gettext_noop ("verbose output"), 236 gettext_noop ("create ego NAME"),
88 0, &GNUNET_GETOPT_set_one, &verbose}, 237 1, &GNUNET_GETOPT_set_string, &create_ego},
238 {'D', "delete", "NAME",
239 gettext_noop ("delete ego NAME "),
240 1, &GNUNET_GETOPT_set_string, &delete_ego},
241 {'L', "list", NULL,
242 gettext_noop ("list all egos"),
243 0, &GNUNET_GETOPT_set_one, &list},
244 {'m', "monitor", NULL,
245 gettext_noop ("run in monitor mode egos"),
246 0, &GNUNET_GETOPT_set_one, &monitor},
89 GNUNET_GETOPT_OPTION_END 247 GNUNET_GETOPT_OPTION_END
90 }; 248 };
91 249
@@ -93,7 +251,7 @@ main (int argc, char *const *argv)
93 return 2; 251 return 2;
94 252
95 res = GNUNET_PROGRAM_run (argc, argv, "gnunet-identity", 253 res = GNUNET_PROGRAM_run (argc, argv, "gnunet-identity",
96 gettext_noop ("Print information about IDENTITY state"), 254 gettext_noop ("Maintain egos"),
97 options, &run, 255 options, &run,
98 NULL); 256 NULL);
99 GNUNET_free ((void *) argv); 257 GNUNET_free ((void *) argv);
diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c
index 4de7746b0..6c94f1c88 100644
--- a/src/identity/gnunet-service-identity.c
+++ b/src/identity/gnunet-service-identity.c
@@ -25,6 +25,10 @@
25 * 25 *
26 * The purpose of this service is to manage private keys that 26 * The purpose of this service is to manage private keys that
27 * represent the various egos/pseudonyms/identities of a GNUnet user. 27 * represent the various egos/pseudonyms/identities of a GNUnet user.
28 *
29 * FIXME:
30 * - hint for 'end of initial list' is not implemented
31 * (might ALSO be missing in client library!)
28 */ 32 */
29#include "platform.h" 33#include "platform.h"
30#include "gnunet_util_lib.h" 34#include "gnunet_util_lib.h"
diff --git a/src/include/gnunet_disk_lib.h b/src/include/gnunet_disk_lib.h
index c26f9dcda..5359e9d49 100644
--- a/src/include/gnunet_disk_lib.h
+++ b/src/include/gnunet_disk_lib.h
@@ -585,7 +585,9 @@ GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h,
585 */ 585 */
586ssize_t 586ssize_t
587GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle * h, 587GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle * h,
588 const void *buffer, size_t n); 588 const void *buffer,
589 size_t n);
590
589 591
590/** 592/**
591 * Write a buffer to a file. If the file is longer than 593 * Write a buffer to a file. If the file is longer than