FreeBSD下如何使用mutt连接gmail

FreeBSD下如何使用mutt连接gmail

电子邮件是一个很重要的通讯工具,很多人都有自己的电子邮件,google的gmail完全免费,而且空间很大,还允许用户使用客户端对其进行访问,这样就不需要直接登陆google的网站,非常方便,总之是优点多多。为了保证电子邮件的安全性,gmail的电子邮件服务器使用了SSL安全协议,目前多数图形界面的邮件客户端都直接支持这个协议,不需要用户进行某些特殊的设置,比如:Evolution。

这些图形界面的电子邮件客户端有许多优点,比如比较漂亮,比如很容易使用,可以很快的上手,但是也有一个共同的缺点:体积比较大,编译起来比较费劲。Mutt是一个非常小巧的电子邮件客户端,编译起来很容易,并且定制性非常的高,但是配置上稍微有点复杂,尤其是由于gmail使用了SSL协议,所以很多人在使用Mutt连接gmail的时候总是配置不好。

这个wiki页面主要介绍在FreeBSD系统下如何使用mutt将openssl、vim、gnupg、fetchmail、procmail、msmtp、ca_root_nss整合起来并连接到gmail,虽然是针对FreeBSD系统的,其中多数内容也适合各个Linux发行版本以及各个BSD分支,在其他系统上只需要做少量调整。

目标:

我们在这里,我们假设需要配置的gmail账号的详细信息如下:

gmail账号:fender0107401_2_gmail.com
gmail账号的密码:123456

其中:_2_等价于@,这么写是为了防止这个电子邮件被“机器人”给抓去了。

这个人订阅了很多FreeBSD的邮件列表,并且给每个邮件列表建立一个邮箱来保存,以此来方便自己管理自己的电子邮件,并且这个人不喜欢编译太大的软件,在经过几次对Evolution的编译以及升级之后,决定放弃Evolution而转向Mutt,于是乎他选择了mutt+fetchmail+procmail+msmtp+ca_root_nss+vim+gnupg这个解决方案,为了实现这个解决方案,他需要进行一些配置工作。在配置完成后,他决定把整个过程整理一下并写在wiki上,于是就有了这个wiki页面。

需要安装的port:

ca_root_nss:这port是第三方认证。
fetchmail:用来从gmail的邮件服务器上(pop.gmail.com)取回电子邮件(首先和服务器建立SSL连接);
procmail:由getchmail取会来的电子邮件,通过procmail进行分拣工作,分发的各自的邮箱去,比如你可以给freebsd-doc邮件列表单独制定一个邮箱,这样可以方便对邮件进行管理;
msmtp:用于发送电子邮件到gmail的邮件服务器(smtp.gmail.com)上去(首先和服务器建立SSL连接);
gnupg:用于对电子邮件进行加密,这样只有某个人才能察看文件的内容;或者是对电子邮件进行数字签名,这样别人可以通过你的gpg公钥开验证你的电子邮件是否被编辑过,如果被别人编辑过,数字签名验证就会失败。关于gnupg的加密模型或者说加密机制可以参考其主页:gnupg;
vim:用于编辑邮件,我是一个vim用户,几乎用vim和gvim写一切东西,写邮件虽然不需要什么太多高级功能,但是用习惯了,自然是选择vim来编辑邮件,你也可以指定任何一个你喜欢的编辑器来代替vim;
mutt:用于把上面的各个port串起来,或者说是集成起来。

SSL协议:

SSL是Secure Socket Layer的缩写,本质上一个协议,或者说是一个保证连接安全性的机制。所谓协议就是一个文本,目前有许多这个协议的实现方案,在开源世界里面我们自然使用开源的实现方案:OpenSSL。谈到OpenSSL这个SSL实现,我们应该感谢Eric Young和Tim Hudson这两个程序员,因为是他们开发并实现了OpenSSL。

为了保证能正确的配置成功,需要简单地了解一下OpenSSL这个协议在建立连接时需要哪些步骤,也就是客户端和服务器建立连接时“握手”的基本过程。

游戏角色:

客户端:提出建立ssl连接的人;
服务器:提供ssl服务的人;
第三方认证机构:第三方认证机构签发数字证书,客户端使用这个证书对服务器所发送来的公钥进行验证,保证的确是目标服务器。

游戏规则:

客户机对目标服务器提出建立ssl连接的申请,告诉服务器自己所能支持的加密方案;
服务器收到申请以后,从客户机所支持的加密方案里面选择一个最安全的,作为本次连接的加密方案;然后把自己的公钥发送给客户端;
客户端收到公钥以后,使用第三方认证来验证这个收到的服务器公钥,如果验证成功就使用这个收到的服务器公钥加密一个随机数后发送给服务器,作为对称加密的对称加密的密钥;
服务器接受到这个加密的随机数以后,使用自己的私钥解密,作为对称加密的密钥;
自此之后服务器和客户端之间使用对称加密来进行加密的通信连接,也就是连接建立成功了;
在上述过程中,任何一个环节的失败都会导致链接失败。

总结一下:首先使用“非对称加密”,然后使用“对称加密”;第三方认证机构确保用户在“非对称加密”过程中使用正确的服务器“公钥”;在“对称加密”过程中使用的“对称密钥”由“非对称加密过程”来传递。

注:

这是只是一个很简单的介绍,实际中连接的建立过程比这个要复杂一些,另外还可能有一些变化(用于减少服务器负担)。我看到过有人说SSL协议并不安全,我并没有仔细的研究过,但是从上面的“握手”过程来看,还是比较安全的,关于SSL的详细内容可以参考相关资料。

配置任务:

任务1:安装第三方认证

我最开始写这个wiki的时候,按认证是比较麻烦的,需要一些手工操作,现在要简单多了,只需要安装ca_root_nss这个port就可以了,这个port里面包含了很多的第三方认证。

