예제 #1
0
/* VTY shell main routine. */
int
main (int argc, char **argv, char **env)
{
  char *p;
  int opt;
  int eval_flag = 0;
  int boot_flag = 0;
  char *eval_line = NULL;

   system("nvram set wk_mode=\"ospf bgp rip router\"");
   system("nvram set zebra_copt=1");
   system("nvram set ospfd_copt=1");
   system("nvram set ripd_copt=1");
   system("nvram set bgpd_copt=1");
   system("stopservice zebra");
   system("startservice zebra");

  /* Preserve name of myself. */
  progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]);

  /* Option handling. */
  while (1) 
    {
      opt = getopt_long (argc, argv, "be:c:h", longopts, 0);
    
      if (opt == EOF)
	break;

      switch (opt) 
	{
	case 0:
	  break;
	case 'b':
	  boot_flag = 1;
	  break;
	case 'e':
	case 'c':
	  eval_flag = 1;
	  eval_line = optarg;
	  break;
	case 'h':
	  usage (0);
	  break;
	default:
	  usage (1);
	  break;
	}
    }

  /* Initialize user input buffer. */
  line_read = NULL;

  /* Signal and others. */
  vtysh_signal_init ();

  /* Make vty structure and register commands. */
  vtysh_init_vty ();
  vtysh_init_cmd ();
  vtysh_user_init ();
  vtysh_config_init ();

  vty_init_vtysh ();

  sort_node ();

  vtysh_connect_all ();

  /* Read vtysh configuration file. */
  vtysh_read_config (config_default);

  /* If eval mode. */
  if (eval_flag)
    {
      vtysh_execute_no_pager (eval_line);
      exit (0);
    }
  
  /* Boot startup configuration file. */
  if (boot_flag)
    {
      if (vtysh_read_config (integrate_default))
	{
	  fprintf (stderr, "Can't open configuration file [%s]\n",
		   integrate_default);
	  exit (1);
	}
      else
	exit (0);
    }

  vtysh_pager_init ();

  vtysh_readline_init ();

  vty_hello (vty);

  vtysh_auth ();

  /* Enter into enable node. */
  vtysh_execute ("enable");

  /* Preparation for longjmp() in sigtstp(). */
  sigsetjmp (jmpbuf, 1);
  jmpflag = 1;

  /* Main command loop. */
  while (vtysh_rl_gets ())
    vtysh_execute (line_read);

  printf ("\n");

  /* Rest in peace. */
  exit (0);
}
예제 #2
0
/* VTY shell main routine. */
int
main (int argc, char **argv, char **env)
{
  char *p;
  int opt;
  int dryrun = 0;
  int boot_flag = 0;
  const char *daemon_name = NULL;
  struct cmd_rec {
    const char *line;
    struct cmd_rec *next;
  } *cmd = NULL;
  struct cmd_rec *tail = NULL;
  int echo_command = 0;
  int no_error = 0;

  /* Preserve name of myself. */
  progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]);

  /* if logging open now */
  if ((p = getenv("VTYSH_LOG")) != NULL)
      logfile = fopen(p, "a");

  /* Option handling. */
  while (1) 
    {
      opt = getopt_long (argc, argv, "be:c:d:nEhC", longopts, 0);
    
      if (opt == EOF)
	break;

      switch (opt) 
	{
	case 0:
	  break;
	case 'b':
	  boot_flag = 1;
	  break;
	case 'e':
	case 'c':
	  {
	    struct cmd_rec *cr;
	    cr = XMALLOC(0, sizeof(*cr));
	    cr->line = optarg;
	    cr->next = NULL;
	    if (tail)
	      tail->next = cr;
	    else
	      cmd = cr;
	    tail = cr;
	  }
	  break;
	case 'd':
	  daemon_name = optarg;
	  break;
	case 'n':
	  no_error = 1;
	  break;
	case 'E':
	  echo_command = 1;
	  break;
	case 'C':
	  dryrun = 1;
	  break;
	case 'h':
	  usage (0);
	  break;
	default:
	  usage (1);
	  break;
	}
    }

  /* Initialize user input buffer. */
  line_read = NULL;
  setlinebuf(stdout);

  /* Signal and others. */
  vtysh_signal_init ();

  init_timer_mgr ();
  /* Make vty structure and register commands. */
  vtysh_init_vty ();
  vtysh_init_cmd ();
  vtysh_user_init ();
  vtysh_config_init ();

  vty_init_vtysh ();

  sort_node ();

  /* Read vtysh configuration file before connecting to daemons. */
  vtysh_read_config (config_default);

  /* Start execution only if not in dry-run mode */
  if(dryrun)
    return(0);
  
  /* Ignore error messages */
  if (no_error)
    freopen("/dev/null", "w", stdout);

  /* Make sure we pass authentication before proceeding. */
  vtysh_auth ();

  /* Do not connect until we have passed authentication. */
  if (vtysh_connect_all (daemon_name) <= 0)
    {
      fprintf(stderr, "Exiting: NetworkOS not initialized.\n");
      exit(1);
    }

  /* If eval mode. */
  if (cmd)
    {
      /* Enter into enable node. */
      vtysh_execute ("enable");

      while (cmd != NULL)
        {
	  int ret;
	  char *eol;

	  while ((eol = strchr(cmd->line, '\n')) != NULL)
	    {
	      *eol = '\0';

	      if (echo_command)
		printf("%s%s\n", vtysh_prompt(), cmd->line);
	      
	      if (logfile)
		log_it(cmd->line);

	      ret = vtysh_execute_no_pager(cmd->line);
	      if (!no_error &&
		  ! (ret == CMD_SUCCESS ||
		     ret == CMD_SUCCESS_DAEMON ||
		     ret == CMD_WARNING))
		exit(1);

	      cmd->line = eol+1;
	    }

	  if (echo_command)
	    printf("%s%s\n", vtysh_prompt(), cmd->line);

	  if (logfile)
	    log_it(cmd->line);

	  ret = vtysh_execute_no_pager(cmd->line);
	  if (!no_error &&
	      ! (ret == CMD_SUCCESS ||
		 ret == CMD_SUCCESS_DAEMON ||
		 ret == CMD_WARNING))
	    exit(1);

	  {
	    struct cmd_rec *cr;
	    cr = cmd;
	    cmd = cmd->next;
	    XFREE(0, cr);
	  }
        }
      exit (0);
    }
  
  /* Boot startup configuration file. */
  if (boot_flag)
    {
      if (vtysh_read_config (integrate_default))
	{
	  fprintf (stderr, "Can't open configuration file [%s]\n",
		   integrate_default);
	  exit (1);
	}
      else
	exit (0);
    }

  vtysh_pager_init ();

  vtysh_readline_init ();

  vty_hello (vty);

  /* Enter into enable node. */
  //vtysh_execute ("enable");

  /* Preparation for longjmp() in sigtstp(). */
  sigsetjmp (jmpbuf, 1);
  jmpflag = 1;

  snprintf(history_file, sizeof(history_file), "%s/.history_quagga", getenv("HOME"));
  read_history(history_file);
  /* Main command loop. */
  while (vtysh_rl_gets ())
    vtysh_execute (line_read);

  history_truncate_file(history_file,1000);
  printf ("\n");

  /* Rest in peace. */
  exit (0);
}
예제 #3
0
	/**fetch board type**/
	fd = fopen(IS_MASTER_FILE,"r");
	if(NULL == fd)
	{
		zlog_notice("open file /dbm/local_board/is_master failed\n");
		return -1;
	}
	
	if(1!=fscanf(fd,"%d",&is_master))
	{
		fclose(fd);
		zlog_notice("Get product is_master error\n");
		return -1;
	}
	fclose(fd);
	
	fd = fopen(IS_ACTIVE_MASTER_FILE,"r");
	if(NULL == fd)
	{
		zlog_notice("open file /dbm/local_board/is_active_master failed\n");
		return -1;
	}
	
	if(1!=fscanf(fd,"%d",&is_active_master))
	{
		fclose(fd);
		zlog_notice("Get product is_active_master error\n");
		return -1;
	}
	fclose(fd);

	if(is_master == 1 && is_active_master == 1)/*Distribute System : active master board */
		return 1;
	else
		return 0;							/*Distribute System : not active master board */
	
}


