Blob Blame History Raw
diff --git a/libselinux/include/selinux/selinux.h b/libselinux/include/selinux/selinux.h
index 6b9089d..aba6e33 100644
--- a/libselinux/include/selinux/selinux.h
+++ b/libselinux/include/selinux/selinux.h
@@ -360,6 +360,8 @@ extern int selinux_set_mapping(struct security_class_mapping *map);
 
 /* Common helpers */
 
+/* Convert between mode and security class values */
+extern security_class_t mode_to_security_class(mode_t mode);
 /* Convert between security class values and string names */
 extern security_class_t string_to_security_class(const char *name);
 extern const char *security_class_to_string(security_class_t cls);
@@ -496,7 +498,9 @@ extern const char *selinux_policy_root(void);
 
 /* These functions return the paths to specific files under the 
    policy root directory. */
+extern const char *selinux_current_policy_path(void);
 extern const char *selinux_binary_policy_path(void);
+extern char *selinux_binary_policy_path_min_max(int min, int *max);
 extern const char *selinux_failsafe_context_path(void);
 extern const char *selinux_removable_context_path(void);
 extern const char *selinux_default_context_path(void);
diff --git a/libselinux/man/man3/avc_add_callback.3 b/libselinux/man/man3/avc_add_callback.3
index 9c83cac..dbfe72d 100644
--- a/libselinux/man/man3/avc_add_callback.3
+++ b/libselinux/man/man3/avc_add_callback.3
@@ -3,33 +3,35 @@
 .\" Author: Eamon Walsh (ewalsh@tycho.nsa.gov) 2004
 .TH "avc_add_callback" "3" "9 June 2004" "" "SELinux API documentation"
 .SH "NAME"
-avc_add_callback \- additional event notification for SELinux userspace object managers.
+avc_add_callback \- additional event notification for SELinux userspace object managers
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
-
+.br
 .B #include <selinux/avc.h>
 .sp
 .BI "int avc_add_callback(int (*" callback ")(uint32_t " event , 
 .in +\w'int avc_add_callback(int (*callback)('u
 .BI "security_id_t " ssid ,
-
+.br
 .BI "security_id_t " tsid ,
-
+.br
 .BI "security_class_t " tclass ,
-
+.br
 .BI "access_vector_t " perms ,
-
+.br
 .BI "access_vector_t *" out_retained "),"
 .in
 .in +\w'int avc_add_callback('u
 .BI "uint32_t " events ", security_id_t " ssid , 
-
+.br
 .BI "security_id_t " tsid ", security_class_t " tclass ,
-
+.br
 .BI "access_vector_t " perms ");"
 .in
+.
 .SH "DESCRIPTION"
-.B avc_add_callback
+.BR avc_add_callback ()
 is used to register callback functions on security events.  The purpose of this functionality is to allow userspace object managers to take additional action when a policy change, usually a policy reload, causes permissions to be granted or revoked.
 
 .I events
@@ -55,10 +57,14 @@ and will cause any SID to match.
 .I callback
 is the callback function provided by the userspace object manager.  The
 .I event
-argument indicates the security event which occured; the remaining arguments are interpreted according to the event as described below.  The return value of the callback should be zero on success, \-1 on error with errno set appropriately (but see
+argument indicates the security event which occured; the remaining arguments
+are interpreted according to the event as described below.  The return value
+of the callback should be zero on success, \-1 on error with
+.I errno
+set appropriately (but see
 .B RETURN VALUE
 below).
-
+.
 .SH "SECURITY EVENTS"
 In all cases below,
 .I ssid
@@ -69,7 +75,7 @@ may be set to
 indicating that the change applies to all source and/or target SID's.  Unless otherwise indicated, the
 .I out_retained
 parameter is unused.
-
+.
 .TP
 .B AVC_CALLBACK_GRANT
 Previously denied permissions are now granted for
@@ -142,10 +148,10 @@ should no longer be audited when denied for
 .I tsid
 with respect to
 .IR tclass .
-
+.
 .SH "RETURN VALUE"
 On success,
-.B avc_add_callback
+.BR avc_add_callback ()
 returns zero.  On error, \-1 is returned and
 .I errno
 is set appropriately.
@@ -157,25 +163,27 @@ on all further permission checks until
 is called.  In non-threaded mode, the permission check on which the error occurred will return \-1 and the value of 
 .I errno
 encountered to the caller.  In both cases, a log message is produced and the kernel may be notified of the error.
-
+.
 .SH "ERRORS"
 .TP
 .B ENOMEM
 An attempt to allocate memory failed.
-
+.
 .SH "NOTES"
 If the userspace AVC is running in threaded mode, callbacks registered via
-.B avc_add_callback
+.BR avc_add_callback ()
 may be executed in the context of the netlink handler thread.  This will likely introduce synchronization issues requiring the use of locks.  See
 .BR avc_init (3).
 
 Support for dynamic revocation and retained permissions is mostly unimplemented in the SELinux kernel module.  The only security event that currently gets excercised is
 .BR AVC_CALLBACK_RESET .
-
+.
 .SH "AUTHOR"
 Eamon Walsh <ewalsh@tycho.nsa.gov>
-
+.
 .SH "SEE ALSO"
+.ad l
+.nh
 .BR avc_init (3),
 .BR avc_has_perm (3),
 .BR avc_context_to_sid (3),
diff --git a/libselinux/man/man3/avc_cache_stats.3 b/libselinux/man/man3/avc_cache_stats.3
index 96f2b21..c00f090 100644
--- a/libselinux/man/man3/avc_cache_stats.3
+++ b/libselinux/man/man3/avc_cache_stats.3
@@ -3,10 +3,11 @@
 .\" Author: Eamon Walsh (ewalsh@tycho.nsa.gov) 2004
 .TH "avc_cache_stats" "3" "27 May 2004" "" "SELinux API documentation"
 .SH "NAME"
-avc_cache_stats, avc_av_stats, avc_sid_stats \- obtain userspace SELinux AVC statistics.
+avc_cache_stats, avc_av_stats, avc_sid_stats \- obtain userspace SELinux AVC statistics
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
-
+.br
 .B #include <selinux/avc.h>
 .sp
 .BI "void avc_av_stats(void);"
@@ -14,15 +15,16 @@ avc_cache_stats, avc_av_stats, avc_sid_stats \- obtain userspace SELinux AVC sta
 .BI "void avc_sid_stats(void);"
 .sp
 .BI "void avc_cache_stats(struct avc_cache_stats *" stats ");"
+.
 .SH "DESCRIPTION"
 The userspace AVC maintains two internal hash tables, one to store security ID's and one to cache access decisions.
 
-.B avc_av_stats
+.BR avc_av_stats ()
 and
-.B avc_sid_stats
+.BR avc_sid_stats ()
 produce log messages indicating the status of the access decision and SID tables, respectively.  The messages contain the number of entries in the table, number of hash buckets and number of buckets used, and maximum number of entries in a single bucket.
 
-.B avc_cache_stats
+.BR avc_cache_stats ()
 populates a structure whose fields reflect cache activity:
 
 .RS
@@ -74,26 +76,28 @@ Number of cache misses.
 .TP
 .I cav_probes
 Number of entries examined while searching the cache.
-
+.
 .SH "NOTES"
 When the cache is flushed as a result of a call to
-.B avc_reset
+.BR avc_reset ()
 or a policy change notification,
 the statistics returned by
-.B avc_cache_stats
+.BR avc_cache_stats ()
 are reset to zero.  The SID table, however, is left
 unchanged.
 
 When a policy change notification is received, a call to
-.B avc_av_stats
+.BR avc_av_stats ()
 is made before the cache is flushed.
-
+.
 .SH "AUTHOR"
 Eamon Walsh <ewalsh@tycho.nsa.gov>
-
+.
 .SH "SEE ALSO"
+.ad l
+.nh
 .BR avc_init (3),
 .BR avc_has_perm (3),
 .BR avc_context_to_sid (3),
-.BR avc_add_callback (3)
+.BR avc_add_callback (3),
 .BR selinux (8)
diff --git a/libselinux/man/man3/avc_compute_create.3 b/libselinux/man/man3/avc_compute_create.3
index 52d09b5..ce615bf 100644
--- a/libselinux/man/man3/avc_compute_create.3
+++ b/libselinux/man/man3/avc_compute_create.3
@@ -3,10 +3,11 @@
 .\" Author: Eamon Walsh (ewalsh@tycho.nsa.gov) 2007
 .TH "avc_compute_create" "3" "30 Mar 2007" "" "SELinux API documentation"
 .SH "NAME"
-avc_compute_create, avc_compute_member \- obtain SELinux label for new object.
+avc_compute_create, avc_compute_member \- obtain SELinux label for new object
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
-
+.br
 .B #include <selinux/avc.h>
 .sp
 .BI "int avc_compute_create(security_id_t " ssid ", security_id_t " tsid ,
@@ -18,26 +19,27 @@ avc_compute_create, avc_compute_member \- obtain SELinux label for new object.
 .in +\w'int avc_compute_member('u
 .BI "security_class_t " tclass ", security_id_t *" newsid ");"
 .in
+.
 .SH "DESCRIPTION"
-.B avc_compute_create
+.BR avc_compute_create ()
 is used to compute a SID to use for labeling a new object in a particular class based on a SID pair.  This call is identical to
-.BR security_compute_create ,
+.BR security_compute_create (),
 but does not require converting from userspace SID's to contexts and back again.
 
-.B avc_compute_member
+.BR avc_compute_member ()
 is used to compute a SID to use for labeling a polyinstantiated object instance of a particular class based on a SID pair.  This call is identical to
-.BR security_compute_member ,
+.BR security_compute_member (),
 but does not require converting from userspace SID's to contexts and back again.
 
 These functions
 return a SID for the computed context in the memory referenced by
 .IR sid .
-
+.
 .SH "RETURN VALUE"
 On success, zero is returned.  On error, \-1 is returned and
 .I errno
 is set appropriately.
-
+.
 .SH "ERRORS"
 .TP
 .B EINVAL
@@ -48,14 +50,13 @@ and/or the security contexts referenced by
 and
 .I tsid
 are not recognized by the currently loaded policy.
-
 .TP
 .B ENOMEM
 An attempt to allocate memory failed.
-
+.
 .SH "AUTHOR"
 Eamon Walsh <ewalsh@tycho.nsa.gov>
-
+.
 .SH "SEE ALSO"
 .BR avc_init (3),
 .BR avc_context_to_sid (3),
diff --git a/libselinux/man/man3/avc_context_to_sid.3 b/libselinux/man/man3/avc_context_to_sid.3
index 1caf5ec..e416b09 100644
--- a/libselinux/man/man3/avc_context_to_sid.3
+++ b/libselinux/man/man3/avc_context_to_sid.3
@@ -3,10 +3,11 @@
 .\" Author: Eamon Walsh (ewalsh@tycho.nsa.gov) 2004
 .TH "avc_context_to_sid" "3" "27 May 2004" "" "SELinux API documentation"
 .SH "NAME"
-avc_context_to_sid, avc_sid_to_context, avc_get_initial_sid \- obtain and manipulate SELinux security ID's.
+avc_context_to_sid, avc_sid_to_context, avc_get_initial_sid \- obtain and manipulate SELinux security ID's
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
-
+.br
 .B #include <selinux/avc.h>
 .sp
 .BI "int avc_context_to_sid(security_context_t " ctx ", security_id_t *" sid ");"
@@ -14,17 +15,17 @@ avc_context_to_sid, avc_sid_to_context, avc_get_initial_sid \- obtain and manipu
 .BI "int avc_sid_to_context(security_id_t " sid ", security_context_t *" ctx ");"
 .sp
 .BI "int avc_get_initial_sid(const char *" name ", security_id_t *" sid ");"
-.sp
+.
 .SH "DESCRIPTION"
 Security ID's (SID's) are opaque representations of security contexts, managed by the userspace AVC.
 
-.B avc_context_to_sid
+.BR avc_context_to_sid ()
 returns a SID for the given
 .I context
 in the memory referenced by
 .IR sid .
 
-.B avc_sid_to_context
+.BR avc_sid_to_context ()
 returns a copy of the context represented by
 .I sid
 in the memory referenced by
@@ -32,40 +33,41 @@ in the memory referenced by
 The user must free the copy with
 .BR freecon (3).
 
-.B avc_get_initial_sid
+.BR avc_get_initial_sid ()
 returns a SID for the kernel initial security identifier specified by 
 .IR name .
-
+.
 .SH "RETURN VALUE"
-.B avc_context_to_sid
+.BR avc_context_to_sid ()
 and
-.B avc_sid_to_context
+.BR avc_sid_to_context ()
 return zero on success.  On error, \-1 is returned and
 .I errno
 is set appropriately.
-
+.
 .SH "ERRORS"
 .TP
 .B ENOMEM
 An attempt to allocate memory failed.
-
 .SH "NOTES"
 As of libselinux version 2.0.86, SID's are no longer reference counted.  A SID will be valid from the time it is first obtained until the next call to
 .BR avc_destroy (3).
 The
-.B sidget
+.BR sidget (3)
 and
-.B sidput
+.BR sidput (3)
 functions, formerly used to adjust the reference count, are no-ops and are deprecated.
-
+.
 .SH "AUTHOR"
 Eamon Walsh <ewalsh@tycho.nsa.gov>
-
+.
 .SH "SEE ALSO"
+.ad l
+.nh
 .BR avc_init (3),
 .BR avc_has_perm (3),
 .BR avc_cache_stats (3),
 .BR avc_add_callback (3),
 .BR getcon (3),
-.BR freecon (3)
+.BR freecon (3),
 .BR selinux (8)
diff --git a/libselinux/man/man3/avc_has_perm.3 b/libselinux/man/man3/avc_has_perm.3
index 50f4d44..7353952 100644
--- a/libselinux/man/man3/avc_has_perm.3
+++ b/libselinux/man/man3/avc_has_perm.3
@@ -3,10 +3,11 @@
 .\" Author: Eamon Walsh (ewalsh@tycho.nsa.gov) 2004
 .TH "avc_has_perm" "3" "27 May 2004" "" "SELinux API documentation"
 .SH "NAME"
-avc_has_perm, avc_has_perm_noaudit, avc_audit, avc_entry_ref_init \- obtain and audit SELinux access decisions.
+avc_has_perm, avc_has_perm_noaudit, avc_audit, avc_entry_ref_init \- obtain and audit SELinux access decisions
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
-
+.br
 .B #include <selinux/avc.h>
 .sp
 .BI "void avc_entry_ref_init(struct avc_entry_ref *" aeref ");"
@@ -14,32 +15,33 @@ avc_has_perm, avc_has_perm_noaudit, avc_audit, avc_entry_ref_init \- obtain and
 .BI "int avc_has_perm(security_id_t " ssid ", security_id_t " tsid ,
 .in +\w'int avc_has_perm('u
 .BI "security_class_t " tclass ", access_vector_t " requested ,
-
+.br
 .BI "struct avc_entry_ref *" aeref ", void *" auditdata ");"
 .in
 .sp
 .BI "int avc_has_perm_noaudit(security_id_t " ssid ", security_id_t " tsid ,
 .in +\w'int avc_has_perm('u
 .BI "security_class_t " tclass ", access_vector_t " requested ,
-
+.br
 .BI "struct avc_entry_ref *" aeref ", struct av_decision *" avd ");"
 .in
 .sp
 .BI "void avc_audit(security_id_t " ssid ", security_id_t " tsid ,
 .in +\w'void avc_audit('u
 .BI "security_class_t " tclass ", access_vector_t " requested ,
-
+.br
 .BI "struct av_decision *" avd ", int " result ", void *" auditdata ");"
 .in
+.
 .SH "DESCRIPTION"
-.B avc_entry_ref_init
+.BR avc_entry_ref_init ()
 initializes an
 .B avc_entry_ref
 structure; see
 .B ENTRY REFERENCES
 below.  This function may be implemented as a macro.
 
-.B avc_has_perm
+.BR avc_has_perm ()
 checks whether the 
 .I requested
 permissions are granted
@@ -55,19 +57,19 @@ and updating
 if non-NULL, to refer to a cache entry with the resulting decision.  The granting or denial of permissions is audited in accordance with the policy.  The
 .I auditdata
 parameter is for supplemental auditing; see
-.B avc_audit
+.BR avc_audit ()
 below.
 
-.B avc_has_perm_noaudit
+.BR avc_has_perm_noaudit ()
 behaves as
-.B avc_has_perm
+.BR avc_has_perm ()
 without producing an audit message.  The access decision is returned in
 .I avd
 and can be passed to
-.B avc_audit
+.BR avc_audit ()
 explicitly.
 
-.B avc_audit
+.BR avc_audit ()
 produces an audit message for the access query represented by
 .IR ssid ,
 .IR tsid ,
@@ -77,7 +79,7 @@ and
 with a decision represented by
 .IR avd .
 Pass the value returned by
-.B avc_has_perm_noaudit
+.BR avc_has_perm_noaudit ()
 as
 .IR result .
 The
@@ -86,7 +88,7 @@ parameter is passed to the user-supplied
 .B func_audit
 callback and can be used to add supplemental information to the audit message; see
 .BR avc_init (3).
-
+.
 .SH "ENTRY REFERENCES"
 Entry references can be used to speed cache performance for repeated queries on the same subject and target.  The userspace AVC will check the
 .I aeref
@@ -97,14 +99,14 @@ will be updated to reference the cache entry for that query.  A subsequent query
 After declaring an
 .B avc_entry_ref
 structure, use
-.B avc_entry_ref_init
+.BR avc_entry_ref_init ()
 to initialize it before passing it to
-.B avc_has_perm
+.BR avc_has_perm ()
 or
-.B avc_has_perm_noaudit
+.BR \%avc_has_perm_noaudit ()
 for the first time.
 Using an uninitialized structure will produce undefined behavior.
-
+.
 .SH "RETURN VALUE"
 If requested permissions are granted, zero is returned.  If requested permissions are denied or an error occured, \-1 is returned and
 .I errno
@@ -113,9 +115,9 @@ is set appropriately.
 In permissive mode, zero will be returned and
 .I errno
 unchanged even if permissions were denied.
-.B avc_has_perm
+.BR avc_has_perm ()
 will still produce an audit message in this case.
-
+.
 .SH "ERRORS"
 .TP
 .B EACCES
@@ -132,7 +134,7 @@ are not recognized by the currently loaded policy.
 .TP
 .B ENOMEM
 An attempt to allocate memory failed.
-
+.
 .SH "NOTES"
 Internal errors encountered by the userspace AVC may cause certain values of
 .I errno
@@ -142,14 +144,16 @@ or
 .BR EINVAL .
 Make sure that userspace object managers are granted appropriate access to
 netlink by the policy.
-
+.
 .SH "AUTHOR"
 Eamon Walsh <ewalsh@tycho.nsa.gov>
-
+.
 .SH "SEE ALSO"
+.ad l
+.nh
 .BR avc_init (3),
 .BR avc_context_to_sid (3),
 .BR avc_cache_stats (3),
 .BR avc_add_callback (3),
-.BR security_compute_av (3)
-.BR selinux(8)
+.BR security_compute_av (3),
+.BR selinux (8)
diff --git a/libselinux/man/man3/avc_init.3 b/libselinux/man/man3/avc_init.3
index 331a665..e26c3be 100644
--- a/libselinux/man/man3/avc_init.3
+++ b/libselinux/man/man3/avc_init.3
@@ -3,37 +3,39 @@
 .\" Author: Eamon Walsh (ewalsh@tycho.nsa.gov) 2004
 .TH "avc_init" "3" "27 May 2004" "" "SELinux API documentation"
 .SH "NAME"
-avc_init - legacy userspace SELinux AVC setup.
+avc_init \- legacy userspace SELinux AVC setup
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
-
+.br
 .B #include <selinux/avc.h>
 .sp
 .BI "int avc_init(const char *" msgprefix , 
 .in +\w'int avc_init('u
 .BI "const struct avc_memory_callback *" mem_callbacks ,
-
+.br
 .BI "const struct avc_log_callback *" log_callbacks ,
-
+.br
 .BI "const struct avc_thread_callback *" thread_callbacks ,
-
+.br
 .BI "const struct avc_lock_callback *" lock_callbacks ");"
+.
 .SH "DESCRIPTION"
-.B avc_init
+.BR avc_init ()
 is deprecated; please use
 .BR avc_open (3)
 in conjunction with
 .BR selinux_set_callback (3)
 in all new code.
 
