fixxxxxxes et mon infra et down je vais me tueeeeeeeeeeeeeeeeeeeer

This commit is contained in:
Gu://em_ 2026-04-07 23:36:31 +02:00
parent 6456f05c2c
commit 3e4e32ed45
7 changed files with 31 additions and 18 deletions

2
epitar/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
*.o
epitar

View file

@ -7,7 +7,7 @@ DBG_LDFLAGS= -fsanitize=address
SRC_DIR = src SRC_DIR = src
LIB_SRCS = LIB_SRCS = tar/archive.c tar/extract.c tar/tar.c utils/config.c utils/filesystem.c
MAIN_SRCS = main.c MAIN_SRCS = main.c
# SRCS = $(patsubst %,$(SRC_DIR)/%, $(MAIN_SRCS)) # SRCS = $(patsubst %,$(SRC_DIR)/%, $(MAIN_SRCS))

View file

@ -36,17 +36,17 @@ int main(int argc, char **argv)
case SUCCESS: case SUCCESS:
return 0; return 0;
case FILE_NOT_FOUND: // case FILE_NOT_FOUND:
case UNKNOWN_ERROR: // case UNKNOWN_ERROR:
puts("epitar: error extracting tarball <tarball>"); // printf("epitar: error extracting tarball %s\n", config.archive_file);
return 3; // return 3;
case BAD_CHECKSUM: case BAD_CHECKSUM:
puts("epitar: bad checksum"); puts("epitar: bad checksum");
return 2; return 2;
default: default:
puts("epitar: error extracting tarball <tarball>"); printf("epitar: error extracting tarball %s\n", config.archive_file);
return 3; return 3;
} }
} }

View file

@ -1,6 +1,8 @@
#include "archive.h" #include "archive.h"
#include "tar.h"
enum error_code archive(char *archive_name, char **files, bool verbose) { enum error_code archive(char *archive_name, char **files, bool verbose) {
(void) archive_name;
(void) files;
(void) verbose;
return UNKNOWN_ERROR; return UNKNOWN_ERROR;
} }

View file

@ -1,7 +1,7 @@
#ifndef ARCHIVE_H #ifndef ARCHIVE_H
#define ARCHIVE_H #define ARCHIVE_H
#include "tar.h" #include "../utils/errors.h"
#include <stdbool.h> #include <stdbool.h>

View file

@ -13,13 +13,9 @@
*/ */
static enum error_code extract_ustar(FILE *stream, struct ustar_header *header) static enum error_code extract_ustar(FILE *stream, struct ustar_header *header)
{ {
// Length
size_t file_length = atol(header->size);
if (file_length == 0)
return INVALID_FORMAT;
struct file_stats stats = { .name = header->name, struct file_stats stats = { .name = header->name,
.length = atol(header->size), .length = strtol(header->size, NULL, 8),
.content_stream = stream, .content_stream = stream,
.mode = header->mode, .mode = header->mode,
.uid = header->uid, .uid = header->uid,
@ -74,7 +70,7 @@ static enum error_code extract_file(FILE *content, union tar_header *header,
if ((ustar_header = get_ustar_header(header)) != NULL) if ((ustar_header = get_ustar_header(header)) != NULL)
{ {
if (verbose) if (verbose)
printf("./%s", ustar_header->name); printf("./%s\n", ustar_header->name);
return extract_ustar(content, ustar_header); return extract_ustar(content, ustar_header);
} }
// UNIXTAR // UNIXTAR
@ -121,7 +117,7 @@ enum error_code extract(char *archive_name, bool verbose)
// Check if empty // Check if empty
char empty_block[BLOCK_SIZE] = { 0 }; char empty_block[BLOCK_SIZE] = { 0 };
if (memcmp(&header.raw_block, empty_block, BLOCK_SIZE) != 0) if (memcmp(&header.raw_block, empty_block, BLOCK_SIZE) == 0)
{ {
if (got_empty_block) // Previous block empty if (got_empty_block) // Previous block empty
read_state = SUCCESS; read_state = SUCCESS;
@ -141,7 +137,18 @@ enum error_code extract(char *archive_name, bool verbose)
fclose(stream); fclose(stream);
return err; return err;
} }
}
// Calculate how many padding bytes need to be skipped
size_t file_size = strtol(header.ustar.size, NULL, 8);
size_t padded_size = ((file_size + BLOCK_SIZE - 1) / BLOCK_SIZE) * BLOCK_SIZE;
size_t skip_bytes = padded_size - file_size;
if (skip_bytes > 0 && fseek(stream, skip_bytes, SEEK_CUR) != 0)
{
fclose(stream);
return UNKNOWN_ERROR; return UNKNOWN_ERROR;
} }
}
return SUCCESS;
}

View file

@ -1,3 +1,5 @@
#define _POSIX_C_SOURCE 200809L
#include "filesystem.h" #include "filesystem.h"
#include "errors.h" #include "errors.h"
@ -115,8 +117,8 @@ enum error_code setowner(char *path, char *uid, char *gid)
if (path == NULL || uid == NULL || gid == NULL) if (path == NULL || uid == NULL || gid == NULL)
return UNKNOWN_ERROR; return UNKNOWN_ERROR;
uid_t uid_val = (uid_t)strtol(uid, NULL, 10); uid_t uid_val = strtol(uid, NULL, 10);
gid_t gid_val = (gid_t)strtol(gid, NULL, 10); gid_t gid_val = strtol(gid, NULL, 10);
int err = chown(path, uid_val, gid_val); int err = chown(path, uid_val, gid_val);
return err == 0 ? SUCCESS : CANNOT_CREATE_TARGET; return err == 0 ? SUCCESS : CANNOT_CREATE_TARGET;