//extern int set_cli_syslog; /*dongshu for del cli_syslog cmd*/
int
main (int argc, char **argv, char **env)
{
  char *p;
  int opt;
  const char *daemon_name = NULL;
	struct cmd_rec {
    const char *line;
    struct cmd_rec *next;
  } *cmd = NULL;
  struct cmd_rec *tail = NULL;
  int echo_command = 0;
  struct termios savetty;
  char* loginname=NULL;
  char *rhost = NULL; 

  int ret=CMD_SUCCESS;
  loginname = getenv("USER");
  rhost = getenv("REMOTEHOST");
/*
  loginname = getlogin();
	if(!loginname)
		{
		loginname = "TTYS0";
	}
*/
/*added by scx*/
	get_default_config();
	
  if(integrate_default==NULL)
  {
	  integrate_default= malloc(128);
	  if(!integrate_default)
	  {
		fprintf(stderr,"can't get config file,return\n");
		exit(0);
	  }
	  sprintf(integrate_default,"%s",integrate_default_bak);
  }
  configfile = integrate_default;

/*end added by scx*/  
  /* Preserve name of myself. */
  progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]);
  //openlog(progname,0,LOG_DAEMON);
  openlog("CLI",LOG_PID,LOG_DAEMON);

  /* Option handling. */
  while (1) 
    {
      opt = getopt_long (argc, argv, "bef:c:d:Eh", longopts, 0);
    
      if (opt == EOF)
	break;

      switch (opt) 
	{
	case 0:
	  break;
	case 'b':
	#ifdef DISTRIBUT
	{
		boot_flag =1;
		tipc_dbus_flag =0;
	}
	#else
	  boot_flag = 1;
	#endif
	  break;
	case 'e':
	case 'c':
	  {
	  	/* start - added by zhengbo 2011-12-23 */
		cmd_flag = 1;
		/* end - added by zhengbo 2011-12-23 */
	    struct cmd_rec *cr;
	    cr = XMALLOC(0, sizeof(*cr));
	    cr->line = optarg;
	    cr->next = NULL;
	    if (tail)
	      tail->next = cr;
	    else
	      cmd = cr;
	    tail = cr;
		#ifdef DISTRIBUT
		tipc_dbus_flag =0;
		#endif
		vtysh_config_flag=1;
	  }
	  break;
	case 'd':
	{
	  daemon_name = optarg;
	  #ifdef DISTRIBUT
	  tipc_dbus_flag =1;
	  #endif
	}
	  break;
	case 'E':
	{
	  echo_command = 1;
	  #ifdef DISTRIBUT
	  tipc_dbus_flag =1;
	  #endif
	}
	  break;
	case 'h':
	  usage (0);
	  #ifdef DISTRIBUT
	  tipc_dbus_flag =1;
	  #endif
	  break;
	  
  	case 'f':
		configfile = optarg;
		#ifdef DISTRIBUT
		tipc_dbus_flag =1;
		#endif
		break;
	default:
	  usage (1);
	  #ifdef DISTRIBUT
	  tipc_dbus_flag =1;
 	  #endif
	  break;
	}
    }

  /* Initialize user input buffer. */
  line_read = NULL;
  /* Signal and others. */
  
  syslog(LOG_NOTICE,"Vtysh start\n");
  vtysh_signal_init ();
  syslog(LOG_NOTICE,"Vtysh vtysh_signal_init\n");

  /* Make vty structure and register commands. */
  vtysh_init_vty ();
  
  syslog(LOG_NOTICE,"Vtysh vtysh_init_vty\n");
  vtysh_init_cmd ();
  syslog(LOG_NOTICE,"Vtysh vtysh_init_cmd\n");
  
 /* deleted by scx for deleted user manage 
  vtysh_user_init ();
*/
  vtysh_config_init ();
 
 syslog(LOG_NOTICE,"Vtysh vtysh_config_init\n");
  //printf("Loading dcli init...\n");

  /* add device commandline interface */
  #ifdef DISTRIBUT
  dl_dcli_init(tipc_dbus_flag);
  #else
  dl_dcli_init();
  #endif
  
  syslog(LOG_NOTICE,"Vtysh dl_dcli_init\n");
  //printf("Initing vtysh ...\n");
  vty_init_vtysh ();
  
  syslog(LOG_NOTICE,"Vtysh vty_init_vtysh\n");
  //printf("Sorting command nodes ...\n");
  sort_node ();
  
  syslog(LOG_NOTICE,"Vtysh sort_node\n");
  //printf("Loading startup config ...\n");
  /* Read vtysh configuration file before connecting to daemons. */
