Update setcap

This commit is contained in:
Shohei YOSHIDA 2022-11-25 18:15:00 +09:00
parent 59560d43a4
commit fc35e4e6c3
No known key found for this signature in database
GPG Key ID: C9A1BB11BB940CF2
1 changed files with 76 additions and 58 deletions

View File

@ -38,71 +38,89 @@
# - Zephyr Pellerin (https://github.com/zv) # - Zephyr Pellerin (https://github.com/zv)
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
local curcontext=$curcontext state line expl ret=1 _setcap() {
local -a args privs operators local curcontext=$curcontext state line expl ret=1
args=( '*:file:->files' _arguments -C -s \
'1:capability:->capability' '-v[verify that the specified capabilities are currently associated with the file]' \
'-v[verify]' '-q[quiet]' ) '-n[set the file capability for use only in a user namespace with this root user ID owner]:rootuid' \
'-q[make the program less verbose in its output]' \
'1:capability:->capability' \
'*:file:_files' \
&& ret=0
_arguments -C -s "$args[@]" && ret=0 case "$state" in
(capability)
if compset -P '*?[=+-]'; then
local -a operators=("e:effective" "i:inheritable" "p:permitted")
_describe -t operators "operator" operators && ret=0
else
_setcap_capabilities && ret=0
fi
;;
esac
operators=("e:effective" "i:inheritable" "p:permitted") return 0
}
case "$state" in (( $+functions[_setcap_capabilities] )) ||
capability) _setcap_capabilities() {
if compset -P '*?[=+-]'; then local ret=1
_describe -t operators "operator" operators && ret=0 local -a capabilities=(
else 'cap_audit_control:Enable and disable kernel auditing'
_values -s , capability \ 'cap_audit_read:Allow reading the audit log'
'cap_audit_control[Enable and disable kernel auditing]' \ 'cap_audit_write:Write records to kernel auditing log'
'cap_audit_read[Allow reading the audit log]' \ 'cap_block_suspend:Employ features that can block system suspend'
'cap_audit_write[Write records to kernel auditing log.]' \ 'cap_bpf:Employ privileged BPF operations'
'cap_block_suspend[Employ features that can block system suspend]' \ 'cap_checkpoint_restore:Facilitate checkpoint/restore'
'cap_chown[Make arbitrary changes to file UIDs and GIDs]' \ 'cap_chown:Make arbitrary changes to file UIDs and GIDs'
'cap_dac_override[Bypass file read, write, and execute permission checks.]' \ 'cap_dac_override:Bypass file read, write, and execute permission checks'
'cap_dac_read_search[Bypass file read permission checks]' \ 'cap_dac_read_search:Bypass file read permission checks'
'cap_fowner[Bypass filesystem UID checks, set extended attrs.]' \ 'cap_fowner:Bypass filesystem UID checks, set extended attrs'
"cap_fsetid[Don't clear set-user-ID and set-group-ID permission bits when a file is modified]" \ "cap_fsetid:Don't clear set-user-ID and set-group-ID permission bits when a file is modified"
'cap_ipc_lock[Lock memory]' \ 'cap_ipc_lock:Lock memory'
'cap_ipc_owner[Bypass checks on SySV IPC object operations.]' \ 'cap_ipc_owner:Bypass checks on SySV IPC object operations'
'cap_kill[Bypass permission checks for sending signals]' \ 'cap_kill:Bypass permission checks for sending signals'
'cap_lease[Establish leases on arbitrary files]' \ 'cap_lease:Establish leases on arbitrary files'
'cap_linux_immutable[Set immutability or append only]' \ 'cap_linux_immutable:Set immutability or append only'
'cap_mac_admin[Override Mandatory Access Control]' \ 'cap_mac_admin:Override Mandatory Access Control'
'cap_mac_override[Allow MAC configuration or state changes.]' \ 'cap_mac_override:Allow MAC configuration or state changes'
'cap_mknod[Create special files using mknod(2)]' \ 'cap_mknod:Create special files using mknod(2)'
'cap_net_admin[Perform various network-related operations]' \ 'cap_net_admin:Perform various network-related operations'
'cap_net_bind_service[Bind a socket to a privileged ports.]' \ 'cap_net_bind_service:Bind a socket to a privileged ports'
'cap_net_broadcast[Make socket broadcasts and listen to multicast.]' \ 'cap_net_broadcast:Make socket broadcasts and listen to multicast'
'cap_net_raw[Use raw sockets.]' \ 'cap_net_raw:Use raw sockets'
'cap_setgid[Manipulate process GIDs.]' \ 'cap_perfmon:Employ various performance-monitoring mechanisms'
'cap_setfcap[Set file capabilities.]' \ 'cap_setgid:Manipulate process GIDs'
"cap_setpcap[Grant or remove any capability in the caller's permitted capability set to or from any other process.]" \ 'cap_setfcap:Set file capabilities'
'cap_setuid[Manipulate or forge process UIDs]' \ "cap_setpcap:Grant or remove any capability in the caller's permitted capability set to or from any other process"
'cap_sys_admin[Perform numerous administrative tasks.]' \ 'cap_setuid:Manipulate or forge process UIDs'
'cap_sys_boot[Reboot]' \ 'cap_sys_admin:Perform numerous administrative tasks'
'cap_sys_chroot[Use chroot]' \ 'cap_sys_boot:Reboot'
'cap_sys_module[Load kernel module.]' \ 'cap_sys_chroot:Use chroot'
'cap_sys_nice[Nice or renice processes.]' \ 'cap_sys_module:Load kernel module'
'cap_sys_pacct[Use acct(2).]' \ 'cap_sys_nice:Nice or renice processes'
'cap_sys_ptrace[Inspect processes with ptrace or use process_vm_writev.]' \ 'cap_sys_pacct:Use acct(2)'
'cap_sys_rawio[Numerous device IO functions, including performing raw IO and access x86 MSRs]' \ 'cap_sys_ptrace:Inspect processes with ptrace or use process_vm_writev'
'cap_sys_resource[Set numerous resource limits]' \ 'cap_sys_rawio:Numerous device IO functions, including performing raw IO and access x86 MSRs'
'cap_sys_time[Set system clock]' \ 'cap_sys_resource:Set numerous resource limits'
'cap_sys_tty_config[Use vhangup(2)]' \ 'cap_sys_time:Set system clock'
'cap_syslog[Perform privileged syslog(2) operations.]' \ 'cap_sys_tty_config:Use vhangup(2)'
'cap_wake_alarm[Trigger something that will wake up the system]' && ret=0 'cap_syslog:Perform privileged syslog(2) operations'
fi ;; 'cap_wake_alarm:Trigger something that will wake up the system'
files) _files && ret=0 ;; )
esac
return ret _values -s , capability $capabilities && ret=0
return $ret
}
_setcap "$@"
# Local variables: # Local variables:
# mode: shell-script # mode: Shell-Script
# sh-basic-offset: 2 # sh-indentation: 2
# sh-indent-comment: t
# indent-tabs-mode: nil # indent-tabs-mode: nil
# sh-basic-offset: 2
# End: # End:
# ex: sw=2 ts=2 et filetype=sh # ex: sw=2 ts=2 et filetype=sh