ctdlsh now has two working commands, 'date' and 'passwd'
authorArt Cancro <ajc@uncensored.citadel.org>
Tue, 27 Sep 2011 02:48:05 +0000 (22:48 -0400)
committerArt Cancro <ajc@uncensored.citadel.org>
Tue, 27 Sep 2011 02:48:05 +0000 (22:48 -0400)
ctdlsh/bootstrap [changed mode: 0644->0755]
ctdlsh/src/Makefile.am
ctdlsh/src/Makefile.in
ctdlsh/src/ctdlsh.h
ctdlsh/src/datetime.c
ctdlsh/src/main.c
ctdlsh/src/passwd.c [new file with mode: 0644]

old mode 100644 (file)
new mode 100755 (executable)
index 3b6da1981eb7661b66c0c257eff4ca9123b0807c..1f9f00ff3718045a5a49126f3f291d464a8ba552 100644 (file)
@@ -4,4 +4,4 @@
 ##/
 
 bin_PROGRAMS = ctdlsh
-ctdlsh_SOURCES = main.c sockets.c ctdlsh.h datetime.c
+ctdlsh_SOURCES = main.c sockets.c ctdlsh.h datetime.c passwd.c
index a8418e5165668ec48d9c7540aa3c3f6f75a872fe..8c36fb6fe5ec26b06ef367a9aec244b944f5052e 100644 (file)
@@ -46,7 +46,7 @@ CONFIG_CLEAN_VPATH_FILES =
 am__installdirs = "$(DESTDIR)$(bindir)"
 PROGRAMS = $(bin_PROGRAMS)
 am_ctdlsh_OBJECTS = main.$(OBJEXT) sockets.$(OBJEXT) \
-       datetime.$(OBJEXT)
+       datetime.$(OBJEXT) passwd.$(OBJEXT)
 ctdlsh_OBJECTS = $(am_ctdlsh_OBJECTS)
 ctdlsh_LDADD = $(LDADD)
 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
@@ -145,7 +145,7 @@ target_alias = @target_alias@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
-ctdlsh_SOURCES = main.c sockets.c ctdlsh.h datetime.c
+ctdlsh_SOURCES = main.c sockets.c ctdlsh.h datetime.c passwd.c
 all: all-am
 
 .SUFFIXES:
@@ -229,6 +229,7 @@ distclean-compile:
 
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/datetime.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/passwd.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sockets.Po@am__quote@
 
 .c.o:
index f12fd0606ee43c572524262181402ce480ee75aa..42dcb408548db584654c5951452e88df9f76de8c 100644 (file)
@@ -9,6 +9,7 @@
 #include <sys/un.h>
 #include <string.h>
 #include <pwd.h>
+#include <time.h>
 #include <errno.h>
 #include <stdarg.h>
 #include <fcntl.h>
@@ -50,5 +51,15 @@ struct partial_config {
        int c_ipgm_secret;              /* Internal program authentication  */
 };
 
-int cmd_quit(char *);
-int cmd_datetime(char *);
+typedef int ctdlsh_cmdfunc_t(int, char *);
+
+enum ctdlsh_cmdfunc_return_values {
+       cmdret_ok,
+       cmdret_exit,
+       cmdret_error
+};
+
+int cmd_help(int, char *);
+int cmd_quit(int, char *);
+int cmd_datetime(int, char *);
+int cmd_passwd(int, char *);
index a93e50ea7042619e3e6fb80e9907bc38cf04d3d3..122b98f7fd0c45a6edc8d5021a72b0d835ce067a 100644 (file)
@@ -5,8 +5,15 @@
 
 #include "ctdlsh.h"
 
