参考这一篇文章http://blog.csdn.net/jk198310/article/details/15809341
然后结合自己实际操作过程中遇到的一些问题总结出来这个流程
最近做一个关于把samba服务移植到安卓项目,网上不乏一些文章,但是照着文章做还是会出现好多问题,不得不各种百度,google,终于克服困难成功运行起来,
所以把自己记得的流程记录下来,结合网上一些文章总结,并将自己实际遇到的问题贴出来;
废话少说
下面是具体流程:
我用的samba包是samba-3.5.9,交叉编译工具包是arm-linux-gcc-4.4.3.tar.gz
首先解压samba-3.5.9.tar.gz,进入到
samba-3.5.9目录下的source3目录下
:~/programfiles$ cd samba-3.5.9/source3/
:~/programfiles/samba-3.5.9/source3$
source3/lib/system.c作修改4个函数
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)
为了避免出错,建议先备份system.文件,或者像我这样把原始四个函数注释掉,然后添加修改后的函数,如下:
/*
struct passwd *sys_getpwnam(const char *name)
{
return getpwnam(name);
}
struct passwd *sys_getpwuid(uid_t uid)
{
return getpwuid(uid);
}
struct group *sys_getgrnam(const char *name)
{
return getgrnam(name);
}
struct group *sys_getgrgid(gid_t gid)
{
return getgrgid(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);
}
然后在source3目录下编写交叉编译的配置脚本insatll:
#!/bin/bash
CROSS_COMPILE=/home/sunfch/programfiles/opt/FriendlyARM/toolschain/4.4.3/bin/arm-none-linux-gnueabi- //这个根据你自己解压后交叉编译工具的目录,及选择arm-none-linux-gnueabi-gcc 编译,
RUNTIME_DIR=/data/data/samba
./configure \
CC="$CROSS_COMPILE"gcc \
AR="$CROSS_COMPILE"ar \
LD="$CROSS_COMPILE"ld \
RANLIB="$CROSS_COMPILE"ranlib \
--host=i686 \
--target=arm-linux \
--disable-cups \
--disable-iprint \
--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 \
如果出现如下错误:
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等编译为静态的。(不然在Android上执行会出现 no such file or directory问题)
我在执行这一步遇到了以下错误:
error:file not recognized;file format not recognized
或者
configure:error: require function not found
错误纠结了很长时间,最后才发现交叉编译gcc版本问题,make distclean清除,将交叉编译工具改为我上面说的工具,应该就没问题了:
随便在某个目录下(能快速找到就行)建一个smb.conf配置文件,比如我直接在source3下
vim smb.conf
[global]
interfaces = 192.168.0.103/24
workgroup = WORKGROUP
server string = Samba on Android
netbios name = ANDROID
remote announce = 255.255.255.255
encrypt passwords = yes
security = user
#security = share
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
[test]
#vfs objects = fake_perms
comment = Android /mnt/sdcard
#path = /mnt/sdcard
path = /data/data/samba/var/tmp
#path = /etc
force user = root
read only = no
writable = yes
#guest ok = no
browseable = yes
然后建立adb shell 进入到手机adb下
cd /data/data/
mkdir samba
cd samba
mkdir bin etc lib var
cd etc
mkdir samba
cd ../var
mkdir lock tmp log
文件夹建立完成后exit退出adb,然后在 source3目录下
adb push smb.conf /data/data/samba/etc/samba //将smb.conf导入手机/data/data/samba/etc/samba中
进入到bin目录下:
adb push smbd /data/data/samba/bin
adb push smbpasswd /data/data/samba/bin
在adb下用
export TMPDIR=/data/data/samba/var/tmp/ //设置TMPDIR环境变量
bin/smbd -D 启动samba服务,
bin/smbpasswd -a root 添加root用户
你在tmp目录下建立一个目录share,
然后在adb下用netcfg命令查看手机IP 地址;
这时候你就可以通过windows下,用win+R键调出运行框
输入\\192.168.0.103
就可输入root和密码,登录成功就可一看到share目录
本人亲测
有什么问题可以联系我:qq:996340566
skype:zhou.lei1992
阅读(3229) | 评论(0) | 转发(0) |