version 1.75, 2008/01/21 17:24:30 |
version 1.76, 2008/02/04 21:53:00 |
|
|
if (msg_len > SFTP_MAX_MSG_LENGTH) { |
if (msg_len > SFTP_MAX_MSG_LENGTH) { |
error("bad message from %s local user %s", |
error("bad message from %s local user %s", |
client_addr, pw->pw_name); |
client_addr, pw->pw_name); |
cleanup_exit(11); |
sftp_server_cleanup_exit(11); |
} |
} |
if (buf_len < msg_len + 4) |
if (buf_len < msg_len + 4) |
return; |
return; |
|
|
break; |
break; |
} |
} |
/* discard the remaining bytes from the current packet */ |
/* discard the remaining bytes from the current packet */ |
if (buf_len < buffer_len(&iqueue)) |
if (buf_len < buffer_len(&iqueue)) { |
fatal("iqueue grew unexpectedly"); |
error("iqueue grew unexpectedly"); |
|
sftp_server_cleanup_exit(255); |
|
} |
consumed = buf_len - buffer_len(&iqueue); |
consumed = buf_len - buffer_len(&iqueue); |
if (msg_len < consumed) |
if (msg_len < consumed) { |
fatal("msg_len %d < consumed %d", msg_len, consumed); |
error("msg_len %d < consumed %d", msg_len, consumed); |
|
sftp_server_cleanup_exit(255); |
|
} |
if (msg_len > consumed) |
if (msg_len > consumed) |
buffer_consume(&iqueue, msg_len - consumed); |
buffer_consume(&iqueue, msg_len - consumed); |
} |
} |
|
|
/* Cleanup handler that logs active handles upon normal exit */ |
/* Cleanup handler that logs active handles upon normal exit */ |
void |
void |
cleanup_exit(int i) |
sftp_server_cleanup_exit(int i) |
{ |
{ |
if (pw != NULL && client_addr != NULL) { |
if (pw != NULL && client_addr != NULL) { |
handle_log_exit(); |
handle_log_exit(); |
|
|
} |
} |
|
|
static void |
static void |
usage(void) |
sftp_server_usage(void) |
{ |
{ |
extern char *__progname; |
extern char *__progname; |
|
|
|
|
} |
} |
|
|
int |
int |
main(int argc, char **argv) |
sftp_server_main(int argc, char **argv) |
{ |
{ |
fd_set *rset, *wset; |
fd_set *rset, *wset; |
int in, out, max, ch, skipargs = 0, log_stderr = 0; |
int in, out, max, ch, skipargs = 0, log_stderr = 0; |
|
|
break; |
break; |
case 'h': |
case 'h': |
default: |
default: |
usage(); |
sftp_server_usage(); |
} |
} |
} |
} |
|
|
|
|
|
|
if ((cp = getenv("SSH_CONNECTION")) != NULL) { |
if ((cp = getenv("SSH_CONNECTION")) != NULL) { |
client_addr = xstrdup(cp); |
client_addr = xstrdup(cp); |
if ((cp = strchr(client_addr, ' ')) == NULL) |
if ((cp = strchr(client_addr, ' ')) == NULL) { |
fatal("Malformed SSH_CONNECTION variable: \"%s\"", |
error("Malformed SSH_CONNECTION variable: \"%s\"", |
getenv("SSH_CONNECTION")); |
getenv("SSH_CONNECTION")); |
|
sftp_server_cleanup_exit(255); |
|
} |
*cp = '\0'; |
*cp = '\0'; |
} else |
} else |
client_addr = xstrdup("UNKNOWN"); |
client_addr = xstrdup("UNKNOWN"); |
|
|
if ((pw = getpwuid(getuid())) == NULL) |
if ((pw = getpwuid(getuid())) == NULL) { |
fatal("No user found for uid %lu", (u_long)getuid()); |
error("No user found for uid %lu", (u_long)getuid()); |
|
sftp_server_cleanup_exit(255); |
|
} |
pw = pwcopy(pw); |
pw = pwcopy(pw); |
|
|
logit("session opened for local user %s from [%s]", |
logit("session opened for local user %s from [%s]", |
|
|
if (errno == EINTR) |
if (errno == EINTR) |
continue; |
continue; |
error("select: %s", strerror(errno)); |
error("select: %s", strerror(errno)); |
cleanup_exit(2); |
sftp_server_cleanup_exit(2); |
} |
} |
|
|
/* copy stdin to iqueue */ |
/* copy stdin to iqueue */ |
|
|
len = read(in, buf, sizeof buf); |
len = read(in, buf, sizeof buf); |
if (len == 0) { |
if (len == 0) { |
debug("read eof"); |
debug("read eof"); |
cleanup_exit(0); |
sftp_server_cleanup_exit(0); |
} else if (len < 0) { |
} else if (len < 0) { |
error("read: %s", strerror(errno)); |
error("read: %s", strerror(errno)); |
cleanup_exit(1); |
sftp_server_cleanup_exit(1); |
} else { |
} else { |
buffer_append(&iqueue, buf, len); |
buffer_append(&iqueue, buf, len); |
} |
} |
|
|
len = write(out, buffer_ptr(&oqueue), olen); |
len = write(out, buffer_ptr(&oqueue), olen); |
if (len < 0) { |
if (len < 0) { |
error("write: %s", strerror(errno)); |
error("write: %s", strerror(errno)); |
cleanup_exit(1); |
sftp_server_cleanup_exit(1); |
} else { |
} else { |
buffer_consume(&oqueue, len); |
buffer_consume(&oqueue, len); |
} |
} |