-int cmd_datetime(char *cmdbuf) {
-       abort();
+int cmd_datetime(int server_socket, char *cmdbuf) {
+       char buf[1024];
+       time_t now;
+
+       sock_puts(server_socket, "TIME");
+       sock_getln(server_socket, buf, sizeof buf);
+       now = atol(&buf[4]);
+       printf("%s", asctime(localtime(&now)));
+       return(cmdret_ok);
 }
 
 
index c47b89c997db3edcc84f3c1c4de3ac94caa4f625..3dd4b9dd7136d16eec6cbacd3f08cdc16f35244b 100644 (file)
@@ -8,30 +8,45 @@
 
 
 
-int cmd_quit(char *cmdbuf) {
-       abort();
+int cmd_quit(int sock, char *cmdbuf) {
+       return(cmdret_exit);
 }
 
 
-
-
 /*
  * Commands understood by ctdlsh
  */
 typedef struct {
        char *name;
-       rl_icpfunc_t *func;
+       ctdlsh_cmdfunc_t *func;
        char *doc;
 } COMMAND;
 
-
 COMMAND commands[] = {
+       {       "?",            cmd_help,       "Display this message"                  },
+       {       "help",         cmd_help,       "Display this message"                  },
        {       "quit",         cmd_quit,       "Quit using ctdlsh"                     },
+       {       "exit",         cmd_quit,       "Quit using ctdlsh"                     },
        {       "date",         cmd_datetime,   "Print the server's date and time"      },
+       {       "time",         cmd_datetime,   "Print the server's date and time"      },
+       {       "passwd",       cmd_passwd,     "Set or change an account password"     },
        {       NULL,           NULL,           NULL                                    }
 };
 
 
+int cmd_help(int sock, char *cmdbuf) {
+       int i;
+
+       for (i=0; commands[i].func != NULL; ++i) {
+               printf("%-10s %s\n", commands[i].name, commands[i].doc);
+       }
+}
+
+
+
+
+
+
 int discover_ipgm_secret(char *dirname) {
        int fd;
        struct partial_config ccc;
@@ -101,6 +116,7 @@ void do_main_loop(int server_socket) {
        char buf[1024];
        char server_reply[1024];
        int i;
+       int ret = (-1);
 
        strcpy(prompt, "> ");
 
@@ -121,11 +137,17 @@ void do_main_loop(int server_socket) {
        rl_attempted_completion_function = ctdlsh_completion;
 
        /* Here we go ... main command loop */
-       while (cmd = readline(prompt)) {
+       while ((ret != cmdret_exit) && (cmd = readline(prompt))) {
 
                if ((cmd) && (*cmd)) {
                        add_history(cmd);
-                       /* FIXME put something here */
+
+                       for (i=0; commands[i].func != NULL; ++i) {
+                               if (!strncasecmp(cmd, commands[i].name, strlen(commands[i].name))) {
+                                       ret = (*commands[i].func) (server_socket, cmd);
+                               }
+                       }
+
                }
 
                free(cmd);
diff --git a/ctdlsh/src/passwd.c b/ctdlsh/src/passwd.c
new file mode 100644 (file)
index 0000000..65ae280
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * (c) 2009-2011 by Art Cancro and citadel.org
+ * This program is released under the terms of the GNU General Public License v3.
+ */
+
+#include "ctdlsh.h"
+
+int cmd_passwd(int server_socket, char *cmdbuf) {
+       char buf[1024];
+       time_t now;
+       char account_name[1024];
+       char *p1;
+       char *p2;
+
+       strcpy(account_name, &cmdbuf[7]);
+       sock_printf(server_socket, "AGUP %s\n", account_name);
+       sock_getln(server_socket, buf, sizeof buf);
+       if (buf[0] != '2') {
+               fprintf(stderr, "No such user.\n");
+               return(cmdret_error);
+       }
+
+       p1 = readline("Enter new password: ");
+       p2 = readline("Enter it again: ");
+
+       if (strcmp(p1, p2)) {
+               fprintf(stderr, "Passwords do not match.  Account password is unchanged.\n");
+               return(cmdret_error);
+       }
+
+       sock_printf(server_socket, "ASUP %s|%s\n", account_name, p2);
+       sock_getln(server_socket, buf, sizeof buf);
+       if (buf[0] != '2') {
+               fprintf(stderr, "%s\n", &buf[4]);
+               return(cmdret_error);
+       }
+
+       printf("Password has been changed.\n");
+       return(cmdret_ok);
+}
+
+
+
+