Friday, December 4, 2009

SELINUX从理解到动手配置

更多精彩请到 http://www.139ya.com

SELINUX从理解到动手配置


http://www.xxlinux.com/linux/article/network/security/20090531/16821.html

SELinux 可以为你的系统提供较棒的安全防护。 使用者能被分配预先定义好的角色,以便他们不能存取文件或者访问他们不拥有的程序。

Selinux的启用与关闭

编辑/etc/selinux/conf文件

SELINUX=enforcing(强制:违反了策略,你就无法继续操作下去)

Permissive(有效,但不强制:违反了策略的话它让你继续操作,但是把你的违反的内容记录下来)

Disabled(禁用)

禁用的另一种方式:在启动的时候,也可以通过传递参数selinux给内核来控制它

编辑/etc/grup.conf

title Red Hat Enterprise Linux Server (2.6.18-8.el5)

root (hd0,0)

kernel /vmlinuz-2.6.18-8.el5 ro root=LABEL=/ rhgb quiet selinux=0

initrd /initrd-2.6.18-8.el5.img

SELINUXTYPE=targeted

此参数可选项:targeted和strice。分别是targeted只控制关键网络服务,strice控制所有的服务

查询selinux的状态

[root@linuxas ~]# /usr/sbin/getenforce

Enforcing

[root@linuxas ~]# sestatus -bv

SELinux status: enabled

SELinuxfs mount: /selinux

Current mode: enforcing

Mode from config file: enforcing

Policy version: 21

Policy from config file: targeted

查看selinux加载的内核模块

[root@linuxas selinux]# semodule -l

amavis 1.1.0

ccs 1.0.0

clamav 1.1.0

dcc 1.1.0

evolution 1.1.0

iscsid 1.0.0

mozilla 1.1.0

mplayer 1.1.0

nagios 1.1.0

oddjob 1.0.1

pcscd 1.0.0

pyzor 1.1.0

razor 1.1.0

ricci 1.0.0

smartmon 1.1.0

查看selinux错误日志

[root@linuxas selinux]# sealert -a /var/log/audit/audit.log

SElinux的图形化管理工具

[root@linuxas selinux]# system-config-selinux

Selinux的基本操作

查看文件:ls –Z(--context)

[root@linuxas ~]# ls -Z

drwx------ root root root:object_r:user_home_t Desktop

-rw------- root root system_u:object_r:user_home_t anaconda-ks.cfg

-rw-r--r-- root root root:object_r:user_home_t install.log

-rw-r--r-- root root root:object_r:user_home_t install.log.syslog

[root@linuxas ~]# ls --context

drwx------ root root root:object_r:user_home_t Desktop

-rw------- root root system_u:object_r:user_home_t anaconda-ks.cfg

-rw-r--r-- root root root:object_r:user_home_t install.log

-rw-r--r-- root root root:object_r:user_home_t install.log.syslog

查看文件系统的扩展属性:getfattr

[root@linuxas ~]# getfattr -m. -d /etc/passwd

getfattr: Removing leading '/' from absolute path names

# file: etc/passwd

security.selinux="system_u:object_r:etc_t:s0�00"

查看的文件的 security.selinux 属性中储存了此文件的安全上下文, 所以上面例子中的上下文就是 system_ubject_r:etc_t 。

所有运行了SE Linux的ext2/3文件系统上都有 security.selinux 这个属性。

更改文件的扩展属性标签:chcon (不能在 /proc 文件系统上使用,就是说 /proc 文件系统不支持这种标记的改变。)

[root@linuxas test]# ls --context aa.txt

-rw-r--r-- root root root:object_r:user_home_t aa.txt

[root@linuxas test]# chcon -t etc_t aa.txt

[root@linuxas test]# ls --context aa.txt

-rw-r--r-- root root root:object_r:etc_t aa.txt

恢复原来的文件标签: restorecon

[root@linuxas test]# restorecon aa.txt

[root@linuxas test]# ls -Z aa.txt

-rw-r--r-- root root user_u:object_r:user_home_t aa.txt

显示当前用户的Selinux context

[root@linuxas ~]# id -Z

root:system_r:unconfined_t:SystemLow-SystemHigh

runcon 使用特定的context来执行指令

[root@linuxas ~]# runcon -t user_home_t cat /etc/passwd

root:system_r:user_home_t:SystemLow-SystemHigh is not a valid context

查看某种服务是否受到SELinux的保护

[root@linuxas ~]# getsebool -a (RHEL4:inactive受保护,active不受保护;RHEL5:off受保护,on不受保护)

Thursday, December 3, 2009

Eclipse插件开发小结

更多精彩请到 http://www.139ya.com

http://wjj-tt.spaces.live.com/blog/cns!91CCF857592F26C!106.entry

这两天看了一下Eclipse的插件开发,参考的书就是那本著名的Contributing to Eclipse。

把两点体会记录如下:

1、Extension和Extension-point

