SCCS-vsn: usr.sbin/sendmail/src/alias.c 3.25
SCCS-vsn: usr.sbin/sendmail/src/conf.c 3.34
SCCS-vsn: usr.sbin/sendmail/src/sendmail.h 3.47
SCCS-vsn: usr.sbin/sendmail/src/util.c 3.10
SCCS-vsn: usr.sbin/sendmail/src/version.c 3.50
SCCS-vsn: usr.sbin/sendmail/src/main.c 3.42
SCCS-vsn: usr.sbin/sendmail/src/recipient.c 3.25
# include "sendmail.h"
# ifdef DBM
# include "sendmail.h"
# ifdef DBM
-static char SccsId[] = "@(#)alias.c 3.24 %G% (with DBM)";
+static char SccsId[] = "@(#)alias.c 3.25 %G% (with DBM)";
-static char SccsId[] = "@(#)alias.c 3.24 %G% (without DBM)";
+static char SccsId[] = "@(#)alias.c 3.25 %G% (without DBM)";
ADDRESS *user;
{
char buf[60];
ADDRESS *user;
{
char buf[60];
+ extern bool safefile();
/* good address -- look for .forward file in home */
define('z', user->q_home);
(void) expand("$z/.forward", buf, &buf[sizeof buf - 1]);
/* good address -- look for .forward file in home */
define('z', user->q_home);
(void) expand("$z/.forward", buf, &buf[sizeof buf - 1]);
- if (stat(buf, &stbuf) < 0 || stbuf.st_uid != user->q_uid ||
- !bitset(S_IREAD, stbuf.st_mode))
+ if (!safefile(buf, user->q_uid, S_IREAD))
return;
/* we do have an address to forward to -- do it */
return;
/* we do have an address to forward to -- do it */
-static char SccsId[] = "@(#)conf.c 3.33 %G%";
+static char SccsId[] = "@(#)conf.c 3.34 %G%";
\f/*
** Header info table
** Final (null) entry contains the flags used for any other field.
\f/*
** Header info table
** Final (null) entry contains the flags used for any other field.
+ if (Daemon)
+ return (RealUid);
+ else
+ return (getuid());
+ if (Daemon)
+ return (RealGid);
+ else
+ return (getgid());
# include <signal.h>
# include <pwd.h>
# include <signal.h>
# include <pwd.h>
+# include <sys/types.h>
+# include <sys/stat.h>
# define _DEFINE
# include "sendmail.h"
# ifdef LOG
# include <syslog.h>
# endif LOG
# define _DEFINE
# include "sendmail.h"
# ifdef LOG
# include <syslog.h>
# endif LOG
-static char SccsId[] = "@(#)main.c 3.41 %G%";
+static char SccsId[] = "@(#)main.c 3.42 %G%";
/*
** SENDMAIL -- Post mail to a set of destinations.
/*
** SENDMAIL -- Post mail to a set of destinations.
char ybuf[10]; /* holds tty id */
bool aliasinit = FALSE;
extern char *ttyname();
char ybuf[10]; /* holds tty id */
bool aliasinit = FALSE;
extern char *ttyname();
+ char cfbuf[60]; /* holds .cf filename */
+ extern bool safefile();
bool canrename;
argv[argc] = NULL;
bool canrename;
argv[argc] = NULL;
printf("Version %s Debug %d\n", Version, Debug);
break;
printf("Version %s Debug %d\n", Version, Debug);
break;
- case 'D': /* redefine internal macro */
+ case 'M': /* redefine internal macro */
define(p[2], &p[3]);
break;
# endif DEBUG
define(p[2], &p[3]);
break;
# endif DEBUG
+ case 'D': /* run as a daemon */
+ Daemon = TRUE;
+ MailBack = TRUE;
+ break;
+
default:
/* at Eric Schmidt's suggestion, this will not be an error....
syserr("Unknown flag %s", p);
default:
/* at Eric Schmidt's suggestion, this will not be an error....
syserr("Unknown flag %s", p);
+ ** Read system control file.
*/
readcf(ConfFile, safecf);
*/
readcf(ConfFile, safecf);
-# ifndef V6
- p = getenv("HOME");
- if (p != NULL)
- {
- char cfbuf[60];
-
- define('z', p);
- (void) expand("$z/.mailcf", cfbuf, &cfbuf[sizeof cfbuf - 1]);
- if (access(cfbuf, 2) == 0)
- readcf(cfbuf, FALSE);
- }
-# endif V6
+ /*
+ ** Initialize aliases.
+ */
initaliases(AliasFile, aliasinit);
# ifdef DBM
initaliases(AliasFile, aliasinit);
# ifdef DBM
# ifdef DEBUG
if (Debug > 15)
{
# ifdef DEBUG
if (Debug > 15)
{
+ /* print configuration table (or at least part of it) */
printrules();
for (i = 0; i < MAXMAILERS; i++)
{
printrules();
for (i = 0; i < MAXMAILERS; i++)
{
+ /*
+ ** If a daemon, wait for a request.
+ ** getrequests will always return in a child.
+ */
+
+ if (Daemon)
+ getrequests();
+
/*
locname = getname();
if (locname == NULL || locname[0] == '\0')
/*
locname = getname();
if (locname == NULL || locname[0] == '\0')
+ {
+ errno = 0;
+ p = getlogin();
+ errno = 0;
+ }
+ if (Daemon || p == NULL)
{
extern struct passwd *getpwuid();
int uid;
{
extern struct passwd *getpwuid();
int uid;
+ /*
+ ** Process passwd file entry.
+ */
+
+ /* run user's .mailcf file */
+ define('z', pw->pw_dir);
+ (void) expand("$z/.mailcf", cfbuf, &cfbuf[sizeof cfbuf - 1]);
+ if (safefile(cfbuf, getruid(), S_IREAD))
+ readcf(cfbuf, FALSE);
+
/* extract full name from passwd file */
if ((fullname == NULL || fullname[0] == '\0') &&
pw != NULL && pw->pw_gecos != NULL)
/* extract full name from passwd file */
if ((fullname == NULL || fullname[0] == '\0') &&
pw != NULL && pw->pw_gecos != NULL)
- if (argc <= 0 && !GrabTo)
+ if (!Daemon && argc <= 0 && !GrabTo)
usrerr("Usage: /etc/sendmail [flags] addr...");
/*
usrerr("Usage: /etc/sendmail [flags] addr...");
/*
if (GrabTo)
DontSend = TRUE;
if (GrabTo)
DontSend = TRUE;
+ if (Daemon)
+ getrecipients();
+ else
+ sendtoargv(argv);
/* if we have had errors sofar, drop out now */
if (Errors > 0 && ExitStat == EX_OK)
/* if we have had errors sofar, drop out now */
if (Errors > 0 && ExitStat == EX_OK)
# include <sys/stat.h>
# include "sendmail.h"
# include <sys/stat.h>
# include "sendmail.h"
-static char SccsId[] = "@(#)recipient.c 3.24 %G%";
+static char SccsId[] = "@(#)recipient.c 3.25 %G%";
/*
** SENDTO -- Designate a send list.
/*
** SENDTO -- Designate a send list.
a->q_flags |= QDONTSEND;
}
else if ((stat(buf, &stb) >= 0) ? (!writable(&stb)) :
a->q_flags |= QDONTSEND;
}
else if ((stat(buf, &stb) >= 0) ? (!writable(&stb)) :
- (*p = '\0', access(buf, 3) < 0))
+ (*p = '\0', !safefile(buf, getruid(), S_IWRITE|S_IEXEC)))
{
a->q_flags |= QBADADDR;
giveresponse(EX_CANTCREAT, TRUE, m);
{
a->q_flags |= QBADADDR;
giveresponse(EX_CANTCREAT, TRUE, m);
/*
** SENDMAIL.H -- Global definitions for sendmail.
/*
** SENDMAIL.H -- Global definitions for sendmail.
-**
-** @(#)sendmail.h 3.46 %G%
*/
# ifdef _DEFINE
# define EXTERN
*/
# ifdef _DEFINE
# define EXTERN
+static char SmailSccsId[] = "@(#)sendmail.h 3.47 %G%";
# else _DEFINE
# define EXTERN extern
# endif _DEFINE
# else _DEFINE
# define EXTERN extern
# endif _DEFINE
EXTERN bool GrabTo; /* if set, get recipients from msg */
EXTERN bool DontSend; /* mark recipients as QDONTSEND */
EXTERN bool NoReturn; /* don't return letter to sender */
EXTERN bool GrabTo; /* if set, get recipients from msg */
EXTERN bool DontSend; /* mark recipients as QDONTSEND */
EXTERN bool NoReturn; /* don't return letter to sender */
+EXTERN bool Daemon; /* running as a daemon */
+EXTERN int RealUid; /* when Daemon, real uid of caller */
+EXTERN int RealGid; /* when Daemon, real gid of caller */
EXTERN int OldUmask; /* umask when sendmail starts up */
EXTERN int Debug; /* debugging level */
EXTERN int Errors; /* set if errors */
EXTERN int OldUmask; /* umask when sendmail starts up */
EXTERN int Debug; /* debugging level */
EXTERN int Errors; /* set if errors */
+# include <sys/types.h>
+# include <sys/stat.h>
# include <sysexits.h>
# include "useful.h"
# include <ctype.h>
# include "conf.h"
# include <sysexits.h>
# include "useful.h"
# include <ctype.h>
# include "conf.h"
-static char SccsId[] = "@(#)util.c 3.9 %G%";
+static char SccsId[] = "@(#)util.c 3.10 %G%";
/*
** STRIPQUOTES -- Strip quotes & quote bits from a string.
/*
** STRIPQUOTES -- Strip quotes & quote bits from a string.
+** SAFEFILE -- return true if a file exists and is safe for a user.
+**
+** Parameters:
+** fn -- filename to check.
+** uid -- uid to compare against.
+** mode -- mode bits that must match.
+**
+** Returns:
+** TRUE if fn exists, is owned by uid, and matches mode.
+** FALSE otherwise.
+**
+** Side Effects:
+** none.
+*/
+
+bool
+safefile(fn, uid, mode)
+ char *fn;
+ int uid;
+ int mode;
+{
+ struct stat stbuf;
+
+ if (stat(fn, &stbuf) >= 0 && stbuf.st_uid == uid &&
+ (stbuf.st_mode & mode) == mode)
+ return (TRUE);
+ return (FALSE);
+}
+\f/*
** SYSLOG -- fake entry to fool lint
*/
** SYSLOG -- fake entry to fool lint
*/
-static char SccsId[] = "@(#)SendMail version 3.49 of %G%";
+static char SccsId[] = "@(#)SendMail version 3.50 of %G%";
-char Version[] = "3.49 [%G%]";
+char Version[] = "3.50 [%G%]";