aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/man/gnunet-identity.14
-rw-r--r--src/identity/gnunet-identity.c212
2 files changed, 91 insertions, 125 deletions
diff --git a/doc/man/gnunet-identity.1 b/doc/man/gnunet-identity.1
index 3f4510d99..4a8970cf5 100644
--- a/doc/man/gnunet-identity.1
+++ b/doc/man/gnunet-identity.1
@@ -58,9 +58,7 @@ Creates a new ego with the given
58Delete the ego with the given 58Delete the ego with the given
59.Ar NAME . 59.Ar NAME .
60.It Fl e Ar NAME | Fl \-ego= Ns Ar NAME 60.It Fl e Ar NAME | Fl \-ego= Ns Ar NAME
61Perform "set" operation with the respective ego. 61Perform "set" operation with the respective ego or restrict "display" operation to the respective ego.
62Needs to be used together with option
63.Fl s .
64.It Fl h | \-help 62.It Fl h | \-help
65Print the help page. 63Print the help page.
66.It d | \-display 64.It d | \-display
diff --git a/src/identity/gnunet-identity.c b/src/identity/gnunet-identity.c
index 583305710..8366b9918 100644
--- a/src/identity/gnunet-identity.c
+++ b/src/identity/gnunet-identity.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -119,6 +119,11 @@ shutdown_task (void *cls)
119 GNUNET_IDENTITY_cancel (delete_op); 119 GNUNET_IDENTITY_cancel (delete_op);
120 delete_op = NULL; 120 delete_op = NULL;
121 } 121 }
122 if (NULL != set_ego)
123 {
124 GNUNET_free (set_ego);
125 set_ego = NULL;
126 }
122 GNUNET_IDENTITY_disconnect (sh); 127 GNUNET_IDENTITY_disconnect (sh);
123 sh = NULL; 128 sh = NULL;
124} 129}
@@ -130,12 +135,8 @@ shutdown_task (void *cls)
130static void 135static void
131test_finished () 136test_finished ()
132{ 137{
133 if ( (NULL == create_op) && 138 if ((NULL == create_op) && (NULL == delete_op) && (NULL == set_op) &&
134 (NULL == delete_op) && 139 (NULL == set_subsystem) && (! list) && (! monitor))
135 (NULL == set_op) &&
136 (NULL == set_ego) &&
137 (! list) &&
138 (! monitor) )
139 { 140 {
140 if (TIMEOUT_STATUS_CODE == global_ret) 141 if (TIMEOUT_STATUS_CODE == global_ret)
141 global_ret = 0; 142 global_ret = 0;
@@ -151,16 +152,13 @@ test_finished ()
151 * @param emsg NULL on success, otherwise an error message 152 * @param emsg NULL on success, otherwise an error message
152 */ 153 */
153static void 154static void
154delete_finished (void *cls, 155delete_finished (void *cls, const char *emsg)
155 const char *emsg)
156{ 156{
157 struct GNUNET_IDENTITY_Operation **op = cls; 157 struct GNUNET_IDENTITY_Operation **op = cls;
158 158
159 *op = NULL; 159 *op = NULL;
160 if (NULL != emsg) 160 if (NULL != emsg)
161 fprintf (stderr, 161 fprintf (stderr, "%s\n", gettext (emsg));
162 "%s\n",
163 gettext (emsg));
164 test_finished (); 162 test_finished ();
165} 163}
166 164
@@ -174,30 +172,25 @@ delete_finished (void *cls,
174 */ 172 */
175static void 173static void
176create_finished (void *cls, 174create_finished (void *cls,
177 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, 175 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk,
178 const char *emsg) 176 const char *emsg)
179{ 177{
180 struct GNUNET_IDENTITY_Operation **op = cls; 178 struct GNUNET_IDENTITY_Operation **op = cls;
181 179
182 *op = NULL; 180 *op = NULL;
183 if (NULL == pk) 181 if (NULL == pk)
184 { 182 {
185 fprintf (stderr, 183 fprintf (stderr, _ ("Failed to create ego: %s\n"), emsg);
186 _("Failed to create ego: %s\n"),
187 emsg);
188 global_ret = 1; 184 global_ret = 1;
189 } 185 }
190 else if (verbose) 186 else if (verbose)
191 { 187 {
192 struct GNUNET_CRYPTO_EcdsaPublicKey pub; 188 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
193 char *pubs; 189 char *pubs;
194 190
195 GNUNET_CRYPTO_ecdsa_key_get_public (pk, 191 GNUNET_CRYPTO_ecdsa_key_get_public (pk, &pub);
196 &pub);
197 pubs = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pub); 192 pubs = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pub);
198 fprintf (stdout, 193 fprintf (stdout, "%s\n", pubs);
199 "%s\n",
200 pubs);
201 GNUNET_free (pubs); 194 GNUNET_free (pubs);
202 } 195 }
203 test_finished (); 196 test_finished ();
@@ -211,15 +204,12 @@ create_finished (void *cls,
211 * @param emsg error message (NULL on success) 204 * @param emsg error message (NULL on success)
212 */ 205 */
213static void 206static void
214set_done (void *cls, 207set_done (void *cls, const char *emsg)
215 const char *emsg)
216{ 208{
217 set_op = NULL; 209 set_op = NULL;
218 if (NULL != emsg) 210 if (NULL != emsg)
219 { 211 {
220 fprintf (stderr, 212 fprintf (stderr, _ ("Failed to set default ego: %s\n"), emsg);
221 _("Failed to set default ego: %s\n"),
222 emsg);
223 global_ret = 1; 213 global_ret = 1;
224 } 214 }
225 test_finished (); 215 test_finished ();
@@ -261,42 +251,34 @@ set_done (void *cls,
261*/ 251*/
262static void 252static void
263print_ego (void *cls, 253print_ego (void *cls,
264 struct GNUNET_IDENTITY_Ego *ego, 254 struct GNUNET_IDENTITY_Ego *ego,
265 void **ctx, 255 void **ctx,
266 const char *identifier) 256 const char *identifier)
267{ 257{
268 struct GNUNET_CRYPTO_EcdsaPublicKey pk; 258 struct GNUNET_CRYPTO_EcdsaPublicKey pk;
269 char *s; 259 char *s;
270 260
271 if ( (NULL != set_ego) && 261 if ((NULL != set_ego) && (NULL != set_subsystem) && (NULL != ego) &&
272 (NULL != ego) && 262 (NULL != identifier) && (0 == strcmp (identifier, set_ego)))
273 (NULL != identifier) && 263 {
274 (0 == strcmp (identifier, 264 set_op = GNUNET_IDENTITY_set (sh, set_subsystem, ego, &set_done, NULL);
275 set_ego)) ) 265 GNUNET_free (set_subsystem);
276 { 266 set_subsystem = NULL;
277 set_op = GNUNET_IDENTITY_set (sh, 267 GNUNET_free (set_ego);
278 set_subsystem, 268 set_ego = NULL;
279 ego, 269 }
280 &set_done, 270 if ((NULL == ego) && (NULL != set_ego) && (NULL != set_subsystem))
281 NULL);
282 GNUNET_free (set_subsystem);
283 set_subsystem = NULL;
284 GNUNET_free (set_ego);
285 set_ego = NULL;
286 }
287 if ( (NULL == ego) &&
288 (NULL != set_ego) )
289 { 271 {
290 fprintf (stderr, 272 fprintf (stderr,
291 "Could not set ego to `%s' for subsystem `%s', ego not known\n", 273 "Could not set ego to `%s' for subsystem `%s', ego not known\n",
292 set_ego, 274 set_ego,
293 set_subsystem); 275 set_subsystem);
294 GNUNET_free (set_subsystem); 276 GNUNET_free (set_subsystem);
295 set_subsystem = NULL; 277 set_subsystem = NULL;
296 GNUNET_free (set_ego); 278 GNUNET_free (set_ego);
297 set_ego = NULL; 279 set_ego = NULL;
298 } 280 }
299 if ( (NULL == ego) && (! monitor) ) 281 if ((NULL == ego) && (! monitor))
300 { 282 {
301 list = 0; 283 list = 0;
302 test_finished (); 284 test_finished ();
@@ -306,15 +288,12 @@ print_ego (void *cls,
306 return; 288 return;
307 if (NULL == ego) 289 if (NULL == ego)
308 return; 290 return;
309 GNUNET_IDENTITY_ego_get_public_key (ego, 291 if ((NULL != set_ego) && (0 != strcmp (identifier, set_ego)))
310 &pk); 292 return;
293 GNUNET_IDENTITY_ego_get_public_key (ego, &pk);
311 s = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); 294 s = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk);
312 if ( (monitor) || 295 if ((monitor) || (NULL != identifier))
313 (NULL != identifier) ) 296 fprintf (stdout, "%s - %s\n", identifier, s);
314 fprintf (stdout,
315 "%s - %s\n",
316 identifier,
317 s);
318 GNUNET_free (s); 297 GNUNET_free (s);
319} 298}
320 299
@@ -333,28 +312,19 @@ run (void *cls,
333 const char *cfgfile, 312 const char *cfgfile,
334 const struct GNUNET_CONFIGURATION_Handle *cfg) 313 const struct GNUNET_CONFIGURATION_Handle *cfg)
335{ 314{
336 if ( (NULL == set_subsystem) ^ 315 if ((NULL != set_subsystem) && (NULL == set_ego))
337 (NULL == set_ego) )
338 { 316 {
339 fprintf (stderr, 317 fprintf (stderr, "Option -s requires option -e to be specified as well.\n");
340 "Options -e and -s must always be specified together\n");
341 return; 318 return;
342 } 319 }
343 sh = GNUNET_IDENTITY_connect (cfg, 320 sh = GNUNET_IDENTITY_connect (cfg, &print_ego, NULL);
344 &print_ego,
345 NULL);
346 if (NULL != delete_ego) 321 if (NULL != delete_ego)
347 delete_op = GNUNET_IDENTITY_delete (sh, 322 delete_op =
348 delete_ego, 323 GNUNET_IDENTITY_delete (sh, delete_ego, &delete_finished, &delete_op);
349 &delete_finished,
350 &delete_op);
351 if (NULL != create_ego) 324 if (NULL != create_ego)
352 create_op = GNUNET_IDENTITY_create (sh, 325 create_op =
353 create_ego, 326 GNUNET_IDENTITY_create (sh, create_ego, &create_finished, &create_op);
354 &create_finished, 327 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
355 &create_op);
356 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
357 NULL);
358 test_finished (); 328 test_finished ();
359} 329}
360 330
@@ -369,55 +339,53 @@ run (void *cls,
369int 339int
370main (int argc, char *const *argv) 340main (int argc, char *const *argv)
371{ 341{
372 struct GNUNET_GETOPT_CommandLineOption options[] = { 342 struct GNUNET_GETOPT_CommandLineOption options[] =
373 GNUNET_GETOPT_option_string ('C', 343 {GNUNET_GETOPT_option_string ('C',
374 "create", 344 "create",
375 "NAME", 345 "NAME",
376 gettext_noop ("create ego NAME"), 346 gettext_noop ("create ego NAME"),
377 &create_ego), 347 &create_ego),
378 348 GNUNET_GETOPT_option_string ('D',
379 GNUNET_GETOPT_option_string ('D', 349 "delete",
380 "delete", 350 "NAME",
381 "NAME", 351 gettext_noop ("delete ego NAME "),
382 gettext_noop ("delete ego NAME "), 352 &delete_ego),
383 &delete_ego), 353 GNUNET_GETOPT_option_flag ('d',
384 354 "display",
385 GNUNET_GETOPT_option_flag ('d', 355 gettext_noop ("display all egos"),
386 "display", 356 &list),
387 gettext_noop ("display all egos"), 357 GNUNET_GETOPT_option_string (
388 &list), 358 'e',
389 359 "ego",
390 GNUNET_GETOPT_option_string ('e', 360 "NAME",
391 "ego", 361 gettext_noop (
392 "NAME", 362 "set default identity to NAME for a subsystem SUBSYSTEM (use together with -s) or restrict results to NAME (use together with -d)"),
393 gettext_noop ("set default identity to EGO for a subsystem SUBSYSTEM (use together with -s)"), 363 &set_ego),
394 &set_ego), 364 GNUNET_GETOPT_option_flag ('m',
395 365 "monitor",
396 GNUNET_GETOPT_option_flag ('m', 366 gettext_noop ("run in monitor mode egos"),
397 "monitor", 367 &monitor),
398 gettext_noop ("run in monitor mode egos"), 368 GNUNET_GETOPT_option_string (
399 &monitor), 369 's',
400 370 "set",
401 GNUNET_GETOPT_option_string ('s', 371 "SUBSYSTEM",
402 "set", 372 gettext_noop (
403 "SUBSYSTEM", 373 "set default identity to EGO for a subsystem SUBSYSTEM (use together with -e)"),
404 gettext_noop ("set default identity to EGO for a subsystem SUBSYSTEM (use together with -e)"), 374 &set_subsystem),
405 &set_subsystem), 375 GNUNET_GETOPT_option_verbose (&verbose),
406 GNUNET_GETOPT_option_verbose (&verbose), 376 GNUNET_GETOPT_OPTION_END};
407 GNUNET_GETOPT_OPTION_END
408 };
409 int res; 377 int res;
410 378
411 if (GNUNET_OK != 379 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
412 GNUNET_STRINGS_get_utf8_args (argc, argv,
413 &argc, &argv))
414 return 4; 380 return 4;
415 global_ret = TIMEOUT_STATUS_CODE; /* timeout */ 381 global_ret = TIMEOUT_STATUS_CODE; /* timeout */
416 res = GNUNET_PROGRAM_run (argc, argv, 382 res = GNUNET_PROGRAM_run (argc,
383 argv,
417 "gnunet-identity", 384 "gnunet-identity",
418 gettext_noop ("Maintain egos"), 385 gettext_noop ("Maintain egos"),
419 options, &run, 386 options,
420 NULL); 387 &run,
388 NULL);
421 GNUNET_free ((void *) argv); 389 GNUNET_free ((void *) argv);
422 390
423 if (GNUNET_OK != res) 391 if (GNUNET_OK != res)