From 3636ea628d051cf2ba7a9038c50528c561d0aeaa Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 19 Dec 2020 18:43:38 +0100 Subject: change GNUNET_DISK_fn_write() to always do atomic writes and to NOT overwrite existing files; also change the return value to not return the size of the written file but GNUNET_OK on success, and integrate creating the directory if needed; breaks API, hence bumping libgnunetutil version --- src/fs/gnunet-search.c | 15 +- src/fs/test_fs_download.c | 7 +- src/fs/test_fs_file_information.c | 6 +- src/fs/test_fs_list_indexed.c | 6 +- src/fs/test_fs_publish.c | 6 +- src/fs/test_fs_publish_persistence.c | 6 +- src/fs/test_fs_unindex.c | 3 +- src/fs/test_fs_unindex_persistence.c | 3 +- src/identity/gnunet-service-identity.c | 6 +- src/include/gnunet_common.h | 2 +- src/include/gnunet_configuration_lib.h | 59 ++-- src/include/gnunet_crypto_lib.h | 30 +- src/include/gnunet_disk_lib.h | 46 +-- src/nse/gnunet-service-nse.c | 23 +- src/peerinfo-tool/gnunet-peerinfo.c | 15 +- src/peerinfo/gnunet-service-peerinfo.c | 31 +- src/revocation/gnunet-revocation.c | 21 +- src/testbed/gnunet_mpi_test.c | 2 +- src/topology/friends.c | 9 - src/util/Makefile.am | 2 +- src/util/configuration.c | 385 +++------------------- src/util/crypto_ecc.c | 251 +-------------- src/util/crypto_ecc_setup.c | 118 +------ src/util/crypto_rsa.c | 181 +---------- src/util/disk.c | 561 +++++++++------------------------ src/util/gnunet-scrypt.c | 15 +- src/util/test_disk.c | 4 +- 27 files changed, 408 insertions(+), 1405 deletions(-) diff --git a/src/fs/gnunet-search.c b/src/fs/gnunet-search.c index d25ae55e6..e49609b18 100644 --- a/src/fs/gnunet-search.c +++ b/src/fs/gnunet-search.c @@ -111,17 +111,20 @@ clean_task (void *cls) ctx = NULL; if (output_filename == NULL) return; - if (GNUNET_OK != GNUNET_FS_directory_builder_finish (db, &dsize, &ddata)) + if (GNUNET_OK != + GNUNET_FS_directory_builder_finish (db, &dsize, &ddata)) { GNUNET_break (0); GNUNET_free (output_filename); return; } - if (dsize != GNUNET_DISK_fn_write (output_filename, - ddata, - dsize, - GNUNET_DISK_PERM_USER_READ - | GNUNET_DISK_PERM_USER_WRITE)) + (void) GNUNET_DISK_directory_remove (output_filename); + if (GNUNET_OK != + GNUNET_DISK_fn_write (output_filename, + ddata, + dsize, + GNUNET_DISK_PERM_USER_READ + | GNUNET_DISK_PERM_USER_WRITE)) { fprintf (stderr, _ ("Failed to write directory with search results to `%s'\n"), diff --git a/src/fs/test_fs_download.c b/src/fs/test_fs_download.c index 2be2e7f6a..2fe0da77c 100644 --- a/src/fs/test_fs_download.c +++ b/src/fs/test_fs_download.c @@ -299,8 +299,11 @@ run (void *cls, "USE_INDEX")) { fn1 = GNUNET_DISK_mktemp ("gnunet-download-indexed-test"); - GNUNET_assert (FILESIZE == - GNUNET_DISK_fn_write (fn1, buf, FILESIZE, + (void) GNUNET_DISK_directory_remove (fn1); + GNUNET_assert (GNUNET_OK == + GNUNET_DISK_fn_write (fn1, + buf, + FILESIZE, GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)); GNUNET_free (buf); diff --git a/src/fs/test_fs_file_information.c b/src/fs/test_fs_file_information.c index 9305471d6..9d0978e06 100644 --- a/src/fs/test_fs_file_information.c +++ b/src/fs/test_fs_file_information.c @@ -82,7 +82,8 @@ run (void *cls, char *const *args, const char *cfgfile, buf = GNUNET_malloc (FILESIZE); for (i = 0; i < FILESIZE; i++) buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); - GNUNET_assert (FILESIZE == + (void) GNUNET_DISK_directory_remove (fn1); + GNUNET_assert (GNUNET_OK == GNUNET_DISK_fn_write (fn1, buf, FILESIZE, GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)); @@ -92,7 +93,8 @@ run (void *cls, char *const *args, const char *cfgfile, buf = GNUNET_malloc (FILESIZE); for (i = 0; i < FILESIZE; i++) buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); - GNUNET_assert (FILESIZE == + (void) GNUNET_DISK_directory_remove (fn2); + GNUNET_assert (GNUNET_OK == GNUNET_DISK_fn_write (fn2, buf, FILESIZE, GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)); diff --git a/src/fs/test_fs_list_indexed.c b/src/fs/test_fs_list_indexed.c index 93367883f..2f04a017a 100644 --- a/src/fs/test_fs_list_indexed.c +++ b/src/fs/test_fs_list_indexed.c @@ -198,7 +198,8 @@ run (void *cls, buf = GNUNET_malloc (FILESIZE); for (i = 0; i < FILESIZE; i++) buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); - GNUNET_assert (FILESIZE == + (void) GNUNET_DISK_directory_remove (fn1); + GNUNET_assert (GNUNET_OK == GNUNET_DISK_fn_write (fn1, buf, FILESIZE, GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)); @@ -208,7 +209,8 @@ run (void *cls, buf = GNUNET_malloc (FILESIZE); for (i = 0; i < FILESIZE; i++) buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); - GNUNET_assert (FILESIZE == + (void) GNUNET_DISK_directory_remove (fn2); + GNUNET_assert (GNUNET_OK == GNUNET_DISK_fn_write (fn2, buf, FILESIZE, GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)); diff --git a/src/fs/test_fs_publish.c b/src/fs/test_fs_publish.c index c42e546e3..2ffc722da 100644 --- a/src/fs/test_fs_publish.c +++ b/src/fs/test_fs_publish.c @@ -184,7 +184,8 @@ run (void *cls, buf = GNUNET_malloc (FILESIZE); for (i = 0; i < FILESIZE; i++) buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); - GNUNET_assert (FILESIZE == + (void) GNUNET_DISK_directory_remove (fn1); + GNUNET_assert (GNUNET_OK == GNUNET_DISK_fn_write (fn1, buf, FILESIZE, GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)); @@ -194,7 +195,8 @@ run (void *cls, buf = GNUNET_malloc (FILESIZE); for (i = 0; i < FILESIZE; i++) buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); - GNUNET_assert (FILESIZE == + (void) GNUNET_DISK_directory_remove (fn2); + GNUNET_assert (GNUNET_OK == GNUNET_DISK_fn_write (fn2, buf, FILESIZE, GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)); diff --git a/src/fs/test_fs_publish_persistence.c b/src/fs/test_fs_publish_persistence.c index 4ec39d06e..da0209793 100644 --- a/src/fs/test_fs_publish_persistence.c +++ b/src/fs/test_fs_publish_persistence.c @@ -258,7 +258,8 @@ run (void *cls, buf = GNUNET_malloc (FILESIZE); for (i = 0; i < FILESIZE; i++) buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); - GNUNET_assert (FILESIZE == + (void) GNUNET_DISK_directory_remove (fn1); + GNUNET_assert (GNUNET_OK == GNUNET_DISK_fn_write (fn1, buf, FILESIZE, GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)); @@ -268,7 +269,8 @@ run (void *cls, buf = GNUNET_malloc (FILESIZE); for (i = 0; i < FILESIZE; i++) buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); - GNUNET_assert (FILESIZE == + (void) GNUNET_DISK_directory_remove (fn2); + GNUNET_assert (GNUNET_OK == GNUNET_DISK_fn_write (fn2, buf, FILESIZE, GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)); diff --git a/src/fs/test_fs_unindex.c b/src/fs/test_fs_unindex.c index a11c574c1..992672244 100644 --- a/src/fs/test_fs_unindex.c +++ b/src/fs/test_fs_unindex.c @@ -197,7 +197,8 @@ run (void *cls, buf = GNUNET_malloc (FILESIZE); for (i = 0; i < FILESIZE; i++) buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); - GNUNET_assert (FILESIZE == + (void) GNUNET_DISK_directory_remove (fn); + GNUNET_assert (GNUNET_OK == GNUNET_DISK_fn_write (fn, buf, FILESIZE, GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)); diff --git a/src/fs/test_fs_unindex_persistence.c b/src/fs/test_fs_unindex_persistence.c index c3668f4e0..802aaf7ca 100644 --- a/src/fs/test_fs_unindex_persistence.c +++ b/src/fs/test_fs_unindex_persistence.c @@ -267,7 +267,8 @@ run (void *cls, buf = GNUNET_malloc (FILESIZE); for (i = 0; i < FILESIZE; i++) buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); - GNUNET_assert (FILESIZE == + (void) GNUNET_DISK_directory_remove (fn); + GNUNET_assert (GNUNET_OK == GNUNET_DISK_fn_write (fn, buf, FILESIZE, GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)); diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c index 6cdb1c2f7..2bb4b0897 100644 --- a/src/identity/gnunet-service-identity.c +++ b/src/identity/gnunet-service-identity.c @@ -697,8 +697,7 @@ check_create_message (void *cls, /** - * Handler for CREATE message from client, creates - * new identity. + * Handler for CREATE message from client, creates new identity. * * @param cls unused * @param client who sent the message @@ -737,8 +736,7 @@ handle_create_message (void *cls, ego); send_result_code (client, 0, NULL); fn = get_ego_filename (ego); - (void) GNUNET_DISK_directory_create_for_file (fn); - if (sizeof(struct GNUNET_IDENTITY_PrivateKey) != + if (GNUNET_OK != GNUNET_DISK_fn_write (fn, &crm->private_key, sizeof(struct GNUNET_IDENTITY_PrivateKey), diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h index bc2055709..b5af1146d 100644 --- a/src/include/gnunet_common.h +++ b/src/include/gnunet_common.h @@ -345,7 +345,7 @@ struct GNUNET_AsyncScopeSave * #GNUNET_NO to stop iteration with no error, * #GNUNET_SYSERR to abort iteration with error! */ -typedef int +typedef enum GNUNET_GenericReturnValue (*GNUNET_FileNameCallback) (void *cls, const char *filename); diff --git a/src/include/gnunet_configuration_lib.h b/src/include/gnunet_configuration_lib.h index b4e7f7d8f..ad55c1b9a 100644 --- a/src/include/gnunet_configuration_lib.h +++ b/src/include/gnunet_configuration_lib.h @@ -82,7 +82,7 @@ GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg); * @param filename name of the configuration file, NULL to load defaults * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename); @@ -95,7 +95,7 @@ GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, * @param defaults_d directory with the defaults * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg, const char *defaults_d); @@ -120,7 +120,7 @@ GNUNET_CONFIGURATION_default (void); * @param filename name of the configuration file * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename); @@ -149,7 +149,7 @@ GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, * when we come across them * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, const char *mem, size_t size, @@ -163,19 +163,20 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, * @param filename where to write the configuration * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename); /** * Write only configuration entries that have been changed to configuration file + * * @param cfg_default default configuration * @param cfg_new new configuration * @param filename where to write the configuration diff between default and new * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write_diffs (const struct GNUNET_CONFIGURATION_Handle *cfg_default, const struct @@ -204,7 +205,7 @@ GNUNET_CONFIGURATION_get_diff (const struct * @param cfg configuration to inspect * @return #GNUNET_NO if clean, #GNUNET_YES if dirty, #GNUNET_SYSERR on error (i.e. last save failed) */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg); @@ -215,7 +216,7 @@ GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg); * @param cfg the configuration * @return status code */ -typedef int +typedef enum GNUNET_GenericReturnValue (*GNUNET_CONFIGURATION_Callback)(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg); @@ -231,7 +232,7 @@ typedef int * @return #GNUNET_SYSERR if parsing the configuration failed, * otherwise return value from @a cb. */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse_and_run (const char *filename, GNUNET_CONFIGURATION_Callback cb, void *cb_cls); @@ -311,7 +312,7 @@ GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, * @param number where to store the numeric value of the option * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, @@ -328,7 +329,7 @@ GNUNET_CONFIGURATION_get_value_number (const struct * @param number where to store the floating value of the option * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_float (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, @@ -345,7 +346,7 @@ GNUNET_CONFIGURATION_get_value_float (const struct * @param time set to the time value stored in the configuration * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, @@ -362,7 +363,7 @@ GNUNET_CONFIGURATION_get_value_time (const struct * @param size set to the size in bytes as stored in the configuration * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_size (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, @@ -378,7 +379,7 @@ GNUNET_CONFIGURATION_get_value_size (const struct * @param option option of interest * @return #GNUNET_YES if so, #GNUNET_NO if not. */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option); @@ -394,12 +395,12 @@ GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg, * value, or NULL if option is not specified * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ -int -GNUNET_CONFIGURATION_get_value_string (const struct - GNUNET_CONFIGURATION_Handle *cfg, - const char *section, - const char *option, - char **value); +enum GNUNET_GenericReturnValue +GNUNET_CONFIGURATION_get_value_string ( + const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *section, + const char *option, + char **value); /** @@ -413,7 +414,7 @@ GNUNET_CONFIGURATION_get_value_string (const struct * value, or NULL if option is not specified * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, @@ -466,7 +467,7 @@ GNUNET_CONFIGURATION_iterate_section_values (const struct * or NULL if option is not specified and no default given * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, @@ -483,7 +484,7 @@ GNUNET_CONFIGURATION_get_value_choice (const struct * @param option option of interest * @return #GNUNET_YES, #GNUNET_NO or if option has no valid value, #GNUNET_SYSERR */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, @@ -502,7 +503,7 @@ GNUNET_CONFIGURATION_get_value_yesno (const struct * #GNUNET_NO is the value does not exist * #GNUNET_SYSERR on decoding error */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, @@ -527,9 +528,9 @@ GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg, * @return $-expanded string */ char * -GNUNET_CONFIGURATION_expand_dollar (const struct - GNUNET_CONFIGURATION_Handle *cfg, - char *orig); +GNUNET_CONFIGURATION_expand_dollar ( + const struct GNUNET_CONFIGURATION_Handle *cfg, + char *orig); /** @@ -573,7 +574,7 @@ GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg, * @return #GNUNET_OK on success, * #GNUNET_SYSERR if the filename is not in the list */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_remove_value_filename (struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, @@ -592,7 +593,7 @@ GNUNET_CONFIGURATION_remove_value_filename (struct * @return #GNUNET_OK on success, * #GNUNET_SYSERR if the filename already in the list */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_append_value_filename (struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index 6dc56f0e4..5521dad3c 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h @@ -1023,7 +1023,7 @@ GNUNET_CRYPTO_hmac_derive_key ( * @param ... pair of void * & size_t for context chunks, terminated by NULL * @return #GNUNET_YES on success */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hkdf (void *result, size_t out_len, int xtr_algo, @@ -1049,7 +1049,7 @@ GNUNET_CRYPTO_hkdf (void *result, * @param argp va_list of void * & size_t pairs for context chunks * @return #GNUNET_YES on success */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, int xtr_algo, @@ -1072,7 +1072,7 @@ GNUNET_CRYPTO_hkdf_v (void *result, * @param argp va_list of void * & size_t pairs for context chunks * @return #GNUNET_YES on success */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_kdf_v (void *result, size_t out_len, const void *xts, @@ -1116,7 +1116,7 @@ GNUNET_CRYPTO_kdf_mod_mpi (gcry_mpi_t *r, * @param ... void * & size_t pairs for context chunks * @return #GNUNET_YES on success */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_kdf (void *result, size_t out_len, const void *xts, @@ -1215,7 +1215,7 @@ GNUNET_CRYPTO_eddsa_public_key_to_string ( * @param pub where to store the public key * @return #GNUNET_OK on success */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_public_key_from_string ( const char *enc, size_t enclen, @@ -1245,7 +1245,7 @@ GNUNET_CRYPTO_eddsa_private_key_from_string ( * @param pub where to store the public key * @return #GNUNET_OK on success */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_public_key_from_string ( const char *enc, size_t enclen, @@ -1267,7 +1267,7 @@ GNUNET_CRYPTO_eddsa_public_key_from_string ( * @return #GNUNET_OK on success, #GNUNET_NO if @a do_create was set but * we found an existing file, #GNUNET_SYSERR on failure */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_key_from_file (const char *filename, int do_create, struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey); @@ -1606,7 +1606,7 @@ GNUNET_CRYPTO_ecc_dlog_release (struct GNUNET_CRYPTO_EccDlogContext *dlc); * @param key_material where to write the key material (xyG) * @return #GNUNET_SYSERR on error, #GNUNET_OK on success */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_HashCode *key_material); @@ -1622,7 +1622,7 @@ GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, * @param key_material where to write the key material H(h(x)yG) * @return #GNUNET_SYSERR on error, #GNUNET_OK on success */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_ecdh (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_HashCode *key_material); @@ -1637,7 +1637,7 @@ GNUNET_CRYPTO_eddsa_ecdh (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, * @param key_material where to write the key material H(h(x)yG) * @return #GNUNET_SYSERR on error, #GNUNET_OK on success */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_ecdh (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_HashCode *key_material); @@ -1653,7 +1653,7 @@ GNUNET_CRYPTO_ecdsa_ecdh (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, * @param key_material where to write the key material H(yX)=H(h(x)yG) * @return #GNUNET_SYSERR on error, #GNUNET_OK on success */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdh_eddsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, const struct GNUNET_CRYPTO_EddsaPublicKey *pub, struct GNUNET_HashCode *key_material); @@ -1668,7 +1668,7 @@ GNUNET_CRYPTO_ecdh_eddsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, * @param key_material where to write the key material H(yX)=H(h(x)yG) * @return #GNUNET_SYSERR on error, #GNUNET_OK on success */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdh_ecdsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, struct GNUNET_HashCode *key_material); @@ -1689,7 +1689,7 @@ GNUNET_CRYPTO_ecdh_ecdsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, * @param[out] sig where to write the signature * @return #GNUNET_SYSERR on error, #GNUNET_OK on success */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_sign_ ( const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, @@ -1736,7 +1736,7 @@ GNUNET_CRYPTO_eddsa_sign_ ( * @param[out] sig where to write the signature * @return #GNUNET_SYSERR on error, #GNUNET_OK on success */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_sign_ ( const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, @@ -2333,7 +2333,7 @@ GNUNET_CRYPTO_rsa_unblind (const struct GNUNET_CRYPTO_RsaSignature *sig, * @param public_key public key of the signer * @returns #GNUNET_YES if ok, #GNUNET_NO if RSA key is malicious, #GNUNET_SYSERR if signature */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_rsa_verify (const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_RsaSignature *sig, const struct GNUNET_CRYPTO_RsaPublicKey *public_key); diff --git a/src/include/gnunet_disk_lib.h b/src/include/gnunet_disk_lib.h index 3f29dc2e4..b794088c4 100644 --- a/src/include/gnunet_disk_lib.h +++ b/src/include/gnunet_disk_lib.h @@ -251,7 +251,7 @@ enum GNUNET_DISK_PipeEnd * @param h handle to check * @return #GNUNET_YES if invalid, #GNUNET_NO if valid */ -int +enum GNUNET_GenericReturnValue GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h); @@ -263,7 +263,7 @@ GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h); * @return #GNUNET_YES if yes, #GNUNET_NO if not a file, #GNUNET_SYSERR if something * else (will print an error message in that case, too). */ -int +enum GNUNET_GenericReturnValue GNUNET_DISK_file_test (const char *fil); @@ -304,7 +304,7 @@ GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, * and return #GNUNET_SYSERR for directories. * @return #GNUNET_SYSERR on error, #GNUNET_OK on success */ -int +enum GNUNET_GenericReturnValue GNUNET_DISK_file_size (const char *filename, uint64_t *size, int include_symbolic_links, @@ -326,7 +326,7 @@ GNUNET_DISK_file_size (const char *filename, * @param ino set to the inode ID * @return #GNUNET_OK on success */ -int +enum GNUNET_GenericReturnValue GNUNET_DISK_file_get_identifiers (const char *filename, uint64_t *dev, uint64_t *ino); @@ -385,7 +385,7 @@ GNUNET_DISK_file_open (const char *fn, * @param size where to write size of the file * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ -int +enum GNUNET_GenericReturnValue GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh, off_t *size); @@ -447,7 +447,7 @@ GNUNET_DISK_pipe_from_fd (enum GNUNET_DISK_PipeFlags pf, * @param p pipe * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise */ -int +enum GNUNET_GenericReturnValue GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p); @@ -458,7 +458,7 @@ GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p); * @param end which end of the pipe to close * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise */ -int +enum GNUNET_GenericReturnValue GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd end); @@ -485,7 +485,7 @@ GNUNET_DISK_pipe_detach_end (struct GNUNET_DISK_PipeHandle *p, * @param h file handle * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise */ -int +enum GNUNET_GenericReturnValue GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h); @@ -609,16 +609,19 @@ GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle *h, /** - * Write a buffer to a file. If the file is longer than - * the given buffer size, it will be truncated. + * Write a buffer to a file atomically. The directory is created if + * necessary. Fail if @a filename already exists or if not exactly @a buf + * with @a buf_size bytes could be written to @a filename. * * @param fn file name * @param buffer the data to write * @param n number of bytes to write * @param mode file permissions - * @return number of bytes written on success, #GNUNET_SYSERR on error + * @return #GNUNET_OK on success, + * #GNUNET_NO if a file existed under @a filename + * #GNUNET_SYSERR on failure */ -ssize_t +enum GNUNET_GenericReturnValue GNUNET_DISK_fn_write (const char *fn, const void *buffer, size_t n, @@ -632,7 +635,7 @@ GNUNET_DISK_fn_write (const char *fn, * @param dst destination file name * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ -int +enum GNUNET_GenericReturnValue GNUNET_DISK_file_copy (const char *src, const char *dst); @@ -659,7 +662,7 @@ GNUNET_DISK_directory_scan (const char *dir_name, * @returns #GNUNET_OK on success, #GNUNET_SYSERR on failure, * #GNUNET_NO if directory exists but is not writeable */ -int +enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file (const char *filename); @@ -675,8 +678,9 @@ GNUNET_DISK_directory_create_for_file (const char *filename); * @return #GNUNET_YES if yes, #GNUNET_NO if not; #GNUNET_SYSERR if it * does not exist or `stat`ed */ -int -GNUNET_DISK_directory_test (const char *fil, int is_readable); +enum GNUNET_GenericReturnValue +GNUNET_DISK_directory_test (const char *fil, + int is_readable); /** @@ -685,7 +689,7 @@ GNUNET_DISK_directory_test (const char *fil, int is_readable); * @param filename the file to remove * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ -int +enum GNUNET_GenericReturnValue GNUNET_DISK_directory_remove (const char *filename); @@ -707,7 +711,7 @@ GNUNET_DISK_purge_cfg_dir (const char *cfg_filename, * @param dir the directory to create * @returns #GNUNET_SYSERR on failure, #GNUNET_OK otherwise */ -int +enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create (const char *dir); @@ -725,7 +729,7 @@ GNUNET_DISK_filename_canonicalize (char *fn); * @param user new owner of the file * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure */ -int +enum GNUNET_GenericReturnValue GNUNET_DISK_file_change_owner (const char *filename, const char *user); @@ -758,7 +762,7 @@ GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h, * @param h mapping handle * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise */ -int +enum GNUNET_GenericReturnValue GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h); @@ -768,7 +772,7 @@ GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h); * @param h handle to an open file * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise */ -int +enum GNUNET_GenericReturnValue GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h); diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c index dfd71e57a..8e9cd0c9d 100644 --- a/src/nse/gnunet-service-nse.c +++ b/src/nse/gnunet-service-nse.c @@ -824,19 +824,26 @@ check_proof_of_work (const struct GNUNET_CRYPTO_EddsaPublicKey *pkey, * Write our current proof to disk. */ static void -write_proof () +write_proof (void) { char *proof; if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "PROOFFILE", &proof)) + GNUNET_CONFIGURATION_get_value_filename (cfg, + "NSE", + "PROOFFILE", + &proof)) return; - if (sizeof(my_proof) != GNUNET_DISK_fn_write (proof, - &my_proof, - sizeof(my_proof), - GNUNET_DISK_PERM_USER_READ - | GNUNET_DISK_PERM_USER_WRITE)) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", proof); + (void) GNUNET_DISK_directory_remove (proof); + if (GNUNET_OK != + GNUNET_DISK_fn_write (proof, + &my_proof, + sizeof(my_proof), + GNUNET_DISK_PERM_USER_READ + | GNUNET_DISK_PERM_USER_WRITE)) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, + "write", + proof); GNUNET_free (proof); } diff --git a/src/peerinfo-tool/gnunet-peerinfo.c b/src/peerinfo-tool/gnunet-peerinfo.c index 987c7c3a0..8b149c98e 100644 --- a/src/peerinfo-tool/gnunet-peerinfo.c +++ b/src/peerinfo-tool/gnunet-peerinfo.c @@ -451,13 +451,14 @@ dump_my_hello () fprintf (stderr, _ ("Failure: Received invalid %s\n"), "HELLO"); return; } - if (GNUNET_SYSERR == GNUNET_DISK_fn_write (dump_hello, - my_hello, - size, - GNUNET_DISK_PERM_USER_READ - | GNUNET_DISK_PERM_USER_WRITE - | GNUNET_DISK_PERM_GROUP_READ - | GNUNET_DISK_PERM_OTHER_READ)) + if (GNUNET_SYSERR == + GNUNET_DISK_fn_write (dump_hello, + my_hello, + size, + GNUNET_DISK_PERM_USER_READ + | GNUNET_DISK_PERM_USER_WRITE + | GNUNET_DISK_PERM_GROUP_READ + | GNUNET_DISK_PERM_OTHER_READ)) { fprintf (stderr, _ ("Failed to write HELLO with %u bytes to file `%s'\n"), diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c index 79af90dd4..1b1232ecb 100644 --- a/src/peerinfo/gnunet-service-peerinfo.c +++ b/src/peerinfo/gnunet-service-peerinfo.c @@ -807,13 +807,14 @@ update_hello (const struct GNUNET_PeerIdentity *peer, } GNUNET_assert (pos == size); - if (GNUNET_SYSERR == GNUNET_DISK_fn_write (fn, - buffer, - size, - GNUNET_DISK_PERM_USER_READ - | GNUNET_DISK_PERM_USER_WRITE - | GNUNET_DISK_PERM_GROUP_READ - | GNUNET_DISK_PERM_OTHER_READ)) + if (GNUNET_SYSERR == + GNUNET_DISK_fn_write (fn, + buffer, + size, + GNUNET_DISK_PERM_USER_READ + | GNUNET_DISK_PERM_USER_WRITE + | GNUNET_DISK_PERM_GROUP_READ + | GNUNET_DISK_PERM_OTHER_READ)) GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn); else GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -987,13 +988,15 @@ discard_hosts_helper (void *cls, const char *fn) if (0 < write_pos) { - GNUNET_DISK_fn_write (fn, - writebuffer, - write_pos, - GNUNET_DISK_PERM_USER_READ - | GNUNET_DISK_PERM_USER_WRITE - | GNUNET_DISK_PERM_GROUP_READ - | GNUNET_DISK_PERM_OTHER_READ); + (void) GNUNET_DISK_directory_remove (fn); + GNUNET_assert (GNUNET_OK == + GNUNET_DISK_fn_write (fn, + writebuffer, + write_pos, + GNUNET_DISK_PERM_USER_READ + | GNUNET_DISK_PERM_USER_WRITE + | GNUNET_DISK_PERM_GROUP_READ + | GNUNET_DISK_PERM_OTHER_READ)); } else if (0 != unlink (fn)) GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING diff --git a/src/revocation/gnunet-revocation.c b/src/revocation/gnunet-revocation.c index d59ea7c81..b5737158b 100644 --- a/src/revocation/gnunet-revocation.c +++ b/src/revocation/gnunet-revocation.c @@ -230,7 +230,7 @@ sync_pow () { size_t psize = GNUNET_REVOCATION_proof_get_size (proof_of_work); if ((NULL != filename) && - (psize != + (GNUNET_OK != GNUNET_DISK_fn_write (filename, proof_of_work, psize, @@ -280,14 +280,17 @@ calculate_pow (void *cls) if (GNUNET_OK == GNUNET_REVOCATION_pow_round (ph)) { psize = GNUNET_REVOCATION_proof_get_size (proof_of_work); - if ((NULL != filename) && - (psize != - GNUNET_DISK_fn_write (filename, - proof_of_work, - psize, - GNUNET_DISK_PERM_USER_READ - | GNUNET_DISK_PERM_USER_WRITE))) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename); + if (NULL != filename) + { + (void) GNUNET_DISK_directory_remove (filename); + if (GNUNET_OK != + GNUNET_DISK_fn_write (filename, + proof_of_work, + psize, + GNUNET_DISK_PERM_USER_READ + | GNUNET_DISK_PERM_USER_WRITE)) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename); + } if (perform) { perform_revocation (); diff --git a/src/testbed/gnunet_mpi_test.c b/src/testbed/gnunet_mpi_test.c index e0caf9676..241e5c53e 100644 --- a/src/testbed/gnunet_mpi_test.c +++ b/src/testbed/gnunet_mpi_test.c @@ -49,7 +49,7 @@ main (int argc, char *argv[]) (void) GNUNET_asprintf (&filename, "%d-%d.mpiout", (int) pid, rank); msg_size = GNUNET_asprintf (&msg, "My rank is: %d\n", rank); printf ("%s", msg); - if (msg_size == + if (GNUNET_OK == GNUNET_DISK_fn_write (filename, msg, msg_size, GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_GROUP_READ diff --git a/src/topology/friends.c b/src/topology/friends.c index a3b15d8f7..65c7e81d7 100644 --- a/src/topology/friends.c +++ b/src/topology/friends.c @@ -59,15 +59,6 @@ GNUNET_FRIENDS_parse (const struct GNUNET_CONFIGURATION_Handle *cfg, "FRIENDS"); return GNUNET_SYSERR; } - if (GNUNET_SYSERR == - GNUNET_DISK_directory_create_for_file (fn)) - { - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, - "mkdir", - fn); - GNUNET_free (fn); - return GNUNET_SYSERR; - } if ((GNUNET_OK != GNUNET_DISK_file_test (fn)) && (GNUNET_OK != diff --git a/src/util/Makefile.am b/src/util/Makefile.am index d2e4b4d1a..33fe26e34 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -138,7 +138,7 @@ libgnunetutil_la_LIBADD = \ libgnunetutil_la_LDFLAGS = \ $(GN_LIB_LDFLAGS) \ - -version-info 13:2:1 + -version-info 14:0:0 if HAVE_TESTING GNUNET_ECC = gnunet-ecc diff --git a/src/util/configuration.c b/src/util/configuration.c index e5c01f81f..ecdcb3d53 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c @@ -93,7 +93,7 @@ struct GNUNET_CONFIGURATION_Handle * #GNUNET_NO if clean, #GNUNET_YES if dirty, * #GNUNET_SYSERR on error (i.e. last save failed) */ - int dirty; + enum GNUNET_GenericReturnValue dirty; }; @@ -109,11 +109,6 @@ struct DiffHandle }; -/** - * Create a GNUNET_CONFIGURATION_Handle. - * - * @return fresh configuration object - */ struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create () { @@ -199,11 +194,6 @@ GNUNET_CONFIGURATION_create () } -/** - * Destroy configuration object. - * - * @param cfg configuration to destroy - */ void GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg) { @@ -215,24 +205,13 @@ GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg) } -/** - * Parse a configuration file @a filename and run the function - * @a cb with the resulting configuration object. Then free the - * configuration object and return the status value from @a cb. - * - * @param filename configuration to parse, NULL for "default" - * @param cb function to run - * @param cb_cls closure for @a cb - * @return #GNUNET_SYSERR if parsing the configuration failed, - * otherwise return value from @a cb. - */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse_and_run (const char *filename, GNUNET_CONFIGURATION_Callback cb, void *cb_cls) { struct GNUNET_CONFIGURATION_Handle *cfg; - int ret; + enum GNUNET_GenericReturnValue ret; cfg = GNUNET_CONFIGURATION_create (); if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, filename)) @@ -247,18 +226,7 @@ GNUNET_CONFIGURATION_parse_and_run (const char *filename, } -/** - * De-serializes configuration - * - * @param cfg configuration to update - * @param mem the memory block of serialized configuration - * @param size the size of the memory block - * @param basedir set to path from which we recursively load configuration - * from inlined configurations; NULL if not and raise warnings - * when we come across them - * @return #GNUNET_OK on success, #GNUNET_SYSERR on error - */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, const char *mem, size_t size, @@ -273,7 +241,7 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, size_t to_read; size_t i; int emptyline; - int ret; + enum GNUNET_GenericReturnValue ret; char *section; char *eq; char *tag; @@ -411,15 +379,7 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, } -/** - * Parse a configuration file, add all of the options in the - * file to the configuration environment. - * - * @param cfg configuration to update - * @param filename name of the configuration file - * @return #GNUNET_OK on success, #GNUNET_SYSERR on error - */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename) { @@ -429,7 +389,7 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, char *mem; char *endsep; int dirty; - int ret; + enum GNUNET_GenericReturnValue ret; ssize_t sret; fn = GNUNET_STRINGS_filename_expand (filename); @@ -476,28 +436,13 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, } -/** - * Test if there are configuration options that were - * changed since the last save. - * - * @param cfg configuration to inspect - * @return #GNUNET_NO if clean, #GNUNET_YES if dirty, #GNUNET_SYSERR on error (i.e. last save failed) - */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg) { return cfg->dirty; } -/** - * Serializes the given configuration. - * - * @param cfg configuration to serialize - * @param size will be set to the size of the serialized memory block - * @return the memory block where the serialized configuration is - * present. This memory should be freed by the caller - */ char * GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, size_t *size) @@ -580,21 +525,13 @@ GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, } -/** - * Write configuration file. - * - * @param cfg configuration to write - * @param filename where to write the configuration - * @return #GNUNET_OK on success, #GNUNET_SYSERR on error - */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename) { char *fn; char *cfg_buf; size_t size; - ssize_t sret; fn = GNUNET_STRINGS_filename_expand (filename); if (fn == NULL) @@ -604,15 +541,17 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_free (fn); return GNUNET_SYSERR; } - cfg_buf = GNUNET_CONFIGURATION_serialize (cfg, &size); - sret = GNUNET_DISK_fn_write (fn, - cfg_buf, - size, - GNUNET_DISK_PERM_USER_READ - | GNUNET_DISK_PERM_USER_WRITE - | GNUNET_DISK_PERM_GROUP_READ - | GNUNET_DISK_PERM_GROUP_WRITE); - if ((sret < 0) || (size != (size_t) sret)) + cfg_buf = GNUNET_CONFIGURATION_serialize (cfg, + &size); + (void) GNUNET_DISK_directory_remove (fn); + if (GNUNET_OK != + GNUNET_DISK_fn_write (fn, + cfg_buf, + size, + GNUNET_DISK_PERM_USER_READ + | GNUNET_DISK_PERM_USER_WRITE + | GNUNET_DISK_PERM_GROUP_READ + | GNUNET_DISK_PERM_GROUP_WRITE)) { GNUNET_free (fn); GNUNET_free (cfg_buf); @@ -629,36 +568,25 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, } -/** - * Iterate over all options in the configuration. - * - * @param cfg configuration to inspect - * @param iter function to call on each option - * @param iter_cls closure for @a iter - */ void GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls) { - struct ConfigSection *spos; - struct ConfigEntry *epos; - - for (spos = cfg->sections; NULL != spos; spos = spos->next) - for (epos = spos->entries; NULL != epos; epos = epos->next) + for (struct ConfigSection *spos = cfg->sections; + NULL != spos; + spos = spos->next) + for (struct ConfigEntry *epos = spos->entries; + NULL != epos; + epos = epos->next) if (NULL != epos->val) - iter (iter_cls, spos->name, epos->key, epos->val); + iter (iter_cls, + spos->name, + epos->key, + epos->val); } -/** - * Iterate over values of a section in the configuration. - * - * @param cfg configuration to inspect - * @param section the section - * @param iter function to call on each option - * @param iter_cls closure for @a iter - */ void GNUNET_CONFIGURATION_iterate_section_values ( const struct GNUNET_CONFIGURATION_Handle *cfg, @@ -680,13 +608,6 @@ GNUNET_CONFIGURATION_iterate_section_values ( } -/** - * Iterate over all sections in the configuration. - * - * @param cfg configuration to inspect - * @param iter function to call on each section - * @param iter_cls closure for @a iter - */ void GNUNET_CONFIGURATION_iterate_sections ( const struct GNUNET_CONFIGURATION_Handle *cfg, @@ -706,12 +627,6 @@ GNUNET_CONFIGURATION_iterate_sections ( } -/** - * Remove the given section and all options in it. - * - * @param cfg configuration to inspect - * @param section name of the section to remove - */ void GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, const char *section) @@ -769,12 +684,6 @@ copy_entry (void *cls, } -/** - * Duplicate an existing configuration object. - * - * @param cfg configuration to duplicate - * @return duplicate configuration - */ struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg) { @@ -858,13 +767,6 @@ compare_entries (void *cls, } -/** - * Compute configuration with only entries that have been changed - * - * @param cfg_default original configuration - * @param cfg_new new configuration - * @return configuration with only the differences, never NULL - */ struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_get_diff ( const struct GNUNET_CONFIGURATION_Handle *cfg_default, @@ -879,15 +781,7 @@ GNUNET_CONFIGURATION_get_diff ( } -/** - * Write only configuration entries that have been changed to configuration file - * - * @param cfg_default default configuration - * @param cfg_new new configuration - * @param filename where to write the configuration diff between default and new - * @return #GNUNET_OK on success, #GNUNET_SYSERR on error - */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write_diffs ( const struct GNUNET_CONFIGURATION_Handle *cfg_default, const struct GNUNET_CONFIGURATION_Handle *cfg_new, @@ -903,14 +797,6 @@ GNUNET_CONFIGURATION_write_diffs ( } -/** - * Set a configuration value that should be a string. - * - * @param cfg configuration to update - * @param section section of interest - * @param option option of interest - * @param value value to set - */ void GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, @@ -953,14 +839,6 @@ GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg, } -/** - * Set a configuration value that should be a number. - * - * @param cfg configuration to update - * @param section section of interest - * @param option option of interest - * @param number value to set - */ void GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, @@ -974,16 +852,7 @@ GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg, } -/** - * Get a configuration value that should be a number. - * - * @param cfg configuration to inspect - * @param section section of interest - * @param option option of interest - * @param number where to store the numeric value of the option - * @return #GNUNET_OK on success, #GNUNET_SYSERR on error - */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number ( const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, @@ -1003,16 +872,7 @@ GNUNET_CONFIGURATION_get_value_number ( } -/** - * Get a configuration value that should be a floating point number. - * - * @param cfg configuration to inspect - * @param section section of interest - * @param option option of interest - * @param number where to store the floating value of the option - * @return #GNUNET_OK on success, #GNUNET_SYSERR on error - */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_float ( const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, @@ -1032,16 +892,7 @@ GNUNET_CONFIGURATION_get_value_float ( } -/** - * Get a configuration value that should be a relative time. - * - * @param cfg configuration to inspect - * @param section section of interest - * @param option option of interest - * @param time set to the time value stored in the configuration - * @return #GNUNET_OK on success, #GNUNET_SYSERR on error - */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_time ( const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, @@ -1065,16 +916,7 @@ GNUNET_CONFIGURATION_get_value_time ( } -/** - * Get a configuration value that should be a size in bytes. - * - * @param cfg configuration to inspect - * @param section section of interest - * @param option option of interest - * @param size set to the size in bytes as stored in the configuration - * @return #GNUNET_OK on success, #GNUNET_SYSERR on error - */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_size ( const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, @@ -1101,7 +943,7 @@ GNUNET_CONFIGURATION_get_value_size ( * value, or NULL if option is not specified * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string ( const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, @@ -1120,19 +962,7 @@ GNUNET_CONFIGURATION_get_value_string ( } -/** - * Get a configuration value that should be in a set of - * predefined strings - * - * @param cfg configuration to inspect - * @param section section of interest - * @param option option of interest - * @param choices NULL-terminated list of legal values - * @param value will be set to an entry in the legal list, - * or NULL if option is not specified and no default given - * @return #GNUNET_OK on success, #GNUNET_SYSERR on error - */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_choice ( const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, @@ -1163,19 +993,7 @@ GNUNET_CONFIGURATION_get_value_choice ( } -/** - * Get crockford32-encoded fixed-size binary data from a configuration. - * - * @param cfg configuration to access - * @param section section to access - * @param option option to access - * @param buf where to store the decoded binary result - * @param buf_size exact number of bytes to store in @a buf - * @return #GNUNET_OK on success - * #GNUNET_NO is the value does not exist - * #GNUNET_SYSERR on decoding error - */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, @@ -1207,15 +1025,7 @@ GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg, } -/** - * Test if we have a value for a particular option - * - * @param cfg configuration to inspect - * @param section section of interest - * @param option option of interest - * @return #GNUNET_YES if so, #GNUNET_NO if not. - */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option) @@ -1390,22 +1200,6 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg, } -/** - * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR" - * where either in the "PATHS" section or the environment "FOO" is - * set to "DIRECTORY". We also support default expansion, - * i.e. ${VARIABLE:-default} will expand to $VARIABLE if VARIABLE is - * set in PATHS or the environment, and otherwise to "default". Note - * that "default" itself can also be a $-expression, thus - * "${VAR1:-{$VAR2}}" will expand to VAR1 and if that is not defined - * to VAR2. - * - * @param cfg configuration to use for path expansion - * @param orig string to $-expand (will be freed!). Note that multiple - * $-expressions can be present in this string. They will all be - * $-expanded. - * @return $-expanded string - */ char * GNUNET_CONFIGURATION_expand_dollar ( const struct GNUNET_CONFIGURATION_Handle *cfg, @@ -1431,17 +1225,7 @@ GNUNET_CONFIGURATION_expand_dollar ( } -/** - * Get a configuration value that should be a string. - * - * @param cfg configuration to inspect - * @param section section of interest - * @param option option of interest - * @param value will be set to a freshly allocated configuration - * value, or NULL if option is not specified - * @return #GNUNET_OK on success, #GNUNET_SYSERR on error - */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename ( const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, @@ -1466,16 +1250,7 @@ GNUNET_CONFIGURATION_get_value_filename ( } -/** - * Get a configuration value that should be in a set of - * "YES" or "NO". - * - * @param cfg configuration to inspect - * @param section section of interest - * @param option option of interest - * @return #GNUNET_YES, #GNUNET_NO or #GNUNET_SYSERR - */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno ( const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, @@ -1495,16 +1270,6 @@ GNUNET_CONFIGURATION_get_value_yesno ( } -/** - * Iterate over the set of filenames stored in a configuration value. - * - * @param cfg configuration to inspect - * @param section section of interest - * @param option option of interest - * @param cb function to call on each filename - * @param cb_cls closure for @a cb - * @return number of filenames iterated over, -1 on error - */ int GNUNET_CONFIGURATION_iterate_value_filenames ( const struct GNUNET_CONFIGURATION_Handle *cfg, @@ -1618,7 +1383,7 @@ escape_name (const char *value) * @param fn filename we are currently looking at * @return #GNUNET_OK if the names do not match, #GNUNET_SYSERR if they do */ -static int +static enum GNUNET_GenericReturnValue test_match (void *cls, const char *fn) { const char *of = cls; @@ -1627,19 +1392,7 @@ test_match (void *cls, const char *fn) } -/** - * Append a filename to a configuration value that - * represents a list of filenames - * - * @param cfg configuration to update - * @param section section of interest - * @param option option of interest - * @param value filename to append - * @return #GNUNET_OK on success, - * #GNUNET_NO if the filename already in the list - * #GNUNET_SYSERR on error - */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_append_value_filename ( struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, @@ -1674,19 +1427,7 @@ GNUNET_CONFIGURATION_append_value_filename ( } -/** - * Remove a filename from a configuration value that - * represents a list of filenames - * - * @param cfg configuration to update - * @param section section of interest - * @param option option of interest - * @param value filename to remove - * @return #GNUNET_OK on success, - * #GNUNET_NO if the filename is not in the list, - * #GNUNET_SYSERR on error - */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_remove_value_filename ( struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, @@ -1771,12 +1512,11 @@ GNUNET_CONFIGURATION_remove_value_filename ( * @param filename file to parse * @return #GNUNET_OK on success */ -static int +static enum GNUNET_GenericReturnValue parse_configuration_file (void *cls, const char *filename) { struct GNUNET_CONFIGURATION_Handle *cfg = cls; char *ext; - int ret; /* Examine file extension */ ext = strrchr (filename, '.'); @@ -1786,20 +1526,11 @@ parse_configuration_file (void *cls, const char *filename) return GNUNET_OK; } - ret = GNUNET_CONFIGURATION_parse (cfg, filename); - return ret; + return GNUNET_CONFIGURATION_parse (cfg, filename); } -/** - * Load default configuration. This function will parse the - * defaults from the given defaults_d directory. - * - * @param cfg configuration to update - * @param defaults_d directory with the defaults - * @return #GNUNET_OK on success, #GNUNET_SYSERR on error - */ -int +enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg, const char *defaults_d) { @@ -1810,43 +1541,31 @@ GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg, } -/** - * Return GNUnet's default configuration. A new configuration is allocated - * each time and it's up to the caller to destroy it when done. This function - * returns GNUnet's configuration even when #GNUNET_OS_init has been called - * with a value different from #GNUNET_OS_project_data_default. - * - * @return a freshly allocated configuration - */ struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_default (void) { const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get (); const struct GNUNET_OS_ProjectData *dpd = GNUNET_OS_project_data_default (); - - GNUNET_OS_init (dpd); - - struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create (); const char *xdg = getenv ("XDG_CONFIG_HOME"); char *cfgname = NULL; + struct GNUNET_CONFIGURATION_Handle *cfg; + GNUNET_OS_init (dpd); + cfg = GNUNET_CONFIGURATION_create (); if (NULL != xdg) GNUNET_asprintf (&cfgname, "%s/%s", xdg, pd->config_file); else cfgname = GNUNET_strdup (pd->user_config_file); - - if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfgname)) + if (GNUNET_OK != + GNUNET_CONFIGURATION_load (cfg, cfgname)) { GNUNET_OS_init (pd); GNUNET_CONFIGURATION_destroy (cfg); GNUNET_free (cfgname); return NULL; } - GNUNET_free (cfgname); - GNUNET_OS_init (pd); - return cfg; } diff --git a/src/util/crypto_ecc.c b/src/util/crypto_ecc.c index 019dbe94e..bc58142c2 100644 --- a/src/util/crypto_ecc.c +++ b/src/util/crypto_ecc.c @@ -166,12 +166,6 @@ decode_private_ecdsa_key (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv) } -/** - * Extract the public key for the given private key. - * - * @param priv the private key - * @param pub where to write the public key - */ void GNUNET_CRYPTO_ecdsa_key_get_public ( const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, @@ -183,12 +177,6 @@ GNUNET_CRYPTO_ecdsa_key_get_public ( } -/** - * Extract the public key for the given private key. - * - * @param priv the private key - * @param pub where to write the public key - */ void GNUNET_CRYPTO_eddsa_key_get_public ( const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, @@ -205,12 +193,6 @@ GNUNET_CRYPTO_eddsa_key_get_public ( } -/** - * Extract the public key for the given private key. - * - * @param priv the private key - * @param pub where to write the public key - */ void GNUNET_CRYPTO_ecdhe_key_get_public ( const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, @@ -222,12 +204,6 @@ GNUNET_CRYPTO_ecdhe_key_get_public ( } -/** - * Convert a public key to a string. - * - * @param pub key to convert - * @return string representing @a pub - */ char * GNUNET_CRYPTO_ecdsa_public_key_to_string ( const struct GNUNET_CRYPTO_EcdsaPublicKey *pub) @@ -255,12 +231,6 @@ GNUNET_CRYPTO_ecdsa_public_key_to_string ( } -/** - * Convert a public key to a string. - * - * @param pub key to convert - * @return string representing @a pub - */ char * GNUNET_CRYPTO_eddsa_public_key_to_string ( const struct GNUNET_CRYPTO_EddsaPublicKey *pub) @@ -288,12 +258,6 @@ GNUNET_CRYPTO_eddsa_public_key_to_string ( } -/** - * Convert a private key to a string. - * - * @param priv key to convert - * @return string representing @a pub - */ char * GNUNET_CRYPTO_eddsa_private_key_to_string ( const struct GNUNET_CRYPTO_EddsaPrivateKey *priv) @@ -321,12 +285,6 @@ GNUNET_CRYPTO_eddsa_private_key_to_string ( } -/** - * Convert a private key to a string. - * - * @param priv key to convert - * @return string representing @a priv - */ char * GNUNET_CRYPTO_ecdsa_private_key_to_string ( const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv) @@ -354,15 +312,7 @@ GNUNET_CRYPTO_ecdsa_private_key_to_string ( } -/** - * Convert a string representing a public key to a public key. - * - * @param enc encoded public key - * @param enclen number of bytes in @a enc (without 0-terminator) - * @param pub where to store the public key - * @return #GNUNET_OK on success - */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_public_key_from_string ( const char *enc, size_t enclen, @@ -387,15 +337,7 @@ GNUNET_CRYPTO_ecdsa_public_key_from_string ( } -/** - * Convert a string representing a public key to a public key. - * - * @param enc encoded public key - * @param enclen number of bytes in @a enc (without 0-terminator) - * @param pub where to store the public key - * @return #GNUNET_OK on success - */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_public_key_from_string ( const char *enc, size_t enclen, @@ -420,15 +362,7 @@ GNUNET_CRYPTO_eddsa_public_key_from_string ( } -/** - * Convert a string representing a private key to a private key. - * - * @param enc encoded public key - * @param enclen number of bytes in @a enc (without 0-terminator) - * @param priv where to store the private key - * @return #GNUNET_OK on success - */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_private_key_from_string ( const char *enc, size_t enclen, @@ -460,12 +394,6 @@ GNUNET_CRYPTO_eddsa_private_key_from_string ( } -/** - * @ingroup crypto - * Clear memory that was used to store a private key. - * - * @param pk location of the key - */ void GNUNET_CRYPTO_ecdhe_key_clear (struct GNUNET_CRYPTO_EcdhePrivateKey *pk) { @@ -473,12 +401,6 @@ GNUNET_CRYPTO_ecdhe_key_clear (struct GNUNET_CRYPTO_EcdhePrivateKey *pk) } -/** - * @ingroup crypto - * Clear memory that was used to store a private key. - * - * @param pk location of the key - */ void GNUNET_CRYPTO_ecdsa_key_clear (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk) { @@ -486,12 +408,6 @@ GNUNET_CRYPTO_ecdsa_key_clear (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk) } -/** - * @ingroup crypto - * Clear memory that was used to store a private key. - * - * @param pk location of the key - */ void GNUNET_CRYPTO_eddsa_key_clear (struct GNUNET_CRYPTO_EddsaPrivateKey *pk) { @@ -499,11 +415,6 @@ GNUNET_CRYPTO_eddsa_key_clear (struct GNUNET_CRYPTO_EddsaPrivateKey *pk) } -/** - * Create a new private key. - * - * @param[out] pk fresh private key - */ void GNUNET_CRYPTO_ecdhe_key_create (struct GNUNET_CRYPTO_EcdhePrivateKey *pk) { @@ -515,11 +426,6 @@ GNUNET_CRYPTO_ecdhe_key_create (struct GNUNET_CRYPTO_EcdhePrivateKey *pk) } -/** - * Create a new private key. - * - * @param[out] pk private key to initialize - */ void GNUNET_CRYPTO_ecdsa_key_create (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk) { @@ -535,11 +441,6 @@ GNUNET_CRYPTO_ecdsa_key_create (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk) } -/** - * Create a new private key. - * - * @param[out] pk set to fresh private key - */ void GNUNET_CRYPTO_eddsa_key_create (struct GNUNET_CRYPTO_EddsaPrivateKey *pk) { @@ -560,11 +461,6 @@ GNUNET_CRYPTO_eddsa_key_create (struct GNUNET_CRYPTO_EddsaPrivateKey *pk) } -/** - * Get the shared private key we use for anonymous users. - * - * @return "anonymous" private key - */ const struct GNUNET_CRYPTO_EcdsaPrivateKey * GNUNET_CRYPTO_ecdsa_key_get_anonymous () { @@ -629,19 +525,7 @@ data_to_ecdsa_value (const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose) } -/** - * Sign a given block. The @a purpose data is the - * beginning of the data of which the signature is to be - * created. The `size` field in @a purpose must correctly - * indicate the number of bytes of the data structure, including - * its header. - * - * @param priv private key to use for the signing - * @param purpose what to sign (size, purpose) - * @param sig where to write the signature - * @return #GNUNET_SYSERR on error, #GNUNET_OK on success - */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_sign_ ( const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, @@ -691,19 +575,7 @@ GNUNET_CRYPTO_ecdsa_sign_ ( } -/** - * Sign a given block. The @a purpose data is the - * beginning of the data of which the signature is to be - * created. The `size` field in @a purpose must correctly - * indicate the number of bytes of the data structure, including - * its header. - * - * @param priv private key to use for the signing - * @param purpose what to sign (size, purpose) - * @param sig where to write the signature - * @return #GNUNET_SYSERR on error, #GNUNET_OK on success - */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_sign_ ( const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, @@ -727,21 +599,7 @@ GNUNET_CRYPTO_eddsa_sign_ ( } -/** - * Verify signature. The @a validate data is the - * beginning of the data of which the signature is to be - * verified. The `size` field in @a validate must correctly - * indicate the number of bytes of the data structure, including - * its header. If @a purpose does not match the purpose given - * in @a validate (the latter - * - * @param purpose what is the purpose that the signature should have? - * @param validate block to validate (size, purpose, data) - * @param sig signature that is being validated - * @param pub public key of the signer - * @returns #GNUNET_OK if ok, #GNUNET_SYSERR if invalid - */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_verify_ ( uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, @@ -800,22 +658,7 @@ GNUNET_CRYPTO_ecdsa_verify_ ( } -/** - * Verify signature. The @a validate data is the - * beginning of the data of which the signature is to be - * verified. The `size` field in @a validate must correctly - * indicate the number of bytes of the data structure, including - * its header. If @a purpose does not match the purpose given - * in @a validate (the latter must be in big endian), signature - * verification fails. - * - * @param purpose what is the purpose that the signature should have? - * @param validate block to validate (size, purpose, data) - * @param sig signature that is being validated - * @param pub public key of the signer - * @returns #GNUNET_OK if ok, #GNUNET_SYSERR if invalid - */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_verify_ ( uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, @@ -838,15 +681,7 @@ GNUNET_CRYPTO_eddsa_verify_ ( } -/** - * Derive key material from a public and a private ECDHE key. - * - * @param priv private key to use for the ECDH (x) - * @param pub public key to use for the ECDH (yG) - * @param key_material where to write the key material (xyG) - * @return #GNUNET_SYSERR on error, #GNUNET_OK on success - */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_HashCode *key_material) @@ -895,18 +730,6 @@ derive_h (const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, } -/** - * Derive a private key from a given private key and a label. - * Essentially calculates a private key 'd = H(l,P) * x mod n' - * where n is the size of the ECC group and P is the public - * key associated with the private key 'd'. - * - * @param priv original private key - * @param label label to use for key deriviation - * @param context additional context to use for HKDF of 'h'; - * typically the name of the subsystem/application - * @return derived private key - */ struct GNUNET_CRYPTO_EcdsaPrivateKey * GNUNET_CRYPTO_ecdsa_private_key_derive ( const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, @@ -949,16 +772,6 @@ GNUNET_CRYPTO_ecdsa_private_key_derive ( } -/** - * Derive a public key from a given public key and a label. - * Essentially calculates a public key 'V = H(l,P) * P'. - * - * @param pub original public key - * @param label label to use for key derivation - * @param context additional context to use for HKDF of 'h'; - * typically the name of the subsystem/application - * @param result where to write the derived public key - */ void GNUNET_CRYPTO_ecdsa_public_key_derive ( const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, @@ -1010,17 +823,7 @@ GNUNET_CRYPTO_ecdsa_public_key_derive ( } -/** - * @ingroup crypto - * Derive key material from a ECDH public key and a private EdDSA key. - * Dual to #GNUNET_CRRYPTO_ecdh_eddsa. - * - * @param priv private key from EdDSA to use for the ECDH (x) - * @param pub public key to use for the ECDH (yG) - * @param key_material where to write the key material H(h(x)yG) - * @return #GNUNET_SYSERR on error, #GNUNET_OK on success - */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_ecdh (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_HashCode *key_material) @@ -1042,17 +845,7 @@ GNUNET_CRYPTO_eddsa_ecdh (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, } -/** - * @ingroup crypto - * Derive key material from a ECDH public key and a private ECDSA key. - * Dual to #GNUNET_CRRYPTO_ecdh_eddsa. - * - * @param priv private key from ECDSA to use for the ECDH (x) - * @param pub public key to use for the ECDH (yG) - * @param key_material where to write the key material H(h(x)yG) - * @return #GNUNET_SYSERR on error, #GNUNET_OK on success - */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_ecdh (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_HashCode *key_material) @@ -1070,17 +863,7 @@ GNUNET_CRYPTO_ecdsa_ecdh (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, } -/** - * @ingroup crypto - * Derive key material from a EdDSA public key and a private ECDH key. - * Dual to #GNUNET_CRRYPTO_eddsa_ecdh. - * - * @param priv private key to use for the ECDH (y) - * @param pub public key from EdDSA to use for the ECDH (X=h(x)G) - * @param key_material where to write the key material H(yX)=H(h(x)yG) - * @return #GNUNET_SYSERR on error, #GNUNET_OK on success - */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdh_eddsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, const struct GNUNET_CRYPTO_EddsaPublicKey *pub, struct GNUNET_HashCode *key_material) @@ -1097,17 +880,7 @@ GNUNET_CRYPTO_ecdh_eddsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, } -/** - * @ingroup crypto - * Derive key material from a ECDSA public key and a private ECDH key. - * Dual to #GNUNET_CRYPTO_ecdsa_ecdh. - * - * @param priv private key to use for the ECDH (y) - * @param pub public key from ECDSA to use for the ECDH (X=h(x)G) - * @param key_material where to write the key material H(yX)=H(h(x)yG) - * @return #GNUNET_SYSERR on error, #GNUNET_OK on success - */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdh_ecdsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, struct GNUNET_HashCode *key_material) diff --git a/src/util/crypto_ecc_setup.c b/src/util/crypto_ecc_setup.c index 6c71030b2..f7cd8c6d9 100644 --- a/src/util/crypto_ecc_setup.c +++ b/src/util/crypto_ecc_setup.c @@ -61,7 +61,7 @@ * @param buf_size number of bytes in @a buf * @return #GNUNET_OK on success */ -static int +static enum GNUNET_GenericReturnValue read_from_file (const char *filename, void *buf, size_t buf_size) @@ -122,104 +122,6 @@ read_from_file (const char *filename, } -/** - * Write contents of @a buf atomically to @a filename. - * Fail if @a filename already exists or if not exactly - * @a buf with @a buf_size bytes could be written to - * @a filename. - * - * @param filename where to write - * @param buf buffer to write - * @param buf_size number of bytes in @a buf to write - * @return #GNUNET_OK on success, - * #GNUNET_NO if a file existed under @a filename - * #GNUNET_SYSERR on failure - */ -static int -atomic_write_to_file (const char *filename, - const void *buf, - size_t buf_size) -{ - char *tmpl; - int fd; - - if (GNUNET_OK != - GNUNET_DISK_directory_create_for_file (filename)) - { - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, - "mkstemp", - filename); - return GNUNET_SYSERR; - } - { - char *dname; - - dname = GNUNET_strdup (filename); - GNUNET_asprintf (&tmpl, - "%s/XXXXXX", - dirname (dname)); - GNUNET_free (dname); - } - fd = mkstemp (tmpl); - if (-1 == fd) - { - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, - "mkstemp", - tmpl); - GNUNET_free (tmpl); - return GNUNET_SYSERR; - } - if (0 != fchmod (fd, - S_IRUSR)) - { - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, - "chmod", - tmpl); - GNUNET_assert (0 == close (fd)); - if (0 != unlink (tmpl)) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, - "unlink", - tmpl); - GNUNET_free (tmpl); - return GNUNET_SYSERR; - } - if (buf_size != - write (fd, - buf, - buf_size)) - { - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, - "write", - tmpl); - GNUNET_assert (0 == close (fd)); - if (0 != unlink (tmpl)) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, - "unlink", - tmpl); - GNUNET_free (tmpl); - return GNUNET_SYSERR; - } - GNUNET_assert (0 == close (fd)); - - if (0 != link (tmpl, - filename)) - { - if (0 != unlink (tmpl)) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, - "unlink", - tmpl); - GNUNET_free (tmpl); - return GNUNET_NO; - } - if (0 != unlink (tmpl)) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, - "unlink", - tmpl); - GNUNET_free (tmpl); - return GNUNET_OK; -} - - /** * @ingroup crypto * @brief Create a new private key by reading it from a file. @@ -235,12 +137,12 @@ atomic_write_to_file (const char *filename, * @return #GNUNET_OK on success, #GNUNET_NO if @a do_create was set but * we found an existing file, #GNUNET_SYSERR on failure */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_key_from_file (const char *filename, int do_create, struct GNUNET_CRYPTO_EddsaPrivateKey *pkey) { - int ret; + enum GNUNET_GenericReturnValue ret; if (GNUNET_OK == read_from_file (filename, @@ -251,9 +153,10 @@ GNUNET_CRYPTO_eddsa_key_from_file (const char *filename, return (do_create) ? GNUNET_NO : GNUNET_OK; } GNUNET_CRYPTO_eddsa_key_create (pkey); - ret = atomic_write_to_file (filename, + ret = GNUNET_DISK_fn_write (filename, pkey, - sizeof (*pkey)); + sizeof (*pkey), + GNUNET_DISK_PERM_USER_READ); if ( (GNUNET_OK == ret) || (GNUNET_SYSERR == ret) ) return ret; @@ -286,7 +189,7 @@ GNUNET_CRYPTO_eddsa_key_from_file (const char *filename, * @return #GNUNET_OK on success, #GNUNET_NO if @a do_create was set but * we found an existing file, #GNUNET_SYSERR on failure */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecdsa_key_from_file (const char *filename, int do_create, struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey) @@ -301,9 +204,10 @@ GNUNET_CRYPTO_ecdsa_key_from_file (const char *filename, } GNUNET_CRYPTO_ecdsa_key_create (pkey); if (GNUNET_OK == - atomic_write_to_file (filename, + GNUNET_DISK_fn_write (filename, pkey, - sizeof (*pkey))) + sizeof (*pkey), + GNUNET_DISK_PERM_USER_READ)) return GNUNET_OK; /* maybe another process succeeded in the meantime, try reading one more time */ if (GNUNET_OK == @@ -357,7 +261,7 @@ GNUNET_CRYPTO_eddsa_key_create_from_configuration ( * @return #GNUNET_OK on success, #GNUNET_SYSERR if the identity * could not be retrieved */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_get_peer_identity (const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_PeerIdentity *dst) { diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c index fec4d13db..63232cab6 100644 --- a/src/util/crypto_rsa.c +++ b/src/util/crypto_rsa.c @@ -139,12 +139,6 @@ key_from_sexp (gcry_mpi_t *array, } -/** - * Create a new private key. Caller must free return value. - * - * @param len length of the key in bits (i.e. 2048) - * @return fresh private key - */ struct GNUNET_CRYPTO_RsaPrivateKey * GNUNET_CRYPTO_rsa_private_key_create (unsigned int len) { @@ -174,11 +168,6 @@ GNUNET_CRYPTO_rsa_private_key_create (unsigned int len) } -/** - * Free memory occupied by the private key. - * - * @param key pointer to the memory to free - */ void GNUNET_CRYPTO_rsa_private_key_free (struct GNUNET_CRYPTO_RsaPrivateKey *key) { @@ -187,14 +176,6 @@ GNUNET_CRYPTO_rsa_private_key_free (struct GNUNET_CRYPTO_RsaPrivateKey *key) } -/** - * Encode the private key in a format suitable for - * storing it into a file. - * - * @param key the private key - * @param[out] buffer set to a buffer with the encoded key - * @return size of memory allocated in @a buffer - */ size_t GNUNET_CRYPTO_rsa_private_key_encode (const struct GNUNET_CRYPTO_RsaPrivateKey *key, @@ -218,14 +199,6 @@ GNUNET_CRYPTO_rsa_private_key_encode (const struct } -/** - * Decode the private key from the data-format back - * to the "normal", internal format. - * - * @param buf the buffer where the private key data is stored - * @param buf_size the size of the data in @a buf - * @return NULL on error - */ struct GNUNET_CRYPTO_RsaPrivateKey * GNUNET_CRYPTO_rsa_private_key_decode (const void *buf, size_t buf_size) @@ -255,12 +228,6 @@ GNUNET_CRYPTO_rsa_private_key_decode (const void *buf, } -/** - * Extract the public key of the given private key. - * - * @param priv the private key - * @return NULL on error, otherwise the public key - */ struct GNUNET_CRYPTO_RsaPublicKey * GNUNET_CRYPTO_rsa_private_key_get_public ( const struct GNUNET_CRYPTO_RsaPrivateKey *priv) @@ -296,11 +263,6 @@ GNUNET_CRYPTO_rsa_private_key_get_public ( } -/** - * Free memory occupied by the public key. - * - * @param key pointer to the memory to free - */ void GNUNET_CRYPTO_rsa_public_key_free (struct GNUNET_CRYPTO_RsaPublicKey *key) { @@ -334,14 +296,6 @@ struct GNUNET_CRYPTO_RsaPublicKeyHeaderP GNUNET_NETWORK_STRUCT_END -/** - * Encode the public key in a format suitable for - * storing it into a file. - * - * @param key the private key - * @param[out] buffer set to a buffer with the encoded key - * @return size of memory allocated in @a buffer - */ size_t GNUNET_CRYPTO_rsa_public_key_encode ( const struct GNUNET_CRYPTO_RsaPublicKey *key, @@ -409,12 +363,6 @@ GNUNET_CRYPTO_rsa_public_key_encode ( } -/** - * Compute hash over the public key. - * - * @param key public key to hash - * @param hc where to store the hash code - */ void GNUNET_CRYPTO_rsa_public_key_hash (const struct GNUNET_CRYPTO_RsaPublicKey *key, struct GNUNET_HashCode *hc) @@ -431,14 +379,6 @@ GNUNET_CRYPTO_rsa_public_key_hash (const struct GNUNET_CRYPTO_RsaPublicKey *key, } -/** - * Decode the public key from the data-format back - * to the "normal", internal format. - * - * @param buf the buffer where the public key data is stored - * @param len the length of the data in @a buf - * @return NULL on error - */ struct GNUNET_CRYPTO_RsaPublicKey * GNUNET_CRYPTO_rsa_public_key_decode (const char *buf, size_t len) @@ -612,13 +552,6 @@ rsa_blinding_key_derive (const struct GNUNET_CRYPTO_RsaPublicKey *pkey, */ -/** - * Compare the values of two signatures. - * - * @param s1 one signature - * @param s2 the other signature - * @return 0 if the two are equal - */ int GNUNET_CRYPTO_rsa_signature_cmp (const struct GNUNET_CRYPTO_RsaSignature *s1, const struct GNUNET_CRYPTO_RsaSignature *s2) @@ -645,13 +578,6 @@ GNUNET_CRYPTO_rsa_signature_cmp (const struct GNUNET_CRYPTO_RsaSignature *s1, } -/** - * Compare the values of two public keys. - * - * @param p1 one public key - * @param p2 the other public key - * @return 0 if the two are equal - */ int GNUNET_CRYPTO_rsa_public_key_cmp (const struct GNUNET_CRYPTO_RsaPublicKey *p1, const struct GNUNET_CRYPTO_RsaPublicKey *p2) @@ -678,13 +604,6 @@ GNUNET_CRYPTO_rsa_public_key_cmp (const struct GNUNET_CRYPTO_RsaPublicKey *p1, } -/** - * Compare the values of two private keys. - * - * @param p1 one private key - * @param p2 the other private key - * @return 0 if the two are equal - */ int GNUNET_CRYPTO_rsa_private_key_cmp (const struct GNUNET_CRYPTO_RsaPrivateKey *p1, const struct GNUNET_CRYPTO_RsaPrivateKey *p2) @@ -711,12 +630,6 @@ GNUNET_CRYPTO_rsa_private_key_cmp (const struct GNUNET_CRYPTO_RsaPrivateKey *p1, } -/** - * Obtain the length of the RSA key in bits. - * - * @param key the public key to introspect - * @return length of the key in bits - */ unsigned int GNUNET_CRYPTO_rsa_public_key_len (const struct GNUNET_CRYPTO_RsaPublicKey *key) { @@ -827,17 +740,7 @@ rsa_full_domain_hash (const struct GNUNET_CRYPTO_RsaPublicKey *pkey, } -/** - * Blinds the given message with the given blinding key - * - * @param hash hash of the message to sign - * @param bkey the blinding key - * @param pkey the public key of the signer - * @param[out] buf set to a buffer with the blinded message to be signed - * @param[out] buf_size number of bytes stored in @a buf - * @return #GNUNET_YES if successful, #GNUNET_NO if RSA key is malicious - */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks, struct GNUNET_CRYPTO_RsaPublicKey *pkey, @@ -863,7 +766,7 @@ GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash, GNUNET_break (0); *buf = NULL; *buf_size = 0; - return 0; + return GNUNET_NO; } data = rsa_full_domain_hash (pkey, hash); @@ -993,14 +896,6 @@ rsa_sign_mpi (const struct GNUNET_CRYPTO_RsaPrivateKey *key, } -/** - * Sign a blinded value, which must be a full domain hash of a message. - * - * @param key private key to use for the signing - * @param msg the message to sign - * @param msg_len number of bytes in @a msg to sign - * @return NULL on error, signature on success - */ struct GNUNET_CRYPTO_RsaSignature * GNUNET_CRYPTO_rsa_sign_blinded (const struct GNUNET_CRYPTO_RsaPrivateKey *key, const void *msg, @@ -1025,13 +920,6 @@ GNUNET_CRYPTO_rsa_sign_blinded (const struct GNUNET_CRYPTO_RsaPrivateKey *key, } -/** - * Create and sign a full domain hash of a message. - * - * @param key private key to use for the signing - * @param hash the hash of the message to sign - * @return NULL on error, including a malicious RSA key, signature on success - */ struct GNUNET_CRYPTO_RsaSignature * GNUNET_CRYPTO_rsa_sign_fdh (const struct GNUNET_CRYPTO_RsaPrivateKey *key, const struct GNUNET_HashCode *hash) @@ -1052,11 +940,6 @@ GNUNET_CRYPTO_rsa_sign_fdh (const struct GNUNET_CRYPTO_RsaPrivateKey *key, } -/** - * Free memory occupied by signature. - * - * @param sig memory to free - */ void GNUNET_CRYPTO_rsa_signature_free (struct GNUNET_CRYPTO_RsaSignature *sig) { @@ -1065,13 +948,6 @@ GNUNET_CRYPTO_rsa_signature_free (struct GNUNET_CRYPTO_RsaSignature *sig) } -/** - * Encode the given signature in a format suitable for storing it into a file. - * - * @param sig the signature - * @param[out] buffer set to a buffer with the encoded key - * @return size of memory allocated in @a buffer - */ size_t GNUNET_CRYPTO_rsa_signature_encode ( const struct GNUNET_CRYPTO_RsaSignature *sig, @@ -1112,14 +988,6 @@ GNUNET_CRYPTO_rsa_signature_encode ( } -/** - * Decode the signature from the data-format back to the "normal", internal - * format. - * - * @param buf the buffer where the public key data is stored - * @param buf_size the size of the data in @a buf - * @return NULL on error - */ struct GNUNET_CRYPTO_RsaSignature * GNUNET_CRYPTO_rsa_signature_decode (const void *buf, size_t buf_size) @@ -1156,12 +1024,6 @@ GNUNET_CRYPTO_rsa_signature_decode (const void *buf, } -/** - * Duplicate the given public key - * - * @param key the public key to duplicate - * @return the duplicate key; NULL upon error - */ struct GNUNET_CRYPTO_RsaPublicKey * GNUNET_CRYPTO_rsa_public_key_dup (const struct GNUNET_CRYPTO_RsaPublicKey *key) { @@ -1181,16 +1043,6 @@ GNUNET_CRYPTO_rsa_public_key_dup (const struct GNUNET_CRYPTO_RsaPublicKey *key) } -/** - * Unblind a blind-signed signature. The signature should have been generated - * with #GNUNET_CRYPTO_rsa_sign() using a hash that was blinded with - * #GNUNET_CRYPTO_rsa_blind(). - * - * @param sig the signature made on the blinded signature purpose - * @param bks the blinding key secret used to blind the signature purpose - * @param pkey the public key of the signer - * @return unblinded signature on success, NULL if RSA key is bad or malicious. - */ struct GNUNET_CRYPTO_RsaSignature * GNUNET_CRYPTO_rsa_unblind (const struct GNUNET_CRYPTO_RsaSignature *sig, const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks, @@ -1272,16 +1124,7 @@ GNUNET_CRYPTO_rsa_unblind (const struct GNUNET_CRYPTO_RsaSignature *sig, } -/** - * Verify whether the given hash corresponds to the given signature and - * the signature is valid with respect to the given public key. - * - * @param hash hash of the message to verify to match the @a sig - * @param sig signature that is being validated - * @param pkey public key of the signer - * @returns #GNUNET_YES if ok, #GNUNET_NO if RSA key is malicious, #GNUNET_SYSERR if signature is invalid - */ -int +enum GNUNET_GenericReturnValue GNUNET_CRYPTO_rsa_verify (const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_RsaSignature *sig, const struct GNUNET_CRYPTO_RsaPublicKey *pkey) @@ -1319,23 +1162,17 @@ GNUNET_CRYPTO_rsa_verify (const struct GNUNET_HashCode *hash, __FILE__, __LINE__, gcry_strerror (rc)); - return GNUNET_SYSERR; BENCHMARK_END (rsa_verify); + return GNUNET_SYSERR; } BENCHMARK_END (rsa_verify); return GNUNET_OK; } -/** - * Duplicate the given private key - * - * @param key the private key to duplicate - * @return the duplicate key; NULL upon error - */ struct GNUNET_CRYPTO_RsaPrivateKey * -GNUNET_CRYPTO_rsa_private_key_dup (const struct - GNUNET_CRYPTO_RsaPrivateKey *key) +GNUNET_CRYPTO_rsa_private_key_dup ( + const struct GNUNET_CRYPTO_RsaPrivateKey *key) { struct GNUNET_CRYPTO_RsaPrivateKey *dup; gcry_sexp_t dup_sexp; @@ -1353,12 +1190,6 @@ GNUNET_CRYPTO_rsa_private_key_dup (const struct } -/** - * Duplicate the given private key - * - * @param key the private key to duplicate - * @return the duplicate key; NULL upon error - */ struct GNUNET_CRYPTO_RsaSignature * GNUNET_CRYPTO_rsa_signature_dup (const struct GNUNET_CRYPTO_RsaSignature *sig) { diff --git a/src/util/disk.c b/src/util/disk.c index c95e9753c..3bafe311d 100644 --- a/src/util/disk.c +++ b/src/util/disk.c @@ -92,7 +92,7 @@ struct GetFileSizeData int include_sym_links; /** - * GNUNET_YES if mode is file-only (return total == -1 for directories). + * #GNUNET_YES if mode is file-only (return total == -1 for directories). */ int single_file_mode; }; @@ -142,8 +142,8 @@ translate_unix_perms (enum GNUNET_DISK_AccessPermissions perm) * @param fn current filename we are looking at * @return #GNUNET_SYSERR on serious errors, otherwise #GNUNET_OK */ -static int -getSizeRec (void *cls, const char *fn) +static enum GNUNET_GenericReturnValue +get_size_rec (void *cls, const char *fn) { struct GetFileSizeData *gfsd = cls; @@ -175,35 +175,23 @@ getSizeRec (void *cls, const char *fn) if ((S_ISDIR (buf.st_mode)) && (0 == access (fn, X_OK)) && ((! S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES))) { - if (GNUNET_SYSERR == GNUNET_DISK_directory_scan (fn, &getSizeRec, gfsd)) + if (GNUNET_SYSERR == GNUNET_DISK_directory_scan (fn, &get_size_rec, gfsd)) return GNUNET_SYSERR; } return GNUNET_OK; } -/** - * Checks whether a handle is invalid - * - * @param h handle to check - * @return #GNUNET_YES if invalid, #GNUNET_NO if valid - */ -int +enum GNUNET_GenericReturnValue GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h) { return ((! h) || (h->fd == -1)) ? GNUNET_YES : GNUNET_NO; } -/** - * Get the size of an open file. - * - * @param fh open file handle - * @param size where to write size of the file - * @return #GNUNET_OK on success, #GNUNET_SYSERR on error - */ -int -GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh, off_t *size) +enum GNUNET_GenericReturnValue +GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh, + off_t *size) { struct stat sbuf; @@ -214,80 +202,42 @@ GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh, off_t *size) } -/** - * Move the read/write pointer in a file - * - * @param h handle of an open file - * @param offset position to move to - * @param whence specification to which position the offset parameter relates to - * @return the new position on success, #GNUNET_SYSERR otherwise - */ off_t GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, off_t offset, enum GNUNET_DISK_Seek whence) { + static int t[] = { SEEK_SET, SEEK_CUR, SEEK_END }; + if (h == NULL) { errno = EINVAL; return GNUNET_SYSERR; } - - static int t[] = { SEEK_SET, SEEK_CUR, SEEK_END }; - return lseek (h->fd, offset, t[whence]); } -/** - * Get the size of the file (or directory) of the given file (in - * bytes). - * - * @param filename name of the file or directory - * @param size set to the size of the file (or, - * in the case of directories, the sum - * of all sizes of files in the directory) - * @param include_symbolic_links should symbolic links be - * included? - * @param single_file_mode #GNUNET_YES to only get size of one file - * and return #GNUNET_SYSERR for directories. - * @return #GNUNET_SYSERR on error, #GNUNET_OK on success - */ -int +enum GNUNET_GenericReturnValue GNUNET_DISK_file_size (const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode) { struct GetFileSizeData gfsd; - int ret; + enum GNUNET_GenericReturnValue ret; GNUNET_assert (size != NULL); gfsd.total = 0; gfsd.include_sym_links = include_symbolic_links; gfsd.single_file_mode = single_file_mode; - ret = getSizeRec (&gfsd, filename); + ret = get_size_rec (&gfsd, filename); *size = gfsd.total; return ret; } -/** - * Obtain some unique identifiers for the given file - * that can be used to identify it in the local system. - * This function is used between GNUnet processes to - * quickly check if two files with the same absolute path - * are actually identical. The two processes represent - * the same peer but may communicate over the network - * (and the file may be on an NFS volume). This function - * may not be supported on all operating systems. - * - * @param filename name of the file - * @param dev set to the device ID - * @param ino set to the inode ID - * @return #GNUNET_OK on success - */ -int +enum GNUNET_GenericReturnValue GNUNET_DISK_file_get_identifiers (const char *filename, uint64_t *dev, uint64_t *ino) @@ -367,14 +317,6 @@ mktemp_name (const char *t) } -/** - * Update POSIX permissions mask of a file on disk. If both argumets - * are #GNUNET_NO, the file is made world-read-write-executable (777). - * - * @param fn name of the file to update - * @param require_uid_match #GNUNET_YES means 700 - * @param require_gid_match #GNUNET_YES means 770 unless @a require_uid_match is set - */ void GNUNET_DISK_fix_permissions (const char *fn, int require_uid_match, @@ -394,17 +336,6 @@ GNUNET_DISK_fix_permissions (const char *fn, } -/** - * Create an (empty) temporary directory on disk. If the given name is not - * an absolute path, the current 'TMPDIR' will be prepended. In any case, - * 6 random characters will be appended to the name to create a unique - * filename. - * - * @param t component to use for the name; - * does NOT contain "XXXXXX" or "/tmp/". - * @return NULL on error, otherwise name of fresh - * file on disk in directory for temporary files - */ char * GNUNET_DISK_mkdtemp (const char *t) { @@ -425,13 +356,6 @@ GNUNET_DISK_mkdtemp (const char *t) } -/** - * Move a file out of the way (create a backup) by - * renaming it to "orig.NUM~" where NUM is the smallest - * number that is not used yet. - * - * @param fil name of the file to back up - */ void GNUNET_DISK_file_backup (const char *fil) { @@ -453,17 +377,6 @@ GNUNET_DISK_file_backup (const char *fil) } -/** - * Create an (empty) temporary file on disk. If the given name is not - * an absolute path, the current 'TMPDIR' will be prepended. In any case, - * 6 random characters will be appended to the name to create a unique - * filename. - * - * @param t component to use for the name; - * does NOT contain "XXXXXX" or "/tmp/". - * @return NULL on error, otherwise name of fresh - * file on disk in directory for temporary files - */ char * GNUNET_DISK_mktemp (const char *t) { @@ -487,19 +400,7 @@ GNUNET_DISK_mktemp (const char *t) } -/** - * Test if @a fil is a directory and listable. Optionally, also check if the - * directory is readable. Will not print an error message if the directory does - * not exist. Will log errors if #GNUNET_SYSERR is returned (i.e., a file exists - * with the same name). - * - * @param fil filename to test - * @param is_readable #GNUNET_YES to additionally check if @a fil is readable; - * #GNUNET_NO to disable this check - * @return #GNUNET_YES if yes, #GNUNET_NO if not; #GNUNET_SYSERR if it - * does not exist or stat'ed - */ -int +enum GNUNET_GenericReturnValue GNUNET_DISK_directory_test (const char *fil, int is_readable) { struct stat filestat; @@ -532,15 +433,7 @@ GNUNET_DISK_directory_test (const char *fil, int is_readable) } -/** - * Check that fil corresponds to a filename - * (of a file that exists and that is not a directory). - * - * @param fil filename to check - * @return #GNUNET_YES if yes, #GNUNET_NO if not a file, #GNUNET_SYSERR if something - * else (will print an error message in that case, too). - */ -int +enum GNUNET_GenericReturnValue GNUNET_DISK_file_test (const char *fil) { struct stat filestat; @@ -552,7 +445,7 @@ GNUNET_DISK_file_test (const char *fil) return GNUNET_SYSERR; ret = stat (rdir, &filestat); - if (ret != 0) + if (0 != ret) { if (errno != ENOENT) { @@ -579,13 +472,7 @@ GNUNET_DISK_file_test (const char *fil) } -/** - * Implementation of "mkdir -p" - * - * @param dir the directory to create - * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure - */ -int +enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create (const char *dir) { char *rdir; @@ -671,22 +558,13 @@ GNUNET_DISK_directory_create (const char *dir) } -/** - * Create the directory structure for storing a file. - * - * @param filename name of a file in the directory - * @returns #GNUNET_OK on success, - * #GNUNET_SYSERR on failure, - * #GNUNET_NO if the directory - * exists but is not writeable for us - */ -int +enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file (const char *filename) { char *rdir; size_t len; - int ret; int eno; + enum GNUNET_GenericReturnValue res; rdir = GNUNET_STRINGS_filename_expand (filename); if (NULL == rdir) @@ -699,7 +577,6 @@ GNUNET_DISK_directory_create_for_file (const char *filename) GNUNET_free (rdir); return GNUNET_OK; } - len = strlen (rdir); while ((len > 0) && (rdir[len] != DIR_SEPARATOR)) len--; @@ -710,24 +587,17 @@ GNUNET_DISK_directory_create_for_file (const char *filename) GNUNET_free (rdir); rdir = GNUNET_strdup ("/"); } - ret = GNUNET_DISK_directory_create (rdir); - if ((GNUNET_OK == ret) && (0 != access (rdir, W_OK))) - ret = GNUNET_NO; + res = GNUNET_DISK_directory_create (rdir); + if ( (GNUNET_OK == res) && + (0 != access (rdir, W_OK)) ) + res = GNUNET_NO; eno = errno; GNUNET_free (rdir); errno = eno; - return ret; + return res; } -/** - * Read the contents of a binary file into a buffer. - * - * @param h handle to an open file - * @param result the buffer to write the result to - * @param len the maximum number of bytes to read - * @return the number of bytes read on success, #GNUNET_SYSERR on failure - */ ssize_t GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h, void *result, @@ -738,35 +608,23 @@ GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h, errno = EINVAL; return GNUNET_SYSERR; } - return read (h->fd, result, len); } -/** - * Read the contents of a binary file into a buffer. - * Guarantees not to block (returns GNUNET_SYSERR and sets errno to EAGAIN - * when no data can be read). - * - * @param h handle to an open file - * @param result the buffer to write the result to - * @param len the maximum number of bytes to read - * @return the number of bytes read on success, #GNUNET_SYSERR on failure - */ ssize_t GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle *h, void *result, size_t len) { + int flags; + ssize_t ret; + if (NULL == h) { errno = EINVAL; return GNUNET_SYSERR; } - - int flags; - ssize_t ret; - /* set to non-blocking, read, then set back */ flags = fcntl (h->fd, F_GETFL); if (0 == (flags & O_NONBLOCK)) @@ -782,22 +640,18 @@ GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle *h, } -/** - * Read the contents of a binary file into a buffer. - * - * @param fn file name - * @param result the buffer to write the result to - * @param len the maximum number of bytes to read - * @return number of bytes read, #GNUNET_SYSERR on failure - */ ssize_t -GNUNET_DISK_fn_read (const char *fn, void *result, size_t len) +GNUNET_DISK_fn_read (const char *fn, + void *result, + size_t len) { struct GNUNET_DISK_FileHandle *fh; ssize_t ret; int eno; - fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE); + fh = GNUNET_DISK_file_open (fn, + GNUNET_DISK_OPEN_READ, + GNUNET_DISK_PERM_NONE); if (NULL == fh) return GNUNET_SYSERR; ret = GNUNET_DISK_file_read (fh, result, len); @@ -808,14 +662,6 @@ GNUNET_DISK_fn_read (const char *fn, void *result, size_t len) } -/** - * Write a buffer to a file. - * - * @param h handle to open file - * @param buffer the data to write - * @param n number of bytes to write - * @return number of bytes written on success, #GNUNET_SYSERR on error - */ ssize_t GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h, const void *buffer, @@ -831,29 +677,19 @@ GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h, } -/** - * Write a buffer to a file, blocking, if necessary. - * - * @param h handle to open file - * @param buffer the data to write - * @param n number of bytes to write - * @return number of bytes written on success, #GNUNET_SYSERR on error - */ ssize_t GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n) { + int flags; + ssize_t ret; + if (NULL == h) { errno = EINVAL; return GNUNET_SYSERR; } - - - int flags; - ssize_t ret; - /* set to blocking, write, then set back */ flags = fcntl (h->fd, F_GETFL); if (0 != (flags & O_NONBLOCK)) @@ -865,48 +701,95 @@ GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle *h, } -/** - * Write a buffer to a file. If the file is longer than the - * number of bytes that will be written, it will be truncated. - * - * @param fn file name - * @param buffer the data to write - * @param n number of bytes to write - * @param mode file permissions - * @return number of bytes written on success, #GNUNET_SYSERR on error - */ -ssize_t +enum GNUNET_GenericReturnValue GNUNET_DISK_fn_write (const char *fn, - const void *buffer, - size_t n, + const void *buf, + size_t buf_size, enum GNUNET_DISK_AccessPermissions mode) { - struct GNUNET_DISK_FileHandle *fh; - ssize_t ret; + char *tmpl; + int fd; - fh = - GNUNET_DISK_file_open (fn, - GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE - | GNUNET_DISK_OPEN_CREATE, - mode); - if (! fh) + if (GNUNET_OK != + GNUNET_DISK_directory_create_for_file (fn)) + { + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, + "mkstemp", + fn); return GNUNET_SYSERR; - ret = GNUNET_DISK_file_write (fh, buffer, n); - GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); - return ret; + } + { + char *dname; + + dname = GNUNET_strdup (fn); + GNUNET_asprintf (&tmpl, + "%s/XXXXXX", + dirname (dname)); + GNUNET_free (dname); + } + fd = mkstemp (tmpl); + if (-1 == fd) + { + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, + "mkstemp", + tmpl); + GNUNET_free (tmpl); + return GNUNET_SYSERR; + } + + if (0 != fchmod (fd, + translate_unix_perms (mode))) + { + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, + "chmod", + tmpl); + GNUNET_assert (0 == close (fd)); + if (0 != unlink (tmpl)) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, + "unlink", + tmpl); + GNUNET_free (tmpl); + return GNUNET_SYSERR; + } + if (buf_size != + write (fd, + buf, + buf_size)) + { + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, + "write", + tmpl); + GNUNET_assert (0 == close (fd)); + if (0 != unlink (tmpl)) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, + "unlink", + tmpl); + GNUNET_free (tmpl); + return GNUNET_SYSERR; + } + GNUNET_assert (0 == close (fd)); + + if (0 != link (tmpl, + fn)) + { + if (0 != unlink (tmpl)) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, + "unlink", + tmpl); + GNUNET_free (tmpl); + return GNUNET_NO; + } + if (0 != unlink (tmpl)) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, + "unlink", + tmpl); + GNUNET_free (tmpl); + return GNUNET_OK; + + } -/** - * Scan a directory for files. - * - * @param dir_name the name of the directory - * @param callback the method to call for each file, - * can be NULL, in that case, we only count - * @param callback_cls closure for @a callback - * @return the number of files found, #GNUNET_SYSERR on error or - * ieration aborted by callback returning #GNUNET_SYSERR - */ int GNUNET_DISK_directory_scan (const char *dir_name, GNUNET_FileNameCallback callback, @@ -916,7 +799,7 @@ GNUNET_DISK_directory_scan (const char *dir_name, struct dirent *finfo; struct stat istat; int count = 0; - int ret; + enum GNUNET_GenericReturnValue ret; char *name; char *dname; unsigned int name_len; @@ -1008,8 +891,9 @@ GNUNET_DISK_directory_scan (const char *dir_name, * @param fn directory to remove * @return #GNUNET_OK */ -static int -remove_helper (void *unused, const char *fn) +static enum GNUNET_GenericReturnValue +remove_helper (void *unused, + const char *fn) { (void) unused; (void) GNUNET_DISK_directory_remove (fn); @@ -1017,14 +901,7 @@ remove_helper (void *unused, const char *fn) } -/** - * Remove all files in a directory (rm -r). Call with - * caution. - * - * @param filename the file to remove - * @return #GNUNET_OK on success, #GNUNET_SYSERR on error - */ -int +enum GNUNET_GenericReturnValue GNUNET_DISK_directory_remove (const char *filename) { struct stat istat; @@ -1036,14 +913,17 @@ GNUNET_DISK_directory_remove (const char *filename) } if (0 != lstat (filename, &istat)) return GNUNET_NO; /* file may not exist... */ - (void) chmod (filename, S_IWUSR | S_IRUSR | S_IXUSR); + (void) chmod (filename, + S_IWUSR | S_IRUSR | S_IXUSR); if (0 == unlink (filename)) return GNUNET_OK; - if ((errno != EISDIR) && - /* EISDIR is not sufficient in all cases, e.g. - * sticky /tmp directory may result in EPERM on BSD. - * So we also explicitly check "isDirectory" */ - (GNUNET_YES != GNUNET_DISK_directory_test (filename, GNUNET_YES))) + if ( (errno != EISDIR) && + /* EISDIR is not sufficient in all cases, e.g. + * sticky /tmp directory may result in EPERM on BSD. + * So we also explicitly check "isDirectory" */ + (GNUNET_YES != + GNUNET_DISK_directory_test (filename, + GNUNET_YES)) ) { LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "rmdir", filename); return GNUNET_SYSERR; @@ -1060,15 +940,9 @@ GNUNET_DISK_directory_remove (const char *filename) } -/** - * Copy a file. - * - * @param src file to copy - * @param dst destination file name - * @return #GNUNET_OK on success, #GNUNET_SYSERR on error - */ -int -GNUNET_DISK_file_copy (const char *src, const char *dst) +enum GNUNET_GenericReturnValue +GNUNET_DISK_file_copy (const char *src, + const char *dst) { char *buf; uint64_t pos; @@ -1131,10 +1005,6 @@ FAIL: } -/** - * @brief Removes special characters as ':' from a filename. - * @param fn the filename to canonicalize - */ void GNUNET_DISK_filename_canonicalize (char *fn) { @@ -1157,15 +1027,9 @@ GNUNET_DISK_filename_canonicalize (char *fn) } -/** - * @brief Change owner of a file - * - * @param filename name of file to change the owner of - * @param user name of the new owner - * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure - */ -int -GNUNET_DISK_file_change_owner (const char *filename, const char *user) +enum GNUNET_GenericReturnValue +GNUNET_DISK_file_change_owner (const char *filename, + const char *user) { struct passwd *pws; @@ -1187,18 +1051,6 @@ GNUNET_DISK_file_change_owner (const char *filename, const char *user) } -/** - * Open a file. Note that the access permissions will only be - * used if a new file is created and if the underlying operating - * system supports the given permissions. - * - * @param fn file name to be opened - * @param flags opening flags, a combination of GNUNET_DISK_OPEN_xxx bit flags - * @param perm permissions for the newly created file, use - * #GNUNET_DISK_PERM_NONE if a file could not be created by this - * call (because of flags) - * @return IO handle on success, NULL on error - */ struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open (const char *fn, enum GNUNET_DISK_OpenFlags flags, @@ -1270,42 +1122,28 @@ GNUNET_DISK_file_open (const char *fn, } -/** - * Close an open file. - * - * @param h file handle - * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise - */ -int +enum GNUNET_GenericReturnValue GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h) { - int ret; + enum GNUNET_GenericReturnValue ret; - if (h == NULL) + if (NULL == h) { errno = EINVAL; return GNUNET_SYSERR; } ret = GNUNET_OK; - - if (close (h->fd) != 0) + if (0 != close (h->fd)) { LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "close"); ret = GNUNET_SYSERR; } - GNUNET_free (h); return ret; } -/** - * Get a handle from a native integer FD. - * - * @param fno native integer file descriptor - * @return file handle corresponding to the descriptor, NULL on error - */ struct GNUNET_DISK_FileHandle * GNUNET_DISK_get_handle_from_int_fd (int fno) { @@ -1322,12 +1160,6 @@ GNUNET_DISK_get_handle_from_int_fd (int fno) } -/** - * Get a handle from a native streaming FD. - * - * @param fd native streaming file descriptor - * @return file handle corresponding to the descriptor - */ struct GNUNET_DISK_FileHandle * GNUNET_DISK_get_handle_from_native (FILE *fd) { @@ -1336,7 +1168,6 @@ GNUNET_DISK_get_handle_from_native (FILE *fd) fno = fileno (fd); if (-1 == fno) return NULL; - return GNUNET_DISK_get_handle_from_int_fd (fno); } @@ -1362,15 +1193,7 @@ struct GNUNET_DISK_MapHandle #define MAP_FAILED ((void *) -1) #endif -/** - * Map a file into memory - * - * @param h open file handle - * @param m handle to the new mapping - * @param access access specification, GNUNET_DISK_MAP_TYPE_xxx - * @param len size of the mapping - * @return pointer to the mapped memory region, NULL on failure - */ + void * GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h, struct GNUNET_DISK_MapHandle **m, @@ -1402,16 +1225,10 @@ GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h, } -/** - * Unmap a file - * - * @param h mapping handle - * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise - */ -int +enum GNUNET_GenericReturnValue GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h) { - int ret; + enum GNUNET_GenericReturnValue ret; if (NULL == h) { @@ -1424,12 +1241,7 @@ GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h) } -/** - * Write file changes to disk - * @param h handle to an open file - * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise - */ -int +enum GNUNET_GenericReturnValue GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h) { if (h == NULL) @@ -1446,12 +1258,6 @@ GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h) } -/** - * Creates an interprocess channel - * - * @param pf how to configure the pipe - * @return handle to the new pipe, NULL on error - */ struct GNUNET_DISK_PipeHandle * GNUNET_DISK_pipe (enum GNUNET_DISK_PipeFlags pf) { @@ -1469,15 +1275,6 @@ GNUNET_DISK_pipe (enum GNUNET_DISK_PipeFlags pf) } -/** - * Creates a pipe object from a couple of file descriptors. - * Useful for wrapping existing pipe FDs. - * - * @param pf how to configure the pipe - * @param fd an array of two fd values. One of them may be -1 for read-only or write-only pipes - * - * @return handle to the new pipe, NULL on error - */ struct GNUNET_DISK_PipeHandle * GNUNET_DISK_pipe_from_fd (enum GNUNET_DISK_PipeFlags pf, int fd[2]) @@ -1551,18 +1348,11 @@ GNUNET_DISK_pipe_from_fd (enum GNUNET_DISK_PipeFlags pf, } -/** - * Closes an interprocess channel - * - * @param p pipe to close - * @param end which end of the pipe to close - * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise - */ -int +enum GNUNET_GenericReturnValue GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd end) { - int ret = GNUNET_OK; + enum GNUNET_GenericReturnValue ret = GNUNET_OK; if (end == GNUNET_DISK_PIPE_END_READ) { @@ -1580,23 +1370,10 @@ GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p, p->fd[1] = NULL; } } - return ret; } -/** - * Detaches one of the ends from the pipe. - * Detached end is a fully-functional FileHandle, it will - * not be affected by anything you do with the pipe afterwards. - * Each end of a pipe can only be detched from it once (i.e. - * it is not duplicated). - * - * @param p pipe to detach an end from - * @param end which end of the pipe to detach - * @return Detached end on success, NULL on failure - * (or if that end is not present or is closed). - */ struct GNUNET_DISK_FileHandle * GNUNET_DISK_pipe_detach_end (struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd end) @@ -1624,13 +1401,7 @@ GNUNET_DISK_pipe_detach_end (struct GNUNET_DISK_PipeHandle *p, } -/** - * Closes an interprocess channel - * - * @param p pipe to close - * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise - */ -int +enum GNUNET_GenericReturnValue GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p) { int ret = GNUNET_OK; @@ -1661,13 +1432,6 @@ GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p) } -/** - * Get the handle to a particular pipe end - * - * @param p pipe - * @param n end to access - * @return handle for the respective end - */ const struct GNUNET_DISK_FileHandle * GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd n) @@ -1685,26 +1449,16 @@ GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p, } -/** - * Retrieve OS file handle - * @internal - * @param fh GNUnet file descriptor - * @param dst destination buffer - * @param dst_len length of dst - * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise - */ -int +enum GNUNET_GenericReturnValue GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh, void *dst, size_t dst_len) { if (NULL == fh) return GNUNET_SYSERR; - if (dst_len < sizeof(int)) return GNUNET_SYSERR; *((int *) dst) = fh->fd; - return GNUNET_OK; } @@ -1716,8 +1470,9 @@ GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh, * @param cfg our configuration * @return #GNUNET_OK on success */ -static int -purge_cfg_dir (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) +static enum GNUNET_GenericReturnValue +purge_cfg_dir (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg) { const char *option = cls; char *tmpname; @@ -1739,15 +1494,9 @@ purge_cfg_dir (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) } -/** - * Remove the directory given under @a option in - * section [PATHS] in configuration under @a cfg_filename - * - * @param cfg_filename configuration file to parse - * @param option option with the dir name to purge - */ void -GNUNET_DISK_purge_cfg_dir (const char *cfg_filename, const char *option) +GNUNET_DISK_purge_cfg_dir (const char *cfg_filename, + const char *option) { GNUNET_break (GNUNET_OK == GNUNET_CONFIGURATION_parse_and_run (cfg_filename, diff --git a/src/util/gnunet-scrypt.c b/src/util/gnunet-scrypt.c index 136c6debb..5c3dfc12e 100644 --- a/src/util/gnunet-scrypt.c +++ b/src/util/gnunet-scrypt.c @@ -65,12 +65,15 @@ static void shutdown_task (void *cls) { (void) cls; - if (sizeof(proof) != GNUNET_DISK_fn_write (pwfn, - &proof, - sizeof(proof), - GNUNET_DISK_PERM_USER_READ - | GNUNET_DISK_PERM_USER_WRITE)) - GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", pwfn); + if (GNUNET_OK != + GNUNET_DISK_fn_write (pwfn, + &proof, + sizeof(proof), + GNUNET_DISK_PERM_USER_READ + | GNUNET_DISK_PERM_USER_WRITE)) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, + "write", + pwfn); } diff --git a/src/util/test_disk.c b/src/util/test_disk.c index 6969e49e6..12bde8107 100644 --- a/src/util/test_disk.c +++ b/src/util/test_disk.c @@ -30,12 +30,12 @@ static int -testReadWrite () +testReadWrite (void) { char tmp[100 + 1]; int ret; - if (strlen (TESTSTRING) != + if (GNUNET_OK != GNUNET_DISK_fn_write (".testfile", TESTSTRING, strlen (TESTSTRING), GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)) -- cgit v1.2.3