« »

[原创]移植常用软件到ARM平台之samba2

1.平台环境:
ARM1026EJ-Sid(wb)B rev 2 (v5l)

2.移植软件:
samba2(下载:samba2.2.12)

3.移植目标:
能在目标平台上正常以后台进程方式运行
能正常输出日志,便于查错(日常运行时关闭)
能提供基于用户的认证功能

4.移植说明:
因samba3较大,相对samba2也只是提供了对域控的支持,一般情况下用不到,所以选择了samba2的最后一个版本。
最终生成的配置文件位置由./configure –prefix=/xx/xx决定,需特别注意,否则将导致进程无法加载。
另外如用windows访问共享时出现无权访问的问题,请注销或重启再访问即可解决问题。

具体移植步骤:

1.解压源码
2.进入源码目录:

  1. cd samba-2.2.12/source

3.修改源码:
(1)在include/config.h文件里最后面增加:

  1. #define USE_SETEUID 1

(2)修改lib/util_unistr.c第739、762行为:

  1. return True;

(3)在passdb/pdb_tdb.c第44行开始添加如下代码:

  1. #define PWD_BUFFER_SIZE 256
  2. char bb_path_passwd_file[]="/etc/passwd" ;
  3. struct passwd *__getpwent(int pwd_fd)
  4. {
  5.        static char line_buff[PWD_BUFFER_SIZE];
  6.        static struct passwd passwd;
  7.        char *field_begin;
  8.         char *endptr;
  9.         char *gid_ptr=NULL;
  10.         char *uid_ptr=NULL;
  11.         int line_len;
  12.         int i;
  13.  
  14.         restart:
  15.         if ((line_len = read(pwd_fd, line_buff, PWD_BUFFER_SIZE)) <= 0)
  16.                 return NULL;
  17.         field_begin = strchr(line_buff, '\n');
  18.         if (field_begin != NULL)
  19.                 lseek(pwd_fd, (long) (1 + field_begin - (line_buff + line_len)),SEEK_CUR);
  20.         else
  21.            {                                             
  22.                 do
  23.                 {
  24.                        if ((line_len = read(pwd_fd, line_buff, PWD_BUFFER_SIZE)) <= 0)
  25.                                        return NULL;
  26.                 } while (!(field_begin = strchr(line_buff, '\n')));
  27.                 lseek(pwd_fd, (long) (field_begin - line_buff) - line_len + 1,SEEK_CUR);
  28.                 goto restart;
  29.         }
  30.         if (*line_buff == '#' || *line_buff == ' ' || *line_buff == '\n' ||*line_buff =='\t')
  31.                 goto restart;
  32.         *field_begin = '\0';
  33.         field_begin = line_buff;
  34.         for (i = 0; i < 7; i++)
  35.         {
  36.                  switch (i)
  37.                  {
  38.                        case 0:
  39.                                passwd.pw_name = field_begin;
  40.                                break;
  41.                       case 1:
  42.                                passwd.pw_passwd = field_begin;
  43.                                break;
  44.                       case 2:
  45.                                uid_ptr = field_begin;
  46.                                break;
  47.                       case 3:
  48.                                gid_ptr = field_begin;
  49.                                break;
  50.                       case 4:
  51.                       passwd.pw_gecos = field_begin;
  52.                                break;
  53.                       case 5:
  54.                                passwd.pw_dir = field_begin;
  55.                                break;
  56.                       case 6:
  57.                                passwd.pw_shell = field_begin;
  58.                                break;
  59.                }
  60.                if (i < 6)
  61.                    {
  62.                       field_begin = strchr(field_begin, ':');
  63.                       *field_begin++ = '\0';
  64.                }
  65.       }
  66.       passwd.pw_gid = (gid_t) strtoul(gid_ptr, &endptr, 10);
  67.       if (*endptr != '\0')
  68.                passwd.pw_uid = (uid_t) strtoul(uid_ptr, &endptr, 10);
  69.       if (*endptr != '\0')
  70.                goto restart;
  71.       return &passwd;
  72. }
  73. struct passwd *getpwnam(const char *name)
  74. {
  75.       int passwd_fd;
  76.       struct passwd *passwd;
  77.       if (name == NULL)
  78.       {
  79.                errno = EINVAL;
  80.                return NULL;
  81.       }
  82.       if ((passwd_fd = open(bb_path_passwd_file, O_RDONLY)) < 0)
  83.                return NULL;
  84.       while ((passwd = __getpwent(passwd_fd)) != NULL)
  85.                if (!strcmp(passwd->pw_name, name))
  86.                {
  87.                        close(passwd_fd);
  88.                        return passwd;
  89.                }
  90.       close(passwd_fd);
  91.       return NULL;
  92. }
  93. struct passwd *getpwuid(uid_t uid)
  94. {
  95.       int passwd_fd;
  96.          struct passwd *passwd;
  97.          if ((passwd_fd = open("/etc/passwd", O_RDONLY)) < 0)
  98.                  return NULL;
  99.          while ((passwd = __getpwent(passwd_fd)) != NULL)
  100.                  if (passwd->pw_uid == uid) {
  101.                           close(passwd_fd);
  102.                           return passwd;
  103.                   }
  104.          close(passwd_fd);
  105.          return NULL;
  106. }
  107. int setgroups(size_t size, const gid_t * list)
  108. {
  109.          return 0;
  110. }

4.编译源码
(1)设置环境变量:

  1. export CC=arm-linux-gcc-4.2.4
  2. export LDFLAGS='-L/usr/local/arm-linux/lib'
  3. export CFLAGS='-O3 -s -static -I/usr/local/arm-linux/include'

(2)编译

  1. ./configure --prefix=/mnt/usb1_1/samba/ --host=arm-linux
  2. make
  3. make install

5.软件移植
(1)复制下列文件及目录

  1. /mnt/usb1_1/samba
  2. /mnt/usb1_1/samba/bin
  3. /mnt/usb1_1/samba/var
  4. /mnt/usb1_1/samba/private
  5. /mnt/usb1_1/samba/lib

(2)使用方法
I.添加用户名及设置密码

  1. adduser linuxany
  2. bin/smbpasswd -a linuxany
  3. bin/smbpasswd linuxany linuxany.com
  4. (说明:linuxany为用户名,linuxany.com为密码)

II.启动samba服务

  1. sbin/nmbd -D
  2. sbin/smbd -D

您还可能感兴趣的内容

日志信息 »

该日志于2010-02-15 17:31由 admin 发表在ARM分类下, 你可以发表评论。除了可以将这个日志以保留源地址及作者的情况下引用到你的网站或博客,还可以通过RSS 2.0订阅这个日志的所有评论。

没有评论

发表评论 »


返回顶部