Started writing the management program.

This commit is contained in:
2024-02-15 00:17:20 +01:00
commit 827b62fbcd
12 changed files with 700 additions and 0 deletions

70
src/entry.c Normal file
View File

@@ -0,0 +1,70 @@
#include "entry.h"
#include "sandbox.h"
#include "utils.h"
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
char* get_entries_path(void) {
return format("%s/%s", MASTER_DIRECTORY, ENTRIES_DIRECTORY);
}
bool is_valid_entry_name(const char* name) {
if (name == NULL)
return false;
// Check that the name is not empty
size_t length = strlen(name);
if (length == 0)
return false;
// Check that the name does not contain /
for (size_t i = 0; i < length; i++)
if (name[i] == '/')
return false;
// Check that the name is not . or ..
if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
return false;
return true;
}
char* get_entry_path(const char* entry) {
char* entries_path = get_entries_path();
if (entries_path == NULL)
return NULL;
// Combine the entries path with the entry name
char* entry_path = format("%s/%s", entries_path, entry);
// Free the entries path
free(entries_path);
return entry_path;
}
bool entry_exists(const char* entry) {
char* entry_path = get_entry_path(entry);
if (entry_path == NULL)
return false;
// Check if the entry path exists
struct stat statbuf;
int result = stat(entry_path, &statbuf);
// Free the entry path
free(entry_path);
if (result != 0)
return false;
if (!S_ISDIR(statbuf.st_mode))
return false;
return true;
}