summaryrefslogtreecommitdiff
blob: 5187c9cbcff1c12d1e015224d32bb4965f1aa275 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
diff -urN shadow-4.0.3.orig/lib/Makefile.am shadow-4.0.3/lib/Makefile.am
--- shadow-4.0.3.orig/lib/Makefile.am	2001-10-06 14:53:20.000000000 -0500
+++ shadow-4.0.3/lib/Makefile.am	2003-08-07 08:38:20.000000000 -0500
@@ -1,7 +1,7 @@
 
 AUTOMAKE_OPTIONS = 1.0 foreign
 
-DEFS = 
+DEFS = -DWITH_SELINUX
 INCLUDES = -I$(top_srcdir)
 
 lib_LTLIBRARIES = libshadow.la
diff -urN shadow-4.0.3.orig/lib/commonio.c shadow-4.0.3/lib/commonio.c
--- shadow-4.0.3.orig/lib/commonio.c	2001-11-17 07:15:52.000000000 -0600
+++ shadow-4.0.3/lib/commonio.c	2003-08-07 08:38:20.000000000 -0500
@@ -15,7 +15,10 @@
 #ifdef HAVE_SHADOW_H
 #include <shadow.h>
 #endif
-
+#ifdef WITH_SELINUX
+#include <selinux/selinux.h>
+static security_context_t old_context=NULL;
+#endif
 #include "commonio.h"
 
 /* local function prototypes */
@@ -437,6 +440,15 @@
 		return 0;
 	}
 
+#ifdef WITH_SELINUX
+	db->scontext=NULL;
+	if (is_selinux_enabled() &&  (! db->readonly)) {
+	  if (fgetfilecon(fileno(db->fp),&db->scontext) < 0) {
+		goto cleanup;
+	  }
+	}
+#endif
+
 	buflen = BUFLEN;
 	buf = (char *) malloc(buflen);
 	if (!buf)
@@ -492,6 +504,12 @@
 	free(buf);
 cleanup:
 	free_linked_list(db);
+#ifdef WITH_SELINUX
+	if (db->scontext!= NULL) {
+	  freecon(db->scontext);
+	  db->scontext=NULL;
+	}
+#endif
 	fclose(db->fp);
 	db->fp = NULL;
 	errno = ENOMEM;
@@ -627,6 +645,19 @@
 			goto fail;
 		}
 
+#ifdef WITH_SELINUX
+		if (db->scontext != NULL) {
+		  int stat=getfscreatecon(&old_context);
+		  if (stat< 0) {
+		    errors++;
+		    goto fail;
+		  }
+		  if (setfscreatecon(db->scontext)<0) {
+		    errors++;
+		    goto fail;
+		  }
+		}
+#endif
 		/*
 		 * Create backup file.
 		 */
@@ -683,14 +714,26 @@
 		goto fail;
 
 	nscd_need_reload = 1;
-
+	goto success;
+fail:
+	errors++;
 success:
-	free_linked_list(db);
-	return 1;
 
-fail:
+#ifdef WITH_SELINUX
+	if (db->scontext != NULL) {
+	  if (setfscreatecon(old_context)<0) {
+	    errors++;
+	  }
+	  if (old_context != NULL) {		  
+	    freecon(old_context);
+	    old_context=NULL;
+	  }
+	  freecon(db->scontext);
+	  db->scontext=NULL;
+	}
+#endif
 	free_linked_list(db);
-	return 0;
+	return errors==0;
 }
 
 
diff -urN shadow-4.0.3.orig/lib/commonio.h shadow-4.0.3/lib/commonio.h
--- shadow-4.0.3.orig/lib/commonio.h	2001-08-14 16:09:54.000000000 -0500
+++ shadow-4.0.3/lib/commonio.h	2003-08-07 08:38:20.000000000 -0500
@@ -1,5 +1,8 @@
 /* $Id: shadow-4.0.3-selinux.diff,v 1.1 2003/10/29 03:14:07 pebenito Exp $ */
 
+#ifdef WITH_SELINUX
+#include <selinux/selinux.h>
+#endif
 /*
  * Linked list entry.
  */
@@ -70,6 +73,9 @@
 	 */
 	FILE *fp;
 
+#ifdef WITH_SELINUX
+        security_context_t scontext;
+#endif
 	/*
 	 * Head, tail, current position in linked list.
 	 */
diff -urN shadow-4.0.3.orig/src/Makefile.am shadow-4.0.3/src/Makefile.am
--- shadow-4.0.3.orig/src/Makefile.am	2002-03-10 01:12:52.000000000 -0600
+++ shadow-4.0.3/src/Makefile.am	2003-08-07 08:38:20.000000000 -0500
@@ -4,7 +4,7 @@
 ubindir = ${prefix}/bin
 usbindir = ${prefix}/sbin
 
-DEFS = -D_HAVE_CONFIG_H -DLOCALEDIR=\"$(datadir)/locale\"
+DEFS = -D_HAVE_CONFIG_H -DLOCALEDIR=\"$(datadir)/locale\" -DWITH_SELINUX
 
 INCLUDES = -I${top_srcdir} \
 	-I${top_srcdir}/lib \
@@ -35,7 +35,7 @@
 suidubins = chage chfn chsh expiry gpasswd newgrp passwd
 
 LDADD = $(top_builddir)/libmisc/libmisc.la \
-	$(top_builddir)/lib/libshadow.la
+	$(top_builddir)/lib/libshadow.la -lselinux
 
 chpasswd_LDADD = $(LDADD) $(LIBPAM)
 chage_LDADD    = $(LDADD) $(LIBPAM)
diff -urN shadow-4.0.3.orig/src/Makefile.in shadow-4.0.3/src/Makefile.in
--- shadow-4.0.3.orig/src/Makefile.in	2002-03-13 13:04:10.000000000 -0600
+++ shadow-4.0.3/src/Makefile.in	2003-08-07 08:45:13.000000000 -0500
@@ -145,7 +145,7 @@
 suidubins = chage chfn chsh expiry gpasswd newgrp passwd
 
 LDADD = $(top_builddir)/libmisc/libmisc.la \
-	$(top_builddir)/lib/libshadow.la
+	$(top_builddir)/lib/libshadow.la -lselinux
 
 
 chpasswd_LDADD = $(LDADD) $(LIBPAM)