]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: cli: store CLI level in the appctx
authorWilliam Lallemand <wlallemand@haproxy.com>
Thu, 13 Dec 2018 08:05:44 +0000 (09:05 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 13 Dec 2018 08:45:16 +0000 (09:45 +0100)
Store and check the level in the appctx in order to allow dynamic
permission changes over the CLI.

include/types/applet.h
src/cli.c

index d9cd6a026e31f9330ba193fce9bbb09497faa1ac..9fc9ec8f45c9bbd4a00777911529685f38d72825 100644 (file)
@@ -66,6 +66,7 @@ struct appctx {
        void (*io_release)(struct appctx *appctx);  /* used within the cli_io_handler when st0 = CLI_ST_CALLBACK,
                                                       if the command is terminated or the session released */
        int cli_severity_output;        /* used within the cli_io_handler to format severity output of informational feedback */
+       int cli_level;              /* the level of CLI which can be lowered dynamically */
        struct buffer_wait buffer_wait; /* position in the list of objects waiting for a buffer */
        unsigned long thread_mask;      /* mask of thread IDs authorized to process the applet */
        struct task *t;                  /* task associated to the applet */
index 0bb5bb018759ff381faf6db4511bf6f12e408a81..adefcfa1d41c4665fb0b346b2fd8a7a17f9dddca 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -381,10 +381,8 @@ static int stats_parse_global(char **args, int section_type, struct proxy *curpx
  */
 int cli_has_level(struct appctx *appctx, int level)
 {
-       struct stream_interface *si = appctx->owner;
-       struct stream *s = si_strm(si);
 
-       if ((strm_li(s)->bind_conf->level & ACCESS_LVL_MASK) < level) {
+       if ((appctx->cli_level & ACCESS_LVL_MASK) < level) {
                appctx->ctx.cli.severity = LOG_ERR;
                appctx->ctx.cli.msg = stats_permission_denied_msg;
                appctx->st0 = CLI_ST_PRINT;
@@ -563,6 +561,7 @@ static void cli_io_handler(struct appctx *appctx)
                        /* reset severity to default at init */
                        appctx->cli_severity_output = bind_conf->severity_output;
                        appctx->st0 = CLI_ST_GETREQ;
+                       appctx->cli_level = bind_conf->level;
                }
                else if (appctx->st0 == CLI_ST_END) {
                        /* Let's close for real now. We just close the request