samba源码编译安装(版本4.13.0)

前言

一般来说,安装samba最快的方式应该是通过yum的方式,只需一行命令:yum install -y samba即可完成。为什么需要通过源码编译安装呢?
原因有二:

  • 通过yum方式安装的没法修改源码,打补丁
  • yum方式不能安装到目前最新的版本4.13.0,通过yum安装目前是4.10.0

我们最终的目的是为了修补漏洞而采用源码编译安装,这是前段时间安全扫描爆出的漏洞:

看两个漏洞的详情:
在这里插入图片描述
在这里插入图片描述
可见有的漏洞是出现在指定的版本,我们可以通过升级版本解决,也可以在当前版本打补丁,但要通过源码安装才行,另一方面只是一味的升级也不解决问题,有些问题是高版本也存在,最后还是得打补丁!
所以,本文就是先通过源码安装的方式升级到最高的版本,后面再针对漏洞打补丁。

编译安装samba

下载三个包

  • samba-4.13.0.tar.gz
  • gnutls-3.6.4.tar.xz
  • nettle-3.4.1.tar.gz

下载链接:链接:https://pan.baidu.com/s/1i3PA5Sagjd_ozypYiZPskw 密码:wzau

安装依赖

yum install -y python3 python36 python3-devel perl-Parse-Yapp libtasn1-devel libunistring-devel zlib-devel gmp-devel libldap2-dev openldap-devel m4

共需要安装samba、gnutls、nettle

因为安装samba依赖gnutls的版本 > 3.4.7,所以得升级gnutls,升级gnutls它又依赖nettle,这里我们还是按照正常安装的逻辑来进行,缺少依赖就依次去补充依赖,找不到文件就考虑使用软连接,下面是我上次安装的过程记录。

1、进入解压后的samba目录执行:

./configure --disable-python --without-ad-dc --without-json --without-libarchive

错误:

Checking for GnuTLS >= 3.4.7
['/usr/bin/pkg-config', 'gnutls >= 3.4.7', '--cflags', '--libs', 'gnutls']
err: Package gnutls was not found in the pkg-config search path.
Perhaps you should add the directory containing `gnutls.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gnutls' found
Package gnutls was not found in the pkg-config search path.
Perhaps you should add the directory containing `gnutls.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gnutls' found

解决:安装GnuTLS 3.4.7以上的版本,现在选择gnutls-3.6.4

2、进入解压后的gnutls目录执行

./configure  --without-p11-kit 

错误:
configure: error:

*** Libnettle 3.4 was not found.
解决:安装Libnettle

3、进入解压后的nettle目录执行

3.1 卸载已存在nettle
yum remove nettle*
3.2 检查配置
./configure

结果:成功

3.3 make编译
make

结果:

