2004-10-18 Colin Walters <walters@verbum.org>
[platform/upstream/dbus.git] / bus / selinux.c
1 /* selinux.c  SELinux security checks for D-BUS
2  *
3  * Author: Matthew Rickard <mjricka@epoch.ncsc.mil>
4  *
5  * Licensed under the Academic Free License version 2.1
6  * 
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  */
22 #include <dbus/dbus-internals.h>
23 #include <dbus/dbus-string.h>
24 #include "selinux.h"
25 #include "services.h"
26 #include "policy.h"
27 #include "utils.h"
28 #include "config-parser.h"
29
30 #ifdef HAVE_SELINUX
31 #include <errno.h>
32 #include <pthread.h>
33 #include <syslog.h>
34 #include <selinux/selinux.h>
35 #include <selinux/avc.h>
36 #include <selinux/av_permissions.h>
37 #include <selinux/flask.h>
38 #include <signal.h>
39 #include <stdarg.h>
40 #endif /* HAVE_SELINUX */
41
42 #define BUS_SID_FROM_SELINUX(sid)  ((BusSELinuxID*) (sid))
43 #define SELINUX_SID_FROM_BUS(sid)  ((security_id_t) (sid))
44
45 #ifdef HAVE_SELINUX
46 /* Store the value telling us if SELinux is enabled in the kernel. */
47 static dbus_bool_t selinux_enabled = FALSE;
48
49 /* Store an avc_entry_ref to speed AVC decisions. */
50 static struct avc_entry_ref aeref;
51
52 /* Store the SID of the bus itself to use as the default. */
53 static security_id_t bus_sid = SECSID_WILD;
54
55 /* Thread to listen for SELinux status changes via netlink. */
56 static pthread_t avc_notify_thread;
57
58 /* Prototypes for AVC callback functions.  */
59 static void log_callback (const char *fmt, ...);
60 static void *avc_create_thread (void (*run) (void));
61 static void avc_stop_thread (void *thread);
62 static void *avc_alloc_lock (void);
63 static void avc_get_lock (void *lock);
64 static void avc_release_lock (void *lock);
65 static void avc_free_lock (void *lock);
66
67 /* AVC callback structures for use in avc_init.  */
68 static const struct avc_memory_callback mem_cb =
69 {
70   .func_malloc = dbus_malloc,
71   .func_free = dbus_free
72 };
73 static const struct avc_log_callback log_cb =
74 {
75   .func_log = log_callback,
76   .func_audit = NULL
77 };
78 static const struct avc_thread_callback thread_cb =
79 {
80   .func_create_thread = avc_create_thread,
81   .func_stop_thread = avc_stop_thread
82 };
83 static const struct avc_lock_callback lock_cb =
84 {
85   .func_alloc_lock = avc_alloc_lock,
86   .func_get_lock = avc_get_lock,
87   .func_release_lock = avc_release_lock,
88   .func_free_lock = avc_free_lock
89 };
90 #endif /* HAVE_SELINUX */
91
92 /**
93  * Log callback to log denial messages from the AVC.
94  * This is used in avc_init.  Logs to both standard
95  * error and syslogd.
96  *
97  * @param fmt the format string
98  * @param variable argument list
99  */
100 #ifdef HAVE_SELINUX
101 static void 
102 log_callback (const char *fmt, ...) 
103 {
104   va_list ap;
105   va_start(ap, fmt);
106   vsyslog (LOG_INFO, fmt, ap);
107   va_end(ap);
108 }
109
110 /**
111  * On a policy reload we need to reparse the SELinux configuration file, since
112  * this could have changed.  Send a SIGHUP to reload all configs.
113  */
114 static int
115 policy_reload_callback (u_int32_t event, security_id_t ssid, 
116                         security_id_t tsid, security_class_t tclass, 
117                         access_vector_t perms, access_vector_t *out_retained)
118 {
119   if (event == AVC_CALLBACK_RESET)
120     return raise (SIGHUP);
121   
122   return 0;
123 }
124
125 /**
126  * Create thread to notify the AVC of enforcing and policy reload
127  * changes via netlink.
128  *
129  * @param run the thread run function
130  * @return pointer to the thread
131  */
132 static void *
133 avc_create_thread (void (*run) (void))
134 {
135   int rc;
136
137   rc = pthread_create (&avc_notify_thread, NULL, (void *(*) (void *)) run, NULL);
138   if (rc != 0)
139     {
140       _dbus_warn ("Failed to start AVC thread: %s\n", _dbus_strerror (rc));
141       exit (1);
142     }
143   return &avc_notify_thread;
144 }
145
146 /* Stop AVC netlink thread.  */
147 static void
148 avc_stop_thread (void *thread)
149 {
150   pthread_cancel (*(pthread_t *) thread);
151 }
152
153 /* Allocate a new AVC lock.  */
154 static void *
155 avc_alloc_lock (void)
156 {
157   pthread_mutex_t *avc_mutex;
158
159   avc_mutex = dbus_new (pthread_mutex_t, 1);
160   if (avc_mutex == NULL)
161     {
162       _dbus_warn ("Could not create mutex: %s\n", _dbus_strerror (errno));
163       exit (1);
164     }
165   pthread_mutex_init (avc_mutex, NULL);
166
167   return avc_mutex;
168 }
169
170 /* Acquire an AVC lock.  */
171 static void
172 avc_get_lock (void *lock)
173 {
174   pthread_mutex_lock (lock);
175 }
176
177 /* Release an AVC lock.  */
178 static void
179 avc_release_lock (void *lock)
180 {
181   pthread_mutex_unlock (lock);
182 }
183
184 /* Free an AVC lock.  */
185 static void
186 avc_free_lock (void *lock)
187 {
188   pthread_mutex_destroy (lock);
189   dbus_free (lock);
190 }
191 #endif /* HAVE_SELINUX */
192
193 /**
194  * Return whether or not SELinux is enabled; must be
195  * called after bus_selinux_init.
196  */
197 dbus_bool_t
198 bus_selinux_enabled (void)
199 {
200   return selinux_enabled;
201 }
202
203 /**
204  * Initialize the user space access vector cache (AVC) for D-BUS and set up
205  * logging callbacks.
206  */
207 dbus_bool_t
208 bus_selinux_init (void)
209 {
210 #ifdef HAVE_SELINUX
211   int r;
212   char *bus_context;
213
214   _dbus_assert (bus_sid == SECSID_WILD);
215   
216   /* Determine if we are running an SELinux kernel. */
217   r = is_selinux_enabled ();
218   if (r < 0)
219     {
220       _dbus_warn ("Could not tell if SELinux is enabled: %s\n",
221                   _dbus_strerror (errno));
222       return FALSE;
223     }
224
225   selinux_enabled = r != 0;
226
227   if (!selinux_enabled)
228     {
229       _dbus_verbose ("SELinux not enabled in this kernel.\n");
230       return TRUE;
231     }
232
233   _dbus_verbose ("SELinux is enabled in this kernel.\n");
234
235   avc_entry_ref_init (&aeref);
236   if (avc_init ("avc", &mem_cb, &log_cb, &thread_cb, &lock_cb) < 0)
237     {
238       _dbus_warn ("Failed to start Access Vector Cache (AVC).\n");
239       return FALSE;
240     }
241   else
242     {
243       openlog ("dbus", LOG_PERROR, LOG_USER);
244       _dbus_verbose ("Access Vector Cache (AVC) started.\n");
245     }
246
247   if (avc_add_callback (policy_reload_callback, AVC_CALLBACK_RESET,
248                        NULL, NULL, 0, 0) < 0)
249     {
250       _dbus_warn ("Failed to add policy reload callback: %s\n",
251                   _dbus_strerror (errno));
252       avc_destroy ();
253       return FALSE;
254     }
255
256   bus_context = NULL;
257   bus_sid = SECSID_WILD;
258
259   if (getcon (&bus_context) < 0)
260     {
261       _dbus_verbose ("Error getting context of bus: %s\n",
262                      _dbus_strerror (errno));
263       return FALSE;
264     }
265       
266   if (avc_context_to_sid (bus_context, &bus_sid) < 0)
267     {
268       _dbus_verbose ("Error getting SID from bus context: %s\n",
269                      _dbus_strerror (errno));
270       freecon (bus_context);
271       return FALSE;
272     }
273
274   freecon (bus_context);
275   
276   return TRUE;
277 #else
278   return TRUE;
279 #endif /* HAVE_SELINUX */
280 }
281
282 /**
283  * Decrement SID reference count.
284  * 
285  * @param sid the SID to decrement
286  */
287 void
288 bus_selinux_id_unref (BusSELinuxID *sid)
289 {
290 #ifdef HAVE_SELINUX
291   if (!selinux_enabled)
292     return;
293
294   _dbus_assert (sid != NULL);
295   
296   sidput (SELINUX_SID_FROM_BUS (sid));
297 #endif /* HAVE_SELINUX */
298 }
299
300 void
301 bus_selinux_id_ref (BusSELinuxID *sid)
302 {
303 #ifdef HAVE_SELINUX
304   if (!selinux_enabled)
305     return;
306
307   _dbus_assert (sid != NULL);
308   
309   sidget (SELINUX_SID_FROM_BUS (sid));
310 #endif /* HAVE_SELINUX */
311 }
312
313 /**
314  * Determine if the SELinux security policy allows the given sender
315  * security context to go to the given recipient security context.
316  * This function determines if the requested permissions are to be
317  * granted from the connection to the message bus or to another
318  * optionally supplied security identifier (e.g. for a service
319  * context).  Currently these permissions are either send_msg or
320  * acquire_svc in the dbus class.
321  *
322  * @param sender_sid source security context
323  * @param override_sid is the target security context.  If SECSID_WILD this will
324  *        use the context of the bus itself (e.g. the default).
325  * @param target_class is the target security class.
326  * @param requested is the requested permissions.
327  * @returns #TRUE if security policy allows the send.
328  */
329 #ifdef HAVE_SELINUX
330 static dbus_bool_t
331 bus_selinux_check (BusSELinuxID        *sender_sid,
332                    BusSELinuxID        *override_sid,
333                    security_class_t     target_class,
334                    access_vector_t      requested)
335 {
336   if (!selinux_enabled)
337     return TRUE;
338
339   /* Make the security check.  AVC checks enforcing mode here as well. */
340   if (avc_has_perm (SELINUX_SID_FROM_BUS (sender_sid),
341                     override_sid ?
342                     SELINUX_SID_FROM_BUS (override_sid) :
343                     SELINUX_SID_FROM_BUS (bus_sid), 
344                     target_class, requested, &aeref, NULL) < 0)
345     {
346       _dbus_verbose ("SELinux denying due to security policy.\n");
347       return FALSE;
348     }
349   else
350     return TRUE;
351 }
352 #endif /* HAVE_SELINUX */
353
354 /**
355  * Returns true if the given connection can acquire a service,
356  * assuming the given security ID is needed for that service.
357  *
358  * @param connection connection that wants to own the service
359  * @param service_sid the SID of the service from the table
360  * @returns #TRUE if acquire is permitted.
361  */
362 dbus_bool_t
363 bus_selinux_allows_acquire_service (DBusConnection     *connection,
364                                     BusSELinuxID       *service_sid)
365 {
366 #ifdef HAVE_SELINUX
367   BusSELinuxID *connection_sid;
368   
369   if (!selinux_enabled)
370     return TRUE;
371
372   connection_sid = bus_connection_get_selinux_id (connection);
373   
374   return bus_selinux_check (connection_sid,
375                             service_sid,
376                             SECCLASS_DBUS,
377                             DBUS__ACQUIRE_SVC);
378 #else
379   return TRUE;
380 #endif /* HAVE_SELINUX */
381 }
382
383 /**
384  * Check if SELinux security controls allow the message to be sent to a
385  * particular connection based on the security context of the sender and
386  * that of the receiver. The destination connection need not be the
387  * addressed recipient, it could be an "eavesdropper"
388  *
389  * @param sender the sender of the message.
390  * @param proposed_recipient the connection the message is to be sent to.
391  * @returns whether to allow the send
392  */
393 dbus_bool_t
394 bus_selinux_allows_send (DBusConnection     *sender,
395                          DBusConnection     *proposed_recipient)
396 {
397 #ifdef HAVE_SELINUX
398   BusSELinuxID *recipient_sid;
399   BusSELinuxID *sender_sid;
400
401   if (!selinux_enabled)
402     return TRUE;
403
404   sender_sid = bus_connection_get_selinux_id (sender);
405   /* A NULL proposed_recipient means the bus itself. */
406   if (proposed_recipient)
407     recipient_sid = bus_connection_get_selinux_id (proposed_recipient);
408   else
409     recipient_sid = BUS_SID_FROM_SELINUX (bus_sid);
410
411   return bus_selinux_check (sender_sid, recipient_sid,
412                             SECCLASS_DBUS, DBUS__SEND_MSG);
413 #else
414   return TRUE;
415 #endif /* HAVE_SELINUX */
416 }
417
418 /**
419  * Gets the security context of a connection to the bus. It is up to
420  * the caller to freecon() when they are done. 
421  *
422  * @param connection the connection to get the context of.
423  * @param con the location to store the security context.
424  * @returns #TRUE if context is successfully obtained.
425  */
426 #ifdef HAVE_SELINUX
427 static dbus_bool_t
428 bus_connection_read_selinux_context (DBusConnection     *connection,
429                                      char              **con)
430 {
431   int fd;
432
433   if (!selinux_enabled)
434     return FALSE;
435
436   _dbus_assert (connection != NULL);
437   
438   if (!dbus_connection_get_unix_fd (connection, &fd))
439     {
440       _dbus_verbose ("Failed to get file descriptor of socket.\n");
441       return FALSE;
442     }
443   
444   if (getpeercon (fd, con) < 0)
445     {
446       _dbus_verbose ("Error getting context of socket peer: %s\n",
447                      _dbus_strerror (errno));
448       return FALSE;
449     }
450   
451   _dbus_verbose ("Successfully read connection context.\n");
452   return TRUE;
453 }
454 #endif /* HAVE_SELINUX */
455
456 /**
457  * Read the SELinux ID from the connection.
458  *
459  * @param connection the connection to read from
460  * @returns the SID if successfully determined, #NULL otherwise.
461  */
462 BusSELinuxID*
463 bus_selinux_init_connection_id (DBusConnection *connection,
464                                 DBusError      *error)
465 {
466 #ifdef HAVE_SELINUX
467   char *con;
468   security_id_t sid;
469   
470   if (!selinux_enabled)
471     return NULL;
472
473   if (!bus_connection_read_selinux_context (connection, &con))
474     {
475       dbus_set_error (error, DBUS_ERROR_FAILED,
476                       "Failed to read an SELinux context from connection");
477       _dbus_verbose ("Error getting peer context.\n");
478       return NULL;
479     }
480
481   _dbus_verbose ("Converting context to SID to store on connection\n");
482
483   if (avc_context_to_sid (con, &sid) < 0)
484     {
485       if (errno == ENOMEM)
486         BUS_SET_OOM (error);
487       else
488         dbus_set_error (error, DBUS_ERROR_FAILED,
489                         "Error getting SID from context: %s\n",
490                         _dbus_strerror (errno));
491       
492       _dbus_warn ("Error getting SID from context: %s\n",
493                   _dbus_strerror (errno));
494       
495       freecon (con);
496       return NULL;
497     }
498  
499   freecon (con); 
500   return BUS_SID_FROM_SELINUX (sid);
501 #else
502   return NULL;
503 #endif /* HAVE_SELINUX */
504 }
505
506
507 /**
508  * Function for freeing hash table data.  These SIDs
509  * should no longer be referenced.
510  */
511 static void
512 bus_selinux_id_table_free_value (BusSELinuxID *sid)
513 {
514 #ifdef HAVE_SELINUX
515   /* NULL sometimes due to how DBusHashTable works */
516   if (sid)
517     bus_selinux_id_unref (sid);
518 #endif /* HAVE_SELINUX */
519 }
520
521 /**
522  * Creates a new table mapping service names to security ID.
523  * A security ID is a "compiled" security context, a security
524  * context is just a string.
525  *
526  * @returns the new table or #NULL if no memory
527  */
528 DBusHashTable*
529 bus_selinux_id_table_new (void)
530 {
531   return _dbus_hash_table_new (DBUS_HASH_STRING,
532                                (DBusFreeFunction) dbus_free,
533                                (DBusFreeFunction) bus_selinux_id_table_free_value);
534 }
535
536 /** 
537  * Hashes a service name and service context into the service SID
538  * table as a string and a SID.
539  *
540  * @param service_name is the name of the service.
541  * @param service_context is the context of the service.
542  * @param service_table is the table to hash them into.
543  * @return #FALSE if not enough memory
544  */
545 dbus_bool_t
546 bus_selinux_id_table_insert (DBusHashTable *service_table,
547                              const char    *service_name,
548                              const char    *service_context)
549 {
550 #ifdef HAVE_SELINUX
551   dbus_bool_t retval;
552   security_id_t sid;
553   char *key;
554
555   if (!selinux_enabled)
556     return TRUE;
557
558   sid = SECSID_WILD;
559   retval = FALSE;
560
561   key = _dbus_strdup (service_name);
562   if (key == NULL)
563     return retval;
564   
565   if (avc_context_to_sid ((char *) service_context, &sid) < 0)
566     {
567       _dbus_assert (errno == ENOMEM);
568       goto out;
569     }
570
571   if (!_dbus_hash_table_insert_string (service_table,
572                                        key,
573                                        BUS_SID_FROM_SELINUX (sid)))
574     goto out;
575
576   _dbus_verbose ("Parsed \tservice: %s \n\t\tcontext: %s\n",
577                   key, 
578                   sid->ctx);
579
580   /* These are owned by the hash, so clear them to avoid unref */
581   key = NULL;
582   sid = SECSID_WILD;
583
584   retval = TRUE;
585   
586  out:
587   if (sid != SECSID_WILD)
588     sidput (sid);
589
590   if (key)
591     dbus_free (key);
592
593   return retval;
594 #else
595   return TRUE;
596 #endif /* HAVE_SELINUX */
597 }
598
599
600 /**
601  * Find the security identifier associated with a particular service
602  * name.  Return a pointer to this SID, or #NULL/SECSID_WILD if the
603  * service is not found in the hash table.  This should be nearly a
604  * constant time operation.  If SELinux support is not available,
605  * always return NULL.
606  *
607  * @param service_table the hash table to check for service name.
608  * @param service_name the name of the service to look for.
609  * @returns the SELinux ID associated with the service
610  */
611 BusSELinuxID*
612 bus_selinux_id_table_lookup (DBusHashTable    *service_table,
613                              const DBusString *service_name)
614 {
615 #ifdef HAVE_SELINUX
616   security_id_t sid;
617
618   sid = SECSID_WILD;     /* default context */
619
620   if (!selinux_enabled)
621     return NULL;
622   
623   _dbus_verbose ("Looking up service SID for %s\n",
624                  _dbus_string_get_const_data (service_name));
625
626   sid = _dbus_hash_table_lookup_string (service_table,
627                                         _dbus_string_get_const_data (service_name));
628
629   if (sid == SECSID_WILD)
630     _dbus_verbose ("Service %s not found\n", 
631                    _dbus_string_get_const_data (service_name));
632   else
633     _dbus_verbose ("Service %s found\n", 
634                    _dbus_string_get_const_data (service_name));
635
636   return BUS_SID_FROM_SELINUX (sid);
637 #endif /* HAVE_SELINUX */
638   return NULL;
639 }
640
641 /**
642  * Copy security ID table mapping from one table into another.
643  *
644  * @param dest the table to copy into
645  * @param override the table to copy from
646  * @returns #FALSE if out of memory
647  */
648 #ifdef HAVE_SELINUX
649 static dbus_bool_t
650 bus_selinux_id_table_copy_over (DBusHashTable    *dest,
651                                 DBusHashTable    *override)
652 {
653   const char *key;
654   char *key_copy;
655   BusSELinuxID *sid;
656   DBusHashIter iter;
657   
658   _dbus_hash_iter_init (override, &iter);
659   while (_dbus_hash_iter_next (&iter))
660     {
661       key = _dbus_hash_iter_get_string_key (&iter);
662       sid = _dbus_hash_iter_get_value (&iter);
663
664       key_copy = _dbus_strdup (key);
665       if (key_copy == NULL)
666         return FALSE;
667
668       if (!_dbus_hash_table_insert_string (dest,
669                                            key_copy,
670                                            sid))
671         {
672           dbus_free (key_copy);
673           return FALSE;
674         }
675
676       bus_selinux_id_ref (sid);
677     }
678
679   return TRUE;
680 }
681 #endif /* HAVE_SELINUX */
682
683 /**
684  * Creates the union of the two tables (each table maps a service
685  * name to a security ID). In case of the same service name in
686  * both tables, the security ID from "override" will be used.
687  *
688  * @param base the base table
689  * @param override the table that takes precedence in the merge
690  * @returns the new table, or #NULL if out of memory
691  */
692 DBusHashTable*
693 bus_selinux_id_table_union (DBusHashTable    *base,
694                             DBusHashTable    *override)
695 {
696   DBusHashTable *combined_table;
697
698   combined_table = bus_selinux_id_table_new ();
699
700   if (combined_table == NULL)
701     return NULL;
702   
703 #ifdef HAVE_SELINUX 
704   if (!selinux_enabled)
705     return combined_table;
706
707   if (!bus_selinux_id_table_copy_over (combined_table, base))
708     {
709       _dbus_hash_table_unref (combined_table);
710       return NULL;
711     }
712
713   if (!bus_selinux_id_table_copy_over (combined_table, override))
714     {
715       _dbus_hash_table_unref (combined_table);
716       return NULL;
717     }
718 #endif /* HAVE_SELINUX */
719   
720   return combined_table;
721 }
722
723 /**
724  * Get the SELinux policy root.  This is used to find the D-BUS
725  * specific config file within the policy.
726  */
727 const char *
728 bus_selinux_get_policy_root (void)
729 {
730 #ifdef HAVE_SELINUX
731   return selinux_policy_root ();
732 #else
733   return NULL;
734 #endif /* HAVE_SELINUX */
735
736
737 /**
738  * For debugging:  Print out the current hash table of service SIDs.
739  */
740 void
741 bus_selinux_id_table_print (DBusHashTable *service_table)
742 {
743 #ifdef DBUS_ENABLE_VERBOSE_MODE
744 #ifdef HAVE_SELINUX
745   DBusHashIter iter;
746
747   if (!selinux_enabled)
748     return;
749   
750   _dbus_verbose ("Service SID Table:\n");
751   _dbus_hash_iter_init (service_table, &iter);
752   while (_dbus_hash_iter_next (&iter))
753     {
754       const char *key = _dbus_hash_iter_get_string_key (&iter);
755       security_id_t sid = _dbus_hash_iter_get_value (&iter);
756       _dbus_verbose ("The key is %s\n", key);
757       _dbus_verbose ("The context is %s\n", sid->ctx);
758       _dbus_verbose ("The refcount is %d\n", sid->refcnt);
759     }
760 #endif /* HAVE_SELINUX */
761 #endif /* DBUS_ENABLE_VERBOSE_MODE */
762 }
763
764
765 #ifdef DBUS_ENABLE_VERBOSE_MODE
766 #ifdef HAVE_SELINUX
767 /**
768  * Print out some AVC statistics.
769  */
770 static void
771 bus_avc_print_stats (void)
772 {
773   struct avc_cache_stats cstats;
774
775   if (!selinux_enabled)
776     return;
777   
778   _dbus_verbose ("AVC Statistics:\n");
779   avc_cache_stats (&cstats);
780   avc_av_stats ();
781   _dbus_verbose ("AVC Cache Statistics:\n");
782   _dbus_verbose ("Entry lookups: %d\n", cstats.entry_lookups);
783   _dbus_verbose ("Entry hits: %d\n", cstats.entry_hits);
784   _dbus_verbose ("Entry misses %d\n", cstats.entry_misses);
785   _dbus_verbose ("Entry discards: %d\n", cstats.entry_discards);
786   _dbus_verbose ("CAV lookups: %d\n", cstats.cav_lookups);
787   _dbus_verbose ("CAV hits: %d\n", cstats.cav_hits);
788   _dbus_verbose ("CAV probes: %d\n", cstats.cav_probes);
789   _dbus_verbose ("CAV misses: %d\n", cstats.cav_misses);
790 }
791 #endif /* HAVE_SELINUX */
792 #endif /* DBUS_ENABLE_VERBOSE_MODE */
793
794
795 /**
796  * Destroy the AVC before we terminate.
797  */
798 void
799 bus_selinux_shutdown (void)
800 {
801 #ifdef HAVE_SELINUX
802   if (!selinux_enabled)
803     return;
804
805   sidput (bus_sid);
806   bus_sid = SECSID_WILD;
807   
808 #ifdef DBUS_ENABLE_VERBOSE_MODE
809   bus_avc_print_stats ();
810 #endif /* DBUS_ENABLE_VERBOSE_MODE */
811
812   avc_destroy ();
813 #endif /* HAVE_SELINUX */
814 }
815