http_servlet_basicauth
—
HTTP basic authentication servlet
PDEL Library (libpdel, -lpdel)
#include
<sys/types.h>
#include
<stdio.h>
#include
<netinet/in.h>
#include
<openssl/ssl.h>
#include
<pdel/http/http_defs.h>
#include
<pdel/http/http_server.h>
#include
<pdel/http/servlet/basicauth.h>
struct http_servlet *
http_servlet_basicauth_create
(
http_servlet_basicauth_t
*auth,
void
*arg,
void
(*destroy)(void *));
http_servlet_basicauth_create
() creates a new
servlet that implements HTTP basic authentication. The servlet should be
registered with a lower order than the other servlets that it protects, so
that it executes first.
auth is a pointer to a function having this
type:
typedef const char *http_servlet_basicauth_t(void *arg,
struct http_request *req, const char *username,
const char *password);
arg is the opaque cookie supplied to
http_servlet_basicauth_create
().
req is the HTTP request object and
username and
password are the credentials supplied with
the request, or the empty string if none were supplied.
auth
() should return
NULL
to allow access. Otherwise, it should
return the authorization realm string to deny access. This string is not freed
by the calling function.
Warning: this is
reversed from usual semantics; returning
NULL
indicates success and allows access.
When the servlet is destroyed, if
destroy is
not
NULL
, it will be invoked with
arg as its parameter.
On failure,
http_servlet_basicauth_create
()
returns
NULL
and sets
errno to an appropriate value.
http_request(3),
http_response(3),
http_server(3),
http_servlet(3),
http_servlet_cookieauth(3),
libpdel(3)
J. Franks,
P. Hallam-Baker, J.
Hostetler, S. Lawrence, P.
Leach, A. Luotonen, and L.
Stewart, HTTP Authentication: Basic and Digest Access
Authentication, RFC 2617.
The PDEL library was developed at Packet Design, LLC.
http://www.packetdesign.com/
Archie Cobbs
⟨archie@freebsd.org⟩