from: http://hi.baidu.com/left99/item/1932f412063629011894ecc9
文中使用的源碼是samba-3.5.9。交叉編譯工具是arm-2011.03,是在
http://www.codesourcery.com/sgpp/lite/arm/portal/subscription3057
https://sourcery.mentor.com/sgpp/lite/arm/portal/subscription3057
下載的最新版本。
本文件中使用的路徑爲相對於源碼根目錄的路徑。
第一步要修改一下源碼,不然不能正常運行,因爲在android中不知什麼原因getpwnam等不能使用的,總是失敗。
把
lib/system.c
中的4個函數
struct passwd *sys_getpwnam(const char *name)
struct passwd *sys_getpwuid(uid_t uid)
struct group *sys_getgrnam(const char *name)
struct group *sys_getgrgid(gid_t gid)
改爲:
static struct passwd rootpw = {
"root",
"root",
0,
0,
"root",
"/root"
"/system/bin/sh",
};
struct passwd *sys_getpwnam(const char *name)
{
// return getpwnam(name);
return &rootpw;
}
struct passwd *sys_getpwuid(uid_t uid)
{
// return getpwuid(uid);
return &rootpw;
}
static char *rootmem[] = {
"root"
};
static struct group rootgr = {
"root",
"root",
0,
rootmem,
};
struct group *sys_getgrnam(const char *name)
{
return &rootgr;
// return getgrnam(name);
}
struct group *sys_getgrgid(gid_t gid)
{
return &rootgr;
// return getgrgid(gid);
}
配置腳本:
#!/bin/bash
CROSS_COMPILE=/home/geilpc/local/arm-2011.03/bin/arm-none-linux-gnueabi-
RUNTIME_DIR=/data/data/samba
./configure \
CC="$CROSS_COMPILE"gcc \
AR="$CROSS_COMPILE"ar \
LD="$CROSS_COMPILE"ld \
RANLIB="$CROSS_COMPILE"ranlib \
--build=i386-linux-gnu \
--host=arm-linux-gnu \
--with-ads=no \
--with-ldap=no \
--with-cifsmount=no \
--prefix=$RUNTIME_DIR \
--exec-prefix=$RUNTIME_DIR \
--with-logfilebase=$RUNTIME_DIR/var/log \
--with-swatdir=$RUNTIME_DIR/usr/local/swat \
--with-rootsbindir=$RUNTIME_DIR/sbin \
--with-lockdir=$RUNTIME_DIR/var/lock \
--with-piddir=$RUNTIME_DIR/var/lock \
--with-privatedir=$RUNTIME_DIR/etc/samba \
--with-configdir=$RUNTIME_DIR/etc/samba \
--cache-file=armsel-linux.cache \
--with-static-modules=vfs_fake_perms \
把它放到source3目錄下執行。
執行該編譯腳本過程中會出現問題,如下:
3.1 error: cannot run test program while cross compiling錯誤
checking that the C compiler understands negative enum values... configure: error: in `/root/samba-3.3.3/source':
configure: error: cannot run test program while cross compiling
解決方法:
#echo samba_cv_CC_NEGATIVE_ENUM_VALUES=yes>armsel-linux.cache
然後在source3目錄下執行:
make LDFLAGS="-all-static -static"
上面這外是爲把smbd, nmbd等編譯爲靜態的。
--with-static-modules=vfs_fake_perms \
這個是爲了把vfs_fake_perms模塊編譯爲靜態的,如果不是靜態的它會生成共享庫fake_perms.so
模塊的名字可以在
source3/configure.in
中找到,在這樣的地方:
dnl Add modules that have to be built by default here
dnl These have to be built static:
default_static_modules="pdb_smbpasswd pdb_tdbsam pdb_wbc_sam rpc_lsarpc rpc_samr rpc_winreg rpc_initshutdown rpc_dssetup rpc_wkssvc rpc_svcctl rpc_ntsvcs rpc_netlogon rpc_netdfs rpc_srvsvc rpc_spoolss rpc_eventlog auth_sam auth_unix auth_winbind auth_wbc auth_server
auth_domain auth_builtin auth_netlogond vfs_default nss_info_template"
對於samba的配置文件在:
/data/data/samba/etc/samba/smb.conf
內容如下:
[global]
interfaces = wlan0 eth0 lo
workgroup = WORKGROUP
server string = Samba on Android
netbios name = ANDROID
remote announce = 255.255.255.255
encrypt passwords = yes
security = USER
restrict anonymous = 1
load printers = no
printcap name = /dev/null
disable spoolss = yes
deadtime = 5
delete readonly = yes
nt acl support = no
inherit permissions = yes
socket options = SO_SNDBUF=16384 SO_RCVBUF=16384
[sdcard]
vfs objects = fake_perms
comment = Android /mnt/sdcard
path = /mnt/sdcard
force user = root
read only = no
writable = yes
guest ok = no
注意下面這幾行:
vfs objects = fake_perms
force user = root
samba的環境設置:
注意配置腳本中的:
RUNTIME_DIR=/data/data/samba
創建幾個文件夾:
mkdir /data/data/samba/etc
mkdir /data/data/samba/var/log
mkdir /data/data/samba/var/lock
mkdir /data/data/samba/lib
mkdir /data/data/samba/etc/samba
mkdir /tmp
/tmp這個目錄是必須的,不然看不到共享目錄。
這個目錄應該可以放到任一位置。
這個目錄可能通過下面的命令來指定:
export TMPDIR=/data/data/samba/var/tmp/
在
lib/util/util.c
中有這樣的函數:
_PUBLIC_ const char *tmpdir(void)
{
char *p;
if ((p = getenv("TMPDIR")))
return p;
return "/tmp";
}
創建幾個空文件:
/data/data/samba/etc/printcap
/data/data/samba/lib/valid.dat
要用編譯生成的程序:
nmbd
smbd
smbpasswd
testparm
使用時首先要用smbpasswd新加一個用戶,不然,在共享目錄下不然看到文件夾。