More stuff done

This commit is contained in:
Afonso Franco 2024-05-11 17:32:12 +01:00
parent da345fc422
commit 897c8150a5
Signed by: afonso
SSH key fingerprint: SHA256:PQTRDHPH3yALEGtHXnXBp3Orfcn21pK20t0tS1kHg54
4 changed files with 147 additions and 12 deletions

View file

@ -1,3 +1,62 @@
int main(){
#include "../../libs/communication/communication.h"
#include "../../libs/protocol/protocol.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
int main() {
unsigned char buffer[MESSAGE_SIZE];
read(0, buffer, MESSAGE_SIZE);
message msg;
deserialize_message(buffer, MESSAGE_SIZE, &msg);
if (msg.header.isgroup) {
const char *directory_format = "/opt/djumbai/group/%d/";
char group_path[50];
sprintf(group_path, directory_format, msg.header.receiver);
char message_box_path[70];
sprintf(message_box_path, group_path, "message_box/");
struct stat st;
if (stat(group_path, &st) == -1) {
// Directory doesn't exist, so create it
if (mkdir(group_path, 0070) == -1) {
perror("mkdir");
return EXIT_FAILURE;
}
}
if (stat(message_box_path, &st) == -1) {
// Directory doesn't exist, so create it
if (mkdir(message_box_path, 0070) == -1) {
perror("mkdir");
return EXIT_FAILURE;
}
}
chroot(message_box_path);
//Do the rest
} else {
// struct stat st;
// if (stat(user_path, &st) == -1) {
// // Directory doesn't exist, so create it
// if (mkdir(user_path, 0700) == -1) {
// perror("mkdir");
// return EXIT_FAILURE;
// }
// }
// if (stat(message_box_path, &st) == -1) {
// // Directory doesn't exist, so create it
// if (mkdir(message_box_path, 0700) == -1) {
// perror("mkdir");
// return EXIT_FAILURE;
// }
// }
// chroot(message_box_path);
//
// Message receiver is a user
// Write to the user's mailbox
}
}