1
1
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@652 7dcaeef0-15fb-0310-b436-a5af3365683c
Этот коммит содержится в:
Andreas Schneider 2009-04-29 11:54:32 +00:00
родитель f119a27bb6
Коммит e13c2871ff

Просмотреть файл

@ -175,70 +175,79 @@ void ssh_bind_fd_toaccept(SSH_BIND *ssh_bind) {
ssh_bind->toaccept = 1; ssh_bind->toaccept = 1;
} }
SSH_SESSION *ssh_bind_accept(SSH_BIND *ssh_bind){ SSH_SESSION *ssh_bind_accept(SSH_BIND *ssh_bind) {
SSH_SESSION *session; SSH_SESSION *session;
PRIVATE_KEY *dsa=NULL, *rsa=NULL; PRIVATE_KEY *dsa = NULL;
PRIVATE_KEY *rsa = NULL;
int fd = -1; int fd = -1;
if(ssh_bind->bindfd<0){ if (ssh_bind->bindfd < 0) {
ssh_set_error(ssh_bind,SSH_FATAL,"Can't accept new clients on a " ssh_set_error(ssh_bind, SSH_FATAL,
"not bound socket."); "Can't accept new clients on a not bound socket.");
return NULL; return NULL;
} }
if(!ssh_bind->options->dsakey && !ssh_bind->options->rsakey){
ssh_set_error(ssh_bind,SSH_FATAL,"DSA or RSA host key file must be set before accept()"); if (ssh_bind->options->dsakey == NULL || ssh_bind->options->rsakey == NULL) {
ssh_set_error(ssh_bind, SSH_FATAL,
"DSA or RSA host key file must be set before accept()");
return NULL; return NULL;
} }
if(ssh_bind->options->dsakey){
dsa=_privatekey_from_file(ssh_bind,ssh_bind->options->dsakey,TYPE_DSS); if (ssh_bind->options->dsakey) {
if(!dsa) dsa = _privatekey_from_file(ssh_bind, ssh_bind->options->dsakey, TYPE_DSS);
if (dsa == NULL) {
return NULL; return NULL;
} }
if(ssh_bind->options->rsakey){ }
rsa=_privatekey_from_file(ssh_bind,ssh_bind->options->rsakey,TYPE_RSA);
if(!rsa){ if (ssh_bind->options->rsakey) {
if(dsa) rsa = _privatekey_from_file(ssh_bind, ssh_bind->options->rsakey, TYPE_RSA);
if (rsa == NULL) {
privatekey_free(dsa); privatekey_free(dsa);
return NULL; return NULL;
} }
} }
fd = accept(ssh_bind->bindfd, NULL, NULL); fd = accept(ssh_bind->bindfd, NULL, NULL);
if(fd<0){ if (fd < 0) {
ssh_set_error(ssh_bind,SSH_FATAL,"Accepting a new connection: %s", ssh_set_error(ssh_bind, SSH_FATAL,
"Accepting a new connection: %s",
strerror(errno)); strerror(errno));
if(dsa)
privatekey_free(dsa); privatekey_free(dsa);
if(rsa)
privatekey_free(rsa); privatekey_free(rsa);
return NULL; return NULL;
} }
session=ssh_new();
session->server=1; session = ssh_new();
session->version=2; if (session == NULL) {
ssh_set_error(ssh_bind, SSH_FATAL, "Not enough space");
privatekey_free(dsa);
privatekey_free(rsa);
return NULL;
}
session->server = 1;
session->version = 2;
session->options = ssh_options_copy(ssh_bind->options); session->options = ssh_options_copy(ssh_bind->options);
if (session->options == NULL) { if (session->options == NULL) {
ssh_set_error(ssh_bind, SSH_FATAL, "No space left"); ssh_set_error(ssh_bind, SSH_FATAL, "No space left");
if (dsa)
privatekey_free(dsa); privatekey_free(dsa);
if (rsa)
privatekey_free(rsa); privatekey_free(rsa);
ssh_cleanup(session); ssh_cleanup(session);
return NULL; return NULL;
} }
ssh_socket_free(session->socket); ssh_socket_free(session->socket);
session->socket=ssh_socket_new(session); session->socket = ssh_socket_new(session);
if (session->socket == NULL) { if (session->socket == NULL) {
if (dsa)
privatekey_free(dsa); privatekey_free(dsa);
if (rsa)
privatekey_free(rsa); privatekey_free(rsa);
ssh_cleanup(session); ssh_cleanup(session);
return NULL; return NULL;
} }
ssh_socket_set_fd(session->socket,fd); ssh_socket_set_fd(session->socket,fd);
session->dsa_key=dsa; session->dsa_key = dsa;
session->rsa_key=rsa; session->rsa_key = rsa;
return session; return session;
} }