-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 This patch looks good to me. acked. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk9x3o0ACgkQrlYvE4MpobPaIACbBSAttFeL3iUu5gvvF7l7Zeq9 2SwAn1naXhbxl0dMjEQOjQF+HG3BcY6Q =M2Us -----END PGP SIGNATURE-----
>From f25467b1d495750d75ba82d029b219590d0f997a Mon Sep 17 00:00:00 2001 From: Dan Walsh <dwalsh@xxxxxxxxxx> Date: Tue, 6 Mar 2012 10:45:29 -0500 Subject: [PATCH 58/73] policycoreutils: Add bash-completion scripts for setsebool and semanage Signed-off-by: Eric Paris <eparis@xxxxxxxxxx> --- policycoreutils/scripts/genhomedircon | 1 - policycoreutils/semanage/Makefile | 5 + .../semanage/semanage-bash-completion.sh | 151 ++++++++++++++++++++ policycoreutils/setsebool/Makefile | 5 + .../setsebool/setsebool-bash-completion.sh | 58 ++++++++ 5 files changed, 219 insertions(+), 1 deletion(-) create mode 100644 policycoreutils/semanage/semanage-bash-completion.sh create mode 100644 policycoreutils/setsebool/setsebool-bash-completion.sh diff --git a/policycoreutils/scripts/genhomedircon b/policycoreutils/scripts/genhomedircon index 58b19cd..ab696a7 100644 --- a/policycoreutils/scripts/genhomedircon +++ b/policycoreutils/scripts/genhomedircon @@ -1,3 +1,2 @@ #!/bin/sh - /usr/sbin/semodule -Bn diff --git a/policycoreutils/semanage/Makefile b/policycoreutils/semanage/Makefile index 468e3b1..24d6a21 100644 --- a/policycoreutils/semanage/Makefile +++ b/policycoreutils/semanage/Makefile @@ -5,9 +5,12 @@ SBINDIR ?= $(PREFIX)/sbin MANDIR = $(PREFIX)/share/man PYLIBVER ?= $(shell python -c 'import sys;print "python%d.%d" % sys.version_info[0:2]') PYTHONLIBDIR ?= $(LIBDIR)/$(PYLIBVER) +BASHCOMPLETIONDIR ?= $(DESTDIR)/etc/bash_completion.d/ TARGETS=semanage +BASHCOMPLETIONS=semanage-bash-completion.sh + all: $(TARGETS) install: all @@ -17,6 +20,8 @@ install: all install -m 644 semanage.8 $(MANDIR)/man8 test -d $(PYTHONLIBDIR)/site-packages || install -m 755 -d $(PYTHONLIBDIR)/site-packages install -m 755 seobject.py $(PYTHONLIBDIR)/site-packages + -mkdir -p $(BASHCOMPLETIONDIR) + install -m 644 $(BASHCOMPLETIONS) $(BASHCOMPLETIONDIR) clean: diff --git a/policycoreutils/semanage/semanage-bash-completion.sh b/policycoreutils/semanage/semanage-bash-completion.sh new file mode 100644 index 0000000..ff1285a --- /dev/null +++ b/policycoreutils/semanage/semanage-bash-completion.sh @@ -0,0 +1,151 @@ +# This file is part of systemd. +# +# Copyright 2011 Dan Walsh +# +# systemd is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# systemd is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with systemd; If not, see <http://www.gnu.org/licenses/>. + +__contains_word () { + local word=$1; shift + for w in $*; do [[ $w = $word ]] && return 0; done + return 1 +} + +ALL_OPTS='-l --list -S -o -n --noheading -h --help' +MANAGED_OPTS='-a --add -m --modify -d --delete -D --deleteall -C --locallist ' + +__get_all_stores () { + dir -1 -F /etc/selinux/ | grep '/' | cut -d'/' -f 1 +} +__get_all_ftypes () { + echo '-- -d -c -b -s -l -p' +} +__get_all_users () { + seinfo -u 2> /dev/null | tail -n +3 +} +__get_all_types () { + seinfo -t 2> /dev/null | tail -n +3 +} +__get_all_port_types () { + seinfo -aport_type -x 2>/dev/null | tail -n +2 +} +__get_all_domains () { + seinfo -adomain -x 2>/dev/null | tail -n +2 +} +__get_all_node_types () { + seinfo -anode_type -x 2>/dev/null | tail -n +2 +} +__get_all_file_types () { + seinfo -afile_type -x 2>/dev/null | tail -n +2 +} +__get_all_roles () { + seinfo -t 2> /dev/null | tail -n +3 +} +__get_all_stores () { + dir -1 -F /etc/selinux/ | grep '/' | cut -d'/' -f 1 +} +__get_boolean_opts () { echo '$ALL_OPTS --on -off -1 -0 -F' ; } +__get_user_opts () { echo '$ALL_OPTS $MANAGED_OPTS -L -r -R --role '; } +__get_login_opts () { echo '$ALL_OPTS $MANAGED_OPTS -s -r '; } +__get_port_opts () { echo '$ALL_OPTS $MANAGED_OPTS -t -type -r --range -p --proto'; } +__get_interface_opts () { echo '$ALL_OPTS $MANAGED_OPTS -t --type '; } +__get_node_opts () { echo '$ALL_OPTS $MANAGED_OPTS -t --type -M --mask -p --proto'; } +__get_fcontext_opts () { echo '$ALL_OPTS $MANAGED_OPTS -t --type -e --equal -f --ftype '; } +__get_module_opts () { echo '$ALL_OPTS --enable --disable '; } +__get_dontaudit_opts () { echo '-S on off' ; } +__get_permissive_opts () { echo '$ALL_OPTS -a --add -d --delete' ; } + +_semanage () { + local command=${COMP_WORDS[1]} + local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} + local verb comps + local -A VERBS=( + [LOGIN]='login' + [USER]='user' + [PORT]='port' + [INTERFACE]='interface' + [MODULE]='module' + [NODE]='node' + [FCONTEXT]='fcontext' + [BOOLEAN]='boolean' + [PERMISSIVE]='permissive' + [DONTAUDIT]='dontaudit' + ) + + if [ "$prev" = "-a" -a "$command" = "permissive" ]; then + COMPREPLY=( $(compgen -W "$( __get_all_domains ) " -- "$cur") ) + return 0 + fi + if [ "$verb" = "" -a "$prev" = "semanage" ]; then + comps="${VERBS[*]}" + elif [ "$verb" = "" -a "$prev" = "-S" -o "$prev" = "--store" ]; then + COMPREPLY=( $(compgen -W "$( __get_all_stores ) " -- "$cur") ) + return 0 + elif [ "$verb" = "" -a "$prev" = "-p" -o "$prev" = "--proto" ]; then + COMPREPLY=( $(compgen -W "tcp udp" -- "$cur") ) + return 0 + elif [ "$verb" = "" -a "$prev" = "-r" -o "$prev" = "--roles" ]; then + COMPREPLY=( $(compgen -W "$( __get_all_roles ) " -- "$cur") ) + return 0 + elif [ "$verb" = "" -a "$prev" = "-s" -o "$prev" = "--seuser" ]; then + COMPREPLY=( $(compgen -W "$( __get_all_users ) " -- "$cur") ) + return 0 + elif [ "$verb" = "" -a "$prev" = "-f" -o "$prev" = "--ftype" ]; then + COMPREPLY=( $(compgen -W "$( __get_all_ftypes ) " -- "$cur") ) + return 0 + elif [ "$verb" = "" -a "$prev" = "-t" -o "$prev" = "--types" ]; then + if [ "$command" = "port" ]; then + COMPREPLY=( $(compgen -W "$( __get_all_port_types ) " -- "$cur") ) + return 0 + fi + if [ "$command" = "fcontext" ]; then + COMPREPLY=( $(compgen -W "$( __get_all_file_types ) " -- "$cur") ) + return 0 + fi + COMPREPLY=( $(compgen -W "$( __get_all_types ) " -- "$cur") ) + return 0 + elif __contains_word "$command" ${VERBS[LOGIN]} ; then + COMPREPLY=( $(compgen -W "$( __get_login_opts ) " -- "$cur") ) + return 0 + elif __contains_word "$command" ${VERBS[USER]} ; then + COMPREPLY=( $(compgen -W "$( __get_user_opts ) " -- "$cur") ) + return 0 + elif __contains_word "$command" ${VERBS[PORT]} ; then + COMPREPLY=( $(compgen -W "$( __get_port_opts ) " -- "$cur") ) + return 0 + elif __contains_word "$command" ${VERBS[INTERFACE]} ; then + COMPREPLY=( $(compgen -W "$( __get_interface_opts ) " -- "$cur") ) + return 0p + elif __contains_word "$command" ${VERBS[MODULE]} ; then + COMPREPLY=( $(compgen -W "$( __get_module_opts ) " -- "$cur") ) + return 0 + elif __contains_word "$command" ${VERBS[NODE]} ; then + COMPREPLY=( $(compgen -W "$( __get_node_opts ) " -- "$cur") ) + return 0 + elif __contains_word "$command" ${VERBS[FCONTEXT]} ; then + COMPREPLY=( $(compgen -W "$( __get_fcontext_opts ) " -- "$cur") ) + return 0 + elif __contains_word "$command" ${VERBS[BOOLEAN]} ; then + COMPREPLY=( $(compgen -W "$( __get_boolean_opts ) " -- "$cur") ) + return 0 + elif __contains_word "$command" ${VERBS[PERMISSIVE]} ; then + COMPREPLY=( $(compgen -W "$( __get_permissive_opts ) " -- "$cur") ) + return 0 + elif __contains_word "$command" ${VERBS[DONTAUDIT]} ; then + COMPREPLY=( $(compgen -W "$( __get_dontaudit_opts ) " -- "$cur") ) + return 0 + fi + COMPREPLY=( $(compgen -W "$comps" -- "$cur") ) + return 0 +} +complete -F _semanage semanage diff --git a/policycoreutils/setsebool/Makefile b/policycoreutils/setsebool/Makefile index 69c55a5..a6addc5 100644 --- a/policycoreutils/setsebool/Makefile +++ b/policycoreutils/setsebool/Makefile @@ -4,12 +4,15 @@ INCLUDEDIR ?= $(PREFIX)/include SBINDIR ?= $(PREFIX)/sbin MANDIR = $(PREFIX)/share/man LIBDIR ?= $(PREFIX)/lib +BASHCOMPLETIONDIR ?= $(DESTDIR)/etc/bash_completion.d/ CFLAGS ?= -Werror -Wall -W override CFLAGS += -I$(INCLUDEDIR) LDLIBS = -lsepol -lselinux -lsemanage -L$(LIBDIR) SETSEBOOL_OBJS = setsebool.o +BASHCOMPLETIONS=setsebool-bash-completion.sh + all: setsebool setsebool: $(SETSEBOOL_OBJS) @@ -19,6 +22,8 @@ install: all install -m 755 setsebool $(SBINDIR) -mkdir -p $(MANDIR)/man8 install -m 644 setsebool.8 $(MANDIR)/man8/ + -mkdir -p $(BASHCOMPLETIONDIR) + install -m 644 $(BASHCOMPLETIONS) $(BASHCOMPLETIONDIR) relabel: diff --git a/policycoreutils/setsebool/setsebool-bash-completion.sh b/policycoreutils/setsebool/setsebool-bash-completion.sh new file mode 100644 index 0000000..d0f3b42 --- /dev/null +++ b/policycoreutils/setsebool/setsebool-bash-completion.sh @@ -0,0 +1,58 @@ +# This file is part of systemd. +# +# Copyright 2011 Dan Walsh +# +# systemd is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# systemd is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with systemd; If not, see <http://www.gnu.org/licenses/>. + +__contains_word () { + local word=$1; shift + for w in $*; do [[ $w = $word ]] && return 0; done + return 1 +} + +__get_all_booleans () { + getsebool -a | cut -f1 -d' ' +} + +_setsebool () { + local command=${COMP_WORDS[1]} + local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} + local verb comps + + if [ "$verb" = "" -a "$prev" = "setsebool" -o "$prev" = "-P" ]; then + COMPREPLY=( $(compgen -W "-P $( __get_all_booleans ) " -- "$cur") ) + return 0 + fi + COMPREPLY=( $(compgen -W "0 1 -P" -- "$cur") ) + return 0 +} + +_getsebool () { + local command=${COMP_WORDS[1]} + local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} + local verb comps + + if [ "$verb" = "" -a "$prev" == "getsebool" ]; then + COMPREPLY=( $(compgen -W "-a $( __get_all_booleans ) " -- "$cur") ) + return 0 + fi + if [ "$verb" = "" -a "$prev" != "-a" ]; then + COMPREPLY=( $(compgen -W "$( __get_all_booleans ) " -- "$cur") ) + return 0 + fi + return 0 +} + +complete -F _setsebool setsebool +complete -F _getsebool getsebool -- 1.7.9.3