From: nishi Date: Sat, 20 Apr 2024 02:35:41 +0000 (+0000) Subject: got auth working... kinda X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=50eece00aff4d78fed1b2c8abb7def32de1507fd;p=mandshurica.git got auth working... kinda git-svn-id: file:///raid/svn-main/nishi-mandshurica/trunk@50 f982e544-4a7d-3444-ad1a-fde59a2a69f1 --- diff --git a/Mandshurica/util.c b/Mandshurica/util.c index 1475409..8a00ff2 100644 --- a/Mandshurica/util.c +++ b/Mandshurica/util.c @@ -138,7 +138,31 @@ char* mandshurica_parse_form(const char* form, const char* name) { int i; char cbuf[2]; cbuf[1] = 0; + char* _form = mandshurica_strdup(form); + int start = 0; for(i = 0;; i++) { + if(_form[i] == 0 || _form[i] == '&') { + char oldc = _form[i]; + _form[i] = 0; + int j; + bool found = false; + char* _tform = _form + start; + for(j = 0; _tform[j] != 0; j++) { + if(_tform[j] == '=') { + _tform[j] = 0; + if(strcmp(_tform, name) == 0) found = true; + break; + } + } + if(found) { + char* val = mandshurica_strdup(_tform + j + 1); + free(_form); + return val; + } + start = i + 1; + if(oldc == 0) break; + } } + free(_form); return NULL; } diff --git a/Module/http.c b/Module/http.c index 3f3a774..cef0b00 100644 --- a/Module/http.c +++ b/Module/http.c @@ -196,7 +196,27 @@ void http_handler(int sock) { int (*mod_auth)(const char*, const char*) = (int (*)(const char*, const char*))dlsym((*config->libs)[j]->lib, "mod_auth"); char* usr = mandshurica_parse_form(postbuf, "username"); char* pwd = mandshurica_parse_form(postbuf, "password"); - printf("%s, %s\n", usr == NULL ? "(null)" : usr, pwd == NULL ? "(null)" : pwd); + if(usr != NULL && pwd != NULL) { + int res = mod_auth(usr, pwd); + if(res == MS_AUTH_OK) { + } 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); + send(sock, "Content-Length: 0\r\n", 19, 0); + send(sock, "\r\n", 2, 0); + } else if(res == MS_AUTH_FAIL) { + + send(sock, "HTTP/1.1 403 Forbidden\r\n", 15 + 9, 0); + send(sock, "Connection: keep-alive\r\n", 24, 0); + send(sock, "Content-Length: 0\r\n", 19, 0); + send(sock, "\r\n", 2, 0); + } + } else { + send(sock, "HTTP/1.1 400 Bad Request\r\n", 17 + 9, 0); + send(sock, "Connection: keep-alive\r\n", 24, 0); + send(sock, "Content-Length: 0\r\n", 19, 0); + send(sock, "\r\n", 2, 0); + } sent = true; } }