]> git.meshlink.io Git - meshlink/blobdiff - src/protocol_auth.c
Add meshlink_set_invitation_timeout().
[meshlink] / src / protocol_auth.c
index b11acaef7c5e4238dcba37af577bb8077da2fef3..4ba3ebe4282dc1742942b2944a31309a233559da 100644 (file)
@@ -239,6 +239,24 @@ static bool receive_invitation_sptps(void *handle, uint8_t type, const void *dat
 
        if(!f) {
                logger(mesh, MESHLINK_ERROR, "Error trying to open invitation %s\n", cookie);
+               unlink(usedname);
+               return false;
+       }
+
+       // Check the timestamp
+       struct stat st;
+
+       if(fstat(fileno(f), &st)) {
+               logger(mesh, MESHLINK_ERROR, "Could not stat invitation file %s\n", usedname);
+               fclose(f);
+               unlink(usedname);
+               return false;
+       }
+
+       if(time(NULL) > st.st_mtime + mesh->invitation_timeout) {
+               logger(mesh, MESHLINK_ERROR, "Peer %s tried to use an outdated invitation file %s\n", c->name, usedname);
+               fclose(f);
+               unlink(usedname);
                return false;
        }