Extension 和Extension-point是相互关联的,由Extension-point定义插件具备的扩展点并且定义了如何使用这些扩展点(由Schema中 定义),而Extension则是根据扩展点中定义的Schema来描述扩展的内容。Extension定义的是对已有插件进行的扩展,其中point是 扩展源的id。对于不同的扩展源,Extension的元素定义各不相同。Extension-piont定义的是本插件向外提供的扩展功能,利用 Schema来定义Extension。

【学习心得】JFace和SWT有什么区别呢?

更多精彩请到 http://www.139ya.com


JFace:插件的用户界面框架
我们已经见到工作台定义扩展点来为使插件向平台添加用户界面功能。许多这些扩展点,特别是向导扩展,是通过使用 org.eclipse.jface.* 包中的类来实现的。有什么区别?

JFace 是一个用户界面工具箱,它提供很难实现的、用于开发用户界面功能部件的 helper 类。JFace 在原始的窗口小部件系统的级别之上运行。它提供用于处理常见的用户界面编程任务的类:

查看器负责处理填充、排序、过滤和更新窗口小部件等最辛苦的工作。
操作和添加项介绍用于定义用户操作的语义,并指定在何处提供它们。
图像和字体注册表提供用于处理用户界面资源的常见模式。
对话框和向导定义用于构建与用户进行复杂交互的框架。
JFace 使您可以专注于实现特定插件的功能,而不必花费精力来处理底层窗口小部件系统或者解决几乎在任何用户界面应用程序中都很常见的问题。

JFace 和工作台
何处是 JFace 结束而工作台开始的位置?有时候界线并不是这样明显。通常,JFace API(来自于包 org.eclipse.jface.*)独立于工作台扩展点和 API。可以想象,根本不必使用任何工作台代码就可以编写 JFace 程序。

工作台使用 JFace,但是又试图尽可能减少依赖项。例如,工作台部件模型(IWorkbenchPart)被设计为独立于 JFace。我们很早就知道可以直接使用 SWT 窗口小部件来实现视图和编辑器,而不必使用任何 JFace 类。工作台尽可能保持“JFace 中立”,允许程序员使用他们觉得有用的 JFace 的部件。实际上,在工作台的大多数实现中都使用了 JFace,并且在 API 定义中引用了 JFace 类型。(例如,IMenuManager、IToolBarManager 和 IStatusLineManager 的 JFace 接口显示为工作台 IActionBar 方法中的类型。)

JFace 和 SWT
SWT 和 JFace 之间的界线是很明显的。SWT 根本不依赖于任何 JFace 或平台代码。许多 SWT 示例说明可以如何构建独立的应用程序。

JFace 用来在 SWT 库顶部提供常见的应用程序用户界面功能。JFace 并不试图“隐藏”SWT 或者替换它的功能。它提供一些类和接口,以处理与使用 SWT 来对动态用户界面编程相关联的许多常见任务。

通过了解查看器及它们与 SWT 窗口小部件之间的关系,就可以更清楚地了解 JFace 和 SWT 之间的关系。



Java是一种强大的编程语言。但强大就意味复杂,尤其是和Java相关的名词就象天上的星星一样,数都数不过来。在本文中就涉及到两个比较常用的名词 SWT和JFace。在标题中将SWT和JFace放到一起,并不是说SWT和JFace是一个意思,而是说它们的关系非常紧密。

基于Java的图形库最主要的有三种,它们分别是Swing、AWT和SWT。其中前两个是Sun随JDK一起发布的,而SWT则是由IBM领导的开源项目(现在已经脱离IBM了)Eclipse的一个子项目。SWT的执行效率非常高。这是由于SWT的底层是由C编写的。由于SWT通过C直接调用系统层的 GUI API。因此,使用SWT编写GUI程序,在外观上就和使用C++、Delphi(在Windows下)编写的程序完全一样。它的这一点和AWT类似。 AWT在底层也是使用C直接调用系统层的GUI API。但它们是有区别的,最大的区别可能就是一个是Sun提供的,一个是Eclipse自带的。这就意味着如果使用AWT,只要机器上安装了JDK或 JRE,发布软件时无需带其它的库。而如何使用SWT,在发布时必须要自带上SWT的*.dll(Windows版)或*.so(Linux/Unix 版)文件以及相关的*.jar包。还有就是它们所提供的图形接口有一些差异。SWT可能更丰富一些,我们可以看看Eclipse的界面就知道了。但随着 Sun对AWT库的不断更新,AWT的图形表现能力也在不断地提高。

虽然SWT很强大,但它比较底层。也就是说它的一些功能在使用上还比较低级,不太符合面向对象的特征。因此,在SWT的基础上又开发了JFace。JFace在SWT上进行了一定的扩展。因此,也可说JFace是基于 SWT的,就象在VC中使用MFC来包装Win32 API一样。

Wednesday, December 2, 2009

What is Spring?

更多精彩请到 http://www.139ya.com

http://onjava.com/onjava/2005/10/05/what-is-spring.html


Spring is a lightweight container, with wrappers that make it easy to use many different services and frameworks. Lightweight containers accept any JavaBean, instead of specific types of components.

