[英]How do I force rpm -V to verify ALL files?
我希望能夠針對rpm數據庫驗證所有文件(所有文件都來自rpm,即)。
示例:當我要求rpm驗證包含/ etc / hosts的包時,我得到:
# rpm -Vv setup-2.8.14-16.el6.noarch
......... c /etc/aliases
S.5....T. c /etc/bashrc
......... c /etc/csh.cshrc
......... c /etc/csh.login
......... c /etc/environment
......... c /etc/exports
......... c /etc/filesystems
......... c /etc/group
......... c /etc/gshadow
......... c /etc/host.conf
......... c /etc/hosts
......... c /etc/hosts.allow
(stuff deleted)
我想看看例如/ etc / hosts被更改了。 我該怎么做呢?
這似乎是兩個問題:
對於第一個,您可以使用-qf
選項詢問rpm
哪個包擁有一個文件。 假設有一個POSIX shell,請檢查/etc/hosts
:
rpm -V $(rpm -qf /etc/hosts) | fgrep /etc/hosts
當然可以將其制作成腳本,例如,
#!/bin/sh
rpm -V $(rpm -qf $1) | fgrep $1
要檢查所有包,請使用-a
選項,例如,
rpm -Va
回復澄清:你在行上看到的c
告訴你文件標有rpm標簽%config
標簽。 此頁面列出了這些字母,包括注意到c
的使用:
RPM數據庫僅記錄原始大小md5sum文件的所有權。 %config
標簽是一種解決方法,用於確認系統維護人員希望修改某些文件(並避免使驗證報告混亂)。 你有幾個選擇(都涉及額外的工作):
對於提取, unrpm
腳本很有用。 (這個名稱不止一個; 這是一個鏈接 )。
rpm規范文件可以明確說明-V
應該驗證文件的哪些方面,並且通常期望配置文件(由輸出的第2列中的c
顯示)更改,並且不會在更新時覆蓋。
您可以使用rpm -qlv
輕松獲得原始文件大小和所有權,因此您可以執行相同文件的ls
,然后比較它們。 例如,
rpm=setup
rpm -ql $rpm |
xargs ls -ld --time-style='+%b %d %Y' |
tr -s ' ' |
sort -k9 |
diff -u <(rpm -qlv $rpm |tr -s ' ' | sort -k9) -
可以顯示更改( -
rpm的前綴, +
現在)或不顯示( 字首)。
這是一個腳本,它獲取包名列表並使用--dump
來獲取校驗和信息(等),這在我的Fedora 22上似乎是一個sha256sum而不是md5sum,並將它與真實文件進行比較。 雖然rpm -V
有一個額外的最終字段,“功能不同”,但轉儲輸出中不提供此信息。
#!/bin/bash
for pkg
do rpm -q --dump "$pkg" |
while read path size mtime digest mode owner group isconfig isdoc rdev symlink
do if [ "$path" = package ] # not installed
then echo "$path $size $mtime $digest $mode"
continue
fi
S=. M=. F=. D=. L=. U=. G=. T=.
type=$(stat --format='%F' $path)
if [ "$type" = "regular file" ]
then if realsum=$(sha256sum <$path)
then [ $digest != ${realsum/ -/} ] && F=5
else F=?
fi
elif [ "$type" = "symbolic link" ]
then reallink=$(readlink $path)
[ "$symlink" != "$reallink" ] && L=L
# elif [ "$type" = "directory" ] ...
fi
eval $(stat --format='s=%s u=%U g=%G t=%Y hexmode=%f' $path)
realmode=$(printf "%07o" 0x$hexmode)
realmode6=$(printf "%06o" 0x$hexmode)
[ "$mode" != "$realmode" -a "$mode" != "$realmode6" ] && M=M
[ "$size" != "$s" ] && S=S
[ "$owner" != "$u" ] && U=U
[ "$owner" != "$g" ] && G=G
[ "$mtime" != "$t" ] && T=T
flags="$S$M$F$D$L$U$G$T"
[ "$flags" = "........" ] ||
echo "$flags $path" # missing: P capabilities
done
done
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.