#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>

#define BLOCKER    "/opt/village_storage/blocker"
#define FLAG_PATH  "/root/flag"

int main(void) {
    struct stat st;

    if (stat(BLOCKER, &st) == 0) {
        fprintf(stderr, "chest is still locked, remove the blocker first\n");
        return 1;
    }

    if (setuid(0) != 0) {
        perror("setuid");
        return 1;
    }

    FILE *f = fopen(FLAG_PATH, "r");
    if (!f) {
        perror("fopen flag");
        return 1;
    }

    char buf[256];
    while (fgets(buf, sizeof(buf), f))
        fputs(buf, stdout);
    fclose(f);
    return 0;
}
