#include "citadel_ipc.h"
#include "citadel_decls.h"
#include "tools.h"
-
+#include "citadel_dirs.h"
#ifdef THREADED_CLIENT
pthread_mutex_t rwlock;
#endif
int CtdlIPCQuit(CtdlIPC *ipc)
{
register int ret = 221; /* Default to successful quit */
- char aaa[128];
+ char aaa[SIZ];
CtdlIPC_lock(ipc);
if (ipc->sock > -1) {
int CtdlIPCLogout(CtdlIPC *ipc)
{
register int ret;
- char aaa[128];
+ char aaa[SIZ];
CtdlIPC_lock(ipc);
CtdlIPC_putline(ipc, "LOUT");
{"LKRA", "LKRN", "LKRO", "LZRM", "LRMS", "LPRM" };
char aaa[SIZ];
char *bbb = NULL;
- size_t bbbsize;
+ size_t bbb_len;
if (!listing) return -2;
if (*listing) return -2; /* Free the listing first */
if (floor < -1) return -2; /* Can't validate upper bound, sorry */
sprintf(aaa, "%s %d", proto[which], floor);
- ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, &bbb, &bbbsize, cret);
+ ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, &bbb, &bbb_len, cret);
if (ret / 100 == 1) {
struct march *mptr;
while (bbb && strlen(bbb)) {
int a;
- extract_token(aaa, bbb, 0, '\n');
+ extract_token(aaa, bbb, 0, '\n', sizeof aaa);
a = strlen(aaa);
memmove(bbb, bbb + a + 1, strlen(bbb) - a);
mptr = (struct march *) malloc(sizeof (struct march));
if (mptr) {
mptr->next = NULL;
- extract(mptr->march_name, aaa, 0);
+ extract_token(mptr->march_name, aaa, 0, '|', sizeof mptr->march_name);
mptr->march_flags = (unsigned int) extract_int(aaa, 1);
mptr->march_floor = (char) extract_int(aaa, 2);
mptr->march_order = (char) extract_int(aaa, 3);
}
}
*listing = march;
+ if (bbb) free(bbb);
return ret;
}
}
ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
if (ret / 100 == 2) {
- extract(rret[0]->RRname, cret, 0);
+ extract_token(rret[0]->RRname, cret, 0, '|', sizeof rret[0]->RRname);
rret[0]->RRunread = extract_long(cret, 1);
rret[0]->RRtotal = extract_long(cret, 2);
rret[0]->RRinfoupdated = extract_int(cret, 3);
rret[0]->RRaide = extract_int(cret, 8);
rret[0]->RRnewmail = extract_long(cret, 9);
rret[0]->RRfloor = extract_int(cret, 10);
+ rret[0]->RRflags2 = extract_int(cret, 14);
} else {
free(*rret);
+ *rret = NULL;
}
+ free(aaa);
return ret;
}
{ "ALL", "OLD", "NEW", "LAST", "FIRST", "GT", "LT" };
char aaa[33];
char *bbb = NULL;
- size_t bbbsize;
+ size_t bbb_len;
if (!cret) return -2;
if (!mret) return -2;
sprintf(aaa, "MSGS %s|%d|%d", proto[which], whicharg,
(mtemplate) ? 1 : 0);
if (mtemplate) count = strlen(mtemplate);
- ret = CtdlIPCGenericCommand(ipc, aaa, mtemplate, count, &bbb, &bbbsize, cret);
+ ret = CtdlIPCGenericCommand(ipc, aaa, mtemplate, count, &bbb, &bbb_len, cret);
if (ret / 100 != 1)
return ret;
count = 0;
if (!*mret)
return -1;
while (bbb && strlen(bbb)) {
- extract_token(aaa, bbb, 0, '\n');
+ extract_token(aaa, bbb, 0, '\n', sizeof aaa);
remove_token(bbb, 0, '\n');
*mret = (unsigned long *)realloc(*mret, (size_t)((count + 2) *
sizeof (unsigned long)));
register int ret;
char aaa[SIZ];
char *bbb = NULL;
- size_t bbbsize;
+ size_t bbb_len;
int multipart_hunting = 0;
- char multipart_prefix[SIZ];
+ char multipart_prefix[128];
if (!cret) return -1;
if (!mret) return -1;
strcpy(mret[0]->content_type, "");
sprintf(aaa, "MSG%d %ld|%d", as_mime, msgnum, headers);
- ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, &bbb, &bbbsize, cret);
+ ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, &bbb, &bbb_len, cret);
if (ret / 100 == 1) {
if (as_mime != 2) {
strcpy(mret[0]->mime_chosen, "1"); /* Default chosen-part is "1" */
while (strlen(bbb) > 4 && bbb[4] == '=') {
- extract_token(aaa, bbb, 0, '\n');
+ extract_token(aaa, bbb, 0, '\n', sizeof aaa);
remove_token(bbb, 0, '\n');
if (!strncasecmp(aaa, "nhdr=yes", 8))
* us to determine which part we want to download.
*/
else if (!strncasecmp(aaa, "pref=", 5)) {
- extract(multipart_prefix, &aaa[5], 1);
+ extract_token(multipart_prefix, &aaa[5], 1, '|', sizeof multipart_prefix);
if (!strcasecmp(multipart_prefix,
"multipart/alternative")) {
++multipart_hunting;
}
}
else if (!strncasecmp(aaa, "suff=", 5)) {
- extract(multipart_prefix, &aaa[5], 1);
+ extract_token(multipart_prefix, &aaa[5], 1, '|', sizeof multipart_prefix);
if (!strcasecmp(multipart_prefix,
"multipart/alternative")) {
++multipart_hunting;
if (ptr) {
/* Fill the buffers for the caller */
- extract(ptr->name, &aaa[5], 0);
- extract(ptr->filename, &aaa[5], 1);
- extract(ptr->number, &aaa[5], 2);
- extract(ptr->disposition, &aaa[5], 3);
- extract(ptr->mimetype, &aaa[5], 4);
+ extract_token(ptr->name, &aaa[5], 0, '|', sizeof ptr->name);
+ extract_token(ptr->filename, &aaa[5], 1, '|', sizeof ptr->filename);
+ extract_token(ptr->number, &aaa[5], 2, '|', sizeof ptr->number);
+ extract_token(ptr->disposition, &aaa[5], 3, '|', sizeof ptr->disposition);
+ extract_token(ptr->mimetype, &aaa[5], 4, '|', sizeof ptr->mimetype);
ptr->length = extract_long(&aaa[5], 5);
if (!mret[0]->attachments)
mret[0]->attachments = ptr;
/* If doing a MIME thing, pull out the extra headers */
if (as_mime == 4) {
do {
- if (!strncasecmp(bbb, "Content-type: ", 14)) {
- extract_token(mret[0]->content_type, bbb, 0, '\n');
- strcpy(mret[0]->content_type,
- &mret[0]->content_type[14]);
+ if (!strncasecmp(bbb, "Content-type:", 13)) {
+ extract_token(mret[0]->content_type, bbb, 0, '\n', sizeof mret[0]->content_type);
+ strcpy(mret[0]->content_type, &mret[0]->content_type[13]);
striplt(mret[0]->content_type);
+
+ /* strip out ";charset=" portion. FIXME do something with
+ * the charset (like... convert it) instead of just throwing
+ * it away
+ */
+ if (strstr(mret[0]->content_type, ";") != NULL) {
+ strcpy(strstr(mret[0]->content_type, ";"), "");
+ }
+
+ }
+ if (!strncasecmp(bbb, "X-Citadel-MSG4-Partnum:", 23)) {
+ extract_token(mret[0]->mime_chosen, bbb, 0, '\n', sizeof mret[0]->mime_chosen);
+ strcpy(mret[0]->mime_chosen, &mret[0]->mime_chosen[23]);
+ striplt(mret[0]->mime_chosen);
}
remove_token(bbb, 0, '\n');
} while ((bbb[0] != 0) && (bbb[0] != '\n'));
int line = 0;
while (*listing && strlen(listing)) {
- extract_token(buf, listing, 0, '\n');
+ extract_token(buf, listing, 0, '\n', sizeof buf);
remove_token(listing, 0, '\n');
switch (line++) {
case 0: ipc->ServInfo.pid = atoi(buf);
break;
case 5: ipc->ServInfo.rev_level = atoi(buf);
break;
- case 6: strcpy(ipc->ServInfo.bbs_city,buf);
+ case 6: strcpy(ipc->ServInfo.site_location,buf);
break;
case 7: strcpy(ipc->ServInfo.sysadm,buf);
break;
break;
case 14: ipc->ServInfo.supports_ldap = atoi(buf);
break;
+ case 15: ipc->ServInfo.newuser_disabled = atoi(buf);
+ break;
}
}
}
+ if (listing) free(listing);
return ret;
}
ret = CtdlIPCGenericCommand(ipc, "GETR", NULL, 0, NULL, NULL, cret);
if (ret / 100 == 2) {
- extract(qret[0]->QRname, cret, 0);
- extract(qret[0]->QRpasswd, cret, 1);
- extract(qret[0]->QRdirname, cret, 2);
+ extract_token(qret[0]->QRname, cret, 0, '|', sizeof qret[0]->QRname);
+ extract_token(qret[0]->QRpasswd, cret, 1, '|', sizeof qret[0]->QRpasswd);
+ extract_token(qret[0]->QRdirname, cret, 2, '|', sizeof qret[0]->QRdirname);
qret[0]->QRflags = extract_int(cret, 3);
qret[0]->QRfloor = extract_int(cret, 4);
qret[0]->QRorder = extract_int(cret, 5);
/* ENT0 */
-int CtdlIPCPostMessage(CtdlIPC *ipc, int flag, const struct ctdlipcmessage *mr, char *cret)
+int CtdlIPCPostMessage(CtdlIPC *ipc, int flag, int *subject_required, const struct ctdlipcmessage *mr, char *cret)
{
register int ret;
char cmd[SIZ];
mr->anonymous, mr->type, mr->subject, mr->author);
ret = CtdlIPCGenericCommand(ipc, cmd, mr->text, strlen(mr->text), NULL,
NULL, cret);
+ if ((flag == 0) && (subject_required != NULL)) {
+ /* Is the server strongly recommending that the user enter a message subject? */
+ if ((cret[3] != '\0') && (cret[4] != '\0')) {
+ *subject_required = extract_int(&cret[4], 1);
+ }
+
+
+ }
return ret;
}
/* LIST */
-int CtdlIPCUserListing(CtdlIPC *ipc, char **listing, char *cret)
+int CtdlIPCUserListing(CtdlIPC *ipc, char *searchstring, char **listing, char *cret)
{
size_t bytes;
+ char *cmd;
+ int ret;
if (!cret) return -1;
if (!listing) return -1;
if (*listing) return -1;
+ if (!searchstring) return -1;
+
+ cmd = malloc(strlen(searchstring) + 10);
+ sprintf(cmd, "LIST %s", searchstring);
- return CtdlIPCGenericCommand(ipc, "LIST", NULL, 0, listing, &bytes, cret);
+ ret = CtdlIPCGenericCommand(ipc, cmd, NULL, 0, listing, &bytes, cret);
+ free(cmd);
+ return(ret);
}
ipc->downloading = 1;
bytes = extract_long(cret, 0);
last_mod = extract_int(cret, 1);
- extract(mimetype, cret, 2);
+ extract_token(mimetype, cret, 2, '|', sizeof mimetype);
ret = CtdlIPCReadDownload(ipc, buf, bytes, resume,
progress_gauge_callback, cret);
ipc->downloading = 1;
bytes = extract_long(cret, 0);
last_mod = extract_int(cret, 1);
- extract(filename, cret, 2);
- extract(mimetype, cret, 3);
+ extract_token(filename, cret, 2, '|', sizeof filename);
+ extract_token(mimetype, cret, 3, '|', sizeof mimetype);
/* ret = CtdlIPCReadDownload(ipc, buf, bytes, 0, progress_gauge_callback, cret); */
ret = CtdlIPCHighSpeedReadDownload(ipc, buf, bytes, 0, progress_gauge_callback, cret);
ret = CtdlIPCEndDownload(ipc, cret);
ipc->downloading = 1;
bytes = extract_long(cret, 0);
last_mod = extract_int(cret, 1);
- extract(mimetype, cret, 2);
+ extract_token(mimetype, cret, 2, '|', sizeof mimetype);
/* ret = CtdlIPCReadDownload(ipc, buf, bytes, 0, progress_gauge_callback, cret); */
ret = CtdlIPCHighSpeedReadDownload(ipc, buf, bytes, 0, progress_gauge_callback, cret);
ret = CtdlIPCEndDownload(ipc, cret);
ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
if (ret / 100 == 2) {
- extract(uret[0]->fullname, cret, 0);
- extract(uret[0]->password, cret, 1);
+ extract_token(uret[0]->fullname, cret, 0, '|', sizeof uret[0]->fullname);
+ extract_token(uret[0]->password, cret, 1, '|', sizeof uret[0]->password);
uret[0]->flags = extract_int(cret, 2);
uret[0]->timescalled = extract_long(cret, 3);
uret[0]->posted = extract_long(cret, 4);
struct ExpirePolicy **policy, char *cret)
{
static char *proto[] = {"room", "floor", "site", "mailboxes" };
- char aaa[11];
+ char cmd[256];
register int ret;
if (!cret) return -2;
if (!*policy) return -1;
if (which < 0 || which > 3) return -2;
- sprintf(aaa, "GPEX %s", proto[which]);
- ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
+ sprintf(cmd, "GPEX %s", proto[which]);
+ ret = CtdlIPCGenericCommand(ipc, cmd, NULL, 0, NULL, NULL, cret);
if (ret / 100 == 2) {
policy[0]->expire_mode = extract_int(cret, 0);
policy[0]->expire_value = extract_int(cret, 1);
}
return ret;
-
}
int CtdlIPCGetSystemConfigByType(CtdlIPC *ipc, const char *mimetype,
char **listing, char *cret)
{
+ register int ret;
char *aaa;
size_t bytes;
aaa = malloc(strlen(mimetype) + 13);
if (!aaa) return -1;
sprintf(aaa, "CONF GETSYS|%s", mimetype);
- return CtdlIPCGenericCommand(ipc, aaa, NULL, 0,
+ ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0,
listing, &bytes, cret);
+ free(aaa);
+ return ret;
}
int CtdlIPCSetSystemConfigByType(CtdlIPC *ipc, const char *mimetype,
const char *listing, char *cret)
{
+ register int ret;
char *aaa;
if (!cret) return -2;
aaa = malloc(strlen(mimetype) + 13);
if (!aaa) return -1;
sprintf(aaa, "CONF PUTSYS|%s", mimetype);
- return CtdlIPCGenericCommand(ipc, aaa, listing, strlen(listing),
+ ret = CtdlIPCGenericCommand(ipc, aaa, listing, strlen(listing),
NULL, NULL, cret);
+ free(aaa);
+ return ret;
}
SSL_set_session_id_context(temp_ssl, "Citadel SID", 14);
#endif
- if (!access("/var/run/egd-pool", F_OK))
- RAND_egd("/var/run/egd-pool");
+ if (!access(EGD_POOL, F_OK))
+ RAND_egd(EGD_POOL);
if (!RAND_status()) {
error_printf("PRNG not properly seeded\n");
/* QDIR */
int CtdlIPCDirectoryLookup(CtdlIPC *ipc, const char *address, char *cret)
{
+ register int ret;
char *aaa;
if (!address) return -2;
if (!aaa) return -1;
sprintf(aaa, "QDIR %s", address);
- return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
+ ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret);
+ free(aaa);
+ return ret;
}
if (!buf) return 0;
if (!cret) return 0;
if (bytes < 1) return 0;
- if (offset < 0) return 0;
CtdlIPC_lock(ipc);
sprintf(aaa, "READ %d|%d", (int)offset, (int)bytes);
*buf = (void *)realloc(*buf, (size_t)(offset + len));
if (*buf) {
/* I know what I'm doing */
- serv_read(ipc, (*buf + offset), len);
+ serv_read(ipc, ((char *)(*buf) + offset), len);
} else {
/* We have to read regardless */
serv_read(ipc, aaa, len);
else {
len = extract_long(&aaa[4], 0);
/* I know what I'm doing */
- serv_read(ipc, ((*buf) + (i * 4096)), len);
+ serv_read(ipc, ((char *)(*buf) + (i * 4096)), len);
}
if (progress_gauge_callback)
progress_gauge_callback(ipc, i * 4096 + len, bytes);
char aaa[SIZ];
char buf[4096];
FILE *fd;
+ int ferr;
if (!cret) return -1;
if (!path) return -1;
}
if (progress_gauge_callback)
progress_gauge_callback(ipc, 1, 1);
- return (!ferror(fd) ? ret : -2);
+ ferr = ferror(fd);
+ fclose(fd);
+ return (!ferr ? ret : -2);
}
sleep(1);
continue;
}
+/***
+ Not sure why we'd want to handle these error codes any differently,
+ but this definitely isn't the way to handle them. Someone must have
+ naively assumed that we could fall back to unencrypted communications,
+ but all it does is just recursively blow the stack.
if (errval == SSL_ERROR_ZERO_RETURN ||
errval == SSL_ERROR_SSL) {
serv_read(ipc, &buf[len], bytes - len);
return;
}
+ ***/
error_printf("SSL_read in serv_read: %s\n",
ERR_reason_error_string(ERR_peek_error()));
connection_died(ipc, 1);
}
/* Get started */
+ a = 0;
ssl_ctx = NULL;
dh = NULL;
SSL_load_error_strings();
serv_read(ipc, &buf[i], 1);
/* Strip the trailing newline (and carriage return, if present) */
- if (buf[i] == 10) buf[i--] = 0;
- if (buf[i] == 13) buf[i--] = 0;
+ if (i>=0 && buf[i] == 10) buf[i--] = 0;
+ if (i>=0 && buf[i] == 13) buf[i--] = 0;
}
void CtdlIPC_chat_recv(CtdlIPC* ipc, char* buf)
{
- return CtdlIPC_getline(ipc, buf);
+ CtdlIPC_getline(ipc, buf);
}
/*
*/
static void CtdlIPC_putline(CtdlIPC *ipc, const char *buf)
{
- /* error_printf("< %s\n", buf); */
- serv_write(ipc, buf, strlen(buf));
- serv_write(ipc, "\n", 1);
+ char *cmd = NULL;
+ int len;
+
+ len = strlen(buf);
+ cmd = malloc(len + 2);
+ if (!cmd) {
+ /* This requires no extra memory */
+ serv_write(ipc, buf, len);
+ serv_write(ipc, "\n", 1);
+ } else {
+ /* This is network-optimized */
+ strncpy(cmd, buf, len);
+ strcpy(cmd + len, "\n");
+ serv_write(ipc, cmd, len + 1);
+ free(cmd);
+ }
ipc->last_command_sent = time(NULL);
}
void CtdlIPC_chat_send(CtdlIPC* ipc, const char* buf)
{
- return CtdlIPC_putline(ipc, buf);
+ CtdlIPC_putline(ipc, buf);
}
/* If we're using a unix domain socket we can do a bunch of stuff */
if (!strcmp(cithost, UDS)) {
if (!strcasecmp(citport, DEFAULT_PORT)) {
- snprintf(sockpath, sizeof sockpath, "%s%s",
- BBSDIR, "/citadel.socket");
+ snprintf(sockpath, sizeof sockpath, file_citadel_socket);
}
else {
- snprintf(sockpath, sizeof sockpath, "%s%s",
- citport, "/citadel.socket");
+ snprintf(sockpath, sizeof sockpath, "%s/%s", citport, "citadel.socket");
}
ipc->sock = uds_connectsock(&(ipc->isLocal), sockpath);
if (ipc->sock == -1) {