mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-12 09:52:27 +00:00
vtysh: detangle configuration writes
vtysh has a very convoluted and confusing setup where it isn't even clear which files are written where (since some filenames come indirectly from loading config). Detangle. This also removes writing vtysh.conf. The file is intended to be manually edited since it has some vague security concerns (if PAM is used). Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
This commit is contained in:
parent
e227e24231
commit
cb947ba3ae
@ -77,8 +77,6 @@ struct vtysh_client vtysh_client[] =
|
||||
|
||||
enum vtysh_write_integrated vtysh_write_integrated = WRITE_INTEGRATED_UNSPECIFIED;
|
||||
|
||||
extern char config_default[];
|
||||
|
||||
static void
|
||||
vclient_close (struct vtysh_client *vclient)
|
||||
{
|
||||
@ -2465,33 +2463,19 @@ write_config_integrated(void)
|
||||
{
|
||||
u_int i;
|
||||
char line[] = "write terminal\n";
|
||||
FILE *fp, *fp1;
|
||||
FILE *fp;
|
||||
|
||||
fprintf (stdout,"Building Configuration...\n");
|
||||
|
||||
backup_config_file(integrate_default);
|
||||
backup_config_file(host.config);
|
||||
|
||||
fp = fopen (integrate_default, "w");
|
||||
backup_config_file(quagga_config);
|
||||
fp = fopen (quagga_config, "w");
|
||||
if (fp == NULL)
|
||||
{
|
||||
fprintf (stdout,"%% Can't open configuration file %s due to '%s'\n",
|
||||
integrate_default, safe_strerror(errno));
|
||||
quagga_config, safe_strerror(errno));
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
fp1 = fopen (host.config, "w");
|
||||
if (fp1 == NULL)
|
||||
{
|
||||
fprintf (stdout,"%% Can't open configuration file %s due to '%s'\n",
|
||||
host.config, safe_strerror(errno));
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
vtysh_config_write ();
|
||||
vtysh_config_dump (fp1);
|
||||
|
||||
fclose (fp1);
|
||||
for (i = 0; i < array_size(vtysh_client); i++)
|
||||
vtysh_client_config (&vtysh_client[i], line);
|
||||
|
||||
@ -2500,20 +2484,14 @@ write_config_integrated(void)
|
||||
|
||||
fclose (fp);
|
||||
|
||||
if (chmod (integrate_default, CONFIGFILE_MASK) != 0)
|
||||
if (chmod (quagga_config, CONFIGFILE_MASK) != 0)
|
||||
{
|
||||
fprintf (stdout,"%% Can't chmod configuration file %s: %s\n",
|
||||
integrate_default, safe_strerror(errno));
|
||||
quagga_config, safe_strerror(errno));
|
||||
return CMD_WARNING;
|
||||
}
|
||||
|
||||
if (chmod (host.config, CONFIGFILE_MASK) != 0)
|
||||
{
|
||||
fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n",
|
||||
integrate_default, safe_strerror(errno), errno);
|
||||
return CMD_WARNING;
|
||||
}
|
||||
fprintf(stdout,"Integrated configuration saved to %s\n",integrate_default);
|
||||
fprintf(stdout,"Integrated configuration saved to %s\n", quagga_config);
|
||||
|
||||
fprintf (stdout,"[OK]\n");
|
||||
|
||||
@ -2527,7 +2505,7 @@ static bool vtysh_writeconfig_integrated(void)
|
||||
switch (vtysh_write_integrated)
|
||||
{
|
||||
case WRITE_INTEGRATED_UNSPECIFIED:
|
||||
if (stat(integrate_default, &s) && errno == ENOENT)
|
||||
if (stat(quagga_config, &s) && errno == ENOENT)
|
||||
return false;
|
||||
return true;
|
||||
case WRITE_INTEGRATED_NO:
|
||||
@ -2547,42 +2525,18 @@ DEFUN (vtysh_write_memory,
|
||||
int ret = CMD_SUCCESS;
|
||||
char line[] = "write memory\n";
|
||||
u_int i;
|
||||
FILE *fp;
|
||||
|
||||
fprintf (stdout, "Note: this version of vtysh never writes vtysh.conf\n");
|
||||
|
||||
/* If integrated Quagga.conf explicitely set. */
|
||||
if (vtysh_writeconfig_integrated())
|
||||
return write_config_integrated();
|
||||
else
|
||||
backup_config_file(integrate_default);
|
||||
|
||||
fprintf (stdout,"Building Configuration...\n");
|
||||
|
||||
for (i = 0; i < array_size(vtysh_client); i++)
|
||||
ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
|
||||
|
||||
|
||||
fp = fopen(host.config, "w");
|
||||
if (fp == NULL)
|
||||
{
|
||||
fprintf (stdout,"%% Can't open configuration file %s due to '%s'\n",
|
||||
host.config, safe_strerror(errno));
|
||||
return CMD_SUCCESS;
|
||||
}
|
||||
|
||||
vtysh_config_write ();
|
||||
vtysh_config_dump (fp);
|
||||
|
||||
fclose (fp);
|
||||
|
||||
if (chmod (host.config, CONFIGFILE_MASK) != 0)
|
||||
{
|
||||
fprintf (stdout,"%% Can't chmod configuration file %s: %s\n",
|
||||
integrate_default, safe_strerror(errno));
|
||||
return CMD_WARNING;
|
||||
}
|
||||
|
||||
fprintf (stdout,"[OK]\n");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -53,6 +53,8 @@ enum vtysh_write_integrated {
|
||||
|
||||
extern enum vtysh_write_integrated vtysh_write_integrated;
|
||||
|
||||
extern char *quagga_config;
|
||||
|
||||
void vtysh_init_vty (void);
|
||||
void vtysh_init_cmd (void);
|
||||
extern int vtysh_connect_all (const char *optional_daemon_name);
|
||||
|
@ -376,7 +376,6 @@ vtysh_read_config (const char *config_default_dir)
|
||||
FILE *confp = NULL;
|
||||
int ret;
|
||||
|
||||
host_config_set (config_default_dir);
|
||||
confp = fopen (config_default_dir, "r");
|
||||
if (confp == NULL)
|
||||
{
|
||||
|
@ -67,8 +67,9 @@ struct zebra_privs_t vtysh_privs =
|
||||
};
|
||||
|
||||
/* Configuration file name and directory. */
|
||||
char config_default[] = SYSCONFDIR VTYSH_DEFAULT_CONFIG;
|
||||
char quagga_config_default[] = SYSCONFDIR QUAGGA_DEFAULT_CONFIG;
|
||||
static char vtysh_config_always[] = SYSCONFDIR VTYSH_DEFAULT_CONFIG;
|
||||
static char quagga_config_default[] = SYSCONFDIR QUAGGA_DEFAULT_CONFIG;
|
||||
char *quagga_config = quagga_config_default;
|
||||
char history_file[MAXPATHLEN];
|
||||
|
||||
/* Flag for indicate executing child command. */
|
||||
@ -373,7 +374,7 @@ main (int argc, char **argv, char **env)
|
||||
vty_init_vtysh ();
|
||||
|
||||
/* Read vtysh configuration file before connecting to daemons. */
|
||||
vtysh_read_config(config_default);
|
||||
vtysh_read_config(vtysh_config_always);
|
||||
|
||||
if (markfile)
|
||||
{
|
||||
@ -516,13 +517,13 @@ main (int argc, char **argv, char **env)
|
||||
/* Boot startup configuration file. */
|
||||
if (boot_flag)
|
||||
{
|
||||
vtysh_flock_config (integrate_default);
|
||||
int ret = vtysh_read_config (integrate_default);
|
||||
vtysh_flock_config (quagga_config);
|
||||
int ret = vtysh_read_config (quagga_config);
|
||||
vtysh_unflock_config ();
|
||||
if (ret)
|
||||
{
|
||||
fprintf (stderr, "Configuration file[%s] processing failure: %d\n",
|
||||
integrate_default, ret);
|
||||
quagga_config, ret);
|
||||
if (no_error)
|
||||
exit (0);
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user