2007年10月19日

Postfix With SMTP-AUTH And TLS (Mandriva)

Install the required packages (Postfix, cyrus-sasl, imap, etc.) like this:

urpmi cyrus-sasl libsasl2 libsasl2-devel libsasl2-plug-plain libsasl2-plug-anonymous libsasl2-plug-crammd5 libsasl2-plug-digestmd5 libsasl2-plug-gssapi libsasl2-plug-login postfix imap

Then run (make sure that you use the correct values for mydomain, myhostname, and mydestination):


postconf -e 'mydomain = example.com'
postconf -e 'myhostname = server1.$mydomain'
postconf -e 'mydestination = /etc/postfix/local-host-names, localhost.example.com'
postconf -e 'smtpd_sasl_local_domain ='
postconf -e 'smtpd_sasl_auth_enable = yes'
postconf -e 'smtpd_sasl_security_options = noanonymous'
postconf -e 'broken_sasl_auth_clients = yes'
postconf -e 'smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination'
postconf -e 'inet_interfaces = all'
postconf -e 'mynetworks = 127.0.0.0/8'
touch /etc/postfix/local-host-names
touch /var/lib/mailman/data/aliases


Edit /etc/sasl2/smtpd.conf. It should look like this:

vi /etc/sasl2/smtpd.conf


# SASL library configuration file for postfix
# all parameters are documented into:
# /usr/share/doc/cyrus-sasl/options.html

# The mech_list parameters list the sasl mechanisms to use,
# default being all mechs found.
mech_list: plain login

# To authenticate using the separate saslauthd daemon, (e.g. for
# system or ldap users). Also see /etc/sysconfig/saslauthd.
pwcheck_method: saslauthd
saslauthd_path: /var/lib/sasl2/mux

# To authenticate against users stored in sasldb.
#pwcheck_method: auxprop
#auxprop_plugin: sasldb
#sasldb_path: /var/lib/sasl2/sasl.db



Create the SSL certificate needed for TLS:

mkdir /etc/postfix/ssl
cd /etc/postfix/ssl/
openssl genrsa -des3 -rand /etc/hosts -out smtpd.key 1024

chmod 600 smtpd.key
openssl req -new -key smtpd.key -out smtpd.csr

openssl x509 -req -days 3650 -in smtpd.csr -signkey smtpd.key -out smtpd.crt

openssl rsa -in smtpd.key -out smtpd.key.unencrypted

mv -f smtpd.key.unencrypted smtpd.key
openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650

and configure Postfix for TLS:


postconf -e 'smtpd_tls_auth_only = no'
postconf -e 'smtp_use_tls = yes'
postconf -e 'smtpd_use_tls = yes'
postconf -e 'smtp_tls_note_starttls_offer = yes'
postconf -e 'smtpd_tls_key_file = /etc/postfix/ssl/smtpd.key'
postconf -e 'smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.crt'
postconf -e 'smtpd_tls_CAfile = /etc/postfix/ssl/cacert.pem'
postconf -e 'smtpd_tls_loglevel = 1'
postconf -e 'smtpd_tls_received_header = yes'
postconf -e 'smtpd_tls_session_cache_timeout = 3600s'
postconf -e 'tls_random_source = dev:/dev/urandom'


Now start Postfix, saslauthd, imap and pop3:

chkconfig imap on
chkconfig imaps on
chkconfig ipop3 on
chkconfig pop3s on
/etc/init.d/postfix restart
/etc/init.d/saslauthd restart
/etc/init.d/xinetd restart

To see if SMTP-AUTH and TLS work properly now run the following command:

telnet localhost 25

After you have established the connection to your Postfix mail server type

ehlo localhost

If you see the lines

250-STARTTLS

and

250-AUTH PLAIN LOGIN

everything is fine:

[root@server1 ssl]# telnet localhost 25
Trying 127.0.0.1...

Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 server1.example.com ESMTP Postfix (2.4.5) (Mandriva Linux)
ehlo localhost
250-server1.example.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH PLAIN LOGIN
250-AUTH=PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
quit
221 2.0.0 Bye
Connection closed by foreign host.

[root@server1 ssl]#

Type

quit

to return to the system's shell.

2007年8月27日

科研沒挑戰 引進人才也白搭

轉貼李家同教授所寫的文章:
報載行政院認為我國缺乏科技人才,決定將從國外輸入一百萬的科技人才。看了以後,我十分困惑。

我有很多從台清交名校畢業的學生,在科技界服務,薪水不錯,但他們總有一個牢騷:工作太簡單了一點,挑戰性不夠。

在台灣,大多數工程師是非常優秀的,他們畢業時,和歐美明星大學畢業生,沒有什麼差別。可是進入職場以後,慢慢地差距就拉大了。

在歐美,工程師常有機會做非常難的工作。他們真正的成長,是在這些公司裡開始的。

我有一位清大電機系的學生,畢業後進入「類比電路設計」的行業,多年來一直在設計同樣的線路,但是難度越來越高,經驗也越來越豐富。每次完成了一個線路,然後他們會將規格提高一點,他總能達成任務,又設計出了一個非常高規格的線路。

我相信,像他這種人,台灣有的是。我們缺乏的是非常有挑戰性的研究計畫。這位同學在研究所裡根本沒有學過這種技術,就靠一點一滴地努力,終於成了專家。

我們國家,如果需要這種線路,十有八九會去向外國購買,我們的工程師只能將之當成黑盒子般地使用。我們的工程師用了別人的線路長達十年之久,另外一位工程師設計線路長達十年之久,誰比較厲害呢?

