8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch#ifndef SMTP_COMMAND_H
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch#define SMTP_COMMAND_H
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch#define SMTP_COMMAND_DEFAULT_MAX_PARAMETERS_SIZE 4*1024
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch#define SMTP_COMMAND_DEFAULT_MAX_AUTH_SIZE 8*1024
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch#define SMTP_COMMAND_DEFAULT_MAX_DATA_SIZE 40*1024*1024
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Boschstruct smtp_command_limits {
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch /* Maximum size of command parameters, starting after first space */
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch uoff_t max_parameters_size;
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch /* Maximum size of authentication response */
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch uoff_t max_auth_size;
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch /* Absolute maximum size of command data, beyond which the parser yields
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch a fatal error; i.e. closing the connection in the server. This should
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch be higher than a normal message size limit, which would return a
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch normal informative error. The limit here just serves to protect
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch against abuse. */
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch uoff_t max_data_size;
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch};
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Boschstruct smtp_command {
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch const char *name;
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch const char *parameters;
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch};
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Boschstatic inline void
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Boschsmtp_command_limits_merge(struct smtp_command_limits *limits,
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch const struct smtp_command_limits *new_limits)
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch{
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch if (new_limits->max_parameters_size > 0)
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch limits->max_parameters_size = new_limits->max_parameters_size;
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch if (new_limits->max_auth_size > 0)
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch limits->max_auth_size = new_limits->max_auth_size;
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch if (new_limits->max_data_size > 0)
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch limits->max_data_size = new_limits->max_data_size;
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch}
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch#endif