"Spring is more than just a 'lightweight container,'" says Justin Gehtland. "It allows Java developers who are building J2EE apps to get to the heart of their real domain problems and stop spending so much time on the minutiae of providing services to their domain." Gehtland and Bruce Tate are coauthors of Spring: A Developer's Notebook, a no-nonsense book that will get you up to speed quickly on the new Spring open source framework. Spring: A Developer's Notebook includes examples and practical applications that demonstrate exactly how to use Spring, in ten chapters of code-intensive labs.

Today we'll feature the first of two chapters from the book, in our two-part series dubbed "What Is Spring." The series will help you understand how you can use Spring to produce simple, clean, and effective applications.

In this week's excerpt of Chapter 1, "Getting Started," authors Tate and Gehtland take a simple application and show you how to automate it and enable it for Spring. (In part 2 next week, the authors will cover how Spring can help in development of simple, clean, web-based UI's--excerpted from Chapter 2, "Building a User Interface.")

Introduction to Eclipse Plugin Development

更多精彩请到 http://www.139ya.com

From : http://www.eclipsepluginsite.com/index.html

Eclipse Plugin Development TUTORIAL

Eclipse Plugin Development Tutorial website to teach you how to develop eclipse plugins using simple examples to a complex eclipse rcp over time. This chapter will give you a detailed insight into Eclipse Architecture and we will develop a simple but fully functional eclipse plug-in so as to give you a quick start with eclipse plug-in development.

Overview

Eclipse isn’t a huge single java program, but rather a small program which provides the functionality of typical loader called plug-in loader. Eclipse (plug-in loader) is surrounded by hundreds and thousands of plug-ins. Plug-in is nothing but another java program which extends the functionality of Eclipse in some way. Each eclipse plug-in can either consume services provided by other plug-in or can extend its functionality to be consumed by other plug-ins. These plug-in are dynamically loaded by eclipse at run time on demand basis.

An Open Platform

Eclipse is an open platform. It is designed to be easily and infinitely extensible by third parties. At the core is the eclipse SDK, we can build various products/tools around this SDK. These products or tools can further be extended by other products/tools and so on. For example, we can extend simple text editor to create xml editor. Eclipse architecture is truly amazing when it comes to extensibility. This extensibility is achieved by creating these products/tools in form of plug-ins.


Figure 1-1


Inside the Eclipse SDK



Figure 1-2

RCP: On the bottom is RCP which provides the architecture and framework to build any rich client application.

IDE: It is a tools platform and a rich client application itself. We can build various form of tooling by using IDE for example Database tooling.

JDT: It is a complete java IDE and a platform in itself.

PDE: It provides all tools necessary to develop plug-ins and RCP applications. This is what we will concentrate on the course of this tutorial.

Plug-ins everywhere

All the layers in eclipse SDK are made up of plug-ins. If you see all the way, you will notice that everything is a plug-in in eclipse sdk.




Figure 1-3

Plug-in Architecture

A plugin is a small unit of Eclipse Platform that can be developed separately. It must be noted that all of the functionality of eclipse is located in different plugins (except for the kernel)





A plug-in can be delivered as a jar file. A plug-in is self-contained bundle in a sense that it contains the code and resources that it needs to run for ex: code, image files, resource bundles etc. A plug-in is self describing - when I say it is self describing it means that it describes who it is and what it contributes to the world. It also declares what it requires from the world.

A Mechanism For Extensibility

Figure 1-7

We all know that eclipse is extensible. In order to achieve this extensibility eclipse uses the concept of extension points and extension. Think of extension point as Electric socket and think of extension as a plug. Plug-in A exposes a extension point (electric socket) which Plug-in B extends by providing an extension (an electric plug). Plug-in A knows nothing about plug-in B. If we think about it this is very similar to concept of Inheritance – we extend functionality of base class to provide more specific implementation. Think of Plug-in A as a text editor and Plug-in B as xml editor. Text editor declares extension point thereby declaring to the world that it is open for extension and xml editor extends text editor by using its extension point to customize it in its own way. It is important to understand that each extension point essentially declares
a contract. An extension point provider only accepts those extensions which abide by the contract.

These extension points and extensions are declared in plugin.xml (discussed earlier). The runtime is able to wire extensions and extension points and form a registry using markup alone.

Plug-in Example

Now that we have covered good amount of architecture basics, its time to get our hands dirty with some actual plug-in coding. The process for creating a plug-in is best demonstrated by implementing a plug-in on which discussion and examples can be based. Here we will take a step-by-step approach to create a simple but fully operational plug-in. This example will try to give you an feel of eclipse plug-in development. However, don’t try to grab all the details at this point. It is fine if you are not able to understand much of the details in this example. Rest of the tutorial will cover all the topics in great depth.

We will build a simple Resource Manager plug-in. Features of this plug-in are as follows:

  • Ability to add/remove resources (essentially files in workspace) to resource manager.
  • Display list of resources which were added to resource manager.
  • Ability to open up associated editor whenever resource is clicked.