dovecot-2.0-pigeonhole: Enforced ManageSieve protocol syntax bet...
pigeonhole at rename-it.nl
pigeonhole at rename-it.nl
Mon Aug 23 19:51:49 EEST 2010
details: http://hg.rename-it.nl/dovecot-2.0-pigeonhole/rev/551cd0af5b08
changeset: 1386:551cd0af5b08
user: Stephan Bosch <stephan at rename-it.nl>
date: Mon Aug 23 18:50:58 2010 +0200
description:
Enforced ManageSieve protocol syntax better with some of the commands; some commands still allowed spurious extra arguments.
diffstat:
TODO | 2 --
src/managesieve/cmd-capability.c | 4 ++++
src/managesieve/cmd-deletescript.c | 2 +-
src/managesieve/cmd-getscript.c | 2 +-
src/managesieve/cmd-havespace.c | 8 +-------
src/managesieve/cmd-listscripts.c | 4 ++++
src/managesieve/cmd-logout.c | 4 ++++
src/managesieve/cmd-noop.c | 13 ++++++-------
src/managesieve/cmd-renamescript.c | 2 +-
src/managesieve/cmd-setactive.c | 2 +-
src/managesieve/managesieve-client.c | 36 ++++++++++++++++++++++--------------
src/managesieve/managesieve-client.h | 10 ++++++++--
12 files changed, 53 insertions(+), 36 deletions(-)
diffs (260 lines):
diff -r 4dd2538ec95b -r 551cd0af5b08 TODO
--- a/TODO Mon Aug 23 09:10:11 2010 +0200
+++ b/TODO Mon Aug 23 18:50:58 2010 +0200
@@ -10,8 +10,6 @@
Next (in order of descending priority/precedence):
-* Enforce ManageSieve protocol syntax better with some of the commands. Some
- commands still allow spurious extra arguments.
* Code cleanup:
- Review all FIXMEs
diff -r 4dd2538ec95b -r 551cd0af5b08 src/managesieve/cmd-capability.c
--- a/src/managesieve/cmd-capability.c Mon Aug 23 09:10:11 2010 +0200
+++ b/src/managesieve/cmd-capability.c Mon Aug 23 18:50:58 2010 +0200
@@ -17,6 +17,10 @@
const char *sievecap, *notifycap;
unsigned int max_redirects;
+ /* no arguments */
+ if ( !client_read_no_args(cmd) )
+ return FALSE;
+
o_stream_cork(client->output);
T_BEGIN {
diff -r 4dd2538ec95b -r 551cd0af5b08 src/managesieve/cmd-deletescript.c
--- a/src/managesieve/cmd-deletescript.c Mon Aug 23 09:10:11 2010 +0200
+++ b/src/managesieve/cmd-deletescript.c Mon Aug 23 18:50:58 2010 +0200
@@ -17,7 +17,7 @@
struct sieve_script *script;
/* <scrip name>*/
- if (!client_read_string_args(cmd, 1, &scriptname))
+ if ( !client_read_string_args(cmd, 1, TRUE, &scriptname) )
return FALSE;
script = sieve_storage_script_init(storage, scriptname);
diff -r 4dd2538ec95b -r 551cd0af5b08 src/managesieve/cmd-getscript.c
--- a/src/managesieve/cmd-getscript.c Mon Aug 23 09:10:11 2010 +0200
+++ b/src/managesieve/cmd-getscript.c Mon Aug 23 18:50:58 2010 +0200
@@ -90,7 +90,7 @@
enum sieve_error error;
/* <scriptname> */
- if (!client_read_string_args(cmd, 1, &scriptname))
+ if ( !client_read_string_args(cmd, 1, TRUE, &scriptname) )
return FALSE;
ctx = p_new(cmd->pool, struct cmd_getscript_context, 1);
diff -r 4dd2538ec95b -r 551cd0af5b08 src/managesieve/cmd-havespace.c
--- a/src/managesieve/cmd-havespace.c Mon Aug 23 09:10:11 2010 +0200
+++ b/src/managesieve/cmd-havespace.c Mon Aug 23 18:50:58 2010 +0200
@@ -20,17 +20,11 @@
struct managesieve_arg *args;
const char *scriptname;
uoff_t size;
- int ret;
/* <scriptname> <size> */
- if (!(ret=client_read_args(cmd, 2, 0, &args)))
+ if ( !client_read_args(cmd, 2, 0, TRUE, &args) )
return FALSE;
- if ( ret > 2 ) {
- client_send_no(client, "Too many arguments");
- return TRUE;
- }
-
if ( (scriptname = managesieve_arg_string(&args[0])) == NULL ) {
client_send_no(client, "Invalid string for scriptname.");
return TRUE;
diff -r 4dd2538ec95b -r 551cd0af5b08 src/managesieve/cmd-listscripts.c
--- a/src/managesieve/cmd-listscripts.c Mon Aug 23 09:10:11 2010 +0200
+++ b/src/managesieve/cmd-listscripts.c Mon Aug 23 18:50:58 2010 +0200
@@ -20,6 +20,10 @@
bool active;
string_t *str;
+ /* no arguments */
+ if ( !client_read_no_args(cmd) )
+ return FALSE;
+
if ( (ctx = sieve_storage_list_init(client->storage))
== NULL ) {
client_send_storage_error(client, client->storage);
diff -r 4dd2538ec95b -r 551cd0af5b08 src/managesieve/cmd-logout.c
--- a/src/managesieve/cmd-logout.c Mon Aug 23 09:10:11 2010 +0200
+++ b/src/managesieve/cmd-logout.c Mon Aug 23 18:50:58 2010 +0200
@@ -11,6 +11,10 @@
{
struct client *client = cmd->client;
+ /* no arguments */
+ if ( !client_read_no_args(cmd) )
+ return FALSE;
+
client_send_line(client, "OK \"Logout completed.\"");
client_disconnect(client, "Logged out");
return TRUE;
diff -r 4dd2538ec95b -r 551cd0af5b08 src/managesieve/cmd-noop.c
--- a/src/managesieve/cmd-noop.c Mon Aug 23 09:10:11 2010 +0200
+++ b/src/managesieve/cmd-noop.c Mon Aug 23 18:50:58 2010 +0200
@@ -17,17 +17,11 @@
struct managesieve_arg *args;
const char *text;
string_t *resp_code;
- int ret;
/* [<echo string>] */
- if (!(ret=client_read_args(cmd, 0, 0, &args)))
+ if ( !client_read_args(cmd, 0, 0, FALSE, &args) )
return FALSE;
- if ( ret > 1 ) {
- client_send_no(client, "Too many arguments");
- return TRUE;
- }
-
if ( args[0].type == MANAGESIEVE_ARG_EOL ) {
client_send_ok(client, "NOOP Completed");
return TRUE;
@@ -38,6 +32,11 @@
return TRUE;
}
+ if ( args[1].type != MANAGESIEVE_ARG_EOL ) {
+ client_send_command_error(cmd, "Too many arguments.");
+ return TRUE;
+ }
+
resp_code = t_str_new(256);
str_append(resp_code, "TAG ");
managesieve_quote_append_string(resp_code, text, FALSE);
diff -r 4dd2538ec95b -r 551cd0af5b08 src/managesieve/cmd-renamescript.c
--- a/src/managesieve/cmd-renamescript.c Mon Aug 23 09:10:11 2010 +0200
+++ b/src/managesieve/cmd-renamescript.c Mon Aug 23 18:50:58 2010 +0200
@@ -18,7 +18,7 @@
struct sieve_script *script;
/* <oldname> <newname> */
- if (!client_read_string_args(cmd, 2, &scriptname, &newname))
+ if (!client_read_string_args(cmd, 2, TRUE, &scriptname, &newname))
return FALSE;
script = sieve_storage_script_init(storage, scriptname);
diff -r 4dd2538ec95b -r 551cd0af5b08 src/managesieve/cmd-setactive.c
--- a/src/managesieve/cmd-setactive.c Mon Aug 23 09:10:11 2010 +0200
+++ b/src/managesieve/cmd-setactive.c Mon Aug 23 18:50:58 2010 +0200
@@ -18,7 +18,7 @@
int ret;
/* <scriptname> */
- if (!client_read_string_args(cmd, 1, &scriptname))
+ if ( !client_read_string_args(cmd, 1, TRUE, &scriptname) )
return FALSE;
if ( *scriptname != '\0' ) {
diff -r 4dd2538ec95b -r 551cd0af5b08 src/managesieve/managesieve-client.c
--- a/src/managesieve/managesieve-client.c Mon Aug 23 09:10:11 2010 +0200
+++ b/src/managesieve/managesieve-client.c Mon Aug 23 18:50:58 2010 +0200
@@ -412,14 +412,28 @@
}
bool client_read_args(struct client_command_context *cmd, unsigned int count,
- unsigned int flags, struct managesieve_arg **args_r)
+ unsigned int flags, bool no_more, struct managesieve_arg **args_r)
{
+ struct managesieve_arg *dummy_args_r = NULL;
int ret;
+ if ( args_r == NULL ) args_r = &dummy_args_r;
+
i_assert(count <= INT_MAX);
- ret = managesieve_parser_read_args(cmd->client->parser, count, flags, args_r);
- if (ret >= (int)count) {
+ ret = managesieve_parser_read_args
+ (cmd->client->parser, ( no_more ? 0 : count ), flags, args_r);
+ if ( ret >= 0 ) {
+ if ( count > 0 || no_more ) {
+ if ( ret < (int)count ) {
+ client_send_command_error(cmd, "Missing arguments.");
+ return FALSE;
+ } else if ( no_more && ret > (int)count ) {
+ client_send_command_error(cmd, "Too many arguments.");
+ return FALSE;
+ }
+ }
+
/* all parameters read successfully */
return TRUE;
} else if (ret == -2) {
@@ -430,15 +444,14 @@
}
return FALSE;
} else {
- /* error, or missing arguments */
- client_send_command_error(cmd, ret < 0 ? NULL :
- "Missing arguments");
+ /* error */
+ client_send_command_error(cmd, NULL);
return FALSE;
}
}
bool client_read_string_args(struct client_command_context *cmd,
- unsigned int count, ...)
+ unsigned int count, bool no_more, ...)
{
struct managesieve_arg *managesieve_args;
va_list va;
@@ -446,10 +459,10 @@
unsigned int i;
bool result = TRUE;
- if (!client_read_args(cmd, count, 0, &managesieve_args))
+ if (!client_read_args(cmd, count, 0, no_more, &managesieve_args))
return FALSE;
- va_start(va, count);
+ va_start(va, no_more);
for (i = 0; i < count; i++) {
const char **ret = va_arg(va, const char **);
@@ -471,11 +484,6 @@
}
va_end(va);
- if (result && managesieve_args[i].type != MANAGESIEVE_ARG_EOL) {
- client_send_command_error(cmd, "Too many arguments.");
- result = FALSE;
- }
-
return result;
}
diff -r 4dd2538ec95b -r 551cd0af5b08 src/managesieve/managesieve-client.h
--- a/src/managesieve/managesieve-client.h Mon Aug 23 09:10:11 2010 +0200
+++ b/src/managesieve/managesieve-client.h Mon Aug 23 18:50:58 2010 +0200
@@ -114,11 +114,17 @@
/* Read a number of arguments. Returns TRUE if everything was read or
FALSE if either needs more data or error occurred. */
bool client_read_args(struct client_command_context *cmd, unsigned int count,
- unsigned int flags, struct managesieve_arg **args_r);
+ unsigned int flags, bool no_more, struct managesieve_arg **args_r);
/* Reads a number of string arguments. ... is a list of pointers where to
store the arguments. */
bool client_read_string_args(struct client_command_context *cmd,
- unsigned int count, ...);
+ unsigned int count, bool no_more, ...);
+
+static inline bool client_read_no_args
+(struct client_command_context *cmd)
+{
+ return client_read_args(cmd, 0, 0, TRUE, NULL);
+}
void _client_reset_command(struct client *client);
void client_input(struct client *client);
More information about the dovecot-cvs
mailing list