* serv_vcard: don't run hooks when not logged in (such as in SMTP sessions)
authorArt Cancro <ajc@citadel.org>
Sun, 26 Dec 1999 21:50:07 +0000 (21:50 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 26 Dec 1999 21:50:07 +0000 (21:50 +0000)
* serv_pop3: added.  This is the skeleton for a module implementing POP3.

citadel/ChangeLog
citadel/Makefile.in
citadel/internet_addressing.c
citadel/serv_pop3.c [new file with mode: 0644]
citadel/serv_vcard.c

index 6a5f745d743eb002e32d33c5c8c4d715d70ec502..042f1621b7af2ada96b802c4cd9cfe44a5c1dda1 100644 (file)
@@ -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 <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
        * Initial CVS import 
+
index 4154518b646ab7bdb381e588652633eaabbec6a1..7c603374216f008678d5b17b0b2f60be99ff8779 100644 (file)
@@ -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
 
index c1942956034645bba9cf75f19b94b22753bc9e78..837279aabea9187ebd2808836908a0f680a2c2b6 100644 (file)
@@ -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 (file)
index 0000000..f8dcb2f
--- /dev/null
@@ -0,0 +1,156 @@
+/* $Id$ */
+
+#define POP3_PORT      1110
+
+#include "sysdep.h"
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <pwd.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/wait.h>
+#include <string.h>
+#include <limits.h>
+#include "citadel.h"
+#include "server.h"
+#include <time.h>
+#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$";
+}
index 2a33e84a050b1db7d5402dc89c69e35e08bf93d6..1e906ba22b0ffe051891e2291d2f229e30552eba 100644 (file)
@@ -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.
         */