система модулей

This commit is contained in:
2026-07-24 02:38:57 +08:00
parent 349ea7e91e
commit 30504ce9f4
24 changed files with 1260 additions and 10 deletions

52
src/auth.c Normal file
View File

@@ -0,0 +1,52 @@
#include <stdio.h>
#include <string.h>
#include "auth.h"
#include "config.h"
int check_folder_password(const char *folder_name, const char *password) {
if (!password || !folder_name || password[0] == '\0') return 0;
FILE *f = fopen(g_config.passwd_file, "r");
if (!f) return 1;
char line[512];
while (fgets(line, sizeof(line), f)) {
line[strcspn(line, "\r\n")] = 0;
char *colon = strchr(line, ':');
if (!colon) continue;
*colon = '\0';
char *folder = line;
char *pass = colon + 1;
const char *last_slash = strrchr(folder_name, '/');
const char *base_name = last_slash ? last_slash + 1 : folder_name;
if (strcmp(folder, folder_name) == 0 || strcmp(folder, base_name) == 0) {
fclose(f);
return strcmp(pass, password) == 0;
}
}
fclose(f);
return 1;
}
int is_folder_protected(const char *folder_path) {
if (!folder_path || folder_path[0] == '\0') return 0;
FILE *f = fopen(g_config.passwd_file, "r");
if (!f) return 0;
char line[512];
while (fgets(line, sizeof(line), f)) {
line[strcspn(line, "\r\n")] = 0;
char *colon = strchr(line, ':');
if (!colon) continue;
*colon = '\0';
const char *last_slash = strrchr(folder_path, '/');
const char *folder_name = last_slash ? last_slash + 1 : folder_path;
if (strcmp(line, folder_path) == 0 || strcmp(line, folder_name) == 0) {
fclose(f);
return 1;
}
}
fclose(f);
return 0;
}