PcapPlusPlus  24.09
SmtpLayer.h
Go to the documentation of this file.
1 #ifndef PACKETPP_SMTP_LAYER
2 #define PACKETPP_SMTP_LAYER
3 
4 #include "PayloadLayer.h"
6 
8 
13 namespace pcpp
14 {
19  {
20  protected:
21  SmtpLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
22  : SingleCommandTextProtocol(data, dataLen, prevLayer, packet, SMTP) {};
23 
24  SmtpLayer(const std::string& command, const std::string& option)
25  : SingleCommandTextProtocol(command, option, SMTP) {};
26 
27  public:
33  static bool isSmtpPort(uint16_t port)
34  {
35  return port == 25 || port == 587;
36  }
37 
38  // overridden methods
39 
42  {}
43 
47  size_t getHeaderLen() const
48  {
49  return m_DataLen;
50  }
51 
54  {}
55 
60  {
62  }
63  };
64 
68  class SmtpRequestLayer : public SmtpLayer
69  {
70  public:
74  enum class SmtpCommand : uint64_t
75  {
77  UNK,
79  DATA = ('D') | ('A' << 8) | ('T' << 16) | ('A' << 24),
81  EHLO = ('E') | ('H' << 8) | ('L' << 16) | ('O' << 24),
83  EXPN = ('E') | ('X' << 8) | ('P' << 16) | ('N' << 24),
85  HELO = ('H') | ('E' << 8) | ('L' << 16) | ('O' << 24),
87  HELP = ('H') | ('E' << 8) | ('L' << 16) | ('P' << 24),
89  MAIL = ('M') | ('A' << 8) | ('I' << 16) | ('L' << 24),
91  NOOP = ('N') | ('O' << 8) | ('O' << 16) | ('P' << 24),
93  QUIT = ('Q') | ('U' << 8) | ('I' << 16) | ('T' << 24),
95  RCPT = ('R') | ('C' << 8) | ('P' << 16) | ('T' << 24),
97  RSET = ('R') | ('S' << 8) | ('E' << 16) | ('T' << 24),
99  VRFY = ('V') | ('R' << 8) | ('F' << 16) | ('Y' << 24),
101  STARTTLS = (('S') | ('T' << 8) | ('A' << 16) | ('R' << 24) |
102  static_cast<uint64_t>(('T') | ('T' << 8) | ('L' << 16) | ('S' << 24)) << 32),
104  TURN = ('T') | ('U' << 8) | ('R' << 16) | ('N' << 24),
106  SEND = ('S') | ('E' << 8) | ('N' << 16) | ('D' << 24),
108  SOML = ('S') | ('O' << 8) | ('M' << 16) | ('L' << 24),
110  SAML = ('S') | ('A' << 8) | ('M' << 16) | ('L' << 24),
112  AUTH = ('A') | ('U' << 8) | ('T' << 16) | ('H' << 24),
114  ATRN = ('A') | ('T' << 8) | ('R' << 16) | ('N' << 24),
116  BDAT = ('B') | ('D' << 8) | ('A' << 16) | ('T' << 24),
118  ETRN = ('E') | ('T' << 8) | ('R' << 16) | ('N' << 24),
120  XADR = ('X') | ('A' << 8) | ('D' << 16) | ('R' << 24),
122  XCIR = ('X') | ('C' << 8) | ('I' << 16) | ('R' << 24),
124  XSTA = ('X') | ('S' << 8) | ('T' << 16) | ('A' << 24),
126  XGEN = ('X') | ('G' << 8) | ('E' << 16) | ('N' << 24)
127  };
128 
135  SmtpRequestLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
136  : SmtpLayer(data, dataLen, prevLayer, packet) {};
137 
143  explicit SmtpRequestLayer(const SmtpCommand& command, const std::string& option = "")
144  : SmtpLayer(getCommandAsString(command), option) {};
145 
152 
158 
163  std::string getCommandString() const;
164 
170  bool setCommandOption(const std::string& value);
171 
177  std::string getCommandOption(bool removeEscapeCharacters = true) const;
178 
184  static std::string getCommandInfo(SmtpCommand code);
185 
191  static std::string getCommandAsString(SmtpCommand code);
192 
193  // overridden methods
194 
198  std::string toString() const;
199  };
200 
205  {
206  public:
210  enum class SmtpStatusCode : int
211  {
213  SYSTEM_STATUS = 211,
215  HELP_MESSAGE = 214,
217  SERVICE_READY = 220,
219  SERVICE_CLOSE = 221,
221  AUTH_SUCCESS = 235,
223  COMPLETED = 250,
225  WILL_FORWARD = 251,
227  CANNOT_VERIFY = 252,
229  AUTH_INPUT = 334,
231  MAIL_INPUT = 354,
233  SERVICE_UNAVAILABLE = 421,
235  PASS_NEEDED = 432,
239  ABORT_LOCAL_ERROR = 451,
241  INSUFFICIENT_STORAGE = 452,
243  TEMP_AUTH_FAILED = 454,
247  CMD_NOT_RECOGNIZED = 500,
249  SYNTAX_ERROR_PARAM = 501,
251  CMD_NOT_IMPLEMENTED = 502,
253  CMD_BAD_SEQUENCE = 503,
255  PARAM_NOT_IMPLEMENTED = 504,
257  MAIL_NOT_ACCEPTED = 521,
259  ENCRYPT_NEED = 523,
261  AUTH_REQUIRED = 530,
263  AUTH_TOO_WEAK = 534,
265  AUTH_CRED_INVALID = 535,
267  ENCRYPT_REQUIRED = 538,
269  MAILBOX_UNAVAILABLE = 550,
271  USER_NOT_LOCAL = 551,
273  EXCEED_STORAGE = 552,
275  NAME_NOT_ALLOWED = 553,
277  TRANSACTION_FAIL = 554,
279  DOMAIN_NOT_ACCEPT = 556
280  };
281 
288  SmtpResponseLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
289  : SmtpLayer(data, dataLen, prevLayer, packet) {};
290 
296  explicit SmtpResponseLayer(const SmtpStatusCode& code, const std::string& option = "")
297  : SmtpLayer(std::to_string(int(code)), option) {};
298 
305 
311 
316  std::string getStatusCodeString() const;
317 
323  bool setStatusOption(const std::string& value);
324 
330  std::string getStatusOption(bool removeEscapeCharacters = true) const;
331 
337  static std::string getStatusCodeAsString(SmtpStatusCode code);
338 
339  // overridden methods
340 
344  std::string toString() const;
345  };
346 } // namespace pcpp
347 
348 #endif /* PACKETPP_SMTP_LAYER */
Definition: Layer.h:70
Definition: Packet.h:27
Definition: SingleCommandTextProtocol.h:19
Definition: SmtpLayer.h:19
void computeCalculateFields()
Does nothing for this layer.
Definition: SmtpLayer.h:53
size_t getHeaderLen() const
Definition: SmtpLayer.h:47
OsiModelLayer getOsiModelLayer() const
Definition: SmtpLayer.h:59
static bool isSmtpPort(uint16_t port)
Definition: SmtpLayer.h:33
void parseNextLayer()
SMTP is the always last so does nothing for this layer.
Definition: SmtpLayer.h:41
Definition: SmtpLayer.h:69
std::string toString() const
std::string getCommandString() const
SmtpCommand
Definition: SmtpLayer.h:75
@ STARTTLS
Start TLS handshake.
@ SAML
Send mail to terminal and mailbox.
@ TURN
Reverse the role of sender and receiver.
@ ETRN
Request to start SMTP queue processing.
@ ATRN
Reverse the role of sender and receiver.
@ SEND
Send mail to terminal.
@ EXPN
Expand the mailing list.
@ EHLO
Initiate conversation.
@ XGEN
Release status of whether a compiled configuration and character set are in use.
@ SOML
Send mail to terminal or to mailbox.
@ XADR
Release status of the channel.
@ XSTA
Release status of the number of messages in channel queues.
@ XCIR
Release status of the circuit checking facility.
@ AUTH
Authenticate client and server.
@ HELO
Initiate conversation.
static std::string getCommandAsString(SmtpCommand code)
bool setCommand(SmtpCommand code)
SmtpRequestLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: SmtpLayer.h:135
SmtpCommand getCommand() const
static std::string getCommandInfo(SmtpCommand code)
std::string getCommandOption(bool removeEscapeCharacters=true) const
SmtpRequestLayer(const SmtpCommand &command, const std::string &option="")
Definition: SmtpLayer.h:143
bool setCommandOption(const std::string &value)
Definition: SmtpLayer.h:205
SmtpResponseLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: SmtpLayer.h:288
static std::string getStatusCodeAsString(SmtpStatusCode code)
bool setStatusOption(const std::string &value)
SmtpStatusCode
Definition: SmtpLayer.h:211
@ NAME_NOT_ALLOWED
Requested action not taken: mailbox name not allowed.
@ PARAM_NOT_ACCOMMODATED
Server unable to accommodate parameters.
@ INSUFFICIENT_STORAGE
Requested action not taken: insufficient system storage.
@ SERVICE_READY
<domain> Service ready
@ EXCEED_STORAGE
Requested mail action aborted: exceeded storage allocation.
@ SERVICE_UNAVAILABLE
<domain> Service not available, closing transmission channel
@ MAILBOX_UNAVAILABLE_TEMP
Requested mail action not taken: mailbox unavailable (mail busy or temporarily blocked)
@ SERVICE_CLOSE
<domain> Service closing transmission channel
@ ENCRYPT_REQUIRED
Encryption required for requested authentication mechanism.
@ AUTH_CRED_INVALID
Authentication credentials invalid.
@ SYSTEM_STATUS
System status, or system help reply.
@ ABORT_LOCAL_ERROR
Requested action aborted: local error in processing.
@ CMD_BAD_SEQUENCE
Bad sequence of commands.
@ CMD_NOT_IMPLEMENTED
Command not implemented.
@ AUTH_REQUIRED
Authentication required.
@ CMD_NOT_RECOGNIZED
Syntax error, command unrecognized.
@ USER_NOT_LOCAL
User not local; please try <forward-path>
@ COMPLETED
Requested mail action okay, completed.
@ SYNTAX_ERROR_PARAM
Syntax error in parameters or arguments.
@ PASS_NEEDED
A password transition is needed.
@ DOMAIN_NOT_ACCEPT
Domain does not accept mail.
@ MAIL_NOT_ACCEPTED
Server does not accept mail.
@ MAILBOX_UNAVAILABLE
Requested action not taken: mailbox unavailable.
@ PARAM_NOT_IMPLEMENTED
Command parameter not implemented.
@ TEMP_AUTH_FAILED
Temporary authentication failed.
@ AUTH_SUCCESS
Authentication successful.
@ MAIL_INPUT
Start mail input; end with <CRLF>.<CRLF>
@ WILL_FORWARD
User not local; will forward to <forward-path>
@ AUTH_TOO_WEAK
Authentication mechanism is too weak.
@ CANNOT_VERIFY
Cannot VRFY user, but will accept message and attempt delivery.
bool setStatusCode(SmtpStatusCode code)
std::string getStatusCodeString() const
std::string toString() const
std::string getStatusOption(bool removeEscapeCharacters=true) const
SmtpResponseLayer(const SmtpStatusCode &code, const std::string &option="")
Definition: SmtpLayer.h:296
SmtpStatusCode getStatusCode() const
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:354
@ OsiModelApplicationLayer
Definition: ProtocolType.h:368