Improve command line and error handling in pop3d.
* pop3d/pop3d.h: Remove unused includes. (ABORT): New state. (pop3d_command_handler_t, struct pop3d_command): New types. (pop3d_find_command): New function. (pop3d_stat,pop3d_top,pop3d_uidl,pop3d_user,pop3d_apop) (pop3d_auth,pop3d_capa,pop3d_dele,pop3d_list,pop3d_noop) (pop3d_quit,pop3d_retr,pop3d_rset): Remove const from the arguments. Functions are free to modify it. (pop3d_parse_command): New function. * pop3d/cmd.c: New file. * pop3d/Makefile.am: Link in cmd.o * pop3d/apop.c: Use pop3d_parse_command to parse commands * pop3d/auth.c: Likewise. * pop3d/extra.c (pop3d_args, pop3d_cmd): Remove. (pop3d_parse_command): New function. (pop3d_abquit): use pop3d_error_string to convert error numbers to messages. * pop3d/pop3d.c (cb_bulletin_db): Protect by #ifdef USE_DBM (pop3d_mainloop): Change loop condition. Use pop3d_parse_command to parse commands, pop3d_find_command to lookup handlers in the command table and pop3d_error_string to convert error numbers to messages. (main): Call enable_stls if necessary. * pop3d/capa.c, pop3d/dele.c, pop3d/list.c, pop3d/noop.c, pop3d/quit.c, pop3d/retr.c, pop3d/rset.c, pop3d/stat.c, pop3d/stls.c, pop3d/top.c, pop3d/uidl.c, pop3d/user.c: Remove const qualifier from the command handler argument.
Showing
19 changed files
with
229 additions
and
287 deletions
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | 1 | /* GNU Mailutils -- a suite of utilities for electronic mail |
2 | Copyright (C) 1999, 2000, 2001, 2002, 2005, 2007 Free Software Foundation, Inc. | 2 | Copyright (C) 1999, 2000, 2001, 2002, 2005, 2007, |
3 | 2009 Free Software Foundation, Inc. | ||
3 | 4 | ||
4 | GNU Mailutils is free software; you can redistribute it and/or modify | 5 | GNU Mailutils is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
... | @@ -12,9 +13,7 @@ | ... | @@ -12,9 +13,7 @@ |
12 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
13 | 14 | ||
14 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
15 | along with GNU Mailutils; if not, write to the Free Software | 16 | along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ |
16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
17 | MA 02110-1301 USA */ | ||
18 | 17 | ||
19 | #include "pop3d.h" | 18 | #include "pop3d.h" |
20 | 19 | ||
... | @@ -144,9 +143,9 @@ pop3d_apopuser (const char *user) | ... | @@ -144,9 +143,9 @@ pop3d_apopuser (const char *user) |
144 | } | 143 | } |
145 | 144 | ||
146 | int | 145 | int |
147 | pop3d_apop (const char *arg) | 146 | pop3d_apop (char *arg) |
148 | { | 147 | { |
149 | char *tmp, *user_digest, *user, *password; | 148 | char *tmp, *password, *user_digest, *user; |
150 | char buf[POP_MAXCMDLEN]; | 149 | char buf[POP_MAXCMDLEN]; |
151 | struct mu_md5_ctx md5context; | 150 | struct mu_md5_ctx md5context; |
152 | unsigned char md5digest[16]; | 151 | unsigned char md5digest[16]; |
... | @@ -157,22 +156,18 @@ pop3d_apop (const char *arg) | ... | @@ -157,22 +156,18 @@ pop3d_apop (const char *arg) |
157 | if (strlen (arg) == 0) | 156 | if (strlen (arg) == 0) |
158 | return ERR_BAD_ARGS; | 157 | return ERR_BAD_ARGS; |
159 | 158 | ||
160 | user = pop3d_cmd (arg); | 159 | pop3d_parse_command (arg, &user, &user_digest); |
161 | if (strlen (user) > (POP_MAXCMDLEN - APOP_DIGEST)) | 160 | if (strlen (user) > (POP_MAXCMDLEN - APOP_DIGEST)) |
162 | { | 161 | { |
163 | mu_diag_output (MU_DIAG_INFO, _("User name too long: %s"), user); | 162 | mu_diag_output (MU_DIAG_INFO, _("User name too long: %s"), user); |
164 | free (user); | ||
165 | return ERR_BAD_ARGS; | 163 | return ERR_BAD_ARGS; |
166 | } | 164 | } |
167 | user_digest = pop3d_args (arg); | ||
168 | 165 | ||
169 | password = pop3d_apopuser (user); | 166 | password = pop3d_apopuser (user); |
170 | if (password == NULL) | 167 | if (password == NULL) |
171 | { | 168 | { |
172 | mu_diag_output (MU_DIAG_INFO, _("Password for `%s' not found in the database"), | 169 | mu_diag_output (MU_DIAG_INFO, _("Password for `%s' not found in the database"), |
173 | user); | 170 | user); |
174 | free (user); | ||
175 | free (user_digest); | ||
176 | return ERR_BAD_LOGIN; | 171 | return ERR_BAD_LOGIN; |
177 | } | 172 | } |
178 | 173 | ||
... | @@ -194,14 +189,10 @@ pop3d_apop (const char *arg) | ... | @@ -194,14 +189,10 @@ pop3d_apop (const char *arg) |
194 | if (strcmp (user_digest, buf)) | 189 | if (strcmp (user_digest, buf)) |
195 | { | 190 | { |
196 | mu_diag_output (MU_DIAG_INFO, _("APOP failed for `%s'"), user); | 191 | mu_diag_output (MU_DIAG_INFO, _("APOP failed for `%s'"), user); |
197 | free (user); | ||
198 | free (user_digest); | ||
199 | return ERR_BAD_LOGIN; | 192 | return ERR_BAD_LOGIN; |
200 | } | 193 | } |
201 | 194 | ||
202 | free (user_digest); | ||
203 | auth_data = mu_get_auth_by_name (user); | 195 | auth_data = mu_get_auth_by_name (user); |
204 | free (user); | ||
205 | if (auth_data == NULL) | 196 | if (auth_data == NULL) |
206 | return ERR_BAD_LOGIN; | 197 | return ERR_BAD_LOGIN; |
207 | 198 | ... | ... |
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | 1 | /* GNU Mailutils -- a suite of utilities for electronic mail |
2 | Copyright (C) 1999, 2001 Free Software Foundation, Inc. | 2 | Copyright (C) 1999, 2001, 2009 Free Software Foundation, Inc. |
3 | 3 | ||
4 | GNU Mailutils is free software; you can redistribute it and/or modify | 4 | GNU Mailutils is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 5 | it under the terms of the GNU General Public License as published by |
... | @@ -12,16 +12,14 @@ | ... | @@ -12,16 +12,14 @@ |
12 | GNU General Public License for more details. | 12 | GNU General Public License for more details. |
13 | 13 | ||
14 | You should have received a copy of the GNU General Public License | 14 | You should have received a copy of the GNU General Public License |
15 | along with GNU Mailutils; if not, write to the Free Software | 15 | along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ |
16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
17 | MA 02110-1301 USA */ | ||
18 | 16 | ||
19 | #include "pop3d.h" | 17 | #include "pop3d.h" |
20 | 18 | ||
21 | /* AUTH is not yet implemented */ | 19 | /* AUTH is not yet implemented */ |
22 | 20 | ||
23 | int | 21 | int |
24 | pop3d_auth (const char *arg MU_ARG_UNUSED) | 22 | pop3d_auth (char *arg MU_ARG_UNUSED) |
25 | { | 23 | { |
26 | if (state != AUTHORIZATION) | 24 | if (state != AUTHORIZATION) |
27 | return ERR_WRONG_STATE; | 25 | return ERR_WRONG_STATE; | ... | ... |
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | 1 | /* GNU Mailutils -- a suite of utilities for electronic mail |
2 | Copyright (C) 1999, 2001, 2003, 2007 Free Software Foundation, Inc. | 2 | Copyright (C) 1999, 2001, 2003, 2007, 2009 Free Software Foundation, Inc. |
3 | 3 | ||
4 | GNU Mailutils is free software; you can redistribute it and/or modify | 4 | GNU Mailutils is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 5 | it under the terms of the GNU General Public License as published by |
... | @@ -12,9 +12,7 @@ | ... | @@ -12,9 +12,7 @@ |
12 | GNU General Public License for more details. | 12 | GNU General Public License for more details. |
13 | 13 | ||
14 | You should have received a copy of the GNU General Public License | 14 | You should have received a copy of the GNU General Public License |
15 | along with GNU Mailutils; if not, write to the Free Software | 15 | along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ |
16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
17 | MA 02110-1301 USA */ | ||
18 | 16 | ||
19 | #include "pop3d.h" | 17 | #include "pop3d.h" |
20 | 18 | ||
... | @@ -28,7 +26,7 @@ | ... | @@ -28,7 +26,7 @@ |
28 | Capabilities available in the AUTHORIZATION state MUST be announced | 26 | Capabilities available in the AUTHORIZATION state MUST be announced |
29 | in both states. */ | 27 | in both states. */ |
30 | int | 28 | int |
31 | pop3d_capa (const char *arg) | 29 | pop3d_capa (char *arg) |
32 | { | 30 | { |
33 | if (strlen (arg) != 0) | 31 | if (strlen (arg) != 0) |
34 | return ERR_BAD_ARGS; | 32 | return ERR_BAD_ARGS; | ... | ... |
pop3d/cmd.c
0 → 100644
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | ||
2 | Copyright (C) 2009 Free Software Foundation, Inc. | ||
3 | |||
4 | GNU Mailutils is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 3, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | GNU Mailutils is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ | ||
16 | |||
17 | #include "pop3d.h" | ||
18 | |||
19 | static struct pop3d_command command_table[] = { | ||
20 | #ifdef WITH_TLS | ||
21 | { "STLS", pop3d_stls }, | ||
22 | # define COMMAND_TABLE_HEAD 1 | ||
23 | #else | ||
24 | # define COMMAND_TABLE_HEAD 0 | ||
25 | #endif | ||
26 | { "RETR", pop3d_retr }, | ||
27 | { "DELE", pop3d_dele }, | ||
28 | { "USER", pop3d_user }, | ||
29 | { "QUIT", pop3d_quit }, | ||
30 | { "APOP", pop3d_apop }, | ||
31 | { "AUTH", pop3d_auth }, | ||
32 | { "STAT", pop3d_stat }, | ||
33 | { "LIST", pop3d_list }, | ||
34 | { "NOOP", pop3d_noop }, | ||
35 | { "RSET", pop3d_rset }, | ||
36 | { "TOP", pop3d_top }, | ||
37 | { "UIDL", pop3d_uidl }, | ||
38 | { "CAPA", pop3d_capa }, | ||
39 | { NULL } | ||
40 | }; | ||
41 | |||
42 | static struct pop3d_command *command_table_head = | ||
43 | command_table + COMMAND_TABLE_HEAD; | ||
44 | |||
45 | pop3d_command_handler_t | ||
46 | pop3d_find_command (const char *name) | ||
47 | { | ||
48 | struct pop3d_command *p; | ||
49 | for (p = command_table_head; p->name; p++) | ||
50 | { | ||
51 | if (mu_c_strcasecmp (name, p->name) == 0) | ||
52 | return p->handler; | ||
53 | } | ||
54 | return p->handler; | ||
55 | } | ||
56 | |||
57 | #ifdef WITH_TLS | ||
58 | void | ||
59 | enable_stls () | ||
60 | { | ||
61 | command_table_head = command_table; | ||
62 | } | ||
63 | #endif | ||
64 | |||
65 | struct error_table | ||
66 | { | ||
67 | int code; | ||
68 | const char *text; | ||
69 | }; | ||
70 | |||
71 | static struct error_table error_table[] = { | ||
72 | { ERR_WRONG_STATE, "Incorrect state" }, | ||
73 | { ERR_BAD_ARGS, "Invalid arguments" }, | ||
74 | { ERR_BAD_LOGIN, "Bad login" }, | ||
75 | { ERR_NO_MESG, "No such message" }, | ||
76 | { ERR_MESG_DELE, "Message has been deleted" }, | ||
77 | { ERR_NOT_IMPL, "Not implemented" }, | ||
78 | { ERR_BAD_CMD, "Invalid command" }, | ||
79 | { ERR_MBOX_LOCK, "[IN-USE] Mailbox in use" }, | ||
80 | { ERR_TOO_LONG, "Argument too long" }, | ||
81 | { ERR_NO_MEM, "Out of memory, quitting" }, | ||
82 | { ERR_SIGNAL, "Quitting on signal" }, | ||
83 | { ERR_FILE, "Some deleted messages not removed" }, | ||
84 | { ERR_NO_IFILE, "No input stream" }, | ||
85 | { ERR_NO_OFILE, "No output stream" }, | ||
86 | { ERR_IO, "I/O error" }, | ||
87 | { ERR_PROTO, "Remote protocol error" }, | ||
88 | { ERR_TIMEOUT, "Session timed out" }, | ||
89 | { ERR_UNKNOWN, "Unknown error" }, | ||
90 | { ERR_MBOX_SYNC, "Mailbox was updated by other process" }, | ||
91 | #ifdef WITH_TLS | ||
92 | { ERR_TLS_ACTIVE, "Command not permitted when TLS active" }, | ||
93 | #endif /* WITH_TLS */ | ||
94 | { ERR_TLS_IO, "TLS I/O error" }, | ||
95 | { ERR_LOGIN_DELAY, | ||
96 | "[LOGIN-DELAY] Attempt to log in within the minimum login delay interval" }, | ||
97 | { ERR_TERMINATE, "Terminating on request" }, | ||
98 | { 0 } | ||
99 | }; | ||
100 | |||
101 | const char * | ||
102 | pop3d_error_string (int code) | ||
103 | { | ||
104 | struct error_table *ep; | ||
105 | for (ep = error_table; ep->code != 0; ep++) | ||
106 | if (ep->code == code) | ||
107 | return ep->text; | ||
108 | return "unknown error"; | ||
109 | } |
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | 1 | /* GNU Mailutils -- a suite of utilities for electronic mail |
2 | Copyright (C) 1999, 2000, 2001, 2005, 2007 Free Software Foundation, Inc. | 2 | Copyright (C) 1999, 2000, 2001, 2005, 2007, |
3 | 2009 Free Software Foundation, Inc. | ||
3 | 4 | ||
4 | GNU Mailutils is free software; you can redistribute it and/or modify | 5 | GNU Mailutils is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
... | @@ -12,16 +13,14 @@ | ... | @@ -12,16 +13,14 @@ |
12 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
13 | 14 | ||
14 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
15 | along with GNU Mailutils; if not, write to the Free Software | 16 | along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ |
16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
17 | MA 02110-1301 USA */ | ||
18 | 17 | ||
19 | #include "pop3d.h" | 18 | #include "pop3d.h" |
20 | 19 | ||
21 | /* DELE adds a message number to the list of messages to be deleted on QUIT */ | 20 | /* DELE adds a message number to the list of messages to be deleted on QUIT */ |
22 | 21 | ||
23 | int | 22 | int |
24 | pop3d_dele (const char *arg) | 23 | pop3d_dele (char *arg) |
25 | { | 24 | { |
26 | size_t num; | 25 | size_t num; |
27 | mu_message_t msg; | 26 | mu_message_t msg; | ... | ... |
... | @@ -22,66 +22,22 @@ | ... | @@ -22,66 +22,22 @@ |
22 | 22 | ||
23 | static mu_stream_t istream, ostream; | 23 | static mu_stream_t istream, ostream; |
24 | 24 | ||
25 | /* Takes a string as input and returns either the remainder of the string | 25 | void |
26 | after the first space, or a zero length string if no space */ | 26 | pop3d_parse_command (char *cmd, char **pcmd, char **parg) |
27 | |||
28 | char * | ||
29 | pop3d_args (const char *cmd) | ||
30 | { | 27 | { |
31 | int space = -1, i = 0, len; | 28 | char *p; |
32 | char *buf; | 29 | |
33 | 30 | cmd = mu_str_skip_class (cmd, MU_CTYPE_BLANK); | |
34 | len = strlen (cmd) + 1; | 31 | *pcmd = cmd; |
35 | buf = malloc (len * sizeof (char)); | 32 | p = mu_str_skip_class_comp (cmd, MU_CTYPE_SPACE); |
36 | if (buf == NULL) | 33 | *p++ = 0; |
37 | pop3d_abquit (ERR_NO_MEM); | 34 | if (*p) |
38 | |||
39 | while (space < 0 && i < len) | ||
40 | { | 35 | { |
41 | if (cmd[i] == ' ') | 36 | *parg = p; |
42 | space = i + 1; | 37 | mu_rtrim_class (p, MU_CTYPE_SPACE); |
43 | else if (cmd[i] == '\0' || cmd[i] == '\r' || cmd[i] == '\n') | ||
44 | len = i; | ||
45 | i++; | ||
46 | } | 38 | } |
47 | |||
48 | if (space < 0) | ||
49 | buf[0] = '\0'; | ||
50 | else | 39 | else |
51 | { | 40 | *parg = ""; |
52 | for (i = space; i < len; i++) | ||
53 | if (cmd[i] == '\0' || cmd[i] == '\r' || cmd[i] == '\n') | ||
54 | buf[i - space] = '\0'; | ||
55 | else | ||
56 | buf[i - space] = cmd[i]; | ||
57 | } | ||
58 | |||
59 | return buf; | ||
60 | } | ||
61 | |||
62 | /* This takes a string and returns the string up to the first space or end of | ||
63 | the string, whichever occurs first */ | ||
64 | |||
65 | char * | ||
66 | pop3d_cmd (const char *cmd) | ||
67 | { | ||
68 | char *buf; | ||
69 | int i = 0, len; | ||
70 | |||
71 | len = strlen (cmd) + 1; | ||
72 | buf = malloc (len * sizeof (char)); | ||
73 | if (buf == NULL) | ||
74 | pop3d_abquit (ERR_NO_MEM); | ||
75 | |||
76 | for (i = 0; i < len; i++) | ||
77 | { | ||
78 | if (cmd[i] == ' ' || cmd[i] == '\0' || cmd[i] == '\r' || cmd[i] == '\n') | ||
79 | len = i; | ||
80 | else | ||
81 | buf[i] = cmd[i]; | ||
82 | } | ||
83 | buf[i - 1] = '\0'; | ||
84 | return buf; | ||
85 | } | 41 | } |
86 | 42 | ||
87 | /* This is called if GNU POP3 needs to quit without going to the UPDATE stage. | 43 | /* This is called if GNU POP3 needs to quit without going to the UPDATE stage. |
... | @@ -105,7 +61,7 @@ pop3d_abquit (int reason) | ... | @@ -105,7 +61,7 @@ pop3d_abquit (int reason) |
105 | { | 61 | { |
106 | case ERR_NO_MEM: | 62 | case ERR_NO_MEM: |
107 | code = EX_SOFTWARE; | 63 | code = EX_SOFTWARE; |
108 | pop3d_outf ("-ERR Out of memory, quitting\r\n"); | 64 | pop3d_outf ("-ERR %s\r\n", pop3d_error_string (reason)); |
109 | mu_diag_output (MU_DIAG_ERROR, _("Out of memory")); | 65 | mu_diag_output (MU_DIAG_ERROR, _("Out of memory")); |
110 | break; | 66 | break; |
111 | 67 | ||
... | @@ -121,7 +77,7 @@ pop3d_abquit (int reason) | ... | @@ -121,7 +77,7 @@ pop3d_abquit (int reason) |
121 | 77 | ||
122 | case ERR_TIMEOUT: | 78 | case ERR_TIMEOUT: |
123 | code = EX_TEMPFAIL; | 79 | code = EX_TEMPFAIL; |
124 | pop3d_outf ("-ERR Session timed out\r\n"); | 80 | pop3d_outf ("-ERR %s\r\n", pop3d_error_string (reason)); |
125 | if (state == TRANSACTION) | 81 | if (state == TRANSACTION) |
126 | mu_diag_output (MU_DIAG_INFO, _("Session timed out for user: %s"), | 82 | mu_diag_output (MU_DIAG_INFO, _("Session timed out for user: %s"), |
127 | username); | 83 | username); |
... | @@ -160,7 +116,7 @@ pop3d_abquit (int reason) | ... | @@ -160,7 +116,7 @@ pop3d_abquit (int reason) |
160 | 116 | ||
161 | default: | 117 | default: |
162 | code = EX_SOFTWARE; | 118 | code = EX_SOFTWARE; |
163 | pop3d_outf ("-ERR Quitting (reason unknown)\r\n"); | 119 | pop3d_outf ("-ERR Quitting: %s\r\n", pop3d_error_string (reason)); |
164 | mu_diag_output (MU_DIAG_ERROR, _("Quitting (numeric reason %d)"), | 120 | mu_diag_output (MU_DIAG_ERROR, _("Quitting (numeric reason %d)"), |
165 | reason); | 121 | reason); |
166 | break; | 122 | break; | ... | ... |
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | 1 | /* GNU Mailutils -- a suite of utilities for electronic mail |
2 | Copyright (C) 1999, 2000, 2001, 2005, | 2 | Copyright (C) 1999, 2000, 2001, 2005, 2007, |
3 | 2007 Free Software Foundation, Inc. | 3 | 2009 Free Software Foundation, Inc. |
4 | 4 | ||
5 | GNU Mailutils is free software; you can redistribute it and/or modify | 5 | GNU Mailutils is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
... | @@ -13,16 +13,14 @@ | ... | @@ -13,16 +13,14 @@ |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with GNU Mailutils; if not, write to the Free Software | 16 | along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ |
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
18 | MA 02110-1301 USA */ | ||
19 | 17 | ||
20 | #include "pop3d.h" | 18 | #include "pop3d.h" |
21 | 19 | ||
22 | /* Displays the size of message number arg or all messages (if no arg) */ | 20 | /* Displays the size of message number arg or all messages (if no arg) */ |
23 | 21 | ||
24 | int | 22 | int |
25 | pop3d_list (const char *arg) | 23 | pop3d_list (char *arg) |
26 | { | 24 | { |
27 | size_t mesgno; | 25 | size_t mesgno; |
28 | mu_message_t msg = NULL; | 26 | mu_message_t msg = NULL; | ... | ... |
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | 1 | /* GNU Mailutils -- a suite of utilities for electronic mail |
2 | Copyright (C) 1999, 2001, 2007 Free Software Foundation, Inc. | 2 | Copyright (C) 1999, 2001, 2007, 2009 Free Software Foundation, Inc. |
3 | 3 | ||
4 | GNU Mailutils is free software; you can redistribute it and/or modify | 4 | GNU Mailutils is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 5 | it under the terms of the GNU General Public License as published by |
... | @@ -12,16 +12,14 @@ | ... | @@ -12,16 +12,14 @@ |
12 | GNU General Public License for more details. | 12 | GNU General Public License for more details. |
13 | 13 | ||
14 | You should have received a copy of the GNU General Public License | 14 | You should have received a copy of the GNU General Public License |
15 | along with GNU Mailutils; if not, write to the Free Software | 15 | along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ |
16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
17 | MA 02110-1301 USA */ | ||
18 | 16 | ||
19 | #include "pop3d.h" | 17 | #include "pop3d.h" |
20 | 18 | ||
21 | /* Does nothing */ | 19 | /* Does nothing */ |
22 | 20 | ||
23 | int | 21 | int |
24 | pop3d_noop (const char *arg) | 22 | pop3d_noop (char *arg) |
25 | { | 23 | { |
26 | if (strlen (arg) != 0) | 24 | if (strlen (arg) != 0) |
27 | return ERR_BAD_ARGS; | 25 | return ERR_BAD_ARGS; | ... | ... |
... | @@ -117,6 +117,7 @@ cb_bulletin_source (mu_debug_t debug, void *data, mu_config_value_t *val) | ... | @@ -117,6 +117,7 @@ cb_bulletin_source (mu_debug_t debug, void *data, mu_config_value_t *val) |
117 | return 0; | 117 | return 0; |
118 | } | 118 | } |
119 | 119 | ||
120 | #ifdef USE_DBM | ||
120 | static int | 121 | static int |
121 | cb_bulletin_db (mu_debug_t debug, void *data, mu_config_value_t *val) | 122 | cb_bulletin_db (mu_debug_t debug, void *data, mu_config_value_t *val) |
122 | { | 123 | { |
... | @@ -125,6 +126,7 @@ cb_bulletin_db (mu_debug_t debug, void *data, mu_config_value_t *val) | ... | @@ -125,6 +126,7 @@ cb_bulletin_db (mu_debug_t debug, void *data, mu_config_value_t *val) |
125 | set_bulletin_db (val->v.string); /* FIXME: Error reporting? */ | 126 | set_bulletin_db (val->v.string); /* FIXME: Error reporting? */ |
126 | return 0; | 127 | return 0; |
127 | } | 128 | } |
129 | #endif | ||
128 | 130 | ||
129 | static struct mu_cfg_param pop3d_cfg_param[] = { | 131 | static struct mu_cfg_param pop3d_cfg_param[] = { |
130 | { "undelete", mu_cfg_bool, &undelete_on_startup, 0, NULL, | 132 | { "undelete", mu_cfg_bool, &undelete_on_startup, 0, NULL, |
... | @@ -327,15 +329,16 @@ pop3d_mainloop (int fd, FILE *infile, FILE *outfile) | ... | @@ -327,15 +329,16 @@ pop3d_mainloop (int fd, FILE *infile, FILE *outfile) |
327 | /* Lets boogie. */ | 329 | /* Lets boogie. */ |
328 | pop3d_outf ("+OK POP3 Ready %s\r\n", md5shared); | 330 | pop3d_outf ("+OK POP3 Ready %s\r\n", md5shared); |
329 | 331 | ||
330 | while (state != UPDATE) | 332 | while (state != UPDATE && state != ABORT) |
331 | { | 333 | { |
332 | char *buf, *arg, *cmd; | 334 | char *buf; |
333 | 335 | char *arg, *cmd; | |
336 | pop3d_command_handler_t handler; | ||
337 | |||
334 | pop3d_flush_output (); | 338 | pop3d_flush_output (); |
335 | status = OK; | 339 | status = OK; |
336 | buf = pop3d_readline (buffer, sizeof (buffer)); | 340 | buf = pop3d_readline (buffer, sizeof (buffer)); |
337 | cmd = pop3d_cmd (buf); | 341 | pop3d_parse_command (buf, &cmd, &arg); |
338 | arg = pop3d_args (buf); | ||
339 | 342 | ||
340 | /* The mailbox size needs to be check to make sure that we are in | 343 | /* The mailbox size needs to be check to make sure that we are in |
341 | sync. Some other applications may not respect the *.lock or | 344 | sync. Some other applications may not respect the *.lock or |
... | @@ -361,79 +364,13 @@ pop3d_mainloop (int fd, FILE *infile, FILE *outfile) | ... | @@ -361,79 +364,13 @@ pop3d_mainloop (int fd, FILE *infile, FILE *outfile) |
361 | status = ERR_TOO_LONG; | 364 | status = ERR_TOO_LONG; |
362 | else if (strlen (cmd) > 4) | 365 | else if (strlen (cmd) > 4) |
363 | status = ERR_BAD_CMD; | 366 | status = ERR_BAD_CMD; |
364 | else if (mu_c_strncasecmp (cmd, "RETR", 4) == 0) | 367 | else if ((handler = pop3d_find_command (cmd)) != NULL) |
365 | status = pop3d_retr (arg); | 368 | status = handler (arg); |
366 | else if (mu_c_strncasecmp (cmd, "DELE", 4) == 0) | ||
367 | status = pop3d_dele (arg); | ||
368 | else if (mu_c_strncasecmp (cmd, "USER", 4) == 0) | ||
369 | status = pop3d_user (arg); | ||
370 | else if (mu_c_strncasecmp (cmd, "QUIT", 4) == 0) | ||
371 | status = pop3d_quit (arg); | ||
372 | else if (mu_c_strncasecmp (cmd, "APOP", 4) == 0) | ||
373 | status = pop3d_apop (arg); | ||
374 | else if (mu_c_strncasecmp (cmd, "AUTH", 4) == 0) | ||
375 | status = pop3d_auth (arg); | ||
376 | else if (mu_c_strncasecmp (cmd, "STAT", 4) == 0) | ||
377 | status = pop3d_stat (arg); | ||
378 | else if (mu_c_strncasecmp (cmd, "LIST", 4) == 0) | ||
379 | status = pop3d_list (arg); | ||
380 | else if (mu_c_strncasecmp (cmd, "NOOP", 4) == 0) | ||
381 | status = pop3d_noop (arg); | ||
382 | else if (mu_c_strncasecmp (cmd, "RSET", 4) == 0) | ||
383 | status = pop3d_rset (arg); | ||
384 | else if ((mu_c_strncasecmp (cmd, "TOP", 3) == 0) && (strlen (cmd) == 3)) | ||
385 | status = pop3d_top (arg); | ||
386 | else if (mu_c_strncasecmp (cmd, "UIDL", 4) == 0) | ||
387 | status = pop3d_uidl (arg); | ||
388 | else if (mu_c_strncasecmp (cmd, "CAPA", 4) == 0) | ||
389 | status = pop3d_capa (arg); | ||
390 | #ifdef WITH_TLS | ||
391 | else if ((mu_c_strncasecmp (cmd, "STLS", 4) == 0) && tls_available) | ||
392 | { | ||
393 | status = pop3d_stls (arg); | ||
394 | if (status) | ||
395 | { | ||
396 | mu_diag_output (MU_DIAG_ERROR, _("Session terminated")); | ||
397 | break; | ||
398 | } | ||
399 | } | ||
400 | #endif /* WITH_TLS */ | ||
401 | else | 369 | else |
402 | status = ERR_BAD_CMD; | 370 | status = ERR_BAD_CMD; |
403 | 371 | ||
404 | if (status == OK) | 372 | if (status != OK) |
405 | ; /* Everything is good. */ | 373 | pop3d_outf ("-ERR %s\r\n", pop3d_error_string (status)); |
406 | else if (status == ERR_WRONG_STATE) | ||
407 | pop3d_outf ("-ERR " BAD_STATE "\r\n"); | ||
408 | else if (status == ERR_BAD_ARGS) | ||
409 | pop3d_outf ("-ERR " BAD_ARGS "\r\n"); | ||
410 | else if (status == ERR_NO_MESG) | ||
411 | pop3d_outf ("-ERR " NO_MESG "\r\n"); | ||
412 | else if (status == ERR_MESG_DELE) | ||
413 | pop3d_outf ("-ERR " MESG_DELE "\r\n"); | ||
414 | else if (status == ERR_NOT_IMPL) | ||
415 | pop3d_outf ("-ERR " NOT_IMPL "\r\n"); | ||
416 | else if (status == ERR_BAD_CMD) | ||
417 | pop3d_outf ("-ERR " BAD_COMMAND "\r\n"); | ||
418 | else if (status == ERR_BAD_LOGIN) | ||
419 | pop3d_outf ("-ERR " BAD_LOGIN "\r\n"); | ||
420 | else if (status == ERR_MBOX_LOCK) | ||
421 | pop3d_outf ("-ERR [IN-USE] " MBOX_LOCK "\r\n"); | ||
422 | else if (status == ERR_TOO_LONG) | ||
423 | pop3d_outf ("-ERR " TOO_LONG "\r\n"); | ||
424 | else if (status == ERR_FILE) | ||
425 | pop3d_outf ("-ERR " FILE_EXP "\r\n"); | ||
426 | #ifdef WITH_TLS | ||
427 | else if (status == ERR_TLS_ACTIVE) | ||
428 | pop3d_outf ("-ERR " TLS_ACTIVE "\r\n"); | ||
429 | #endif /* WITH_TLS */ | ||
430 | else if (status == ERR_LOGIN_DELAY) | ||
431 | pop3d_outf ("-ERR [LOGIN-DELAY] " LOGIN_DELAY "\r\n"); | ||
432 | else | ||
433 | pop3d_outf ("-ERR unknown error\r\n"); | ||
434 | |||
435 | free (cmd); | ||
436 | free (arg); | ||
437 | } | 374 | } |
438 | 375 | ||
439 | pop3d_bye (); | 376 | pop3d_bye (); |
... | @@ -553,7 +490,11 @@ main (int argc, char **argv) | ... | @@ -553,7 +490,11 @@ main (int argc, char **argv) |
553 | #ifdef WITH_TLS | 490 | #ifdef WITH_TLS |
554 | tls_available = mu_check_tls_environment (); | 491 | tls_available = mu_check_tls_environment (); |
555 | if (tls_available) | 492 | if (tls_available) |
556 | tls_available = mu_init_tls_libs (); | 493 | { |
494 | tls_available = mu_init_tls_libs (); | ||
495 | if (tls_available) | ||
496 | enable_stls (); | ||
497 | } | ||
557 | #endif /* WITH_TLS */ | 498 | #endif /* WITH_TLS */ |
558 | 499 | ||
559 | /* Actually run the daemon. */ | 500 | /* Actually run the daemon. */ | ... | ... |
... | @@ -31,44 +31,6 @@ | ... | @@ -31,44 +31,6 @@ |
31 | /* The implementation */ | 31 | /* The implementation */ |
32 | #define IMPL "GNU POP3 Daemon" | 32 | #define IMPL "GNU POP3 Daemon" |
33 | 33 | ||
34 | /* You can edit the messages the POP server prints out here */ | ||
35 | |||
36 | /* A command that doesn't exist */ | ||
37 | #define BAD_COMMAND "Invalid command" | ||
38 | |||
39 | /* Incorrect number of arguments passed to a command */ | ||
40 | #define BAD_ARGS "Invalid arguments" | ||
41 | |||
42 | /* Command issued in wrong state */ | ||
43 | #define BAD_STATE "Incorrect state" | ||
44 | |||
45 | /* An action on a message that doesn't exist */ | ||
46 | #define NO_MESG "No such message" | ||
47 | |||
48 | /* An action on a message that doesn't exist */ | ||
49 | #define MESG_DELE "Message has been deleted" | ||
50 | |||
51 | /* A command that is known but not implemented */ | ||
52 | #define NOT_IMPL "Not implemented" | ||
53 | |||
54 | /* Invalid username or password */ | ||
55 | #define BAD_LOGIN "Bad login" | ||
56 | |||
57 | /* User authenticated, but mailbox is locked */ | ||
58 | #define MBOX_LOCK "Mailbox in use" | ||
59 | |||
60 | /* The command argument was > 40 characters */ | ||
61 | #define TOO_LONG "Argument too long" | ||
62 | |||
63 | /* An error occured when expunging. */ | ||
64 | #define FILE_EXP "Some deleted messages not removed" | ||
65 | |||
66 | /* Command not permitted when TLS active. */ | ||
67 | #define TLS_ACTIVE "Command not permitted when TLS active" | ||
68 | |||
69 | /* Trying to log in within the minimum login delay interval */ | ||
70 | #define LOGIN_DELAY "Attempt to log in within the minimum login delay interval" | ||
71 | |||
72 | /* APOP password file, without .db or .passwd, which are added based on file | 34 | /* APOP password file, without .db or .passwd, which are added based on file |
73 | type automatically */ | 35 | type automatically */ |
74 | #define APOP_PASSFILE_NAME "apop" | 36 | #define APOP_PASSFILE_NAME "apop" |
... | @@ -183,10 +145,11 @@ extern int expire_on_exit; | ... | @@ -183,10 +145,11 @@ extern int expire_on_exit; |
183 | #define POP3_ATTRIBUTE_DELE 0x0001 | 145 | #define POP3_ATTRIBUTE_DELE 0x0001 |
184 | #define POP3_ATTRIBUTE_RETR 0x0010 | 146 | #define POP3_ATTRIBUTE_RETR 0x0010 |
185 | 147 | ||
186 | #define INITIAL -1 | 148 | #define INITIAL -1 |
187 | #define AUTHORIZATION 0 | 149 | #define AUTHORIZATION 0 |
188 | #define TRANSACTION 1 | 150 | #define TRANSACTION 1 |
189 | #define UPDATE 2 | 151 | #define UPDATE 2 |
152 | #define ABORT 3 | ||
190 | 153 | ||
191 | #define OK 0 | 154 | #define OK 0 |
192 | #define ERR_WRONG_STATE 1 | 155 | #define ERR_WRONG_STATE 1 |
... | @@ -214,6 +177,13 @@ extern int expire_on_exit; | ... | @@ -214,6 +177,13 @@ extern int expire_on_exit; |
214 | #define ERR_TERMINATE 23 | 177 | #define ERR_TERMINATE 23 |
215 | 178 | ||
216 | typedef struct mu_pop_server *mu_pop_server_t; | 179 | typedef struct mu_pop_server *mu_pop_server_t; |
180 | typedef int (*pop3d_command_handler_t) (char *); | ||
181 | |||
182 | struct pop3d_command | ||
183 | { | ||
184 | const char *name; | ||
185 | pop3d_command_handler_t handler; | ||
186 | }; | ||
217 | 187 | ||
218 | extern mu_pop_server_t pop3srv; | 188 | extern mu_pop_server_t pop3srv; |
219 | extern mu_mailbox_t mbox; | 189 | extern mu_mailbox_t mbox; |
... | @@ -234,34 +204,38 @@ extern struct mu_auth_data *auth_data; | ... | @@ -234,34 +204,38 @@ extern struct mu_auth_data *auth_data; |
234 | extern unsigned int idle_timeout; | 204 | extern unsigned int idle_timeout; |
235 | extern int pop3d_transcript; | 205 | extern int pop3d_transcript; |
236 | 206 | ||
207 | extern pop3d_command_handler_t pop3d_find_command (const char *name); | ||
208 | |||
209 | extern int pop3d_stat (char *); | ||
210 | extern int pop3d_top (char *); | ||
211 | extern int pop3d_uidl (char *); | ||
212 | extern int pop3d_user (char *); | ||
213 | extern int pop3d_apop (char *); | ||
214 | extern int pop3d_auth (char *); | ||
215 | extern int pop3d_capa (char *); | ||
216 | extern int pop3d_dele (char *); | ||
217 | extern int pop3d_list (char *); | ||
218 | extern int pop3d_noop (char *); | ||
219 | extern int pop3d_quit (char *); | ||
220 | extern int pop3d_retr (char *); | ||
221 | extern int pop3d_rset (char *); | ||
222 | |||
237 | extern void pop3d_bye (void); | 223 | extern void pop3d_bye (void); |
238 | extern int pop3d_abquit (int); | 224 | extern int pop3d_abquit (int); |
239 | extern int pop3d_apop (const char *); | ||
240 | extern char *pop3d_apopuser (const char *); | 225 | extern char *pop3d_apopuser (const char *); |
241 | extern char *pop3d_args (const char *); | ||
242 | extern int pop3d_auth (const char *); | ||
243 | extern int pop3d_capa (const char *); | ||
244 | extern char *pop3d_cmd (const char *); | ||
245 | extern int pop3d_dele (const char *); | ||
246 | extern int pop3d_list (const char *); | ||
247 | extern int pop3d_lock (void); | 226 | extern int pop3d_lock (void); |
248 | extern int pop3d_noop (const char *); | ||
249 | extern int pop3d_quit (const char *); | ||
250 | extern int pop3d_retr (const char *); | ||
251 | extern int pop3d_rset (const char *); | ||
252 | extern void process_cleanup (void); | 227 | extern void process_cleanup (void); |
253 | 228 | ||
229 | extern void pop3d_parse_command (char *cmd, char **pcmd, char **parg); | ||
230 | |||
254 | extern RETSIGTYPE pop3d_master_signal (int); | 231 | extern RETSIGTYPE pop3d_master_signal (int); |
255 | extern RETSIGTYPE pop3d_child_signal (int); | 232 | extern RETSIGTYPE pop3d_child_signal (int); |
256 | 233 | ||
257 | extern int pop3d_stat (const char *); | ||
258 | #ifdef WITH_TLS | 234 | #ifdef WITH_TLS |
259 | extern int pop3d_stls (const char *); | 235 | extern int pop3d_stls (char *); |
236 | extern void enable_stls (void); | ||
260 | #endif /* WITH_TLS */ | 237 | #endif /* WITH_TLS */ |
261 | extern int pop3d_top (const char *); | ||
262 | extern int pop3d_touchlock (void); | 238 | extern int pop3d_touchlock (void); |
263 | extern int pop3d_uidl (const char *); | ||
264 | extern int pop3d_user (const char *); | ||
265 | extern int pop3d_unlock (void); | 239 | extern int pop3d_unlock (void); |
266 | extern void pop3d_outf (const char *fmt, ...) MU_PRINTFLIKE(1,2); | 240 | extern void pop3d_outf (const char *fmt, ...) MU_PRINTFLIKE(1,2); |
267 | 241 | ||
... | @@ -291,7 +265,6 @@ extern void deliver_pending_bulletins (void); | ... | @@ -291,7 +265,6 @@ extern void deliver_pending_bulletins (void); |
291 | extern void set_bulletin_db (const char *file); | 265 | extern void set_bulletin_db (const char *file); |
292 | extern int set_bulletin_source (const char *source); | 266 | extern int set_bulletin_source (const char *source); |
293 | extern int pop3d_begin_session (void); | 267 | extern int pop3d_begin_session (void); |
294 | 268 | extern const char *pop3d_error_string (int code); | |
295 | |||
296 | 269 | ||
297 | #endif /* _POP3D_H */ | 270 | #endif /* _POP3D_H */ | ... | ... |
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | 1 | /* GNU Mailutils -- a suite of utilities for electronic mail |
2 | Copyright (C) 1999, 2000, 2001, 2002, 2005, | 2 | Copyright (C) 1999, 2000, 2001, 2002, 2005, 2007, |
3 | 2007 Free Software Foundation, Inc. | 3 | 2009 Free Software Foundation, Inc. |
4 | 4 | ||
5 | GNU Mailutils is free software; you can redistribute it and/or modify | 5 | GNU Mailutils is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
... | @@ -13,9 +13,7 @@ | ... | @@ -13,9 +13,7 @@ |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with GNU Mailutils; if not, write to the Free Software | 16 | along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ |
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
18 | MA 02110-1301 USA */ | ||
19 | 17 | ||
20 | #include "pop3d.h" | 18 | #include "pop3d.h" |
21 | 19 | ||
... | @@ -28,7 +26,7 @@ | ... | @@ -28,7 +26,7 @@ |
28 | static void pop3d_fix_mark (); | 26 | static void pop3d_fix_mark (); |
29 | 27 | ||
30 | int | 28 | int |
31 | pop3d_quit (const char *arg) | 29 | pop3d_quit (char *arg) |
32 | { | 30 | { |
33 | int err = OK; | 31 | int err = OK; |
34 | if (strlen (arg) != 0) | 32 | if (strlen (arg) != 0) | ... | ... |
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | 1 | /* GNU Mailutils -- a suite of utilities for electronic mail |
2 | Copyright (C) 1999, 2000, 2001, 2005, 2007 Free Software Foundation, Inc. | 2 | Copyright (C) 1999, 2000, 2001, 2005, 2007, |
3 | 2009 Free Software Foundation, Inc. | ||
3 | 4 | ||
4 | GNU Mailutils is free software; you can redistribute it and/or modify | 5 | GNU Mailutils is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
... | @@ -12,16 +13,14 @@ | ... | @@ -12,16 +13,14 @@ |
12 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
13 | 14 | ||
14 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
15 | along with GNU Mailutils; if not, write to the Free Software | 16 | along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ |
16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
17 | MA 02110-1301 USA */ | ||
18 | 17 | ||
19 | #include "pop3d.h" | 18 | #include "pop3d.h" |
20 | 19 | ||
21 | /* Prints out the specified message */ | 20 | /* Prints out the specified message */ |
22 | 21 | ||
23 | int | 22 | int |
24 | pop3d_retr (const char *arg) | 23 | pop3d_retr (char *arg) |
25 | { | 24 | { |
26 | size_t mesgno, n; | 25 | size_t mesgno, n; |
27 | char buf[BUFFERSIZE]; | 26 | char buf[BUFFERSIZE]; | ... | ... |
... | @@ -12,16 +12,14 @@ | ... | @@ -12,16 +12,14 @@ |
12 | GNU General Public License for more details. | 12 | GNU General Public License for more details. |
13 | 13 | ||
14 | You should have received a copy of the GNU General Public License | 14 | You should have received a copy of the GNU General Public License |
15 | along with GNU Mailutils; if not, write to the Free Software | 15 | along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ |
16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
17 | MA 02110-1301 USA */ | ||
18 | 16 | ||
19 | #include "pop3d.h" | 17 | #include "pop3d.h" |
20 | 18 | ||
21 | /* Resets the connection so that no messages are marked as deleted */ | 19 | /* Resets the connection so that no messages are marked as deleted */ |
22 | 20 | ||
23 | int | 21 | int |
24 | pop3d_rset (const char *arg) | 22 | pop3d_rset (char *arg) |
25 | { | 23 | { |
26 | size_t i; | 24 | size_t i; |
27 | size_t total = 0; | 25 | size_t total = 0; | ... | ... |
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | 1 | /* GNU Mailutils -- a suite of utilities for electronic mail |
2 | Copyright (C) 1999, 2000, 2001, 2005, 2007 Free Software Foundation, Inc. | 2 | Copyright (C) 1999, 2000, 2001, 2005, 2007, |
3 | 2009 Free Software Foundation, Inc. | ||
3 | 4 | ||
4 | GNU Mailutils is free software; you can redistribute it and/or modify | 5 | GNU Mailutils is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
... | @@ -21,7 +22,7 @@ | ... | @@ -21,7 +22,7 @@ |
21 | /* Prints the number of messages and the total size of all messages */ | 22 | /* Prints the number of messages and the total size of all messages */ |
22 | 23 | ||
23 | int | 24 | int |
24 | pop3d_stat (const char *arg) | 25 | pop3d_stat (char *arg) |
25 | { | 26 | { |
26 | size_t mesgno; | 27 | size_t mesgno; |
27 | size_t size = 0; | 28 | size_t size = 0; | ... | ... |
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | 1 | /* GNU Mailutils -- a suite of utilities for electronic mail |
2 | Copyright (C) 2003, 2007 Free Software Foundation, Inc. | 2 | Copyright (C) 2003, 2007, 2009 Free Software Foundation, Inc. |
3 | 3 | ||
4 | GNU Mailutils is free software; you can redistribute it and/or modify | 4 | GNU Mailutils is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 5 | it under the terms of the GNU General Public License as published by |
... | @@ -12,9 +12,7 @@ | ... | @@ -12,9 +12,7 @@ |
12 | GNU General Public License for more details. | 12 | GNU General Public License for more details. |
13 | 13 | ||
14 | You should have received a copy of the GNU General Public License | 14 | You should have received a copy of the GNU General Public License |
15 | along with GNU Mailutils; if not, write to the Free Software | 15 | along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ |
16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
17 | MA 02110-1301 USA */ | ||
18 | 16 | ||
19 | #include "pop3d.h" | 17 | #include "pop3d.h" |
20 | 18 | ||
... | @@ -23,7 +21,7 @@ | ... | @@ -23,7 +21,7 @@ |
23 | #ifdef WITH_TLS | 21 | #ifdef WITH_TLS |
24 | 22 | ||
25 | int | 23 | int |
26 | pop3d_stls (const char *arg) | 24 | pop3d_stls (char *arg) |
27 | { | 25 | { |
28 | if (strlen (arg) != 0) | 26 | if (strlen (arg) != 0) |
29 | return ERR_BAD_ARGS; | 27 | return ERR_BAD_ARGS; |
... | @@ -40,7 +38,11 @@ pop3d_stls (const char *arg) | ... | @@ -40,7 +38,11 @@ pop3d_stls (const char *arg) |
40 | tls_done = pop3d_init_tls_server (); | 38 | tls_done = pop3d_init_tls_server (); |
41 | 39 | ||
42 | if (!tls_done) | 40 | if (!tls_done) |
43 | return ERR_UNKNOWN; | 41 | { |
42 | mu_diag_output (MU_DIAG_ERROR, _("Session terminated")); | ||
43 | state = ABORT; | ||
44 | return ERR_UNKNOWN; | ||
45 | } | ||
44 | 46 | ||
45 | state = AUTHORIZATION; /* Confirm we're in this state. Necessary for | 47 | state = AUTHORIZATION; /* Confirm we're in this state. Necessary for |
46 | --tls-required to work */ | 48 | --tls-required to work */ | ... | ... |
... | @@ -12,16 +12,14 @@ | ... | @@ -12,16 +12,14 @@ |
12 | GNU General Public License for more details. | 12 | GNU General Public License for more details. |
13 | 13 | ||
14 | You should have received a copy of the GNU General Public License | 14 | You should have received a copy of the GNU General Public License |
15 | along with GNU Mailutils; if not, write to the Free Software | 15 | along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ |
16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
17 | MA 02110-1301 USA */ | ||
18 | 16 | ||
19 | #include "pop3d.h" | 17 | #include "pop3d.h" |
20 | 18 | ||
21 | /* Prints the header of a message plus a specified number of lines. */ | 19 | /* Prints the header of a message plus a specified number of lines. */ |
22 | 20 | ||
23 | int | 21 | int |
24 | pop3d_top (const char *arg) | 22 | pop3d_top (char *arg) |
25 | { | 23 | { |
26 | size_t mesgno; | 24 | size_t mesgno; |
27 | int lines; | 25 | int lines; |
... | @@ -41,12 +39,10 @@ pop3d_top (const char *arg) | ... | @@ -41,12 +39,10 @@ pop3d_top (const char *arg) |
41 | if (state != TRANSACTION) | 39 | if (state != TRANSACTION) |
42 | return ERR_WRONG_STATE; | 40 | return ERR_WRONG_STATE; |
43 | 41 | ||
44 | mesgc = pop3d_cmd (arg); | 42 | pop3d_parse_command (arg, &mesgc, &linesc); |
45 | linesc = pop3d_args (arg); | 43 | |
46 | mesgno = strtoul (mesgc, NULL, 10); | 44 | mesgno = strtoul (mesgc, NULL, 10); |
47 | lines = strlen (linesc) > 0 ? strtol (linesc, NULL, 10) : -1; | 45 | lines = *linesc ? strtol (linesc, NULL, 10) : -1; |
48 | free (mesgc); | ||
49 | free (linesc); | ||
50 | 46 | ||
51 | if (lines < 0) | 47 | if (lines < 0) |
52 | return ERR_BAD_ARGS; | 48 | return ERR_BAD_ARGS; | ... | ... |
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | 1 | /* GNU Mailutils -- a suite of utilities for electronic mail |
2 | Copyright (C) 1999, 2000, 2001, 2005, 2007 Free Software Foundation, Inc. | 2 | Copyright (C) 1999, 2000, 2001, 2005, 2007, |
3 | 2009 Free Software Foundation, Inc. | ||
3 | 4 | ||
4 | GNU Mailutils is free software; you can redistribute it and/or modify | 5 | GNU Mailutils is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
... | @@ -12,14 +13,12 @@ | ... | @@ -12,14 +13,12 @@ |
12 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
13 | 14 | ||
14 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
15 | along with GNU Mailutils; if not, write to the Free Software | 16 | along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ |
16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
17 | MA 02110-1301 USA */ | ||
18 | 17 | ||
19 | #include "pop3d.h" | 18 | #include "pop3d.h" |
20 | 19 | ||
21 | int | 20 | int |
22 | pop3d_uidl (const char *arg) | 21 | pop3d_uidl (char *arg) |
23 | { | 22 | { |
24 | size_t mesgno; | 23 | size_t mesgno; |
25 | char uidl[128]; | 24 | char uidl[128]; | ... | ... |
... | @@ -13,9 +13,7 @@ | ... | @@ -13,9 +13,7 @@ |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with GNU Mailutils; if not, write to the Free Software | 16 | along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */ |
17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
18 | MA 02110-1301 USA */ | ||
19 | 17 | ||
20 | #include "pop3d.h" | 18 | #include "pop3d.h" |
21 | 19 | ||
... | @@ -89,7 +87,7 @@ pop3d_begin_session () | ... | @@ -89,7 +87,7 @@ pop3d_begin_session () |
89 | } | 87 | } |
90 | 88 | ||
91 | int | 89 | int |
92 | pop3d_user (const char *arg) | 90 | pop3d_user (char *arg) |
93 | { | 91 | { |
94 | char *buf, pass[POP_MAXCMDLEN], *tmp, *cmd; | 92 | char *buf, pass[POP_MAXCMDLEN], *tmp, *cmd; |
95 | char buffer[512]; | 93 | char buffer[512]; |
... | @@ -104,36 +102,27 @@ pop3d_user (const char *arg) | ... | @@ -104,36 +102,27 @@ pop3d_user (const char *arg) |
104 | pop3d_flush_output (); | 102 | pop3d_flush_output (); |
105 | 103 | ||
106 | buf = pop3d_readline (buffer, sizeof (buffer)); | 104 | buf = pop3d_readline (buffer, sizeof (buffer)); |
107 | cmd = pop3d_cmd (buf); | 105 | pop3d_parse_command (buf, &cmd, &tmp); |
108 | tmp = pop3d_args (buf); | ||
109 | 106 | ||
110 | if (strlen (tmp) > POP_MAXCMDLEN) | 107 | if (strlen (tmp) > POP_MAXCMDLEN) |
111 | { | 108 | return ERR_TOO_LONG; |
112 | free (cmd); | ||
113 | free (tmp); | ||
114 | return ERR_TOO_LONG; | ||
115 | } | ||
116 | else | 109 | else |
117 | { | 110 | { |
118 | strncpy (pass, tmp, POP_MAXCMDLEN); | 111 | strncpy (pass, tmp, POP_MAXCMDLEN); |
119 | /* strncpy () is lame, make sure the string is null terminated. */ | 112 | /* strncpy () is lame, make sure the string is null terminated. */ |
120 | pass[POP_MAXCMDLEN - 1] = '\0'; | 113 | pass[POP_MAXCMDLEN - 1] = '\0'; |
121 | free (tmp); | ||
122 | } | 114 | } |
123 | 115 | ||
124 | if (mu_c_strcasecmp (cmd, "PASS") == 0) | 116 | if (mu_c_strcasecmp (cmd, "PASS") == 0) |
125 | { | 117 | { |
126 | int rc; | 118 | int rc; |
127 | 119 | ||
128 | free (cmd); | ||
129 | |||
130 | #ifdef _USE_APOP | 120 | #ifdef _USE_APOP |
131 | /* Check to see if they have an APOP password. If so, refuse USER/PASS */ | 121 | /* Check to see if they have an APOP password. If so, refuse USER/PASS */ |
132 | tmp = pop3d_apopuser (arg); | 122 | tmp = pop3d_apopuser (arg); |
133 | if (tmp != NULL) | 123 | if (tmp != NULL) |
134 | { | 124 | { |
135 | mu_diag_output (MU_DIAG_INFO, _("APOP user %s tried to log in with USER"), arg); | 125 | mu_diag_output (MU_DIAG_INFO, _("APOP user %s tried to log in with USER"), arg); |
136 | free (tmp); | ||
137 | return ERR_BAD_LOGIN; | 126 | return ERR_BAD_LOGIN; |
138 | } | 127 | } |
139 | #endif | 128 | #endif |
... | @@ -159,12 +148,10 @@ pop3d_user (const char *arg) | ... | @@ -159,12 +148,10 @@ pop3d_user (const char *arg) |
159 | else if (mu_c_strcasecmp (cmd, "QUIT") == 0) | 148 | else if (mu_c_strcasecmp (cmd, "QUIT") == 0) |
160 | { | 149 | { |
161 | mu_diag_output (MU_DIAG_INFO, _("Possible probe of account `%s'"), arg); | 150 | mu_diag_output (MU_DIAG_INFO, _("Possible probe of account `%s'"), arg); |
162 | free (cmd); | ||
163 | return pop3d_quit (pass); | 151 | return pop3d_quit (pass); |
164 | } | 152 | } |
165 | else | 153 | else |
166 | { | 154 | { |
167 | free (cmd); | ||
168 | return ERR_BAD_CMD; | 155 | return ERR_BAD_CMD; |
169 | } | 156 | } |
170 | 157 | ... | ... |
-
Please register or sign in to post a comment