16
16
#include <sepol/policydb.h>
17
17
#endif
18
18
#include <dlfcn.h>
19
+ #include "callbacks.h"
19
20
#include "policy.h"
20
21
#include <limits.h>
21
22
@@ -136,25 +137,25 @@ int selinux_mkload_policy(int preservebools __attribute__((unused)))
136
137
fd = open (path , O_RDONLY | O_CLOEXEC );
137
138
}
138
139
if (fd < 0 ) {
139
- fprintf ( stderr ,
140
- "SELinux: Could not open policy file <= %s.%d: %m\n" ,
141
- selinux_binary_policy_path (), maxvers );
140
+ selinux_log ( SELINUX_ERROR ,
141
+ "SELinux: Could not open policy file <= %s.%d: %m\n" ,
142
+ selinux_binary_policy_path (), maxvers );
142
143
goto dlclose ;
143
144
}
144
145
145
146
if (fstat (fd , & sb ) < 0 ) {
146
- fprintf ( stderr ,
147
- "SELinux: Could not stat policy file %s: %m\n" ,
148
- path );
147
+ selinux_log ( SELINUX_ERROR ,
148
+ "SELinux: Could not stat policy file %s: %m\n" ,
149
+ path );
149
150
goto close ;
150
151
}
151
152
152
153
size = sb .st_size ;
153
154
data = map = mmap (NULL , size , PROT_READ , MAP_PRIVATE , fd , 0 );
154
155
if (map == MAP_FAILED ) {
155
- fprintf ( stderr ,
156
- "SELinux: Could not map policy file %s: %m\n" ,
157
- path );
156
+ selinux_log ( SELINUX_ERROR ,
157
+ "SELinux: Could not map policy file %s: %m\n" ,
158
+ path );
158
159
goto close ;
159
160
}
160
161
@@ -175,9 +176,9 @@ int selinux_mkload_policy(int preservebools __attribute__((unused)))
175
176
if (policydb_set_vers (policydb , kernvers ) ||
176
177
policydb_to_image (NULL , policydb , & data , & size )) {
177
178
/* Downgrade failed, keep searching. */
178
- fprintf ( stderr ,
179
- "SELinux: Could not downgrade policy file %s, searching for an older version.\n" ,
180
- path );
179
+ selinux_log ( SELINUX_ERROR ,
180
+ "SELinux: Could not downgrade policy file %s, searching for an older version.\n" ,
181
+ path );
181
182
policy_file_free (pf );
182
183
policydb_free (policydb );
183
184
munmap (map , sb .st_size );
@@ -192,9 +193,9 @@ int selinux_mkload_policy(int preservebools __attribute__((unused)))
192
193
rc = security_load_policy (data , size );
193
194
194
195
if (rc )
195
- fprintf ( stderr ,
196
- "SELinux: Could not load policy file %s: %m\n" ,
197
- path );
196
+ selinux_log ( SELINUX_ERROR ,
197
+ "SELinux: Could not load policy file %s: %m\n" ,
198
+ path );
198
199
199
200
unmap :
200
201
if (data != map )
@@ -205,7 +206,7 @@ int selinux_mkload_policy(int preservebools __attribute__((unused)))
205
206
dlclose :
206
207
#ifdef SHARED
207
208
if (errormsg )
208
- fprintf ( stderr , "libselinux: %s\n" , errormsg );
209
+ selinux_log ( SELINUX_ERROR , "libselinux: %s\n" , errormsg );
209
210
if (libsepolh )
210
211
dlclose (libsepolh );
211
212
#endif
@@ -317,7 +318,7 @@ int selinux_init_load_policy(int *enforce)
317
318
* enforce = 0 ;
318
319
} else {
319
320
/* Only emit this error if selinux was not disabled */
320
- fprintf ( stderr , "Mount failed for selinuxfs on %s: %m\n" , SELINUXMNT );
321
+ selinux_log ( SELINUX_ERROR , "Mount failed for selinuxfs on %s: %m\n" , SELINUXMNT );
321
322
}
322
323
323
324
if (rc == 0 )
@@ -365,7 +366,7 @@ int selinux_init_load_policy(int *enforce)
365
366
if (orig_enforce != * enforce ) {
366
367
rc = security_setenforce (* enforce );
367
368
if (rc < 0 ) {
368
- fprintf ( stderr , "SELinux: Unable to switch to %s mode: %m\n" , (* enforce ? "enforcing" : "permissive" ));
369
+ selinux_log ( SELINUX_ERROR , "SELinux: Unable to switch to %s mode: %m\n" , (* enforce ? "enforcing" : "permissive" ));
369
370
if (* enforce )
370
371
goto noload ;
371
372
}
0 commit comments