fprintf(stdout, "Building Configuration...\n");
- backup_config_file(quagga_config);
- fp = fopen(quagga_config, "w");
+ backup_config_file(frr_config);
+ fp = fopen(frr_config, "w");
if (fp == NULL) {
fprintf(stdout,
"%% Error: failed to open configuration file %s: %s\n",
- quagga_config, safe_strerror(errno));
+ frr_config, safe_strerror(errno));
return CMD_WARNING_CONFIG_FAILED;
}
fd = fileno(fp);
if (fchmod(fd, CONFIGFILE_MASK) != 0) {
printf("%% Warning: can't chmod configuration file %s: %s\n",
- quagga_config, safe_strerror(errno));
+ frr_config, safe_strerror(errno));
err++;
}
if ((uid != (uid_t)-1 || gid != (gid_t)-1)
&& fchown(fd, uid, gid)) {
printf("%% Warning: can't chown configuration file %s: %s\n",
- quagga_config, safe_strerror(errno));
+ frr_config, safe_strerror(errno));
err++;
}
} else {
- printf("%% Warning: stat() failed on %s: %s\n", quagga_config,
+ printf("%% Warning: stat() failed on %s: %s\n", frr_config,
safe_strerror(errno));
err++;
}
fclose(fp);
- printf("Integrated configuration saved to %s\n", quagga_config);
+ printf("Integrated configuration saved to %s\n", frr_config);
if (err)
return CMD_WARNING;
switch (vtysh_write_integrated) {
case WRITE_INTEGRATED_UNSPECIFIED:
- if (stat(quagga_config, &s) && errno == ENOENT)
+ if (stat(frr_config, &s) && errno == ENOENT)
return false;
return true;
case WRITE_INTEGRATED_NO:
if (!vclient->path[0])
snprintf(vclient->path, sizeof(vclient->path), "%s/%s.vty",
- vty_sock_path, vclient->name);
+ vtydir, vclient->name);
path = vclient->path;
/* Stat socket to see if we have permission to access it. */
return;
/* ls vty_sock_dir and look for all files ending in .vty */
- dir = opendir(vty_sock_path);
+ dir = opendir(vtydir);
if (dir) {
while ((file = readdir(dir)) != NULL) {
if (begins_with(file->d_name, "ospfd-")
if (n == MAXIMUM_INSTANCES) {
fprintf(stderr,
"Parsing %s, client limit(%d) reached!\n",
- vty_sock_path, n);
+ vtydir, n);
break;
}
client = (struct vtysh_client *)malloc(
client->name = "ospfd";
client->flag = VTYSH_OSPFD;
snprintf(client->path, sizeof(client->path),
- "%s/%s", vty_sock_path, file->d_name);
+ "%s/%s", vtydir, file->d_name);
client->next = NULL;
vtysh_client_sorted_insert(head_client, client);
n++;
static uid_t elevuid, realuid;
static gid_t elevgid, realgid;
+#define VTYSH_CONFIG_NAME "vtysh.conf"
+#define FRR_CONFIG_NAME "frr.conf"
+
/* Configuration file name and directory. */
-static char vtysh_config_always[MAXPATHLEN] = SYSCONFDIR VTYSH_DEFAULT_CONFIG;
-static char quagga_config_default[MAXPATHLEN] = SYSCONFDIR FRR_DEFAULT_CONFIG;
-char *quagga_config = quagga_config_default;
-char history_file[MAXPATHLEN];
+static char vtysh_config[MAXPATHLEN];
+char frr_config[MAXPATHLEN];
+char vtydir[MAXPATHLEN];
+static char history_file[MAXPATHLEN];
/* Flag for indicate executing child command. */
int execute_flag = 0;
-/* VTY Socket prefix */
-const char *vty_sock_path = NULL;
-
/* For sigsetjmp() & siglongjmp(). */
static sigjmp_buf jmpbuf;
int boot_flag = 0;
const char *daemon_name = NULL;
const char *inputfile = NULL;
- const char *vtysh_configfile_name;
struct cmd_rec {
char *line;
struct cmd_rec *next;
int ret = 0;
char *homedir = NULL;
int ditch_suid = 0;
+ char sysconfdir[MAXPATHLEN];
/* SUID: drop down to calling user & go back up when needed */
elevuid = geteuid();
/* Preserve name of myself. */
progname = ((p = strrchr(argv[0], '/')) ? ++p : argv[0]);
+ strlcpy(sysconfdir, frr_sysconfdir, sizeof(sysconfdir));
+ strlcpy(vtydir, frr_vtydir, sizeof(vtydir));
+
/* Option handling. */
while (1) {
opt = getopt_long(argc, argv, "be:c:d:nf:mEhCw", longopts, 0);
} break;
case OPTION_VTYSOCK:
ditch_suid = 1; /* option disables SUID */
- vty_sock_path = optarg;
+ strlcpy(vtydir, optarg, sizeof(vtydir));
break;
case OPTION_CONFDIR:
ditch_suid = 1; /* option disables SUID */
- /*
- * Overwrite location for vtysh.conf
- */
- vtysh_configfile_name =
- strrchr(VTYSH_DEFAULT_CONFIG, '/');
- if (vtysh_configfile_name)
- /* skip '/' */
- vtysh_configfile_name++;
- else
- /*
- * VTYSH_DEFAULT_CONFIG configured with relative
- * path
- * during config? Should really never happen for
- * sensible config
- */
- vtysh_configfile_name =
- (char *)VTYSH_DEFAULT_CONFIG;
- strlcpy(vtysh_config_always, optarg,
- sizeof(vtysh_config_always));
- strlcat(vtysh_config_always, "/",
- sizeof(vtysh_config_always));
- strlcat(vtysh_config_always, vtysh_configfile_name,
- sizeof(vtysh_config_always));
- /*
- * Overwrite location for frr.conf
- */
- vtysh_configfile_name =
- strrchr(FRR_DEFAULT_CONFIG, '/');
- if (vtysh_configfile_name)
- /* skip '/' */
- vtysh_configfile_name++;
- else
- /*
- * FRR_DEFAULT_CONFIG configured with relative
- * path
- * during config? Should really never happen for
- * sensible config
- */
- vtysh_configfile_name =
- (char *)FRR_DEFAULT_CONFIG;
- strlcpy(quagga_config_default, optarg,
- sizeof(vtysh_config_always));
- strlcat(quagga_config_default, "/",
- sizeof(vtysh_config_always));
- strlcat(quagga_config_default, vtysh_configfile_name,
- sizeof(quagga_config_default));
+ strlcpy(sysconfdir, optarg, sizeof(sysconfdir));
break;
case 'd':
daemon_name = optarg;
elevgid = realgid;
}
- if (!vty_sock_path)
- vty_sock_path = frr_vtydir;
-
if (markfile + writeconfig + dryrun + boot_flag > 1) {
fprintf(stderr,
"Invalid combination of arguments. Please specify at "
"NOT SUPPORTED since its\nresults are inconsistent!\n");
}
+ snprintf(vtysh_config, sizeof(vtysh_config), "%s/%s",
+ sysconfdir, VTYSH_CONFIG_NAME);
+ snprintf(frr_config, sizeof(frr_config), "%s/%s",
+ sysconfdir, FRR_CONFIG_NAME);
+
/* Initialize user input buffer. */
line_read = NULL;
setlinebuf(stdout);
/* Read vtysh configuration file before connecting to daemons.
* (file may not be readable to calling user in SUID mode) */
suid_on();
- vtysh_read_config(vtysh_config_always);
+ vtysh_read_config(vtysh_config);
suid_off();
if (markfile) {
if (inputfile) {
ret = vtysh_read_config(inputfile);
} else {
- ret = vtysh_read_config(quagga_config_default);
+ ret = vtysh_read_config(frr_config);
}
exit(ret);
/* Boot startup configuration file. */
if (boot_flag) {
- vtysh_flock_config(quagga_config);
- int ret = vtysh_read_config(quagga_config);
+ vtysh_flock_config(frr_config);
+ int ret = vtysh_read_config(frr_config);
vtysh_unflock_config();
if (ret) {
fprintf(stderr,
"Configuration file[%s] processing failure: %d\n",
- quagga_config, ret);
+ frr_config, ret);
if (no_error)
exit(0);
else