Browse Source

Add shell_access.c file

Serj Kalichev 9 years ago
parent
commit
077c82cc1f
5 changed files with 49 additions and 14 deletions
  1. 2 0
      bin/clish.c
  2. 3 0
      clish/shell.h
  3. 1 0
      clish/shell/module.am
  4. 14 0
      clish/shell/shell_access.c
  5. 29 14
      clish/shell/shell_plugin.c

+ 2 - 0
bin/clish.c

@@ -305,6 +305,8 @@ int main(int argc, char **argv)
 		if ((sym = clish_shell_get_hook(shell, CLISH_SYM_TYPE_LOG)))
 			clish_sym__set_permanent(sym, BOOL_FALSE);
 	}
+	/* Check access rights of VIEWs, COMMANDs etc. */
+	clish_shell_check_access(shell);
 
 	/* Set source of command stream: files or interactive tty */
 	if(optind < argc) {

+ 3 - 0
clish/shell.h

@@ -203,6 +203,9 @@ void *clish_shell__del_udata(clish_shell_t *instance, const char *name);
 int clish_shell__set_udata(clish_shell_t *instance,
 	const char *name, void *data);
 
+/* Access functions */
+int clish_shell_check_access(clish_shell_t *instance);
+
 _END_C_DECL
 
 #endif				/* _clish_shell_h */

+ 1 - 0
clish/shell/module.am

@@ -23,6 +23,7 @@ libclish_la_SOURCES += \
 	clish/shell/shell_expat.c \
 	clish/shell/shell_udata.c \
 	clish/shell/shell_misc.c \
+	clish/shell/shell_access.c \
 	clish/shell/context.c
 
 

+ 14 - 0
clish/shell/shell_access.c

@@ -0,0 +1,14 @@
+/*
+ * shell_access.c
+ */
+#include <string.h>
+
+#include "private.h"
+
+/*-------------------------------------------------------- */
+int clish_shell_check_access(clish_shell_t *this)
+{
+
+
+	return 0;
+}

+ 29 - 14
clish/shell/shell_plugin.c

@@ -139,31 +139,46 @@ clish_sym_t *clish_shell_add_unresolved_sym(clish_shell_t *this,
 	return clish_shell_add_sym(this, NULL, name, type);
 }
 
+/*----------------------------------------------------------------------- */
+/* Link one unresolved symbol.
+ * sym - unresolved symbol
+ * Returns 0 if the symbol was succesfully resolved
+ */
+static int link_unresolved_sym(clish_shell_t *this, clish_sym_t *sym)
+{
+	clish_sym_t *plugin_sym;
+	char *sym_name = NULL;
+	int sym_type;
+
+	if (clish_sym__get_func(sym)) /* Don't relink non-null fn */
+		return 0;
+	sym_name = clish_sym__get_name(sym);
+	sym_type = clish_sym__get_type(sym);
+	plugin_sym = plugins_find_sym(this, sym_name, sym_type);
+	if (!plugin_sym) {
+		fprintf(stderr, "Error: Can't resolve symbol %s.\n",
+			sym_name);
+		return -1;
+	}
+	/* Copy symbol attributes */
+	clish_sym_clone(sym, plugin_sym);
+
+	return 0;
+}
+
 /*----------------------------------------------------------------------- */
 /* Link unresolved symbols */
 int clish_shell_link_plugins(clish_shell_t *this)
 {
-	clish_sym_t *sym, *plugin_sym;
+	clish_sym_t *sym;
 	lub_list_node_t *iter;
-	char *sym_name = NULL;
-	int sym_type;
 
 	/* Iterate elements */
 	for(iter = lub_list__get_head(this->syms);
 		iter; iter = lub_list_node__get_next(iter)) {
 		sym = (clish_sym_t *)lub_list_node__get_data(iter);
-		if (clish_sym__get_func(sym)) /* Don't relink non-null fn */
-			continue;
-		sym_name = clish_sym__get_name(sym);
-		sym_type = clish_sym__get_type(sym);
-		plugin_sym = plugins_find_sym(this, sym_name, sym_type);
-		if (!plugin_sym) {
-			fprintf(stderr, "Error: Can't resolve symbol %s.\n",
-				sym_name);
+		if (link_unresolved_sym(this, sym) < 0)
 			return -1;
-		}
-		/* Copy symbol attributes */
-		clish_sym_clone(sym, plugin_sym);
 	}
 
 	return 0;