KHTTPBASIC_VALIDATE(3) Library Functions Manual KHTTPBASIC_VALIDATE(3)

NAME

khttpbasic_validatevalidate an HTTP basic authorisation request

LIBRARY

library “libkcgi”

SYNOPSIS

#include <sys/types.h>
#include <stdarg.h>
#include <stdint.h>
#include <kcgi.h>
int
khttpbasic_validate(struct kreq *req, const char *user, const char *password);

DESCRIPTION

The khttpbasic_validate() function validates the given user and password with the HTTP basic-authorised request req as returned by khttp_parse(3) or khttp_fcgi_parse(3).

RETURN VALUES

khttpbasic_validate() will return zero if validation failed, less than zero if the request was not properly set up for HTTP basic validation (no HTTP method, not a basic request, not already authenticated by the web server), or greater than zero if the validation succeeded.

EXAMPLES

The following parses a request r with a single page “page” and no form inputs. If validation is not provided, it raises an HTTP 401. The expected principle is “james”, password “bond”.
if (KCGI_OK != khttp_parse(&r, NULL, 0, &page, 1, 0)) 
  return 0; 
 
if (khttpbasic_validate(&r, "james", "bond") <= 0) { 
  khttp_head(&r, kresps[KRESP_STATUS], 
    "%s", khttps[KHTTP_401]); 
  khttp_head(&r, kresps[KRESP_WWW_AUTHENTICATE], 
    "basic realm=\"%s\"", "some realm"); 
} else 
  khttp_head(&r, kresps[KRESP_STATUS], 
    "%s", khttps[KHTTP_200]); 
 
khttp_body(&r);

SEE ALSO

kcgi(3), khttp_fcgi_parse(3), khttp_parse(3), khttpdigest_validate(3)

AUTHORS

The khttpbasic_validate() function was written by Kristaps Dzonsons <kristaps@bsd.lv>.
March 22, 2018 OpenBSD 6.2