-.B avc_init
+.BR avc_init ()
 initializes the userspace AVC and must be called before any other AVC operation can be performed.  A non-NULL
 .I msgprefix
 will be prepended to all audit messages produced by the userspace AVC.  The default is `uavc'.  The remaining arguments, if non-NULL, specify callbacks to be used by the userspace AVC.
-
+.
 .SH "CALLBACKS"
 The userspace AVC can be directed how to perform memory allocation, logging, thread creation, and locking via callback functions passed to
-.BR avc_init .
+.BR avc_init ().
 The purpose of this functionality is to allow the userspace AVC to be smoothly integrated into existing userspace object managers.
 
 Use an
@@ -150,26 +152,26 @@ The
 callback should destroy
 .IR lock ,
 freeing any resources associated with it.  The default behavior is not to perform any locking.  Note that undefined behavior may result if threading is used without appropriate locking.
-
+.
 .SH "NETLINK NOTIFICATION"
 Beginning with version 2.6.4, the Linux kernel supports SELinux status change notification via netlink.  Two message types are currently implemented, indicating changes to the enforcing mode and to the loaded policy in the kernel, respectively.  The userspace AVC listens for these messages and takes the appropriate action, modifying the behavior of
 .BR avc_has_perm (3)
 to reflect the current enforcing mode and flushing the cache on receipt of a policy load notification.  Audit messages are produced when netlink notifications are processed.
 
 In the default single-threaded mode, the userspace AVC checks for new netlink messages at the start of each permission query.  If threading and locking callbacks are passed to
-.B avc_init
+.BR avc_init ()
 however, a dedicated thread will be started to listen on the netlink socket.  This may increase performance and will ensure that log messages are generated immediately rather than at the time of the next permission query.
-
+.
 .SH "RETURN VALUE"
 Functions with a return value return zero on success.  On error, \-1 is returned and
 .I errno
 is set appropriately.
-
+.
 .SH "NOTES"
 The
 .I msgprefix
 argument to
-.B avc_init
+.BR avc_init ()
 currently has a length limit of 15 characters and will be truncated if necessary.
 
 If a provided
@@ -184,12 +186,11 @@ If a netlink thread has been created and an error occurs on the socket (such as
 on all further permission checks until
 .B avc_destroy 
 is called.
-
+.
 .SH "AUTHOR"
 Eamon Walsh <ewalsh@tycho.nsa.gov>
-
+.
 .SH "SEE ALSO"
 .BR avc_open (3),
 .BR selinux_set_callback (3),
 .BR selinux (8)
-
diff --git a/libselinux/man/man3/avc_netlink_loop.3 b/libselinux/man/man3/avc_netlink_loop.3
index 785be4c..c8268a1 100644
--- a/libselinux/man/man3/avc_netlink_loop.3
+++ b/libselinux/man/man3/avc_netlink_loop.3
@@ -5,24 +5,25 @@
 .SH "NAME"
 avc_netlink_open, avc_netlink_close, avc_netlink_acquire_fd,
 avc_netlink_release_fd, avc_netlink_check_nb, avc_netlink_loop \- SELinux
-netlink processing.
+netlink processing
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
-
+.br
 .B #include <selinux/avc.h>
 .sp
 .BI "int avc_netlink_open(int " blocking ");"
 .sp
-.BI "void avc_netlink_close(void);"
-.sp
-.BI "int avc_netlink_acquire_fd(void);"
+.B void avc_netlink_close(void);
 .sp
-.BI "void avc_netlink_release_fd(void);"
+.B int avc_netlink_acquire_fd(void);
 .sp
-.BI "void avc_netlink_loop(void);"
+.B void avc_netlink_release_fd(void);
 .sp
-.BI "int avc_netlink_check_nb(void);"
+.B void avc_netlink_loop(void);
 .sp
+.B int avc_netlink_check_nb(void);
+.
 .SH "DESCRIPTION"
 These functions enable applications to handle notification of SELinux events
 via netlink.  The userspace AVC normally checks for netlink messages on each
@@ -35,7 +36,7 @@ loop.  These functions also permit netlink monitoring without requiring a
 call to
 .BR avc_open (3).
 
-.B avc_netlink_open
+.BR avc_netlink_open ()
 opens a netlink socket to receive SELinux notifications.  The socket
 descriptor is stored internally; use
 .BR avc_netlink_acquire_fd (3)
@@ -45,38 +46,38 @@ argument controls whether the O_NONBLOCK flag is set on the socket descriptor.
 .BR avc_open (3)
 calls this function internally, specifying non-blocking behavior.
 
-.B avc_netlink_close
+.BR avc_netlink_close ()
 closes the netlink socket.  This function is called automatically by
 .BR avc_destroy (3).
 
-.B avc_netlink_acquire_fd
+.BR avc_netlink_acquire_fd ()
 returns the netlink socket descriptor number and informs the userspace AVC
 not to check the socket descriptor automatically on calls to
 .BR avc_has_perm (3).
 
-.B avc_netlink_release_fd
+.BR avc_netlink_release_fd ()
 returns control of the netlink socket to the userspace AVC, re-enabling
 automatic processing of notifications.
 
-.B avc_netlink_check_nb
+.BR avc_netlink_check_nb ()
 checks the netlink socket for pending messages and processes them.
 Callbacks for policyload and enforcing changes will be called;
 see
 .BR selinux_set_callback (3).
 This function does not block.
 
-.B avc_netlink_loop
+.BR avc_netlink_loop ()
 enters a loop blocking on the netlink socket and processing messages as they
 are received.  This function will not return unless an error occurs on
 the socket, in which case the socket is closed.
-
+.
 .SH "RETURN VALUE"
-.B avc_netlink_acquire_fd
+.BR avc_netlink_acquire_fd ()
 returns a non-negative file descriptor number on success.  Other functions
-with a return value return zero on success.  On error, -1 is returned and
+with a return value return zero on success.  On error, \-1 is returned and
 .I errno
 is set appropriately.
-
+.
 .SH "SEE ALSO"
 .BR avc_open (3),
 .BR selinux_set_callback (3),
diff --git a/libselinux/man/man3/avc_open.3 b/libselinux/man/man3/avc_open.3
index d1dab8f..5b275a8 100644
--- a/libselinux/man/man3/avc_open.3
+++ b/libselinux/man/man3/avc_open.3
@@ -3,10 +3,11 @@
 .\" Author: Eamon Walsh (ewalsh@tycho.nsa.gov) 2008
 .TH "avc_open" "3" "12 Jun 2008" "" "SELinux API documentation"
 .SH "NAME"
-avc_open, avc_destroy, avc_reset, avc_cleanup \- userspace SELinux AVC setup and teardown.
+avc_open, avc_destroy, avc_reset, avc_cleanup \- userspace SELinux AVC setup and teardown
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
-
+.br
 .B #include <selinux/avc.h>
 .sp
 .BI "int avc_open(struct selinux_opt *" options ", unsigned " nopt ");"
@@ -16,49 +17,48 @@ avc_open, avc_destroy, avc_reset, avc_cleanup \- userspace SELinux AVC setup and
 .BI "int avc_reset(void);"
 .sp
 .BI "void avc_cleanup(void);"
+.
 .SH "DESCRIPTION"
-.B avc_open
+.BR avc_open ()
 initializes the userspace AVC and must be called before any other AVC operation can be performed.
 
-.B avc_destroy
+.BR avc_destroy ()
 destroys the userspace AVC, freeing all internal memory structures.  After this call has been made, 
-.B avc_open
+.BR avc_open ()
 must be called again before any AVC operations can be performed.
 
-.B avc_reset
+.BR avc_reset ()
 flushes the userspace AVC, causing it to forget any cached access decisions.  The userspace AVC normally calls this function automatically when needed, see
 .B NETLINK NOTIFICATION
 below.
 
-.B avc_cleanup
+.BR avc_cleanup ()
 attempts to free unused memory within the userspace AVC, but does not flush any cached access decisions.  Under normal operation, calling this function should not be necessary.
-
 .SH "OPTIONS"
 The userspace AVC obeys callbacks set via
 .BR selinux_set_callback (3),
 in particular the logging and audit callbacks.
 
 The options which may be passed to
-.B avc_open
+.BR avc_open ()
 include the following:
-
 .TP
 .B AVC_OPT_SETENFORCE
 This option forces the userspace AVC into enforcing mode if the option value is non-NULL; permissive mode otherwise.  The system enforcing mode will be ignored.
-
+.
 .SH "NETLINK NOTIFICATION"
 Beginning with version 2.6.4, the Linux kernel supports SELinux status change notification via netlink.  Two message types are currently implemented, indicating changes to the enforcing mode and to the loaded policy in the kernel, respectively.  The userspace AVC listens for these messages and takes the appropriate action, modifying the behavior of
 .BR avc_has_perm (3)
 to reflect the current enforcing mode and flushing the cache on receipt of a policy load notification.  Audit messages are produced when netlink notifications are processed.
-
+.
 .SH "RETURN VALUE"
 Functions with a return value return zero on success.  On error, \-1 is returned and
 .I errno
 is set appropriately.
-
+.
 .SH "AUTHOR"
 Eamon Walsh <ewalsh@tycho.nsa.gov>
-
+.
 .SH "SEE ALSO"
 .BR selinux (8),
 .BR avc_has_perm (3),
@@ -67,4 +67,3 @@ Eamon Walsh <ewalsh@tycho.nsa.gov>
 .BR avc_add_callback (3),
 .BR selinux_set_callback (3),
 .BR security_compute_av (3)
-
diff --git a/libselinux/man/man3/context_new.3 b/libselinux/man/man3/context_new.3
index 820f927..3dabac3 100644
--- a/libselinux/man/man3/context_new.3
+++ b/libselinux/man/man3/context_new.3
@@ -1,61 +1,83 @@
 .TH "context_new" "3" "20 December 2011" "dwalsh@redhat.com" "SELinux API documentation"
 .SH "NAME"
 context_new, context_str, context_free, context_type_get, context_type_set, context_range_get, context_range_set,context_role_get, context_role_set, context_user_get, context_user_set \- Routines to manipulate SELinux security contexts
-
+.
 .SH "SYNOPSIS"
 .B #include <selinux/context.h>
-
+.sp
 .BI "context_t context_new(const char *" context_str );
-
+.sp
 .BI "const char * context_str(context_t " con );
-
+.sp
 .BI "void context_free(context_t " con );
-
+.sp
 .BI "const char * context_type_get(context_t " con );
-
+.sp
 .BI "const char * context_range_get(context_t " con );
-
+.sp
 .BI "const char * context_role_get(context_t " con );
-
+.sp
 .BI "const char * context_user_get(context_t " con );
-
+.sp
 .BI "int context_type_set(context_t " con ", const char *" type );
-
+.sp
 .BI "int context_range_set(context_t " con ", const char *" range );
-
+.sp
 .BI "int context_role_set(context_t " con ", const char *" role );
-
+.sp
 .BI "int context_user_set(context_t " con ", const char *" user );
-
+.
 .SH "DESCRIPTION"
 These functions allow an application to manipulate the fields of a
 security context string without requiring it to know the format of the
 string.
 
-context_new
- Return a new context initialized to a context string 
-
-context_str
- Return a pointer to the string value of the context_t
-Valid until the next call to context_str or context_free 
-for the same context_t*
-
-context_free
- Free the storage used by a context
-
-context_type_get, context_range_get, context_role_get, context_user_get
- Get a pointer to the string value of a context component
-
-.B NOTE: 
+.BR context_new ()
+returns a new context initialized to a context string.
+
+.BR context_str ()
+returns a pointer to the string value of the
+.BR context_t ,
+valid until the next call to
+.BR context_str ()
+or
+.BR context_free ()
+for the same
+.BR context_t* .
+
+.BR context_free ()
+frees the storage used by a context.
+
+.BR context_type_get (),
+.BR context_range_get (),
+.BR context_role_get (),
+.BR \%context_user_get ()
+get a pointer to the string value of a context component.
+
+.B Note:
 Values returned by the get functions are only valid until the next call 
-to a set function or context_free() for the same context_t structure.
-
-context_type_set, context_range_set, context_role_set, context_user_set
- Set a context component
-
+to a set function or
+.BR context_free ()
+for the same
+.B context_t
+structure.
+
+.BR context_type_set (),
+.BR context_range_set (),
+.BR context_role_set (),
+.BR \%context_user_set ()
+set a context component.
+.
 .SH "RETURN VALUE"
-On success, zero is returned. On failure, -1 is returned and errno is
-set appropriately.
+On failure
+.BR context_*_set ()
+functions return non-zero and 0 on success.
+
+The other functions return NULL on failure and non-NULL on success.
 
+On failure
+.I errno
+is set appropriately.
+.
 .SH "SEE ALSO"
 .BR selinux "(8)"
diff --git a/libselinux/man/man3/fgetfilecon_raw.3 b/libselinux/man/man3/fgetfilecon_raw.3
new file mode 100644
index 0000000..ae6dfcf
--- /dev/null
+++ b/libselinux/man/man3/fgetfilecon_raw.3
@@ -0,0 +1 @@
+.so man3/getfilecon.3
diff --git a/libselinux/man/man3/fsetfilecon_raw.3 b/libselinux/man/man3/fsetfilecon_raw.3
new file mode 100644
index 0000000..33c321a
--- /dev/null
+++ b/libselinux/man/man3/fsetfilecon_raw.3
@@ -0,0 +1 @@
+.so man3/setfilecon.3
diff --git a/libselinux/man/man3/get_ordered_context_list.3 b/libselinux/man/man3/get_ordered_context_list.3
index c3fa956..63cba81 100644
--- a/libselinux/man/man3/get_ordered_context_list.3
+++ b/libselinux/man/man3/get_ordered_context_list.3
@@ -1,10 +1,10 @@
 .TH "get_ordered_context_list" "3" "1 January 2004" "russell@coker.com.au" "SELinux"
 .SH "NAME"
 get_ordered_context_list, get_ordered_context_list_with_level, get_default_context, get_default_context_with_level, get_default_context_with_role, get_default_context_with_rolelevel, query_user_context, manual_user_enter_context, get_default_role \- determine SELinux context(s) for user sessions
-
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
-
+.br
 .B #include <selinux/get_context_list.h>
 .sp
 .BI "int get_ordered_context_list(const char *" user ", security_context_t "fromcon ", security_context_t **" list );
@@ -15,66 +15,94 @@ get_ordered_context_list, get_ordered_context_list_with_level, get_default_conte
 .sp
 .BI "int get_default_context_with_level(const char *" user ", const char *" level ", security_context_t "fromcon ", security_context_t *" newcon );
 .sp
-.BI "int get_default_context_with_role(const char* " user ", const char *" role ", security_context_t " fromcon ", security_context_t *" newcon ");
+.BI "int get_default_context_with_role(const char *" user ", const char *" role ", security_context_t " fromcon ", security_context_t *" newcon ");
 .sp
-.BI "int get_default_context_with_rolelevel(const char* " user ", const char* " level ", const char *" role ", security_context_t " fromcon ", security_context_t *" newcon ");
+.BI "int get_default_context_with_rolelevel(const char *" user ", const char *" level ", const char *" role ", security_context_t " fromcon ", security_context_t *" newcon ");
 .sp
 .BI "int query_user_context(security_context_t *" list ", security_context_t *" newcon );
 .sp
 .BI "int manual_user_enter_context(const char *" user ", security_context_t *" newcon );
 .sp
 .BI "int get_default_type(const char *" role ", char **" type );
-
+.
 .SH "DESCRIPTION"
-.B get_ordered_context_list
+.BR get_ordered_context_list ()
 invokes the 
-.B security_compute_user
+.BR security_compute_user (3)
 function to obtain the list of contexts for the specified
 .I user
 that are reachable from the specified
 .I fromcon
 context.  The function then orders the resulting list based on the global
-.B /etc/selinux/<SELINUXTYPE>/contexts/default_contexts
+.I \%/etc/selinux/{SELINUXTYPE}/contexts/default_contexts
 file and the per-user
-.B /etc/selinux/<SELINUXTYPE>/contexts/users/<username>
+.I \%/etc/selinux/{SELINUXTYPE}/contexts/users/<username>
 file if it exists.  The 
 .I fromcon
 parameter may be NULL to indicate that the current context should
 be used.  The function returns the number of contexts in the
-list, or -1 upon errors.  The list must be freed using the
-.B freeconary
+list, or \-1 upon errors.  The list must be freed using the
+.BR freeconary (3)
 function.
 
-.B get_ordered_context_list_with_level
-invokes the get_ordered_context_list function and applies the specified level.
+.BR get_ordered_context_list_with_level ()
+invokes the
+.BR \%get_ordered_context_list ()
+function and applies the specified level.
 
-.B get_default_context
-is the same as get_ordered_context_list but only returns a single context
-which has to be freed with freecon.
+.BR get_default_context ()
+is the same as
+.BR get_ordered_context_list ()
+but only returns a single context
+which has to be freed with
+.BR freecon (3).
 
-.B get_default_context_with_level
-invokes the get_default_context function and applies the specified level.
+.BR get_default_context_with_level ()
+invokes the
+.BR get_default_context ()
+function and applies the specified level.
 
-.B get_default_context_with_role
-is the same as get_default_context but only returns a context with the specified role, returning -1 if no such context is reachable for the user.
+.BR get_default_context_with_role ()
+is the same as
+.BR get_default_context ()
+but only returns a context with the specified role, returning \-1 if no
+such context is reachable for the user.
 
-.B get_default_context_with_rolelevel
-invokes the get_default_context_with_role function and applies the specified level.
+.BR get_default_context_with_rolelevel ()
+invokes the
+.BR \%get_default_context_with_role ()
+function and applies the specified level.
 
-.B query_user_context
+.BR query_user_context ()
 takes a list of contexts, queries the user via stdin/stdout as to which context
 they want, and returns a new context as selected by the user (which has to be
-freed with freecon).
+freed with
+.BR freecon (3)).
 
-.B manual_user_enter_context
-allows the user to manually enter a context as a fallback if a list of authorized contexts could not be obtained. Caller must free via freecon.
-
-.B get_default_type
-Get the default type (domain) for 'role' and set 'type' to refer to it, which has to be freed with free.
+.BR manual_user_enter_context ()
+allows the user to manually enter a context as a fallback if a list of
+authorized contexts could not be obtained. Caller must free via
+.BR freecon (3).
 
+.BR get_default_type ()
+Get the default type (domain) for
+.I role
+and set
+.I type
+to refer to it, which has to be freed with free.
+.
 .SH "RETURN VALUE"
-get_ordered_context_list and get_ordered_context_list_with_level return the number of contexts in the list upon success or -1 upon errors.
-The other functions return 0 for success or -1 for errors.
-
+.BR get_ordered_context_list ()
+and
+.BR get_ordered_context_list_with_level ()
+return the number of contexts in the list upon success or \-1 upon errors.
+The other functions return 0 for success or \-1 for errors.
+.
 .SH "SEE ALSO"
-.BR selinux "(8), " freeconary "(3), " freecon "(3), " security_compute_av "(3)", getseuserbyname"(3)"
+.ad l
+.nh
+.BR selinux (8),
+.BR freeconary (3),
+.BR freecon (3),
+.BR security_compute_av (3),
+.BR getseuserbyname (3)
diff --git a/libselinux/man/man3/getcon.3 b/libselinux/man/man3/getcon.3
index c620c51..239bb7d 100644
--- a/libselinux/man/man3/getcon.3
+++ b/libselinux/man/man3/getcon.3
@@ -1,78 +1,118 @@
 .TH "getcon" "3" "21 December 2011" "russell@coker.com.au" "SELinux API documentation"
 .SH "NAME"
-getcon, getprevcon, getpidcon \- get SELinux security context of a process.
+getcon, getprevcon, getpidcon \- get SELinux security context of a process
 
-freecon, freeconary \- free memory associated with SELinux security contexts.
+freecon, freeconary \- free memory associated with SELinux security contexts
 
-getpeercon - get security context of a peer socket.
+getpeercon \- get security context of a peer socket
 
-setcon - set current security context of a process.
+setcon \- set current security context of a process
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
 .BI "int getcon(security_context_t *" context );
-
+.sp
+.BI "int getcon_raw(security_context_t *" context );
+.sp
 .BI "int getprevcon(security_context_t *" context );
-
+.sp
+.BI "int getprevcon_raw(security_context_t *" context );
+.sp
 .BI "int getpidcon(pid_t " pid ", security_context_t *" context );
-
-.BI "int getpeercon(int " fd ", security_context_t *" context);
-
+.sp
+.BI "int getpidcon_raw(pid_t " pid ", security_context_t *" context );
+.sp
+.BI "int getpeercon(int " fd ", security_context_t *" context );
+.sp
+.BI "int getpeercon_raw(int " fd ", security_context_t *" context );
+.sp
 .BI "void freecon(security_context_t "con );
-
+.sp
 .BI "void freeconary(security_context_t *" con );
-
-.BI "int setcon(security_context_t " context);
-
+.sp
+.BI "int setcon(security_context_t " context );
+.sp
+.BI "int setcon_raw(security_context_t " context );
+.
 .SH "DESCRIPTION"
-.B getcon
+.BR getcon ()
 retrieves the context of the current process, which must be free'd with
 freecon.
 
-.B getprevcon
+.BR getprevcon ()
 same as getcon but gets the context before the last exec.
 
-.B getpidcon
+.BR getpidcon ()
 returns the process context for the specified PID.
 
-.B getpeercon
-retrieves context of peer socket, and set *context to refer to it, which must be free'd with freecon.
+.BR getpeercon ()
+retrieves context of peer socket, and set
+.BI * context
+to refer to it, which must be free'd with
+.BR freecon ().
 
-.B freecon
+.BR freecon ()
 frees the memory allocated for a security context.
 
-.B freeconary
+.BR freeconary ()
 frees the memory allocated for a context array.
 
 If
 .I con
 is NULL, no operation is performed.
 
-.B setcon
+.BR setcon ()
 sets the current security context of the process to a new value.  Note
 that use of this function requires that the entire application be
 trusted to maintain any desired separation between the old and new
 security contexts, unlike exec-based transitions performed via
-setexeccon(3).  When possible, decompose your application and use
-setexeccon() and execve() instead.
+.BR setexeccon (3).
+When possible, decompose your application and use
+.BR setexeccon (3)
+and
+.BR execve (3)
+instead.
 
 Since access to file descriptors is revalidated upon use by SELinux,
 the new context must be explicitly authorized in the policy to use the
 descriptors opened by the old context if that is desired.  Otherwise,
 attempts by the process to use any existing descriptors (including
-stdin, stdout, and stderr) after performing the setcon() will fail.
-
-A multi-threaded application can perform a setcon() prior to creating
+.IR stdin ,
+.IR stdout ,
+and
+.IR stderr )
+after performing the
+.BR setcon ()
+will fail.
+
+A multi-threaded application can perform a
+.BR setcon ()
+prior to creating
 any child threads, in which case all of the child threads will inherit
-the new context.  However, setcon() will fail if there are any other
+the new context.  However,
+.BR setcon ()
+will fail if there are any other
 threads running in the same process.
 
-If the process was being ptraced at the time of the setcon()
+If the process was being ptraced at the time of the
+.BR setcon ()
 operation, ptrace permission will be revalidated against the new
-context and the setcon() will fail if it is not allowed by policy.
-
+context and the
+.BR setcon ()
+will fail if it is not allowed by policy.
+
+.BR getcon_raw (),
+.BR getprevcon_raw (),
+.BR getpidcon_raw (),
+.BR getpeercon_raw ()
+and
+.BR setcon_raw ()
+behave identically to their non-raw counterparts but do not perform context
+translation.
+.
 .SH "RETURN VALUE"
-On error -1 is returned.  On success 0 is returned.
-
+On error \-1 is returned.  On success 0 is returned.
+.
 .SH "SEE ALSO"
 .BR selinux "(8), " setexeccon "(3)"
diff --git a/libselinux/man/man3/getcon_raw.3 b/libselinux/man/man3/getcon_raw.3
new file mode 100644
index 0000000..1210b5a
--- /dev/null
+++ b/libselinux/man/man3/getcon_raw.3
@@ -0,0 +1 @@
+.so man3/getcon.3
diff --git a/libselinux/man/man3/getexeccon.3 b/libselinux/man/man3/getexeccon.3
index 4b832a2..c188a3a 100644
--- a/libselinux/man/man3/getexeccon.3
+++ b/libselinux/man/man3/getexeccon.3
@@ -1,43 +1,68 @@
 .TH "getexeccon" "3" "1 January 2004" "russell@coker.com.au" "SELinux API documentation"
 .SH "NAME"
-getexeccon, setexeccon \- get or set the SELinux security context used for executing a new process.
+getexeccon, setexeccon \- get or set the SELinux security context used for executing a new process
 
 rpm_execcon \- run a helper for rpm in an appropriate security context
-
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
 .BI "int getexeccon(security_context_t *" context );
-
+.sp
+.BI "int getexeccon_raw(security_context_t *" context );
+.sp
 .BI "int setexeccon(security_context_t "context );
-
+.sp
+.BI "int setexeccon_raw(security_context_t "context );
+.sp
 .BI "int rpm_execcon(unsigned int " verified ", const char *" filename ", char *const " argv "[] , char *const " envp "[]);
-
+.
 .SH "DESCRIPTION"
-.B getexeccon
+.BR getexeccon ()
 retrieves the context used for executing a new process.
-This returned context should be freed with freecon if non-NULL.  
-getexeccon sets *con to NULL if no exec context has been explicitly 
+This returned context should be freed with
+.BR freecon (3)
+if non-NULL.
+.BR getexeccon ()
+sets
+.BI * context
+to NULL if no exec context has been explicitly
 set by the program (i.e. using the default policy behavior).
 
-.B setexeccon
-sets the context used for the next execve call.  
+.BR setexeccon ()
+sets the context used for the next
+.BR execve (2)
+call.
 NULL can be passed to
-setexeccon to reset to the default policy behavior.  
-The exec context is automatically reset after the next execve, so a
-program doesn't need to explicitly sanitize it upon startup.  
-
-
-setexeccon can be applied prior to library
-functions that internally perform an execve, e.g. execl*, execv*, popen,
+.BR setexeccon ()
+to reset to the default policy behavior.
+The exec context is automatically reset after the next
+.BR execve (2),
+so a program doesn't need to explicitly sanitize it upon startup.
+
+.BR setexeccon ()
+can be applied prior to library
+functions that internally perform an
+.BR execve (2),
+e.g.
+.BR execl *(3),
+.BR execv *(3),
+.BR popen (3),
 in order to set an exec context for that operation.  
 
+.BR getexeccon_raw ()
+and
+.BR setexeccon_raw ()
+behave identically to their non-raw counterparts but do not perform context
+translation.
 
-Note: Signal handlers that perform an execve must take care to
+.B Note:
+Signal handlers that perform an
+.BR execve (2)
+must take care to
 save, reset, and restore the exec context to avoid unexpected behavior.
 
-
-.B rpm_execcon
+.BR rpm_execcon ()
 runs a helper for rpm in an appropriate security context.  The
 verified parameter should contain the return code from the signature
 verification (0 == ok, 1 == notfound, 2 == verifyfail, 3 ==
@@ -46,15 +71,18 @@ the function.  The function determines the proper security context for
 the helper based on policy, sets the exec context accordingly, and
 then executes the specified filename with the provided argument and
 environment arrays.
-
-
+.
 .SH "RETURN VALUE"
-On error -1 is returned.
-
-On success getexeccon and setexeccon returns 0.
-rpm_execcon only returns upon errors, as it calls execve(2).
-
+On error \-1 is returned.
+
+On success
+.BR getexeccon ()
+and
+.BR setexeccon ()
+returns 0.
+.BR rpm_execcon ()
+only returns upon errors, as it calls
+.BR execve (2).
+.
 .SH "SEE ALSO"
 .BR selinux "(8), " freecon "(3), " getcon "(3)"
-
-
diff --git a/libselinux/man/man3/getexeccon_raw.3 b/libselinux/man/man3/getexeccon_raw.3
new file mode 100644
index 0000000..b2e6ab8
--- /dev/null
+++ b/libselinux/man/man3/getexeccon_raw.3
@@ -0,0 +1 @@
+.so man3/getexeccon.3
diff --git a/libselinux/man/man3/getfilecon.3 b/libselinux/man/man3/getfilecon.3
index 61b216f..ea79b31 100644
--- a/libselinux/man/man3/getfilecon.3
+++ b/libselinux/man/man3/getfilecon.3
@@ -1,42 +1,72 @@
 .TH "getfilecon" "3" "1 January 2004" "russell@coker.com.au" "SELinux API documentation"
 .SH "NAME"
 getfilecon, fgetfilecon, lgetfilecon \- get SELinux security context of a file
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
 .BI "int getfilecon(const char *" path ", security_context_t *" con );
-
+.sp
+.BI "int getfilecon_raw(const char *" path ", security_context_t *" con );
+.sp
 .BI "int lgetfilecon(const char *" path ", security_context_t *" con );
-
+.sp
+.BI "int lgetfilecon_raw(const char *" path ", security_context_t *" con );
+.sp
 .BI "int fgetfilecon(int "fd ", security_context_t *" con );
+.sp
+.BI "int fgetfilecon_raw(int "fd ", security_context_t *" con );
+.
 .SH "DESCRIPTION"
-.B getfilecon
+.BR getfilecon ()
 retrieves the context associated with the given path in the file system, the
 length of the context is returned.
 
-.B lgetfilecon
-is identical to getfilecon, except in the case of a symbolic link, where the
+.BR lgetfilecon ()
+is identical to
+.BR getfilecon (),
+except in the case of a symbolic link, where the
 link itself is interrogated, not the file that it refers to.
 
-.B fgetfilecon
-is identical to getfilecon, only the open file pointed to by filedes (as
-returned by open(2)) is interrogated in place of path.
+.BR fgetfilecon ()
+is identical to
+.BR getfilecon (),
+only the open file pointed to by filedes (as returned by
+.BR open (2))
+is interrogated in place of path.
 
+.BR getfilecon_raw (),
+.BR lgetfilecon_raw ()
+and
+.BR fgetfilecon_raw ()
+behave identically to their non-raw counterparts but do not perform context
+translation.
 
-The returned context should be freed with freecon if non-NULL.  
+The returned context should be freed with
+.BR freecon (3)
+if non-NULL.
+.
 .SH "RETURN VALUE"
 On success, a positive number is returned indicating the size of the
-extended attribute value. On failure, \-1 is returned and errno is  set
-appropriately.
+extended attribute value. On failure, \-1 is returned and
+.I errno
+is  set appropriately.
 
 If the context does not exist, or the process has no access to
-this attribute, errno is set to ENODATA.
-
-If extended attributes are not supported by the filesystem, or are dis\-
-abled, errno is set to ENOTSUP.
+this attribute,
+.I errno
+is set to
+.BR ENODATA .
 
-The errors documented for the stat(2) system call are also applicable
-here.
+If extended attributes are not supported by the filesystem, or are
+disabled,
+.I errno
+is set to
+.BR ENOTSUP .
 
+The errors documented for the
+.BR stat (2)
+system call are also applicable here.
+.
 .SH "SEE ALSO"
 .BR selinux "(8), " freecon "(3), " setfilecon "(3), " setfscreatecon "(3)"
diff --git a/libselinux/man/man3/getfilecon_raw.3 b/libselinux/man/man3/getfilecon_raw.3
new file mode 100644
index 0000000..ae6dfcf
--- /dev/null
+++ b/libselinux/man/man3/getfilecon_raw.3
@@ -0,0 +1 @@
+.so man3/getfilecon.3
diff --git a/libselinux/man/man3/getfscreatecon.3 b/libselinux/man/man3/getfscreatecon.3
index 474aa28..c7675be 100644
--- a/libselinux/man/man3/getfscreatecon.3
+++ b/libselinux/man/man3/getfscreatecon.3
@@ -1,38 +1,57 @@
 .TH "getfscreatecon" "3" "1 January 2004" "russell@coker.com.au" "SELinux API documentation"
 .SH "NAME"
-getfscreatecon, setfscreatecon \- get or set the SELinux security context used for creating a new file system object.
-
+getfscreatecon, setfscreatecon \- get or set the SELinux security context used for creating a new file system object
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
 .BI "int getfscreatecon(security_context_t *" con );
-
+.sp
+.BI "int getfscreatecon_raw(security_context_t *" con );
+.sp
 .BI "int setfscreatecon(security_context_t "context );
-
+.sp
+.BI "int setfscreatecon_raw(security_context_t "context );
+.
 .SH "DESCRIPTION"
-.B getfscreatecon
+.BR getfscreatecon ()
 retrieves the context used for creating a new file system object.
-This returned context should be freed with freecon if non-NULL.  
-getfscreatecon sets *con to NULL if no fscreate context has been explicitly 
+This returned context should be freed with
+.BR freecon (3)
+if non-NULL.
+.BR getfscreatecon ()
+sets *con to NULL if no fscreate context has been explicitly
 set by the program (i.e. using the default policy behavior).
 
-.B setfscreatecon
+.BR setfscreatecon ()
 sets the context used for creating a new file system object.
 NULL can be passed to
-setfscreatecon to reset to the default policy behavior.  
-The fscreate context is automatically reset after the next execve, so a
-program doesn't need to explicitly sanitize it upon startup.  
-
-setfscreatecon can be applied prior to library
+.BR setfscreatecon ()
+to reset to the default policy behavior.
+The fscreate context is automatically reset after the next
+.BR execve (2),
+so a program doesn't need to explicitly sanitize it upon startup.
+
+.BR setfscreatecon ()
+can be applied prior to library
 functions that internally perform an file creation,
 in order to set an file context on the objects.
 
+.BR getfscreatecon_raw ()
+and
+.BR setfscreatecon_raw ()
+behave identically to their non-raw counterparts but do not perform context
+translation.
 
-Note: Signal handlers that perform an setfscreate must take care to
+.B Note:
+Signal handlers that perform a
+.BR setfscreatecon ()
+must take care to
 save, reset, and restore the fscreate context to avoid unexpected behavior.
+.
 .SH "RETURN VALUE"
-On error -1 is returned.
+On error \-1 is returned.
 On success 0 is returned.
-
+.
 .SH "SEE ALSO"
 .BR selinux "(8), " freecon "(3), " getcon "(3), " getexeccon "(3)"
diff --git a/libselinux/man/man3/getfscreatecon_raw.3 b/libselinux/man/man3/getfscreatecon_raw.3
new file mode 100644
index 0000000..21aeebd
--- /dev/null
+++ b/libselinux/man/man3/getfscreatecon_raw.3
@@ -0,0 +1 @@
+.so man3/getfscreatecon.3
diff --git a/libselinux/man/man3/getkeycreatecon.3 b/libselinux/man/man3/getkeycreatecon.3
index 3b594a0..d6a118c 100644
--- a/libselinux/man/man3/getkeycreatecon.3
+++ b/libselinux/man/man3/getkeycreatecon.3
@@ -1,38 +1,57 @@
-.TH "getkeycreatecon" "3" "9 September 2008" "dwalsh@redhat.com from russell@coker.com.au" "SELinux API documentation"
+.TH "getkeycreatecon" "3" "9 September 2008" "dwalsh@redhat.com" "SELinux API documentation"
 .SH "NAME"
-getkeycreatecon, setkeycreatecon \- get or set the SELinux security context used for creating a new kernel keyrings.
-
+getkeycreatecon, setkeycreatecon \- get or set the SELinux security context used for creating a new kernel keyrings
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
 .BI "int getkeycreatecon(security_context_t *" con );
-
+.sp
+.BI "int getkeycreatecon_raw(security_context_t *" con );
+.sp
 .BI "int setkeycreatecon(security_context_t "context );
-
+.sp
+.BI "int setkeycreatecon_raw(security_context_t "context );
+.
 .SH "DESCRIPTION"
-.B getkeycreatecon
+.BR getkeycreatecon ()
 retrieves the context used for creating a new kernel keyring.
-This returned context should be freed with freecon if non-NULL.  
-getkeycreatecon sets *con to NULL if no keycreate context has been explicitly 
+This returned context should be freed with
+.BR freecon (3)
+if non-NULL.
+.BR getkeycreatecon ()
+sets *con to NULL if no keycreate context has been explicitly
 set by the program (i.e. using the default policy behavior).
 
-.B setkeycreatecon
+.BR setkeycreatecon ()
 sets the context used for creating a new kernel keyring.
 NULL can be passed to
-setkeycreatecon to reset to the default policy behavior.  
-The keycreate context is automatically reset after the next execve, so a
-program doesn't need to explicitly sanitize it upon startup.  
-
-setkeycreatecon can be applied prior to library
+.BR setkeycreatecon ()
+to reset to the default policy behavior.
+The keycreate context is automatically reset after the next
+.BR execve (2),
+so a program doesn't need to explicitly sanitize it upon startup.
+
+.BR setkeycreatecon ()
+can be applied prior to library
 functions that internally perform an file creation,
 in order to set an file context on the objects.
 
+.BR getkeycreatecon_raw ()
+and
+.BR setkeycreatecon_raw ()
+behave identically to their non-raw counterparts but do not perform context
+translation.
 
-Note: Signal handlers that perform an setkeycreate must take care to
+.B Note:
+Signal handlers that perform a
+.BR setkeycreatecon ()
+must take care to
 save, reset, and restore the keycreate context to avoid unexpected behavior.
+.
 .SH "RETURN VALUE"
-On error -1 is returned.
+On error \-1 is returned.
 On success 0 is returned.
-
+.
 .SH "SEE ALSO"
 .BR selinux "(8), " freecon "(3), " getcon "(3), " getexeccon "(3)"
diff --git a/libselinux/man/man3/getkeycreatecon_raw.3 b/libselinux/man/man3/getkeycreatecon_raw.3
new file mode 100644
index 0000000..1e0ec5f
--- /dev/null
+++ b/libselinux/man/man3/getkeycreatecon_raw.3
@@ -0,0 +1 @@
+.so man3/getkeycreatecon.3
diff --git a/libselinux/man/man3/getpeercon_raw.3 b/libselinux/man/man3/getpeercon_raw.3
new file mode 100644
index 0000000..1210b5a
--- /dev/null
+++ b/libselinux/man/man3/getpeercon_raw.3
@@ -0,0 +1 @@
+.so man3/getcon.3
diff --git a/libselinux/man/man3/getpidcon_raw.3 b/libselinux/man/man3/getpidcon_raw.3
new file mode 100644
index 0000000..1210b5a
--- /dev/null
+++ b/libselinux/man/man3/getpidcon_raw.3
@@ -0,0 +1 @@
+.so man3/getcon.3
diff --git a/libselinux/man/man3/getprevcon_raw.3 b/libselinux/man/man3/getprevcon_raw.3
new file mode 100644
index 0000000..1210b5a
--- /dev/null
+++ b/libselinux/man/man3/getprevcon_raw.3
@@ -0,0 +1 @@
+.so man3/getcon.3
diff --git a/libselinux/man/man3/getseuserbyname.3 b/libselinux/man/man3/getseuserbyname.3
index 1630356..c231e65 100644
--- a/libselinux/man/man3/getseuserbyname.3
+++ b/libselinux/man/man3/getseuserbyname.3
@@ -1,28 +1,33 @@
 .TH "getseuserbyname" "3" "29 September 2005" "dwalsh@redhat.com" "SELinux API documentation"
 .SH "NAME"
 getseuserbyname \- get SELinux username and level for a given Linux username
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
 .BI "int getseuserbyname(const char *" linuxuser ", char **" selinuxuser ", char **" level ");
+.
 .SH "DESCRIPTION"
-.B getseuserbyname
+.BR getseuserbyname ()
 retrieves the SELinux username and security level associated with 
 a given Linux username.  The SELinux username and security level can
 then be passed to other libselinux functions such as 
-get_ordered_context_list_with_level and get_default_context_with_level.
-
-
+.BR \%get_ordered_context_list_with_level (3)
+and
+.BR \%get_default_context_with_level (3).
 
 The returned SELinux username and level should be freed by the caller
 using free.  
+.
 .SH "RETURN VALUE"
 On success, 0 is returned.
-On failure, \-1 is returned and errno is set appropriately.
-
-The errors documented for the stat(2) system call are also applicable
-here.
+On failure, \-1 is returned and
+.I errno
+is set appropriately.
 
+The errors documented for the
+.BR stat (2)
+system call are also applicable here.
+.
 .SH "SEE ALSO"
 .BR selinux "(8)"
-
diff --git a/libselinux/man/man3/getsockcreatecon.3 b/libselinux/man/man3/getsockcreatecon.3
index 24f2cc0..99e9436 100644
--- a/libselinux/man/man3/getsockcreatecon.3
+++ b/libselinux/man/man3/getsockcreatecon.3
@@ -1,38 +1,57 @@
-.TH "getsockcreatecon" "3" "24 September 2008" "dwalsh@redhat.com from russell@coker.com.au" "SELinux API documentation"
+.TH "getsockcreatecon" "3" "24 September 2008" "dwalsh@redhat.com" "SELinux API documentation"
 .SH "NAME"
-getsockcreatecon, setsockcreatecon \- get or set the SELinux security context used for creating a new labeled sockets.
-
+getsockcreatecon, setsockcreatecon \- get or set the SELinux security context used for creating a new labeled sockets
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
 .BI "int getsockcreatecon(security_context_t *" con );
-
+.sp
+.BI "int getsockcreatecon_raw(security_context_t *" con );
+.sp
 .BI "int setsockcreatecon(security_context_t "context );
-
+.sp
+.BI "int setsockcreatecon_raw(security_context_t "context );
+.
 .SH "DESCRIPTION"
-.B getsockcreatecon
+.BR getsockcreatecon ()
 retrieves the context used for creating a new labeled network socket.
-This returned context should be freed with freecon if non-NULL.  
-getsockcreatecon sets *con to NULL if no sockcreate context has been explicitly 
+This returned context should be freed with
+.BR freecon (3)
+if non-NULL.
+.BR getsockcreatecon ()
+sets *con to NULL if no sockcreate context has been explicitly
 set by the program (i.e. using the default policy behavior).
 
-.B setsockcreatecon
+.BR setsockcreatecon ()
 sets the context used for creating a new labeled network sockets
 NULL can be passed to
-setsockcreatecon to reset to the default policy behavior.  
-The sockcreate context is automatically reset after the next execve, so a
-program doesn't need to explicitly sanitize it upon startup.  
-
-setsockcreatecon can be applied prior to library
+.BR setsockcreatecon ()
+to reset to the default policy behavior.
+The sockcreate context is automatically reset after the next
+.BR execve (2),
+so a program doesn't need to explicitly sanitize it upon startup.
+
+.BR setsockcreatecon ()
+can be applied prior to library
 functions that internally perform an file creation,
 in order to set an file context on the objects.
 
+.BR getsockcreatecon_raw ()
+and
+.BR setsockcreatecon_raw ()
+behave identically to their non-raw counterparts but do not perform context
+translation.
 
-Note: Signal handlers that perform an setsockcreate must take care to
+.B Note:
+Signal handlers that perform a
+.BR setsockcreatecon ()
+must take care to
 save, reset, and restore the sockcreate context to avoid unexpected behavior.
+.
 .SH "RETURN VALUE"
-On error -1 is returned.
+On error \-1 is returned.
 On success 0 is returned.
-
+.
 .SH "SEE ALSO"
 .BR selinux "(8), " freecon "(3), " getcon "(3)
diff --git a/libselinux/man/man3/getsockcreatecon_raw.3 b/libselinux/man/man3/getsockcreatecon_raw.3
new file mode 100644
index 0000000..ed1a371
--- /dev/null
+++ b/libselinux/man/man3/getsockcreatecon_raw.3
@@ -0,0 +1 @@
+.so man3/getsockcreatecon.3
diff --git a/libselinux/man/man3/init_selinuxmnt.3 b/libselinux/man/man3/init_selinuxmnt.3
index e70098b..8466f9f 100644
--- a/libselinux/man/man3/init_selinuxmnt.3
+++ b/libselinux/man/man3/init_selinuxmnt.3
@@ -1,28 +1,31 @@
 .TH "init_selinuxmnt" "3" "21 Nov 2009" "" "SELinux API documentation"
 .SH "NAME"
-init_selinuxmnt \- initialize the global variable selinux_mnt.
-
+init_selinuxmnt \- initialize the global variable selinux_mnt
+.
 .SH "SYNOPSIS"
 .BI "static void init_selinuxmnt(void);"
 .sp
 .BI "static void fini_selinuxmnt(void);"
 .sp
 .BI "void set_selinuxmnt(char *" mnt ");"
-
+.
 .SH "DESCRIPTION"
-.B init_selinuxmnt 
-initializes the global variable selinux_mnt to the selinuxfs mountpoint.
+.BR init_selinuxmnt ()
+initializes the global variable
+.I selinux_mnt
+to the selinuxfs mountpoint.
 
-.B fini_selinuxmnt
-deinitializes the global variable selinux_mnt that stores the selinuxfs
-mountpoint.
+.BR fini_selinuxmnt ()
+deinitializes the global variable
+.I selinux_mnt
+that stores the selinuxfs mountpoint.
 
-.B set_selinuxmnt
+.BR set_selinuxmnt ()
 changes the selinuxfs mountpoint to
-.I mnt. 
-
+.IR mnt .
+.
 .SH "AUTHOR"
 This manual page has been written by Guido Trentalancia <guido@trentalancia.com>
-
+.
 .SH "SEE ALSO"
 .BR selinux (8),
diff --git a/libselinux/man/man3/is_context_customizable.3 b/libselinux/man/man3/is_context_customizable.3
index d230ace..0f748b6 100644
--- a/libselinux/man/man3/is_context_customizable.3
+++ b/libselinux/man/man3/is_context_customizable.3
@@ -1,25 +1,24 @@
 .TH "is_context_customizable" "3" "10 January 2005" "dwalsh@redhat.com" "SELinux API documentation"
 .SH "NAME"
-is_context_customizable \- check whether SELinux context type is customizable by the administrator.
+is_context_customizable \- check whether SELinux context type is customizable by the administrator
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
-.B int is_context_customizable(security_context_t scon);
-
+.BI "int is_context_customizable(security_context_t " scon );
+.
 .SH "DESCRIPTION"
-.B is_context_customizable
-
-This function checks whether the type of scon is in the /etc/selinux/SELINUXTYPE/context/customizable_types file.  A customizable type is a file context type that
+This function checks whether the type of scon is in the
+.I /etc/selinux/{SELINUXTYPE}/context/customizable_types
+file.  A customizable type is a file context type that
 administrators set on files, usually to allow certain domains to share the file content. restorecon and setfiles, by default, leave these context in place.
-
- 
+.
 .SH "RETURN VALUE"
-returns 1 if security context is customizable or 0 if it is not. 
-returns -1 on error
-
+Returns 1 if security context is customizable or 0 if it is not.
+Returns \-1 on error.
+.
 .SH "FILE"
-/etc/selinux/SELINUXTYPE/context/customizable_types
-
+.I /etc/selinux/{SELINUXTYPE}/context/customizable_types
+.
 .SH "SEE ALSO"
 .BR selinux "(8)"
-
diff --git a/libselinux/man/man3/is_selinux_enabled.3 b/libselinux/man/man3/is_selinux_enabled.3
index d744c0b..f02052c 100644
--- a/libselinux/man/man3/is_selinux_enabled.3
+++ b/libselinux/man/man3/is_selinux_enabled.3
@@ -1,24 +1,24 @@
 .TH "is_selinux_enabled" "3" "7 Mar 2010" "russell@coker.com.au" "SELinux API documentation"
 .SH "NAME"
 is_selinux_enabled \- check whether SELinux is enabled
-
+.
 .SH "NAME"
 is_selinux_mls_enabled \- check whether SELinux is enabled for (Multi Level Securty) MLS 
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
 .B int is_selinux_enabled();
-
+.sp
 .B int is_selinux_mls_enabled();
-
+.
 .SH "DESCRIPTION"
-.B is_selinux_enabled
+.BR is_selinux_enabled ()
 returns 1 if SELinux is running or 0 if it is not. 
 On error, \-1 is returned.
 
-.B is_selinux_mls_enabled
+.BR is_selinux_mls_enabled ()
 returns 1 if SELinux is running in MLS mode or 0 if it is not. 
-
+.
 .SH "SEE ALSO"
 .BR selinux "(8)"
-
diff --git a/libselinux/man/man3/lgetfilecon_raw.3 b/libselinux/man/man3/lgetfilecon_raw.3
new file mode 100644
index 0000000..ae6dfcf
--- /dev/null
+++ b/libselinux/man/man3/lgetfilecon_raw.3
@@ -0,0 +1 @@
+.so man3/getfilecon.3
diff --git a/libselinux/man/man3/lsetfilecon_raw.3 b/libselinux/man/man3/lsetfilecon_raw.3
new file mode 100644
index 0000000..33c321a
--- /dev/null
+++ b/libselinux/man/man3/lsetfilecon_raw.3
@@ -0,0 +1 @@
+.so man3/setfilecon.3
diff --git a/libselinux/man/man3/matchmediacon.3 b/libselinux/man/man3/matchmediacon.3
index 1a3a561..f77ab5e 100644
--- a/libselinux/man/man3/matchmediacon.3
+++ b/libselinux/man/man3/matchmediacon.3
@@ -1,26 +1,30 @@
 .TH "matchmediacon" "3" "15 November 2004" "dwalsh@redhat.com" "SELinux API documentation"
 .SH "NAME"
-matchmediacon \- get the default SELinux security context for the specified mediatype from the policy.
-
+matchmediacon \- get the default SELinux security context for the specified mediatype from the policy
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
-.BI "int matchmediacon(const char *" media ", security_context_t *" con);"
-
-
+.BI "int matchmediacon(const char *" media ", security_context_t *" con );
+.
 .SH "DESCRIPTION"
-
-.B matchmediacon 
-matches the specified media type with the media contexts configuration and sets the security context "con" to refer to the resulting context. 
+.BR matchmediacon ()
+matches the specified media type with the media contexts configuration and
+sets the security context
+.I con
+to refer to the resulting context.
 .sp
-
-.B Note: 
-   Caller must free returned security context "con" using freecon.
+.B Note:
+Caller must free returned security context
+.I con
+using
+.BR freecon (3).
+.
 .SH "RETURN VALUE"
-Returns 0 on success or -1 otherwise.
-
+Returns 0 on success or \-1 otherwise.
+.
 .SH Files
-/etc/selinux/POLICYTYPE/contexts/files/media
-
+.I /etc/selinux/{POLICYTYPE}/contexts/files/media
+.
 .SH "SEE ALSO"
 .BR selinux "(8), " freecon "(3)
diff --git a/libselinux/man/man3/matchpathcon.3 b/libselinux/man/man3/matchpathcon.3
index cdbb252..4c320ab 100644
--- a/libselinux/man/man3/matchpathcon.3
+++ b/libselinux/man/man3/matchpathcon.3
@@ -1,65 +1,59 @@
 .TH "matchpathcon" "3" "21 November 2009" "sds@tycho.nsa.gov" "SELinux API documentation"
 .SH "NAME"
-matchpathcon, matchpathcon_index \- get the default SELinux security context for the specified path from the file contexts configuration.
-
+matchpathcon, matchpathcon_index \- get the default SELinux security context for the specified path from the file contexts configuration
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
-
 .BI "int matchpathcon_init(const char *" path ");"
-
+.sp
 .BI "int matchpathcon_init_prefix(const char *" path ", const char *" subset ");"
-
+.sp
 .BI "int matchpathcon_fini(void);"
 .sp
-
 .BI "int matchpathcon(const char *" path ", mode_t " mode ", security_context_t *" con ");
 .sp
-
-.BI "int matchpathcon_index(const char *" name ", mode_t " mode ", security_context_t * " con ");"
-
+.BI "int matchpathcon_index(const char *" name ", mode_t " mode ", security_context_t *" con ");"
+.
 .SH "DESCRIPTION"
-.B matchpathcon_init
+.BR matchpathcon_init ()
 loads the file contexts configuration specified by
 .I path
 into memory for use by subsequent 
-.B matchpathcon 
+.BR matchpathcon ()
 calls.  If
 .I path
 is NULL, then the active file contexts configuration is loaded by default,
 i.e. the path returned by 
-.B selinux_file_context_path(3).
+.BR selinux_file_context_path (3).
 Unless the 
 .B MATCHPATHCON_BASEONLY 
 flag has been set via 
-.B set_matchpathcon_flags(3),
+.BR \%set_matchpathcon_flags (3),
 files with the same path prefix but a 
-.B .homedirs
+.B \%.homedirs
 and
 .B .local
 suffix are also looked up and loaded if present.  These files provide
 dynamically generated entries for user home directories and for local
 customizations.
 
-.sp
-.B matchpathcon_init_prefix
+.BR matchpathcon_init_prefix ()
 is the same as
-.B matchpathcon_init
+.BR matchpathcon_init ()
 but only loads entries with regular expressions that have stems prefixed
 by
-.I prefix.
+.I \%prefix.
 
-.sp
-.B matchpathcon_fini
+.BR matchpathcon_fini ()
 frees the memory allocated by a prior call to
-.B matchpathcon_init.
+.BR matchpathcon_init. ()
 This function can be used to free and reset the internal state between multiple 
-.B matchpathcon_init 
+.BR matchpathcon_init ()
 calls, or to free memory when finished using 
-.B matchpathcon.
+.BR matchpathcon ().
 
-.sp
-.B matchpathcon 
+.BR matchpathcon ()
 matches the specified pathname and mode against the file contexts
 configuration and sets the security context 
 .I con 
@@ -67,7 +61,7 @@ to refer to the
 resulting context. The caller must free the returned security context 
 .I con
 using
-.B freecon(3)
+.BR freecon (3)
 when finished using it.
 .I mode
 can be 0 to disable mode matching, but
@@ -76,23 +70,23 @@ Only the file format bits (i.e. the file type) of the
 .I mode 
 are used.
 If 
-.B matchpathcon_init
+.BR matchpathcon_init ()
 has not already been called, then this function will call it upon
 its first invocation with a NULL
 .I path,
 defaulting to the active file contexts configuration.
-.sp
 
-.B matchpathcon_index
+.BR matchpathcon_index ()
 is the same as
-.B matchpathcon
+.BR matchpathcon ()
 but returns a specification index that can later be used in a
-.B matchpathcon_filespec_add(3)
+.BR matchpathcon_filespec_add (3)
 call.
-.sp
-
+.
 .SH "RETURN VALUE"
 Returns zero on success or \-1 otherwise.
-
+.
 .SH "SEE ALSO"
+.ad l
+.nh
 .BR selinux "(8), " set_matchpathcon_flags "(3), " set_matchpathcon_invalidcon "(3), " set_matchpathcon_printf "(3), " matchpathcon_filespec_add "(3), " matchpathcon_checkmatches "(3), " freecon "(3), " setfilecon "(3), " setfscreatecon "(3)"
diff --git a/libselinux/man/man3/matchpathcon_checkmatches.3 b/libselinux/man/man3/matchpathcon_checkmatches.3
index 47ee94c..6bbee44 100644
--- a/libselinux/man/man3/matchpathcon_checkmatches.3
+++ b/libselinux/man/man3/matchpathcon_checkmatches.3
@@ -1,33 +1,30 @@
 .TH "matchpathcon_checkmatches" "3" "21 November 2009" "sds@tycho.nsa.gov" "SELinux API documentation"
 .SH "NAME"
-matchpathcon_checkmatches, matchpathcon_filespec_add, matchpathcon_filespec_destroy, matchpathcon_filespec_eval \- check and report whether any specification index has no matches with any inode. Maintenance and statistics on inode associations.
-
+matchpathcon_checkmatches, matchpathcon_filespec_add, matchpathcon_filespec_destroy, matchpathcon_filespec_eval \- check and report whether any specification index has no matches with any inode. Maintenance and statistics on inode associations
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
-
 .BI "void matchpathcon_checkmatches(char *" str ");"
 .sp
-
 .BI "int matchpathcon_filespec_add(ino_t " ino ", int " specind ", const char *" file ");"
-
+.sp
 .BI "void matchpathcon_filespec_destroy(void);"
-
+.sp
 .BI "void matchpathcon_filespec_eval(void);"
-
+.
 .SH "DESCRIPTION"
-.B matchpathcon_checkmatches
+.BR matchpathcon_checkmatches ()
 checks whether any specification has no matches and reports them.
 The
 .I str
 argument is used as a prefix for any warning messages.
 .sp
-
-.B matchpathcon_filespec_add
+.BR matchpathcon_filespec_add ()
 maintains an association between an inode
 .I ino
 and a specification index
-.I specind,
+.IR specind ,
 and checks whether a conflicting specification is already associated
 with the same inode (e.g. due to multiple hard links). If so, then
 it uses the latter of the two specifications based on their order in the 
@@ -35,18 +32,17 @@ it uses the latter of the two specifications based on their order in the
 context configuration. Returns the specification index used or \-1 on
 error.
 .sp
-
-.B matchpathcon_filespec_destroy
+.BR matchpathcon_filespec_destroy ()
 destroys any inode associations that have been added, e.g. to restart
 for a new filesystem.
 .sp
-
-.B matchpathcon_filespec_eval
+.BR matchpathcon_filespec_eval ()
 displays statistics on the hash table usage for the inode associations.
-
-.sp
+.
 .SH "RETURN VALUE"
 Returns zero on success or \-1 otherwise.
-
+.
 .SH "SEE ALSO"
+.ad l
+.nh
 .BR selinux "(8), " matchpathcon "(3), " matchpathcon_index "(3), " freecon "(3), " setfilecon "(3), " setfscreatecon "(3)"
diff --git a/libselinux/man/man3/mode_to_security_class.3 b/libselinux/man/man3/mode_to_security_class.3
new file mode 100644
index 0000000..bda9daf
--- /dev/null
+++ b/libselinux/man/man3/mode_to_security_class.3
@@ -0,0 +1 @@
+.so man3/security_class_to_string.3
diff --git a/libselinux/man/man3/security_check_context.3 b/libselinux/man/man3/security_check_context.3
index af55f06..7ba4ead 100644
--- a/libselinux/man/man3/security_check_context.3
+++ b/libselinux/man/man3/security_check_context.3
@@ -1,16 +1,23 @@
 .TH "security_check_context" "3" "1 January 2004" "russell@coker.com.au" "SELinux API documentation"
 .SH "NAME"
 security_check_context \- check the validity of a SELinux context
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
 .BI "int security_check_context(security_context_t "con );
-
+.sp
+.BI "int security_check_context_raw(security_context_t "con );
+.
 .SH "DESCRIPTION"
-.B security_check_context
+.BR security_check_context ()
 returns 0 if SELinux is running and the context is valid, otherwise it
-returns -1.
+returns \-1.
 
+.BR security_check_context_raw ()
+behaves identically to
+.BR \%security_check_context ()
+but does not perform context translation.
+.
 .SH "SEE ALSO"
 .BR selinux "(8)"
-
diff --git a/libselinux/man/man3/security_check_context_raw.3 b/libselinux/man/man3/security_check_context_raw.3
new file mode 100644
index 0000000..ee93986
--- /dev/null
+++ b/libselinux/man/man3/security_check_context_raw.3
@@ -0,0 +1 @@
+.so man3/security_check_context.3
diff --git a/libselinux/man/man3/security_class_to_string.3 b/libselinux/man/man3/security_class_to_string.3
index 140737e..0e9f01d 100644
--- a/libselinux/man/man3/security_class_to_string.3
+++ b/libselinux/man/man3/security_class_to_string.3
@@ -3,42 +3,44 @@
 .\" Author: Eamon Walsh (ewalsh@tycho.nsa.gov) 2007
 .TH "security_class_to_string" "3" "30 Mar 2007" "" "SELinux API documentation"
 .SH "NAME"
-security_class_to_string, security_av_perm_to_string, string_to_security_class, string_to_av_perm, security_av_string \- convert
+security_class_to_string, security_av_perm_to_string, string_to_security_class, string_to_av_perm, security_av_string, mode_to_security_class \- convert
 between SELinux class and permission values and string names.
-
+.
 print_access_vector \- display an access vector in human-readable form. 
-
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
-
+.br
 .B #include <selinux/flask.h>
 .sp
-.BI "const char * security_class_to_string(security_class_t " tclass ");"
+.BI "const char *security_class_to_string(security_class_t " tclass ");"
 .sp
-.BI "const char * security_av_perm_to_string(security_class_t " tclass ", access_vector_t " av ");"
+.BI "const char *security_av_perm_to_string(security_class_t " tclass ", access_vector_t " av ");"
 .sp
 .BI "int security_av_string(security_class_t " tclass ", access_vector_t " av ", char **" result ");"
 .sp
 .BI "security_class_t string_to_security_class(const char *" name ");"
 .sp
+.BI "security_class_t mode_to_security_class(mode_t " mode ");"
+.sp
 .BI "access_vector_t string_to_av_perm(security_class_t " tclass ", const char *" name ");"
 .sp
 .BI "void print_access_vector(security_class_t " tclass ", access_vector_t " av ");"
-
+.
 .SH "DESCRIPTION"
-.B security_class_to_string
+.BR security_class_to_string ()
 returns a string name for class
 .IR tclass ,
 or NULL if the class is invalid.  The returned string must not be modified or freed.
 
-.B security_av_perm_to_string
+.BR security_av_perm_to_string ()
 returns a string name for the access vector bit
 .I av
 of class
 .IR tclass ,
 or NULL if either argument is invalid.  The returned string must not be modified or freed.
 
-.B security_av_string
+.BR security_av_string ()
 computes a full access vector string representation using
 .I tclass
 and
@@ -48,30 +50,35 @@ which may have multiple bits set.  The string is returned in the memory pointed
 and should be freed by the caller using
 .BR free (3).
 
-.B string_to_security_class
+.BR string_to_security_class ()
 returns the class value corresponding to the string name
 .IR name ,
 or zero if no such class exists.
 
-.B string_to_av_perm
+.BR mode_to_security_class ()
+returns the class value corresponding to the specified 
+.IR mode ,
+or zero if no such class exists.
+
+.BR string_to_av_perm ()
 returns the access vector bit corresponding to the string name
 .I name
 and security class
 .IR tclass ,
 or zero if no such value exists.
 
-.B print_access_vector
+.BR print_access_vector ()
 displays an access vector in human-readable form on the standard output
 stream.
-
+.
 .SH "RETURN VALUE"
-.B security_av_string
+.BR security_av_string ()
 returns zero on success or \-1 on error with
 .I errno
 set appropriately.
-.B print_access_vector
+.BR print_access_vector ()
 does not return a value. All other functions return zero or NULL on error.
-
+.
 .SH "ERRORS"
 .TP
 .B EINVAL
@@ -80,11 +87,12 @@ A class or access vector argument is not recognized by the currently loaded poli
 .TP
 .B ENOMEM
 An attempt to allocate memory failed.
-
+.
 .SH "AUTHOR"
 Eamon Walsh <ewalsh@tycho.nsa.gov>
-
+.
 .SH "SEE ALSO"
 .BR selinux (8),
 .BR getcon (3),
 .BR getfilecon (3)
+.BR stat (3)
diff --git a/libselinux/man/man3/security_compute_av.3 b/libselinux/man/man3/security_compute_av.3
index 468831a..c6837fc 100644
--- a/libselinux/man/man3/security_compute_av.3
+++ b/libselinux/man/man3/security_compute_av.3
@@ -2,112 +2,139 @@
 .SH "NAME"
 security_compute_av, security_compute_av_flags, security_compute_create, security_compute_create_name, security_compute_relabel,
 security_compute_member, security_compute_user, security_get_initial_context \- query
-the SELinux policy database in the kernel.
-
+the SELinux policy database in the kernel
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
-
+.br
 .B #include <selinux/flask.h>
 .sp
 .BI "int security_compute_av(security_context_t "scon ", security_context_t "tcon ", security_class_t "tclass ", access_vector_t "requested ", struct av_decision *" avd );
 .sp
+.BI "int security_compute_av_raw(security_context_t "scon ", security_context_t "tcon ", security_class_t "tclass ", access_vector_t "requested ", struct av_decision *" avd );
+.sp
 .BI "int security_compute_av_flags(security_context_t "scon ", security_context_t "tcon ", security_class_t "tclass ", access_vector_t "requested ", struct av_decision *" avd );
 .sp
+.BI "int security_compute_av_flags_raw(security_context_t "scon ", security_context_t "tcon ", security_class_t "tclass ", access_vector_t "requested ", struct av_decision *" avd );
+.sp
 .BI "int security_compute_create(security_context_t "scon ", security_context_t "tcon ", security_class_t "tclass ", security_context_t *" newcon );
 .sp
+.BI "int security_compute_create_raw(security_context_t "scon ", security_context_t "tcon ", security_class_t "tclass ", security_context_t *" newcon );
+.sp
 .BI "int security_compute_create_name(security_context_t "scon ", security_context_t "tcon ", security_class_t "tclass ", const char *"objname ", security_context_t *" newcon );
 .sp
+.BI "int security_compute_create_name_raw(security_context_t "scon ", security_context_t "tcon ", security_class_t "tclass ", const char *"objname ", security_context_t *" newcon );
+.sp
 .BI "int security_compute_relabel(security_context_t "scon ", security_context_t "tcon ", security_class_t "tclass ", security_context_t *" newcon );
 .sp
+.BI "int security_compute_relabel_raw(security_context_t "scon ", security_context_t "tcon ", security_class_t "tclass ", security_context_t *" newcon );
+.sp
 .BI "int security_compute_member(security_context_t "scon ", security_context_t "tcon ", security_class_t "tclass ", security_context_t *" newcon );
 .sp
+.BI "int security_compute_member_raw(security_context_t "scon ", security_context_t "tcon ", security_class_t "tclass ", security_context_t *" newcon );
+.sp
 .BI "int security_compute_user(security_context_t "scon ", const char *" username ", security_context_t **" con );
 .sp
-.BI "int security_get_initial_context(const char *" name ", security_context_t
-"con );
+.BI "int security_compute_user_raw(security_context_t "scon ", const char *" username ", security_context_t **" con );
 .sp
-.BI "int selinux_check_access(const security_context_t " scon, " const security_context_t " tcon, " const char *" class, " const char *" perm, "void *" auditdata);
+.BI "int security_get_initial_context(const char *" name ", security_context_t " con );
+.sp
+.BI "int security_get_initial_context_raw(const char *" name ", security_context_t " con );
+.sp
+.BI "int selinux_check_access(const security_context_t " scon ", const security_context_t " tcon ", const char *" class ", const char *" perm ", void *" auditdata);
 .sp
 .BI "int selinux_check_passwd_access(access_vector_t " requested );
 .sp
 .BI "int checkPasswdAccess(access_vector_t " requested );
-
+.
 .SH "DESCRIPTION"
-.B security_compute_av
+.BR security_compute_av ()
 queries whether the policy permits the source context
-.B scon
+.I scon
 to access the target context
-.B tcon
+.I tcon
 via class
-.B tclass
+.I tclass
 with the
-.B requested
+.I requested
 access vector.  The decision is returned in
-.BR avd .
+.IR avd .
 
-.B security_compute_av_flags
+.BR security_compute_av_flags ()
 is identical to
 .B security_compute_av
 but additionally sets the
-.B flags
+.I flags
 field of
-.BR avd .
+.IR avd .
 Currently one flag is supported:
 .BR SELINUX_AVD_FLAGS_PERMISSIVE ,
 which indicates the decision is computed on a permissive domain.
 
-.B security_compute_create
+.BR security_compute_create ()
 is used to compute a context to use for labeling a new object in a particular
 class based on a SID pair.
 
-.B security_compute_create_name
+.BR security_compute_create_name ()
 is identical to
-.B security_compute_create
+.BR \%security_compute_create ()
 but also takes name of the new object in creation as an argument.
 When
-.BR TYPE_TRANSITION
+.B TYPE_TRANSITION
 rule on the given class and a SID pair has object name extension,
 we shall be able to obtain a correct
-.BR newcon
+.I newcon
 according to the security policy. Note that this interface is only
 supported on the linux 2.6.40 or later.
 In the older kernel, the object name will be simply ignored.
 
-.B security_compute_relabel
+.BR security_compute_relabel ()
 is used to compute the new context to use when relabeling an object, it is used
 in the pam_selinux.so source and the newrole source to determine the correct
 label for the tty at login time, but can be used for other things.
 
-.B security_compute_member
+.BR security_compute_member ()
 is used to compute the context to use when labeling a polyinstantiated object
 instance.
 
-.B security_compute_user
+.BR security_compute_user ()
 is used to determine the set of user contexts that can be reached from a
 source context. It is mainly used by
-.B get_ordered_context_list.
+.BR get_ordered_context_list ().
 
-.B security_get_initial_context
+.BR security_get_initial_context ()
 is used to get the context of a kernel initial security identifier specified by 
 .I name
 
-.B selinux_check_access
+.BR security_compute_av_raw (),
+.BR security_compute_av_flags_raw (),
+.BR \%security_compute_create_raw (),
+.BR \%security_compute_create_name_raw (),
+.BR \%security_compute_relabel_raw (),
+.BR \%security_compute_member_raw (),
+.BR \%security_compute_user_raw ()
+and
+.BR \%security_get_initial_context_raw ()
+behave identically to their non-raw counterparts but do not perform context
+translation.
+
+.BR selinux_check_access ()
 is used to check if the source context has the access permission for the specified class on the target context.
 
-.B selinux_check_passwd_access
+.BR selinux_check_passwd_access ()
 is used to check for a permission in the
 .I passwd
 class.
-.B selinux_check_passwd_access
+.BR selinux_check_passwd_access ()
 uses getprevcon() for the source and target security contexts.
 
-.B checkPasswdAccess
+.BR checkPasswdAccess ()
 is a deprecated alias of the
-.B selinux_check_passwd_access
+.BR selinux_check_passwd_access ()
 function.
-
+.
 .SH "RETURN VALUE"
 Returns zero on success or \-1 on error.
-
+.
 .SH "SEE ALSO"
 .BR selinux "(8), " getcon "(3), " getfilecon "(3), " get_ordered_context_list "(3)"
diff --git a/libselinux/man/man3/security_compute_av_flags_raw.3 b/libselinux/man/man3/security_compute_av_flags_raw.3
new file mode 100644
index 0000000..a60bca4
--- /dev/null
+++ b/libselinux/man/man3/security_compute_av_flags_raw.3
@@ -0,0 +1 @@
+.so man3/security_compute_av.3
diff --git a/libselinux/man/man3/security_compute_av_raw.3 b/libselinux/man/man3/security_compute_av_raw.3
new file mode 100644
index 0000000..a60bca4
--- /dev/null
+++ b/libselinux/man/man3/security_compute_av_raw.3
@@ -0,0 +1 @@
+.so man3/security_compute_av.3
diff --git a/libselinux/man/man3/security_compute_create_name_raw.3 b/libselinux/man/man3/security_compute_create_name_raw.3
new file mode 100644
index 0000000..a60bca4
--- /dev/null
+++ b/libselinux/man/man3/security_compute_create_name_raw.3
@@ -0,0 +1 @@
+.so man3/security_compute_av.3
diff --git a/libselinux/man/man3/security_compute_create_raw.3 b/libselinux/man/man3/security_compute_create_raw.3
new file mode 100644
index 0000000..a60bca4
--- /dev/null
+++ b/libselinux/man/man3/security_compute_create_raw.3
@@ -0,0 +1 @@
+.so man3/security_compute_av.3
diff --git a/libselinux/man/man3/security_compute_member_raw.3 b/libselinux/man/man3/security_compute_member_raw.3
new file mode 100644
index 0000000..a60bca4
--- /dev/null
+++ b/libselinux/man/man3/security_compute_member_raw.3
@@ -0,0 +1 @@
+.so man3/security_compute_av.3
diff --git a/libselinux/man/man3/security_compute_relabel_raw.3 b/libselinux/man/man3/security_compute_relabel_raw.3
new file mode 100644
index 0000000..a60bca4
--- /dev/null
+++ b/libselinux/man/man3/security_compute_relabel_raw.3
@@ -0,0 +1 @@
+.so man3/security_compute_av.3
diff --git a/libselinux/man/man3/security_compute_user_raw.3 b/libselinux/man/man3/security_compute_user_raw.3
new file mode 100644
index 0000000..a60bca4
--- /dev/null
+++ b/libselinux/man/man3/security_compute_user_raw.3
@@ -0,0 +1 @@
+.so man3/security_compute_av.3
diff --git a/libselinux/man/man3/security_disable.3 b/libselinux/man/man3/security_disable.3
index 6725bde..aeb78da 100644
--- a/libselinux/man/man3/security_disable.3
+++ b/libselinux/man/man3/security_disable.3
@@ -1,28 +1,30 @@
 .TH "security_disable" "3" "21 Nov 2009" "" "SELinux API documentation"
 .SH "NAME"
-security_disable \- disable the SELinux kernel code at runtime.
-
+security_disable \- disable the SELinux kernel code at runtime
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
 .BI "int security_disable(void);"
-
+.
 .SH "DESCRIPTION"
-.B security_disable
-disables the SELinux kernel code, unregisters selinuxfs from /proc/filesystems,
-and then unmounts /selinux.
+.BR security_disable ()
+disables the SELinux kernel code, unregisters selinuxfs from
+.IR /proc/filesystems ,
+and then unmounts
+.IR /selinux .
 .sp
 This function can only be called at runtime and prior to the initial policy
 load. After the initial policy load, the SELinux kernel code cannot be disabled,
 but only placed in "permissive" mode by using
-.B setenforce(1).
-
+.BR setenforce (1).
+.
 .SH "RETURN VALUE"
-.B security_disable
+.BR security_disable ()
 returns zero on success or \-1 on error.
-
+.
 .SH "AUTHOR"
 This manual page has been written by Guido Trentalancia <guido@trentalancia.com>
-
+.
 .SH "SEE ALSO"
 .BR selinux (8), " setenforce "(3)
diff --git a/libselinux/man/man3/security_get_initial_context_raw.3 b/libselinux/man/man3/security_get_initial_context_raw.3
new file mode 100644
index 0000000..a60bca4
--- /dev/null
+++ b/libselinux/man/man3/security_get_initial_context_raw.3
@@ -0,0 +1 @@
+.so man3/security_compute_av.3
diff --git a/libselinux/man/man3/security_getenforce.3 b/libselinux/man/man3/security_getenforce.3
index 86771b5..7658014 100644
--- a/libselinux/man/man3/security_getenforce.3
+++ b/libselinux/man/man3/security_getenforce.3
@@ -1,29 +1,29 @@
 .TH "security_getenforce" "3" "1 January 2004" "russell@coker.com.au" "SELinux API documentation"
 .SH "NAME"
 security_getenforce, security_setenforce, security_deny_unknown \- get or set the enforcing state of SELinux
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
 .B int security_getenforce(void);
-
+.sp
 .BI "int security_setenforce(int "value );
-
+.sp
 .B int security_deny_unknown(void);
-
+.
 .SH "DESCRIPTION"
-.B security_getenforce
+.BR security_getenforce ()
 returns 0 if SELinux is running in permissive mode, 1 if it is running in
-enforcing mode, and -1 on error.
+enforcing mode, and \-1 on error.
 
-.B security_setenforce
+.BR security_setenforce ()
 sets SELinux to enforcing mode if the value 1 is passed in, and sets it to
-permissive mode if 0 is passed in.  On success 0 is returned, on error -1 is
+permissive mode if 0 is passed in.  On success 0 is returned, on error \-1 is
 returned.
 
-.B security_deny_unknown
+.BR security_deny_unknown ()
 returns 0 if SELinux treats policy queries on undefined object classes or
-permissions as being allowed, 1 if such queries are denied, and -1 on error.
-
+permissions as being allowed, 1 if such queries are denied, and \-1 on error.
+.
 .SH "SEE ALSO"
 .BR selinux "(8)"
-
diff --git a/libselinux/man/man3/security_load_booleans.3 b/libselinux/man/man3/security_load_booleans.3
index 40e91bc..3dc963d 100644
--- a/libselinux/man/man3/security_load_booleans.3
+++ b/libselinux/man/man3/security_load_booleans.3
@@ -3,6 +3,7 @@
 security_load_booleans, security_set_boolean, security_commit_booleans, 
 security_get_boolean_names, security_get_boolean_active,
 security_get_boolean_pending \- routines for manipulating SELinux boolean values
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
@@ -19,10 +20,8 @@ security_get_boolean_pending \- routines for manipulating SELinux boolean values
 .BI "int security_set_boolean_list(size_t " boolcnt ", SELboolean *" boollist ", int " permanent ");"
 .sp
 .BI "int security_commit_booleans(void);"
-
-
+.
 .SH "DESCRIPTION"
-
 The SELinux policy can include conditional rules that are enabled or
 disabled based on the current values of a set of policy booleans.
 These policy booleans allow runtime modification of the security
@@ -31,41 +30,37 @@ policy without having to load a new policy.
 The SELinux API allows for a transaction based update. So you can
 set several boolean values and then commit them all at once.
 
-.B security_load_booleans
-
+.BR security_load_booleans ()
 loads policy boolean settings. Path may be NULL, in which case the
 booleans are loaded from the active policy boolean configuration file.
 
-.B security_get_boolean_names
-
+.BR security_get_boolean_names ()
 provides a list of boolean names, currently supported by the loaded policy.
 
-.B security_get_boolean_pending
-
+.BR security_get_boolean_pending ()
 returns the pending value for boolean or \-1 on failure.
 
-.B security_get_boolean_active
-
+.BR security_get_boolean_active ()
 returns the active value for boolean or \-1 on failure.
 
-.B security_set_boolean 
-
+.BR security_set_boolean ()
 sets the pending value for boolean 
 
-.B security_set_boolean_list
-
+.BR security_set_boolean_list ()
 saves a list of booleans in a single transaction.
 
-.B security_commit_booleans
-
+.BR security_commit_booleans ()
 commits all pending values for the booleans.
-
+.
 .SH "RETURN VALUE"
 Where not otherwise stated, functions described in this manual page return
 zero on success or \-1 on error. 
-
+.
 .SH AUTHOR	
 This manual page was written by Dan Walsh <dwalsh@redhat.com>.
-
+.
 .SH "SEE ALSO"
-selinux(8), getsebool(8), booleans(8), togglesebool(8)
+.BR selinux (8),
+.BR getsebool (8),
+.BR booleans (8),
+.BR togglesebool (8)
diff --git a/libselinux/man/man3/security_load_policy.3 b/libselinux/man/man3/security_load_policy.3
index 163503e..c4439bf 100644
--- a/libselinux/man/man3/security_load_policy.3
+++ b/libselinux/man/man3/security_load_policy.3
@@ -1,7 +1,7 @@
 .TH "security_load_policy" "3" "3 November 2009" "guido@trentalancia.com" "SELinux API documentation"
 .SH "NAME"
 security_load_policy \- load a new SELinux policy
-
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
@@ -10,15 +10,15 @@ security_load_policy \- load a new SELinux policy
 .BI "int selinux_mkload_policy(int " preservebools ");"
 .sp
 .BI "int selinux_init_load_policy(int *" enforce ");"
-
+.
 .SH "DESCRIPTION"
-.B security_load_policy
+.BR security_load_policy ()
 loads a new policy, returns 0 for success and \-1 for error.
 
-.B selinux_mkload_policy
+.BR selinux_mkload_policy ()
 makes a policy image and loads it. This function provides a higher level
 interface for loading policy than
-.B security_load_policy,
+.BR \%security_load_policy (),
 internally determining the right policy version, locating and opening
 the policy file, mapping it into memory, manipulating it as needed for
 current boolean settings and/or local definitions, and then calling
@@ -29,7 +29,7 @@ be preserved into the new policy (if 1) or reset to the saved policy
 settings (if 0). The former case is the default for policy reloads, while
 the latter case is an option for policy reloads but is primarily used for
 the initial policy load.
-.B selinux_init_load_policy
+.BR selinux_init_load_policy ()
 performs the initial policy load. This function determines the desired
 enforcing mode, sets the
 .I enforce
@@ -40,19 +40,18 @@ handles the initial selinuxfs mount required to perform these actions.
 It should also be noted that after the initial policy load, the SELinux
 kernel code cannot anymore be disabled and the selinuxfs cannot be
 unmounted using a call to
-.B security_disable(3).
+.BR security_disable (3).
 Therefore, after the initial policy load, the only operational changes
 are those permitted by
-.B setenforce(3)
+.BR setenforce (3)
 (i.e. eventually setting the framework in permissive mode rather than
 in enforcing one).
-
+.
 .SH "RETURN VALUE"
-returns zero on success or \-1 on error.
-
+Returns zero on success or \-1 on error.
+.
 .SH "AUTHOR"
 This manual page has been written by Guido Trentalancia <guido@trentalancia.com>
-
+.
 .SH "SEE ALSO"
 .BR selinux "(8), " security_disable "(3), " setenforce "(1)
-
diff --git a/libselinux/man/man3/security_policyvers.3 b/libselinux/man/man3/security_policyvers.3
index 9e5dfd2..041ff3a 100644
--- a/libselinux/man/man3/security_policyvers.3
+++ b/libselinux/man/man3/security_policyvers.3
@@ -5,12 +5,11 @@ security_policyvers \- get the version of the SELinux policy
 .B #include <selinux/selinux.h>
 .sp
 .B int security_policyvers();
-
+.
 .SH "DESCRIPTION"
-.B security_policyvers
-returns the version of the policy (a positive integer) on success, or -1 on
+.BR security_policyvers ()
+returns the version of the policy (a positive integer) on success, or \-1 on
 error.
-
+.
 .SH "SEE ALSO"
 .BR selinux "(8)"
-
diff --git a/libselinux/man/man3/selabel_lookup.3 b/libselinux/man/man3/selabel_lookup.3
index ab792bb..08b3161 100644
--- a/libselinux/man/man3/selabel_lookup.3
+++ b/libselinux/man/man3/selabel_lookup.3
@@ -3,27 +3,29 @@
 .\" Author: Eamon Walsh (ewalsh@tycho.nsa.gov) 2007
 .TH "selabel_lookup" "3" "18 Jun 2007" "" "SELinux API documentation"
 .SH "NAME"
-selabel_lookup \- obtain SELinux security context from a string label.
+selabel_lookup \- obtain SELinux security context from a string label
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
-
+.br
 .B #include <selinux/label.h>
 .sp
 .BI "int selabel_lookup(struct selabel_handle *" hnd ,
 .in +\w'int selabel_lookup('u
 .BI "security_context_t *" context ,
-
+.br
 .BI "const char *" key ", int " type ");"
 .in
 .sp
 .BI "int selabel_lookup_raw(struct selabel_handle *" hnd ,
 .in +\w'int selabel_lookup_raw('u
 .BI "security_context_t *" context ,
-
+.br
 .BI "const char *" key ", int " type ");"
-
+.in
+.
 .SH "DESCRIPTION"
-.B selabel_lookup
+.BR selabel_lookup ()
 performs a lookup operation on the handle 
 .IR hnd ,
 returning the result in the memory pointed to by 
@@ -38,16 +40,16 @@ parameters are the inputs to the lookup operation and are interpreted according
 .I handle
 is open on.
 
-.B selabel_lookup_raw
+.BR selabel_lookup_raw ()
 behaves identically to 
-.B selabel_lookup
+.BR selabel_lookup ()
 but does not perform context translation.
-
+.
 .SH "RETURN VALUE"
 On success, zero is returned.  On error, \-1 is returned and
 .I errno
 is set appropriately.
-
+.
 .SH "ERRORS"
 .TP
 .B ENOENT
@@ -66,13 +68,12 @@ inputs are invalid, or the context being returned failed validation.
 .TP
 .B ENOMEM
 An attempt to allocate memory failed.
-
+.
 .SH "AUTHOR"
 Eamon Walsh <ewalsh@tycho.nsa.gov>
-
+.
 .SH "SEE ALSO"
 .BR selabel_open (3),
 .BR selabel_stats (3),
 .BR selinux_set_callback (3),
 .BR selinux (8)
-
diff --git a/libselinux/man/man3/selabel_lookup_raw.3 b/libselinux/man/man3/selabel_lookup_raw.3
new file mode 100644
index 0000000..64e003e
--- /dev/null
+++ b/libselinux/man/man3/selabel_lookup_raw.3
@@ -0,0 +1 @@
+.so man3/selabel_lookup.3
diff --git a/libselinux/man/man3/selabel_open.3 b/libselinux/man/man3/selabel_open.3
index 8674e37..00f2828 100644
--- a/libselinux/man/man3/selabel_open.3
+++ b/libselinux/man/man3/selabel_open.3
@@ -3,23 +3,24 @@
 .\" Author: Eamon Walsh (ewalsh@tycho.nsa.gov) 2007
 .TH "selabel_open" "3" "18 Jun 2007" "" "SELinux API documentation"
 .SH "NAME"
-selabel_open, selabel_close \- userspace SELinux labeling interface.
+selabel_open, selabel_close \- userspace SELinux labeling interface
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
-
+.br
 .B #include <selinux/label.h>
 .sp
 .BI "struct selabel_handle *selabel_open(int " backend , 
 .in +\w'struct selabel_handle *selabel_open('u
 .BI "struct selinux_opt *" options ,
-
+.br
 .BI "unsigned " nopt ");"
 .in
 .sp
 .BI "void selabel_close(struct selabel_handle *" hnd ");"
-
+.
 .SH "DESCRIPTION"
-.B selabel_open
+.BR selabel_open ()
 is used to initialize a labeling handle to be used for lookup operations.  The 
 .I backend
 argument specifies which backend is to be opened; the list of current backends appears in 
@@ -48,14 +49,14 @@ The available option types are described in
 .B GLOBAL OPTIONS
 below as well as in the documentation for each individual backend.  The return value on success is a non-NULL value for use in subsequent label operations.
 
-.B selabel_close
+.BR selabel_close ()
 terminates use of a handle, freeing any internal resources associated with it.  After this call has been made, the handle must not be used again.
-
+.
 .SH "GLOBAL OPTIONS"
 Global options which may be passed to
-.B selabel_open
+.BR selabel_open ()
 include the following:
-
+.
 .TP
 .B SELABEL_OPT_UNUSED
 The option with a type code of zero is a no-op.  Thus an array of options may be initizalized to zero and any untouched elements will not cause an error.
@@ -66,9 +67,8 @@ A non-null value for this option enables context validation.  By default,
 is used; a custom validation function can be provided via
 .BR selinux_set_callback (3).
 Note that an invalid context may not be treated as an error unless it is actually encountered during a lookup operation.
-
+.
 .SH "BACKENDS"
-
 .TP
 .B SELABEL_CTX_FILE
 File contexts backend, described in 
@@ -85,18 +85,19 @@ X Windows contexts backend, described in
 .B SELABEL_CTX_DB
 Database objects contexts backend, described in
 .BR selabel_db (5).
-
+.
 .SH "RETURN VALUE"
 A non-NULL handle value is returned on success.  On error, NULL is returned and
 .I errno
 is set appropriately.
-
+.
 .SH "AUTHOR"
 Eamon Walsh <ewalsh@tycho.nsa.gov>
-
+.
 .SH "SEE ALSO"
+.ad l
+.nh
 .BR selabel_lookup (3),
 .BR selabel_stats (3),
 .BR selinux_set_callback (3),
 .BR selinux (8)
-
diff --git a/libselinux/man/man3/selabel_stats.3 b/libselinux/man/man3/selabel_stats.3
index 441f422..44e1a65 100644
--- a/libselinux/man/man3/selabel_stats.3
+++ b/libselinux/man/man3/selabel_stats.3
@@ -3,33 +3,33 @@
 .\" Author: Eamon Walsh (ewalsh@tycho.nsa.gov) 2007
 .TH "selabel_stats" "3" "18 Jun 2007" "" "SELinux API documentation"
 .SH "NAME"
-selabel_stats \- obtain SELinux labeling statistics.
+selabel_stats \- obtain SELinux labeling statistics
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
-
+.br
 .B #include <selinux/label.h>
 .sp
-.BI "void selabel_lookup(struct selabel_handle *" hnd ");"
-
+.BI "void selabel_stats(struct selabel_handle *" hnd ");"
+.
 .SH "DESCRIPTION"
-.B selabel_stats
+.BR selabel_stats ()
 causes zero or more messages to be printed containing backend-specific information about number of queries performed, number of unused entries, or other operational information.
 
 The messages are printed to standard error by default; a custom logging function can be provided via 
 .BR selinux_set_callback (3).
-
+.
 .SH "RETURN VALUE"
 None.
-
+.
 .SH "ERRORS"
 None.
-
+.
 .SH "AUTHOR"
 Eamon Walsh <ewalsh@tycho.nsa.gov>
-
+.
 .SH "SEE ALSO"
 .BR selabel_open (3),
 .BR selabel_lookup (3),
 .BR selinux_set_callback (3),
 .BR selinux (8)
-
diff --git a/libselinux/man/man3/selinux_binary_policy_path.3 b/libselinux/man/man3/selinux_binary_policy_path.3
index 8ead1a4..1870f05 100644
--- a/libselinux/man/man3/selinux_binary_policy_path.3
+++ b/libselinux/man/man3/selinux_binary_policy_path.3
@@ -5,89 +5,110 @@ selinux_failsafe_context_path, selinux_removable_context_path,
 selinux_default_context_path, selinux_user_contexts_path,
 selinux_file_context_path, selinux_media_context_path,
 selinux_contexts_path, selinux_booleans_path \- These functions return the paths to the active SELinux policy configuration
-directories and files.
-
+directories and files
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
-
-extern const char *selinux_path(void);
-
-extern const char *selinux_policy_root(void);
-
-extern const char *selinux_binary_policy_path(void);
-
-extern const char *selinux_failsafe_context_path(void);
-
-extern const char *selinux_removable_context_path(void);
-
-extern const char *selinux_default_context_path(void);
-
-extern const char *selinux_user_contexts_path(void);
-
-extern const char *selinux_usersconf_path(void);
-
-extern const char *selinux_x_context_path(void);
-
-extern const char *selinux_sepgsql_context_path(void);
-
-extern const char *selinux_file_context_path(void);
-
-extern const char *selinux_media_context_path(void);
-
-extern const char *selinux_securetty_types_path(void);
-
-extern const char *selinux_contexts_path(void);
-
-extern const char *selinux_booleans_path(void);
-
-
+.B const char *selinux_path(void);
+.sp
+.B const char *selinux_policy_root(void);
+.sp
+.B const char *selinux_binary_policy_path(void);
+.sp
+.B const char *selinux_current_policy_path(void);
+.sp
+.B const char *selinux_failsafe_context_path(void);
+.sp
+.B const char *selinux_removable_context_path(void);
+.sp
+.B const char *selinux_default_context_path(void);
+.sp
+.B const char *selinux_user_contexts_path(void);
+.sp
+.B const char *selinux_usersconf_path(void);
+.sp
+.B const char *selinux_x_context_path(void);
+.sp
+.B const char *selinux_sepgsql_context_path(void);
+.sp
+.B const char *selinux_file_context_path(void);
+.sp
+.B const char *selinux_media_context_path(void);
+.sp
+.B const char *selinux_securetty_types_path(void);
+.sp
+.B const char *selinux_contexts_path(void);
+.sp
+.B const char *selinux_booleans_path(void);
+.
 .SH "DESCRIPTION"
-
 These functions return the paths to the active policy configuration
-directories and files based on the settings in /etc/selinux/config.
-
+directories and files based on the settings in
+.IR /etc/selinux/config .
+.sp
+.BR selinux_path ()
+returns the top-level SELinux configuration directory.
 .sp
-selinux_path() - top-level SELinux configuration directory
+.BR selinux_policy_root ()
+returns the top-level policy directory.
 .sp
-selinux_policy_root() - top-level policy directory 
+.BR selinux_binary_policy_path ()
+returns the binary policy file loaded into kernel.
 .sp
-selinux_binary_policy_path() - binary policy file loaded into kernel
+.BR selinux_current_policy_path ()
+returns binary policy file loaded into kernel
 .sp
-selinux_default_type_path - context file mapping roles to default types.
+.BR selinux_default_type_path ()
+returns the context file mapping roles to default types.
 .sp
-selinux_failsafe_context_path() - failsafe context for emergency logins
+.BR selinux_failsafe_context_path ()
+returns the failsafe context for emergency logins.
 .sp
-selinux_removable_context_path() - filesystem context for removable media
+.BR selinux_removable_context_path ()
+returns the filesystem context for removable media.
 .sp
-selinux_default_context_path() - system-wide default contexts for user sessions
+.BR selinux_default_context_path ()
+returns the system-wide default contexts for user sessions.
 .sp
-selinux_user_contexts_path() - directory containing per-user default contexts
+.BR selinux_user_contexts_path ()
+returns the directory containing per-user default contexts.
 .sp
-selinux_usersconf_path() - file containing mapping between Linux Users and SELinux users
+.BR selinux_usersconf_path ()
+returns the file containing mapping between Linux Users and SELinux users.
 .sp
-selinux_x_context_path() - file containing configuration for XSELinux extension
+.BR selinux_x_context_path ()
+returns the file containing configuration for XSELinux extension.
 .sp
-selinux_sepgsql_context_path() - file containing configuration for SE-PostgreSQL
+.BR selinux_sepgsql_context_path ()
+returns the file containing configuration for SE-PostgreSQL.
 .sp
-selinux_netfilter_context_path - default netfilter context 
+.BR selinux_netfilter_context_path ()
+returns the default netfilter context.
 .sp
-selinux_file_context_path() - default system file contexts configuration
+.BR selinux_file_context_path ()
+returns the default system file contexts configuration.
 .sp
-selinux_file_context_local_path() - local customization file contexts configuration
+.BR selinux_file_context_local_path ()
+returns the local customization file contexts configuration.
 .sp
-selinux_file_context_homedir_path() - home directory file contexts configuration
+.BR selinux_file_context_homedir_path ()
+returns the home directory file contexts configuration.
 .sp
-selinux_media_context_path() - file contexts for media device nodes
+.BR selinux_media_context_path ()
+returns the file contexts for media device nodes.
 .sp
-selinux_contexts_path() - directory containing all of the context configuration files
+.BR selinux_contexts_path ()
+returns the directory containing all of the context configuration files.
 .sp
-selinux_securetty_types_path() - defines tty types for newrole securettys
+.BR selinux_securetty_types_path ()
+returns the defines tty types for newrole securettys.
 .sp
-selinux_booleans_path() - initial policy boolean settings
-
+.BR selinux_booleans_path ()
+returns the initial policy boolean settings.
+.
 .SH AUTHOR	
 This manual page was written by Dan Walsh <dwalsh@redhat.com>.
-
+.
 .SH "SEE ALSO"
 .BR selinux "(8)"
diff --git a/libselinux/man/man3/selinux_boolean_sub.3 b/libselinux/man/man3/selinux_boolean_sub.3
index 8d54c88..308c268 100644
--- a/libselinux/man/man3/selinux_boolean_sub.3
+++ b/libselinux/man/man3/selinux_boolean_sub.3
@@ -1,25 +1,29 @@
-.TH "selinux_boolean_subs" "3" "11 June 2012" "dwalsh@redhat.com" "SELinux API documentation"
+.TH "selinux_boolean_sub" "3" "11 June 2012" "dwalsh@redhat.com" "SELinux API documentation"
 .SH "NAME"
-selinux_boolean_subs
+selinux_boolean_sub \-
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
-.BI "char *selinux_boolean_subs(const char * " boolean_name, ");"
+.BI "char *selinux_boolean_sub(const char *" boolean_name ");"
 .sp
 .SH "DESCRIPTION"
-.B selinux_boolean_sub
-searches the /etc/selinux/POLICYTYPE/booleans.subs_dist file
+.BR selinux_boolean_sub ()
+searches the
+.I \%/etc/selinux/{POLICYTYPE}/booleans.subs_dist
+file
 for a maching boolean_name record.  If the record exists the boolean substitution name is returned.  If not
-.B selinux_boolean_sub
-returns the original boolean_name.
+.BR \%selinux_boolean_sub ()
+returns the original
+.IR \%boolean_name .
 
 .SH "RETURN VALUE"
-.BR selinux_boolean_subs
+.BR selinux_boolean_sub ()
 returns the
 .I boolean_name
 or the substituted name on success.  The returned value must be freed with
 .BR free "(3)."
-.BR selinux_boolean_subs
+.BR selinux_boolean_sub ()
 returns NULL on error.
 .SH "SEE ALSO"
-security_get_boolean_names.3
+.BR security_get_boolean_names (3)
diff --git a/libselinux/man/man3/selinux_check_securetty_context.3 b/libselinux/man/man3/selinux_check_securetty_context.3
index 65a10d3..22e8533 100644
--- a/libselinux/man/man3/selinux_check_securetty_context.3
+++ b/libselinux/man/man3/selinux_check_securetty_context.3
@@ -1,16 +1,16 @@
 .TH "selinux_check_securetty_context" "3" "1 January 2007" "dwalsh@redhat.com" "SELinux API documentation"
 .SH "NAME"
 selinux_check_securetty_context \- check whether a SELinux tty security context is defined as a securetty context
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
 .BI "int selinux_check_securetty_context(security_context_t "tty_context );
-
+.
 .SH "DESCRIPTION"
-.B selinux_check_securetty_context
-returns 0 if tty_context is a securetty context
+.BR selinux_check_securetty_context ()
+returns 0 if tty_context is a securetty context,
 returns < 0 otherwise. 
-
+.
 .SH "SEE ALSO"
 .BR selinux "(8)"
-
diff --git a/libselinux/man/man3/selinux_colors_path.3 b/libselinux/man/man3/selinux_colors_path.3
index 851d81d..cc57e43 100644
--- a/libselinux/man/man3/selinux_colors_path.3
+++ b/libselinux/man/man3/selinux_colors_path.3
@@ -1,36 +1,37 @@
 .TH "selinux_colors_path" "3" "08 April 2011" "SELinux API documentation"
-
 .SH "NAME"
-selinux_colors_path \- Return a path to the active SELinux policy color configuration file.
+selinux_colors_path \- Return a path to the active SELinux policy color configuration file
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
 .B const char *selinux_colors_path(void);
-
+.
 .SH "DESCRIPTION"
-.B selinux_colors_path
+.BR selinux_colors_path ()
 returns the path to the active policy color configuration file. 
 .sp
 The path is built from the path returned by 
 .BR selinux_policy_root "(3)"
 with 
-.B /secolor.conf
+.I /secolor.conf
 appended.
 .sp
 This optional configuration file whose format is shown in 
-.BR secolor.conf "(5),"
+.BR \%secolor.conf (5),
 controls the colors to be associated with the 
 .I raw
 context components of the
 .BR selinux_raw_context_to_color "(3)"
 function when information is to be displayed by an SELinux color-aware application.
-
+.
 .SH "RETURN VALUE"
 On success, the path to the active policy color configuration file is returned. If a path is not available NULL is returned.
-
+.
 .SH "ERRORS"
 None.
-
+.
 .SH "SEE ALSO"
+.ad l
+.nh
 .BR selinux "(8), " selinux_policy_root "(3), " selinux_config "(5), " selinux_raw_context_to_color "(3), " secolor.conf  "(5)"
-
diff --git a/libselinux/man/man3/selinux_file_context_cmp.3 b/libselinux/man/man3/selinux_file_context_cmp.3
index cd67188..30bbaa3 100644
--- a/libselinux/man/man3/selinux_file_context_cmp.3
+++ b/libselinux/man/man3/selinux_file_context_cmp.3
@@ -1,8 +1,7 @@
 .TH "selinux_file_context_cmp" "3" "08 March 2011" "SELinux API documentation"
-
 .SH "NAME"
-selinux_file_context_cmp \- Compare two SELinux security contexts excluding the 'user' component.
-
+selinux_file_context_cmp \- Compare two SELinux security contexts excluding the 'user' component
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
@@ -10,20 +9,20 @@ selinux_file_context_cmp \- Compare two SELinux security contexts excluding the
 .RS
 .BI "const security_context_t " b ");"
 .RE
-
+.
 .SH "DESCRIPTION"
-.B selinux_file_context_cmp
+.BR selinux_file_context_cmp ()
 compares two context strings excluding the user component with
-.B strcmp(3)
+.BR strcmp (3)
 as shown in the
 .B EXAMPLE
 section.
 .sp
 This is useful as for most object contexts, the user component is not relevant.
-
+.
 .SH "RETURN VALUE"
 The return values follow the
-.B strcmp(3)
+.BR strcmp (3)
 function, where:
 .RS
 0  if they are equal.
@@ -40,13 +39,13 @@ is greater than
 is less than
 .I b
 .RE
-
+.
 .SH "ERRORS"
 None.
-
+.
 .SH "NOTES"
 The contexts being compared do not specifically need to be file contexts.
-
+.
 .SH "EXAMPLE"
 If context
 .I a
@@ -68,8 +67,8 @@ then the actual strings compared are:
 .RE
 .sp
 Therefore they will match and
-.B selinux_file_context_cmp
+.BR selinux_file_context_cmp ()
 will return zero.
-
+.
 .SH "SEE ALSO"
 .BR selinux "(8)"
diff --git a/libselinux/man/man3/selinux_file_context_verify.3 b/libselinux/man/man3/selinux_file_context_verify.3
index e22be70..893949f 100644
--- a/libselinux/man/man3/selinux_file_context_verify.3
+++ b/libselinux/man/man3/selinux_file_context_verify.3
@@ -1,15 +1,14 @@
 .TH "selinux_file_context_verify" "3" "08 March 2011" "SELinux API documentation"
-
 .SH "NAME"
-selinux_file_context_verify \- Compare the SELinux security context on disk to the default security context required by the policy file contexts file.
-
+selinux_file_context_verify \- Compare the SELinux security context on disk to the default security context required by the policy file contexts file
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
 .BI "int selinux_file_context_verify(const char *" path ", mode_t " mode ");"
-
+.
 .SH "DESCRIPTION"
-.B selinux_file_context_verify
+.BR selinux_file_context_verify ()
 compares the context of the specified
 .I path
 that is held on disk (in the extended attribute), to the system default entry held in the file contexts series of files.
@@ -21,7 +20,7 @@ may be zero.
 Note that the two contexts are compared for "significant" differences (i.e. the user component of the contexts are ignored) as shown in the
 .B EXAMPLE
 section.
-
+.
 .SH "RETURN VALUE"
 If the contexts significantly match, 1 (one) is returned.
 .sp
@@ -40,7 +39,7 @@ section, or if
 On failure \-1 is returned and
 .I errno
 set appropriately.
-
+.
 .SH "ERRORS"
 .TP
 .B ENOTSUP
@@ -58,22 +57,26 @@ are invalid, or the returned context fails validation.
 .TP
 .B ENOMEM
 if attempt to allocate memory failed.
-
+.
 .SH "FILES"
 The following configuration files (the file contexts series of files) supporting the active policy will be used (should they exist) to determine the
 .I path
 default context:
 .sp
 .RS
-contexts/files/file_contexts - This file must exist.
+.I contexts/files/file_contexts
+- This file must exist.
 .sp
-contexts/files/file_contexts.local - If exists has local customizations.
+.I contexts/files/file_contexts.local
+- If exists has local customizations.
 .sp
-contexts/files/file_contexts.homedirs - If exists has users home directory customizations.
+.I contexts/files/file_contexts.homedirs
+- If exists has users home directory customizations.
 .sp
-contexts/files/file_contexts.subs - If exists has substitutions that are then applied to the 'in memory' version of the file contexts files.
+.I contexts/files/file_contexts.subs
+- If exists has substitutions that are then applied to the 'in memory' version of the file contexts files.
 .RE
-
+.
 .SH "EXAMPLE"
 If the files context is:
 .RS
@@ -91,8 +94,8 @@ then the actual strings compared are:
 .RE
 .sp
 Therefore they will match and
-.B selinux_file_context_verify
+.BR selinux_file_context_verify ()
 will return 1.
-
+.
 .SH "SEE ALSO"
 .BR selinux "(8)"
diff --git a/libselinux/man/man3/selinux_getenforcemode.3 b/libselinux/man/man3/selinux_getenforcemode.3
index a6a753e..7ed94c1 100644
--- a/libselinux/man/man3/selinux_getenforcemode.3
+++ b/libselinux/man/man3/selinux_getenforcemode.3
@@ -1,25 +1,31 @@
 .TH "selinux_getenforcemode" "3" "25 May 2004" "dwalsh@redhat.com" "SELinux API documentation"
 .SH "NAME"
 selinux_getenforcemode \- get the enforcing state of SELinux
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
-.B int selinux_getenforcemode(int *enforce);
-
-
+.BI "int selinux_getenforcemode(int *" enforce );
+.
 .SH "DESCRIPTION"
-.B selinux_getenforcemode
-Reads the contents of the /etc/selinux/config file to determine how the 
-system was setup to run SELinux.
+.BR selinux_getenforcemode ()
+Reads the contents of the
+.I /etc/selinux/config
+file to determine how the system was setup to run SELinux.
 
-Sets the value of enforce to 1 if SELinux should be run in enforcing mode.
-Sets the value of enforce to 0 if SELinux should be run in permissive mode.
-Sets the value of enforce to -1 if SELinux should be disabled.
+Sets the value of
+.I enforce
+to 1 if SELinux should be run in enforcing mode.
+Sets the value of
+.I enforce
+to 0 if SELinux should be run in permissive mode.
+Sets the value of
+.I enforce
+to \-1 if SELinux should be disabled.
+.
 .SH "RETURN VALUE"
 On success, zero is returned.
-On failure, -1 is returned.
-
+On failure, \-1 is returned.
+.
 .SH "SEE ALSO"
 .BR selinux "(8)"
-
-
diff --git a/libselinux/man/man3/selinux_getpolicytype.3 b/libselinux/man/man3/selinux_getpolicytype.3
index 67f9518..c947e2c 100644
--- a/libselinux/man/man3/selinux_getpolicytype.3
+++ b/libselinux/man/man3/selinux_getpolicytype.3
@@ -1,21 +1,23 @@
 .TH "selinux_getpolicytype" "3" "24 Sep 2008" "dwalsh@redhat.com" "SELinux API documentation"
 .SH "NAME"
 selinux_getpolicytype \- get the type of SELinux policy running on the system
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
-.B int selinux_getpolicytype();
-
-
+.BI "int selinux_getpolicytype(char **" policytype );
+.
 .SH "DESCRIPTION"
-.B selinux_getpolicytype
-Reads the contents of the /etc/selinux/config file to determine the SELinux policy used on the system.
-
+.BR selinux_getpolicytype ()
+Reads the contents of the
+.I /etc/selinux/config
+file to determine the SELinux policy used on the system, and sets
+.I \%policytype
+accordinly.
+.
 .SH "RETURN VALUE"
 On success, zero is returned.
-On failure, -1 is returned.
-
+On failure, \-1 is returned.
+.
 .SH "SEE ALSO"
 .BR selinux "(8)"
-
-
diff --git a/libselinux/man/man3/selinux_lsetfilecon_default.3 b/libselinux/man/man3/selinux_lsetfilecon_default.3
index 0589c7a..d4fc658 100644
--- a/libselinux/man/man3/selinux_lsetfilecon_default.3
+++ b/libselinux/man/man3/selinux_lsetfilecon_default.3
@@ -1,20 +1,20 @@
 .TH "selinux_lsetfilecon_default" "3" "21 November 2009" "sds@tycho.nsa.gov" "SELinux API documentation"
 .SH "NAME"
-selinux_lsetfilecon_default \- set the file context to the system defaults.
-
+selinux_lsetfilecon_default \- set the file context to the system defaults
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
-
 .BI "int selinux_lsetfilecon_default(const char *" path ");"
-
+.
 .SH "DESCRIPTION"
-.B selinux_lsetfilecon_default
+.BR selinux_lsetfilecon_default ()
 sets the file context to the system defaults.
-.sp
-
+.
 .SH "RETURN VALUE"
 Returns zero on success or \-1 otherwise.
-
+.
 .SH "SEE ALSO"
+.ad l
+.nh
 .BR selinux "(8), " selinux_file_context_cmp "(3), " selinux_file_context_verify "(3), " matchpathcon "(3), " freecon "(3), " setfilecon "(3), " setfscreatecon "(3)"
diff --git a/libselinux/man/man3/selinux_policy_root.3 b/libselinux/man/man3/selinux_policy_root.3
index 7499c75..a6ccf86 100644
--- a/libselinux/man/man3/selinux_policy_root.3
+++ b/libselinux/man/man3/selinux_policy_root.3
@@ -1,20 +1,21 @@
 .TH "selinux_policy_root" "3" "25 May 2004" "dwalsh@redhat.com" "SELinux API documentation"
 .SH "NAME"
-selinux_policy_root \- return the path of the SELinux policy files for this machine.
+selinux_policy_root \- return the path of the SELinux policy files for this machine
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
-.B char *selinux_policy_root();
-
-
+.B const char *selinux_policy_root(void);
+.
 .SH "DESCRIPTION"
-.B selinux_policy_root
-Reads the contents of the /etc/selinux/config file to determine which policy files should be used for this machine.
+.BR selinux_policy_root ()
+reads the contents of the
+.I /etc/selinux/config
+file to determine which policy files should be used for this machine.
+.
 .SH "RETURN VALUE"
 On success, returns a directory path containing the SELinux policy files.
 On failure, NULL is returned.
-
+.
 .SH "SEE ALSO"
 .BR selinux "(8)"
-
-
diff --git a/libselinux/man/man3/selinux_raw_context_to_color.3 b/libselinux/man/man3/selinux_raw_context_to_color.3
index d3ca83b..3737f60 100644
--- a/libselinux/man/man3/selinux_raw_context_to_color.3
+++ b/libselinux/man/man3/selinux_raw_context_to_color.3
@@ -1,8 +1,7 @@
 .TH "selinux_raw_context_to_color" "3" "08 April 2011" "SELinux API documentation"
-
 .SH "NAME"
-selinux_raw_context_to_color \- Return RGB color string for an SELinux security context.
-
+selinux_raw_context_to_color \- Return RGB color string for an SELinux security context
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
@@ -10,9 +9,9 @@ selinux_raw_context_to_color \- Return RGB color string for an SELinux security
 .RS
 .BI "char **" color_str ");"
 .RE
-
+.
 .SH "DESCRIPTION"
-.B selinux_raw_context_to_color
+.BR selinux_raw_context_to_color ()
 returns a 
 .I color_str
 associated to the raw context 
@@ -20,7 +19,7 @@ associated to the raw context
 provided that the 
 .BR mcstransd "(8)"
 daemon is running, the policy is an MLS type policy (MCS or MLS) and there is a color configuration file
-.BR secolor.conf "(5)"
+.BR \%secolor.conf (5)
 (see the
 .B FILES
 section).
@@ -39,7 +38,7 @@ string must be freed with
 If a color has not been configured for a specific user, role, type and/or range component of context 
 .IR raw ","
 then
-.B selinux_raw_context_to_color
+.BR \%selinux_raw_context_to_color ()
 will select the color returned in 
 .I color_str
 in order of precedence as follows:
@@ -55,7 +54,7 @@ user, role, type
 .RE
 
 If there are no entries in the 
-.B secolor.conf
+.BR secolor.conf (5)
 file for any of the components of context 
 .I raw
 (or the file is not present), then the default string returned in 
@@ -68,32 +67,32 @@ is:
 #000000 #ffffff #000000 #ffffff #000000 #ffffff #000000 #ffffff
 .sp
 .RE
-
+.
 .SH "RETURN VALUE"
 On success, zero is returned.
 .br
 On failure, \-1 is returned with 
 .I errno
 set appropriately.
-
+.
 .SH "ERRORS"
 .B ENOENT
 If the 
 .BR mcstransd "(8)"
 daemon is not running. 
-
+.
 .SH "FILES"
-.B selinux_raw_context_to_color
+.BR selinux_raw_context_to_color ()
 obtains the translated entry from the active policy 
 .BR secolor.conf "(5)"
 file as returned by
-.BR selinux_colors_path "(3)."
+.BR \%selinux_colors_path (3).
 The file format is described in 
-.BR secolor.conf "(5)."
-
+.BR \%secolor.conf (5).
+.
 .SH "NOTES"
 1. The primary use of 
-.B selinux_raw_context_to_color
+.BR selinux_raw_context_to_color ()
 is to return a color that corresponds to a range, that can then be used to highlight information at different MLS levels.
 .sp
 2. The 
@@ -101,11 +100,11 @@ is to return a color that corresponds to a range, that can then be used to highl
 daemon process security level must dominate the 
 .I raw
 security level passed to it by the 
-.B selinux_raw_context_to_color
+.BR selinux_raw_context_to_color ()
 function. If not, the range color selected will be as defined by the order of precedence.
-
+.
 .SH "EXAMPLE"
-.B selinux_raw_context_to_color
+.BR selinux_raw_context_to_color ()
 returns the foreground and background colors of the context string components (user:role:type:range) as RGB triples as follows:
 .sp
 
@@ -117,8 +116,8 @@ returns the foreground and background colors of the context string components (u
 .br
  black   white :  white   black  : tan    orange  : black   green 
 .br
-
+.
 .SH "SEE ALSO"
+.ad l
+.nh
 .BR selinux "(8), " selinux_colors_path "(3), " mcstransd "(8), " secolor.conf "(5), " selinux_raw_to_trans_context "(3), " selinux_trans_to_raw_context "(3), " free "(3)"
-
-
diff --git a/libselinux/man/man3/selinux_set_callback.3 b/libselinux/man/man3/selinux_set_callback.3
index 4f8d74d..073e135 100644
--- a/libselinux/man/man3/selinux_set_callback.3
+++ b/libselinux/man/man3/selinux_set_callback.3
@@ -3,14 +3,15 @@
 .\" Author: Eamon Walsh (ewalsh@tycho.nsa.gov) 2007
 .TH "selinux_set_callback" "3" "20 Jun 2007" "" "SELinux API documentation"
 .SH "NAME"
-selinux_set_callback \- userspace SELinux callback facilities.
+selinux_set_callback \- userspace SELinux callback facilities
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
 .BI "void selinux_set_callback(int " type ", union selinux_callback " callback ");"
-
+.
 .SH "DESCRIPTION"
-.B selinux_set_callback
+.BR selinux_set_callback ()
 sets the callback indicated by
 .I type
 to the value of
@@ -45,7 +46,7 @@ argument indicates the type of message and will be set to one of the following:
 .B SELINUX_INFO
 
 .B SELINUX_AVC
-
+.
 .TP
 .B SELINUX_CB_AUDIT
 .BI "int (*" func_audit ") (void *" auditdata ", security_class_t " cls ,
@@ -64,7 +65,7 @@ A human-readable interpretation should be printed to
 using no more than
 .I msgbufsize
 characters.
-
+.
 .TP
 .B SELINUX_CB_VALIDATE
 .BI "int (*" func_validate ") (security_context_t *" ctx ");"
@@ -78,7 +79,7 @@ The value of
 should be set to
 .B EINVAL
 to indicate an invalid context.
-
+.
 .TP
 .B SELINUX_CB_SETENFORCE
 .BI "int (*" func_setenforce ") (int " enforcing ");"
@@ -91,7 +92,7 @@ argument indicates the new value and is set to
 for enforcing mode, and
 .I 0
 for permissive mode.
-
+.
 .TP
 .B SELINUX_CB_POLICYLOAD
 .BI "int (*" func_policyload ") (int " seqno ");"
@@ -100,19 +101,18 @@ This callback is invoked when the system security policy is reloaded.
 The
 .I seqno
 argument is the current sequential number of the policy generation in the system.
-
+.
 .SH "RETURN VALUE"
 None.
-
+.
 .SH "ERRORS"
 None.
-
+.
 .SH "AUTHOR"
 Eamon Walsh <ewalsh@tycho.nsa.gov>
-
+.
 .SH "SEE ALSO"
 .BR selabel_open (3),
 .BR avc_init (3),
-.BR avc_netlink_open(3),
+.BR avc_netlink_open (3),
 .BR selinux (8)
-
diff --git a/libselinux/man/man3/selinux_set_mapping.3 b/libselinux/man/man3/selinux_set_mapping.3
index 7ac069a..a93f7b2 100644
--- a/libselinux/man/man3/selinux_set_mapping.3
+++ b/libselinux/man/man3/selinux_set_mapping.3
@@ -3,7 +3,8 @@
 .\" Author: Eamon Walsh (ewalsh@tycho.nsa.gov) 2008
 .TH "selinux_set_mapping" "3" "12 Jun 2008" "" "SELinux API documentation"
 .SH "NAME"
-selinux_set_mapping \- establish dynamic object class and permission mapping.
+selinux_set_mapping \- establish dynamic object class and permission mapping
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
@@ -15,9 +16,9 @@ struct security_class_mapping {
 .fi
 .sp
 .BI "int selinux_set_mapping(struct security_class_mapping *" map ");"
-
+.
 .SH "DESCRIPTION"
-.B selinux_set_mapping
+.BR selinux_set_mapping ()
 establishes a mapping from a user-provided ordering of object classes and permissions to the numbers actually used by the loaded system policy.  Use of this function is highly preferred over the generated constants in the libselinux header files, as this method allows the policy's class and permission values to change over time.
 
 After the mapping is established, all libselinux functions that operate on class and permission values take the user-provided numbers, which are determined as follows:
@@ -33,12 +34,12 @@ field should refer to the string name of an object class, and the corresponding
 field should refer to an array of permission bit names terminated by a NULL string.
 
 The object classes named in the mapping and the bit indexes of each set of permission bits named in the mapping are numbered in order starting from 1.  These numbers are the values that should be passed to subsequent libselinux calls.
-
+.
 .SH "RETURN VALUE"
-Zero is returned on success.  On error, -1 is returned and
+Zero is returned on success.  On error, \-1 is returned and
 .I errno
 is set appropriately.
-
+.
 .SH "ERRORS"
 .TP
 .B EINVAL
@@ -46,7 +47,7 @@ One of the class or permission names requested in the mapping is not present in
 .TP
 .B ENOMEM
 An attempt to allocate memory failed.
-
+.
 .SH "EXAMPLE"
 .RS
 .ta 4n 10n
@@ -78,10 +79,10 @@ and
 (for the 
 .B file
 class) will be identified by 1, 2, 4, and 8 respectively.  Classes and permissions not listed in the mapping cannot be used.
-
+.
 .SH "AUTHOR"
 Eamon Walsh <ewalsh@tycho.nsa.gov>
-
+.
 .SH "SEE ALSO"
 .BR avc_open (8),
 .BR selinux (8)
diff --git a/libselinux/man/man3/selinux_status_open.3 b/libselinux/man/man3/selinux_status_open.3
index e897939..f779dd9 100644
--- a/libselinux/man/man3/selinux_status_open.3
+++ b/libselinux/man/man3/selinux_status_open.3
@@ -3,11 +3,12 @@
 selinux_status_open, selinux_status_close, selinux_status_updated,
 selinux_status_getenforce, selinux_status_policyload and
 selinux_status_deny_unknown \- reference the SELinux kernel status
-without invocation of system calls.
+without invocation of system calls
+.
 .SH "SYNOPSIS"
 .B #include <selinux/avc.h>
 .sp
-.BI "int selinux_status_open(int " fallback, ");"
+.BI "int selinux_status_open(int " fallback ");"
 .sp
 .BI "void selinux_status_close(void);"
 .sp
@@ -18,7 +19,7 @@ without invocation of system calls.
 .BI "int selinux_status_policyload(void);"
 .sp
 .BI "int selinux_status_deny_unknown(void);"
-.sp
+.
 .SH "DESCRIPTION"
 Linux 2.6.37 or later provides a SELinux kernel status page; being mostly
 placed on
@@ -26,15 +27,15 @@ placed on
 entry. It enables userspace applications to mmap this page with read-only
 mode, then it informs some status without system call invocations.
 .sp
-In some cases that a userspace application tries to apply heavy frequest
-access control; such as row\-level security in databases, it will face
+In some cases that a userspace application tries to apply heavy frequent
+access control; such as row-level security in databases, it will face
 unignorable cost to communicate with kernel space to check invalidation
 of userspace avc.
 .sp
 These functions provides applications a way to know some kernel events
-without system\-call invocation or worker thread for monitoring.
+without system-call invocation or worker thread for monitoring.
 .sp
-.BR selinux_status_open
+.BR selinux_status_open ()
 tries to
 .BR open (2)
 .I /selinux/status
@@ -51,46 +52,49 @@ and overwrite corresponding callbacks ( setenforce and policyload).
 Thus, we need to pay attention to the interaction with these interfaces,
 when fallback mode is enabled.
 .sp
-.BR selinux_status_close
+.BR selinux_status_close ()
 unmap the kernel status page and close its file descriptor, or close the
 netlink socket if fallbacked.
 .sp
-.BR selinux_status_updated
+.BR selinux_status_updated ()
 informs us whether something has been updated since the last call.
 It returns 0 if nothing was happened, however, 1 if something has been
-updated in this duration, or -1 on error.
+updated in this duration, or \-1 on error.
 .sp
-.BR selinux_status_getenforce
+.BR selinux_status_getenforce ()
 returns 0 if SELinux is running in permissive mode, 1 if enforcing mode,
-or -1 on error.
+or \-1 on error.
 Same as
 .BR security_getenforce (3)
 except with or without system call invocation.
 .sp
-.BR selinux_status_policyload
-returns times of policy reloaded on the running system, or -1 on error.
+.BR selinux_status_policyload ()
+returns times of policy reloaded on the running system, or \-1 on error.
 Note that it is not a reliable value on fallback-mode until it receive
 the first event message via netlink socket.
 Thus, don't use this value to know actual times of policy reloaded.
 .sp
-.BR selinux_status_deny_unknown
+.BR selinux_status_deny_unknown ()
 returns 0 if SELinux treats policy queries on undefined object classes or
-permissions as being allowed, 1 if such queries are denied, or -1 on error.
+permissions as being allowed, 1 if such queries are denied, or \-1 on error.
 .sp
 Also note that these interfaces are not thread-safe, so you have to protect
 them from concurrent calls using exclusive locks when multiple threads are
 performing.
+.
 .SH "RETURN VALUE"
-.BR selinux_status_open
+.BR selinux_status_open ()
 returns 0 or 1 on success. 1 means we are ready to use these interfaces,
 but netlink socket was opened as fallback instead of the kernel status page.
-On error, -1 shall be returned.
+On error, \-1 shall be returned.
 .sp
 Any other functions with a return value shall return its characteristic
-value as described above, or -1 on errors.
-.sp
+value as described above, or \-1 on errors.
+.
 .SH "SEE ALSO"
-.BR mmap (2)
-.BR avc_netlink_open (3)
-.BR security_getenforce (3)
+.ad l
+.nh
+.BR mmap (2),
+.BR avc_netlink_open (3),
+.BR security_getenforce (3),
 .BR security_deny_unknown (3)
diff --git a/libselinux/man/man3/set_matchpathcon_flags.3 b/libselinux/man/man3/set_matchpathcon_flags.3
index 037fe05..2841bec 100644
--- a/libselinux/man/man3/set_matchpathcon_flags.3
+++ b/libselinux/man/man3/set_matchpathcon_flags.3
@@ -1,42 +1,41 @@
 .TH "set_matchpathcon_flags" "3" "21 November 2009" "sds@tycho.nsa.gov" "SELinux API documentation"
 .SH "NAME"
-set_matchpathcon_flags, set_matchpathcon_invalidcon, set_matchpathcon_printf \- set flags controlling the operation of matchpathcon or matchpathcon_index and configure the behaviour of validity checking and error displaying.
-
+set_matchpathcon_flags, set_matchpathcon_invalidcon, set_matchpathcon_printf \- set flags controlling the operation of matchpathcon or matchpathcon_index and configure the behaviour of validity checking and error displaying
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
-
 .BI "void set_matchpathcon_flags(unsigned int " flags ");"
-
-.BI "void set_matchpathcon_invalidcon(int (*" f ")(const char *" path ", unsigned " lineno ", char * " context "));"
-
+.sp
+.BI "void set_matchpathcon_invalidcon(int (*" f ")(const char *" path ", unsigned " lineno ", char *" context "));"
+.sp
 .BI "void set_matchpathcon_printf(void (*" f ")(const char *" fmt ", ...));"
-
+.
 .SH "DESCRIPTION"
-.B set_matchpathcon_flags
+.BR set_matchpathcon_flags ()
 sets the flags controlling the operation of 
-.B matchpathcon_init
+.BR matchpathcon_init (3)
 and subsequently
-.B matchpathcon_index
+.BR matchpathcon_index (3)
 or
-.B matchpathcon.
+.BR matchpathcon (3).
 If the 
 .B MATCHPATHCON_BASEONLY
 flag is set, then only the base file contexts configuration file
 will be processed, not any dynamically generated entries or local customizations.
 .sp
 
-.B set_matchpathcon_invalidcon
+.BR set_matchpathcon_invalidcon ()
 sets the function used by 
-.B matchpathcon_init
+.BR matchpathcon_init (3)
 when checking the validity of a context in the file contexts
 configuration.  If not set, then this defaults to a test based 
 on 
-.B security_check_context(3),
+.BR security_check_context (3),
 which checks validity against the active policy on a SELinux system.
 This can be set to instead perform checking based on a binary policy file,
 e.g. using 
-.B sepol_check_context(3),
+.BR sepol_check_context (3),
 as is done by 
 .B setfiles \-c.
 The function is also responsible for reporting any such error, and
@@ -47,16 +46,17 @@ and
 in such error messages.
 .sp
 
-.B set_matchpathcon_printf
+.BR set_matchpathcon_printf ()
 sets the function used by 
-.B matchpathcon_init
+.BR matchpathcon_init (3)
 when displaying errors about the file contexts configuration.  If not set, 
 then this defaults to fprintf(stderr, fmt, ...).  This can be set to redirect
 error reporting to a different destination.
-.sp
-
+.
 .SH "RETURN VALUE"
 Returns zero on success or \-1 otherwise.
-
+.
 .SH "SEE ALSO"
+.ad l
+.nh
 .BR selinux "(8), " matchpathcon "(3), " matchpathcon_index "(3), " set_matchpathcon_invalidcon "(3), " set_matchpathcon_printf "(3), " freecon "(3), " setfilecon "(3), " setfscreatecon "(3)"
diff --git a/libselinux/man/man3/setcon_raw.3 b/libselinux/man/man3/setcon_raw.3
new file mode 100644
index 0000000..1210b5a
--- /dev/null
+++ b/libselinux/man/man3/setcon_raw.3
@@ -0,0 +1 @@
+.so man3/getcon.3
diff --git a/libselinux/man/man3/setexeccon_raw.3 b/libselinux/man/man3/setexeccon_raw.3
new file mode 100644
index 0000000..b2e6ab8
--- /dev/null
+++ b/libselinux/man/man3/setexeccon_raw.3
@@ -0,0 +1 @@
+.so man3/getexeccon.3
diff --git a/libselinux/man/man3/setfilecon.3 b/libselinux/man/man3/setfilecon.3
index 18030cd..5acc9bb 100644
--- a/libselinux/man/man3/setfilecon.3
+++ b/libselinux/man/man3/setfilecon.3
@@ -1,41 +1,66 @@
 .TH "setfilecon" "3" "1 January 2004" "russell@coker.com.au" "SELinux API documentation"
 .SH "NAME"
 setfilecon, fsetfilecon, lsetfilecon \- set SELinux security context of a file
-
+.
 .SH "SYNOPSIS"
 .B #include <selinux/selinux.h>
 .sp
 .BI "int setfilecon(const char *" path ", security_context_t "con );
-
+.sp
+.BI "int setfilecon_raw(const char *" path ", security_context_t "con );
+.sp
 .BI "int lsetfilecon(const char *" path ", security_context_t "con );
-
+.sp
+.BI "int lsetfilecon_raw(const char *" path ", security_context_t "con );
+.sp
 .BI "int fsetfilecon(int "fd ", security_context_t "con );
-
+.sp
+.BI "int fsetfilecon_raw(int "fd ", security_context_t "con );
+.
 .SH "DESCRIPTION"
-.B setfilecon
+.BR setfilecon ()
 sets the security context of the file system object.
 
-.B lsetfilecon
+.BR lsetfilecon ()
 is identical to setfilecon, except in the case of a symbolic link, where the
 link itself has it's context set, not the file that it refers to.
 
-.B fsetfilecon
+.BR fsetfilecon ()
 is identical to setfilecon, only the open file pointed to by filedes (as
-returned by open(2)) has it's context set in place of path.
+returned by
+.BR open (2))
+has it's context set in place of path.
 
+.BR setfilecon_raw (),
+.BR lsetfilecon_raw (),
+and
+.BR fsetfilecon_raw ()
+behave identically to their non-raw counterparts but do not perform context
+translation.
+.
 .SH "RETURN VALUE"
-On success, zero is returned. On failure, -1 is returned and errno is
-set appropriately.
-
+On success, zero is returned. On failure, \-1 is returned and
+.I errno
+is set appropriately.
+.
+.SH "ERRORS"
 If there is insufficient space remaining to store the extended
-attribute, errno is set to either ENOSPC, or EDQUOT if quota enforce-
-ment was the cause.
-
-If extended attributes are not supported by the filesystem, or are dis-
-abled, errno is set to ENOTSUP.
+attribute,
+.I errno
+is set to either
+.BR ENOSPC ,
+or
+.B EDQUOT
+if quota enforcement was the cause.
 
-The errors documented for the stat(2) system call are also applicable
-here.
+If extended attributes are not supported by the filesystem, or are disabled,
+.I errno
+is set to
+.BR ENOTSUP .
 
+The errors documented for the
+.BR stat (2)
+system call are also applicable here.
+.
 .SH "SEE ALSO"
 .BR selinux "(3), " freecon "(3), " getfilecon "(3), " setfscreatecon "(3)"
diff --git a/libselinux/man/man3/setfilecon_raw.3 b/libselinux/man/man3/setfilecon_raw.3
new file mode 100644
index 0000000..33c321a
--- /dev/null
+++ b/libselinux/man/man3/setfilecon_raw.3
@@ -0,0 +1 @@
+.so man3/setfilecon.3
diff --git a/libselinux/man/man3/setfscreatecon_raw.3 b/libselinux/man/man3/setfscreatecon_raw.3
new file mode 100644
index 0000000..21aeebd
--- /dev/null
+++ b/libselinux/man/man3/setfscreatecon_raw.3
@@ -0,0 +1 @@
+.so man3/getfscreatecon.3
diff --git a/libselinux/man/man3/setkeycreatecon_raw.3 b/libselinux/man/man3/setkeycreatecon_raw.3
new file mode 100644
index 0000000..1e0ec5f
--- /dev/null
+++ b/libselinux/man/man3/setkeycreatecon_raw.3
@@ -0,0 +1 @@
+.so man3/getkeycreatecon.3
diff --git a/libselinux/man/man3/setsockcreatecon_raw.3 b/libselinux/man/man3/setsockcreatecon_raw.3
new file mode 100644
index 0000000..ed1a371
--- /dev/null
+++ b/libselinux/man/man3/setsockcreatecon_raw.3
@@ -0,0 +1 @@
+.so man3/getsockcreatecon.3
diff --git a/libselinux/man/man5/booleans.5 b/libselinux/man/man5/booleans.5
index 8efc889..2e9caa7 100644
--- a/libselinux/man/man5/booleans.5
+++ b/libselinux/man/man5/booleans.5
@@ -1,8 +1,7 @@
 .TH "booleans" "5" "28-Nov-2011" "Security Enhanced Linux" "SELinux configuration"
-
 .SH "NAME"
-booleans \- The SELinux booleans configuration files.
-
+booleans \- The SELinux booleans configuration files
+.
 .SH "DESCRIPTION"
 The \fIbooleans\fR file, if present contains booleans to support a specific distribution.
 .sp
@@ -36,7 +35,7 @@ Looks for a \fIbooleans\fR and/or \fIbooleans.local\fR file at \fBselinux_boolea
 .RE
 .sp
 Where \fI{SELINUXTYPE}\fR is the entry from the selinux configuration file \fIconfig\fR (see \fBselinux_config\fR(5)).
-
+.
 .SH "FILE FORMAT"
 Both boolean files have the same format and contain one or more boolean names and their value.
 .sp
@@ -69,11 +68,13 @@ file (see
 .BR selinux_config "(5)), then " selinux_mkload_policy "(3) will check for a "
 .I booleans.local
 file in the
-.B selinux_booleans_path
+.BR selinux_booleans_path (3)
 and also a
 .I local.users
 file (see
 .BR local.users "(5)) in the " selinux_users_path "(3). "
-
+.
 .SH "SEE ALSO"
+.ad l
+.nh
 .BR selinux "(8), " booleans "(8), " setsebool "(8), " semanage "(8), " selinux_booleans_path "(3), " security_set_boolean_list "(3), " security_load_booleans "(3), " selinux_mkload_policy "(3), " selinux_users_path "(3), " selinux_config "(5), " local.users "(5) "
diff --git a/libselinux/man/man5/customizable_types.5 b/libselinux/man/man5/customizable_types.5
index c2180f9..4924f7b 100644
--- a/libselinux/man/man5/customizable_types.5
+++ b/libselinux/man/man5/customizable_types.5
@@ -1,20 +1,21 @@
 .TH "customizable_types" "5" "28-Nov-2011" "Security Enhanced Linux" "SELinux configuration"
-
 .SH "NAME"
-customizable_types \- The SELinux customizable types configuration file.
-
+customizable_types \- The SELinux customizable types configuration file
+.
 .SH "DESCRIPTION"
 The \fIcustomizable_types\fR file contains a list of types that can be customised in some way by SELinux-aware applications.
 .sp
 Generally this is a file context type that is usually set on files that need to be shared among certain domains and where the administrator wants to manually manage the type.
 .sp
 The  use  of customizable types is deprecated as the preferred approach is to use
-.B semanage fcontext ...
-(8). However, SELinux-aware applications such as
-.BR setfiles "(8) "
+.BR semanage (8)
+.BR fcontext (8)
+.BR ... (8).
+However, SELinux-aware applications such as
+.BR setfiles (8)
 will use this information to obtain a list of types relating to files that should not be relabeled.
 .sp
-.BR selinux_customizable_types_path "(3) "
+.BR selinux_customizable_types_path (3)
 will return the active policy path to this file. The default customizable types file is:
 .RS
 .I /etc/selinux/{SELINUXTYPE}/contexts/customizable_types
@@ -22,9 +23,9 @@ will return the active policy path to this file. The default customizable types
 .sp
 Where \fI{SELINUXTYPE}\fR is the entry from the selinux configuration file \fIconfig\fR (see \fBselinux_config\fR(5)).
 .sp
-.BR is_context_customizable "(3) "
+.BR is_context_customizable (3)
 reads this file to determine if a context is customisable or not for the active policy.
-
+.
 .SH "FILE FORMAT"
 Each line in the file consists of the following:
 .RS
@@ -38,7 +39,7 @@ Where:
 The type defined in the policy that can be customised.
 .RE
 .RE
-
+.
 .SH "EXAMPLE"
 # ./contexts/customizable_types
 .br
@@ -51,6 +52,8 @@ public_content_t
 swapfile_t
 .br
 sysadm_untrusted_content_t
-
+.
 .SH "SEE ALSO"
+.ad l
+.nh
 .BR selinux "(8), " selinux_customizable_types_path "(3), " is_context_customizable "(3), " semanage "(8), " setfiles "(8), " selinux_config "(5) "
diff --git a/libselinux/man/man5/default_contexts.5 b/libselinux/man/man5/default_contexts.5
index e377e55..f63d24a 100644
--- a/libselinux/man/man5/default_contexts.5
+++ b/libselinux/man/man5/default_contexts.5
@@ -1,8 +1,7 @@
 .TH "default_contexts" "5" "28-Nov-2011" "Security Enhanced Linux" "SELinux configuration"
-
 .SH "NAME"
-default_contexts \- The SELinux default contexts configuration file.
-
+default_contexts \- The SELinux default contexts configuration file
+.
 .SH "DESCRIPTION"
 The default contexts configuration file \fIdefault_contexts\fR contains entries that allow SELinux-aware login applications such as
 .BR PAM "(8) "
@@ -32,7 +31,7 @@ The default context configuration file path for the active policy is returned by
 .RE
 .sp
 Where \fI{SELINUXTYPE}\fR is the entry from the selinux configuration file \fIconfig\fR (see \fBselinux_config\fR(5)).
-
+.
 .SH "FILE FORMAT"
 Each line in the default configuration file consists of the following:
 .RS
@@ -50,7 +49,7 @@ This consists of a \fIrole\fB:\fItype\fR[\fB:\fIrange\fR] entry that represents
 This consists of one or more \fIrole\fB:\fItype\fR[\fB:\fIrange\fR] entries that represent the user login process context defined in the policy.
 .RE
 .RE
-
+.
 .SH "EXAMPLE"
 # ./contexts/default_contexts
 .br
@@ -65,6 +64,8 @@ system_r:sshd_t:s0			 user_r:user_t:s0
 system_r:sulogin_t:s0		 sysadm_r:sysadm_t:s0
 .br
 system_r:xdm_t:s0			 user_r:user_t:s0
-
+.
 .SH "SEE ALSO"
+.ad l
+.nh
 .BR selinux "(8), " selinux_default_contexts_path "(3), " PAM "(8), " selinux_default_type_path "(3), " get_default_context "(3), " get_ordered_context_list "(3), " get_ordered_context_list_with_level "(3), " get_default_context_with_level "(3), " get_default_context_with_role "(3), " get_default_context_with_rolelevel "(3), " query_user_context "(3), " manual_user_enter_context "(3), " selinux_config "(5) "
diff --git a/libselinux/man/man5/default_type.5 b/libselinux/man/man5/default_type.5
index 45f4806..082a5f0 100644
--- a/libselinux/man/man5/default_type.5
+++ b/libselinux/man/man5/default_type.5
@@ -1,8 +1,7 @@
 .TH "default_type" "5" "28-Nov-2011" "Security Enhanced Linux" "SELinux configuration"
-
 .SH "NAME"
-default_type \- The SELinux default type configuration file.
-
+default_type \- The SELinux default type configuration file
+.
 .SH "DESCRIPTION"
 The \fIdefault_type\fR file contains entries that allow SELinux-aware applications such as \fBnewrole\fR(1) to select a default type for a role if one is not supplied.
 .sp
@@ -14,7 +13,7 @@ The \fIdefault_type\fR file contains entries that allow SELinux-aware applicatio
 Where \fI{SELINUXTYPE}\fR is the entry from the selinux configuration file \fIconfig\fR (see \fBselinux_config\fR(5)).
 .sp
 \fBget_default_type\fR(3) reads this file to determine a type for the active policy.
-
+.
 .SH "FILE FORMAT"
 Each line within the \fIdefault_type\fR file is formatted with \fIrole\fB:\fItype\fR entries where:
 .RS
@@ -26,13 +25,15 @@ The SELinux role.
 .RS
 The domain type that is returned for this role.
 .RE
-
+.
 .SH "EXAMPLE"
 # ./contexts/default_type
 .br
 auditadm_r:auditadm_t
 .br
 user_r:user_t
-
+.
 .SH "SEE ALSO"
+.ad l
+.nh
 .BR selinux "(8), " get_default_type "(3), " newrole "(1), " selinux_default_type_path "(3), " selinux_config "(5) "
diff --git a/libselinux/man/man5/failsafe_context.5 b/libselinux/man/man5/failsafe_context.5
index ef8e9ac..e7032e5 100644
--- a/libselinux/man/man5/failsafe_context.5
+++ b/libselinux/man/man5/failsafe_context.5
@@ -1,8 +1,7 @@
 .TH "failsafe_context" "5" "28-Nov-2011" "Security Enhanced Linux" "SELinux configuration"
-
 .SH "NAME"
-failsafe_context \- The SELinux fail safe context configuration file.
-
+failsafe_context \- The SELinux fail safe context configuration file
+.
 .SH "DESCRIPTION"
 The
 .I failsafe_context
@@ -37,7 +36,7 @@ The following functions read this file from the active policy path if they canno
 .br
 .BR manual_user_enter_context "(3) "
 .RE
-
+.
 .SH "FILE FORMAT"
 The file consists of a single line entry as follows:
 .RS
@@ -53,11 +52,13 @@ Where:
 A role, type and optional range (for MCS/MLS), separated by colons (:) to form a valid login process context for an administrator to access the system.
 .RE
 .RE
-
+.
 .SH "EXAMPLE"
 # ./contexts/failsafe_context
 .br
 unconfined_r:unconfined_t:s0
-
+.
 .SH "SEE ALSO"
+.ad l
+.nh
 .BR selinux "(8), " selinux_failsafe_context_path "(3), " PAM "(8), " selinux_default_type_path "(3), " get_default_context "(3), " get_ordered_context_list "(3), " get_ordered_context_list_with_level "(3), " get_default_context_with_level "(3), " get_default_context_with_role "(3), " get_default_context_with_rolelevel "(3), " query_user_context "(3), " manual_user_enter_context "(3), " selinux_config "(5) "
diff --git a/libselinux/man/man5/local.users.5 b/libselinux/man/man5/local.users.5
index 8347ae8..94d4673 100644
--- a/libselinux/man/man5/local.users.5
+++ b/libselinux/man/man5/local.users.5
@@ -1,8 +1,7 @@
 .TH "local.users" "5" "28-Nov-2011" "Security Enhanced Linux" "SELinux configuration"
-
 .SH "NAME"
-local.users \- The SELinux local users configuration file.
-
+local.users \- The SELinux local users configuration file
+.
 .SH "DESCRIPTION"
 The file contains local user definitions in the form of policy language user statements and is only found on older SELinux systems as it has been deprecated and replaced by the \fBsemange\fR(8) services.
 .sp
@@ -15,7 +14,7 @@ will return the active policy path to the directory where this file is located.
 .RE
 .sp
 Where \fI{SELINUXTYPE}\fR is the entry from the selinux configuration file \fIconfig\fR (see \fBselinux_config\fR(5)).
-
+.
 .SH "FILE FORMAT"
 The file consists of one or more entries terminated with '\fB;\fR', each on a separate line as follows:
 .RS
@@ -57,11 +56,13 @@ If MLS/MCS is configured, the range keyword.
 The current and clearance levels that the user can run. These are separated by a hyphen '\fB-\fR' as shown in the \fBEXAMPLE\fR section.
 .RE
 .RE
-
+.
 .SH "EXAMPLE"
 # ./users/local.users
 .br
-user test_u roles staff_r level s0 range s0 - s15:c0.c1023;
-
+user test_u roles staff_r level s0 range s0 \- s15:c0.c1023;
+.
 .SH "SEE ALSO"
+.ad l
+.nh
 .BR selinux "(8), " semanage "(8), " selinux_users_path "(3), " selinux_config "(5), " selinux_mkload_policy "(3) "
diff --git a/libselinux/man/man5/removable_context.5 b/libselinux/man/man5/removable_context.5
index 72d3d4c..60aaa93 100644
--- a/libselinux/man/man5/removable_context.5
+++ b/libselinux/man/man5/removable_context.5
@@ -1,8 +1,7 @@
 .TH "removable_context" "5" "28-Nov-2011" "Security Enhanced Linux" "SELinux configuration"
-
 .SH "NAME"
-removable_context \- The SELinux removable devices context configuration file.
-
+removable_context \- The SELinux removable devices context configuration file
+.
 .SH "DESCRIPTION"
 This file contains the default label that should be used for removable devices that are not defined in the \fImedia\fR file (that is described in
 .BR selabel_media "(5)). "
@@ -14,7 +13,7 @@ will return the active policy path to this file. The default removable context f
 .RE
 .sp
 Where \fI{SELINUXTYPE}\fR is the entry from the selinux configuration file \fIconfig\fR (see \fBselinux_config\fR(5)).
-
+.
 .SH "FILE FORMAT"
 The file consists of a single line entry as follows:
 .RS
@@ -28,10 +27,11 @@ Where:
 A user, role, type and optional range (for MCS/MLS) separated by colons (:) that will be applied to removable devices.
 .RE
 .RE
+.
 .SH "EXAMPLE"
 # ./contexts/removable_contexts
 .br
 system_u:object_r:removable_t:s0
-
+.
 .SH "SEE ALSO"
 .BR selinux "(8), " selinux_removable_context_path "(3), " selabel_media "(5), " selinux_config "(5) "
diff --git a/libselinux/man/man5/secolor.conf.5 b/libselinux/man/man5/secolor.conf.5
index e50d560..b834577 100644
--- a/libselinux/man/man5/secolor.conf.5
+++ b/libselinux/man/man5/secolor.conf.5
@@ -1,8 +1,7 @@
 .TH "secolor.conf" "5" "08 April 2011" "SELinux API documentation"
-
 .SH "NAME"
-secolor.conf \- The SELinux color configuration file.
-
+secolor.conf \- The SELinux color configuration file
+.
 .SH "DESCRIPTION"
 This optional file controls the color to be associated to the context components associated to the 
 .I raw
@@ -15,7 +14,7 @@ obtains this color information from the active policy
 .B secolor.conf
 file as returned by 
 .BR selinux_colors_path "(3)."
-
+.
 .SH "FILE FORMAT"
 The file format is as follows:
 .RS
@@ -86,7 +85,7 @@ A
 .I color_mask
 may also be used.
 .RE
-
+.
 .SH "EXAMPLES"
 Example 1 entries are:
 .RS
@@ -112,17 +111,17 @@ role * = white black
 .br
 type * = tan orange
 .br
-range s0-s0:c0.c1023 = black green
+range s0\-s0:c0.c1023 = black green
 .br
-range s1-s1:c0.c1023 = white green
+range s1\-s1:c0.c1023 = white green
 .br
-range s3-s3:c0.c1023 = black tan
+range s3\-s3:c0.c1023 = black tan
 .br
-range s5-s5:c0.c1023 = white blue
+range s5\-s5:c0.c1023 = white blue
 .br
-range s7-s7:c0.c1023 = black red
+range s7\-s7:c0.c1023 = black red
 .br
-range s9-s9:c0.c1023 = black orange
+range s9\-s9:c0.c1023 = black orange
 .br
 range s15:c0.c1023   = black yellow
 .RE
@@ -174,8 +173,6 @@ role *            = black white
 .br
 type *            = black white
 .RE
-
+.
 .SH "SEE ALSO"
 .BR selinux "(8), " selinux_raw_context_to_color "(3), " selinux_colors_path "(3)"
-
-
diff --git a/libselinux/man/man5/securetty_types.5 b/libselinux/man/man5/securetty_types.5
index 3f13fdd..dbc5c2e 100644
--- a/libselinux/man/man5/securetty_types.5
+++ b/libselinux/man/man5/securetty_types.5
@@ -1,8 +1,7 @@
 .TH "securetty_types" "5" "28-Nov-2011" "Security Enhanced Linux" "SELinux configuration"
-
 .SH "NAME"
-securetty_types \- The SELinux secure tty type configuration file.
-
+securetty_types \- The SELinux secure tty type configuration file
+.
 .SH "DESCRIPTION"
 The
 .I securetty_types
@@ -20,7 +19,7 @@ Where \fI{SELINUXTYPE}\fR is the entry from the selinux configuration file \fIco
 .sp
 SELinux-aware applications such as
 .BR newrole "(1) use this information to check the status of a tty. "
-
+.
 .SH "FILE FORMAT"
 Each line in the file consists of the following entry:
 .sp
@@ -30,7 +29,7 @@ Each line in the file consists of the following entry:
 One or more type entries that are defined in the policy for secure tty devices.
 .RE
 .RE
-
+.
 .SH "EXAMPLE"
 # ./contexts/securetty_types
 .br
@@ -39,6 +38,8 @@ sysadm_tty_device_t
 user_tty_device_t
 .br
 staff_tty_device_t
-
+.
 .SH "SEE ALSO"
+.ad l
+.nh
 .BR selinux "(8), " selinux_securetty_types_path "(3), " newrole "(1), " selinux_check_securetty_context "(3), " selinux_config "(5) "
diff --git a/libselinux/man/man5/selabel_db.5 b/libselinux/man/man5/selabel_db.5
index c809d18..b3342f6 100644
--- a/libselinux/man/man5/selabel_db.5
+++ b/libselinux/man/man5/selabel_db.5
@@ -3,9 +3,10 @@
 .\" Author: KaiGai Kohei <kaigai@ak.jp.nec.com> 2009
 .TH "selabel_db" "5" "01 DEC 2011" "Security Enhanced Linux" "SELinux API documentation"
 .SH "NAME"
-selabel_db \- userspace SELinux labeling interface and configuration file format for the RDBMS objects context backend.
+selabel_db \- userspace SELinux labeling interface and configuration file format for the RDBMS objects context backend
+.
 .SH "SYNOPSIS"
-..B #include <selinux/label.h>
+.B #include <selinux/label.h>
 .sp
 .BI "int selabel_lookup(struct selabel_handle *" hnd ,
 .in +\w'int selabel_lookup('u
@@ -19,7 +20,7 @@ selabel_db \- userspace SELinux labeling interface and configuration file format
 .BI "security_context_t *" context ,
 .br
 .BI "const char *" object_name ", int " object_type ");"
-
+.
 .SH "DESCRIPTION"
 The DB contexts backend maps from a pair of object name and class into security contexts. It is used to find the appropriate context for database objects when relabeling a certain database. The returned \fIcontext\fR must be freed using \fBfreecon\fR(3).
 .br
@@ -87,13 +88,15 @@ The
 argument specifies the name of a language object, such as "postgres.public.tcl".
 .RE
 .sp
-Any messages generated by \fBselabel_lookup\fR are sent to \fIstderr\fR by default, although this can be changed by \fBselinux_set_callback\fR(3).
+Any messages generated by \fBselabel_lookup\fR(3) are sent to \fIstderr\fR
+by default, although this can be changed by \fBselinux_set_callback\fR(3).
 .sp
-.B selabel_lookup_raw
-behaves identically to \fBselabel_lookup\fR but does not perform context translation.
+.BR selabel_lookup_raw (3)
+behaves identically to \fBselabel_lookup\fR(3) but does not perform context
+translation.
 .sp
 The \fBFILES\fR section details the configuration files used to determine the database object context.
-
+.
 .SH "OPTIONS"
 In addition to the global options described in \fBselabel_open\fR(3), this backend recognizes the following options:
 .RS
@@ -102,7 +105,7 @@ In addition to the global options described in \fBselabel_open\fR(3), this backe
 A non-null value for this option specifies a path to a file that will be opened in lieu of the standard DB contexts file.
 It tries to open the specfile designed for SE-PostgreSQL as default, so if another RDBMS uses this interface, it needs to give an explicit specfile designed for that RDBMS (see the \fBFILES\fR section for details).
 .RE
-
+.
 .SH "FILES"
 The database context file used to retrieve a context depends on the \fBSELABEL_OPT_PATH\fR parameter passed to \fBselabel_open\fR(3). If \fINULL\fR, then the \fBSELABEL_OPT_PATH\fR value will default to the active policy database contexts location (as returned by \fBselinux_sepgsql_context_path\fR(3)), otherwise the actual \fBSELABEL_OPT_PATH\fR value specified is used (this option must be used to support databases other than SE-PostgreSQL).
 .sp
@@ -114,7 +117,7 @@ The default database object contexts file is:
 Where \fI{SELINUXTYPE}\fR is the entry from the selinux configuration file \fIconfig\fR (see \fBselinux_config\fR(5)).
 .sp
 The entries within the database contexts file are shown in the \fBObject Name String Values\fR and \fBFILE FORMAT\fR sections.
-
+.
 .SH "Object Name String Values"
 The string name assigned to each \fIobject_type\fR argument that can be present in the database contexts file are:
 .TS
@@ -133,7 +136,7 @@ SELABEL_DB_PROCEDURE@db_procedure
 SELABEL_DB_SEQUENCE@db_sequence
 SELABEL_DB_BLOB@db_blob
 .TE
-
+.
 .SH "FILE FORMAT"
 Each line within the database contexts file is as follows:
 .RS
@@ -177,7 +180,7 @@ db_tuple       row_low       system_u:object_r:sepgsql_table_t:s0
 db_tuple       row_high      system_u:object_r:sepgsql_table_t:s0:c1023
 .br
 db_tuple       *.*.*         system_u:object_r:sepgsql_table_t:s0
-
+.
 .SH "NOTES"
 .IP "1." 4
 A suitable database contexts file needs to be written for the target RDBMS and the \fBSELABEL_OPT_PATH\fR option must be used in \fBselabel_open\fR(3) to load it.
@@ -188,11 +191,17 @@ SE-PostgreSQL has a namespace hierarchy where a database is the top level object
 .RS
 .RS
 .sp
-If a security context is required for "my_table" table in the "public" schema within the "postgres" database, then the \fBselabel_lookup\fR parameters for \fIobject_type\fR would be \fBSELABEL_DB_TABLE\fR and the \fIobject_name\fR would be "postgres.public.my_table", the security context (if available), would be returned in \fIcontext\fR.
+If a security context is required for "my_table" table in the "public"
+schema within the "postgres" database, then the \fBselabel_lookup\fR(3)
+parameters for \fIobject_type\fR would be \fBSELABEL_DB_TABLE\fR and the
+\fIobject_name\fR would be "postgres.public.my_table", the security
+context (if available), would be returned in \fIcontext\fR.
 .RE
 .RE
 .IP "3." 4
 If contexts are to be validated, then the global option \fBSELABEL_OPT_VALIDATE\fR must be set before calling \fBselabel_open\fR(3). If this is not set, then it is possible for an invalid context to be returned.
-
+.
 .SH "SEE ALSO"
+.ad l
+.nh
 .BR selinux "(8), " selabel_open "(3), " selabel_lookup "(3), " selabel_stats "(3), " selabel_close "(3), " selinux_set_callback "(3), " selinux_sepgsql_context_path "(3), " freecon "(3), " selinux_config "(5) "
diff --git a/libselinux/man/man5/selabel_file.5 b/libselinux/man/man5/selabel_file.5
index 8a1f826..5703f27 100644
--- a/libselinux/man/man5/selabel_file.5
+++ b/libselinux/man/man5/selabel_file.5
@@ -3,7 +3,8 @@
 .\" Author: Eamon Walsh (ewalsh@tycho.nsa.gov) 2007
 .TH "selabel_file" "5" "01 Dec 2011" "Security Enhanced Linux" "SELinux API documentation"
 .SH "NAME"
-selabel_file \- userspace SELinux labeling interface and configuration file format for the file contexts backend.
+selabel_file \- userspace SELinux labeling interface and configuration file format for the file contexts backend
+.
 .SH "SYNOPSIS"
 .B #include <selinux/label.h>
 .sp
@@ -19,7 +20,7 @@ selabel_file \- userspace SELinux labeling interface and configuration file form
 .BI "security_context_t *" context ,
 .br
 .BI "const char *" path ", int " mode ");"
-
+.
 .SH "DESCRIPTION"
 The file contexts backend maps from pathname/mode combinations into security contexts. It is used to find the appropriate context for each file when relabeling a file system. The returned \fIcontext\fR must be freed using \fBfreecon\fR(3).
 .br
@@ -32,13 +33,15 @@ No context corresponding to the \fIpath\fR and \fImode\fR was found - This will
 .sp
 The \fIpath\fR argument should be set to the full pathname of the file whose assigned context is being checked. The \fImode\fR argument should be set to the mode bits of the file, as determined by \fBlstat\fR(2). \fImode\fR may be zero, however full matching may not occur.
 .sp
-Any messages generated by \fBselabel_lookup\fR are sent to \fIstderr\fR by default, although this can be changed by \fBselinux_set_callback\fR(3).
+Any messages generated by \fBselabel_lookup\fR(3) are sent to \fIstderr\fR
+by default, although this can be changed by \fBselinux_set_callback\fR(3).
 .sp
-.B selabel_lookup_raw
-behaves identically to \fBselabel_lookup\fR but does not perform context translation.
+.BR selabel_lookup_raw (3)
+behaves identically to \fBselabel_lookup\fR(3) but does not perform context
+translation.
 .sp
 The \fBFILES\fR section details the configuration files used to determine a file context.
-
+.
 .SH "OPTIONS"
 In addition to the global options described in 
 .BR selabel_open (3),
@@ -54,7 +57,7 @@ A non-null value for this option indicates that any local customizations to the
 .B SELABEL_OPT_SUBSET
 A non-null value for this option is interpreted as a path prefix, for example "/etc".  Only file context specifications starting with the given prefix are loaded.  This may increase lookup performance, however any attempt to look up a path not starting with the given prefix will fail.
 .RE
-
+.
 .SH "FILES"
 The file context files used to retrieve the default context depends on the \fBSELABEL_OPT_PATH\fR parameter passed to \fBselabel_open\fR(3). If \fINULL\fR, then the \fBSELABEL_OPT_PATH\fR value will default to the active policy file contexts location (as returned by \fBselinux_file_context_path\fR(3)), otherwise the actual \fBSELABEL_OPT_PATH\fR value specified is used.
 .sp
@@ -104,7 +107,7 @@ Where \fI{SELINUXTYPE}\fR is the entry from the selinux configuration file \fIco
 Only the \fIfile_contexts\fR file is mandatory, the remainder are optional.
 .sp
 The entries within the file contexts series of files are shown in the \fBFILE FORMAT\fR section.
-
+.
 .SH "FILE FORMAT"
 .sp
 .SH "File Contexts Format"
@@ -126,13 +129,13 @@ An entry that defines the pathname that may be in the form of a regular expressi
 .RS
 An optional file type consisting of:
 .RS
-\fI\-b\fR \- Block Device      \fI\-c\fR \- Character Device
+\fI\-b\fR - Block Device      \fI\-c\fR - Character Device
 .br
-\fI\-d\fR \- Directory         \fI\-p\fR \- Named Pipe
+\fI\-d\fR - Directory         \fI\-p\fR - Named Pipe
 .br
-\fI\-l\fR \- Symbolic Link     \fI\-s\fR \- Socket
+\fI\-l\fR - Symbolic Link     \fI\-s\fR - Socket
 .br
-\fI\-\-\fR \- Ordinary file
+\fI\-\-\fR - Ordinary file
 .RE
 .RE
 .I context
@@ -155,12 +158,11 @@ Example:
 .br
 /.*                   system_u:object_r:default_t:s0
 .br
-/[^/]+        --      system_u:object_r:etc_runtime_t:s0
+/[^/]+        \-\-      system_u:object_r:etc_runtime_t:s0
 .br
 /tmp/.*               <<none>>
 .RE
 .sp
-
 .SH "Substitution File Format"
 .sp
 Each line within the substitution files (\fI.subs\fR and \fI.subs_dist\fR) has the form:
@@ -190,14 +192,15 @@ Example:
 .br
 /myspool    /var/spool/mail
 .sp
-Using the above example, when \fBselabel_lookup\fR is passed a path of \fI/myweb/index.html\fR the function will substitute the \fI/myweb\fR component with \fI/var/www\fR, therefore the path used is:
+Using the above example, when \fBselabel_lookup\fR(3) is passed a path of
+\fI/myweb/index.html\fR the function will substitute the \fI/myweb\fR
+component with \fI/var/www\fR, therefore the path used is:
 .sp
 .RS
 .I /var/www/index.html
 .RE
 .RE
-.sp
-
+.
 .SH "NOTES"
 .IP "1." 4
 If contexts are to be validated, then the global option \fBSELABEL_OPT_VALIDATE\fR must be set before calling \fBselabel_open\fR(3). If this is not set, then it is possible for an invalid context to be returned.
@@ -208,6 +211,8 @@ requested validates the entries. If possible use the \fBSELABEL_OPT_SUBSET\fR op
 Depending on the version of SELinux it is possible that a \fIfile_contexts.template\fR file may also be present, however this is now deprecated.
 .br
 The template file has the same format as the \fIfile_contexts\fR file and may also contain the keywords \fBHOME_ROOT\fR, \fBHOME_DIR\fR, \fBROLE\fR and \fBUSER\fR. This functionality has now been moved to the policy store and managed by \fBsemodule\fR(8) and \fBgenhomedircon\fR(8).
-
+.
 .SH "SEE ALSO"
+.ad l
+.nh
 .BR selinux "(8), " selabel_open "(3), " selabel_lookup "(3), " selabel_stats "(3), " selabel_close "(3), " selinux_set_callback "(3), " selinux_file_context_path "(3), " freecon "(3), " selinux_config "(5), " lstat "(2), "selinux_file_context_subs_path "(3), " selinux_file_context_subs_dist_path "(3), " selinux_file_context_homedir_path "(3), "selinux_file_context_local_path "(3), " semodule "(8), " genhomedircon "(8) "
diff --git a/libselinux/man/man5/selabel_media.5 b/libselinux/man/man5/selabel_media.5
index 0df1961..398f0fc 100644
--- a/libselinux/man/man5/selabel_media.5
+++ b/libselinux/man/man5/selabel_media.5
@@ -3,8 +3,8 @@
 .\" Author: Eamon Walsh (ewalsh@tycho.nsa.gov) 2007
 .TH "selabel_media" "5" "29 Nov 2011" "Security Enhanced Linux" "SELinux API documentation"
 .SH "NAME"
-selabel_media \- userspace SELinux labeling interface and configuration file format for the media contexts backend.
-
+selabel_media \- userspace SELinux labeling interface and configuration file format for the media contexts backend
+.
 .SH "SYNOPSIS"
 .B #include <selinux/label.h>
 .sp
@@ -20,7 +20,7 @@ selabel_media \- userspace SELinux labeling interface and configuration file for
 .BI "security_context_t *" context ,
 .br
 .BI "const char *" device_name ", int " unused ");"
-
+.
 .SH "DESCRIPTION"
 The media contexts backend maps from media device names such as "cdrom" or "floppy" into security contexts. It is used to find the appropriate context for establishing context mounts on these devices. The returned \fIcontext\fR must be freed using \fBfreecon\fR(3).
 .br
@@ -28,19 +28,21 @@ The media contexts backend maps from media device names such as "cdrom" or "flop
 .sp
 The integer lookup argument is currently unused and should be set to zero.
 .sp
-Any messages generated by \fBselabel_lookup\fR are sent to \fIstderr\fR by default, although this can be changed by \fBselinux_set_callback\fR(3).
+Any messages generated by \fBselabel_lookup\fR(3) are sent to \fIstderr\fR
+by default, although this can be changed by \fBselinux_set_callback\fR(3).
 .sp
-.B selabel_lookup_raw
-behaves identically to \fBselabel_lookup\fR but does not perform context translation.
+.BR selabel_lookup_raw (3)
+behaves identically to \fBselabel_lookup\fR(3) but does not perform context
+translation.
 .sp
 The \fBFILES\fR section details the configuration files used to determine the media context.
-
+.
 .SH "OPTIONS"
 In addition to the global options described in \fBselabel_open\fR(3), this backend recognizes the following options:
 .TP
 .B SELABEL_OPT_PATH
 A non-null value for this option specifies a path to a file that will be opened in lieu of the standard \fImedia\fR contexts file.
-
+.
 .SH "FILES"
 The media context file used to retrieve a default context depends on the \fBSELABEL_OPT_PATH\fR parameter passed to \fBselabel_open\FR(3). If \fINULL\fR, then the \fBSELABEL_OPT_PATH\fR value will default to the active policy media contexts location (as returned by \fBselinux_media_context_path\fR(3)), otherwise the actual \fBSELABEL_OPT_PATH\fR value specified is used.
 .sp
@@ -52,7 +54,7 @@ The default media contexts file is:
 Where \fI{SELINUXTYPE}\fR is the entry from the selinux configuration file \fIconfig\fR (see \fBselinux_config\fR(5)).
 .sp
 Should there not be a valid entry in the \fImedia\fR file, then the default \fIremovable_context\fR file will be read (see \fBremovable_context\fR(5)).
-
+.
 .SH "FILE FORMAT"
 Each line within the \fImedia\fR file is as follows:
 .RS
@@ -80,10 +82,12 @@ cdrom system_u:object_r:removable_device_t
 floppy system_u:object_r:removable_device_t
 .br
 disk system_u:object_r:fixed_disk_device_t
-
+.
 .SH "NOTES"
 If contexts are to be validated, then the global option \fBSELABEL_OPT_VALIDATE\fR must be set before calling \fBselabel_open\fR(3). If
 this is not set, then it is possible for an invalid context to be returned.
-
+.
 .SH "SEE ALSO"
+.ad l
+.nh
 .BR selinux "(8), " selabel_open "(3), " selabel_lookup "(3), " selabel_stats "(3), " selabel_close "(3), " selinux_set_callback "(3), " selinux_media_context_path "(3), " freecon "(3), " selinux_config "(5), " removable_context "(5) "
diff --git a/libselinux/man/man5/selabel_x.5 b/libselinux/man/man5/selabel_x.5
index 60bf3f2..5a38a8d 100644
--- a/libselinux/man/man5/selabel_x.5
+++ b/libselinux/man/man5/selabel_x.5
@@ -2,10 +2,9 @@
 .\"
 .\" Author: Eamon Walsh (ewalsh@tycho.nsa.gov) 2007
 .TH "selabel_x" "5" "29 Nov 2011" "Security Enhanced Linux" "SELinux API documentation"
-
 .SH "NAME"
-selabel_x \- userspace SELinux labeling interface and configuration file format for the X Window System contexts backend. This backend is also used to determine the default context for labeling remotely connected X clients.
-
+selabel_x \- userspace SELinux labeling interface and configuration file format for the X Window System contexts backend. This backend is also used to determine the default context for labeling remotely connected X clients
+.
 .SH "SYNOPSIS"
 .B #include <selinux/label.h>
 .sp
@@ -21,7 +20,7 @@ selabel_x \- userspace SELinux labeling interface and configuration file format
 .BI "security_context_t *" context ,
 .br
 .BI "const char *" object_name ", int " object_type ");"
-
+.
 .SH "DESCRIPTION"
 The X contexts backend maps from X Window System object names into security contexts. It is used to find the appropriate context for X Window System objects whose significance and/or usage semantics are determined primarily by name. The returned \fIcontext\fR must be freed using \fBfreecon\fR(3).
 .br
@@ -74,7 +73,7 @@ Any messages generated by \fBselabel_lookup\fR(3) are sent to \fIstderr\fR by de
 behaves identically to \fBselabel_lookup\fR but does not perform context translation.
 .sp
 The \fBFILES\fR section details the configuration files used to determine the X object context.
-
+.
 .SH "OPTIONS"
 In addition to the global options described in \fBselabel_open\fR(3), this backend recognizes the following options:
 .RS
@@ -82,7 +81,7 @@ In addition to the global options described in \fBselabel_open\fR(3), this backe
 .B SELABEL_OPT_PATH
 A non-null value for this option specifies a path to a file that will be opened in lieu of the standard X contexts file (see the \fBFILES\fR section for details).
 .RE
-
+.
 .SH "FILES"
 The X context file used to retrieve a default context depends on the \fBSELABEL_OPT_PATH\fR parameter passed to \fBselabel_open\fR(3). If \fINULL\fR, then the \fBSELABEL_OPT_PATH\fR value will default to the active policy X contexts location (as returned by \fBselinux_x_context_path\fR(3)), otherwise the actual \fBSELABEL_OPT_PATH\fR value specified is used.
 .sp
@@ -94,7 +93,7 @@ The default X object contexts file is:
 Where \fI{SELINUXTYPE}\fR is the entry from the selinux configuration file \fIconfig\fR (see \fBselinux_config\fR(5)).
 .sp
 The entries within the X contexts file are shown in the \fBObject Name String Values\fR and \fBFILE FORMAT\fR sections.
-
+.
 .SH "Object Name String Values"
 The string name assigned to each \fIobject_type\fR argument that can be present in the X contexts file are:
 .TS
@@ -110,7 +109,7 @@ SELABEL_X_CLIENT@client
 SELABEL_X_POLYPROP@poly_property
 SELABEL_X_POLYSELN@poly_selection
 .TE
-
+.
 .SH "FILE FORMAT"
 Each line within the X contexts file is as follows:
 .RS
@@ -126,7 +125,10 @@ There can be multiple lines with the same \fIobject_type\fR string that will for
 .RE
 .I object_name
 .RS
-These are the object names of the specific X-server resource such as \fBPRIMARY\fR, \fBCUT_BUFFER0\fR etc. They are generally defined in the X\-server source code (\fIprotocol.txt\fR and \fIBuiltInAtoms\fR in the dix directory of the xorg\-server source package).
+These are the object names of the specific X-server resource such as
+\fBPRIMARY\fR, \fBCUT_BUFFER0\fR etc. They are generally defined in the
+X-server source code (\fIprotocol.txt\fR and \fIBuiltInAtoms\fR in the
+dix directory of the xorg\-server source package).
 The entry can contain '*' for wildcard matching or '?' for substitution.
 Note that if the '*' is used, then be aware that the order of entries in the file is important. The '*' on its own is used to ensure a default fallback context is assigned and should be the last entry in the \fIobject_type\fR block.
 .RE
@@ -138,23 +140,27 @@ The security context that will be applied to the object.
 .sp
 Example 1:
 .sp
+.nf
 # object_type  object_name  context
-.br
 selection      PRIMARY      system_u:object_r:clipboard_xselection_t:s0
-.br
 selection      *            system_u:object_r:xselection_t:s0
+.fi
 .sp
-Example 2 \- This example shows how a client entry can be configured to ensure an entry is always found:
+Example 2 - This example shows how a client entry can be configured to
+ensure an entry is always found:
 .sp
+.nf
 # object_type  object_name  context
-.br
 client         *            system_u:object_r:remote_t:s0
-
+.fi
+.
 .SH "NOTES"
 .IP "1." 4
 Properties and selections are marked as either polyinstantiated or not. For these name types, the "POLY" option searches only the names marked as being polyinstantiated, while the other option searches only the names marked as not being polyinstantiated. Users of the interface should check both mappings, optionally taking action based on the result (e.g. polyinstantiating the object).
 .IP "2." 4
 If contexts are to be validated, then the global option \fBSELABEL_OPT_VALIDATE\fR must be set before calling \fBselabel_open\fR(3). If this is not set, then it is possible for an invalid context to be returned.
-
+.
 .SH "SEE ALSO"
+.ad l
+.nh
 .BR selinux "(8), " selabel_open "(3), " selabel_lookup "(3), " selabel_stats "(3), " selabel_close "(3), " selinux_set_callback "(3), " selinux_x_context_path "(3), " freecon "(3), " selinux_config "(5) "
diff --git a/libselinux/man/man5/service_seusers.5 b/libselinux/man/man5/service_seusers.5
index 59a135a..385a326 100644
--- a/libselinux/man/man5/service_seusers.5
+++ b/libselinux/man/man5/service_seusers.5
@@ -1,8 +1,7 @@
 .TH "service_seusers" "5" "28-Nov-2011" "Security Enhanced Linux" "SELinux configuration"
-
 .SH "NAME"
-service_seusers \- The SELinux GNU/Linux user and service to SELinux user mapping configuration files.
-
+service_seusers \- The SELinux GNU/Linux user and service to SELinux user mapping configuration files
+.
 .SH "DESCRIPTION"
 These are optional files that allow services to define an SELinux user when authenticating via SELinux-aware login applications such as
 .BR PAM "(8). "
@@ -20,7 +19,7 @@ appended (where \fIusername\fR is a file representing the GNU/Linux user name).
 Where \fI{SELINUXTYPE}\fR is the entry from the selinux configuration file \fIconfig\fR (see \fBselinux_config\fR(5)).
 .sp
 .BR getseuser "(3) reads this file to map services to an SELinux user. "
-
+.
 .SH "FILE FORMAT"
 Each line within the \fIusername\fR file is formatted as follows with each component separated by a colon:
 .RS
@@ -42,9 +41,9 @@ The SELinux user name.
 The range for MCS/MLS policies.
 .RE
 .RE
-
+.
 .SH "EXAMPLES"
-Example 1 \- for the 'root' user:
+Example 1 - for the 'root' user:
 .RS
 # ./logins/root
 .br
@@ -53,7 +52,7 @@ ipa:user_u:s0
 this_service:unconfined_u:s0
 .RE
 .sp
-Example 2 \- for GNU/Linux user 'rch':
+Example 2 - for GNU/Linux user 'rch':
 .RS
 # ./logins/rch
 .br
@@ -61,6 +60,8 @@ ipa:unconfined_u:s0
 .br
 that_service:unconfined_u:s0
 .RE
-
+.
 .SH "SEE ALSO"
+.ad l
+.nh
 .BR selinux "(8), " PAM "(8), " selinux_policy_root "(3), " getseuser "(3), " selinux_config "(5) "
diff --git a/libselinux/man/man5/seusers.5 b/libselinux/man/man5/seusers.5
index 8c99ee8..2512560 100644
--- a/libselinux/man/man5/seusers.5
+++ b/libselinux/man/man5/seusers.5
@@ -1,8 +1,7 @@
 .TH "seusers" "5" "28-Nov-2011" "Security Enhanced Linux" "SELinux configuration"
-
 .SH "NAME"
-seusers \- The SELinux GNU/Linux user to SELinux user mapping configuration file.
-
+seusers \- The SELinux GNU/Linux user to SELinux user mapping configuration file
+.
 .SH "DESCRIPTION"
 The
 .I seusers
@@ -17,7 +16,7 @@ will return the active policy path to this file. The default SELinux users mappi
 Where \fI{SELINUXTYPE}\fR is the entry from the selinux configuration file \fIconfig\fR (see \fBselinux_config\fR(5)).
 .sp
 .BR getseuserbyname "(3) reads this file to map a GNU/Linux user or group to an SELinux user. "
-
+.
 .SH "FILE FORMAT"
 Each line of the
 .I seusers
@@ -44,19 +43,21 @@ The SELinux  user identity.
 The optional level or range for an MLS/MCS policy.
 .RE
 .RE
-
+.
 .SH "EXAMPLE"
 # ./seusers
 .br
 system_u:system_u:s0\-s15:c0.c255
 .br
-root:root:s0-s15:c0.c255
+root:root:s0\-s15:c0.c255
 .br
 fred:user_u:s0
 .br
 __default__:user_u:s0
 .br
 %user_group:user_u:s0
-
+.
 .SH "SEE ALSO"
+.ad l
+.nh
 .BR selinux "(8), " PAM "(8), " selinux_usersconf_path "(3), " getseuserbyname "(3), " selinux_config "(5) "
diff --git a/libselinux/man/man5/user_contexts.5 b/libselinux/man/man5/user_contexts.5
index 2b3df7a..fc53d6c 100644
--- a/libselinux/man/man5/user_contexts.5
+++ b/libselinux/man/man5/user_contexts.5
@@ -1,8 +1,7 @@
 .TH "user_contexts" "5" "28-Nov-2011" "Security Enhanced Linux" "SELinux configuration"
-
 .SH "NAME"
-user_contexts \- The SELinux user contexts configuration files.
-
+user_contexts \- The SELinux user contexts configuration files
+.
 .SH "DESCRIPTION"
 These optional user context configuration files contain entries that allow SELinux-aware login applications such as
 .BR PAM (8)
@@ -28,7 +27,7 @@ SELinux-aware login applications generally use one or more of the following libs
 .RE
 .sp
 There can be one file for each SELinux user configured on the system. The file  path is formed using the path returned by
-.BR selinux_user_contexts_path (3)
+.BR \%selinux_user_contexts_path (3)
 for the active policy, with the SELinux user name appended, for example:
 .RS
 .I /etc/selinux/{SELINUXTYPE}/contexts/users/unconfined_u
@@ -41,7 +40,7 @@ Where \fI{SELINUXTYPE}\fR is the entry from the selinux configuration file \fIco
 These files contain context information as described in the
 .B FILE FORMAT
 section.
-
+.
 .SH "FILE FORMAT"
 Each line in the user context configuration file consists of the following:
 .RS
@@ -59,7 +58,7 @@ This consists of a \fIrole\fB:\fItype\fR[\fB:\fIrange\fR] entry that represents
 This consists of a \fIrole\fB:\fItype\fR[\fB:\fIrange\fR] entry that represents the user login process context.
 .RE
 .RE
-
+.
 .SH "EXAMPLE"
 # Example for xguest_u at /etc/selinux/targeted/contexts/users/xguest_u
 .br
@@ -76,6 +75,8 @@ system_r:sshd_t:s0			xguest_r:xguest_t:s0
 system_r:xdm_t:s0			xguest_r:xguest_t:s0
 .br
 xguest_r:xguest_t:s0		xguest_r:xguest_t:s0
-
+.
 .SH "SEE ALSO"
+.ad l
+.nh
 .BR selinux "(8), " selinux_user_contexts_path "(3), " PAM "(8), "  get_ordered_context_list "(3), " get_ordered_context_list_with_level "(3), " get_default_context_with_level "(3), " get_default_context_with_role "(3), " get_default_context_with_rolelevel "(3), " query_user_context "(3), " manual_user_enter_context "(3), " selinux_config "(5) "
diff --git a/libselinux/man/man5/virtual_domain_context.5 b/libselinux/man/man5/virtual_domain_context.5
index 6048f98..2f555a0 100644
--- a/libselinux/man/man5/virtual_domain_context.5
+++ b/libselinux/man/man5/virtual_domain_context.5
@@ -1,8 +1,7 @@
 .TH "virtual_domain_context" "5" "28-Nov-2011" "Security Enhanced Linux" "SELinux configuration"
-
 .SH "NAME"
-virtual_domain_context \- The SELinux virtual machine domain context configuration file.
-
+virtual_domain_context \- The SELinux virtual machine domain context configuration file
+.
 .SH "DESCRIPTION"
 The
 .I virtual_domain_context
@@ -15,7 +14,7 @@ will return the active policy path to this file. The default virtual domain cont
 .RE
 .sp
 Where \fI{SELINUXTYPE}\fR is the entry from the selinux configuration file \fIconfig\fR (see \fBselinux_config\fR(5)).
-
+.
 .SH "FILE FORMAT"
 Each line in the file consists of an entry as follows:
 .RS
@@ -29,11 +28,13 @@ Where:
 A user, role, type and optional range (for MCS/MLS) separated by colons (:) that can be used as a virtual domain context.
 .RE
 .RE
-
+.
 .SH "EXAMPLE"
 # ./contexts/virtual_domain_context
 .br
 system_u:object_r:svirt_t:s0
-
+.
 .SH "SEE ALSO"
+.ad l
+.nh
 .BR selinux "(8), " libvirtd "(8), " selinux_virtual_domain_context_path "(3), " selinux_config "(5) "
diff --git a/libselinux/man/man5/virtual_image_context.5 b/libselinux/man/man5/virtual_image_context.5
index 4e9809b..04cbd79 100644
--- a/libselinux/man/man5/virtual_image_context.5
+++ b/libselinux/man/man5/virtual_image_context.5
@@ -1,8 +1,7 @@
 .TH "virtual_image_context" "5" "28-Nov-2011" "Security Enhanced Linux" "SELinux configuration"
-
 .SH "NAME"
-virtual_image_context \- The SELinux virtual machine image context configuration file.
-
+virtual_image_context \- The SELinux virtual machine image context configuration file
+.
 .SH "DESCRIPTION"
 The
 .I virtual_image_context
@@ -15,7 +14,7 @@ will return the active policy path to this file. The default virtual image conte
 .RE
 .sp
 Where \fI{SELINUXTYPE}\fR is the entry from the selinux configuration file \fIconfig\fR (see \fBselinux_config\fR(5)).
-
+.
 .SH "FILE FORMAT"
 Each line in the file consists of an entry as follows:
 .RS
@@ -29,13 +28,15 @@ Where:
 A user, role, type and optional range (for MCS/MLS) separated by colons (:) that can be used as a virtual image context.
 .RE
 .RE
-
+.
 .SH "EXAMPLE"
 # ./contexts/virtual_image_context
 .br
 system_u:object_r:svirt_image_t:s0
 .br
 system_u:object_r:svirt_content_t:s0
-
+.
 .SH "SEE ALSO"
+.ad l
+.nh
 .BR selinux "(8), " libvirtd "(8), " selinux_virtual_image_context_path "(3), " selinux_config "(5) "
diff --git a/libselinux/man/man8/avcstat.8 b/libselinux/man/man8/avcstat.8
index 1035331..6251591 100644
--- a/libselinux/man/man8/avcstat.8
+++ b/libselinux/man/man8/avcstat.8
@@ -1,31 +1,35 @@
 .TH "avcstat" "8" "18 Nov 2004" "dwalsh@redhat.com" "SELinux Command Line documentation"
 .SH "NAME"
 avcstat \- Display SELinux AVC statistics
-
+.
 .SH "SYNOPSIS"
 .B avcstat
-.I [-c] [-f status_file] [interval]
-
+.RB [ \-c ]
+.RB [ \-f
+.IR status_file ]
+.RI [ interval ]
+.
 .SH "DESCRIPTION"
-.B avcstat 
-
-Display SELinux AVC statistics.  If the interval parameter is specified, the
-program will loop, displaying updated statistics every 'interval' seconds.
+Display SELinux AVC statistics.  If the
+.I interval
+parameter is specified, the program will loop, displaying updated
+statistics every
+.I interval
+seconds.
 Relative values are displayed by default. 
-
+.
 .SH OPTIONS
 .TP
 .B \-c
 Display the cumulative values.
-
 .TP
 .B \-f
-Specifies the location of the AVC statistics file, defaulting to '/selinux/avc/cache_stats'.
-
-.SH "SEE ALSO"
-selinux(8)
-
+Specifies the location of the AVC statistics file, defaulting to
+.IR /selinux/avc/cache_stats .
+.
 .SH AUTHOR	
 This manual page was written by Dan Walsh <dwalsh@redhat.com>.
 The program was written by James Morris <jmorris@redhat.com>.
-
+.
+.SH "SEE ALSO"
+.BR selinux (8)
diff --git a/libselinux/man/man8/booleans.8 b/libselinux/man/man8/booleans.8
index 89c7654..9c4dbc3 100644
--- a/libselinux/man/man8/booleans.8
+++ b/libselinux/man/man8/booleans.8
@@ -1,11 +1,10 @@
 .TH "booleans" "8" "11 Aug 2004" "dwalsh@redhat.com" "SELinux Command Line documentation"
 .SH "NAME"
-booleans \- Policy booleans enable runtime customization of SELinux policy.
-
+booleans \- Policy booleans enable runtime customization of SELinux policy
+.
 .SH "DESCRIPTION"
 This manual page describes SELinux policy booleans.
 .BR
-
 The SELinux policy can include conditional rules that are enabled or
 disabled based on the current values of a set of policy booleans.
 These policy booleans allow runtime modification of the security
@@ -18,32 +17,42 @@ value.
 
 The policy defines a default value for each boolean, typically false.
 These default values can be overridden via local settings created via the
-.B setsebool(8)
-utility, using -P to make the setting persistent across reboots.
-The 
-.B system-config-securitylevel
+.BR setsebool (8)
+utility, using
+.B \-P
+to make the setting persistent across reboots.  The
+.B system\-config\-securitylevel
 tool provides a graphical interface for altering
 the settings.  The
-.B load_policy(8)
+.BR load_policy (8)
 program will preserve
 current boolean settings upon a policy reload by default, or can
-optionally reset booleans to the boot-time defaults via the -b option.
+optionally reset booleans to the boot-time defaults via the
+.B \-b
+option.
 
 Boolean values can be listed by using the
-.B getsebool(8)
-utility and passing it the -a option.
+.BR getsebool (8)
+utility and passing it the
+.B \-a
+option.
 
 Boolean values can also be changed at runtime via the
-.B setsebool(8)
+.BR setsebool (8)
 utility or the
-.B togglesebool
+.BR togglesebool (8)
 utility.  By default, these utilities only change the
 current boolean value and do not affect the persistent settings,
-unless the -P option is used to setsebool.
-
+unless the
+.B \-P
+option is used to setsebool.
+.
 .SH AUTHOR	
 This manual page was written by Dan Walsh <dwalsh@redhat.com>.
 The SELinux conditional policy support was developed by Tresys Technology.
-
+.
 .SH "SEE ALSO"
-getsebool(8), setsebool(8), selinux(8), togglesebool(8)
+.BR getsebool (8),
+.BR setsebool (8),
+.BR selinux (8),
+.BR togglesebool (8)
diff --git a/libselinux/man/man8/getenforce.8 b/libselinux/man/man8/getenforce.8
index 8dc63c8..906279f 100644
--- a/libselinux/man/man8/getenforce.8
+++ b/libselinux/man/man8/getenforce.8
@@ -1,15 +1,18 @@
 .TH "getenforce" "1" "7 April 2004" "dwalsh@redhat.com" "SELinux Command Line documentation"
 .SH "NAME"
 getenforce \- get the current mode of SELinux
+.
 .SH "SYNOPSIS"
 .B getenforce
-
+.
 .SH "DESCRIPTION"
 .B getenforce
 reports whether SELinux is enforcing, permissive, or disabled.
-
+.
 .SH AUTHOR	
 Dan Walsh, <dwalsh@redhat.com>
-
+.
 .SH "SEE ALSO"
-selinux(8), setenforce(8), selinuxenabled(8)
+.BR selinux (8),
+.BR setenforce (8),
+.BR selinuxenabled (8)
diff --git a/libselinux/man/man8/getsebool.8 b/libselinux/man/man8/getsebool.8
index a4200ee..6353a2a 100644
--- a/libselinux/man/man8/getsebool.8
+++ b/libselinux/man/man8/getsebool.8
@@ -1,11 +1,12 @@
 .TH "getsebool" "8" "11 Aug 2004" "dwalsh@redhat.com" "SELinux Command Line documentation"
 .SH "NAME"
 getsebool \- get SELinux boolean value(s) 
-
+.
 .SH "SYNOPSIS"
 .B getsebool
-.I "[-a] [boolean]"
-
+.RB [ \-a ]
+.RI [ boolean ]
+.
 .SH "DESCRIPTION"
 .B getsebool 
 reports where a particular SELinux boolean or
@@ -20,16 +21,17 @@ value is changed, then the booleans are committed, causing their
 active values to become their pending values.  This allows a group of
 booleans to be changed in a single transaction, by setting all of
 their pending values as desired and then committing once.
-
+.
 .SH OPTIONS
 .TP
 .B \-a
 Show all SELinux booleans.
-
-.SH "SEE ALSO"
-selinux(8), setsebool(8), booleans(8)
-
+.
 .SH AUTHOR	
 This manual page was written by Dan Walsh <dwalsh@redhat.com>.
 The program was written by Tresys Technology.
-
+.
+.SH "SEE ALSO"
+.BR selinux (8),
+.BR setsebool (8),
+.BR booleans (8)
diff --git a/libselinux/man/man8/matchpathcon.8 b/libselinux/man/man8/matchpathcon.8
index 26ce74c..368991f 100644
--- a/libselinux/man/man8/matchpathcon.8
+++ b/libselinux/man/man8/matchpathcon.8
@@ -1,41 +1,57 @@
 .TH "matchpathcon" "8" "21 April 2005" "dwalsh@redhat.com" "SELinux Command Line documentation"
 .SH "NAME"
-matchpathcon \- get the default SELinux security context for the specified path from the file contexts configuration.
-
+matchpathcon \- get the default SELinux security context for the specified path from the file contexts configuration
+.
 .SH "SYNOPSIS"
-.B matchpathcon [-V] [-N] [-n] [-m type] [-f file_contexts_file ] [-p prefix ] filepath...
-.SH "DESCRIPTION"
 .B matchpathcon
+.RB [ \-V ]
+.RB [ \-N ]
+.RB [ \-n ]
+.RB [ \-m
+.IR type ]
+.RB [ \-f
+.IR file_contexts_file ]
+.RB [ \-p
+.IR prefix ]
+.I filepath...
+.
+.SH "DESCRIPTION"
+.BR matchpathcon
 queries the system policy and outputs the default security context associated with the filepath.
 
-Note: Identical paths can have different security contexts, depending on the file type. (regular file, directory, link file, char file ...)
+.B Note:
+Identical paths can have different security contexts, depending on the file
+type (regular file, directory, link file, char file ...).
 
 .B matchpathcon 
 will also take the file type into consideration in determining the default security context if the file exists.  If the file does not exist, no file type matching will occur.
-
+.
 .SH OPTIONS
-.B \-m type
+.TP
+.BI \-m " type"
 Force file type for the lookup.
-Valid types are file, dir, pipe, chr_file, blk_file, lnk_file, sock_file
-
+Valid types are
+.BR file ", " dir ", "pipe ", " chr_file ", " blk_file ", "
+.BR lnk_file ", " sock_file .
+.TP
 .B \-n
 Do not display path.
-
+.TP
 .B \-N
 Do not use translations.
-
-.B \-f file_context_file
+.TP
+.BI \-f " file_context_file"
 Use alternate file_context file
-
-.B \-p prefix
+.TP
+.BI \-p " prefix"
 Use prefix to speed translations
-
+.TP
 .B \-V
 Verify file context on disk matches defaults
-
+.
 .SH AUTHOR	
 This manual page was written by Dan Walsh <dwalsh@redhat.com>.
-
+.
 .SH "SEE ALSO"
 .BR selinux "(8), "
-.BR matchpathcon "(3), " 
+.BR matchpathcon (3)
diff --git a/libselinux/man/man8/selinux.8 b/libselinux/man/man8/selinux.8
index 9f16f77..a328866 100644
--- a/libselinux/man/man8/selinux.8
+++ b/libselinux/man/man8/selinux.8
@@ -1,10 +1,8 @@
 .TH  "selinux"  "8"  "29 Apr 2005" "dwalsh@redhat.com" "SELinux Command Line documentation"
-
 .SH "NAME"
 SELinux \- NSA Security-Enhanced Linux (SELinux)
-
+.
 .SH "DESCRIPTION"
-
 NSA Security-Enhanced Linux (SELinux) is an implementation of a
 flexible mandatory access control architecture in the Linux operating
 system.  The SELinux architecture provides general support for the
@@ -52,31 +50,58 @@ policies will be created (Multi-Level Security for example).  You can
 define which policy you will run by setting the
 .B SELINUXTYPE
 environment variable within
-.I /etc/selinux/config.
+.IR /etc/selinux/config .
 The corresponding
 policy configuration for each such policy must be installed in the
-/etc/selinux/SELINUXTYPE/ directories.
+.I /etc/selinux/{SELINUXTYPE}/
+directories.
 
 A given SELinux policy can be customized further based on a set of
 compile-time tunable options and a set of runtime policy booleans.
-.B system-config-securitylevel
+.B \%system\-config\-securitylevel
 allows customization of these booleans and tunables.
 
 Many domains that are protected by SELinux also include SELinux man pages explaining how to customize their policy.  
-
-.SH FILE LABELING
-
+.
+.SH "FILE LABELING"
 All files, directories, devices ... have a security context/label associated with them.  These context are stored in the extended attributes of the file system.
 Problems with SELinux often arise from the file system being mislabeled. This can be caused by booting the machine with a non SELinux kernel.  If you see an error message containing file_t, that is usually a good indicator that you have a serious problem with file system labeling.  
 
-The best way to relabel the file system is to create the flag file /.autorelabel and reboot.  system-config-securitylevel, also has this capability.  The restorcon/fixfiles commands are also available for relabeling files. 
-  
+The best way to relabel the file system is to create the flag file
+.I /.autorelabel
+and reboot.
+.BR system\-config\-selinux ,
+also has this capability.  The
+.BR restorcon / fixfiles
+commands are also available for relabeling files.
+.
 .SH AUTHOR	
 This manual page was written by Dan Walsh <dwalsh@redhat.com>.
-
+.
+.SH FILES
+.I /etc/selinux/config
+.
 .SH "SEE ALSO"
-booleans(8), setsebool(8), selinuxenabled(8), togglesebool(8), restorecon(8), setfiles(8), ftpd_selinux(8), named_selinux(8), rsync_selinux(8), httpd_selinux(8), nfs_selinux(8), samba_selinux(8), kerberos_selinux(8), nis_selinux(8), ypbind_selinux(8)
+.ad l
+.nh
+.BR booleans (8),
+.BR setsebool (8),
+.BR selinuxenabled (8),
+.BR togglesebool (8),
+.BR restorecon (8),
+.BR setfiles (8),
+.BR semange (8),
+.BR sepolicy(8)
 
+Every confined service on the system has a man page in the following format:
+.br
 
-.SH FILES
-/etc/selinux/config
+.B <servicename>_selinux(8)
+
+For example, httpd has the 
+.B httpd_selinux(8) 
+man page.
+
+.B man -k selinux 
+
+Will list all SELinux man pages.
diff --git a/libselinux/man/man8/selinuxenabled.8 b/libselinux/man/man8/selinuxenabled.8
index b25431f..e0b5201 100644
--- a/libselinux/man/man8/selinuxenabled.8
+++ b/libselinux/man/man8/selinuxenabled.8
@@ -1,16 +1,20 @@
 .TH "selinuxenabled" "1" "7 April 2004" "dwalsh@redhat.com" "SELinux Command Line documentation"
 .SH "NAME"
 selinuxenabled \- tool to be used within shell scripts to determine if selinux is enabled
+.
 .SH "SYNOPSIS"
 .B selinuxenabled
-
+.
 .SH "DESCRIPTION"
-.B selinuxenabled
-Indicates whether SELinux is enabled or disabled. It exits with status 0 
-if SELinux is enabled and 1 if it is not enabled.
-
+Indicates whether SELinux is enabled or disabled.
+.
+.SH "EXIT STATUS"
+It exits with status 0 if SELinux is enabled and 1 if it is not enabled.
+.
 .SH AUTHOR	
 Dan Walsh, <dwalsh@redhat.com>
-
+.
 .SH "SEE ALSO"
-selinux(8), setenforce(8), getenforce(8)
+.BR selinux (8),
+.BR setenforce (8),
+.BR getenforce (8)
diff --git a/libselinux/man/man8/selinuxexeccon.8 b/libselinux/man/man8/selinuxexeccon.8
index 6482d74..765cf8c 100644
--- a/libselinux/man/man8/selinuxexeccon.8
+++ b/libselinux/man/man8/selinuxexeccon.8
@@ -1,24 +1,27 @@
 .TH "selinuxexeccon" "1" "14 May 2011" "dwalsh@redhat.com" "SELinux Command Line documentation"
 .SH "NAME"
 selinuxexeccon \- report SELinux context used for this executable
-
+.
 .SH "SYNOPSIS"
-.B selinuxexeccon command [ fromcon] o
-
+.B selinuxexeccon
+.I command
+.RI [ fromcon ]
+.
 .SH "DESCRIPTION"
 .B selinuxexeccon
 reports the SELinux process context for the specified command from the specified context or the current context.
-
+.
 .SH EXAMPLE
+.nf
 # selinuxexeccon /usr/bin/passwd 
 staff_u:staff_r:passwd_t:s0-s0:c0.c1023
 
-.br
 # selinuxexeccon /usr/sbin/sendmail system_u:system_r:httpd_t:s0
 system_u:system_r:system_mail_t:s0
-
+.fi
+.
 .SH AUTHOR	
 This manual page was written by Dan Walsh <dwalsh@redhat.com>.
-
+.
 .SH "SEE ALSO"
-secon(8)
+.BR secon (8)
diff --git a/libselinux/man/man8/setenforce.8 b/libselinux/man/man8/setenforce.8
index 639883e..b038da0 100644
--- a/libselinux/man/man8/setenforce.8
+++ b/libselinux/man/man8/setenforce.8
@@ -1,19 +1,31 @@
 .TH "setenforce" "1" "7 April 2004" "dwalsh@redhat.com" "SELinux Command Line documentation"
 .SH "NAME"
-setenforce \- modify the mode SELinux is running in.
+setenforce \- modify the mode SELinux is running in
+.
 .SH "SYNOPSIS"
-.B setenforce [ Enforcing | Permissive | 1 | 0 ]
-
+.B setenforce
+.RB [ Enforcing | Permissive | 1 | 0 ]
+.
 .SH "DESCRIPTION"
-Use Enforcing or 1 to put SELinux in enforcing mode.
+Use
+.B Enforcing
+or
+.B 1
+to put SELinux in enforcing mode.
 .br
-Use Permissive or 0 to put SELinux in permissive mode.
+Use
+.B Permissive
+or
+.B 0
+to put SELinux in permissive mode.
 
 If SELinux is disabled and you want to enable it, or SELinux is enabled and you want to disable it, please see 
-.B selinux(8).
-
+.BR selinux (8).
+.
 .SH AUTHOR	
 Dan Walsh, <dwalsh@redhat.com>
-
+.
 .SH "SEE ALSO"
-selinux(8), getenforce(8), selinuxenabled(8)
+.BR selinux (8),
+.BR getenforce (8),
+.BR selinuxenabled (8)
diff --git a/libselinux/man/man8/togglesebool.8 b/libselinux/man/man8/togglesebool.8
index ae21175..948aff1 100644
--- a/libselinux/man/man8/togglesebool.8
+++ b/libselinux/man/man8/togglesebool.8
@@ -1,17 +1,22 @@
 .TH "togglesebool" "1" "26 Oct 2004" "sgrubb@redhat.com" "SELinux Command Line documentation"
 .SH "NAME"
 togglesebool \- flip the current value of a SELinux boolean
+.
 .SH "SYNOPSIS"
-.B togglesebool boolean...
-
+.B togglesebool
+.I boolean...
+.
 .SH "DESCRIPTION"
 .B togglesebool
 flips the current value of a list of booleans. If the value is currently a 1,
 then it will be changed to a 0 and vice versa. Only the "in memory" values are
 changed; the boot-time settings are unaffected. 
-
+.
 .SH AUTHOR	
 This man page was written by Steve Grubb <sgrubb@redhat.com>
-
+.
 .SH "SEE ALSO"
-selinux(8), booleans(8), getsebool(8), setsebool(8)
+.BR selinux (8),
+.BR booleans (8),
+.BR getsebool (8),
+.BR setsebool (8)
diff --git a/libselinux/src/Makefile b/libselinux/src/Makefile
index ac019df..c4f5d4c 100644
--- a/libselinux/src/Makefile
+++ b/libselinux/src/Makefile
@@ -16,11 +16,11 @@ PYINC ?= $(shell pkg-config --cflags $(PYPREFIX))
 PYLIBDIR ?= $(LIBDIR)/$(PYLIBVER)
 RUBYLIBVER ?= $(shell $(RUBY) -e 'print RUBY_VERSION.split(".")[0..1].join(".")')
 RUBYPLATFORM ?= $(shell $(RUBY) -e 'print RUBY_PLATFORM')
-RUBYINC ?= $(shell pkg-config --cflags ruby-$(RUBYLIBVER))
+RUBYINC ?= $(shell pkg-config --cflags ruby)
 RUBYINSTALL ?= $(LIBDIR)/ruby/site_ruby/$(RUBYLIBVER)/$(RUBYPLATFORM)
 LIBBASE=$(shell basename $(LIBDIR))
 
-LDFLAGS ?= -lpcre
+LDFLAGS ?= -lpcre -lpthread
 
 VERSION = $(shell cat ../VERSION)
 LIBVERSION = 1
@@ -106,17 +106,17 @@ $(SWIGRUBYLOBJ): $(SWIGRUBYCOUT)
 	$(CC) $(CFLAGS) $(SWIG_CFLAGS) $(RUBYINC) -fPIC -DSHARED -c -o $@ $<
 
 $(SWIGSO): $(SWIGLOBJ)
-	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $< -L. -lselinux -L$(LIBDIR)
+	$(CC) $(CFLAGS) -shared -o $@ $< -L. -lselinux $(LDFLAGS) -L$(LIBDIR)
 
 $(SWIGRUBYSO): $(SWIGRUBYLOBJ)
-	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ -L. -lselinux -L$(LIBDIR)
+	$(CC) $(CFLAGS) -shared -o $@ $^ -L. -lselinux $(LDFLAGS) -L$(LIBDIR)
 
 $(LIBA): $(OBJS)
 	$(AR) rcs $@ $^
 	$(RANLIB) $@
 
 $(LIBSO): $(LOBJS)
-	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ -ldl -L$(LIBDIR) -Wl,-soname,$(LIBSO),-z,defs,-z,relro
+	$(CC) $(CFLAGS) -shared -o $@ $^ -ldl $(LDFLAGS) -L$(LIBDIR) -Wl,-soname,$(LIBSO),-z,defs,-z,relro
 	ln -sf $@ $(TARGET) 
 
 $(LIBPC): $(LIBPC).in ../VERSION
@@ -129,7 +129,7 @@ $(AUDIT2WHYLOBJ): audit2why.c
 	$(CC) $(filter-out -Werror, $(CFLAGS)) $(PYINC) -fPIC -DSHARED -c -o $@ $<
 
 $(AUDIT2WHYSO): $(AUDIT2WHYLOBJ)
-	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ -L. -lselinux $(LIBDIR)/libsepol.a -L$(LIBDIR)
+	$(CC) $(CFLAGS) -shared -o $@ $^ -L. $(LDFLAGS) -lselinux $(LIBDIR)/libsepol.a -L$(LIBDIR)
 
 %.o:  %.c policy.h
 	$(CC) $(CFLAGS) $(TLSFLAGS) -c -o $@ $<
diff --git a/libselinux/src/audit2why.c b/libselinux/src/audit2why.c
index 02483a3..73c07aa 100644
--- a/libselinux/src/audit2why.c
+++ b/libselinux/src/audit2why.c
@@ -164,6 +164,9 @@ static PyObject *finish(PyObject *self __attribute__((unused)), PyObject *args)
   
 	if (PyArg_ParseTuple(args,(char *)":finish")) {
 		int i = 0;
+		if (! avc)
+			Py_RETURN_NONE;
+
 		for (i = 0; i < boolcnt; i++) {
 			free(boollist[i]->name);
 			free(boollist[i]);
@@ -177,7 +180,7 @@ static PyObject *finish(PyObject *self __attribute__((unused)), PyObject *args)
 		avc = NULL;
 		boollist = NULL;
 		boolcnt = 0;
-	  
+
 		/* Boilerplate to return "None" */
 		Py_RETURN_NONE;
 	}
@@ -188,48 +191,24 @@ static PyObject *finish(PyObject *self __attribute__((unused)), PyObject *args)
 static int __policy_init(const char *init_path)
 {
 	FILE *fp;
-	int vers = 0;
-	char path[PATH_MAX];
+	const char *path;
 	char errormsg[PATH_MAX];
 	struct sepol_policy_file *pf = NULL;
 	int rc;
 	unsigned int cnt;
 
-	if (init_path) {
-		strncpy(path, init_path, PATH_MAX);
-		fp = fopen(path, "r");
-		if (!fp) {
-			snprintf(errormsg, sizeof(errormsg), 
-				 "unable to open %s:  %s\n",
-				 path, strerror(errno));
-			PyErr_SetString( PyExc_ValueError, errormsg);
-			return 1;
-		}
-	} else {
-		vers = sepol_policy_kern_vers_max();
-		if (vers < 0) {
-			snprintf(errormsg, sizeof(errormsg), 
-				 "Could not get policy version:  %s\n",
-				 strerror(errno));
-			PyErr_SetString( PyExc_ValueError, errormsg);
-			return 1;
-		}
-		snprintf(path, PATH_MAX, "%s.%d",
-			 selinux_binary_policy_path(), vers);
-		fp = fopen(path, "r");
-		while (!fp && errno == ENOENT && --vers) {
-			snprintf(path, PATH_MAX, "%s.%d",
-				 selinux_binary_policy_path(), vers);
-			fp = fopen(path, "r");
-		}
-		if (!fp) {
-			snprintf(errormsg, sizeof(errormsg), 
-				 "unable to open %s.%d:  %s\n",
-				 selinux_binary_policy_path(),
-				 security_policyvers(), strerror(errno));
-			PyErr_SetString( PyExc_ValueError, errormsg);
-			return 1;
-		}
+	if (init_path)
+		path = init_path;
+	else
+		path = selinux_current_policy_path();
+
+	fp = fopen(path, "r");
+	if (!fp) {
+		snprintf(errormsg, sizeof(errormsg), 
+			 "unable to open %s:  %s\n",
+			 path, strerror(errno));
+		PyErr_SetString( PyExc_ValueError, errormsg);
+		return 1;
 	}
 
 	avc = calloc(sizeof(struct avc_t), 1);
@@ -271,7 +250,7 @@ static int __policy_init(const char *init_path)
 		return 1;
 	}
 
-	boollist = calloc(cnt, sizeof(struct boolean_t));
+	boollist = calloc(cnt, sizeof(*boollist));
 	if (!boollist) {
 		PyErr_SetString( PyExc_MemoryError, "Out of memory\n");
 		return 1;
@@ -295,6 +274,10 @@ static int __policy_init(const char *init_path)
 static PyObject *init(PyObject *self __attribute__((unused)), PyObject *args) {
   int result;
   char *init_path=NULL;
+  if (avc) {
+	  PyErr_SetString( PyExc_RuntimeError, "init called multiple times");
+	  return NULL;
+  }
   if (!PyArg_ParseTuple(args,(char *)"|s:policy_init",&init_path))
     return NULL;
   result = __policy_init(init_path);
@@ -302,10 +285,12 @@ static PyObject *init(PyObject *self __attribute__((unused)), PyObject *args) {
 }
 
 #define RETURN(X) \
-	PyTuple_SetItem(result, 0, Py_BuildValue("i", X));	\
-	return result;						
+	{ \
+		return Py_BuildValue("iO", (X), Py_None);	\
+	}					
 
 static PyObject *analyze(PyObject *self __attribute__((unused)) , PyObject *args) {
+	char *reason_buf = NULL;
 	security_context_t scon; 
 	security_context_t tcon;
 	char *tclassstr; 
@@ -320,10 +305,6 @@ static PyObject *analyze(PyObject *self __attribute__((unused)) , PyObject *args
 	struct sepol_av_decision avd;
 	int rc;
 	int i=0;
-	PyObject *result = PyTuple_New(2);
-	if (!result) return NULL;
-	Py_INCREF(Py_None);
-	PyTuple_SetItem(result, 1, Py_None);
 
 	if (!PyArg_ParseTuple(args,(char *)"sssO!:audit2why",&scon,&tcon,&tclassstr,&PyList_Type, &listObj)) 
 		return NULL;
@@ -334,22 +315,21 @@ static PyObject *analyze(PyObject *self __attribute__((unused)) , PyObject *args
 	/* should raise an error here. */
 	if (numlines < 0)	return NULL; /* Not a list */
 
-	if (!avc) {
+	if (!avc)
 		RETURN(NOPOLICY)
-	}
 
 	rc = sepol_context_to_sid(scon, strlen(scon) + 1, &ssid);
-	if (rc < 0) {
+	if (rc < 0)
 		RETURN(BADSCON)
-	}
+
 	rc = sepol_context_to_sid(tcon, strlen(tcon) + 1, &tsid);
-	if (rc < 0) {
+	if (rc < 0)
 		RETURN(BADTCON)
-	}
+
 	tclass = string_to_security_class(tclassstr);
-	if (!tclass) {
+	if (!tclass)
 		RETURN(BADTCLASS)
-	}
+
 	/* Convert the permission list to an AV. */
 	av = 0;
 
@@ -369,21 +349,20 @@ static PyObject *analyze(PyObject *self __attribute__((unused)) , PyObject *args
 #endif
 		
 		perm = string_to_av_perm(tclass, permstr);
-		if (!perm) {
+		if (!perm)
 			RETURN(BADPERM)
-		}
+
 		av |= perm;
 	}
 
 	/* Reproduce the computation. */
-	rc = sepol_compute_av_reason(ssid, tsid, tclass, av, &avd, &reason);
-	if (rc < 0) {
+	rc = sepol_compute_av_reason_buffer(ssid, tsid, tclass, av, &avd, &reason, &reason_buf, 0);
+	if (rc < 0)
 		RETURN(BADCOMPUTE)
-	}
 
-	if (!reason) {
+	if (!reason)
 		RETURN(ALLOW)
-	}
+
 	if (reason & SEPOL_COMPUTEAV_TE) {
 		avc->ssid = ssid;
 		avc->tsid = tsid;
@@ -396,33 +375,39 @@ static PyObject *analyze(PyObject *self __attribute__((unused)) , PyObject *args
 				RETURN(TERULE)
 			}
 		} else {
-			PyTuple_SetItem(result, 0, Py_BuildValue("i", BOOLEAN));
+			PyObject *outboollist;
 			struct boolean_t *b = bools;
 			int len=0;
 			while (b->name) {
 				len++; b++;
 			}
 			b = bools;
-			PyObject *outboollist = PyTuple_New(len);
+			outboollist = PyList_New(len);
 			len=0;
 			while(b->name) {
-				PyObject *bool = Py_BuildValue("(si)", b->name, b->active);
-				PyTuple_SetItem(outboollist, len++, bool);
+				PyObject *bool_ = Py_BuildValue("(si)", b->name, b->active);
+				PyList_SetItem(outboollist, len++, bool_);
 				b++;
 			}
 			free(bools);
-			PyTuple_SetItem(result, 1, outboollist);
-			return result;
+			/* 'N' steals the reference to outboollist */
+			return Py_BuildValue("iN", BOOLEAN, outboollist);
 		}
 	}
 
 	if (reason & SEPOL_COMPUTEAV_CONS) {
-		RETURN(CONSTRAINT);
+		if (reason_buf) {
+			PyObject *result = NULL;
+			result = Py_BuildValue("is", CONSTRAINT, reason_buf);
+			free(reason_buf);
+			return result;
+		} 
+		RETURN(CONSTRAINT)
 	}
 
-	if (reason & SEPOL_COMPUTEAV_RBAC) {
+	if (reason & SEPOL_COMPUTEAV_RBAC)
 		RETURN(RBAC)
-	}
+
         RETURN(BADCOMPUTE)
 }
 
diff --git a/libselinux/src/avc.c b/libselinux/src/avc.c
index 802a07f..6ff83a7 100644
--- a/libselinux/src/avc.c
+++ b/libselinux/src/avc.c
@@ -827,6 +827,7 @@ int avc_has_perm(security_id_t ssid, security_id_t tsid,
 	errsave = errno;
 	avc_audit(ssid, tsid, tclass, requested, &avd, rc, auditdata);
 	errno = errsave;
+	if (!avc_enforcing) return 0;
 	return rc;
 }
 
diff --git a/libselinux/src/avc_internal.c b/libselinux/src/avc_internal.c
index 6d508ee..f735e73 100644
--- a/libselinux/src/avc_internal.c
+++ b/libselinux/src/avc_internal.c
@@ -60,13 +60,12 @@ int avc_netlink_open(int blocking)
 	int len, rc = 0;
 	struct sockaddr_nl addr;
 
-	fd = socket(PF_NETLINK, SOCK_RAW, NETLINK_SELINUX);
+	fd = socket(PF_NETLINK, SOCK_RAW | SOCK_CLOEXEC, NETLINK_SELINUX);
 	if (fd < 0) {
 		rc = fd;
 		goto out;
 	}
 	
-	fcntl(fd, F_SETFD, FD_CLOEXEC);
 	if (!blocking && fcntl(fd, F_SETFL, O_NONBLOCK)) {
 		close(fd);
 		fd = -1;
diff --git a/libselinux/src/fgetfilecon.c b/libselinux/src/fgetfilecon.c
index c88d515..3395c9f 100644
--- a/libselinux/src/fgetfilecon.c
+++ b/libselinux/src/fgetfilecon.c
@@ -39,7 +39,7 @@ int fgetfilecon_raw(int fd, security_context_t * context)
       out:
 	if (ret == 0) {
 		/* Re-map empty attribute values to errors. */
-		errno = EOPNOTSUPP;
+		errno = ENOTSUP;
 		ret = -1;
 	}
 	if (ret < 0)
diff --git a/libselinux/src/file_path_suffixes.h b/libselinux/src/file_path_suffixes.h
index 825f295..d11c8dc 100644
--- a/libselinux/src/file_path_suffixes.h
+++ b/libselinux/src/file_path_suffixes.h
@@ -26,4 +26,4 @@ S_(BINPOLICY, "/policy/policy")
     S_(FILE_CONTEXT_SUBS, "/contexts/files/file_contexts.subs")
     S_(FILE_CONTEXT_SUBS_DIST, "/contexts/files/file_contexts.subs_dist")
     S_(SEPGSQL_CONTEXTS, "/contexts/sepgsql_contexts")
-    S_(BOOLEAN_SUBS, "/booleans.subs")
+    S_(BOOLEAN_SUBS, "/booleans.subs_dist")
diff --git a/libselinux/src/get_context_list.c b/libselinux/src/get_context_list.c
index e02157c..eb72593 100644
--- a/libselinux/src/get_context_list.c
+++ b/libselinux/src/get_context_list.c
@@ -489,11 +489,19 @@ int get_ordered_context_list(const char *user,
 		reachable[nordered] = NULL;
 		rc = nordered;
 	} else {
-		rc = nreach;
+		if (security_getenforce()) {
+			errno = EPERM;
+			rc = -1;
+		} else {
+			rc = nreach;
+		}
 	}
 
       out:
-	*list = reachable;
+	if (rc > 0)
+		*list = reachable;
+	else
+		freeconary(reachable);
 
 	free(ordering);
 	if (freefrom)
diff --git a/libselinux/src/getfilecon.c b/libselinux/src/getfilecon.c
index 67e4463..eb2ce8a 100644
--- a/libselinux/src/getfilecon.c
+++ b/libselinux/src/getfilecon.c
@@ -39,7 +39,7 @@ int getfilecon_raw(const char *path, security_context_t * context)
       out:
 	if (ret == 0) {
 		/* Re-map empty attribute values to errors. */
-		errno = EOPNOTSUPP;
+		errno = ENOTSUP;
 		ret = -1;
 	}
 	if (ret < 0)
diff --git a/libselinux/src/label_android_property.c b/libselinux/src/label_android_property.c
index 79bf923..e11ccf8 100644
--- a/libselinux/src/label_android_property.c
+++ b/libselinux/src/label_android_property.c
@@ -153,6 +153,9 @@ static int init(struct selabel_handle *rec, struct selinux_opt *opts,
 			break;
 		}
 
+	if (!path) 
+		return -1;
+
 	/* Open the specification file. */
 	if ((fp = fopen(path, "r")) == NULL)
 		return -1;
diff --git a/libselinux/src/label_file.c b/libselinux/src/label_file.c
index 02b3cd2..7f140dd 100644
--- a/libselinux/src/label_file.c
+++ b/libselinux/src/label_file.c
@@ -8,6 +8,7 @@
  * developed by Secure Computing Corporation.
  */
 
+#include <assert.h>
 #include <fcntl.h>
 #include <stdarg.h>
 #include <string.h>
@@ -16,7 +17,12 @@
 #include <ctype.h>
 #include <errno.h>
 #include <limits.h>
+#include <stdint.h>
 #include <pcre.h>
+
+#include <linux/limits.h>
+
+#include <sys/mman.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -229,6 +235,176 @@ static int process_line(struct selabel_handle *rec,
 	return 0;
 }
 
+static int load_mmap(struct selabel_handle *rec, const char *path, struct stat *stat)
+{
+	struct saved_data *data = (struct saved_data *)rec->data;
+	char mmap_path[PATH_MAX + 1];
+	int mmapfd;
+	int rc, i;
+	struct stat mmap_stat;
+	char *addr;
+	size_t len;
+	int stem_map_len, *stem_map;
+
+	uint32_t *magic;
+	uint32_t *section_len;
+	uint32_t *plen;
+
+	rc = snprintf(mmap_path, sizeof(mmap_path), "%s.bin", path);
+	if (rc >= sizeof(mmap_path))
+		return -1;
+
+	mmapfd = open(mmap_path, O_RDONLY | O_CLOEXEC);
+	if (mmapfd < 0)
+		return -1;
+
+	rc = fstat(mmapfd, &mmap_stat);
+	if (rc < 0) {
+		close(mmapfd);
+		return -1;
+	}
+
+	/* if mmap is old, ignore it */
+	if (mmap_stat.st_mtime < stat->st_mtime) {
+		close(mmapfd);
+		return -1;
+	}
+
+	if (mmap_stat.st_mtime == stat->st_mtime &&
+	    mmap_stat.st_mtim.tv_nsec < stat->st_mtim.tv_nsec) {
+		close(mmapfd);
+		return -1;
+	}
+
+	/* ok, read it in... */
+	len = mmap_stat.st_size;
+	len += (sysconf(_SC_PAGE_SIZE) - 1);
+	len &= ~(sysconf(_SC_PAGE_SIZE) - 1);
+
+	addr = mmap(NULL, len, PROT_READ, MAP_PRIVATE, mmapfd, 0);
+	close(mmapfd);
+	if (addr == MAP_FAILED) {
+		perror("mmap");
+		return -1;
+	}
+
+	/* check if this looks like an fcontext file */
+	magic = (uint32_t *)addr;
+	if (*magic != SELINUX_MAGIC_COMPILED_FCONTEXT)
+		return -1;
+	addr += sizeof(uint32_t);
+
+	/* check if this version is higher than we understand */
+	section_len = (uint32_t *)addr;
+	if (*section_len > SELINUX_COMPILED_FCONTEXT_MAX_VERS)
+		return -1;
+	addr += sizeof(uint32_t);
+
+	/* allocate the stems_data array */
+	section_len = (uint32_t *)addr;
+	addr += sizeof(uint32_t);
+
+	/*
+	 * map indexed by the stem # in the mmap file and contains the stem
+	 * number in the data stem_arr
+	 */
+	stem_map_len = *section_len;
+	stem_map = calloc(stem_map_len, sizeof(*stem_map));
+	if (!stem_map)
+		return -1;
+
+	for (i = 0; i < *section_len; i++) {
+		char *buf;
+		uint32_t stem_len;
+		int newid;
+
+		/* the length does not inlude the nul */
+		plen = (uint32_t *)addr;
+		addr += sizeof(uint32_t);
+
+		stem_len = *plen;
+		buf = (char *)addr;
+		addr += (stem_len + 1); // +1 is the nul
+
+		/* store the mapping between old and new */
+		newid = find_stem(data, buf, stem_len);
+		if (newid < 0) {
+			newid = store_stem(data, buf, stem_len);
+			if (newid < 0) {
+				rc = newid;
+				goto err;
+			}
+			data->stem_arr[newid].from_mmap = 1;
+		}
+		stem_map[i] = newid;
+	}
+
+	/* allocate the regex array */
+	section_len = (uint32_t *)addr;
+	addr += sizeof(*section_len);
+
+	for (i = 0; i < *section_len; i++) {
+		struct spec *spec;
+		int32_t stem_id;
+
+		rc = grow_specs(data);
+		if (rc < 0)
+			goto err;
+
+		spec = &data->spec_arr[data->nspec];
+		spec->from_mmap = 1;
+		spec->regcomp = 1;
+
+		plen = (uint32_t *)addr;
+		addr += sizeof(uint32_t);
+		rc = -1;
+		spec->lr.ctx_raw = strdup((char *)addr);
+		if (!spec->lr.ctx_raw)
+			goto err;
+
+		addr += *plen;
+
+		plen = (uint32_t *)addr;
+		addr += sizeof(uint32_t);
+		spec->regex_str = (char *)addr;
+		addr += *plen;
+
+		spec->mode = *(mode_t *)addr;
+		addr += sizeof(mode_t);
+
+		/* map the stem id from the mmap file to the data->stem_arr */
+		stem_id = *(int32_t *)addr;
+		if (stem_id == -1 || stem_id >= stem_map_len)
+			spec->stem_id = -1;
+		else
+			spec->stem_id = stem_map[stem_id];
+		addr += sizeof(int32_t);
+
+		/* retrieve the hasMetaChars bit */
+		spec->hasMetaChars = *(uint32_t *)addr;
+		addr += sizeof(uint32_t);
+
+		plen = (uint32_t *)addr;
+		addr += sizeof(uint32_t);
+		spec->regex = (pcre *)addr;
+		addr += *plen;
+
+		plen = (uint32_t *)addr;
+		addr += sizeof(uint32_t);
+		spec->lsd.study_data = (void *)addr;
+		spec->lsd.flags |= PCRE_EXTRA_STUDY_DATA;
+		addr += *plen;
+
+		data->nspec++;
+	}
+	/* win */
+	rc = 0;
+err:
+	free(stem_map);
+
+	return rc;
+}
+
 static int process_file(const char *path, const char *suffix, struct selabel_handle *rec, const char *prefix)
 {
 	FILE *fp;
@@ -261,6 +437,10 @@ static int process_file(const char *path, const char *suffix, struct selabel_han
 		return -1;
 	}
 
+	rc = load_mmap(rec, path, &sb);
+	if (rc == 0)
+		goto out;
+
 	/*
 	 * The do detailed validation of the input and fill the spec array
 	 */
@@ -270,6 +450,7 @@ static int process_file(const char *path, const char *suffix, struct selabel_han
 		if (rc)
 			return rc;
 	}
+out:
 	free(line_buf);
 	fclose(fp);
 
@@ -357,6 +538,8 @@ static void closef(struct selabel_handle *rec)
 
 	for (i = 0; i < data->nspec; i++) {
 		spec = &data->spec_arr[i];
+		if (spec->from_mmap)
+			continue;
 		free(spec->regex_str);
 		free(spec->type_str);
 		free(spec->lr.ctx_raw);
@@ -369,6 +552,8 @@ static void closef(struct selabel_handle *rec)
 
 	for (i = 0; i < (unsigned int)data->num_stems; i++) {
 		stem = &data->stem_arr[i];
+		if (stem->from_mmap)
+			continue;
 		free(stem->buf);
 	}
 
diff --git a/libselinux/src/label_file.h b/libselinux/src/label_file.h
index cb5633b..9799bbb 100644
--- a/libselinux/src/label_file.h
+++ b/libselinux/src/label_file.h
@@ -5,24 +5,32 @@
 
 #include "label_internal.h"
 
+#define SELINUX_MAGIC_COMPILED_FCONTEXT	0xf97cff8a
+#define SELINUX_COMPILED_FCONTEXT_MAX_VERS	1
+
 /* A file security context specification. */
 struct spec {
 	struct selabel_lookup_rec lr;	/* holds contexts for lookup result */
 	char *regex_str;	/* regular expession string for diagnostics */
 	char *type_str;		/* type string for diagnostic messages */
 	pcre *regex;		/* compiled regular expression */
-	pcre_extra *sd;		/* extra compiled stuff */
+	union {
+		pcre_extra *sd;	/* pointer to extra compiled stuff */
+		pcre_extra lsd;	/* used to hold the mmap'd version */
+	};
 	mode_t mode;		/* mode format value */
 	int matches;		/* number of matching pathnames */
 	int stem_id;		/* indicates which stem-compression item */
 	char hasMetaChars;	/* regular expression has meta-chars */
 	char regcomp;		/* regex_str has been compiled to regex */
+	char from_mmap;		/* this spec is from an mmap of the data */
 };
 
 /* A regular expression stem */
 struct stem {
 	char *buf;
 	int len;
+	char from_mmap;
 };
 
 /* Our stored configuration */
@@ -45,7 +53,10 @@ struct saved_data {
 
 static inline pcre_extra *get_pcre_extra(struct spec *spec)
 {
-	return spec->sd;
+	if (spec->from_mmap)
+		return &spec->lsd;
+	else
+		return spec->sd;
 }
 
 static inline mode_t string_to_mode(char *mode)
diff --git a/libselinux/src/lgetfilecon.c b/libselinux/src/lgetfilecon.c
index a53f56e..58dc807 100644
--- a/libselinux/src/lgetfilecon.c
+++ b/libselinux/src/lgetfilecon.c
@@ -39,7 +39,7 @@ int lgetfilecon_raw(const char *path, security_context_t * context)
       out:
 	if (ret == 0) {
 		/* Re-map empty attribute values to errors. */
-		errno = EOPNOTSUPP;
+		errno = ENOTSUP;
 		ret = -1;
 	}
 	if (ret < 0)
diff --git a/libselinux/src/load_policy.c b/libselinux/src/load_policy.c
index 10e29b9..888dab5 100644
--- a/libselinux/src/load_policy.c
+++ b/libselinux/src/load_policy.c
@@ -49,8 +49,9 @@ int load_setlocaldefs hidden = 1;
 int selinux_mkload_policy(int preservebools)
 {	
 	int kernvers = security_policyvers();
-	int maxvers = kernvers, minvers = DEFAULT_POLICY_VERSION, vers;
+	int maxvers = kernvers, minvers = DEFAULT_POLICY_VERSION;
 	int setlocaldefs = load_setlocaldefs;
+	char *pol_path = NULL;
 	char path[PATH_MAX];
 	struct stat sb;
 	struct utsname uts;
@@ -162,29 +163,24 @@ checkbool:
 			maxvers = max(kernvers, maxvers);
 	}
 
-	vers = maxvers;
-      search:
-	snprintf(path, sizeof(path), "%s.%d",
-		 selinux_binary_policy_path(), vers);
-	fd = open(path, O_RDONLY);
-	while (fd < 0 && errno == ENOENT
-	       && --vers >= minvers) {
-		/* Check prior versions to see if old policy is available */
-		snprintf(path, sizeof(path), "%s.%d",
-			 selinux_binary_policy_path(), vers);
-		fd = open(path, O_RDONLY);
+search:
+	pol_path = selinux_binary_policy_path_min_max(minvers, &maxvers);
+	if (!pol_path) {
+		fprintf(stderr, "SELinux: unable to find usable policy file:  %s\n",
+			strerror(errno));
+		goto dlclose;
 	}
+
+	fd = open(pol_path, O_RDONLY);
 	if (fd < 0) {
-		fprintf(stderr,
-			"SELinux:  Could not open policy file <= %s.%d:  %s\n",
-			selinux_binary_policy_path(), maxvers, strerror(errno));
+		fprintf(stderr, "SELinux:  Could not open policy file %s:  %s\n",
+			pol_path, strerror(errno));
 		goto dlclose;
 	}
 
 	if (fstat(fd, &sb) < 0) {
-		fprintf(stderr,
-			"SELinux:  Could not stat policy file %s:  %s\n",
-			path, strerror(errno));
+		fprintf(stderr, "SELinux:  Could not stat policy file %s:  %s\n",
+			pol_path, strerror(errno));
 		goto close;
 	}
 
@@ -195,13 +191,12 @@ checkbool:
 	size = sb.st_size;
 	data = map = mmap(NULL, size, prot, MAP_PRIVATE, fd, 0);
 	if (map == MAP_FAILED) {
-		fprintf(stderr,
-			"SELinux:  Could not map policy file %s:  %s\n",
-			path, strerror(errno));
+		fprintf(stderr, "SELinux:  Could not map policy file %s:  %s\n",
+			pol_path, strerror(errno));
 		goto close;
 	}
 
-	if (vers > kernvers && usesepol) {
+	if (maxvers > kernvers && usesepol) {
 		/* Need to downgrade to kernel-supported version. */
 		if (policy_file_create(&pf))
 			goto unmap;
@@ -220,12 +215,12 @@ checkbool:
 			/* Downgrade failed, keep searching. */
 			fprintf(stderr,
 				"SELinux:  Could not downgrade policy file %s, searching for an older version.\n",
-				path);
+				pol_path);
 			policy_file_free(pf);
 			policydb_free(policydb);
 			munmap(map, sb.st_size);
 			close(fd);
-			vers--;
+			maxvers--;
 			goto search;
 		}
 		policy_file_free(pf);
@@ -281,7 +276,7 @@ checkbool:
 	if (rc)
 		fprintf(stderr,
 			"SELinux:  Could not load policy file %s:  %s\n",
-			path, strerror(errno));
+			pol_path, strerror(errno));
 
       unmap:
 	if (data != map)
@@ -296,6 +291,7 @@ checkbool:
 	if (libsepolh)
 		dlclose(libsepolh);
 #endif
+	free(pol_path);
 	return rc;
 }
 
diff --git a/libselinux/src/mapping.c b/libselinux/src/mapping.c
index b0264e7..f205804 100644
--- a/libselinux/src/mapping.c
+++ b/libselinux/src/mapping.c
@@ -66,7 +66,7 @@ selinux_set_mapping(struct security_class_mapping *map)
 			goto err2;
 
 		k = 0;
-		while (p_in->perms && p_in->perms[k]) {
+		while (p_in->perms[k]) {
 			/* An empty permission string skips ahead */
 			if (!*p_in->perms[k]) {
 				k++;
diff --git a/libselinux/src/matchpathcon.c b/libselinux/src/matchpathcon.c
index 2d7369e..2a00807 100644
--- a/libselinux/src/matchpathcon.c
+++ b/libselinux/src/matchpathcon.c
@@ -2,6 +2,7 @@
 #include <string.h>
 #include <errno.h>
 #include <stdio.h>
+#include <syslog.h>
 #include "selinux_internal.h"
 #include "label_internal.h"
 #include "callbacks.h"
@@ -62,7 +63,7 @@ static void
 {
 	va_list ap;
 	va_start(ap, fmt);
-	vfprintf(stderr, fmt, ap);
+	vsyslog(LOG_ERR, fmt, ap);
 	va_end(ap);
 }
 
diff --git a/libselinux/src/procattr.c b/libselinux/src/procattr.c
index 83381e4..70355c1 100644
--- a/libselinux/src/procattr.c
+++ b/libselinux/src/procattr.c
@@ -1,6 +1,7 @@
 #include <sys/syscall.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <pthread.h>
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -8,33 +9,98 @@
 #include "selinux_internal.h"
 #include "policy.h"
 
+static __thread pid_t cpid;
+static __thread pid_t tid;
+static __thread security_context_t prev_current;
+static __thread security_context_t prev_exec;
+static __thread security_context_t prev_fscreate;
+static __thread security_context_t prev_keycreate;
+static __thread security_context_t prev_sockcreate;
+
+static pthread_once_t once = PTHREAD_ONCE_INIT;
+static pthread_key_t destructor_key;
+static int destructor_key_initialized = 0;
+static __thread char destructor_initialized;
+
 static pid_t gettid(void)
 {
 	return syscall(__NR_gettid);
 }
 
-static int getprocattrcon_raw(security_context_t * context,
-			      pid_t pid, const char *attr)
+static void procattr_thread_destructor(void __attribute__((unused)) *unused)
+{
+	free(prev_current);
+	free(prev_exec);
+	free(prev_fscreate);
+	free(prev_keycreate);
+	free(prev_sockcreate);
+}
+
+static void free_procattr(void)
+{
+	procattr_thread_destructor(NULL);
+	cpid = tid = 0;
+	prev_current = prev_exec = prev_fscreate = prev_keycreate = prev_sockcreate = NULL;
+}
+
+void __attribute__((destructor)) procattr_destructor(void);
+
+void hidden __attribute__((destructor)) procattr_destructor(void)
+{
+	if (destructor_key_initialized)
+		__selinux_key_delete(destructor_key);
+}
+
+static inline void init_thread_destructor(void)
+{
+	if (destructor_initialized == 0) {
+		__selinux_setspecific(destructor_key, (void *)1);
+		destructor_initialized = 1;
+	}
+}
+
+static void init_procattr(void)
+{
+	if (__selinux_key_create(&destructor_key, procattr_thread_destructor) == 0) {
+		pthread_atfork(NULL, NULL, free_procattr);
+		destructor_key_initialized = 1;
+	}
+}
+
+static int openattr(pid_t pid, const char *attr, int flags) 
 {
-	char *path, *buf;
-	size_t size;
 	int fd, rc;
-	ssize_t ret;
-	pid_t tid;
-	int errno_hold;
+	char *path;
 
 	if (pid > 0)
 		rc = asprintf(&path, "/proc/%d/attr/%s", pid, attr);
 	else {
-		tid = gettid();
+		if (!tid)
+			tid = gettid();
 		rc = asprintf(&path, "/proc/self/task/%d/attr/%s", tid, attr);
 	}
 	if (rc < 0)
 		return -1;
 
-	fd = open(path, O_RDONLY);
+	fd = open(path, flags);
 	free(path);
-	if (fd < 0)
+	return fd;
+}
+
+static int getprocattrcon_raw(security_context_t * context,
+			      pid_t pid, const char *attr)
+{
+	char *buf;
+	size_t size;
+	int fd;
+	ssize_t ret;
+	int errno_hold;
+
+	__selinux_once(once, init_procattr);
+	init_thread_destructor();
+
+	fd = openattr(pid, attr, O_RDONLY);
+	if (fd < 0) 
 		return -1;
 
 	size = selinux_page_size;
@@ -77,6 +143,9 @@ static int getprocattrcon(security_context_t * context,
 	int ret;
 	security_context_t rcontext;
 
+	if (cpid != getpid())
+		free_procattr();
+
 	ret = getprocattrcon_raw(&rcontext, pid, attr);
 
 	if (!ret) {
@@ -90,40 +159,69 @@ static int getprocattrcon(security_context_t * context,
 static int setprocattrcon_raw(security_context_t context,
 			      pid_t pid, const char *attr)
 {
-	char *path;
-	int fd, rc;
-	pid_t tid;
+	int fd;
 	ssize_t ret;
 	int errno_hold;
+	security_context_t *prev_context;
 
-	if (pid > 0)
-		rc = asprintf(&path, "/proc/%d/attr/%s", pid, attr);
-	else {
-		tid = gettid();
-		rc = asprintf(&path, "/proc/self/task/%d/attr/%s", tid, attr);
-	}
-	if (rc < 0)
-		return -1;
+	__selinux_once(once, init_procattr);
+	init_thread_destructor();
 
-	fd = open(path, O_RDWR);
-	free(path);
+	if (cpid != getpid())
+		free_procattr();
+
+	switch (attr[0]) {
+		case 'c':
+			prev_context = &prev_current;
+			break;
+		case 'e':
+			prev_context = &prev_exec;
+			break;
+		case 'f':
+			prev_context = &prev_fscreate;
+			break;
+		case 'k':
+			prev_context = &prev_keycreate;
+			break;
+		case 's':
+			prev_context = &prev_sockcreate;
+			break;
+		default:
+			return -1;
+	};
+
+	if (!context && !*prev_context)
+		return 0;
+	if (context && *prev_context && !strcmp(context, *prev_context))
+		return 0;
+
+	fd = openattr(pid, attr, O_RDWR);
 	if (fd < 0)
 		return -1;
-	if (context)
+	if (context) {
+		ret = -1;
+		context = strdup(context);
+		if (!context)
+			goto out;
 		do {
 			ret = write(fd, context, strlen(context) + 1);
 		} while (ret < 0 && errno == EINTR);
-	else
+	} else {
 		do {
 			ret = write(fd, NULL, 0);	/* clear */
 		} while (ret < 0 && errno == EINTR);
+	}
+out:
 	errno_hold = errno;
 	close(fd);
 	errno = errno_hold;
-	if (ret < 0)
+	if (ret < 0) {
+		free(context);
 		return -1;
-	else
+	} else {
+		*prev_context = context;
 		return 0;
+	}
 }
 
 static int setprocattrcon(const security_context_t context,
diff --git a/libselinux/src/selinux_config.c b/libselinux/src/selinux_config.c
index 296f357..cb65666 100644
--- a/libselinux/src/selinux_config.c
+++ b/libselinux/src/selinux_config.c
@@ -9,6 +9,7 @@
 #include <unistd.h>
 #include <pthread.h>
 #include "selinux_internal.h"
+#include "policy.h"
 #include "get_default_type_internal.h"
 
 #define SELINUXDIR "/etc/selinux/"
@@ -296,13 +297,57 @@ const char *selinux_removable_context_path(void)
 
 hidden_def(selinux_removable_context_path)
 
+char *selinux_binary_policy_path_min_max(int min, int *max)
+{
+	int ret;
+	char *path = NULL;
+
+	while(*max >= min) {
+		ret = asprintf(&path, "%s.%d", get_path(BINPOLICY), *max);
+		if (ret < 0)
+			goto err;
+		ret = access(path, R_OK);
+		if (!ret)
+			return path;
+		free(path);
+		path = NULL;
+		*max = *max - 1;
+	}
+err:
+	free(path);
+	return NULL;
+}
+hidden_def(selinux_binary_policy_path_min_max)
+
 const char *selinux_binary_policy_path(void)
 {
 	return get_path(BINPOLICY);
 }
-
 hidden_def(selinux_binary_policy_path)
 
+const char *selinux_current_policy_path(void)
+{
+	int rc = 0;
+	int vers = 0;
+	static char policy_path[PATH_MAX];
+
+	snprintf(policy_path, sizeof(policy_path), "%s/policy", selinux_mnt);
+	if (access(policy_path, F_OK) != 0 ) {
+		vers = security_policyvers();
+		do {
+			/* Check prior versions to see if old policy is available */
+			snprintf(policy_path, sizeof(policy_path), "%s.%d",
+				 selinux_binary_policy_path(), vers);
+		} while ((rc = access(policy_path, F_OK)) && --vers > 0);
+
+		if (rc) return NULL;
+	}
+
+	return policy_path;
+}
+
+hidden_def(selinux_current_policy_path)
+
 const char *selinux_file_context_path(void)
 {
 	return get_path(FILE_CONTEXTS);
diff --git a/libselinux/src/selinux_internal.h b/libselinux/src/selinux_internal.h
index 2c7c85c..008aa6d 100644
--- a/libselinux/src/selinux_internal.h
+++ b/libselinux/src/selinux_internal.h
@@ -61,7 +61,9 @@ hidden_proto(selinux_mkload_policy)
     hidden_proto(security_deny_unknown)
     hidden_proto(selinux_boolean_sub)
     hidden_proto(selinux_binary_policy_path)
+    hidden_proto(selinux_binary_policy_path_min_max)
     hidden_proto(selinux_booleans_subs_path)
+    hidden_proto(selinux_current_policy_path)
     hidden_proto(selinux_default_context_path)
     hidden_proto(selinux_securetty_types_path)
     hidden_proto(selinux_failsafe_context_path)
diff --git a/libselinux/src/sestatus.c b/libselinux/src/sestatus.c
index 10a6495..ed29dc5 100644
--- a/libselinux/src/sestatus.c
+++ b/libselinux/src/sestatus.c
@@ -256,19 +256,23 @@ int selinux_status_open(int fallback)
 {
 	int	fd;
 	char	path[PATH_MAX];
+	long	pagesize;
 
 	if (!selinux_mnt) {
 		errno = ENOENT;
 		return -1;
 	}
 
+	pagesize = sysconf(_SC_PAGESIZE);
+	if (pagesize < 0)
+		return -1;
+
 	snprintf(path, sizeof(path), "%s/status", selinux_mnt);
-	fd = open(path, O_RDONLY);
+	fd = open(path, O_RDONLY | O_CLOEXEC);
 	if (fd < 0)
 		goto error;
 
-	selinux_status = mmap(NULL, sysconf(_SC_PAGESIZE),
-			      PROT_READ, MAP_SHARED, fd, 0);
+	selinux_status = mmap(NULL, pagesize, PROT_READ, MAP_SHARED, fd, 0);
 	if (selinux_status == MAP_FAILED) {
 		close(fd);
 		goto error;
@@ -318,6 +322,8 @@ error:
  */
 void selinux_status_close(void)
 {
+	long pagesize;
+
 	/* not opened */
 	if (selinux_status == NULL)
 		return;
@@ -331,7 +337,10 @@ void selinux_status_close(void)
 		return;
 	}
 
-	munmap(selinux_status, sysconf(_SC_PAGESIZE));
+	pagesize = sysconf(_SC_PAGESIZE);
+	/* not much we can do other than leak memory */
+	if (pagesize > 0)
+		munmap(selinux_status, pagesize);
 	selinux_status = NULL;
 
 	close(selinux_status_fd);
diff --git a/libselinux/src/setrans_client.c b/libselinux/src/setrans_client.c
index 502e9db..f9065bd 100644
--- a/libselinux/src/setrans_client.c
+++ b/libselinux/src/setrans_client.c
@@ -56,7 +56,10 @@ static int setransd_open(void)
 	{
 		fd = socket(PF_UNIX, SOCK_STREAM, 0);
 		if (fd >= 0)
-			fcntl(fd, F_SETFD, FD_CLOEXEC);
+			if (fcntl(fd, F_SETFD, FD_CLOEXEC)) {
+				close(fd);
+				return -1;
+			}
 	}
 	if (fd < 0)
 		return -1;
@@ -151,9 +154,10 @@ receive_response(int fd, uint32_t function, char **outdata, int32_t * ret_val)
 	}
 
 	data = malloc(data_size);
-	if (!data) {
+	if (!data)
 		return -1;
-	}
+	/* coveriety doesn't realize that data will be initialized in readv */
+	memset(data, 0, data_size);
 
 	resp_data.iov_base = data;
 	resp_data.iov_len = data_size;
diff --git a/libselinux/src/seusers.c b/libselinux/src/seusers.c
index cfea186..09e704b 100644
--- a/libselinux/src/seusers.c
+++ b/libselinux/src/seusers.c
@@ -141,9 +141,16 @@ static int check_group(const char *group, const char *name, const gid_t gid) {
 	}
 
 	if (getgrouplist(name, gid, NULL, &ng) < 0) {
-		groups = (gid_t *) malloc(sizeof (gid_t) * ng);
-		if (!groups) goto done;
-		if (getgrouplist(name, gid, groups, &ng) < 0) goto done;
+		if (ng == 0)
+			goto done;
+		groups = calloc(ng, sizeof(*groups));
+		if (!groups)
+			goto done;
+		if (getgrouplist(name, gid, groups, &ng) < 0)
+			goto done;
+	} else {
+		/* WTF?  ng was 0 and we didn't fail? Are we in 0 groups? */
+		goto done;
 	}
 
 	for (i = 0; i < ng; i++) {
diff --git a/libselinux/src/stringrep.c b/libselinux/src/stringrep.c
index 176ac34..ba75ccd 100644
--- a/libselinux/src/stringrep.c
+++ b/libselinux/src/stringrep.c
@@ -258,18 +258,21 @@ static struct discover_class_node * discover_class(const char *s)
 		struct stat m;
 
 		snprintf(path, sizeof path, "%s/class/%s/perms/%s", selinux_mnt,s,dentry->d_name);
-		if (stat(path,&m) < 0)
+		fd = open(path, O_RDONLY | O_CLOEXEC);
+		if (fd < 0)
+			goto err4;
+
+		if (fstat(fd, &m) < 0) {
+			close(fd);
 			goto err4;
+		}
 
 		if (m.st_mode & S_IFDIR) {
+			close(fd);
 			dentry = readdir(dir);
 			continue;
 		}
 
-		fd = open(path, O_RDONLY);
-		if (fd < 0)
-			goto err4;
-
 		memset(buf, 0, sizeof(buf));
 		ret = read(fd, buf, sizeof(buf) - 1);
 		close(fd);
@@ -279,6 +282,9 @@ static struct discover_class_node * discover_class(const char *s)
 		if (sscanf(buf, "%u", &value) != 1)
 			goto err4;
 
+		if (value == 0 || value > NVECTORS)
+			goto err4;
+
 		node->perms[value-1] = strdup(dentry->d_name);
 		if (node->perms[value-1] == NULL)
 			goto err4;
@@ -436,6 +442,27 @@ security_class_t string_to_security_class(const char *s)
 	return map_class(node->value);
 }
 
+security_class_t mode_to_security_class(mode_t m) {
+
+	if (S_ISREG(m))
+		return string_to_security_class("file");
+	if (S_ISDIR(m))
+		return string_to_security_class("dir");
+	if (S_ISCHR(m))
+		return string_to_security_class("chr_file");
+	if (S_ISBLK(m))
+		return string_to_security_class("blk_file");
+	if (S_ISFIFO(m))
+		return string_to_security_class("fifo_file");
+	if (S_ISLNK(m))
+		return string_to_security_class("lnk_file");
+	if (S_ISSOCK(m))
+		return string_to_security_class("sock_file");
+
+	errno=EINVAL;
+	return 0;
+}
+
 access_vector_t string_to_av_perm(security_class_t tclass, const char *s)
 {
 	struct discover_class_node *node;
diff --git a/libselinux/utils/.gitignore b/libselinux/utils/.gitignore
index 8b9294d..060eaab 100644
--- a/libselinux/utils/.gitignore
+++ b/libselinux/utils/.gitignore
@@ -13,6 +13,7 @@ getsebool
 getseuser
 matchpathcon
 policyvers
+sefcontext_compile
 selinux_check_securetty_context
 selinuxenabled
 selinuxexeccon
diff --git a/libselinux/utils/Makefile b/libselinux/utils/Makefile
index 5f3e047..f469924 100644
--- a/libselinux/utils/Makefile
+++ b/libselinux/utils/Makefile
@@ -28,6 +28,7 @@ LDLIBS += -L../src -lselinux -L$(LIBDIR)
 
 TARGETS=$(patsubst %.c,%,$(wildcard *.c))
 
+sefcontext_compile: LDLIBS += -lpcre
 
 ifeq ($(DISABLE_AVC),y)
 	UNUSED_TARGETS+=compute_av compute_create compute_member compute_relabel
diff --git a/libselinux/utils/avcstat.c b/libselinux/utils/avcstat.c
index 73432f2..1d4d5c8 100644
--- a/libselinux/utils/avcstat.c
+++ b/libselinux/utils/avcstat.c
@@ -155,7 +155,7 @@ int main(int argc, char **argv)
 		ssize_t ret, parsed = 0;
 
 		memset(buf, 0, DEF_BUF_SIZE);
-		ret = read(fd, buf, DEF_BUF_SIZE);
+		ret = read(fd, buf, DEF_BUF_SIZE-1);
 		if (ret < 0)
 			die("read");
 
diff --git a/libselinux/utils/sefcontext_compile.c b/libselinux/utils/sefcontext_compile.c
new file mode 100644
index 0000000..15cc836
--- /dev/null
+++ b/libselinux/utils/sefcontext_compile.c
@@ -0,0 +1,350 @@
+#include <ctype.h>
+#include <errno.h>
+#include <pcre.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <linux/limits.h>
+
+#include "../src/label_file.h"
+
+static int process_file(struct saved_data *data, const char *filename)
+{
+	struct spec *spec;
+	unsigned int line_num;
+	char *line_buf = NULL;
+	size_t line_len;
+	ssize_t len;
+	FILE *context_file;
+
+	context_file = fopen(filename, "r");
+	if (!context_file) {
+		fprintf(stderr, "Error opening %s: %s\n", filename, strerror(errno));
+		return -1;
+	}
+
+	line_num = 0;
+	while ((len = getline(&line_buf, &line_len, context_file)) != -1) {
+		char *context;
+		char *mode;
+		char *regex;
+		char *cp, *anchored_regex;
+		char *buf_p;
+		pcre *re;
+		pcre_extra *sd;
+		const char *err;
+		int items, erroff, rc;
+		size_t regex_len;
+		int32_t stem_id;
+
+		len = strlen(line_buf);
+		if (line_buf[len - 1] == '\n')
+			line_buf[len - 1] = 0;
+		buf_p = line_buf;
+		while (isspace(*buf_p))
+			buf_p++;
+		/* Skip comment lines and empty lines. */
+		if (*buf_p == '#' || *buf_p == 0)
+			continue;
+
+		items = sscanf(line_buf, "%ms %ms %ms", &regex, &mode, &context);
+		if (items < 2 || items > 3) {
+			fprintf(stderr, "invalid entry, skipping:%s", line_buf);
+			continue;
+		}
+
+		if (items == 2) {
+			context = mode;
+			mode = NULL;
+		}
+
+		rc = grow_specs(data);
+		if (rc) {
+			fprintf(stderr, "grow_specs failed: %s\n", strerror(errno));
+			return rc;
+		}
+
+		spec = &data->spec_arr[data->nspec];
+
+		spec->lr.ctx_raw = context;
+		spec->mode = string_to_mode(mode);
+		if (spec->mode == -1) {
+			fprintf(stderr, "%s: line %d has invalid file type %s\n",
+				regex, line_num + 1, mode);
+			spec->mode = 0;
+		}
+		free(mode);
+		spec->regex_str = regex;
+
+		stem_id = find_stem_from_spec(data, regex);
+		spec->stem_id = stem_id;
+		/* skip past the fixed stem part */
+		if (stem_id != -1)
+			regex += data->stem_arr[stem_id].len;
+
+		regex_len = strlen(regex);
+		cp = anchored_regex = malloc(regex_len + 3);
+		if (!cp) {
+			fprintf(stderr, "Malloc Failed: %s\n", strerror(errno));
+			return -1;
+		}
+		*cp++ = '^';
+		memcpy(cp, regex, regex_len);
+		cp += regex_len;
+		*cp++ = '$';
+		*cp = '\0';
+
+		spec_hasMetaChars(spec);
+
+		re = pcre_compile(anchored_regex, 0, &err, &erroff, NULL);
+		if (!re) {
+			fprintf(stderr, "PCRE compilation failed for %s at offset %d: %s\n", anchored_regex, erroff, err);
+			return -1;
+		}
+		spec->regex = re;
+
+		sd = pcre_study(re, 0, &err);
+		if (!sd) {
+			fprintf(stderr, "PCRE study failed for %s: %s\n", anchored_regex, err);
+			return -1;
+		}
+		free(anchored_regex);
+		spec->sd = sd;
+
+		line_num++;
+		data->nspec++;
+	}
+
+	free(line_buf);
+	fclose(context_file);
+
+	return 0;
+}
+
+/*
+ * File Format
+ *
+ * u32 - magic number
+ * u32 - version
+ * u32 - number of stems
+ * ** Stems
+ * 	u32  - length of stem EXCLUDING nul
+ * 	char - stem char array INCLUDING nul
+ * u32 - number of regexs
+ * ** Regexes
+ * 	u32  - length of upcoming context INCLUDING nul
+ * 	char - char array of the raw context
+ *	u32  - length of the upcoming regex_str
+ *	char - char array of the original regex string including the stem.
+ *	mode_t - mode bits
+ *	s32  - stemid associated with the regex
+ *	u32  - spec has meta characters
+ *	u32  - data length of the pcre regex
+ *	char - a bufer holding the raw pcre regex info
+ *	u32  - data length of the pcre regex study daya
+ *	char - a buffer holding the raw pcre regex study data
+ */
+static int write_binary_file(struct saved_data *data, char *filename)
+{
+	struct spec *specs = data->spec_arr;
+	FILE *bin_file;
+	size_t len;
+	uint32_t magic = SELINUX_MAGIC_COMPILED_FCONTEXT;
+	uint32_t section_len;
+	uint32_t i;
+
+	bin_file = fopen(filename, "w");
+	if (!bin_file) {
+		perror("fopen output_file");
+		exit(EXIT_FAILURE);
+	}
+
+	/* write some magic number */
+	len = fwrite(&magic, sizeof(uint32_t), 1, bin_file);
+	if (len != 1)
+		return -1;
+
+	/* write the version */
+	section_len = SELINUX_COMPILED_FCONTEXT_MAX_VERS;
+	len = fwrite(&section_len, sizeof(uint32_t), 1, bin_file);
+	if (len != 1)
+		return -1;
+
+	/* write the number of stems coming */
+	section_len = data->num_stems;
+	len = fwrite(&section_len, sizeof(uint32_t), 1, bin_file);
+	if (len != 1)
+		return -1;
+
+	for (i = 0; i < section_len; i++) {
+		char *stem = data->stem_arr[i].buf;
+		uint32_t stem_len = data->stem_arr[i].len;
+
+		/* write the strlen (aka no nul) */
+		len = fwrite(&stem_len, sizeof(uint32_t), 1, bin_file);
+		if (len != 1)
+			return -1;
+
+		/* include the nul in the file */
+		stem_len += 1;
+		len = fwrite(stem, sizeof(char), stem_len, bin_file);
+		if (len != stem_len)
+			return -1;
+	}
+
+	/* write the number of regexes coming */
+	section_len = data->nspec;
+	len = fwrite(&section_len, sizeof(uint32_t), 1, bin_file);
+	if (len != 1)
+		return -1;
+
+	for (i = 0; i < section_len; i++) {
+		char *context = specs[i].lr.ctx_raw;
+		char *regex_str = specs[i].regex_str;
+		mode_t mode = specs[i].mode;
+		int32_t stem_id = specs[i].stem_id;
+		pcre *re = specs[i].regex;
+		pcre_extra *sd = get_pcre_extra(&specs[i]);
+		uint32_t to_write;
+		size_t size;
+		int rc;
+
+		/* length of the context string (including nul) */
+		to_write = strlen(context) + 1;
+		len = fwrite(&to_write, sizeof(uint32_t), 1, bin_file);
+		if (len != 1)
+			return -1;
+
+		/* original context strin (including nul) */
+		len = fwrite(context, sizeof(char), to_write, bin_file);
+		if (len != to_write)
+			return -1;
+
+		/* length of the original regex string (including nul) */
+		to_write = strlen(regex_str) + 1;
+		len = fwrite(&to_write, sizeof(uint32_t), 1, bin_file);
+		if (len != 1)
+			return -1;
+
+		/* original regex string */
+		len = fwrite(regex_str, sizeof(char), to_write, bin_file);
+		if (len != to_write)
+			return -1;
+
+		/* binary F_MODE bits */
+		len = fwrite(&mode, sizeof(mode), 1, bin_file);
+		if (len != 1)
+			return -1;
+
+		/* stem for this regex (could be -1) */
+		len = fwrite(&stem_id, sizeof(stem_id), 1, bin_file);
+		if (len != 1)
+			return -1;
+
+		/* does this spec have a metaChar? */
+		to_write = specs[i].hasMetaChars;
+		len = fwrite(&to_write, sizeof(to_write), 1, bin_file);
+		if (len != 1)
+			return -1;
+
+		/* determine the size of the pcre data in bytes */
+		rc = pcre_fullinfo(re, NULL, PCRE_INFO_SIZE, &size);
+		if (rc < 0)
+			return -1;
+
+		/* write the number of bytes in the pcre data */
+		to_write = size;
+		len = fwrite(&to_write, sizeof(uint32_t), 1, bin_file);
+		if (len != 1)
+			return -1;
+
+		/* write the actual pcre data as a char array */
+		len = fwrite(re, 1, to_write, bin_file);
+		if (len != to_write)
+			return -1;
+
+		/* determine the size of the pcre study info */
+		rc = pcre_fullinfo(re, sd, PCRE_INFO_STUDYSIZE, &size);
+		if (rc < 0)
+			return -1;
+
+		/* write the number of bytes in the pcre study data */
+		to_write = size;
+		len = fwrite(&to_write, sizeof(uint32_t), 1, bin_file);
+		if (len != 1)
+			return -1;
+
+		/* write the actual pcre study data as a char array */
+		len = fwrite(sd->study_data, 1, to_write, bin_file);
+		if (len != to_write)
+			return -1;
+	}
+
+	fclose(bin_file);
+
+	return 0;
+}
+
+static int free_specs(struct saved_data *data)
+{
+	struct spec *specs = data->spec_arr;
+	unsigned int num_entries = data->nspec;
+	unsigned int i;
+
+	for (i = 0; i < num_entries; i++) {
+		free(specs[i].lr.ctx_raw);
+		free(specs[i].lr.ctx_trans);
+		free(specs[i].regex_str);
+		pcre_free(specs[i].regex);
+		pcre_free_study(specs[i].sd);
+	}
+	free(specs);
+
+	num_entries = data->num_stems;
+	for (i = 0; i < num_entries; i++) {
+		free(data->stem_arr[i].buf);
+	}
+	free(data->stem_arr);
+
+	memset(data, 0, sizeof(*data));
+	return 0;
+}
+
+int main(int argc, char *argv[])
+{
+	struct saved_data data;
+	const char *path;
+	char stack_path[PATH_MAX + 1];
+	int rc;
+
+	if (argc != 2) {
+		fprintf(stderr, "usage: %s input_file\n", argv[0]);
+		exit(EXIT_FAILURE);
+	}
+
+	memset(&data, 0, sizeof(data));
+
+	path = argv[1];
+
+	rc = process_file(&data, path);
+	if (rc < 0)
+		return rc;
+
+	rc = sort_specs(&data);
+	if (rc)
+		return rc;
+
+	rc = snprintf(stack_path, sizeof(stack_path), "%s.bin", path);
+	if (rc < 0 || rc >= sizeof(stack_path))
+		return rc;
+	rc = write_binary_file(&data, stack_path);
+	if (rc < 0)
+		return rc;
+
+	rc = free_specs(&data);
+	if (rc < 0)
+		return rc;
+
+	return 0;
+}