diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-12-19 18:43:38 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-12-19 18:43:38 +0100 |
commit | 3636ea628d051cf2ba7a9038c50528c561d0aeaa (patch) | |
tree | 87664b904950052e8b6997a371ed5ecb1ea4b310 | |
parent | 74d7528e6bd53cf5acc939c63a5be74a001e5ce1 (diff) | |
download | gnunet-3636ea628d051cf2ba7a9038c50528c561d0aeaa.tar.gz gnunet-3636ea628d051cf2ba7a9038c50528c561d0aeaa.zip |
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
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) | |||
111 | ctx = NULL; | 111 | ctx = NULL; |
112 | if (output_filename == NULL) | 112 | if (output_filename == NULL) |
113 | return; | 113 | return; |
114 | if (GNUNET_OK != GNUNET_FS_directory_builder_finish (db, &dsize, &ddata)) | 114 | if (GNUNET_OK != |
115 | GNUNET_FS_directory_builder_finish (db, &dsize, &ddata)) | ||
115 | { | 116 | { |
116 | GNUNET_break (0); | 117 | GNUNET_break (0); |
117 | GNUNET_free (output_filename); | 118 | GNUNET_free (output_filename); |
118 | return; | 119 | return; |
119 | } | 120 | } |
120 | if (dsize != GNUNET_DISK_fn_write (output_filename, | 121 | (void) GNUNET_DISK_directory_remove (output_filename); |
121 | ddata, | 122 | if (GNUNET_OK != |
122 | dsize, | 123 | GNUNET_DISK_fn_write (output_filename, |
123 | GNUNET_DISK_PERM_USER_READ | 124 | ddata, |
124 | | GNUNET_DISK_PERM_USER_WRITE)) | 125 | dsize, |
126 | GNUNET_DISK_PERM_USER_READ | ||
127 | | GNUNET_DISK_PERM_USER_WRITE)) | ||
125 | { | 128 | { |
126 | fprintf (stderr, | 129 | fprintf (stderr, |
127 | _ ("Failed to write directory with search results to `%s'\n"), | 130 | _ ("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, | |||
299 | "USE_INDEX")) | 299 | "USE_INDEX")) |
300 | { | 300 | { |
301 | fn1 = GNUNET_DISK_mktemp ("gnunet-download-indexed-test"); | 301 | fn1 = GNUNET_DISK_mktemp ("gnunet-download-indexed-test"); |
302 | GNUNET_assert (FILESIZE == | 302 | (void) GNUNET_DISK_directory_remove (fn1); |
303 | GNUNET_DISK_fn_write (fn1, buf, FILESIZE, | 303 | GNUNET_assert (GNUNET_OK == |
304 | GNUNET_DISK_fn_write (fn1, | ||
305 | buf, | ||
306 | FILESIZE, | ||
304 | GNUNET_DISK_PERM_USER_READ | 307 | GNUNET_DISK_PERM_USER_READ |
305 | | GNUNET_DISK_PERM_USER_WRITE)); | 308 | | GNUNET_DISK_PERM_USER_WRITE)); |
306 | GNUNET_free (buf); | 309 | 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, | |||
82 | buf = GNUNET_malloc (FILESIZE); | 82 | buf = GNUNET_malloc (FILESIZE); |
83 | for (i = 0; i < FILESIZE; i++) | 83 | for (i = 0; i < FILESIZE; i++) |
84 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | 84 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); |
85 | GNUNET_assert (FILESIZE == | 85 | (void) GNUNET_DISK_directory_remove (fn1); |
86 | GNUNET_assert (GNUNET_OK == | ||
86 | GNUNET_DISK_fn_write (fn1, buf, FILESIZE, | 87 | GNUNET_DISK_fn_write (fn1, buf, FILESIZE, |
87 | GNUNET_DISK_PERM_USER_READ | 88 | GNUNET_DISK_PERM_USER_READ |
88 | | GNUNET_DISK_PERM_USER_WRITE)); | 89 | | GNUNET_DISK_PERM_USER_WRITE)); |
@@ -92,7 +93,8 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
92 | buf = GNUNET_malloc (FILESIZE); | 93 | buf = GNUNET_malloc (FILESIZE); |
93 | for (i = 0; i < FILESIZE; i++) | 94 | for (i = 0; i < FILESIZE; i++) |
94 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | 95 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); |
95 | GNUNET_assert (FILESIZE == | 96 | (void) GNUNET_DISK_directory_remove (fn2); |
97 | GNUNET_assert (GNUNET_OK == | ||
96 | GNUNET_DISK_fn_write (fn2, buf, FILESIZE, | 98 | GNUNET_DISK_fn_write (fn2, buf, FILESIZE, |
97 | GNUNET_DISK_PERM_USER_READ | 99 | GNUNET_DISK_PERM_USER_READ |
98 | | GNUNET_DISK_PERM_USER_WRITE)); | 100 | | 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, | |||
198 | buf = GNUNET_malloc (FILESIZE); | 198 | buf = GNUNET_malloc (FILESIZE); |
199 | for (i = 0; i < FILESIZE; i++) | 199 | for (i = 0; i < FILESIZE; i++) |
200 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | 200 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); |
201 | GNUNET_assert (FILESIZE == | 201 | (void) GNUNET_DISK_directory_remove (fn1); |
202 | GNUNET_assert (GNUNET_OK == | ||
202 | GNUNET_DISK_fn_write (fn1, buf, FILESIZE, | 203 | GNUNET_DISK_fn_write (fn1, buf, FILESIZE, |
203 | GNUNET_DISK_PERM_USER_READ | 204 | GNUNET_DISK_PERM_USER_READ |
204 | | GNUNET_DISK_PERM_USER_WRITE)); | 205 | | GNUNET_DISK_PERM_USER_WRITE)); |
@@ -208,7 +209,8 @@ run (void *cls, | |||
208 | buf = GNUNET_malloc (FILESIZE); | 209 | buf = GNUNET_malloc (FILESIZE); |
209 | for (i = 0; i < FILESIZE; i++) | 210 | for (i = 0; i < FILESIZE; i++) |
210 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | 211 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); |
211 | GNUNET_assert (FILESIZE == | 212 | (void) GNUNET_DISK_directory_remove (fn2); |
213 | GNUNET_assert (GNUNET_OK == | ||
212 | GNUNET_DISK_fn_write (fn2, buf, FILESIZE, | 214 | GNUNET_DISK_fn_write (fn2, buf, FILESIZE, |
213 | GNUNET_DISK_PERM_USER_READ | 215 | GNUNET_DISK_PERM_USER_READ |
214 | | GNUNET_DISK_PERM_USER_WRITE)); | 216 | | 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, | |||
184 | buf = GNUNET_malloc (FILESIZE); | 184 | buf = GNUNET_malloc (FILESIZE); |
185 | for (i = 0; i < FILESIZE; i++) | 185 | for (i = 0; i < FILESIZE; i++) |
186 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | 186 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); |
187 | GNUNET_assert (FILESIZE == | 187 | (void) GNUNET_DISK_directory_remove (fn1); |
188 | GNUNET_assert (GNUNET_OK == | ||
188 | GNUNET_DISK_fn_write (fn1, buf, FILESIZE, | 189 | GNUNET_DISK_fn_write (fn1, buf, FILESIZE, |
189 | GNUNET_DISK_PERM_USER_READ | 190 | GNUNET_DISK_PERM_USER_READ |
190 | | GNUNET_DISK_PERM_USER_WRITE)); | 191 | | GNUNET_DISK_PERM_USER_WRITE)); |
@@ -194,7 +195,8 @@ run (void *cls, | |||
194 | buf = GNUNET_malloc (FILESIZE); | 195 | buf = GNUNET_malloc (FILESIZE); |
195 | for (i = 0; i < FILESIZE; i++) | 196 | for (i = 0; i < FILESIZE; i++) |
196 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | 197 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); |
197 | GNUNET_assert (FILESIZE == | 198 | (void) GNUNET_DISK_directory_remove (fn2); |
199 | GNUNET_assert (GNUNET_OK == | ||
198 | GNUNET_DISK_fn_write (fn2, buf, FILESIZE, | 200 | GNUNET_DISK_fn_write (fn2, buf, FILESIZE, |
199 | GNUNET_DISK_PERM_USER_READ | 201 | GNUNET_DISK_PERM_USER_READ |
200 | | GNUNET_DISK_PERM_USER_WRITE)); | 202 | | 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, | |||
258 | buf = GNUNET_malloc (FILESIZE); | 258 | buf = GNUNET_malloc (FILESIZE); |
259 | for (i = 0; i < FILESIZE; i++) | 259 | for (i = 0; i < FILESIZE; i++) |
260 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | 260 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); |
261 | GNUNET_assert (FILESIZE == | 261 | (void) GNUNET_DISK_directory_remove (fn1); |
262 | GNUNET_assert (GNUNET_OK == | ||
262 | GNUNET_DISK_fn_write (fn1, buf, FILESIZE, | 263 | GNUNET_DISK_fn_write (fn1, buf, FILESIZE, |
263 | GNUNET_DISK_PERM_USER_READ | 264 | GNUNET_DISK_PERM_USER_READ |
264 | | GNUNET_DISK_PERM_USER_WRITE)); | 265 | | GNUNET_DISK_PERM_USER_WRITE)); |
@@ -268,7 +269,8 @@ run (void *cls, | |||
268 | buf = GNUNET_malloc (FILESIZE); | 269 | buf = GNUNET_malloc (FILESIZE); |
269 | for (i = 0; i < FILESIZE; i++) | 270 | for (i = 0; i < FILESIZE; i++) |
270 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | 271 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); |
271 | GNUNET_assert (FILESIZE == | 272 | (void) GNUNET_DISK_directory_remove (fn2); |
273 | GNUNET_assert (GNUNET_OK == | ||
272 | GNUNET_DISK_fn_write (fn2, buf, FILESIZE, | 274 | GNUNET_DISK_fn_write (fn2, buf, FILESIZE, |
273 | GNUNET_DISK_PERM_USER_READ | 275 | GNUNET_DISK_PERM_USER_READ |
274 | | GNUNET_DISK_PERM_USER_WRITE)); | 276 | | 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, | |||
197 | buf = GNUNET_malloc (FILESIZE); | 197 | buf = GNUNET_malloc (FILESIZE); |
198 | for (i = 0; i < FILESIZE; i++) | 198 | for (i = 0; i < FILESIZE; i++) |
199 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | 199 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); |
200 | GNUNET_assert (FILESIZE == | 200 | (void) GNUNET_DISK_directory_remove (fn); |
201 | GNUNET_assert (GNUNET_OK == | ||
201 | GNUNET_DISK_fn_write (fn, buf, FILESIZE, | 202 | GNUNET_DISK_fn_write (fn, buf, FILESIZE, |
202 | GNUNET_DISK_PERM_USER_READ | 203 | GNUNET_DISK_PERM_USER_READ |
203 | | GNUNET_DISK_PERM_USER_WRITE)); | 204 | | 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, | |||
267 | buf = GNUNET_malloc (FILESIZE); | 267 | buf = GNUNET_malloc (FILESIZE); |
268 | for (i = 0; i < FILESIZE; i++) | 268 | for (i = 0; i < FILESIZE; i++) |
269 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); | 269 | buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); |
270 | GNUNET_assert (FILESIZE == | 270 | (void) GNUNET_DISK_directory_remove (fn); |
271 | GNUNET_assert (GNUNET_OK == | ||
271 | GNUNET_DISK_fn_write (fn, buf, FILESIZE, | 272 | GNUNET_DISK_fn_write (fn, buf, FILESIZE, |
272 | GNUNET_DISK_PERM_USER_READ | 273 | GNUNET_DISK_PERM_USER_READ |
273 | | GNUNET_DISK_PERM_USER_WRITE)); | 274 | | 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, | |||
697 | 697 | ||
698 | 698 | ||
699 | /** | 699 | /** |
700 | * Handler for CREATE message from client, creates | 700 | * Handler for CREATE message from client, creates new identity. |
701 | * new identity. | ||
702 | * | 701 | * |
703 | * @param cls unused | 702 | * @param cls unused |
704 | * @param client who sent the message | 703 | * @param client who sent the message |
@@ -737,8 +736,7 @@ handle_create_message (void *cls, | |||
737 | ego); | 736 | ego); |
738 | send_result_code (client, 0, NULL); | 737 | send_result_code (client, 0, NULL); |
739 | fn = get_ego_filename (ego); | 738 | fn = get_ego_filename (ego); |
740 | (void) GNUNET_DISK_directory_create_for_file (fn); | 739 | if (GNUNET_OK != |
741 | if (sizeof(struct GNUNET_IDENTITY_PrivateKey) != | ||
742 | GNUNET_DISK_fn_write (fn, | 740 | GNUNET_DISK_fn_write (fn, |
743 | &crm->private_key, | 741 | &crm->private_key, |
744 | sizeof(struct GNUNET_IDENTITY_PrivateKey), | 742 | 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 | |||
345 | * #GNUNET_NO to stop iteration with no error, | 345 | * #GNUNET_NO to stop iteration with no error, |
346 | * #GNUNET_SYSERR to abort iteration with error! | 346 | * #GNUNET_SYSERR to abort iteration with error! |
347 | */ | 347 | */ |
348 | typedef int | 348 | typedef enum GNUNET_GenericReturnValue |
349 | (*GNUNET_FileNameCallback) (void *cls, | 349 | (*GNUNET_FileNameCallback) (void *cls, |
350 | const char *filename); | 350 | const char *filename); |
351 | 351 | ||
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); | |||
82 | * @param filename name of the configuration file, NULL to load defaults | 82 | * @param filename name of the configuration file, NULL to load defaults |
83 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 83 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
84 | */ | 84 | */ |
85 | int | 85 | enum GNUNET_GenericReturnValue |
86 | GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, | 86 | GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, |
87 | const char *filename); | 87 | const char *filename); |
88 | 88 | ||
@@ -95,7 +95,7 @@ GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
95 | * @param defaults_d directory with the defaults | 95 | * @param defaults_d directory with the defaults |
96 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 96 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
97 | */ | 97 | */ |
98 | int | 98 | enum GNUNET_GenericReturnValue |
99 | GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg, | 99 | GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg, |
100 | const char *defaults_d); | 100 | const char *defaults_d); |
101 | 101 | ||
@@ -120,7 +120,7 @@ GNUNET_CONFIGURATION_default (void); | |||
120 | * @param filename name of the configuration file | 120 | * @param filename name of the configuration file |
121 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 121 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
122 | */ | 122 | */ |
123 | int | 123 | enum GNUNET_GenericReturnValue |
124 | GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, | 124 | GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, |
125 | const char *filename); | 125 | const char *filename); |
126 | 126 | ||
@@ -149,7 +149,7 @@ GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
149 | * when we come across them | 149 | * when we come across them |
150 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 150 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
151 | */ | 151 | */ |
152 | int | 152 | enum GNUNET_GenericReturnValue |
153 | GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, | 153 | GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, |
154 | const char *mem, | 154 | const char *mem, |
155 | size_t size, | 155 | size_t size, |
@@ -163,19 +163,20 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
163 | * @param filename where to write the configuration | 163 | * @param filename where to write the configuration |
164 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 164 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
165 | */ | 165 | */ |
166 | int | 166 | enum GNUNET_GenericReturnValue |
167 | GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, | 167 | GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, |
168 | const char *filename); | 168 | const char *filename); |
169 | 169 | ||
170 | 170 | ||
171 | /** | 171 | /** |
172 | * Write only configuration entries that have been changed to configuration file | 172 | * Write only configuration entries that have been changed to configuration file |
173 | * | ||
173 | * @param cfg_default default configuration | 174 | * @param cfg_default default configuration |
174 | * @param cfg_new new configuration | 175 | * @param cfg_new new configuration |
175 | * @param filename where to write the configuration diff between default and new | 176 | * @param filename where to write the configuration diff between default and new |
176 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 177 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
177 | */ | 178 | */ |
178 | int | 179 | enum GNUNET_GenericReturnValue |
179 | GNUNET_CONFIGURATION_write_diffs (const struct | 180 | GNUNET_CONFIGURATION_write_diffs (const struct |
180 | GNUNET_CONFIGURATION_Handle *cfg_default, | 181 | GNUNET_CONFIGURATION_Handle *cfg_default, |
181 | const struct | 182 | const struct |
@@ -204,7 +205,7 @@ GNUNET_CONFIGURATION_get_diff (const struct | |||
204 | * @param cfg configuration to inspect | 205 | * @param cfg configuration to inspect |
205 | * @return #GNUNET_NO if clean, #GNUNET_YES if dirty, #GNUNET_SYSERR on error (i.e. last save failed) | 206 | * @return #GNUNET_NO if clean, #GNUNET_YES if dirty, #GNUNET_SYSERR on error (i.e. last save failed) |
206 | */ | 207 | */ |
207 | int | 208 | enum GNUNET_GenericReturnValue |
208 | GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg); | 209 | GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg); |
209 | 210 | ||
210 | 211 | ||
@@ -215,7 +216,7 @@ GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg); | |||
215 | * @param cfg the configuration | 216 | * @param cfg the configuration |
216 | * @return status code | 217 | * @return status code |
217 | */ | 218 | */ |
218 | typedef int | 219 | typedef enum GNUNET_GenericReturnValue |
219 | (*GNUNET_CONFIGURATION_Callback)(void *cls, | 220 | (*GNUNET_CONFIGURATION_Callback)(void *cls, |
220 | const struct GNUNET_CONFIGURATION_Handle *cfg); | 221 | const struct GNUNET_CONFIGURATION_Handle *cfg); |
221 | 222 | ||
@@ -231,7 +232,7 @@ typedef int | |||
231 | * @return #GNUNET_SYSERR if parsing the configuration failed, | 232 | * @return #GNUNET_SYSERR if parsing the configuration failed, |
232 | * otherwise return value from @a cb. | 233 | * otherwise return value from @a cb. |
233 | */ | 234 | */ |
234 | int | 235 | enum GNUNET_GenericReturnValue |
235 | GNUNET_CONFIGURATION_parse_and_run (const char *filename, | 236 | GNUNET_CONFIGURATION_parse_and_run (const char *filename, |
236 | GNUNET_CONFIGURATION_Callback cb, | 237 | GNUNET_CONFIGURATION_Callback cb, |
237 | void *cb_cls); | 238 | void *cb_cls); |
@@ -311,7 +312,7 @@ GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
311 | * @param number where to store the numeric value of the option | 312 | * @param number where to store the numeric value of the option |
312 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 313 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
313 | */ | 314 | */ |
314 | int | 315 | enum GNUNET_GenericReturnValue |
315 | GNUNET_CONFIGURATION_get_value_number (const struct | 316 | GNUNET_CONFIGURATION_get_value_number (const struct |
316 | GNUNET_CONFIGURATION_Handle *cfg, | 317 | GNUNET_CONFIGURATION_Handle *cfg, |
317 | const char *section, | 318 | const char *section, |
@@ -328,7 +329,7 @@ GNUNET_CONFIGURATION_get_value_number (const struct | |||
328 | * @param number where to store the floating value of the option | 329 | * @param number where to store the floating value of the option |
329 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 330 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
330 | */ | 331 | */ |
331 | int | 332 | enum GNUNET_GenericReturnValue |
332 | GNUNET_CONFIGURATION_get_value_float (const struct | 333 | GNUNET_CONFIGURATION_get_value_float (const struct |
333 | GNUNET_CONFIGURATION_Handle *cfg, | 334 | GNUNET_CONFIGURATION_Handle *cfg, |
334 | const char *section, | 335 | const char *section, |
@@ -345,7 +346,7 @@ GNUNET_CONFIGURATION_get_value_float (const struct | |||
345 | * @param time set to the time value stored in the configuration | 346 | * @param time set to the time value stored in the configuration |
346 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 347 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
347 | */ | 348 | */ |
348 | int | 349 | enum GNUNET_GenericReturnValue |
349 | GNUNET_CONFIGURATION_get_value_time (const struct | 350 | GNUNET_CONFIGURATION_get_value_time (const struct |
350 | GNUNET_CONFIGURATION_Handle *cfg, | 351 | GNUNET_CONFIGURATION_Handle *cfg, |
351 | const char *section, | 352 | const char *section, |
@@ -362,7 +363,7 @@ GNUNET_CONFIGURATION_get_value_time (const struct | |||
362 | * @param size set to the size in bytes as stored in the configuration | 363 | * @param size set to the size in bytes as stored in the configuration |
363 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 364 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
364 | */ | 365 | */ |
365 | int | 366 | enum GNUNET_GenericReturnValue |
366 | GNUNET_CONFIGURATION_get_value_size (const struct | 367 | GNUNET_CONFIGURATION_get_value_size (const struct |
367 | GNUNET_CONFIGURATION_Handle *cfg, | 368 | GNUNET_CONFIGURATION_Handle *cfg, |
368 | const char *section, | 369 | const char *section, |
@@ -378,7 +379,7 @@ GNUNET_CONFIGURATION_get_value_size (const struct | |||
378 | * @param option option of interest | 379 | * @param option option of interest |
379 | * @return #GNUNET_YES if so, #GNUNET_NO if not. | 380 | * @return #GNUNET_YES if so, #GNUNET_NO if not. |
380 | */ | 381 | */ |
381 | int | 382 | enum GNUNET_GenericReturnValue |
382 | GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg, | 383 | GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg, |
383 | const char *section, | 384 | const char *section, |
384 | const char *option); | 385 | const char *option); |
@@ -394,12 +395,12 @@ GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
394 | * value, or NULL if option is not specified | 395 | * value, or NULL if option is not specified |
395 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 396 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
396 | */ | 397 | */ |
397 | int | 398 | enum GNUNET_GenericReturnValue |
398 | GNUNET_CONFIGURATION_get_value_string (const struct | 399 | GNUNET_CONFIGURATION_get_value_string ( |
399 | GNUNET_CONFIGURATION_Handle *cfg, | 400 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
400 | const char *section, | 401 | const char *section, |
401 | const char *option, | 402 | const char *option, |
402 | char **value); | 403 | char **value); |
403 | 404 | ||
404 | 405 | ||
405 | /** | 406 | /** |
@@ -413,7 +414,7 @@ GNUNET_CONFIGURATION_get_value_string (const struct | |||
413 | * value, or NULL if option is not specified | 414 | * value, or NULL if option is not specified |
414 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 415 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
415 | */ | 416 | */ |
416 | int | 417 | enum GNUNET_GenericReturnValue |
417 | GNUNET_CONFIGURATION_get_value_filename (const struct | 418 | GNUNET_CONFIGURATION_get_value_filename (const struct |
418 | GNUNET_CONFIGURATION_Handle *cfg, | 419 | GNUNET_CONFIGURATION_Handle *cfg, |
419 | const char *section, | 420 | const char *section, |
@@ -466,7 +467,7 @@ GNUNET_CONFIGURATION_iterate_section_values (const struct | |||
466 | * or NULL if option is not specified and no default given | 467 | * or NULL if option is not specified and no default given |
467 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 468 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
468 | */ | 469 | */ |
469 | int | 470 | enum GNUNET_GenericReturnValue |
470 | GNUNET_CONFIGURATION_get_value_choice (const struct | 471 | GNUNET_CONFIGURATION_get_value_choice (const struct |
471 | GNUNET_CONFIGURATION_Handle *cfg, | 472 | GNUNET_CONFIGURATION_Handle *cfg, |
472 | const char *section, | 473 | const char *section, |
@@ -483,7 +484,7 @@ GNUNET_CONFIGURATION_get_value_choice (const struct | |||
483 | * @param option option of interest | 484 | * @param option option of interest |
484 | * @return #GNUNET_YES, #GNUNET_NO or if option has no valid value, #GNUNET_SYSERR | 485 | * @return #GNUNET_YES, #GNUNET_NO or if option has no valid value, #GNUNET_SYSERR |
485 | */ | 486 | */ |
486 | int | 487 | enum GNUNET_GenericReturnValue |
487 | GNUNET_CONFIGURATION_get_value_yesno (const struct | 488 | GNUNET_CONFIGURATION_get_value_yesno (const struct |
488 | GNUNET_CONFIGURATION_Handle *cfg, | 489 | GNUNET_CONFIGURATION_Handle *cfg, |
489 | const char *section, | 490 | const char *section, |
@@ -502,7 +503,7 @@ GNUNET_CONFIGURATION_get_value_yesno (const struct | |||
502 | * #GNUNET_NO is the value does not exist | 503 | * #GNUNET_NO is the value does not exist |
503 | * #GNUNET_SYSERR on decoding error | 504 | * #GNUNET_SYSERR on decoding error |
504 | */ | 505 | */ |
505 | int | 506 | enum GNUNET_GenericReturnValue |
506 | GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg, | 507 | GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg, |
507 | const char *section, | 508 | const char *section, |
508 | const char *option, | 509 | const char *option, |
@@ -527,9 +528,9 @@ GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
527 | * @return $-expanded string | 528 | * @return $-expanded string |
528 | */ | 529 | */ |
529 | char * | 530 | char * |
530 | GNUNET_CONFIGURATION_expand_dollar (const struct | 531 | GNUNET_CONFIGURATION_expand_dollar ( |
531 | GNUNET_CONFIGURATION_Handle *cfg, | 532 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
532 | char *orig); | 533 | char *orig); |
533 | 534 | ||
534 | 535 | ||
535 | /** | 536 | /** |
@@ -573,7 +574,7 @@ GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
573 | * @return #GNUNET_OK on success, | 574 | * @return #GNUNET_OK on success, |
574 | * #GNUNET_SYSERR if the filename is not in the list | 575 | * #GNUNET_SYSERR if the filename is not in the list |
575 | */ | 576 | */ |
576 | int | 577 | enum GNUNET_GenericReturnValue |
577 | GNUNET_CONFIGURATION_remove_value_filename (struct | 578 | GNUNET_CONFIGURATION_remove_value_filename (struct |
578 | GNUNET_CONFIGURATION_Handle *cfg, | 579 | GNUNET_CONFIGURATION_Handle *cfg, |
579 | const char *section, | 580 | const char *section, |
@@ -592,7 +593,7 @@ GNUNET_CONFIGURATION_remove_value_filename (struct | |||
592 | * @return #GNUNET_OK on success, | 593 | * @return #GNUNET_OK on success, |
593 | * #GNUNET_SYSERR if the filename already in the list | 594 | * #GNUNET_SYSERR if the filename already in the list |
594 | */ | 595 | */ |
595 | int | 596 | enum GNUNET_GenericReturnValue |
596 | GNUNET_CONFIGURATION_append_value_filename (struct | 597 | GNUNET_CONFIGURATION_append_value_filename (struct |
597 | GNUNET_CONFIGURATION_Handle *cfg, | 598 | GNUNET_CONFIGURATION_Handle *cfg, |
598 | const char *section, | 599 | 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 ( | |||
1023 | * @param ... pair of void * & size_t for context chunks, terminated by NULL | 1023 | * @param ... pair of void * & size_t for context chunks, terminated by NULL |
1024 | * @return #GNUNET_YES on success | 1024 | * @return #GNUNET_YES on success |
1025 | */ | 1025 | */ |
1026 | int | 1026 | enum GNUNET_GenericReturnValue |
1027 | GNUNET_CRYPTO_hkdf (void *result, | 1027 | GNUNET_CRYPTO_hkdf (void *result, |
1028 | size_t out_len, | 1028 | size_t out_len, |
1029 | int xtr_algo, | 1029 | int xtr_algo, |
@@ -1049,7 +1049,7 @@ GNUNET_CRYPTO_hkdf (void *result, | |||
1049 | * @param argp va_list of void * & size_t pairs for context chunks | 1049 | * @param argp va_list of void * & size_t pairs for context chunks |
1050 | * @return #GNUNET_YES on success | 1050 | * @return #GNUNET_YES on success |
1051 | */ | 1051 | */ |
1052 | int | 1052 | enum GNUNET_GenericReturnValue |
1053 | GNUNET_CRYPTO_hkdf_v (void *result, | 1053 | GNUNET_CRYPTO_hkdf_v (void *result, |
1054 | size_t out_len, | 1054 | size_t out_len, |
1055 | int xtr_algo, | 1055 | int xtr_algo, |
@@ -1072,7 +1072,7 @@ GNUNET_CRYPTO_hkdf_v (void *result, | |||
1072 | * @param argp va_list of void * & size_t pairs for context chunks | 1072 | * @param argp va_list of void * & size_t pairs for context chunks |
1073 | * @return #GNUNET_YES on success | 1073 | * @return #GNUNET_YES on success |
1074 | */ | 1074 | */ |
1075 | int | 1075 | enum GNUNET_GenericReturnValue |
1076 | GNUNET_CRYPTO_kdf_v (void *result, | 1076 | GNUNET_CRYPTO_kdf_v (void *result, |
1077 | size_t out_len, | 1077 | size_t out_len, |
1078 | const void *xts, | 1078 | const void *xts, |
@@ -1116,7 +1116,7 @@ GNUNET_CRYPTO_kdf_mod_mpi (gcry_mpi_t *r, | |||
1116 | * @param ... void * & size_t pairs for context chunks | 1116 | * @param ... void * & size_t pairs for context chunks |
1117 | * @return #GNUNET_YES on success | 1117 | * @return #GNUNET_YES on success |
1118 | */ | 1118 | */ |
1119 | int | 1119 | enum GNUNET_GenericReturnValue |
1120 | GNUNET_CRYPTO_kdf (void *result, | 1120 | GNUNET_CRYPTO_kdf (void *result, |
1121 | size_t out_len, | 1121 | size_t out_len, |
1122 | const void *xts, | 1122 | const void *xts, |
@@ -1215,7 +1215,7 @@ GNUNET_CRYPTO_eddsa_public_key_to_string ( | |||
1215 | * @param pub where to store the public key | 1215 | * @param pub where to store the public key |
1216 | * @return #GNUNET_OK on success | 1216 | * @return #GNUNET_OK on success |
1217 | */ | 1217 | */ |
1218 | int | 1218 | enum GNUNET_GenericReturnValue |
1219 | GNUNET_CRYPTO_ecdsa_public_key_from_string ( | 1219 | GNUNET_CRYPTO_ecdsa_public_key_from_string ( |
1220 | const char *enc, | 1220 | const char *enc, |
1221 | size_t enclen, | 1221 | size_t enclen, |
@@ -1245,7 +1245,7 @@ GNUNET_CRYPTO_eddsa_private_key_from_string ( | |||
1245 | * @param pub where to store the public key | 1245 | * @param pub where to store the public key |
1246 | * @return #GNUNET_OK on success | 1246 | * @return #GNUNET_OK on success |
1247 | */ | 1247 | */ |
1248 | int | 1248 | enum GNUNET_GenericReturnValue |
1249 | GNUNET_CRYPTO_eddsa_public_key_from_string ( | 1249 | GNUNET_CRYPTO_eddsa_public_key_from_string ( |
1250 | const char *enc, | 1250 | const char *enc, |
1251 | size_t enclen, | 1251 | size_t enclen, |
@@ -1267,7 +1267,7 @@ GNUNET_CRYPTO_eddsa_public_key_from_string ( | |||
1267 | * @return #GNUNET_OK on success, #GNUNET_NO if @a do_create was set but | 1267 | * @return #GNUNET_OK on success, #GNUNET_NO if @a do_create was set but |
1268 | * we found an existing file, #GNUNET_SYSERR on failure | 1268 | * we found an existing file, #GNUNET_SYSERR on failure |
1269 | */ | 1269 | */ |
1270 | int | 1270 | enum GNUNET_GenericReturnValue |
1271 | GNUNET_CRYPTO_ecdsa_key_from_file (const char *filename, | 1271 | GNUNET_CRYPTO_ecdsa_key_from_file (const char *filename, |
1272 | int do_create, | 1272 | int do_create, |
1273 | struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey); | 1273 | struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey); |
@@ -1606,7 +1606,7 @@ GNUNET_CRYPTO_ecc_dlog_release (struct GNUNET_CRYPTO_EccDlogContext *dlc); | |||
1606 | * @param key_material where to write the key material (xyG) | 1606 | * @param key_material where to write the key material (xyG) |
1607 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success | 1607 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success |
1608 | */ | 1608 | */ |
1609 | int | 1609 | enum GNUNET_GenericReturnValue |
1610 | GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, | 1610 | GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, |
1611 | const struct GNUNET_CRYPTO_EcdhePublicKey *pub, | 1611 | const struct GNUNET_CRYPTO_EcdhePublicKey *pub, |
1612 | struct GNUNET_HashCode *key_material); | 1612 | struct GNUNET_HashCode *key_material); |
@@ -1622,7 +1622,7 @@ GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, | |||
1622 | * @param key_material where to write the key material H(h(x)yG) | 1622 | * @param key_material where to write the key material H(h(x)yG) |
1623 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success | 1623 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success |
1624 | */ | 1624 | */ |
1625 | int | 1625 | enum GNUNET_GenericReturnValue |
1626 | GNUNET_CRYPTO_eddsa_ecdh (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, | 1626 | GNUNET_CRYPTO_eddsa_ecdh (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, |
1627 | const struct GNUNET_CRYPTO_EcdhePublicKey *pub, | 1627 | const struct GNUNET_CRYPTO_EcdhePublicKey *pub, |
1628 | struct GNUNET_HashCode *key_material); | 1628 | struct GNUNET_HashCode *key_material); |
@@ -1637,7 +1637,7 @@ GNUNET_CRYPTO_eddsa_ecdh (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, | |||
1637 | * @param key_material where to write the key material H(h(x)yG) | 1637 | * @param key_material where to write the key material H(h(x)yG) |
1638 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success | 1638 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success |
1639 | */ | 1639 | */ |
1640 | int | 1640 | enum GNUNET_GenericReturnValue |
1641 | GNUNET_CRYPTO_ecdsa_ecdh (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, | 1641 | GNUNET_CRYPTO_ecdsa_ecdh (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, |
1642 | const struct GNUNET_CRYPTO_EcdhePublicKey *pub, | 1642 | const struct GNUNET_CRYPTO_EcdhePublicKey *pub, |
1643 | struct GNUNET_HashCode *key_material); | 1643 | struct GNUNET_HashCode *key_material); |
@@ -1653,7 +1653,7 @@ GNUNET_CRYPTO_ecdsa_ecdh (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, | |||
1653 | * @param key_material where to write the key material H(yX)=H(h(x)yG) | 1653 | * @param key_material where to write the key material H(yX)=H(h(x)yG) |
1654 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success | 1654 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success |
1655 | */ | 1655 | */ |
1656 | int | 1656 | enum GNUNET_GenericReturnValue |
1657 | GNUNET_CRYPTO_ecdh_eddsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, | 1657 | GNUNET_CRYPTO_ecdh_eddsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, |
1658 | const struct GNUNET_CRYPTO_EddsaPublicKey *pub, | 1658 | const struct GNUNET_CRYPTO_EddsaPublicKey *pub, |
1659 | struct GNUNET_HashCode *key_material); | 1659 | struct GNUNET_HashCode *key_material); |
@@ -1668,7 +1668,7 @@ GNUNET_CRYPTO_ecdh_eddsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, | |||
1668 | * @param key_material where to write the key material H(yX)=H(h(x)yG) | 1668 | * @param key_material where to write the key material H(yX)=H(h(x)yG) |
1669 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success | 1669 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success |
1670 | */ | 1670 | */ |
1671 | int | 1671 | enum GNUNET_GenericReturnValue |
1672 | GNUNET_CRYPTO_ecdh_ecdsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, | 1672 | GNUNET_CRYPTO_ecdh_ecdsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, |
1673 | const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, | 1673 | const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, |
1674 | struct GNUNET_HashCode *key_material); | 1674 | struct GNUNET_HashCode *key_material); |
@@ -1689,7 +1689,7 @@ GNUNET_CRYPTO_ecdh_ecdsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, | |||
1689 | * @param[out] sig where to write the signature | 1689 | * @param[out] sig where to write the signature |
1690 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success | 1690 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success |
1691 | */ | 1691 | */ |
1692 | int | 1692 | enum GNUNET_GenericReturnValue |
1693 | GNUNET_CRYPTO_eddsa_sign_ ( | 1693 | GNUNET_CRYPTO_eddsa_sign_ ( |
1694 | const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, | 1694 | const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, |
1695 | const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, | 1695 | const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, |
@@ -1736,7 +1736,7 @@ GNUNET_CRYPTO_eddsa_sign_ ( | |||
1736 | * @param[out] sig where to write the signature | 1736 | * @param[out] sig where to write the signature |
1737 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success | 1737 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success |
1738 | */ | 1738 | */ |
1739 | int | 1739 | enum GNUNET_GenericReturnValue |
1740 | GNUNET_CRYPTO_ecdsa_sign_ ( | 1740 | GNUNET_CRYPTO_ecdsa_sign_ ( |
1741 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, | 1741 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, |
1742 | const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, | 1742 | const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, |
@@ -2333,7 +2333,7 @@ GNUNET_CRYPTO_rsa_unblind (const struct GNUNET_CRYPTO_RsaSignature *sig, | |||
2333 | * @param public_key public key of the signer | 2333 | * @param public_key public key of the signer |
2334 | * @returns #GNUNET_YES if ok, #GNUNET_NO if RSA key is malicious, #GNUNET_SYSERR if signature | 2334 | * @returns #GNUNET_YES if ok, #GNUNET_NO if RSA key is malicious, #GNUNET_SYSERR if signature |
2335 | */ | 2335 | */ |
2336 | int | 2336 | enum GNUNET_GenericReturnValue |
2337 | GNUNET_CRYPTO_rsa_verify (const struct GNUNET_HashCode *hash, | 2337 | GNUNET_CRYPTO_rsa_verify (const struct GNUNET_HashCode *hash, |
2338 | const struct GNUNET_CRYPTO_RsaSignature *sig, | 2338 | const struct GNUNET_CRYPTO_RsaSignature *sig, |
2339 | const struct GNUNET_CRYPTO_RsaPublicKey *public_key); | 2339 | 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 | |||
251 | * @param h handle to check | 251 | * @param h handle to check |
252 | * @return #GNUNET_YES if invalid, #GNUNET_NO if valid | 252 | * @return #GNUNET_YES if invalid, #GNUNET_NO if valid |
253 | */ | 253 | */ |
254 | int | 254 | enum GNUNET_GenericReturnValue |
255 | GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h); | 255 | GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h); |
256 | 256 | ||
257 | 257 | ||
@@ -263,7 +263,7 @@ GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h); | |||
263 | * @return #GNUNET_YES if yes, #GNUNET_NO if not a file, #GNUNET_SYSERR if something | 263 | * @return #GNUNET_YES if yes, #GNUNET_NO if not a file, #GNUNET_SYSERR if something |
264 | * else (will print an error message in that case, too). | 264 | * else (will print an error message in that case, too). |
265 | */ | 265 | */ |
266 | int | 266 | enum GNUNET_GenericReturnValue |
267 | GNUNET_DISK_file_test (const char *fil); | 267 | GNUNET_DISK_file_test (const char *fil); |
268 | 268 | ||
269 | 269 | ||
@@ -304,7 +304,7 @@ GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, | |||
304 | * and return #GNUNET_SYSERR for directories. | 304 | * and return #GNUNET_SYSERR for directories. |
305 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success | 305 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success |
306 | */ | 306 | */ |
307 | int | 307 | enum GNUNET_GenericReturnValue |
308 | GNUNET_DISK_file_size (const char *filename, | 308 | GNUNET_DISK_file_size (const char *filename, |
309 | uint64_t *size, | 309 | uint64_t *size, |
310 | int include_symbolic_links, | 310 | int include_symbolic_links, |
@@ -326,7 +326,7 @@ GNUNET_DISK_file_size (const char *filename, | |||
326 | * @param ino set to the inode ID | 326 | * @param ino set to the inode ID |
327 | * @return #GNUNET_OK on success | 327 | * @return #GNUNET_OK on success |
328 | */ | 328 | */ |
329 | int | 329 | enum GNUNET_GenericReturnValue |
330 | GNUNET_DISK_file_get_identifiers (const char *filename, | 330 | GNUNET_DISK_file_get_identifiers (const char *filename, |
331 | uint64_t *dev, | 331 | uint64_t *dev, |
332 | uint64_t *ino); | 332 | uint64_t *ino); |
@@ -385,7 +385,7 @@ GNUNET_DISK_file_open (const char *fn, | |||
385 | * @param size where to write size of the file | 385 | * @param size where to write size of the file |
386 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 386 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
387 | */ | 387 | */ |
388 | int | 388 | enum GNUNET_GenericReturnValue |
389 | GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh, | 389 | GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh, |
390 | off_t *size); | 390 | off_t *size); |
391 | 391 | ||
@@ -447,7 +447,7 @@ GNUNET_DISK_pipe_from_fd (enum GNUNET_DISK_PipeFlags pf, | |||
447 | * @param p pipe | 447 | * @param p pipe |
448 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | 448 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
449 | */ | 449 | */ |
450 | int | 450 | enum GNUNET_GenericReturnValue |
451 | GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p); | 451 | GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p); |
452 | 452 | ||
453 | 453 | ||
@@ -458,7 +458,7 @@ GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p); | |||
458 | * @param end which end of the pipe to close | 458 | * @param end which end of the pipe to close |
459 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | 459 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
460 | */ | 460 | */ |
461 | int | 461 | enum GNUNET_GenericReturnValue |
462 | GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p, | 462 | GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p, |
463 | enum GNUNET_DISK_PipeEnd end); | 463 | enum GNUNET_DISK_PipeEnd end); |
464 | 464 | ||
@@ -485,7 +485,7 @@ GNUNET_DISK_pipe_detach_end (struct GNUNET_DISK_PipeHandle *p, | |||
485 | * @param h file handle | 485 | * @param h file handle |
486 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | 486 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
487 | */ | 487 | */ |
488 | int | 488 | enum GNUNET_GenericReturnValue |
489 | GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h); | 489 | GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h); |
490 | 490 | ||
491 | 491 | ||
@@ -609,16 +609,19 @@ GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle *h, | |||
609 | 609 | ||
610 | 610 | ||
611 | /** | 611 | /** |
612 | * Write a buffer to a file. If the file is longer than | 612 | * Write a buffer to a file atomically. The directory is created if |
613 | * the given buffer size, it will be truncated. | 613 | * necessary. Fail if @a filename already exists or if not exactly @a buf |
614 | * with @a buf_size bytes could be written to @a filename. | ||
614 | * | 615 | * |
615 | * @param fn file name | 616 | * @param fn file name |
616 | * @param buffer the data to write | 617 | * @param buffer the data to write |
617 | * @param n number of bytes to write | 618 | * @param n number of bytes to write |
618 | * @param mode file permissions | 619 | * @param mode file permissions |
619 | * @return number of bytes written on success, #GNUNET_SYSERR on error | 620 | * @return #GNUNET_OK on success, |
621 | * #GNUNET_NO if a file existed under @a filename | ||
622 | * #GNUNET_SYSERR on failure | ||
620 | */ | 623 | */ |
621 | ssize_t | 624 | enum GNUNET_GenericReturnValue |
622 | GNUNET_DISK_fn_write (const char *fn, | 625 | GNUNET_DISK_fn_write (const char *fn, |
623 | const void *buffer, | 626 | const void *buffer, |
624 | size_t n, | 627 | size_t n, |
@@ -632,7 +635,7 @@ GNUNET_DISK_fn_write (const char *fn, | |||
632 | * @param dst destination file name | 635 | * @param dst destination file name |
633 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 636 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
634 | */ | 637 | */ |
635 | int | 638 | enum GNUNET_GenericReturnValue |
636 | GNUNET_DISK_file_copy (const char *src, | 639 | GNUNET_DISK_file_copy (const char *src, |
637 | const char *dst); | 640 | const char *dst); |
638 | 641 | ||
@@ -659,7 +662,7 @@ GNUNET_DISK_directory_scan (const char *dir_name, | |||
659 | * @returns #GNUNET_OK on success, #GNUNET_SYSERR on failure, | 662 | * @returns #GNUNET_OK on success, #GNUNET_SYSERR on failure, |
660 | * #GNUNET_NO if directory exists but is not writeable | 663 | * #GNUNET_NO if directory exists but is not writeable |
661 | */ | 664 | */ |
662 | int | 665 | enum GNUNET_GenericReturnValue |
663 | GNUNET_DISK_directory_create_for_file (const char *filename); | 666 | GNUNET_DISK_directory_create_for_file (const char *filename); |
664 | 667 | ||
665 | 668 | ||
@@ -675,8 +678,9 @@ GNUNET_DISK_directory_create_for_file (const char *filename); | |||
675 | * @return #GNUNET_YES if yes, #GNUNET_NO if not; #GNUNET_SYSERR if it | 678 | * @return #GNUNET_YES if yes, #GNUNET_NO if not; #GNUNET_SYSERR if it |
676 | * does not exist or `stat`ed | 679 | * does not exist or `stat`ed |
677 | */ | 680 | */ |
678 | int | 681 | enum GNUNET_GenericReturnValue |
679 | GNUNET_DISK_directory_test (const char *fil, int is_readable); | 682 | GNUNET_DISK_directory_test (const char *fil, |
683 | int is_readable); | ||
680 | 684 | ||
681 | 685 | ||
682 | /** | 686 | /** |
@@ -685,7 +689,7 @@ GNUNET_DISK_directory_test (const char *fil, int is_readable); | |||
685 | * @param filename the file to remove | 689 | * @param filename the file to remove |
686 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 690 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
687 | */ | 691 | */ |
688 | int | 692 | enum GNUNET_GenericReturnValue |
689 | GNUNET_DISK_directory_remove (const char *filename); | 693 | GNUNET_DISK_directory_remove (const char *filename); |
690 | 694 | ||
691 | 695 | ||
@@ -707,7 +711,7 @@ GNUNET_DISK_purge_cfg_dir (const char *cfg_filename, | |||
707 | * @param dir the directory to create | 711 | * @param dir the directory to create |
708 | * @returns #GNUNET_SYSERR on failure, #GNUNET_OK otherwise | 712 | * @returns #GNUNET_SYSERR on failure, #GNUNET_OK otherwise |
709 | */ | 713 | */ |
710 | int | 714 | enum GNUNET_GenericReturnValue |
711 | GNUNET_DISK_directory_create (const char *dir); | 715 | GNUNET_DISK_directory_create (const char *dir); |
712 | 716 | ||
713 | 717 | ||
@@ -725,7 +729,7 @@ GNUNET_DISK_filename_canonicalize (char *fn); | |||
725 | * @param user new owner of the file | 729 | * @param user new owner of the file |
726 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 730 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
727 | */ | 731 | */ |
728 | int | 732 | enum GNUNET_GenericReturnValue |
729 | GNUNET_DISK_file_change_owner (const char *filename, | 733 | GNUNET_DISK_file_change_owner (const char *filename, |
730 | const char *user); | 734 | const char *user); |
731 | 735 | ||
@@ -758,7 +762,7 @@ GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h, | |||
758 | * @param h mapping handle | 762 | * @param h mapping handle |
759 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | 763 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
760 | */ | 764 | */ |
761 | int | 765 | enum GNUNET_GenericReturnValue |
762 | GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h); | 766 | GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h); |
763 | 767 | ||
764 | 768 | ||
@@ -768,7 +772,7 @@ GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h); | |||
768 | * @param h handle to an open file | 772 | * @param h handle to an open file |
769 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | 773 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
770 | */ | 774 | */ |
771 | int | 775 | enum GNUNET_GenericReturnValue |
772 | GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h); | 776 | GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h); |
773 | 777 | ||
774 | 778 | ||
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, | |||
824 | * Write our current proof to disk. | 824 | * Write our current proof to disk. |
825 | */ | 825 | */ |
826 | static void | 826 | static void |
827 | write_proof () | 827 | write_proof (void) |
828 | { | 828 | { |
829 | char *proof; | 829 | char *proof; |
830 | 830 | ||
831 | if (GNUNET_OK != | 831 | if (GNUNET_OK != |
832 | GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "PROOFFILE", &proof)) | 832 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
833 | "NSE", | ||
834 | "PROOFFILE", | ||
835 | &proof)) | ||
833 | return; | 836 | return; |
834 | if (sizeof(my_proof) != GNUNET_DISK_fn_write (proof, | 837 | (void) GNUNET_DISK_directory_remove (proof); |
835 | &my_proof, | 838 | if (GNUNET_OK != |
836 | sizeof(my_proof), | 839 | GNUNET_DISK_fn_write (proof, |
837 | GNUNET_DISK_PERM_USER_READ | 840 | &my_proof, |
838 | | GNUNET_DISK_PERM_USER_WRITE)) | 841 | sizeof(my_proof), |
839 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", proof); | 842 | GNUNET_DISK_PERM_USER_READ |
843 | | GNUNET_DISK_PERM_USER_WRITE)) | ||
844 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
845 | "write", | ||
846 | proof); | ||
840 | GNUNET_free (proof); | 847 | GNUNET_free (proof); |
841 | } | 848 | } |
842 | 849 | ||
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 () | |||
451 | fprintf (stderr, _ ("Failure: Received invalid %s\n"), "HELLO"); | 451 | fprintf (stderr, _ ("Failure: Received invalid %s\n"), "HELLO"); |
452 | return; | 452 | return; |
453 | } | 453 | } |
454 | if (GNUNET_SYSERR == GNUNET_DISK_fn_write (dump_hello, | 454 | if (GNUNET_SYSERR == |
455 | my_hello, | 455 | GNUNET_DISK_fn_write (dump_hello, |
456 | size, | 456 | my_hello, |
457 | GNUNET_DISK_PERM_USER_READ | 457 | size, |
458 | | GNUNET_DISK_PERM_USER_WRITE | 458 | GNUNET_DISK_PERM_USER_READ |
459 | | GNUNET_DISK_PERM_GROUP_READ | 459 | | GNUNET_DISK_PERM_USER_WRITE |
460 | | GNUNET_DISK_PERM_OTHER_READ)) | 460 | | GNUNET_DISK_PERM_GROUP_READ |
461 | | GNUNET_DISK_PERM_OTHER_READ)) | ||
461 | { | 462 | { |
462 | fprintf (stderr, | 463 | fprintf (stderr, |
463 | _ ("Failed to write HELLO with %u bytes to file `%s'\n"), | 464 | _ ("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, | |||
807 | } | 807 | } |
808 | GNUNET_assert (pos == size); | 808 | GNUNET_assert (pos == size); |
809 | 809 | ||
810 | if (GNUNET_SYSERR == GNUNET_DISK_fn_write (fn, | 810 | if (GNUNET_SYSERR == |
811 | buffer, | 811 | GNUNET_DISK_fn_write (fn, |
812 | size, | 812 | buffer, |
813 | GNUNET_DISK_PERM_USER_READ | 813 | size, |
814 | | GNUNET_DISK_PERM_USER_WRITE | 814 | GNUNET_DISK_PERM_USER_READ |
815 | | GNUNET_DISK_PERM_GROUP_READ | 815 | | GNUNET_DISK_PERM_USER_WRITE |
816 | | GNUNET_DISK_PERM_OTHER_READ)) | 816 | | GNUNET_DISK_PERM_GROUP_READ |
817 | | GNUNET_DISK_PERM_OTHER_READ)) | ||
817 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn); | 818 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn); |
818 | else | 819 | else |
819 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 820 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -987,13 +988,15 @@ discard_hosts_helper (void *cls, const char *fn) | |||
987 | 988 | ||
988 | if (0 < write_pos) | 989 | if (0 < write_pos) |
989 | { | 990 | { |
990 | GNUNET_DISK_fn_write (fn, | 991 | (void) GNUNET_DISK_directory_remove (fn); |
991 | writebuffer, | 992 | GNUNET_assert (GNUNET_OK == |
992 | write_pos, | 993 | GNUNET_DISK_fn_write (fn, |
993 | GNUNET_DISK_PERM_USER_READ | 994 | writebuffer, |
994 | | GNUNET_DISK_PERM_USER_WRITE | 995 | write_pos, |
995 | | GNUNET_DISK_PERM_GROUP_READ | 996 | GNUNET_DISK_PERM_USER_READ |
996 | | GNUNET_DISK_PERM_OTHER_READ); | 997 | | GNUNET_DISK_PERM_USER_WRITE |
998 | | GNUNET_DISK_PERM_GROUP_READ | ||
999 | | GNUNET_DISK_PERM_OTHER_READ)); | ||
997 | } | 1000 | } |
998 | else if (0 != unlink (fn)) | 1001 | else if (0 != unlink (fn)) |
999 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | 1002 | 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 () | |||
230 | { | 230 | { |
231 | size_t psize = GNUNET_REVOCATION_proof_get_size (proof_of_work); | 231 | size_t psize = GNUNET_REVOCATION_proof_get_size (proof_of_work); |
232 | if ((NULL != filename) && | 232 | if ((NULL != filename) && |
233 | (psize != | 233 | (GNUNET_OK != |
234 | GNUNET_DISK_fn_write (filename, | 234 | GNUNET_DISK_fn_write (filename, |
235 | proof_of_work, | 235 | proof_of_work, |
236 | psize, | 236 | psize, |
@@ -280,14 +280,17 @@ calculate_pow (void *cls) | |||
280 | if (GNUNET_OK == GNUNET_REVOCATION_pow_round (ph)) | 280 | if (GNUNET_OK == GNUNET_REVOCATION_pow_round (ph)) |
281 | { | 281 | { |
282 | psize = GNUNET_REVOCATION_proof_get_size (proof_of_work); | 282 | psize = GNUNET_REVOCATION_proof_get_size (proof_of_work); |
283 | if ((NULL != filename) && | 283 | if (NULL != filename) |
284 | (psize != | 284 | { |
285 | GNUNET_DISK_fn_write (filename, | 285 | (void) GNUNET_DISK_directory_remove (filename); |
286 | proof_of_work, | 286 | if (GNUNET_OK != |
287 | psize, | 287 | GNUNET_DISK_fn_write (filename, |
288 | GNUNET_DISK_PERM_USER_READ | 288 | proof_of_work, |
289 | | GNUNET_DISK_PERM_USER_WRITE))) | 289 | psize, |
290 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename); | 290 | GNUNET_DISK_PERM_USER_READ |
291 | | GNUNET_DISK_PERM_USER_WRITE)) | ||
292 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename); | ||
293 | } | ||
291 | if (perform) | 294 | if (perform) |
292 | { | 295 | { |
293 | perform_revocation (); | 296 | 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[]) | |||
49 | (void) GNUNET_asprintf (&filename, "%d-%d.mpiout", (int) pid, rank); | 49 | (void) GNUNET_asprintf (&filename, "%d-%d.mpiout", (int) pid, rank); |
50 | msg_size = GNUNET_asprintf (&msg, "My rank is: %d\n", rank); | 50 | msg_size = GNUNET_asprintf (&msg, "My rank is: %d\n", rank); |
51 | printf ("%s", msg); | 51 | printf ("%s", msg); |
52 | if (msg_size == | 52 | if (GNUNET_OK == |
53 | GNUNET_DISK_fn_write (filename, msg, msg_size, | 53 | GNUNET_DISK_fn_write (filename, msg, msg_size, |
54 | GNUNET_DISK_PERM_USER_READ | 54 | GNUNET_DISK_PERM_USER_READ |
55 | | GNUNET_DISK_PERM_GROUP_READ | 55 | | 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, | |||
59 | "FRIENDS"); | 59 | "FRIENDS"); |
60 | return GNUNET_SYSERR; | 60 | return GNUNET_SYSERR; |
61 | } | 61 | } |
62 | if (GNUNET_SYSERR == | ||
63 | GNUNET_DISK_directory_create_for_file (fn)) | ||
64 | { | ||
65 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
66 | "mkdir", | ||
67 | fn); | ||
68 | GNUNET_free (fn); | ||
69 | return GNUNET_SYSERR; | ||
70 | } | ||
71 | if ((GNUNET_OK != | 62 | if ((GNUNET_OK != |
72 | GNUNET_DISK_file_test (fn)) && | 63 | GNUNET_DISK_file_test (fn)) && |
73 | (GNUNET_OK != | 64 | (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 = \ | |||
138 | 138 | ||
139 | libgnunetutil_la_LDFLAGS = \ | 139 | libgnunetutil_la_LDFLAGS = \ |
140 | $(GN_LIB_LDFLAGS) \ | 140 | $(GN_LIB_LDFLAGS) \ |
141 | -version-info 13:2:1 | 141 | -version-info 14:0:0 |
142 | 142 | ||
143 | if HAVE_TESTING | 143 | if HAVE_TESTING |
144 | GNUNET_ECC = gnunet-ecc | 144 | 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 | |||
93 | * #GNUNET_NO if clean, #GNUNET_YES if dirty, | 93 | * #GNUNET_NO if clean, #GNUNET_YES if dirty, |
94 | * #GNUNET_SYSERR on error (i.e. last save failed) | 94 | * #GNUNET_SYSERR on error (i.e. last save failed) |
95 | */ | 95 | */ |
96 | int dirty; | 96 | enum GNUNET_GenericReturnValue dirty; |
97 | }; | 97 | }; |
98 | 98 | ||
99 | 99 | ||
@@ -109,11 +109,6 @@ struct DiffHandle | |||
109 | }; | 109 | }; |
110 | 110 | ||
111 | 111 | ||
112 | /** | ||
113 | * Create a GNUNET_CONFIGURATION_Handle. | ||
114 | * | ||
115 | * @return fresh configuration object | ||
116 | */ | ||
117 | struct GNUNET_CONFIGURATION_Handle * | 112 | struct GNUNET_CONFIGURATION_Handle * |
118 | GNUNET_CONFIGURATION_create () | 113 | GNUNET_CONFIGURATION_create () |
119 | { | 114 | { |
@@ -199,11 +194,6 @@ GNUNET_CONFIGURATION_create () | |||
199 | } | 194 | } |
200 | 195 | ||
201 | 196 | ||
202 | /** | ||
203 | * Destroy configuration object. | ||
204 | * | ||
205 | * @param cfg configuration to destroy | ||
206 | */ | ||
207 | void | 197 | void |
208 | GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg) | 198 | GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg) |
209 | { | 199 | { |
@@ -215,24 +205,13 @@ GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg) | |||
215 | } | 205 | } |
216 | 206 | ||
217 | 207 | ||
218 | /** | 208 | enum GNUNET_GenericReturnValue |
219 | * Parse a configuration file @a filename and run the function | ||
220 | * @a cb with the resulting configuration object. Then free the | ||
221 | * configuration object and return the status value from @a cb. | ||
222 | * | ||
223 | * @param filename configuration to parse, NULL for "default" | ||
224 | * @param cb function to run | ||
225 | * @param cb_cls closure for @a cb | ||
226 | * @return #GNUNET_SYSERR if parsing the configuration failed, | ||
227 | * otherwise return value from @a cb. | ||
228 | */ | ||
229 | int | ||
230 | GNUNET_CONFIGURATION_parse_and_run (const char *filename, | 209 | GNUNET_CONFIGURATION_parse_and_run (const char *filename, |
231 | GNUNET_CONFIGURATION_Callback cb, | 210 | GNUNET_CONFIGURATION_Callback cb, |
232 | void *cb_cls) | 211 | void *cb_cls) |
233 | { | 212 | { |
234 | struct GNUNET_CONFIGURATION_Handle *cfg; | 213 | struct GNUNET_CONFIGURATION_Handle *cfg; |
235 | int ret; | 214 | enum GNUNET_GenericReturnValue ret; |
236 | 215 | ||
237 | cfg = GNUNET_CONFIGURATION_create (); | 216 | cfg = GNUNET_CONFIGURATION_create (); |
238 | if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, filename)) | 217 | if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, filename)) |
@@ -247,18 +226,7 @@ GNUNET_CONFIGURATION_parse_and_run (const char *filename, | |||
247 | } | 226 | } |
248 | 227 | ||
249 | 228 | ||
250 | /** | 229 | enum GNUNET_GenericReturnValue |
251 | * De-serializes configuration | ||
252 | * | ||
253 | * @param cfg configuration to update | ||
254 | * @param mem the memory block of serialized configuration | ||
255 | * @param size the size of the memory block | ||
256 | * @param basedir set to path from which we recursively load configuration | ||
257 | * from inlined configurations; NULL if not and raise warnings | ||
258 | * when we come across them | ||
259 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
260 | */ | ||
261 | int | ||
262 | GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, | 230 | GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, |
263 | const char *mem, | 231 | const char *mem, |
264 | size_t size, | 232 | size_t size, |
@@ -273,7 +241,7 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
273 | size_t to_read; | 241 | size_t to_read; |
274 | size_t i; | 242 | size_t i; |
275 | int emptyline; | 243 | int emptyline; |
276 | int ret; | 244 | enum GNUNET_GenericReturnValue ret; |
277 | char *section; | 245 | char *section; |
278 | char *eq; | 246 | char *eq; |
279 | char *tag; | 247 | char *tag; |
@@ -411,15 +379,7 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
411 | } | 379 | } |
412 | 380 | ||
413 | 381 | ||
414 | /** | 382 | enum GNUNET_GenericReturnValue |
415 | * Parse a configuration file, add all of the options in the | ||
416 | * file to the configuration environment. | ||
417 | * | ||
418 | * @param cfg configuration to update | ||
419 | * @param filename name of the configuration file | ||
420 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
421 | */ | ||
422 | int | ||
423 | GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, | 383 | GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, |
424 | const char *filename) | 384 | const char *filename) |
425 | { | 385 | { |
@@ -429,7 +389,7 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
429 | char *mem; | 389 | char *mem; |
430 | char *endsep; | 390 | char *endsep; |
431 | int dirty; | 391 | int dirty; |
432 | int ret; | 392 | enum GNUNET_GenericReturnValue ret; |
433 | ssize_t sret; | 393 | ssize_t sret; |
434 | 394 | ||
435 | fn = GNUNET_STRINGS_filename_expand (filename); | 395 | fn = GNUNET_STRINGS_filename_expand (filename); |
@@ -476,28 +436,13 @@ GNUNET_CONFIGURATION_parse (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
476 | } | 436 | } |
477 | 437 | ||
478 | 438 | ||
479 | /** | 439 | enum GNUNET_GenericReturnValue |
480 | * Test if there are configuration options that were | ||
481 | * changed since the last save. | ||
482 | * | ||
483 | * @param cfg configuration to inspect | ||
484 | * @return #GNUNET_NO if clean, #GNUNET_YES if dirty, #GNUNET_SYSERR on error (i.e. last save failed) | ||
485 | */ | ||
486 | int | ||
487 | GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg) | 440 | GNUNET_CONFIGURATION_is_dirty (const struct GNUNET_CONFIGURATION_Handle *cfg) |
488 | { | 441 | { |
489 | return cfg->dirty; | 442 | return cfg->dirty; |
490 | } | 443 | } |
491 | 444 | ||
492 | 445 | ||
493 | /** | ||
494 | * Serializes the given configuration. | ||
495 | * | ||
496 | * @param cfg configuration to serialize | ||
497 | * @param size will be set to the size of the serialized memory block | ||
498 | * @return the memory block where the serialized configuration is | ||
499 | * present. This memory should be freed by the caller | ||
500 | */ | ||
501 | char * | 446 | char * |
502 | GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, | 447 | GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, |
503 | size_t *size) | 448 | size_t *size) |
@@ -580,21 +525,13 @@ GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
580 | } | 525 | } |
581 | 526 | ||
582 | 527 | ||
583 | /** | 528 | enum GNUNET_GenericReturnValue |
584 | * Write configuration file. | ||
585 | * | ||
586 | * @param cfg configuration to write | ||
587 | * @param filename where to write the configuration | ||
588 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
589 | */ | ||
590 | int | ||
591 | GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, | 529 | GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, |
592 | const char *filename) | 530 | const char *filename) |
593 | { | 531 | { |
594 | char *fn; | 532 | char *fn; |
595 | char *cfg_buf; | 533 | char *cfg_buf; |
596 | size_t size; | 534 | size_t size; |
597 | ssize_t sret; | ||
598 | 535 | ||
599 | fn = GNUNET_STRINGS_filename_expand (filename); | 536 | fn = GNUNET_STRINGS_filename_expand (filename); |
600 | if (fn == NULL) | 537 | if (fn == NULL) |
@@ -604,15 +541,17 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
604 | GNUNET_free (fn); | 541 | GNUNET_free (fn); |
605 | return GNUNET_SYSERR; | 542 | return GNUNET_SYSERR; |
606 | } | 543 | } |
607 | cfg_buf = GNUNET_CONFIGURATION_serialize (cfg, &size); | 544 | cfg_buf = GNUNET_CONFIGURATION_serialize (cfg, |
608 | sret = GNUNET_DISK_fn_write (fn, | 545 | &size); |
609 | cfg_buf, | 546 | (void) GNUNET_DISK_directory_remove (fn); |
610 | size, | 547 | if (GNUNET_OK != |
611 | GNUNET_DISK_PERM_USER_READ | 548 | GNUNET_DISK_fn_write (fn, |
612 | | GNUNET_DISK_PERM_USER_WRITE | 549 | cfg_buf, |
613 | | GNUNET_DISK_PERM_GROUP_READ | 550 | size, |
614 | | GNUNET_DISK_PERM_GROUP_WRITE); | 551 | GNUNET_DISK_PERM_USER_READ |
615 | if ((sret < 0) || (size != (size_t) sret)) | 552 | | GNUNET_DISK_PERM_USER_WRITE |
553 | | GNUNET_DISK_PERM_GROUP_READ | ||
554 | | GNUNET_DISK_PERM_GROUP_WRITE)) | ||
616 | { | 555 | { |
617 | GNUNET_free (fn); | 556 | GNUNET_free (fn); |
618 | GNUNET_free (cfg_buf); | 557 | GNUNET_free (cfg_buf); |
@@ -629,36 +568,25 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
629 | } | 568 | } |
630 | 569 | ||
631 | 570 | ||
632 | /** | ||
633 | * Iterate over all options in the configuration. | ||
634 | * | ||
635 | * @param cfg configuration to inspect | ||
636 | * @param iter function to call on each option | ||
637 | * @param iter_cls closure for @a iter | ||
638 | */ | ||
639 | void | 571 | void |
640 | GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, | 572 | GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, |
641 | GNUNET_CONFIGURATION_Iterator iter, | 573 | GNUNET_CONFIGURATION_Iterator iter, |
642 | void *iter_cls) | 574 | void *iter_cls) |
643 | { | 575 | { |
644 | struct ConfigSection *spos; | 576 | for (struct ConfigSection *spos = cfg->sections; |
645 | struct ConfigEntry *epos; | 577 | NULL != spos; |
646 | 578 | spos = spos->next) | |
647 | for (spos = cfg->sections; NULL != spos; spos = spos->next) | 579 | for (struct ConfigEntry *epos = spos->entries; |
648 | for (epos = spos->entries; NULL != epos; epos = epos->next) | 580 | NULL != epos; |
581 | epos = epos->next) | ||
649 | if (NULL != epos->val) | 582 | if (NULL != epos->val) |
650 | iter (iter_cls, spos->name, epos->key, epos->val); | 583 | iter (iter_cls, |
584 | spos->name, | ||
585 | epos->key, | ||
586 | epos->val); | ||
651 | } | 587 | } |
652 | 588 | ||
653 | 589 | ||
654 | /** | ||
655 | * Iterate over values of a section in the configuration. | ||
656 | * | ||
657 | * @param cfg configuration to inspect | ||
658 | * @param section the section | ||
659 | * @param iter function to call on each option | ||
660 | * @param iter_cls closure for @a iter | ||
661 | */ | ||
662 | void | 590 | void |
663 | GNUNET_CONFIGURATION_iterate_section_values ( | 591 | GNUNET_CONFIGURATION_iterate_section_values ( |
664 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 592 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
@@ -680,13 +608,6 @@ GNUNET_CONFIGURATION_iterate_section_values ( | |||
680 | } | 608 | } |
681 | 609 | ||
682 | 610 | ||
683 | /** | ||
684 | * Iterate over all sections in the configuration. | ||
685 | * | ||
686 | * @param cfg configuration to inspect | ||
687 | * @param iter function to call on each section | ||
688 | * @param iter_cls closure for @a iter | ||
689 | */ | ||
690 | void | 611 | void |
691 | GNUNET_CONFIGURATION_iterate_sections ( | 612 | GNUNET_CONFIGURATION_iterate_sections ( |
692 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 613 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
@@ -706,12 +627,6 @@ GNUNET_CONFIGURATION_iterate_sections ( | |||
706 | } | 627 | } |
707 | 628 | ||
708 | 629 | ||
709 | /** | ||
710 | * Remove the given section and all options in it. | ||
711 | * | ||
712 | * @param cfg configuration to inspect | ||
713 | * @param section name of the section to remove | ||
714 | */ | ||
715 | void | 630 | void |
716 | GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, | 631 | GNUNET_CONFIGURATION_remove_section (struct GNUNET_CONFIGURATION_Handle *cfg, |
717 | const char *section) | 632 | const char *section) |
@@ -769,12 +684,6 @@ copy_entry (void *cls, | |||
769 | } | 684 | } |
770 | 685 | ||
771 | 686 | ||
772 | /** | ||
773 | * Duplicate an existing configuration object. | ||
774 | * | ||
775 | * @param cfg configuration to duplicate | ||
776 | * @return duplicate configuration | ||
777 | */ | ||
778 | struct GNUNET_CONFIGURATION_Handle * | 687 | struct GNUNET_CONFIGURATION_Handle * |
779 | GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg) | 688 | GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg) |
780 | { | 689 | { |
@@ -858,13 +767,6 @@ compare_entries (void *cls, | |||
858 | } | 767 | } |
859 | 768 | ||
860 | 769 | ||
861 | /** | ||
862 | * Compute configuration with only entries that have been changed | ||
863 | * | ||
864 | * @param cfg_default original configuration | ||
865 | * @param cfg_new new configuration | ||
866 | * @return configuration with only the differences, never NULL | ||
867 | */ | ||
868 | struct GNUNET_CONFIGURATION_Handle * | 770 | struct GNUNET_CONFIGURATION_Handle * |
869 | GNUNET_CONFIGURATION_get_diff ( | 771 | GNUNET_CONFIGURATION_get_diff ( |
870 | const struct GNUNET_CONFIGURATION_Handle *cfg_default, | 772 | const struct GNUNET_CONFIGURATION_Handle *cfg_default, |
@@ -879,15 +781,7 @@ GNUNET_CONFIGURATION_get_diff ( | |||
879 | } | 781 | } |
880 | 782 | ||
881 | 783 | ||
882 | /** | 784 | enum GNUNET_GenericReturnValue |
883 | * Write only configuration entries that have been changed to configuration file | ||
884 | * | ||
885 | * @param cfg_default default configuration | ||
886 | * @param cfg_new new configuration | ||
887 | * @param filename where to write the configuration diff between default and new | ||
888 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
889 | */ | ||
890 | int | ||
891 | GNUNET_CONFIGURATION_write_diffs ( | 785 | GNUNET_CONFIGURATION_write_diffs ( |
892 | const struct GNUNET_CONFIGURATION_Handle *cfg_default, | 786 | const struct GNUNET_CONFIGURATION_Handle *cfg_default, |
893 | const struct GNUNET_CONFIGURATION_Handle *cfg_new, | 787 | const struct GNUNET_CONFIGURATION_Handle *cfg_new, |
@@ -903,14 +797,6 @@ GNUNET_CONFIGURATION_write_diffs ( | |||
903 | } | 797 | } |
904 | 798 | ||
905 | 799 | ||
906 | /** | ||
907 | * Set a configuration value that should be a string. | ||
908 | * | ||
909 | * @param cfg configuration to update | ||
910 | * @param section section of interest | ||
911 | * @param option option of interest | ||
912 | * @param value value to set | ||
913 | */ | ||
914 | void | 800 | void |
915 | GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg, | 801 | GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg, |
916 | const char *section, | 802 | const char *section, |
@@ -953,14 +839,6 @@ GNUNET_CONFIGURATION_set_value_string (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
953 | } | 839 | } |
954 | 840 | ||
955 | 841 | ||
956 | /** | ||
957 | * Set a configuration value that should be a number. | ||
958 | * | ||
959 | * @param cfg configuration to update | ||
960 | * @param section section of interest | ||
961 | * @param option option of interest | ||
962 | * @param number value to set | ||
963 | */ | ||
964 | void | 842 | void |
965 | GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg, | 843 | GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg, |
966 | const char *section, | 844 | const char *section, |
@@ -974,16 +852,7 @@ GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
974 | } | 852 | } |
975 | 853 | ||
976 | 854 | ||
977 | /** | 855 | enum GNUNET_GenericReturnValue |
978 | * Get a configuration value that should be a number. | ||
979 | * | ||
980 | * @param cfg configuration to inspect | ||
981 | * @param section section of interest | ||
982 | * @param option option of interest | ||
983 | * @param number where to store the numeric value of the option | ||
984 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
985 | */ | ||
986 | int | ||
987 | GNUNET_CONFIGURATION_get_value_number ( | 856 | GNUNET_CONFIGURATION_get_value_number ( |
988 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 857 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
989 | const char *section, | 858 | const char *section, |
@@ -1003,16 +872,7 @@ GNUNET_CONFIGURATION_get_value_number ( | |||
1003 | } | 872 | } |
1004 | 873 | ||
1005 | 874 | ||
1006 | /** | 875 | enum GNUNET_GenericReturnValue |
1007 | * Get a configuration value that should be a floating point number. | ||
1008 | * | ||
1009 | * @param cfg configuration to inspect | ||
1010 | * @param section section of interest | ||
1011 | * @param option option of interest | ||
1012 | * @param number where to store the floating value of the option | ||
1013 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
1014 | */ | ||
1015 | int | ||
1016 | GNUNET_CONFIGURATION_get_value_float ( | 876 | GNUNET_CONFIGURATION_get_value_float ( |
1017 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 877 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
1018 | const char *section, | 878 | const char *section, |
@@ -1032,16 +892,7 @@ GNUNET_CONFIGURATION_get_value_float ( | |||
1032 | } | 892 | } |
1033 | 893 | ||
1034 | 894 | ||
1035 | /** | 895 | enum GNUNET_GenericReturnValue |
1036 | * Get a configuration value that should be a relative time. | ||
1037 | * | ||
1038 | * @param cfg configuration to inspect | ||
1039 | * @param section section of interest | ||
1040 | * @param option option of interest | ||
1041 | * @param time set to the time value stored in the configuration | ||
1042 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
1043 | */ | ||
1044 | int | ||
1045 | GNUNET_CONFIGURATION_get_value_time ( | 896 | GNUNET_CONFIGURATION_get_value_time ( |
1046 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 897 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
1047 | const char *section, | 898 | const char *section, |
@@ -1065,16 +916,7 @@ GNUNET_CONFIGURATION_get_value_time ( | |||
1065 | } | 916 | } |
1066 | 917 | ||
1067 | 918 | ||
1068 | /** | 919 | enum GNUNET_GenericReturnValue |
1069 | * Get a configuration value that should be a size in bytes. | ||
1070 | * | ||
1071 | * @param cfg configuration to inspect | ||
1072 | * @param section section of interest | ||
1073 | * @param option option of interest | ||
1074 | * @param size set to the size in bytes as stored in the configuration | ||
1075 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
1076 | */ | ||
1077 | int | ||
1078 | GNUNET_CONFIGURATION_get_value_size ( | 920 | GNUNET_CONFIGURATION_get_value_size ( |
1079 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 921 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
1080 | const char *section, | 922 | const char *section, |
@@ -1101,7 +943,7 @@ GNUNET_CONFIGURATION_get_value_size ( | |||
1101 | * value, or NULL if option is not specified | 943 | * value, or NULL if option is not specified |
1102 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 944 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
1103 | */ | 945 | */ |
1104 | int | 946 | enum GNUNET_GenericReturnValue |
1105 | GNUNET_CONFIGURATION_get_value_string ( | 947 | GNUNET_CONFIGURATION_get_value_string ( |
1106 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 948 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
1107 | const char *section, | 949 | const char *section, |
@@ -1120,19 +962,7 @@ GNUNET_CONFIGURATION_get_value_string ( | |||
1120 | } | 962 | } |
1121 | 963 | ||
1122 | 964 | ||
1123 | /** | 965 | enum GNUNET_GenericReturnValue |
1124 | * Get a configuration value that should be in a set of | ||
1125 | * predefined strings | ||
1126 | * | ||
1127 | * @param cfg configuration to inspect | ||
1128 | * @param section section of interest | ||
1129 | * @param option option of interest | ||
1130 | * @param choices NULL-terminated list of legal values | ||
1131 | * @param value will be set to an entry in the legal list, | ||
1132 | * or NULL if option is not specified and no default given | ||
1133 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
1134 | */ | ||
1135 | int | ||
1136 | GNUNET_CONFIGURATION_get_value_choice ( | 966 | GNUNET_CONFIGURATION_get_value_choice ( |
1137 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 967 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
1138 | const char *section, | 968 | const char *section, |
@@ -1163,19 +993,7 @@ GNUNET_CONFIGURATION_get_value_choice ( | |||
1163 | } | 993 | } |
1164 | 994 | ||
1165 | 995 | ||
1166 | /** | 996 | enum GNUNET_GenericReturnValue |
1167 | * Get crockford32-encoded fixed-size binary data from a configuration. | ||
1168 | * | ||
1169 | * @param cfg configuration to access | ||
1170 | * @param section section to access | ||
1171 | * @param option option to access | ||
1172 | * @param buf where to store the decoded binary result | ||
1173 | * @param buf_size exact number of bytes to store in @a buf | ||
1174 | * @return #GNUNET_OK on success | ||
1175 | * #GNUNET_NO is the value does not exist | ||
1176 | * #GNUNET_SYSERR on decoding error | ||
1177 | */ | ||
1178 | int | ||
1179 | GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg, | 997 | GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg, |
1180 | const char *section, | 998 | const char *section, |
1181 | const char *option, | 999 | const char *option, |
@@ -1207,15 +1025,7 @@ GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1207 | } | 1025 | } |
1208 | 1026 | ||
1209 | 1027 | ||
1210 | /** | 1028 | enum GNUNET_GenericReturnValue |
1211 | * Test if we have a value for a particular option | ||
1212 | * | ||
1213 | * @param cfg configuration to inspect | ||
1214 | * @param section section of interest | ||
1215 | * @param option option of interest | ||
1216 | * @return #GNUNET_YES if so, #GNUNET_NO if not. | ||
1217 | */ | ||
1218 | int | ||
1219 | GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg, | 1029 | GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg, |
1220 | const char *section, | 1030 | const char *section, |
1221 | const char *option) | 1031 | const char *option) |
@@ -1390,22 +1200,6 @@ expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1390 | } | 1200 | } |
1391 | 1201 | ||
1392 | 1202 | ||
1393 | /** | ||
1394 | * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR" | ||
1395 | * where either in the "PATHS" section or the environment "FOO" is | ||
1396 | * set to "DIRECTORY". We also support default expansion, | ||
1397 | * i.e. ${VARIABLE:-default} will expand to $VARIABLE if VARIABLE is | ||
1398 | * set in PATHS or the environment, and otherwise to "default". Note | ||
1399 | * that "default" itself can also be a $-expression, thus | ||
1400 | * "${VAR1:-{$VAR2}}" will expand to VAR1 and if that is not defined | ||
1401 | * to VAR2. | ||
1402 | * | ||
1403 | * @param cfg configuration to use for path expansion | ||
1404 | * @param orig string to $-expand (will be freed!). Note that multiple | ||
1405 | * $-expressions can be present in this string. They will all be | ||
1406 | * $-expanded. | ||
1407 | * @return $-expanded string | ||
1408 | */ | ||
1409 | char * | 1203 | char * |
1410 | GNUNET_CONFIGURATION_expand_dollar ( | 1204 | GNUNET_CONFIGURATION_expand_dollar ( |
1411 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 1205 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
@@ -1431,17 +1225,7 @@ GNUNET_CONFIGURATION_expand_dollar ( | |||
1431 | } | 1225 | } |
1432 | 1226 | ||
1433 | 1227 | ||
1434 | /** | 1228 | enum GNUNET_GenericReturnValue |
1435 | * Get a configuration value that should be a string. | ||
1436 | * | ||
1437 | * @param cfg configuration to inspect | ||
1438 | * @param section section of interest | ||
1439 | * @param option option of interest | ||
1440 | * @param value will be set to a freshly allocated configuration | ||
1441 | * value, or NULL if option is not specified | ||
1442 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
1443 | */ | ||
1444 | int | ||
1445 | GNUNET_CONFIGURATION_get_value_filename ( | 1229 | GNUNET_CONFIGURATION_get_value_filename ( |
1446 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 1230 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
1447 | const char *section, | 1231 | const char *section, |
@@ -1466,16 +1250,7 @@ GNUNET_CONFIGURATION_get_value_filename ( | |||
1466 | } | 1250 | } |
1467 | 1251 | ||
1468 | 1252 | ||
1469 | /** | 1253 | enum GNUNET_GenericReturnValue |
1470 | * Get a configuration value that should be in a set of | ||
1471 | * "YES" or "NO". | ||
1472 | * | ||
1473 | * @param cfg configuration to inspect | ||
1474 | * @param section section of interest | ||
1475 | * @param option option of interest | ||
1476 | * @return #GNUNET_YES, #GNUNET_NO or #GNUNET_SYSERR | ||
1477 | */ | ||
1478 | int | ||
1479 | GNUNET_CONFIGURATION_get_value_yesno ( | 1254 | GNUNET_CONFIGURATION_get_value_yesno ( |
1480 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 1255 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
1481 | const char *section, | 1256 | const char *section, |
@@ -1495,16 +1270,6 @@ GNUNET_CONFIGURATION_get_value_yesno ( | |||
1495 | } | 1270 | } |
1496 | 1271 | ||
1497 | 1272 | ||
1498 | /** | ||
1499 | * Iterate over the set of filenames stored in a configuration value. | ||
1500 | * | ||
1501 | * @param cfg configuration to inspect | ||
1502 | * @param section section of interest | ||
1503 | * @param option option of interest | ||
1504 | * @param cb function to call on each filename | ||
1505 | * @param cb_cls closure for @a cb | ||
1506 | * @return number of filenames iterated over, -1 on error | ||
1507 | */ | ||
1508 | int | 1273 | int |
1509 | GNUNET_CONFIGURATION_iterate_value_filenames ( | 1274 | GNUNET_CONFIGURATION_iterate_value_filenames ( |
1510 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 1275 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
@@ -1618,7 +1383,7 @@ escape_name (const char *value) | |||
1618 | * @param fn filename we are currently looking at | 1383 | * @param fn filename we are currently looking at |
1619 | * @return #GNUNET_OK if the names do not match, #GNUNET_SYSERR if they do | 1384 | * @return #GNUNET_OK if the names do not match, #GNUNET_SYSERR if they do |
1620 | */ | 1385 | */ |
1621 | static int | 1386 | static enum GNUNET_GenericReturnValue |
1622 | test_match (void *cls, const char *fn) | 1387 | test_match (void *cls, const char *fn) |
1623 | { | 1388 | { |
1624 | const char *of = cls; | 1389 | const char *of = cls; |
@@ -1627,19 +1392,7 @@ test_match (void *cls, const char *fn) | |||
1627 | } | 1392 | } |
1628 | 1393 | ||
1629 | 1394 | ||
1630 | /** | 1395 | enum GNUNET_GenericReturnValue |
1631 | * Append a filename to a configuration value that | ||
1632 | * represents a list of filenames | ||
1633 | * | ||
1634 | * @param cfg configuration to update | ||
1635 | * @param section section of interest | ||
1636 | * @param option option of interest | ||
1637 | * @param value filename to append | ||
1638 | * @return #GNUNET_OK on success, | ||
1639 | * #GNUNET_NO if the filename already in the list | ||
1640 | * #GNUNET_SYSERR on error | ||
1641 | */ | ||
1642 | int | ||
1643 | GNUNET_CONFIGURATION_append_value_filename ( | 1396 | GNUNET_CONFIGURATION_append_value_filename ( |
1644 | struct GNUNET_CONFIGURATION_Handle *cfg, | 1397 | struct GNUNET_CONFIGURATION_Handle *cfg, |
1645 | const char *section, | 1398 | const char *section, |
@@ -1674,19 +1427,7 @@ GNUNET_CONFIGURATION_append_value_filename ( | |||
1674 | } | 1427 | } |
1675 | 1428 | ||
1676 | 1429 | ||
1677 | /** | 1430 | enum GNUNET_GenericReturnValue |
1678 | * Remove a filename from a configuration value that | ||
1679 | * represents a list of filenames | ||
1680 | * | ||
1681 | * @param cfg configuration to update | ||
1682 | * @param section section of interest | ||
1683 | * @param option option of interest | ||
1684 | * @param value filename to remove | ||
1685 | * @return #GNUNET_OK on success, | ||
1686 | * #GNUNET_NO if the filename is not in the list, | ||
1687 | * #GNUNET_SYSERR on error | ||
1688 | */ | ||
1689 | int | ||
1690 | GNUNET_CONFIGURATION_remove_value_filename ( | 1431 | GNUNET_CONFIGURATION_remove_value_filename ( |
1691 | struct GNUNET_CONFIGURATION_Handle *cfg, | 1432 | struct GNUNET_CONFIGURATION_Handle *cfg, |
1692 | const char *section, | 1433 | const char *section, |
@@ -1771,12 +1512,11 @@ GNUNET_CONFIGURATION_remove_value_filename ( | |||
1771 | * @param filename file to parse | 1512 | * @param filename file to parse |
1772 | * @return #GNUNET_OK on success | 1513 | * @return #GNUNET_OK on success |
1773 | */ | 1514 | */ |
1774 | static int | 1515 | static enum GNUNET_GenericReturnValue |
1775 | parse_configuration_file (void *cls, const char *filename) | 1516 | parse_configuration_file (void *cls, const char *filename) |
1776 | { | 1517 | { |
1777 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; | 1518 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; |
1778 | char *ext; | 1519 | char *ext; |
1779 | int ret; | ||
1780 | 1520 | ||
1781 | /* Examine file extension */ | 1521 | /* Examine file extension */ |
1782 | ext = strrchr (filename, '.'); | 1522 | ext = strrchr (filename, '.'); |
@@ -1786,20 +1526,11 @@ parse_configuration_file (void *cls, const char *filename) | |||
1786 | return GNUNET_OK; | 1526 | return GNUNET_OK; |
1787 | } | 1527 | } |
1788 | 1528 | ||
1789 | ret = GNUNET_CONFIGURATION_parse (cfg, filename); | 1529 | return GNUNET_CONFIGURATION_parse (cfg, filename); |
1790 | return ret; | ||
1791 | } | 1530 | } |
1792 | 1531 | ||
1793 | 1532 | ||
1794 | /** | 1533 | enum GNUNET_GenericReturnValue |
1795 | * Load default configuration. This function will parse the | ||
1796 | * defaults from the given defaults_d directory. | ||
1797 | * | ||
1798 | * @param cfg configuration to update | ||
1799 | * @param defaults_d directory with the defaults | ||
1800 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
1801 | */ | ||
1802 | int | ||
1803 | GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg, | 1534 | GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg, |
1804 | const char *defaults_d) | 1535 | const char *defaults_d) |
1805 | { | 1536 | { |
@@ -1810,43 +1541,31 @@ GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1810 | } | 1541 | } |
1811 | 1542 | ||
1812 | 1543 | ||
1813 | /** | ||
1814 | * Return GNUnet's default configuration. A new configuration is allocated | ||
1815 | * each time and it's up to the caller to destroy it when done. This function | ||
1816 | * returns GNUnet's configuration even when #GNUNET_OS_init has been called | ||
1817 | * with a value different from #GNUNET_OS_project_data_default. | ||
1818 | * | ||
1819 | * @return a freshly allocated configuration | ||
1820 | */ | ||
1821 | struct GNUNET_CONFIGURATION_Handle * | 1544 | struct GNUNET_CONFIGURATION_Handle * |
1822 | GNUNET_CONFIGURATION_default (void) | 1545 | GNUNET_CONFIGURATION_default (void) |
1823 | { | 1546 | { |
1824 | const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get (); | 1547 | const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get (); |
1825 | const struct GNUNET_OS_ProjectData *dpd = GNUNET_OS_project_data_default (); | 1548 | const struct GNUNET_OS_ProjectData *dpd = GNUNET_OS_project_data_default (); |
1826 | |||
1827 | GNUNET_OS_init (dpd); | ||
1828 | |||
1829 | struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create (); | ||
1830 | const char *xdg = getenv ("XDG_CONFIG_HOME"); | 1549 | const char *xdg = getenv ("XDG_CONFIG_HOME"); |
1831 | char *cfgname = NULL; | 1550 | char *cfgname = NULL; |
1551 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
1832 | 1552 | ||
1553 | GNUNET_OS_init (dpd); | ||
1554 | cfg = GNUNET_CONFIGURATION_create (); | ||
1833 | if (NULL != xdg) | 1555 | if (NULL != xdg) |
1834 | GNUNET_asprintf (&cfgname, "%s/%s", xdg, pd->config_file); | 1556 | GNUNET_asprintf (&cfgname, "%s/%s", xdg, pd->config_file); |
1835 | else | 1557 | else |
1836 | cfgname = GNUNET_strdup (pd->user_config_file); | 1558 | cfgname = GNUNET_strdup (pd->user_config_file); |
1837 | 1559 | if (GNUNET_OK != | |
1838 | if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfgname)) | 1560 | GNUNET_CONFIGURATION_load (cfg, cfgname)) |
1839 | { | 1561 | { |
1840 | GNUNET_OS_init (pd); | 1562 | GNUNET_OS_init (pd); |
1841 | GNUNET_CONFIGURATION_destroy (cfg); | 1563 | GNUNET_CONFIGURATION_destroy (cfg); |
1842 | GNUNET_free (cfgname); | 1564 | GNUNET_free (cfgname); |
1843 | return NULL; | 1565 | return NULL; |
1844 | } | 1566 | } |
1845 | |||
1846 | GNUNET_free (cfgname); | 1567 | GNUNET_free (cfgname); |
1847 | |||
1848 | GNUNET_OS_init (pd); | 1568 | GNUNET_OS_init (pd); |
1849 | |||
1850 | return cfg; | 1569 | return cfg; |
1851 | } | 1570 | } |
1852 | 1571 | ||
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) | |||
166 | } | 166 | } |
167 | 167 | ||
168 | 168 | ||
169 | /** | ||
170 | * Extract the public key for the given private key. | ||
171 | * | ||
172 | * @param priv the private key | ||
173 | * @param pub where to write the public key | ||
174 | */ | ||
175 | void | 169 | void |
176 | GNUNET_CRYPTO_ecdsa_key_get_public ( | 170 | GNUNET_CRYPTO_ecdsa_key_get_public ( |
177 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, | 171 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, |
@@ -183,12 +177,6 @@ GNUNET_CRYPTO_ecdsa_key_get_public ( | |||
183 | } | 177 | } |
184 | 178 | ||
185 | 179 | ||
186 | /** | ||
187 | * Extract the public key for the given private key. | ||
188 | * | ||
189 | * @param priv the private key | ||
190 | * @param pub where to write the public key | ||
191 | */ | ||
192 | void | 180 | void |
193 | GNUNET_CRYPTO_eddsa_key_get_public ( | 181 | GNUNET_CRYPTO_eddsa_key_get_public ( |
194 | const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, | 182 | const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, |
@@ -205,12 +193,6 @@ GNUNET_CRYPTO_eddsa_key_get_public ( | |||
205 | } | 193 | } |
206 | 194 | ||
207 | 195 | ||
208 | /** | ||
209 | * Extract the public key for the given private key. | ||
210 | * | ||
211 | * @param priv the private key | ||
212 | * @param pub where to write the public key | ||
213 | */ | ||
214 | void | 196 | void |
215 | GNUNET_CRYPTO_ecdhe_key_get_public ( | 197 | GNUNET_CRYPTO_ecdhe_key_get_public ( |
216 | const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, | 198 | const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, |
@@ -222,12 +204,6 @@ GNUNET_CRYPTO_ecdhe_key_get_public ( | |||
222 | } | 204 | } |
223 | 205 | ||
224 | 206 | ||
225 | /** | ||
226 | * Convert a public key to a string. | ||
227 | * | ||
228 | * @param pub key to convert | ||
229 | * @return string representing @a pub | ||
230 | */ | ||
231 | char * | 207 | char * |
232 | GNUNET_CRYPTO_ecdsa_public_key_to_string ( | 208 | GNUNET_CRYPTO_ecdsa_public_key_to_string ( |
233 | const struct GNUNET_CRYPTO_EcdsaPublicKey *pub) | 209 | const struct GNUNET_CRYPTO_EcdsaPublicKey *pub) |
@@ -255,12 +231,6 @@ GNUNET_CRYPTO_ecdsa_public_key_to_string ( | |||
255 | } | 231 | } |
256 | 232 | ||
257 | 233 | ||
258 | /** | ||
259 | * Convert a public key to a string. | ||
260 | * | ||
261 | * @param pub key to convert | ||
262 | * @return string representing @a pub | ||
263 | */ | ||
264 | char * | 234 | char * |
265 | GNUNET_CRYPTO_eddsa_public_key_to_string ( | 235 | GNUNET_CRYPTO_eddsa_public_key_to_string ( |
266 | const struct GNUNET_CRYPTO_EddsaPublicKey *pub) | 236 | const struct GNUNET_CRYPTO_EddsaPublicKey *pub) |
@@ -288,12 +258,6 @@ GNUNET_CRYPTO_eddsa_public_key_to_string ( | |||
288 | } | 258 | } |
289 | 259 | ||
290 | 260 | ||
291 | /** | ||
292 | * Convert a private key to a string. | ||
293 | * | ||
294 | * @param priv key to convert | ||
295 | * @return string representing @a pub | ||
296 | */ | ||
297 | char * | 261 | char * |
298 | GNUNET_CRYPTO_eddsa_private_key_to_string ( | 262 | GNUNET_CRYPTO_eddsa_private_key_to_string ( |
299 | const struct GNUNET_CRYPTO_EddsaPrivateKey *priv) | 263 | const struct GNUNET_CRYPTO_EddsaPrivateKey *priv) |
@@ -321,12 +285,6 @@ GNUNET_CRYPTO_eddsa_private_key_to_string ( | |||
321 | } | 285 | } |
322 | 286 | ||
323 | 287 | ||
324 | /** | ||
325 | * Convert a private key to a string. | ||
326 | * | ||
327 | * @param priv key to convert | ||
328 | * @return string representing @a priv | ||
329 | */ | ||
330 | char * | 288 | char * |
331 | GNUNET_CRYPTO_ecdsa_private_key_to_string ( | 289 | GNUNET_CRYPTO_ecdsa_private_key_to_string ( |
332 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv) | 290 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv) |
@@ -354,15 +312,7 @@ GNUNET_CRYPTO_ecdsa_private_key_to_string ( | |||
354 | } | 312 | } |
355 | 313 | ||
356 | 314 | ||
357 | /** | 315 | enum GNUNET_GenericReturnValue |
358 | * Convert a string representing a public key to a public key. | ||
359 | * | ||
360 | * @param enc encoded public key | ||
361 | * @param enclen number of bytes in @a enc (without 0-terminator) | ||
362 | * @param pub where to store the public key | ||
363 | * @return #GNUNET_OK on success | ||
364 | */ | ||
365 | int | ||
366 | GNUNET_CRYPTO_ecdsa_public_key_from_string ( | 316 | GNUNET_CRYPTO_ecdsa_public_key_from_string ( |
367 | const char *enc, | 317 | const char *enc, |
368 | size_t enclen, | 318 | size_t enclen, |
@@ -387,15 +337,7 @@ GNUNET_CRYPTO_ecdsa_public_key_from_string ( | |||
387 | } | 337 | } |
388 | 338 | ||
389 | 339 | ||
390 | /** | 340 | enum GNUNET_GenericReturnValue |
391 | * Convert a string representing a public key to a public key. | ||
392 | * | ||
393 | * @param enc encoded public key | ||
394 | * @param enclen number of bytes in @a enc (without 0-terminator) | ||
395 | * @param pub where to store the public key | ||
396 | * @return #GNUNET_OK on success | ||
397 | */ | ||
398 | int | ||
399 | GNUNET_CRYPTO_eddsa_public_key_from_string ( | 341 | GNUNET_CRYPTO_eddsa_public_key_from_string ( |
400 | const char *enc, | 342 | const char *enc, |
401 | size_t enclen, | 343 | size_t enclen, |
@@ -420,15 +362,7 @@ GNUNET_CRYPTO_eddsa_public_key_from_string ( | |||
420 | } | 362 | } |
421 | 363 | ||
422 | 364 | ||
423 | /** | 365 | enum GNUNET_GenericReturnValue |
424 | * Convert a string representing a private key to a private key. | ||
425 | * | ||
426 | * @param enc encoded public key | ||
427 | * @param enclen number of bytes in @a enc (without 0-terminator) | ||
428 | * @param priv where to store the private key | ||
429 | * @return #GNUNET_OK on success | ||
430 | */ | ||
431 | int | ||
432 | GNUNET_CRYPTO_eddsa_private_key_from_string ( | 366 | GNUNET_CRYPTO_eddsa_private_key_from_string ( |
433 | const char *enc, | 367 | const char *enc, |
434 | size_t enclen, | 368 | size_t enclen, |
@@ -460,12 +394,6 @@ GNUNET_CRYPTO_eddsa_private_key_from_string ( | |||
460 | } | 394 | } |
461 | 395 | ||
462 | 396 | ||
463 | /** | ||
464 | * @ingroup crypto | ||
465 | * Clear memory that was used to store a private key. | ||
466 | * | ||
467 | * @param pk location of the key | ||
468 | */ | ||
469 | void | 397 | void |
470 | GNUNET_CRYPTO_ecdhe_key_clear (struct GNUNET_CRYPTO_EcdhePrivateKey *pk) | 398 | GNUNET_CRYPTO_ecdhe_key_clear (struct GNUNET_CRYPTO_EcdhePrivateKey *pk) |
471 | { | 399 | { |
@@ -473,12 +401,6 @@ GNUNET_CRYPTO_ecdhe_key_clear (struct GNUNET_CRYPTO_EcdhePrivateKey *pk) | |||
473 | } | 401 | } |
474 | 402 | ||
475 | 403 | ||
476 | /** | ||
477 | * @ingroup crypto | ||
478 | * Clear memory that was used to store a private key. | ||
479 | * | ||
480 | * @param pk location of the key | ||
481 | */ | ||
482 | void | 404 | void |
483 | GNUNET_CRYPTO_ecdsa_key_clear (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk) | 405 | GNUNET_CRYPTO_ecdsa_key_clear (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk) |
484 | { | 406 | { |
@@ -486,12 +408,6 @@ GNUNET_CRYPTO_ecdsa_key_clear (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk) | |||
486 | } | 408 | } |
487 | 409 | ||
488 | 410 | ||
489 | /** | ||
490 | * @ingroup crypto | ||
491 | * Clear memory that was used to store a private key. | ||
492 | * | ||
493 | * @param pk location of the key | ||
494 | */ | ||
495 | void | 411 | void |
496 | GNUNET_CRYPTO_eddsa_key_clear (struct GNUNET_CRYPTO_EddsaPrivateKey *pk) | 412 | GNUNET_CRYPTO_eddsa_key_clear (struct GNUNET_CRYPTO_EddsaPrivateKey *pk) |
497 | { | 413 | { |
@@ -499,11 +415,6 @@ GNUNET_CRYPTO_eddsa_key_clear (struct GNUNET_CRYPTO_EddsaPrivateKey *pk) | |||
499 | } | 415 | } |
500 | 416 | ||
501 | 417 | ||
502 | /** | ||
503 | * Create a new private key. | ||
504 | * | ||
505 | * @param[out] pk fresh private key | ||
506 | */ | ||
507 | void | 418 | void |
508 | GNUNET_CRYPTO_ecdhe_key_create (struct GNUNET_CRYPTO_EcdhePrivateKey *pk) | 419 | GNUNET_CRYPTO_ecdhe_key_create (struct GNUNET_CRYPTO_EcdhePrivateKey *pk) |
509 | { | 420 | { |
@@ -515,11 +426,6 @@ GNUNET_CRYPTO_ecdhe_key_create (struct GNUNET_CRYPTO_EcdhePrivateKey *pk) | |||
515 | } | 426 | } |
516 | 427 | ||
517 | 428 | ||
518 | /** | ||
519 | * Create a new private key. | ||
520 | * | ||
521 | * @param[out] pk private key to initialize | ||
522 | */ | ||
523 | void | 429 | void |
524 | GNUNET_CRYPTO_ecdsa_key_create (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk) | 430 | GNUNET_CRYPTO_ecdsa_key_create (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk) |
525 | { | 431 | { |
@@ -535,11 +441,6 @@ GNUNET_CRYPTO_ecdsa_key_create (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk) | |||
535 | } | 441 | } |
536 | 442 | ||
537 | 443 | ||
538 | /** | ||
539 | * Create a new private key. | ||
540 | * | ||
541 | * @param[out] pk set to fresh private key | ||
542 | */ | ||
543 | void | 444 | void |
544 | GNUNET_CRYPTO_eddsa_key_create (struct GNUNET_CRYPTO_EddsaPrivateKey *pk) | 445 | GNUNET_CRYPTO_eddsa_key_create (struct GNUNET_CRYPTO_EddsaPrivateKey *pk) |
545 | { | 446 | { |
@@ -560,11 +461,6 @@ GNUNET_CRYPTO_eddsa_key_create (struct GNUNET_CRYPTO_EddsaPrivateKey *pk) | |||
560 | } | 461 | } |
561 | 462 | ||
562 | 463 | ||
563 | /** | ||
564 | * Get the shared private key we use for anonymous users. | ||
565 | * | ||
566 | * @return "anonymous" private key | ||
567 | */ | ||
568 | const struct GNUNET_CRYPTO_EcdsaPrivateKey * | 464 | const struct GNUNET_CRYPTO_EcdsaPrivateKey * |
569 | GNUNET_CRYPTO_ecdsa_key_get_anonymous () | 465 | GNUNET_CRYPTO_ecdsa_key_get_anonymous () |
570 | { | 466 | { |
@@ -629,19 +525,7 @@ data_to_ecdsa_value (const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose) | |||
629 | } | 525 | } |
630 | 526 | ||
631 | 527 | ||
632 | /** | 528 | enum GNUNET_GenericReturnValue |
633 | * Sign a given block. The @a purpose data is the | ||
634 | * beginning of the data of which the signature is to be | ||
635 | * created. The `size` field in @a purpose must correctly | ||
636 | * indicate the number of bytes of the data structure, including | ||
637 | * its header. | ||
638 | * | ||
639 | * @param priv private key to use for the signing | ||
640 | * @param purpose what to sign (size, purpose) | ||
641 | * @param sig where to write the signature | ||
642 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success | ||
643 | */ | ||
644 | int | ||
645 | GNUNET_CRYPTO_ecdsa_sign_ ( | 529 | GNUNET_CRYPTO_ecdsa_sign_ ( |
646 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, | 530 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, |
647 | const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, | 531 | const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, |
@@ -691,19 +575,7 @@ GNUNET_CRYPTO_ecdsa_sign_ ( | |||
691 | } | 575 | } |
692 | 576 | ||
693 | 577 | ||
694 | /** | 578 | enum GNUNET_GenericReturnValue |
695 | * Sign a given block. The @a purpose data is the | ||
696 | * beginning of the data of which the signature is to be | ||
697 | * created. The `size` field in @a purpose must correctly | ||
698 | * indicate the number of bytes of the data structure, including | ||
699 | * its header. | ||
700 | * | ||
701 | * @param priv private key to use for the signing | ||
702 | * @param purpose what to sign (size, purpose) | ||
703 | * @param sig where to write the signature | ||
704 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success | ||
705 | */ | ||
706 | int | ||
707 | GNUNET_CRYPTO_eddsa_sign_ ( | 579 | GNUNET_CRYPTO_eddsa_sign_ ( |
708 | const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, | 580 | const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, |
709 | const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, | 581 | const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, |
@@ -727,21 +599,7 @@ GNUNET_CRYPTO_eddsa_sign_ ( | |||
727 | } | 599 | } |
728 | 600 | ||
729 | 601 | ||
730 | /** | 602 | enum GNUNET_GenericReturnValue |
731 | * Verify signature. The @a validate data is the | ||
732 | * beginning of the data of which the signature is to be | ||
733 | * verified. The `size` field in @a validate must correctly | ||
734 | * indicate the number of bytes of the data structure, including | ||
735 | * its header. If @a purpose does not match the purpose given | ||
736 | * in @a validate (the latter | ||
737 | * | ||
738 | * @param purpose what is the purpose that the signature should have? | ||
739 | * @param validate block to validate (size, purpose, data) | ||
740 | * @param sig signature that is being validated | ||
741 | * @param pub public key of the signer | ||
742 | * @returns #GNUNET_OK if ok, #GNUNET_SYSERR if invalid | ||
743 | */ | ||
744 | int | ||
745 | GNUNET_CRYPTO_ecdsa_verify_ ( | 603 | GNUNET_CRYPTO_ecdsa_verify_ ( |
746 | uint32_t purpose, | 604 | uint32_t purpose, |
747 | const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, | 605 | const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, |
@@ -800,22 +658,7 @@ GNUNET_CRYPTO_ecdsa_verify_ ( | |||
800 | } | 658 | } |
801 | 659 | ||
802 | 660 | ||
803 | /** | 661 | enum GNUNET_GenericReturnValue |
804 | * Verify signature. The @a validate data is the | ||
805 | * beginning of the data of which the signature is to be | ||
806 | * verified. The `size` field in @a validate must correctly | ||
807 | * indicate the number of bytes of the data structure, including | ||
808 | * its header. If @a purpose does not match the purpose given | ||
809 | * in @a validate (the latter must be in big endian), signature | ||
810 | * verification fails. | ||
811 | * | ||
812 | * @param purpose what is the purpose that the signature should have? | ||
813 | * @param validate block to validate (size, purpose, data) | ||
814 | * @param sig signature that is being validated | ||
815 | * @param pub public key of the signer | ||
816 | * @returns #GNUNET_OK if ok, #GNUNET_SYSERR if invalid | ||
817 | */ | ||
818 | int | ||
819 | GNUNET_CRYPTO_eddsa_verify_ ( | 662 | GNUNET_CRYPTO_eddsa_verify_ ( |
820 | uint32_t purpose, | 663 | uint32_t purpose, |
821 | const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, | 664 | const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, |
@@ -838,15 +681,7 @@ GNUNET_CRYPTO_eddsa_verify_ ( | |||
838 | } | 681 | } |
839 | 682 | ||
840 | 683 | ||
841 | /** | 684 | enum GNUNET_GenericReturnValue |
842 | * Derive key material from a public and a private ECDHE key. | ||
843 | * | ||
844 | * @param priv private key to use for the ECDH (x) | ||
845 | * @param pub public key to use for the ECDH (yG) | ||
846 | * @param key_material where to write the key material (xyG) | ||
847 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success | ||
848 | */ | ||
849 | int | ||
850 | GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, | 685 | GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, |
851 | const struct GNUNET_CRYPTO_EcdhePublicKey *pub, | 686 | const struct GNUNET_CRYPTO_EcdhePublicKey *pub, |
852 | struct GNUNET_HashCode *key_material) | 687 | struct GNUNET_HashCode *key_material) |
@@ -895,18 +730,6 @@ derive_h (const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, | |||
895 | } | 730 | } |
896 | 731 | ||
897 | 732 | ||
898 | /** | ||
899 | * Derive a private key from a given private key and a label. | ||
900 | * Essentially calculates a private key 'd = H(l,P) * x mod n' | ||
901 | * where n is the size of the ECC group and P is the public | ||
902 | * key associated with the private key 'd'. | ||
903 | * | ||
904 | * @param priv original private key | ||
905 | * @param label label to use for key deriviation | ||
906 | * @param context additional context to use for HKDF of 'h'; | ||
907 | * typically the name of the subsystem/application | ||
908 | * @return derived private key | ||
909 | */ | ||
910 | struct GNUNET_CRYPTO_EcdsaPrivateKey * | 733 | struct GNUNET_CRYPTO_EcdsaPrivateKey * |
911 | GNUNET_CRYPTO_ecdsa_private_key_derive ( | 734 | GNUNET_CRYPTO_ecdsa_private_key_derive ( |
912 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, | 735 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, |
@@ -949,16 +772,6 @@ GNUNET_CRYPTO_ecdsa_private_key_derive ( | |||
949 | } | 772 | } |
950 | 773 | ||
951 | 774 | ||
952 | /** | ||
953 | * Derive a public key from a given public key and a label. | ||
954 | * Essentially calculates a public key 'V = H(l,P) * P'. | ||
955 | * | ||
956 | * @param pub original public key | ||
957 | * @param label label to use for key derivation | ||
958 | * @param context additional context to use for HKDF of 'h'; | ||
959 | * typically the name of the subsystem/application | ||
960 | * @param result where to write the derived public key | ||
961 | */ | ||
962 | void | 775 | void |
963 | GNUNET_CRYPTO_ecdsa_public_key_derive ( | 776 | GNUNET_CRYPTO_ecdsa_public_key_derive ( |
964 | const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, | 777 | const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, |
@@ -1010,17 +823,7 @@ GNUNET_CRYPTO_ecdsa_public_key_derive ( | |||
1010 | } | 823 | } |
1011 | 824 | ||
1012 | 825 | ||
1013 | /** | 826 | enum GNUNET_GenericReturnValue |
1014 | * @ingroup crypto | ||
1015 | * Derive key material from a ECDH public key and a private EdDSA key. | ||
1016 | * Dual to #GNUNET_CRRYPTO_ecdh_eddsa. | ||
1017 | * | ||
1018 | * @param priv private key from EdDSA to use for the ECDH (x) | ||
1019 | * @param pub public key to use for the ECDH (yG) | ||
1020 | * @param key_material where to write the key material H(h(x)yG) | ||
1021 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success | ||
1022 | */ | ||
1023 | int | ||
1024 | GNUNET_CRYPTO_eddsa_ecdh (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, | 827 | GNUNET_CRYPTO_eddsa_ecdh (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, |
1025 | const struct GNUNET_CRYPTO_EcdhePublicKey *pub, | 828 | const struct GNUNET_CRYPTO_EcdhePublicKey *pub, |
1026 | struct GNUNET_HashCode *key_material) | 829 | struct GNUNET_HashCode *key_material) |
@@ -1042,17 +845,7 @@ GNUNET_CRYPTO_eddsa_ecdh (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, | |||
1042 | } | 845 | } |
1043 | 846 | ||
1044 | 847 | ||
1045 | /** | 848 | enum GNUNET_GenericReturnValue |
1046 | * @ingroup crypto | ||
1047 | * Derive key material from a ECDH public key and a private ECDSA key. | ||
1048 | * Dual to #GNUNET_CRRYPTO_ecdh_eddsa. | ||
1049 | * | ||
1050 | * @param priv private key from ECDSA to use for the ECDH (x) | ||
1051 | * @param pub public key to use for the ECDH (yG) | ||
1052 | * @param key_material where to write the key material H(h(x)yG) | ||
1053 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success | ||
1054 | */ | ||
1055 | int | ||
1056 | GNUNET_CRYPTO_ecdsa_ecdh (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, | 849 | GNUNET_CRYPTO_ecdsa_ecdh (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, |
1057 | const struct GNUNET_CRYPTO_EcdhePublicKey *pub, | 850 | const struct GNUNET_CRYPTO_EcdhePublicKey *pub, |
1058 | struct GNUNET_HashCode *key_material) | 851 | struct GNUNET_HashCode *key_material) |
@@ -1070,17 +863,7 @@ GNUNET_CRYPTO_ecdsa_ecdh (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, | |||
1070 | } | 863 | } |
1071 | 864 | ||
1072 | 865 | ||
1073 | /** | 866 | enum GNUNET_GenericReturnValue |
1074 | * @ingroup crypto | ||
1075 | * Derive key material from a EdDSA public key and a private ECDH key. | ||
1076 | * Dual to #GNUNET_CRRYPTO_eddsa_ecdh. | ||
1077 | * | ||
1078 | * @param priv private key to use for the ECDH (y) | ||
1079 | * @param pub public key from EdDSA to use for the ECDH (X=h(x)G) | ||
1080 | * @param key_material where to write the key material H(yX)=H(h(x)yG) | ||
1081 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success | ||
1082 | */ | ||
1083 | int | ||
1084 | GNUNET_CRYPTO_ecdh_eddsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, | 867 | GNUNET_CRYPTO_ecdh_eddsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, |
1085 | const struct GNUNET_CRYPTO_EddsaPublicKey *pub, | 868 | const struct GNUNET_CRYPTO_EddsaPublicKey *pub, |
1086 | struct GNUNET_HashCode *key_material) | 869 | struct GNUNET_HashCode *key_material) |
@@ -1097,17 +880,7 @@ GNUNET_CRYPTO_ecdh_eddsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, | |||
1097 | } | 880 | } |
1098 | 881 | ||
1099 | 882 | ||
1100 | /** | 883 | enum GNUNET_GenericReturnValue |
1101 | * @ingroup crypto | ||
1102 | * Derive key material from a ECDSA public key and a private ECDH key. | ||
1103 | * Dual to #GNUNET_CRYPTO_ecdsa_ecdh. | ||
1104 | * | ||
1105 | * @param priv private key to use for the ECDH (y) | ||
1106 | * @param pub public key from ECDSA to use for the ECDH (X=h(x)G) | ||
1107 | * @param key_material where to write the key material H(yX)=H(h(x)yG) | ||
1108 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success | ||
1109 | */ | ||
1110 | int | ||
1111 | GNUNET_CRYPTO_ecdh_ecdsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, | 884 | GNUNET_CRYPTO_ecdh_ecdsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, |
1112 | const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, | 885 | const struct GNUNET_CRYPTO_EcdsaPublicKey *pub, |
1113 | struct GNUNET_HashCode *key_material) | 886 | 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 @@ | |||
61 | * @param buf_size number of bytes in @a buf | 61 | * @param buf_size number of bytes in @a buf |
62 | * @return #GNUNET_OK on success | 62 | * @return #GNUNET_OK on success |
63 | */ | 63 | */ |
64 | static int | 64 | static enum GNUNET_GenericReturnValue |
65 | read_from_file (const char *filename, | 65 | read_from_file (const char *filename, |
66 | void *buf, | 66 | void *buf, |
67 | size_t buf_size) | 67 | size_t buf_size) |
@@ -123,104 +123,6 @@ read_from_file (const char *filename, | |||
123 | 123 | ||
124 | 124 | ||
125 | /** | 125 | /** |
126 | * Write contents of @a buf atomically to @a filename. | ||
127 | * Fail if @a filename already exists or if not exactly | ||
128 | * @a buf with @a buf_size bytes could be written to | ||
129 | * @a filename. | ||
130 | * | ||
131 | * @param filename where to write | ||
132 | * @param buf buffer to write | ||
133 | * @param buf_size number of bytes in @a buf to write | ||
134 | * @return #GNUNET_OK on success, | ||
135 | * #GNUNET_NO if a file existed under @a filename | ||
136 | * #GNUNET_SYSERR on failure | ||
137 | */ | ||
138 | static int | ||
139 | atomic_write_to_file (const char *filename, | ||
140 | const void *buf, | ||
141 | size_t buf_size) | ||
142 | { | ||
143 | char *tmpl; | ||
144 | int fd; | ||
145 | |||
146 | if (GNUNET_OK != | ||
147 | GNUNET_DISK_directory_create_for_file (filename)) | ||
148 | { | ||
149 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
150 | "mkstemp", | ||
151 | filename); | ||
152 | return GNUNET_SYSERR; | ||
153 | } | ||
154 | { | ||
155 | char *dname; | ||
156 | |||
157 | dname = GNUNET_strdup (filename); | ||
158 | GNUNET_asprintf (&tmpl, | ||
159 | "%s/XXXXXX", | ||
160 | dirname (dname)); | ||
161 | GNUNET_free (dname); | ||
162 | } | ||
163 | fd = mkstemp (tmpl); | ||
164 | if (-1 == fd) | ||
165 | { | ||
166 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
167 | "mkstemp", | ||
168 | tmpl); | ||
169 | GNUNET_free (tmpl); | ||
170 | return GNUNET_SYSERR; | ||
171 | } | ||
172 | if (0 != fchmod (fd, | ||
173 | S_IRUSR)) | ||
174 | { | ||
175 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
176 | "chmod", | ||
177 | tmpl); | ||
178 | GNUNET_assert (0 == close (fd)); | ||
179 | if (0 != unlink (tmpl)) | ||
180 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | ||
181 | "unlink", | ||
182 | tmpl); | ||
183 | GNUNET_free (tmpl); | ||
184 | return GNUNET_SYSERR; | ||
185 | } | ||
186 | if (buf_size != | ||
187 | write (fd, | ||
188 | buf, | ||
189 | buf_size)) | ||
190 | { | ||
191 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
192 | "write", | ||
193 | tmpl); | ||
194 | GNUNET_assert (0 == close (fd)); | ||
195 | if (0 != unlink (tmpl)) | ||
196 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | ||
197 | "unlink", | ||
198 | tmpl); | ||
199 | GNUNET_free (tmpl); | ||
200 | return GNUNET_SYSERR; | ||
201 | } | ||
202 | GNUNET_assert (0 == close (fd)); | ||
203 | |||
204 | if (0 != link (tmpl, | ||
205 | filename)) | ||
206 | { | ||
207 | if (0 != unlink (tmpl)) | ||
208 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | ||
209 | "unlink", | ||
210 | tmpl); | ||
211 | GNUNET_free (tmpl); | ||
212 | return GNUNET_NO; | ||
213 | } | ||
214 | if (0 != unlink (tmpl)) | ||
215 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | ||
216 | "unlink", | ||
217 | tmpl); | ||
218 | GNUNET_free (tmpl); | ||
219 | return GNUNET_OK; | ||
220 | } | ||
221 | |||
222 | |||
223 | /** | ||
224 | * @ingroup crypto | 126 | * @ingroup crypto |
225 | * @brief Create a new private key by reading it from a file. | 127 | * @brief Create a new private key by reading it from a file. |
226 | * | 128 | * |
@@ -235,12 +137,12 @@ atomic_write_to_file (const char *filename, | |||
235 | * @return #GNUNET_OK on success, #GNUNET_NO if @a do_create was set but | 137 | * @return #GNUNET_OK on success, #GNUNET_NO if @a do_create was set but |
236 | * we found an existing file, #GNUNET_SYSERR on failure | 138 | * we found an existing file, #GNUNET_SYSERR on failure |
237 | */ | 139 | */ |
238 | int | 140 | enum GNUNET_GenericReturnValue |
239 | GNUNET_CRYPTO_eddsa_key_from_file (const char *filename, | 141 | GNUNET_CRYPTO_eddsa_key_from_file (const char *filename, |
240 | int do_create, | 142 | int do_create, |
241 | struct GNUNET_CRYPTO_EddsaPrivateKey *pkey) | 143 | struct GNUNET_CRYPTO_EddsaPrivateKey *pkey) |
242 | { | 144 | { |
243 | int ret; | 145 | enum GNUNET_GenericReturnValue ret; |
244 | 146 | ||
245 | if (GNUNET_OK == | 147 | if (GNUNET_OK == |
246 | read_from_file (filename, | 148 | read_from_file (filename, |
@@ -251,9 +153,10 @@ GNUNET_CRYPTO_eddsa_key_from_file (const char *filename, | |||
251 | return (do_create) ? GNUNET_NO : GNUNET_OK; | 153 | return (do_create) ? GNUNET_NO : GNUNET_OK; |
252 | } | 154 | } |
253 | GNUNET_CRYPTO_eddsa_key_create (pkey); | 155 | GNUNET_CRYPTO_eddsa_key_create (pkey); |
254 | ret = atomic_write_to_file (filename, | 156 | ret = GNUNET_DISK_fn_write (filename, |
255 | pkey, | 157 | pkey, |
256 | sizeof (*pkey)); | 158 | sizeof (*pkey), |
159 | GNUNET_DISK_PERM_USER_READ); | ||
257 | if ( (GNUNET_OK == ret) || | 160 | if ( (GNUNET_OK == ret) || |
258 | (GNUNET_SYSERR == ret) ) | 161 | (GNUNET_SYSERR == ret) ) |
259 | return ret; | 162 | return ret; |
@@ -286,7 +189,7 @@ GNUNET_CRYPTO_eddsa_key_from_file (const char *filename, | |||
286 | * @return #GNUNET_OK on success, #GNUNET_NO if @a do_create was set but | 189 | * @return #GNUNET_OK on success, #GNUNET_NO if @a do_create was set but |
287 | * we found an existing file, #GNUNET_SYSERR on failure | 190 | * we found an existing file, #GNUNET_SYSERR on failure |
288 | */ | 191 | */ |
289 | int | 192 | enum GNUNET_GenericReturnValue |
290 | GNUNET_CRYPTO_ecdsa_key_from_file (const char *filename, | 193 | GNUNET_CRYPTO_ecdsa_key_from_file (const char *filename, |
291 | int do_create, | 194 | int do_create, |
292 | struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey) | 195 | struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey) |
@@ -301,9 +204,10 @@ GNUNET_CRYPTO_ecdsa_key_from_file (const char *filename, | |||
301 | } | 204 | } |
302 | GNUNET_CRYPTO_ecdsa_key_create (pkey); | 205 | GNUNET_CRYPTO_ecdsa_key_create (pkey); |
303 | if (GNUNET_OK == | 206 | if (GNUNET_OK == |
304 | atomic_write_to_file (filename, | 207 | GNUNET_DISK_fn_write (filename, |
305 | pkey, | 208 | pkey, |
306 | sizeof (*pkey))) | 209 | sizeof (*pkey), |
210 | GNUNET_DISK_PERM_USER_READ)) | ||
307 | return GNUNET_OK; | 211 | return GNUNET_OK; |
308 | /* maybe another process succeeded in the meantime, try reading one more time */ | 212 | /* maybe another process succeeded in the meantime, try reading one more time */ |
309 | if (GNUNET_OK == | 213 | if (GNUNET_OK == |
@@ -357,7 +261,7 @@ GNUNET_CRYPTO_eddsa_key_create_from_configuration ( | |||
357 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the identity | 261 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the identity |
358 | * could not be retrieved | 262 | * could not be retrieved |
359 | */ | 263 | */ |
360 | int | 264 | enum GNUNET_GenericReturnValue |
361 | GNUNET_CRYPTO_get_peer_identity (const struct GNUNET_CONFIGURATION_Handle *cfg, | 265 | GNUNET_CRYPTO_get_peer_identity (const struct GNUNET_CONFIGURATION_Handle *cfg, |
362 | struct GNUNET_PeerIdentity *dst) | 266 | struct GNUNET_PeerIdentity *dst) |
363 | { | 267 | { |
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, | |||
139 | } | 139 | } |
140 | 140 | ||
141 | 141 | ||
142 | /** | ||
143 | * Create a new private key. Caller must free return value. | ||
144 | * | ||
145 | * @param len length of the key in bits (i.e. 2048) | ||
146 | * @return fresh private key | ||
147 | */ | ||
148 | struct GNUNET_CRYPTO_RsaPrivateKey * | 142 | struct GNUNET_CRYPTO_RsaPrivateKey * |
149 | GNUNET_CRYPTO_rsa_private_key_create (unsigned int len) | 143 | GNUNET_CRYPTO_rsa_private_key_create (unsigned int len) |
150 | { | 144 | { |
@@ -174,11 +168,6 @@ GNUNET_CRYPTO_rsa_private_key_create (unsigned int len) | |||
174 | } | 168 | } |
175 | 169 | ||
176 | 170 | ||
177 | /** | ||
178 | * Free memory occupied by the private key. | ||
179 | * | ||
180 | * @param key pointer to the memory to free | ||
181 | */ | ||
182 | void | 171 | void |
183 | GNUNET_CRYPTO_rsa_private_key_free (struct GNUNET_CRYPTO_RsaPrivateKey *key) | 172 | GNUNET_CRYPTO_rsa_private_key_free (struct GNUNET_CRYPTO_RsaPrivateKey *key) |
184 | { | 173 | { |
@@ -187,14 +176,6 @@ GNUNET_CRYPTO_rsa_private_key_free (struct GNUNET_CRYPTO_RsaPrivateKey *key) | |||
187 | } | 176 | } |
188 | 177 | ||
189 | 178 | ||
190 | /** | ||
191 | * Encode the private key in a format suitable for | ||
192 | * storing it into a file. | ||
193 | * | ||
194 | * @param key the private key | ||
195 | * @param[out] buffer set to a buffer with the encoded key | ||
196 | * @return size of memory allocated in @a buffer | ||
197 | */ | ||
198 | size_t | 179 | size_t |
199 | GNUNET_CRYPTO_rsa_private_key_encode (const struct | 180 | GNUNET_CRYPTO_rsa_private_key_encode (const struct |
200 | GNUNET_CRYPTO_RsaPrivateKey *key, | 181 | GNUNET_CRYPTO_RsaPrivateKey *key, |
@@ -218,14 +199,6 @@ GNUNET_CRYPTO_rsa_private_key_encode (const struct | |||
218 | } | 199 | } |
219 | 200 | ||
220 | 201 | ||
221 | /** | ||
222 | * Decode the private key from the data-format back | ||
223 | * to the "normal", internal format. | ||
224 | * | ||
225 | * @param buf the buffer where the private key data is stored | ||
226 | * @param buf_size the size of the data in @a buf | ||
227 | * @return NULL on error | ||
228 | */ | ||
229 | struct GNUNET_CRYPTO_RsaPrivateKey * | 202 | struct GNUNET_CRYPTO_RsaPrivateKey * |
230 | GNUNET_CRYPTO_rsa_private_key_decode (const void *buf, | 203 | GNUNET_CRYPTO_rsa_private_key_decode (const void *buf, |
231 | size_t buf_size) | 204 | size_t buf_size) |
@@ -255,12 +228,6 @@ GNUNET_CRYPTO_rsa_private_key_decode (const void *buf, | |||
255 | } | 228 | } |
256 | 229 | ||
257 | 230 | ||
258 | /** | ||
259 | * Extract the public key of the given private key. | ||
260 | * | ||
261 | * @param priv the private key | ||
262 | * @return NULL on error, otherwise the public key | ||
263 | */ | ||
264 | struct GNUNET_CRYPTO_RsaPublicKey * | 231 | struct GNUNET_CRYPTO_RsaPublicKey * |
265 | GNUNET_CRYPTO_rsa_private_key_get_public ( | 232 | GNUNET_CRYPTO_rsa_private_key_get_public ( |
266 | const struct GNUNET_CRYPTO_RsaPrivateKey *priv) | 233 | const struct GNUNET_CRYPTO_RsaPrivateKey *priv) |
@@ -296,11 +263,6 @@ GNUNET_CRYPTO_rsa_private_key_get_public ( | |||
296 | } | 263 | } |
297 | 264 | ||
298 | 265 | ||
299 | /** | ||
300 | * Free memory occupied by the public key. | ||
301 | * | ||
302 | * @param key pointer to the memory to free | ||
303 | */ | ||
304 | void | 266 | void |
305 | GNUNET_CRYPTO_rsa_public_key_free (struct GNUNET_CRYPTO_RsaPublicKey *key) | 267 | GNUNET_CRYPTO_rsa_public_key_free (struct GNUNET_CRYPTO_RsaPublicKey *key) |
306 | { | 268 | { |
@@ -334,14 +296,6 @@ struct GNUNET_CRYPTO_RsaPublicKeyHeaderP | |||
334 | GNUNET_NETWORK_STRUCT_END | 296 | GNUNET_NETWORK_STRUCT_END |
335 | 297 | ||
336 | 298 | ||
337 | /** | ||
338 | * Encode the public key in a format suitable for | ||
339 | * storing it into a file. | ||
340 | * | ||
341 | * @param key the private key | ||
342 | * @param[out] buffer set to a buffer with the encoded key | ||
343 | * @return size of memory allocated in @a buffer | ||
344 | */ | ||
345 | size_t | 299 | size_t |
346 | GNUNET_CRYPTO_rsa_public_key_encode ( | 300 | GNUNET_CRYPTO_rsa_public_key_encode ( |
347 | const struct GNUNET_CRYPTO_RsaPublicKey *key, | 301 | const struct GNUNET_CRYPTO_RsaPublicKey *key, |
@@ -409,12 +363,6 @@ GNUNET_CRYPTO_rsa_public_key_encode ( | |||
409 | } | 363 | } |
410 | 364 | ||
411 | 365 | ||
412 | /** | ||
413 | * Compute hash over the public key. | ||
414 | * | ||
415 | * @param key public key to hash | ||
416 | * @param hc where to store the hash code | ||
417 | */ | ||
418 | void | 366 | void |
419 | GNUNET_CRYPTO_rsa_public_key_hash (const struct GNUNET_CRYPTO_RsaPublicKey *key, | 367 | GNUNET_CRYPTO_rsa_public_key_hash (const struct GNUNET_CRYPTO_RsaPublicKey *key, |
420 | struct GNUNET_HashCode *hc) | 368 | struct GNUNET_HashCode *hc) |
@@ -431,14 +379,6 @@ GNUNET_CRYPTO_rsa_public_key_hash (const struct GNUNET_CRYPTO_RsaPublicKey *key, | |||
431 | } | 379 | } |
432 | 380 | ||
433 | 381 | ||
434 | /** | ||
435 | * Decode the public key from the data-format back | ||
436 | * to the "normal", internal format. | ||
437 | * | ||
438 | * @param buf the buffer where the public key data is stored | ||
439 | * @param len the length of the data in @a buf | ||
440 | * @return NULL on error | ||
441 | */ | ||
442 | struct GNUNET_CRYPTO_RsaPublicKey * | 382 | struct GNUNET_CRYPTO_RsaPublicKey * |
443 | GNUNET_CRYPTO_rsa_public_key_decode (const char *buf, | 383 | GNUNET_CRYPTO_rsa_public_key_decode (const char *buf, |
444 | size_t len) | 384 | size_t len) |
@@ -612,13 +552,6 @@ rsa_blinding_key_derive (const struct GNUNET_CRYPTO_RsaPublicKey *pkey, | |||
612 | */ | 552 | */ |
613 | 553 | ||
614 | 554 | ||
615 | /** | ||
616 | * Compare the values of two signatures. | ||
617 | * | ||
618 | * @param s1 one signature | ||
619 | * @param s2 the other signature | ||
620 | * @return 0 if the two are equal | ||
621 | */ | ||
622 | int | 555 | int |
623 | GNUNET_CRYPTO_rsa_signature_cmp (const struct GNUNET_CRYPTO_RsaSignature *s1, | 556 | GNUNET_CRYPTO_rsa_signature_cmp (const struct GNUNET_CRYPTO_RsaSignature *s1, |
624 | const struct GNUNET_CRYPTO_RsaSignature *s2) | 557 | const struct GNUNET_CRYPTO_RsaSignature *s2) |
@@ -645,13 +578,6 @@ GNUNET_CRYPTO_rsa_signature_cmp (const struct GNUNET_CRYPTO_RsaSignature *s1, | |||
645 | } | 578 | } |
646 | 579 | ||
647 | 580 | ||
648 | /** | ||
649 | * Compare the values of two public keys. | ||
650 | * | ||
651 | * @param p1 one public key | ||
652 | * @param p2 the other public key | ||
653 | * @return 0 if the two are equal | ||
654 | */ | ||
655 | int | 581 | int |
656 | GNUNET_CRYPTO_rsa_public_key_cmp (const struct GNUNET_CRYPTO_RsaPublicKey *p1, | 582 | GNUNET_CRYPTO_rsa_public_key_cmp (const struct GNUNET_CRYPTO_RsaPublicKey *p1, |
657 | const struct GNUNET_CRYPTO_RsaPublicKey *p2) | 583 | const struct GNUNET_CRYPTO_RsaPublicKey *p2) |
@@ -678,13 +604,6 @@ GNUNET_CRYPTO_rsa_public_key_cmp (const struct GNUNET_CRYPTO_RsaPublicKey *p1, | |||
678 | } | 604 | } |
679 | 605 | ||
680 | 606 | ||
681 | /** | ||
682 | * Compare the values of two private keys. | ||
683 | * | ||
684 | * @param p1 one private key | ||
685 | * @param p2 the other private key | ||
686 | * @return 0 if the two are equal | ||
687 | */ | ||
688 | int | 607 | int |
689 | GNUNET_CRYPTO_rsa_private_key_cmp (const struct GNUNET_CRYPTO_RsaPrivateKey *p1, | 608 | GNUNET_CRYPTO_rsa_private_key_cmp (const struct GNUNET_CRYPTO_RsaPrivateKey *p1, |
690 | const struct GNUNET_CRYPTO_RsaPrivateKey *p2) | 609 | const struct GNUNET_CRYPTO_RsaPrivateKey *p2) |
@@ -711,12 +630,6 @@ GNUNET_CRYPTO_rsa_private_key_cmp (const struct GNUNET_CRYPTO_RsaPrivateKey *p1, | |||
711 | } | 630 | } |
712 | 631 | ||
713 | 632 | ||
714 | /** | ||
715 | * Obtain the length of the RSA key in bits. | ||
716 | * | ||
717 | * @param key the public key to introspect | ||
718 | * @return length of the key in bits | ||
719 | */ | ||
720 | unsigned int | 633 | unsigned int |
721 | GNUNET_CRYPTO_rsa_public_key_len (const struct GNUNET_CRYPTO_RsaPublicKey *key) | 634 | GNUNET_CRYPTO_rsa_public_key_len (const struct GNUNET_CRYPTO_RsaPublicKey *key) |
722 | { | 635 | { |
@@ -827,17 +740,7 @@ rsa_full_domain_hash (const struct GNUNET_CRYPTO_RsaPublicKey *pkey, | |||
827 | } | 740 | } |
828 | 741 | ||
829 | 742 | ||
830 | /** | 743 | enum GNUNET_GenericReturnValue |
831 | * Blinds the given message with the given blinding key | ||
832 | * | ||
833 | * @param hash hash of the message to sign | ||
834 | * @param bkey the blinding key | ||
835 | * @param pkey the public key of the signer | ||
836 | * @param[out] buf set to a buffer with the blinded message to be signed | ||
837 | * @param[out] buf_size number of bytes stored in @a buf | ||
838 | * @return #GNUNET_YES if successful, #GNUNET_NO if RSA key is malicious | ||
839 | */ | ||
840 | int | ||
841 | GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash, | 744 | GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash, |
842 | const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks, | 745 | const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks, |
843 | struct GNUNET_CRYPTO_RsaPublicKey *pkey, | 746 | struct GNUNET_CRYPTO_RsaPublicKey *pkey, |
@@ -863,7 +766,7 @@ GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash, | |||
863 | GNUNET_break (0); | 766 | GNUNET_break (0); |
864 | *buf = NULL; | 767 | *buf = NULL; |
865 | *buf_size = 0; | 768 | *buf_size = 0; |
866 | return 0; | 769 | return GNUNET_NO; |
867 | } | 770 | } |
868 | 771 | ||
869 | data = rsa_full_domain_hash (pkey, hash); | 772 | data = rsa_full_domain_hash (pkey, hash); |
@@ -993,14 +896,6 @@ rsa_sign_mpi (const struct GNUNET_CRYPTO_RsaPrivateKey *key, | |||
993 | } | 896 | } |
994 | 897 | ||
995 | 898 | ||
996 | /** | ||
997 | * Sign a blinded value, which must be a full domain hash of a message. | ||
998 | * | ||
999 | * @param key private key to use for the signing | ||
1000 | * @param msg the message to sign | ||
1001 | * @param msg_len number of bytes in @a msg to sign | ||
1002 | * @return NULL on error, signature on success | ||
1003 | */ | ||
1004 | struct GNUNET_CRYPTO_RsaSignature * | 899 | struct GNUNET_CRYPTO_RsaSignature * |
1005 | GNUNET_CRYPTO_rsa_sign_blinded (const struct GNUNET_CRYPTO_RsaPrivateKey *key, | 900 | GNUNET_CRYPTO_rsa_sign_blinded (const struct GNUNET_CRYPTO_RsaPrivateKey *key, |
1006 | const void *msg, | 901 | const void *msg, |
@@ -1025,13 +920,6 @@ GNUNET_CRYPTO_rsa_sign_blinded (const struct GNUNET_CRYPTO_RsaPrivateKey *key, | |||
1025 | } | 920 | } |
1026 | 921 | ||
1027 | 922 | ||
1028 | /** | ||
1029 | * Create and sign a full domain hash of a message. | ||
1030 | * | ||
1031 | * @param key private key to use for the signing | ||
1032 | * @param hash the hash of the message to sign | ||
1033 | * @return NULL on error, including a malicious RSA key, signature on success | ||
1034 | */ | ||
1035 | struct GNUNET_CRYPTO_RsaSignature * | 923 | struct GNUNET_CRYPTO_RsaSignature * |
1036 | GNUNET_CRYPTO_rsa_sign_fdh (const struct GNUNET_CRYPTO_RsaPrivateKey *key, | 924 | GNUNET_CRYPTO_rsa_sign_fdh (const struct GNUNET_CRYPTO_RsaPrivateKey *key, |
1037 | const struct GNUNET_HashCode *hash) | 925 | const struct GNUNET_HashCode *hash) |
@@ -1052,11 +940,6 @@ GNUNET_CRYPTO_rsa_sign_fdh (const struct GNUNET_CRYPTO_RsaPrivateKey *key, | |||
1052 | } | 940 | } |
1053 | 941 | ||
1054 | 942 | ||
1055 | /** | ||
1056 | * Free memory occupied by signature. | ||
1057 | * | ||
1058 | * @param sig memory to free | ||
1059 | */ | ||
1060 | void | 943 | void |
1061 | GNUNET_CRYPTO_rsa_signature_free (struct GNUNET_CRYPTO_RsaSignature *sig) | 944 | GNUNET_CRYPTO_rsa_signature_free (struct GNUNET_CRYPTO_RsaSignature *sig) |
1062 | { | 945 | { |
@@ -1065,13 +948,6 @@ GNUNET_CRYPTO_rsa_signature_free (struct GNUNET_CRYPTO_RsaSignature *sig) | |||
1065 | } | 948 | } |
1066 | 949 | ||
1067 | 950 | ||
1068 | /** | ||
1069 | * Encode the given signature in a format suitable for storing it into a file. | ||
1070 | * | ||
1071 | * @param sig the signature | ||
1072 | * @param[out] buffer set to a buffer with the encoded key | ||
1073 | * @return size of memory allocated in @a buffer | ||
1074 | */ | ||
1075 | size_t | 951 | size_t |
1076 | GNUNET_CRYPTO_rsa_signature_encode ( | 952 | GNUNET_CRYPTO_rsa_signature_encode ( |
1077 | const struct GNUNET_CRYPTO_RsaSignature *sig, | 953 | const struct GNUNET_CRYPTO_RsaSignature *sig, |
@@ -1112,14 +988,6 @@ GNUNET_CRYPTO_rsa_signature_encode ( | |||
1112 | } | 988 | } |
1113 | 989 | ||
1114 | 990 | ||
1115 | /** | ||
1116 | * Decode the signature from the data-format back to the "normal", internal | ||
1117 | * format. | ||
1118 | * | ||
1119 | * @param buf the buffer where the public key data is stored | ||
1120 | * @param buf_size the size of the data in @a buf | ||
1121 | * @return NULL on error | ||
1122 | */ | ||
1123 | struct GNUNET_CRYPTO_RsaSignature * | 991 | struct GNUNET_CRYPTO_RsaSignature * |
1124 | GNUNET_CRYPTO_rsa_signature_decode (const void *buf, | 992 | GNUNET_CRYPTO_rsa_signature_decode (const void *buf, |
1125 | size_t buf_size) | 993 | size_t buf_size) |
@@ -1156,12 +1024,6 @@ GNUNET_CRYPTO_rsa_signature_decode (const void *buf, | |||
1156 | } | 1024 | } |
1157 | 1025 | ||
1158 | 1026 | ||
1159 | /** | ||
1160 | * Duplicate the given public key | ||
1161 | * | ||
1162 | * @param key the public key to duplicate | ||
1163 | * @return the duplicate key; NULL upon error | ||
1164 | */ | ||
1165 | struct GNUNET_CRYPTO_RsaPublicKey * | 1027 | struct GNUNET_CRYPTO_RsaPublicKey * |
1166 | GNUNET_CRYPTO_rsa_public_key_dup (const struct GNUNET_CRYPTO_RsaPublicKey *key) | 1028 | GNUNET_CRYPTO_rsa_public_key_dup (const struct GNUNET_CRYPTO_RsaPublicKey *key) |
1167 | { | 1029 | { |
@@ -1181,16 +1043,6 @@ GNUNET_CRYPTO_rsa_public_key_dup (const struct GNUNET_CRYPTO_RsaPublicKey *key) | |||
1181 | } | 1043 | } |
1182 | 1044 | ||
1183 | 1045 | ||
1184 | /** | ||
1185 | * Unblind a blind-signed signature. The signature should have been generated | ||
1186 | * with #GNUNET_CRYPTO_rsa_sign() using a hash that was blinded with | ||
1187 | * #GNUNET_CRYPTO_rsa_blind(). | ||
1188 | * | ||
1189 | * @param sig the signature made on the blinded signature purpose | ||
1190 | * @param bks the blinding key secret used to blind the signature purpose | ||
1191 | * @param pkey the public key of the signer | ||
1192 | * @return unblinded signature on success, NULL if RSA key is bad or malicious. | ||
1193 | */ | ||
1194 | struct GNUNET_CRYPTO_RsaSignature * | 1046 | struct GNUNET_CRYPTO_RsaSignature * |
1195 | GNUNET_CRYPTO_rsa_unblind (const struct GNUNET_CRYPTO_RsaSignature *sig, | 1047 | GNUNET_CRYPTO_rsa_unblind (const struct GNUNET_CRYPTO_RsaSignature *sig, |
1196 | const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks, | 1048 | const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks, |
@@ -1272,16 +1124,7 @@ GNUNET_CRYPTO_rsa_unblind (const struct GNUNET_CRYPTO_RsaSignature *sig, | |||
1272 | } | 1124 | } |
1273 | 1125 | ||
1274 | 1126 | ||
1275 | /** | 1127 | enum GNUNET_GenericReturnValue |
1276 | * Verify whether the given hash corresponds to the given signature and | ||
1277 | * the signature is valid with respect to the given public key. | ||
1278 | * | ||
1279 | * @param hash hash of the message to verify to match the @a sig | ||
1280 | * @param sig signature that is being validated | ||
1281 | * @param pkey public key of the signer | ||
1282 | * @returns #GNUNET_YES if ok, #GNUNET_NO if RSA key is malicious, #GNUNET_SYSERR if signature is invalid | ||
1283 | */ | ||
1284 | int | ||
1285 | GNUNET_CRYPTO_rsa_verify (const struct GNUNET_HashCode *hash, | 1128 | GNUNET_CRYPTO_rsa_verify (const struct GNUNET_HashCode *hash, |
1286 | const struct GNUNET_CRYPTO_RsaSignature *sig, | 1129 | const struct GNUNET_CRYPTO_RsaSignature *sig, |
1287 | const struct GNUNET_CRYPTO_RsaPublicKey *pkey) | 1130 | const struct GNUNET_CRYPTO_RsaPublicKey *pkey) |
@@ -1319,23 +1162,17 @@ GNUNET_CRYPTO_rsa_verify (const struct GNUNET_HashCode *hash, | |||
1319 | __FILE__, | 1162 | __FILE__, |
1320 | __LINE__, | 1163 | __LINE__, |
1321 | gcry_strerror (rc)); | 1164 | gcry_strerror (rc)); |
1322 | return GNUNET_SYSERR; | ||
1323 | BENCHMARK_END (rsa_verify); | 1165 | BENCHMARK_END (rsa_verify); |
1166 | return GNUNET_SYSERR; | ||
1324 | } | 1167 | } |
1325 | BENCHMARK_END (rsa_verify); | 1168 | BENCHMARK_END (rsa_verify); |
1326 | return GNUNET_OK; | 1169 | return GNUNET_OK; |
1327 | } | 1170 | } |
1328 | 1171 | ||
1329 | 1172 | ||
1330 | /** | ||
1331 | * Duplicate the given private key | ||
1332 | * | ||
1333 | * @param key the private key to duplicate | ||
1334 | * @return the duplicate key; NULL upon error | ||
1335 | */ | ||
1336 | struct GNUNET_CRYPTO_RsaPrivateKey * | 1173 | struct GNUNET_CRYPTO_RsaPrivateKey * |
1337 | GNUNET_CRYPTO_rsa_private_key_dup (const struct | 1174 | GNUNET_CRYPTO_rsa_private_key_dup ( |
1338 | GNUNET_CRYPTO_RsaPrivateKey *key) | 1175 | const struct GNUNET_CRYPTO_RsaPrivateKey *key) |
1339 | { | 1176 | { |
1340 | struct GNUNET_CRYPTO_RsaPrivateKey *dup; | 1177 | struct GNUNET_CRYPTO_RsaPrivateKey *dup; |
1341 | gcry_sexp_t dup_sexp; | 1178 | gcry_sexp_t dup_sexp; |
@@ -1353,12 +1190,6 @@ GNUNET_CRYPTO_rsa_private_key_dup (const struct | |||
1353 | } | 1190 | } |
1354 | 1191 | ||
1355 | 1192 | ||
1356 | /** | ||
1357 | * Duplicate the given private key | ||
1358 | * | ||
1359 | * @param key the private key to duplicate | ||
1360 | * @return the duplicate key; NULL upon error | ||
1361 | */ | ||
1362 | struct GNUNET_CRYPTO_RsaSignature * | 1193 | struct GNUNET_CRYPTO_RsaSignature * |
1363 | GNUNET_CRYPTO_rsa_signature_dup (const struct GNUNET_CRYPTO_RsaSignature *sig) | 1194 | GNUNET_CRYPTO_rsa_signature_dup (const struct GNUNET_CRYPTO_RsaSignature *sig) |
1364 | { | 1195 | { |
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 | |||
92 | int include_sym_links; | 92 | int include_sym_links; |
93 | 93 | ||
94 | /** | 94 | /** |
95 | * GNUNET_YES if mode is file-only (return total == -1 for directories). | 95 | * #GNUNET_YES if mode is file-only (return total == -1 for directories). |
96 | */ | 96 | */ |
97 | int single_file_mode; | 97 | int single_file_mode; |
98 | }; | 98 | }; |
@@ -142,8 +142,8 @@ translate_unix_perms (enum GNUNET_DISK_AccessPermissions perm) | |||
142 | * @param fn current filename we are looking at | 142 | * @param fn current filename we are looking at |
143 | * @return #GNUNET_SYSERR on serious errors, otherwise #GNUNET_OK | 143 | * @return #GNUNET_SYSERR on serious errors, otherwise #GNUNET_OK |
144 | */ | 144 | */ |
145 | static int | 145 | static enum GNUNET_GenericReturnValue |
146 | getSizeRec (void *cls, const char *fn) | 146 | get_size_rec (void *cls, const char *fn) |
147 | { | 147 | { |
148 | struct GetFileSizeData *gfsd = cls; | 148 | struct GetFileSizeData *gfsd = cls; |
149 | 149 | ||
@@ -175,35 +175,23 @@ getSizeRec (void *cls, const char *fn) | |||
175 | if ((S_ISDIR (buf.st_mode)) && (0 == access (fn, X_OK)) && | 175 | if ((S_ISDIR (buf.st_mode)) && (0 == access (fn, X_OK)) && |
176 | ((! S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES))) | 176 | ((! S_ISLNK (buf.st_mode)) || (gfsd->include_sym_links == GNUNET_YES))) |
177 | { | 177 | { |
178 | if (GNUNET_SYSERR == GNUNET_DISK_directory_scan (fn, &getSizeRec, gfsd)) | 178 | if (GNUNET_SYSERR == GNUNET_DISK_directory_scan (fn, &get_size_rec, gfsd)) |
179 | return GNUNET_SYSERR; | 179 | return GNUNET_SYSERR; |
180 | } | 180 | } |
181 | return GNUNET_OK; | 181 | return GNUNET_OK; |
182 | } | 182 | } |
183 | 183 | ||
184 | 184 | ||
185 | /** | 185 | enum GNUNET_GenericReturnValue |
186 | * Checks whether a handle is invalid | ||
187 | * | ||
188 | * @param h handle to check | ||
189 | * @return #GNUNET_YES if invalid, #GNUNET_NO if valid | ||
190 | */ | ||
191 | int | ||
192 | GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h) | 186 | GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h) |
193 | { | 187 | { |
194 | return ((! h) || (h->fd == -1)) ? GNUNET_YES : GNUNET_NO; | 188 | return ((! h) || (h->fd == -1)) ? GNUNET_YES : GNUNET_NO; |
195 | } | 189 | } |
196 | 190 | ||
197 | 191 | ||
198 | /** | 192 | enum GNUNET_GenericReturnValue |
199 | * Get the size of an open file. | 193 | GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh, |
200 | * | 194 | off_t *size) |
201 | * @param fh open file handle | ||
202 | * @param size where to write size of the file | ||
203 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
204 | */ | ||
205 | int | ||
206 | GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh, off_t *size) | ||
207 | { | 195 | { |
208 | struct stat sbuf; | 196 | struct stat sbuf; |
209 | 197 | ||
@@ -214,80 +202,42 @@ GNUNET_DISK_file_handle_size (struct GNUNET_DISK_FileHandle *fh, off_t *size) | |||
214 | } | 202 | } |
215 | 203 | ||
216 | 204 | ||
217 | /** | ||
218 | * Move the read/write pointer in a file | ||
219 | * | ||
220 | * @param h handle of an open file | ||
221 | * @param offset position to move to | ||
222 | * @param whence specification to which position the offset parameter relates to | ||
223 | * @return the new position on success, #GNUNET_SYSERR otherwise | ||
224 | */ | ||
225 | off_t | 205 | off_t |
226 | GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, | 206 | GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, |
227 | off_t offset, | 207 | off_t offset, |
228 | enum GNUNET_DISK_Seek whence) | 208 | enum GNUNET_DISK_Seek whence) |
229 | { | 209 | { |
210 | static int t[] = { SEEK_SET, SEEK_CUR, SEEK_END }; | ||
211 | |||
230 | if (h == NULL) | 212 | if (h == NULL) |
231 | { | 213 | { |
232 | errno = EINVAL; | 214 | errno = EINVAL; |
233 | return GNUNET_SYSERR; | 215 | return GNUNET_SYSERR; |
234 | } | 216 | } |
235 | |||
236 | static int t[] = { SEEK_SET, SEEK_CUR, SEEK_END }; | ||
237 | |||
238 | return lseek (h->fd, offset, t[whence]); | 217 | return lseek (h->fd, offset, t[whence]); |
239 | } | 218 | } |
240 | 219 | ||
241 | 220 | ||
242 | /** | 221 | enum GNUNET_GenericReturnValue |
243 | * Get the size of the file (or directory) of the given file (in | ||
244 | * bytes). | ||
245 | * | ||
246 | * @param filename name of the file or directory | ||
247 | * @param size set to the size of the file (or, | ||
248 | * in the case of directories, the sum | ||
249 | * of all sizes of files in the directory) | ||
250 | * @param include_symbolic_links should symbolic links be | ||
251 | * included? | ||
252 | * @param single_file_mode #GNUNET_YES to only get size of one file | ||
253 | * and return #GNUNET_SYSERR for directories. | ||
254 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success | ||
255 | */ | ||
256 | int | ||
257 | GNUNET_DISK_file_size (const char *filename, | 222 | GNUNET_DISK_file_size (const char *filename, |
258 | uint64_t *size, | 223 | uint64_t *size, |
259 | int include_symbolic_links, | 224 | int include_symbolic_links, |
260 | int single_file_mode) | 225 | int single_file_mode) |
261 | { | 226 | { |
262 | struct GetFileSizeData gfsd; | 227 | struct GetFileSizeData gfsd; |
263 | int ret; | 228 | enum GNUNET_GenericReturnValue ret; |
264 | 229 | ||
265 | GNUNET_assert (size != NULL); | 230 | GNUNET_assert (size != NULL); |
266 | gfsd.total = 0; | 231 | gfsd.total = 0; |
267 | gfsd.include_sym_links = include_symbolic_links; | 232 | gfsd.include_sym_links = include_symbolic_links; |
268 | gfsd.single_file_mode = single_file_mode; | 233 | gfsd.single_file_mode = single_file_mode; |
269 | ret = getSizeRec (&gfsd, filename); | 234 | ret = get_size_rec (&gfsd, filename); |
270 | *size = gfsd.total; | 235 | *size = gfsd.total; |
271 | return ret; | 236 | return ret; |
272 | } | 237 | } |
273 | 238 | ||
274 | 239 | ||
275 | /** | 240 | enum GNUNET_GenericReturnValue |
276 | * Obtain some unique identifiers for the given file | ||
277 | * that can be used to identify it in the local system. | ||
278 | * This function is used between GNUnet processes to | ||
279 | * quickly check if two files with the same absolute path | ||
280 | * are actually identical. The two processes represent | ||
281 | * the same peer but may communicate over the network | ||
282 | * (and the file may be on an NFS volume). This function | ||
283 | * may not be supported on all operating systems. | ||
284 | * | ||
285 | * @param filename name of the file | ||
286 | * @param dev set to the device ID | ||
287 | * @param ino set to the inode ID | ||
288 | * @return #GNUNET_OK on success | ||
289 | */ | ||
290 | int | ||
291 | GNUNET_DISK_file_get_identifiers (const char *filename, | 241 | GNUNET_DISK_file_get_identifiers (const char *filename, |
292 | uint64_t *dev, | 242 | uint64_t *dev, |
293 | uint64_t *ino) | 243 | uint64_t *ino) |
@@ -367,14 +317,6 @@ mktemp_name (const char *t) | |||
367 | } | 317 | } |
368 | 318 | ||
369 | 319 | ||
370 | /** | ||
371 | * Update POSIX permissions mask of a file on disk. If both argumets | ||
372 | * are #GNUNET_NO, the file is made world-read-write-executable (777). | ||
373 | * | ||
374 | * @param fn name of the file to update | ||
375 | * @param require_uid_match #GNUNET_YES means 700 | ||
376 | * @param require_gid_match #GNUNET_YES means 770 unless @a require_uid_match is set | ||
377 | */ | ||
378 | void | 320 | void |
379 | GNUNET_DISK_fix_permissions (const char *fn, | 321 | GNUNET_DISK_fix_permissions (const char *fn, |
380 | int require_uid_match, | 322 | int require_uid_match, |
@@ -394,17 +336,6 @@ GNUNET_DISK_fix_permissions (const char *fn, | |||
394 | } | 336 | } |
395 | 337 | ||
396 | 338 | ||
397 | /** | ||
398 | * Create an (empty) temporary directory on disk. If the given name is not | ||
399 | * an absolute path, the current 'TMPDIR' will be prepended. In any case, | ||
400 | * 6 random characters will be appended to the name to create a unique | ||
401 | * filename. | ||
402 | * | ||
403 | * @param t component to use for the name; | ||
404 | * does NOT contain "XXXXXX" or "/tmp/". | ||
405 | * @return NULL on error, otherwise name of fresh | ||
406 | * file on disk in directory for temporary files | ||
407 | */ | ||
408 | char * | 339 | char * |
409 | GNUNET_DISK_mkdtemp (const char *t) | 340 | GNUNET_DISK_mkdtemp (const char *t) |
410 | { | 341 | { |
@@ -425,13 +356,6 @@ GNUNET_DISK_mkdtemp (const char *t) | |||
425 | } | 356 | } |
426 | 357 | ||
427 | 358 | ||
428 | /** | ||
429 | * Move a file out of the way (create a backup) by | ||
430 | * renaming it to "orig.NUM~" where NUM is the smallest | ||
431 | * number that is not used yet. | ||
432 | * | ||
433 | * @param fil name of the file to back up | ||
434 | */ | ||
435 | void | 359 | void |
436 | GNUNET_DISK_file_backup (const char *fil) | 360 | GNUNET_DISK_file_backup (const char *fil) |
437 | { | 361 | { |
@@ -453,17 +377,6 @@ GNUNET_DISK_file_backup (const char *fil) | |||
453 | } | 377 | } |
454 | 378 | ||
455 | 379 | ||
456 | /** | ||
457 | * Create an (empty) temporary file on disk. If the given name is not | ||
458 | * an absolute path, the current 'TMPDIR' will be prepended. In any case, | ||
459 | * 6 random characters will be appended to the name to create a unique | ||
460 | * filename. | ||
461 | * | ||
462 | * @param t component to use for the name; | ||
463 | * does NOT contain "XXXXXX" or "/tmp/". | ||
464 | * @return NULL on error, otherwise name of fresh | ||
465 | * file on disk in directory for temporary files | ||
466 | */ | ||
467 | char * | 380 | char * |
468 | GNUNET_DISK_mktemp (const char *t) | 381 | GNUNET_DISK_mktemp (const char *t) |
469 | { | 382 | { |
@@ -487,19 +400,7 @@ GNUNET_DISK_mktemp (const char *t) | |||
487 | } | 400 | } |
488 | 401 | ||
489 | 402 | ||
490 | /** | 403 | enum GNUNET_GenericReturnValue |
491 | * Test if @a fil is a directory and listable. Optionally, also check if the | ||
492 | * directory is readable. Will not print an error message if the directory does | ||
493 | * not exist. Will log errors if #GNUNET_SYSERR is returned (i.e., a file exists | ||
494 | * with the same name). | ||
495 | * | ||
496 | * @param fil filename to test | ||
497 | * @param is_readable #GNUNET_YES to additionally check if @a fil is readable; | ||
498 | * #GNUNET_NO to disable this check | ||
499 | * @return #GNUNET_YES if yes, #GNUNET_NO if not; #GNUNET_SYSERR if it | ||
500 | * does not exist or stat'ed | ||
501 | */ | ||
502 | int | ||
503 | GNUNET_DISK_directory_test (const char *fil, int is_readable) | 404 | GNUNET_DISK_directory_test (const char *fil, int is_readable) |
504 | { | 405 | { |
505 | struct stat filestat; | 406 | struct stat filestat; |
@@ -532,15 +433,7 @@ GNUNET_DISK_directory_test (const char *fil, int is_readable) | |||
532 | } | 433 | } |
533 | 434 | ||
534 | 435 | ||
535 | /** | 436 | enum GNUNET_GenericReturnValue |
536 | * Check that fil corresponds to a filename | ||
537 | * (of a file that exists and that is not a directory). | ||
538 | * | ||
539 | * @param fil filename to check | ||
540 | * @return #GNUNET_YES if yes, #GNUNET_NO if not a file, #GNUNET_SYSERR if something | ||
541 | * else (will print an error message in that case, too). | ||
542 | */ | ||
543 | int | ||
544 | GNUNET_DISK_file_test (const char *fil) | 437 | GNUNET_DISK_file_test (const char *fil) |
545 | { | 438 | { |
546 | struct stat filestat; | 439 | struct stat filestat; |
@@ -552,7 +445,7 @@ GNUNET_DISK_file_test (const char *fil) | |||
552 | return GNUNET_SYSERR; | 445 | return GNUNET_SYSERR; |
553 | 446 | ||
554 | ret = stat (rdir, &filestat); | 447 | ret = stat (rdir, &filestat); |
555 | if (ret != 0) | 448 | if (0 != ret) |
556 | { | 449 | { |
557 | if (errno != ENOENT) | 450 | if (errno != ENOENT) |
558 | { | 451 | { |
@@ -579,13 +472,7 @@ GNUNET_DISK_file_test (const char *fil) | |||
579 | } | 472 | } |
580 | 473 | ||
581 | 474 | ||
582 | /** | 475 | enum GNUNET_GenericReturnValue |
583 | * Implementation of "mkdir -p" | ||
584 | * | ||
585 | * @param dir the directory to create | ||
586 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | ||
587 | */ | ||
588 | int | ||
589 | GNUNET_DISK_directory_create (const char *dir) | 476 | GNUNET_DISK_directory_create (const char *dir) |
590 | { | 477 | { |
591 | char *rdir; | 478 | char *rdir; |
@@ -671,22 +558,13 @@ GNUNET_DISK_directory_create (const char *dir) | |||
671 | } | 558 | } |
672 | 559 | ||
673 | 560 | ||
674 | /** | 561 | enum GNUNET_GenericReturnValue |
675 | * Create the directory structure for storing a file. | ||
676 | * | ||
677 | * @param filename name of a file in the directory | ||
678 | * @returns #GNUNET_OK on success, | ||
679 | * #GNUNET_SYSERR on failure, | ||
680 | * #GNUNET_NO if the directory | ||
681 | * exists but is not writeable for us | ||
682 | */ | ||
683 | int | ||
684 | GNUNET_DISK_directory_create_for_file (const char *filename) | 562 | GNUNET_DISK_directory_create_for_file (const char *filename) |
685 | { | 563 | { |
686 | char *rdir; | 564 | char *rdir; |
687 | size_t len; | 565 | size_t len; |
688 | int ret; | ||
689 | int eno; | 566 | int eno; |
567 | enum GNUNET_GenericReturnValue res; | ||
690 | 568 | ||
691 | rdir = GNUNET_STRINGS_filename_expand (filename); | 569 | rdir = GNUNET_STRINGS_filename_expand (filename); |
692 | if (NULL == rdir) | 570 | if (NULL == rdir) |
@@ -699,7 +577,6 @@ GNUNET_DISK_directory_create_for_file (const char *filename) | |||
699 | GNUNET_free (rdir); | 577 | GNUNET_free (rdir); |
700 | return GNUNET_OK; | 578 | return GNUNET_OK; |
701 | } | 579 | } |
702 | |||
703 | len = strlen (rdir); | 580 | len = strlen (rdir); |
704 | while ((len > 0) && (rdir[len] != DIR_SEPARATOR)) | 581 | while ((len > 0) && (rdir[len] != DIR_SEPARATOR)) |
705 | len--; | 582 | len--; |
@@ -710,24 +587,17 @@ GNUNET_DISK_directory_create_for_file (const char *filename) | |||
710 | GNUNET_free (rdir); | 587 | GNUNET_free (rdir); |
711 | rdir = GNUNET_strdup ("/"); | 588 | rdir = GNUNET_strdup ("/"); |
712 | } | 589 | } |
713 | ret = GNUNET_DISK_directory_create (rdir); | 590 | res = GNUNET_DISK_directory_create (rdir); |
714 | if ((GNUNET_OK == ret) && (0 != access (rdir, W_OK))) | 591 | if ( (GNUNET_OK == res) && |
715 | ret = GNUNET_NO; | 592 | (0 != access (rdir, W_OK)) ) |
593 | res = GNUNET_NO; | ||
716 | eno = errno; | 594 | eno = errno; |
717 | GNUNET_free (rdir); | 595 | GNUNET_free (rdir); |
718 | errno = eno; | 596 | errno = eno; |
719 | return ret; | 597 | return res; |
720 | } | 598 | } |
721 | 599 | ||
722 | 600 | ||
723 | /** | ||
724 | * Read the contents of a binary file into a buffer. | ||
725 | * | ||
726 | * @param h handle to an open file | ||
727 | * @param result the buffer to write the result to | ||
728 | * @param len the maximum number of bytes to read | ||
729 | * @return the number of bytes read on success, #GNUNET_SYSERR on failure | ||
730 | */ | ||
731 | ssize_t | 601 | ssize_t |
732 | GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h, | 602 | GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h, |
733 | void *result, | 603 | void *result, |
@@ -738,35 +608,23 @@ GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h, | |||
738 | errno = EINVAL; | 608 | errno = EINVAL; |
739 | return GNUNET_SYSERR; | 609 | return GNUNET_SYSERR; |
740 | } | 610 | } |
741 | |||
742 | return read (h->fd, result, len); | 611 | return read (h->fd, result, len); |
743 | } | 612 | } |
744 | 613 | ||
745 | 614 | ||
746 | /** | ||
747 | * Read the contents of a binary file into a buffer. | ||
748 | * Guarantees not to block (returns GNUNET_SYSERR and sets errno to EAGAIN | ||
749 | * when no data can be read). | ||
750 | * | ||
751 | * @param h handle to an open file | ||
752 | * @param result the buffer to write the result to | ||
753 | * @param len the maximum number of bytes to read | ||
754 | * @return the number of bytes read on success, #GNUNET_SYSERR on failure | ||
755 | */ | ||
756 | ssize_t | 615 | ssize_t |
757 | GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle *h, | 616 | GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle *h, |
758 | void *result, | 617 | void *result, |
759 | size_t len) | 618 | size_t len) |
760 | { | 619 | { |
620 | int flags; | ||
621 | ssize_t ret; | ||
622 | |||
761 | if (NULL == h) | 623 | if (NULL == h) |
762 | { | 624 | { |
763 | errno = EINVAL; | 625 | errno = EINVAL; |
764 | return GNUNET_SYSERR; | 626 | return GNUNET_SYSERR; |
765 | } | 627 | } |
766 | |||
767 | int flags; | ||
768 | ssize_t ret; | ||
769 | |||
770 | /* set to non-blocking, read, then set back */ | 628 | /* set to non-blocking, read, then set back */ |
771 | flags = fcntl (h->fd, F_GETFL); | 629 | flags = fcntl (h->fd, F_GETFL); |
772 | if (0 == (flags & O_NONBLOCK)) | 630 | if (0 == (flags & O_NONBLOCK)) |
@@ -782,22 +640,18 @@ GNUNET_DISK_file_read_non_blocking (const struct GNUNET_DISK_FileHandle *h, | |||
782 | } | 640 | } |
783 | 641 | ||
784 | 642 | ||
785 | /** | ||
786 | * Read the contents of a binary file into a buffer. | ||
787 | * | ||
788 | * @param fn file name | ||
789 | * @param result the buffer to write the result to | ||
790 | * @param len the maximum number of bytes to read | ||
791 | * @return number of bytes read, #GNUNET_SYSERR on failure | ||
792 | */ | ||
793 | ssize_t | 643 | ssize_t |
794 | GNUNET_DISK_fn_read (const char *fn, void *result, size_t len) | 644 | GNUNET_DISK_fn_read (const char *fn, |
645 | void *result, | ||
646 | size_t len) | ||
795 | { | 647 | { |
796 | struct GNUNET_DISK_FileHandle *fh; | 648 | struct GNUNET_DISK_FileHandle *fh; |
797 | ssize_t ret; | 649 | ssize_t ret; |
798 | int eno; | 650 | int eno; |
799 | 651 | ||
800 | fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_NONE); | 652 | fh = GNUNET_DISK_file_open (fn, |
653 | GNUNET_DISK_OPEN_READ, | ||
654 | GNUNET_DISK_PERM_NONE); | ||
801 | if (NULL == fh) | 655 | if (NULL == fh) |
802 | return GNUNET_SYSERR; | 656 | return GNUNET_SYSERR; |
803 | ret = GNUNET_DISK_file_read (fh, result, len); | 657 | ret = GNUNET_DISK_file_read (fh, result, len); |
@@ -808,14 +662,6 @@ GNUNET_DISK_fn_read (const char *fn, void *result, size_t len) | |||
808 | } | 662 | } |
809 | 663 | ||
810 | 664 | ||
811 | /** | ||
812 | * Write a buffer to a file. | ||
813 | * | ||
814 | * @param h handle to open file | ||
815 | * @param buffer the data to write | ||
816 | * @param n number of bytes to write | ||
817 | * @return number of bytes written on success, #GNUNET_SYSERR on error | ||
818 | */ | ||
819 | ssize_t | 665 | ssize_t |
820 | GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h, | 666 | GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h, |
821 | const void *buffer, | 667 | const void *buffer, |
@@ -831,29 +677,19 @@ GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h, | |||
831 | } | 677 | } |
832 | 678 | ||
833 | 679 | ||
834 | /** | ||
835 | * Write a buffer to a file, blocking, if necessary. | ||
836 | * | ||
837 | * @param h handle to open file | ||
838 | * @param buffer the data to write | ||
839 | * @param n number of bytes to write | ||
840 | * @return number of bytes written on success, #GNUNET_SYSERR on error | ||
841 | */ | ||
842 | ssize_t | 680 | ssize_t |
843 | GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle *h, | 681 | GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle *h, |
844 | const void *buffer, | 682 | const void *buffer, |
845 | size_t n) | 683 | size_t n) |
846 | { | 684 | { |
685 | int flags; | ||
686 | ssize_t ret; | ||
687 | |||
847 | if (NULL == h) | 688 | if (NULL == h) |
848 | { | 689 | { |
849 | errno = EINVAL; | 690 | errno = EINVAL; |
850 | return GNUNET_SYSERR; | 691 | return GNUNET_SYSERR; |
851 | } | 692 | } |
852 | |||
853 | |||
854 | int flags; | ||
855 | ssize_t ret; | ||
856 | |||
857 | /* set to blocking, write, then set back */ | 693 | /* set to blocking, write, then set back */ |
858 | flags = fcntl (h->fd, F_GETFL); | 694 | flags = fcntl (h->fd, F_GETFL); |
859 | if (0 != (flags & O_NONBLOCK)) | 695 | if (0 != (flags & O_NONBLOCK)) |
@@ -865,48 +701,95 @@ GNUNET_DISK_file_write_blocking (const struct GNUNET_DISK_FileHandle *h, | |||
865 | } | 701 | } |
866 | 702 | ||
867 | 703 | ||
868 | /** | 704 | enum GNUNET_GenericReturnValue |
869 | * Write a buffer to a file. If the file is longer than the | ||
870 | * number of bytes that will be written, it will be truncated. | ||
871 | * | ||
872 | * @param fn file name | ||
873 | * @param buffer the data to write | ||
874 | * @param n number of bytes to write | ||
875 | * @param mode file permissions | ||
876 | * @return number of bytes written on success, #GNUNET_SYSERR on error | ||
877 | */ | ||
878 | ssize_t | ||
879 | GNUNET_DISK_fn_write (const char *fn, | 705 | GNUNET_DISK_fn_write (const char *fn, |
880 | const void *buffer, | 706 | const void *buf, |
881 | size_t n, | 707 | size_t buf_size, |
882 | enum GNUNET_DISK_AccessPermissions mode) | 708 | enum GNUNET_DISK_AccessPermissions mode) |
883 | { | 709 | { |
884 | struct GNUNET_DISK_FileHandle *fh; | 710 | char *tmpl; |
885 | ssize_t ret; | 711 | int fd; |
886 | 712 | ||
887 | fh = | 713 | if (GNUNET_OK != |
888 | GNUNET_DISK_file_open (fn, | 714 | GNUNET_DISK_directory_create_for_file (fn)) |
889 | GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE | 715 | { |
890 | | GNUNET_DISK_OPEN_CREATE, | 716 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
891 | mode); | 717 | "mkstemp", |
892 | if (! fh) | 718 | fn); |
893 | return GNUNET_SYSERR; | 719 | return GNUNET_SYSERR; |
894 | ret = GNUNET_DISK_file_write (fh, buffer, n); | 720 | } |
895 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); | 721 | { |
896 | return ret; | 722 | char *dname; |
723 | |||
724 | dname = GNUNET_strdup (fn); | ||
725 | GNUNET_asprintf (&tmpl, | ||
726 | "%s/XXXXXX", | ||
727 | dirname (dname)); | ||
728 | GNUNET_free (dname); | ||
729 | } | ||
730 | fd = mkstemp (tmpl); | ||
731 | if (-1 == fd) | ||
732 | { | ||
733 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
734 | "mkstemp", | ||
735 | tmpl); | ||
736 | GNUNET_free (tmpl); | ||
737 | return GNUNET_SYSERR; | ||
738 | } | ||
739 | |||
740 | if (0 != fchmod (fd, | ||
741 | translate_unix_perms (mode))) | ||
742 | { | ||
743 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
744 | "chmod", | ||
745 | tmpl); | ||
746 | GNUNET_assert (0 == close (fd)); | ||
747 | if (0 != unlink (tmpl)) | ||
748 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | ||
749 | "unlink", | ||
750 | tmpl); | ||
751 | GNUNET_free (tmpl); | ||
752 | return GNUNET_SYSERR; | ||
753 | } | ||
754 | if (buf_size != | ||
755 | write (fd, | ||
756 | buf, | ||
757 | buf_size)) | ||
758 | { | ||
759 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
760 | "write", | ||
761 | tmpl); | ||
762 | GNUNET_assert (0 == close (fd)); | ||
763 | if (0 != unlink (tmpl)) | ||
764 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | ||
765 | "unlink", | ||
766 | tmpl); | ||
767 | GNUNET_free (tmpl); | ||
768 | return GNUNET_SYSERR; | ||
769 | } | ||
770 | GNUNET_assert (0 == close (fd)); | ||
771 | |||
772 | if (0 != link (tmpl, | ||
773 | fn)) | ||
774 | { | ||
775 | if (0 != unlink (tmpl)) | ||
776 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | ||
777 | "unlink", | ||
778 | tmpl); | ||
779 | GNUNET_free (tmpl); | ||
780 | return GNUNET_NO; | ||
781 | } | ||
782 | if (0 != unlink (tmpl)) | ||
783 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | ||
784 | "unlink", | ||
785 | tmpl); | ||
786 | GNUNET_free (tmpl); | ||
787 | return GNUNET_OK; | ||
788 | |||
789 | |||
897 | } | 790 | } |
898 | 791 | ||
899 | 792 | ||
900 | /** | ||
901 | * Scan a directory for files. | ||
902 | * | ||
903 | * @param dir_name the name of the directory | ||
904 | * @param callback the method to call for each file, | ||
905 | * can be NULL, in that case, we only count | ||
906 | * @param callback_cls closure for @a callback | ||
907 | * @return the number of files found, #GNUNET_SYSERR on error or | ||
908 | * ieration aborted by callback returning #GNUNET_SYSERR | ||
909 | */ | ||
910 | int | 793 | int |
911 | GNUNET_DISK_directory_scan (const char *dir_name, | 794 | GNUNET_DISK_directory_scan (const char *dir_name, |
912 | GNUNET_FileNameCallback callback, | 795 | GNUNET_FileNameCallback callback, |
@@ -916,7 +799,7 @@ GNUNET_DISK_directory_scan (const char *dir_name, | |||
916 | struct dirent *finfo; | 799 | struct dirent *finfo; |
917 | struct stat istat; | 800 | struct stat istat; |
918 | int count = 0; | 801 | int count = 0; |
919 | int ret; | 802 | enum GNUNET_GenericReturnValue ret; |
920 | char *name; | 803 | char *name; |
921 | char *dname; | 804 | char *dname; |
922 | unsigned int name_len; | 805 | unsigned int name_len; |
@@ -1008,8 +891,9 @@ GNUNET_DISK_directory_scan (const char *dir_name, | |||
1008 | * @param fn directory to remove | 891 | * @param fn directory to remove |
1009 | * @return #GNUNET_OK | 892 | * @return #GNUNET_OK |
1010 | */ | 893 | */ |
1011 | static int | 894 | static enum GNUNET_GenericReturnValue |
1012 | remove_helper (void *unused, const char *fn) | 895 | remove_helper (void *unused, |
896 | const char *fn) | ||
1013 | { | 897 | { |
1014 | (void) unused; | 898 | (void) unused; |
1015 | (void) GNUNET_DISK_directory_remove (fn); | 899 | (void) GNUNET_DISK_directory_remove (fn); |
@@ -1017,14 +901,7 @@ remove_helper (void *unused, const char *fn) | |||
1017 | } | 901 | } |
1018 | 902 | ||
1019 | 903 | ||
1020 | /** | 904 | enum GNUNET_GenericReturnValue |
1021 | * Remove all files in a directory (rm -r). Call with | ||
1022 | * caution. | ||
1023 | * | ||
1024 | * @param filename the file to remove | ||
1025 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
1026 | */ | ||
1027 | int | ||
1028 | GNUNET_DISK_directory_remove (const char *filename) | 905 | GNUNET_DISK_directory_remove (const char *filename) |
1029 | { | 906 | { |
1030 | struct stat istat; | 907 | struct stat istat; |
@@ -1036,14 +913,17 @@ GNUNET_DISK_directory_remove (const char *filename) | |||
1036 | } | 913 | } |
1037 | if (0 != lstat (filename, &istat)) | 914 | if (0 != lstat (filename, &istat)) |
1038 | return GNUNET_NO; /* file may not exist... */ | 915 | return GNUNET_NO; /* file may not exist... */ |
1039 | (void) chmod (filename, S_IWUSR | S_IRUSR | S_IXUSR); | 916 | (void) chmod (filename, |
917 | S_IWUSR | S_IRUSR | S_IXUSR); | ||
1040 | if (0 == unlink (filename)) | 918 | if (0 == unlink (filename)) |
1041 | return GNUNET_OK; | 919 | return GNUNET_OK; |
1042 | if ((errno != EISDIR) && | 920 | if ( (errno != EISDIR) && |
1043 | /* EISDIR is not sufficient in all cases, e.g. | 921 | /* EISDIR is not sufficient in all cases, e.g. |
1044 | * sticky /tmp directory may result in EPERM on BSD. | 922 | * sticky /tmp directory may result in EPERM on BSD. |
1045 | * So we also explicitly check "isDirectory" */ | 923 | * So we also explicitly check "isDirectory" */ |
1046 | (GNUNET_YES != GNUNET_DISK_directory_test (filename, GNUNET_YES))) | 924 | (GNUNET_YES != |
925 | GNUNET_DISK_directory_test (filename, | ||
926 | GNUNET_YES)) ) | ||
1047 | { | 927 | { |
1048 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "rmdir", filename); | 928 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "rmdir", filename); |
1049 | return GNUNET_SYSERR; | 929 | return GNUNET_SYSERR; |
@@ -1060,15 +940,9 @@ GNUNET_DISK_directory_remove (const char *filename) | |||
1060 | } | 940 | } |
1061 | 941 | ||
1062 | 942 | ||
1063 | /** | 943 | enum GNUNET_GenericReturnValue |
1064 | * Copy a file. | 944 | GNUNET_DISK_file_copy (const char *src, |
1065 | * | 945 | const char *dst) |
1066 | * @param src file to copy | ||
1067 | * @param dst destination file name | ||
1068 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
1069 | */ | ||
1070 | int | ||
1071 | GNUNET_DISK_file_copy (const char *src, const char *dst) | ||
1072 | { | 946 | { |
1073 | char *buf; | 947 | char *buf; |
1074 | uint64_t pos; | 948 | uint64_t pos; |
@@ -1131,10 +1005,6 @@ FAIL: | |||
1131 | } | 1005 | } |
1132 | 1006 | ||
1133 | 1007 | ||
1134 | /** | ||
1135 | * @brief Removes special characters as ':' from a filename. | ||
1136 | * @param fn the filename to canonicalize | ||
1137 | */ | ||
1138 | void | 1008 | void |
1139 | GNUNET_DISK_filename_canonicalize (char *fn) | 1009 | GNUNET_DISK_filename_canonicalize (char *fn) |
1140 | { | 1010 | { |
@@ -1157,15 +1027,9 @@ GNUNET_DISK_filename_canonicalize (char *fn) | |||
1157 | } | 1027 | } |
1158 | 1028 | ||
1159 | 1029 | ||
1160 | /** | 1030 | enum GNUNET_GenericReturnValue |
1161 | * @brief Change owner of a file | 1031 | GNUNET_DISK_file_change_owner (const char *filename, |
1162 | * | 1032 | const char *user) |
1163 | * @param filename name of file to change the owner of | ||
1164 | * @param user name of the new owner | ||
1165 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | ||
1166 | */ | ||
1167 | int | ||
1168 | GNUNET_DISK_file_change_owner (const char *filename, const char *user) | ||
1169 | { | 1033 | { |
1170 | struct passwd *pws; | 1034 | struct passwd *pws; |
1171 | 1035 | ||
@@ -1187,18 +1051,6 @@ GNUNET_DISK_file_change_owner (const char *filename, const char *user) | |||
1187 | } | 1051 | } |
1188 | 1052 | ||
1189 | 1053 | ||
1190 | /** | ||
1191 | * Open a file. Note that the access permissions will only be | ||
1192 | * used if a new file is created and if the underlying operating | ||
1193 | * system supports the given permissions. | ||
1194 | * | ||
1195 | * @param fn file name to be opened | ||
1196 | * @param flags opening flags, a combination of GNUNET_DISK_OPEN_xxx bit flags | ||
1197 | * @param perm permissions for the newly created file, use | ||
1198 | * #GNUNET_DISK_PERM_NONE if a file could not be created by this | ||
1199 | * call (because of flags) | ||
1200 | * @return IO handle on success, NULL on error | ||
1201 | */ | ||
1202 | struct GNUNET_DISK_FileHandle * | 1054 | struct GNUNET_DISK_FileHandle * |
1203 | GNUNET_DISK_file_open (const char *fn, | 1055 | GNUNET_DISK_file_open (const char *fn, |
1204 | enum GNUNET_DISK_OpenFlags flags, | 1056 | enum GNUNET_DISK_OpenFlags flags, |
@@ -1270,42 +1122,28 @@ GNUNET_DISK_file_open (const char *fn, | |||
1270 | } | 1122 | } |
1271 | 1123 | ||
1272 | 1124 | ||
1273 | /** | 1125 | enum GNUNET_GenericReturnValue |
1274 | * Close an open file. | ||
1275 | * | ||
1276 | * @param h file handle | ||
1277 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | ||
1278 | */ | ||
1279 | int | ||
1280 | GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h) | 1126 | GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h) |
1281 | { | 1127 | { |
1282 | int ret; | 1128 | enum GNUNET_GenericReturnValue ret; |
1283 | 1129 | ||
1284 | if (h == NULL) | 1130 | if (NULL == h) |
1285 | { | 1131 | { |
1286 | errno = EINVAL; | 1132 | errno = EINVAL; |
1287 | return GNUNET_SYSERR; | 1133 | return GNUNET_SYSERR; |
1288 | } | 1134 | } |
1289 | 1135 | ||
1290 | ret = GNUNET_OK; | 1136 | ret = GNUNET_OK; |
1291 | 1137 | if (0 != close (h->fd)) | |
1292 | if (close (h->fd) != 0) | ||
1293 | { | 1138 | { |
1294 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "close"); | 1139 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "close"); |
1295 | ret = GNUNET_SYSERR; | 1140 | ret = GNUNET_SYSERR; |
1296 | } | 1141 | } |
1297 | |||
1298 | GNUNET_free (h); | 1142 | GNUNET_free (h); |
1299 | return ret; | 1143 | return ret; |
1300 | } | 1144 | } |
1301 | 1145 | ||
1302 | 1146 | ||
1303 | /** | ||
1304 | * Get a handle from a native integer FD. | ||
1305 | * | ||
1306 | * @param fno native integer file descriptor | ||
1307 | * @return file handle corresponding to the descriptor, NULL on error | ||
1308 | */ | ||
1309 | struct GNUNET_DISK_FileHandle * | 1147 | struct GNUNET_DISK_FileHandle * |
1310 | GNUNET_DISK_get_handle_from_int_fd (int fno) | 1148 | GNUNET_DISK_get_handle_from_int_fd (int fno) |
1311 | { | 1149 | { |
@@ -1322,12 +1160,6 @@ GNUNET_DISK_get_handle_from_int_fd (int fno) | |||
1322 | } | 1160 | } |
1323 | 1161 | ||
1324 | 1162 | ||
1325 | /** | ||
1326 | * Get a handle from a native streaming FD. | ||
1327 | * | ||
1328 | * @param fd native streaming file descriptor | ||
1329 | * @return file handle corresponding to the descriptor | ||
1330 | */ | ||
1331 | struct GNUNET_DISK_FileHandle * | 1163 | struct GNUNET_DISK_FileHandle * |
1332 | GNUNET_DISK_get_handle_from_native (FILE *fd) | 1164 | GNUNET_DISK_get_handle_from_native (FILE *fd) |
1333 | { | 1165 | { |
@@ -1336,7 +1168,6 @@ GNUNET_DISK_get_handle_from_native (FILE *fd) | |||
1336 | fno = fileno (fd); | 1168 | fno = fileno (fd); |
1337 | if (-1 == fno) | 1169 | if (-1 == fno) |
1338 | return NULL; | 1170 | return NULL; |
1339 | |||
1340 | return GNUNET_DISK_get_handle_from_int_fd (fno); | 1171 | return GNUNET_DISK_get_handle_from_int_fd (fno); |
1341 | } | 1172 | } |
1342 | 1173 | ||
@@ -1362,15 +1193,7 @@ struct GNUNET_DISK_MapHandle | |||
1362 | #define MAP_FAILED ((void *) -1) | 1193 | #define MAP_FAILED ((void *) -1) |
1363 | #endif | 1194 | #endif |
1364 | 1195 | ||
1365 | /** | 1196 | |
1366 | * Map a file into memory | ||
1367 | * | ||
1368 | * @param h open file handle | ||
1369 | * @param m handle to the new mapping | ||
1370 | * @param access access specification, GNUNET_DISK_MAP_TYPE_xxx | ||
1371 | * @param len size of the mapping | ||
1372 | * @return pointer to the mapped memory region, NULL on failure | ||
1373 | */ | ||
1374 | void * | 1197 | void * |
1375 | GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h, | 1198 | GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h, |
1376 | struct GNUNET_DISK_MapHandle **m, | 1199 | struct GNUNET_DISK_MapHandle **m, |
@@ -1402,16 +1225,10 @@ GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h, | |||
1402 | } | 1225 | } |
1403 | 1226 | ||
1404 | 1227 | ||
1405 | /** | 1228 | enum GNUNET_GenericReturnValue |
1406 | * Unmap a file | ||
1407 | * | ||
1408 | * @param h mapping handle | ||
1409 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | ||
1410 | */ | ||
1411 | int | ||
1412 | GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h) | 1229 | GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h) |
1413 | { | 1230 | { |
1414 | int ret; | 1231 | enum GNUNET_GenericReturnValue ret; |
1415 | 1232 | ||
1416 | if (NULL == h) | 1233 | if (NULL == h) |
1417 | { | 1234 | { |
@@ -1424,12 +1241,7 @@ GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h) | |||
1424 | } | 1241 | } |
1425 | 1242 | ||
1426 | 1243 | ||
1427 | /** | 1244 | enum GNUNET_GenericReturnValue |
1428 | * Write file changes to disk | ||
1429 | * @param h handle to an open file | ||
1430 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | ||
1431 | */ | ||
1432 | int | ||
1433 | GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h) | 1245 | GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h) |
1434 | { | 1246 | { |
1435 | if (h == NULL) | 1247 | if (h == NULL) |
@@ -1446,12 +1258,6 @@ GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h) | |||
1446 | } | 1258 | } |
1447 | 1259 | ||
1448 | 1260 | ||
1449 | /** | ||
1450 | * Creates an interprocess channel | ||
1451 | * | ||
1452 | * @param pf how to configure the pipe | ||
1453 | * @return handle to the new pipe, NULL on error | ||
1454 | */ | ||
1455 | struct GNUNET_DISK_PipeHandle * | 1261 | struct GNUNET_DISK_PipeHandle * |
1456 | GNUNET_DISK_pipe (enum GNUNET_DISK_PipeFlags pf) | 1262 | GNUNET_DISK_pipe (enum GNUNET_DISK_PipeFlags pf) |
1457 | { | 1263 | { |
@@ -1469,15 +1275,6 @@ GNUNET_DISK_pipe (enum GNUNET_DISK_PipeFlags pf) | |||
1469 | } | 1275 | } |
1470 | 1276 | ||
1471 | 1277 | ||
1472 | /** | ||
1473 | * Creates a pipe object from a couple of file descriptors. | ||
1474 | * Useful for wrapping existing pipe FDs. | ||
1475 | * | ||
1476 | * @param pf how to configure the pipe | ||
1477 | * @param fd an array of two fd values. One of them may be -1 for read-only or write-only pipes | ||
1478 | * | ||
1479 | * @return handle to the new pipe, NULL on error | ||
1480 | */ | ||
1481 | struct GNUNET_DISK_PipeHandle * | 1278 | struct GNUNET_DISK_PipeHandle * |
1482 | GNUNET_DISK_pipe_from_fd (enum GNUNET_DISK_PipeFlags pf, | 1279 | GNUNET_DISK_pipe_from_fd (enum GNUNET_DISK_PipeFlags pf, |
1483 | int fd[2]) | 1280 | int fd[2]) |
@@ -1551,18 +1348,11 @@ GNUNET_DISK_pipe_from_fd (enum GNUNET_DISK_PipeFlags pf, | |||
1551 | } | 1348 | } |
1552 | 1349 | ||
1553 | 1350 | ||
1554 | /** | 1351 | enum GNUNET_GenericReturnValue |
1555 | * Closes an interprocess channel | ||
1556 | * | ||
1557 | * @param p pipe to close | ||
1558 | * @param end which end of the pipe to close | ||
1559 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | ||
1560 | */ | ||
1561 | int | ||
1562 | GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p, | 1352 | GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p, |
1563 | enum GNUNET_DISK_PipeEnd end) | 1353 | enum GNUNET_DISK_PipeEnd end) |
1564 | { | 1354 | { |
1565 | int ret = GNUNET_OK; | 1355 | enum GNUNET_GenericReturnValue ret = GNUNET_OK; |
1566 | 1356 | ||
1567 | if (end == GNUNET_DISK_PIPE_END_READ) | 1357 | if (end == GNUNET_DISK_PIPE_END_READ) |
1568 | { | 1358 | { |
@@ -1580,23 +1370,10 @@ GNUNET_DISK_pipe_close_end (struct GNUNET_DISK_PipeHandle *p, | |||
1580 | p->fd[1] = NULL; | 1370 | p->fd[1] = NULL; |
1581 | } | 1371 | } |
1582 | } | 1372 | } |
1583 | |||
1584 | return ret; | 1373 | return ret; |
1585 | } | 1374 | } |
1586 | 1375 | ||
1587 | 1376 | ||
1588 | /** | ||
1589 | * Detaches one of the ends from the pipe. | ||
1590 | * Detached end is a fully-functional FileHandle, it will | ||
1591 | * not be affected by anything you do with the pipe afterwards. | ||
1592 | * Each end of a pipe can only be detched from it once (i.e. | ||
1593 | * it is not duplicated). | ||
1594 | * | ||
1595 | * @param p pipe to detach an end from | ||
1596 | * @param end which end of the pipe to detach | ||
1597 | * @return Detached end on success, NULL on failure | ||
1598 | * (or if that end is not present or is closed). | ||
1599 | */ | ||
1600 | struct GNUNET_DISK_FileHandle * | 1377 | struct GNUNET_DISK_FileHandle * |
1601 | GNUNET_DISK_pipe_detach_end (struct GNUNET_DISK_PipeHandle *p, | 1378 | GNUNET_DISK_pipe_detach_end (struct GNUNET_DISK_PipeHandle *p, |
1602 | enum GNUNET_DISK_PipeEnd end) | 1379 | enum GNUNET_DISK_PipeEnd end) |
@@ -1624,13 +1401,7 @@ GNUNET_DISK_pipe_detach_end (struct GNUNET_DISK_PipeHandle *p, | |||
1624 | } | 1401 | } |
1625 | 1402 | ||
1626 | 1403 | ||
1627 | /** | 1404 | enum GNUNET_GenericReturnValue |
1628 | * Closes an interprocess channel | ||
1629 | * | ||
1630 | * @param p pipe to close | ||
1631 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | ||
1632 | */ | ||
1633 | int | ||
1634 | GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p) | 1405 | GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p) |
1635 | { | 1406 | { |
1636 | int ret = GNUNET_OK; | 1407 | int ret = GNUNET_OK; |
@@ -1661,13 +1432,6 @@ GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p) | |||
1661 | } | 1432 | } |
1662 | 1433 | ||
1663 | 1434 | ||
1664 | /** | ||
1665 | * Get the handle to a particular pipe end | ||
1666 | * | ||
1667 | * @param p pipe | ||
1668 | * @param n end to access | ||
1669 | * @return handle for the respective end | ||
1670 | */ | ||
1671 | const struct GNUNET_DISK_FileHandle * | 1435 | const struct GNUNET_DISK_FileHandle * |
1672 | GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p, | 1436 | GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p, |
1673 | enum GNUNET_DISK_PipeEnd n) | 1437 | enum GNUNET_DISK_PipeEnd n) |
@@ -1685,26 +1449,16 @@ GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p, | |||
1685 | } | 1449 | } |
1686 | 1450 | ||
1687 | 1451 | ||
1688 | /** | 1452 | enum GNUNET_GenericReturnValue |
1689 | * Retrieve OS file handle | ||
1690 | * @internal | ||
1691 | * @param fh GNUnet file descriptor | ||
1692 | * @param dst destination buffer | ||
1693 | * @param dst_len length of dst | ||
1694 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | ||
1695 | */ | ||
1696 | int | ||
1697 | GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh, | 1453 | GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh, |
1698 | void *dst, | 1454 | void *dst, |
1699 | size_t dst_len) | 1455 | size_t dst_len) |
1700 | { | 1456 | { |
1701 | if (NULL == fh) | 1457 | if (NULL == fh) |
1702 | return GNUNET_SYSERR; | 1458 | return GNUNET_SYSERR; |
1703 | |||
1704 | if (dst_len < sizeof(int)) | 1459 | if (dst_len < sizeof(int)) |
1705 | return GNUNET_SYSERR; | 1460 | return GNUNET_SYSERR; |
1706 | *((int *) dst) = fh->fd; | 1461 | *((int *) dst) = fh->fd; |
1707 | |||
1708 | return GNUNET_OK; | 1462 | return GNUNET_OK; |
1709 | } | 1463 | } |
1710 | 1464 | ||
@@ -1716,8 +1470,9 @@ GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh, | |||
1716 | * @param cfg our configuration | 1470 | * @param cfg our configuration |
1717 | * @return #GNUNET_OK on success | 1471 | * @return #GNUNET_OK on success |
1718 | */ | 1472 | */ |
1719 | static int | 1473 | static enum GNUNET_GenericReturnValue |
1720 | purge_cfg_dir (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | 1474 | purge_cfg_dir (void *cls, |
1475 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
1721 | { | 1476 | { |
1722 | const char *option = cls; | 1477 | const char *option = cls; |
1723 | char *tmpname; | 1478 | char *tmpname; |
@@ -1739,15 +1494,9 @@ purge_cfg_dir (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1739 | } | 1494 | } |
1740 | 1495 | ||
1741 | 1496 | ||
1742 | /** | ||
1743 | * Remove the directory given under @a option in | ||
1744 | * section [PATHS] in configuration under @a cfg_filename | ||
1745 | * | ||
1746 | * @param cfg_filename configuration file to parse | ||
1747 | * @param option option with the dir name to purge | ||
1748 | */ | ||
1749 | void | 1497 | void |
1750 | GNUNET_DISK_purge_cfg_dir (const char *cfg_filename, const char *option) | 1498 | GNUNET_DISK_purge_cfg_dir (const char *cfg_filename, |
1499 | const char *option) | ||
1751 | { | 1500 | { |
1752 | GNUNET_break (GNUNET_OK == | 1501 | GNUNET_break (GNUNET_OK == |
1753 | GNUNET_CONFIGURATION_parse_and_run (cfg_filename, | 1502 | 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 | |||
65 | shutdown_task (void *cls) | 65 | shutdown_task (void *cls) |
66 | { | 66 | { |
67 | (void) cls; | 67 | (void) cls; |
68 | if (sizeof(proof) != GNUNET_DISK_fn_write (pwfn, | 68 | if (GNUNET_OK != |
69 | &proof, | 69 | GNUNET_DISK_fn_write (pwfn, |
70 | sizeof(proof), | 70 | &proof, |
71 | GNUNET_DISK_PERM_USER_READ | 71 | sizeof(proof), |
72 | | GNUNET_DISK_PERM_USER_WRITE)) | 72 | GNUNET_DISK_PERM_USER_READ |
73 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", pwfn); | 73 | | GNUNET_DISK_PERM_USER_WRITE)) |
74 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | ||
75 | "write", | ||
76 | pwfn); | ||
74 | } | 77 | } |
75 | 78 | ||
76 | 79 | ||
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 @@ | |||
30 | 30 | ||
31 | 31 | ||
32 | static int | 32 | static int |
33 | testReadWrite () | 33 | testReadWrite (void) |
34 | { | 34 | { |
35 | char tmp[100 + 1]; | 35 | char tmp[100 + 1]; |
36 | int ret; | 36 | int ret; |
37 | 37 | ||
38 | if (strlen (TESTSTRING) != | 38 | if (GNUNET_OK != |
39 | GNUNET_DISK_fn_write (".testfile", TESTSTRING, strlen (TESTSTRING), | 39 | GNUNET_DISK_fn_write (".testfile", TESTSTRING, strlen (TESTSTRING), |
40 | GNUNET_DISK_PERM_USER_READ | 40 | GNUNET_DISK_PERM_USER_READ |
41 | | GNUNET_DISK_PERM_USER_WRITE)) | 41 | | GNUNET_DISK_PERM_USER_WRITE)) |