if (quagga_timestamp(0, buf, sizeof(buf)) == 0)
{
- zlog (NULL, LOG_INFO, "quagga_timestamp error");
+ zlog_info("quagga_timestamp error");
return;
}
if (cr)
snprintf(prompt_str, sizeof(prompt_str), cmd_prompt (vty->node), vty_str);
/* now log the command */
- zlog(NULL, LOG_ERR, "%s%s", prompt_str, buf);
+ zlog_err("%s%s", prompt_str, buf);
}
/* Split readline string up into the vector */
vline = cmd_make_strvec (buf);
ret = cmd_execute_command (vline, vty, NULL, 0);
/* Get the name of the protocol if any */
- if (zlog_default)
- protocolname = zlog_proto_names[zlog_default->protocol];
- else
- protocolname = zlog_proto_names[ZLOG_NONE];
+ protocolname = zlog_protoname();
#ifdef CONSUMED_TIME_CHECK
GETRUSAGE(&after);
case ZEBRA_NODE:
case RIP_NODE:
case RIPNG_NODE:
+ case EIGRP_NODE:
case BGP_NODE:
case BGP_VPNV4_NODE:
case BGP_VPNV6_NODE:
case BGP_ENCAP_NODE:
case BGP_ENCAPV6_NODE:
+ case BGP_VRF_POLICY_NODE:
case BGP_VNC_DEFAULTS_NODE:
case BGP_VNC_NVE_GROUP_NODE:
case BGP_VNC_L2_GROUP_NODE:
case BGP_IPV4M_NODE:
case BGP_IPV6_NODE:
case BGP_IPV6M_NODE:
+ case BGP_EVPN_NODE:
case RMAP_NODE:
case OSPF_NODE:
case OSPF6_NODE:
vty_backward_pure_word (vty);
vty_insert_word_overwrite (vty, matched[0]);
XFREE (MTYPE_TMP, matched[0]);
- vector_only_index_free (matched);
- return;
break;
case CMD_COMPLETE_LIST_MATCH:
for (i = 0; matched[i] != NULL; i++)
break;
}
if (matched)
- vector_only_index_free (matched);
+ XFREE (MTYPE_TMP, matched);
}
static void
case ZEBRA_NODE:
case RIP_NODE:
case RIPNG_NODE:
+ case EIGRP_NODE:
case BGP_NODE:
case RMAP_NODE:
case OSPF_NODE:
if ((acl = access_list_lookup (AFI_IP, vty_accesslist_name)) &&
(access_list_apply (acl, &p) == FILTER_DENY))
{
- zlog (NULL, LOG_INFO, "Vty connection refused from %s",
- sockunion2str (&su, buf, SU_ADDRSTRLEN));
+ zlog_info ("Vty connection refused from %s",
+ sockunion2str (&su, buf, SU_ADDRSTRLEN));
close (vty_sock);
/* continue accepting connections */
if ((acl = access_list_lookup (AFI_IP6, vty_ipv6_accesslist_name)) &&
(access_list_apply (acl, &p) == FILTER_DENY))
{
- zlog (NULL, LOG_INFO, "Vty connection refused from %s",
- sockunion2str (&su, buf, SU_ADDRSTRLEN));
+ zlog_info ("Vty connection refused from %s",
+ sockunion2str (&su, buf, SU_ADDRSTRLEN));
close (vty_sock);
/* continue accepting connections */
ret = setsockopt (vty_sock, IPPROTO_TCP, TCP_NODELAY,
(char *) &on, sizeof (on));
if (ret < 0)
- zlog (NULL, LOG_INFO, "can't set sockopt to vty_sock : %s",
- safe_strerror (errno));
+ zlog_info ("can't set sockopt to vty_sock : %s",
+ safe_strerror (errno));
- zlog (NULL, LOG_INFO, "Vty connection from %s",
- sockunion2str (&su, buf, SU_ADDRSTRLEN));
+ zlog_info ("Vty connection from %s",
+ sockunion2str (&su, buf, SU_ADDRSTRLEN));
vty_create (vty_sock, &su);
/* Make server socket. */
memset (&serv, 0, sizeof (struct sockaddr_un));
serv.sun_family = AF_UNIX;
- strncpy (serv.sun_path, path, strlen (path));
+ strlcpy (serv.sun_path, path, sizeof (serv.sun_path));
#ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
len = serv.sun_len = SUN_LEN(&serv);
#else
zprivs_get_ids(&ids);
- if (ids.gid_vty > 0)
+ /* Hack: ids.gid_vty is actually a uint, but we stored -1 in it
+ earlier for the case when we don't need to chown the file
+ type casting it here to make a compare */
+ if ((int)ids.gid_vty > 0)
{
/* set group of socket */
if ( chown (path, -1, ids.gid_vty) )
vty_close (struct vty *vty)
{
int i;
+ bool was_stdio = false;
/* Cancel threads.*/
if (vty->t_read)
/* Unset vector. */
vector_unset (vtyvec, vty->fd);
+ if (vty->wfd > 0 && vty->type == VTY_FILE)
+ fsync (vty->wfd);
+
/* Close socket. */
if (vty->fd > 0)
- close (vty->fd);
+ {
+ close (vty->fd);
+ if (vty->wfd > 0 && vty->wfd != vty->fd)
+ close (vty->wfd);
+ }
else
- vty_stdio_reset ();
+ was_stdio = true;
if (vty->buf)
XFREE (MTYPE_VTY, vty->buf);
/* OK free vty. */
XFREE (MTYPE_VTY, vty);
+
+ if (was_stdio)
+ vty_stdio_reset ();
}
/* When time out occur output message then close connection. */
}
static FILE *
-vty_use_backup_config (char *fullpath)
+vty_use_backup_config (const char *fullpath)
{
char *fullpath_sav, *fullpath_tmp;
FILE *ret = NULL;
- struct stat buf;
int tmp, sav;
int c;
char buffer[512];
fullpath_sav = malloc (strlen (fullpath) + strlen (CONF_BACKUP_EXT) + 1);
strcpy (fullpath_sav, fullpath);
strcat (fullpath_sav, CONF_BACKUP_EXT);
- if (stat (fullpath_sav, &buf) == -1)
+
+ sav = open (fullpath_sav, O_RDONLY);
+ if (sav < 0)
{
free (fullpath_sav);
return NULL;
/* Open file to configuration write. */
tmp = mkstemp (fullpath_tmp);
if (tmp < 0)
- {
- free (fullpath_sav);
- free (fullpath_tmp);
- return NULL;
- }
+ goto out_close_sav;
- sav = open (fullpath_sav, O_RDONLY);
- if (sav < 0)
- {
- unlink (fullpath_tmp);
- free (fullpath_sav);
- free (fullpath_tmp);
- return NULL;
- }
+ if (fchmod (tmp, CONFIGFILE_MASK) != 0)
+ goto out_close;
while((c = read (sav, buffer, 512)) > 0)
{
if (write (tmp, buffer, c) <= 0)
- {
- free (fullpath_sav);
- free (fullpath_tmp);
- close (sav);
- close (tmp);
- return NULL;
- }
+ goto out_close;
}
close (sav);
close (tmp);
- if (chmod(fullpath_tmp, CONFIGFILE_MASK) != 0)
+ if (rename (fullpath_tmp, fullpath) == 0)
+ ret = fopen (fullpath, "r");
+ else
+ unlink (fullpath_tmp);
+
+ if (0)
{
+out_close:
+ close (tmp);
unlink (fullpath_tmp);
- free (fullpath_sav);
- free (fullpath_tmp);
- return NULL;
+out_close_sav:
+ close (sav);
}
- if (link (fullpath_tmp, fullpath) == 0)
- ret = fopen (fullpath, "r");
-
- unlink (fullpath_tmp);
-
free (fullpath_sav);
free (fullpath_tmp);
return ret;
/* Read up configuration file from file_name. */
void
-vty_read_config (char *config_file,
+vty_read_config (const char *config_file,
char *config_default_dir)
{
char cwd[MAXPATHLEN];
FILE *confp = NULL;
- char *fullpath;
+ const char *fullpath;
char *tmp = NULL;
/* If -f flag specified. */
tmp_free_and_out:
if (tmp)
- XFREE (MTYPE_TMP, fullpath);
+ XFREE (MTYPE_TMP, tmp);
}
/* Small utility function which output log to the VTY. */
}
}
-DEFUN (config_who,
+DEFUN_NOSH (config_who,
config_who_cmd,
"who",
"Display who is on vty\n")
}
/* Move to vty configuration mode. */
-DEFUN (line_vty,
+DEFUN_NOSH (line_vty,
line_vty_cmd,
"line vty",
"Configure a terminal line\n"
return CMD_SUCCESS;
}
-DEFUN (terminal_monitor,
+DEFUN_NOSH (terminal_monitor,
terminal_monitor_cmd,
"terminal monitor",
"Set terminal line parameters\n"
return CMD_SUCCESS;
}
-DEFUN (terminal_no_monitor,
+DEFUN_NOSH (terminal_no_monitor,
terminal_no_monitor_cmd,
"terminal no monitor",
"Set terminal line parameters\n"
return CMD_SUCCESS;
}
-DEFUN (no_terminal_monitor,
+DEFUN_NOSH (no_terminal_monitor,
no_terminal_monitor_cmd,
"no terminal monitor",
NO_STR
}
-DEFUN (show_history,
+DEFUN_NOSH (show_history,
show_history_cmd,
"show history",
SHOW_STR
vty_reset ();
vector_free (vtyvec);
vector_free (Vvty_serv_thread);
+ vtyvec = NULL;
+ Vvty_serv_thread = NULL;
}
}