post by tommy @ 13 六月, 2006 09:49
看了一下 pureftpd 的參數, 發現有另一個參數 -A (--chrooteveryone) 可以將 root 除外的所有使用者都做 chroot 的處理. 不過我的需求是.... 某些帳號 (就是我自己) 不要做 chroot. 在以前使用 vsftpd 時, 可以用一個檔案來控制那些帳號可以不用 chroot, 所以就仿照這個 idea, 修改 pureftpd 來使用.
diff -Nur src.orig/ftpd.c src/ftpd.c
--- src.orig/ftpd.c 2006-06-12 22:52:37.590994047 +0800
+++ src/ftpd.c 2006-06-13 09:38:45.293442782 +0800
@@ -1573,6 +1573,31 @@
return chdir(home);
}
+// add by twu2 20060612 begin
+int is_no_chroot_user(char *username)
+{
+ FILE *fp;
+ char buf[1024];
+ char *p;
+ int match = 0;
+
+ if (username == NULL || *username == '\0') return 0;
+ fp = fopen("/etc/pure-ftpd/nochroot.user", "rt");
+ if (fp == NULL) return 0;
+ while (1) {
+ if (fgets(buf, 1024, fp) == NULL) break;
+ p = strtok(buf, " \t\r\n");
+ if (p == NULL) continue;
+ if (strcmp(p, username) == 0) {
+ match = 1;
+ break;
+ }
+ }
+ fclose(fp);
+ return match;
+}
+// add by twu2 20060612 end
+
void dopass(char *password)
{
static unsigned int tapping;
@@ -1798,6 +1823,10 @@
addreply(0, MSG_RATIO, ratio_upload, ratio_download);
}
#endif
+// add by twu2 20060612 begin
+ if (userchroot == 2 && is_no_chroot_user(account))
+ userchroot = 0;
+// add by twu2 20060612 end
if (userchroot != 0 && chrooted == 0) {
#ifndef NON_ROOT_FTP
# ifndef HAVE_SYS_FSUID_H
這個 patch 可以由這個抓取: http://www.teatime.com.tw/~tommy/mypatch/pureftpd_no_chroot_user.patch
程式會在使用 -A 參數時, 檢查 /etc/pure-ftpd/nochroot.user 的檔案內容, 使用帳號存在於這個檔案內, 就不做 chroot 的動作.