diff options
author | Kozlov Dmitry <dima@server> | 2010-12-28 13:57:36 +0300 |
---|---|---|
committer | Kozlov Dmitry <dima@server> | 2010-12-28 13:57:36 +0300 |
commit | e299571805aabb898b1297fd699b98f66e398876 (patch) | |
tree | c7df8cf57810cddd2619de65109c697c0852ca04 | |
parent | 7ab0dd10cbb94ea8246237246fb67d08922bd2d4 (diff) | |
download | accel-ppp-e299571805aabb898b1297fd699b98f66e398876.tar.gz accel-ppp-e299571805aabb898b1297fd699b98f66e398876.zip |
cli: inform that daemon is in shutdown mode
-rw-r--r-- | accel-pptpd/cli/cli.c | 28 | ||||
-rw-r--r-- | accel-pptpd/cli/cli_p.h | 2 | ||||
-rw-r--r-- | accel-pptpd/cli/telnet.c | 19 |
3 files changed, 36 insertions, 13 deletions
diff --git a/accel-pptpd/cli/cli.c b/accel-pptpd/cli/cli.c index b8f82c8..048809c 100644 --- a/accel-pptpd/cli/cli.c +++ b/accel-pptpd/cli/cli.c @@ -8,6 +8,7 @@ #include "cli.h" #include "cli_p.h" #include "log.h" +#include "events.h" #include "memdebug.h" @@ -17,7 +18,8 @@ #define MSG_UNKNOWN_CMD "command unknown\r\n" char *conf_cli_passwd; -const char *conf_cli_prompt = "accel-pptp# "; +static const char *def_cli_prompt = "accel-pptp"; +char *conf_cli_prompt; static LIST_HEAD(simple_cmd_list); static LIST_HEAD(regexp_cmd_list); @@ -196,12 +198,30 @@ int cli_process_cmd(struct cli_client_t *cln) return 0; } -static void __init init(void) +static void load_config(void) { const char *opt; - - conf_cli_passwd = conf_get_opt("cli", "passwd"); + + if (conf_cli_passwd) + _free(conf_cli_passwd); + opt = conf_get_opt("cli", "password"); + if (opt) + conf_cli_passwd = _strdup(conf_cli_passwd); + else + conf_cli_passwd = NULL; + + if (conf_cli_prompt && conf_cli_prompt != def_cli_prompt) + _free(conf_cli_prompt); opt = conf_get_opt("cli", "prompt"); if (opt) conf_cli_prompt = _strdup(opt); + else + conf_cli_prompt = (char *)def_cli_prompt; +} + +static void __init init(void) +{ + load_config(); + + triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config); } diff --git a/accel-pptpd/cli/cli_p.h b/accel-pptpd/cli/cli_p.h index 9e3e6cf..0fcba30 100644 --- a/accel-pptpd/cli/cli_p.h +++ b/accel-pptpd/cli/cli_p.h @@ -16,7 +16,7 @@ struct cli_client_t int cli_process_cmd(struct cli_client_t *cln); extern char *conf_cli_passwd; -extern const char *conf_cli_prompt; +extern char *conf_cli_prompt; #endif diff --git a/accel-pptpd/cli/telnet.c b/accel-pptpd/cli/telnet.c index b191864..a91418a 100644 --- a/accel-pptpd/cli/telnet.c +++ b/accel-pptpd/cli/telnet.c @@ -23,7 +23,9 @@ #include "cli_p.h" #define RECV_BUF_SIZE 1024 -#define AUTH_FAILED "\r\nAuthentication failed\r\n" + +#define MSG_AUTH_FAILED "\r\nAuthentication failed\r\n" +#define MSG_SHUTDOWN_IN_PROGRESS "note: 'shutdown soft' is in progress...\r\n" #define ESC_LEFT "[D" #define ESC_RIGHT "[C" @@ -191,10 +193,6 @@ static int send_banner(struct telnet_client_t *cln) { if (telnet_send(cln, "accel-pptp version " ACCEL_PPTP_VERSION "\r\n", sizeof("accel-pptp version " ACCEL_PPTP_VERSION "\r\n"))) return -1; - if (cln->auth && ppp_shutdown) { - if (telnet_send(cln, "warning: 'shutdown soft' is in progress...\r\n", sizeof("warning: 'shutdown soft' is in progress...\r\n"))) - return -1; - } return 0; } @@ -220,7 +218,8 @@ static int send_password_request(struct telnet_client_t *cln) static int send_prompt(struct telnet_client_t *cln) { - return telnet_send(cln, conf_cli_prompt, strlen(conf_cli_prompt)); + sprintf((char *)temp_buf, "%s%s# ", conf_cli_prompt, ppp_shutdown ? "(shutdown)" : ""); + return telnet_send(cln, temp_buf, strlen((char *)temp_buf)); } /*static void print_buf(const uint8_t *buf, int size) @@ -285,14 +284,14 @@ static int telnet_input_char(struct telnet_client_t *cln, uint8_t c) if (!cln->auth) { if (strcmp((char *)cln->cmdline, conf_cli_passwd)) { - if (telnet_send(cln, AUTH_FAILED, sizeof(AUTH_FAILED))) + if (telnet_send(cln, MSG_AUTH_FAILED, sizeof(MSG_AUTH_FAILED))) return -1; disconnect(cln); return -1; } cln->auth = 1; if (ppp_shutdown) { - if (telnet_send(cln, "warning: 'shutdown soft' is in progress...\r\n", sizeof("warning: 'shutdown soft' is in progress...\r\n"))) + if (telnet_send(cln, MSG_SHUTDOWN_IN_PROGRESS, sizeof(MSG_SHUTDOWN_IN_PROGRESS))) return -1; } } else if (cln->cmdline_len) { @@ -599,6 +598,10 @@ static int serv_read(struct triton_md_handler_t *h) send_password_request(conn); else { conn->auth = 1; + if (ppp_shutdown) { + if (telnet_send(conn, MSG_SHUTDOWN_IN_PROGRESS, sizeof(MSG_SHUTDOWN_IN_PROGRESS))) + continue; + } send_prompt(conn); } triton_collect_cpu_usage(); |