Pages

Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Friday, December 25, 2009

vsftpd 日誌(log)不支援中文檔名的解決方式

vsftpd (2.0.4-1.2) 的日誌(vsftpd.log)不支援中文日文等字元(如檔名),會顯示為一串的問號。

網路上找了一下,解決的方式有二:
方法一. 將 log 寫入系統 log
方法二.修改原始碼


方法一比較好處理,缺點是會寫入 message 裡,跟其他 log 混在一起,只要在 vsftpd.conf 裡加入
syslog_enable=YES 即可


方法二要先看一下原始檔,以下節錄網路資料:

日誌記錄檔, file logging.c, line 152 - 171:
static void
vsf_log_do_log_to_file(int fd, struct mystr* p_str)
{
if (!tunable_no_log_lock)
{
int retval = vsf_sysutil_lock_file_write(fd);
if (vsf_sysutil_retval_is_error(retval))
{
return;
}
}
str_replace_unprintable(p_str, '?');
str_append_char(p_str, '\n');
/* Ignore write failure; maybe the disk filled etc. */
(void) str_write_loop(p_str, fd);
if (!tunable_no_log_lock)
{
vsf_sysutil_unlock_file(fd);
}
}



函數用 str_replace_unprintable(p_str, '?') 把所有「無法輸出的字元」替換為問號.

str_replace_unprintable 函數, file str.c, line 656 - 668:
void
str_replace_unprintable(struct mystr* p_str, char new_char)
{
unsigned int i;
for (i=0; i <>len; i++)
{
if (!vsf_sysutil_isprint(p_str->p_buf[i]))
{
p_str->p_buf[i] = new_char;
}
}
}



函數 vsf_sysutil_isprint, file sysutil.c, line 883 - 903:
int
vsf_sysutil_isprint(int the_char)
{
/* From Solar - we know better than some libc's! Don't let any potential
* control chars through
*/
unsigned char uc = (unsigned char) the_char;
if (uc <= 31)
{
return 0;
}
if (uc == 177)
{
return 0;
}
if (uc >= 128 && uc <= 159)
{
return 0;
}
return isprint(the_char);
}



作者注釋 "Don't let any potential control chars through" 表明對「無法輸出的字元」所做的定義

解決的方法就是注釋掉 logging.c 檔中的 static void vsf_log_do_log_to_file(int fd, struct mystr* p_str) 函數中的 str_replace_unprintable(p_str, '?');這一行
個人覺得比較麻煩,且有降低系統的安全的可能性(potential),所以我選「方法一」~

Tuesday, September 16, 2008

Linux (RedHat) 下 VNCServer 的使用

VNCServer 使用

啟動 vncserver

使用個人帳號直接執行vncserver,第一次執行時會要求輸入密碼,不一定要跟系統的一樣,連線後權限同原帳號(建議不要使用root)

[testuser@testserver ~]$ vncserver

 

New 'testserver.testdomain:1 (testuser)' desktop is testserver.testdomain:1

 

Starting applications specified in /home/testuser/.vnc/xstartup

Log file is /home/testuser/.vnc/testserver.testdomain:1.log

 

使用 VNC連線

第一種方式直接用 vncviewer 連線

輸入 server ip 或名稱,port 5901 則代表 :1

 

 輸入剛才設定的密碼(與系統密碼不同)


登入後是陽春的 twm自已的桌面也找不到了。


來修改 xstartup ,變更為 gnome (or kde)

[testuser@testserver .vnc]$ vi /home/testuser/.vnc/xstartup

#!/bin/sh

 

# Uncomment the following two lines for normal desktop:

# unset SESSION_MANAGER

# exec /etc/X11/xinit/xinitrc

 

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup

[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources

xsetroot -solid grey

vncconfig -iconic &

xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &

# twm &

gnome-session &

# startkde &

Kill 掉原來的程序

[testuser@testserver ~]$ vncserver –kill :1

Killing Xvnc process ID 4533

重新啟動

[testuser@testserver ~]$ vncserver

 

New 'testserver.testdomain:1 (testuser)' desktop is testserver.testdomain:1

 

Starting applications specified in /home/testuser/.vnc/xstartup

Log file is /home/testuser/.vnc/testserver.testdomain:1.log

登入後就是漂亮的 gnome 和原本的桌面啦


另一種連結方式:

Windows 底下開 browser,輸入網址(port 5801 代表 :1)

http://testserver:5801/


登入後只有 256 色,效能也沒有 vncviewer 好,應急時可使用


Tuesday, July 10, 2007

[*unix] 解決 IP 分享器架設 VSFTP 的連線逾時(Timeout)情形

[*unix] 解決 IP 分享器架設 VSFTP 的連線逾時(Timeout)情形

如果 FTP Server 在 IP 分享器後面,除本地網域,外面的 FTP Client 連進來容易出現 Connection Timeout 的狀況。

解決方式,一種是強迫 FTP Client 使用 PORT 連線(關閉 PASV)。
vsftp 則必須設定 vsftpd.conf 的 pasv_enable=NO 。

第二種方式需設定 vsftpd.conf
如要設定 開啟 65400~65410 Port 給 PASV 使用:

pasv_enable=YES //這行要開啟下面二行才會生效
pasv_min_port=65400
pasv_max_port=65410


另外要確認以下三點

1.分享器跟 Server 是否設定在 DMZ? 如果沒有,須把 65400~65410 對應到 ftp server上。
2.分享器上是否有防火牆擋住 65400~65410 ?
3.Linux 上的防火牆加入以下的指令:
iptables -I INPUT -p tcp --dport 65400:65410 -j accept

Monday, October 23, 2006

[linux] grep, egrep, fgrep - Global Regular Expression Print

grep 一次只能搜索一個指定的模式。
grep [選項] [查找模式] [檔案名1,檔案名2,……]

egrep 檢索擴展的正則運算式(括運算式組和可選項)
egrep [選項] [查找模式] [檔案名1,檔案名2,……]