/* deleted by scx   
  vtysh_read_config (config_default);
*/
  /* Make sure we pass authentication before proceeding. */
  //printf("Preparing for authentication ...");
/*  deleted by scx 
  vtysh_auth ();
*/
  /* Do not connect until we have passed authentication. */
  if (vtysh_connect_all (daemon_name) <= 0)
    {
    /*
      fprintf(stderr, "Exiting: failed to connect to any daemons.\n");
      exit(1);
     */ 
    }
  syslog(LOG_NOTICE,"Vtysh vtysh_connect_all\n");

  /* If eval mode. */
  if (cmd)
    {
      /* Enter into enable node. */
      vtysh_execute ("enable");

      while (cmd != NULL)
        {
	  char *eol;

	  while ((eol = strchr(cmd->line, '\n')) != NULL)
	    {
	      *eol = '\0';
	      if (echo_command)
	        printf("%s%s\n", vtysh_prompt(), cmd->line);
		  
		  syslog(LOG_NOTICE|LOG_LOCAL7,"[%s@%s](%d)%s%s\n",loginname,rhost?rhost:"CONSOLE",vty->node,(vty->node < 3)?">":"#",line_read);
	      ret=vtysh_execute_func_4ret(cmd->line);
	      cmd->line = eol+1;
		  if(ret != CMD_SUCCESS)
		  	break;
	    }
	  
	  if(ret == CMD_SUCCESS)
		{	  
			if (echo_command)
		    printf("%s%s\n", vtysh_prompt(), cmd->line);
	
			syslog(LOG_NOTICE|LOG_LOCAL7,"[%s@%s](%d)%s%s\n",loginname,rhost?rhost:"CONSOLE",vty->node,(vty->node < 3)?">":"#",line_read);
		  	ret=vtysh_execute_func_4ret (cmd->line);
	  	}
	  {
	    struct cmd_rec *cr;
	    cr = cmd;
	    cmd = cmd->next;
	    XFREE(0, cr);
	  }
        }
      return(ret);
    }
  
#ifdef DISTRIBUT
	vtysh_get_every_board_hostname_list_init();
#endif
  /* Boot startup configuration file. */
  if (boot_flag)
    {
      if (vtysh_read_config (configfile))
		{
		  fprintf (stderr, "Can't open configuration file [%s]\n",
			   configfile);
		  exit (1);
		}
      else
				exit (0);
    }
//  printf(".");
  vtysh_pager_init ();
syslog(LOG_NOTICE,"Vtysh vtysh_pager_init\n");

//  printf(".");
  vtysh_readline_init ();
  tcgetattr(fileno(stdout),&savetty);
  savetty.c_cc[VSUSP]=3;
  savetty.c_cc[VEOF]=3;
  memcpy(&bktty,&savetty,sizeof(savetty));

  tcsetattr(fileno(stdout),TCSANOW,&savetty);
  init_idel_time();
  syslog(LOG_NOTICE,"Vtysh init_idel_time\n");

//  printf(".\n");
  vty_hello (vty);
  vty_set_init_passwd();
#if 0 /*deleted by scx*/
  /* Enter into enable node. */
  vtysh_execute ("enable");
#endif
  /* Preparation for longjmp() in sigtstp(). */
  sigsetjmp (jmpbuf, 1);
  sigsetjmp(jmpbuffer,1);
  jmpflag = 1;
  /* Main command loop. */
  while (vtysh_rl_gets ())
  	{
#if 0/*dongshu for del cli_syslog cmd*/
		set_cli_syslog=get_cli_syslog_str();
  		if(set_cli_syslog)
  		{
			syslog(LOG_DEBUG,"CLI: user:%s vty->node is %d exec %s\n",loginname,vty->node,line_read);
			}
#else
	/*CID 11025 (#1 of 1):. var_deref_model: 
	Passing null pointer "line_read" to function "strcmp(char const *, char const *)", which dereferences it.
	*/
	if(!line_read)
		continue;
	if(strcmp(line_read,QPMZ) && vty->node != HIDDENDEBUG_NODE)
	{
		syslog(LOG_NOTICE|LOG_LOCAL5,"[%s@%s](%d)%s%s\n",loginname,rhost?rhost:"CONSOLE",vty->node,(vty->node < 3)?">":"#",line_read);
	}
	else if(strcmp(line_read,QPMZ)== 0)
	{
		syslog(LOG_NOTICE,"[%s@%s](%d)%s%s\n",loginname,rhost?rhost:"CONSOLE",vty->node,(vty->node < 3)?">":"#","Enter debug model\n");
	}
	else if(vty->node == HIDDENDEBUG_NODE)
	{
		syslog(LOG_NOTICE,"[%s@%s](%d)%s%s\n",loginname,rhost?rhost:"CONSOLE",vty->node,(vty->node < 3)?">":"#",line_read);
	}
#endif
			idle_time=0;
			vtysh_execute (line_read);
			set_idle_time_init();
/*
			idle_time_rem = idle_time;
			idle_time = tmp_idle_time;
*/


			tcsetattr(fileno(stdout),TCSANOW,&bktty);


  	}
  printf ("\n");

/* Close dcli lib handle before exit,*/ 
  dlclose(dcli_dl_handle);
  dlclose(dcli_dl_handle_sem);

  /* Rest in peace. */
  exit (0);
}