Browse Source

Add option EnableNACM

Serj Kalichev 10 months ago
parent
commit
7d5be44093
9 changed files with 86 additions and 75 deletions
  1. 0 1
      bin/Makefile.am
  2. 9 0
      docs/klish-plugin-sysrepo.ru.md
  3. 0 1
      src/Makefile.am
  4. 67 1
      src/pline.c
  5. 1 0
      src/pline.h
  6. 8 0
      src/plugin.c
  7. 0 3
      src/private.h
  8. 0 69
      src/sr_copypaste.c
  9. 1 0
      xml/sysrepo.xml

+ 0 - 1
bin/Makefile.am

@@ -3,6 +3,5 @@ bin_PROGRAMS += \
 
 bin_ytree_SOURCES = \
 	bin/ytree.c \
-	src/sr_copypaste.c \
 	src/pline.c \
 	src/kly.c

+ 9 - 0
docs/klish-plugin-sysrepo.ru.md

@@ -667,6 +667,14 @@ pass <hidden>
 умолчанию имеет значение `2`.
 
 
+### Настройка `EnableNACM`
+
+По умолчанию модуль NACM (ietf-netconf-acm) считается служебным и его настройка
+невозможна. Элементы скрыты от пользователя. Настройка `EnableNACM = y`
+заставляет рассматривать модуль NACM в качестве обычного модуля. Пользователь
+получает возможность управлять NACM.
+
+
 ### Пример настройки модуля
 
 ```
@@ -679,5 +687,6 @@ pass <hidden>
 	Indent = 2
 	HidePasswords = y
 	DefaultKeys = y
+	EnableNACM = n
 </PLUGIN>
 ```

+ 0 - 1
src/Makefile.am

@@ -12,7 +12,6 @@ kplugin_sysrepo_la_SOURCES += \
 	src/plugin.c \
 	src/private.h \
 	src/syms.c \
-	src/sr_copypaste.c \
 	src/show.c \
 	src/pline.h \
 	src/pline.c \

+ 67 - 1
src/pline.c

@@ -23,6 +23,72 @@
 #include "pline.h"
 
 