韓國工業界在十年前,和我們平起平坐,為什麼現在已經超過了我們?因為他們已經在基礎科技上,打下了很好的基礎。他們不斷在挑戰高難度的技術發展,一定要 擁有獨立自主的技術,而儘量地不依靠外國。他們在經歷如此高難度的挑戰以後,已經變成了世界頂尖的工程師。

韓國會有這種研究計畫,是因為有野心,也有耐心。他們如果朝野上下都在想短時間內看到成效,一定只會引進外國技術,永遠不能獨立自主。

我們要引進國外的科技人才,在國內要先營造一個有高挑戰性工作的環境。如果研發工作沒有挑戰性,過了一陣子,科技人才就不是人才;反過來說,如果我們有很多極難的研究計畫,外國的科技人材會不請自來的。

我建議政府策畫幾個難度較高的計畫,責成政府或民間單位在不依賴外國技術的原則之下完成這些計畫。舉例來說,我們可以要求設計一些通訊工業上所需要的積體 電路,十分精準的步進馬達,或者一個高規格的控制器。如此不僅在很多技術上可以獨立自主,最重要的是國家會多了一大批十分有競爭力的工程師。

工程師都是磨練出來的,我們有時過份地強調創意,而忽略了經驗的重要性。很多有創意的科技人才,其實是因為他在這個領域裡工作了很久,才會有好的創意。

我不反對引進外國科技人才,但培養本土的科技人才一樣重要。培養科技人才,唯一的辦法就是請他從事他不會做的工作。等到有一天他達成任務,他就是人才了。


我的心也有戚戚焉。感覺台灣產官學界大部分要的是速成不是長久;想要什麼都用錢去砸;沒想到要如何培養人才;把人才當庸才用,把庸才當人才用。把不切實際只會空彈的人視為人才,把腳踏實地,苦幹實幹的人視為庸才,甚至視為敝屣;這真是讓我痛心之處。

2007年8月9日

PHP的STDIN(標準輸入)、STDOUT(標準輸出)及STDERR(標準錯誤輸出)

有管理過Unix like的作業系統或是有在撰寫Unix like程式的人往往會使用到標準輸入(STDIN)、輸出(STDOUT)及錯誤輸出(STDERR)的管線來完成一些訊息的輸入、輸出及錯誤訊息的表達。
但是若要用php來完成同樣的事情時,則未免有些遺憾,沒有現成的系統錯誤輸出及系統輸入函數(像是scanf)可以使用,但是可以利用一些簡單的fopen()、fprintf()及fscanf()的檔案I/O函數來組合成類似的功能。以下為簡單的程式範例:

1).使用fopen()及fscanf()的函數組合出類似scanf()的功能:
<?
/* 判斷STDIN是否已經預先被定義了 */
if(!defined("STDIN")) {
define("STDIN", fopen('php://stdin','r'));
}

/* 透過標準格式化輸出函數將字串印出 */
printf("Please Input some thing:\n");

/* 利用fscanf()的函數來讀取預先定義好的STDIN,並將其直傳入$input的變數中 */
fscanf(STDIN, "%s", $input);

/* 透過標準格式化輸出函數將$input變數的值印出 */
printf("Your input data is \"%s\"\n", $input);
?>

---------------------------------------------------------------------------
2).使用fopen()及fprintf()的函數將訊息列印到標準錯誤輸出:
<?
/* 判斷STDERR是否已經預先被定義了 */
if(!defined("STDERR")) {
define("STDERR", fopen('php://stderr','w'));
}

/* 透過標準格式化輸出函數將字串印出 */
printf("Standard Message Output\n");

/* 利用fprintf()的函數將訊息寫入預先定義好的STDERR */
fprintf(STDERR, "Standard Error Message Output\n");
?>

續待.....

2007年7月23日

如何掛載initrd的影像檔

initrd的檔案格式在kernel 2.4及kernel 2.6是不一樣的
kernel 2.4的掛載方式:
  1. mkdir initrd
  2. cp /boot/inirtd.img ./initrd.img.gz
  3. gunzip initrd.img.gz
  4. mount -t ext -o loop initrd.img ./initrd
kernel 2.6的目前還沒研究出掛載的方式,但可以用cpio把整個影像檔解開來:
  1. mkdir initrd
  2. cp /boot/inirtd.img ./initrd.img.gz
  3. gunzip initrd.img.gz
  4. cp initrd.img initrd/
  5. cd initrd/
  6. cpio -i --make-directories < initrd.ing

2007年7月20日

$ setterm -dump 3 -----> 錄 tty3 的東東 , 產生 screen.dump
$ setterm -append -----> 錄 目前 tty 加在 screen.dump 的尾巴
$ setterm -h | less -----> 看看 它的功能

我們為別人也為自己找到解決問題的方法,真的好高興,沒有白努力!
下面是我自己找到的方法:原來在Linux下拍下tty畫面也很簡單
因為我預設的畫面是25X80

dd if=/dev/tty1 of=capture_filename bs=2000 count=1
vi capture_filename 即可看到剛才tty1上的螢幕內容

如果是
dd if=/dev/tty1 of=capture_filename bs=4004 count=1
vi capture_filename 可看到剛才tty1上的螢幕內容及色彩編碼
結構是
前四個字元值 列數 每列字元數 游標位置列 游標水平位置
後面則是色彩字元前文字字元後的雙字元結構
只要 cat capture_filename > /dev/tty3
就可把剛才抓下的畫面秀在tty3上面,好玩吧!


精選文章

Ubuntu 20.04 LTS VM syslog 出現 multipathd 錯誤時的處置措施

在 VM 上安裝完 Ubuntu 20.04 LTS 版本後在一次例行性檢查中發現 syslog 中發現一直跳出 multipathd 的錯誤,如下圖 這問題產生的原因是 ESXi 不會產生 udev 必要的資訊,所以 udev 就無法產生出相對應的 /dev/disk/by-i...