Lines 1-98
Link Here
|
1 |
--- b.c.orig Fri Jan 20 00:38:25 1995 |
1 |
--- b.c.orig Wed Apr 11 17:10:49 2001 |
2 |
+++ b.c Sun Dec 3 09:58:21 2000 |
2 |
+++ b.c Sat Apr 21 23:11:38 2001 |
3 |
@@ -21,6 +21,9 @@ |
3 |
@@ -16,6 +16,9 @@ |
4 |
#include <pwd.h> |
4 |
#include <pwd.h> |
5 |
#endif |
5 |
#endif |
6 |
#include <errno.h> |
6 |
#include <errno.h> |
7 |
+#include <sys/file.h> |
7 |
+#include <sys/file.h> |
8 |
+#include <sys/types.h> |
8 |
+#include <sys/types.h> |
9 |
+#include <sys/stat.h> |
9 |
+#include <sys/stat.h> |
|
|
10 |
#include <stdlib.h> |
11 |
#include <ctype.h> |
12 |
#include <string.h> |
13 |
@@ -178,6 +181,7 @@ |
14 |
else |
15 |
b->o = pdefault; |
16 |
mset (b->marks, 0, sizeof (b->marks)); |
17 |
+ b->filehandle = -1; /* initialize filehandle &&& ob */ |
18 |
b->rdonly = 0; |
19 |
b->orphan = 0; |
20 |
b->oldcur = 0; |
21 |
@@ -229,6 +233,11 @@ |
22 |
void brm (B *b) { |
23 |
if (b && !--b->count) |
24 |
{ |
25 |
+ if (b->filehandle != -1) { |
26 |
+ /* close filehandle, free lock &&& ob */ |
27 |
+ close (b->filehandle); |
28 |
+ } |
29 |
+ |
30 |
if (b->changed) |
31 |
abrerr (b->name); |
32 |
if (b == errbuf) |
33 |
@@ -1867,7 +1876,8 @@ |
34 |
B *b; |
35 |
long skip, amnt; |
36 |
char *n; |
37 |
- int nowrite = 0; |
38 |
+ struct stat sb; |
39 |
+ int nowrite = 0, fh = -1; |
10 |
|
40 |
|
11 |
#include "config.h" |
41 |
if (!s || !s[0]) |
12 |
#include "blocks.h" |
42 |
{ |
13 |
@@ -201,6 +204,7 @@ |
43 |
@@ -1920,6 +1930,14 @@ |
14 |
if(prop) b->o=prop->o; |
44 |
goto opnerr; |
15 |
else b->o=pdefault; |
45 |
} |
16 |
mset(b->marks,0,sizeof(b->marks)); |
|
|
17 |
+ b->filehandle = -1; /* initialize filehandle &&& ob */ |
18 |
b->rdonly=0; |
19 |
b->orphan=0; |
20 |
b->oldcur=0; |
21 |
@@ -255,6 +259,10 @@ |
22 |
{ |
23 |
if(b && !--b->count) |
24 |
{ |
25 |
+ if (b->filehandle != -1) { |
26 |
+ /* close filehandle, free lock &&& ob */ |
27 |
+ close (b->filehandle); |
28 |
+ } |
29 |
if(b->changed) abrerr(b->name); |
30 |
if(b==errbuf) errbuf=0; |
31 |
if(b->undo) undorm(b->undo); |
32 |
@@ -1671,7 +1679,8 @@ |
33 |
B *b; |
34 |
long skip,amnt; |
35 |
char *n; |
36 |
- int nowrite=0; |
37 |
+ struct stat sb; |
38 |
+ int nowrite=0,fh=-1; |
39 |
|
46 |
|
40 |
if(!s || !s[0]) |
47 |
+ /* Lock the file &&& ob,petef */ |
41 |
{ |
48 |
+ if (fi) |
42 |
@@ -1704,6 +1713,28 @@ |
49 |
+ { |
43 |
else fclose(fi); |
50 |
+ fh = dup( fileno(fi) ); |
44 |
fi=fopen(n,"r"); |
51 |
+ nowrite = (flock (fh, LOCK_EX | LOCK_NB)); |
45 |
if(!fi) nowrite=0; |
52 |
+ } |
46 |
+/*printf ("nowrite open=%i\n", nowrite); */ |
|
|
47 |
+ |
48 |
+ /* check file mod, if no write flags set, |
49 |
+ joe in read only mode. &&& ob */ |
50 |
+ |
51 |
+ if (!nowrite) { |
52 |
+ nowrite = (!stat (n, &sb)) && (!(sb.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH))); |
53 |
+ } |
54 |
+/*printf ("nowrite stat=%i\n", nowrite); */ |
55 |
+ |
53 |
+ |
56 |
+ /* lock the file if writable, or go into read only mode if |
|
|
57 |
+ already locked, */ |
58 |
+ |
59 |
+ if ((fi) && (!nowrite)) { |
60 |
+ fh = dup( fileno(fi) ); |
61 |
+ nowrite = (flock (fh, LOCK_EX | LOCK_NB)); |
62 |
+ } |
63 |
+/*printf ("nowrite flock=%i\n", nowrite); */ |
64 |
+ |
54 |
+ |
65 |
+/*nowrite = 1; */ /* for test purpose */ |
55 |
/* Skip data if we need to */ |
66 |
+/*printf ("nowrite=%i\n", nowrite); */ |
56 |
if (skip && lseek (fileno (fi), skip, 0) < 0) |
67 |
+ |
57 |
{ |
68 |
} |
58 |
@@ -1978,6 +1996,8 @@ |
69 |
joesep(n); |
59 |
vsrm (n); |
70 |
|
|
|
71 |
@@ -1761,6 +1792,7 @@ |
72 |
vsrm(n); |
73 |
|
60 |
|
74 |
b->er=error; |
61 |
b->er = error; |
75 |
+ if( fh != -1 ) b->filehandle = fh; |
62 |
+ if (fh != -1) |
76 |
return b; |
63 |
+ b->filehandle = fh; |
77 |
} |
64 |
return b; |
|
|
65 |
} |
78 |
|
66 |
|
79 |
@@ -1990,7 +2022,18 @@ |
|
|
80 |
{ |
81 |
long tim=time(0); |
82 |
B *b; |
83 |
- FILE *f=fopen("DEADJOE","a"); |
84 |
+ FILE *f; |
85 |
+ struct stat sb; |
86 |
+ if ((lstat("DEADJOE", &sb) == 0) && (((sb.st_mode & S_IFLNK) && (sb.st_uid != getuid())) || (sb.st_nlink > 1))) |
87 |
+ { |
88 |
+ printf("*** JOE was aborted "); |
89 |
+ if (sig) printf("by signal %d, cannot save DEADJOE due to unsafe symlink\n",sig); |
90 |
+ else printf("because the terminal closed, cannot save DEADJOE due to unsafe symlink\n"); |
91 |
+ if(sig) ttclsn(); |
92 |
+ _exit(1); |
93 |
+ } |
94 |
+ f=fopen("DEADJOE","a"); |
95 |
+ chmod("DEADJOE", S_IRUSR | S_IWUSR); |
96 |
fprintf(f,"\n*** Modified files in JOE when it aborted on %s",ctime(&tim)); |
97 |
if(sig) fprintf(f,"*** JOE was aborted by signal %d\n",sig); |
98 |
else fprintf(f,"*** JOE was aborted because the terminal closed\n"); |