`
xitong
  • 浏览: 6206035 次
文章分类
社区版块
存档分类
最新评论

Leopard的检疫"quarantine"功能

 
阅读更多
Created: 2008-10-12
Update;
2008-12-13: Added shell script part + minor sentences correction.


以前使用Tiger,使用到10.4.11,换了新机器也就随着换了Leopard. 后来发现Leopard与Tiger的一个改进,就是它可以分别出是Internet/email下载的程序还是光盘或者从它处,比如USB盘或者网络共享等,复制的程序, 而对于从Internet上下载的程序系统会提示用户是否运行该程序,因为绝大多数的下载程序有可能有安全隐患,而杜绝安全隐患的最后的关卡,还是操作者本人,再有也是安全问题的复杂性,至今没有一个程序方法可以断定的,所以也只能把最后一道安全大门交给用户自己来管理了。无论如何,Leopard已经关注了这个问题,Leopard的这个功能官方的叫法是"Tagging Downloaded Applications",而这里给它一个简单的名字叫它"检疫"quarantine功能,下面可以看到这个叫法的原因。

下面这个图就是当你第一次从/Applications目录里面运行一个下载的app文件时,Leopard提示的

绝大多数下载的程序都是存放在dmg格式的打包文件里面,双击这个文件,OS X系统会自动将它绑定到一个卷上,下面这个图就是当你从这个卷运行程序时,leopard提示的

其中有一个选项,可以永久忽略这个提示。这一点和上面的是不一样。
仔细看,里面还提示我是用什么程序下载的; FireFox.

这个功能是如何实现的呢,下面我们就通过几个步骤看看揭开这内部的秘密:

首先呢,我们先看没有运行过的在Applications目录里面的程序
我们可以使用ls命令的选项来看看:
  1. $ls-ld@/Applications/Monolingual.app
  2. drwxr-xr-x@3schooladminadmin102Mar272008/Applications/Monolingual.app
  3. com.apple.quarantine46
其中的第三行的"com.apple.quarantine 46"是其它程序没有的。

我们运行该程序后,再来看看
  1. $ls-ld@/Applications/Monolingual.app
  2. drwxr-xr-x@3schooladminadmin102Mar272008/Applications/Monolingual.app
这次之剩下两行了。

而我们用同样的方法再看看绑定的卷中的同样的文件的情况:
  1. $ls-ld@/Volumes/Monolingual/Monolingual.app
  2. drwxr-xr-x3schooladminadmin102Mar272008/Volumes/Monolingual/Monolingual.app
大家发现没有里面没有那个"quarantine",怎么还是有那个提示呢?

我们再看看那个绑定卷的情况:
  1. $ls-ld@/Volumes/Monolingual/
  2. drwxr-xr-x13schooladminadmin510Mar272008/Volumes/Monolingual/
同样是没有,那么到底存在那里呢了?

我们看看那个dmg文件吧:
  1. $ls-ld@/Users/schooladmin/Desktop/Monolingual-1.3.9.dmg
  2. -rw-r--r--@1schooladminadmin1477183Dec1222:05/Users/schooladmin/Desktop/Monolingual-1.3.9.dmg
  3. com.apple.diskimages.recentcksum79
  4. com.apple.quarantine46
哈哈,有了,只不过是又多了一行, "com.apple.diskimages.recentcksum", 这个明显是存储着下载文件的校验码信息。
运行该程序并选中那个选项, 再来看看:
  1. $ls-ld@/Users/schooladmin/Desktop/Monolingual-1.3.9.dmg
  2. -rw-r--r--@1schooladminadmin1477183Dec1222:05/Users/schooladmin/Desktop/Monolingual-1.3.9.dmg
  3. com.apple.diskimages.recentcksum79
这回那个"quarantine"没有了。
通过这个我们知道了, 绑定的过程在内存中继承了"quarantine"的属性.

下面介绍一个新命令行CLI的命令:xattr就是用于操作这种extended attribute的
我们用它来察看详细的"quarantine"属性:
  1. $xattr-l/Users/schooladmin/Desktop/Monolingual-1.3.9.dmg
  2. com.apple.diskimages.recentcksum:i:788837on681640C5-B192-3AB1-BB5D-866B73EE3939@1229144748-CRC32:$9FE72ECF
  3. com.apple.quarantine:0000;494342a5;Firefox.app;|org.mozilla.firefox
看到了,里面还记载了下载程序的名称呢。

下面这个就是我们要说的最终要的命令行参数了,就是删除它:
  1. $xattr-dcom.apple.quarantine/Users/schooladmin/Desktop/Monolingual-1.3.9.dmg
再看看:
  1. xattr-l/Users/schooladmin/Desktop/Monolingual-1.3.9.dmg
  2. com.apple.diskimages.recentcksum:i:788837on681640C5-B192-3AB1-BB5D-866B73EE3939@1229144748-CRC32:$9FE72ECF
已经被删除了。这样在第一次运行的时候也不会提示了。
这样如果你在内部系统的几十、数百台机器上发布了一个被quarantine的程序,如何解除呢,就用这个命令吧。管理工作不再是恶梦了。

xattr命令的在线解释,它没有man页。
$ xattr -h
usage: xattr [-l] file [file ...]
xattr -p [-l] attr_name file [file ...]
xattr -w attr_name attr_value file [file ...]
xattr -d attr_name file [file ...]

The first form lists the names of all xattrs on the given file(s).
The second form (-p) prints the value of the xattr attr_name.
The third form (-w) sets the value of the xattr attr_name to attr_value.
The fourth form (-d) deletes the xattr attr_name.

options:
-h: print this help
-l: print long format (attr_name: attr_value)

这里有一个实现自动将一个目录里面的所有文件目录的"quarantine"属性删除的Applescript大家可以参考:
Applescript文件的实现: http://henrik.nyh.se/2007/10/lift-the-leopard-download-quarantine

忘了说了,本人更喜欢使用shell命令来完成工作,简单明了一些, 下面的命令就可以把指定目录(myfolder)里面的所有文件的quarantine属性都删除:
  1. find myfolder -print0|xargs-0xattr-dcom.apple.quarantine
还可以通过在.cshrc文件里加入下面的alias就可以变成一个命令行的命令了noquarantine:
  1. aliasnoquarantine'find!$-print0|xargs-0sudoxattr-dcom.apple.quarantine'


参考: http://www.macosxhints.com/article.php?story=20071029151619619
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics