Ejemplo n.º 1
0
/*****************************************************************
**	reload a zone via "rndc"
*****************************************************************/
int	reload_zone (const char *domain, const zconf_t *z)
{
	char	cmdline[254+1];
	char	str[254+1];
	FILE	*fp;

	assert (z != NULL);
	dbg_val3 ("reload_zone %d :%s: :%s:\n", z->verbosity, domain, z->view);
	if ( z->view )
		snprintf (str, sizeof (str), "\"%s\" in view \"%s\"", domain, z->view);
	else
		snprintf (str, sizeof (str), "\"%s\"", domain);

	lg_mesg (LG_NOTICE, "%s: reload triggered", str);
	verbmesg (1, z, "\tReload zone %s\n", str);

	if ( z->view )
		snprintf (cmdline, sizeof (cmdline), "%s reload %s IN %s", RELOADCMD, domain, z->view);
	else
		snprintf (cmdline, sizeof (cmdline), "%s reload %s", RELOADCMD, domain);

	*str = '\0';
	if ( z->noexec == 0 )
	{
		verbmesg (2, z, "\t  Run cmd \"%s\"\n", cmdline);
		if ( (fp = popen (cmdline, "r")) == NULL || fgets (str, sizeof str, fp) == NULL )
			return -1;
		pclose (fp);
		verbmesg (2, z, "\t  rndc reload return: \"%s\"\n", str_chop (str, '\n'));
	}

	return 0;
}
Ejemplo n.º 2
0
// --------------------
// business stuff
// --------------------
simple_list *read_file_to_list(const char *filename)
{
	char line_buf[MAX_BUF];

	FILE *fp = fopen(filename, "r");
	if (fp == NULL)
	{
		return NULL;
	}

	simple_list *list = simple_list_new();
	while (fgets(line_buf, MAX_BUF, fp))
	{
		simple_list_push_string(list, str_chop(line_buf));
	}

	fclose(fp);
	return list;
}
Ejemplo n.º 3
0
/*****************************************************************
**	dyn_update_freeze ()
*****************************************************************/
int	dyn_update_freeze (const char *domain, const zconf_t *z, int freeze)
{
	char	cmdline[254+1];
	char	str[254+1];
	char	*action;
	FILE	*fp;

	assert (z != NULL);
	if ( freeze )
		action = "freeze";
	else
		action = "thaw";

	if ( z->view )
		snprintf (str, sizeof (str), "\"%s\" in view \"%s\"", domain, z->view);
	else
		snprintf (str, sizeof (str), "\"%s\"", domain);

	lg_mesg (LG_NOTICE, "%s: %s dynamic zone", str, action);
	verbmesg (1, z, "\t%s dynamic zone %s\n", action, str);

	if ( z->view )
		snprintf (cmdline, sizeof (cmdline), "%s %s %s IN %s", RELOADCMD, action, domain, z->view);
	else
		snprintf (cmdline, sizeof (cmdline), "%s %s %s", RELOADCMD, action, domain);

	verbmesg (2, z, "\t  Run cmd \"%s\"\n", cmdline);
	*str = '\0';
	if ( z->noexec == 0 )
	{
		if ( (fp = popen (cmdline, "r")) == NULL || fgets (str, sizeof str, fp) == NULL )
			return -1;
		pclose (fp);
	}

	verbmesg (2, z, "\t  rndc %s return: \"%s\"\n", action, str_chop (str, '\n'));

	return 0;
}
Ejemplo n.º 4
0
VString tilde_expand( const char* a_path )
{
#ifdef _TARGET_UNIX_
  VString path;
  struct passwd* pwd;
  if ( !a_path || !a_path[0] || a_path[0] != '~' )
    return VString( a_path );

  int z = 1; // first after ~
  while( a_path[z] != '/' && a_path[z] != 0 )
    str_add_ch( path, a_path[z++] );

  if ( path == "" )
    path = getenv( "USER" );
  if ( path != "" )
    {
    pwd = getpwnam( path );
    if (!pwd) return VString( a_path );
    path = pwd->pw_dir;
    }
  else
    {
    char* pw_dir = getenv("HOME");
    if (!pw_dir) return VString( a_path );
    path = pw_dir;
    }
  // get rid of trailing `/' if exists
  str_fix_path( path );
  str_chop( path );
  path += a_path + z;
  return path;
#else //_TARGET_UNIX_
  VString path = a_path;
  return path;
#endif //_TARGET_UNIX_
};
Ejemplo n.º 5
0
/*****************************************************************
**	distribute and reload a zone via "distribute_command"
**	what is
**		1 for zone distribution and relaod
**		2 for key distribution (used by dynamic zoes)
*****************************************************************/
int	dist_and_reload (const zone_t *zp, int what)
{
	char	path[MAX_PATHSIZE+1];
	char	cmdline[254+1];
	char	zone[254+1];
	char	str[254+1];
	char	*view;
	FILE	*fp;

	assert (zp != NULL);
	assert (zp->conf->dist_cmd != NULL);
	assert ( what == 1 || what == 2 );

	if ( zp->conf->dist_cmd == NULL )
		return 0;

	if ( !is_exec_ok (zp->conf->dist_cmd) )
	{
		char	*mesg;

		if ( getuid () == 0 )
			mesg = "\tDistribution command %s not run as root\n";
		else
			mesg = "\tDistribution command %s not run due to strange file mode settings\n";

		verbmesg (1, zp->conf, mesg, zp->conf->dist_cmd);
		lg_mesg (LG_ERROR, "exec of distribution command %s disabled due to security reasons", zp->conf->dist_cmd);

		return -1;
	}

	view = "";	/* default is an empty view string */
	if ( zp->conf->view )
	{
		snprintf (zone, sizeof (zone), "\"%s\" in view \"%s\"", zp->zone, zp->conf->view);
		view = zp->conf->view;
	}
	else
		snprintf (zone, sizeof (zone), "\"%s\"", zp->zone);


	if ( what == 2 )
	{
		lg_mesg (LG_NOTICE, "%s: key distribution triggered", zone);
		verbmesg (1, zp->conf, "\tDistribute keys for zone %s\n", zone);
		snprintf (cmdline, sizeof (cmdline), "%s distkeys %s %s %s",
					zp->conf->dist_cmd, zp->zone, path, view);
		*str = '\0';
		if ( zp->conf->noexec == 0 )
		{
			verbmesg (2, zp->conf, "\t  Run cmd \"%s\"\n", cmdline);
			if ( (fp = popen (cmdline, "r")) == NULL || fgets (str, sizeof str, fp) == NULL )
				return -2;
			pclose (fp);
			verbmesg (2, zp->conf, "\t  %s distribute return: \"%s\"\n", zp->conf->dist_cmd, str_chop (str, '\n'));
		}

		return 0;
	}

	pathname (path, sizeof (path), zp->dir, zp->sfile, NULL);

	lg_mesg (LG_NOTICE, "%s: distribution triggered", zone);
	verbmesg (1, zp->conf, "\tDistribute zone %s\n", zone);
	snprintf (cmdline, sizeof (cmdline), "%s distribute %s %s %s", zp->conf->dist_cmd, zp->zone, path, view);

	*str = '\0';
	if ( zp->conf->noexec == 0 )
	{
		verbmesg (2, zp->conf, "\t  Run cmd \"%s\"\n", cmdline);
		if ( (fp = popen (cmdline, "r")) == NULL || fgets (str, sizeof str, fp) == NULL )
			return -2;
		pclose (fp);
		verbmesg (2, zp->conf, "\t  %s distribute return: \"%s\"\n", zp->conf->dist_cmd, str_chop (str, '\n'));
	}


	lg_mesg (LG_NOTICE, "%s: reload triggered", zone);
	verbmesg (1, zp->conf, "\tReload zone %s\n", zone);
	snprintf (cmdline, sizeof (cmdline), "%s reload %s %s %s", zp->conf->dist_cmd, zp->zone, path, view);

	*str = '\0';
	if ( zp->conf->noexec == 0 )
	{
		verbmesg (2, zp->conf, "\t  Run cmd \"%s\"\n", cmdline);
		if ( (fp = popen (cmdline, "r")) == NULL || fgets (str, sizeof str, fp) == NULL )
			return -2;
		pclose (fp);
		verbmesg (2, zp->conf, "\t  %s reload return: \"%s\"\n", zp->conf->dist_cmd, str_chop (str, '\n'));
	}

	return 0;
}
Ejemplo n.º 6
0
int vfu_get_dir_name( const char *prompt, VString &target, int should_exist )
{ 
  int res = -1;
  /*
  #ifdef _TARGET_UNIX_
  leaveok(stdscr, FALSE);
  #endif
  */
  VArray dir_list;
   
  say1(prompt); 
  say2(""); 
  
  int pos = 0; 
  int page = 0;
  int ch = 0; 
  
  int insert = 1;
  int firsthit = 1;
  
  pos = str_len( target );

  //------------------------------------------------------------------
  
  con_cshow();
  say2( target, firsthit ? cINPUT2 : cINPUT );
  while(1) 
    {
    int mx = con_max_x() - 1;
    VString target_out = target;
    if ( (pos < page) || (pos+1 > page + mx) || (page > 0 && pos == page) ) 
      page = pos - mx / 2;
    if ( page < 0 ) page = 0;

    str_trim_left( target_out, page );
    str_sleft( target_out, mx );
    str_pad( target_out, -mx );
    if ( page > 0 )
      str_set_ch( target_out, 0, '<' );
    if ( str_len( target ) - page > mx )
      str_set_ch( target_out, mx-1, '>' );
    
    say2( target_out, firsthit ? cINPUT2 : cINPUT );
    con_xy( pos-page+1, con_max_y() );

    
    if (ch == 0) ch = con_getch();
    if (ch == '\\') ch = '/'; /* dos hack :)) */
    if ( ch == '/' && str_find( target, '/' ) == -1 && target[0] == '~' )
      {
      target = tilde_expand( target );
      str_fix_path( target );
      pos = str_len( target );
      ch = 0;
      }
      
    if ((ch == 8 || ch == KEY_BACKSPACE) && pos > 0) 
      { 
      pos--; 
      str_del( target, pos, 1 );
      } 
    else
    if (ch == KEY_CTRL_A && str_len( target ) > 0)
      {
      int z = str_len( target )-1;
      if ( str_get_ch(target, z) == '/' ) z--;
      while ( z > 0 && str_get_ch(target,z) != '/' ) z--;
      z++;
      str_sleft(target,z);
      pos = z;
      }
    else
    if ( ch == 9 && str_len( target ) > 0)
      { 
      int z; 
      dir_list.undef();
      VString dmain; /* main/base path */
      VString dtail; /* item that should be expanded/glob */
      
      dmain = str_file_path( target );
      dtail = str_file_name_ext( target );
      
      /*
      int lastslash = str_rfind(target, '/');
      if ( lastslash == -1 ) 
        {
        dmain = "";
        dtail = target;
        }
      else
        {
        dmain = target;
        dtail = target;
        str_sleft( dmain, lastslash+1 );
        str_trim_left( dtail, lastslash+1 );
        }
      */
      
      __glob_gdn( dmain, dtail, dir_list );
  
      z = dir_list.count()-1;
      if (dir_list.count()) 
        {
        if ( dir_list.count() > 1)
          {
          int mc = 0; /* match count        */
          int mi = 0; /* match letter index */
          while(4)
            {
            mc = 0;
            int li; /* counter */
            for ( li = 0; li < dir_list.count(); li++ )
              {
              if ( str_get_ch( dir_list[ 0], mi ) == 
                   str_get_ch( dir_list[li], mi ) )
                mc++;
              }
            if ( mc != dir_list.count() )
              break;
            mi++;
            }
          target.setn( dmain + dir_list[0], str_len( dmain ) + mi );
          pos = str_len( target );
          say2( target, cINPUT );
          con_xy( pos+1, con_max_y() );
          
          vfu_beep();
          ch = con_getch();
          if ( ch != 9 ) { dir_list.undef(); continue; }
          dir_list.sort();
          con_chide();
          z = vfu_menu_box( 10, 5, "Complete...", &dir_list );
          con_cshow();
          ch = 0;
          }
        else
          ch = 0;
        if ( z != -1 )
          {
          while( str_len( target ) > 0 && target[-1] != '/' )
            str_chop( target );
          target += dir_list[z];
          }
        
        pos = str_len( target );
        
        dir_list.undef();
        if (ch != 0) continue;
        }
      else
        { /* no match found -- cannot complete */
        vfu_beep();
        }
      } 
    else 
    if (ch == 13)
      { 
      res = 1;
      break; 
      } 
    else 
    if (ch == 27) 
      { 
      target = "";
      res = 0;
      break; 
      } 
    if (ch == KEY_CTRL_U)
      { 
      target = "";
      pos = 0;
      }
    else
    if (ch == KEY_CTRL_X)
      {
        char t[MAX_PATH];
        if ( target[0] == '~' )
          target = tilde_expand( target );
        expand_path( target, t );
        str_fix_path( t );
        target = t;
        pos = str_len( target );
      }
    else 
    if (ch >= 32 && ch <= 255 ) // && pos < 70) 
      { 
      if (firsthit) 
        {
        target = "";
        pos = 0;
        }
      if (!insert) str_del( target, pos, 1 );
      str_ins_ch( target, pos, ch );
      pos++;
      } else
    if( ch == KEY_LEFT  )
      {
      if (pos > 0)
        pos--;
      } else
    if( ch == KEY_RIGHT )
      {
      if (pos < str_len( target ))
        pos++;
      } else
    if ( ch == KEY_IC   ) insert = !insert; else
    if ( ch == KEY_HOME ) pos = 0; else
    if ( ch == KEY_END  ) pos = str_len(target); else
    if ( ch == KEY_DC  && pos < str_len(target) ) 
       str_del( target, pos, 1 ); else
    if ( ch == KEY_NPAGE || ch == KEY_PPAGE )
      {
      con_chide();
      int zz = vfu_hist_menu( 5, 5, ( ch == KEY_PPAGE ) ? "Dir Entry History" : "ChDir History", 
                              ( ch == KEY_PPAGE ) ? HID_GETDIR : HID_CHDIR );
      con_cshow();
      if (zz != -1)
        {
        const char* pc = vfu_hist_get( ( ch == KEY_PPAGE ) ? HID_GETDIR : HID_CHDIR, zz );
        if ( pc )
          {
          target = pc;
          pos = str_len( target );
          }
        }
      }
    ch = 0; 
    firsthit = 0;
    }
  con_chide();
  
  //------------------------------------------------------------------
  str_cut_spc( target );
  if ( res == 1 && target[0] == '~' )
    {
    target = tilde_expand( target );
    str_fix_path( target );
    }
/*  
  if ( target.len() > 0 )
    { 
    // well this tmp is kind of s... ama k'vo da pravi chovek :)
    // FIXME: dos version?
    if ( __ExpandGetDirName && target[0] != '/'
       #ifdef _TARGET_GO32_
       && !( target[1] == ':' && target[2] == '/' )
       #endif
       )
      target = CPath + target;
    StrFixPath( target ); // add trailing slash if not exist
    } 
*/    
  /*
  #ifdef _TARGET_UNIX_
  leaveok(stdscr, TRUE);
  #endif
  */
  if ( res == 1 && str_len( target ) > 0 && should_exist && !dir_exist( target ))
    {
    vfu_beep();
    int ch = tolower( vfu_ask( "Directory does not exist! Create? "
                               "( ENTER=Yes, ESC=cancel )",
                               "\033\rcC" ));
    if ( ch == 27 ) 
      {
      res = 0;
      target = ""; 
      }
    else
    if ( ch == 13 )
       if (make_path( target ))
         {
         if(tolower(
            vfu_ask( "Cannot create path! ( ESC=cancel, C=continue-anyway )", 
            "\033Cc" )) == 27)
            {
            res = 0;
            target = "";
            }
         }
    }
  
  say1(" "); 
  say2(" "); 
  if ( str_len( target ) > 0)
    {
    str_fix_path( target );
    vfu_hist_add( HID_GETDIR, target );
    }
    
  str_cut_spc( target );
  
  ASSERT( res == 0 || res == 1 );
  return res;
}