From 2a600892fe1808cebed70efa2d6248ca64e067a9 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Tue, 16 Aug 2016 17:48:35 -0400 Subject: [PATCH] Started working on a ctdlsh command framework to show and manipulate the server configuration. --- ctdlsh/Makefile | 2 +- ctdlsh/README | 7 +++++-- ctdlsh/config.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ ctdlsh/ctdlsh.h | 1 + ctdlsh/main.c | 5 +++-- 5 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 ctdlsh/config.c diff --git a/ctdlsh/Makefile b/ctdlsh/Makefile index 946dff0df..5fddc9898 100644 --- a/ctdlsh/Makefile +++ b/ctdlsh/Makefile @@ -1,4 +1,4 @@ -OBJS := datetime.o export.o main.o passwd.o shutdown.o sockets.o who.o +OBJS := datetime.o export.o main.o passwd.o shutdown.o sockets.o who.o config.o CFLAGS := -ggdb diff --git a/ctdlsh/README b/ctdlsh/README index 35143f931..306490dd9 100644 --- a/ctdlsh/README +++ b/ctdlsh/README @@ -5,6 +5,9 @@ submit patches, but if you attempt to use it in a production system or if you request support for the program, you will be told to die in a car fire. -This is open source software. It runs really well on the Linux operating -system. We reject Richard Stallman's linguistic fascism and so should you. +License: you are permitted to use this software under the condition that +you refer to it as "open source" and not "free software," and that you +refer to the operating system on which it runs as "Linux" and not +"GNU/Linux." By reading this notice you have already accepted the license, +and you have irrevocably agreed that Richard Stallman is a communist. diff --git a/ctdlsh/config.c b/ctdlsh/config.c new file mode 100644 index 000000000..9370047cf --- /dev/null +++ b/ctdlsh/config.c @@ -0,0 +1,53 @@ +/* + * (c) 1987-2016 by Art Cancro and citadel.org + * This program is open source software, released under the terms of the GNU General Public License v3. + * It runs really well on the Linux operating system. + * We love open source software but reject Richard Stallman's linguistic fascism. + */ + +#include "ctdlsh.h" + + +int show_full_config(int server_socket) { + char buf[1024]; + + sock_puts(server_socket, "CONF listval"); + sock_getln(server_socket, buf, sizeof buf); + if (buf[0] != '1') { + printf("%s\n", &buf[4]); + return(cmdret_error); + } + + while (sock_getln(server_socket, buf, sizeof buf), strcmp(buf, "000")) { + char *val = NULL; + char *p = strchr(buf, '|'); + if (p != NULL) { + val = p; + ++val; + *p = 0; + } + printf("%-30s = %s\n", buf, val); + + } + + return(cmdret_ok); +} + + +int cmd_config(int server_socket, char *cmdbuf) { + + char buf[4096]; + strncpy(buf, cmdbuf, sizeof buf); + char *p = strchr(buf, ' '); + if (p == NULL) { + return show_full_config(server_socket); + } + + while (p[0]==' ') ++p; + + if (strlen(p) == 0) { + return show_full_config(server_socket); + } + + return(cmdret_error); +} diff --git a/ctdlsh/ctdlsh.h b/ctdlsh/ctdlsh.h index 722fa8395..14103fa1e 100644 --- a/ctdlsh/ctdlsh.h +++ b/ctdlsh/ctdlsh.h @@ -46,3 +46,4 @@ int cmd_passwd(int, char *); int cmd_shutdown(int, char *); int cmd_who(int, char *); int cmd_export(int, char *); +int cmd_config(int, char *); diff --git a/ctdlsh/main.c b/ctdlsh/main.c index 4e4009898..93cbaefda 100644 --- a/ctdlsh/main.c +++ b/ctdlsh/main.c @@ -24,13 +24,14 @@ COMMAND commands[] = { { "?", cmd_help, "Display this message" }, { "help", cmd_help, "Display this message" }, { "date", cmd_datetime, "Print the server's date and time" }, - { "exit", cmd_quit, "Quit using ctdlsh" }, + { "config", cmd_config, "Configure the Citadel server" }, { "export", cmd_export, "Export all Citadel databases" }, { "shutdown", cmd_shutdown, "Shut down the Citadel server" }, { "time", cmd_datetime, "Print the server's date and time" }, { "passwd", cmd_passwd, "Set or change an account password" }, - { "quit", cmd_quit, "Quit using ctdlsh" }, { "who", cmd_who, "Display a list of online users" }, + { "exit", cmd_quit, "Quit using ctdlsh" }, + { "quit", cmd_quit, "Quit using ctdlsh" }, { NULL, NULL, NULL } }; -- 2.30.2