GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
KHTTPBASIC_VALIDATE(3) FreeBSD Library Functions Manual KHTTPBASIC_VALIDATE(3)

khttpbasic_validate
validate an HTTP basic authorisation request

library “libkcgi”

#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);

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

In both cases, the request is validated by base64-encoding user:password and comparing it to the given token.

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

In the following fragment, assume r a pointer to a struct kreq successfully initialised by khttp_parse(3). If validation is not provided, it returns an HTTP 401. The expected principle is “james”, password “bond”. Otherwise, it returns an HTTP 200.
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]);

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

Written by Kristaps Dzonsons <kristaps@bsd.lv>.
June 12, 2022 FreeBSD 13.1-RELEASE

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.