summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2021-03-25 16:53:33 -0500
committerJohn Estabrook <jestabro@vyos.io>2021-05-14 10:03:40 -0500
commit4903dc924fe79711e47840faecb58030c0ecc98d (patch)
tree127cc66195d18d0203510196790be1407aa545ce
parentc44599db534a4dcc47f5f4f22fb60c67943101bd (diff)
downloadvyos-1x-4903dc924fe79711e47840faecb58030c0ecc98d.tar.gz
vyos-1x-4903dc924fe79711e47840faecb58030c0ecc98d.zip
configd: T3426: add support for script arguments to vyos-configd
(cherry picked from commit b3d914edcb506bb25c3798683cda341b8acbb0ad)
-rwxr-xr-xsrc/services/vyos-configd19
-rw-r--r--src/shim/vyshim.c2
2 files changed, 13 insertions, 8 deletions
diff --git a/src/services/vyos-configd b/src/services/vyos-configd
index 6004e9b95..6f770b696 100755
--- a/src/services/vyos-configd
+++ b/src/services/vyos-configd
@@ -132,7 +132,9 @@ def explicit_print(path, mode, msg):
except OSError:
logger.critical("error explicit_print")
-def run_script(script, config) -> int:
+def run_script(script, config, args) -> int:
+ if args:
+ script.argv = args
config.set_level([])
try:
c = script.get_config(config)
@@ -206,23 +208,26 @@ def process_node_data(config, data) -> int:
return R_ERROR_DAEMON
script_name = None
+ args = None
- res = re.match(r'^.+\/([^/].+).py(VYOS_TAGNODE_VALUE=.+)?', data)
+ res = re.match(r'^(VYOS_TAGNODE_VALUE=[^/]+)?.*\/([^/]+).py(.*)', data)
if res.group(1):
- script_name = res.group(1)
- if res.group(2):
- env = res.group(2).split('=')
+ env = res.group(1).split('=')
os.environ[env[0]] = env[1]
-
+ if res.group(2):
+ script_name = res.group(2)
if not script_name:
logger.critical(f"Missing script_name")
return R_ERROR_DAEMON
+ if res.group(3):
+ args = res.group(3).split()
+ args.insert(0, f'{script_name}.py')
if script_name not in include_set:
return R_PASS
with stdout_redirected(session_out, session_mode):
- result = run_script(conf_mode_scripts[script_name], config)
+ result = run_script(conf_mode_scripts[script_name], config, args)
return result
diff --git a/src/shim/vyshim.c b/src/shim/vyshim.c
index e6d1d5a78..cae8b6152 100644
--- a/src/shim/vyshim.c
+++ b/src/shim/vyshim.c
@@ -81,7 +81,7 @@ int main(int argc, char* argv[])
debug_print("Connecting to vyos-configd ...\n");
zmq_connect(requester, SOCKET_PATH);
- for (int i = argc-1; i > 0 ; i--) {
+ for (int i = 1; i < argc ; i++) {
strncat(&string_node_data[0], argv[i], 127);
}