From cbd9ffc2d38ecaf73e5d4293c94478244516b25b Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Sun, 26 Dec 1999 21:50:07 +0000 Subject: [PATCH] * serv_vcard: don't run hooks when not logged in (such as in SMTP sessions) * serv_pop3: added. This is the skeleton for a module implementing POP3. --- citadel/ChangeLog | 5 ++ citadel/Makefile.in | 11 ++- citadel/internet_addressing.c | 10 ++- citadel/serv_pop3.c | 156 ++++++++++++++++++++++++++++++++++ citadel/serv_vcard.c | 4 + 5 files changed, 183 insertions(+), 3 deletions(-) create mode 100644 citadel/serv_pop3.c diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 6a5f745d7..042f1621b 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,4 +1,8 @@ $Log$ +Revision 1.432 1999/12/26 21:50:07 ajc +* serv_vcard: don't run hooks when not logged in (such as in SMTP sessions) +* serv_pop3: added. This is the skeleton for a module implementing POP3. + Revision 1.431 1999/12/23 04:46:23 ajc * "Finished" initial hack of RFC822 import @@ -1502,3 +1506,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant Fri Jul 10 1998 Art Cancro * Initial CVS import + diff --git a/citadel/Makefile.in b/citadel/Makefile.in index 4154518b6..7c6033742 100644 --- a/citadel/Makefile.in +++ b/citadel/Makefile.in @@ -26,7 +26,8 @@ SERV_ICQ=@SERV_ICQ@ CLIENT_TARGETS=citadel$(EXEEXT) whobbs$(EXEEXT) SERVER_TARGETS=citserver setup $(CHKPWD) SERV_MODULES=modules/serv_chat$(SO) modules/serv_vcard$(SO) \ - modules/serv_upgrade$(SO) modules/serv_smtp$(SO) \ + modules/serv_upgrade$(SO) \ + modules/serv_smtp$(SO) modules/serv_pop3$(SO) \ modules/serv_expire$(SO) $(SERV_ICQ) UTIL_TARGETS=aidepost netmailer netproc netsetup msgform readlog rcit \ stats citmail netpoll mailinglist userlist sendcommand \ @@ -71,7 +72,7 @@ SOURCES=aidepost.c citadel.c citmail.c citserver.c client_chat.c commands.c \ support.c sysdep.c tools.c user_ops.c userlist.c serv_expire.c \ whobbs.c sendcommand.c mime_parser.c base64.c qpdecode.c getutline.c \ auth.c chkpwd.c client_icq.c html.c vcard.c serv_upgrade.c \ - serv_smtp.c internet_addressing.c parsedate.c genstamp.c + serv_smtp.c serv_pop3.c internet_addressing.c parsedate.c genstamp.c DEP_FILES=$(SOURCES:.c=.d) @@ -138,6 +139,12 @@ modules/serv_smtp.so: serv_smtp.mo modules/serv_smtp.mo: serv_smtp.mo ln -f serv_smtp.mo modules +modules/serv_pop3.so: serv_pop3.mo + $(LINK_SHARED) -o modules/serv_pop3.so serv_pop3.mo + +modules/serv_pop3.mo: serv_pop3.mo + ln -f serv_pop3.mo modules + modules/serv_expire.so: serv_expire.mo $(LINK_SHARED) -o modules/serv_expire.so serv_expire.mo diff --git a/citadel/internet_addressing.c b/citadel/internet_addressing.c index c19429560..837279aab 100644 --- a/citadel/internet_addressing.c +++ b/citadel/internet_addressing.c @@ -348,6 +348,14 @@ int convert_field(struct CtdlMessage *msg, int beg, int end) { processed = 1; } + /* If a content type is specified, this becomes a MIME message. The + * content-type header itself remains in the RFC822 headers, not in + * the Citadel headers, therefore we do not set 'processed' to 1. + */ + else if (!strcasecmp(key, "Content-type")) { + msg->cm_format_type = 4; + } + /* Clean up and move on. */ phree(key); /* Don't free 'value', it's actually the same buffer */ return(processed); @@ -371,7 +379,7 @@ struct CtdlMessage *convert_internet_message(char *rfc822) { memset(msg, 0, sizeof(struct CtdlMessage)); msg->cm_magic = CTDLMESSAGE_MAGIC; /* self check */ msg->cm_anon_type = 0; /* never anonymous */ - msg->cm_format_type = 4; /* always MIME */ + msg->cm_format_type = 1; /* text unless specified */ msg->cm_fields['M'] = rfc822; lprintf(9, "Unconverted RFC822 message length = %d\n", strlen(rfc822)); diff --git a/citadel/serv_pop3.c b/citadel/serv_pop3.c new file mode 100644 index 000000000..f8dcb2fd2 --- /dev/null +++ b/citadel/serv_pop3.c @@ -0,0 +1,156 @@ +/* $Id$ */ + +#define POP3_PORT 1110 + +#include "sysdep.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "citadel.h" +#include "server.h" +#include +#include "sysdep_decls.h" +#include "citserver.h" +#include "support.h" +#include "config.h" +#include "dynloader.h" +#include "room_ops.h" +#include "user_ops.h" +#include "policy.h" +#include "database.h" +#include "msgbase.h" +#include "tools.h" +#include "internet_addressing.h" + + +struct citpop3 { /* Information about the current session */ + char FIX[3]; +}; + +#define POP3 ((struct citpop3 *)CtdlGetUserData(SYM_POP3)) + +long SYM_POP3; + + +/* + * Here's where our POP3 session begins its happy day. + */ +void pop3_greeting(void) { + + strcpy(CC->cs_clientname, "POP3 session"); + CC->internal_pgm = 1; + CtdlAllocUserData(SYM_POP3, sizeof(struct citpop3)); + + cprintf("+OK Welcome to the Citadel/UX POP3 server at %s\r\n", + config.c_fqdn); +} + + +/* + * Specify user name (implements POP3 "USER" command) + */ +void pop3_user(char *argbuf) { + char username[256]; + + if (CC->logged_in) { + cprintf("-ERR You are already logged in.\r\n"); + return; + } + + strcpy(username, argbuf); + striplt(username); + + lprintf(9, "Trying <%s>\n", username); + if (CtdlLoginExistingUser(username) == login_ok) { + cprintf("+OK Password required for %s\r\n", username); + } + else { + cprintf("-ERR No such user.\r\n"); + } +} + + +/* + * Authorize with password (implements POP3 "PASS" command) + */ +void pop3_pass(char *argbuf) { + char password[256]; + + strcpy(password, argbuf); + striplt(password); + + lprintf(9, "Trying <%s>\n", password); + if (CtdlTryPassword(password) == pass_ok) { + cprintf("+OK %s is logged in!\r\n", CC->usersupp.fullname); + lprintf(9, "POP3 password login successful\n"); + } + else { + cprintf("-ERR That is NOT the password! Go away!\r\n"); + } +} + + + +/* + * Main command loop for POP3 sessions. + */ +void pop3_command_loop(void) { + char cmdbuf[256]; + + time(&CC->lastcmd); + memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */ + if (client_gets(cmdbuf) < 1) { + lprintf(3, "POP3 socket is broken. Ending session.\r\n"); + CC->kill_me = 1; + return; + } + lprintf(5, "citserver[%3d]: %s\r\n", CC->cs_pid, cmdbuf); + while (strlen(cmdbuf) < 5) strcat(cmdbuf, " "); + + if (!strncasecmp(cmdbuf, "NOOP", 4)) { + cprintf("+OK This command successfully did nothing.\r\n"); + } + + else if (!strncasecmp(cmdbuf, "QUIT", 4)) { + cprintf("+OK Goodbye...\r\n"); + CC->kill_me = 1; + return; + } + + else if (!strncasecmp(cmdbuf, "USER", 4)) { + pop3_user(&cmdbuf[5]); + } + + else if (!strncasecmp(cmdbuf, "PASS", 4)) { + pop3_pass(&cmdbuf[5]); + } + + else if (!CC->logged_in) { + cprintf("-ERR Not logged in.\r\n"); + } + + else { + cprintf("500 I'm afraid I can't do that, Dave.\r\n"); + } + +} + + + +char *Dynamic_Module_Init(void) +{ + SYM_POP3 = CtdlGetDynamicSymbol(); + CtdlRegisterServiceHook(POP3_PORT, + pop3_greeting, + pop3_command_loop); + return "$Id$"; +} diff --git a/citadel/serv_vcard.c b/citadel/serv_vcard.c index 2a33e84a0..1e906ba22 100644 --- a/citadel/serv_vcard.c +++ b/citadel/serv_vcard.c @@ -62,6 +62,8 @@ int vcard_upload_beforesave(struct CtdlMessage *msg) { char buf[256]; + if (!CC->logged_in) return(0); /* Only do this if logged in. */ + /* If this isn't the configuration room, or if this isn't a MIME * message, don't bother. */ @@ -127,6 +129,8 @@ int vcard_upload_aftersave(struct CtdlMessage *msg) { long I; + if (!CC->logged_in) return(0); /* Only do this if logged in. */ + /* If this isn't the configuration room, or if this isn't a MIME * message, don't bother. */ -- 2.39.2