BSD 4_4_Lite2 release
[unix-history] / usr / src / usr.sbin / sendmail / src / util.c
index 5bbfed1..6c170ba 100644 (file)
@@ -3,16 +3,41 @@
  * Copyright (c) 1988, 1993
  *     The Regents of the University of California.  All rights reserved.
  *
  * Copyright (c) 1988, 1993
  *     The Regents of the University of California.  All rights reserved.
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. 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 BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)util.c     8.78 (Berkeley) %G%";
+static char sccsid[] = "@(#)util.c     8.78 (Berkeley) 6/21/95";
 #endif /* not lint */
 
 # include "sendmail.h"
 # include <sysexits.h>
 #endif /* not lint */
 
 # include "sendmail.h"
 # include <sysexits.h>
-# include "conf.h"
 \f/*
 **  STRIPQUOTES -- Strip quotes & quote bits from a string.
 **
 \f/*
 **  STRIPQUOTES -- Strip quotes & quote bits from a string.
 **
@@ -332,116 +357,60 @@ makelower(p)
                        *p = tolower(c);
 }
 \f/*
                        *p = tolower(c);
 }
 \f/*
-**  FULLNAME -- extract full name from a passwd file entry.
+**  BUILDFNAME -- build full name from gecos style entry.
+**
+**     This routine interprets the strange entry that would appear
+**     in the GECOS field of the password file.
 **
 **     Parameters:
 **
 **     Parameters:
-**             pw -- password entry to start from.
-**             buf -- buffer to store result in.
+**             p -- name to build.
+**             login -- the login name of this user (for &).
+**             buf -- place to put the result.
 **
 **     Returns:
 **
 **     Returns:
-**             TRUE -- if the resulting message should be a MIME format.
-**             FALSE -- if MIME is not necessary.
+**             none.
 **
 **     Side Effects:
 **             none.
 */
 
 void
 **
 **     Side Effects:
 **             none.
 */
 
 void
-/* values for should_quote */
-#define NO_QUOTE       0
-#define SHOULD_QUOTE   1
-#define SHOULD_MIME    2
-
-int
-       register unsigned char *gecos;
-       const unsigned char *login;
-       unsigned char *buf;
+buildfname(gecos, login, buf)
+       register char *gecos;
+       char *login;
+       char *buf;
 {
 {
-       register unsigned char *bp = buf;
-       unsigned char *p;
-       int should_quote = NO_QUOTE;
-       register char *p = pw->pw_gecos;
+       register char *p;
+       register char *bp = buf;
+       int l;
 
 
-       /* make sure specials, SPACE and CTLs are quoted within " " */
-       for (p = gecos; *p && *p != ',' && *p != ';' && *p != '%'; p++)
-       {
-               if (*p >= 0200)
-               {
-                       should_quote = SHOULD_MIME;
-                       break;
-               }
-               switch (*p)
-               {
-                 case '(':
-                 case ')':
-                 case '<':
-                 case '>':
-                 case '@':
-                 case ':':
-                 case '\\':
-                 case '"':
-                 case '.':
-                 case '[':
-                 case ']':
-                       should_quote = SHOULD_QUOTE;
-                       break;
-               }       
-       }
-       if (should_quote == SHOULD_MIME)
+       if (*gecos == '*')
+               gecos++;
+
+       /* find length of final string */
+       l = 0;
+       for (p = gecos; *p != '\0' && *p != ',' && *p != ';' && *p != '%'; p++)
        {
        {
-               strcpy (bp, "=?iso-8859-1?Q?");
-               bp += 15;
-               for (p = gecos; *p && *p != ',' && *p != ';' && *p != '%'; p++)
-               {
-                       if (*p == ' ')
-                               *bp++ = '_';
-                        else if (*p == '&')
-                        {
-                               (void) strcpy(bp, login);
-                               *bp = toupper(*bp);
-                               bp += strlen (bp);
-                       }
-                       else if (*p < 040 || *p >= 200 || 
-                                strchr("_?()<>@:\\\".[]", *p) != NULL)
-                       {
-                               *bp++ = '=';
-                               *bp++ = "0123456789ABCDEF"[(*p >> 4) & 0xf];
-                               *bp++ = "0123456789ABCDEF"[*p & 0xf];
-                       }
-                       else
-                               *bp++ = *p;
-               }
-               strcpy (bp, "?= ");
-               bp += 3;
+               if (*p == '&')
+                       l += strlen(login);
+               else
+                       l++;
        }
        }
-       else
+
+       /* now fill in buf */
+       for (p = gecos; *p != '\0' && *p != ',' && *p != ';' && *p != '%'; p++)
        {
        {
-               if (should_quote)
-                       *bp++ = '"';
-               for (p = gecos; *p && *p != ',' && *p != ';' && *p != '%'; p++)
+               if (*p == '&')
                {
                {
-                       if (*p == '&')
-                       {
-                               (void) strcpy(bp, login);
-                               *bp = toupper(*bp);
-                               while (*bp != '\0')
-                                       bp++;
-                       }
-                       else
-                       {
-                               if (*p == '"')
-                                       *bp++ = '\\';
-                               *bp++ = *p;
-                       }
+                       (void) strcpy(bp, login);
+                       *bp = toupper(*bp);
+                       while (*bp != '\0')
+                               bp++;
                }
                }
-               if (bp[-1] == '\\')
-                       *bp++ = '\\';
-               if (should_quote)
-                       *bp++ = '"';
+               else
+                       *bp++ = *p;
        }
        }
-
        *bp = '\0';
        *bp = '\0';
-       return should_quote == SHOULD_MIME;
 }
 \f/*
 **  SAFEFILE -- return true if a file exists and is safe for a user.
 }
 \f/*
 **  SAFEFILE -- return true if a file exists and is safe for a user.