m4 ./asm.m4 machine.m4 config.m4 aes-decrypt-internal.asm >aes-decrypt-internal.s
/bin/sh: m4: command not found
make[1]: *** [aes-decrypt-internal.o] Error 127
make[1]: Leaving directory `/root/samba/nettle-3.4.1'

解决:

yum install -y m4.x86_64 

再次make:

make

结果:

rsa-sign-tr.c: 在函数‘sec_equal’中:
rsa-sign-tr.c:243:3: 错误:只允许在 C99 模式下使用‘for’循环初始化声明
   for (size_t i = 0; i < limbs; i++)
   ^
rsa-sign-tr.c:243:3: 附注:使用 -std=c99 或 -std=gnu99 来编译您的代码
make[1]: *** [rsa-sign-tr.o] 错误 1
make[1]: 离开目录“/kingdom/samba/nettle-3.4.1”
make: *** [all] 错误 2

解决:

vim config.make (修改第5,6行)

CFLAGS = -g -O2 -ggdb3 -Wno-pointer-sign -Wall -W   -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes   -Wpointer-arith -Wbad-function-cast -Wnested-externs -std=c99
CXXFLAGS = -g -O2

再次make:

make

结果:成功

3.4 install安装
make install

结果:成功

nettle安装成功

4、进入gnutls继续编译

4.1 检查配置
./configure  --without-p11-kit 

结果:

configure: error: 

*** Libnettle 3.4 was not found.

解决:创建软连接

ln -s /usr/local/lib64/pkgconfig/nettle.pc /usr/lib64/pkgconfig/nettle.pc
### 我这里/usr/local/lib64/pkgconfig/这个目录下没有hogweed.pc,所以从安装包一个过去,存在就不拷
cp /root/samba/nettle-3.4.1/hogweed.pc /usr/local/lib64/pkgconfig/
ln -s /usr/local/lib64/pkgconfig/hogweed.pc /usr/lib64/pkgconfig/hogweed.pc
ln -sf /usr/local/lib64/libhogweed.so  /usr/lib64/libhogweed.so 
ln -sf /usr/local/lib64/libnettle.so.6 /usr/lib64/libnettle.so.6
ln -sf /usr/local/lib64/libhogweed.so.4 /usr/lib64/libhogweed.so.4

再次执行:

./configure  --without-p11-kit 

结果:

checking for __gmpz_cmp in -lgmp... no
configure: error: 
*** gmp was not found.

解决:

yum install -y gmp-devel

再次执行:

./configure  --without-p11-kit 

结果:

/usr/bin/ld: cannot find -lhogweed
collect2: error: ld returned 1 exit status
make[4]: *** [libgnutls.la] Error 1
make[4]: Leaving directory `/root/samba/gnutls-3.6.4/lib'
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory `/root/samba/gnutls-3.6.4/lib'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/root/samba/gnutls-3.6.4/lib'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/root/samba/gnutls-3.6.4'
make: *** [all] Error 2

解决:

ln -sf /usr/local/lib64/libhogweed.so  /usr/lib64/libhogweed.so 
ln -sf /usr/local/lib64/libnettle.so.6 /usr/lib64/libnettle.so.6

再次执行:

./configure  --without-p11-kit 

结果:成功!

4.2 make编译
make

结果:

collect2: error: ld returned 1 exit status
make[4]: *** [libgnutls.la] Error 1
make[4]: Leaving directory `/root/samba/gnutls-3.6.4/lib'
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory `/root/samba/gnutls-3.6.4/lib'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/root/samba/gnutls-3.6.4/lib'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/root/samba/gnutls-3.6.4'
make: *** [all] Error 2

解决:

ln -sf /usr/local/lib64/libhogweed.so.4 /usr/lib64/libhogweed.so.4

再次make:

make

结果:成功

4.3 install安装
make install

结果:成功

成功安装gnutils3.6.4

5、再次进入解压后的samba目录

5.1 执行./configure
./configure --disable-python --without-ad-dc --without-json --without-libarchive  --without-acl-support

结果:

Checking for GnuTLS >= 3.4.7
['/usr/bin/pkg-config', 'gnutls >= 3.4.7', '--cflags', '--libs', 'gnutls']
err: Package gnutls was not found in the pkg-config search path.
Perhaps you should add the directory containing `gnutls.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gnutls' found
Package gnutls was not found in the pkg-config search path.
Perhaps you should add the directory containing `gnutls.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gnutls' found

即使我们升级了gnutls,它还是提示没找到,原因是安装的位置没有在系统目录,需要建立软连接才能被找到

解决:建立软连接

ln -sf /usr/local/lib/pkgconfig/gnutls.pc /usr/lib64/pkgconfig/gnutls.pc
ln -sf /usr/local/lib/libgnutls.so /usr/lib64/libgnutls.so
ln -sf /usr/local/lib/libgnutls.so.30 /usr/lib64/libgnutls.so.30

再次./configure

./configure --disable-python --without-ad-dc --without-json --without-libarchive  --without-acl-support

结果:

LDAP support not found. Try installing libldap2-dev or openldap-devel. Otherwise, use --without-ldap to build without LDAP support. LDAP support is required for the LDAP passdb backend, LDAP idmap backends and ADS. ADS support improves communication with Active Directory domain controllers.

解决:

#如果安装失败直接禁用--without-ldap
yum install -y libldap2-dev openldap-devel

编译samba:

./configure --disable-python --without-ad-dc --without-json --without-libarchive  --without-acl-support --without-pam --with-shared-modules=\!vfs_snapper --without-ldap --without-ads

结果:成功!

WARNING: ans1Parser hasn't been found! Please install it (e.g. libtasn1-bin)
Checking linker accepts -Wl,-no-undefined                                                       : yes 
Checking linker accepts ['-undefined', 'dynamic_lookup']                                        : no 
-lc not needed                                                                                  : -lc is unnecessary 
Checking configure summary                                                                      : ok 
Checking compiler for PIE support                                                               : yes 
Checking compiler for full RELRO support                                                        : yes 
Checking if compiler accepts -fstack-protector-strong                                           : no 
Checking if compiler accepts -fstack-protector                                                  : no 
Checking if compiler accepts -fstack-clash-protection                                           : no configure' finished successfully (2m1.763s)
5.2 make编译
make

结果:

Waf: Leaving directory `/root/samba/samba-4.13.0/bin/default'
Build commands will be stored in bin/default/compile_commands.json
'build' finished successfully (10m35.203s)
5.3 samba安装
make install

