以非 root 使用者身分檢查 sendmail 狀態

以非 root 使用者身分檢查 sendmail 狀態

我正在從 5.5 轉換到 CentOS 6.5,需要一種方法來檢查 sendmail 是否開啟。由於我不想經歷的原因,我需要能夠檢查 sendmail 是否以非 root 使用者身分開啟。在 CentOS 5.5 中,我可以/sbin/service sendmail status以非 root 使用者身分執行。在 CentOS 6.5 中,安全性更加嚴格,並且在/etc/init.d/sendmail腳本中添加了新程式碼:

# Check that we're a privileged user
[ `id -u` = 0 ] || exit 4

sendmail 腳本使用以下程式碼來檢查其狀態:

status)
   echo -n sendmail; status -p /var/run/sendmail.pid -l sendmail
   RETVAL=$?
   echo -n sm-client; status -p /var/run/sm-client.pid -l sm-client
   [ $RETVAL -eq 0 ] && RETVAL=$?
  ;;

在 sendmail 腳本的開頭,該functions庫是原始程式碼,因此可以在腳本status()中調用functions

 # Source function library.
. /etc/rc.d/init.d/functions

作為 root,您通常會在運行時看到以下內容/sbin/service sendmail status

sendmail (pid  1107) is running...
sm-client (pid  1115) is running...

當以非 root 使用者身分執行時,我收到return code 4

到目前為止我所嘗試的是檢查/var/run/sendmail.pid以獲取進程 ID,然後檢查是否有並輸入/procpid。例如,

作為非 root 用戶:

cat /var/run/sendmail.pid - Get the pid

1107
/usr/sbin/sendmail -bd -q3600s

然後我檢查/proc/1107/status

Name:   sendmail
State:  S (sleeping)
Tgid:   1107
Pid:    1107
PPid:   1
TracerPid:      0
Uid:    0       0       0       0
Gid:    0       51      51      51
Utrace: 0
FDSize: 32
Groups: 51
VmPeak:    12844 kB
VmSize:    12840 kB
VmLck:         0 kB
VmHWM:      2020 kB
VmRSS:      2020 kB
VmData:     1176 kB
VmStk:       208 kB
VmExe:       824 kB
VmLib:     10156 kB
VmPTE:        44 kB
VmSwap:        0 kB
Threads:        1
SigQ:   0/3865
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000000000
SigIgn: 0000000000001006
SigCgt: 0000000180016201
CapInh: 0000000000000000
CapPrm: ffffffffffffffff
CapEff: ffffffffffffffff
CapBnd: ffffffffffffffff
Cpus_allowed:   1
Cpus_allowed_list:      0
Mems_allowed:   1
Mems_allowed_list:      0
voluntary_ctxt_switches:        560
nonvoluntary_ctxt_switches:     2

如果/proc/<pid>不存在,我知道服務沒有打開/sbin/service sendmail status

關於檢查 sendmail 服務是否以非 root 使用者身分執行的最佳方法有什麼想法嗎?

相關內容