1 #ifndef SMTP_COMMAND_H
2 #define SMTP_COMMAND_H
3 
4 #define SMTP_COMMAND_DEFAULT_MAX_PARAMETERS_SIZE  4*1024
5 #define SMTP_COMMAND_DEFAULT_MAX_AUTH_SIZE        8*1024
6 #define SMTP_COMMAND_DEFAULT_MAX_DATA_SIZE        40*1024*1024
7 
8 struct smtp_command_limits {
9 	/* Maximum size of command parameters, starting after first space */
10 	uoff_t max_parameters_size;
11 	/* Maximum size of authentication response */
12 	uoff_t max_auth_size;
13 	/* Absolute maximum size of command data, beyond which the parser yields
14 	   a fatal error; i.e. closing the connection in the server. This should
15 	   be higher than a normal message size limit, which would return a
16 	   normal informative error. The limit here just serves to protect
17 	   against abuse. */
18 	uoff_t max_data_size;
19 };
20 
21 struct smtp_command {
22 	const char *name;
23 	const char *parameters;
24 };
25 
26 static inline void
smtp_command_limits_merge(struct smtp_command_limits * limits,const struct smtp_command_limits * new_limits)27 smtp_command_limits_merge(struct smtp_command_limits *limits,
28 			  const struct smtp_command_limits *new_limits)
29 {
30 	if (new_limits->max_parameters_size > 0)
31 		limits->max_parameters_size = new_limits->max_parameters_size;
32 	if (new_limits->max_auth_size > 0)
33 		limits->max_auth_size = new_limits->max_auth_size;
34 	if (new_limits->max_data_size > 0)
35 		limits->max_data_size = new_limits->max_data_size;
36 }
37 
38 #endif
39