From: nishi Date: Wed, 8 May 2024 03:22:26 +0000 (+0000) Subject: lock there too X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=f3f9e7ae6a6b8b2d11df13e567103a5fee9dd980;p=mandshurica.git lock there too git-svn-id: file:///raid/svn-main/nishi-mandshurica/trunk@62 f982e544-4a7d-3444-ad1a-fde59a2a69f1 --- diff --git a/Mandshurica/db.c b/Mandshurica/db.c index 4a93002..ddfce62 100644 --- a/Mandshurica/db.c +++ b/Mandshurica/db.c @@ -37,7 +37,6 @@ #include struct ms_db* mandshurica_db_open(const char* path) { - FILE* fp = fopen(path, "r+b"); if(fp != NULL) { struct ms_db* db = malloc(sizeof(*db)); @@ -64,6 +63,7 @@ void mandshurica_db_write(struct ms_db* db, const char* key, const char* value) /* key:value */ char* mandshurica_db_get(struct ms_db* db, const char* key) { + flockfile(db->fp); fseek(db->fp, 0, SEEK_SET); char cbuf[2]; cbuf[1] = 0; @@ -96,5 +96,6 @@ char* mandshurica_db_get(struct ms_db* db, const char* key) { } } free(line); + funlockfile(db->fp); return NULL; } diff --git a/Module/cookie.c b/Module/cookie.c index 3aca139..edf145d 100644 --- a/Module/cookie.c +++ b/Module/cookie.c @@ -62,7 +62,8 @@ int mod_init(struct mandshurica_config* _config) { return 0; } -int mod_auth(const char* username, const char* password) { +int mod_auth(const char* username, const char* password, void** ptr) { + *ptr = NULL; struct ms_db* db = mandshurica_db_open(config->mandshurica_get_param("CookieDB")); if(db != NULL) { char* pwd = mandshurica_db_get(db, username); diff --git a/Module/http.c b/Module/http.c index de92abe..222547d 100644 --- a/Module/http.c +++ b/Module/http.c @@ -195,12 +195,14 @@ void http_handler(int sock) { const char* httppath = (const char*)dlsym((*config->libs)[j]->lib, "mod_http_path"); if(httppath != NULL) { if(strcmp(httppath, path) == 0) { - int (*mod_auth)(const char*, const char*) = (int (*)(const char*, const char*))dlsym((*config->libs)[j]->lib, "mod_auth"); + int (*mod_auth)(const char*, const char*, void**) = (int (*)(const char*, const char*, void**))dlsym((*config->libs)[j]->lib, "mod_auth"); char* usr = mandshurica_parse_form(postbuf, "username"); char* pwd = mandshurica_parse_form(postbuf, "password"); if(usr != NULL && pwd != NULL) { - int res = mod_auth(usr, pwd); + void* ptr; + int res = mod_auth(usr, pwd, &ptr); if(res == MS_AUTH_OK) { + printf("%llx\n", ptr); char* type; uint64_t len; char* data = NULL;