Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 106 additions & 9 deletions miltertest/miltertest.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ struct mt_eom_request
struct mt_context
{
char ctx_response; /* milter response code */
char ctx_smtp_reply[BUFRSZ]; /* last SMFIR_REPLYCODE data */
int ctx_fd; /* descriptor */
int ctx_state; /* current state */
unsigned long ctx_mactions; /* requested actions */
Expand Down Expand Up @@ -672,6 +673,11 @@ mt_assert_state(struct mt_context *ctx, int state)
return FALSE;

ctx->ctx_response = rcmd;
if (rcmd == SMFIR_REPLYCODE)
strlcpy(ctx->ctx_smtp_reply, buf,
sizeof ctx->ctx_smtp_reply);
else
ctx->ctx_smtp_reply[0] = '\0';
}

if (rcmd != SMFIR_CONTINUE)
Expand Down Expand Up @@ -715,6 +721,11 @@ mt_assert_state(struct mt_context *ctx, int state)
return FALSE;

ctx->ctx_response = rcmd;
if (rcmd == SMFIR_REPLYCODE)
strlcpy(ctx->ctx_smtp_reply, buf,
sizeof ctx->ctx_smtp_reply);
else
ctx->ctx_smtp_reply[0] = '\0';
}

if (rcmd != SMFIR_CONTINUE)
Expand Down Expand Up @@ -758,6 +769,11 @@ mt_assert_state(struct mt_context *ctx, int state)
return FALSE;

ctx->ctx_response = rcmd;
if (rcmd == SMFIR_REPLYCODE)
strlcpy(ctx->ctx_smtp_reply, buf,
sizeof ctx->ctx_smtp_reply);
else
ctx->ctx_smtp_reply[0] = '\0';
}

if (rcmd != SMFIR_CONTINUE)
Expand Down Expand Up @@ -801,6 +817,11 @@ mt_assert_state(struct mt_context *ctx, int state)
return FALSE;

ctx->ctx_response = rcmd;
if (rcmd == SMFIR_REPLYCODE)
strlcpy(ctx->ctx_smtp_reply, buf,
sizeof ctx->ctx_smtp_reply);
else
ctx->ctx_smtp_reply[0] = '\0';
}

if (rcmd != SMFIR_CONTINUE)
Expand Down Expand Up @@ -841,6 +862,11 @@ mt_assert_state(struct mt_context *ctx, int state)
return FALSE;

ctx->ctx_response = rcmd;
if (rcmd == SMFIR_REPLYCODE)
strlcpy(ctx->ctx_smtp_reply, buf,
sizeof ctx->ctx_smtp_reply);
else
ctx->ctx_smtp_reply[0] = '\0';
}

if (rcmd != SMFIR_CONTINUE)
Expand Down Expand Up @@ -887,6 +913,11 @@ mt_assert_state(struct mt_context *ctx, int state)
return FALSE;

ctx->ctx_response = rcmd;
if (rcmd == SMFIR_REPLYCODE)
strlcpy(ctx->ctx_smtp_reply, buf,
sizeof ctx->ctx_smtp_reply);
else
ctx->ctx_smtp_reply[0] = '\0';
}

if (rcmd != SMFIR_CONTINUE)
Expand Down Expand Up @@ -926,6 +957,11 @@ mt_assert_state(struct mt_context *ctx, int state)
return FALSE;

ctx->ctx_response = rcmd;
if (rcmd == SMFIR_REPLYCODE)
strlcpy(ctx->ctx_smtp_reply, buf,
sizeof ctx->ctx_smtp_reply);
else
ctx->ctx_smtp_reply[0] = '\0';
}

if (rcmd != SMFIR_CONTINUE)
Expand Down Expand Up @@ -966,6 +1002,11 @@ mt_assert_state(struct mt_context *ctx, int state)
return FALSE;

ctx->ctx_response = rcmd;
if (rcmd == SMFIR_REPLYCODE)
strlcpy(ctx->ctx_smtp_reply, buf,
sizeof ctx->ctx_smtp_reply);
else
ctx->ctx_smtp_reply[0] = '\0';
}

if (rcmd != SMFIR_CONTINUE)
Expand Down Expand Up @@ -1551,6 +1592,7 @@ mt_connect(lua_State *l)
new->ctx_state = STATE_INIT;
new->ctx_fd = fd;
new->ctx_response = '\0';
new->ctx_smtp_reply[0] = '\0';
new->ctx_eomreqs = NULL;
new->ctx_mactions = 0;
new->ctx_mpopts = 0;
Expand Down Expand Up @@ -1831,6 +1873,10 @@ mt_negotiate(lua_State *l)
}

ctx->ctx_response = rcmd;
if (rcmd == SMFIR_REPLYCODE)
strlcpy(ctx->ctx_smtp_reply, buf, sizeof ctx->ctx_smtp_reply);
else
ctx->ctx_smtp_reply[0] = '\0';
ctx->ctx_state = STATE_NEGOTIATED;

/* decode and store requested protocol steps and actions */
Expand Down Expand Up @@ -2144,6 +2190,10 @@ mt_conninfo(lua_State *l)
}

ctx->ctx_response = rcmd;
if (rcmd == SMFIR_REPLYCODE)
strlcpy(ctx->ctx_smtp_reply, buf, sizeof ctx->ctx_smtp_reply);
else
ctx->ctx_smtp_reply[0] = '\0';
ctx->ctx_state = STATE_CONNINFO;

if (verbose > 0)
Expand Down Expand Up @@ -2235,6 +2285,10 @@ mt_unknown(lua_State *l)
}

ctx->ctx_response = rcmd;
if (rcmd == SMFIR_REPLYCODE)
strlcpy(ctx->ctx_smtp_reply, buf, sizeof ctx->ctx_smtp_reply);
else
ctx->ctx_smtp_reply[0] = '\0';

