Patches from the Debian packages
cover Patches from the Debian packages
Hi,
Please find in the following mails patches that are coming from the debian packages or that fix issues that were detected using some debian tools.
Most of the patches are fixing build system or manpage formating issues.
One is adding a reworked open_init_pty executable (patch made by Russell).
An other one is adding handeling of UID_MAX (similar to UID_MIN) in genhomedircon.
Cheers
Laurent Bigonville
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 1/15 Policycoreutils: Allow overriding INITDIR in restorecond Makefile
From: Laurent Bigonville <[email protected]>
--- policycoreutils/restorecond/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
policycoreutils/restorecond/Makefile +1 -1
@@ -7,7 +7,7 @@ AUTOSTARTDIR = $(DESTDIR)/etc/xdg/autostart DBUSSERVICEDIR = $(DESTDIR)/usr/share/dbus-1/services autostart_DATA = sealertauto.desktop -INITDIR = $(DESTDIR)/etc/rc.d/init.d +INITDIR ?= $(DESTDIR)/etc/rc.d/init.d SELINUXDIR = $(DESTDIR)/etc/selinux DBUSFLAGS = -DHAVE_DBUS -I/usr/include/dbus-1.0 -I/usr/lib64/dbus-1.0/include -I/usr/lib/dbus-1.0/include
Signature · 7 lines
1.7.10.4 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 2/15 policycoreutils: Create correct man directory for run_init manpages
In reply to Laurent BigonvilleFrom: Russell Coker <[email protected]>
--- policycoreutils/run_init/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
policycoreutils/run_init/Makefile +1 -1
@@ -33,7 +33,7 @@ open_init_pty: open_init_pty.c install: all test -d $(SBINDIR) || install -m 755 -d $(SBINDIR) - test -d $(MANDIR)/man1 || install -m 755 -d $(MANDIR)/man1 + test -d $(MANDIR)/man8 || install -m 755 -d $(MANDIR)/man8 install -m 755 run_init $(SBINDIR) install -m 755 open_init_pty $(SBINDIR) install -m 644 run_init.8 $(MANDIR)/man8/
Signature · 7 lines
1.7.10.4 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 3/15 policycoreutils: Allow overriding CFLAGS in setfiles and sestatus Makefiles
In reply to Laurent BigonvilleFrom: Simon Ruderich <[email protected]>
This is required to be able to pass hardening flags in Debian.
--- policycoreutils/sestatus/Makefile | 2 +- policycoreutils/setfiles/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
policycoreutils/sestatus/Makefile +1 -1
@@ -5,7 +5,7 @@ MANDIR = $(PREFIX)/share/man ETCDIR ?= $(DESTDIR)/etc LIBDIR ?= $(PREFIX)/lib -CFLAGS = -Werror -Wall -W +CFLAGS ?= -Werror -Wall -W override CFLAGS += -I$(PREFIX)/include -D_FILE_OFFSET_BITS=64 LDLIBS = -lselinux -L$(LIBDIR)
policycoreutils/setfiles/Makefile +1 -1
@@ -8,7 +8,7 @@ AUDITH = $(shell ls /usr/include/libaudit.h 2>/dev/null) PROGRESS_STEP=$(shell grep "^\#define STAR_COUNT" restore.h | awk -S '{ print $$3 }') ABORT_ON_ERRORS=$(shell grep "^\#define ABORT_ON_ERRORS" setfiles.c | awk -S '{ print $$3 }') -CFLAGS = -g -Werror -Wall -W +CFLAGS ?= -g -Werror -Wall -W override CFLAGS += -I$(PREFIX)/include LDLIBS = -lselinux -lsepol -L$(LIBDIR)
Signature · 7 lines
1.7.10.4 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 6/15 libsepol: Allow overriding LIBBASE in src/Makefile
In reply to Laurent BigonvilleFrom: Laurent Bigonville <[email protected]>
--- libsepol/src/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/src/Makefile +1 -1
@@ -3,7 +3,7 @@ PREFIX ?= $(DESTDIR)/usr INCLUDEDIR ?= $(PREFIX)/include LIBDIR ?= $(PREFIX)/lib SHLIBDIR ?= $(DESTDIR)/lib -LIBBASE=$(shell basename $(LIBDIR)) +LIBBASE ?= $(shell basename $(LIBDIR)) VERSION = $(shell cat ../VERSION) LIBVERSION = 1
Signature · 7 lines
1.7.10.4 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 11/15 libselinux: Fix cases where hyphen were used as minus sign in manpages
In reply to Laurent BigonvilleFrom: Laurent Bigonville <[email protected]>
And also other minor formating issues
--- libselinux/man/man3/avc_netlink_loop.3 | 2 +- libselinux/man/man3/context_new.3 | 2 +- libselinux/man/man3/get_ordered_context_list.3 | 8 ++++---- libselinux/man/man3/getcon.3 | 2 +- libselinux/man/man3/getexeccon.3 | 2 +- libselinux/man/man3/getfscreatecon.3 | 2 +- libselinux/man/man3/getkeycreatecon.3 | 2 +- libselinux/man/man3/getsockcreatecon.3 | 2 +- libselinux/man/man3/is_context_customizable.3 | 2 +- libselinux/man/man3/matchmediacon.3 | 2 +- libselinux/man/man3/security_check_context.3 | 2 +- libselinux/man/man3/security_getenforce.3 | 6 +++--- libselinux/man/man3/security_policyvers.3 | 2 +- libselinux/man/man3/security_setenforce.3 | 2 +- libselinux/man/man3/selinux_boolean_sub.3 | 2 +- libselinux/man/man3/selinux_getenforcemode.3 | 4 ++-- libselinux/man/man3/selinux_getpolicytype.3 | 2 +- libselinux/man/man3/selinux_set_mapping.3 | 2 +- libselinux/man/man3/selinux_status_open.3 | 12 ++++++------ libselinux/man/man3/setfilecon.3 | 6 +++--- libselinux/man/man5/selabel_db.5 | 2 +- libselinux/man/man8/booleans.8 | 8 ++++---- 22 files changed, 38 insertions(+), 38 deletions(-)
libselinux/man/man3/avc_netlink_loop.3 +1 -1
@@ -73,7 +73,7 @@ the socket, in which case the socket is closed. .SH "RETURN VALUE" .B 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.
libselinux/man/man3/context_new.3 +1 -1
@@ -54,7 +54,7 @@ context_type_set, context_range_set, context_role_set, context_user_set Set a context component .SH "RETURN VALUE" -On success, zero is returned. On failure, -1 is returned and errno is +On success, zero is returned. On failure, \-1 is returned and errno is set appropriately. .SH "SEE ALSO"
libselinux/man/man3/get_ordered_context_list.3 +4 -4
@@ -41,7 +41,7 @@ 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 +list, or \-1 upon errors. The list must be freed using the .B freeconary function.
@@ -56,7 +56,7 @@ which has to be freed with freecon. invokes the 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. +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. .B get_default_context_with_rolelevel invokes the get_default_context_with_role function and applies the specified level.
@@ -73,8 +73,8 @@ allows the user to manually enter a context as a fallback if a list of authorize Get the default type (domain) for 'role' and set '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. +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. .SH "SEE ALSO" .BR selinux "(8), " freeconary "(3), " freecon "(3), " security_compute_av "(3)", getseuserbyname"(3)"
libselinux/man/man3/getcon.3 +1 -1
@@ -72,7 +72,7 @@ operation, ptrace permission will be revalidated against the new context and the setcon() will fail if it is not allowed by policy. .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)"
libselinux/man/man3/getexeccon.3 +1 -1
@@ -49,7 +49,7 @@ environment arrays. .SH "RETURN VALUE" -On error -1 is returned. +On error \-1 is returned. On success getexeccon and setexeccon returns 0. rpm_execcon only returns upon errors, as it calls execve(2).
libselinux/man/man3/getfscreatecon.3 +1 -1
@@ -31,7 +31,7 @@ in order to set an file context on the objects. Note: Signal handlers that perform an setfscreate 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"
libselinux/man/man3/getkeycreatecon.3 +1 -1
@@ -31,7 +31,7 @@ in order to set an file context on the objects. Note: Signal handlers that perform an setkeycreate 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"
libselinux/man/man3/getsockcreatecon.3 +1 -1
@@ -31,7 +31,7 @@ in order to set an file context on the objects. Note: Signal handlers that perform an setsockcreate 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"
libselinux/man/man3/is_context_customizable.3 +1 -1
@@ -15,7 +15,7 @@ administrators set on files, usually to allow certain domains to share the file .SH "RETURN VALUE" returns 1 if security context is customizable or 0 if it is not. -returns -1 on error +returns \-1 on error .SH "FILE" /etc/selinux/SELINUXTYPE/context/customizable_types
libselinux/man/man3/matchmediacon.3 +1 -1
@@ -17,7 +17,7 @@ matches the specified media type with the media contexts configuration and sets .B Note: Caller must free returned security context "con" using freecon. .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
libselinux/man/man3/security_check_context.3 +1 -1
@@ -9,7 +9,7 @@ security_check_context \- check the validity of a SELinux context .SH "DESCRIPTION" .B security_check_context returns 0 if SELinux is running and the context is valid, otherwise it -returns -1. +returns \-1. .SH "SEE ALSO" .BR selinux "(8)"
libselinux/man/man3/security_getenforce.3 +3 -3
@@ -13,16 +13,16 @@ security_getenforce, security_setenforce, security_deny_unknown \- get or set th .SH "DESCRIPTION" .B 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 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 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)"
libselinux/man/man3/security_policyvers.3 +1 -1
@@ -8,7 +8,7 @@ security_policyvers \- get the version of the SELinux policy .SH "DESCRIPTION" .B security_policyvers -returns the version of the policy (a positive integer) on success, or -1 on +returns the version of the policy (a positive integer) on success, or \-1 on error. .SH "SEE ALSO"
libselinux/man/man3/security_setenforce.3 +1 -1
@@ -1 +1 @@ -.so security_getenforce.3 +.so man3/security_getenforce.3
libselinux/man/man3/selinux_boolean_sub.3 +1 -1
@@ -1,6 +1,6 @@ .TH "selinux_boolean_subs" "3" "11 June 2012" "[email protected]" "SELinux API documentation" .SH "NAME" -selinux_boolean_subs +selinux_boolean_subs \- returns the boolean substitution name if existing. .SH "SYNOPSIS" .B #include <selinux/selinux.h> .sp
libselinux/man/man3/selinux_getenforcemode.3 +2 -2
@@ -14,10 +14,10 @@ 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 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)"
libselinux/man/man3/selinux_getpolicytype.3 +1 -1
@@ -13,7 +13,7 @@ Reads the contents of the /etc/selinux/config file to determine the SELinux poli .SH "RETURN VALUE" On success, zero is returned. -On failure, -1 is returned. +On failure, \-1 is returned. .SH "SEE ALSO" .BR selinux "(8)"
libselinux/man/man3/selinux_set_mapping.3 +1 -1
@@ -35,7 +35,7 @@ field should refer to an array of permission bit names terminated by a NULL stri 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.
libselinux/man/man3/selinux_status_open.3 +6 -6
@@ -58,24 +58,24 @@ netlink socket if fallbacked. .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 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. +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 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
@@ -84,10 +84,10 @@ performing. .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. +value as described above, or \-1 on errors. .sp .SH "SEE ALSO" .BR mmap (2)
libselinux/man/man3/setfilecon.3 +3 -3
@@ -24,15 +24,15 @@ 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. .SH "RETURN VALUE" -On success, zero is returned. On failure, -1 is returned and errno is +On success, zero is returned. On failure, \-1 is returned and errno is set appropriately. 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. +If extended attributes are not supported by the filesystem, or are disabled, +errno is set to ENOTSUP. The errors documented for the stat(2) system call are also applicable here.
libselinux/man/man5/selabel_db.5 +1 -1
@@ -5,7 +5,7 @@ .SH "NAME" 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
libselinux/man/man8/booleans.8 +4 -4
@@ -19,7 +19,7 @@ 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. +utility, using \-P to make the setting persistent across reboots. The .B system-config-securitylevel tool provides a graphical interface for altering
@@ -27,11 +27,11 @@ the settings. The .B 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 option. Boolean values can be listed by using the .B getsebool(8) -utility and passing it the -a option. +utility and passing it the \-a option. Boolean values can also be changed at runtime via the .B setsebool(8)
@@ -39,7 +39,7 @@ utility or the .B togglesebool 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 \-P option is used to setsebool. .SH AUTHOR This manual page was written by Dan Walsh <[email protected]>.
Signature · 7 lines
1.7.10.4 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 12/15 checkpolicy: Fix cases where hyphen were used as minus sign in manpages
In reply to Laurent BigonvilleFrom: Laurent Bigonville <[email protected]>
--- checkpolicy/checkmodule.8 | 6 +++--- checkpolicy/checkpolicy.8 | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-)
checkpolicy/checkmodule.8 +3 -3
@@ -3,7 +3,7 @@ checkmodule \- SELinux policy module compiler .SH SYNOPSIS .B checkmodule -.I "[-h] [-b] [-m] [-M] [-U handle_unknown ] [-V] [-o output_file] [input_file]" +.I "[\-h] [\-b] [\-m] [\-M] [\-U handle_unknown ] [\-V] [\-o output_file] [input_file]" .SH "DESCRIPTION" This manual page describes the .BR checkmodule
@@ -12,7 +12,7 @@ command. .B checkmodule is a program that checks and compiles a SELinux security policy module into a binary representation. It can generate either a base policy -module (default) or a non-base policy module (-m option); typically, +module (default) or a non-base policy module (\-m option); typically, you would build a non-base policy module to add to an existing module store that already has a base module provided by the base policy. Use semodule_package to combine this module with its optional file
@@ -48,7 +48,7 @@ Specify how the kernel should handle unknown classes or permissions (deny, allow .SH EXAMPLE .nf # Build a MLS/MCS-enabled non-base policy module. -$ checkmodule -M -m httpd.te -o httpd.mod +$ checkmodule \-M \-m httpd.te \-o httpd.mod .fi .SH "SEE ALSO"
checkpolicy/checkpolicy.8 +2 -2
@@ -3,7 +3,7 @@ checkpolicy \- SELinux policy compiler .SH SYNOPSIS .B checkpolicy -.I "[-b] [-d] [-M] [-c policyvers] [-o output_file] [input_file]" +.I "[\-b] [\-d] [\-M] [\-c policyvers] [\-o output_file] [input_file]" .br .SH "DESCRIPTION" This manual page describes the
@@ -14,7 +14,7 @@ command. is a program that checks and compiles a SELinux security policy configuration into a binary representation that can be loaded into the kernel. If no input file name is specified, checkpolicy will attempt to read from -policy.conf or policy, depending on whether the -b flag is specified. +policy.conf or policy, depending on whether the \-b flag is specified. .SH OPTIONS .TP
Signature · 7 lines
1.7.10.4 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 4/15 policycoreutils: Add new open_init_pty that doesn't waste CPU time
In reply to Laurent BigonvilleFrom: Russell Coker <[email protected]>
--- policycoreutils/run_init/Makefile | 7 +- policycoreutils/run_init/open_init_pty.c | 399 -------------------------- policycoreutils/run_init/open_init_pty.cpp | 423 ++++++++++++++++++++++++++++ 3 files changed, 427 insertions(+), 402 deletions(-) delete mode 100644 policycoreutils/run_init/open_init_pty.c create mode 100644 policycoreutils/run_init/open_init_pty.cpp
policycoreutils/run_init/Makefile +4 -3
@@ -10,6 +10,7 @@ AUDITH = $(shell ls /usr/include/libaudit.h 2>/dev/null) CFLAGS ?= -Werror -Wall -W override CFLAGS += -I$(PREFIX)/include -DUSE_NLS -DLOCALEDIR="\"$(LOCALEDIR)\"" -DPACKAGE="\"policycoreutils\"" +CPPFLAGS ?= $(CFLAGS) LDLIBS += -lselinux -L$(PREFIX)/lib ifeq ($(PAMH), /usr/include/security/pam_appl.h) override CFLAGS += -DUSE_PAM
@@ -23,12 +24,12 @@ ifeq ($(AUDITH), /usr/include/libaudit.h) LDLIBS += -laudit endif -TARGETS=$(patsubst %.c,%,$(wildcard *.c)) +TARGETS=open_init_pty run_init all: $(TARGETS) -open_init_pty: open_init_pty.c - $(LINK.c) $^ -ldl -lutil -o $@ +open_init_pty: open_init_pty.cpp + $(LINK.cpp) $^ -ldl -lutil -o $@ install: all
policycoreutils/run_init/open_init_pty.c deleted +0 -399
399 lines not on this page · raw message
policycoreutils/run_init/open_init_pty.cpp new file +423 -0
423 lines not on this page · raw message
Signature · 7 lines
1.7.10.4 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 5/15 checkpolicy: Allow overriding LIBDIR in test/Makefile
In reply to Laurent BigonvilleFrom: Laurent Bigonville <[email protected]>
--- checkpolicy/test/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
checkpolicy/test/Makefile +1 -1
@@ -3,7 +3,7 @@ # PREFIX ?= $(DESTDIR)/usr BINDIR=$(PREFIX)/bin -LIBDIR=$(PREFIX)/lib +LIBDIR ?= $(PREFIX)/lib INCLUDEDIR ?= $(PREFIX)/include CFLAGS ?= -g -Wall -W -Werror -O2 -pipe
Signature · 7 lines
1.7.10.4 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 7/15 libsemanage: Also check for the uppoer bound on user ids in login.defs
In reply to Laurent BigonvilleFrom: Manoj Srivastava <[email protected]>
Some non-Debian packages (like qmail, shudder) create users not below MIN_UID, but above MAX_UID, in /etc/login.defs (non-system users are supposed to have uids between MIN_UID and MAX_UID.
genhomedircon.c:gethomedirs() checks pwent.pw_uid against MIN_UID in /etc/login.defs to exclude system users from generating homedir contexts. But unfortunately it does not check it against MAX_UID setting from the same file. This gets us lines like the following in the contexts/files/file_contexts.homedirs file:
,----
| # | # Home Context for user user_u | # | /var/qmail/[^/]*/.+ user_u:object_r:user_home_t:s0 | /var/qmail/[^/]*/\.ssh(/.*)? user_u:object_r:user_home_ssh_t:s0 | /var/qmail/[^/]*/\.gnupg(/.+)? user_u:object_r:user_gpg_secret_t:s0 | /var/qmail/[^/]* -d user_u:object_r:user_home_dir_t:s0 | /var/qmail/lost\+found/.* <<none>> | /var/qmail -d system_u:object_r:home_root_t:s0 | /var/qmail/\.journal <<none>> | /var/qmail/lost\+found -d system_u:object_r:lost_found_t:s0 | /tmp/gconfd-.* -d user_u:object_r:user_tmp_t:s0 `---- This commit adds checking uid value againt MAX_UID too. --- libsemanage/src/genhomedircon.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-)
libsemanage/src/genhomedircon.c +19 -4
@@ -283,8 +283,8 @@ static semanage_list_t *get_home_dirs(genhomedircon_settings_t * s)char *rbuf =NULL ;char *path =NULL ;long rbuflen; -uid_t temp, minuid =0 ; -int minuid_set =0 ; +uid_t temp, minuid =0 , maxuid =0 ; +int minuid_set =0 , maxuid_set =0 ;struct passwd pwstorage, *pwbuf;struct stat buf;int retval;
@@ -335,6 +335,17 @@ static semanage_list_t *get_home_dirs(genhomedircon_settings_t * s)free (path); path =NULL ; + path =semanage_findval (PATH_ETC_LOGIN_DEFS ,"UID_MAX" ,NULL ); +if (path && *path) { + temp =atoi (path); +if (!maxuid_set || temp > maxuid) { + maxuid = temp; + maxuid_set =1 ; + } + } +free (path); + path =NULL ; + path =semanage_findval (PATH_ETC_LIBUSER ,"LU_UIDNUMBER" ,"=" );if (path && *path) { temp =atoi (path);
@@ -350,6 +361,10 @@ static semanage_list_t *get_home_dirs(genhomedircon_settings_t * s) minuid =500 ; minuid_set =1 ; } +if (!maxuid_set) { + maxuid =60000 ; + maxuid_set =1 ; + } rbuflen =sysconf (_SC_GETPW_R_SIZE_MAX);if (rbuflen <=0 )
@@ -359,7 +374,7 @@ static semanage_list_t *get_home_dirs(genhomedircon_settings_t * s) goto fail;setpwent ();while ((retval =getpwent_r (&pwstorage, rbuf, rbuflen, &pwbuf)) ==0 ) { -if (pwbuf->pw_uid < minuid) +if (pwbuf->pw_uid < minuid || pwbuf->pw_uid > maxuid)continue ;if (!semanage_list_find (shells, pwbuf->pw_shell))continue ;
@@ -392,7 +407,7 @@ static semanage_list_t *get_home_dirs(genhomedircon_settings_t * s)/* NOTE: old genhomedircon printed a warning on match */ if (hand.matched) { -WARN (s->h_semanage,"%s homedir %s or its parent directory conflicts with a file context already specified in the policy. This usually indicates an incorrectly defined system account. If it is a system account please make sure its uid is less than %u or its login shell is /sbin/nologin." , pwbuf->pw_name, pwbuf->pw_dir, minuid); +WARN (s->h_semanage,"%s homedir %s or its parent directory conflicts with a file context already specified in the policy. This usually indicates an incorrectly defined system account. If it is a system account please make sure its uid is less than %u or greater than %u or its login shell is /sbin/nologin." , pwbuf->pw_name, pwbuf->pw_dir, minuid, maxuid); }else {if (semanage_list_push (&homedir_list, path)) goto fail;
Signature · 7 lines
1.7.10.4 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 14/15 libsepol: Fix cases where hyphen were used as minus sign in manpages
In reply to Laurent BigonvilleFrom: Laurent Bigonville <[email protected]>
--- libsepol/man/man3/sepol_check_context.3 | 2 +- libsepol/man/man3/sepol_genbools.3 | 2 +- libsepol/man/man3/sepol_genusers.3 | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
libsepol/man/man3/sepol_check_context.3 +1 -1
@@ -22,4 +22,4 @@ policy on a SELinux system, use from libselinux instead. .SH "RETURN VALUE" -Returns 0 on success or -1 with errno set otherwise. +Returns 0 on success or \-1 with errno set otherwise.
libsepol/man/man3/sepol_genbools.3 +1 -1
@@ -21,7 +21,7 @@ does likewise, but obtains the boolean settings from the parallel arrays (names, values) with nel elements each. .SH "RETURN VALUE" -Returns 0 on success or -1 otherwise, with errno set appropriately. +Returns 0 on success or \-1 otherwise, with errno set appropriately. An errno of ENOENT indicates that the boolean file did not exist. An errno of EINVAL indicates that one or more booleans listed in the boolean file was undefined in the policy or had an invalid value specified;
libsepol/man/man3/sepol_genusers.3 +1 -1
@@ -44,7 +44,7 @@ set to 1 prior to calling in order to enable deletion of such users. .SH "RETURN VALUE" -Returns 0 on success or -1 otherwise, with errno set appropriately. +Returns 0 on success or \-1 otherwise, with errno set appropriately. An errno of ENOENT indicates that one or both of the user configuration files did not exist. An errno of EINVAL indicates that either the original binary policy image or the generated one were
Signature · 7 lines
1.7.10.4 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 8/15 libselinux: Allow overriding LIBBASE in src/Makefile
In reply to Laurent BigonvilleFrom: Laurent Bigonville <[email protected]>
--- libselinux/src/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libselinux/src/Makefile +1 -1
@@ -18,7 +18,7 @@ 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)) RUBYINSTALL ?= $(LIBDIR)/ruby/site_ruby/$(RUBYLIBVER)/$(RUBYPLATFORM) -LIBBASE=$(shell basename $(LIBDIR)) +LIBBASE ?= $(shell basename $(LIBDIR)) LDFLAGS ?= -lpcre
Signature · 7 lines
1.7.10.4 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 9/15 libselinux: Do not use LDFLAGS to set -lpcre
In reply to Laurent BigonvilleFrom: Laurent Bigonville <[email protected]>
This is breaking build if LDFLAGS is redefined.
This is the case on Debian where hardening flags are passed automatically by the build system.
--- libselinux/src/Makefile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
libselinux/src/Makefile +1 -3
@@ -20,8 +20,6 @@ RUBYINC ?= $(shell pkg-config --cflags ruby-$(RUBYLIBVER)) RUBYINSTALL ?= $(LIBDIR)/ruby/site_ruby/$(RUBYLIBVER)/$(RUBYPLATFORM) LIBBASE ?= $(shell basename $(LIBDIR)) -LDFLAGS ?= -lpcre - VERSION = $(shell cat ../VERSION) LIBVERSION = 1
@@ -116,7 +114,7 @@ $(LIBA): $(OBJS) $(RANLIB) $@ $(LIBSO): $(LOBJS) - $(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ -ldl -L$(LIBDIR) -Wl,-soname,$(LIBSO),-z,defs,-z,relro + $(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ -lpcre -ldl -L$(LIBDIR) -Wl,-soname,$(LIBSO),-z,defs,-z,relro ln -sf $@ $(TARGET) $(LIBPC): $(LIBPC).in ../VERSION
Signature · 7 lines
1.7.10.4 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 15/15 policycoreutils: Fix cases where hyphen were used as minus sign in manpages
In reply to Laurent BigonvilleFrom: Laurent Bigonville <[email protected]>
And also other minor formating issues
--- policycoreutils/audit2allow/audit2allow.1 | 32 ++++++------- policycoreutils/man/man5/selinux_config.5 | 2 +- policycoreutils/mcstrans/man/man8/mcs.8 | 2 +- policycoreutils/newrole/newrole.1 | 24 +++++----- policycoreutils/scripts/chcat.8 | 4 +- policycoreutils/scripts/fixfiles.8 | 22 ++++----- policycoreutils/scripts/genhomedircon.8 | 2 +- policycoreutils/semanage/semanage.8 | 48 ++++++++++---------- policycoreutils/semodule/semodule.8 | 16 +++---- policycoreutils/semodule_deps/semodule_deps.8 | 6 +-- .../semodule_package/semodule_package.8 | 8 ++-- policycoreutils/sestatus/sestatus.conf.5 | 2 +- policycoreutils/setfiles/restorecon.8 | 4 ++ policycoreutils/setfiles/setfiles.8 | 4 +- policycoreutils/setsebool/setsebool.8 | 8 ++-- 15 files changed, 94 insertions(+), 90 deletions(-)
policycoreutils/audit2allow/audit2allow.1 +16 -16
@@ -29,7 +29,7 @@ \- generate SELinux policy allow/dontaudit rules from logs of denied operations .BR audit2why -\- translates SELinux audit messages into a description of why the access was denied (audit2allow -w) +\- translates SELinux audit messages into a description of why the access was denied (audit2allow \-w) .SH SYNOPSIS .B audit2allow
@@ -37,16 +37,16 @@ .SH OPTIONS .TP .B "\-a" | "\-\-all" -Read input from audit and message log, conflicts with -i +Read input from audit and message log, conflicts with \-i .TP .B "\-b" | "\-\-boot" -Read input from audit messages since last boot conflicts with -i +Read input from audit messages since last boot conflicts with \-i .TP .B "\-d" | "\-\-dmesg" Read input from output of .I /bin/dmesg. Note that all audit messages are not available via dmesg when -auditd is running; use "ausearch -m avc | audit2allow" or "-a" instead. +auditd is running; use "ausearch \-m avc | audit2allow" or "\-a" instead. .TP .B "\-D" | "\-\-dontaudit" Generate dontaudit rules (Default: allow)
@@ -65,7 +65,7 @@ read input only after last policy reload Generate module/require output <modulename> .TP .B "\-M <modulename>" -Generate loadable module package, conflicts with -o +Generate loadable module package, conflicts with \-o .TP .B "\-p <policyfile>" | "\-\-policy <policyfile>" Policy file to use for analysis
@@ -123,7 +123,7 @@ an 'allow' rule. .PP .B Using audit2allow to generate module policy -$ cat /var/log/audit/audit.log | audit2allow -m local > local.te +$ cat /var/log/audit/audit.log | audit2allow \-m local > local.te $ cat local.te module local 1.0;
@@ -141,7 +141,7 @@ allow myapp_t etc_t:file { getattr open read }; .B Using audit2allow to generate module policy using reference policy -$ cat /var/log/audit/audit.log | audit2allow -R -m local > local.te +$ cat /var/log/audit/audit.log | audit2allow \-R \-m local > local.te $ cat local.te policy_module(local, 1.0)
@@ -157,30 +157,30 @@ files_read_etc_files(myapp_t) # SELinux provides a policy devel environment under /usr/share/selinux/devel # You can create a te file and compile it by executing -$ make -f /usr/share/selinux/devel/Makefile -$ semodule -i local.pp +$ make \-f /usr/share/selinux/devel/Makefile +$ semodule \-i local.pp .B Building module policy manually # Compile the module -$ checkmodule -M -m -o local.mod local.te +$ checkmodule \-M \-m \-o local.mod local.te # Create the package -$ semodule_package -o local.pp -m local.mod +$ semodule_package \-o local.pp \-m local.mod # Load the module into the kernel -$ semodule -i local.pp +$ semodule \-i local.pp .B Using audit2allow to generate and build module policy -$ cat /var/log/audit/audit.log | audit2allow -M local +$ cat /var/log/audit/audit.log | audit2allow \-M local Generating type enforcment file: local.te -Compiling policy: checkmodule -M -m -o local.mod local.te -Building package: semodule_package -o local.pp -m local.mod +Compiling policy: checkmodule \-M \-m \-o local.mod local.te +Building package: semodule_package \-o local.pp \-m local.mod ******************** IMPORTANT *********************** In order to load this newly created policy package into the kernel, you are required to execute -semodule -i local.pp +semodule \-i local.pp .B Using audit2allow to generate monolithic (non-module) policy $ cd /etc/selinux/$SELINUXTYPE/src/policy
policycoreutils/man/man5/selinux_config.5 +1 -1
@@ -122,7 +122,7 @@ This is an optional entry that allows the file system to be relabeled. .sp If set to \fI0\fR and there is a file called \fI.autorelabel\fR in the root directory, then on a reboot, the loader will drop to a shell where a root login is required. An administrator can then manually relabel the file system. .sp -If set to \fI1\fR or no entry present (the default) and there is a \fI.autorelabel\fR file in the root directory, then the file system will be automatically relabeled using \fBfixfiles -F restore\fR +If set to \fI1\fR or no entry present (the default) and there is a \fI.autorelabel\fR file in the root directory, then the file system will be automatically relabeled using \fBfixfiles \-F restore\fR .sp In both cases the \fI/.autorelabel\fR file will be removed so that relabeling is not done again. .RE
policycoreutils/mcstrans/man/man8/mcs.8 +1 -1
@@ -20,7 +20,7 @@ readable form. Administrators can define any labels they want in this file. Certain applications like printing and auditing will use these labels to identify the files. By setting a category on a file you will prevent other applications/services from having access to the files. -.p +.P Examples of file labels would be PatientRecord, CompanyConfidential etc. .SH "SEE ALSO"
policycoreutils/newrole/newrole.1 +12 -12
@@ -44,7 +44,7 @@ Additional arguments .I ARGS may be provided after a -- option, in which case they are supplied to the new shell. -In particular, an argument of -- -c will cause the next argument to be +In particular, an argument of \-\- \-c will cause the next argument to be treated as a command by most command interpreters. .PP If a command argument is specified to newrole and the command name is found
@@ -66,31 +66,31 @@ shows the current version of newrole .SH EXAMPLE .br Changing role: - # id -Z + # id \-Z staff_u:staff_r:staff_t:SystemLow-SystemHigh - # newrole -r sysadm_r - # id -Z + # newrole \-r sysadm_r + # id \-Z staff_u:sysadm_r:sysadm_t:SystemLow-SystemHigh Changing sensitivity only: - # id -Z + # id \-Z staff_u:sysadm_r:sysadm_t:Unclassified-SystemHigh - # newrole -l Secret - # id -Z + # newrole \-l Secret + # id \-Z staff_u:sysadm_r:sysadm_t:Secret-SystemHigh .PP Changing sensitivity and clearance: - # id -Z + # id \-Z staff_u:sysadm_r:sysadm_t:Unclassified-SystemHigh - # newrole -l Secret-Secret - # id -Z + # newrole \-l Secret-Secret + # id \-Z staff_u:sysadm_r:sysadm_t:Secret .PP Running a program in a given role or level: - # newrole -r sysadm_r -- -c "/path/to/app arg1 arg2..." - # newrole -l Secret -- -c "/path/to/app arg1 arg2..." + # newrole \-r sysadm_r \-\- \-c "/path/to/app arg1 arg2..." + # newrole \-l Secret \-\- \-c "/path/to/app arg1 arg2..." .SH FILES /etc/passwd - user account information
policycoreutils/scripts/chcat.8 +2 -2
@@ -21,7 +21,7 @@ chcat \- change file SELinux security category [\fI-d\fR] \fIuser\fR... .br .B chcat -\fI-L\fR [ -l ] [ user ... ] +\fI-L\fR [ \-l ] [ user ... ] .br .SH DESCRIPTION .PP
@@ -31,7 +31,7 @@ Use +/- to add/remove categories from a \fIfile\fR or \fIuser\fR. .PP .B Note: -When removing a category you must specify '--' on the command line before using the -Category syntax. This tells the command that you have finished entering options and are now specifying a category name instead. +When removing a category you must specify '\-\-' on the command line before using the \-Category syntax. This tells the command that you have finished entering options and are now specifying a category name instead. .TP \fB\-d\fR
policycoreutils/scripts/fixfiles.8 +11 -11
@@ -5,13 +5,13 @@ fixfiles \- fix file SELinux security contexts. .SH "SYNOPSIS" .B fixfiles -.I [-F] [-l logfile ] { check | restore|[-f] relabel | verify } [[dir/file] ... ] +.I [\-F] [\-l logfile ] { check | restore|[\-f] relabel | verify } [[dir/file] ... ] .B fixfiles -.I [-F] [ -R rpmpackagename[,rpmpackagename...] ] [-l logfile ] { check | restore | verify } +.I [\-F] [ \-R rpmpackagename[,rpmpackagename...] ] [\-l logfile ] { check | restore | verify } .B fixfiles -.I [ -C PREVIOUS_FILECONTEXT ] [-l logfile ] { check | restore | verify } +.I [ \-C PREVIOUS_FILECONTEXT ] [\-l logfile ] { check | restore | verify } .B fixfiles .I onboot
@@ -28,7 +28,7 @@ It can also be run at any time to relabel when adding support for new policy, or just check whether the file contexts are all as you expect. By default it will relabel all mounted ext2, ext3, xfs and jfs file systems as long as they do not have a security context mount -option. You can use the -R flag to use rpmpackages as an alternative. +option. You can use the \-R flag to use rpmpackages as an alternative. The file /etc/selinux/fixfiles_exclude_dirs can contain a list of directories excluded from relabelling. .P
@@ -37,21 +37,21 @@ will setup the machine to relabel on the next reboot. .SH "OPTIONS" .TP -.B -l logfile +.B \-l logfile Save the output to the specified logfile .TP -.B -F -Force reset of context to match file_context for customizable files +.B \-F +Force reset of context to match file_context for customizable files .TP -.B -f +.B \-f Clear /tmp directory with out prompt for removal. .TP -.B -R rpmpackagename[,rpmpackagename...] -Use the rpm database to discover all files within the specified packages and restore the file contexts. (-a will get all files in the RPM database). +.B \-R rpmpackagename[,rpmpackagename...] +Use the rpm database to discover all files within the specified packages and restore the file contexts. (\-a will get all files in the RPM database). .TP -.B -C PREVIOUS_FILECONTEXT +.B \-C PREVIOUS_FILECONTEXT Run a diff on the PREVIOUS_FILECONTEXT file to the currently installed one, and restore the context of all affected files. .SH "ARGUMENTS"
policycoreutils/scripts/genhomedircon.8 +1 -1
@@ -1,4 +1,4 @@ -.TH GENHOMEDIRCON "12" "Sep 2011" "Security Enhanced Linux" "SELinux" +.TH GENHOMEDIRCON "8" "Sep 2011" "Security Enhanced Linux" "SELinux" .SH NAME genhomedircon \- generate SELinux file context configuration entries for user home directories .SH SYNOPSIS
policycoreutils/semanage/semanage.8 +24 -24
125 lines not on this page · raw message
policycoreutils/semodule/semodule.8 +8 -8
@@ -21,7 +21,7 @@ by semodule_package. Conventionally, these files have a .pp suffix force a reload of policy .TP .B \-B, \-\-build -force a rebuild of policy (also reloads unless -n is used) +force a rebuild of policy (also reloads unless \-n is used) .TP .B \-D, \-\-disable_dontaudit Temporarily remove dontaudits from policy. Reverts whenever policy is rebuilt
@@ -65,19 +65,19 @@ be verbose .SH EXAMPLE .nf # Install or replace a base policy package. -$ semodule -b base.pp +$ semodule \-b base.pp # Install or replace a non-base policy package. -$ semodule -i httpd.pp +$ semodule \-i httpd.pp # List non-base modules. -$ semodule -l +$ semodule \-l # Turn on all AVC Messages for which SELinux currently is "dontaudit"ing. -$ semodule -DB +$ semodule \-DB # Turn "dontaudit" rules back on. -$ semodule -B +$ semodule \-B # Install or replace all non-base modules in the current directory. -$ semodule -i *.pp +$ semodule \-i *.pp # Install or replace all modules in the current directory. -$ ls *.pp | grep -Ev "base.pp|enableaudit.pp" | xargs /usr/sbin/semodule -b base.pp -i +$ ls *.pp | grep \-Ev "base.pp|enableaudit.pp" | xargs /usr/sbin/semodule \-b base.pp \-i .fi .SH SEE ALSO
policycoreutils/semodule_deps/semodule_deps.8 +3 -3
@@ -3,7 +3,7 @@ semodule_deps \- show the dependencies between SELinux policy packages. .SH SYNOPSIS -.B semodule_deps [-v -g -b] basemodpkg modpkg1 [modpkg2 ... ] +.B semodule_deps [\-v \-g \-b] basemodpkg modpkg1 [modpkg2 ... ] .br .SH DESCRIPTION .PP
@@ -19,12 +19,12 @@ general this means that the list of modules will usually be quite long. By default options to the base module are excluded as almost every -module has this dependency. The -b option will include these +module has this dependency. The \-b option will include these dependencies. In addition to human readable output, semodule_deps can output the dependencies in the Graphviz dot format (http://www.graphviz.org/) -using the -g option. This is useful for producing a picture of the +using the \-g option. This is useful for producing a picture of the dependencies. .SH "OPTIONS"
policycoreutils/semodule_package/semodule_package.8 +4 -4
@@ -3,7 +3,7 @@ semodule_package \- Create a SELinux policy module package. .SH SYNOPSIS -.B semodule_package -o <output file> -m <module> [-f <file contexts>] +.B semodule_package \-o <output file> \-m <module> [\-f <file contexts>] .br .SH DESCRIPTION .PP
@@ -16,11 +16,11 @@ be installed via semodule. .SH EXAMPLE .nf # Build a policy package for a base module. -$ semodule_package -o base.pp -m base.mod -f file_contexts +$ semodule_package \-o base.pp \-m base.mod \-f file_contexts # Build a policy package for a httpd module. -$ semodule_package -o httpd.pp -m httpd.mod -f httpd.fc +$ semodule_package \-o httpd.pp \-m httpd.mod \-f httpd.fc # Build a policy package for local TE rules and no file contexts. -$ semodule_package -o local.pp -m local.mod +$ semodule_package \-o local.pp \-m local.mod .fi .SH "OPTIONS"
policycoreutils/sestatus/sestatus.conf.5 +1 -1
@@ -49,7 +49,7 @@ The start of the file list block. .RE .I file_name .RS -One or more fully qualified file names, each on a new line will that will have its context displayed. If the file does not exist, then it is ignored. If the file is a symbolic link, then \fBsestatus -v\fR will also display the target file context. +One or more fully qualified file names, each on a new line will that will have its context displayed. If the file does not exist, then it is ignored. If the file is a symbolic link, then \fBsestatus \-v\fR will also display the target file context. .RE .sp .B [process]
policycoreutils/setfiles/restorecon.8 +4 -0
@@ -26,6 +26,10 @@ If a file object does not have a context, restorecon will write the default context to the file object's extended attributes. If a file object has a context, restorecon will only modify the type portion of the security context. The -F option will force a replacement of the entire context. +.P +It is the same executable as +.BR setfiles +but operates in a slightly different manner depending on it's argv[0]. .SH "OPTIONS" .TP
policycoreutils/setfiles/setfiles.8 +2 -2
@@ -4,7 +4,7 @@ setfiles \- set SELinux file security contexts. .SH "SYNOPSIS" .B setfiles -.I [\-c policy] [\-d] [\-l] [\-n] [\-e directory] [\-o filename] [\-q] [\-s] [\-v] [\-W] [\-F] spec_file pathname... +.I [\-c policy] [\-d] [\-l] [\-n] [\-e directory] [\-o filename] [\-p] [\-q] [\-s] [\-v] [\-W] [\-F] spec_file pathname... .SH "DESCRIPTION" This manual page describes the .BR setfiles
@@ -23,7 +23,7 @@ check whether the file contexts are all set as specified by the active policy If a file object does not have a context, setfiles will write the default context to the file object's extended attributes. If a file object has a context, setfiles will only modify the type portion of the security context. -The -F option will force a replacement of the entire context. +The \-F option will force a replacement of the entire context. .SH "OPTIONS" .TP .B \-c
policycoreutils/setsebool/setsebool.8 +4 -4
@@ -4,21 +4,21 @@ setsebool \- set SELinux boolean value .SH "SYNOPSIS" .B setsebool -.I "[ -PN ] boolean value | bool1=val1 bool2=val2 ..." +.I "[ \-PN ] boolean value | bool1=val1 bool2=val2 ..." .SH "DESCRIPTION" .B setsebool sets the current state of a particular SELinux boolean or a list of booleans to a given value. The value may be 1 or true or on to enable the boolean, or 0 or false or off to disable it. -Without the -P option, only the current boolean value is +Without the \-P option, only the current boolean value is affected; the boot-time default settings are not changed. -If the -P option is given, all pending values are written to +If the \-P option is given, all pending values are written to the policy file on disk. So they will be persistent across reboots. -If the -N option is given, the policy on disk is not reloaded into the kernel. +If the \-N option is given, the policy on disk is not reloaded into the kernel. .SH AUTHOR
Signature · 7 lines
1.7.10.4 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 10/15 libselinux: Fix various minor manpage issues and correct section numbering.
In reply to Laurent BigonvilleFrom: Laurent Bigonville <[email protected]>
--- libselinux/man/man3/security_disable.3 | 4 ++-- libselinux/man/man3/security_load_policy.3 | 4 ++-- libselinux/man/man8/getenforce.8 | 2 +- libselinux/man/man8/selinuxenabled.8 | 2 +- libselinux/man/man8/selinuxexeccon.8 | 2 +- libselinux/man/man8/setenforce.8 | 2 +- libselinux/man/man8/togglesebool.8 | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-)
libselinux/man/man3/security_disable.3 +2 -2
@@ -15,7 +15,7 @@ and then unmounts /selinux. 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). +.B security_setenforce(3). .SH "RETURN VALUE" .B security_disable
@@ -25,4 +25,4 @@ returns zero on success or \-1 on error. This manual page has been written by Guido Trentalancia <[email protected]> .SH "SEE ALSO" -.BR selinux (8), " setenforce "(3) +.BR selinux (8), " setenforce "(8)
libselinux/man/man3/security_load_policy.3 +2 -2
@@ -43,7 +43,7 @@ unmounted using a call to .B security_disable(3). Therefore, after the initial policy load, the only operational changes are those permitted by -.B setenforce(3) +.B security_setenforce(3) (i.e. eventually setting the framework in permissive mode rather than in enforcing one).
@@ -54,5 +54,5 @@ returns zero on success or \-1 on error. This manual page has been written by Guido Trentalancia <[email protected]> .SH "SEE ALSO" -.BR selinux "(8), " security_disable "(3), " setenforce "(1) +.BR selinux "(8), " security_disable "(3), " setenforce "(8)
libselinux/man/man8/getenforce.8 +1 -1
@@ -1,4 +1,4 @@ -.TH "getenforce" "1" "7 April 2004" "[email protected]" "SELinux Command Line documentation" +.TH "getenforce" "8" "7 April 2004" "[email protected]" "SELinux Command Line documentation" .SH "NAME" getenforce \- get the current mode of SELinux .SH "SYNOPSIS"
libselinux/man/man8/selinuxenabled.8 +1 -1
@@ -1,4 +1,4 @@ -.TH "selinuxenabled" "1" "7 April 2004" "[email protected]" "SELinux Command Line documentation" +.TH "selinuxenabled" "8" "7 April 2004" "[email protected]" "SELinux Command Line documentation" .SH "NAME" selinuxenabled \- tool to be used within shell scripts to determine if selinux is enabled .SH "SYNOPSIS"
libselinux/man/man8/selinuxexeccon.8 +1 -1
@@ -1,4 +1,4 @@ -.TH "selinuxexeccon" "1" "14 May 2011" "[email protected]" "SELinux Command Line documentation" +.TH "selinuxexeccon" "8" "14 May 2011" "[email protected]" "SELinux Command Line documentation" .SH "NAME" selinuxexeccon \- report SELinux context used for this executable
libselinux/man/man8/setenforce.8 +1 -1
@@ -1,4 +1,4 @@ -.TH "setenforce" "1" "7 April 2004" "[email protected]" "SELinux Command Line documentation" +.TH "setenforce" "8" "7 April 2004" "[email protected]" "SELinux Command Line documentation" .SH "NAME" setenforce \- modify the mode SELinux is running in. .SH "SYNOPSIS"
libselinux/man/man8/togglesebool.8 +1 -1
@@ -1,4 +1,4 @@ -.TH "togglesebool" "1" "26 Oct 2004" "[email protected]" "SELinux Command Line documentation" +.TH "togglesebool" "8" "26 Oct 2004" "[email protected]" "SELinux Command Line documentation" .SH "NAME" togglesebool \- flip the current value of a SELinux boolean .SH "SYNOPSIS"
Signature · 7 lines
1.7.10.4 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
PATCH 13/15 libsemanage: Fix cases where hyphen were used as minus sign in manpages
In reply to Laurent BigonvilleFrom: Laurent Bigonville <[email protected]>
--- libsemanage/man/man3/semanage_bool_set_active.3 | 2 +- libsemanage/man/man3/semanage_count.3 | 2 +- libsemanage/man/man3/semanage_del.3 | 2 +- libsemanage/man/man3/semanage_exists.3 | 2 +- libsemanage/man/man3/semanage_iterate.3 | 4 ++-- libsemanage/man/man3/semanage_list.3 | 2 +- libsemanage/man/man3/semanage_modify.3 | 2 +- libsemanage/man/man3/semanage_query.3 | 2 +- libsemanage/man/man3/semanage_set_root.3 | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-)
libsemanage/man/man3/semanage_bool_set_active.3 +1 -1
@@ -40,7 +40,7 @@ This function requires an semanage connection to be established (see ). .SH "RETURN VALUE" -In case of failure, -1 is returned, and the semanage error callback is invoked, describing the error. +In case of failure, \-1 is returned, and the semanage error callback is invoked, describing the error. Otherwise 0 is returned. .SH "SEE ALSO"
libsemanage/man/man3/semanage_count.3 +1 -1
@@ -33,7 +33,7 @@ This function requires an semanage connection to be established (see ) .SH "RETURN VALUE" -In case of failure, -1 is returned, and the semanage error callback is invoked, describing the error. +In case of failure, \-1 is returned, and the semanage error callback is invoked, describing the error. Otherwise a non-negative integer is returned (a commit number). The same number will be returned by all other semanage object read calls until the next commit. .SH "SEE ALSO"
libsemanage/man/man3/semanage_del.3 +1 -1
@@ -40,7 +40,7 @@ This function requires an semanage connection to be established (see ). .SH "RETURN VALUE" -In case of failure, -1 is returned, and the semanage error callback is invoked, describing the error. +In case of failure, \-1 is returned, and the semanage error callback is invoked, describing the error. Otherwise 0 is returned. .SH "SEE ALSO"
libsemanage/man/man3/semanage_exists.3 +1 -1
@@ -38,7 +38,7 @@ This function requires an semanage connection to be established (see ) .SH "RETURN VALUE" -In case of failure, -1 is returned, and the semanage error callback is invoked, describing the error. +In case of failure, \-1 is returned, and the semanage error callback is invoked, describing the error. Otherwise a non-negative integer is returned (a commit number). The same number will be returned by all other read calls to the semanage database until the next commit. .SH "SEE ALSO"
libsemanage/man/man3/semanage_iterate.3 +2 -2
@@ -31,7 +31,7 @@ if that is necessary. The handler code may not invoke any semanage write requests for the same object type (i.e. modifying the underlying store is not allowed). The iterate function is reentrant only while inside a transaction (see .B semanage_begin_transaction -). It is not safe to execute other semanage read or write requests within iterate if not inside a transaction. The handler may return -1 to signal error exit, 0 to signal continue, and 1 to signal successful exit early (the iterate function will stop accordingly). +). It is not safe to execute other semanage read or write requests within iterate if not inside a transaction. The handler may return \-1 to signal error exit, 0 to signal continue, and 1 to signal successful exit early (the iterate function will stop accordingly). .TP .B Parameters:
@@ -50,7 +50,7 @@ This function requires an semanage connection to be established (see ) .SH "RETURN VALUE" -In case of failure, -1 is returned, and the semanage error callback is invoked, describing the error. +In case of failure, \-1 is returned, and the semanage error callback is invoked, describing the error. Otherwise a non-negative integer is returned (a commit number). The same number will be returned by all other semanage object read calls until the next commit. .SH "SEE ALSO"
libsemanage/man/man3/semanage_list.3 +1 -1
@@ -39,7 +39,7 @@ This function requires an semanage connection to be established (see ) .SH "RETURN VALUE" -In case of failure, -1 is returned, and the semanage error callback is invoked, describing the error. +In case of failure, \-1 is returned, and the semanage error callback is invoked, describing the error. Otherwise a non-negative integer is returned (a commit number). The same number will be returned by all other semanage object read calls until the next commit. .SH "SEE ALSO"
libsemanage/man/man3/semanage_modify.3 +1 -1
@@ -42,7 +42,7 @@ This function requires an semanage connection to be established (see ). .SH "RETURN VALUE" -In case of failure, -1 is returned, and the semanage error callback is invoked, describing the error. +In case of failure, \-1 is returned, and the semanage error callback is invoked, describing the error. Otherwise 0 is returned. .SH "SEE ALSO"
libsemanage/man/man3/semanage_query.3 +1 -1
@@ -39,7 +39,7 @@ This function requires an semanage connection to be established (see ) .SH "RETURN VALUE" -In case of failure, -1 is returned, and the semanage error callback is invoked, describing the error. +In case of failure, \-1 is returned, and the semanage error callback is invoked, describing the error. Otherwise a non-negative integer is returned (a commit number). The same number will be returned by all other semanage object read calls until the next commit. .SH "SEE ALSO"
libsemanage/man/man3/semanage_set_root.3 +1 -1
@@ -15,7 +15,7 @@ Set the alternate root directory for SELinux configuration directory. This function sets an alternate root directory to for SELinux configuration paths to be used by the semanage library. .SH "RETURN VALUE" -In case of failure, -1 is returned. +In case of failure, \-1 is returned. Otherwise 0 is returned. .SH "SEE ALSO"
Signature · 7 lines
1.7.10.4 -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [PATCH 04/15] policycoreutils: Add new open_init_pty that doesn't waste CPU time
In reply to Laurent BigonvilleI applied all of these to my devel tree except this one. It's huge and I don't know why we need it, or want it, or want C++ or whatever...
-Eric
Quoted 876 lines · Laurent Bigonville
From: Russell Coker <[email protected]>
--- policycoreutils/run_init/Makefile | 7 +- policycoreutils/run_init/open_init_pty.c | 399 -------------------------- policycoreutils/run_init/open_init_pty.cpp | 423 ++++++++++++++++++++++++++++ 3 files changed, 427 insertions(+), 402 deletions(-) delete mode 100644 policycoreutils/run_init/open_init_pty.c create mode 100644 policycoreutils/run_init/open_init_pty.cpppolicycoreutils/run_init/Makefile +4
-3@@ -10,6 +10,7 @@ AUDITH = $(shell ls /usr/include/libaudit.h 2>/dev/null) CFLAGS ?= -Werror -Wall -W override CFLAGS += -I$(PREFIX)/include -DUSE_NLS -DLOCALEDIR="\"$(LOCALEDIR)\"" -DPACKAGE="\"policycoreutils\"" +CPPFLAGS ?= $(CFLAGS) LDLIBS += -lselinux -L$(PREFIX)/lib ifeq ($(PAMH), /usr/include/security/pam_appl.h) override CFLAGS += -DUSE_PAM@@ -23,12 +24,12 @@ ifeq ($(AUDITH), /usr/include/libaudit.h) LDLIBS += -laudit endif -TARGETS=$(patsubst %.c,%,$(wildcard *.c)) +TARGETS=open_init_pty run_init all: $(TARGETS) -open_init_pty: open_init_pty.c - $(LINK.c) $^ -ldl -lutil -o $@ +open_init_pty: open_init_pty.cpp + $(LINK.cpp) $^ -ldl -lutil -o $@ install: allpolicycoreutils/run_init/open_init_pty.c deleted +0
-399@@ -1,399 +0,0 @@ -/* -*- Mode: C -*- -* open_init_pty.c --- -* Author : Manoj Srivastava ( [email protected] ) -* Created On : Fri Jan 14 10:48:28 2005 -* Created On Node : glaurung.internal.golden-gryphon.com -* Last Modified By : Manoj Srivastava -* Last Modified On : Thu Sep 15 00:57:00 2005 -* Last Machine Used: glaurung.internal.golden-gryphon.com -* Update Count : 92 -* Status : Unknown, Use with caution! -* HISTORY : -* Description : -* -* Distributed under the terms of the GNU General Public License v2 -* -* open_init_pty -* -* SYNOPSIS: -* -* This program allows a systems administrator to execute daemons -* which need to work in the initrc domain, and which need to have -* pty's as system_u:system_r:initrc_t -* -* USAGE: -* -* * arch-tag: a5583d39-72b9-4cdf-ba1b-5678ea4cbe20 -*/ - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <signal.h> -#include <errno.h> - -#include <sysexits.h> - -#include <pty.h> /* for openpty and forkpty */ -#include <utmp.h> /* for login_tty */ -#include <termios.h> -#include <fcntl.h> - -#include <sys/select.h> - -static struct termios saved_termios; -static int saved_fd =-1 ; -static enum {RESET ,RAW ,CBREAK } tty_state =RESET ; - -static int tty_semi_raw (int fd) -{ -struct termios buf; - -if (tty_state ==RESET ) { -if (tcgetattr (fd, &saved_termios) <0 ) { -return -1 ; - } - } - - buf = saved_termios; -/* -* echo off, canonical mode off, extended input processing off, -* signal chars off -*/ - buf.c_lflag &= ~(ECHO |ICANON |IEXTEN |ISIG ); -/* -* no SIGINT on break, CR-to-NL off, input parity check off, do not -* strip 8th bit on input,output flow control off -*/ - buf.c_iflag &= ~(BRKINT |ICRNL |INPCK |ISTRIP |IXON ); -/* Clear size bits, parity checking off */ - buf.c_cflag &= ~(CSIZE |PARENB ); -/* set 8 bits/char */ - buf.c_cflag |=CS8 ; -/* Output processing off -buf.c_oflag &= ~(OPOST); */ - - buf.c_cc[VMIN ] =1 ;/* one byte at a time, no timer */ - buf.c_cc[VTIME ] =0 ; -if (tcsetattr (fd,TCSANOW , &buf) <0 ) { -return -1 ; - }/* end of if(tcsetattr(fileno(stdin), TCSANOW, &buf) < 0) */ - tty_state =RAW ; - saved_fd = fd; -return 0 ; -} - -void tty_atexit (void ) -{ -if (tty_state !=CBREAK && tty_state !=RAW ) { -return ; - } - -if (tcsetattr (saved_fd,TCSANOW , &saved_termios) <0 ) { -return ; - }/* end of if(tcsetattr(fileno(stdin), TCSANOW, &buf) < 0) */ - tty_state =RESET ; -return ; -} - -int main (int argc,char *argv[]) -{ -pid_t child_pid; -struct termios tty_attr; -struct winsize window_size; -int pty_master; -int retval =0 ; - -/* for select */ -fd_set readfds; -fd_set writefds; -fd_set exceptfds; - -int err_count =0 ; - -/* for sigtimedwait() */ -struct timespec timeout; -char buf[16384 ]; - -if (argc ==1 ) { -printf ("usage: %s PROGRAM [ARGS]...\n" , argv[0 ]); -exit (1 ); - } - -sigset_t signal_set; -siginfo_t signalinfo; - -/* set up SIGCHLD */ -sigemptyset (&signal_set);/* no signals */ -sigaddset (&signal_set,SIGCHLD );/* Add sig child */ -sigprocmask (SIG_BLOCK , &signal_set,NULL );/* Block the signal */ - -/* Set both to 0, so sigtimed wait just does a poll */ - timeout.tv_sec =0 ; - timeout.tv_nsec =0 ; - -if (isatty (fileno (stdin))) { -/* get terminal parameters associated with stdout */ -if (tcgetattr (fileno (stdout), &tty_attr) <0 ) { -perror ("tcgetattr:" ); -exit (EX_OSERR ); - } - -/* end of if(tcsetattr(&tty_attr)) */ -/* get window size */ -if (ioctl (fileno (stdout),TIOCGWINSZ , &window_size) <0 ) { -perror ("ioctl stdout:" ); -exit (1 ); - } - - child_pid =forkpty (&pty_master,NULL , &tty_attr, &window_size); - }/* end of if(isatty(fileno(stdin))) */ -else {/* not interactive */ - child_pid =forkpty (&pty_master,NULL ,NULL ,NULL ); - } - -if (child_pid <0 ) { -perror ("forkpty():" ); -fflush (stdout); -fflush (stderr); -exit (EX_OSERR ); - }/* end of if(child_pid < 0) */ -if (child_pid ==0 ) { -/* in the child */ -struct termios s_tty_attr; -if (tcgetattr (fileno (stdin), &s_tty_attr)) { -perror ("Child:" ); -fflush (stdout); -fflush (stderr); -exit (EXIT_FAILURE ); - } -/* Turn off echo */ - s_tty_attr.c_lflag &= ~(ECHO |ECHOE |ECHOK |ECHONL ); -/* Also turn of NL to CR?LF on output */ - s_tty_attr.c_oflag &= ~(ONLCR ); -if (tcsetattr (fileno (stdin),TCSANOW , &s_tty_attr)) { -perror ("Child:" ); -exit (EXIT_FAILURE ); - } - {/* There is no reason to block sigchild for the process we -shall exec here */ -sigset_t chld_signal_set; -/* release SIGCHLD */ -sigemptyset (&chld_signal_set);/* no signals */ -sigaddset (&chld_signal_set,SIGCHLD );/* Add sig child */ -sigprocmask (SIG_UNBLOCK , &chld_signal_set,NULL );/* Unblock the signal */ - } - -if (execvp (argv[1 ], argv +1 )) { -perror ("Exec:" ); -fflush (stdout); -fflush (stderr); -exit (EXIT_FAILURE ); - } - } - -/* end of if(child_pid == 0) */ -/* -* OK. Prepare to handle IO from the child. We need to transfer -* everything from the child's stdout to ours. -*/ -FD_ZERO (&readfds); -FD_ZERO (&writefds); -FD_ZERO (&exceptfds); - -/* -* Read current file descriptor flags, preparing to do non blocking reads -*/ - retval =fcntl (pty_master,F_GETFL ); -if (retval <0 ) { -perror ("fcntl_get" ); -fflush (stdout); -fflush (stderr); -exit (EX_IOERR ); - } - -/* Set the connection to be non-blocking */ -if (fcntl (pty_master,F_SETFL , retval |O_NONBLOCK ) <0 ) { -perror ("fcnt_setFlag_nonblock:" ); -fflush (stdout); -fflush (stderr); -exit (1 ); - } - -FD_SET (pty_master, &readfds); -FD_SET (pty_master, &writefds); -FD_SET (fileno (stdin), &readfds); -if (isatty (fileno (stdin))) { -if (tty_semi_raw (fileno (stdin)) <0 ) { -perror ("Error: settingraw mode:" ); -fflush (stdout); -fflush (stderr); - }/* end of if(tty_raw(fileno(stdin)) < 0) */ -if (atexit (tty_atexit) <0 ) { -perror ("Atexit setup:" ); -fflush (stdout); -fflush (stderr); - }/* end of if(atexit(tty_atexit) < 0) */ - } - -/* ignore return from nice, but lower our priority */ - int ignore __attribute__ ((unused)) = nice(19); - -/* while no signal, we loop around */ - int done = 0; -while (!done) { -struct timeval interval; -fd_set t_readfds; -fd_set t_writefds; -fd_set t_exceptfds; -/* -* We still use a blocked signal, and check for SIGCHLD every -* loop, since waiting infinitely did not really help the load -* when running, say, top. -*/ - interval.tv_sec =0 ; - interval.tv_usec =200000 ;/* so, check for signals every 200 milli -seconds */ - - t_readfds = readfds; - t_writefds = writefds; - t_exceptfds = exceptfds; - -/* check for the signal */ - retval =sigtimedwait (&signal_set, &signalinfo, &timeout); - -if (retval ==SIGCHLD ) { -/* child terminated */ - done =1 ;/* in case they do not close off their -file descriptors */ - }else { -if (retval <0 ) { -if (errno !=EAGAIN ) { -perror ("sigtimedwait" ); -fflush (stdout); -fflush (stderr); -exit (EX_IOERR ); - }else { -/* No signal in set was delivered within the timeout period specified */ - } - } - }/* end of else */ - -if (select - (pty_master +1 , &t_readfds, &t_writefds, &t_exceptfds, - &interval) <0 ) { -perror ("Select:" ); -fflush (stdout); -fflush (stderr); -exit (EX_IOERR ); - } - -if (FD_ISSET (pty_master, &t_readfds)) { - retval =read (pty_master, buf, (unsigned int )16384 ); -if (retval <0 ) { -if (errno !=EINTR && errno !=EAGAIN ) {/* Nothing left to read? */ -fflush (stdout); -fflush (stderr); -/* fprintf(stderr, "DEBUG: %d: Nothing left to read?\n", __LINE__); */ -exit (EXIT_SUCCESS ); - }/* end of else */ - }/* end of if(retval < 0) */ -else { -if (retval ==0 ) { -if (++err_count >5 ) {/* child closed connection */ -fflush (stdout); -fflush (stderr); -/*fprintf(stderr, "DEBUG: %d: child closed connection?\n", __LINE__); */ -exit (EXIT_SUCCESS ); - } - }/* end of if(retval == 0) */ -else { -ssize_t nleft = retval; -ssize_t nwritten =0 ; -char *ptr = buf; -while (nleft >0 ) { -if ((nwritten = -write (fileno (stdout), ptr, - (unsigned int )nleft)) - <=0 ) { -if (errno ==EINTR ) { - nwritten =0 ; - }/* end of if(errno == EINTR) */ -else { -perror ("write" ); -fflush (stdout); -fflush (stderr); -exit (EXIT_SUCCESS ); - }/* end of else */ - }/* end of if((nwritten = write(sockfd, ptr, nleft)) <= 0) */ - nleft -= nwritten; - ptr += nwritten; - }/* end of while(nleft > 0) */ - -/* fprintf(stderr, "DEBUG: %d: wrote %d\n", __LINE__, retval); */ -fflush (stdout); - }/* end of else */ - }/* end of else */ - } -if (FD_ISSET (fileno (stdin), &t_readfds)) { -if (FD_ISSET (pty_master, &t_writefds)) { - retval = -read (fileno (stdin), buf, - (unsigned int )16384 ); -if (retval <0 ) { -if (errno !=EINTR && errno !=EAGAIN ) {/* Nothing left to read? */ -fflush (stdout); -fflush (stderr); -exit (EXIT_SUCCESS ); - }/* end of else */ - }/* end of if(retval < 0) */ -else { -if (retval ==0 ) { -if (++err_count >5 ) {/* lost controlling tty */ -fflush (stdout); -fflush (stderr); -exit (EXIT_SUCCESS ); - } - }/* end of if(retval == 0) */ -else { -ssize_t nleft = retval; -ssize_t nwritten =0 ; -char *ptr = buf; -while (nleft >0 ) { -if ((nwritten = -write (pty_master, - ptr, - (unsigned -int )nleft)) - <=0 ) { -if (errno == -EINTR ) { - nwritten - =0 ; - }/* end of if(errno == EINTR) */ -else { -perror - ("write" ); -fflush - (stdout); -fflush - (stderr); -exit (EXIT_SUCCESS ); - }/* end of else */ - }/* end of if((nwritten = write(sockfd, ptr, nleft)) <= 0) */ - nleft -= nwritten; - ptr += nwritten; - }/* end of while(nleft > 0) */ - -fflush (stdout); - }/* end of else */ - }/* end of else */ - }/* end of if(FD_ISSET(pty_master, &writefds)) */ - }/* something to read on stdin */ - }/* Loop */ - -fflush (stdout); -fflush (stderr); - -exit (EXIT_SUCCESS ); -}/* end of main() */ policycoreutils/run_init/open_init_pty.cpp new file +423
-1@@ -0,0 +1,423 @@ +/* -*- Mode: C -*- + * open_init_pty.c --- + * Author : Manoj Srivastava ( [email protected] ) + * Created On : Fri Jan 14 10:48:28 2005 + * Created On Node : glaurung.internal.golden-gryphon.com + * Last Modified By : Manoj Srivastava + * Last Modified On : Thu Sep 15 00:57:00 2005 + * Last Machine Used: glaurung.internal.golden-gryphon.com + * Update Count : 92 + * Status : Unknown, Use with caution! + * HISTORY : + * Description : + * + * Distributed under the terms of the GNU General Public License v2 + * + * open_init_pty + * + * SYNOPSIS: + * + * This program allows a systems administrator to execute daemons + * which need to work in the initrc domain, and which need to have + * pty's as system_u:system_r:initrc_t + * + * USAGE: + * + * * arch-tag: a5583d39-72b9-4cdf-ba1b-5678ea4cbe20 + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <signal.h> +#include <errno.h> + +#include <sysexits.h> + +#include <pty.h> /* for openpty and forkpty */ +#include <utmp.h> /* for login_tty */ +#include <termios.h> +#include <fcntl.h> + +#include <sys/select.h> +#include <sys/wait.h> + + +#define MAXRETR 3 /* The max number of IO retries on a fd */ +#define BUFSIZE 2048 /* The ring buffer size */ + +static struct termios saved_termios; +static int saved_fd = -1; +static enum { RESET, RAW, CBREAK } tty_state = RESET; + +static int tty_semi_raw(int fd) +{ + struct termios buf; + + if (tty_state == RESET) { + if (tcgetattr(fd, &saved_termios) < 0) { + return -1; + } + } + + buf = saved_termios; + /* + * echo off, canonical mode off, extended input processing off, + * signal chars off + */ + buf.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG); + /* + * no SIGINT on break, CR-to-NL off, input parity check off, do not + * strip 8th bit on input,output flow control off + */ + buf.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON); + /* Clear size bits, parity checking off */ + buf.c_cflag &= ~(CSIZE | PARENB); + /* set 8 bits/char */ + buf.c_cflag |= CS8; + /* Output processing off + buf.c_oflag &= ~(OPOST); */ + + buf.c_cc[VMIN] = 1; /* one byte at a time, no timer */ + buf.c_cc[VTIME] = 0; + if (tcsetattr(fd, TCSANOW, &buf) < 0) { + return -1; + } + tty_state = RAW; + saved_fd = fd; + return 0; +} + +static void tty_atexit(void) +{ + if (tty_state != CBREAK && tty_state != RAW) { + return; + } + + if (tcsetattr(saved_fd, TCSANOW, &saved_termios) < 0) { + return; + } + tty_state = RESET; + return; +} + + +/* The simple ring buffer */ +class ring_buffer +{ +public: + ring_buffer(char *buf, size_t size) + { + m_buf = m_wptr = m_rptr = buf; + m_size = size; + m_count = 0; + } + + size_t get_count() { return m_count; } + int isempty() { return m_count == 0; } + + // return the unused space size in the buffer + size_t space() + { + if(m_rptr > m_wptr) + return m_rptr - m_wptr; + if(m_rptr < m_wptr || m_count == 0) + return m_buf + m_size - m_wptr; + return 0; // should not hit this + } + + // return the used space in the buffer + size_t chunk_size() + { + if(m_rptr < m_wptr) + return m_wptr - m_rptr; + if(m_rptr > m_wptr || m_count > 0) + return m_buf + m_size - m_rptr; + return 0; // should not hit this + } + + // read from fd and write to buffer memory + ssize_t rb_read(int fd) + { + ssize_t n = read(fd, m_wptr, space()); + if(n <= 0) + return n; + m_wptr += n; + m_count += n; + if(m_buf + m_size <= m_wptr) + m_wptr = m_buf; + return n; + } + + ssize_t rb_write(int fd) + { + ssize_t n = write(fd, m_rptr, chunk_size()); + if(n <= 0) + return n; + m_rptr += n; + m_count -= n; + if(m_buf + m_size <= m_rptr) + m_rptr = m_buf; + return n; + } + +private: + char *m_buf; /* pointer to buffer memory */ + char *m_wptr; + char *m_rptr; + size_t m_size; /* the number of bytes allocated for buf */ + size_t m_count; +}; + +static void setfd_nonblock(int fd) +{ + int fsflags = fcntl(fd, F_GETFL); + + if (fsflags < 0) { + fprintf(stderr, "fcntl(%d, F_GETFL): %s\n", + fd, strerror(errno)); + exit(EX_IOERR); + } + + if (fcntl(STDIN_FILENO, F_SETFL, fsflags | O_NONBLOCK) < 0) { + fprintf(stderr, "fcntl(%d, F_SETFL, ... | O_NONBLOCK): %s\n", + fd, strerror(errno)); + exit(EX_IOERR); + } +} + +static void sigchld_handler(int asig __attribute__ ((unused))) +{ +} + +int main(int argc, char *argv[]) +{ + pid_t child_pid; + int child_exit_status; + struct termios tty_attr; + struct winsize window_size; + int pty_master; + char inbuf_mem[BUFSIZE]; + char outbuf_mem[BUFSIZE]; + ring_buffer inbuf(inbuf_mem, sizeof(inbuf_mem)); + ring_buffer outbuf(outbuf_mem, sizeof(outbuf_mem)); + + if (argc == 1) { + printf("usage: %s PROGRAM [ARGS]...\n", argv[0]); + exit(1); + } + + /* Wee need I/O calls to fail with EINTR on SIGCHLD... */ + if ( signal(SIGCHLD, sigchld_handler) == SIG_ERR ) { + perror("signal(SIGCHLD,...)"); + exit(EX_OSERR); + } + + if (isatty(STDIN_FILENO)) { + /* get terminal parameters associated with stdout */ + if (tcgetattr(STDOUT_FILENO, &tty_attr) < 0) { + perror("tcgetattr(stdout,...)"); + exit(EX_OSERR); + } + + /* end of if(tcsetattr(&tty_attr)) */ + /* get window size */ + if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &window_size) < 0) { + perror("ioctl(stdout,...)"); + exit(1); + } + + child_pid = forkpty(&pty_master, NULL, &tty_attr, &window_size); + } /* end of if(isatty(STDIN_FILENO)) */ + else { /* not interactive */ + child_pid = forkpty(&pty_master, NULL, NULL, NULL); + } + + if (child_pid < 0) { + perror("forkpty()"); + fflush(stdout); + fflush(stderr); + exit(EX_OSERR); + } /* end of if(child_pid < 0) */ + if (child_pid == 0) { + /* in the child */ + struct termios s_tty_attr; + if (tcgetattr(STDIN_FILENO, &s_tty_attr)) { + perror("tcgetattr(stdin,...)"); + exit(EXIT_FAILURE); + } + /* Turn off echo */ + s_tty_attr.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); + /* Also turn of NL to CR?LF on output */ + s_tty_attr.c_oflag &= ~(ONLCR); + if (tcsetattr(STDIN_FILENO, TCSANOW, &s_tty_attr)) { + perror("tcsetattr(stdin,...)"); + exit(EXIT_FAILURE); + } + + if (execvp(argv[1], argv + 1)) { + perror("execvp()"); + exit(EXIT_FAILURE); + } + } + + /* + * Non blocking mode for all file descriptors. + */ + setfd_nonblock(pty_master); + setfd_nonblock(STDIN_FILENO); + setfd_nonblock(STDOUT_FILENO); + + if (isatty(STDIN_FILENO)) { + if (tty_semi_raw(STDIN_FILENO) < 0) { + perror("tty_semi_raw(stdin)"); + } + if (atexit(tty_atexit) < 0) { + perror("atexit()"); + } + } + + /* for select()... */ + fd_set readfds; + fd_set writefds; + fd_set exceptfds; + FD_ZERO(&readfds); + FD_ZERO(&writefds); + FD_ZERO(&exceptfds); + + unsigned err_n_rpty = 0; + unsigned err_n_wpty = 0; + unsigned err_n_stdin = 0; + unsigned err_n_stdout = 0; + + int done = 0; + + do { + /* Accept events only on fds, that we can handle now. */ + int do_select = 0; + + if ( outbuf.space() > 0 && err_n_rpty < MAXRETR ) { + FD_SET(pty_master, &readfds); + do_select = 1; + } else + FD_CLR(pty_master, &readfds); + + if ( ! inbuf.isempty() && err_n_wpty < MAXRETR ) { + FD_SET(pty_master, &writefds); + do_select = 1; + } else + FD_CLR(pty_master, &writefds); + + if ( inbuf.space() > 0 && err_n_stdin < MAXRETR ) { + FD_SET(STDIN_FILENO, &readfds); + do_select = 1; + } else + FD_CLR(STDIN_FILENO, &readfds); + + if ( ! outbuf.isempty() && err_n_stdout < MAXRETR ) { + FD_SET(STDOUT_FILENO, &writefds); + do_select = 1; + } else + FD_CLR(STDOUT_FILENO, &writefds); + + if ( ! do_select ) + { +#ifdef DEBUG + fprintf(stderr, "No I/O job for us, calling waitpid()...\n"); +#endif + while ( waitpid(child_pid, &child_exit_status, 0) < 0 ) + ; + break; + } + + int select_rc = select(pty_master + 1, + &readfds, &writefds, &exceptfds, NULL); + if ( select_rc < 0 ) { + perror("select()"); + exit(EX_IOERR); + } +#ifdef DEBUG + fprintf(stderr, "select() returned %d\n", select_rc); +#endif + + if (FD_ISSET(STDOUT_FILENO, &writefds)) { +#ifdef DEBUG + fprintf(stderr, "stdout can be written\n"); +#endif + ssize_t n = outbuf.rb_write(STDOUT_FILENO); + if ( n <= 0 && n != EINTR && n != EAGAIN ) + err_n_stdout++; +#ifdef DEBUG + if ( n >= 0 ) + fprintf(stderr, "%d bytes written into stdout\n", n); + else + perror("write(stdout,...)"); +#endif + } + if (FD_ISSET(pty_master, &writefds)) { +#ifdef DEBUG + fprintf(stderr, "pty_master can be written\n"); +#endif + ssize_t n = inbuf.rb_write(pty_master); + if ( n <= 0 && n != EINTR && n != EAGAIN ) + err_n_wpty++; +#ifdef DEBUG + if ( n >= 0 ) + fprintf(stderr, "%d bytes written into pty_master\n", n); + else + perror("write(pty_master,...)"); +#endif + } + if (FD_ISSET(STDIN_FILENO, &readfds)) { +#ifdef DEBUG + fprintf(stderr, "stdin can be read\n"); +#endif + ssize_t n = inbuf.rb_read(STDIN_FILENO); + if ( n <= 0 && n != EINTR && n != EAGAIN ) + err_n_stdin++; +#ifdef DEBUG + if ( n >= 0 ) + fprintf(stderr, "%d bytes read from stdin\n", n); + else + perror("read(stdin,...)"); +#endif + } + if (FD_ISSET(pty_master, &readfds)) { +#ifdef DEBUG + fprintf(stderr, "pty_master can be read\n"); +#endif + ssize_t n = outbuf.rb_read(pty_master); + if ( n <= 0 && n != EINTR && n != EAGAIN ) + err_n_rpty++; +#ifdef DEBUG + if ( n >= 0 ) + fprintf(stderr, "%d bytes read from pty_master\n", n); + else + perror("read(pty_master,...)"); +#endif + } + + if ( ! done ) + if ( waitpid(child_pid, &child_exit_status, WNOHANG) > 0 ) + done = 1; + + } while ( !done + || !(inbuf.isempty() || err_n_wpty >= MAXRETR) + || !(outbuf.isempty() || err_n_stdout >= MAXRETR) ); + +#ifdef DEBUG + fprintf(stderr, "inbuf: %u bytes left, outbuf: %u bytes left\n", + inbuf.get_count(), outbuf.get_count()); + fprintf(stderr, "err_n_rpty=%u, err_n_wpty=%u, " + "err_n_stdin=%u, err_n_stdout=%u\n", + err_n_rpty, err_n_wpty, err_n_stdin, err_n_stdout); +#endif + if ( WIFEXITED(child_exit_status) ) + exit(WEXITSTATUS(child_exit_status)); + exit(EXIT_FAILURE); +} /* end of main() */ + +/* + * vim:ts=4: + */ --1.7.10.4
Quoted 4 lines
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Re: [PATCH 04/15] policycoreutils: Add new open_init_pty that doesn't waste CPU time
In reply to Laurent BigonvilleRussell, can you review and sign off on this patch? If it matches your expectations I'll push it to the upstream policycoreutils.
-Eric
Quoted 876 lines · Laurent Bigonville
From: Russell Coker <[email protected]>
--- policycoreutils/run_init/Makefile | 7 +- policycoreutils/run_init/open_init_pty.c | 399 -------------------------- policycoreutils/run_init/open_init_pty.cpp | 423 ++++++++++++++++++++++++++++ 3 files changed, 427 insertions(+), 402 deletions(-) delete mode 100644 policycoreutils/run_init/open_init_pty.c create mode 100644 policycoreutils/run_init/open_init_pty.cpppolicycoreutils/run_init/Makefile +4
-3@@ -10,6 +10,7 @@ AUDITH = $(shell ls /usr/include/libaudit.h 2>/dev/null) CFLAGS ?= -Werror -Wall -W override CFLAGS += -I$(PREFIX)/include -DUSE_NLS -DLOCALEDIR="\"$(LOCALEDIR)\"" -DPACKAGE="\"policycoreutils\"" +CPPFLAGS ?= $(CFLAGS) LDLIBS += -lselinux -L$(PREFIX)/lib ifeq ($(PAMH), /usr/include/security/pam_appl.h) override CFLAGS += -DUSE_PAM@@ -23,12 +24,12 @@ ifeq ($(AUDITH), /usr/include/libaudit.h) LDLIBS += -laudit endif -TARGETS=$(patsubst %.c,%,$(wildcard *.c)) +TARGETS=open_init_pty run_init all: $(TARGETS) -open_init_pty: open_init_pty.c - $(LINK.c) $^ -ldl -lutil -o $@ +open_init_pty: open_init_pty.cpp + $(LINK.cpp) $^ -ldl -lutil -o $@ install: allpolicycoreutils/run_init/open_init_pty.c deleted +0
-399@@ -1,399 +0,0 @@ -/* -*- Mode: C -*- -* open_init_pty.c --- -* Author : Manoj Srivastava ( [email protected] ) -* Created On : Fri Jan 14 10:48:28 2005 -* Created On Node : glaurung.internal.golden-gryphon.com -* Last Modified By : Manoj Srivastava -* Last Modified On : Thu Sep 15 00:57:00 2005 -* Last Machine Used: glaurung.internal.golden-gryphon.com -* Update Count : 92 -* Status : Unknown, Use with caution! -* HISTORY : -* Description : -* -* Distributed under the terms of the GNU General Public License v2 -* -* open_init_pty -* -* SYNOPSIS: -* -* This program allows a systems administrator to execute daemons -* which need to work in the initrc domain, and which need to have -* pty's as system_u:system_r:initrc_t -* -* USAGE: -* -* * arch-tag: a5583d39-72b9-4cdf-ba1b-5678ea4cbe20 -*/ - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <signal.h> -#include <errno.h> - -#include <sysexits.h> - -#include <pty.h> /* for openpty and forkpty */ -#include <utmp.h> /* for login_tty */ -#include <termios.h> -#include <fcntl.h> - -#include <sys/select.h> - -static struct termios saved_termios; -static int saved_fd =-1 ; -static enum {RESET ,RAW ,CBREAK } tty_state =RESET ; - -static int tty_semi_raw (int fd) -{ -struct termios buf; - -if (tty_state ==RESET ) { -if (tcgetattr (fd, &saved_termios) <0 ) { -return -1 ; - } - } - - buf = saved_termios; -/* -* echo off, canonical mode off, extended input processing off, -* signal chars off -*/ - buf.c_lflag &= ~(ECHO |ICANON |IEXTEN |ISIG ); -/* -* no SIGINT on break, CR-to-NL off, input parity check off, do not -* strip 8th bit on input,output flow control off -*/ - buf.c_iflag &= ~(BRKINT |ICRNL |INPCK |ISTRIP |IXON ); -/* Clear size bits, parity checking off */ - buf.c_cflag &= ~(CSIZE |PARENB ); -/* set 8 bits/char */ - buf.c_cflag |=CS8 ; -/* Output processing off -buf.c_oflag &= ~(OPOST); */ - - buf.c_cc[VMIN ] =1 ;/* one byte at a time, no timer */ - buf.c_cc[VTIME ] =0 ; -if (tcsetattr (fd,TCSANOW , &buf) <0 ) { -return -1 ; - }/* end of if(tcsetattr(fileno(stdin), TCSANOW, &buf) < 0) */ - tty_state =RAW ; - saved_fd = fd; -return 0 ; -} - -void tty_atexit (void ) -{ -if (tty_state !=CBREAK && tty_state !=RAW ) { -return ; - } - -if (tcsetattr (saved_fd,TCSANOW , &saved_termios) <0 ) { -return ; - }/* end of if(tcsetattr(fileno(stdin), TCSANOW, &buf) < 0) */ - tty_state =RESET ; -return ; -} - -int main (int argc,char *argv[]) -{ -pid_t child_pid; -struct termios tty_attr; -struct winsize window_size; -int pty_master; -int retval =0 ; - -/* for select */ -fd_set readfds; -fd_set writefds; -fd_set exceptfds; - -int err_count =0 ; - -/* for sigtimedwait() */ -struct timespec timeout; -char buf[16384 ]; - -if (argc ==1 ) { -printf ("usage: %s PROGRAM [ARGS]...\n" , argv[0 ]); -exit (1 ); - } - -sigset_t signal_set; -siginfo_t signalinfo; - -/* set up SIGCHLD */ -sigemptyset (&signal_set);/* no signals */ -sigaddset (&signal_set,SIGCHLD );/* Add sig child */ -sigprocmask (SIG_BLOCK , &signal_set,NULL );/* Block the signal */ - -/* Set both to 0, so sigtimed wait just does a poll */ - timeout.tv_sec =0 ; - timeout.tv_nsec =0 ; - -if (isatty (fileno (stdin))) { -/* get terminal parameters associated with stdout */ -if (tcgetattr (fileno (stdout), &tty_attr) <0 ) { -perror ("tcgetattr:" ); -exit (EX_OSERR ); - } - -/* end of if(tcsetattr(&tty_attr)) */ -/* get window size */ -if (ioctl (fileno (stdout),TIOCGWINSZ , &window_size) <0 ) { -perror ("ioctl stdout:" ); -exit (1 ); - } - - child_pid =forkpty (&pty_master,NULL , &tty_attr, &window_size); - }/* end of if(isatty(fileno(stdin))) */ -else {/* not interactive */ - child_pid =forkpty (&pty_master,NULL ,NULL ,NULL ); - } - -if (child_pid <0 ) { -perror ("forkpty():" ); -fflush (stdout); -fflush (stderr); -exit (EX_OSERR ); - }/* end of if(child_pid < 0) */ -if (child_pid ==0 ) { -/* in the child */ -struct termios s_tty_attr; -if (tcgetattr (fileno (stdin), &s_tty_attr)) { -perror ("Child:" ); -fflush (stdout); -fflush (stderr); -exit (EXIT_FAILURE ); - } -/* Turn off echo */ - s_tty_attr.c_lflag &= ~(ECHO |ECHOE |ECHOK |ECHONL ); -/* Also turn of NL to CR?LF on output */ - s_tty_attr.c_oflag &= ~(ONLCR ); -if (tcsetattr (fileno (stdin),TCSANOW , &s_tty_attr)) { -perror ("Child:" ); -exit (EXIT_FAILURE ); - } - {/* There is no reason to block sigchild for the process we -shall exec here */ -sigset_t chld_signal_set; -/* release SIGCHLD */ -sigemptyset (&chld_signal_set);/* no signals */ -sigaddset (&chld_signal_set,SIGCHLD );/* Add sig child */ -sigprocmask (SIG_UNBLOCK , &chld_signal_set,NULL );/* Unblock the signal */ - } - -if (execvp (argv[1 ], argv +1 )) { -perror ("Exec:" ); -fflush (stdout); -fflush (stderr); -exit (EXIT_FAILURE ); - } - } - -/* end of if(child_pid == 0) */ -/* -* OK. Prepare to handle IO from the child. We need to transfer -* everything from the child's stdout to ours. -*/ -FD_ZERO (&readfds); -FD_ZERO (&writefds); -FD_ZERO (&exceptfds); - -/* -* Read current file descriptor flags, preparing to do non blocking reads -*/ - retval =fcntl (pty_master,F_GETFL ); -if (retval <0 ) { -perror ("fcntl_get" ); -fflush (stdout); -fflush (stderr); -exit (EX_IOERR ); - } - -/* Set the connection to be non-blocking */ -if (fcntl (pty_master,F_SETFL , retval |O_NONBLOCK ) <0 ) { -perror ("fcnt_setFlag_nonblock:" ); -fflush (stdout); -fflush (stderr); -exit (1 ); - } - -FD_SET (pty_master, &readfds); -FD_SET (pty_master, &writefds); -FD_SET (fileno (stdin), &readfds); -if (isatty (fileno (stdin))) { -if (tty_semi_raw (fileno (stdin)) <0 ) { -perror ("Error: settingraw mode:" ); -fflush (stdout); -fflush (stderr); - }/* end of if(tty_raw(fileno(stdin)) < 0) */ -if (atexit (tty_atexit) <0 ) { -perror ("Atexit setup:" ); -fflush (stdout); -fflush (stderr); - }/* end of if(atexit(tty_atexit) < 0) */ - } - -/* ignore return from nice, but lower our priority */ - int ignore __attribute__ ((unused)) = nice(19); - -/* while no signal, we loop around */ - int done = 0; -while (!done) { -struct timeval interval; -fd_set t_readfds; -fd_set t_writefds; -fd_set t_exceptfds; -/* -* We still use a blocked signal, and check for SIGCHLD every -* loop, since waiting infinitely did not really help the load -* when running, say, top. -*/ - interval.tv_sec =0 ; - interval.tv_usec =200000 ;/* so, check for signals every 200 milli -seconds */ - - t_readfds = readfds; - t_writefds = writefds; - t_exceptfds = exceptfds; - -/* check for the signal */ - retval =sigtimedwait (&signal_set, &signalinfo, &timeout); - -if (retval ==SIGCHLD ) { -/* child terminated */ - done =1 ;/* in case they do not close off their -file descriptors */ - }else { -if (retval <0 ) { -if (errno !=EAGAIN ) { -perror ("sigtimedwait" ); -fflush (stdout); -fflush (stderr); -exit (EX_IOERR ); - }else { -/* No signal in set was delivered within the timeout period specified */ - } - } - }/* end of else */ - -if (select - (pty_master +1 , &t_readfds, &t_writefds, &t_exceptfds, - &interval) <0 ) { -perror ("Select:" ); -fflush (stdout); -fflush (stderr); -exit (EX_IOERR ); - } - -if (FD_ISSET (pty_master, &t_readfds)) { - retval =read (pty_master, buf, (unsigned int )16384 ); -if (retval <0 ) { -if (errno !=EINTR && errno !=EAGAIN ) {/* Nothing left to read? */ -fflush (stdout); -fflush (stderr); -/* fprintf(stderr, "DEBUG: %d: Nothing left to read?\n", __LINE__); */ -exit (EXIT_SUCCESS ); - }/* end of else */ - }/* end of if(retval < 0) */ -else { -if (retval ==0 ) { -if (++err_count >5 ) {/* child closed connection */ -fflush (stdout); -fflush (stderr); -/*fprintf(stderr, "DEBUG: %d: child closed connection?\n", __LINE__); */ -exit (EXIT_SUCCESS ); - } - }/* end of if(retval == 0) */ -else { -ssize_t nleft = retval; -ssize_t nwritten =0 ; -char *ptr = buf; -while (nleft >0 ) { -if ((nwritten = -write (fileno (stdout), ptr, - (unsigned int )nleft)) - <=0 ) { -if (errno ==EINTR ) { - nwritten =0 ; - }/* end of if(errno == EINTR) */ -else { -perror ("write" ); -fflush (stdout); -fflush (stderr); -exit (EXIT_SUCCESS ); - }/* end of else */ - }/* end of if((nwritten = write(sockfd, ptr, nleft)) <= 0) */ - nleft -= nwritten; - ptr += nwritten; - }/* end of while(nleft > 0) */ - -/* fprintf(stderr, "DEBUG: %d: wrote %d\n", __LINE__, retval); */ -fflush (stdout); - }/* end of else */ - }/* end of else */ - } -if (FD_ISSET (fileno (stdin), &t_readfds)) { -if (FD_ISSET (pty_master, &t_writefds)) { - retval = -read (fileno (stdin), buf, - (unsigned int )16384 ); -if (retval <0 ) { -if (errno !=EINTR && errno !=EAGAIN ) {/* Nothing left to read? */ -fflush (stdout); -fflush (stderr); -exit (EXIT_SUCCESS ); - }/* end of else */ - }/* end of if(retval < 0) */ -else { -if (retval ==0 ) { -if (++err_count >5 ) {/* lost controlling tty */ -fflush (stdout); -fflush (stderr); -exit (EXIT_SUCCESS ); - } - }/* end of if(retval == 0) */ -else { -ssize_t nleft = retval; -ssize_t nwritten =0 ; -char *ptr = buf; -while (nleft >0 ) { -if ((nwritten = -write (pty_master, - ptr, - (unsigned -int )nleft)) - <=0 ) { -if (errno == -EINTR ) { - nwritten - =0 ; - }/* end of if(errno == EINTR) */ -else { -perror - ("write" ); -fflush - (stdout); -fflush - (stderr); -exit (EXIT_SUCCESS ); - }/* end of else */ - }/* end of if((nwritten = write(sockfd, ptr, nleft)) <= 0) */ - nleft -= nwritten; - ptr += nwritten; - }/* end of while(nleft > 0) */ - -fflush (stdout); - }/* end of else */ - }/* end of else */ - }/* end of if(FD_ISSET(pty_master, &writefds)) */ - }/* something to read on stdin */ - }/* Loop */ - -fflush (stdout); -fflush (stderr); - -exit (EXIT_SUCCESS ); -}/* end of main() */ policycoreutils/run_init/open_init_pty.cpp new file +423
-1@@ -0,0 +1,423 @@ +/* -*- Mode: C -*- + * open_init_pty.c --- + * Author : Manoj Srivastava ( [email protected] ) + * Created On : Fri Jan 14 10:48:28 2005 + * Created On Node : glaurung.internal.golden-gryphon.com + * Last Modified By : Manoj Srivastava + * Last Modified On : Thu Sep 15 00:57:00 2005 + * Last Machine Used: glaurung.internal.golden-gryphon.com + * Update Count : 92 + * Status : Unknown, Use with caution! + * HISTORY : + * Description : + * + * Distributed under the terms of the GNU General Public License v2 + * + * open_init_pty + * + * SYNOPSIS: + * + * This program allows a systems administrator to execute daemons + * which need to work in the initrc domain, and which need to have + * pty's as system_u:system_r:initrc_t + * + * USAGE: + * + * * arch-tag: a5583d39-72b9-4cdf-ba1b-5678ea4cbe20 + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <signal.h> +#include <errno.h> + +#include <sysexits.h> + +#include <pty.h> /* for openpty and forkpty */ +#include <utmp.h> /* for login_tty */ +#include <termios.h> +#include <fcntl.h> + +#include <sys/select.h> +#include <sys/wait.h> + + +#define MAXRETR 3 /* The max number of IO retries on a fd */ +#define BUFSIZE 2048 /* The ring buffer size */ + +static struct termios saved_termios; +static int saved_fd = -1; +static enum { RESET, RAW, CBREAK } tty_state = RESET; + +static int tty_semi_raw(int fd) +{ + struct termios buf; + + if (tty_state == RESET) { + if (tcgetattr(fd, &saved_termios) < 0) { + return -1; + } + } + + buf = saved_termios; + /* + * echo off, canonical mode off, extended input processing off, + * signal chars off + */ + buf.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG); + /* + * no SIGINT on break, CR-to-NL off, input parity check off, do not + * strip 8th bit on input,output flow control off + */ + buf.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON); + /* Clear size bits, parity checking off */ + buf.c_cflag &= ~(CSIZE | PARENB); + /* set 8 bits/char */ + buf.c_cflag |= CS8; + /* Output processing off + buf.c_oflag &= ~(OPOST); */ + + buf.c_cc[VMIN] = 1; /* one byte at a time, no timer */ + buf.c_cc[VTIME] = 0; + if (tcsetattr(fd, TCSANOW, &buf) < 0) { + return -1; + } + tty_state = RAW; + saved_fd = fd; + return 0; +} + +static void tty_atexit(void) +{ + if (tty_state != CBREAK && tty_state != RAW) { + return; + } + + if (tcsetattr(saved_fd, TCSANOW, &saved_termios) < 0) { + return; + } + tty_state = RESET; + return; +} + + +/* The simple ring buffer */ +class ring_buffer +{ +public: + ring_buffer(char *buf, size_t size) + { + m_buf = m_wptr = m_rptr = buf; + m_size = size; + m_count = 0; + } + + size_t get_count() { return m_count; } + int isempty() { return m_count == 0; } + + // return the unused space size in the buffer + size_t space() + { + if(m_rptr > m_wptr) + return m_rptr - m_wptr; + if(m_rptr < m_wptr || m_count == 0) + return m_buf + m_size - m_wptr; + return 0; // should not hit this + } + + // return the used space in the buffer + size_t chunk_size() + { + if(m_rptr < m_wptr) + return m_wptr - m_rptr; + if(m_rptr > m_wptr || m_count > 0) + return m_buf + m_size - m_rptr; + return 0; // should not hit this + } + + // read from fd and write to buffer memory + ssize_t rb_read(int fd) + { + ssize_t n = read(fd, m_wptr, space()); + if(n <= 0) + return n; + m_wptr += n; + m_count += n; + if(m_buf + m_size <= m_wptr) + m_wptr = m_buf; + return n; + } + + ssize_t rb_write(int fd) + { + ssize_t n = write(fd, m_rptr, chunk_size()); + if(n <= 0) + return n; + m_rptr += n; + m_count -= n; + if(m_buf + m_size <= m_rptr) + m_rptr = m_buf; + return n; + } + +private: + char *m_buf; /* pointer to buffer memory */ + char *m_wptr; + char *m_rptr; + size_t m_size; /* the number of bytes allocated for buf */ + size_t m_count; +}; + +static void setfd_nonblock(int fd) +{ + int fsflags = fcntl(fd, F_GETFL); + + if (fsflags < 0) { + fprintf(stderr, "fcntl(%d, F_GETFL): %s\n", + fd, strerror(errno)); + exit(EX_IOERR); + } + + if (fcntl(STDIN_FILENO, F_SETFL, fsflags | O_NONBLOCK) < 0) { + fprintf(stderr, "fcntl(%d, F_SETFL, ... | O_NONBLOCK): %s\n", + fd, strerror(errno)); + exit(EX_IOERR); + } +} + +static void sigchld_handler(int asig __attribute__ ((unused))) +{ +} + +int main(int argc, char *argv[]) +{ + pid_t child_pid; + int child_exit_status; + struct termios tty_attr; + struct winsize window_size; + int pty_master; + char inbuf_mem[BUFSIZE]; + char outbuf_mem[BUFSIZE]; + ring_buffer inbuf(inbuf_mem, sizeof(inbuf_mem)); + ring_buffer outbuf(outbuf_mem, sizeof(outbuf_mem)); + + if (argc == 1) { + printf("usage: %s PROGRAM [ARGS]...\n", argv[0]); + exit(1); + } + + /* Wee need I/O calls to fail with EINTR on SIGCHLD... */ + if ( signal(SIGCHLD, sigchld_handler) == SIG_ERR ) { + perror("signal(SIGCHLD,...)"); + exit(EX_OSERR); + } + + if (isatty(STDIN_FILENO)) { + /* get terminal parameters associated with stdout */ + if (tcgetattr(STDOUT_FILENO, &tty_attr) < 0) { + perror("tcgetattr(stdout,...)"); + exit(EX_OSERR); + } + + /* end of if(tcsetattr(&tty_attr)) */ + /* get window size */ + if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &window_size) < 0) { + perror("ioctl(stdout,...)"); + exit(1); + } + + child_pid = forkpty(&pty_master, NULL, &tty_attr, &window_size); + } /* end of if(isatty(STDIN_FILENO)) */ + else { /* not interactive */ + child_pid = forkpty(&pty_master, NULL, NULL, NULL); + } + + if (child_pid < 0) { + perror("forkpty()"); + fflush(stdout); + fflush(stderr); + exit(EX_OSERR); + } /* end of if(child_pid < 0) */ + if (child_pid == 0) { + /* in the child */ + struct termios s_tty_attr; + if (tcgetattr(STDIN_FILENO, &s_tty_attr)) { + perror("tcgetattr(stdin,...)"); + exit(EXIT_FAILURE); + } + /* Turn off echo */ + s_tty_attr.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); + /* Also turn of NL to CR?LF on output */ + s_tty_attr.c_oflag &= ~(ONLCR); + if (tcsetattr(STDIN_FILENO, TCSANOW, &s_tty_attr)) { + perror("tcsetattr(stdin,...)"); + exit(EXIT_FAILURE); + } + + if (execvp(argv[1], argv + 1)) { + perror("execvp()"); + exit(EXIT_FAILURE); + } + } + + /* + * Non blocking mode for all file descriptors. + */ + setfd_nonblock(pty_master); + setfd_nonblock(STDIN_FILENO); + setfd_nonblock(STDOUT_FILENO); + + if (isatty(STDIN_FILENO)) { + if (tty_semi_raw(STDIN_FILENO) < 0) { + perror("tty_semi_raw(stdin)"); + } + if (atexit(tty_atexit) < 0) { + perror("atexit()"); + } + } + + /* for select()... */ + fd_set readfds; + fd_set writefds; + fd_set exceptfds; + FD_ZERO(&readfds); + FD_ZERO(&writefds); + FD_ZERO(&exceptfds); + + unsigned err_n_rpty = 0; + unsigned err_n_wpty = 0; + unsigned err_n_stdin = 0; + unsigned err_n_stdout = 0; + + int done = 0; + + do { + /* Accept events only on fds, that we can handle now. */ + int do_select = 0; + + if ( outbuf.space() > 0 && err_n_rpty < MAXRETR ) { + FD_SET(pty_master, &readfds); + do_select = 1; + } else + FD_CLR(pty_master, &readfds); + + if ( ! inbuf.isempty() && err_n_wpty < MAXRETR ) { + FD_SET(pty_master, &writefds); + do_select = 1; + } else + FD_CLR(pty_master, &writefds); + + if ( inbuf.space() > 0 && err_n_stdin < MAXRETR ) { + FD_SET(STDIN_FILENO, &readfds); + do_select = 1; + } else + FD_CLR(STDIN_FILENO, &readfds); + + if ( ! outbuf.isempty() && err_n_stdout < MAXRETR ) { + FD_SET(STDOUT_FILENO, &writefds); + do_select = 1; + } else + FD_CLR(STDOUT_FILENO, &writefds); + + if ( ! do_select ) + { +#ifdef DEBUG + fprintf(stderr, "No I/O job for us, calling waitpid()...\n"); +#endif + while ( waitpid(child_pid, &child_exit_status, 0) < 0 ) + ; + break; + } + + int select_rc = select(pty_master + 1, + &readfds, &writefds, &exceptfds, NULL); + if ( select_rc < 0 ) { + perror("select()"); + exit(EX_IOERR); + } +#ifdef DEBUG + fprintf(stderr, "select() returned %d\n", select_rc); +#endif + + if (FD_ISSET(STDOUT_FILENO, &writefds)) { +#ifdef DEBUG + fprintf(stderr, "stdout can be written\n"); +#endif + ssize_t n = outbuf.rb_write(STDOUT_FILENO); + if ( n <= 0 && n != EINTR && n != EAGAIN ) + err_n_stdout++; +#ifdef DEBUG + if ( n >= 0 ) + fprintf(stderr, "%d bytes written into stdout\n", n); + else + perror("write(stdout,...)"); +#endif + } + if (FD_ISSET(pty_master, &writefds)) { +#ifdef DEBUG + fprintf(stderr, "pty_master can be written\n"); +#endif + ssize_t n = inbuf.rb_write(pty_master); + if ( n <= 0 && n != EINTR && n != EAGAIN ) + err_n_wpty++; +#ifdef DEBUG + if ( n >= 0 ) + fprintf(stderr, "%d bytes written into pty_master\n", n); + else + perror("write(pty_master,...)"); +#endif + } + if (FD_ISSET(STDIN_FILENO, &readfds)) { +#ifdef DEBUG + fprintf(stderr, "stdin can be read\n"); +#endif + ssize_t n = inbuf.rb_read(STDIN_FILENO); + if ( n <= 0 && n != EINTR && n != EAGAIN ) + err_n_stdin++; +#ifdef DEBUG + if ( n >= 0 ) + fprintf(stderr, "%d bytes read from stdin\n", n); + else + perror("read(stdin,...)"); +#endif + } + if (FD_ISSET(pty_master, &readfds)) { +#ifdef DEBUG + fprintf(stderr, "pty_master can be read\n"); +#endif + ssize_t n = outbuf.rb_read(pty_master); + if ( n <= 0 && n != EINTR && n != EAGAIN ) + err_n_rpty++; +#ifdef DEBUG + if ( n >= 0 ) + fprintf(stderr, "%d bytes read from pty_master\n", n); + else + perror("read(pty_master,...)"); +#endif + } + + if ( ! done ) + if ( waitpid(child_pid, &child_exit_status, WNOHANG) > 0 ) + done = 1; + + } while ( !done + || !(inbuf.isempty() || err_n_wpty >= MAXRETR) + || !(outbuf.isempty() || err_n_stdout >= MAXRETR) ); + +#ifdef DEBUG + fprintf(stderr, "inbuf: %u bytes left, outbuf: %u bytes left\n", + inbuf.get_count(), outbuf.get_count()); + fprintf(stderr, "err_n_rpty=%u, err_n_wpty=%u, " + "err_n_stdin=%u, err_n_stdout=%u\n", + err_n_rpty, err_n_wpty, err_n_stdin, err_n_stdout); +#endif + if ( WIFEXITED(child_exit_status) ) + exit(WEXITSTATUS(child_exit_status)); + exit(EXIT_FAILURE); +} /* end of main() */ + +/* + * vim:ts=4: + */ --1.7.10.4
Quoted 4 lines
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.