##/
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
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)
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:
@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:
#include <sys/un.h>
#include <string.h>
#include <pwd.h>
+#include <time.h>
#include <errno.h>
#include <stdarg.h>
#include <fcntl.h>
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 *);
#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);
}
-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;
char buf[1024];
char server_reply[1024];
int i;
+ int ret = (-1);
strcpy(prompt, "> ");
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);
--- /dev/null
+/*
+ * (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);
+}
+
+
+
+