if (verbose > 0)
{
Expand Down Expand Up @@ -2320,6 +2374,10 @@ mt_helo(lua_State *l)
}

ctx->ctx_response = rcmd;
if (rcmd == SMFIR_REPLYCODE)
strlcpy(ctx->ctx_smtp_reply, buf, sizeof ctx->ctx_smtp_reply);
else
ctx->ctx_smtp_reply[0] = '\0';
ctx->ctx_state = STATE_HELO;

if (verbose > 0)
Expand Down Expand Up @@ -2414,6 +2472,10 @@ mt_mailfrom(lua_State *l)
}

ctx->ctx_response = rcmd;
if (rcmd == SMFIR_REPLYCODE)
strlcpy(ctx->ctx_smtp_reply, buf, sizeof ctx->ctx_smtp_reply);
else
ctx->ctx_smtp_reply[0] = '\0';
ctx->ctx_state = STATE_ENVFROM;
mt_flush_eomreqs(ctx);

Expand Down Expand Up @@ -2516,6 +2578,10 @@ mt_rcptto(lua_State *l)
}

ctx->ctx_response = rcmd;
if (rcmd == SMFIR_REPLYCODE)
strlcpy(ctx->ctx_smtp_reply, buf, sizeof ctx->ctx_smtp_reply);
else
ctx->ctx_smtp_reply[0] = '\0';
ctx->ctx_state = STATE_ENVRCPT;

if (verbose > 0)
Expand Down Expand Up @@ -2595,6 +2661,10 @@ mt_data(lua_State *l)
}

ctx->ctx_response = rcmd;
if (rcmd == SMFIR_REPLYCODE)
strlcpy(ctx->ctx_smtp_reply, buf, sizeof ctx->ctx_smtp_reply);
else
ctx->ctx_smtp_reply[0] = '\0';
ctx->ctx_state = STATE_DATA;

if (verbose > 0)
Expand Down Expand Up @@ -2692,6 +2762,10 @@ mt_header(lua_State *l)
}

ctx->ctx_response = rcmd;
if (rcmd == SMFIR_REPLYCODE)
strlcpy(ctx->ctx_smtp_reply, buf, sizeof ctx->ctx_smtp_reply);
else
ctx->ctx_smtp_reply[0] = '\0';
ctx->ctx_state = STATE_HEADER;

if (verbose > 0)
Expand Down Expand Up @@ -2765,6 +2839,10 @@ mt_eoh(lua_State *l)
}

ctx->ctx_response = rcmd;
if (rcmd == SMFIR_REPLYCODE)
strlcpy(ctx->ctx_smtp_reply, buf, sizeof ctx->ctx_smtp_reply);
else
ctx->ctx_smtp_reply[0] = '\0';
ctx->ctx_state = STATE_EOH;

if (verbose > 0)
Expand Down Expand Up @@ -2841,6 +2919,10 @@ mt_bodystring(lua_State *l)
}

ctx->ctx_response = rcmd;
if (rcmd == SMFIR_REPLYCODE)
strlcpy(ctx->ctx_smtp_reply, buf, sizeof ctx->ctx_smtp_reply);
else
ctx->ctx_smtp_reply[0] = '\0';
ctx->ctx_state = STATE_BODY;

if (verbose > 0)
Expand Down Expand Up @@ -2932,6 +3014,10 @@ mt_bodyrandom(lua_State *l)
}

ctx->ctx_response = rcmd;
if (rcmd == SMFIR_REPLYCODE)
strlcpy(ctx->ctx_smtp_reply, buf, sizeof ctx->ctx_smtp_reply);
else
ctx->ctx_smtp_reply[0] = '\0';
ctx->ctx_state = STATE_BODY;

if (verbose > 0)
Expand Down Expand Up @@ -3050,6 +3136,10 @@ mt_bodyfile(lua_State *l)
fclose(f);

ctx->ctx_response = rcmd;
if (rcmd == SMFIR_REPLYCODE)
strlcpy(ctx->ctx_smtp_reply, chunk, sizeof ctx->ctx_smtp_reply);
else
ctx->ctx_smtp_reply[0] = '\0';
ctx->ctx_state = STATE_BODY;

lua_pushnil(l);
Expand Down Expand Up @@ -3637,23 +3727,30 @@ mt_eom_check(lua_State *l)

lua_pop(l, lua_gettop(l));

for (r = ctx->ctx_eomreqs; r != NULL; r = r->eom_next)
{
if (r->eom_request == SMFIR_REPLYCODE)
{
char rbuf[BUFRSZ];
char rbuf[BUFRSZ];

snprintf(rbuf, sizeof rbuf, "%s%s%s%s%s",
smtp,
esc == NULL ? "" : " ", esc == NULL ? "" : esc,
text == NULL ? "" : " ", text == NULL ? "" : text);
snprintf(rbuf, sizeof rbuf, "%s%s%s%s%s",
smtp,
esc == NULL ? "" : " ", esc == NULL ? "" : esc,
text == NULL ? "" : " ", text == NULL ? "" : text);

if (strcmp(rbuf, (char *) r->eom_rdata) == 0)
for (r = ctx->ctx_eomreqs; r != NULL; r = r->eom_next)
{
if (r->eom_request == SMFIR_REPLYCODE &&
strcmp(rbuf, (char *) r->eom_rdata) == 0)
{
lua_pushboolean(l, 1);
return 1;
}
}

if (ctx->ctx_smtp_reply[0] != '\0' &&
strcmp(rbuf, ctx->ctx_smtp_reply) == 0)
{
lua_pushboolean(l, 1);
return 1;
}
}

lua_pushboolean(l, 0);
Expand Down
Loading