summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2000-09-30 09:49:08 +1100
committerDamien Miller <djm@mindrot.org>2000-09-30 09:49:08 +1100
commit3dfb0dd7fd3e792e73e27a213f53b3fe452b8e45 (patch)
tree9a7251d0f01a726aac7cda14f759081a0adaccde
parentbea034a5bfcce67b1149b28a57c58a605170e68f (diff)
- (djm) Support in bsd-snprintf.c for long long conversions from
Ben Lindstrom <mouring@pconline.com> - (djm) Cleanup NeXT support from Ben Lindstrom <mouring@pconline.com>
-rw-r--r--bsd-snprintf.c38
-rw-r--r--next-posix.c61
-rw-r--r--next-posix.h45
-rw-r--r--sshd.c2
4 files changed, 93 insertions, 53 deletions
diff --git a/bsd-snprintf.c b/bsd-snprintf.c
index 5b674c569..3a82a586f 100644
--- a/bsd-snprintf.c
+++ b/bsd-snprintf.c
@@ -38,6 +38,10 @@
38 * missing. Some systems only have snprintf() but not vsnprintf(), so 38 * missing. Some systems only have snprintf() but not vsnprintf(), so
39 * the code is now broken down under HAVE_SNPRINTF and HAVE_VSNPRINTF. 39 * the code is now broken down under HAVE_SNPRINTF and HAVE_VSNPRINTF.
40 * 40 *
41 * Ben Lindstrom <mouring@pconline.com> 09/27/00 for OpenSSH
42 * Welcome to the world of %lld and %qd support. With other
43 * long long support. This is needed for sftp-server to work
44 * right.
41 **************************************************************/ 45 **************************************************************/
42 46
43#include "config.h" 47#include "config.h"
@@ -111,9 +115,10 @@ static void dopr_outch (char *buffer, size_t *currlen, size_t maxlen, char c );
111#define DP_F_UNSIGNED (1 << 6) 115#define DP_F_UNSIGNED (1 << 6)
112 116
113/* Conversion Flags */ 117/* Conversion Flags */
114#define DP_C_SHORT 1 118#define DP_C_SHORT 1
115#define DP_C_LONG 2 119#define DP_C_LONG 2
116#define DP_C_LDOUBLE 3 120#define DP_C_LDOUBLE 3
121#define DP_C_LONG_LONG 4
117 122
118#define char_to_int(p) (p - '0') 123#define char_to_int(p) (p - '0')
119#ifndef MAX 124#ifndef MAX
@@ -222,7 +227,6 @@ static void dopr (char *buffer, size_t maxlen, const char *format, va_list args)
222 state = DP_S_MOD; 227 state = DP_S_MOD;
223 break; 228 break;
224 case DP_S_MOD: 229 case DP_S_MOD:
225 /* Currently, we don't support Long Long, bummer */
226 switch (ch) 230 switch (ch)
227 { 231 {
228 case 'h': 232 case 'h':
@@ -232,7 +236,15 @@ static void dopr (char *buffer, size_t maxlen, const char *format, va_list args)
232 case 'l': 236 case 'l':
233 cflags = DP_C_LONG; 237 cflags = DP_C_LONG;
234 ch = *format++; 238 ch = *format++;
239 if (ch == 'l') {
240 cflags = DP_C_LONG_LONG;
241 ch = *format++;
242 }
235 break; 243 break;
244 case 'q':
245 cflags = DP_C_LONG_LONG;
246 ch = *format++;
247 break;
236 case 'L': 248 case 'L':
237 cflags = DP_C_LDOUBLE; 249 cflags = DP_C_LDOUBLE;
238 ch = *format++; 250 ch = *format++;
@@ -251,6 +263,8 @@ static void dopr (char *buffer, size_t maxlen, const char *format, va_list args)
251 value = va_arg (args, short int); 263 value = va_arg (args, short int);
252 else if (cflags == DP_C_LONG) 264 else if (cflags == DP_C_LONG)
253 value = va_arg (args, long int); 265 value = va_arg (args, long int);
266 else if (cflags == DP_C_LONG_LONG)
267 value = va_arg (args, long long);
254 else 268 else
255 value = va_arg (args, int); 269 value = va_arg (args, int);
256 fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags); 270 fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
@@ -261,6 +275,8 @@ static void dopr (char *buffer, size_t maxlen, const char *format, va_list args)
261 value = va_arg (args, unsigned short int); 275 value = va_arg (args, unsigned short int);
262 else if (cflags == DP_C_LONG) 276 else if (cflags == DP_C_LONG)
263 value = va_arg (args, unsigned long int); 277 value = va_arg (args, unsigned long int);
278 else if (cflags == DP_C_LONG_LONG)
279 value = va_arg (args, unsigned long long);
264 else 280 else
265 value = va_arg (args, unsigned int); 281 value = va_arg (args, unsigned int);
266 fmtint (buffer, &currlen, maxlen, value, 8, min, max, flags); 282 fmtint (buffer, &currlen, maxlen, value, 8, min, max, flags);
@@ -271,6 +287,8 @@ static void dopr (char *buffer, size_t maxlen, const char *format, va_list args)
271 value = va_arg (args, unsigned short int); 287 value = va_arg (args, unsigned short int);
272 else if (cflags == DP_C_LONG) 288 else if (cflags == DP_C_LONG)
273 value = va_arg (args, unsigned long int); 289 value = va_arg (args, unsigned long int);
290 else if (cflags == DP_C_LONG_LONG)
291 value = va_arg (args, unsigned long long);
274 else 292 else
275 value = va_arg (args, unsigned int); 293 value = va_arg (args, unsigned int);
276 fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags); 294 fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
@@ -283,6 +301,8 @@ static void dopr (char *buffer, size_t maxlen, const char *format, va_list args)
283 value = va_arg (args, unsigned short int); 301 value = va_arg (args, unsigned short int);
284 else if (cflags == DP_C_LONG) 302 else if (cflags == DP_C_LONG)
285 value = va_arg (args, unsigned long int); 303 value = va_arg (args, unsigned long int);
304 else if (cflags == DP_C_LONG_LONG)
305 value = va_arg (args, unsigned long long);
286 else 306 else
287 value = va_arg (args, unsigned int); 307 value = va_arg (args, unsigned int);
288 fmtint (buffer, &currlen, maxlen, value, 16, min, max, flags); 308 fmtint (buffer, &currlen, maxlen, value, 16, min, max, flags);
@@ -337,6 +357,12 @@ static void dopr (char *buffer, size_t maxlen, const char *format, va_list args)
337 num = va_arg (args, long int *); 357 num = va_arg (args, long int *);
338 *num = currlen; 358 *num = currlen;
339 } 359 }
360 else if (cflags == DP_C_LONG_LONG)
361 {
362 long long *num;
363 num = va_arg (args, long long *);
364 *num = currlen;
365 }
340 else 366 else
341 { 367 {
342 int *num; 368 int *num;
@@ -747,9 +773,11 @@ int main (void)
747 "%+22.33d", 773 "%+22.33d",
748 "%01.3d", 774 "%01.3d",
749 "%4d", 775 "%4d",
776 "%lld",
777 "%qd",
750 NULL 778 NULL
751 }; 779 };
752 long int_nums[] = { -1, 134, 91340, 341, 0203, 0}; 780 long long int_nums[] = { -1, 134, 91340, 341, 0203, 0, 9999999 };
753 int x, y; 781 int x, y;
754 int fail = 0; 782 int fail = 0;
755 int num = 0; 783 int num = 0;
diff --git a/next-posix.c b/next-posix.c
index de7723e97..d5cc733d0 100644
--- a/next-posix.c
+++ b/next-posix.c
@@ -1,3 +1,25 @@
1/*
2 * Redistribution and use in source and binary forms, with or without
3 * modification, are permitted provided that the following conditions
4 * are met:
5 * 1. Redistributions of source code must retain the above copyright
6 * notice, this list of conditions and the following disclaimer.
7 * 2. Redistributions in binary form must reproduce the above copyright
8 * notice, this list of conditions and the following disclaimer in the
9 * documentation and/or other materials provided with the distribution.
10 *
11 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
12 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
13 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
14 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
15 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
16 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
17 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
18 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
19 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
20 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21 */
22
1#include "includes.h" 23#include "includes.h"
2 24
3#ifdef HAVE_NEXT 25#ifdef HAVE_NEXT
@@ -8,46 +30,32 @@
8pid_t 30pid_t
9posix_wait(int *status) 31posix_wait(int *status)
10{ 32{
11 #undef wait /* Use NeXT's wait() function */
12 union wait statusp; 33 union wait statusp;
13 pid_t wait_pid; 34 pid_t wait_pid;
14 35
36 #undef wait /* Use NeXT's wait() function */
15 wait_pid = wait(&statusp); 37 wait_pid = wait(&statusp);
16 status = (int *) statusp.w_status; 38 status = (int *) statusp.w_status;
17 39
18 return wait_pid; 40 return wait_pid;
19} 41}
20 42
21 43pid_t
22int 44waitpid(int pid, int *stat_loc, int options)
23posix_utime(char *filename,struct utimbuf *buf)
24{
25 time_t timep[2];
26
27 timep[0] = buf->actime;
28 timep[1] = buf->modtime;
29
30 #undef utime /* Use NeXT's utime() function */
31 return utime(filename,timep);
32}
33
34
35int
36waitpid(int pid, int *stat_loc, int options)
37{ 45{
46 union wait statusp;
47 pid_t wait_pid;
48
38 if (pid <= 0) { 49 if (pid <= 0) {
39 if (pid != -1) { 50 if (pid != -1) {
40 errno = EINVAL; 51 errno = EINVAL;
41 return -1; 52 return -1;
42 } 53 }
43 pid = 0; /* wait4() expects pid=0 for indiscriminate wait. */ 54 pid = 0; /* wait4() wants pid=0 for indiscriminate wait. */
44 } 55 }
45 return wait4(pid, (union wait *)stat_loc, options, NULL); 56 wait_pid = wait4(pid, &statusp, options, NULL);
46} 57 stat_loc = (int *)statusp.w_status;
47 58 return wait_pid;
48pid_t setsid(void)
49{
50 return setpgrp(0, getpid());
51} 59}
52 60
53int 61int
@@ -81,10 +89,7 @@ tcsetattr(int fd, int opt, const struct termios *t)
81 89
82int tcsetpgrp(int fd, pid_t pgrp) 90int tcsetpgrp(int fd, pid_t pgrp)
83{ 91{
84 int s; 92 return (ioctl(fd, TIOCSPGRP, &pgrp));
85
86 s = pgrp;
87 return (ioctl(fd, TIOCSPGRP, &s));
88} 93}
89 94
90speed_t cfgetospeed(const struct termios *t) 95speed_t cfgetospeed(const struct termios *t)
diff --git a/next-posix.h b/next-posix.h
index fc06e41bc..3ac4739d0 100644
--- a/next-posix.h
+++ b/next-posix.h
@@ -1,5 +1,24 @@
1/* 1/*
2 * Defines and prototypes specific to NeXT system 2 * Redistribution and use in source and binary forms, with or without
3 * modification, are permitted provided that the following conditions
4 * are met:
5 * 1. Redistributions of source code must retain the above copyright
6 * notice, this list of conditions and the following disclaimer.
7 * 2. Redistributions in binary form must reproduce the above copyright
8 * notice, this list of conditions and the following disclaimer in the
9 * documentation and/or other materials provided with the distribution.
10 *
11 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
12 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
13 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
14 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
15 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
16 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
17 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
18 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
19 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
20 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21 *
3 */ 22 */
4 23
5#ifndef _NEXT_POSIX_H 24#ifndef _NEXT_POSIX_H
@@ -9,15 +28,9 @@
9 28
10#include <sys/dir.h> 29#include <sys/dir.h>
11 30
12/* readdir() returns struct direct (BSD) not struct dirent (POSIX) */ 31/* NeXT's Readdir() is BSD (struct direct) not POSIX (struct dirent) */
13#define dirent direct 32#define dirent direct
14 33
15/* POSIX utime() struct */
16struct utimbuf {
17 time_t actime;
18 time_t modtime;
19};
20
21/* FILE */ 34/* FILE */
22#define O_NONBLOCK 00004 /* non-blocking open */ 35#define O_NONBLOCK 00004 /* non-blocking open */
23 36
@@ -31,19 +44,14 @@ struct utimbuf {
31#define WIFSIGNALED(w) (!WIFEXITED(w) && !WIFSTOPPED(w)) 44#define WIFSIGNALED(w) (!WIFEXITED(w) && !WIFSTOPPED(w))
32#define WEXITSTATUS(w) (int)(WIFEXITED(w) ? (((w) >> 8) & 0377) : -1) 45#define WEXITSTATUS(w) (int)(WIFEXITED(w) ? (((w) >> 8) & 0377) : -1)
33#define WTERMSIG(w) (int)(WIFSIGNALED(w) ? ((w) & 0177) : -1) 46#define WTERMSIG(w) (int)(WIFSIGNALED(w) ? ((w) & 0177) : -1)
34#define WCOREFLAG 0x80
35#define WCOREDUMP(w) ((w) & WCOREFLAG)
36
37/* POSIX "wrapper" functions to replace to BSD functions */
38int posix_utime(char *filename, struct utimbuf *buf); /* new utime() */
39#define utime posix_utime
40 47
41pid_t posix_wait(int *status); /* new wait() */ 48/* Swap out the next 'BSDish' wait() for a more POSIX complient one */
42#define wait posix_wait 49pid_t posix_wait(int *status);
50#define wait(a) posix_wait(a)
43 51
44/* MISC functions */ 52/* MISC functions */
45int waitpid(int pid, int *stat_loc, int options); 53#define setsid() setpgrp(0, getpid())
46pid_t setsid(void); 54pid_t waitpid(int pid, int *stat_loc, int options);
47 55
48/* TERMCAP */ 56/* TERMCAP */
49int tcgetattr(int fd, struct termios *t); 57int tcgetattr(int fd, struct termios *t);
@@ -54,5 +62,4 @@ speed_t cfgetispeed(const struct termios *t);
54int cfsetospeed(struct termios *t, int speed); 62int cfsetospeed(struct termios *t, int speed);
55 63
56#endif /* HAVE_NEXT */ 64#endif /* HAVE_NEXT */
57
58#endif /* _NEXT_POSIX_H */ 65#endif /* _NEXT_POSIX_H */
diff --git a/sshd.c b/sshd.c
index 7fed51c42..ae22cd953 100644
--- a/sshd.c
+++ b/sshd.c
@@ -1263,7 +1263,7 @@ do_ssh1_kex()
1263 if (len < 0 || len > sizeof(session_key)) 1263 if (len < 0 || len > sizeof(session_key))
1264 fatal("do_connection: bad len from %s: session_key_int %d > sizeof(session_key) %d", 1264 fatal("do_connection: bad len from %s: session_key_int %d > sizeof(session_key) %d",
1265 get_remote_ipaddr(), 1265 get_remote_ipaddr(),
1266 len, sizeof(session_key)); 1266 len, (int) sizeof(session_key));
1267 memset(session_key, 0, sizeof(session_key)); 1267 memset(session_key, 0, sizeof(session_key));
1268 BN_bn2bin(session_key_int, session_key + sizeof(session_key) - len); 1268 BN_bn2bin(session_key_int, session_key + sizeof(session_key) - len);
1269 1269