我确实在 stackoverflow 上查找了同样的问题,但无法找出我的系统上出了什么问题。
{编辑} 不确定为什么这个问题被否决了。请在下面发表评论,这样我们就知道不应该在这里问什么了。
问题描述:ssh连接成功。sftp认证后关闭。
以下是我在 DEBUG3 级别 sshd 日志中发现的内容:
Nov 15 05:56:56 cz1 sshd[9712]: subsystem request for sftp by user sftpuser
Nov 15 05:56:56 cz1 sshd[9712]: debug1: subsystem: exec() /usr/lib/openssh/sftp-server -p /opt/bbee/lib/libbbee_sftp_stats.so.0.0.0
Nov 15 05:56:56 cz1 sshd[9712]: debug2: fd 3 setting TCP_NODELAY
Nov 15 05:56:56 cz1 sshd[9712]: debug2: fd 9 setting O_NONBLOCK
Nov 15 05:56:56 cz1 sshd[9712]: debug2: fd 8 setting O_NONBLOCK
Nov 15 05:56:56 cz1 sshd[9712]: debug2: fd 11 setting O_NONBLOCK
Nov 15 05:56:56 cz1 sshd[9713]: debug3: Copy environment: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
Nov 15 05:56:56 cz1 sshd[9713]: debug3: Copy environment: LD_LIBRARY_PATH=/opt/bbee/thirdparty/lib/5.x:/opt/bbee/lib:/opt/bbee/thirdparty/lib:/opt/bbee/thirdparty/lib/openhpi
Nov 15 05:56:56 cz1 sshd[9713]: debug3: Copy environment: LANG=en_US.UTF-8
Nov 15 05:56:56 cz1 sshd[9713]: debug3: Copy environment: LANGUAGE=en_US:
Nov 15 05:56:56 cz1 sshd[9712]: debug1: Received SIGCHLD.
Nov 15 05:56:56 cz1 sshd[9712]: debug1: session_by_pid: pid 9713
Nov 15 05:56:56 cz1 sshd[9712]: debug1: session_exit_message: session 0 channel 0 pid 9713
Nov 15 05:56:56 cz1 sshd[9712]: debug2: channel 0: request exit-signal confirm 0
Nov 15 05:56:56 cz1 sshd[9712]: debug1: session_exit_message: release channel 0
Nov 15 05:56:56 cz1 sshd[9712]: debug2: channel 0: write failed
Nov 15 05:56:56 cz1 sshd[9712]: debug2: channel 0: close_write
Nov 15 05:56:56 cz1 sshd[9712]: debug2: channel 0: send eow
Nov 15 05:56:56 cz1 sshd[9712]: debug2: channel 0: output open -> closed
Nov 15 05:56:56 cz1 sshd[9712]: debug2: channel 0: read<=0 rfd 9 len 0
Nov 15 05:56:56 cz1 sshd[9712]: debug2: channel 0: read failed
Nov 15 05:56:56 cz1 sshd[9712]: debug2: channel 0: close_read
Nov 15 05:56:56 cz1 sshd[9712]: debug2: channel 0: input open -> drain
Nov 15 05:56:56 cz1 sshd[9712]: debug2: channel 0: read 0 from efd 11
Nov 15 05:56:56 cz1 sshd[9712]: debug2: channel 0: closing read-efd 11
Nov 15 05:56:56 cz1 sshd[9712]: debug2: channel 0: ibuf empty
Nov 15 05:56:56 cz1 sshd[9712]: debug2: channel 0: send eof
Nov 15 05:56:56 cz1 sshd[9712]: debug2: channel 0: input drain -> closed
Nov 15 05:56:56 cz1 sshd[9712]: debug2: channel 0: send close
Nov 15 05:56:56 cz1 sshd[9712]: debug2: notify_done: reading
Nov 15 05:56:56 cz1 sshd[9712]: debug3: channel 0: will not send data after close
Nov 15 05:56:56 cz1 sshd[9712]: debug2: channel 0: rcvd close
Nov 15 05:56:56 cz1 sshd[9712]: Received disconnect from 192.168.2.17: 11: disconnected by user
Nov 15 05:56:56 cz1 sshd[9712]: debug1: do_cleanup
Nov 15 05:56:56 cz1 sshd[9712]: debug3: PAM: sshpam_thread_cleanup entering
Nov 15 05:56:56 cz1 sshd[9310]: debug3: mm_request_receive entering
Nov 15 05:56:56 cz1 sshd[9310]: debug1: do_cleanup
Nov 15 05:56:56 cz1 sshd[9310]: debug1: PAM: cleanup
Nov 15 05:56:56 cz1 sshd[9310]: debug1: PAM: closing session
Nov 15 05:56:56 cz1 sshd[9310]: pam_unix(sshd:session): session closed for user sftpuser
我在 kern.log 中发现以下内容
Nov 15 05:52:22 cz1 kernel: [97296.394274] sftp-server[65421]: segfault at 0 ip 00007f26e15c6b94 sp 00007fffaa9d0470 error 4 in libc-2.15.so[7f26e1558000+1b4000]
Nov 15 05:56:56 cz1 kernel: [97569.802937] sftp-server[9713]: segfault at 0 ip 00007f8d75558b94 sp 00007fff64043130 error 4 in libc-2.15.so[7f8d754ea000+1b4000]
sftp 仅对 sftpuser 失败,对我创建的另一个用户则不失败。
sftpuser 的值为/etc/passwd
:
sftpuser:x:1004:1004::/home/sftpuser:/bin/bash
我还看到我有一个主目录sftpuser
ls -ltar /home/sftpuser/
total 48
-rw-r--r-- 1 sftpuser sftpuser 220 Mar 28 2013 .bash_logout
-rw-r--r-- 1 sftpuser sftpuser 3629 Jun 6 21:47 .bashrc
drwxr-xr-x 26 root root 4096 Jun 7 02:00 ..
drwx------ 2 sftpuser sftpuser 4096 Nov 11 07:51 .cache
-rw-rw-r-- 1 sftpuser sftpuser 11723 Nov 15 02:44 sftpfail
-rw-r--r-- 1 sftpuser sftpuser 675 Nov 15 04:21 .profile
-rw------- 1 sftpuser sftpuser 1973 Nov 15 04:56 .viminfo
drwx------ 2 sftpuser sftpuser 4096 Nov 15 04:56 .ssh
drwxr-xr-x 4 sftpuser sftpuser 4096 Nov 15 04:56 .
-rw------- 1 sftpuser sftpuser 701 Nov 15 04:56 .bash_history
我的 sshd 配置如下:
UsePAM yes
Subsystem sftp /usr/lib/openssh/sftp-server -p /opt/bbee/lib/libbbee_sftp_stats.so.0.0.0
sftp-server 对 libbbee_sftp_stats.so.0.0.0 执行 dlopen。我们将所有库都放在正确的路径中。我看到 LD_LIBRARY_PATH 正在为 sshd 守护进程导出。
/home/sftpuser/.profile, .bashrc
此外我也没有发现任何回声
注意:同一配置适用于其他用户。
我错过了什么?
{编辑}
我已经修改了 sftp-server 代码以获取回调。
*(void **) (&plugin_process) = dlsym(plugin, "sftp_plugin_process");
if ((plugin_err = dlerror()) != NULL) {
fatal("Failed to find \"sftp_plugin_process\" function in \"%s\": \"%s\"",
optarg, plugin_err);
}
类似地,在执行 open() 时我做了一些更改以调用我的回调:
在sftp-server代码中打开:
static void
process_open(void)
{
u_int32_t id, pflags;
Attrib *a;
char *name;
int handle, fd, flags, mode, status = SSH2_FX_FAILURE;
id = get_int();
name = get_string(NULL);
pflags = get_int(); /* portable flags */
debug3("request %u: open flags %d", id, pflags);
a = get_attrib();
flags = flags_from_portable(pflags);
mode = (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? a->perm : 0666;
logit("open \"%s\" flags %s mode 0%o",
name, string_from_portable(pflags), mode);
if (readonly &&
((flags & O_ACCMODE) == O_WRONLY || (flags & O_ACCMODE) == O_RDWR))
status = SSH2_FX_PERMISSION_DENIED;
else {
fd = open(name, flags, mode);
if (fd < 0) {
status = errno_to_portable(errno);
} else {
handle = handle_new(HANDLE_FILE, name, fd, NULL);
if (handle < 0) {
close(fd);
} else {
send_handle(id, handle);
status = SSH2_FX_OK;
}
}
}
if (status != SSH2_FX_OK) {
send_status(id, status);
}
if (plugin != NULL) { ///////////////////////////////// ADDED CODE HERE TO GET A CALLBACK found in libbee_sftp_stats.so.0.0.0
plugin_process(cookie, client_addr, name, SSH2_FXP_OPEN);
} ////////////////////////////////////////////////////////////////////////////////////////////////
xfree(name);
}