*
*/
-#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"
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) {
struct stat statbuf;
static time_t pc_timestamp = 0;
static char public_clients[SIZ];
+ static char public_clients_file[SIZ];
-#ifndef HAVE_ETC
-#define PUBLIC_CLIENTS "./public_clients"
-#else
-#define PUBLIC_CLIENTS ETC_DIR"/public_clients"
-#endif
+ snprintf(public_clients_file,
+ sizeof public_clients_file,
+ "%s/public_clients",
+ ctdl_etc_dir);
/*
* Check the time stamp on the public_clients file. If it's been
* time we've been through the loop), read its contents and learn
* the IP addresses of the listed hosts.
*/
- if (stat(PUBLIC_CLIENTS, &statbuf) != 0) {
+ if (stat(public_clients_file, &statbuf) != 0) {
/* No public_clients file exists, so bail out */
- lprintf(CTDL_WARNING, "Warning: '%s' does not exist\n", PUBLIC_CLIENTS);
+ lprintf(CTDL_WARNING, "Warning: '%s' does not exist\n",
+ public_clients_file);
return(0);
}
if (statbuf.st_mtime > pc_timestamp) {
begin_critical_section(S_PUBLIC_CLIENTS);
- lprintf(CTDL_INFO, "Loading %s\n", PUBLIC_CLIENTS);
+ lprintf(CTDL_INFO, "Loading %s\n", public_clients_file);
safestrncpy(public_clients, "127.0.0.1", sizeof public_clients);
if (hostname_to_dotted_quad(addrbuf, config.c_fqdn) == 0) {
strcat(public_clients, addrbuf);
}
- fp = fopen(
-#ifndef HAVE_ETC
- "."
-#else
- ETC_DIR
-#endif
- "/public_clients", "r");
+ fp = fopen(public_clients_file, "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);
- dirs[0] = strdup(
-#ifdef HAVE_DATA_DIR
- DATA_DIR"/"
-#endif
- "messages");
- dirs[1] = strdup(
-#ifdef HAVE_DATA_DIR
- DATA_DIR"/"
-#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);
+ dirs[0] = strdup(ctdl_message_dir);
+ dirs[1] = strdup(ctdl_hlp_dir);
+
+ 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");
+ free(dirs[0]);
+ free(dirs[1]);
+ return;
+ }
+
+ /* 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"/"
-#endif
- "messages");
- dirs[1] = strdup(
-#ifdef HAVE_DATA_DIR
- DATA_DIR"/"
-#endif
- "help");
+ dirs[0] = strdup(ctdl_message_dir);
+ dirs[1] = strdup(ctdl_hlp_dir);
+
mesg_locate(targ, sizeof targ, buf, 2, (const char**)dirs);
free(dirs[0]);
free(dirs[1]);
if (strlen(targ)==0) {
snprintf(targ, sizeof targ,
-#ifndef HAVE_DATA_DIR
- "."
-#else
- DATA_DIR
-#endif
- "/help/%s", buf);
+ "%s/%s",
+ ctdl_hlp_dir, 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 */
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]);
}