# cd /usr/ports/security/ca_root_nss
# make install clean

安装的时候会问题是否”Add symlink to /etc/ssl/cert.pem”。

如果添加,那么/etc/ssl/cert.pem就是一个符号连结。

$ file /etc/ssl/cert.pem
/etc/ssl/cert.pem: symbolic link to `/usr/local/share/certs/ca-root-nss.crt’

任务2:安装并配置msmtp

安装:

安装方法:

# cd /usr/ports/mail/msmtp
# make install clean

注意一定打开GNUTLS的支持,我们需要使用这个协议来进行加密连接。

配置:

配置就是写.msmtprc这个文件,我的.msmtprc文件内容如下,使用时注意换成自己的账号和密码就可以了,还需要注意的是自己的第三方认证放在哪里了以及自己的msmtplog保存在什么地方,因为你可能选择和我不同目录:

# set default values

defaults

tls on

tls_starttls on

tls_trust_file /usr/local/share/certs/ca-root-nss.crt # 这里是设定认证文件的位置。

logfile /home/fender/Mail/.msmtp.log

# set my first account

account fender0107401

host smtp.gmail.com

port 587

from fender0107401_2_gmail.com

auth on

user fender0107401

password 123456

# set a default account

account default : fender0107401

注意,写好配置文件以后要修改文件的权限:

$ chmod 600 .msmtprc

现在:发邮件的问题解决了。

任务3:安装并配置fetchmail

安装:

# cd /usr/ports/mail/fetchmail
# make install clean

配置:

配置就是写.fetchmailrc这个文件,我的.fetchmailrc文件内容如下,使用时注意换成自己的账号和密码就可以了,还有就是要注意自己的第三方认证位置:

poll pop.gmail.com

port 995

proto POP3

user ‘fender0107401_2_gmail.com’

password ‘123456’

options

no keep

ssl

sslcertck

注意,写好配置文件以后要修改文件的权限:

$ chmod 600 .fetchmailrc

现在:收邮件的问题解决了。

任务4:安装并配置procmail

安装:

# cd /usr/ports/mail/procmail
# make install clean

配置:

我主要是接收各种订阅的电子邮件列表,通过procmail来进行分拣工作,我的.procmailrc配置文件如下,使用时注意调整目录设置:

################################################################################
PATH=$HOME/bin:/usr/bin:/usr/local/bin:

MAILDIR=$HOME/mail

LOGFILE=$MAILDIR/.procmaillog

################################################################################
# FreeBSD mailing list:
:0
* ^List-Id:.*freebsd-announce
1_freebsd-announce

:0
* ^List-Id:.*freebsd-security-notifications
1_freebsd-security-notifications

:0
* ^List-Id:.*freebsd-amd64
1_freebsd-amd64

:0
* ^List-Id:.*freebsd-doc
1_freebsd-doc

:0
* ^List-Id:.*freebsd-gnome
1_freebsd-gnome

:0
* ^List-Id:.*freebsd-performance
1_freebsd-performance

:0
* ^List-Id:.*freebsd-security
1_freebsd-security

:0
* ^List-Id:.*cnproj-cvs
1_cnproj-cvs

:0
* ^List-Id:.*cnproj-submit
1_cnproj-submit

################################################################################
# Gnu Octave mailing list:

:0
* ^List-Id:.*bug-octave
2_bug-octave
:0
* ^List-Id:.*help-octave
2_help-octave
:0
* ^List-Id:.*octave-maintainers
2_octave-maintainers

################################################################################
:0
* .*
3_default

################################################################################

关于procmail的语法可以参考FreeBSD Handbook中Electronic Mail的相关内容。

现在:分拣邮件的问题解决了。

任务5:安装并配置mutt

安装:

# cd /usr/ports/mail/mutt
# make install clean

配置:

mutt的配置工作主要是通过.muttrc来实现,详细的各种配置选项可以参考下述连接:

mutt_manual

muttrc_example

我把自己的.muttrc中一些比较基本的配置写出来,方便大家参考:

# Personal information
set hostname=PC-686.Workstation

定义系统名。

set realname=Li

定义用户名。

my_hdr From:fender0107401_2_gmail.com

定义我的电子邮件地址。

# sendmail
set sendmail="/usr/local/bin/msmtp"

定义msmtp来发送电子邮件。

# fetchmail and procmail
macro index G "!fetchmail -a -m ‘procmail -d %T’\r"

定义使用fetchmail来接受电子邮件,接受以后使用procmail来分拣邮件。

# GnuPG
source usr/local/share/examples/mutt/gpg.rc

使用gnupg。

set editor="vim"

定义vim作为我编辑器。

set index_format="| %4C | %Z | %{%b %d} | %-15.15L | %s"

定义index的显示方式。

set folder_format="| %2C | %t %N | %8s | %d | %f"

定义邮箱的显示方式,一定要有%N,否则没法知道哪个有新邮件。

.muttrc内容汇总:

# Personal information
set hostname=PC-686.Workstation

set realname=Li

my_hdr From:fender0107401_2_gmail.com

# sendmail
set sendmail="/usr/local/bin/msmtp"

# fetchmail and procmail
macro index G "!fetchmail -a -m ‘procmail -d %T’\r"

# GnuPG
source usr/local/share/examples/mutt/gpg.rc

set editor="vim"

set index_format="| %4C | %Z | %{%b %d} | %-15.15L | %s"

set folder_format="| %2C | %t %N | %8s | %d | %f"

注意事项:

必须打开防火墙,以我使用的ipfw为例,需要在防火墙规则中添加下述内容:
$cmd 00700 allow tcp from any to any 587 out via $nic setup $ks
$cmd 00800 allow tcp from any to any 995 out via $nic setup $ks

其中,$ks和$nic是我设定的变量,$ks的定义如下:

ks="keep-state"

$nic代表我的网卡,定义如下:

nic="re0"

mutt的配置选项很多,我没有都写出来,详细的可以参考下述连接。

mutt_manual

muttrc_example

后记:

现在,打开一个虚拟终端,比如gnome-terminal,然后运行mutt,

G将会下载你的邮件;
如果有新邮件mutt会在相应邮箱前显示一个N;
想发送邮件就按m,编辑以后使用p键可以使用gnupg对其签名;
我并没有写如何安装vim或者是如何使用gnupg,而是直接假设使用者知道如何使用gnupg,相关内容需要可以参考vim或者是gnupg的文档;
有意思的事情还有很多,需要慢慢的探索,我不能把mutt所有的功能都写出来,因为实在是太多太多了,可以定制显示的颜色,可以定义显示邮件的哪些部分,可以指定如何排序……
欢迎补充。

FreeBSD 9.0-BETA3 发布

FreeBSD是类UNIX操作系统,它基于加州伯克利大学的“4.4BSD-Lite”发行并带有一些“4.4BSD-Lite2”增强,面向 i386、amd64、IA-64、arm、MIPS、powerpc、ppc64、PC-98、UltraSPARC等平台。它还间接地基于 “386BSD”,此乃William Jolitz对加州伯克利大学的“Net/2”往i386系统上的移植,尽管如今只有极少的代码保留下来。FreeBSD被全世界的公司、因特网服务提供 商、科研人员、计算机专家、学生、家庭用户等用于他们的工作、教育、娱乐中。FreeBSD带有20000多个软件包,它们是预编译和打包好了、便于安装 的软件,并覆盖了广阔的应用领域:服务器软件、数据库和网页服务器、桌面软件、游戏、网络浏览器和商务软件,而这一切都是免费和易于安装的。
发行说明:
http://lists.freebsd.org/pipermail/freebsd-stable/2011-September/064030.html
下载地址:
FreeBSD-9.0-BETA3-i386-dvd1.iso (500MB, SHA256)
FreeBSD-9.0-BETA3-amd64-dvd1.iso (610MB, SHA256)

FreeBSD-SA-11:05.unix

—–BEGIN PGP SIGNED MESSAGE—–
Hash: SHA1

=============================================================================
FreeBSD-SA-11:05.unix                                       Security Advisory
                                                          The FreeBSD Project

Topic:          Buffer overflow in handling of UNIX socket addresses

Category:       core
Module:         kern
Announced:      2011-09-28
Credits:        Mateusz Guzik
Affects:        All supported versions of FreeBSD.
Corrected:      2011-09-28 08:47:17 UTC (RELENG_7, 7.4-STABLE)
                2011-09-28 08:47:17 UTC (RELENG_7_4, 7.4-RELEASE-p3)
                2011-09-28 08:47:17 UTC (RELENG_7_3, 7.3-RELEASE-p7)
                2011-09-28 08:47:17 UTC (RELENG_8, 8.2-STABLE)
                2011-09-28 08:47:17 UTC (RELENG_8_2, 8.2-RELEASE-p3)
                2011-09-28 08:47:17 UTC (RELENG_8_1, 8.1-RELEASE-p5)
                2011-09-28 08:47:17 UTC (RELENG_9, 9.0-RC1)

For general information regarding FreeBSD Security Advisories,
including descriptions of the fields above, security branches, and the
following sections, please visit <URL:http://security.FreeBSD.org/>.

I.   Background

UNIX-domain sockets, also known as "local" sockets, are a mechanism for
interprocess communication.  They are similar to Internet sockets (and
utilize the same system calls) but instead of relying on IP addresses
and port numbers, UNIX-domain sockets have addresses in the local file
system address space.

II.  Problem Description

When a UNIX-domain socket is attached to a location using the bind(2)
system call, the length of the provided path is not validated.  Later,
when this address was returned via other system calls, it is copied into
a fixed-length buffer.

III. Impact

A local user can cause the FreeBSD kernel to panic.  It may also be
possible to execute code with elevated privileges ("gain root"), escape
from a jail, or to bypass security mechanisms in other ways.

IV.  Workaround

No workaround is available, but systems without untrusted local users
are not vulnerable.

V.   Solution

Perform one of the following:

1) Upgrade your vulnerable system to 7-STABLE or 8-STABLE, or to
the RELENG_8_2, RELENG_8_1, RELENG_7_4, or RELENG_7_3 security
branch dated after the correction date.

2) To update your vulnerable system via a source code patch:

The following patch has been verified to apply to FreeBSD 7.4, 7.3,
8.2 and 8.1 systems.

a) Download the relevant patch from the location below, and verify the
detached PGP signature using your PGP utility.

# fetch http://security.FreeBSD.org/patches/SA-11:05/unix.patch
# fetch http://security.FreeBSD.org/patches/SA-11:05/unix.patch.asc

b) Apply the patch.

# cd /usr/src
# patch < /path/to/patch

c) Recompile your kernel as described in
<URL:http://www.FreeBSD.org/handbook/kernelconfig.html> and reboot the
system.

3) To update your vulnerable system via a binary patch:

Systems running 7.4-RELEASE, 7.3-RELEASE, 8.2-RELEASE, or 8.1-RELEASE on
the i386 or amd64 platforms can be updated via the freebsd-update(8)
utility:

# freebsd-update fetch
# freebsd-update install

VI.  Correction details

The following list contains the revision numbers of each file that was
corrected in FreeBSD.

CVS:

Branch                                                           Revision
  Path
– ————————————————————————-
RELENG_7
  src/sys/kern/uipc_usrreq.c                                   1.206.2.13
RELENG_7_4
  src/UPDATING                                             1.507.2.36.2.5
  src/sys/conf/newvers.sh                                   1.72.2.18.2.8
  src/sys/kern/uipc_usrreq.c                               1.206.2.11.4.2
RELENG_7_3
  src/UPDATING                                             1.507.2.34.2.9
  src/sys/conf/newvers.sh                                  1.72.2.16.2.11
  src/sys/kern/uipc_usrreq.c                               1.206.2.11.2.2
RELENG_8
  src/sys/kern/uipc_usrreq.c                                    1.233.2.6
RELENG_8_2
  src/UPDATING                                             1.632.2.19.2.5
  src/sys/conf/newvers.sh                                   1.83.2.12.2.8
  src/sys/kern/uipc_usrreq.c                                1.233.2.2.2.2
RELENG_8_1
  src/UPDATING                                             1.632.2.14.2.8
  src/sys/conf/newvers.sh                                   1.83.2.10.2.9
  src/sys/kern/uipc_usrreq.c                                1.233.2.1.4.2
RELENG_9
  src/sys/kern/uipc_usrreq.c                                    1.244.2.2
– ————————————————————————-

Subversion:

Branch/path                                                      Revision
– ————————————————————————-
stable/7/                                                         r225827
releng/7.4/                                                       r225827
releng/7.3/                                                       r225827
stable/8/                                                         r225827
releng/8.2/                                                       r225827
releng/8.1/                                                       r225827
stable/9/                                                         r225827
– ————————————————————————-

The latest revision of this advisory is available at
http://security.FreeBSD.org/advisories/FreeBSD-SA-11:05.unix.asc
—–BEGIN PGP SIGNATURE—–
Version: GnuPG v2.0.18 (FreeBSD)

iEYEARECAAYFAk6C4nUACgkQFdaIBMps37J5lwCgnq8BUBWckn0ZKMcsK5IDKMDV
ocgAn0PwSvoKxjGY4dgHlM1M6xVM8OWz
=AO92
—–END PGP SIGNATURE—–

原文链接:http://security.freebsd.org/advisories/FreeBSD-SA-11:05.unix.asc

FreeBSD-SA-11:04.compress.asc

—–BEGIN PGP SIGNED MESSAGE—–
Hash: SHA1

=============================================================================
FreeBSD-SA-11:04.compress                                   Security Advisory
                                                          The FreeBSD Project

Topic:          Errors handling corrupt compress file in compress(1)
                and gzip(1)

Category:       core
Module:         compress
Announced:      2011-09-28
Credits:        Tomas Hoger, Joerg Sonnenberger
Affects:        All supported versions of FreeBSD.
Corrected:      2011-09-28 08:47:17 UTC (RELENG_7, 7.4-STABLE)
                2011-09-28 08:47:17 UTC (RELENG_7_4, 7.4-RELEASE-p3)
                2011-09-28 08:47:17 UTC (RELENG_7_3, 7.3-RELEASE-p7)
                2011-09-28 08:47:17 UTC (RELENG_8, 8.2-STABLE)
                2011-09-28 08:47:17 UTC (RELENG_8_2, 8.2-RELEASE-p3)
                2011-09-28 08:47:17 UTC (RELENG_8_1, 8.1-RELEASE-p5)
                2011-09-28 08:47:17 UTC (RELENG_9, 9.0-RC1)
CVE Name:       CVE-2011-2895

For general information regarding FreeBSD Security Advisories,
including descriptions of the fields above, security branches, and the
following sections, please visit <URL:http://security.FreeBSD.org/>.

I.   Background

The compress utility reduces the size of files using adaptive Lempel-Ziv
coding, or LZW coding, a lossless data compression algorithm.

Both compress(1) and gzip(1) uses code derived from 4.3BSD compress(1).

II.  Problem Description

The code used to decompress a file created by compress(1) does not do
sufficient boundary checks on compressed code words, allowing reference
beyond the decompression table, which may result in a stack overflow or
an infinite loop when the decompressor encounters a corrupted file.

III. Impact

An attacker who can cause a corrupt archive of his choice to be parsed
by uncompress(1) or gunzip(1), can cause these utilities to enter an
infinite loop, to core dump, or possibly to execute arbitrary code
provided by the attacker.

IV.  Workaround

No workaround is available, but systems not handling adaptive Lempel-Ziv
compressed files (.Z) from untrusted source are not vulnerable.

V.   Solution

Perform one of the following:

1) Upgrade your vulnerable system to 7-STABLE or 8-STABLE, or to
the RELENG_8_2, RELENG_8_1, RELENG_7_4, or RELENG_7_3 security
branch dated after the correction date.

2) To update your vulnerable system via a source code patch:

The following patches have been verified to apply to FreeBSD 7.4, 7.3,
8.2 and 8.1 systems.

a) Download the relevant patch from the location below, and verify the
detached PGP signature using your PGP utility.

# fetch http://security.FreeBSD.org/patches/SA-11:04/compress.patch
# fetch http://security.FreeBSD.org/patches/SA-11:04/compress.patch.asc

b) Execute the following commands as root:

# cd /usr/src
# patch < /path/to/patch
# cd /usr/src/usr.bin/compress
# make obj && make depend && make && make install
# cd /usr/src/usr.bin/gzip
# make obj && make depend && make && make install

3) To update your vulnerable system via a binary patch:

Systems running 7.4-RELEASE, 7.3-RELEASE, 8.2-RELEASE, or 8.1-RELEASE on
the i386 or amd64 platforms can be updated via the freebsd-update(8)
utility:

# freebsd-update fetch
# freebsd-update install

VI.  Correction details

The following list contains the revision numbers of each file that was
corrected in FreeBSD.

CVS:

Branch                                                           Revision
  Path
– ————————————————————————-
RELENG_7
  src/usr.bin/compress/zopen.c                                  1.12.10.1
  src/usr.bin/gzip/zuncompress.c                                  1.1.4.3
RELENG_7_4
  src/UPDATING                                             1.507.2.36.2.5
  src/sys/conf/newvers.sh                                   1.72.2.18.2.8
  src/usr.bin/compress/zopen.c                                  1.12.26.2
  src/usr.bin/gzip/zuncompress.c                              1.1.4.1.4.2
RELENG_7_3
  src/UPDATING                                             1.507.2.34.2.9
  src/sys/conf/newvers.sh                                  1.72.2.16.2.11
  src/usr.bin/compress/zopen.c                                  1.12.24.2
  src/usr.bin/gzip/zuncompress.c                              1.1.4.1.2.2
RELENG_8
  src/usr.bin/compress/zopen.c                                  1.12.22.2
  src/usr.bin/gzip/zuncompress.c                                  1.2.2.3
RELENG_8_2
  src/UPDATING                                             1.632.2.19.2.5
  src/sys/conf/newvers.sh                                   1.83.2.12.2.8
  src/usr.bin/compress/zopen.c                              1.12.22.1.6.2
  src/usr.bin/gzip/zuncompress.c                              1.2.2.1.6.2
RELENG_8_1
  src/UPDATING                                             1.632.2.14.2.8
  src/sys/conf/newvers.sh                                   1.83.2.10.2.9
  src/usr.bin/compress/zopen.c                              1.12.22.1.4.2
  src/usr.bin/gzip/zuncompress.c                              1.2.2.1.4.2
RELENG_9
  src/usr.bin/compress/zopen.c                                   1.16.2.2
  src/usr.bin/gzip/zuncompress.c                                  1.4.2.2
– ————————————————————————-

Subversion:

Branch/path                                                      Revision
– ————————————————————————-
stable/7/                                                         r225827
releng/7.4/                                                       r225827
releng/7.3/                                                       r225827
stable/8/                                                         r225827
releng/8.2/                                                       r225827
releng/8.1/                                                       r225827
stable/9/                                                         r225827
– ————————————————————————-

VII. References

http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-2895

The latest revision of this advisory is available at
http://security.FreeBSD.org/advisories/FreeBSD-SA-11:04.compress.asc
—–BEGIN PGP SIGNATURE—–
Version: GnuPG v2.0.18 (FreeBSD)

iEYEARECAAYFAk6C4nIACgkQFdaIBMps37LymQCgmW2YYsSqvjxhiuHXt0bCcCgd
K5YAnA0/Z8++C6TKtUJ5Bzogd80a9OEd
=I+0k
—–END PGP SIGNATURE—–

原文链接:http://security.freebsd.org/advisories/FreeBSD-SA-11:04.compress.asc

FreeBSD-SA-11:03.bind

—–BEGIN PGP SIGNED MESSAGE—–
Hash: SHA1

=============================================================================
FreeBSD-SA-11:03.bind Security Advisory
The FreeBSD Project

Topic: Remote packet Denial of Service against named(8) servers

Category: contrib
Module: bind
Announced: 2011-09-28
Credits: Roy Arends
Affects: 8.2-STABLE after 2011-05-28 and prior to the correction date
Corrected: 2011-07-06 00:50:54 UTC (RELENG_8, 8.2-STABLE)
CVE Name: CVE-2011-2464

Note: This advisory concerns a vulnerability which existed only in
the FreeBSD 8-STABLE branch and was fixed over two months prior to the
date of this advisory.

For general information regarding FreeBSD Security Advisories,
including descriptions of the fields above, security branches, and the
following sections, please visit <URL:http://security.FreeBSD.org/>.

I. Background

BIND 9 is an implementation of the Domain Name System (DNS) protocols.
The named(8) daemon is an Internet Domain Name Server.

II. Problem Description

A logic error in the BIND code causes the BIND daemon to accept bogus
data, which could cause the daemon to crash.

III. Impact

An attacker able to send traffic to the BIND daemon can cause it to
crash, resulting in a denial of service.

IV. Workaround

No workaround is available, but systems not running the BIND name server
are not affected.

V. Solution

Upgrade your vulnerable system to 8-STABLE dated after the correction
date.

VI. Correction details

The following list contains the revision numbers of each file that was
corrected in FreeBSD.

CVS:

Branch Revision
Path
– ————————————————————————-
RELENG_8
src/contrib/bind9/lib/dns/message.c 1.3.2.3
– ————————————————————————-

Subversion:

Branch/path
Revision
– ————————————————————————-
stable/8/ r223815
– ————————————————————————-

VII. References

http://www.isc.org/software/bind/advisories/cve-2011-2464 http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-2464
The latest revision of this advisory is available at
http://security.FreeBSD.org/advisories/FreeBSD-SA-11:03.bind.asc —–BEGIN PGP SIGNATURE—–
Version: GnuPG v2.0.18 (FreeBSD)

iEYEARECAAYFAk6C4CYACgkQFdaIBMps37LwQgCeIDVGsCWOLoVdmWogOOaPC1UG
9G8AoJPlRbNmkEWMg7uoOYrvjWlRRdlK
=aUvD
—–END PGP SIGNATURE—–

原文链接:http://security.freebsd.org/advisories/FreeBSD-SA-11:03.bind.asc

FreeBSD下如何使用移动硬盘

FreeBSD下如何使用移动硬盘

摘要

这个Wiki页面主要介绍如何在FreeBSD系统下面使用USB接口的移动硬盘。

FreeBSD使用移动硬盘的不同方式

严格的说FreeBSD系统只提供了一种使用移动硬盘的方式,但是很多桌面用户都会运行X。

X系统同样提供挂载移动硬盘的方法,比如我用Xorg+GNOME,我也可以使用HALD来挂载移动硬盘。

在这里,我们只介绍如何使用FreeBSD系统提供的方法来挂载移动硬盘。

基本步骤

在FreeBSD系统下面使用移动硬盘并不复杂,只需要几个基本的配置即可实现。

添加内核支持

很显然,不论你使用什么设备,你都需要将其添加进入内核(直接进内核或编译成模块)。

这里我们使用的是USB接口的硬盘,所以就需要添加对USB设备的支持。

简单的说,你需要在内核的配置文件里面添加下述内容:

device scbus
device da
device pass
device uhci
device ohci
device ehci
device usb
device umass

使用默认内核的用户可以无视这个操作,因为默认内核是提供对USB设备的支持。

详细情况可参考FreeBSD Handbook。

完成上述操作之后你的系统就能识别你的移动硬盘了。

对移动硬盘进行分区

如何分区是用户的问题了,这里只介绍如何使用UFS文件系统。

插入移动硬盘,然后用root用户运行sysinstall。
Condigure → Fdisk → 然后设定你喜欢的Slice分区方式,比如我整个移动硬盘都是用UFS,我就直接选择Use Entire Disk;然后,选择Write Changes;然后,选择Do not install a boot manager;然后退出sysinstall。

再次运行sysinstall,注意我说的是再次运行sysinstall。
Condigure → Label → 然后设定你喜欢的Partition分区方式,最后选择Write。

需要注意的是,在这个步骤中,你需要设定新建Partition的挂载位置,你最好选在挂载在/tmp下面,如果你选在挂载在root目录下面,系统就会在root下面创建目录,当然你可以自己删除那个没用的目录。

如果你的rc.conf里面有下述内容,系统开机时会自动清理/tmp目录:

clear_tmp_enable="YES"

我的分区方式是整个移动硬盘只有一个Slice,然后这个Slice里面有3个Partition。

对应/dev目录下面的

da0
da0s1
da0s1d
da0s1e
da0s1f

普通用户挂载

多数情况下,没有人使用root用户进行日常的操作,所以我们必须使用普通用户来挂载以及卸载移动硬盘。

把下述内容添加进入/etc/devfs.rules:
[localrules=5]
add path ‘da*’ mode 0660 group operator

告诉系统operator组可以挂载。

注意是/etc/devfs.rules,不是/etc/devfs.conf。后者用于控制开机就存在的设备,前者用于控制可插拔的设备。

把下述内容添加进入/etc/rc.conf:
devfs_system_ruleset="localrules"

告诉系统使用/etc/devfs.rules中设定的规则。

把下述内容添加进入/etc/sysctl.conf:
vfs.usermount=1

告诉系统普通用户可以挂载。

设定移动硬盘分区的权限
设定权限比较简单,你可以在/mnt目录下面建立自己的文件夹用于挂载自己的移动硬盘,比如我的/mnt目录下面有5个文件夹:

> ls /mnt/
fender_01    fender_02    fender_03    fender_04    fender_05

首先你需要使用root用户来手工挂载移动硬盘分区到fender_01,fender_02,fender_03。

# cd /mnt/
# mount /dev/da0s1d fender_01
# mount /dev/da0s1e fender_02
# mount /dev/da0s1f fender_03

然后你需要设定fender_01,fender_02,fender_03这三个目录的权限。

# cd /mnt/
# chown fender:operator *

注意,fender这个用户在operator组里面。

# pw group mod operator -m fender

完成上述操作你就可以使用fender这个用户来挂载移动硬盘了。

防止HALD挂载移动硬盘

既然本文开始就说明了使用FreeBSD系统提供的基本方法来挂载移动硬盘,我们就需要防止HALD来挂载移动硬盘。

屏蔽方法如下,在/usr/local/share/hal/fdi/preprobe/20thirdparty目录,

建立da.fdi文件并写入:
<?xml version="1.0" encoding="UTF-8"?>

<deviceinfo version="0.2">
  <device>
    <match key="freebsd.driver" string="da">
      <match key="freebsd.unit" int="0">
        <merge key="info.ignore" type="bool">true</merge>
      </match>
    </match>
  </device>
</deviceinfo>

这个文件用于防止HALD挂载移动硬盘。

建立acd.fdi文件并写入:
<?xml version="1.0" encoding="UTF-8"?>
<deviceinfo version="0.2">
  <device>
    <match key="freebsd.driver" string="acd">
      <match key="freebsd.unit" int="0">
        <merge key="info.ignore" type="bool">true</merge>
      </match>
    </match>
  </device>
</deviceinfo>

这个文件用于防止HALD挂载我的光驱(和移动硬盘关系不大)。

如果你没有按照X,那么你可以直接无视这个步骤。

弄一个自动挂载和卸载的脚本

都弄好了就在弄一个脚本吧,省着天天敲命令,一方面是比较麻烦,另外一方面是周围人看着比较奇怪(你看那个变态,用个移动硬盘还得得瑟着敲半天键盘,真能装,)。

> cd
> cd bin/
> cat mount_rhd.sh
#! /bin/sh
mount /dev/da0s1d /mnt/fender_01;
mount /dev/da0s1e /mnt/fender_02;
mount /dev/da0s1f /mnt/fender_03;
> cat umount_rhd.sh
#! /bin/sh
sync;
umount /mnt/fender_01;
umount /mnt/fender_02;
umount /mnt/fender_03;

当然了这个脚本应该放在你的shell能找到的地方了,比如我就放在自己home下面的bin里面,然后把这个bin加到自己shell程序的搜索目录就行了。

最后开个小玩笑,不要以为最后那段代码里面第一个cd命令是多余的,那个cd命令是用于会到自己home的。

原文链接:http://wiki.freebsdchina.org/doc/b/removable_disk_usage

FreeBSD 9.0-BETA2 发布

FreeBSD是类UNIX操作系统,它基于加州伯克利大学的“4.4BSD-Lite”发行并带有一些“4.4BSD-Lite2”增强,面向 i386、amd64、IA-64、arm、MIPS、powerpc、ppc64、PC-98、UltraSPARC等平台。它还间接地基于 “386BSD”,此乃William Jolitz对加州伯克利大学的“Net/2”往i386系统上的移植,尽管如今只有极少的代码保留下来。FreeBSD被全世界的公司、因特网服务提供 商、科研人员、计算机专家、学生、家庭用户等用于他们的工作、教育、娱乐中。FreeBSD带有20000多个软件包,它们是预编译和打包好了、便于安装 的软件,并覆盖了广阔的应用领域:服务器软件、数据库和网页服务器、桌面软件、游戏、网络浏览器和商务软件,而这一切都是免费和易于安装的。

发行说明:
http://lists.freebsd.org/pipermail/freebsd-stable/2011-September/063841.html

下载地址:
FreeBSD-9.0-BETA2-i386-dvd1.iso (498MB, SHA256)
FreeBSD-9.0-BETA2-amd64-dvd1.iso (607MB, SHA256)

FreeBSD PostgreSQL 9 Hot Standby 实践

FreeBSD PostgreSQL 9 Hot Standby 实践

注:PostgreSQL 9 Hot Standby的关键点有2个,工作模式和操作顺序,除了概念的理解。

一、安装PostgreSQL 9

portmaster -d databases/postgresql90-server
修改/etc/login.conf
postgres:\
:lang=en_US.UTF-8:\
:setenv=LC_COLLATE=C:\
:tc=default:
执行cap_mkdb /etc/login.conf

二、初始化主数据库

su pgsql
/usr/local/bin/initdb -D /usr/local/pgsql/data –locale=C -E UTF8 初始化
修改postgresql.conf:
wal_level = hot_standby
max_wal_senders = 1
wal_keep_segments = 32
log_destination = ‘stderr’
logging_collector = on
log级别根据需要设置,建议debug1下一级别即可(log,info)
修改pg_hba.conf:
host replication pgsql 127.0.0.1/32 trust

三、启动主数据库

/usr/local/bin/postmaster -D /usr/local/pgsql/data
看看日志,已经起来:
LOG: database system is ready to accept connections
LOG: autovacuum launcher started

四、基础备份:

流程:在主数据库服务器执行 pg_start_backup(),复制data目录,再执行
pg_stop_backup()。
$ psql -d postgres
postgres=# select pg_start_backup(”);
这个时候,所有请求在写日志之后不会再刷新到磁盘。除非pg_stop_backup()这个函数
被执行。
接下来,把data目录直接复制data2,这个目录将通过scp、rsync等工具同步到节点服
务器,data2就是基础备份的内容。
cd /usr/loca/pgsql
cp -R data/ data2

五、创建节点数据库(Standby)

cd data2
修改postgres.conf
port = 54321
hot_standby = on
增加recovery.conf
standby_mode = ‘on’
primary_conninfo = ‘host=127.0.0.1 port=5432 user=pgsql’
rm postmaster.pid

六、停止主数据库基础备份

postgres=# select pg_stop_backup();
现在数据会写入磁盘,当节点服务器启动后,他会自动连接到主服务器,拉取主服务器
自基础备份后的事务日志。然后,对事务日志进行重演,从而达到恢复数据的效果。

七、启动节点数据库

/usr/local/bin/postmaster -D /usr/local/pgsql/data2
看看日志:
DEBUG: initializing for hot standby
LOG: streaming replication successfully connected to primary
DEBUG: end of backup reached
LOG: consistent recovery state reached at 0/3000000
LOG: database system is ready to accept read only connections

八、测试。

FreeBSD下通过smartcl和sendEmail实现硬盘健康监控通知

FreeBSD下通过smartcl和sendEmail实现硬盘健康监控通知

通过smatctl检查硬盘的S.M.A.R.T.状态,并通过sendEmail向管理员发送邮件报告。

安装相关软件

smartctl

smartctl是非常全面的硬盘S.M.A.R.T.检查工具

cd /usr/ports/sysutils/smartmontools/ && make install clean

sendEmail

sendEmail是一款小巧便捷的邮件工具,支持smtp

cd /usr/ports/net/sendemail/&& make install clean && rehash

这2个软件安装后均无需额外配置即可实现本文功能

编写脚本

#!/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin

  ##变量根据自己情况修改##
  #smtp服务器地址#
smtpadd="smtp.yourmail.com"
  #smtp登录用户#
smtpusr="username"
  #smtp用户密码#
smtppass="password"
  #发件人邮箱#
sender="sneder@yourmail.com"
  #收件人邮箱#
rcver="rcver@yourmail.com"
  #临时日志,用于记录smartctl输出信息#
tmplog="/tmp/my_disks_smart.log"
  #获取主机名,对服务器加以区分#
myhost=`hostname`

  ##列出本机所有硬盘##
dsks=`geom disk status\
| grep -Ev ‘cd[0-9]|^Name.*’\
| awk ‘{print "/dev/" $1}’`

  ##查询每个硬盘的S.M.A.R.T.健康简况,并保存在临时日志中##
for i in ${dsks}
do
smartinfo=`smartctl -H ${i}\
  | grep -Ev ‘^$|===|^smartctl|^Copyright’`
echo ${i} : ${smartinfo} >> ${tmplog}
done

  ##通过邮件报告硬盘健康简况##
email_notify=`sendEmail\
-f ${sender}\
-s ${smtpadd}\
-xu ${smtpusr}\
-xp ${smtppass}\
-t ${rcver}\
-u "disks_smart of ${myhost} at $(date +%Y-%m-%d)"\
-o message-file=${tmplog}\
| grep  sent\ successfully!`

  ##发送后的处理,成功即删除临时日志,失败则添加记录##
if [ ! "${email_notify}" ]
then
  echo "email send fail" >> ${tmplog}
  chmod 600 ${tmplog}
else
  rm ${tmplog}
fi
exit 0

给脚本执行权限

加入cron执行

编辑/etc/crontab

@daily root /path/to/your/script

原文链接:http://wiki.freebsdchina.org/howto/s/smartctl_sendemail

FreeBSD-SA-11:02.bind

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

=============================================================================
FreeBSD-SA-11:02.bind                                       Security Advisory
                                                          The FreeBSD Project

Topic:          BIND remote DoS with large RRSIG RRsets and negative caching

Category:       contrib
Module:         bind
Announced:      2011-05-28
Credits:        Frank Kloeker, Michael Sinatra.
Affects:        All supported versions of FreeBSD.
Corrected:      2011-05-28 00:58:19 UTC (RELENG_7, 7.4-STABLE)
                2011-05-28 08:44:39 UTC (RELENG_7_3, 7.3-RELEASE-p6)
                2011-05-28 08:44:39 UTC (RELENG_7_4, 7.4-RELEASE-p2)
                2011-05-28 00:33:06 UTC (RELENG_8, 8.2-STABLE)
                2011-05-28 08:44:39 UTC (RELENG_8_1, 8.1-RELEASE-p4)
                2011-05-28 08:44:39 UTC (RELENG_8_2, 8.2-RELEASE-p2)
CVE Name:       CVE-2011-1910

For general information regarding FreeBSD Security Advisories,
including descriptions of the fields above, security branches, and the
following sections, please visit <URL:http://security.FreeBSD.org/>.

I.   Background

BIND 9 is an implementation of the Domain Name System (DNS) protocols.
The named(8) daemon is an Internet Domain Name Server.

DNS Security Extensions (DNSSEC) provides data integrity, origin
authentication and authenticated denial of existence to resolvers.

II.  Problem Description

Very large RRSIG RRsets included in a negative response can trigger
an assertion failure that will crash named(8) due to an off-by-one error
in a buffer size check.

III. Impact

If named(8) is being used as a recursive resolver, an attacker who
controls a DNS zone being resolved can cause named(8) to crash,
resulting in a denial of (DNS resolving) service.

DNSSEC does not need to be enabled on the resolver for it to be
vulnerable.

IV.  Workaround

No workaround is available, but systems not running the BIND DNS server
or using it exclusively as an authoritative name server (i.e., not as a
caching resolver) are not vulnerable.

V.   Solution

Perform one of the following:

1) Upgrade your vulnerable system to 7-STABLE or 8-STABLE,
or to the RELENG_8_2, RELENG_8_1, RELENG_7_4, or RELENG_7_3
security branch dated after the correction date.

2) To update your vulnerable system via a source code patch:

The following patches have been verified to apply to FreeBSD
7.3, 7.4, 8.1 and 8.2 systems.

a) Download the relevant patch from the location below, and verify the
detached PGP signature using your PGP utility.

# fetch http://security.FreeBSD.org/patches/SA-11:02/bind.patch
# fetch http://security.FreeBSD.org/patches/SA-11:02/bind.patch.asc

b) Execute the following commands as root:

# cd /usr/src
# patch < /path/to/patch
# cd /usr/src/lib/bind
# make obj && make depend && make && make install
# cd /usr/src/usr.sbin/named
# make obj && make depend && make && make install
# /etc/rc.d/named restart

3) To update your vulnerable system via a binary patch:

Systems running 7.3-RELEASE, 7.4-RELEASE, 8.1-RELEASE, or 8.2-RELEASE
on the i386 or amd64 platforms can be updated via the freebsd-update(8)
utility:

# freebsd-update fetch
# freebsd-update install

VI.  Correction details

The following list contains the revision numbers of each file that was
corrected in FreeBSD.

CVS:

Branch                                                           Revision
  Path
- -------------------------------------------------------------------------
RELENG_7
  src/contrib/bind9/lib/dns/ncache.c                          1.1.1.2.2.3
RELENG_7_4
  src/UPDATING                                             1.507.2.36.2.4
  src/sys/conf/newvers.sh                                   1.72.2.18.2.7
  src/contrib/bind9/lib/dns/ncache.c                      1.1.1.2.2.2.2.1
RELENG_7_3
  src/UPDATING                                             1.507.2.34.2.8
  src/sys/conf/newvers.sh                                  1.72.2.16.2.10
  src/contrib/bind9/lib/dns/ncache.c                         1.1.1.2.10.1
RELENG_8
  src/contrib/bind9/lib/dns/ncache.c                              1.2.2.4
RELENG_8_2
  src/UPDATING                                             1.632.2.19.2.4
  src/sys/conf/newvers.sh                                   1.83.2.12.2.7
  src/contrib/bind9/lib/dns/ncache.c                          1.2.2.2.2.1
RELENG_8_1
  src/UPDATING                                             1.632.2.14.2.7
  src/sys/conf/newvers.sh                                   1.83.2.10.2.8
  src/contrib/bind9/lib/dns/ncache.c                          1.2.2.1.2.1
- -------------------------------------------------------------------------

Subversion:

Branch/path                                                      Revision
- -------------------------------------------------------------------------
stable/7/                                                         r222399
releng/7.4/                                                       r222416
releng/7.3/                                                       r222416
stable/8/                                                         r222396
releng/8.2/                                                       r222416
releng/8.1/                                                       r222416
head/                                                             r222395
- -------------------------------------------------------------------------

VII. References

http://www.isc.org/software/bind/advisories/cve-2011-1910
http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-1910

The latest revision of this advisory is available at
http://security.FreeBSD.org/advisories/FreeBSD-SA-11:02.bind.asc
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9

iEYEARECAAYFAk3gvuQACgkQFdaIBMps37L2iACgizZK4QS3rOaY0x7evMuyWIop
OaoAn3Pku/9HCSUULC2xurSnGU3AtJcz
=aG4/
-----END PGP SIGNATURE-----

 

原文链接:http://security.freebsd.org/advisories/FreeBSD-SA-11:02.bind.asc