结果:成功!

Waf: Leaving directory `/root/samba/samba-4.13.0/bin/default'
Build commands will be stored in bin/default/compile_commands.json
'install' finished successfully (3m13.572s)

启动samba

参考:https://www.cnblogs.com/coolking/p/5569154.html

启动:/usr/local/samba/sbin/smbd -D

结果:
/usr/local/samba/sbin/smbd: error while loading shared libraries: libhogweed.so.4: cannot open shared object file: No such file or directory

创建软连接:
ln -sf /usr/local/lib64/libhogweed.so.4 /usr/lib64/libhogweed.so.4

启动:/usr/local/samba/sbin/smbd -D
结果:失败,原因是没有/usr/local/samba/etc/smb.conf

解决:
1、vim /usr/local/samba/etc/smb.conf

[global]
    workgroup = WORKGROUP
    security = user
    map to guest = Bad User
    log file = /usr/local/samba/var/log.%m
    max log size = 50
    unix charset = UTF-8
#display charset = UTF-8
    guest account = nobody
    dos charset = cp936
    create mask = 777
    directory mask = 777
[kdum]
    comment = All Printers
    path = /kingdom/szkdum
    browseable = yes
    guest ok = yes
    writable = yes
    read only = no
    public = yes
    directory mode = 0777
    create mode = 0770

2、创建nobody用户,存在就把不要创建

useradd -s /sbin/nologin nobody 

3、smb中添加nobody用户

/usr/local/samba/bin/smbpasswd -a nobody

4、启动该用户

/usr/local/samba/bin/smbpasswd -e nobody

5、创建数据存储目录

mkdir -p /kingdom/szkdum

6、赋予目录777权限

chmod -R 777 /kingdom/szkdum

7、分配目录用户和用户组

chown -R nobody:nobody /kingdom/szkdum

8、启动smb

/usr/local/samba/sbin/smbd -D

9、查看进程

netstat -tlnp|grep smbd

在这里插入图片描述
有问题欢迎在评论区交流~

  • 9
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 10
    评论
当你想在CentOS 7上编译安装Samba时,可以按照以下步骤进行操作: 1. 首先,确保你的系统已经安装了一些必需的软件包,包括编译工具和依赖项。使用以下命令安装这些软件包: ```shell sudo yum install -y gcc make autoconf libtool krb5-devel libacl-devel openldap-devel libarchive-devel cups-devel readline-devel python3-devel python3-dns python3-cryptography python3-ldb python3-talloc python3-gpg python3-markdown python3-pefile python3-ipython python3-pygments ``` 2. 下载Samba的源代码。你可以从Samba官方网站(https://www.samba.org/)下载最新版本的源代码,或者使用以下命令下载稳定版本: ```shell curl -LO https://download.samba.org/pub/samba/stable/samba-{version}.tar.gz ``` 将`{version}`替换为你想要下载的版本号。 3. 解压缩下载的源代码文件: ```shell tar -zxvf samba-{version}.tar.gz ``` 4. 进入解压后的目录: ```shell cd samba-{version} ``` 5. 配置编译选项并生成Makefile: ```shell ./configure --prefix=/usr/local/samba --with-systemd ``` 这将把Samba安装到`/usr/local/samba`目录下,并启用systemd支持。 6. 编译安装Samba: ```shell make sudo make install ``` 这将会花一些时间来编译安装Samba。 完成以上步骤后,你应该成功地在CentOS 7上编译安装Samba。你可以根据需要进行额外的配置和设置。请确保按照Samba官方文档中的指南进行进一步的配置和管理。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值