From: Guus Sliepen Date: Tue, 5 Nov 2019 19:46:58 +0000 (+0100) Subject: Refuse invitees if we can't delete the invitation file. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=4d2e290e8670ab07ae402a6e1320ef09144089f8;p=meshlink Refuse invitees if we can't delete the invitation file. If the call to unlink() or a subsequent sync of the invitation directory fails, don't allow the invitee access, to prevent an invitation from being used twice. --- diff --git a/src/conf.c b/src/conf.c index eea9c3dd..ca107b0a 100644 --- a/src/conf.c +++ b/src/conf.c @@ -866,7 +866,19 @@ bool invitation_read(meshlink_handle_t *mesh, const char *conf_subdir, const cha fclose(f); - unlink(used_path); + if(unlink(used_path)) { + logger(mesh, MESHLINK_ERROR, "Failed to unlink `%s': %s", path, strerror(errno)); + 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; + } + return true; }