]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: lua: Add support for userlist as fetches and converters arguments
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 6 Aug 2020 09:04:46 +0000 (11:04 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 7 Aug 2020 12:27:54 +0000 (14:27 +0200)
It means now http_auth() and http_auth_group() sample fetches are now exported
to the lua.

include/haproxy/proxy-t.h
src/hlua.c

index 6216524d482aaa9a0ff63c08a0df35f3a0c3c68a..bd68beebde4d15651a7fe5643372790351ef2de0 100644 (file)
@@ -39,6 +39,7 @@
 #include <haproxy/server-t.h>
 #include <haproxy/tcpcheck-t.h>
 #include <haproxy/thread-t.h>
+#include <haproxy/uri_auth-t.h>
 
 /* values for proxy->state */
 enum pr_state {
index 7df5ef808053cf835207ab88bf97775aa57c0719..10fcf3affeacb1201e4cfe1385ad7f6556bc052a 100644 (file)
@@ -26,6 +26,7 @@
 #include <haproxy/api.h>
 #include <haproxy/applet.h>
 #include <haproxy/arg.h>
+#include <haproxy/auth.h>
 #include <haproxy/cfgparse.h>
 #include <haproxy/channel.h>
 #include <haproxy/cli.h>
@@ -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. */