~ubuntu-branches/ubuntu/vivid/nethack/vivid

« back to all changes in this revision

Viewing changes to debian/patches/02_SECURITY_recover_secure.dpatch

  • Committer: Bazaar Package Importer
  • Author(s): Joshua Kwan
  • Date: 2004-04-28 22:20:28 UTC
  • Revision ID: james.westby@ubuntu.com-20040428222028-ir8ahbbxi1jcot2d
Tags: 3.4.3-5
* Add Catalan translation (Closes: #248734)
* Patch work:
  - 91_enh_menucolors: Fix Pasi Kallinen's email address. pk -> pkalli
  - 19_gnome_ext_events (new): Fix a problem in Gnomehack where mouse click
    events in the extended menu would not be handled (thus a certain
    choice might be chosen, but a different one 'picked' by the code).
    (Closes: #246265)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh -e
 
2
## 02_SECURITY_recover_secure.dpatch by Joshua Kwan <joshk@triplehelix.org>
 
3
##
 
4
## All lines beginning with `## DP:' are a description of the patch.
 
5
## DP: Make sure the user calling recover owns the file.
 
6
 
 
7
if [ $# -ne 1 ]; then
 
8
    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
 
9
    exit 1
 
10
fi
 
11
case "$1" in
 
12
    -patch) patch -f --no-backup-if-mismatch -p1 < $0;;
 
13
    -unpatch) patch -f --no-backup-if-mismatch -R -p1 < $0;;
 
14
    *)
 
15
        echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
 
16
        exit 1;;
 
17
esac
 
18
 
 
19
exit 0
 
20
 
 
21
--- nethack-3.4.1.orig/util/recover.c
 
22
+++ nethack-3.4.1/util/recover.c
 
23
@@ -16,6 +16,12 @@
 
24
 #include "win32api.h"
 
25
 #endif
 
26
 
 
27
+#ifdef SECURE
 
28
+#include <sys/types.h>
 
29
+#include <sys/stat.h>
 
30
+#include <unistd.h>
 
31
+#endif
 
32
+
 
33
 #ifdef VMS
 
34
 extern int FDECL(vms_creat, (const char *,unsigned));
 
35
 extern int FDECL(vms_open, (const char *,int,unsigned));
 
36
@@ -107,15 +113,23 @@
 
37
        }
 
38
 #if defined(SECURE) && !defined(VMS)
 
39
        if (dir
 
40
-# ifdef HACKDIR
 
41
+# ifdef VAR_PLAYGROUND
 
42
+               && strcmp(dir, VAR_PLAYGROUND)
 
43
+# else
 
44
+#  ifdef HACKDIR
 
45
                && strcmp(dir, HACKDIR)
 
46
-# endif
 
47
+#  endif 
 
48
+# endif /* VAR_PLAYGROUND */
 
49
                ) {
 
50
                (void) setgid(getgid());
 
51
                (void) setuid(getuid());
 
52
        }
 
53
 #endif /* SECURE && !VMS */
 
54
 
 
55
+#ifdef VAR_PLAYGROUND
 
56
+       if (!dir) dir = VAR_PLAYGROUND;
 
57
+#endif
 
58
+
 
59
 #ifdef HACKDIR
 
60
        if (!dir) dir = HACKDIR;
 
61
 #endif
 
62
@@ -158,11 +172,19 @@
 
63
 #endif
 
64
 }
 
65
 
 
66
+#ifdef SECURE
 
67
+static uid_t save_uid = -1;
 
68
+#endif
 
69
+
 
70
 int
 
71
 open_levelfile(lev)
 
72
 int lev;
 
73
 {
 
74
        int fd;
 
75
+#ifdef SECURE
 
76
+       struct stat level_stat;
 
77
+       uid_t uid;
 
78
+#endif
 
79
 
 
80
        set_levelfile_name(lev);
 
81
 #if defined(MICRO) || defined(WIN32) || defined(MSDOS)
 
82
@@ -170,6 +192,21 @@
 
83
 #else
 
84
        fd = open(lock, O_RDONLY, 0);
 
85
 #endif
 
86
+       /* Security check: does the user calling recover own the file? */
 
87
+#ifdef SECURE
 
88
+       if (fd != -1) {
 
89
+               uid = getuid();
 
90
+               if (fstat(fd, &level_stat) == -1) {
 
91
+                       Fprintf(stderr, "No permission to stat level file %s.\n", lock);
 
92
+                       return -1;
 
93
+               }
 
94
+               if (uid != 0 && level_stat.st_uid != uid) {
 
95
+                       Fprintf(stderr, "You are not the owner of level file %s.\n", lock);
 
96
+                       return -1;
 
97
+               }
 
98
+               save_uid = level_stat.st_uid;
 
99
+       }
 
100
+#endif
 
101
        return fd;
 
102
 }
 
103
 
 
104
@@ -183,6 +220,13 @@
 
105
 #else
 
106
        fd = creat(savename, FCMASK);
 
107
 #endif
 
108
+
 
109
+#ifdef SECURE
 
110
+       if (fchown(fd, save_uid, -1) == -1) {
 
111
+               Fprintf(stderr, "could not chown %s to %i!\n", savename, 
 
112
+                       save_uid);
 
113
+       }
 
114
+#endif
 
115
        return fd;
 
116
 }
 
117