コード例 #1
0
ファイル: haserl.c プロジェクト: BashfulBladder/gargoyle
int
main (int argc, char *argv[])
{
#ifndef JUST_LUACSHELL
  token_t *tokenchain = NULL;
  buffer_t script_text;
#endif
  script_t *scriptchain;

  int retval = 0;
  char *filename = NULL;

  argv_t *av = NULL;
  char **av2 = argv;
  int av2c = argc;

  int command;
  int count;

  list_t *env = NULL;

  assignGlobalStartupValues ();
#ifndef JUST_LUACSHELL
  haserl_buffer_init (&script_text);
#endif

  /* if more than argv[1] and argv[1] is not a file */
  switch (argc)
    {
    case 1:
      /* we were run, instead of called as a shell script */
      puts ("This is " PACKAGE_NAME " version " PACKAGE_VERSION "\n"
	    "This program runs as a cgi interpeter, not interactively\n"
	    "Please see:  http://haserl.sourceforge.net\n"
#ifdef USE_LUA
	    "This version includes Lua (precompiled"
#ifdef INCLUDE_LUASHELL
	    " and interpreted"
#endif
	    ")\n"
#endif
#ifdef BASHEXTENSIONS
	    "Unsupported bash extensions supplied by simnux enabled\n"
#endif
	);
      return (0);
      break;
    default:			/* more than one */
      /* split combined #! args - linux bundles them as one */
      command = argc_argv (argv[1], &av, "");

      if (command > 1)
	{
	  /* rebuild argv into new av2 */
	  av2c = argc - 1 + command;
	  av2 = xmalloc (sizeof (char *) * av2c);
	  av2[0] = argv[0];
	  for (count = 1; count <= command; count++)
	    {
	      av2[count] = av[count - 1].string;
	    }
	  for (; count < av2c; count++)
	    {
	      av2[count] = argv[count - command + 1];
	    }
	}

      parseCommandLine (av2c, av2);
      free (av);
      if (av2 != argv)
	free (av2);

      if (optind < av2c)
	{
	  filename = av2[optind];
	}
      else
	{
	  die_with_message (NULL, NULL, "No script file specified");
	}

      break;
    }
    
    if (av2[0] != NULL && command == 1) { //prevents argument reconstruction (update.sh & reboot.sh)
		unsigned int prg_len=strlen(av2[0]);
		if (memcmp(av2[0]+prg_len-4, "i18n", 4) == 0) {
	
			if (global.translationKV_map == NULL) {
				buildTranslationMap ();
			}
			lookup_key (NULL, av2[optind], HASERL_SHELL_SYMBOLIC_LINK);
		
			buffer_destroy (&script_text);
		
			unsigned long num_destroyed;
			destroy_string_map(global.translationKV_map, DESTROY_MODE_IGNORE_VALUES, &num_destroyed);
		
			return (0);
		}
	}

  scriptchain = load_script (filename, NULL);
/* drop permissions */
  BecomeUser (scriptchain->uid, scriptchain->gid);

  /* populate the function pointers based on the shell selected */
  if (strcmp (global.shell, "lua") && strcmp (global.shell, "luac"))
    /* default to "bash" */
    {
#ifdef INCLUDE_BASHSHELL
      shell_exec = &bash_exec;
      shell_echo = &bash_echo;
      shell_eval = &bash_eval;
      shell_setup = &bash_setup;
      shell_doscript = &bash_doscript;
      shell_destroy = &bash_destroy;

#ifdef BASHEXTENSIONS
      shell_if = &bash_if;
      shell_elif = &bash_elif;
      shell_else = &bash_else;
      shell_endif = &bash_endif;
      shell_case = &bash_case;
      shell_when = &bash_when;
      shell_otherwise = &bash_otherwise;
      shell_endcase = &bash_endcase;
      shell_while = &bash_while;
      shell_endwhile = &bash_endwhile;
      shell_until = &bash_until;
      shell_enduntil = &bash_enduntil;
      shell_for = &bash_for;
      shell_endfor = &bash_endfor;
      shell_unless = &bash_unless;
      shell_elun = &bash_elun;
      shell_unelse = &bash_unelse;
      shell_endunless = &bash_endunless;
#endif

#else
      die_with_message (NULL, NULL, "Bash shell is not enabled.");
#endif
    }
  else
    {
#ifdef USE_LUA
      shell_setup = &lua_common_setup;
      shell_destroy = &lua_common_destroy;
      global.var_prefix = "FORM.";
      global.nul_prefix = "ENV.";

      if (global.shell[3] == 'c')	/* luac only */
#ifdef INCLUDE_LUACSHELL
	shell_doscript = &luac_doscript;
#else
	die_with_message (NULL, NULL, "Compiled Lua shell is not enabled.");
#endif
      else
	{
#ifdef INCLUDE_LUASHELL
	  shell_exec = &lua_exec;
	  shell_echo = &lua_echo;
	  shell_eval = &lua_eval;
	  shell_doscript = &lua_doscript;
#else
	  die_with_message (NULL, NULL, "Standard Lua shell is not enabled.");
#endif
	}
#else
      die_with_message (NULL, NULL, "Lua shells are not enabled.");
#endif
    }
コード例 #2
0
ファイル: haserl.c プロジェクト: OPSF/uClinux
int
main (int argc, char *argv[])
{
  #ifndef JUST_LUACSHELL
  token_t *tokenchain = NULL;
  buffer_t script_text;
  #endif
  script_t *scriptchain;

  int retval = 0;
  char *filename = NULL;

  argv_t *av = NULL;
  char **av2;

  int command;
  int count;

  list_t *env = NULL;

  assignGlobalStartupValues();
  #ifndef JUST_LUACSHELL
  buffer_init (&script_text);
  #endif

  /* if more than argv[1] and argv[1] is not a file */
  switch (argc)
    {
    case 1:
      /* we were run, instead of called as a shell script */
      puts ("This is " PACKAGE_NAME " version " PACKAGE_VERSION "\n"
	    "This program runs as a cgi interpeter, not interactively\n"
	    "Please see:  http://haserl.sourceforge.net");
      return (0);
      break;
    case 2:
      filename = argv[1];
      break;
    default:			/* more than two */
      command = argc_argv (argv[1], &av, "");

      /* and we need to add the original argv[0] command for optarg to work */
      av2 = xmalloc (sizeof (char *) * (command + 2));
      av2[0] = argv[0];
      for (count = 0; count < command; count++)
	{
	  av2[count + 1] = av[count].string;
	}
      parseCommandLine (command + 1, av2);
      argv[1] = av[1].string;
      free (av);
      free (av2);
      filename = argv[2];
      break;
      /* we silently ignore 3,4,etc. */
    }


  scriptchain = load_script (filename, NULL);
/* drop permissions */
  BecomeUser (scriptchain->uid, scriptchain->gid);

  /* populate the function pointers based on the shell selected */
  if (strcmp(global.shell, "lua") && strcmp(global.shell, "luac")) /* default to "bash" */
    {
      #ifdef INCLUDE_BASHSHELL
      shell_exec = &bash_exec;
      shell_echo = &bash_echo;
      shell_eval = &bash_eval;
      shell_setup = &bash_setup;
      shell_doscript = &bash_doscript;
      shell_destroy = &bash_destroy;
      #else
      die_with_message (NULL, NULL, "Bash shell is not enabled.");
      #endif
    }
  else
    {
      #ifdef USE_LUA
      shell_setup = &lua_common_setup;
      shell_destroy = &lua_common_destroy;
      global.var_prefix = "FORM.";
      global.nul_prefix = "ENV.";

      if(global.shell[3] == 'c')	/* compiled Lua specific function ptr... */
        #ifdef INCLUDE_LUACSHELL
        shell_doscript = &luac_doscript;
        #else
        die_with_message (NULL, NULL, "Compiled Lua shell is not enabled.");
        #endif
      else
        {
           #ifdef INCLUDE_LUASHELL
          shell_exec = &lua_exec;
          shell_echo = &lua_echo;
          shell_eval = &lua_eval;
          shell_doscript = &lua_doscript;
          #else
          die_with_message (NULL, NULL, "Standard Lua shell is not enabled.");
          #endif
        }
      #else
      die_with_message (NULL, NULL, "Lua shells are not enabled.");
      #endif
    }