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)
committerWilfried Goesgens <dothebart@citadel.org>
Tue, 18 Oct 2011 18:58:56 +0000 (20:58 +0200)
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 3b6da19..1f9f00f 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 a8418e5..8c36fb6 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 f12fd06..42dcb40 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 a93e50e..122b98f 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 c47b89c..3dd4b9d 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);
+}
+
+
+
+