File: lock-mail-local.patch

package info (click to toggle)
sendmail 8.18.1-8
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 12,496 kB
  • sloc: ansic: 105,736; perl: 7,504; sh: 5,488; makefile: 889
file content (92 lines) | stat: -rw-r--r-- 1,986 bytes parent folder | download | duplicates (5)
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
Description: Fix order of fcntl and dotlock in mail.local
Author: Tim Marston <tim@ed.am>
Bug-Debian: http://bugs.debian.org/684645
--- a/mail.local/mail.local.c
+++ b/mail.local/mail.local.c
@@ -1105,26 +1105,6 @@ deliver(fd, name)
 	*/
 
 tryagain:
-#ifdef MAILLOCK
-	p = name;
-#else
-	p = path;
-#endif
-	if ((off = lockmbox(p)) != 0)
-	{
-		if (off == EX_TEMPFAIL || e_to_sys(off) == EX_TEMPFAIL)
-		{
-			ExitVal = EX_TEMPFAIL;
-			errcode = "451 4.3.0";
-		}
-		else
-			errcode = "551 5.3.0";
-
-		mailerr(errcode, "lockmailbox %s failed; error code %d %s",
-			p, off, errno > 0 ? sm_errstring(errno) : "");
-		return;
-	}
-
 	if (lstat(path, &sb) < 0)
 	{
 		int save_errno;
@@ -1279,6 +1259,26 @@ tryagain:
 		goto err1;
 	}
 
+#ifdef MAILLOCK
+	p = name;
+#else /* MAILLOCK */
+	p = path;
+#endif /* MAILLOCK */
+	if ((off = lockmbox(p)) != 0)
+	{
+		if (off == EX_TEMPFAIL || e_to_sys(off) == EX_TEMPFAIL)
+		{
+			ExitVal = EX_TEMPFAIL;
+			errcode = "451 4.3.0";
+		}
+		else
+			errcode = "551 5.3.0";
+
+		mailerr(errcode, "lockmailbox %s failed; error code %d %s",
+			p, off, errno > 0 ? sm_errstring(errno) : "");
+		goto err1;
+	}
+
 	/* Get the starting offset of the new message */
 	curoff = lseek(mbfd, (off_t) 0, SEEK_END);
 	(void) sm_snprintf(biffmsg, sizeof(biffmsg), "%s@%lld\n",
@@ -1352,14 +1352,14 @@ err3:
 #endif
 		if (mbfd >= 0)
 			(void) ftruncate(mbfd, curoff);
-err1:		if (mbfd >= 0)
+err1:		unlockmbox();
+		if (mbfd >= 0)
 			(void) close(mbfd);
 err0:
 #if MAIL_LOCAL_TEST
 		if (HomeMailFile == NULL || user.mbdb_uid != getuid())
 #endif
 		(void) setreuid(0, 0);
-		unlockmbox();
 		return;
 	}
 
@@ -1377,6 +1377,7 @@ err0:
 	else
 		cursize = sb.st_size;
 
+	unlockmbox();
 
 	/* Close and check -- NFS doesn't write until the close. */
 	if (close(mbfd))
@@ -1430,7 +1431,6 @@ err0:
 #ifdef DEBUG
 	fprintf(stderr, "reset euid = %d\n", (int) geteuid());
 #endif
-	unlockmbox();
 	if (LMTPMode)
 		printf("250 2.1.5 %s Ok\r\n", name);
 }