Working HTTP Basic Auth.

master
Nicolas Favre-Felix 14 years ago
parent 17c0c59a10
commit 23c904ac91

@ -65,7 +65,7 @@ cmd_authorized(struct cmd *cmd, struct conf *cfg, struct evhttp_request *rq) {
/* go through permissions */ /* go through permissions */
for(a = cfg->perms; a; a = a->next) { for(a = cfg->perms; a; a = a->next) {
if(!acl_match(a, &client_addr)) continue; /* match client */ if(!acl_match(a, rq, &client_addr)) continue; /* match client */
/* go through authorized commands */ /* go through authorized commands */
for(i = 0; i < a->enabled.count; ++i) { for(i = 0; i < a->enabled.count; ++i) {

@ -5,6 +5,7 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include <jansson.h> #include <jansson.h>
#include <evhttp.h>
#include <libb64/cencode.h> #include <libb64/cencode.h>
#include "conf.h" #include "conf.h"
@ -174,15 +175,21 @@ conf_parse_acls(json_t *jtab) {
} }
int int
acl_match(struct acl *a, in_addr_t *ip) { acl_match(struct acl *a, struct evhttp_request *rq, in_addr_t *ip) {
/* TODO: add HTTP Basic Auth */ /* check HTTP Basic Auth */
const char *auth;
auth = evhttp_find_header(rq->input_headers, "Authorization");
if(auth && a->http_basic_auth && strncasecmp(auth, "Basic ", 6) == 0) { /* sent auth */
if(strcmp(auth + 6, a->http_basic_auth) != 0) { /* wrong */
return 0;
}
}
/* CIDR check. */
if(a->cidr.enabled == 0) { /* none given, all match */ if(a->cidr.enabled == 0) { /* none given, all match */
return 1; return 1;
} }
/* CIDR check. */
if(((*ip) & a->cidr.mask) == (a->cidr.subnet & a->cidr.mask)) { if(((*ip) & a->cidr.mask) == (a->cidr.subnet & a->cidr.mask)) {
return 1; return 1;
} }

@ -3,6 +3,8 @@
#include <netinet/in.h> #include <netinet/in.h>
struct evhttp_request;
struct acl_commands { struct acl_commands {
unsigned int count; unsigned int count;
char **commands; char **commands;
@ -45,6 +47,6 @@ void
conf_free(struct conf *conf); conf_free(struct conf *conf);
int int
acl_match(struct acl *a, in_addr_t *ip); acl_match(struct acl *a, struct evhttp_request *rq, in_addr_t *ip);
#endif /* CONF_H */ #endif /* CONF_H */

Loading…
Cancel
Save