• selinux-policy-default(2:2.20231119-2)软件包内容详细介绍(2)


    接前一篇文章:selinux-policy-default(2:2.20231119-2)软件包内容详细介绍(1)

    4. 重点文件内容解析

    (1)control/postist文件

    文件内容如下:

    1. #!/bin/sh
    2. set -e
    3. # summary of how this script can be called:
    4. # * `configure'
    5. # * `abort-upgrade'
    6. # * `abort-remove' `in-favour'
    7. #
    8. # * `abort-remove'
    9. # * `abort-deconfigure' `in-favour'
    10. # `removing'
    11. #
    12. # for details, see http://www.debian.org/doc/debian-policy/ or
    13. # the debian-policy package
    14. # Will be replaced by the binary package flavour in debian/rules
    15. flavour="default"
    16. priority=100
    17. # modules which are not enabled by default, because they are usually
    18. # not needed on a debian system
    19. notdefault="aisexec amtu bugzilla cobbler condor cyphesis git ksmtuned likewise livecd nessus numad oddjob openca rlogin rshd soundserver telnet publicfile thunderbird updfstab usernetctl"
    20. platform=$(hostnamectl chassis) || true
    21. case "$platform" in
    22. handset)
    23. # dont need staff role
    24. notdefault="$notdefault staff"
    25. # dont need hardware specific things for non phone hardware
    26. notdefault="$notdefault acpi cdrecord fcoe iscsi isns openct raid rasdaemon tgtd tvtime vbetool"
    27. # dont need VM things
    28. notdefault="$notdefault hypervkvp"
    29. # dont need serious server daemons
    30. notdefault="$notdefault afs aide amanda amavis apcupsd aptcacher asterisk awstats bacula bind bird bitlbee boinc cachefilesd calamaris certbot cfengine clamav cockpit corosync couchdb courier ctdb cvs cyrus dbadm dictd distcc djbdns dkim dmidecode docker dovecot drbd fetchmail gitosis glance glusterfs inn irc ircd jabber kerberos keystone ldap lightsquid mailman matrixd mediawiki memcached milter minidlna mojomojo mongodb monop mrtg munin nagios nis nsd nslcd ntop nut openhpi openvswitch pacemaker passenger pcscd pegasus perdition pingd portmap portslave postfixpolicyd postgresql postgrey prelude procmail puppet pxe pyzor qemu qmail qpid quantum rabbitmq radius radvd razor realmd redis rsync samba samhain sanlock sasl sblim secadm shibboleth snort spamassassin squid stunnel svnserve sympa tftp tripwire uml uucp uwimap varnishd virt vmware wdmd webadm webalizer xen zabbix zarafa zebra"
    31. # dont need time sharing system daemons
    32. notdefault="$notdefault comsat finger oident rwho slocate slrnpull uptime quota"
    33. ;;
    34. vm)
    35. # dont need hardware specific things for vms
    36. notdefault="$notdefault acpi cdrecord fcoe iscsi isns openct raid rasdaemon tgtd tvtime vbetool"
    37. # dont need handset stuff
    38. notdefault="$notdefault eg25manager feedbackd geoclue iiosensorproxy"
    39. ;;
    40. desktop)
    41. # dont need VM things
    42. notdefault="$notdefault hypervkvp"
    43. # dont need portable stuff
    44. notdefault="$notdefault geoclue"
    45. # dont need handset stuff
    46. notdefault="$notdefault eg25manager feedbackd iiosensorproxy"
    47. ;;
    48. laptop)
    49. # dont need VM things
    50. notdefault="$notdefault hypervkvp"
    51. # dont need handset stuff
    52. notdefault="$notdefault eg25manager feedbackd iiosensorproxy"
    53. ;;
    54. *)
    55. echo "Unknown output from hostnamectl or not running systemd"
    56. ;;
    57. esac
    58. . /etc/selinux/config
    59. case "$1" in
    60. configure)
    61. echo -n "Updating selinux ${flavour} policy (this step might take a moment)..."
    62. # list all the modules that are already installed with our priority
    63. already_installed=`semodule -s ${flavour} --list-modules=full | grep -e "^${priority} " | cut -d' ' -f2`
    64. # record which non-default modules do not yet exist for disabling them later
    65. to_disable=""
    66. for module in ${notdefault}; do
    67. installed=0
    68. for inst_module in ${already_installed}; do
    69. if [ $module = $inst_module ]; then
    70. installed=1
    71. break
    72. fi
    73. done
    74. if [ $installed -ne 1 ]; then
    75. to_disable="$to_disable -d${module}"
    76. fi
    77. done
    78. # List all the modules that we are going to install
    79. to_install=""
    80. for module in `cat /usr/share/selinux/${flavour}/.modules`; do
    81. to_install="$to_install -i/usr/share/selinux/${flavour}/${module}.pp.bz2"
    82. done
    83. # Now build a list of the modules that we were shipping before but that we are not
    84. # anymore and that we need to remove
    85. to_remove=""
    86. for inst_module in $already_installed; do
    87. remove_module=1
    88. for pkg_module in `cat /usr/share/selinux/${flavour}/.modules`; do
    89. if [ $inst_module = $pkg_module ]; then
    90. remove_module=0
    91. break
    92. fi
    93. done
    94. if [ $remove_module -eq 1 ]; then
    95. to_remove="$to_remove -r${inst_module}"
    96. fi
    97. done
    98. # Now load policy into the kernel if it is the configured policy
    99. # and we are running selinux
    100. if [ "${SELINUXTYPE}" != "${flavour}" ] || ! selinuxenabled; then
    101. noreload='-n'
    102. fi
    103. ret=0
    104. semodule -X $priority $noreload -s $flavour $to_remove $to_install $to_disable || ret=$?
    105. if [ $ret -eq 0 ]; then
    106. echo " done."
    107. else
    108. echo " failed."
    109. exit $ret
    110. fi
    111. FC=/etc/selinux/$flavour/contexts/files/file_contexts
    112. OLDFC=$FC.old
    113. if [ -f $OLDFC ]; then
    114. OLDSORT=$(mktemp)
    115. NEWSORT=$(mktemp)
    116. sort < $OLDFC > $OLDSORT
    117. sort < $FC > $NEWSORT
    118. ORIGDIFF=$(mktemp)
    119. diff $OLDSORT $NEWSORT | grep -v ^[0-9] > $ORIGDIFF || true
    120. rm $OLDSORT $NEWSORT
    121. if [ -s $ORIGDIFF ]; then
    122. DIFF=$(mktemp)
    123. cut -f2 -d\ < $ORIGDIFF > $DIFF
    124. GOOD=$(mktemp)
    125. grep -v ^/run $DIFF |grep -v ^/dev | grep "/.*/" > $GOOD || true
    126. if [ -s $GOOD ]; then
    127. echo ""
    128. echo "Relabeling matches for the following file context changes:"
    129. cat $GOOD
    130. echo ""
    131. DIRS=$(cat $GOOD | sed -e 's/(\.\*\/).*$//' -e 's/(.*$//' -e 's/\/[^/]*$//' -e 's/\/[0-9a-z]*\[.*$//' | sort -u | /usr/libexec/selinux/remove-leaf-dirs)
    132. echo The following directories: $DIRS
    133. restorecon -R -v $DIRS || echo "restorecon gave an error but package is still ok"
    134. fi
    135. rm $GOOD
    136. PROB=$(mktemp)
    137. grep ^../run $ORIGDIFF > $PROB || true
    138. grep ^../dev $ORIGDIFF >> $PROB || true
    139. grep -v "/.*/" $ORIGDIFF >> $PROB || true
    140. if [ -s $PROB ]; then
    141. echo "The following lines have changes that can't be automatically applied, consider"
    142. echo "manually relabelling them if appropriate:"
    143. cat $PROB
    144. fi
    145. rm $DIFF $PROB
    146. else
    147. echo "No changes to file contexts"
    148. fi
    149. rm $ORIGDIFF $OLDFC
    150. fi
    151. ;;
    152. abort-upgrade|abort-remove|abort-deconfigure)
    153. ;;
    154. *)
    155. echo "postinst called with unknown argument \`$1'" >&2
    156. exit 1
    157. ;;
    158. esac
    159. # dh_installdeb will replace this with shell code automatically
    160. # generated by other debhelper scripts.
    161. # Automatically added by dh_installdeb/13.11.6
    162. dpkg-maintscript-helper rm_conffile /etc/selinux/default/users/local.users 2:2.20140421-10\~ -- "$@"
    163. dpkg-maintscript-helper rm_conffile /etc/selinux/default/users/system.users 2:2.20140421-10\~ -- "$@"
    164. dpkg-maintscript-helper rm_conffile /etc/selinux/default/modules/semanage.read.LOCK 2:2.20140421-10\~ -- "$@"
    165. dpkg-maintscript-helper rm_conffile /etc/selinux/default/modules/semanage.trans.LOCK 2:2.20140421-10\~ -- "$@"
    166. dpkg-maintscript-helper rm_conffile /etc/selinux/default/modules/active/file_contexts.local 2:2.20140421-10\~ -- "$@"
    167. # End automatically added section
    168. exit 0

    control/postist文件总共189行,还是比较长的,内容也比较多。下边一段一段来看。

    1)!#/bin/sh

    这无需多言,#!/bin/sh是指此脚本使用/bin/sh来解释执行。

    2)set -e

    set -e是shell中的一个选项,其作用是在脚本执行过程中,一旦出现任何命令执行失败(返回非零的退出状态码),脚本就会立即退出,后续的脚本将不会得到执行的机会。

    注意:

    使用set -e,当一行命令中包含多个子命令时,即使某个子命令返回值不为0,但最终那一行命令的返回值为0,脚本也不会报错退出。

    3)注释说明

    接下来是一段如何运行postinst的具体说明。这一段如下:

    1. # summary of how this script can be called:
    2. # * `configure'
    3. # * `abort-upgrade'
    4. # * `abort-remove' `in-favour'
    5. #
    6. # * `abort-remove'
    7. # * `abort-deconfigure' `in-favour'
    8. # `removing'
    9. #
    10. # for details, see http://www.debian.org/doc/debian-policy/ or
    11. # the debian-policy package

    这一段是关于如何调用此(postinst)脚本的摘要。更多详细信息,参阅http://www.debian.org/doc/debian-policy/或debian-policy包。

    4)变量赋值语句

    接下来是几个变量赋值语句,代码片段如下:

    1. # Will be replaced by the binary package flavour in debian/rules
    2. flavour="default"
    3. priority=100
    4. # modules which are not enabled by default, because they are usually
    5. # not needed on a debian system
    6. notdefault="aisexec amtu bugzilla cobbler condor cyphesis git ksmtuned likewise livecd nessus numad oddjob openca rlogin rshd soundserver telnet publicfile thunderbird updfstab usernetctl"

    设置变量flavour的值为"default",此值将被debian/rule中的二进制包flavour所代替。

    设置变量priority的值为100。

    设置变量nodefault的值为"aisexec amtu bugzilla cobbler condor cyphesis git ksmtuned likewise livecd nessus numad oddjob openca rlogin rshd soundserver telnet publicfile thunderbird updfstab usernetctl"。这些值代表默认情况下不会被使能的模块,因为debian系统通常不需要这些模块。

    5)platform变量赋值

    接下来是以下一行代码:

    platform=$(hostnamectl chassis) || true

    虽然只有一行,但其中内容还是挺多的。主要涉及到hostnamectl命令。

    关于hostnamectl命令的详解,请参考相关文章。在此列出笔者电脑中的相关信息,如下: 

    1. $ hostnamectl
    2. Static hostname: Ding-Perlis-MP26JBT0
    3. Icon name: computer
    4. Machine ID: ccd4c48fdb304652ad40edc548349078
    5. Boot ID: 11b3d0d94b7c40cb96663b7ff7ee8790
    6. Operating System: DingOS 0.1 (ding-perlis-minsky-v00)
    7. Kernel: Linux 6.1.46-01-perlis001-2
    8. Architecture: x86-64
    9. Hardware Vendor: Lenovo
    10. Hardware Model: ThinkBook 14 G2 ITL
    11. Firmware Version: F8CN46WW(V2.09)

    命令用法:

    1. $ hostnamectl -h
    2. hostnamectl [OPTIONS...] COMMAND ...
    3. Query or change system hostname.
    4. Commands:
    5. status Show current hostname settings
    6. hostname [NAME] Get/set system hostname
    7. icon-name [NAME] Get/set icon name for host
    8. chassis [NAME] Get/set chassis type for host
    9. deployment [NAME] Get/set deployment environment for host
    10. location [NAME] Get/set location for host
    11. Options:
    12. -h --help Show this help
    13. --version Show package version
    14. --no-ask-password Do not prompt for password
    15. -H --host=[USER@]HOST Operate on remote host
    16. -M --machine=CONTAINER Operate on local container
    17. --transient Only set transient hostname
    18. --static Only set static hostname
    19. --pretty Only set pretty hostname
    20. --json=pretty|short|off
    21. Generate JSON output
    22. See the hostnamectl(1) man page for details.

    实际hostnamectl chassis命令的返回值:

    1. $ hostnamectl chassis

    6)根据platform变量的值决定notdefault的进一步值

    代码片段如下:

    1. case "$platform" in
    2. handset)
    3. # dont need staff role
    4. notdefault="$notdefault staff"
    5. # dont need hardware specific things for non phone hardware
    6. notdefault="$notdefault acpi cdrecord fcoe iscsi isns openct raid rasdaemon tgtd tvtime vbetool"
    7. # dont need VM things
    8. notdefault="$notdefault hypervkvp"
    9. # dont need serious server daemons
    10. notdefault="$notdefault afs aide amanda amavis apcupsd aptcacher asterisk awstats bacula bind bird bitlbee boinc cachefilesd calamaris certbot cfengine clamav cockpit corosync couchdb courier ctdb cvs cyrus dbadm dictd distcc djbdns dkim dmidecode docker dovecot drbd fetchmail gitosis glance glusterfs inn irc ircd jabber kerberos keystone ldap lightsquid mailman matrixd mediawiki memcached milter minidlna mojomojo mongodb monop mrtg munin nagios nis nsd nslcd ntop nut openhpi openvswitch pacemaker passenger pcscd pegasus perdition pingd portmap portslave postfixpolicyd postgresql postgrey prelude procmail puppet pxe pyzor qemu qmail qpid quantum rabbitmq radius radvd razor realmd redis rsync samba samhain sanlock sasl sblim secadm shibboleth snort spamassassin squid stunnel svnserve sympa tftp tripwire uml uucp uwimap varnishd virt vmware wdmd webadm webalizer xen zabbix zarafa zebra"
    11. # dont need time sharing system daemons
    12. notdefault="$notdefault comsat finger oident rwho slocate slrnpull uptime quota"
    13. ;;
    14. vm)
    15. # dont need hardware specific things for vms
    16. notdefault="$notdefault acpi cdrecord fcoe iscsi isns openct raid rasdaemon tgtd tvtime vbetool"
    17. # dont need handset stuff
    18. notdefault="$notdefault eg25manager feedbackd geoclue iiosensorproxy"
    19. ;;
    20. desktop)
    21. # dont need VM things
    22. notdefault="$notdefault hypervkvp"
    23. # dont need portable stuff
    24. notdefault="$notdefault geoclue"
    25. # dont need handset stuff
    26. notdefault="$notdefault eg25manager feedbackd iiosensorproxy"
    27. ;;
    28. laptop)
    29. # dont need VM things
    30. notdefault="$notdefault hypervkvp"
    31. # dont need handset stuff
    32. notdefault="$notdefault eg25manager feedbackd iiosensorproxy"
    33. ;;
    34. *)
    35. echo "Unknown output from hostnamectl or not running systemd"
    36. ;;
    37. esac

    postinst的其余代码请看下回。

  • 相关阅读:
    三极管及继电器的使用(单片机如何控制灯泡等大型电器)
    Jmeter响应时间和tps监听器使用教程
    性能提升3-4倍!贝壳基于Flink + OceanBase的实时维表服务
    armlinux 移植qt
    SpringBoot + Dubbo + zookeeper实现
    智工教育:注册计量师一级和二级的科目一样吗?
    搭建安信可小安派Windows 开发环境
    MySQL 行级锁(行锁、临键锁、间隙锁)
    C++ 派生类函数重载与虚函数继承详解
    神经网络模型结果怎么看,图像识别神经网络模型
  • 原文地址:https://blog.csdn.net/phmatthaus/article/details/134538393