/*
* Copyright (c) 1999-2004, 2009 Proofpoint, Inc. and its suppliers.
* All rights reserved.
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENSE file which can be found at the top level of
* the sendmail distribution.
*
*/
#include "libmilter.h"
#include <sm/errstring.h>
/*
**
** Parameters:
** sz -- new limit.
**
** Returns:
** old limit
*/
{
old = Maxdatasize;
Maxdatasize = sz;
return old;
}
/*
** MI_RD_CMD -- read a command
**
** Parameters:
** sd -- socket descriptor
** timeout -- maximum time to wait
** cmd -- single character command read from sd
** rlen -- pointer to length of result
** name -- name of milter
**
** Returns:
** buffer with rest of command
** (malloc()ed here, should be free()d)
** hack: encode error in cmd
*/
char *
char *cmd;
char *name;
{
ssize_t i;
int ret;
int save_errno;
char *buf;
*cmd = '\0';
*rlen = 0;
i = 0;
for (;;)
{
if (ret == 0)
break;
else if (ret < 0)
{
continue;
break;
}
{
*cmd = SMFIC_SELECT;
return NULL;
}
if (MI_SOCK_READ_FAIL(len))
{
"%s, mi_rd_cmd: read returned %d: %s",
*cmd = SMFIC_RECVERR;
return NULL;
}
if (len == 0)
{
return NULL;
}
break;
i += len;
}
if (ret == 0)
{
*cmd = SMFIC_TIMEOUT;
return NULL;
}
else if (ret < 0)
{
"%s: mi_rd_cmd: %s() returned %d: %s",
*cmd = SMFIC_RECVERR;
return NULL;
}
if (expl <= 0)
return NULL;
if (expl > Maxdatasize)
{
*cmd = SMFIC_TOOBIG;
return NULL;
}
#if _FFR_ADD_NULL
#else /* _FFR_ADD_NULL */
#endif /* _FFR_ADD_NULL */
{
*cmd = SMFIC_MALLOC;
return NULL;
}
i = 0;
for (;;)
{
if (ret == 0)
break;
else if (ret < 0)
{
continue;
break;
}
{
*cmd = SMFIC_SELECT;
return NULL;
}
if (MI_SOCK_READ_FAIL(len))
{
"%s: mi_rd_cmd: read returned %d: %s",
ret = -1;
break;
}
if (len == 0)
{
return NULL;
}
{
*cmd = SMFIC_RECVERR;
return NULL;
}
{
#if _FFR_ADD_NULL
/* makes life simpler for common string routines */
#endif /* _FFR_ADD_NULL */
return buf;
}
i += len;
}
save_errno = errno;
/* select returned 0 (timeout) or < 0 (error) */
if (ret == 0)
{
*cmd = SMFIC_TIMEOUT;
return NULL;
}
if (ret < 0)
{
"%s: mi_rd_cmd: %s() returned %d: %s",
*cmd = SMFIC_RECVERR;
return NULL;
}
*cmd = SMFIC_UNKNERR;
return NULL;
}
/*
** RETRY_WRITEV -- Keep calling the writev() system call
** until all the data is written out or an error occurs.
**
** Parameters:
** fd -- socket descriptor
** iov -- io vector
** iovcnt -- number of elements in io vector
** must NOT exceed UIO_MAXIOV.
** timeout -- maximum time to wait
**
** Returns:
** success: number of bytes written
** otherwise: MI_FAILURE
*/
static ssize_t
int iovcnt;
{
int i;
written = 0;
for (;;)
{
{
iov++;
iovcnt--;
}
if (iovcnt <= 0)
return written;
/*
** We don't care much about the timeout here,
** it's very long anyway; correct solution would be
** to take the time before the loop and reduce the
** timeout after each invocation.
** FD_SETSIZE is checked when socket is created.
*/
if (i == 0)
return MI_FAILURE;
if (i < 0)
{
continue;
return MI_FAILURE;
}
if (n == -1)
{
continue;
return MI_FAILURE;
}
written += n;
for (i = 0; i < iovcnt; i++)
{
{
break;
}
}
if (i == iovcnt)
return written;
}
}
/*
** MI_WR_CMD -- write a cmd to sd
**
** Parameters:
** sd -- socket descriptor
** timeout -- maximum time to wait
** cmd -- single character command to write
** buf -- buffer with further data
** len -- length of buffer (without cmd!)
**
** Returns:
*/
int
int cmd;
char *buf;
{
ssize_t l;
int iovcnt;
return MI_FAILURE;
/* set up the vector for the size / command */
iovcnt = 1;
{
iovcnt = 2;
}
if (l == MI_FAILURE)
return MI_FAILURE;
return MI_SUCCESS;
}