+static int sr_ly_module_is_internal(const struct lys_module *ly_mod)
+{
+	if (!ly_mod->revision) {
+		return 0;
+	}
+
+	if (!strcmp(ly_mod->name, "ietf-yang-metadata")
+	    && !strcmp(ly_mod->revision, "2016-08-05")) {
+		return 1;
+	} else if (!strcmp(ly_mod->name, "yang")
+		   && !strcmp(ly_mod->revision, "2021-04-07")) {
+		return 1;
+	} else if (!strcmp(ly_mod->name, "ietf-inet-types")
+		   && !strcmp(ly_mod->revision, "2013-07-15")) {
+		return 1;
+	} else if (!strcmp(ly_mod->name, "ietf-yang-types")
+		   && !strcmp(ly_mod->revision, "2013-07-15")) {
+		return 1;
+	}
+
+	return 0;
+}
+
+
+static int sr_module_is_internal(const struct lys_module *ly_mod, bool_t enable_nacm)
+{
+	if (!ly_mod->revision) {
+		return 0;
+	}
+
+	if (sr_ly_module_is_internal(ly_mod)) {
+		return 1;
+	}
+
+	if (!strcmp(ly_mod->name, "ietf-datastores")
+	    && !strcmp(ly_mod->revision, "2018-02-14")) {
+		return 1;
+	} else if (!strcmp(ly_mod->name, "ietf-yang-schema-mount")) {
+		return 1;
+	} else if (!strcmp(ly_mod->name, "ietf-yang-library")) {
+		return 1;
+	} else if (!strcmp(ly_mod->name, "ietf-netconf")) {
+		return 1;
+	} else if (!strcmp(ly_mod->name, "ietf-netconf-with-defaults")
+		   && !strcmp(ly_mod->revision, "2011-06-01")) {
+		return 1;
+	} else if (!strcmp(ly_mod->name, "ietf-origin")
+		   && !strcmp(ly_mod->revision, "2018-02-14")) {
+		return 1;
+	} else if (!strcmp(ly_mod->name, "ietf-netconf-notifications")
+		   && !strcmp(ly_mod->revision, "2012-02-06")) {
+		return 1;
+	} else if (!strcmp(ly_mod->name, "sysrepo")) {
+		return 1;
+	} else if (!strcmp(ly_mod->name, "sysrepo-monitoring")) {
+		return 1;
+	} else if (!strcmp(ly_mod->name, "sysrepo-plugind")) {
+		return 1;
+	} else if (!strcmp(ly_mod->name, "ietf-netconf-acm") && !enable_nacm) {
+		return 1;
+	}
+
+	return 0;
+}
+
+
 static pexpr_t *pexpr_new(void)
 {
 	pexpr_t *pexpr = NULL;
@@ -757,7 +823,7 @@ pline_t *pline_parse(sr_session_ctx_t *sess, faux_argv_t *argv, pline_opts_t *op
 	// Iterate all modules
 	i = 0;
 	while ((module = ly_ctx_get_module_iter(ctx, &i))) {
-		if (sr_module_is_internal(module))
+		if (sr_module_is_internal(module, opts->enable_nacm))
 			continue;
 		if (!module->compiled)
 			continue;

+ 1 - 0
src/pline.h

@@ -123,6 +123,7 @@ typedef struct {
 	bool_t default_keys;
 	bool_t show_default_keys;
 	bool_t hide_passwords;
+	bool_t enable_nacm;
 } pline_opts_t;
 
 

+ 8 - 0
src/plugin.c

@@ -97,6 +97,7 @@ int kplugin_sysrepo_init(kcontext_t *context)
 	udata->opts.default_keys = BOOL_FALSE;
 	udata->opts.show_default_keys = BOOL_FALSE;
 	udata->opts.hide_passwords = BOOL_TRUE;
+	udata->opts.enable_nacm = BOOL_FALSE;
 	parse_plugin_conf(kplugin_conf(plugin), &udata->opts);
 
 	kplugin_set_udata(plugin, udata);
@@ -243,6 +244,13 @@ static int parse_plugin_conf(const char *conf, pline_opts_t *opts)
 			opts->hide_passwords = BOOL_FALSE;
 	}
 
+	if ((val = faux_ini_find(ini, "EnableNACM"))) {
+		if (faux_str_cmp(val, "y") == 0)
+			opts->enable_nacm = BOOL_TRUE;
+		else if (faux_str_cmp(val, "n") == 0)
+			opts->enable_nacm = BOOL_FALSE;
+	}
+
 	faux_ini_free(ini);
 
 	return 0;

+ 0 - 3
src/private.h

@@ -73,9 +73,6 @@ bool_t show_xpath(sr_session_ctx_t *sess, const char *xpath, pline_opts_t *opts)
 void show_subtree(const struct lyd_node *nodes_list, size_t level,
 	enum diff_op op, pline_opts_t *opts);
 
-// Sysrepo copy-paste
-int sr_module_is_internal(const struct lys_module *ly_mod);
-
 // kly helper library
 typedef struct {
 	const struct lysc_node *node;

+ 0 - 69
src/sr_copypaste.c

@@ -1,69 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-
-#include <sysrepo.h>
-#include <sysrepo/xpath.h>
-
-#include "private.h"
-
-
-static int
-sr_ly_module_is_internal(const struct lys_module *ly_mod)
-{
-    if (!ly_mod->revision) {
-        return 0;
-    }
-
-    if (!strcmp(ly_mod->name, "ietf-yang-metadata") && !strcmp(ly_mod->revision, "2016-08-05")) {
-        return 1;
-    } else if (!strcmp(ly_mod->name, "yang") && !strcmp(ly_mod->revision, "2021-04-07")) {
-        return 1;
-    } else if (!strcmp(ly_mod->name, "ietf-inet-types") && !strcmp(ly_mod->revision, "2013-07-15")) {
-        return 1;
-    } else if (!strcmp(ly_mod->name, "ietf-yang-types") && !strcmp(ly_mod->revision, "2013-07-15")) {
-        return 1;
-    }
-
-    return 0;
-}
-
-
-int
-sr_module_is_internal(const struct lys_module *ly_mod)
-{
-    if (!ly_mod->revision) {
-        return 0;
-    }
-
-    if (sr_ly_module_is_internal(ly_mod)) {
-        return 1;
-    }
-
-    if (!strcmp(ly_mod->name, "ietf-datastores") && !strcmp(ly_mod->revision, "2018-02-14")) {
-        return 1;
-    } else if (!strcmp(ly_mod->name, "ietf-yang-schema-mount")) {
-        return 1;
-    } else if (!strcmp(ly_mod->name, "ietf-yang-library")) {
-        return 1;
-    } else if (!strcmp(ly_mod->name, "ietf-netconf")) {
-        return 1;
-    } else if (!strcmp(ly_mod->name, "ietf-netconf-with-defaults") && !strcmp(ly_mod->revision, "2011-06-01")) {
-        return 1;
-    } else if (!strcmp(ly_mod->name, "ietf-origin") && !strcmp(ly_mod->revision, "2018-02-14")) {
-        return 1;
-    } else if (!strcmp(ly_mod->name, "ietf-netconf-notifications") && !strcmp(ly_mod->revision, "2012-02-06")) {
-        return 1;
-    } else if (!strcmp(ly_mod->name, "sysrepo")) {
-        return 1;
-    } else if (!strcmp(ly_mod->name, "sysrepo-monitoring")) {
-        return 1;
-    } else if (!strcmp(ly_mod->name, "sysrepo-plugind")) {
-        return 1;
-    } else if (!strcmp(ly_mod->name, "ietf-netconf-acm")) {
-        return 1;
-    }
-
-    return 0;
-}

+ 1 - 0
xml/sysrepo.xml

@@ -14,6 +14,7 @@
 	DefaultKeys = n
 	ShowDefaultKeys = n
 	HidePasswords = y
+	EnableNACM = n
 </PLUGIN>