220 |
ssize_t have= 0; |
ssize_t have= 0; |
221 |
|
|
222 |
va_start(ap, m); |
va_start(ap, m); |
223 |
buf= format(m, ap, &need); |
buf= Util_formatString(m, ap, &need); |
224 |
va_end(ap); |
va_end(ap); |
225 |
have= res->bufsize - res->bufused; |
have= res->bufsize - res->bufused; |
226 |
if(have <= need) { |
if(have <= need) { |
544 |
internal_error(S, SC_BAD_REQUEST, "No request found"); |
internal_error(S, SC_BAD_REQUEST, "No request found"); |
545 |
return NULL; |
return NULL; |
546 |
} |
} |
547 |
chomp(line,REQ_STRLEN); |
Util_chomp(line,REQ_STRLEN); |
548 |
/* RATS: ignore */ /* chomp does zero termination */ |
/* RATS: ignore */ /* Util_chomp does zero termination */ |
549 |
if(sscanf(line, "%s %s HTTP/%3[1.0]", method, url, protocol) != 3) { |
if(sscanf(line, "%s %s HTTP/%3[1.0]", method, url, protocol) != 3) { |
550 |
internal_error(S, SC_BAD_REQUEST, "Cannot parse request"); |
internal_error(S, SC_BAD_REQUEST, "Cannot parse request"); |
551 |
return NULL; |
return NULL; |
556 |
} |
} |
557 |
NEW(req); |
NEW(req); |
558 |
req->S= S; |
req->S= S; |
559 |
url_decode(url); |
Util_urlDecode(url); |
560 |
req->url= xstrdup(url); |
req->url= xstrdup(url); |
561 |
req->method= xstrdup(method); |
req->method= xstrdup(method); |
562 |
req->protocol= xstrdup(protocol); |
req->protocol= xstrdup(protocol); |
608 |
if(NULL != (value= strchr(line, ':'))) { |
if(NULL != (value= strchr(line, ':'))) { |
609 |
NEW(header); |
NEW(header); |
610 |
*value++= 0; |
*value++= 0; |
611 |
trim(line); |
Util_trim(line); |
612 |
trim(value); |
Util_trim(value); |
613 |
chomp(value, (REQ_STRLEN-(value-line))); |
Util_chomp(value, (REQ_STRLEN-(value-line))); |
614 |
header->name= xstrdup(line); |
header->name= xstrdup(line); |
615 |
header->value= xstrdup(value); |
header->value= xstrdup(value); |
616 |
header->next= req->headers; |
header->next= req->headers; |
766 |
char uname[STRLEN]; |
char uname[STRLEN]; |
767 |
const char *credentials= get_header(req, "Authorization"); |
const char *credentials= get_header(req, "Authorization"); |
768 |
|
|
769 |
if(! (credentials && starts_with(credentials, "Basic "))) { |
if(! (credentials && Util_startsWith(credentials, "Basic "))) { |
770 |
return FALSE; |
return FALSE; |
771 |
} |
} |
772 |
strncpy(buf, &credentials[6], STRLEN); |
strncpy(buf, &credentials[6], STRLEN); |
783 |
return FALSE; |
return FALSE; |
784 |
} |
} |
785 |
/* Check if user exist */ |
/* Check if user exist */ |
786 |
if(NULL==get_user_credentials(uname)) { |
if(NULL==Util_getUserCredentials(uname)) { |
787 |
log("Warning: Client '%s' supplied unknown user '%s'" |
log("Warning: Client '%s' supplied unknown user '%s'" |
788 |
" accessing monit httpd\n", socket_get_remote_host(req->S), uname); |
" accessing monit httpd\n", socket_get_remote_host(req->S), uname); |
789 |
return FALSE; |
return FALSE; |
790 |
} |
} |
791 |
/* Check if user has supplied the right password */ |
/* Check if user has supplied the right password */ |
792 |
if(! compare_user_credentials(uname, password)) { |
if(! Util_checkCredentials(uname, password)) { |
793 |
log("Warning: Client '%s' supplied wrong password for user '%s'" |
log("Warning: Client '%s' supplied wrong password for user '%s'" |
794 |
" accessing monit httpd\n", socket_get_remote_host(req->S), uname); |
" accessing monit httpd\n", socket_get_remote_host(req->S), uname); |
795 |
return FALSE; |
return FALSE; |