#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"
lputroom(&qrbuf);
}
+ /*
+ * Create a room in which we can deposit "deleted" messages for
+ * deferred deletion. This will silently fail if the room already
+ * exists, and that's perfectly ok, because we want it to exist.
+ */
+ create_room(DELETED_MSGS_ROOM, 3, "", 0, 1, 0, VIEW_MAILBOX);
+
+ /*
+ * Make sure it's set to be a "system room" so it doesn't show up
+ * in the <K>nown rooms list for Aides. Also set the message expire
+ * policy to "by count, 1 message" so everything gets deleted all
+ * the time (we can't set it to 0 because that's invalid, so we keep
+ * a single message around).
+ */
+ if (lgetroom(&qrbuf, DELETED_MSGS_ROOM) == 0) {
+ qrbuf.QRflags2 |= QR2_SYSTEM;
+ qrbuf.QRep.expire_mode = EXPIRE_NUMMSGS;
+ qrbuf.QRep.expire_value = 1;
+ lputroom(&qrbuf);
+ }
+
lprintf(CTDL_INFO, "Seeding the pseudo-random number generator...\n");
urandom = fopen("/dev/urandom", "r");
if (urandom != NULL) {
static time_t pc_timestamp = 0;
static char public_clients[SIZ];
+#ifndef HAVE_ETC
#define PUBLIC_CLIENTS "./public_clients"
+#else
+#define PUBLIC_CLIENTS ETC_DIR"/public_clients"
+#endif
/*
* Check the time stamp on the public_clients file. If it's been
strcat(public_clients, addrbuf);
}
- fp = fopen("public_clients", "r");
+ fp = fopen(
+#ifndef HAVE_ETC
+ "."
+#else
+ ETC_DIR
+#endif
+ "/public_clients", "r");
if (fp != NULL) while (fgets(buf, sizeof buf, fp)!=NULL) {
for (i=0; i<strlen(buf); ++i) {
if (buf[i] == '#') buf[i] = 0;
char buf[256];
char buf2[256];
char *dirs[2];
+ DIR *dp;
+ struct dirent *d;
extract_token(buf, mname, 0, '|', sizeof buf);
+#ifdef HAVE_DATA_DIR
+ dirs[0] = strdup(DATA_DIR "/messages");
+#else
dirs[0] = strdup("messages");
+#endif
+
+#ifdef HAVE_DATA_DIR
+ dirs[1] = strdup(DATA_DIR "/help");
+#else
dirs[1] = strdup("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);
+#endif
+
+ 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] = '.';
}
+#ifdef HAVE_DATA_DIR
+ dirs[0] = strdup(DATA_DIR "/messages");
+#else
dirs[0] = strdup("messages");
+#endif
+
+#ifdef HAVE_DATA_DIR
+ dirs[1] = strdup(DATA_DIR "/help");
+#else
dirs[1] = strdup("help");
+#endif
+
mesg_locate(targ, sizeof targ, buf, 2, (const char**)dirs);
free(dirs[0]);
free(dirs[1]);
if (strlen(targ)==0) {
- snprintf(targ, sizeof targ, "./help/%s", buf);
+ snprintf(targ, sizeof targ,
+#ifndef HAVE_DATA_DIR
+ "."
+#else
+ DATA_DIR
+#endif
+ "/help/%s", buf);
}
mfp = fopen(targ,"w");
* 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 */
cmd_rdir();
}
+ else if (!strncasecmp(cmdbuf,"EUID",4)) {
+ cmd_euid(&cmdbuf[5]);
+ }
+
else if (!strncasecmp(cmdbuf,"MSG0",4)) {
cmd_msg0(&cmdbuf[5]);
}
cmd_isme(&cmdbuf[5]);
}
+ else if (!strncasecmp(cmdbuf, "FUCK", 4)) {
+ cprintf("100\n");
+
+ struct CtdlMessage *msg;
+ msg = CtdlFetchMessage(3115, 1);
+ cprintf("\nCtdlOutputPreLoadedMsg(msg, MT_RFC822, HEADERS_ONLY, 0, 1);\n--\n");
+ CtdlOutputPreLoadedMsg(msg, MT_RFC822, HEADERS_ONLY, 0, 1);
+ cprintf("--\nCtdlOutputPreLoadedMsg(msg, MT_RFC822, HEADERS_NONE, 0, 1);\n--\n");
+ CtdlOutputPreLoadedMsg(msg, MT_RFC822, HEADERS_NONE, 0, 1);
+ cprintf("--\nCtdlOutputPreLoadedMsg(msg, MT_RFC822, HEADERS_ALL, 0, 1);\n--\n");
+ CtdlOutputPreLoadedMsg(msg, MT_RFC822, HEADERS_ALL, 0, 1);
+ cprintf("--\n");
+ cprintf("000\n");
+ CtdlFreeMessage(msg);
+ }
+
else if (!DLoader_Exec_Cmd(cmdbuf)) {
cprintf("%d Unrecognized or unsupported command.\n",
ERROR + CMD_NOT_SUPPORTED);