13 #include <sys/types.h>
21 #include "sysdep_decls.h"
22 #include "citserver.h"
25 #include "dynloader.h"
32 #include "internet_addressing.h"
35 struct citpop3 { /* Information about the current session */
39 #define POP3 ((struct citpop3 *)CtdlGetUserData(SYM_POP3))
45 * Here's where our POP3 session begins its happy day.
47 void pop3_greeting(void) {
49 strcpy(CC->cs_clientname, "POP3 session");
51 CtdlAllocUserData(SYM_POP3, sizeof(struct citpop3));
53 cprintf("+OK Welcome to the Citadel/UX POP3 server at %s\r\n",
59 * Specify user name (implements POP3 "USER" command)
61 void pop3_user(char *argbuf) {
65 cprintf("-ERR You are already logged in.\r\n");
69 strcpy(username, argbuf);
72 lprintf(9, "Trying <%s>\n", username);
73 if (CtdlLoginExistingUser(username) == login_ok) {
74 cprintf("+OK Password required for %s\r\n", username);
77 cprintf("-ERR No such user.\r\n");
83 * Authorize with password (implements POP3 "PASS" command)
85 void pop3_pass(char *argbuf) {
88 strcpy(password, argbuf);
91 lprintf(9, "Trying <%s>\n", password);
92 if (CtdlTryPassword(password) == pass_ok) {
93 cprintf("+OK %s is logged in!\r\n", CC->usersupp.fullname);
94 lprintf(9, "POP3 password login successful\n");
97 cprintf("-ERR That is NOT the password! Go away!\r\n");
104 * Main command loop for POP3 sessions.
106 void pop3_command_loop(void) {
110 memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
111 if (client_gets(cmdbuf) < 1) {
112 lprintf(3, "POP3 socket is broken. Ending session.\r\n");
116 lprintf(5, "citserver[%3d]: %s\r\n", CC->cs_pid, cmdbuf);
117 while (strlen(cmdbuf) < 5) strcat(cmdbuf, " ");
119 if (!strncasecmp(cmdbuf, "NOOP", 4)) {
120 cprintf("+OK This command successfully did nothing.\r\n");
123 else if (!strncasecmp(cmdbuf, "QUIT", 4)) {
124 cprintf("+OK Goodbye...\r\n");
129 else if (!strncasecmp(cmdbuf, "USER", 4)) {
130 pop3_user(&cmdbuf[5]);
133 else if (!strncasecmp(cmdbuf, "PASS", 4)) {
134 pop3_pass(&cmdbuf[5]);
137 else if (!CC->logged_in) {
138 cprintf("-ERR Not logged in.\r\n");
142 cprintf("500 I'm afraid I can't do that, Dave.\r\n");
149 char *Dynamic_Module_Init(void)
151 SYM_POP3 = CtdlGetDynamicSymbol();
152 CtdlRegisterServiceHook(POP3_PORT,