mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-02-21 09:51:50 +00:00
Add 'api.restful.authorization' config option
This commit is contained in:
parent
5b75221c91
commit
24266b5f3b
@ -741,8 +741,6 @@ int cf_cmp_radio_type(const short *a, const short *b)
|
|||||||
return *a < *b ? -1 : *a > *b ? 1 : 0;
|
return *a < *b ? -1 : *a > *b ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int cf_cmp_interface_type(const short *a, const short *b)
|
int cf_cmp_interface_type(const short *a, const short *b)
|
||||||
{
|
{
|
||||||
return *a < *b ? -1 : *a > *b ? 1 : 0;
|
return *a < *b ? -1 : *a > *b ? 1 : 0;
|
||||||
@ -1141,3 +1139,39 @@ int cf_cmp_log_level(const int *a, const int *b)
|
|||||||
{
|
{
|
||||||
return cf_cmp_int(a, b);
|
return cf_cmp_int(a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Config type: http_authorization_schema
|
||||||
|
*
|
||||||
|
* @author Andrew Bettison <andrew@servalproject.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
int cf_opt_http_authorization_scheme(enum http_authorization_scheme *schemap, const char *text)
|
||||||
|
{
|
||||||
|
if (strcasecmp(text, "noauth") == 0) {
|
||||||
|
*schemap = NOAUTH;
|
||||||
|
return CFOK;
|
||||||
|
}
|
||||||
|
if (strcasecmp(text, "basic") == 0) {
|
||||||
|
*schemap = BASIC;
|
||||||
|
return CFOK;
|
||||||
|
}
|
||||||
|
return CFINVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cf_fmt_http_authorization_scheme(const char **textp, const enum http_authorization_scheme *schemap)
|
||||||
|
{
|
||||||
|
const char *t = NULL;
|
||||||
|
switch (*schemap) {
|
||||||
|
case NOAUTH: t = "noauth"; break;
|
||||||
|
case BASIC: t = "basic"; break;
|
||||||
|
}
|
||||||
|
if (!t)
|
||||||
|
return CFINVALID;
|
||||||
|
*textp = str_edup(t);
|
||||||
|
return CFOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cf_cmp_http_authorization_scheme(const enum http_authorization_scheme *a, const enum http_authorization_scheme *b)
|
||||||
|
{
|
||||||
|
return *a < *b ? -1 : *a > *b ? 1 : 0;
|
||||||
|
}
|
||||||
|
@ -489,8 +489,9 @@ VALUE_SUB_STRUCT(user)
|
|||||||
END_ARRAY(10)
|
END_ARRAY(10)
|
||||||
|
|
||||||
STRUCT(api_restful)
|
STRUCT(api_restful)
|
||||||
SUB_STRUCT(userlist, users,)
|
ATOM(enum http_authorization_scheme, authorization, BASIC, http_authorization_scheme,, "The kind of authorization that REST clients must supply")
|
||||||
ATOM(uint32_t, newsince_timeout, 60, uint32_time_interval,, "Time to block while reporting new bundles")
|
SUB_STRUCT(userlist, users,)
|
||||||
|
ATOM(uint32_t, newsince_timeout, 60, uint32_time_interval,, "Time to block while reporting new bundles")
|
||||||
END_STRUCT
|
END_STRUCT
|
||||||
|
|
||||||
STRUCT(api)
|
STRUCT(api)
|
||||||
|
20
httpd.c
20
httpd.c
@ -324,14 +324,20 @@ int is_http_header_complete(const char *buf, size_t len, size_t read_since_last_
|
|||||||
*/
|
*/
|
||||||
static int is_authorized_restful(const struct http_client_authorization *auth)
|
static int is_authorized_restful(const struct http_client_authorization *auth)
|
||||||
{
|
{
|
||||||
if (auth->scheme != BASIC)
|
switch (config.api.restful.authorization) {
|
||||||
return 0;
|
case NOAUTH:
|
||||||
unsigned i;
|
|
||||||
for (i = 0; i != config.api.restful.users.ac; ++i) {
|
|
||||||
if ( strcmp(config.api.restful.users.av[i].key, auth->credentials.basic.user) == 0
|
|
||||||
&& strcmp(config.api.restful.users.av[i].value.password, auth->credentials.basic.password) == 0
|
|
||||||
)
|
|
||||||
return 1;
|
return 1;
|
||||||
|
case BASIC:
|
||||||
|
if (auth->scheme == BASIC) {
|
||||||
|
unsigned i;
|
||||||
|
for (i = 0; i != config.api.restful.users.ac; ++i) {
|
||||||
|
if ( strcmp(config.api.restful.users.av[i].key, auth->credentials.basic.user) == 0
|
||||||
|
&& strcmp(config.api.restful.users.av[i].value.password, auth->credentials.basic.password) == 0
|
||||||
|
)
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user