From d25d926806a060ee4b477cafd18c2d8023e70fa5 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Thu, 6 Aug 2020 11:04:46 +0200 Subject: [PATCH] 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. --- include/haproxy/proxy-t.h | 1 + src/hlua.c | 28 ++++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) 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. */ -- 2.47.3