summaryrefslogtreecommitdiff
path: root/contrib/sendmail/src/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/sendmail/src/util.c')
-rw-r--r--contrib/sendmail/src/util.c309
1 files changed, 21 insertions, 288 deletions
diff --git a/contrib/sendmail/src/util.c b/contrib/sendmail/src/util.c
index 785d36269eb98..ba35dcd9531cb 100644
--- a/contrib/sendmail/src/util.c
+++ b/contrib/sendmail/src/util.c
@@ -11,7 +11,7 @@
*/
#ifndef lint
-static char sccsid[] = "@(#)util.c 8.167 (Berkeley) 12/1/1998";
+static char sccsid[] = "@(#)util.c 8.159 (Berkeley) 7/1/98";
#endif /* not lint */
# include "sendmail.h"
@@ -174,182 +174,6 @@ rfc822_string(s)
return TRUE;
}
/*
-** SHORTEN_RFC822_STRING -- Truncate and rebalance an RFC822 string
-**
-** Arbitratily shorten (in place) an RFC822 string and rebalance
-** comments and quotes.
-**
-** Parameters:
-** string -- the string to shorten
-** length -- the maximum size, 0 if no maximum
-**
-** Returns:
-** TRUE if string is changed, FALSE otherwise
-**
-** Side Effects:
-** Changes string in place, possibly resulting
-** in a shorter string.
-*/
-
-bool
-shorten_rfc822_string(string, length)
- char *string;
- size_t length;
-{
- bool backslash = FALSE;
- bool modified = FALSE;
- bool quoted = FALSE;
- size_t slen;
- int parencount = 0;
- char *ptr = string;
-
- /*
- ** If have to rebalance an already short enough string,
- ** need to do it within allocated space.
- */
- slen = strlen(string);
- if (length == 0 || slen < length)
- length = slen;
-
- while (*ptr != '\0')
- {
- if (backslash)
- {
- backslash = FALSE;
- goto increment;
- }
-
- if (*ptr == '\\')
- backslash = TRUE;
- else if (*ptr == '(')
- {
- if (!quoted)
- parencount++;
- }
- else if (*ptr == ')')
- {
- if (--parencount < 0)
- parencount = 0;
- }
-
- /* Inside a comment, quotes don't matter */
- if (parencount <= 0 && *ptr == '"')
- quoted = !quoted;
-
-increment:
- /* Check for sufficient space for next character */
- if (length - (ptr - string) <= ((backslash ? 1 : 0) +
- parencount +
- (quoted ? 1 : 0)))
- {
- /* Not enough, backtrack */
- if (*ptr == '\\')
- backslash = FALSE;
- else if (*ptr == '(' && !quoted)
- parencount--;
- else if (*ptr == '"' && parencount == 0)
- quoted = FALSE;
- break;
- }
- ptr++;
- }
-
- /* Rebalance */
- while (parencount-- > 0)
- {
- if (*ptr != ')')
- {
- modified = TRUE;
- *ptr = ')';
- }
- ptr++;
- }
- if (quoted)
- {
- if (*ptr != '"')
- {
- modified = TRUE;
- *ptr = '"';
- }
- ptr++;
- }
- if (*ptr != '\0')
- {
- modified = TRUE;
- *ptr = '\0';
- }
- return modified;
-}
- /*
-** FIND_CHARACTER -- find an unquoted character in an RFC822 string
-**
-** Find an unquoted, non-commented character in an RFC822
-** string and return a pointer to its location in the
-** string.
-**
-** Parameters:
-** string -- the string to search
-** character -- the character to find
-**
-** Returns:
-** pointer to the character, or
-** a pointer to the end of the line if character is not found
-*/
-
-char *
-find_character(string, character)
- char *string;
- char character;
-{
- bool backslash = FALSE;
- bool quoted = FALSE;
- int parencount = 0;
-
- while (string != NULL && *string != '\0')
- {
- if (backslash)
- {
- backslash = FALSE;
- if (!quoted && character == '\\' && *string == '\\')
- break;
- string++;
- continue;
- }
- switch (*string)
- {
- case '\\':
- backslash = TRUE;
- break;
-
- case '(':
- if (!quoted)
- parencount++;
- break;
-
- case ')':
- if (--parencount < 0)
- parencount = 0;
- break;
- }
-
- /* Inside a comment, nothing matters */
- if (parencount > 0)
- {
- string++;
- continue;
- }
-
- if (*string == '"')
- quoted = !quoted;
- else if (*string == character && !quoted)
- break;
- string++;
- }
-
- /* Return pointer to the character */
- return string;
-}
- /*
** XALLOC -- Allocate memory and bitch wildly on failure.
**
** THIS IS A CLUDGE. This should be made to give a proper
@@ -2022,13 +1846,7 @@ path_is_dir(pathname, createflag)
** none
*/
-struct procs
-{
- pid_t proc_pid;
- char *proc_task;
-};
-
-static struct procs *ProcListVec = NULL;
+static pid_t *ProcListVec = NULL;
static int ProcListSize = 0;
#define NO_PID ((pid_t) 0)
@@ -2037,15 +1855,15 @@ static int ProcListSize = 0;
#endif
void
-proc_list_add(pid, task)
+proc_list_add(pid)
pid_t pid;
- char *task;
{
int i;
+ extern void proc_list_probe __P((void));
for (i = 0; i < ProcListSize; i++)
{
- if (ProcListVec[i].proc_pid == NO_PID)
+ if (ProcListVec[i] == NO_PID)
break;
}
if (i >= ProcListSize)
@@ -2056,66 +1874,29 @@ proc_list_add(pid, task)
/* now scan again */
for (i = 0; i < ProcListSize; i++)
{
- if (ProcListVec[i].proc_pid == NO_PID)
+ if (ProcListVec[i] == NO_PID)
break;
}
}
if (i >= ProcListSize)
{
/* grow process list */
- struct procs *npv;
+ pid_t *npv;
- npv = (struct procs *) xalloc(sizeof (struct procs) * (ProcListSize + PROC_LIST_SEG));
+ npv = (pid_t *) xalloc(sizeof (pid_t) * (ProcListSize + PROC_LIST_SEG));
if (ProcListSize > 0)
{
- bcopy(ProcListVec, npv, ProcListSize *
- sizeof (struct procs));
+ bcopy(ProcListVec, npv, ProcListSize * sizeof (pid_t));
free(ProcListVec);
}
for (i = ProcListSize; i < ProcListSize + PROC_LIST_SEG; i++)
- {
- npv[i].proc_pid = NO_PID;
- npv[i].proc_task = NULL;
- }
+ npv[i] = NO_PID;
i = ProcListSize;
ProcListSize += PROC_LIST_SEG;
ProcListVec = npv;
}
- ProcListVec[i].proc_pid = pid;
- ProcListVec[i].proc_task = newstr(task);
-
- /* if process adding itself, it's not a child */
- if (pid != getpid())
- CurChildren++;
-}
- /*
-** PROC_LIST_SET -- set pid task in process list
-**
-** Parameters:
-** pid -- pid to set
-** task -- task of pid
-**
-** Returns:
-** none.
-*/
-
-void
-proc_list_set(pid, task)
- pid_t pid;
- char *task;
-{
- int i;
-
- for (i = 0; i < ProcListSize; i++)
- {
- if (ProcListVec[i].proc_pid == pid)
- {
- if (ProcListVec[i].proc_task != NULL)
- free(ProcListVec[i].proc_task);
- ProcListVec[i].proc_task = newstr(task);
- break;
- }
- }
+ ProcListVec[i] = pid;
+ CurChildren++;
}
/*
** PROC_LIST_DROP -- drop pid from process list
@@ -2135,14 +1916,9 @@ proc_list_drop(pid)
for (i = 0; i < ProcListSize; i++)
{
- if (ProcListVec[i].proc_pid == pid)
+ if (ProcListVec[i] == pid)
{
- ProcListVec[i].proc_pid = NO_PID;
- if (ProcListVec[i].proc_task != NULL)
- {
- free(ProcListVec[i].proc_task);
- ProcListVec[i].proc_task = NULL;
- }
+ ProcListVec[i] = NO_PID;
break;
}
}
@@ -2164,16 +1940,8 @@ proc_list_clear()
{
int i;
- /* start from 1 since 0 is the daemon itself */
- for (i = 1; i < ProcListSize; i++)
- {
- ProcListVec[i].proc_pid = NO_PID;
- if (ProcListVec[i].proc_task != NULL)
- {
- free(ProcListVec[i].proc_task);
- ProcListVec[i].proc_task = NULL;
- }
- }
+ for (i = 0; i < ProcListSize; i++)
+ ProcListVec[i] = NO_PID;
CurChildren = 0;
}
/*
@@ -2191,23 +1959,17 @@ proc_list_probe()
{
int i;
- /* start from 1 since 0 is the daemon itself */
- for (i = 1; i < ProcListSize; i++)
+ for (i = 0; i < ProcListSize; i++)
{
- if (ProcListVec[i].proc_pid == NO_PID)
+ if (ProcListVec[i] == NO_PID)
continue;
- if (kill(ProcListVec[i].proc_pid, 0) < 0)
+ if (kill(ProcListVec[i], 0) < 0)
{
if (LogLevel > 3)
sm_syslog(LOG_DEBUG, CurEnv->e_id,
"proc_list_probe: lost pid %d",
- (int) ProcListVec[i].proc_pid);
- ProcListVec[i].proc_pid = NO_PID;
- if (ProcListVec[i].proc_task != NULL)
- {
- free(ProcListVec[i].proc_task);
- ProcListVec[i].proc_task = NULL;
- }
+ ProcListVec[i]);
+ ProcListVec[i] = NO_PID;
CurChildren--;
}
}
@@ -2215,35 +1977,6 @@ proc_list_probe()
CurChildren = 0;
}
/*
-** PROC_LIST_DISPLAY -- display the process list
-**
-** Parameters:
-** out -- output file pointer
-**
-** Returns:
-** none.
-*/
-
-void
-proc_list_display(out)
- FILE *out;
-{
- int i;
-
- for (i = 0; i < ProcListSize; i++)
- {
- if (ProcListVec[i].proc_pid == NO_PID)
- continue;
-
- fprintf(out, "%d %s%s\n", (int) ProcListVec[i].proc_pid,
- ProcListVec[i].proc_task != NULL ?
- ProcListVec[i].proc_task : "(unknown)",
- (OpMode == MD_SMTP ||
- OpMode == MD_DAEMON ||
- OpMode == MD_ARPAFTP) ? "\r" : "");
- }
-}
- /*
** SM_STRCASECMP -- 8-bit clean version of strcasecmp
**
** Thank you, vendors, for making this all necessary.