Archive for 11月, 2008

Linux 安全组件比较和介绍。

Linux审计子系统(Linux Aduit Subsystem)
LAus可以用来监控文件访问和操作系统的一些情况,是linux为了通过evl-4级认证的一个完全策略。从下面的一个连接可以大体的推断其支持的 kernel和各发行版,http://www.securityfocus.com/bid/12309,尽管这是一个bug报告。

SELinux
SELinux 是 2.6 版本的 Linux 内核中提供的强制访问控制 (MAC)系统。对于目前可用的 Linux 安全模块来说,SELinux 是功能最全面,而且测试最充分的,它是在 20 年的 MAC 研究基础上建立的。SELinux 在类型强制服务器中合并了多级安全性或一种可选的多类策略,并采用了基于角色的访问控制概念。
参考连接:
SELinux实例:使用安全增强的Linux
从头开始生成 SELinux
揭开 SE Linux 的秘密:第 1部分
SELinux 中基于角色的访问控制
Gentoo SELinux Handbook

ACL
ACL是Access Control List的缩写,主要的目的是在提供传统的owner,group,others的read,write,execute权限之外的细部权限设定。 ACL可以针对单一使用者,单一档案或目录来进行r,w,x的权限规范,对于需要特殊权限的使用状况非常有帮助。 Grsecurity是其中比较典型和成熟的一种。
Grsecurity ACL系统
Linux 安全系列:用 grsecurity 保护 Linux

CHROOT
CHROOT就是Change Root,也就是改变程序执行时所参考的根目录位置。可以将程序限制在指定的目录之内。

iptables
Linux提供了一个非常优秀的防火墙工具—netfilter/iptables。它完全免费、功能强大、使用灵活、可以对流入和流出的信息进行细化控制,且可以在一台低配置机器上很好地运行。netfilter/iptabels应用程序,被认为是Linux中实现包过滤功能的第四代应用程序。netfilter/iptables包含在2.4以后的内核中,它可以实现防火墙、NAT(网络地址翻译)和数据包的分割等功能。 netfilter工作在内核内部,而iptables则是让用户定义规则集的表结构。netfilter/iptables从ipchains和 ipwadfm(IP防火墙管理)演化而来,功能更加强大。
参考资料:
iptables从入门到精通
Iptables 指南 1.1.19

Linux-PAM 的 limit
Linux-PAM 的 limit 也很有用,可以限制用户启动进程所占用的资源。(为用户级别的限制,不能为单个程序制定限制。)
配置文件在 /etc/security/limits.conf
参考资料:
Linux Shell命令ulimit的用法

Tripwire 或 AIDE(Advanced Intrusion Detection Environment)

AIDE即Advanced Intrusion Detection Environment,直译为高级入侵检测环境,AIDE,是一个文件完整性检测工具,AIDE 能够构造一个指定文件的数据库。

Tripwire 是目前最为著名的unix下文件系统完整性检查的软件工具,这一软件采用的技术核心就是对每个要监控的文件产生一个数字签名,保留下来。当文件现在的数字签名与保留的数字签名不一致时,那么现在这个文件必定被改动过了。

对了,各种虚拟技术也可以算上。
用户模式内核为了安全需要为主机内核打上补丁,不然虚拟机内的程序可以访问其他程序的内存。

Linux 安全:Linux 内核安全增强、系统安全及安全编程
让 Linux 更安全,第 1 部分:介绍
安全编程: 最小化特权
如何增强 Linux 系统的安全性,第一部分: Linux 安全模块(LSM)简介

Comments (4) »

gentoo python 下使用 python3 出现 ImportError: No module named _sqlite3 错误的解决办法。

默认 gentoo 下 python 不能使用 sqlite3,会出现 ImportError: No module named _sqlite3 错误。
解决办法是增加 sqlite USE 标志并重新编译 python 。虽然有 sqlite3 这个use标志,但是 python 不能识别。建议只为python增加sqlite标志。执行
# echo “dev-lang/python sqlite” >> /etc/portage/package.use
就可以增加use标志。

