需求
升级openssh的包,因为有漏洞的爆出,需要更新openssh的版本
处理
系统自带的版本
openssh-client_7.2p2
我们使用这个版本的打包的debian文件,下载地址
wget https://launchpad.net/ubuntu/+archive/primary/+sourcefiles/openssh/1:7.2p2-4/openssh_7.2p2-4.debian.tar.xz
下载8.4的源码
wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssh/openssh_8.2p1.orig.tar.gz
上面的是本次打包的openssh的版本
下载8.2的debian文件
wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssh/openssh_8.2p1-4ubuntu0.2.debian.tar.xz
8.2这个版本的debian文件只用来比对,不使用,用于后面缺文件的参考
准备系统好源文件
root@qilin1:/etc/apt# cat sources.list
##deb file:///media/kylin/Kylin-4.0.2 juniper main
#deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe
deb http://archive.kylinos.cn/kylin/KYLIN-ALL 4.0.2-server main restricted universe multiverse
根据需要的情况在上面的地址之间切换,基本上都可以在原始源里面找到
tar -xvf openssh_7.2p2-4.debian.tar.xz
tar -xvf openssh_8.2p1.orig.tar.gz
cp -ra debian/ openssh-8.2p1/
开始打包
dpkg-buildpackage -uc -us -b
问题:提示缺依赖包
根据提示安装依赖包
apt-get install libsystemd-dev libaudit-dev dh-autoreconf libedit-dev dh-exec libselinux1-dev libssl-dev libwrap0-dev heimdal-dev dh-systemd
单独下载
wget http://archive.kylinos.cn/kylin/KYLIN-ALL/pool/main/p/pam/libpam0g-dev_1.1.8-3.2kord3k14_arm64.deb
dpkg -i libpam0g-dev_1.1.8-3.2kord3k14_arm64.deb
再次执行
dpkg-buildpackage -uc -us -b
就开始打包了
问题:提示测试里面缺少用例文件
输出的提示如下
test_sshbuf: ...................................................................................................... 103 tests ok
test_sshkey: .......................................................................................... 90 tests ok
test_bitmap: .. 2 tests ok
/bin/sh: 9: /root/openssh/openssh-8.2p1/build-deb/regress/unittests/conversion/test_conversion: not found
Makefile:245: recipe for target 'unit' failed
make[2]: *** [unit] Error 127
make[2]: Leaving directory '/root/openssh/openssh-8.2p1/build-deb/regress'
debian/rules:155: recipe for target 'override_dh_auto_test-arch' failed
make[1]: *** [override_dh_auto_test-arch] Error 2
关闭unittest
root@qilin1:~/openssh/openssh-8.2p1# vim debian/rules
修改配置文件
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
RUN_TESTS := yes
else
RUN_TESTS :=
endif
改成
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
RUN_TESTS := no
else
RUN_TESTS :=
endif
再次执行
dpkg-buildpackage -uc -us -b
问题:有文件找不到,有文件没包含到包
make[1]: Leaving directory '/root/openssh/openssh-8.2p1'
debian/rules override_dh_install-arch
make[1]: Entering directory '/root/openssh/openssh-8.2p1'
rm -f debian/tmp/etc/ssh/sshd_config
dh_install -Nopenssh-client-udeb -Nopenssh-server-udeb --fail-missing
dh_install: openssh-server missing files: usr/share/man/man5/authorized_keys.5
dh_install: usr/share/man/man8/ssh-sk-helper.8 exists in debian/tmp but is not installed to anywhere
dh_install: usr/lib/openssh/ssh-sk-helper exists in debian/tmp but is not installed to anywhere
dh_install: missing files, aborting
debian/rules:187: recipe for target 'override_dh_install-arch' failed
make[1]: *** [override_dh_install-arch] Error 2
make[1]: Leaving directory '/root/openssh/openssh-8.2p1'
debian/rules:122: recipe for target 'binary' failed
添加到包文件
参考8.2的debian文件
修改文件
root@qilin1:~/openssh/openssh-8.2p1# vim debian/openssh-client.install
添加
usr/lib/openssh/ssh-sk-helper
usr/share/man/man8/ssh-sk-helper.8
移除一个man文件
root@qilin1:~/openssh/openssh-8.2p1# vim debian/openssh-server.install
删除
usr/share/man/man5/authorized_keys.5
再次打包
dpkg-buildpackage -uc -us -b
问题:提示没有ChangeLog.gssapi
出错提示如下
make[1]: Leaving directory '/root/openssh/openssh-8.2p1'
debian/rules override_dh_installdocs
make[1]: Entering directory '/root/openssh/openssh-8.2p1'
dh_installdocs \
-Nopenssh-client-ssh1 -Nopenssh-server -Nopenssh-sftp-server
cp: cannot stat 'ChangeLog.gssapi': No such file or directory
dh_installdocs: cp --reflink=auto -a ChangeLog.gssapi debian/openssh-client/usr/share/doc/openssh-client returned exit code 1
debian/rules:207: recipe for target 'override_dh_installdocs' failed
make[1]: *** [override_dh_installdocs] Error 2
make[1]: Leaving directory '/root/openssh/openssh-8.2p1'
debian/rules:122: recipe for target 'binary' failed
make: *** [binary] Error 2
dpkg-buildpackage: error: debian/rules binary gave error exit status 2
删除掉相关的文件即可
修改配置文件
root@qilin1:~/openssh/openssh-8.2p1# vim debian/openssh-client.docs
删除
ChangeLog.gssapi
再次打包
dpkg-buildpackage -uc -us -b
问题:输出的包名称不对
打包出来的名称不对,需要修改
root@qilin1:~/openssh/openssh-8.2p1# vim debian/changelog
修改
openssh (1:7.2p2-4) unstable; urgency=medium
* Drop dependency on libnss-files-udeb (closes: #819686).
* Policy version 3.9.7: no changes required.
修改为
openssh (1:8.2p1-4) unstable; urgency=medium
* Drop dependency on libnss-files-udeb (closes: #819686).
* Policy version 3.9.7: no changes required.
deb使用的是change log进行的包名称控制
现在的包打出来,存在一个问题,安装的时候需要重启ssh,重启就会卡死,这个地方是官方存在一个bug,我们需要处理下
问题:打的包无法安装(无法重启进程引起)
修改源码sshd.c
在开头添加
#include <systemd/sd-daemon.h>
在这个server_accept_loop 函数调用行的上面
/* Accept a connection and return in a forked child */
server_accept_loop(&sock_in, &sock_out,
&newsock, config_s);
}
添加
sd_notify(0, "READY=1");
修改后如下
/* Signal systemd that we are ready to accept connections */
sd_notify(0, "READY=1");
/* Accept a connection and return in a forked child */
server_accept_loop(&sock_in, &sock_out,
&newsock, config_s);
代码修改后,这里存在一个问题,上面的函数编译的时候找不到systemd/sd-daemon.h这个,需要在编译的地方加入库的引用
这个地方的库引用又是其它文件设置的,所以这里需要修改下
root@qilin1:~/openssh/openssh-8.2p1# vim configure.ac
if test "x$openssl" = "xyes" ; then
LIBS="-lcrypto $LIBS"
AC_TRY_LINK_FUNC([RAND_add], ,
修改为
if test "x$openssl" = "xyes" ; then
LIBS="-lcrypto -lsystemd $LIBS"
AC_TRY_LINK_FUNC([RAND_add], ,
添加了一个 -lsystemd
再次编译
得到的包只用取下面的即可
root@qilin1:~/openssh/good# ll
total 964
drwxr-xr-x 2 root root 4096 Oct 20 16:05 ./
drwxr-xr-x 6 root root 4096 Oct 20 16:05 ../
-rw-r--r-- 1 root root 625760 Oct 20 16:04 openssh-client_8.2p1-4_arm64.deb
-rw-r--r-- 1 root root 303494 Oct 20 16:04 openssh-server_8.2p1-4_arm64.deb
-rw-r--r-- 1 root root 41852 Oct 20 16:04 openssh-sftp-server_8.2p1-4_arm64.deb
总结
按照上面的步骤以后就可以打出一个可以使用的包,里面比较关键的是后面的卡死的问题,这个应该后面的版本都通用的,是进程没有通知systemd引起的
其它的就是一些打包过程中版本变化的一些处理