From cb48bca1a4769ac535f94418ac8599eadcfa2571 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Tue, 5 Nov 2019 20:41:50 +0100 Subject: [PATCH] Sync invitation directory when calling meshlink_invite(). --- src/conf.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/conf.c b/src/conf.c index 79db093e..eea9c3dd 100644 --- a/src/conf.c +++ b/src/conf.c @@ -565,6 +565,12 @@ bool config_write_file(meshlink_handle_t *mesh, FILE *f, const config_t *config, if(chacha_poly1305_encrypt_iv96(ctx, seqbuf, config->buf, config->len, buf, &len)) { success = fwrite(seqbuf, sizeof(seqbuf), 1, f) == 1 && fwrite(buf, len, 1, f) == 1; + + if(!success) { + logger(mesh, MESHLINK_ERROR, "Cannot write config file: %s", strerror(errno)); + } + + meshlink_errno = MESHLINK_ESTORAGE; } else { logger(mesh, MESHLINK_ERROR, "Cannot encrypt config file\n"); meshlink_errno = MESHLINK_ESTORAGE; @@ -588,6 +594,7 @@ bool config_write_file(meshlink_handle_t *mesh, FILE *f, const config_t *config, if(fsync(fileno(f))) { logger(mesh, MESHLINK_ERROR, "Failed to sync file: %s\n", strerror(errno)); + meshlink_errno = MESHLINK_ESTORAGE; return false; } @@ -701,6 +708,7 @@ bool config_write(meshlink_handle_t *mesh, const char *conf_subdir, const char * if(!f) { logger(mesh, MESHLINK_ERROR, "Failed to open `%s': %s", tmp_path, strerror(errno)); + meshlink_errno = MESHLINK_ESTORAGE; return false; } @@ -712,11 +720,13 @@ bool config_write(meshlink_handle_t *mesh, const char *conf_subdir, const char * if(fclose(f)) { logger(mesh, MESHLINK_ERROR, "Failed to close `%s': %s", tmp_path, strerror(errno)); + meshlink_errno = MESHLINK_ESTORAGE; return false; } if(rename(tmp_path, path)) { logger(mesh, MESHLINK_ERROR, "Failed to rename `%s' to `%s': %s", tmp_path, path, strerror(errno)); + meshlink_errno = MESHLINK_ESTORAGE; return false; } @@ -771,6 +781,7 @@ bool main_config_write(meshlink_handle_t *mesh, const char *conf_subdir, const c if(!f) { logger(mesh, MESHLINK_ERROR, "Failed to open `%s': %s", tmp_path, strerror(errno)); + meshlink_errno = MESHLINK_ESTORAGE; return false; } @@ -782,12 +793,14 @@ bool main_config_write(meshlink_handle_t *mesh, const char *conf_subdir, const c if(rename(tmp_path, path)) { logger(mesh, MESHLINK_ERROR, "Failed to rename `%s' to `%s': %s", tmp_path, path, strerror(errno)); + meshlink_errno = MESHLINK_ESTORAGE; fclose(f); return false; } if(fclose(f)) { logger(mesh, MESHLINK_ERROR, "Failed to close `%s': %s", tmp_path, strerror(errno)); + meshlink_errno = MESHLINK_ESTORAGE; return false; } @@ -874,6 +887,7 @@ bool invitation_write(meshlink_handle_t *mesh, const char *conf_subdir, const ch if(!f) { logger(mesh, MESHLINK_ERROR, "Failed to open `%s': %s", path, strerror(errno)); + meshlink_errno = MESHLINK_ESTORAGE; return false; } @@ -885,6 +899,15 @@ bool invitation_write(meshlink_handle_t *mesh, const char *conf_subdir, const ch if(fclose(f)) { logger(mesh, MESHLINK_ERROR, "Failed to close `%s': %s", path, strerror(errno)); + meshlink_errno = MESHLINK_ESTORAGE; + return false; + } + + snprintf(path, sizeof(path), "%s" SLASH "%s" SLASH "invitations", mesh->confbase, conf_subdir); + + if(!sync_path(path)) { + logger(mesh, MESHLINK_ERROR, "Failed to sync `%s': %s", path, strerror(errno)); + meshlink_errno = MESHLINK_ESTORAGE; return false; } -- 2.39.5