2 econf.c -- configuration code
3 Copyright (C) 2018 Guus Sliepen <guus@meshlink.io>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <sys/types.h>
28 #include "meshlink_internal.h"
32 /// Generate a path to the main configuration file.
33 static void make_main_path(meshlink_handle_t *mesh, const char *conf_subdir, char *path, size_t len) {
38 snprintf(path, len, "%s" SLASH "%s" SLASH "meshlink.conf", mesh->confbase, conf_subdir);
41 /// Generate a path to a host configuration file.
42 static void make_host_path(meshlink_handle_t *mesh, const char *conf_subdir, const char *name, char *path, size_t len) {
48 snprintf(path, len, "%s" SLASH "%s" SLASH "hosts" SLASH "%s", mesh->confbase, conf_subdir, name);
51 /// Generate a path to an unused invitation file.
52 static void make_invitation_path(meshlink_handle_t *mesh, const char *conf_subdir, const char *name, char *path, size_t len) {
58 snprintf(path, len, "%s" SLASH "%s" SLASH "invitations" SLASH "%s", mesh->confbase, conf_subdir, name);
61 /// Generate a path to a used invitation file.
62 static void make_used_invitation_path(meshlink_handle_t *mesh, const char *conf_subdir, const char *name, char *path, size_t len) {
68 snprintf(path, len, "%s" SLASH "%s" SLASH "invitations" SLASH "%s.used", mesh->confbase, conf_subdir, name);
71 /// Remove a directory recursively
72 static void deltree(const char *dirname) {
75 DIR *d = opendir(dirname);
80 while((ent = readdir(d))) {
81 if(ent->d_name[0] == '.') {
85 char filename[PATH_MAX];
86 snprintf(filename, sizeof(filename), "%s" SLASH "%s", dirname, ent->d_name);
88 if(unlink(filename)) {
99 bool sync_path(const char *pathname) {
102 int fd = open(pathname, O_RDONLY);
105 logger(NULL, MESHLINK_ERROR, "Failed to open %s: %s\n", pathname, strerror(errno));
106 meshlink_errno = MESHLINK_ESTORAGE;
111 logger(NULL, MESHLINK_ERROR, "Failed to sync %s: %s\n", pathname, strerror(errno));
113 meshlink_errno = MESHLINK_ESTORAGE;
118 logger(NULL, MESHLINK_ERROR, "Failed to close %s: %s\n", pathname, strerror(errno));
120 meshlink_errno = MESHLINK_ESTORAGE;
127 /// Try decrypting the main configuration file from the given sub-directory.
128 static bool main_config_decrypt(meshlink_handle_t *mesh, const char *conf_subdir) {
129 assert(mesh->config_key);
130 assert(mesh->confbase);
135 if(!main_config_read(mesh, conf_subdir, &config, mesh->config_key)) {
136 logger(mesh, MESHLINK_ERROR, "Could not read main configuration file");
140 packmsg_input_t in = {config.buf, config.len};
142 uint32_t version = packmsg_get_uint32(&in);
143 config_free(&config);
145 return version == MESHLINK_CONFIG_VERSION;
148 /// Create a fresh configuration directory
149 bool config_init(meshlink_handle_t *mesh, const char *conf_subdir) {
152 if(!mesh->confbase) {
158 // Create "current" sub-directory in the confbase
159 snprintf(path, sizeof(path), "%s" SLASH "%s", mesh->confbase, conf_subdir);
162 if(mkdir(path, 0700)) {
163 logger(mesh, MESHLINK_DEBUG, "Could not create directory %s: %s\n", path, strerror(errno));
167 make_host_path(mesh, conf_subdir, "", path, sizeof(path));
169 if(mkdir(path, 0700)) {
170 logger(mesh, MESHLINK_DEBUG, "Could not create directory %s: %s\n", path, strerror(errno));
174 make_invitation_path(mesh, conf_subdir, "", path, sizeof(path));
176 if(mkdir(path, 0700)) {
177 logger(mesh, MESHLINK_DEBUG, "Could not create directory %s: %s\n", path, strerror(errno));
184 /// Wipe an existing configuration directory
185 bool config_destroy(const char *confbase, const char *conf_subdir) {
196 // Check the presence of configuration base sub directory.
197 snprintf(path, sizeof(path), "%s" SLASH "%s", confbase, conf_subdir);
199 if(stat(path, &st)) {
200 if(errno == ENOENT) {
203 logger(NULL, MESHLINK_ERROR, "Cannot stat %s: %s\n", path, strerror(errno));
204 meshlink_errno = MESHLINK_ESTORAGE;
209 // Remove meshlink.conf
210 snprintf(path, sizeof(path), "%s" SLASH "%s" SLASH "meshlink.conf", confbase, conf_subdir);
213 if(errno != ENOENT) {
214 logger(NULL, MESHLINK_ERROR, "Cannot delete %s: %s\n", path, strerror(errno));
215 meshlink_errno = MESHLINK_ESTORAGE;
220 snprintf(path, sizeof(path), "%s" SLASH "%s", confbase, conf_subdir);
225 static bool copytree(const char *src_dir_name, const void *src_key, const char *dst_dir_name, const void *dst_key) {
226 assert(src_dir_name);
227 assert(dst_dir_name);
229 char src_filename[PATH_MAX];
230 char dst_filename[PATH_MAX];
233 DIR *src_dir = opendir(src_dir_name);
236 logger(NULL, MESHLINK_ERROR, "Could not open directory file %s\n", src_dir_name);
240 // Delete if already exists and create a new destination directory
241 deltree(dst_dir_name);
243 if(mkdir(dst_dir_name, 0700)) {
244 logger(NULL, MESHLINK_ERROR, "Could not create directory %s\n", dst_filename);
248 while((ent = readdir(src_dir))) {
249 if(ent->d_name[0] == '.') {
253 snprintf(dst_filename, sizeof(dst_filename), "%s" SLASH "%s", dst_dir_name, ent->d_name);
254 snprintf(src_filename, sizeof(src_filename), "%s" SLASH "%s", src_dir_name, ent->d_name);
256 if(ent->d_type == DT_DIR) {
257 if(!copytree(src_filename, src_key, dst_filename, dst_key)) {
258 logger(NULL, MESHLINK_ERROR, "Copying %s to %s failed\n", src_filename, dst_filename);
262 if(!sync_path(dst_filename)) {
265 } else if(ent->d_type == DT_REG) {
269 if(stat(src_filename, &st)) {
270 logger(NULL, MESHLINK_ERROR, "Could not stat file `%s': %s\n", src_filename, strerror(errno));
274 FILE *f = fopen(src_filename, "r");
277 logger(NULL, MESHLINK_ERROR, "Failed to open `%s': %s\n", src_filename, strerror(errno));
281 if(!config_read_file(NULL, f, &config, src_key)) {
282 logger(NULL, MESHLINK_ERROR, "Failed to read `%s': %s\n", src_filename, strerror(errno));
288 logger(NULL, MESHLINK_ERROR, "Failed to close `%s': %s\n", src_filename, strerror(errno));
289 config_free(&config);
293 f = fopen(dst_filename, "w");
296 logger(NULL, MESHLINK_ERROR, "Failed to open `%s': %s", dst_filename, strerror(errno));
297 config_free(&config);
301 if(!config_write_file(NULL, f, &config, dst_key)) {
302 logger(NULL, MESHLINK_ERROR, "Failed to write `%s': %s", dst_filename, strerror(errno));
303 config_free(&config);
309 logger(NULL, MESHLINK_ERROR, "Failed to close `%s': %s", dst_filename, strerror(errno));
310 config_free(&config);
314 config_free(&config);
316 struct utimbuf times;
317 times.modtime = st.st_mtime;
318 times.actime = st.st_atime;
320 if(utime(dst_filename, ×)) {
321 logger(NULL, MESHLINK_ERROR, "Failed to utime `%s': %s", dst_filename, strerror(errno));
331 bool config_copy(meshlink_handle_t *mesh, const char *src_dir_name, const void *src_key, const char *dst_dir_name, const void *dst_key) {
332 assert(src_dir_name);
333 assert(dst_dir_name);
335 char src_filename[PATH_MAX];
336 char dst_filename[PATH_MAX];
338 snprintf(dst_filename, sizeof(dst_filename), "%s" SLASH "%s", mesh->confbase, dst_dir_name);
339 snprintf(src_filename, sizeof(src_filename), "%s" SLASH "%s", mesh->confbase, src_dir_name);
341 return copytree(src_filename, src_key, dst_filename, dst_key);
344 /// Check the presence of the main configuration file.
345 bool main_config_exists(meshlink_handle_t *mesh, const char *conf_subdir) {
348 if(!mesh->confbase) {
353 make_main_path(mesh, conf_subdir, path, sizeof(path));
354 return access(path, F_OK) == 0;
357 bool config_rename(meshlink_handle_t *mesh, const char *old_conf_subdir, const char *new_conf_subdir) {
358 assert(old_conf_subdir);
359 assert(new_conf_subdir);
361 if(!mesh->confbase) {
365 char old_path[PATH_MAX];
366 char new_path[PATH_MAX];
368 snprintf(old_path, sizeof(old_path), "%s" SLASH "%s", mesh->confbase, old_conf_subdir);
369 snprintf(new_path, sizeof(new_path), "%s" SLASH "%s", mesh->confbase, new_conf_subdir);
371 return rename(old_path, new_path) == 0;
374 bool config_sync(meshlink_handle_t *mesh, const char *conf_subdir) {
377 if(!mesh->confbase) {
382 snprintf(path, sizeof(path), "%s" SLASH "%s" SLASH "hosts", mesh->confbase, conf_subdir);
384 if(!sync_path(path)) {
388 snprintf(path, sizeof(path), "%s" SLASH "%s", mesh->confbase, conf_subdir);
390 if(!sync_path(path)) {
397 bool meshlink_confbase_exists(meshlink_handle_t *mesh) {
398 if(!mesh->confbase) {
402 bool confbase_exists = false;
403 bool confbase_decryptable = false;
405 if(main_config_exists(mesh, "current")) {
406 confbase_exists = true;
408 if(mesh->config_key && main_config_decrypt(mesh, "current")) {
409 confbase_decryptable = true;
413 if(mesh->config_key && !confbase_decryptable && main_config_exists(mesh, "new")) {
414 confbase_exists = true;
416 if(main_config_decrypt(mesh, "new")) {
417 if(!config_destroy(mesh->confbase, "current")) {
421 if(!config_rename(mesh, "new", "current")) {
425 confbase_decryptable = true;
429 if(mesh->config_key && !confbase_decryptable && main_config_exists(mesh, "old")) {
430 confbase_exists = true;
432 if(main_config_decrypt(mesh, "old")) {
433 if(!config_destroy(mesh->confbase, "current")) {
437 if(!config_rename(mesh, "old", "current")) {
441 confbase_decryptable = true;
445 // Cleanup if current is existing with old and new
446 if(confbase_exists && confbase_decryptable) {
447 config_destroy(mesh->confbase, "old");
448 config_destroy(mesh->confbase, "new");
451 return confbase_exists;
454 /// Lock the main configuration file. Creates confbase if necessary.
455 bool main_config_lock(meshlink_handle_t *mesh) {
456 if(!mesh->confbase) {
460 if(mkdir(mesh->confbase, 0700) && errno != EEXIST) {
461 logger(NULL, MESHLINK_ERROR, "Cannot create configuration directory %s: %s", mesh->confbase, strerror(errno));
462 meshlink_close(mesh);
463 meshlink_errno = MESHLINK_ESTORAGE;
468 snprintf(path, sizeof(path), "%s" SLASH "meshlink.lock", mesh->confbase);
470 mesh->lockfile = fopen(path, "w+");
472 if(!mesh->lockfile) {
473 logger(NULL, MESHLINK_ERROR, "Cannot not open %s: %s\n", path, strerror(errno));
474 meshlink_errno = MESHLINK_ESTORAGE;
479 fcntl(fileno(mesh->lockfile), F_SETFD, FD_CLOEXEC);
483 // TODO: use _locking()?
486 if(flock(fileno(mesh->lockfile), LOCK_EX | LOCK_NB) != 0) {
487 logger(NULL, MESHLINK_ERROR, "Cannot lock %s: %s\n", path, strerror(errno));
488 fclose(mesh->lockfile);
489 mesh->lockfile = NULL;
490 meshlink_errno = MESHLINK_EBUSY;
499 /// Unlock the main configuration file.
500 void main_config_unlock(meshlink_handle_t *mesh) {
502 fclose(mesh->lockfile);
503 mesh->lockfile = NULL;
507 /// Read a configuration file from a FILE handle.
508 bool config_read_file(meshlink_handle_t *mesh, FILE *f, config_t *config, const void *key) {
513 if(fseek(f, 0, SEEK_END) || !(len = ftell(f)) || fseek(f, 0, SEEK_SET)) {
514 logger(mesh, MESHLINK_ERROR, "Cannot get config file size: %s\n", strerror(errno));
515 meshlink_errno = MESHLINK_ESTORAGE;
519 uint8_t *buf = xmalloc(len);
521 if(fread(buf, len, 1, f) != 1) {
522 logger(mesh, MESHLINK_ERROR, "Cannot read config file: %s\n", strerror(errno));
523 meshlink_errno = MESHLINK_ESTORAGE;
528 uint8_t *decrypted = xmalloc(len);
529 size_t decrypted_len = len;
530 chacha_poly1305_ctx_t *ctx = chacha_poly1305_init();
531 chacha_poly1305_set_key(ctx, key);
533 if(len > 12 && chacha_poly1305_decrypt_iv96(ctx, buf, buf + 12, len - 12, decrypted, &decrypted_len)) {
534 chacha_poly1305_exit(ctx);
536 config->buf = decrypted;
537 config->len = decrypted_len;
540 logger(mesh, MESHLINK_ERROR, "Cannot decrypt config file\n");
541 meshlink_errno = MESHLINK_ESTORAGE;
542 chacha_poly1305_exit(ctx);
555 /// Write a configuration file to a FILE handle.
556 bool config_write_file(meshlink_handle_t *mesh, FILE *f, const config_t *config, const void *key) {
560 uint8_t buf[config->len + 16];
561 size_t len = sizeof(buf);
563 randomize(&seqbuf, sizeof(seqbuf));
564 chacha_poly1305_ctx_t *ctx = chacha_poly1305_init();
565 chacha_poly1305_set_key(ctx, key);
566 bool success = false;
568 if(chacha_poly1305_encrypt_iv96(ctx, seqbuf, config->buf, config->len, buf, &len)) {
569 success = fwrite(seqbuf, sizeof(seqbuf), 1, f) == 1 && fwrite(buf, len, 1, f) == 1;
572 logger(mesh, MESHLINK_ERROR, "Cannot write config file: %s", strerror(errno));
575 meshlink_errno = MESHLINK_ESTORAGE;
577 logger(mesh, MESHLINK_ERROR, "Cannot encrypt config file\n");
578 meshlink_errno = MESHLINK_ESTORAGE;
581 chacha_poly1305_exit(ctx);
585 if(fwrite(config->buf, config->len, 1, f) != 1) {
586 logger(mesh, MESHLINK_ERROR, "Cannot write config file: %s", strerror(errno));
587 meshlink_errno = MESHLINK_ESTORAGE;
592 logger(mesh, MESHLINK_ERROR, "Failed to flush file: %s", strerror(errno));
593 meshlink_errno = MESHLINK_ESTORAGE;
597 if(fsync(fileno(f))) {
598 logger(mesh, MESHLINK_ERROR, "Failed to sync file: %s\n", strerror(errno));
599 meshlink_errno = MESHLINK_ESTORAGE;
606 /// Free resources of a loaded configuration file.
607 void config_free(config_t *config) {
608 assert(!config->len || config->buf);
610 free((uint8_t *)config->buf);
615 /// Check the presence of a host configuration file.
616 bool config_exists(meshlink_handle_t *mesh, const char *conf_subdir, const char *name) {
619 if(!mesh->confbase) {
624 make_host_path(mesh, conf_subdir, name, path, sizeof(path));
626 return access(path, F_OK) == 0;
629 /// Read a host configuration file.
630 bool config_read(meshlink_handle_t *mesh, const char *conf_subdir, const char *name, config_t *config, void *key) {
633 if(!mesh->confbase) {
638 make_host_path(mesh, conf_subdir, name, path, sizeof(path));
640 FILE *f = fopen(path, "r");
643 logger(mesh, MESHLINK_ERROR, "Failed to open `%s': %s", path, strerror(errno));
647 if(!config_read_file(mesh, f, config, key)) {
648 logger(mesh, MESHLINK_ERROR, "Failed to read `%s': %s", path, strerror(errno));
658 bool config_scan_all(meshlink_handle_t *mesh, const char *conf_subdir, const char *conf_type, config_scan_action_t action, void *arg) {
662 if(!mesh->confbase) {
668 char dname[PATH_MAX];
669 snprintf(dname, sizeof(dname), "%s" SLASH "%s" SLASH "%s", mesh->confbase, conf_subdir, conf_type);
671 dir = opendir(dname);
674 logger(mesh, MESHLINK_ERROR, "Could not open %s: %s", dname, strerror(errno));
675 meshlink_errno = MESHLINK_ESTORAGE;
679 while((ent = readdir(dir))) {
680 if(ent->d_name[0] == '.') {
684 if(!action(mesh, ent->d_name, arg)) {
694 /// Write a host configuration file.
695 bool config_write(meshlink_handle_t *mesh, const char *conf_subdir, const char *name, const config_t *config, void *key) {
700 if(!mesh->confbase) {
705 char tmp_path[PATH_MAX + 4];
706 make_host_path(mesh, conf_subdir, name, path, sizeof(path));
707 snprintf(tmp_path, sizeof(tmp_path), "%s.tmp", path);
709 FILE *f = fopen(tmp_path, "w");
712 logger(mesh, MESHLINK_ERROR, "Failed to open `%s': %s", tmp_path, strerror(errno));
713 meshlink_errno = MESHLINK_ESTORAGE;
717 if(!config_write_file(mesh, f, config, key)) {
718 logger(mesh, MESHLINK_ERROR, "Failed to write `%s': %s", tmp_path, strerror(errno));
724 logger(mesh, MESHLINK_ERROR, "Failed to close `%s': %s", tmp_path, strerror(errno));
725 meshlink_errno = MESHLINK_ESTORAGE;
729 if(rename(tmp_path, path)) {
730 logger(mesh, MESHLINK_ERROR, "Failed to rename `%s' to `%s': %s", tmp_path, path, strerror(errno));
731 meshlink_errno = MESHLINK_ESTORAGE;
738 /// Read the main configuration file.
739 bool main_config_read(meshlink_handle_t *mesh, const char *conf_subdir, config_t *config, void *key) {
743 if(!mesh->confbase) {
748 make_main_path(mesh, conf_subdir, path, sizeof(path));
750 FILE *f = fopen(path, "r");
753 logger(mesh, MESHLINK_ERROR, "Failed to open `%s': %s", path, strerror(errno));
757 if(!config_read_file(mesh, f, config, key)) {
758 logger(mesh, MESHLINK_ERROR, "Failed to read `%s': %s", path, strerror(errno));
768 /// Write the main configuration file.
769 bool main_config_write(meshlink_handle_t *mesh, const char *conf_subdir, const config_t *config, void *key) {
773 if(!mesh->confbase) {
778 char tmp_path[PATH_MAX + 4];
779 make_main_path(mesh, conf_subdir, path, sizeof(path));
780 snprintf(tmp_path, sizeof(tmp_path), "%s.tmp", path);
782 FILE *f = fopen(tmp_path, "w");
785 logger(mesh, MESHLINK_ERROR, "Failed to open `%s': %s", tmp_path, strerror(errno));
786 meshlink_errno = MESHLINK_ESTORAGE;
790 if(!config_write_file(mesh, f, config, key)) {
791 logger(mesh, MESHLINK_ERROR, "Failed to write `%s': %s", tmp_path, strerror(errno));
796 if(rename(tmp_path, path)) {
797 logger(mesh, MESHLINK_ERROR, "Failed to rename `%s' to `%s': %s", tmp_path, path, strerror(errno));
798 meshlink_errno = MESHLINK_ESTORAGE;
804 logger(mesh, MESHLINK_ERROR, "Failed to close `%s': %s", tmp_path, strerror(errno));
805 meshlink_errno = MESHLINK_ESTORAGE;
812 /// Read an invitation file from the confbase sub-directory, and immediately delete it.
813 bool invitation_read(meshlink_handle_t *mesh, const char *conf_subdir, const char *name, config_t *config, void *key) {
818 if(!mesh->confbase) {
823 char used_path[PATH_MAX];
824 make_invitation_path(mesh, conf_subdir, name, path, sizeof(path));
825 make_used_invitation_path(mesh, conf_subdir, name, used_path, sizeof(used_path));
827 // Atomically rename the invitation file
828 if(rename(path, used_path)) {
829 if(errno == ENOENT) {
830 logger(mesh, MESHLINK_ERROR, "Peer tried to use non-existing invitation %s\n", name);
832 logger(mesh, MESHLINK_ERROR, "Error trying to rename invitation %s\n", name);
838 FILE *f = fopen(used_path, "r");
841 logger(mesh, MESHLINK_ERROR, "Failed to open `%s': %s", path, strerror(errno));
845 // Check the timestamp
848 if(fstat(fileno(f), &st)) {
849 logger(mesh, MESHLINK_ERROR, "Could not stat invitation file %s\n", name);
855 if(mesh->loop.now.tv_sec >= st.st_mtime + mesh->invitation_timeout) {
856 logger(mesh, MESHLINK_ERROR, "Peer tried to use an outdated invitation file %s\n", name);
862 if(!config_read_file(mesh, f, config, key)) {
863 logger(mesh, MESHLINK_ERROR, "Failed to read `%s': %s", path, strerror(errno));
871 if(unlink(used_path)) {
872 logger(mesh, MESHLINK_ERROR, "Failed to unlink `%s': %s", path, strerror(errno));
876 snprintf(path, sizeof(path), "%s" SLASH "%s" SLASH "invitations", mesh->confbase, conf_subdir);
878 if(!sync_path(path)) {
879 logger(mesh, MESHLINK_ERROR, "Failed to sync `%s': %s", path, strerror(errno));
880 meshlink_errno = MESHLINK_ESTORAGE;
887 /// Write an invitation file.
888 bool invitation_write(meshlink_handle_t *mesh, const char *conf_subdir, const char *name, const config_t *config, void *key) {
893 if(!mesh->confbase) {
898 make_invitation_path(mesh, conf_subdir, name, path, sizeof(path));
900 FILE *f = fopen(path, "w");
903 logger(mesh, MESHLINK_ERROR, "Failed to open `%s': %s", path, strerror(errno));
904 meshlink_errno = MESHLINK_ESTORAGE;
908 if(!config_write_file(mesh, f, config, key)) {
909 logger(mesh, MESHLINK_ERROR, "Failed to write `%s': %s", path, strerror(errno));
915 logger(mesh, MESHLINK_ERROR, "Failed to close `%s': %s", path, strerror(errno));
916 meshlink_errno = MESHLINK_ESTORAGE;
920 snprintf(path, sizeof(path), "%s" SLASH "%s" SLASH "invitations", mesh->confbase, conf_subdir);
922 if(!sync_path(path)) {
923 logger(mesh, MESHLINK_ERROR, "Failed to sync `%s': %s", path, strerror(errno));
924 meshlink_errno = MESHLINK_ESTORAGE;
931 /// Purge old invitation files
932 size_t invitation_purge_old(meshlink_handle_t *mesh, time_t deadline) {
933 if(!mesh->confbase) {
938 make_invitation_path(mesh, "current", "", path, sizeof(path));
940 DIR *dir = opendir(path);
943 logger(mesh, MESHLINK_DEBUG, "Could not read directory %s: %s\n", path, strerror(errno));
944 meshlink_errno = MESHLINK_ESTORAGE;
952 while((ent = readdir(dir))) {
953 if(strlen(ent->d_name) != 24) {
957 char invname[PATH_MAX];
960 if(snprintf(invname, sizeof(invname), "%s" SLASH "%s", path, ent->d_name) >= PATH_MAX) {
961 logger(mesh, MESHLINK_DEBUG, "Filename too long: %s" SLASH "%s", path, ent->d_name);
965 if(!stat(invname, &st)) {
966 if(mesh->invitation_key && deadline < st.st_mtime) {
972 logger(mesh, MESHLINK_DEBUG, "Could not stat %s: %s\n", invname, strerror(errno));
978 logger(mesh, MESHLINK_DEBUG, "Error while reading directory %s: %s\n", path, strerror(errno));
980 meshlink_errno = MESHLINK_ESTORAGE;