diff options
author | Harald Welte <laforge@netfilter.org> | 2009-08-07 13:28:08 +0200 |
---|---|---|
committer | Harald Welte <laforge@netfilter.org> | 2009-08-07 13:28:08 +0200 |
commit | c7c19822fd43a01c54a445addb1e8a82067d82a4 (patch) | |
tree | 20e07c9fbe70fc65e17d62d76e325f6ef3d55e52 | |
parent | 07dc73d4f74a9cb7eddc6259fdb7b095f87e52c1 (diff) |
add support for reading of configuration file to VTY
-rw-r--r-- | openbsc/include/vty/vty.h | 4 | ||||
-rw-r--r-- | openbsc/src/vty/command.c | 5 | ||||
-rw-r--r-- | openbsc/src/vty/vty.c | 49 |
3 files changed, 51 insertions, 7 deletions
diff --git a/openbsc/include/vty/vty.h b/openbsc/include/vty/vty.h index ab34cd3b7..4a1a6ff08 100644 --- a/openbsc/include/vty/vty.h +++ b/openbsc/include/vty/vty.h @@ -129,6 +129,7 @@ static inline char *vty_newline(struct vty *vty) /* Prototypes. */ void vty_init (void); +int vty_read_config_file(const char *file_name); void vty_init_vtysh (void); void vty_reset (void); struct vty *vty_new (void); @@ -136,8 +137,7 @@ struct vty *vty_create (int vty_sock, void *priv); int vty_out (struct vty *, const char *, ...) PRINTF_ATTRIBUTE(2, 3); int vty_out_newline(struct vty *); int vty_read(struct vty *vty); -void vty_read_config (char *, char *); -void vty_time_print (struct vty *, int); +//void vty_time_print (struct vty *, int); void vty_close (struct vty *); char *vty_get_cwd (void); void vty_log (const char *level, const char *proto, const char *fmt, va_list); diff --git a/openbsc/src/vty/command.c b/openbsc/src/vty/command.c index 6173292a0..4c9d2db8e 100644 --- a/openbsc/src/vty/command.c +++ b/openbsc/src/vty/command.c @@ -507,7 +507,6 @@ static char *zencrypt(const char *passwd) /* This function write configuration of this host. */ static int config_write_host(struct vty *vty) { -#if 0 if (host.name) vty_out(vty, "hostname %s%s", host.name, VTY_NEWLINE); @@ -527,6 +526,7 @@ static int config_write_host(struct vty *vty) VTY_NEWLINE); } +#if 0 if (zlog_default->default_lvl != LOG_DEBUG) { vty_out(vty, "! N.B. The 'log trap' command is deprecated.%s", VTY_NEWLINE); @@ -579,7 +579,7 @@ static int config_write_host(struct vty *vty) if (zlog_default->record_priority == 1) vty_out(vty, "log record-priority%s", VTY_NEWLINE); - +#endif if (host.advanced) vty_out(vty, "service advanced-vty%s", VTY_NEWLINE); @@ -596,7 +596,6 @@ static int config_write_host(struct vty *vty) else if (!host.motd) vty_out(vty, "no banner motd%s", VTY_NEWLINE); -#endif return 1; } diff --git a/openbsc/src/vty/vty.c b/openbsc/src/vty/vty.c index 9962474c8..5472fa05a 100644 --- a/openbsc/src/vty/vty.c +++ b/openbsc/src/vty/vty.c @@ -1373,6 +1373,39 @@ int vty_read(struct vty *vty) return 0; } +/* Read up configuration file */ +static int +vty_read_file(FILE *confp) +{ + int ret; + struct vty *vty; + + vty = vty_new(); + vty->fd = 0; + vty->type = VTY_FILE; + vty->node = CONFIG_NODE; + + ret = config_from_file(vty, confp); + + if (ret != CMD_SUCCESS) { + switch (ret) { + case CMD_ERR_AMBIGUOUS: + fprintf(stderr, "Ambiguous command.\n"); + break; + case CMD_ERR_NO_MATCH: + fprintf(stderr, "Ther is no such command.\n"); + break; + } + fprintf(stderr, "Error occurred during reading below " + "line:\n%s\n", vty->buf); + vty_close(vty); + return -EINVAL; + } + + vty_close(vty); + return 0; +} + /* Create new vty structure. */ struct vty * vty_create (int vty_sock, void *priv) @@ -1648,7 +1681,19 @@ void vty_init() #endif } -static __attribute__((constructor)) void on_dso_load_vty(void) +int vty_read_config_file(const char *file_name) { - tall_vty_ctx = talloc_named_const(NULL, 1, "vty"); + FILE *cfile; + int rc; + + cfile = fopen(file_name, "r"); + if (!cfile) + return -ENOENT; + + rc = vty_read_file(cfile); + fclose(cfile); + + host_config_set(file_name); + + return rc; } |