*
*/
-#ifdef DLL_EXPORT
-#define IN_LIBCIT
-#endif
-
#include "sysdep.h"
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <string.h>
+#include <dirent.h>
#include <errno.h>
#include <limits.h>
/* #include <dlfcn.h> */
#include "policy.h"
#include "control.h"
#include "tools.h"
+#include "euidindex.h"
#ifndef HAVE_SNPRINTF
#include "snprintf.h"
char buf[256];
char buf2[256];
char *dirs[2];
+ DIR *dp;
+ struct dirent *d;
extract_token(buf, mname, 0, '|', sizeof buf);
- dirs[0] = strdup(
#ifdef HAVE_DATA_DIR
- DATA_DIR"/"
+ dirs[0] = strdup(DATA_DIR "/messages");
+#else
+ dirs[0] = strdup("messages");
#endif
- "messages");
- dirs[1] = strdup(
+
#ifdef HAVE_DATA_DIR
- DATA_DIR"/"
+ dirs[1] = strdup(DATA_DIR "/help");
+#else
+ dirs[1] = strdup("help");
#endif
- "help");
- snprintf(buf2, sizeof buf2, "%s.%d.%d", buf, CC->cs_clientdev, CC->cs_clienttyp);
- mesg_locate(targ, sizeof targ, buf2, 2, (const char **)dirs);
- if (strlen(targ) == 0) {
- snprintf(buf2, sizeof buf2, "%s.%d", buf, CC->cs_clientdev);
+
+ snprintf(buf2, sizeof buf2, "%s.%d.%d",
+ buf, CC->cs_clientdev, CC->cs_clienttyp);
+
+ /* If the client requested "?" then produce a listing */
+ if (!strcmp(buf, "?")) {
+ cprintf("%d %s\n",LISTING_FOLLOWS,buf);
+ dp = opendir(dirs[1]);
+ if (dp != NULL) {
+ while (d = readdir(dp), d != NULL) {
+ if (d->d_name[0] != '.') {
+ cprintf(" %s\n", d->d_name);
+ }
+ }
+ closedir(dp);
+ }
+ cprintf("000\n");
+ }
+
+ /* Otherwise, look for the requested file by name. */
+ else {
mesg_locate(targ, sizeof targ, buf2, 2, (const char **)dirs);
if (strlen(targ) == 0) {
- mesg_locate(targ, sizeof targ, buf, 2, (const char **)dirs);
- }
+ snprintf(buf2, sizeof buf2, "%s.%d",
+ buf, CC->cs_clientdev);
+ mesg_locate(targ, sizeof targ, buf2, 2,
+ (const char **)dirs);
+ if (strlen(targ) == 0) {
+ mesg_locate(targ, sizeof targ, buf, 2,
+ (const char **)dirs);
+ }
+ }
}
+
free(dirs[0]);
free(dirs[1]);
if (buf[a] == '/') buf[a] = '.';
}
- dirs[0] = strdup(
#ifdef HAVE_DATA_DIR
- DATA_DIR"/"
+ dirs[0] = strdup(DATA_DIR "/messages");
+#else
+ dirs[0] = strdup("messages");
#endif
- "messages");
- dirs[1] = strdup(
+
#ifdef HAVE_DATA_DIR
- DATA_DIR"/"
+ dirs[1] = strdup(DATA_DIR "/help");
+#else
+ dirs[1] = strdup("help");
#endif
- "help");
+
mesg_locate(targ, sizeof targ, buf, 2, (const char**)dirs);
free(dirs[0]);
free(dirs[1]);
* This loop recognizes all server commands.
*/
void do_command_loop(void) {
- char cmdbuf[1024];
+ char cmdbuf[SIZ];
time(&CC->lastcmd);
memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
if (client_getln(cmdbuf, sizeof cmdbuf) < 1) {
- lprintf(CTDL_ERR, "Client socket is broken; ending session\n");
+ lprintf(CTDL_ERR, "Client disconnected: ending session.\n");
CC->kill_me = 1;
return;
}
cmd_rdir();
}
+ else if (!strncasecmp(cmdbuf,"EUID",4)) {
+ cmd_euid(&cmdbuf[5]);
+ }
+
else if (!strncasecmp(cmdbuf,"MSG0",4)) {
cmd_msg0(&cmdbuf[5]);
}