From a0347a7ca4ac94ac5f5b74502b35ffb425397705 Mon Sep 17 00:00:00 2001 From: AfonsoCMSousa Date: Thu, 27 Feb 2025 21:10:50 +0000 Subject: [PATCH] Implemented feature that allows users to delete passwords if needed. --- include/dynmem.h | 2 +- src/server.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/include/dynmem.h b/include/dynmem.h index 755e3fb..9b6910f 100644 --- a/include/dynmem.h +++ b/include/dynmem.h @@ -42,7 +42,7 @@ */ #define add(ptr, index, value) ptr[index] = value //@param ptr Pointer to add the value @param index Index of the value to add @param value Value to add -#define remove(ptr, index) ptr[index] = 0 //@param ptr Pointer to remove the value @param index Index of the value to remove +#define removePTR(ptr, index) ptr[index] = 0 //@param ptr Pointer to remove the value @param index Index of the value to remove #ifdef __INTELLISENSE__ #define create(type) ((type *)malloc(sizeof(type))) //@param type Type of the vector @example int *vector = create(int); diff --git a/src/server.c b/src/server.c index 73782fe..fd66609 100644 --- a/src/server.c +++ b/src/server.c @@ -170,6 +170,28 @@ int main(void) emcryptText(key2, req.key); writel(filepath, key2, 256); } + else if (req.type == 2) + { + // debug + printf("Received request type 2\n"); + + char filepath[256]; + + printf("Received key: %s\n", req.key); + printf("Received level: %d\n", req.level); + sprintf(filepath, "%s%d.bin", PASSWORDS, req.level); + + printf("Deleting key from file: %s\n", filepath); + + if (remove(filepath) != 0) + { + fprintf(stderr, "Error deleting file\n"); + } + } + else + { + fprintf(stderr, "Invalid request type\n"); + } } // Close the socket