瀏覽代碼

Access for COMMANDs

Serj Kalichev 9 年之前
父節點
當前提交
774e9e7d80
共有 1 個文件被更改,包括 10 次插入0 次删除
  1. 10 0
      clish/shell/shell_startup.c

+ 10 - 0
clish/shell/shell_startup.c

@@ -173,11 +173,21 @@ int clish_shell_prepare(clish_shell_t *this)
 		cmd = lub_bintree_findfirst(cmd_tree);
 		for (lub_bintree_iterator_init(&cmd_iter, cmd_tree, cmd);
 			cmd; cmd = lub_bintree_iterator_next(&cmd_iter)) {
+			/* Resolve command aliases */
 			if (!clish_command_alias_to_link(cmd)) {
 				fprintf(stderr, CLISH_XML_ERROR_STR"Broken alias %s\n",
 					clish_command__get_name(cmd));
 				return -1;
 			}
+			/* Check access rights for the COMMAND */
+			if (access_fn && clish_command__get_access(cmd) &&
+				access_fn(this, clish_command__get_access(cmd))) {
+				fprintf(stderr, "Warning: Access denied. Remove COMMAND %s from VIEW %s\n",
+					clish_command__get_name(cmd), clish_view__get_name(view));
+				lub_bintree_remove(cmd_tree, cmd);
+				clish_command_delete(cmd);
+				continue;
+			}
 		}
 	}