summaryrefslogtreecommitdiff
path: root/openbsd-compat
diff options
context:
space:
mode:
Diffstat (limited to 'openbsd-compat')
-rw-r--r--openbsd-compat/Makefile.in6
-rw-r--r--openbsd-compat/base64.c2
-rw-r--r--openbsd-compat/basename.c2
-rw-r--r--openbsd-compat/bsd-arc4random.c32
-rw-r--r--openbsd-compat/bsd-cray.c109
-rw-r--r--openbsd-compat/bsd-cray.h3
-rw-r--r--openbsd-compat/bsd-getpeereid.c32
-rw-r--r--openbsd-compat/bsd-misc.c34
-rw-r--r--openbsd-compat/bsd-misc.h32
-rw-r--r--openbsd-compat/bsd-openpty.c203
-rw-r--r--openbsd-compat/daemon.c2
-rw-r--r--openbsd-compat/dirname.c2
-rw-r--r--openbsd-compat/fake-rfc2553.c2
-rw-r--r--openbsd-compat/fake-rfc2553.h6
-rw-r--r--openbsd-compat/getcwd.c2
-rw-r--r--openbsd-compat/getgrouplist.c2
-rw-r--r--openbsd-compat/getopt.c2
-rw-r--r--openbsd-compat/getrrsetbyname.c17
-rw-r--r--openbsd-compat/getrrsetbyname.h14
-rw-r--r--openbsd-compat/glob.c2
-rw-r--r--openbsd-compat/glob.h2
-rw-r--r--openbsd-compat/inet_aton.c2
-rw-r--r--openbsd-compat/inet_ntoa.c2
-rw-r--r--openbsd-compat/inet_ntop.c2
-rw-r--r--openbsd-compat/mktemp.c2
-rw-r--r--openbsd-compat/openbsd-compat.h7
-rw-r--r--openbsd-compat/port-aix.c140
-rw-r--r--openbsd-compat/port-aix.h17
-rw-r--r--openbsd-compat/readpassphrase.c2
-rw-r--r--openbsd-compat/readpassphrase.h2
-rw-r--r--openbsd-compat/realpath.c4
-rw-r--r--openbsd-compat/rresvport.c2
-rw-r--r--openbsd-compat/setenv.c2
-rw-r--r--openbsd-compat/setproctitle.c4
-rw-r--r--openbsd-compat/sigact.c2
-rw-r--r--openbsd-compat/strlcat.c2
-rw-r--r--openbsd-compat/strlcpy.c2
-rw-r--r--openbsd-compat/strmode.c2
-rw-r--r--openbsd-compat/strsep.c2
-rw-r--r--openbsd-compat/strtoul.c114
-rw-r--r--openbsd-compat/sys-queue.h2
-rw-r--r--openbsd-compat/sys-tree.h2
-rw-r--r--openbsd-compat/vis.c2
-rw-r--r--openbsd-compat/vis.h2
-rw-r--r--openbsd-compat/xcrypt.c4
45 files changed, 662 insertions, 170 deletions
diff --git a/openbsd-compat/Makefile.in b/openbsd-compat/Makefile.in
index c48593f7b..5de20abbc 100644
--- a/openbsd-compat/Makefile.in
+++ b/openbsd-compat/Makefile.in
@@ -1,4 +1,4 @@
1# $Id: Makefile.in,v 1.28 2003/07/24 06:52:14 mouring Exp $ 1# $Id: Makefile.in,v 1.30 2004/01/21 06:07:23 djm Exp $
2 2
3sysconfdir=@sysconfdir@ 3sysconfdir=@sysconfdir@
4piddir=@piddir@ 4piddir=@piddir@
@@ -16,9 +16,9 @@ RANLIB=@RANLIB@
16INSTALL=@INSTALL@ 16INSTALL=@INSTALL@
17LDFLAGS=-L. @LDFLAGS@ 17LDFLAGS=-L. @LDFLAGS@
18 18
19OPENBSD=base64.o basename.o bindresvport.o daemon.o dirname.o getcwd.o getgrouplist.o getopt.o getrrsetbyname.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sigact.o strlcat.o strlcpy.o strmode.o strsep.o vis.o 19OPENBSD=base64.o basename.o bindresvport.o daemon.o dirname.o getcwd.o getgrouplist.o getopt.o getrrsetbyname.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sigact.o strlcat.o strlcpy.o strmode.o strsep.o strtoul.o vis.o
20 20
21COMPAT=bsd-arc4random.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o bsd-misc.o bsd-nextstep.o bsd-snprintf.o bsd-waitpid.o fake-rfc2553.o xmmap.o xcrypt.o 21COMPAT=bsd-arc4random.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o bsd-misc.o bsd-nextstep.o bsd-openpty.o bsd-snprintf.o bsd-waitpid.o fake-rfc2553.o xmmap.o xcrypt.o
22 22
23PORTS=port-irix.o port-aix.o 23PORTS=port-irix.o port-aix.o
24 24
diff --git a/openbsd-compat/base64.c b/openbsd-compat/base64.c
index 91a5ab0ed..dcaa03e5d 100644
--- a/openbsd-compat/base64.c
+++ b/openbsd-compat/base64.c
@@ -1,3 +1,5 @@
1/* OPENBSD ORIGINAL: lib/libc/net/base64.c */
2
1/* $OpenBSD: base64.c,v 1.4 2002/01/02 23:00:10 deraadt Exp $ */ 3/* $OpenBSD: base64.c,v 1.4 2002/01/02 23:00:10 deraadt Exp $ */
2 4
3/* 5/*
diff --git a/openbsd-compat/basename.c b/openbsd-compat/basename.c
index 2054c8068..552dc1e1c 100644
--- a/openbsd-compat/basename.c
+++ b/openbsd-compat/basename.c
@@ -1,3 +1,5 @@
1/* OPENBSD ORIGINAL: lib/libc/gen/basename.c */
2
1/* $OpenBSD: basename.c,v 1.11 2003/06/17 21:56:23 millert Exp $ */ 3/* $OpenBSD: basename.c,v 1.11 2003/06/17 21:56:23 millert Exp $ */
2 4
3/* 5/*
diff --git a/openbsd-compat/bsd-arc4random.c b/openbsd-compat/bsd-arc4random.c
index 5f890968e..22003ff0a 100644
--- a/openbsd-compat/bsd-arc4random.c
+++ b/openbsd-compat/bsd-arc4random.c
@@ -1,31 +1,23 @@
1/* 1/*
2 * Copyright (c) 1999-2000 Damien Miller. All rights reserved. 2 * Copyright (c) 1999,2000,2004 Damien Miller <djm@mindrot.org>
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Permission to use, copy, modify, and distribute this software for any
5 * modification, are permitted provided that the following conditions 5 * purpose with or without fee is hereby granted, provided that the above
6 * are met: 6 * copyright notice and this permission notice appear in all copies.
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 * 7 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
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 */ 15 */
24 16
25#include "includes.h" 17#include "includes.h"
26#include "log.h" 18#include "log.h"
27 19
28RCSID("$Id: bsd-arc4random.c,v 1.7 2003/05/18 14:13:38 djm Exp $"); 20RCSID("$Id: bsd-arc4random.c,v 1.8 2004/02/17 05:49:55 djm Exp $");
29 21
30#ifndef HAVE_ARC4RANDOM 22#ifndef HAVE_ARC4RANDOM
31 23
diff --git a/openbsd-compat/bsd-cray.c b/openbsd-compat/bsd-cray.c
index f2ac428cc..f630366be 100644
--- a/openbsd-compat/bsd-cray.c
+++ b/openbsd-compat/bsd-cray.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: bsd-cray.c,v 1.12 2003/06/03 02:45:27 dtucker Exp $ 2 * $Id: bsd-cray.c,v 1.13 2004/01/30 03:34:22 dtucker Exp $
3 * 3 *
4 * bsd-cray.c 4 * bsd-cray.c
5 * 5 *
@@ -59,6 +59,28 @@
59#include <ia.h> 59#include <ia.h>
60#include <urm.h> 60#include <urm.h>
61#include "ssh.h" 61#include "ssh.h"
62
63#include "includes.h"
64#include "sys/types.h"
65
66#ifndef HAVE_STRUCT_SOCKADDR_STORAGE
67# define _SS_MAXSIZE 128 /* Implementation specific max size */
68# define _SS_PADSIZE (_SS_MAXSIZE - sizeof (struct sockaddr))
69
70# define ss_family ss_sa.sa_family
71#endif /* !HAVE_STRUCT_SOCKADDR_STORAGE */
72
73#ifndef IN6_IS_ADDR_LOOPBACK
74# define IN6_IS_ADDR_LOOPBACK(a) \
75 (((u_int32_t *) (a))[0] == 0 && ((u_int32_t *) (a))[1] == 0 && \
76 ((u_int32_t *) (a))[2] == 0 && ((u_int32_t *) (a))[3] == htonl (1))
77#endif /* !IN6_IS_ADDR_LOOPBACK */
78
79#ifndef AF_INET6
80/* Define it to something that should never appear */
81#define AF_INET6 AF_MAX
82#endif
83
62#include "log.h" 84#include "log.h"
63#include "servconf.h" 85#include "servconf.h"
64#include "bsd-cray.h" 86#include "bsd-cray.h"
@@ -182,7 +204,7 @@ cray_setup (uid_t uid, char *username, const char *command)
182 /* passwd stuff for ia_user */ 204 /* passwd stuff for ia_user */
183 passwd_t pwdacm, pwddialup, pwdudb, pwdwal, pwddce; 205 passwd_t pwdacm, pwddialup, pwdudb, pwdwal, pwddce;
184 ia_user_ret_t uret; /* stuff returned from ia_user */ 206 ia_user_ret_t uret; /* stuff returned from ia_user */
185 ia_user_t usent /* ia_user main structure */ 207 ia_user_t usent; /* ia_user main structure */
186 int ia_rcode; /* ia_user return code */ 208 int ia_rcode; /* ia_user return code */
187 ia_failure_t fsent; /* ia_failure structure */ 209 ia_failure_t fsent; /* ia_failure structure */
188 ia_failure_ret_t fret; /* ia_failure return stuff */ 210 ia_failure_ret_t fret; /* ia_failure return stuff */
@@ -501,54 +523,54 @@ cray_setup (uid_t uid, char *username, const char *command)
501 break; 523 break;
502 default: 524 default:
503 valid_acct = nam2acid(acct_name); 525 valid_acct = nam2acid(acct_name);
504 if (valid_acct == -1) { 526 if (valid_acct == -1)
505 printf( 527 printf(
506 "Account id not found for" 528 "Account id not found for"
507 " account name \"%s\"\n\n", 529 " account name \"%s\"\n\n",
508 acct_name); 530 acct_name);
509 break; 531 break;
510 }
511 /*
512 * If an account was given, search the user's
513 * acids array to verify they can use this account.
514 */
515 if ((valid_acct != -1) &&
516 !(ue.ue_permbits & PERMBITS_ACCTID)) {
517 for (i = 0; i < MAXVIDS; i++) {
518 if (ue.ue_acids[i] == -1)
519 break;
520 if (valid_acct == ue.ue_acids[i])
521 break;
522 }
523 if (i == MAXVIDS ||
524 ue.ue_acids[i] == -1) {
525 fprintf(stderr, "Cannot set"
526 " account name to "
527 "\"%s\", permission "
528 "denied\n\n", acct_name);
529 valid_acct = -1;
530 }
531 }
532 } 532 }
533 } else {
534 /* 533 /*
535 * The client isn't connected to a terminal and can't 534 * If an account was given, search the user's
536 * respond to an acid prompt. Use default acid. 535 * acids array to verify they can use this account.
537 */ 536 */
538 debug("cray_setup: ttyname false case, %.100s", 537 if ((valid_acct != -1) &&
539 ttyname); 538 !(ue.ue_permbits & PERMBITS_ACCTID)) {
540 valid_acct = ue.ue_acids[0]; 539 for (i = 0; i < MAXVIDS; i++) {
540 if (ue.ue_acids[i] == -1)
541 break;
542 if (valid_acct == ue.ue_acids[i])
543 break;
544 }
545 if (i == MAXVIDS ||
546 ue.ue_acids[i] == -1) {
547 fprintf(stderr, "Cannot set"
548 " account name to "
549 "\"%s\", permission "
550 "denied\n\n", acct_name);
551 valid_acct = -1;
552 }
553 }
541 } 554 }
542 } else { 555 } else {
543 /* 556 /*
544 * The user doesn't have the askacid permbit set or 557 * The client isn't connected to a terminal and can't
545 * only has one valid account to use. 558 * respond to an acid prompt. Use default acid.
546 */ 559 */
560 debug("cray_setup: ttyname false case, %.100s",
561 ttyname);
547 valid_acct = ue.ue_acids[0]; 562 valid_acct = ue.ue_acids[0];
548 } 563 }
549 if (acctid(0, valid_acct) < 0) { 564 } else {
550 printf ("Bad account id: %d\n", valid_acct); 565 /*
551 exit(1); 566 * The user doesn't have the askacid permbit set or
567 * only has one valid account to use.
568 */
569 valid_acct = ue.ue_acids[0];
570 }
571 if (acctid(0, valid_acct) < 0) {
572 printf ("Bad account id: %d\n", valid_acct);
573 exit(1);
552 } 574 }
553 575
554 /* 576 /*
@@ -778,4 +800,17 @@ cray_set_tmpdir(struct utmp *ut)
778 ut->ut_jid = jid; 800 ut->ut_jid = jid;
779 strncpy(ut->ut_tpath, cray_tmpdir, TPATHSIZ); 801 strncpy(ut->ut_tpath, cray_tmpdir, TPATHSIZ);
780} 802}
781#endif 803#endif /* UNICOS */
804
805#ifdef _UNICOSMP
806#include <pwd.h>
807/*
808 * Set job id and create tmpdir directory.
809 */
810void
811cray_init_job(struct passwd *pw)
812{
813 initrm_silent(pw->pw_uid);
814 return;
815}
816#endif /* _UNICOSMP */
diff --git a/openbsd-compat/bsd-cray.h b/openbsd-compat/bsd-cray.h
index a121ea152..de6ba1a8d 100644
--- a/openbsd-compat/bsd-cray.h
+++ b/openbsd-compat/bsd-cray.h
@@ -1,4 +1,4 @@
1/* $Id: bsd-cray.h,v 1.10 2003/08/29 16:59:52 mouring Exp $ */ 1/* $Id: bsd-cray.h,v 1.11 2004/01/30 03:34:22 dtucker Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2002, Cray Inc. (Wendy Palm <wendyp@cray.com>) 4 * Copyright (c) 2002, Cray Inc. (Wendy Palm <wendyp@cray.com>)
@@ -53,7 +53,6 @@ extern char cray_tmpdir[];
53# define MAXHOSTNAMELEN 64 53# define MAXHOSTNAMELEN 64
54#endif 54#endif
55#ifndef _CRAYT3E 55#ifndef _CRAYT3E
56# include <sys/ttold.h>
57# define TIOCGPGRP (tIOC|20) 56# define TIOCGPGRP (tIOC|20)
58#endif 57#endif
59 58
diff --git a/openbsd-compat/bsd-getpeereid.c b/openbsd-compat/bsd-getpeereid.c
index bcda2c155..fe2edad71 100644
--- a/openbsd-compat/bsd-getpeereid.c
+++ b/openbsd-compat/bsd-getpeereid.c
@@ -1,30 +1,22 @@
1/* 1/*
2 * Copyright (c) 2002 Damien Miller. All rights reserved. 2 * Copyright (c) 2002,2004 Damien Miller <djm@mindrot.org>
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Permission to use, copy, modify, and distribute this software for any
5 * modification, are permitted provided that the following conditions 5 * purpose with or without fee is hereby granted, provided that the above
6 * are met: 6 * copyright notice and this permission notice appear in all copies.
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 * 7 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
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 */ 15 */
24 16
25#include "includes.h" 17#include "includes.h"
26 18
27RCSID("$Id: bsd-getpeereid.c,v 1.2 2003/03/24 22:07:52 djm Exp $"); 19RCSID("$Id: bsd-getpeereid.c,v 1.3 2004/02/17 05:49:55 djm Exp $");
28 20
29#if !defined(HAVE_GETPEEREID) 21#if !defined(HAVE_GETPEEREID)
30 22
diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c
index 08b089bdc..7b06786f5 100644
--- a/openbsd-compat/bsd-misc.c
+++ b/openbsd-compat/bsd-misc.c
@@ -1,31 +1,23 @@
1/* 1/*
2 * Copyright (c) 1999-2003 Damien Miller. All rights reserved. 2 * Copyright (c) 1999-2004 Damien Miller <djm@mindrot.org>
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Permission to use, copy, modify, and distribute this software for any
5 * modification, are permitted provided that the following conditions 5 * purpose with or without fee is hereby granted, provided that the above
6 * are met: 6 * copyright notice and this permission notice appear in all copies.
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 * 7 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
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 */ 15 */
24 16
25#include "includes.h" 17#include "includes.h"
26#include "xmalloc.h" 18#include "xmalloc.h"
27 19
28RCSID("$Id: bsd-misc.c,v 1.19 2003/08/25 01:16:21 mouring Exp $"); 20RCSID("$Id: bsd-misc.c,v 1.21 2004/02/17 05:49:55 djm Exp $");
29 21
30/* 22/*
31 * NB. duplicate __progname in case it is an alias for argv[0] 23 * NB. duplicate __progname in case it is an alias for argv[0]
@@ -164,7 +156,6 @@ int nanosleep(const struct timespec *req, struct timespec *rem)
164 156
165 return(rc); 157 return(rc);
166} 158}
167
168#endif 159#endif
169 160
170#ifndef HAVE_TCGETPGRP 161#ifndef HAVE_TCGETPGRP
@@ -223,6 +214,7 @@ mysignal(int sig, mysig_t act)
223 } 214 }
224 return (osa.sa_handler); 215 return (osa.sa_handler);
225#else 216#else
217 #undef signal
226 return (signal(sig, act)); 218 return (signal(sig, act));
227#endif 219#endif
228} 220}
diff --git a/openbsd-compat/bsd-misc.h b/openbsd-compat/bsd-misc.h
index 6b70473f3..c8073942c 100644
--- a/openbsd-compat/bsd-misc.h
+++ b/openbsd-compat/bsd-misc.h
@@ -1,27 +1,19 @@
1/* $Id: bsd-misc.h,v 1.13 2003/08/29 16:59:52 mouring Exp $ */ 1/* $Id: bsd-misc.h,v 1.14 2004/02/17 05:49:55 djm Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1999-2003 Damien Miller. All rights reserved. 4 * Copyright (c) 1999-2004 Damien Miller <djm@mindrot.org>
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Permission to use, copy, modify, and distribute this software for any
7 * modification, are permitted provided that the following conditions 7 * purpose with or without fee is hereby granted, provided that the above
8 * are met: 8 * copyright notice and this permission notice appear in all copies.
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 9 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 17 */
26 18
27#ifndef _BSD_MISC_H 19#ifndef _BSD_MISC_H
diff --git a/openbsd-compat/bsd-openpty.c b/openbsd-compat/bsd-openpty.c
new file mode 100644
index 000000000..daf5f8b81
--- /dev/null
+++ b/openbsd-compat/bsd-openpty.c
@@ -0,0 +1,203 @@
1/*
2 * Please note: this implementation of openpty() is far from complete.
3 * it is just enough for portable OpenSSH's needs.
4 */
5
6/*
7 * Copyright (c) 2004 Damien Miller <djm@mindrot.org>
8 *
9 * Permission to use, copy, modify, and distribute this software for any
10 * purpose with or without fee is hereby granted, provided that the above
11 * copyright notice and this permission notice appear in all copies.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * Author: Tatu Ylonen <ylo@cs.hut.fi>
24 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
25 * All rights reserved
26 * Allocating a pseudo-terminal, and making it the controlling tty.
27 *
28 * As far as I am concerned, the code I have written for this software
29 * can be used freely for any purpose. Any derived versions of this
30 * software must be clearly marked as such, and if the derived work is
31 * incompatible with the protocol description in the RFC file, it must be
32 * called by a name other than "ssh" or "Secure Shell".
33 */
34
35#include "includes.h"
36#if !defined(HAVE_OPENPTY)
37
38#ifdef HAVE_UTIL_H
39# include <util.h>
40#endif /* HAVE_UTIL_H */
41
42#ifdef HAVE_PTY_H
43# include <pty.h>
44#endif
45#if defined(HAVE_DEV_PTMX) && defined(HAVE_SYS_STROPTS_H)
46# include <sys/stropts.h>
47#endif
48
49#ifndef O_NOCTTY
50#define O_NOCTTY 0
51#endif
52
53int
54openpty(int *amaster, int *aslave, char *name, struct termios *termp,
55 struct winsize *winp)
56{
57#if defined(HAVE__GETPTY)
58 /*
59 * _getpty(3) exists in SGI Irix 4.x, 5.x & 6.x -- it generates more
60 * pty's automagically when needed
61 */
62 char *slave;
63
64 if ((slave = _getpty(amaster, O_RDWR, 0622, 0)) == NULL)
65 return (-1);
66
67 /* Open the slave side. */
68 if ((*aslave = open(slave, O_RDWR | O_NOCTTY)) == -1) {
69 close(*amaster);
70 return (-1);
71 }
72 return (0);
73
74#elif defined(HAVE_DEV_PTMX)
75 /*
76 * This code is used e.g. on Solaris 2.x. (Note that Solaris 2.3
77 * also has bsd-style ptys, but they simply do not work.)
78 */
79 int ptm;
80 char *pts;
81 mysig_t old_signal;
82
83 if ((ptm = open("/dev/ptmx", O_RDWR | O_NOCTTY)) == -1)
84 return (-1);
85
86 /* XXX: need to close ptm on error? */
87 old_signal = signal(SIGCHLD, SIG_DFL);
88 if (grantpt(ptm) < 0)
89 return (-1);
90 signal(SIGCHLD, old_signal);
91
92 if (unlockpt(ptm) < 0)
93 return (-1);
94
95 if ((pts = ptsname(ptm)) == NULL)
96 return (-1);
97 *amaster = ptm;
98
99 /* Open the slave side. */
100 if ((*aslave = open(pts, O_RDWR | O_NOCTTY)) == -1) {
101 close(*amaster);
102 return (-1);
103 }
104
105#ifndef HAVE_CYGWIN
106 /*
107 * Try to push the appropriate streams modules, as described
108 * in Solaris pts(7).
109 */
110 ioctl(*aslave, I_PUSH, "ptem");
111 ioctl(*aslave, I_PUSH, "ldterm");
112# ifndef __hpux
113 ioctl(*aslave, I_PUSH, "ttcompat");
114# endif /* __hpux */
115#endif /* HAVE_CYGWIN */
116
117 return (0);
118
119#elif defined(HAVE_DEV_PTS_AND_PTC)
120 /* AIX-style pty code. */
121 const char *ttname;
122
123 if ((*amaster = open("/dev/ptc", O_RDWR | O_NOCTTY)) == -1)
124 return (-1);
125 if ((ttname = ttyname(*amaster)) == NULL)
126 return (-1);
127 if ((*aslave = open(ttname, O_RDWR | O_NOCTTY)) == -1) {
128 close(*amaster);
129 return (-1);
130 }
131 return (0);
132
133#elif defined(_UNICOS)
134 char ptbuf[64], ttbuf[64];
135 int i;
136 int highpty;
137
138 highpty = 128;
139#ifdef _SC_CRAY_NPTY
140 if ((highpty = sysconf(_SC_CRAY_NPTY)) == -1)
141 highpty = 128;
142#endif /* _SC_CRAY_NPTY */
143
144 for (i = 0; i < highpty; i++) {
145 snprintf(ptbuf, sizeof(ptbuf), "/dev/pty/%03d", i);
146 snprintf(ttbuf, sizeof(ttbuf), "/dev/ttyp%03d", i);
147 if ((*amaster = open(ptbuf, O_RDWR|O_NOCTTY)) == -1)
148 continue;
149 /* Open the slave side. */
150 if ((*aslave = open(ttbuf, O_RDWR|O_NOCTTY)) == -1) {
151 close(*amaster);
152 return (-1);
153 }
154 return (0);
155 }
156 return (-1);
157
158#else
159 /* BSD-style pty code. */
160 char ptbuf[64], ttbuf[64];
161 int i;
162 const char *ptymajors = "pqrstuvwxyzabcdefghijklmno"
163 "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
164 const char *ptyminors = "0123456789abcdef";
165 int num_minors = strlen(ptyminors);
166 int num_ptys = strlen(ptymajors) * num_minors;
167 struct termios tio;
168
169 for (i = 0; i < num_ptys; i++) {
170 snprintf(ptbuf, sizeof(ptbuf), "/dev/pty%c%c",
171 ptymajors[i / num_minors], ptyminors[i % num_minors]);
172 snprintf(ttbuf, sizeof(ttbuf), "/dev/tty%c%c",
173 ptymajors[i / num_minors], ptyminors[i % num_minors]);
174
175 if ((*amaster = open(ptbuf, O_RDWR | O_NOCTTY)) == -1) {
176 /* Try SCO style naming */
177 snprintf(ptbuf, sizeof(ptbuf), "/dev/ptyp%d", i);
178 snprintf(ttbuf, sizeof(ttbuf), "/dev/ttyp%d", i);
179 if ((*amaster = open(ptbuf, O_RDWR | O_NOCTTY)) == -1)
180 continue;
181 }
182
183 /* Open the slave side. */
184 if ((*aslave = open(ttbuf, O_RDWR | O_NOCTTY)) == -1) {
185 close(*amaster);
186 return (-1);
187 }
188 /* set tty modes to a sane state for broken clients */
189 if (tcgetattr(*amaster, &tio) != -1) {
190 tio.c_lflag |= (ECHO | ISIG | ICANON);
191 tio.c_oflag |= (OPOST | ONLCR);
192 tio.c_iflag |= ICRNL;
193 tcsetattr(*amaster, TCSANOW, &tio);
194 }
195
196 return (0);
197 }
198 return (-1);
199#endif
200}
201
202#endif /* !defined(HAVE_OPENPTY) */
203
diff --git a/openbsd-compat/daemon.c b/openbsd-compat/daemon.c
index 6dd45f6a7..c0be5fff9 100644
--- a/openbsd-compat/daemon.c
+++ b/openbsd-compat/daemon.c
@@ -1,3 +1,5 @@
1/* OPENBSD ORIGINAL: lib/libc/gen/daemon.c */
2
1/*- 3/*-
2 * Copyright (c) 1990, 1993 4 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
diff --git a/openbsd-compat/dirname.c b/openbsd-compat/dirname.c
index 1ab7516d8..25ab34dd6 100644
--- a/openbsd-compat/dirname.c
+++ b/openbsd-compat/dirname.c
@@ -1,3 +1,5 @@
1/* OPENBSD ORIGINAL: lib/libc/gen/dirname.c */
2
1/* $OpenBSD: dirname.c,v 1.10 2003/06/17 21:56:23 millert Exp $ */ 3/* $OpenBSD: dirname.c,v 1.10 2003/06/17 21:56:23 millert Exp $ */
2 4
3/* 5/*
diff --git a/openbsd-compat/fake-rfc2553.c b/openbsd-compat/fake-rfc2553.c
index b0cc69bd7..0186b5300 100644
--- a/openbsd-compat/fake-rfc2553.c
+++ b/openbsd-compat/fake-rfc2553.c
@@ -37,7 +37,7 @@
37 37
38#include "includes.h" 38#include "includes.h"
39 39
40RCSID("$Id: fake-rfc2553.c,v 1.4.2.1 2003/09/22 02:09:18 dtucker Exp $"); 40RCSID("$Id: fake-rfc2553.c,v 1.5 2003/09/22 02:08:23 dtucker Exp $");
41 41
42#ifndef HAVE_GETNAMEINFO 42#ifndef HAVE_GETNAMEINFO
43int getnameinfo(const struct sockaddr *sa, size_t salen, char *host, 43int getnameinfo(const struct sockaddr *sa, size_t salen, char *host,
diff --git a/openbsd-compat/fake-rfc2553.h b/openbsd-compat/fake-rfc2553.h
index 2d5439296..eb88605fa 100644
--- a/openbsd-compat/fake-rfc2553.h
+++ b/openbsd-compat/fake-rfc2553.h
@@ -1,4 +1,4 @@
1/* $Id: fake-rfc2553.h,v 1.6.2.1 2003/09/22 02:09:18 dtucker Exp $ */ 1/* $Id: fake-rfc2553.h,v 1.8 2004/02/10 02:05:41 dtucker Exp $ */
2 2
3/* 3/*
4 * Copyright (C) 2000-2003 Damien Miller. All rights reserved. 4 * Copyright (C) 2000-2003 Damien Miller. All rights reserved.
@@ -133,19 +133,23 @@ struct addrinfo {
133#endif /* !HAVE_STRUCT_ADDRINFO */ 133#endif /* !HAVE_STRUCT_ADDRINFO */
134 134
135#ifndef HAVE_GETADDRINFO 135#ifndef HAVE_GETADDRINFO
136#define getaddrinfo(a,b,c,d) (ssh_getaddrinfo(a,b,c,d))
136int getaddrinfo(const char *, const char *, 137int getaddrinfo(const char *, const char *,
137 const struct addrinfo *, struct addrinfo **); 138 const struct addrinfo *, struct addrinfo **);
138#endif /* !HAVE_GETADDRINFO */ 139#endif /* !HAVE_GETADDRINFO */
139 140
140#if !defined(HAVE_GAI_STRERROR) && !defined(HAVE_CONST_GAI_STRERROR_PROTO) 141#if !defined(HAVE_GAI_STRERROR) && !defined(HAVE_CONST_GAI_STRERROR_PROTO)
142#define gai_strerror(a) (ssh_gai_strerror(a))
141char *gai_strerror(int); 143char *gai_strerror(int);
142#endif /* !HAVE_GAI_STRERROR */ 144#endif /* !HAVE_GAI_STRERROR */
143 145
144#ifndef HAVE_FREEADDRINFO 146#ifndef HAVE_FREEADDRINFO
147#define freeaddrinfo(a) (ssh_freeaddrinfo(a))
145void freeaddrinfo(struct addrinfo *); 148void freeaddrinfo(struct addrinfo *);
146#endif /* !HAVE_FREEADDRINFO */ 149#endif /* !HAVE_FREEADDRINFO */
147 150
148#ifndef HAVE_GETNAMEINFO 151#ifndef HAVE_GETNAMEINFO
152#define getnameinfo(a,b,c,d,e,f,g) (ssh_getnameinfo(a,b,c,d,e,f,g))
149int getnameinfo(const struct sockaddr *, size_t, char *, size_t, 153int getnameinfo(const struct sockaddr *, size_t, char *, size_t,
150 char *, size_t, int); 154 char *, size_t, int);
151#endif /* !HAVE_GETNAMEINFO */ 155#endif /* !HAVE_GETNAMEINFO */
diff --git a/openbsd-compat/getcwd.c b/openbsd-compat/getcwd.c
index 31d1cfe93..19be59172 100644
--- a/openbsd-compat/getcwd.c
+++ b/openbsd-compat/getcwd.c
@@ -1,3 +1,5 @@
1/* OPENBSD ORIGINAL: lib/libc/gen/getcwd.c */
2
1/* 3/*
2 * Copyright (c) 1989, 1991, 1993 4 * Copyright (c) 1989, 1991, 1993
3 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
diff --git a/openbsd-compat/getgrouplist.c b/openbsd-compat/getgrouplist.c
index 085cda8c3..59c164f44 100644
--- a/openbsd-compat/getgrouplist.c
+++ b/openbsd-compat/getgrouplist.c
@@ -1,3 +1,5 @@
1/* OPENBSD ORIGINAL: lib/libc/gen/getgrouplist.c */
2
1/* 3/*
2 * Copyright (c) 1991, 1993 4 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
diff --git a/openbsd-compat/getopt.c b/openbsd-compat/getopt.c
index 2136fbfcc..f5ee6778d 100644
--- a/openbsd-compat/getopt.c
+++ b/openbsd-compat/getopt.c
@@ -1,3 +1,5 @@
1/* OPENBSD ORIGINAL: lib/libc/stdlib/getopt.c */
2
1/* 3/*
2 * Copyright (c) 1987, 1993, 1994 4 * Copyright (c) 1987, 1993, 1994
3 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
diff --git a/openbsd-compat/getrrsetbyname.c b/openbsd-compat/getrrsetbyname.c
index 44fa2755b..66d18142e 100644
--- a/openbsd-compat/getrrsetbyname.c
+++ b/openbsd-compat/getrrsetbyname.c
@@ -1,3 +1,5 @@
1/* OPENBSD ORIGINAL: lib/libc/net/getrrsetbyname.c */
2
1/* $OpenBSD: getrrsetbyname.c,v 1.7 2003/03/07 07:34:14 itojun Exp $ */ 3/* $OpenBSD: getrrsetbyname.c,v 1.7 2003/03/07 07:34:14 itojun Exp $ */
2 4
3/* 5/*
@@ -45,12 +47,10 @@
45 47
46#include "includes.h" 48#include "includes.h"
47 49
48#if defined(DNS) && !defined(HAVE_GETRRSETBYNAME) 50#ifndef HAVE_GETRRSETBYNAME
49 51
50#include "getrrsetbyname.h" 52#include "getrrsetbyname.h"
51 53
52/* #include "thread_private.h" */
53
54#define ANSWER_BUFFER_SIZE 1024*64 54#define ANSWER_BUFFER_SIZE 1024*64
55 55
56struct dns_query { 56struct dns_query {
@@ -159,7 +159,6 @@ getrrsetbyname(const char *hostname, unsigned int rdclass,
159 unsigned int rdtype, unsigned int flags, 159 unsigned int rdtype, unsigned int flags,
160 struct rrsetinfo **res) 160 struct rrsetinfo **res)
161{ 161{
162 struct __res_state *_resp = &_res;
163 int result; 162 int result;
164 struct rrsetinfo *rrset = NULL; 163 struct rrsetinfo *rrset = NULL;
165 struct dns_response *response; 164 struct dns_response *response;
@@ -188,19 +187,19 @@ getrrsetbyname(const char *hostname, unsigned int rdclass,
188 } 187 }
189 188
190 /* initialize resolver */ 189 /* initialize resolver */
191 if ((_resp->options & RES_INIT) == 0 && res_init() == -1) { 190 if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
192 result = ERRSET_FAIL; 191 result = ERRSET_FAIL;
193 goto fail; 192 goto fail;
194 } 193 }
195 194
196#ifdef DEBUG 195#ifdef DEBUG
197 _resp->options |= RES_DEBUG; 196 _res.options |= RES_DEBUG;
198#endif /* DEBUG */ 197#endif /* DEBUG */
199 198
200#ifdef RES_USE_DNSSEC 199#ifdef RES_USE_DNSSEC
201 /* turn on DNSSEC if EDNS0 is configured */ 200 /* turn on DNSSEC if EDNS0 is configured */
202 if (_resp->options & RES_USE_EDNS0) 201 if (_res.options & RES_USE_EDNS0)
203 _resp->options |= RES_USE_DNSSEC; 202 _res.options |= RES_USE_DNSSEC;
204#endif /* RES_USE_DNSEC */ 203#endif /* RES_USE_DNSEC */
205 204
206 /* make query */ 205 /* make query */
@@ -575,4 +574,4 @@ count_dns_rr(struct dns_rr *p, u_int16_t class, u_int16_t type)
575 return (n); 574 return (n);
576} 575}
577 576
578#endif /* defined(DNS) && !defined(HAVE_GETRRSETBYNAME) */ 577#endif /* !defined(HAVE_GETRRSETBYNAME) */
diff --git a/openbsd-compat/getrrsetbyname.h b/openbsd-compat/getrrsetbyname.h
index 6466a54d6..39995b63f 100644
--- a/openbsd-compat/getrrsetbyname.h
+++ b/openbsd-compat/getrrsetbyname.h
@@ -1,3 +1,5 @@
1/* OPENBSD BASED ON : include/netdb.h */
2
1/* $OpenBSD: getrrsetbyname.c,v 1.4 2001/08/16 18:16:43 ho Exp $ */ 3/* $OpenBSD: getrrsetbyname.c,v 1.4 2001/08/16 18:16:43 ho Exp $ */
2 4
3/* 5/*
@@ -48,7 +50,7 @@
48 50
49#include "includes.h" 51#include "includes.h"
50 52
51#if defined(DNS) && !defined(HAVE_GETRRSETBYNAME) 53#ifndef HAVE_GETRRSETBYNAME
52 54
53#include <sys/types.h> 55#include <sys/types.h>
54#include <netinet/in.h> 56#include <netinet/in.h>
@@ -56,6 +58,14 @@
56#include <netdb.h> 58#include <netdb.h>
57#include <resolv.h> 59#include <resolv.h>
58 60
61#ifndef HFIXEDSZ
62#define HFIXEDSZ 12
63#endif
64
65#ifndef T_SIG
66#define T_SIG 24
67#endif
68
59/* 69/*
60 * Flags for getrrsetbyname() 70 * Flags for getrrsetbyname()
61 */ 71 */
@@ -95,6 +105,6 @@ struct rrsetinfo {
95int getrrsetbyname(const char *, unsigned int, unsigned int, unsigned int, struct rrsetinfo **); 105int getrrsetbyname(const char *, unsigned int, unsigned int, unsigned int, struct rrsetinfo **);
96void freerrset(struct rrsetinfo *); 106void freerrset(struct rrsetinfo *);
97 107
98#endif /* defined(DNS) && !defined(HAVE_GETRRSETBYNAME) */ 108#endif /* !defined(HAVE_GETRRSETBYNAME) */
99 109
100#endif /* _GETRRSETBYNAME_H */ 110#endif /* _GETRRSETBYNAME_H */
diff --git a/openbsd-compat/glob.c b/openbsd-compat/glob.c
index 50f35c304..7fafc8c40 100644
--- a/openbsd-compat/glob.c
+++ b/openbsd-compat/glob.c
@@ -1,3 +1,5 @@
1/* OPENBSD ORIGINAL: lib/libc/gen/glob.c */
2
1/* 3/*
2 * Copyright (c) 1989, 1993 4 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
diff --git a/openbsd-compat/glob.h b/openbsd-compat/glob.h
index aceddbc48..3428b2013 100644
--- a/openbsd-compat/glob.h
+++ b/openbsd-compat/glob.h
@@ -1,3 +1,5 @@
1/* OPENBSD ORIGINAL: include/glob.h */
2
1/* $OpenBSD: glob.h,v 1.8 2003/06/02 19:34:12 millert Exp $ */ 3/* $OpenBSD: glob.h,v 1.8 2003/06/02 19:34:12 millert Exp $ */
2/* $NetBSD: glob.h,v 1.5 1994/10/26 00:55:56 cgd Exp $ */ 4/* $NetBSD: glob.h,v 1.5 1994/10/26 00:55:56 cgd Exp $ */
3 5
diff --git a/openbsd-compat/inet_aton.c b/openbsd-compat/inet_aton.c
index 5de49868d..c141bcc68 100644
--- a/openbsd-compat/inet_aton.c
+++ b/openbsd-compat/inet_aton.c
@@ -1,3 +1,5 @@
1/* OPENBSD ORIGINAL: lib/libc/net/inet_addr.c */
2
1/* $OpenBSD: inet_addr.c,v 1.7 2003/06/02 20:18:35 millert Exp $ */ 3/* $OpenBSD: inet_addr.c,v 1.7 2003/06/02 20:18:35 millert Exp $ */
2 4
3/* 5/*
diff --git a/openbsd-compat/inet_ntoa.c b/openbsd-compat/inet_ntoa.c
index f9fdc9ee5..dc010dc53 100644
--- a/openbsd-compat/inet_ntoa.c
+++ b/openbsd-compat/inet_ntoa.c
@@ -1,3 +1,5 @@
1/* OPENBSD ORIGINAL: lib/libc/net/inet_ntoa.c */
2
1/* 3/*
2 * Copyright (c) 1983, 1993 4 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
diff --git a/openbsd-compat/inet_ntop.c b/openbsd-compat/inet_ntop.c
index 075eac44f..7031625b4 100644
--- a/openbsd-compat/inet_ntop.c
+++ b/openbsd-compat/inet_ntop.c
@@ -1,3 +1,5 @@
1/* OPENBSD ORIGINAL: lib/libc/net/inet_ntop.c */
2
1/* $OpenBSD: inet_ntop.c,v 1.5 2002/08/23 16:27:31 itojun Exp $ */ 3/* $OpenBSD: inet_ntop.c,v 1.5 2002/08/23 16:27:31 itojun Exp $ */
2 4
3/* Copyright (c) 1996 by Internet Software Consortium. 5/* Copyright (c) 1996 by Internet Software Consortium.
diff --git a/openbsd-compat/mktemp.c b/openbsd-compat/mktemp.c
index 2cd747835..aff8d2005 100644
--- a/openbsd-compat/mktemp.c
+++ b/openbsd-compat/mktemp.c
@@ -1,3 +1,5 @@
1/* OPENBSD ORIGINAL: lib/libc/stdio/mktemp.c */
2
1/* THIS FILE HAS BEEN MODIFIED FROM THE ORIGINAL OPENBSD SOURCE */ 3/* THIS FILE HAS BEEN MODIFIED FROM THE ORIGINAL OPENBSD SOURCE */
2/* Changes: Removed mktemp */ 4/* Changes: Removed mktemp */
3 5
diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h
index 852948c54..6be1bcda4 100644
--- a/openbsd-compat/openbsd-compat.h
+++ b/openbsd-compat/openbsd-compat.h
@@ -1,4 +1,4 @@
1/* $Id: openbsd-compat.h,v 1.24 2003/08/29 16:59:52 mouring Exp $ */ 1/* $Id: openbsd-compat.h,v 1.25 2004/01/21 06:07:23 djm Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1999-2003 Damien Miller. All rights reserved. 4 * Copyright (c) 1999-2003 Damien Miller. All rights reserved.
@@ -138,8 +138,9 @@ unsigned int arc4random(void);
138void arc4random_stir(void); 138void arc4random_stir(void);
139#endif /* !HAVE_ARC4RANDOM */ 139#endif /* !HAVE_ARC4RANDOM */
140 140
141 141#ifndef HAVE_OPENPTY
142 142int openpty(int *, int *, char *, struct termios *, struct winsize *);
143#endif /* HAVE_OPENPTY */
143 144
144/* #include <sys/types.h> XXX needed? For size_t */ 145/* #include <sys/types.h> XXX needed? For size_t */
145 146
diff --git a/openbsd-compat/port-aix.c b/openbsd-compat/port-aix.c
index 9fbcce936..2895f0d44 100644
--- a/openbsd-compat/port-aix.c
+++ b/openbsd-compat/port-aix.c
@@ -24,11 +24,13 @@
24 * 24 *
25 */ 25 */
26#include "includes.h" 26#include "includes.h"
27#include "auth.h"
27#include "ssh.h" 28#include "ssh.h"
28#include "log.h" 29#include "log.h"
29#include "servconf.h" 30#include "servconf.h"
30#include "canohost.h" 31#include "canohost.h"
31#include "xmalloc.h" 32#include "xmalloc.h"
33#include "buffer.h"
32 34
33#ifdef _AIX 35#ifdef _AIX
34 36
@@ -36,6 +38,11 @@
36#include "port-aix.h" 38#include "port-aix.h"
37 39
38extern ServerOptions options; 40extern ServerOptions options;
41extern Buffer loginmsg;
42
43# ifdef HAVE_SETAUTHDB
44static char old_registry[REGISTRY_SIZE] = "";
45# endif
39 46
40/* 47/*
41 * AIX has a "usrinfo" area where logname and other stuff is stored - 48 * AIX has a "usrinfo" area where logname and other stuff is stored -
@@ -63,7 +70,7 @@ aix_usrinfo(struct passwd *pw)
63 xfree(cp); 70 xfree(cp);
64} 71}
65 72
66#ifdef WITH_AIXAUTHENTICATE 73# ifdef WITH_AIXAUTHENTICATE
67/* 74/*
68 * Remove embedded newlines in string (if any). 75 * Remove embedded newlines in string (if any).
69 * Used before logging messages returned by AIX authentication functions 76 * Used before logging messages returned by AIX authentication functions
@@ -83,41 +90,113 @@ aix_remove_embedded_newlines(char *p)
83 if (*--p == ' ') 90 if (*--p == ' ')
84 *p = '\0'; 91 *p = '\0';
85} 92}
86#endif /* WITH_AIXAUTHENTICATE */ 93
94/*
95 * Do authentication via AIX's authenticate routine. We loop until the
96 * reenter parameter is 0, but normally authenticate is called only once.
97 *
98 * Note: this function returns 1 on success, whereas AIX's authenticate()
99 * returns 0.
100 */
101int
102sys_auth_passwd(Authctxt *ctxt, const char *password)
103{
104 char *authmsg = NULL, *host, *msg, *name = ctxt->pw->pw_name;
105 int authsuccess = 0, expired, reenter, result;
106
107 do {
108 result = authenticate((char *)name, (char *)password, &reenter,
109 &authmsg);
110 aix_remove_embedded_newlines(authmsg);
111 debug3("AIX/authenticate result %d, msg %.100s", result,
112 authmsg);
113 } while (reenter);
114
115 if (result == 0) {
116 authsuccess = 1;
117
118 host = (char *)get_canonical_hostname(options.use_dns);
119
120 /*
121 * Record successful login. We don't have a pty yet, so just
122 * label the line as "ssh"
123 */
124 aix_setauthdb(name);
125 if (loginsuccess((char *)name, (char *)host, "ssh", &msg) == 0) {
126 if (msg != NULL) {
127 debug("%s: msg %s", __func__, msg);
128 buffer_append(&loginmsg, msg, strlen(msg));
129 xfree(msg);
130 }
131 }
132
133 /*
134 * Check if the user's password is expired.
135 */
136 expired = passwdexpired(name, &msg);
137 if (msg && *msg) {
138 buffer_append(&loginmsg, msg, strlen(msg));
139 aix_remove_embedded_newlines(msg);
140 }
141 debug3("AIX/passwdexpired returned %d msg %.100s", expired, msg);
142
143 switch (expired) {
144 case 0: /* password not expired */
145 break;
146 case 1: /* expired, password change required */
147 ctxt->force_pwchange = 1;
148 disable_forwarding();
149 break;
150 default: /* user can't change(2) or other error (-1) */
151 logit("Password can't be changed for user %s: %.100s",
152 name, msg);
153 if (msg)
154 xfree(msg);
155 authsuccess = 0;
156 }
157
158 aix_restoreauthdb();
159 }
160
161 if (authmsg != NULL)
162 xfree(authmsg);
163
164 return authsuccess;
165}
87 166
88# ifdef CUSTOM_FAILED_LOGIN 167# ifdef CUSTOM_FAILED_LOGIN
89/* 168/*
90 * record_failed_login: generic "login failed" interface function 169 * record_failed_login: generic "login failed" interface function
91 */ 170 */
92void 171void
93record_failed_login(const char *user, const char *ttyname) 172record_failed_login(const char *user, const char *ttyname)
94{ 173{
95 char *hostname = get_canonical_hostname(options.use_dns); 174 char *hostname = (char *)get_canonical_hostname(options.use_dns);
96 175
97 if (geteuid() != 0) 176 if (geteuid() != 0)
98 return; 177 return;
99 178
100 aix_setauthdb(user); 179 aix_setauthdb(user);
101# ifdef AIX_LOGINFAILED_4ARG 180# ifdef AIX_LOGINFAILED_4ARG
102 loginfailed((char *)user, hostname, (char *)ttyname, AUDIT_FAIL_AUTH); 181 loginfailed((char *)user, hostname, (char *)ttyname, AUDIT_FAIL_AUTH);
103# else 182# else
104 loginfailed((char *)user, hostname, (char *)ttyname); 183 loginfailed((char *)user, hostname, (char *)ttyname);
105# endif 184# endif
185 aix_restoreauthdb();
106} 186}
187# endif /* CUSTOM_FAILED_LOGIN */
107 188
108/* 189/*
109 * If we have setauthdb, retrieve the password registry for the user's 190 * If we have setauthdb, retrieve the password registry for the user's
110 * account then feed it to setauthdb. This may load registry-specific method 191 * account then feed it to setauthdb. This will mean that subsequent AIX auth
111 * code. If we don't have setauthdb or have already called it this is a no-op. 192 * functions will only use the specified loadable module. If we don't have
193 * setauthdb this is a no-op.
112 */ 194 */
113void 195void
114aix_setauthdb(const char *user) 196aix_setauthdb(const char *user)
115{ 197{
116# ifdef HAVE_SETAUTHDB 198# ifdef HAVE_SETAUTHDB
117 static char *registry = NULL; 199 char *registry;
118
119 if (registry != NULL) /* have already done setauthdb */
120 return;
121 200
122 if (setuserdb(S_READ) == -1) { 201 if (setuserdb(S_READ) == -1) {
123 debug3("%s: Could not open userdb to read", __func__); 202 debug3("%s: Could not open userdb to read", __func__);
@@ -125,18 +204,37 @@ aix_setauthdb(const char *user)
125 } 204 }
126 205
127 if (getuserattr((char *)user, S_REGISTRY, &registry, SEC_CHAR) == 0) { 206 if (getuserattr((char *)user, S_REGISTRY, &registry, SEC_CHAR) == 0) {
128 if (setauthdb(registry, NULL) == 0) 207 if (setauthdb(registry, old_registry) == 0)
129 debug3("%s: AIX/setauthdb set registry %s", __func__, 208 debug3("AIX/setauthdb set registry '%s'", registry);
130 registry);
131 else 209 else
132 debug3("%s: AIX/setauthdb set registry %s failed: %s", 210 debug3("AIX/setauthdb set registry '%s' failed: %s",
133 __func__, registry, strerror(errno)); 211 registry, strerror(errno));
134 } else 212 } else
135 debug3("%s: Could not read S_REGISTRY for user: %s", __func__, 213 debug3("%s: Could not read S_REGISTRY for user: %s", __func__,
136 strerror(errno)); 214 strerror(errno));
137 enduserdb(); 215 enduserdb();
138# endif 216# endif /* HAVE_SETAUTHDB */
139} 217}
140# endif /* CUSTOM_FAILED_LOGIN */
141#endif /* _AIX */
142 218
219/*
220 * Restore the user's registry settings from old_registry.
221 * Note that if the first aix_setauthdb fails, setauthdb("") is still safe
222 * (it restores the system default behaviour). If we don't have setauthdb,
223 * this is a no-op.
224 */
225void
226aix_restoreauthdb(void)
227{
228# ifdef HAVE_SETAUTHDB
229 if (setauthdb(old_registry, NULL) == 0)
230 debug3("%s: restoring old registry '%s'", __func__,
231 old_registry);
232 else
233 debug3("%s: failed to restore old registry %s", __func__,
234 old_registry);
235# endif /* HAVE_SETAUTHDB */
236}
237
238# endif /* WITH_AIXAUTHENTICATE */
239
240#endif /* _AIX */
diff --git a/openbsd-compat/port-aix.h b/openbsd-compat/port-aix.h
index 94c8c5119..3118af9a9 100644
--- a/openbsd-compat/port-aix.h
+++ b/openbsd-compat/port-aix.h
@@ -1,4 +1,4 @@
1/* $Id: port-aix.h,v 1.14.2.1 2003/09/19 10:46:22 dtucker Exp $ */ 1/* $Id: port-aix.h,v 1.19 2004/02/10 04:27:35 dtucker Exp $ */
2 2
3/* 3/*
4 * 4 *
@@ -51,12 +51,23 @@
51# include <sys/timers.h> 51# include <sys/timers.h>
52#endif 52#endif
53 53
54/*
55 * According to the setauthdb man page, AIX password registries must be 15
56 * chars or less plus terminating NUL.
57 */
58#ifdef HAVE_SETAUTHDB
59# define REGISTRY_SIZE 16
60#endif
61
62void aix_usrinfo(struct passwd *);
63
54#ifdef WITH_AIXAUTHENTICATE 64#ifdef WITH_AIXAUTHENTICATE
65# define CUSTOM_SYS_AUTH_PASSWD 1
55# define CUSTOM_FAILED_LOGIN 1 66# define CUSTOM_FAILED_LOGIN 1
56void record_failed_login(const char *, const char *); 67void record_failed_login(const char *, const char *);
57void aix_setauthdb(const char *);
58#endif 68#endif
59 69
60void aix_usrinfo(struct passwd *); 70void aix_setauthdb(const char *);
71void aix_restoreauthdb(void);
61void aix_remove_embedded_newlines(char *); 72void aix_remove_embedded_newlines(char *);
62#endif /* _AIX */ 73#endif /* _AIX */
diff --git a/openbsd-compat/readpassphrase.c b/openbsd-compat/readpassphrase.c
index 0d0baf569..4ee1be5de 100644
--- a/openbsd-compat/readpassphrase.c
+++ b/openbsd-compat/readpassphrase.c
@@ -1,3 +1,5 @@
1/* OPENBSD ORIGINAL: lib/libc/gen/readpassphrase.c */
2
1/* $OpenBSD: readpassphrase.c,v 1.16 2003/06/17 21:56:23 millert Exp $ */ 3/* $OpenBSD: readpassphrase.c,v 1.16 2003/06/17 21:56:23 millert Exp $ */
2 4
3/* 5/*
diff --git a/openbsd-compat/readpassphrase.h b/openbsd-compat/readpassphrase.h
index 92908a489..178edf346 100644
--- a/openbsd-compat/readpassphrase.h
+++ b/openbsd-compat/readpassphrase.h
@@ -1,3 +1,5 @@
1/* OPENBSD ORIGINAL: include/readpassphrase.h */
2
1/* $OpenBSD: readpassphrase.h,v 1.3 2002/06/28 12:32:22 millert Exp $ */ 3/* $OpenBSD: readpassphrase.h,v 1.3 2002/06/28 12:32:22 millert Exp $ */
2 4
3/* 5/*
diff --git a/openbsd-compat/realpath.c b/openbsd-compat/realpath.c
index 77da14e7c..218fbecb2 100644
--- a/openbsd-compat/realpath.c
+++ b/openbsd-compat/realpath.c
@@ -1,3 +1,5 @@
1/* OPENBSD ORIGINAL: lib/libc/stdlib/realpath.c */
2
1/* 3/*
2 * Copyright (c) 1994 4 * Copyright (c) 1994
3 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
@@ -150,7 +152,7 @@ loop:
150 serrno = ENAMETOOLONG; 152 serrno = ENAMETOOLONG;
151 goto err1; 153 goto err1;
152 } 154 }
153 if (needslash == 0) 155 if (needslash)
154 strlcat(resolved, "/", MAXPATHLEN); 156 strlcat(resolved, "/", MAXPATHLEN);
155 strlcat(resolved, wbuf, MAXPATHLEN); 157 strlcat(resolved, wbuf, MAXPATHLEN);
156 } 158 }
diff --git a/openbsd-compat/rresvport.c b/openbsd-compat/rresvport.c
index 608a3b184..75167065c 100644
--- a/openbsd-compat/rresvport.c
+++ b/openbsd-compat/rresvport.c
@@ -1,3 +1,5 @@
1/* OPENBSD ORIGINAL: lib/libc/net/rresvport.c */
2
1/* 3/*
2 * Copyright (c) 1995, 1996, 1998 Theo de Raadt. All rights reserved. 4 * Copyright (c) 1995, 1996, 1998 Theo de Raadt. All rights reserved.
3 * Copyright (c) 1983, 1993, 1994 5 * Copyright (c) 1983, 1993, 1994
diff --git a/openbsd-compat/setenv.c b/openbsd-compat/setenv.c
index c9941c195..b7ba0ce83 100644
--- a/openbsd-compat/setenv.c
+++ b/openbsd-compat/setenv.c
@@ -1,3 +1,5 @@
1/* OPENBSD ORIGINAL: lib/libc/stdlib/setenv.c */
2
1/* 3/*
2 * Copyright (c) 1987 Regents of the University of California. 4 * Copyright (c) 1987 Regents of the University of California.
3 * All rights reserved. 5 * All rights reserved.
diff --git a/openbsd-compat/setproctitle.c b/openbsd-compat/setproctitle.c
index b41100fc6..6e2b19bb4 100644
--- a/openbsd-compat/setproctitle.c
+++ b/openbsd-compat/setproctitle.c
@@ -41,8 +41,8 @@
41#endif 41#endif
42 42
43#define SPT_NONE 0 /* don't use it at all */ 43#define SPT_NONE 0 /* don't use it at all */
44#define SPT_PSTAT 1 /* cover argv with title information */ 44#define SPT_PSTAT 1 /* use pstat(PSTAT_SETCMD, ...) */
45#define SPT_REUSEARGV 2 /* use pstat(PSTAT_SETCMD, ...) */ 45#define SPT_REUSEARGV 2 /* cover argv with title information */
46 46
47#ifndef SPT_TYPE 47#ifndef SPT_TYPE
48# define SPT_TYPE SPT_NONE 48# define SPT_TYPE SPT_NONE
diff --git a/openbsd-compat/sigact.c b/openbsd-compat/sigact.c
index 35fbab0eb..2772ac574 100644
--- a/openbsd-compat/sigact.c
+++ b/openbsd-compat/sigact.c
@@ -1,3 +1,5 @@
1/* OPENBSD ORIGINAL: lib/libcurses/base/sigaction.c */
2
1/* $OpenBSD: sigaction.c,v 1.3 1999/06/27 08:14:21 millert Exp $ */ 3/* $OpenBSD: sigaction.c,v 1.3 1999/06/27 08:14:21 millert Exp $ */
2 4
3/**************************************************************************** 5/****************************************************************************
diff --git a/openbsd-compat/strlcat.c b/openbsd-compat/strlcat.c
index cae16657c..70f01cb2a 100644
--- a/openbsd-compat/strlcat.c
+++ b/openbsd-compat/strlcat.c
@@ -1,3 +1,5 @@
1/* OPENBSD ORIGINAL: lib/libc/string/strlcat.c */
2
1/* $OpenBSD: strlcat.c,v 1.11 2003/06/17 21:56:24 millert Exp $ */ 3/* $OpenBSD: strlcat.c,v 1.11 2003/06/17 21:56:24 millert Exp $ */
2 4
3/* 5/*
diff --git a/openbsd-compat/strlcpy.c b/openbsd-compat/strlcpy.c
index c8fe29987..ccfa12a0a 100644
--- a/openbsd-compat/strlcpy.c
+++ b/openbsd-compat/strlcpy.c
@@ -1,3 +1,5 @@
1/* OPENBSD ORIGINAL: lib/libc/string/strlcpy.c */
2
1/* $OpenBSD: strlcpy.c,v 1.8 2003/06/17 21:56:24 millert Exp $ */ 3/* $OpenBSD: strlcpy.c,v 1.8 2003/06/17 21:56:24 millert Exp $ */
2 4
3/* 5/*
diff --git a/openbsd-compat/strmode.c b/openbsd-compat/strmode.c
index adf5e273e..ea8d515e3 100644
--- a/openbsd-compat/strmode.c
+++ b/openbsd-compat/strmode.c
@@ -1,3 +1,5 @@
1/* OPENBSD ORIGINAL: lib/libc/string/strmode.c */
2
1/*- 3/*-
2 * Copyright (c) 1990 The Regents of the University of California. 4 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved. 5 * All rights reserved.
diff --git a/openbsd-compat/strsep.c b/openbsd-compat/strsep.c
index b13671343..330d84ce1 100644
--- a/openbsd-compat/strsep.c
+++ b/openbsd-compat/strsep.c
@@ -1,3 +1,5 @@
1/* OPENBSD ORIGINAL: lib/libc/string/strsep.c */
2
1/* $OpenBSD: strsep.c,v 1.5 2003/06/11 21:08:16 deraadt Exp $ */ 3/* $OpenBSD: strsep.c,v 1.5 2003/06/11 21:08:16 deraadt Exp $ */
2 4
3/*- 5/*-
diff --git a/openbsd-compat/strtoul.c b/openbsd-compat/strtoul.c
new file mode 100644
index 000000000..24d0e253d
--- /dev/null
+++ b/openbsd-compat/strtoul.c
@@ -0,0 +1,114 @@
1/* OPENBSD ORIGINAL: lib/libc/stdlib/strtoul.c */
2
3/*
4 * Copyright (c) 1990 Regents of the University of California.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include "includes.h"
33#ifndef HAVE_STRTOUL
34
35#if defined(LIBC_SCCS) && !defined(lint)
36static char *rcsid = "$OpenBSD: strtoul.c,v 1.5 2003/06/02 20:18:38 millert Exp $";
37#endif /* LIBC_SCCS and not lint */
38
39#include <ctype.h>
40#include <errno.h>
41#include <limits.h>
42#include <stdlib.h>
43
44/*
45 * Convert a string to an unsigned long integer.
46 *
47 * Ignores `locale' stuff. Assumes that the upper and lower case
48 * alphabets and digits are each contiguous.
49 */
50unsigned long
51strtoul(nptr, endptr, base)
52 const char *nptr;
53 char **endptr;
54 register int base;
55{
56 register const char *s;
57 register unsigned long acc, cutoff;
58 register int c;
59 register int neg, any, cutlim;
60
61 /*
62 * See strtol for comments as to the logic used.
63 */
64 s = nptr;
65 do {
66 c = (unsigned char) *s++;
67 } while (isspace(c));
68 if (c == '-') {
69 neg = 1;
70 c = *s++;
71 } else {
72 neg = 0;
73 if (c == '+')
74 c = *s++;
75 }
76 if ((base == 0 || base == 16) &&
77 c == '0' && (*s == 'x' || *s == 'X')) {
78 c = s[1];
79 s += 2;
80 base = 16;
81 }
82 if (base == 0)
83 base = c == '0' ? 8 : 10;
84
85 cutoff = ULONG_MAX / (unsigned long)base;
86 cutlim = ULONG_MAX % (unsigned long)base;
87 for (acc = 0, any = 0;; c = (unsigned char) *s++) {
88 if (isdigit(c))
89 c -= '0';
90 else if (isalpha(c))
91 c -= isupper(c) ? 'A' - 10 : 'a' - 10;
92 else
93 break;
94 if (c >= base)
95 break;
96 if (any < 0)
97 continue;
98 if (acc > cutoff || acc == cutoff && c > cutlim) {
99 any = -1;
100 acc = ULONG_MAX;
101 errno = ERANGE;
102 } else {
103 any = 1;
104 acc *= (unsigned long)base;
105 acc += c;
106 }
107 }
108 if (neg && any > 0)
109 acc = -acc;
110 if (endptr != 0)
111 *endptr = (char *) (any ? s - 1 : nptr);
112 return (acc);
113}
114#endif /* !HAVE_STRTOUL */
diff --git a/openbsd-compat/sys-queue.h b/openbsd-compat/sys-queue.h
index dd5c47525..8ff19e452 100644
--- a/openbsd-compat/sys-queue.h
+++ b/openbsd-compat/sys-queue.h
@@ -1,3 +1,5 @@
1/* OPENBSD ORIGINAL: sys/sys/queue.h */
2
1/* $OpenBSD: queue.h,v 1.23 2003/06/02 23:28:21 millert Exp $ */ 3/* $OpenBSD: queue.h,v 1.23 2003/06/02 23:28:21 millert Exp $ */
2/* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */ 4/* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */
3 5
diff --git a/openbsd-compat/sys-tree.h b/openbsd-compat/sys-tree.h
index 927ca04cd..73cfbe72a 100644
--- a/openbsd-compat/sys-tree.h
+++ b/openbsd-compat/sys-tree.h
@@ -1,3 +1,5 @@
1/* OPENBSD ORIGINAL: sys/sys/tree.h */
2
1/* $OpenBSD: tree.h,v 1.7 2002/10/17 21:51:54 art Exp $ */ 3/* $OpenBSD: tree.h,v 1.7 2002/10/17 21:51:54 art Exp $ */
2/* 4/*
3 * Copyright 2002 Niels Provos <provos@citi.umich.edu> 5 * Copyright 2002 Niels Provos <provos@citi.umich.edu>
diff --git a/openbsd-compat/vis.c b/openbsd-compat/vis.c
index e6a2ce98d..1fb7a01e3 100644
--- a/openbsd-compat/vis.c
+++ b/openbsd-compat/vis.c
@@ -1,3 +1,5 @@
1/* OPENBSD ORIGINAL: lib/libc/gen/vis.c */
2
1/*- 3/*-
2 * Copyright (c) 1989, 1993 4 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
diff --git a/openbsd-compat/vis.h b/openbsd-compat/vis.h
index 1c131cc85..663355a24 100644
--- a/openbsd-compat/vis.h
+++ b/openbsd-compat/vis.h
@@ -1,3 +1,5 @@
1/* OPENBSD ORIGINAL: include/vis.h */
2
1/* $OpenBSD: vis.h,v 1.6 2003/06/02 19:34:12 millert Exp $ */ 3/* $OpenBSD: vis.h,v 1.6 2003/06/02 19:34:12 millert Exp $ */
2/* $NetBSD: vis.h,v 1.4 1994/10/26 00:56:41 cgd Exp $ */ 4/* $NetBSD: vis.h,v 1.4 1994/10/26 00:56:41 cgd Exp $ */
3 5
diff --git a/openbsd-compat/xcrypt.c b/openbsd-compat/xcrypt.c
index 5b5d69c72..a0fe6c620 100644
--- a/openbsd-compat/xcrypt.c
+++ b/openbsd-compat/xcrypt.c
@@ -104,10 +104,6 @@ shadow_pw(struct passwd *pw)
104 104
105 if (spw != NULL) 105 if (spw != NULL)
106 pw_password = spw->ufld.fd_encrypt; 106 pw_password = spw->ufld.fd_encrypt;
107# elif defined(__hpux) && !defined(HAVE_SECUREWARE)
108 struct pr_passwd *spw;
109 if (iscomsec() && (spw = getprpwnam(pw->pw_name)) != NULL)
110 pw_password = spw->ufld.fd_encrypt;
111# endif 107# endif
112 108
113 return pw_password; 109 return pw_password;