summaryrefslogtreecommitdiff
path: root/usr.sbin/sendmail/src/conf.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/sendmail/src/conf.c')
-rw-r--r--usr.sbin/sendmail/src/conf.c330
1 files changed, 294 insertions, 36 deletions
diff --git a/usr.sbin/sendmail/src/conf.c b/usr.sbin/sendmail/src/conf.c
index ab6db9310027..63eb97d4de68 100644
--- a/usr.sbin/sendmail/src/conf.c
+++ b/usr.sbin/sendmail/src/conf.c
@@ -33,7 +33,7 @@
*/
#ifndef lint
-static char sccsid[] = "@(#)conf.c 8.243 (Berkeley) 11/20/95";
+static char sccsid[] = "@(#)conf.c 8.243.1.9 (Berkeley) 9/17/96";
#endif /* not lint */
# include "sendmail.h"
@@ -250,10 +250,9 @@ setdefuser()
static char defuserbuf[40];
DefUser = defuserbuf;
- if ((defpwent = sm_getpwuid(DefUid)) != NULL)
- strcpy(defuserbuf, defpwent->pw_name);
- else
- strcpy(defuserbuf, "nobody");
+ defpwent = sm_getpwuid(DefUid);
+ snprintf(defuserbuf, sizeof defuserbuf, "%s",
+ defpwent == NULL ? "nobody" : defpwent->pw_name);
}
/*
** HOST_MAP_INIT -- initialize host class structures
@@ -2385,53 +2384,303 @@ vsprintf(s, fmt, ap)
/*
** SNPRINTF, VSNPRINT -- counted versions of printf
**
-** These are at best crude emulations.
+** These versions have been grabbed off the net. They have been
+** cleaned up to compile properly and support for .precision and
+** %lx has been added.
*/
#if !HASSNPRINTF
-void
+/**************************************************************
+ * Original:
+ * Patrick Powell Tue Apr 11 09:48:21 PDT 1995
+ * A bombproof version of doprnt (dopr) included.
+ * Sigh. This sort of thing is always nasty do deal with. Note that
+ * the version here does not include floating point...
+ *
+ * snprintf() is used instead of sprintf() as it does limit checks
+ * for string length. This covers a nasty loophole.
+ *
+ * The other functions are there to prevent NULL pointers from
+ * causing nast effects.
+ **************************************************************/
+
+/*static char _id[] = "$Id: snprintf.c,v 1.2 1995/10/09 11:19:47 roberto Exp $";*/
+static void dopr();
+static char *end;
+
+/* VARARGS3 */
+int
# ifdef __STDC__
-snprintf(char *buf, size_t bufsize, const char *fmt, ...)
+snprintf(char *str, size_t count, const char *fmt, ...)
# else
-snprintf(buf, bufsize, fmt, va_alist)
- char *buf;
- size_t bufsize;
+snprintf(str, count, fmt, va_alist)
+ char *str;
+ size_t count;
const char *fmt;
va_dcl
-# endif
+#endif
{
- VA_LOCAL_DECL
+ VA_LOCAL_DECL
- VA_START(fmt);
- vsprintf(buf, fmt, ap);
- VA_END;
-# if defined(XDEBUG) && defined(LOG)
- if (strlen(buf) > bufsize)
- syslog(LOG_ALERT, "INTERNAL ERROR: snprintf overflow: %s",
- shortenstring(buf, 200));
-# endif
+ VA_START (fmt);
+ (void) vsnprintf ( str, count, fmt, ap);
+ VA_END;
+ return( strlen( str ) );
}
-#ifndef luna2
-void
-vsnprintf(buf, bufsize, fmt, ap)
- char *buf;
- size_t bufsize;
- const char *fmt;
- va_list ap;
+# ifndef luna2
+int
+vsnprintf(str, count, fmt, args)
+ char *str;
+ size_t count;
+ const char *fmt;
+ va_list args;
{
- vsprintf(buf, fmt, ap);
-# if defined(XDEBUG) && defined(LOG)
- if (strlen(buf) > bufsize)
- syslog(LOG_ALERT, "INTERNAL ERROR: vsnprintf overflow: %s",
- shortenstring(buf, 200));
-# endif
+ str[0] = 0;
+ end = str+count-1;
+ dopr( str, fmt, args );
+ if( count>0 ){
+ end[0] = 0;
+ }
+ return(strlen(str));
}
-#endif
+/*
+ * dopr(): poor man's version of doprintf
+ */
+
+static void fmtstr __P((char *value, int ljust, int len, int zpad, int maxwidth));
+static void fmtnum __P((long value, int base, int dosign, int ljust, int len, int zpad));
+static void dostr __P(( char * , int ));
+static char *output;
+static void dopr_outch __P(( int c ));
+
+static void
+dopr( buffer, format, args )
+ char *buffer;
+ char *format;
+ va_list args;
+{
+ int ch;
+ long value;
+ int longflag = 0;
+ int pointflag = 0;
+ int maxwidth = 0;
+ char *strvalue;
+ int ljust;
+ int len;
+ int zpad;
+
+ output = buffer;
+ while( (ch = *format++) ){
+ switch( ch ){
+ case '%':
+ ljust = len = zpad = maxwidth = 0;
+ longflag = pointflag = 0;
+ nextch:
+ ch = *format++;
+ switch( ch ){
+ case 0:
+ dostr( "**end of format**" , 0);
+ return;
+ case '-': ljust = 1; goto nextch;
+ case '0': /* set zero padding if len not set */
+ if(len==0 && !pointflag) zpad = '0';
+ case '1': case '2': case '3':
+ case '4': case '5': case '6':
+ case '7': case '8': case '9':
+ if (pointflag)
+ maxwidth = maxwidth*10 + ch - '0';
+ else
+ len = len*10 + ch - '0';
+ goto nextch;
+ case '*':
+ if (pointflag)
+ maxwidth = va_arg( args, int );
+ else
+ len = va_arg( args, int );
+ goto nextch;
+ case '.': pointflag = 1; goto nextch;
+ case 'l': longflag = 1; goto nextch;
+ case 'u': case 'U':
+ /*fmtnum(value,base,dosign,ljust,len,zpad) */
+ if( longflag ){
+ value = va_arg( args, long );
+ } else {
+ value = va_arg( args, int );
+ }
+ fmtnum( value, 10,0, ljust, len, zpad ); break;
+ case 'o': case 'O':
+ /*fmtnum(value,base,dosign,ljust,len,zpad) */
+ if( longflag ){
+ value = va_arg( args, long );
+ } else {
+ value = va_arg( args, int );
+ }
+ fmtnum( value, 8,0, ljust, len, zpad ); break;
+ case 'd': case 'D':
+ if( longflag ){
+ value = va_arg( args, long );
+ } else {
+ value = va_arg( args, int );
+ }
+ fmtnum( value, 10,1, ljust, len, zpad ); break;
+ case 'x':
+ if( longflag ){
+ value = va_arg( args, long );
+ } else {
+ value = va_arg( args, int );
+ }
+ fmtnum( value, 16,0, ljust, len, zpad ); break;
+ case 'X':
+ if( longflag ){
+ value = va_arg( args, long );
+ } else {
+ value = va_arg( args, int );
+ }
+ fmtnum( value,-16,0, ljust, len, zpad ); break;
+ case 's':
+ strvalue = va_arg( args, char *);
+ if (maxwidth > 0 || !pointflag)
+ fmtstr( strvalue,ljust,len,zpad, maxwidth);
+ break;
+ case 'c':
+ ch = va_arg( args, int );
+ dopr_outch( ch ); break;
+ case '%': dopr_outch( ch ); continue;
+ default:
+ dostr( "???????" , 0);
+ }
+ break;
+ default:
+ dopr_outch( ch );
+ break;
+ }
+ }
+ *output = 0;
+}
+
+static void
+fmtstr( value, ljust, len, zpad, maxwidth )
+ char *value;
+ int ljust, len, zpad, maxwidth;
+{
+ int padlen, strlen; /* amount to pad */
+
+ if( value == 0 ){
+ value = "<NULL>";
+ }
+ for( strlen = 0; value[strlen]; ++ strlen ); /* strlen */
+ if (strlen > maxwidth && maxwidth)
+ strlen = maxwidth;
+ padlen = len - strlen;
+ if( padlen < 0 ) padlen = 0;
+ if( ljust ) padlen = -padlen;
+ while( padlen > 0 ) {
+ dopr_outch( ' ' );
+ --padlen;
+ }
+ dostr( value, maxwidth );
+ while( padlen < 0 ) {
+ dopr_outch( ' ' );
+ ++padlen;
+ }
+}
+
+static void
+fmtnum( value, base, dosign, ljust, len, zpad )
+ long value;
+ int base, dosign, ljust, len, zpad;
+{
+ int signvalue = 0;
+ unsigned long uvalue;
+ char convert[20];
+ int place = 0;
+ int padlen = 0; /* amount to pad */
+ int caps = 0;
+
+ /* DEBUGP(("value 0x%x, base %d, dosign %d, ljust %d, len %d, zpad %d\n",
+ value, base, dosign, ljust, len, zpad )); */
+ uvalue = value;
+ if( dosign ){
+ if( value < 0 ) {
+ signvalue = '-';
+ uvalue = -value;
+ }
+ }
+ if( base < 0 ){
+ caps = 1;
+ base = -base;
+ }
+ do{
+ convert[place++] =
+ (caps? "0123456789ABCDEF":"0123456789abcdef")
+ [uvalue % (unsigned)base ];
+ uvalue = (uvalue / (unsigned)base );
+ }while(uvalue);
+ convert[place] = 0;
+ padlen = len - place;
+ if( padlen < 0 ) padlen = 0;
+ if( ljust ) padlen = -padlen;
+ /* DEBUGP(( "str '%s', place %d, sign %c, padlen %d\n",
+ convert,place,signvalue,padlen)); */
+ if( zpad && padlen > 0 ){
+ if( signvalue ){
+ dopr_outch( signvalue );
+ --padlen;
+ signvalue = 0;
+ }
+ while( padlen > 0 ){
+ dopr_outch( zpad );
+ --padlen;
+ }
+ }
+ while( padlen > 0 ) {
+ dopr_outch( ' ' );
+ --padlen;
+ }
+ if( signvalue ) dopr_outch( signvalue );
+ while( place > 0 ) dopr_outch( convert[--place] );
+ while( padlen < 0 ){
+ dopr_outch( ' ' );
+ ++padlen;
+ }
+}
+
+static void
+dostr( str , cut)
+ char *str;
+ int cut;
+{
+ if (cut) {
+ while(*str && cut-- > 0) dopr_outch(*str++);
+ } else {
+ while(*str) dopr_outch(*str++);
+ }
+}
+
+static void
+dopr_outch( c )
+ int c;
+{
+#if 0
+ if( iscntrl(c) && c != '\n' && c != '\t' ){
+ c = '@' + (c & 0x1F);
+ if( end == 0 || output < end ){
+ *output++ = '^';
+ }
+ }
#endif
+ if( end == 0 || output < end ){
+ *output++ = c;
+ }
+}
+
+# endif /* !luna2 */
+
+#endif /* !HASSNPRINTF */
/*
** USERSHELLOK -- tell if a user's shell is ok for unrestricted use
**
@@ -3062,6 +3311,9 @@ chownsafe(fd)
# endif
# include <sys/resource.h>
#endif
+#ifndef FD_SETSIZE
+# define FD_SETSIZE 256
+#endif
void
resetlimits()
@@ -3072,11 +3324,17 @@ resetlimits()
lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
(void) setrlimit(RLIMIT_CPU, &lim);
(void) setrlimit(RLIMIT_FSIZE, &lim);
+# ifdef RLIMIT_NOFILE
+ lim.rlim_cur = lim.rlim_max = FD_SETSIZE;
+ (void) setrlimit(RLIMIT_NOFILE, &lim);
+# endif
#else
# if HASULIMIT
(void) ulimit(2, 0x3fffff);
+ (void) ulimit(4, FD_SETSIZE);
# endif
#endif
+ errno = 0;
}
/*
** GETCFNAME -- return the name of the .cf file.
@@ -3509,7 +3767,7 @@ load_if_names()
ia = (((struct sockaddr_in *) sa)->sin_addr);
/* save IP address in text from */
- (void) sprintf(ip_addr, "[%.*s]",
+ (void) snprintf(ip_addr, sizeof ip_addr, "[%.*s]",
sizeof ip_addr - 3,
inet_ntoa(((struct sockaddr_in *) sa)->sin_addr));
if (!wordinclass(ip_addr, 'w'))