summaryrefslogtreecommitdiff
path: root/security/tripwire/patches/patch-af
blob: c6fbc789b9c3f34384b23207636f95717a7640a7 (plain)
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
$NetBSD: patch-af,v 1.2 2003/12/09 19:17:37 ben Exp $

--- src/dbase.build.c.orig	1994-07-25 08:24:09.000000000 -0700
+++ src/dbase.build.c
@@ -66,7 +66,6 @@ static char rcsid[] = "$Id: dbase.build.
 int files_scanned_num = 0;
 
 /* prototypes */
-char *mktemp();
 static void database_record_write();
 
 char backupfile[MAXPATHLEN+256];
@@ -92,6 +91,7 @@ database_build (pp_list, mode, pp_entry_
 {
     struct list_elem *p_fileentry;
     struct list_elem *p_configentry;
+    int fdw;
     FILE *fpw;
     char database[MAXPATHLEN+256];
     int entrynum,
@@ -130,11 +130,12 @@ database_build (pp_list, mode, pp_entry_
 	    die_with_err("malloc() failed in database_build", (char *) NULL);
 	(void) strcpy(tmpfilename, TEMPFILE_TEMPLATE);
 
-	if ((char *) mktemp(tmpfilename) == NULL)
-	    die_with_err("database_build: mktemp()", (char *) NULL);
+	fdw = mkstemp(tmpfilename);
+	if (fdw == -1)
+	    die_with_err("database_build: mkstemp()", (char *) NULL);
+	unlink(tmpfilename);
 
-	(void) strcpy(tempdatabase_file, tmpfilename);
-	(void) strcpy(database, tempdatabase_file);
+	(void) strcpy(database, tmpfilename);
 	free(tmpfilename);
     }					/* end if temporary database */
     else if (mode == DBASE_UPDATE) {
@@ -224,6 +225,11 @@ printf("database_build(): ---> olddataba
     }
 
     /* rebuild the database */
+    if (mode == DBASE_TEMPORARY) {
+	fpw = fdopen(fdw, "w+");
+	if (fpw == NULL)
+		die_with_err("call fdopen() failed.", NULL);
+    } else
     if ((fpw = fopen(database, "w")) == NULL)
 	die_with_err("Hint: Maybe the database directory '%s' doesn't exist?  fopen()", database);
 
@@ -367,10 +373,10 @@ printf("--(contents)-->%s\n", entry); 
 	  die_with_err("database_build: list_close() failed!\n", (char *) NULL);
     }
 
-    /* we don't want to allow anyone to spoof the temporary file in /tmp */
+    /* If the database was temporary, the file was unlink()ed, and is
+	"hidden" from other processes. */
     if (mode == DBASE_TEMPORARY) {
-	if ((fptempdbase = freopen(database, "r", fpw)) == NULL)
-	    die_with_err("temporary database file disappeared?!?", database);
+	fptempdbase = fpw;
 	rewind(fptempdbase);
     } else {
 	fclose(fpw);
@@ -413,7 +419,7 @@ database_record_write (fpw, filename, fl
     /* filename, entrynum, ignore, mode, inode, nlinks, uid, gid, size,
      *		access, modify, ctime, {sig0, sig1, ..., sig9}
      */
-    static char *format = "%s %ld %s %lo %ld %ld %ld %ld %ld %s %s %s %s\n";
+    static char *format = "%s %d %s %o %u %u %u %u %lld %s %s %s %s\n";
 
     /* initialize our temporary file */
     if (fdsymlink == -1) {
@@ -541,7 +547,7 @@ SKIPPED_SIGS:
 	fprintf(fpw, format, filename_escape(filename), (int32)entrynum, ignorevec,
 	    (int32)statbuf->st_mode, (int32)statbuf->st_ino,
 	    (int32)statbuf->st_nlink, (int32)statbuf->st_uid,
-	    (int32)statbuf->st_gid, (int32)statbuf->st_size,
+	    (int32)statbuf->st_gid, (long long)statbuf->st_size,
 	    pltob64((uint32 *) &va, (char *) vec64_a, 1),
 	    pltob64((uint32 *) &vm, (char *) vec64_m, 1),
 	    pltob64((uint32 *) &vc, (char *) vec64_c, 1),