Small refactoring.

master
Nicolas Favre-Felix 14 years ago
parent 37b1281f0d
commit 17c0c59a10

13
cmd.c

@ -36,7 +36,7 @@ cmd_free(struct cmd *c) {
}
int
cmd_authorized(struct conf *cfg, struct evhttp_request *rq, const char *verb, size_t verb_len) {
cmd_authorized(struct cmd *cmd, struct conf *cfg, struct evhttp_request *rq) {
char *always_off[] = {"MULTI", "EXEC", "WATCH", "DISCARD", "SUBSCRIBE", "PSUBSCRIBE"};
@ -48,9 +48,12 @@ cmd_authorized(struct conf *cfg, struct evhttp_request *rq, const char *verb, si
u_short client_port;
in_addr_t client_addr;
const char *cmd_name = cmd->argv[0];
size_t cmd_len = cmd->argv_len[0];
/* some commands are always disabled, regardless of the config file. */
for(i = 0; i < sizeof(always_off) / sizeof(always_off[0]); ++i) {
if(strncasecmp(always_off[i], verb, verb_len) == 0) {
if(strncasecmp(always_off[i], cmd_name, cmd_len) == 0) {
return 0;
}
}
@ -66,14 +69,14 @@ cmd_authorized(struct conf *cfg, struct evhttp_request *rq, const char *verb, si
/* go through authorized commands */
for(i = 0; i < a->enabled.count; ++i) {
if(strncasecmp(a->enabled.commands[i], verb, verb_len) == 0) {
if(strncasecmp(a->enabled.commands[i], cmd_name, cmd_len) == 0) {
authorized = 1;
}
}
/* go through unauthorized commands */
for(i = 0; i < a->disabled.count; ++i) {
if(strncasecmp(a->disabled.commands[i], verb, verb_len) == 0) {
if(strncasecmp(a->disabled.commands[i], cmd_name, cmd_len) == 0) {
authorized = 0;
}
}
@ -122,7 +125,7 @@ cmd_run(struct server *s, struct evhttp_request *rq,
cmd->argv_len[0] = cmd_len;
/* check that the client is able to run this command */
if(!cmd_authorized(s->cfg, rq, cmd->argv[0], cmd->argv_len[0])) {
if(!cmd_authorized(cmd, s->cfg, rq)) {
return -1;
}

@ -133,6 +133,7 @@ conf_parse_acl(json_t *j) {
pos = base64_encode_block(plain, (int)plain_len, a->http_basic_auth, &b64); /* FIXME: check return value */
base64_encode_blockend(a->http_basic_auth + pos, &b64);
/* end string with \0 rather than \n */
if((p = strchr(a->http_basic_auth + pos, '\n'))) {
*p = 0;
}

Loading…
Cancel
Save