summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog67
-rw-r--r--Makefile.in2
-rw-r--r--auth-options.c6
-rw-r--r--bsd-strmode.c156
-rw-r--r--bsd-strmode.h5
-rw-r--r--bufaux.c4
-rw-r--r--clientloop.c7
-rw-r--r--clientloop.h24
-rw-r--r--configure.in2
-rw-r--r--dh.c4
-rw-r--r--key.c6
-rw-r--r--openbsd-compat.h1
-rw-r--r--packet.c19
-rw-r--r--packet.h4
-rw-r--r--radix.c16
-rw-r--r--scp.c4
-rw-r--r--session.c9
-rw-r--r--sftp-server.c115
-rw-r--r--ssh-add.c4
-rw-r--r--ssh-keygen.14
-rw-r--r--ssh-keygen.c4
-rw-r--r--ssh-keyscan.c27
-rw-r--r--ssh-rsa.c7
-rw-r--r--ssh.c19
-rw-r--r--sshconnect.c17
-rw-r--r--sshconnect.h2
-rw-r--r--sshconnect1.c8
-rw-r--r--sshd.c14
28 files changed, 424 insertions, 133 deletions
diff --git a/ChangeLog b/ChangeLog
index f3edcd44f..656779c25 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,70 @@
120010118
2 - (bal) Super Sized OpenBSD Resync
3 - markus@cvs.openbsd.org 2001/01/11 22:14:20 GMT 2001 by markus
4 [sshd.c]
5 maxfd+1
6 - markus@cvs.openbsd.org 2001/01/13 17:59:18
7 [ssh-keygen.1]
8 small ssh-keygen manpage cleanup; stevesk@pobox.com
9 - markus@cvs.openbsd.org 2001/01/13 18:03:07
10 [scp.c ssh-keygen.c sshd.c]
11 getopt() returns -1 not EOF; stevesk@pobox.com
12 - markus@cvs.openbsd.org 2001/01/13 18:06:54
13 [ssh-keyscan.c]
14 use SSH_DEFAULT_PORT; from stevesk@pobox.com
15 - markus@cvs.openbsd.org 2001/01/13 18:12:47
16 [ssh-keyscan.c]
17 free() -> xfree(); fix memory leak; from stevesk@pobox.com
18 - markus@cvs.openbsd.org 2001/01/13 18:14:13
19 [ssh-add.c]
20 typo, from stevesk@sweden.hp.com
21 - markus@cvs.openbsd.org 2001/01/13 18:32:50
22 [packet.c session.c ssh.c sshconnect.c sshd.c]
23 split out keepalive from packet_interactive (from dale@accentre.com)
24 set IPTOS_LOWDELAY TCP_NODELAY IPTOS_THROUGHPUT for ssh2, too.
25 - markus@cvs.openbsd.org 2001/01/13 18:36:45
26 [packet.c packet.h]
27 reorder, typo
28 - markus@cvs.openbsd.org 2001/01/13 18:38:00
29 [auth-options.c]
30 fix comment
31 - markus@cvs.openbsd.org 2001/01/13 18:43:31
32 [session.c]
33 Wall
34 - markus@cvs.openbsd.org 2001/01/13 19:14:08
35 [clientloop.h clientloop.c ssh.c]
36 move callback to headerfile
37 - markus@cvs.openbsd.org 2001/01/15 21:40:10
38 [ssh.c]
39 use log() instead of stderr
40 - markus@cvs.openbsd.org 2001/01/15 21:43:51
41 [dh.c]
42 use error() not stderr!
43 - markus@cvs.openbsd.org 2001/01/15 21:45:29
44 [sftp-server.c]
45 rename must fail if newpath exists, debug off by default
46 - markus@cvs.openbsd.org 2001/01/15 21:46:38
47 [sftp-server.c]
48 readable long listing for sftp-server, ok deraadt@
49 - markus@cvs.openbsd.org 2001/01/16 19:20:06
50 [key.c ssh-rsa.c]
51 make "ssh-rsa" key format for ssh2 confirm to the ietf-drafts; from
52 galb@vandyke.com. note that you have to delete older ssh2-rsa keys,
53 since they are in the wrong format, too. they must be removed from
54 .ssh/authorized_keys2 and .ssh/known_hosts2, etc.
55 (cd; grep -v ssh-rsa .ssh/authorized_keys2 > TMP && mv TMP
56 .ssh/authorized_keys2) additionally, we now check that
57 BN_num_bits(rsa->n) >= 768.
58 - markus@cvs.openbsd.org 2001/01/16 20:54:27
59 [sftp-server.c]
60 remove some statics. simpler handles; idea from nisse@lysator.liu.se
61 - deraadt@cvs.openbsd.org 2001/01/16 23:58:08
62 [bufaux.c radix.c sshconnect.h sshconnect1.c]
63 indent
64 - (bal) Added bsd-strmode.[ch] since some non-OpenBSD platforms may
65 be missing such feature.
66
67
120010117 6820010117
2 - (djm) Only write random seed file at exit 69 - (djm) Only write random seed file at exit
3 - (djm) Make PAM support optional, enable with --with-pam 70 - (djm) Make PAM support optional, enable with --with-pam
diff --git a/Makefile.in b/Makefile.in
index 1080f26ec..d56cd640a 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -39,7 +39,7 @@ TARGETS=ssh$(EXEEXT) sshd$(EXEEXT) ssh-add$(EXEEXT) ssh-keygen$(EXEEXT) ssh-keys
39 39
40LIBSSH_OBJS=atomicio.o authfd.o authfile.o bufaux.o buffer.o canohost.o channels.o cipher.o cli.o compat.o compress.o crc32.o cygwin_util.o deattack.o dispatch.o hmac.o hostfile.o key.o kex.o log.o match.o mpaux.o nchan.o packet.o radix.o rijndael.o entropy.o readpass.o rsa.o ssh-dss.o ssh-rsa.o tildexpand.o ttymodes.o uidswap.o util.o uuencode.o xmalloc.o 40LIBSSH_OBJS=atomicio.o authfd.o authfile.o bufaux.o buffer.o canohost.o channels.o cipher.o cli.o compat.o compress.o crc32.o cygwin_util.o deattack.o dispatch.o hmac.o hostfile.o key.o kex.o log.o match.o mpaux.o nchan.o packet.o radix.o rijndael.o entropy.o readpass.o rsa.o ssh-dss.o ssh-rsa.o tildexpand.o ttymodes.o uidswap.o util.o uuencode.o xmalloc.o
41 41
42LIBOPENBSD_COMPAT_OBJS=bsd-arc4random.o bsd-base64.o bsd-bindresvport.o bsd-daemon.o bsd-getcwd.o bsd-getgrouplist.o bsd-inet_aton.o bsd-inet_ntoa.o bsd-misc.o bsd-mktemp.o bsd-realpath.o bsd-rresvport.o bsd-setenv.o bsd-sigaction.o bsd-snprintf.o bsd-strlcat.o bsd-strlcpy.o bsd-strsep.o bsd-strtok.o bsd-vis.o bsd-setproctitle.o bsd-waitpid.o fake-getaddrinfo.o fake-getnameinfo.o next-posix.o 42LIBOPENBSD_COMPAT_OBJS=bsd-arc4random.o bsd-base64.o bsd-bindresvport.o bsd-daemon.o bsd-getcwd.o bsd-getgrouplist.o bsd-inet_aton.o bsd-inet_ntoa.o bsd-misc.o bsd-mktemp.o bsd-realpath.o bsd-rresvport.o bsd-setenv.o bsd-sigaction.o bsd-snprintf.o bsd-strlcat.o bsd-strlcpy.o bsd-strmode.o bsd-strsep.o bsd-strtok.o bsd-vis.o bsd-setproctitle.o bsd-waitpid.o fake-getaddrinfo.o fake-getnameinfo.o next-posix.o
43 43
44SSHOBJS= ssh.o sshconnect.o sshconnect1.o sshconnect2.o log-client.o readconf.o clientloop.o 44SSHOBJS= ssh.o sshconnect.o sshconnect1.o sshconnect2.o log-client.o readconf.o clientloop.o
45 45
diff --git a/auth-options.c b/auth-options.c
index c598f70df..ef61d8df8 100644
--- a/auth-options.c
+++ b/auth-options.c
@@ -2,10 +2,6 @@
2 * Author: Tatu Ylonen <ylo@cs.hut.fi> 2 * Author: Tatu Ylonen <ylo@cs.hut.fi>
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 * All rights reserved 4 * All rights reserved
5 * RSA-based authentication. This code determines whether to admit a login
6 * based on RSA authentication. This file also contains functions to check
7 * validity of the host key.
8 *
9 * As far as I am concerned, the code I have written for this software 5 * As far as I am concerned, the code I have written for this software
10 * can be used freely for any purpose. Any derived versions of this 6 * can be used freely for any purpose. Any derived versions of this
11 * software must be clearly marked as such, and if the derived work is 7 * software must be clearly marked as such, and if the derived work is
@@ -14,7 +10,7 @@
14 */ 10 */
15 11
16#include "includes.h" 12#include "includes.h"
17RCSID("$OpenBSD: auth-options.c,v 1.7 2000/12/19 23:17:54 markus Exp $"); 13RCSID("$OpenBSD: auth-options.c,v 1.8 2001/01/13 18:38:00 markus Exp $");
18 14
19#include "ssh.h" 15#include "ssh.h"
20#include "packet.h" 16#include "packet.h"
diff --git a/bsd-strmode.c b/bsd-strmode.c
new file mode 100644
index 000000000..2e2d9054e
--- /dev/null
+++ b/bsd-strmode.c
@@ -0,0 +1,156 @@
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#include "includes.h"
35#ifndef HAVE_STRMODE
36
37#if defined(LIBC_SCCS) && !defined(lint)
38static char *rcsid = "$OpenBSD: strmode.c,v 1.3 1997/06/13 13:57:20 deraadt Exp $";
39#endif /* LIBC_SCCS and not lint */
40
41#include <sys/types.h>
42#include <sys/stat.h>
43#include <string.h>
44
45void
46strmode(mode, p)
47 register mode_t mode;
48 register char *p;
49{
50 /* print type */
51 switch (mode & S_IFMT) {
52 case S_IFDIR: /* directory */
53 *p++ = 'd';
54 break;
55 case S_IFCHR: /* character special */
56 *p++ = 'c';
57 break;
58 case S_IFBLK: /* block special */
59 *p++ = 'b';
60 break;
61 case S_IFREG: /* regular */
62 *p++ = '-';
63 break;
64 case S_IFLNK: /* symbolic link */
65 *p++ = 'l';
66 break;
67 case S_IFSOCK: /* socket */
68 *p++ = 's';
69 break;
70#ifdef S_IFIFO
71 case S_IFIFO: /* fifo */
72 *p++ = 'p';
73 break;
74#endif
75#ifdef S_IFWHT
76 case S_IFWHT: /* whiteout */
77 *p++ = 'w';
78 break;
79#endif
80 default: /* unknown */
81 *p++ = '?';
82 break;
83 }
84 /* usr */
85 if (mode & S_IRUSR)
86 *p++ = 'r';
87 else
88 *p++ = '-';
89 if (mode & S_IWUSR)
90 *p++ = 'w';
91 else
92 *p++ = '-';
93 switch (mode & (S_IXUSR | S_ISUID)) {
94 case 0:
95 *p++ = '-';
96 break;
97 case S_IXUSR:
98 *p++ = 'x';
99 break;
100 case S_ISUID:
101 *p++ = 'S';
102 break;
103 case S_IXUSR | S_ISUID:
104 *p++ = 's';
105 break;
106 }
107 /* group */
108 if (mode & S_IRGRP)
109 *p++ = 'r';
110 else
111 *p++ = '-';
112 if (mode & S_IWGRP)
113 *p++ = 'w';
114 else
115 *p++ = '-';
116 switch (mode & (S_IXGRP | S_ISGID)) {
117 case 0:
118 *p++ = '-';
119 break;
120 case S_IXGRP:
121 *p++ = 'x';
122 break;
123 case S_ISGID:
124 *p++ = 'S';
125 break;
126 case S_IXGRP | S_ISGID:
127 *p++ = 's';
128 break;
129 }
130 /* other */
131 if (mode & S_IROTH)
132 *p++ = 'r';
133 else
134 *p++ = '-';
135 if (mode & S_IWOTH)
136 *p++ = 'w';
137 else
138 *p++ = '-';
139 switch (mode & (S_IXOTH | S_ISVTX)) {
140 case 0:
141 *p++ = '-';
142 break;
143 case S_IXOTH:
144 *p++ = 'x';
145 break;
146 case S_ISVTX:
147 *p++ = 'T';
148 break;
149 case S_IXOTH | S_ISVTX:
150 *p++ = 't';
151 break;
152 }
153 *p++ = ' '; /* will be a '+' if ACL's implemented */
154 *p = '\0';
155}
156#endif
diff --git a/bsd-strmode.h b/bsd-strmode.h
new file mode 100644
index 000000000..773d6bdcd
--- /dev/null
+++ b/bsd-strmode.h
@@ -0,0 +1,5 @@
1#ifndef HAVE_STRMODE
2
3void strmode( register mode_t mode, register char *p);
4
5#endif
diff --git a/bufaux.c b/bufaux.c
index 149677f74..2d20ad6db 100644
--- a/bufaux.c
+++ b/bufaux.c
@@ -37,7 +37,7 @@
37 */ 37 */
38 38
39#include "includes.h" 39#include "includes.h"
40RCSID("$OpenBSD: bufaux.c,v 1.15 2001/01/10 22:56:22 markus Exp $"); 40RCSID("$OpenBSD: bufaux.c,v 1.16 2001/01/16 23:58:08 deraadt Exp $");
41 41
42#include "ssh.h" 42#include "ssh.h"
43#include <openssl/bn.h> 43#include <openssl/bn.h>
@@ -90,7 +90,7 @@ buffer_get_bignum(Buffer *buffer, BIGNUM *value)
90 bytes = (bits + 7) / 8; 90 bytes = (bits + 7) / 8;
91 if (buffer_len(buffer) < bytes) 91 if (buffer_len(buffer) < bytes)
92 fatal("buffer_get_bignum: input buffer too small"); 92 fatal("buffer_get_bignum: input buffer too small");
93 bin = (u_char*) buffer_ptr(buffer); 93 bin = (u_char *) buffer_ptr(buffer);
94 BN_bin2bn(bin, bytes, value); 94 BN_bin2bn(bin, bytes, value);
95 buffer_consume(buffer, bytes); 95 buffer_consume(buffer, bytes);
96 96
diff --git a/clientloop.c b/clientloop.c
index 44a79d0e0..9079bcda8 100644
--- a/clientloop.c
+++ b/clientloop.c
@@ -59,7 +59,7 @@
59 */ 59 */
60 60
61#include "includes.h" 61#include "includes.h"
62RCSID("$OpenBSD: clientloop.c,v 1.42 2000/12/19 23:17:56 markus Exp $"); 62RCSID("$OpenBSD: clientloop.c,v 1.43 2001/01/13 19:14:08 markus Exp $");
63 63
64#include "xmalloc.h" 64#include "xmalloc.h"
65#include "ssh.h" 65#include "ssh.h"
@@ -79,6 +79,7 @@ RCSID("$OpenBSD: clientloop.c,v 1.42 2000/12/19 23:17:56 markus Exp $");
79#include <openssl/rsa.h> 79#include <openssl/rsa.h>
80#include "key.h" 80#include "key.h"
81#include "authfd.h" 81#include "authfd.h"
82#include "clientloop.h"
82 83
83/* import options */ 84/* import options */
84extern Options options; 85extern Options options;
@@ -1247,9 +1248,9 @@ client_input_channel_req(int id, void *arg)
1247} 1248}
1248 1249
1249void 1250void
1250client_set_session_ident(int id) 1251clientloop_set_session_ident(int id)
1251{ 1252{
1252 debug2("client_set_session_ident: id %d", id); 1253 debug2("clientloop_set_session_ident: id %d", id);
1253 session_ident = id; 1254 session_ident = id;
1254 channel_register_callback(id, SSH2_MSG_CHANNEL_REQUEST, 1255 channel_register_callback(id, SSH2_MSG_CHANNEL_REQUEST,
1255 client_input_channel_req, (void *)0); 1256 client_input_channel_req, (void *)0);
diff --git a/clientloop.h b/clientloop.h
new file mode 100644
index 000000000..3ad72aa55
--- /dev/null
+++ b/clientloop.h
@@ -0,0 +1,24 @@
1/*
2 * Copyright (c) 2001 Markus Friedl. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24void clientloop_set_session_ident(int id);
diff --git a/configure.in b/configure.in
index 0dd8c0043..ad05a6e7c 100644
--- a/configure.in
+++ b/configure.in
@@ -315,7 +315,7 @@ AC_CHECK_FUNC(utimes,
315AC_CHECK_HEADERS(bstring.h endian.h floatingpoint.h getopt.h lastlog.h limits.h login.h login_cap.h maillock.h netdb.h netgroup.h netinet/in_systm.h paths.h poll.h pty.h shadow.h security/pam_appl.h sys/bitypes.h sys/bsdtty.h sys/cdefs.h sys/poll.h sys/queue.h sys/select.h sys/stat.h sys/stropts.h sys/sysmacros.h sys/time.h sys/ttcompat.h sys/un.h stddef.h time.h ttyent.h usersec.h util.h utime.h utmp.h utmpx.h vis.h) 315AC_CHECK_HEADERS(bstring.h endian.h floatingpoint.h getopt.h lastlog.h limits.h login.h login_cap.h maillock.h netdb.h netgroup.h netinet/in_systm.h paths.h poll.h pty.h shadow.h security/pam_appl.h sys/bitypes.h sys/bsdtty.h sys/cdefs.h sys/poll.h sys/queue.h sys/select.h sys/stat.h sys/stropts.h sys/sysmacros.h sys/time.h sys/ttcompat.h sys/un.h stddef.h time.h ttyent.h usersec.h util.h utime.h utmp.h utmpx.h vis.h)
316 316
317dnl Checks for library functions. 317dnl Checks for library functions.
318AC_CHECK_FUNCS(arc4random atexit b64_ntop bcopy bindresvport_af clock fchmod freeaddrinfo futimes gai_strerror getcwd getaddrinfo getgrouplist getnameinfo getrlimit getrusage getttyent inet_aton inet_ntoa innetgr login_getcapbool md5_crypt memmove mkdtemp on_exit openpty realpath rresvport_af setdtablesize setenv seteuid setlogin setproctitle setreuid setrlimit setsid sigaction sigvec snprintf strerror strlcat strlcpy strsep strtok_r sysconf utimes vsnprintf vhangup vis waitpid _getpty __b64_ntop) 318AC_CHECK_FUNCS(arc4random atexit b64_ntop bcopy bindresvport_af clock fchmod freeaddrinfo futimes gai_strerror getcwd getaddrinfo getgrouplist getnameinfo getrlimit getrusage getttyent inet_aton inet_ntoa innetgr login_getcapbool md5_crypt memmove mkdtemp on_exit openpty realpath rresvport_af setdtablesize setenv seteuid setlogin setproctitle setreuid setrlimit setsid sigaction sigvec snprintf strerror strlcat strlcpy strmode strsep strtok_r sysconf utimes vsnprintf vhangup vis waitpid _getpty __b64_ntop)
319dnl Checks for time functions 319dnl Checks for time functions
320AC_CHECK_FUNCS(gettimeofday time) 320AC_CHECK_FUNCS(gettimeofday time)
321dnl Checks for libutil functions 321dnl Checks for libutil functions
diff --git a/dh.c b/dh.c
index 35e901433..87a478450 100644
--- a/dh.c
+++ b/dh.c
@@ -23,7 +23,7 @@
23 */ 23 */
24 24
25#include "includes.h" 25#include "includes.h"
26RCSID("$OpenBSD: dh.c,v 1.3 2000/11/16 17:55:43 markus Exp $"); 26RCSID("$OpenBSD: dh.c,v 1.4 2001/01/15 21:43:51 markus Exp $");
27 27
28#include "xmalloc.h" 28#include "xmalloc.h"
29 29
@@ -87,7 +87,7 @@ parse_prime(int linenum, char *line, struct dhgroup *dhg)
87 87
88 return (1); 88 return (1);
89 fail: 89 fail:
90 fprintf(stderr, "Bad prime description in line %d\n", linenum); 90 error("Bad prime description in line %d\n", linenum);
91 return (0); 91 return (0);
92} 92}
93 93
diff --git a/key.c b/key.c
index f9474b16b..21e13b863 100644
--- a/key.c
+++ b/key.c
@@ -46,7 +46,7 @@
46#include "buffer.h" 46#include "buffer.h"
47#include "bufaux.h" 47#include "bufaux.h"
48 48
49RCSID("$OpenBSD: key.c,v 1.13 2000/12/19 23:17:56 markus Exp $"); 49RCSID("$OpenBSD: key.c,v 1.14 2001/01/16 19:20:06 markus Exp $");
50 50
51Key * 51Key *
52key_new(int type) 52key_new(int type)
@@ -555,8 +555,8 @@ key_from_blob(char *blob, int blen)
555 switch(type){ 555 switch(type){
556 case KEY_RSA: 556 case KEY_RSA:
557 key = key_new(type); 557 key = key_new(type);
558 buffer_get_bignum2(&b, key->rsa->n);
559 buffer_get_bignum2(&b, key->rsa->e); 558 buffer_get_bignum2(&b, key->rsa->e);
559 buffer_get_bignum2(&b, key->rsa->n);
560#ifdef DEBUG_PK 560#ifdef DEBUG_PK
561 RSA_print_fp(stderr, key->rsa, 8); 561 RSA_print_fp(stderr, key->rsa, 8);
562#endif 562#endif
@@ -608,8 +608,8 @@ key_to_blob(Key *key, u_char **blobp, u_int *lenp)
608 break; 608 break;
609 case KEY_RSA: 609 case KEY_RSA:
610 buffer_put_cstring(&b, key_ssh_name(key)); 610 buffer_put_cstring(&b, key_ssh_name(key));
611 buffer_put_bignum2(&b, key->rsa->n);
612 buffer_put_bignum2(&b, key->rsa->e); 611 buffer_put_bignum2(&b, key->rsa->e);
612 buffer_put_bignum2(&b, key->rsa->n);
613 break; 613 break;
614 default: 614 default:
615 error("key_to_blob: illegal key type %d", key->type); 615 error("key_to_blob: illegal key type %d", key->type);
diff --git a/openbsd-compat.h b/openbsd-compat.h
index 9213bead5..01dcb4a7b 100644
--- a/openbsd-compat.h
+++ b/openbsd-compat.h
@@ -12,6 +12,7 @@
12#include "bsd-misc.h" 12#include "bsd-misc.h"
13#include "bsd-strlcpy.h" 13#include "bsd-strlcpy.h"
14#include "bsd-strlcat.h" 14#include "bsd-strlcat.h"
15#include "bsd-strmode.h"
15#include "bsd-mktemp.h" 16#include "bsd-mktemp.h"
16#include "bsd-snprintf.h" 17#include "bsd-snprintf.h"
17#include "bsd-daemon.h" 18#include "bsd-daemon.h"
diff --git a/packet.c b/packet.c
index cd42f2f75..bf3a7ee0b 100644
--- a/packet.c
+++ b/packet.c
@@ -37,7 +37,7 @@
37 */ 37 */
38 38
39#include "includes.h" 39#include "includes.h"
40RCSID("$OpenBSD: packet.c,v 1.42 2001/01/09 21:19:50 markus Exp $"); 40RCSID("$OpenBSD: packet.c,v 1.44 2001/01/13 18:36:45 markus Exp $");
41 41
42#include "xmalloc.h" 42#include "xmalloc.h"
43#include "buffer.h" 43#include "buffer.h"
@@ -1230,22 +1230,23 @@ packet_not_very_much_data_to_write()
1230/* Informs that the current session is interactive. Sets IP flags for that. */ 1230/* Informs that the current session is interactive. Sets IP flags for that. */
1231 1231
1232void 1232void
1233packet_set_interactive(int interactive, int keepalives) 1233packet_set_interactive(int interactive)
1234{ 1234{
1235 static int called = 0;
1236 int lowdelay = IPTOS_LOWDELAY;
1237 int throughput = IPTOS_THROUGHPUT;
1235 int on = 1; 1238 int on = 1;
1236 1239
1240 if (called)
1241 return;
1242 called = 1;
1243
1237 /* Record that we are in interactive mode. */ 1244 /* Record that we are in interactive mode. */
1238 interactive_mode = interactive; 1245 interactive_mode = interactive;
1239 1246
1240 /* Only set socket options if using a socket. */ 1247 /* Only set socket options if using a socket. */
1241 if (!packet_connection_is_on_socket()) 1248 if (!packet_connection_is_on_socket())
1242 return; 1249 return;
1243 if (keepalives) {
1244 /* Set keepalives if requested. */
1245 if (setsockopt(connection_in, SOL_SOCKET, SO_KEEPALIVE, (void *) &on,
1246 sizeof(on)) < 0)
1247 error("setsockopt SO_KEEPALIVE: %.100s", strerror(errno));
1248 }
1249 /* 1250 /*
1250 * IPTOS_LOWDELAY and IPTOS_THROUGHPUT are IPv4 only 1251 * IPTOS_LOWDELAY and IPTOS_THROUGHPUT are IPv4 only
1251 */ 1252 */
@@ -1256,7 +1257,6 @@ packet_set_interactive(int interactive, int keepalives)
1256 */ 1257 */
1257#if defined(IP_TOS) && !defined(IP_TOS_IS_BROKEN) 1258#if defined(IP_TOS) && !defined(IP_TOS_IS_BROKEN)
1258 if (packet_connection_is_ipv4()) { 1259 if (packet_connection_is_ipv4()) {
1259 int lowdelay = IPTOS_LOWDELAY;
1260 if (setsockopt(connection_in, IPPROTO_IP, IP_TOS, 1260 if (setsockopt(connection_in, IPPROTO_IP, IP_TOS,
1261 (void *) &lowdelay, sizeof(lowdelay)) < 0) 1261 (void *) &lowdelay, sizeof(lowdelay)) < 0)
1262 error("setsockopt IPTOS_LOWDELAY: %.100s", 1262 error("setsockopt IPTOS_LOWDELAY: %.100s",
@@ -1272,7 +1272,6 @@ packet_set_interactive(int interactive, int keepalives)
1272 * IPTOS_THROUGHPUT. 1272 * IPTOS_THROUGHPUT.
1273 */ 1273 */
1274#if defined(IP_TOS) && !defined(IP_TOS_IS_BROKEN) 1274#if defined(IP_TOS) && !defined(IP_TOS_IS_BROKEN)
1275 int throughput = IPTOS_THROUGHPUT;
1276 if (setsockopt(connection_in, IPPROTO_IP, IP_TOS, (void *) &throughput, 1275 if (setsockopt(connection_in, IPPROTO_IP, IP_TOS, (void *) &throughput,
1277 sizeof(throughput)) < 0) 1276 sizeof(throughput)) < 0)
1278 error("setsockopt IPTOS_THROUGHPUT: %.100s", strerror(errno)); 1277 error("setsockopt IPTOS_THROUGHPUT: %.100s", strerror(errno));
diff --git a/packet.h b/packet.h
index 597fbb151..00f0c3778 100644
--- a/packet.h
+++ b/packet.h
@@ -11,7 +11,7 @@
11 * called by a name other than "ssh" or "Secure Shell". 11 * called by a name other than "ssh" or "Secure Shell".
12 */ 12 */
13 13
14/* RCSID("$OpenBSD: packet.h,v 1.18 2000/12/19 23:17:57 markus Exp $"); */ 14/* RCSID("$OpenBSD: packet.h,v 1.19 2001/01/13 18:32:50 markus Exp $"); */
15 15
16#ifndef PACKET_H 16#ifndef PACKET_H
17#define PACKET_H 17#define PACKET_H
@@ -65,7 +65,7 @@ void packet_start_compression(int level);
65 * Informs that the current session is interactive. Sets IP flags for 65 * Informs that the current session is interactive. Sets IP flags for
66 * optimal performance in interactive use. 66 * optimal performance in interactive use.
67 */ 67 */
68void packet_set_interactive(int interactive, int keepalives); 68void packet_set_interactive(int interactive);
69 69
70/* Returns true if the current connection is interactive. */ 70/* Returns true if the current connection is interactive. */
71int packet_is_interactive(void); 71int packet_is_interactive(void);
diff --git a/radix.c b/radix.c
index 939d0f7fc..3b149a82b 100644
--- a/radix.c
+++ b/radix.c
@@ -25,7 +25,7 @@
25#include "includes.h" 25#include "includes.h"
26#include "uuencode.h" 26#include "uuencode.h"
27 27
28RCSID("$OpenBSD: radix.c,v 1.14 2000/12/19 23:17:57 markus Exp $"); 28RCSID("$OpenBSD: radix.c,v 1.15 2001/01/16 23:58:09 deraadt Exp $");
29 29
30#ifdef AFS 30#ifdef AFS
31#include <krb.h> 31#include <krb.h>
@@ -37,7 +37,7 @@ typedef u_short my_u_short;
37/* Nasty macros from BIND-4.9.2 */ 37/* Nasty macros from BIND-4.9.2 */
38 38
39#define GETSHORT(s, cp) { \ 39#define GETSHORT(s, cp) { \
40 register my_u_char *t_cp = (my_u_char*)(cp); \ 40 register my_u_char *t_cp = (my_u_char *)(cp); \
41 (s) = (((my_u_short)t_cp[0]) << 8) \ 41 (s) = (((my_u_short)t_cp[0]) << 8) \
42 | (((my_u_short)t_cp[1])) \ 42 | (((my_u_short)t_cp[1])) \
43 ; \ 43 ; \
@@ -45,7 +45,7 @@ typedef u_short my_u_short;
45} 45}
46 46
47#define GETLONG(l, cp) { \ 47#define GETLONG(l, cp) { \
48 register my_u_char *t_cp = (my_u_char*)(cp); \ 48 register my_u_char *t_cp = (my_u_char *)(cp); \
49 (l) = (((my_u_int32_t)t_cp[0]) << 24) \ 49 (l) = (((my_u_int32_t)t_cp[0]) << 24) \
50 | (((my_u_int32_t)t_cp[1]) << 16) \ 50 | (((my_u_int32_t)t_cp[1]) << 16) \
51 | (((my_u_int32_t)t_cp[2]) << 8) \ 51 | (((my_u_int32_t)t_cp[2]) << 8) \
@@ -56,7 +56,7 @@ typedef u_short my_u_short;
56 56
57#define PUTSHORT(s, cp) { \ 57#define PUTSHORT(s, cp) { \
58 register my_u_short t_s = (my_u_short)(s); \ 58 register my_u_short t_s = (my_u_short)(s); \
59 register my_u_char *t_cp = (my_u_char*)(cp); \ 59 register my_u_char *t_cp = (my_u_char *)(cp); \
60 *t_cp++ = t_s >> 8; \ 60 *t_cp++ = t_s >> 8; \
61 *t_cp = t_s; \ 61 *t_cp = t_s; \
62 (cp) += 2; \ 62 (cp) += 2; \
@@ -64,7 +64,7 @@ typedef u_short my_u_short;
64 64
65#define PUTLONG(l, cp) { \ 65#define PUTLONG(l, cp) { \
66 register my_u_int32_t t_l = (my_u_int32_t)(l); \ 66 register my_u_int32_t t_l = (my_u_int32_t)(l); \
67 register my_u_char *t_cp = (my_u_char*)(cp); \ 67 register my_u_char *t_cp = (my_u_char *)(cp); \
68 *t_cp++ = t_l >> 24; \ 68 *t_cp++ = t_l >> 24; \
69 *t_cp++ = t_l >> 16; \ 69 *t_cp++ = t_l >> 16; \
70 *t_cp++ = t_l >> 8; \ 70 *t_cp++ = t_l >> 8; \
@@ -73,9 +73,9 @@ typedef u_short my_u_short;
73} 73}
74 74
75#define GETSTRING(s, p, p_l) { \ 75#define GETSTRING(s, p, p_l) { \
76 register char* p_targ = (p) + p_l; \ 76 register char *p_targ = (p) + p_l; \
77 register char* s_c = (s); \ 77 register char *s_c = (s); \
78 register char* p_c = (p); \ 78 register char *p_c = (p); \
79 while (*p_c && (p_c < p_targ)) { \ 79 while (*p_c && (p_c < p_targ)) { \
80 *s_c++ = *p_c++; \ 80 *s_c++ = *p_c++; \
81 } \ 81 } \
diff --git a/scp.c b/scp.c
index 747749281..d353b5ead 100644
--- a/scp.c
+++ b/scp.c
@@ -75,7 +75,7 @@
75 */ 75 */
76 76
77#include "includes.h" 77#include "includes.h"
78RCSID("$OpenBSD: scp.c,v 1.48 2001/01/01 14:52:49 markus Exp $"); 78RCSID("$OpenBSD: scp.c,v 1.49 2001/01/13 18:03:07 markus Exp $");
79 79
80#include "ssh.h" 80#include "ssh.h"
81#include "xmalloc.h" 81#include "xmalloc.h"
@@ -247,7 +247,7 @@ main(argc, argv)
247 addargs("-oFallBackToRsh no"); 247 addargs("-oFallBackToRsh no");
248 248
249 fflag = tflag = 0; 249 fflag = tflag = 0;
250 while ((ch = getopt(argc, argv, "dfprtvBCc:i:P:q46S:o:")) != EOF) 250 while ((ch = getopt(argc, argv, "dfprtvBCc:i:P:q46S:o:")) != -1)
251 switch (ch) { 251 switch (ch) {
252 /* User-visible flags. */ 252 /* User-visible flags. */
253 case '4': 253 case '4':
diff --git a/session.c b/session.c
index 74f5fe255..e52aed5a2 100644
--- a/session.c
+++ b/session.c
@@ -33,7 +33,7 @@
33 */ 33 */
34 34
35#include "includes.h" 35#include "includes.h"
36RCSID("$OpenBSD: session.c,v 1.46 2001/01/04 22:41:03 markus Exp $"); 36RCSID("$OpenBSD: session.c,v 1.48 2001/01/13 18:43:31 markus Exp $");
37 37
38#include "xmalloc.h" 38#include "xmalloc.h"
39#include "ssh.h" 39#include "ssh.h"
@@ -405,10 +405,6 @@ do_authenticated(struct passwd * pw)
405 405
406 case SSH_CMSG_EXEC_SHELL: 406 case SSH_CMSG_EXEC_SHELL:
407 case SSH_CMSG_EXEC_CMD: 407 case SSH_CMSG_EXEC_CMD:
408 /* Set interactive/non-interactive mode. */
409 packet_set_interactive(have_pty || s->display != NULL,
410 options.keepalives);
411
412 if (type == SSH_CMSG_EXEC_CMD) { 408 if (type == SSH_CMSG_EXEC_CMD) {
413 command = packet_get_string(&dlen); 409 command = packet_get_string(&dlen);
414 debug("Exec command '%.500s'", command); 410 debug("Exec command '%.500s'", command);
@@ -548,6 +544,8 @@ do_exec_no_pty(Session *s, const char *command, struct passwd * pw)
548 if (pid < 0) 544 if (pid < 0)
549 packet_disconnect("fork failed: %.100s", strerror(errno)); 545 packet_disconnect("fork failed: %.100s", strerror(errno));
550 s->pid = pid; 546 s->pid = pid;
547 /* Set interactive/non-interactive mode. */
548 packet_set_interactive(s->display != NULL);
551#ifdef USE_PIPES 549#ifdef USE_PIPES
552 /* We are the parent. Close the child sides of the pipes. */ 550 /* We are the parent. Close the child sides of the pipes. */
553 close(pin[0]); 551 close(pin[0]);
@@ -665,6 +663,7 @@ do_exec_pty(Session *s, const char *command, struct passwd * pw)
665 s->ptymaster = ptymaster; 663 s->ptymaster = ptymaster;
666 664
667 /* Enter interactive session. */ 665 /* Enter interactive session. */
666 packet_set_interactive(1);
668 if (compat20) { 667 if (compat20) {
669 session_set_fds(s, ptyfd, fdout, -1); 668 session_set_fds(s, ptyfd, fdout, -1);
670 } else { 669 } else {
diff --git a/sftp-server.c b/sftp-server.c
index e4432ca51..b99f087fa 100644
--- a/sftp-server.c
+++ b/sftp-server.c
@@ -22,7 +22,7 @@
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */ 23 */
24#include "includes.h" 24#include "includes.h"
25RCSID("$OpenBSD: sftp-server.c,v 1.10 2001/01/10 22:56:22 markus Exp $"); 25RCSID("$OpenBSD: sftp-server.c,v 1.13 2001/01/16 20:54:27 markus Exp $");
26 26
27#include "ssh.h" 27#include "ssh.h"
28#include "buffer.h" 28#include "buffer.h"
@@ -189,23 +189,21 @@ encode_attrib(Buffer *b, Attrib *a)
189 } 189 }
190} 190}
191 191
192Attrib * 192void
193stat_to_attrib(struct stat *st) 193stat_to_attrib(struct stat *st, Attrib *a)
194{ 194{
195 static Attrib a; 195 attrib_clear(a);
196 attrib_clear(&a); 196 a->flags = 0;
197 a.flags = 0; 197 a->flags |= SSH2_FILEXFER_ATTR_SIZE;
198 a.flags |= SSH2_FILEXFER_ATTR_SIZE; 198 a->size = st->st_size;
199 a.size = st->st_size; 199 a->flags |= SSH2_FILEXFER_ATTR_UIDGID;
200 a.flags |= SSH2_FILEXFER_ATTR_UIDGID; 200 a->uid = st->st_uid;
201 a.uid = st->st_uid; 201 a->gid = st->st_gid;
202 a.gid = st->st_gid; 202 a->flags |= SSH2_FILEXFER_ATTR_PERMISSIONS;
203 a.flags |= SSH2_FILEXFER_ATTR_PERMISSIONS; 203 a->perm = st->st_mode;
204 a.perm = st->st_mode; 204 a->flags |= SSH2_FILEXFER_ATTR_ACMODTIME;
205 a.flags |= SSH2_FILEXFER_ATTR_ACMODTIME; 205 a->atime = st->st_atime;
206 a.atime = st->st_atime; 206 a->mtime = st->st_mtime;
207 a.mtime = st->st_mtime;
208 return &a;
209} 207}
210 208
211Attrib * 209Attrib *
@@ -264,24 +262,21 @@ handle_is_ok(int i, int type)
264int 262int
265handle_to_string(int handle, char **stringp, int *hlenp) 263handle_to_string(int handle, char **stringp, int *hlenp)
266{ 264{
267 char buf[1024];
268 if (stringp == NULL || hlenp == NULL) 265 if (stringp == NULL || hlenp == NULL)
269 return -1; 266 return -1;
270 snprintf(buf, sizeof buf, "%d", handle); 267 *stringp = xmalloc(sizeof(int32_t));
271 *stringp = xstrdup(buf); 268 PUT_32BIT(*stringp, handle);
272 *hlenp = strlen(*stringp); 269 *hlenp = sizeof(int32_t);
273 return 0; 270 return 0;
274} 271}
275 272
276int 273int
277handle_from_string(char *handle, u_int hlen) 274handle_from_string(char *handle, u_int hlen)
278{ 275{
279/* XXX OVERFLOW ? */ 276 int val;
280 char *ep; 277 if (hlen != sizeof(int32_t))
281 long lval = strtol(handle, &ep, 10);
282 int val = lval;
283 if (*ep != '\0')
284 return -1; 278 return -1;
279 val = GET_32BIT(handle);
285 if (handle_is_ok(val, HANDLE_FILE) || 280 if (handle_is_ok(val, HANDLE_FILE) ||
286 handle_is_ok(val, HANDLE_DIR)) 281 handle_is_ok(val, HANDLE_DIR))
287 return val; 282 return val;
@@ -568,7 +563,7 @@ process_write(void)
568void 563void
569process_do_stat(int do_lstat) 564process_do_stat(int do_lstat)
570{ 565{
571 Attrib *a; 566 Attrib a;
572 struct stat st; 567 struct stat st;
573 u_int32_t id; 568 u_int32_t id;
574 char *name; 569 char *name;
@@ -581,8 +576,8 @@ process_do_stat(int do_lstat)
581 if (ret < 0) { 576 if (ret < 0) {
582 status = errno_to_portable(errno); 577 status = errno_to_portable(errno);
583 } else { 578 } else {
584 a = stat_to_attrib(&st); 579 stat_to_attrib(&st, &a);
585 send_attrib(id, a); 580 send_attrib(id, &a);
586 status = SSH2_FX_OK; 581 status = SSH2_FX_OK;
587 } 582 }
588 if (status != SSH2_FX_OK) 583 if (status != SSH2_FX_OK)
@@ -605,7 +600,7 @@ process_lstat(void)
605void 600void
606process_fstat(void) 601process_fstat(void)
607{ 602{
608 Attrib *a; 603 Attrib a;
609 struct stat st; 604 struct stat st;
610 u_int32_t id; 605 u_int32_t id;
611 int fd, ret, handle, status = SSH2_FX_FAILURE; 606 int fd, ret, handle, status = SSH2_FX_FAILURE;
@@ -619,8 +614,8 @@ process_fstat(void)
619 if (ret < 0) { 614 if (ret < 0) {
620 status = errno_to_portable(errno); 615 status = errno_to_portable(errno);
621 } else { 616 } else {
622 a = stat_to_attrib(&st); 617 stat_to_attrib(&st, &a);
623 send_attrib(id, a); 618 send_attrib(id, &a);
624 status = SSH2_FX_OK; 619 status = SSH2_FX_OK;
625 } 620 }
626 } 621 }
@@ -736,18 +731,41 @@ process_opendir(void)
736} 731}
737 732
738/* 733/*
739 * XXX, draft-ietf-secsh-filexfer-00.txt says: 734 * drwxr-xr-x 5 markus markus 1024 Jan 13 18:39 .ssh
740 * The recommended format for the longname field is as follows:
741 * -rwxr-xr-x 1 mjos staff 348911 Mar 25 14:29 t-filexfer
742 * 1234567890 123 12345678 12345678 12345678 123456789012
743 */ 735 */
744char * 736char *
745ls_file(char *name, struct stat *st) 737ls_file(char *name, struct stat *st)
746{ 738{
747 char buf[1024]; 739 int sz = 0;
748 snprintf(buf, sizeof buf, "0%o %d %d %lld %d %s", 740 struct passwd *pw;
749 st->st_mode, st->st_uid, st->st_gid, (long long)st->st_size, 741 struct group *gr;
750 (int)st->st_mtime, name); 742 struct tm *ltime = localtime(&st->st_mtime);
743 char *user, *group;
744 char buf[1024], mode[11+1], tbuf[12+1], ubuf[11+1], gbuf[11+1];
745
746 strmode(st->st_mode, mode);
747 if ((pw = getpwuid(st->st_uid)) != NULL) {
748 user = pw->pw_name;
749 } else {
750 snprintf(ubuf, sizeof ubuf, "%d", st->st_uid);
751 user = ubuf;
752 }
753 if ((gr = getgrgid(st->st_gid)) != NULL) {
754 group = gr->gr_name;
755 } else {
756 snprintf(gbuf, sizeof gbuf, "%d", st->st_gid);
757 group = gbuf;
758 }
759 if (ltime != NULL) {
760 if (time(NULL) - st->st_mtime < (365*24*60*60)/2)
761 sz = strftime(tbuf, sizeof tbuf, "%b %e %H:%M", ltime);
762 else
763 sz = strftime(tbuf, sizeof tbuf, "%b %e %Y", ltime);
764 }
765 if (sz == 0)
766 tbuf[0] = '\0';
767 snprintf(buf, sizeof buf, "%s %3d %-8.8s %-8.8s %8qd %s %s", mode,
768 st->st_nlink, user, group, (long long)st->st_size, tbuf, name);
751 return xstrdup(buf); 769 return xstrdup(buf);
752} 770}
753 771
@@ -768,7 +786,6 @@ process_readdir(void)
768 if (dirp == NULL || path == NULL) { 786 if (dirp == NULL || path == NULL) {
769 send_status(id, SSH2_FX_FAILURE); 787 send_status(id, SSH2_FX_FAILURE);
770 } else { 788 } else {
771 Attrib *a;
772 struct stat st; 789 struct stat st;
773 char pathname[1024]; 790 char pathname[1024];
774 Stat *stats; 791 Stat *stats;
@@ -784,12 +801,12 @@ process_readdir(void)
784 "%s/%s", path, dp->d_name); 801 "%s/%s", path, dp->d_name);
785 if (lstat(pathname, &st) < 0) 802 if (lstat(pathname, &st) < 0)
786 continue; 803 continue;
787 a = stat_to_attrib(&st); 804 stat_to_attrib(&st, &(stats[count].attrib));
788 stats[count].attrib = *a;
789 stats[count].name = xstrdup(dp->d_name); 805 stats[count].name = xstrdup(dp->d_name);
790 stats[count].long_name = ls_file(dp->d_name, &st); 806 stats[count].long_name = ls_file(dp->d_name, &st);
791 count++; 807 count++;
792 /* send up to 100 entries in one message */ 808 /* send up to 100 entries in one message */
809 /* XXX check packet size instead */
793 if (count == 100) 810 if (count == 100)
794 break; 811 break;
795 } 812 }
@@ -888,15 +905,19 @@ void
888process_rename(void) 905process_rename(void)
889{ 906{
890 u_int32_t id; 907 u_int32_t id;
908 struct stat st;
891 char *oldpath, *newpath; 909 char *oldpath, *newpath;
892 int ret, status; 910 int ret, status = SSH2_FX_FAILURE;
893 911
894 id = get_int(); 912 id = get_int();
895 oldpath = get_string(NULL); 913 oldpath = get_string(NULL);
896 newpath = get_string(NULL); 914 newpath = get_string(NULL);
897 TRACE("rename id %d old %s new %s", id, oldpath, newpath); 915 TRACE("rename id %d old %s new %s", id, oldpath, newpath);
898 ret = rename(oldpath, newpath); 916 /* fail if 'newpath' exists */
899 status = (ret == -1) ? errno_to_portable(errno) : SSH2_FX_OK; 917 if (stat(newpath, &st) == -1) {
918 ret = rename(oldpath, newpath);
919 status = (ret == -1) ? errno_to_portable(errno) : SSH2_FX_OK;
920 }
900 send_status(id, status); 921 send_status(id, status);
901 xfree(oldpath); 922 xfree(oldpath);
902 xfree(newpath); 923 xfree(newpath);
@@ -1006,7 +1027,9 @@ main(int ac, char **av)
1006 __progname = get_progname(av[0]); 1027 __progname = get_progname(av[0]);
1007 handle_init(); 1028 handle_init();
1008 1029
1030#ifdef DEBUG_SFTP_SERVER
1009 log_init("sftp-server", SYSLOG_LEVEL_DEBUG1, SYSLOG_FACILITY_AUTH, 0); 1031 log_init("sftp-server", SYSLOG_LEVEL_DEBUG1, SYSLOG_FACILITY_AUTH, 0);
1032#endif
1010 1033
1011 in = dup(STDIN_FILENO); 1034 in = dup(STDIN_FILENO);
1012 out = dup(STDOUT_FILENO); 1035 out = dup(STDOUT_FILENO);
diff --git a/ssh-add.c b/ssh-add.c
index 857f3d741..c3b3ab4a9 100644
--- a/ssh-add.c
+++ b/ssh-add.c
@@ -35,7 +35,7 @@
35 */ 35 */
36 36
37#include "includes.h" 37#include "includes.h"
38RCSID("$OpenBSD: ssh-add.c,v 1.23 2000/11/12 19:50:38 markus Exp $"); 38RCSID("$OpenBSD: ssh-add.c,v 1.24 2001/01/13 18:14:13 markus Exp $");
39 39
40#include <openssl/evp.h> 40#include <openssl/evp.h>
41#include <openssl/rsa.h> 41#include <openssl/rsa.h>
@@ -91,7 +91,7 @@ delete_all(AuthenticationConnection *ac)
91 if (success) 91 if (success)
92 fprintf(stderr, "All identities removed.\n"); 92 fprintf(stderr, "All identities removed.\n");
93 else 93 else
94 fprintf(stderr, "Failed to remove all identitities.\n"); 94 fprintf(stderr, "Failed to remove all identities.\n");
95} 95}
96 96
97char * 97char *
diff --git a/ssh-keygen.1 b/ssh-keygen.1
index b1430f143..f7b08c983 100644
--- a/ssh-keygen.1
+++ b/ssh-keygen.1
@@ -81,7 +81,7 @@ generates and manages authentication keys for
81defaults to generating an RSA key for use by protocols 1.3 and 1.5; 81defaults to generating an RSA key for use by protocols 1.3 and 1.5;
82specifying the 82specifying the
83.Fl t 83.Fl t
84allows you to create a key for use by protocol 2.0. 84option allows you to create a key for use by protocol 2.0.
85.Pp 85.Pp
86Normally each user wishing to use SSH 86Normally each user wishing to use SSH
87with RSA or DSA authentication runs this once to create the authentication 87with RSA or DSA authentication runs this once to create the authentication
@@ -100,7 +100,7 @@ The public key is stored in a file with the same name but
100appended. 100appended.
101The program also asks for a passphrase. 101The program also asks for a passphrase.
102The passphrase may be empty to indicate no passphrase 102The passphrase may be empty to indicate no passphrase
103(host keys must have empty passphrase), or it may be a string of 103(host keys must have an empty passphrase), or it may be a string of
104arbitrary length. 104arbitrary length.
105Good passphrases are 10-30 characters long and are 105Good passphrases are 10-30 characters long and are
106not simple sentences or otherwise easily guessable (English 106not simple sentences or otherwise easily guessable (English
diff --git a/ssh-keygen.c b/ssh-keygen.c
index 87be6a5f8..5d9fa644e 100644
--- a/ssh-keygen.c
+++ b/ssh-keygen.c
@@ -12,7 +12,7 @@
12 */ 12 */
13 13
14#include "includes.h" 14#include "includes.h"
15RCSID("$OpenBSD: ssh-keygen.c,v 1.38 2000/12/28 18:58:39 markus Exp $"); 15RCSID("$OpenBSD: ssh-keygen.c,v 1.39 2001/01/13 18:03:07 markus Exp $");
16 16
17#include <openssl/evp.h> 17#include <openssl/evp.h>
18#include <openssl/pem.h> 18#include <openssl/pem.h>
@@ -643,7 +643,7 @@ main(int ac, char **av)
643 exit(1); 643 exit(1);
644 } 644 }
645 645
646 while ((opt = getopt(ac, av, "dqpclRxXyb:f:t:P:N:C:")) != EOF) { 646 while ((opt = getopt(ac, av, "dqpclRxXyb:f:t:P:N:C:")) != -1) {
647 switch (opt) { 647 switch (opt) {
648 case 'b': 648 case 'b':
649 bits = atoi(optarg); 649 bits = atoi(optarg);
diff --git a/ssh-keyscan.c b/ssh-keyscan.c
index 5d5427aad..69b029b05 100644
--- a/ssh-keyscan.c
+++ b/ssh-keyscan.c
@@ -8,7 +8,7 @@
8 */ 8 */
9 9
10#include "includes.h" 10#include "includes.h"
11RCSID("$OpenBSD: ssh-keyscan.c,v 1.7 2001/01/08 22:03:23 markus Exp $"); 11RCSID("$OpenBSD: ssh-keyscan.c,v 1.9 2001/01/13 18:12:47 markus Exp $");
12 12
13#if defined(HAVE_SYS_QUEUE_H) && !defined(HAVE_BOGUS_SYS_QUEUE_H) 13#if defined(HAVE_SYS_QUEUE_H) && !defined(HAVE_BOGUS_SYS_QUEUE_H)
14#include <sys/queue.h> 14#include <sys/queue.h>
@@ -31,7 +31,6 @@ static int argno = 1; /* Number of argument currently being parsed */
31 31
32int family = AF_UNSPEC; /* IPv4, IPv6 or both */ 32int family = AF_UNSPEC; /* IPv4, IPv6 or both */
33 33
34#define PORT 22
35#define MAXMAXFD 256 34#define MAXMAXFD 256
36 35
37/* The number of seconds after which to give up on a TCP connection */ 36/* The number of seconds after which to give up on a TCP connection */
@@ -103,7 +102,7 @@ Linebuf_alloc(const char *filename, void (*errfun) (const char *,...))
103 if (filename) { 102 if (filename) {
104 lb->filename = filename; 103 lb->filename = filename;
105 if (!(lb->stream = fopen(filename, "r"))) { 104 if (!(lb->stream = fopen(filename, "r"))) {
106 free(lb); 105 xfree(lb);
107 if (errfun) 106 if (errfun)
108 (*errfun) ("%s: %s\n", filename, strerror(errno)); 107 (*errfun) ("%s: %s\n", filename, strerror(errno));
109 return (NULL); 108 return (NULL);
@@ -116,7 +115,7 @@ Linebuf_alloc(const char *filename, void (*errfun) (const char *,...))
116 if (!(lb->buf = malloc(lb->size = LINEBUF_SIZE))) { 115 if (!(lb->buf = malloc(lb->size = LINEBUF_SIZE))) {
117 if (errfun) 116 if (errfun)
118 (*errfun) ("linebuf (%s): malloc failed\n", lb->filename); 117 (*errfun) ("linebuf (%s): malloc failed\n", lb->filename);
119 free(lb); 118 xfree(lb);
120 return (NULL); 119 return (NULL);
121 } 120 }
122 lb->errfun = errfun; 121 lb->errfun = errfun;
@@ -128,8 +127,8 @@ static inline void
128Linebuf_free(Linebuf * lb) 127Linebuf_free(Linebuf * lb)
129{ 128{
130 fclose(lb->stream); 129 fclose(lb->stream);
131 free(lb->buf); 130 xfree(lb->buf);
132 free(lb); 131 xfree(lb);
133} 132}
134 133
135static inline void 134static inline void
@@ -298,7 +297,7 @@ tcpconnect(char *host)
298 char strport[NI_MAXSERV]; 297 char strport[NI_MAXSERV];
299 int gaierr, s = -1; 298 int gaierr, s = -1;
300 299
301 snprintf(strport, sizeof strport, "%d", PORT); 300 snprintf(strport, sizeof strport, "%d", SSH_DEFAULT_PORT);
302 memset(&hints, 0, sizeof(hints)); 301 memset(&hints, 0, sizeof(hints));
303 hints.ai_family = family; 302 hints.ai_family = family;
304 hints.ai_socktype = SOCK_STREAM; 303 hints.ai_socktype = SOCK_STREAM;
@@ -335,7 +334,7 @@ conalloc(char *iname, char *oname)
335 do { 334 do {
336 name = xstrsep(&namelist, ","); 335 name = xstrsep(&namelist, ",");
337 if (!name) { 336 if (!name) {
338 free(namebase); 337 xfree(namebase);
339 return (-1); 338 return (-1);
340 } 339 }
341 } while ((s = tcpconnect(name)) < 0); 340 } while ((s = tcpconnect(name)) < 0);
@@ -368,10 +367,10 @@ confree(int s)
368 close(s); 367 close(s);
369 if (s >= maxfd || fdcon[s].c_status == CS_UNUSED) 368 if (s >= maxfd || fdcon[s].c_status == CS_UNUSED)
370 fatal("confree: attempt to free bad fdno %d", s); 369 fatal("confree: attempt to free bad fdno %d", s);
371 free(fdcon[s].c_namebase); 370 xfree(fdcon[s].c_namebase);
372 free(fdcon[s].c_output_name); 371 xfree(fdcon[s].c_output_name);
373 if (fdcon[s].c_status == CS_KEYS) 372 if (fdcon[s].c_status == CS_KEYS)
374 free(fdcon[s].c_data); 373 xfree(fdcon[s].c_data);
375 fdcon[s].c_status = CS_UNUSED; 374 fdcon[s].c_status = CS_UNUSED;
376 TAILQ_REMOVE(&tq, &fdcon[s], c_link); 375 TAILQ_REMOVE(&tq, &fdcon[s], c_link);
377 FD_CLR(s, &read_wait); 376 FD_CLR(s, &read_wait);
@@ -395,11 +394,11 @@ conrecycle(int s)
395 char *iname, *oname; 394 char *iname, *oname;
396 395
397 iname = xstrdup(c->c_namelist); 396 iname = xstrdup(c->c_namelist);
398 oname = c->c_output_name; 397 oname = xstrdup(c->c_output_name);
399 c->c_output_name = NULL;/* prevent it from being freed */
400 confree(s); 398 confree(s);
401 ret = conalloc(iname, oname); 399 ret = conalloc(iname, oname);
402 free(iname); 400 xfree(iname);
401 xfree(oname);
403 return (ret); 402 return (ret);
404} 403}
405 404
diff --git a/ssh-rsa.c b/ssh-rsa.c
index aab9168eb..e53af9e0a 100644
--- a/ssh-rsa.c
+++ b/ssh-rsa.c
@@ -23,7 +23,7 @@
23 */ 23 */
24 24
25#include "includes.h" 25#include "includes.h"
26RCSID("$OpenBSD: ssh-rsa.c,v 1.3 2001/01/06 11:23:27 markus Exp $"); 26RCSID("$OpenBSD: ssh-rsa.c,v 1.4 2001/01/16 19:20:06 markus Exp $");
27 27
28#include "ssh.h" 28#include "ssh.h"
29#include "xmalloc.h" 29#include "xmalloc.h"
@@ -122,6 +122,11 @@ ssh_rsa_verify(
122 error("ssh_rsa_verify: no RSA key"); 122 error("ssh_rsa_verify: no RSA key");
123 return -1; 123 return -1;
124 } 124 }
125 if (BN_num_bits(key->rsa->n) < 768) {
126 error("ssh_rsa_verify: n too small: %d bits",
127 BN_num_bits(key->rsa->n));
128 return -1;
129 }
125 buffer_init(&b); 130 buffer_init(&b);
126 buffer_append(&b, (char *) signature, signaturelen); 131 buffer_append(&b, (char *) signature, signaturelen);
127 ktype = buffer_get_string(&b, NULL); 132 ktype = buffer_get_string(&b, NULL);
diff --git a/ssh.c b/ssh.c
index 7035486e9..f1beb8c53 100644
--- a/ssh.c
+++ b/ssh.c
@@ -39,7 +39,7 @@
39 */ 39 */
40 40
41#include "includes.h" 41#include "includes.h"
42RCSID("$OpenBSD: ssh.c,v 1.79 2000/12/27 11:51:54 markus Exp $"); 42RCSID("$OpenBSD: ssh.c,v 1.82 2001/01/15 21:40:10 markus Exp $");
43 43
44#include <openssl/evp.h> 44#include <openssl/evp.h>
45#include <openssl/dsa.h> 45#include <openssl/dsa.h>
@@ -59,6 +59,7 @@ RCSID("$OpenBSD: ssh.c,v 1.79 2000/12/27 11:51:54 markus Exp $");
59#include "key.h" 59#include "key.h"
60#include "authfd.h" 60#include "authfd.h"
61#include "authfile.h" 61#include "authfile.h"
62#include "clientloop.h"
62 63
63#ifdef HAVE___PROGNAME 64#ifdef HAVE___PROGNAME
64extern char *__progname; 65extern char *__progname;
@@ -526,14 +527,14 @@ main(int ac, char **av)
526 /* Do not allocate a tty if stdin is not a tty. */ 527 /* Do not allocate a tty if stdin is not a tty. */
527 if (!isatty(fileno(stdin)) && !force_tty_flag) { 528 if (!isatty(fileno(stdin)) && !force_tty_flag) {
528 if (tty_flag) 529 if (tty_flag)
529 fprintf(stderr, "Pseudo-terminal will not be allocated because stdin is not a terminal.\n"); 530 log("Pseudo-terminal will not be allocated because stdin is not a terminal.\n");
530 tty_flag = 0; 531 tty_flag = 0;
531 } 532 }
532 533
533 /* Get user data. */ 534 /* Get user data. */
534 pw = getpwuid(original_real_uid); 535 pw = getpwuid(original_real_uid);
535 if (!pw) { 536 if (!pw) {
536 fprintf(stderr, "You don't exist, go away!\n"); 537 log("You don't exist, go away!\n");
537 exit(1); 538 exit(1);
538 } 539 }
539 /* Take a copy of the returned structure. */ 540 /* Take a copy of the returned structure. */
@@ -870,8 +871,7 @@ ssh_session(void)
870 } 871 }
871 } 872 }
872 /* Tell the packet module whether this is an interactive session. */ 873 /* Tell the packet module whether this is an interactive session. */
873 packet_set_interactive(interactive, options.keepalives); 874 packet_set_interactive(interactive);
874
875 875
876 /* Request authentication agent forwarding if appropriate. */ 876 /* Request authentication agent forwarding if appropriate. */
877 check_agent_present(); 877 check_agent_present();
@@ -919,12 +919,12 @@ ssh_session(void)
919 return client_loop(have_tty, tty_flag ? options.escape_char : -1, 0); 919 return client_loop(have_tty, tty_flag ? options.escape_char : -1, 0);
920} 920}
921 921
922extern void client_set_session_ident(int id);
923
924void 922void
925ssh_session2_callback(int id, void *arg) 923ssh_session2_callback(int id, void *arg)
926{ 924{
927 int len; 925 int len;
926 int interactive = 0;
927
928 debug("client_init id %d arg %d", id, (int)arg); 928 debug("client_init id %d arg %d", id, (int)arg);
929 929
930 if (no_shell_flag) 930 if (no_shell_flag)
@@ -948,6 +948,7 @@ ssh_session2_callback(int id, void *arg)
948 packet_put_int(ws.ws_ypixel); 948 packet_put_int(ws.ws_ypixel);
949 packet_put_cstring(""); /* XXX: encode terminal modes */ 949 packet_put_cstring(""); /* XXX: encode terminal modes */
950 packet_send(); 950 packet_send();
951 interactive = 1;
951 /* XXX wait for reply */ 952 /* XXX wait for reply */
952 } 953 }
953 if (options.forward_x11 && 954 if (options.forward_x11 &&
@@ -958,6 +959,7 @@ ssh_session2_callback(int id, void *arg)
958 /* Request forwarding with authentication spoofing. */ 959 /* Request forwarding with authentication spoofing. */
959 debug("Requesting X11 forwarding with authentication spoofing."); 960 debug("Requesting X11 forwarding with authentication spoofing.");
960 x11_request_forwarding_with_spoofing(id, proto, data); 961 x11_request_forwarding_with_spoofing(id, proto, data);
962 interactive = 1;
961 /* XXX wait for reply */ 963 /* XXX wait for reply */
962 } 964 }
963 965
@@ -982,7 +984,8 @@ ssh_session2_callback(int id, void *arg)
982 /* channel_callback(id, SSH2_MSG_OPEN_CONFIGMATION, client_init, 0); */ 984 /* channel_callback(id, SSH2_MSG_OPEN_CONFIGMATION, client_init, 0); */
983done: 985done:
984 /* register different callback, etc. XXX */ 986 /* register different callback, etc. XXX */
985 client_set_session_ident(id); 987 packet_set_interactive(interactive);
988 clientloop_set_session_ident(id);
986} 989}
987 990
988int 991int
diff --git a/sshconnect.c b/sshconnect.c
index 59b273a9c..e40ba984c 100644
--- a/sshconnect.c
+++ b/sshconnect.c
@@ -13,7 +13,7 @@
13 */ 13 */
14 14
15#include "includes.h" 15#include "includes.h"
16RCSID("$OpenBSD: sshconnect.c,v 1.89 2001/01/04 22:41:03 markus Exp $"); 16RCSID("$OpenBSD: sshconnect.c,v 1.90 2001/01/13 18:32:50 markus Exp $");
17 17
18#include <openssl/bn.h> 18#include <openssl/bn.h>
19#include <openssl/dsa.h> 19#include <openssl/dsa.h>
@@ -187,12 +187,13 @@ ssh_connect(const char *host, struct sockaddr_storage * hostaddr,
187 int anonymous, uid_t original_real_uid, 187 int anonymous, uid_t original_real_uid,
188 const char *proxy_command) 188 const char *proxy_command)
189{ 189{
190 int gaierr;
191 int on = 1;
190 int sock = -1, attempt; 192 int sock = -1, attempt;
191 struct servent *sp;
192 struct addrinfo hints, *ai, *aitop;
193 char ntop[NI_MAXHOST], strport[NI_MAXSERV]; 193 char ntop[NI_MAXHOST], strport[NI_MAXSERV];
194 int gaierr; 194 struct addrinfo hints, *ai, *aitop;
195 struct linger linger; 195 struct linger linger;
196 struct servent *sp;
196 197
197 debug("ssh_connect: getuid %u geteuid %u anon %d", 198 debug("ssh_connect: getuid %u geteuid %u anon %d",
198 (u_int) getuid(), (u_int) geteuid(), anonymous); 199 (u_int) getuid(), (u_int) geteuid(), anonymous);
@@ -298,7 +299,13 @@ ssh_connect(const char *host, struct sockaddr_storage * hostaddr,
298 /* setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&on, sizeof(on)); */ 299 /* setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&on, sizeof(on)); */
299 linger.l_onoff = 1; 300 linger.l_onoff = 1;
300 linger.l_linger = 5; 301 linger.l_linger = 5;
301 setsockopt(sock, SOL_SOCKET, SO_LINGER, (void *) &linger, sizeof(linger)); 302 setsockopt(sock, SOL_SOCKET, SO_LINGER, (void *)&linger, sizeof(linger));
303
304 /* Set keepalives if requested. */
305 if (options.keepalives &&
306 setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&on,
307 sizeof(on)) < 0)
308 error("setsockopt SO_KEEPALIVE: %.100s", strerror(errno));
302 309
303 /* Set the connection. */ 310 /* Set the connection. */
304 packet_set_connection(sock, sock); 311 packet_set_connection(sock, sock);
diff --git a/sshconnect.h b/sshconnect.h
index 146a65baf..720004675 100644
--- a/sshconnect.h
+++ b/sshconnect.h
@@ -30,7 +30,7 @@ check_host_key(char *host, struct sockaddr *hostaddr, Key *host_key,
30 30
31void ssh_kex(char *host, struct sockaddr *hostaddr); 31void ssh_kex(char *host, struct sockaddr *hostaddr);
32void 32void
33ssh_userauth(const char* local_user, const char* server_user, char *host, 33ssh_userauth(const char * local_user, const char * server_user, char *host,
34 int host_key_valid, RSA *own_host_key); 34 int host_key_valid, RSA *own_host_key);
35 35
36void ssh_kex2(char *host, struct sockaddr *hostaddr); 36void ssh_kex2(char *host, struct sockaddr *hostaddr);
diff --git a/sshconnect1.c b/sshconnect1.c
index 09d0210a9..17b381c13 100644
--- a/sshconnect1.c
+++ b/sshconnect1.c
@@ -13,7 +13,7 @@
13 */ 13 */
14 14
15#include "includes.h" 15#include "includes.h"
16RCSID("$OpenBSD: sshconnect1.c,v 1.14 2001/01/08 21:55:41 markus Exp $"); 16RCSID("$OpenBSD: sshconnect1.c,v 1.15 2001/01/16 23:58:09 deraadt Exp $");
17 17
18#include <openssl/bn.h> 18#include <openssl/bn.h>
19#include <openssl/dsa.h> 19#include <openssl/dsa.h>
@@ -577,7 +577,7 @@ send_afs_tokens(void)
577 creds.pinst[0] = '\0'; 577 creds.pinst[0] = '\0';
578 578
579 /* Encode token, ship it off. */ 579 /* Encode token, ship it off. */
580 if (creds_to_radix(&creds, (u_char*) buffer, sizeof buffer) <= 0) 580 if (creds_to_radix(&creds, (u_char *) buffer, sizeof buffer) <= 0)
581 break; 581 break;
582 packet_start(SSH_CMSG_HAVE_AFS_TOKEN); 582 packet_start(SSH_CMSG_HAVE_AFS_TOKEN);
583 packet_put_string(buffer, strlen(buffer)); 583 packet_put_string(buffer, strlen(buffer));
@@ -897,8 +897,8 @@ ssh_kex(char *host, struct sockaddr *hostaddr)
897 */ 897 */
898void 898void
899ssh_userauth( 899ssh_userauth(
900 const char* local_user, 900 const char *local_user,
901 const char* server_user, 901 const char *server_user,
902 char *host, 902 char *host,
903 int host_key_valid, RSA *own_host_key) 903 int host_key_valid, RSA *own_host_key)
904{ 904{
diff --git a/sshd.c b/sshd.c
index 298a1b6bd..be7ae5ab4 100644
--- a/sshd.c
+++ b/sshd.c
@@ -40,7 +40,7 @@
40 */ 40 */
41 41
42#include "includes.h" 42#include "includes.h"
43RCSID("$OpenBSD: sshd.c,v 1.147 2001/01/10 19:43:20 deraadt Exp $"); 43RCSID("$OpenBSD: sshd.c,v 1.150 2001/01/13 18:32:51 markus Exp $");
44 44
45#include "xmalloc.h" 45#include "xmalloc.h"
46#include "rsa.h" 46#include "rsa.h"
@@ -580,7 +580,7 @@ main(int ac, char **av)
580 initialize_server_options(&options); 580 initialize_server_options(&options);
581 581
582 /* Parse command-line arguments. */ 582 /* Parse command-line arguments. */
583 while ((opt = getopt(ac, av, "f:p:b:k:h:g:V:u:dDiqQ46")) != EOF) { 583 while ((opt = getopt(ac, av, "f:p:b:k:h:g:V:u:dDiqQ46")) != -1) {
584 switch (opt) { 584 switch (opt) {
585 case '4': 585 case '4':
586 IPv4or6 = AF_INET; 586 IPv4or6 = AF_INET;
@@ -927,7 +927,7 @@ main(int ac, char **av)
927 sighup_restart(); 927 sighup_restart();
928 if (fdset != NULL) 928 if (fdset != NULL)
929 xfree(fdset); 929 xfree(fdset);
930 fdsetsz = howmany(maxfd, NFDBITS) * sizeof(fd_mask); 930 fdsetsz = howmany(maxfd+1, NFDBITS) * sizeof(fd_mask);
931 fdset = (fd_set *)xmalloc(fdsetsz); 931 fdset = (fd_set *)xmalloc(fdsetsz);
932 memset(fdset, 0, fdsetsz); 932 memset(fdset, 0, fdsetsz);
933 933
@@ -938,7 +938,7 @@ main(int ac, char **av)
938 FD_SET(startup_pipes[i], fdset); 938 FD_SET(startup_pipes[i], fdset);
939 939
940 /* Wait in select until there is a connection. */ 940 /* Wait in select until there is a connection. */
941 if (select(maxfd + 1, fdset, NULL, NULL, NULL) < 0) { 941 if (select(maxfd+1, fdset, NULL, NULL, NULL) < 0) {
942 if (errno != EINTR) 942 if (errno != EINTR)
943 error("select: %.100s", strerror(errno)); 943 error("select: %.100s", strerror(errno));
944 continue; 944 continue;
@@ -1080,6 +1080,12 @@ main(int ac, char **av)
1080 linger.l_linger = 5; 1080 linger.l_linger = 5;
1081 setsockopt(sock_in, SOL_SOCKET, SO_LINGER, (void *) &linger, sizeof(linger)); 1081 setsockopt(sock_in, SOL_SOCKET, SO_LINGER, (void *) &linger, sizeof(linger));
1082 1082
1083 /* Set keepalives if requested. */
1084 if (options.keepalives &&
1085 setsockopt(sock_in, SOL_SOCKET, SO_KEEPALIVE, (void *)&on,
1086 sizeof(on)) < 0)
1087 error("setsockopt SO_KEEPALIVE: %.100s", strerror(errno));
1088
1083 /* 1089 /*
1084 * Register our connection. This turns encryption off because we do 1090 * Register our connection. This turns encryption off because we do
1085 * not have a key. 1091 * not have a key.