From 16b1e6fd977b09dc4aa378e5ebada0acd410368c Mon Sep 17 00:00:00 2001 From: nishi Date: Wed, 8 May 2024 03:25:55 +0000 Subject: [PATCH] add token system git-svn-id: file:///raid/svn-main/nishi-mandshurica/trunk@63 f982e544-4a7d-3444-ad1a-fde59a2a69f1 --- Module/cookie.c | 3 ++- Module/http.c | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Module/cookie.c b/Module/cookie.c index edf145d..7888a61 100644 --- a/Module/cookie.c +++ b/Module/cookie.c @@ -62,7 +62,7 @@ int mod_init(struct mandshurica_config* _config) { return 0; } -int mod_auth(const char* username, const char* password, void** ptr) { +int mod_auth(const char* username, const char* password, char** ptr) { *ptr = NULL; struct ms_db* db = mandshurica_db_open(config->mandshurica_get_param("CookieDB")); if(db != NULL) { @@ -74,6 +74,7 @@ int mod_auth(const char* username, const char* password, void** ptr) { char* sh = config->mandshurica_sha512(password); if(strcmp(sh, pwd) == 0) { free(sh); + *ptr = mandshurica_strdup("what"); return MS_AUTH_OK; } free(sh); diff --git a/Module/http.c b/Module/http.c index 222547d..fd24422 100644 --- a/Module/http.c +++ b/Module/http.c @@ -195,14 +195,13 @@ 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*, void**) = (int (*)(const char*, const char*, void**))dlsym((*config->libs)[j]->lib, "mod_auth"); + int (*mod_auth)(const char*, const char*, char**) = (int (*)(const char*, const char*, char**))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) { - void* ptr; + char* 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; @@ -256,6 +255,7 @@ void http_handler(int sock) { send(sock, "Content-Length: 0\r\n", 19, 0); send(sock, "\r\n", 2, 0); } + free(ptr); } else if(res == MS_AUTH_ERROR) { send(sock, "HTTP/1.1 400 Bad Request\r\n", 17 + 9, 0); send(sock, "Connection: keep-alive\r\n", 24, 0); -- 2.43.0