gamexg@GGentoo ~ $ python
Python 2.5.2 (r252:60911, Oct 31 2008, 10:01:00)
[GCC 4.1.2 (Gentoo 4.1.2 p1.1)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import sqlite3
Traceback (most recent call last):
File “”, line 1, in
File “/usr/lib/python2.5/sqlite3/__init__.py”, line 24, in
from dbapi2 import *
File “/usr/lib/python2.5/sqlite3/dbapi2.py”, line 27, in
from _sqlite3 import *
ImportError: No module named _sqlite3

Comments (1) »

Gentoo 下的 gnome 图像查看器不能打开 jpg 和 jpeg 图片的问题。

默认情况下 gentoo 下的 gnome 图像查看器不能打开 jpg 和 jpeg 图像。

需要为 USE 增加 jpeg 值。建议直接加到 make.conf 里面去,因为这不是一个程序会受这个问题影响。

Comments (1) »

Python 自动补全 大全(IPython,readline,vim)

如果想使用交互式命令行自动补全,建议使用Ipython。

IPython 比使用
import readline, rlcompleter; readline.parse_and_bind(“tab: complete”)
启动的自动补全更好些。例如import 时也可以自动补全模板名。

想为vim启动自动补全需要下载插件。
http://vim.sourceforge.net/scripts/script.php?script_id=850
下载后将 pydiction 文件解压到 ~/.vim/tools 目录下。
然后对.vimc 增加以下内容

” python auto-complete code
” Typing the following (in insert mode):
” os.lis
” will expand to:
” os.listdir(
” Python 自动补全功能,只需要反覆按 Ctrl-N 就行了
if has(“autocmd”)
autocmd FileType python set complete+=k~/.vim/tools/pydiction
endif

现在使用Ctr+N 就可以自动补全了。

Comments (2) »

gentoo 下 intel 845G(其它的也一样) 显卡开启3D加速。

1 配置内核
Device Drivers —> Graphics support 的配置
│ │ -*- /dev/agpgart (AGP Support) —> │ │
│ │ (*) Direct Rendering Manager (XFree86 4.1.0 and higher DRI suppor│ │
│ │ () Lowlevel video output switch controls │ │
│ │ (*) Support for frame buffer devices —> │ │
│ │ [ ] Backlight & LCD device support —> │ │
│ │ Display device support —> │ │
│ │ Console display driver support —> │ │
│ │ [ ] Bootup logo —> │ │

/dev/agpgart (AGP Support) 的配置
│ │ — /dev/agpgart (AGP Support) │ │
│ │ () ALI chipset support │ │
│ │ () ATI chipset support │ │
│ │ () AMD Irongate, 761, and 762 chipset support │ │
│ │ () AMD Opteron/Athlon64 on-CPU GART support │ │
│ │ -*- Intel 440LX/BX/GX, I8xx and E7x05 chipset support │ │
│ │ () NVIDIA nForce/nForce2 chipset support │ │
│ │ () SiS chipset support │ │
│ │ () Serverworks LE/HE chipset support │ │
│ │ () VIA chipset support │ │
│ │ () Transmeta Efficeon support │ │

Direct Rendering Manager (XFree86 4.1.0 and higher DRI suppor 的配置
│ │ — Direct Rendering Manager (XFree86 4.1.0 and higher DRI suppor│ │
│ │ () 3dfx Banshee/Voodoo3+ │ │
│ │ () ATI Rage 128 │ │
│ │ () ATI Radeon │ │
│ │ () Intel I810 │ │
│ │ (*) Intel 830M, 845G, 852GM, 855GM, 865G (i915 driver) —> │ │
│ │ () Matrox g200/g400 │ │
│ │ () SiS video cards │ │
│ │ () Via unichrome video cards │ │
│ │ () Savage video cards │ │

Intel 830M, 845G, 852GM, 855GM, 865G (i915 driver) 的配置
│ │ ( ) i830 driver │ │
│ │ (X) i915 driver │ │

│ │ — Support for frame buffer devices │ │
│ │ [*] Enable firmware EDID │ │
│ │ -*- Enable Video Mode Handling Helpers │ │
│ │ [ ] Enable Tile Blitting Support │ │
│ │ *** Frame buffer hardware drivers *** │ │
│ │ () Cirrus Logic support │ │
│ │ () Permedia2 support │ │
│ │ () CyberPro 2000/2010/5000 support │ │
│ │ () Arc Monochrome LCD board support │ │
│ │ [ ] Asiliant (Chips) 69000 display support │ │
│ │ [ ] IMS Twin Turbo display support │ │
│ │ () VGA 16-color graphics support │ │
│ │ [ ] VESA VGA graphics support │ │
│ │ [ ] EFI-based Framebuffer Support │ │
│ │ () Hecuba board support │ │
│ │ () Hercules mono graphics support │ │
│ │ () Epson S1D13XXX framebuffer support │ │
│ │ () nVidia Framebuffer Support │ │
│ │ () nVidia Riva support │ │
│ │ () Intel 810/815 support (EXPERIMENTAL) │ │
│ │ () Intel LE80578 (Vermilion) support │ │
│ │ (*) Intel 830M/845G/852GM/855GM/865G/915G/945G support (EXPERIMENTAL) │ │
│ │ [ ] Intel driver Debug Messages │ │
│ │ [*] DDC/I2C for Intel framebuffer support │ │
│ │ () Matrox acceleration │ │
│ │ () ATI Radeon display support │ │
│ │ () ATI Rage128 display support │ │
│ │ () ATI Mach64 display support │ │
│ │ () S3 Trio/Virge support │ │
│ │ () S3 Savage support │ │
│ │ () SiS/XGI display support │ │
│ │ () NeoMagic display support │ │
│ │ () IMG Kyro support │ │
│ │ () 3Dfx Banshee/Voodoo3 display support │ │
│ │ () 3Dfx Voodoo Graphics (sst1) support │ │
│ │ () VIA VT8623 support │ │
│ │ () Cyberblade/i1 support │ │
│ │ () Trident support │ │
│ │ () ARK 2000PV support │ │
│ │ () Permedia3 support (EXPERIMENTAL) │ │
│ │ [ ] AMD Geode family framebuffer support (EXPERIMENTAL) │ │
│ │ () Virtual Frame Buffer support (ONLY FOR TESTING!) │ │

Console display driver support 的配置
│ │ -*- VGA text console │ │
│ │ [*] Enable Scrollback Buffer in System RAM │ │
│ │ (128) Scrollback Buffer Size (in KB) │ │
│ │ [*] Video mode selection support │ │
│ │ (*) Framebuffer Console support │ │
│ │ [ ] Map the console to the primary display device │ │
│ │ [ ] Framebuffer Console Rotation │ │
│ │ [ ] Support for the Framebuffer Console Decorations │ │
│ │ [ ] Select compiled-in fonts │ │

2.修改 make.conf
为 make.conf 增加一下内容
INPUT_DEVICES=”keyboard mouse”
#VIDEO_CARDS=”i810″ # i810 是错误的,使用的话无法开启3D加速
VIDEO_CARDS=”intel”

3. 安装 x11-drivers/xf86-video-intel xorg-x11 gnome
emerge -av x11-drivers/xf86-video-intel xorg-x11 gnome
这一步可能还有其它的东西,不过不记得了。

4.配置xorg.conf
我的配置是
[coolcode download=”xorg.conf”]
Section “ServerLayout”
Identifier “X.org Configured”
Screen 0 “Screen0” 0 0
InputDevice “Mouse0” “CorePointer”
InputDevice “Keyboard0” “CoreKeyboard”
EndSection

Section “Files”
RgbPath “/usr/share/X11/rgb”
ModulePath “/usr/lib/xorg/modules”
FontPath “/usr/share/fonts/misc/”
FontPath “/usr/share/fonts/TTF/”
FontPath “/usr/share/fonts/OTF”
FontPath “/usr/share/fonts/Type1/”
FontPath “/usr/share/fonts/100dpi/”
FontPath “/usr/share/fonts/75dpi/”
EndSection

Section “Module”
#这里是3D加速相关的
Load “dri”
Load “glx”
#Load “drm” # libdrm.a
Load “extmod”
Load “xtrap”
Load “record”
Load “GLcore”
Load “dbe”
Load “freetype”
Load “type1”
EndSection

# 这里是3D加速的部分
Section “dri”
Mode 0666
EndSection

Section “InputDevice”
Identifier “Keyboard0”
Driver “kbd”
EndSection

Section “InputDevice”
Identifier “Mouse0”
Driver “mouse”
Option “Protocol” “auto”
Option “Device” “/dev/input/mice”
Option “ZAxisMapping” “4 5 6 7”
EndSection

Section “Monitor”
Identifier “Monitor0”
VendorName “Monitor Vendor”
ModelName “Monitor Model”
# HorizSync 28.0 – 51.0
# VertRefresh 43.0 – 60.0
Modeline “800x600_85.00” 56.55 800 840 928 1056 600 601 604 630 -HSync +Vsync
# 1024×768 @ 75.00 Hz (GTF) hsync: 60.15 kHz; pclk: 81.80 MHz
Modeline “1024x768_75.00” 81.80 1024 1080 1192 1360 768 769 772 802 -HSync +Vsync
#
EndSection

Section “Device”
### Available Driver options are:-
### Values: : integer, : float, : “True”/”False”,
### : “String”, : ” Hz/kHz/MHz”
### [arg]: arg optional
#Option “NoAccel” # []
#Option “SWcursor” # []
#Option “ColorKey” #
#Option “CacheLines” #
#Option “Dac6Bit” # []
#Option “DRI” # []
#Option “NoDDC” # []
#Option “ShowCache” # []
#Option “XvMCSurfaces” #
#Option “PageFlip” # []
Identifier “Card0”
# 这里是驱动选择,i810是错误的。
Driver “intel”
# Driver “i810”
VendorName “Intel Corporation”
BoardName “82845G/GL[Brookdale-G]/GE Chipset Integrated Graphics Device”
BusID “PCI:0:2:0”
EndSection

Section “Screen”
Identifier “Screen0”
Device “Card0”
Monitor “Monitor0”
SubSection “Display”
Viewport 0 0
Depth 1
EndSubSection
SubSection “Display”
Viewport 0 0
Depth 4
EndSubSection
SubSection “Display”
Viewport 0 0
Depth 8
EndSubSection
SubSection “Display”
Viewport 0 0
Depth 15
EndSubSection
SubSection “Display”
Viewport 0 0
Depth 16
EndSubSection
SubSection “Display”
Viewport 0 0
Depth 24
EndSubSection
EndSection
[/coolcode]

No comment »

git 常用命令介绍

配置
gamexg@GGentoo ~ $ git config –global user.email “[email protected]
gamexg@GGentoo ~ $ git config –global user.name “GameXG”

git-clone git://repo.or.cz/git-gui/git-gui-i18n.git abc
克隆 git://repo.or.cz/git-gui/git-gui-i18n.git 到 abc。不指定 abc 则使用git-gui-i18n。

git-add 添加需要 git 跟踪的文件.
注意:即使是上次提交前已经添加的文件在修改后还是需要再次添加或者使用-a参数执行提交,不然这次提交并不会提交这个文件的修改。

git-rm 从版本库标记指定文件为删除,并删除存在的指定文件。

git-commit 向版本库提交更改。
参数: -a 提交所有已加入版本库的文件的变更(新建但并没有git-add的文件不会被提交,修改和删除已存在版本库的文件将会提交更改。)
参数 -m 变更的注释。没有本参数则会自动打开一个使用环境变量 EDITOR 指定的文本编辑器来输入注释。

注意:如果没有使用-a参数,则只提交从上次提交到现在执行过git-add或git-rm等命令指定的文件才会被提交。即使某些在上次提交前执行git-add也不会提交它的更改。

git-reset 逆转于恢复命令。
–mixed
重置当前版本号为指定版本。清除待提交的文件列表(git-add增加但未git-commit的列表)。不改变任何文件。
–soft
清除待提交的文件列表(git-add增加但未git-commit的列表)。不改变任何文件。
–hard
将工作树中的内容和头索引都切换至指定的版本位置中,也就是说自 之后的所有的跟踪内容和工作树中的内容都会全部丢失。因此,这个选项要慎用,除非你已经非常确定你的确不想再看到那些东西了。 (并不是一点痕迹都没有,在log目录里面还是记录了现在和之前的操作的记录。并且执行git-reset 命令指定为已经之前的版本一样可以成功完成。但是我不确定如果执行git prune-packed之类的命令后是不是还存在。)

git-diff 当前版本和git数据库中的区别,以标准 path 格式显示。

git-branch 分支管理命令
git-branch a # 建立分支a(并不会切换到分支 a ,需要手动执行命令 git-checkout a )
git-branch -D a # 删除分支a
git-branch # 不带参数为查看已存在的分支。

git-merge 分支合并命令
git-merge 分支名称
将指定的分支合并到当前分支。注意:这样会同时将分支的历史提交也全部合并到当前分支。如果不想保留分支的历史提交数据使用 –squash 参数。
–squash 使用本参数将只会合并当前文件,并将被合并的文件标记为代提交。用户需要手动提交。这样就不会将原始分支的提交记录合并到当前分支了。
不知道什么原因 log、 commit 和 message 参数全部无效。

合并冲突
当发生合并冲突时,

参考:
Git 中文教程(可以从网上找到PDF版本)
Git 使用指南(PDF)
使用 Git 管理源代码

No comment »