1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
/*
* Copyright (c) 1983 Eric P. Allman
* Copyright (c) 1988 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted provided
* that: (1) source distributions retain this entire copyright notice and
* comment, and (2) distributions including binaries display the following
* acknowledgement: ``This product includes software developed by the
* University of California, Berkeley and its contributors'' in the
* documentation or other materials provided with the distribution and in
* all advertising materials mentioning features or use of this software.
* Neither the name of the University nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef lint
static char Version[] = "@(#)stat.c e07@nikhef.nl (Eric Wassenaar) 970926";
#endif
#include "vrfy.h"
extern int SmtpErrno; /* saved errno from system calls */
extern char *SmtpPhase; /* connection state message */
extern char *CurHostName; /* remote host that is being contacted */
extern char SmtpErrorBuffer[]; /* smtp temporary failure message */
/*
* Status messages.
*/
static char *SysExMsg[] =
{
/* 64 EX_USAGE */ "500 Bad usage",
/* 65 EX_DATAERR */ "501 Data format error",
/* 66 EX_NOINPUT */ "550 Cannot open input",
/* 67 EX_NOUSER */ "550 User unknown",
/* 68 EX_NOHOST */ "550 Host unknown",
/* 69 EX_UNAVAILABLE */ "554 Service unavailable",
/* 70 EX_SOFTWARE */ "554 Internal error",
/* 71 EX_OSERR */ "451 Operating system error",
/* 72 EX_OSFILE */ "554 System file missing",
/* 73 EX_CANTCREAT */ "550 Can't create output",
/* 74 EX_IOERR */ "451 I/O error",
/* 75 EX_TEMPFAIL */ "250 Deferred",
/* 76 EX_PROTOCOL */ "554 Remote protocol error",
/* 77 EX_NOPERM */ "550 Insufficient permission",
/* 78 EX_CONFIG */ "554 Local configuration error",
#ifdef notdef
/* 79 EX_AMBUSER */ "550 User ambiguous"
#endif
};
static int N_SysEx = sizeof(SysExMsg) / sizeof(SysExMsg[0]);
#define EX__BASE EX_USAGE
/*
** STATSTRING -- Fetch message describing result status
** ----------------------------------------------------
**
** Returns:
** Pointer to appropriate status message.
*/
char *
statstring(stat)
int stat; /* result status */
{
static char buf[BUFSIZ];
if (stat == EX_SUCCESS)
{
(void) sprintf(buf, "250 Ok");
return(buf);
}
stat -= EX__BASE;
if (stat < 0 || stat >= N_SysEx)
{
(void) sprintf(buf, "554 Unknown status %d", stat + EX__BASE);
return(buf);
}
return(SysExMsg[stat]);
}
/*
** ERRSTRING -- Fetch message describing system call errors
** --------------------------------------------------------
**
** Returns:
** Pointer to appropriate error message.
*/
char *
errstring(err)
int err; /* errno from system calls */
{
static char buf[BUFSIZ];
switch (err)
{
case ETIMEDOUT:
case ECONNRESET:
case EIO:
if (err == ECONNRESET)
(void) strcpy(buf, "Connection reset");
else
(void) strcpy(buf, strerror(err));
if (SmtpPhase != NULL)
{
(void) strcat(buf, " during ");
(void) strcat(buf, SmtpPhase);
}
if (CurHostName != NULL)
{
(void) strcat(buf, " with ");
(void) strcat(buf, CurHostName);
}
return(buf);
case EHOSTUNREACH:
case EHOSTDOWN:
case ENETUNREACH:
case ENETDOWN:
if (CurHostName == NULL)
break;
(void) sprintf(buf, "Host %s is unreachable", CurHostName);
return(buf);
case ECONNREFUSED:
if (CurHostName == NULL)
break;
(void) sprintf(buf, "Connection refused by %s", CurHostName);
return(buf);
}
return strerror(err);
}
/*
** GIVERESPONSE -- Issue status message about transaction result
** -------------------------------------------------------------
**
** Returns:
** None.
*/
void
giveresponse(stat)
int stat; /* result status */
{
char buf[BUFSIZ];
register char *p;
if (stat == EX_TEMPFAIL)
{
if (h_errno == TRY_AGAIN)
/* temporary nameserver failure */
p = "Hostname lookup failure";
else if (SmtpErrno != 0)
/* non-fatal system call failure */
p = errstring(SmtpErrno);
else
/* temporary smtp failure reply message received */
p = SmtpErrorBuffer;
/* add extra information for temporary failures */
if (p == NULL || p[0] == '\0')
p = "Transient failure";
(void) sprintf(buf, "%s: %s", statstring(stat), p);
}
else if (stat == EX_NOHOST && h_errno != 0)
{
/* add extra information from nameserver */
if (h_errno == HOST_NOT_FOUND)
p = "Not registered in DNS";
else if (h_errno == NO_ADDRESS)
p = "No address or MX record";
else
p = "Nameserver lookup failure";
(void) sprintf(buf, "%s (%s)", statstring(stat), p);
}
else
(void) sprintf(buf, "%s", statstring(stat));
/* issue status message */
message(buf);
}
|