From: Christopher Faulet Date: Thu, 6 Aug 2020 09:04:46 +0000 (+0200) Subject: MINOR: lua: Add support for userlist as fetches and converters arguments X-Git-Tag: v2.3-dev3~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d25d926806a060ee4b477cafd18c2d8023e70fa5;p=thirdparty%2Fhaproxy.git MINOR: lua: Add support for userlist as fetches and converters arguments It means now http_auth() and http_auth_group() sample fetches are now exported to the lua. --- diff --git a/include/haproxy/proxy-t.h b/include/haproxy/proxy-t.h index 6216524d48..bd68beebde 100644 --- a/include/haproxy/proxy-t.h +++ b/include/haproxy/proxy-t.h @@ -39,6 +39,7 @@ #include #include #include +#include /* values for proxy->state */ enum pr_state { diff --git a/src/hlua.c b/src/hlua.c index 7df5ef8080..10fcf3affe 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -593,6 +594,7 @@ __LJMP int hlua_lua2arg_check(lua_State *L, int first, struct arg *argp, int min_arg; int i, idx; struct proxy *px; + struct userlist *ul; const char *msg = NULL; char *sname, *pname; @@ -821,11 +823,23 @@ __LJMP int hlua_lua2arg_check(lua_State *L, int first, struct arg *argp, argp[idx].type = ARGT_MSK6; break; - case ARGT_MAP: - case ARGT_REG: case ARGT_USR: - msg = "type not yet supported"; - goto error; + if (argp[idx].type != ARGT_STR) { + msg = "string expected"; + goto error; + } + if (p->uri_auth && p->uri_auth->userlist && + !strcmp(p->uri_auth->userlist->name, argp[idx].data.str.area)) + ul = p->uri_auth->userlist; + else + ul = auth_find_userlist(argp[idx].data.str.area); + + if (!ul) { + msg = lua_pushfstring(L, "unable to find userlist '%s'", argp[idx].data.str.area); + goto error; + } + argp[idx].type = ARGT_USR; + argp[idx].data.usr = ul; break; case ARGT_STR: @@ -836,6 +850,12 @@ __LJMP int hlua_lua2arg_check(lua_State *L, int first, struct arg *argp, argp[idx].data.str = tmp; break; + case ARGT_MAP: + case ARGT_REG: + msg = "type not yet supported"; + goto error; + break; + } /* Check for type of argument. */