Deleted Added
full compact
mail.local.c (110553) mail.local.c (110563)
1/*
2 * Copyright (c) 1998-2002 Sendmail, Inc. and its suppliers.
3 * All rights reserved.
4 * Copyright (c) 1990, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
6 *
7 * By using this file, you agree to the terms and conditions set
8 * forth in the LICENSE file which can be found at the top level of
9 * the sendmail distribution.
10 *
1/*
2 * Copyright (c) 1998-2002 Sendmail, Inc. and its suppliers.
3 * All rights reserved.
4 * Copyright (c) 1990, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
6 *
7 * By using this file, you agree to the terms and conditions set
8 * forth in the LICENSE file which can be found at the top level of
9 * the sendmail distribution.
10 *
11 * $FreeBSD: head/contrib/sendmail/mail.local/mail.local.c 110553 2003-02-08 19:25:21Z gshapiro $
11 * $FreeBSD: head/contrib/sendmail/mail.local/mail.local.c 110563 2003-02-08 20:35:51Z gshapiro $
12 *
13 */
14
15#include <sm/gen.h>
16
17SM_IDSTR(copyright,
18"@(#) Copyright (c) 1998-2001 Sendmail, Inc. and its suppliers.\n\
19 All rights reserved.\n\
20 Copyright (c) 1990, 1993, 1994\n\
21 The Regents of the University of California. All rights reserved.\n")
22
12 *
13 */
14
15#include <sm/gen.h>
16
17SM_IDSTR(copyright,
18"@(#) Copyright (c) 1998-2001 Sendmail, Inc. and its suppliers.\n\
19 All rights reserved.\n\
20 Copyright (c) 1990, 1993, 1994\n\
21 The Regents of the University of California. All rights reserved.\n")
22
23SM_IDSTR(id, "@(#)$Id: mail.local.c,v 8.239 2002/05/24 20:56:32 gshapiro Exp $")
23SM_IDSTR(id, "@(#)$Id: mail.local.c,v 8.239.2.2 2002/09/24 02:09:09 ca Exp $")
24
25#include <stdlib.h>
26#include <sm/errstring.h>
27#include <sm/io.h>
28#include <sm/limits.h>
29# include <unistd.h>
30# ifdef EX_OK
31# undef EX_OK /* unistd.h may have another use for this */

--- 633 unchanged lines hidden (view full) ---

665
666 if (inbody != NULL)
667 *inbody = false;
668
669 (void) umask(0077);
670 (void) sm_strlcpy(tmpbuf, _PATH_LOCTMP, sizeof tmpbuf);
671 if ((fd = mkstemp(tmpbuf)) < 0 || (fp = fdopen(fd, "w+")) == NULL)
672 {
24
25#include <stdlib.h>
26#include <sm/errstring.h>
27#include <sm/io.h>
28#include <sm/limits.h>
29# include <unistd.h>
30# ifdef EX_OK
31# undef EX_OK /* unistd.h may have another use for this */

--- 633 unchanged lines hidden (view full) ---

665
666 if (inbody != NULL)
667 *inbody = false;
668
669 (void) umask(0077);
670 (void) sm_strlcpy(tmpbuf, _PATH_LOCTMP, sizeof tmpbuf);
671 if ((fd = mkstemp(tmpbuf)) < 0 || (fp = fdopen(fd, "w+")) == NULL)
672 {
673 if (fd >= 0)
674 (void) close(fd);
673 mailerr("451 4.3.0", "Unable to open temporary file");
674 return -1;
675 }
676 (void) unlink(tmpbuf);
677
678 if (LMTPMode)
679 {
680 printf("354 Go ahead\r\n");

--- 531 unchanged lines hidden (view full) ---

1212 if (!nofsync && fsync(mbfd) < 0)
1213 {
1214 mailerr("450 4.2.0", "%s: %s", path, sm_errstring(errno));
1215err3:
1216 (void) setreuid(0, 0);
1217#ifdef DEBUG
1218 fprintf(stderr, "reset euid = %d\n", (int) geteuid());
1219#endif /* DEBUG */
675 mailerr("451 4.3.0", "Unable to open temporary file");
676 return -1;
677 }
678 (void) unlink(tmpbuf);
679
680 if (LMTPMode)
681 {
682 printf("354 Go ahead\r\n");

--- 531 unchanged lines hidden (view full) ---

1214 if (!nofsync && fsync(mbfd) < 0)
1215 {
1216 mailerr("450 4.2.0", "%s: %s", path, sm_errstring(errno));
1217err3:
1218 (void) setreuid(0, 0);
1219#ifdef DEBUG
1220 fprintf(stderr, "reset euid = %d\n", (int) geteuid());
1221#endif /* DEBUG */
1220 (void) ftruncate(mbfd, curoff);
1222 if (mbfd >= 0)
1223 (void) ftruncate(mbfd, curoff);
1221err1: if (mbfd >= 0)
1222 (void) close(mbfd);
1223err0: unlockmbox();
1224 return;
1225 }
1226
1227 /* Close and check -- NFS doesn't write until the close. */
1228 if (close(mbfd))
1229 {
1230 errcode = "450 4.2.0";
1231#ifdef EDQUOT
1232 if (errno == EDQUOT && BounceQuota)
1233 errcode = "552 5.2.2";
1234#endif /* EDQUOT */
1235 mailerr(errcode, "%s: %s", path, sm_errstring(errno));
1224err1: if (mbfd >= 0)
1225 (void) close(mbfd);
1226err0: unlockmbox();
1227 return;
1228 }
1229
1230 /* Close and check -- NFS doesn't write until the close. */
1231 if (close(mbfd))
1232 {
1233 errcode = "450 4.2.0";
1234#ifdef EDQUOT
1235 if (errno == EDQUOT && BounceQuota)
1236 errcode = "552 5.2.2";
1237#endif /* EDQUOT */
1238 mailerr(errcode, "%s: %s", path, sm_errstring(errno));
1236 (void) truncate(path, curoff);
1239 mbfd = open(path, O_WRONLY|EXTRA_MODE, 0);
1240 if (mbfd < 0
1241 || fstat(mbfd, &sb) < 0 ||
1242 sb.st_nlink != 1 ||
1243 !S_ISREG(sb.st_mode) ||
1244 sb.st_dev != fsb.st_dev ||
1245 sb.st_ino != fsb.st_ino ||
1246# if HAS_ST_GEN && 0 /* AFS returns random values for st_gen */
1247 sb.st_gen != fsb.st_gen ||
1248# endif /* HAS_ST_GEN && 0 */
1249 sb.st_uid != fsb.st_uid
1250 )
1251 {
1252 /* Don't use a bogus file */
1253 if (mbfd >= 0)
1254 {
1255 (void) close(mbfd);
1256 mbfd = -1;
1257 }
1258 }
1259
1260 /* Attempt to truncate back to pre-write size */
1261 goto err3;
1237 }
1238 else if (!nobiff)
1239 notifybiff(biffmsg);
1240
1241 if (setreuid(0, 0) < 0)
1242 {
1243 mailerr("450 4.2.0", "setreuid(0, 0): %s",
1244 sm_errstring(errno));

--- 455 unchanged lines hidden ---
1262 }
1263 else if (!nobiff)
1264 notifybiff(biffmsg);
1265
1266 if (setreuid(0, 0) < 0)
1267 {
1268 mailerr("450 4.2.0", "setreuid(0, 0): %s",
1269 sm_errstring(errno));

--- 455 unchanged lines hidden ---