Skip to content
Snippets Groups Projects
Commit e24042e2 authored by Stephan Bosch's avatar Stephan Bosch
Browse files

Finished code cleanup for now.

parent badedb46
No related branches found
No related tags found
No related merge requests found
Showing with 155 additions and 58 deletions
...@@ -8,7 +8,6 @@ Next (in order of descending priority/precedence): ...@@ -8,7 +8,6 @@ Next (in order of descending priority/precedence):
MUST win. MUST win.
- 'If an address is not syntactically valid, then it will not be matched - 'If an address is not syntactically valid, then it will not be matched
by tests specifying ":localpart" or ":domain"'. by tests specifying ":localpart" or ":domain"'.
* Code cleanup
* Full security review. Enforce limits on number of created objects, script * Full security review. Enforce limits on number of created objects, script
size, execution time, etc... size, execution time, etc...
- Make (configurable) limit on the number of redirects - Make (configurable) limit on the number of redirects
......
/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
*/
#include "sieve-common.h" #include "sieve-common.h"
#include "sieve-commands.h" #include "sieve-commands.h"
#include "sieve-validator.h" #include "sieve-validator.h"
......
/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
*/
#include "lib.h" #include "lib.h"
#include "ioloop.h" #include "ioloop.h"
#include "str-sanitize.h" #include "str-sanitize.h"
......
/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
*/
#include "sieve-common.h" #include "sieve-common.h"
#include "sieve-commands.h" #include "sieve-commands.h"
#include "sieve-validator.h" #include "sieve-validator.h"
......
/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
*/
/* Extension testsuite /* Extension testsuite
* ------------------- * -------------------
* *
...@@ -43,25 +46,9 @@ ...@@ -43,25 +46,9 @@
#include "testsuite-common.h" #include "testsuite-common.h"
/* Forward declarations */ /*
* Operations
static bool ext_testsuite_load(int ext_id); */
static bool ext_testsuite_validator_load(struct sieve_validator *valdtr);
static bool ext_testsuite_generator_load(const struct sieve_codegen_env *cgenv);
static bool ext_testsuite_binary_load(struct sieve_binary *sbin);
/* Commands */
extern const struct sieve_command cmd_test;
extern const struct sieve_command cmd_test_fail;
extern const struct sieve_command cmd_test_set;
/* Tests */
extern const struct sieve_command tst_test_compile;
extern const struct sieve_command tst_test_error;
/* Operations */
const struct sieve_operation *testsuite_operations[] = { const struct sieve_operation *testsuite_operations[] = {
&test_operation, &test_operation,
...@@ -72,18 +59,31 @@ const struct sieve_operation *testsuite_operations[] = { ...@@ -72,18 +59,31 @@ const struct sieve_operation *testsuite_operations[] = {
&test_error_operation &test_error_operation
}; };
/* Operands */ /*
* Operands
*/
const struct sieve_operand *testsuite_operands[] = const struct sieve_operand *testsuite_operands[] =
{ &testsuite_object_operand }; { &testsuite_object_operand };
/* Extension definitions */ /*
* Extension
*/
/* Forward declarations */
static bool ext_testsuite_load(int ext_id);
static bool ext_testsuite_validator_load(struct sieve_validator *valdtr);
static bool ext_testsuite_generator_load(const struct sieve_codegen_env *cgenv);
static bool ext_testsuite_binary_load(struct sieve_binary *sbin);
int ext_testsuite_my_id; /* Extension object */
static int ext_my_id;
const struct sieve_extension testsuite_extension = { const struct sieve_extension testsuite_extension = {
"vnd.dovecot.testsuite", "vnd.dovecot.testsuite",
&ext_testsuite_my_id, &ext_my_id,
ext_testsuite_load, ext_testsuite_load,
ext_testsuite_validator_load, ext_testsuite_validator_load,
ext_testsuite_generator_load, ext_testsuite_generator_load,
...@@ -94,15 +94,15 @@ const struct sieve_extension testsuite_extension = { ...@@ -94,15 +94,15 @@ const struct sieve_extension testsuite_extension = {
SIEVE_EXT_DEFINE_OPERAND(testsuite_object_operand) SIEVE_EXT_DEFINE_OPERAND(testsuite_object_operand)
}; };
/* Extension implementation */
static bool ext_testsuite_load(int ext_id) static bool ext_testsuite_load(int ext_id)
{ {
ext_testsuite_my_id = ext_id; ext_my_id = ext_id;
return TRUE; return TRUE;
} }
/* Load extension into validator */
static bool ext_testsuite_validator_load(struct sieve_validator *valdtr) static bool ext_testsuite_validator_load(struct sieve_validator *valdtr)
{ {
sieve_validator_register_command(valdtr, &cmd_test); sieve_validator_register_command(valdtr, &cmd_test);
...@@ -115,15 +115,11 @@ static bool ext_testsuite_validator_load(struct sieve_validator *valdtr) ...@@ -115,15 +115,11 @@ static bool ext_testsuite_validator_load(struct sieve_validator *valdtr)
return testsuite_validator_context_initialize(valdtr); return testsuite_validator_context_initialize(valdtr);
} }
/* Load extension into generator */
static bool ext_testsuite_generator_load(const struct sieve_codegen_env *cgenv) static bool ext_testsuite_generator_load(const struct sieve_codegen_env *cgenv)
{ {
return testsuite_generator_context_initialize(cgenv->gentr); return testsuite_generator_context_initialize(cgenv->gentr);
} }
/* Load extension into binary */
static bool ext_testsuite_binary_load(struct sieve_binary *sbin ATTR_UNUSED) static bool ext_testsuite_binary_load(struct sieve_binary *sbin ATTR_UNUSED)
{ {
return TRUE; return TRUE;
......
/* Copyright (c) 2005-2007 Dovecot authors, see the included COPYING file */ /* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
*/
/* This file was gratefully stolen from dovecot/src/deliver/deliver.c and altered /* This file was gratefully stolen from dovecot/src/deliver/deliver.c and altered
* to suit our needs. So, this contains lots and lots of duplicated code. * to suit our needs. So, this contains lots and lots of duplicated code.
* The sieve_test program needs to read an email message from stdin and it needs * FIXME: As a matter of fact a similar file is located at src/sieve-bin/mail-raw.c
* to build a struct mail (to be fed to the sieve library). Deliver does something * These must be merged.
* similar already, so that source was a basis for this test binary.
*/ */
#include "lib.h" #include "lib.h"
...@@ -27,12 +27,20 @@ ...@@ -27,12 +27,20 @@
#include <fcntl.h> #include <fcntl.h>
#include <pwd.h> #include <pwd.h>
/*
* Configuration
*/
#define DEFAULT_ENVELOPE_SENDER "MAILER-DAEMON" #define DEFAULT_ENVELOPE_SENDER "MAILER-DAEMON"
/* After buffer grows larger than this, create a temporary file to /tmp /* After buffer grows larger than this, create a temporary file to /tmp
where to read the mail. */ where to read the mail. */
#define MAIL_MAX_MEMORY_BUFFER (1024*128) #define MAIL_MAX_MEMORY_BUFFER (1024*128)
/*
* Implementation
*/
static struct mail_namespace *raw_ns; static struct mail_namespace *raw_ns;
void mail_raw_init(const char *user) void mail_raw_init(const char *user)
......
/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
*/
#ifndef __MAIL_RAW_H #ifndef __MAIL_RAW_H
#define __MAIL_RAW_H #define __MAIL_RAW_H
......
/* Copyright (c) 2005-2007 Dovecot authors, see the included COPYING file */ /* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
*/
#include "lib.h" #include "lib.h"
#include "istream.h" #include "istream.h"
......
/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
*/
/* FIXME: Duplicated */
#ifndef __NAMESPACES_H #ifndef __NAMESPACES_H
#define __NAMESPACES_H #define __NAMESPACES_H
void namespaces_init(void); void namespaces_init(void);
void namespaces_deinit(void); void namespaces_deinit(void);
#endif /* __MAIL_RAW_H */ #endif /* __NAMESPACES_H */
/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
*/
#include "lib.h" #include "lib.h"
#include "str.h" #include "str.h"
#include "string.h" #include "string.h"
......
/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
*/
#ifndef __TESTSUITE_COMMON_H #ifndef __TESTSUITE_COMMON_H
#define __TESTSUITE_COMMON_H #define __TESTSUITE_COMMON_H
extern const struct sieve_extension testsuite_extension; /*
* Extension
*/
extern int ext_testsuite_my_id; extern const struct sieve_extension testsuite_extension;
/* Testsuite message environment */ /*
* Testsuite message environment
*/
extern struct sieve_message_data testsuite_msgdata; extern struct sieve_message_data testsuite_msgdata;
...@@ -19,7 +26,9 @@ void testsuite_envelope_set_sender(const char *value); ...@@ -19,7 +26,9 @@ void testsuite_envelope_set_sender(const char *value);
void testsuite_envelope_set_recipient(const char *value); void testsuite_envelope_set_recipient(const char *value);
void testsuite_envelope_set_auth_user(const char *value); void testsuite_envelope_set_auth_user(const char *value);
/* Testsuite validator context */ /*
* Validator context
*/
struct testsuite_validator_context { struct testsuite_validator_context {
struct sieve_validator_object_registry *object_registrations; struct sieve_validator_object_registry *object_registrations;
...@@ -29,7 +38,9 @@ bool testsuite_validator_context_initialize(struct sieve_validator *valdtr); ...@@ -29,7 +38,9 @@ bool testsuite_validator_context_initialize(struct sieve_validator *valdtr);
struct testsuite_validator_context *testsuite_validator_context_get struct testsuite_validator_context *testsuite_validator_context_get
(struct sieve_validator *valdtr); (struct sieve_validator *valdtr);
/* Testsuite generator context */ /*
* Generator context
*/
struct testsuite_generator_context { struct testsuite_generator_context {
struct sieve_jumplist *exit_jumps; struct sieve_jumplist *exit_jumps;
...@@ -37,7 +48,24 @@ struct testsuite_generator_context { ...@@ -37,7 +48,24 @@ struct testsuite_generator_context {
bool testsuite_generator_context_initialize(struct sieve_generator *gentr); bool testsuite_generator_context_initialize(struct sieve_generator *gentr);
/* Testsuite operations */ /*
* Commands
*/
extern const struct sieve_command cmd_test;
extern const struct sieve_command cmd_test_fail;
extern const struct sieve_command cmd_test_set;
/*
* Tests
*/
extern const struct sieve_command tst_test_compile;
extern const struct sieve_command tst_test_error;
/*
* Operations
*/
enum testsuite_operation_code { enum testsuite_operation_code {
TESTSUITE_OPERATION_TEST, TESTSUITE_OPERATION_TEST,
...@@ -55,7 +83,9 @@ extern const struct sieve_operation test_set_operation; ...@@ -55,7 +83,9 @@ extern const struct sieve_operation test_set_operation;
extern const struct sieve_operation test_compile_operation; extern const struct sieve_operation test_compile_operation;
extern const struct sieve_operation test_error_operation; extern const struct sieve_operation test_error_operation;
/* Testsuite operands */ /*
* Operands
*/
extern const struct sieve_operand testsuite_object_operand; extern const struct sieve_operand testsuite_object_operand;
...@@ -63,7 +93,9 @@ enum testsuite_operand_code { ...@@ -63,7 +93,9 @@ enum testsuite_operand_code {
TESTSUITE_OPERAND_OBJECT TESTSUITE_OPERAND_OBJECT
}; };
/* Test context */ /*
* Test context
*/
void testsuite_test_start(string_t *name); void testsuite_test_start(string_t *name);
void testsuite_test_fail(string_t *reason); void testsuite_test_fail(string_t *reason);
...@@ -72,14 +104,18 @@ void testsuite_test_succeed(string_t *reason); ...@@ -72,14 +104,18 @@ void testsuite_test_succeed(string_t *reason);
void testsuite_testcase_fail(const char *reason); void testsuite_testcase_fail(const char *reason);
int testsuite_testcase_result(void); int testsuite_testcase_result(void);
/* Tested script environment */ /*
* Tested script environment
*/
bool testsuite_script_compile(const char *script_path); bool testsuite_script_compile(const char *script_path);
void testsuite_script_get_error_init(void); void testsuite_script_get_error_init(void);
const char *testsuite_script_get_error_next(bool location); const char *testsuite_script_get_error_next(bool location);
/* Testsuite init/deinit */ /*
* Testsuite init/deinit
*/
void testsuite_init(void); void testsuite_init(void);
void testsuite_deinit(void); void testsuite_deinit(void);
......
/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
*/
#include "lib.h" #include "lib.h"
#include "string.h" #include "string.h"
#include "ostream.h" #include "ostream.h"
......
/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
*/
#ifndef __TESTSUITE_OBJECTS_H #ifndef __TESTSUITE_OBJECTS_H
#define __TESTSUITE_OBJECTS_H #define __TESTSUITE_OBJECTS_H
...@@ -6,7 +9,9 @@ ...@@ -6,7 +9,9 @@
#include "testsuite-common.h" #include "testsuite-common.h"
/* Testsuite object operand */ /*
* Testsuite object operand
*/
struct testsuite_object_operand_interface { struct testsuite_object_operand_interface {
struct sieve_extension_obj_registry testsuite_objects; struct sieve_extension_obj_registry testsuite_objects;
...@@ -14,7 +19,9 @@ struct testsuite_object_operand_interface { ...@@ -14,7 +19,9 @@ struct testsuite_object_operand_interface {
extern const struct sieve_operand_class testsuite_object_oprclass; extern const struct sieve_operand_class testsuite_object_oprclass;
/* Testsuite object access */ /*
* Testsuite object access
*/
struct testsuite_object { struct testsuite_object {
struct sieve_object object; struct sieve_object object;
...@@ -26,7 +33,9 @@ struct testsuite_object { ...@@ -26,7 +33,9 @@ struct testsuite_object {
string_t *(*get_member)(const struct sieve_runtime_env *renv, int id); string_t *(*get_member)(const struct sieve_runtime_env *renv, int id);
}; };
/* Testsuite object registration */ /*
* Testsuite object registration
*/
const struct testsuite_object *testsuite_object_find const struct testsuite_object *testsuite_object_find
(struct sieve_validator *valdtr, const char *identifier); (struct sieve_validator *valdtr, const char *identifier);
...@@ -35,13 +44,17 @@ void testsuite_object_register ...@@ -35,13 +44,17 @@ void testsuite_object_register
void testsuite_register_core_objects void testsuite_register_core_objects
(struct testsuite_validator_context *ctx); (struct testsuite_validator_context *ctx);
/* Testsuite object argument */ /*
* Testsuite object argument
*/
bool testsuite_object_argument_activate bool testsuite_object_argument_activate
(struct sieve_validator *valdtr, struct sieve_ast_argument *arg, (struct sieve_validator *valdtr, struct sieve_ast_argument *arg,
struct sieve_command_context *cmd); struct sieve_command_context *cmd);
/* Testsuite object code */ /*
* Testsuite object code
*/
const struct testsuite_object *testsuite_object_read const struct testsuite_object *testsuite_object_read
(struct sieve_binary *sbin, sieve_size_t *address); (struct sieve_binary *sbin, sieve_size_t *address);
...@@ -52,7 +65,9 @@ const char *testsuite_object_member_name ...@@ -52,7 +65,9 @@ const char *testsuite_object_member_name
bool testsuite_object_dump bool testsuite_object_dump
(const struct sieve_dumptime_env *denv, sieve_size_t *address); (const struct sieve_dumptime_env *denv, sieve_size_t *address);
/* Testsuite core objects */ /*
* Testsuite core objects
*/
extern const struct testsuite_object message_testsuite_object; extern const struct testsuite_object message_testsuite_object;
extern const struct testsuite_object envelope_testsuite_object; extern const struct testsuite_object envelope_testsuite_object;
......
/* Copyright (c) 2005-2007 Dovecot authors, see the included COPYING file */ /* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
*/
#include "lib.h" #include "lib.h"
#include "lib-signals.h" #include "lib-signals.h"
...@@ -26,6 +27,10 @@ ...@@ -26,6 +27,10 @@
#include <fcntl.h> #include <fcntl.h>
#include <pwd.h> #include <pwd.h>
/*
* Configuration
*/
#define DEFAULT_SENDMAIL_PATH "/usr/lib/sendmail" #define DEFAULT_SENDMAIL_PATH "/usr/lib/sendmail"
#define DEFAULT_ENVELOPE_SENDER "MAILER-DAEMON" #define DEFAULT_ENVELOPE_SENDER "MAILER-DAEMON"
......
/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
*/
#include "sieve-common.h" #include "sieve-common.h"
#include "sieve-script.h" #include "sieve-script.h"
#include "sieve-commands.h" #include "sieve-commands.h"
...@@ -33,7 +36,9 @@ const struct sieve_command tst_test_compile = { ...@@ -33,7 +36,9 @@ const struct sieve_command tst_test_compile = {
NULL NULL
}; };
/* Test_compile operation */ /*
* Operation
*/
static bool tst_test_compile_operation_dump static bool tst_test_compile_operation_dump
(const struct sieve_operation *op, (const struct sieve_operation *op,
...@@ -50,7 +55,9 @@ const struct sieve_operation test_compile_operation = { ...@@ -50,7 +55,9 @@ const struct sieve_operation test_compile_operation = {
tst_test_compile_operation_execute tst_test_compile_operation_execute
}; };
/* Validation */ /*
* Validation
*/
static bool tst_test_compile_validate static bool tst_test_compile_validate
(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_command_context *tst) (struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_command_context *tst)
...@@ -65,7 +72,9 @@ static bool tst_test_compile_validate ...@@ -65,7 +72,9 @@ static bool tst_test_compile_validate
return sieve_validator_argument_activate(valdtr, tst, arg, FALSE); return sieve_validator_argument_activate(valdtr, tst, arg, FALSE);
} }
/* Code generation */ /*
* Code generation
*/
static inline struct testsuite_generator_context * static inline struct testsuite_generator_context *
_get_generator_context(struct sieve_generator *gentr) _get_generator_context(struct sieve_generator *gentr)
......
/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
*/
#include "sieve-common.h" #include "sieve-common.h"
#include "sieve-error.h" #include "sieve-error.h"
#include "sieve-script.h" #include "sieve-script.h"
...@@ -39,7 +42,9 @@ const struct sieve_command tst_test_error = { ...@@ -39,7 +42,9 @@ const struct sieve_command tst_test_error = {
NULL NULL
}; };
/* Test_error operation */ /*
* Operation
*/
static bool tst_test_error_operation_dump static bool tst_test_error_operation_dump
(const struct sieve_operation *op, (const struct sieve_operation *op,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.