summaryrefslogtreecommitdiff
path: root/openbsd-compat
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2005-05-25 11:01:01 +0000
committerColin Watson <cjwatson@debian.org>2005-05-25 11:01:01 +0000
commite88de75a1a236779a10e8ccbcc51d25308be8840 (patch)
tree7495477a2a7d0cac17a9fcded020b6ea816182ef /openbsd-compat
parent30a0f9443782cd9d7308acd09430bf586186aa55 (diff)
parent5d05471f6657646d1d6500c7c43134462c407ee6 (diff)
Merge 4.0p1 to the trunk.
Diffstat (limited to 'openbsd-compat')
-rw-r--r--openbsd-compat/bsd-arc4random.c8
-rw-r--r--openbsd-compat/bsd-cray.c4
-rw-r--r--openbsd-compat/bsd-cray.h6
-rw-r--r--openbsd-compat/bsd-cygwin_util.c54
-rw-r--r--openbsd-compat/bsd-cygwin_util.h4
-rw-r--r--openbsd-compat/bsd-misc.c13
-rw-r--r--openbsd-compat/bsd-misc.h6
-rw-r--r--openbsd-compat/bsd-openpty.c2
-rw-r--r--openbsd-compat/bsd-snprintf.c4
-rw-r--r--openbsd-compat/fake-rfc2553.h3
-rw-r--r--openbsd-compat/getrrsetbyname.c2
-rw-r--r--openbsd-compat/inet_ntop.c2
-rw-r--r--openbsd-compat/mktemp.c5
-rw-r--r--openbsd-compat/port-aix.c121
-rw-r--r--openbsd-compat/port-aix.h46
-rw-r--r--openbsd-compat/realpath.c69
-rw-r--r--openbsd-compat/xmmap.c4
17 files changed, 269 insertions, 84 deletions
diff --git a/openbsd-compat/bsd-arc4random.c b/openbsd-compat/bsd-arc4random.c
index 5284e1af8..1eeb6953b 100644
--- a/openbsd-compat/bsd-arc4random.c
+++ b/openbsd-compat/bsd-arc4random.c
@@ -17,7 +17,7 @@
17#include "includes.h" 17#include "includes.h"
18#include "log.h" 18#include "log.h"
19 19
20RCSID("$Id: bsd-arc4random.c,v 1.9 2004/07/18 23:30:40 djm Exp $"); 20RCSID("$Id: bsd-arc4random.c,v 1.10 2005/02/16 02:01:28 djm Exp $");
21 21
22#ifndef HAVE_ARC4RANDOM 22#ifndef HAVE_ARC4RANDOM
23 23
@@ -34,7 +34,8 @@ RCSID("$Id: bsd-arc4random.c,v 1.9 2004/07/18 23:30:40 djm Exp $");
34static int rc4_ready = 0; 34static int rc4_ready = 0;
35static RC4_KEY rc4; 35static RC4_KEY rc4;
36 36
37unsigned int arc4random(void) 37unsigned int
38arc4random(void)
38{ 39{
39 unsigned int r = 0; 40 unsigned int r = 0;
40 static int first_time = 1; 41 static int first_time = 1;
@@ -53,7 +54,8 @@ unsigned int arc4random(void)
53 return(r); 54 return(r);
54} 55}
55 56
56void arc4random_stir(void) 57void
58arc4random_stir(void)
57{ 59{
58 unsigned char rand_buf[SEED_SIZE]; 60 unsigned char rand_buf[SEED_SIZE];
59 int i; 61 int i;
diff --git a/openbsd-compat/bsd-cray.c b/openbsd-compat/bsd-cray.c
index f630366be..d1f1c059c 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.13 2004/01/30 03:34:22 dtucker Exp $ 2 * $Id: bsd-cray.c,v 1.14 2005/02/02 06:10:11 dtucker Exp $
3 * 3 *
4 * bsd-cray.c 4 * bsd-cray.c
5 * 5 *
@@ -171,7 +171,7 @@ cray_access_denied(char *username)
171 * record_failed_login: generic "login failed" interface function 171 * record_failed_login: generic "login failed" interface function
172 */ 172 */
173void 173void
174record_failed_login(const char *user, const char *ttyname) 174record_failed_login(const char *user, const char *hostname, const char *ttyname)
175{ 175{
176 cray_login_failure((char *)user, IA_UDBERR); 176 cray_login_failure((char *)user, IA_UDBERR);
177} 177}
diff --git a/openbsd-compat/bsd-cray.h b/openbsd-compat/bsd-cray.h
index de6ba1a8d..774eceb5a 100644
--- a/openbsd-compat/bsd-cray.h
+++ b/openbsd-compat/bsd-cray.h
@@ -1,4 +1,4 @@
1/* $Id: bsd-cray.h,v 1.11 2004/01/30 03:34:22 dtucker Exp $ */ 1/* $Id: bsd-cray.h,v 1.12 2005/02/02 06:10:11 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>)
@@ -42,10 +42,10 @@ void cray_init_job(struct passwd *);
42void cray_job_termination_handler(int); 42void cray_job_termination_handler(int);
43void cray_login_failure(char *, int ); 43void cray_login_failure(char *, int );
44int cray_access_denied(char *); 44int cray_access_denied(char *);
45#define CUSTOM_FAILED_LOGIN 1
46void record_failed_login(const char *, const char *);
47extern char cray_tmpdir[]; 45extern char cray_tmpdir[];
48 46
47#define CUSTOM_FAILED_LOGIN 1
48
49#ifndef IA_SSHD 49#ifndef IA_SSHD
50# define IA_SSHD IA_LOGIN 50# define IA_SSHD IA_LOGIN
51#endif 51#endif
diff --git a/openbsd-compat/bsd-cygwin_util.c b/openbsd-compat/bsd-cygwin_util.c
index 92cdba6e0..f53abb6e2 100644
--- a/openbsd-compat/bsd-cygwin_util.c
+++ b/openbsd-compat/bsd-cygwin_util.c
@@ -29,7 +29,7 @@
29 29
30#include "includes.h" 30#include "includes.h"
31 31
32RCSID("$Id: bsd-cygwin_util.c,v 1.12 2004/04/18 11:15:45 djm Exp $"); 32RCSID("$Id: bsd-cygwin_util.c,v 1.13 2004/08/30 10:42:08 dtucker Exp $");
33 33
34#ifdef HAVE_CYGWIN 34#ifdef HAVE_CYGWIN
35 35
@@ -38,6 +38,7 @@ RCSID("$Id: bsd-cygwin_util.c,v 1.12 2004/04/18 11:15:45 djm Exp $");
38#include <sys/utsname.h> 38#include <sys/utsname.h>
39#include <sys/vfs.h> 39#include <sys/vfs.h>
40#include <windows.h> 40#include <windows.h>
41#include "xmalloc.h"
41#define is_winnt (GetVersion() < 0x80000000) 42#define is_winnt (GetVersion() < 0x80000000)
42 43
43#define ntsec_on(c) ((c) && strstr((c),"ntsec") && !strstr((c),"nontsec")) 44#define ntsec_on(c) ((c) && strstr((c),"ntsec") && !strstr((c),"nontsec"))
@@ -96,7 +97,6 @@ has_capability(int what)
96 */ 97 */
97 if (!inited) { 98 if (!inited) {
98 struct utsname uts; 99 struct utsname uts;
99 char *c;
100 100
101 if (!uname(&uts)) { 101 if (!uname(&uts)) {
102 int major_high = 0, major_low = 0, minor = 0; 102 int major_high = 0, major_low = 0, minor = 0;
@@ -236,4 +236,54 @@ register_9x_service(void)
236 RegisterServiceProcess(0, 1); 236 RegisterServiceProcess(0, 1);
237} 237}
238 238
239#define NL(x) x, (sizeof (x) - 1)
240#define WENV_SIZ (sizeof (wenv_arr) / sizeof (wenv_arr[0]))
241
242static struct wenv {
243 const char *name;
244 size_t namelen;
245} wenv_arr[] = {
246 { NL("ALLUSERSPROFILE=") },
247 { NL("COMMONPROGRAMFILES=") },
248 { NL("COMPUTERNAME=") },
249 { NL("COMSPEC=") },
250 { NL("NUMBER_OF_PROCESSORS=") },
251 { NL("OS=") },
252 { NL("PATH=") },
253 { NL("PATHEXT=") },
254 { NL("PROCESSOR_ARCHITECTURE=") },
255 { NL("PROCESSOR_IDENTIFIER=") },
256 { NL("PROCESSOR_LEVEL=") },
257 { NL("PROCESSOR_REVISION=") },
258 { NL("PROGRAMFILES=") },
259 { NL("SYSTEMDRIVE=") },
260 { NL("SYSTEMROOT=") },
261 { NL("TMP=") },
262 { NL("TEMP=") },
263 { NL("WINDIR=") },
264};
265
266char **
267fetch_windows_environment(void)
268{
269 char **e, **p;
270 int i, idx = 0;
271
272 p = xmalloc(WENV_SIZ * sizeof(char *));
273 for (e = environ; *e != NULL; ++e) {
274 for (i = 0; i < WENV_SIZ; ++i) {
275 if (!strncmp(*e, wenv_arr[i].name, wenv_arr[i].namelen))
276 p[idx++] = *e;
277 }
278 }
279 p[idx] = NULL;
280 return p;
281}
282
283void
284free_windows_environment(char **p)
285{
286 xfree(p);
287}
288
239#endif /* HAVE_CYGWIN */ 289#endif /* HAVE_CYGWIN */
diff --git a/openbsd-compat/bsd-cygwin_util.h b/openbsd-compat/bsd-cygwin_util.h
index 5ccb0fba2..6719b8a49 100644
--- a/openbsd-compat/bsd-cygwin_util.h
+++ b/openbsd-compat/bsd-cygwin_util.h
@@ -1,4 +1,4 @@
1/* $Id: bsd-cygwin_util.h,v 1.10 2003/08/07 06:28:16 dtucker Exp $ */ 1/* $Id: bsd-cygwin_util.h,v 1.11 2004/08/30 10:42:08 dtucker Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2000, 2001, Corinna Vinschen <vinschen@cygnus.com> 4 * Copyright (c) 2000, 2001, Corinna Vinschen <vinschen@cygnus.com>
@@ -46,6 +46,8 @@ int binary_pipe(int fd[2]);
46int check_nt_auth(int, struct passwd *); 46int check_nt_auth(int, struct passwd *);
47int check_ntsec(const char *); 47int check_ntsec(const char *);
48void register_9x_service(void); 48void register_9x_service(void);
49char **fetch_windows_environment(void);
50void free_windows_environment(char **);
49 51
50#define open binary_open 52#define open binary_open
51#define pipe binary_pipe 53#define pipe binary_pipe
diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c
index 1b276b4f4..41f92cce9 100644
--- a/openbsd-compat/bsd-misc.c
+++ b/openbsd-compat/bsd-misc.c
@@ -18,7 +18,7 @@
18#include "includes.h" 18#include "includes.h"
19#include "xmalloc.h" 19#include "xmalloc.h"
20 20
21RCSID("$Id: bsd-misc.c,v 1.25 2004/08/15 08:41:00 djm Exp $"); 21RCSID("$Id: bsd-misc.c,v 1.26 2005/02/25 23:07:38 dtucker Exp $");
22 22
23#ifndef HAVE___PROGNAME 23#ifndef HAVE___PROGNAME
24char *__progname; 24char *__progname;
@@ -122,17 +122,6 @@ int truncate(const char *path, off_t length)
122} 122}
123#endif /* HAVE_TRUNCATE */ 123#endif /* HAVE_TRUNCATE */
124 124
125#if !defined(HAVE_SETGROUPS) && defined(SETGROUPS_NOOP)
126/*
127 * Cygwin setgroups should be a noop.
128 */
129int
130setgroups(size_t size, const gid_t *list)
131{
132 return (0);
133}
134#endif
135
136#if !defined(HAVE_NANOSLEEP) && !defined(HAVE_NSLEEP) 125#if !defined(HAVE_NANOSLEEP) && !defined(HAVE_NSLEEP)
137int nanosleep(const struct timespec *req, struct timespec *rem) 126int nanosleep(const struct timespec *req, struct timespec *rem)
138{ 127{
diff --git a/openbsd-compat/bsd-misc.h b/openbsd-compat/bsd-misc.h
index 33a1d707f..b61ec4244 100644
--- a/openbsd-compat/bsd-misc.h
+++ b/openbsd-compat/bsd-misc.h
@@ -1,4 +1,4 @@
1/* $Id: bsd-misc.h,v 1.17 2004/08/15 08:41:00 djm Exp $ */ 1/* $Id: bsd-misc.h,v 1.18 2005/02/25 23:07:38 dtucker Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1999-2004 Damien Miller <djm@mindrot.org> 4 * Copyright (c) 1999-2004 Damien Miller <djm@mindrot.org>
@@ -67,10 +67,6 @@ int utimes(char *, struct timeval *);
67int truncate (const char *, off_t); 67int truncate (const char *, off_t);
68#endif /* HAVE_TRUNCATE */ 68#endif /* HAVE_TRUNCATE */
69 69
70#if !defined(HAVE_SETGROUPS) && defined(SETGROUPS_NOOP)
71int setgroups(size_t, const gid_t *);
72#endif
73
74#if !defined(HAVE_NANOSLEEP) && !defined(HAVE_NSLEEP) 70#if !defined(HAVE_NANOSLEEP) && !defined(HAVE_NSLEEP)
75#ifndef HAVE_STRUCT_TIMESPEC 71#ifndef HAVE_STRUCT_TIMESPEC
76struct timespec { 72struct timespec {
diff --git a/openbsd-compat/bsd-openpty.c b/openbsd-compat/bsd-openpty.c
index daf5f8b81..8eb62b7a8 100644
--- a/openbsd-compat/bsd-openpty.c
+++ b/openbsd-compat/bsd-openpty.c
@@ -102,7 +102,6 @@ openpty(int *amaster, int *aslave, char *name, struct termios *termp,
102 return (-1); 102 return (-1);
103 } 103 }
104 104
105#ifndef HAVE_CYGWIN
106 /* 105 /*
107 * Try to push the appropriate streams modules, as described 106 * Try to push the appropriate streams modules, as described
108 * in Solaris pts(7). 107 * in Solaris pts(7).
@@ -112,7 +111,6 @@ openpty(int *amaster, int *aslave, char *name, struct termios *termp,
112# ifndef __hpux 111# ifndef __hpux
113 ioctl(*aslave, I_PUSH, "ttcompat"); 112 ioctl(*aslave, I_PUSH, "ttcompat");
114# endif /* __hpux */ 113# endif /* __hpux */
115#endif /* HAVE_CYGWIN */
116 114
117 return (0); 115 return (0);
118 116
diff --git a/openbsd-compat/bsd-snprintf.c b/openbsd-compat/bsd-snprintf.c
index e4d8a439a..b5a7ef7a0 100644
--- a/openbsd-compat/bsd-snprintf.c
+++ b/openbsd-compat/bsd-snprintf.c
@@ -58,7 +58,7 @@
58 58
59#include "includes.h" 59#include "includes.h"
60 60
61RCSID("$Id: bsd-snprintf.c,v 1.7 2003/05/18 14:13:39 djm Exp $"); 61RCSID("$Id: bsd-snprintf.c,v 1.9 2004/09/23 11:35:09 dtucker Exp $");
62 62
63#if defined(BROKEN_SNPRINTF) /* For those with broken snprintf() */ 63#if defined(BROKEN_SNPRINTF) /* For those with broken snprintf() */
64# undef HAVE_SNPRINTF 64# undef HAVE_SNPRINTF
@@ -369,7 +369,7 @@ fmtstr(char *buffer, size_t *currlen, size_t maxlen,
369 if (value == 0) 369 if (value == 0)
370 value = "<NULL>"; 370 value = "<NULL>";
371 371
372 for (strln = 0; value[strln]; ++strln); /* strlen */ 372 for (strln = 0; strln < max && value[strln]; ++strln); /* strlen */
373 padlen = min - strln; 373 padlen = min - strln;
374 if (padlen < 0) 374 if (padlen < 0)
375 padlen = 0; 375 padlen = 0;
diff --git a/openbsd-compat/fake-rfc2553.h b/openbsd-compat/fake-rfc2553.h
index baea07038..636792ed7 100644
--- a/openbsd-compat/fake-rfc2553.h
+++ b/openbsd-compat/fake-rfc2553.h
@@ -1,4 +1,4 @@
1/* $Id: fake-rfc2553.h,v 1.9 2004/03/10 10:06:33 dtucker Exp $ */ 1/* $Id: fake-rfc2553.h,v 1.10 2005/02/11 07:32:13 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.
@@ -117,6 +117,7 @@ struct sockaddr_in6 {
117# define EAI_NODATA 1 117# define EAI_NODATA 1
118# define EAI_MEMORY 2 118# define EAI_MEMORY 2
119# define EAI_NONAME 3 119# define EAI_NONAME 3
120# define EAI_SYSTEM 4
120#endif 121#endif
121 122
122#ifndef HAVE_STRUCT_ADDRINFO 123#ifndef HAVE_STRUCT_ADDRINFO
diff --git a/openbsd-compat/getrrsetbyname.c b/openbsd-compat/getrrsetbyname.c
index 660427c1f..4e869c4df 100644
--- a/openbsd-compat/getrrsetbyname.c
+++ b/openbsd-compat/getrrsetbyname.c
@@ -277,7 +277,7 @@ getrrsetbyname(const char *hostname, unsigned int rdclass,
277 277
278 /* allocate memory for signatures */ 278 /* allocate memory for signatures */
279 rrset->rri_sigs = calloc(rrset->rri_nsigs, sizeof(struct rdatainfo)); 279 rrset->rri_sigs = calloc(rrset->rri_nsigs, sizeof(struct rdatainfo));
280 if (rrset->rri_sigs == NULL) { 280 if (rrset->rri_nsigs > 0 && rrset->rri_sigs == NULL) {
281 result = ERRSET_NOMEMORY; 281 result = ERRSET_NOMEMORY;
282 goto fail; 282 goto fail;
283 } 283 }
diff --git a/openbsd-compat/inet_ntop.c b/openbsd-compat/inet_ntop.c
index 7031625b4..47796c370 100644
--- a/openbsd-compat/inet_ntop.c
+++ b/openbsd-compat/inet_ntop.c
@@ -35,9 +35,7 @@ static char rcsid[] = "$OpenBSD: inet_ntop.c,v 1.5 2002/08/23 16:27:31 itojun Ex
35#include <sys/socket.h> 35#include <sys/socket.h>
36#include <netinet/in.h> 36#include <netinet/in.h>
37#include <arpa/inet.h> 37#include <arpa/inet.h>
38#ifndef HAVE_CYGWIN
39#include <arpa/nameser.h> 38#include <arpa/nameser.h>
40#endif
41#include <string.h> 39#include <string.h>
42#include <errno.h> 40#include <errno.h>
43#include <stdio.h> 41#include <stdio.h>
diff --git a/openbsd-compat/mktemp.c b/openbsd-compat/mktemp.c
index aff8d2005..969f69580 100644
--- a/openbsd-compat/mktemp.c
+++ b/openbsd-compat/mktemp.c
@@ -40,11 +40,6 @@
40static char rcsid[] = "$OpenBSD: mktemp.c,v 1.17 2003/06/02 20:18:37 millert Exp $"; 40static char rcsid[] = "$OpenBSD: mktemp.c,v 1.17 2003/06/02 20:18:37 millert Exp $";
41#endif /* LIBC_SCCS and not lint */ 41#endif /* LIBC_SCCS and not lint */
42 42
43#ifdef HAVE_CYGWIN
44#define open binary_open
45extern int binary_open();
46#endif
47
48static int _gettemp(char *, int *, int, int); 43static int _gettemp(char *, int *, int, int);
49 44
50int 45int
diff --git a/openbsd-compat/port-aix.c b/openbsd-compat/port-aix.c
index 78f4faea3..fa6a4ff7b 100644
--- a/openbsd-compat/port-aix.c
+++ b/openbsd-compat/port-aix.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * 2 *
3 * Copyright (c) 2001 Gert Doering. All rights reserved. 3 * Copyright (c) 2001 Gert Doering. All rights reserved.
4 * Copyright (c) 2003,2004 Darren Tucker. All rights reserved.
4 * 5 *
5 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
@@ -27,19 +28,15 @@
27#include "auth.h" 28#include "auth.h"
28#include "ssh.h" 29#include "ssh.h"
29#include "log.h" 30#include "log.h"
30#include "servconf.h"
31#include "canohost.h"
32#include "xmalloc.h" 31#include "xmalloc.h"
33#include "buffer.h" 32#include "buffer.h"
34 33
35#ifdef _AIX 34#ifdef _AIX
36 35
37#include <uinfo.h> 36#include <uinfo.h>
37#include <sys/socket.h>
38#include "port-aix.h" 38#include "port-aix.h"
39 39
40extern ServerOptions options;
41extern Buffer loginmsg;
42
43# ifdef HAVE_SETAUTHDB 40# ifdef HAVE_SETAUTHDB
44static char old_registry[REGISTRY_SIZE] = ""; 41static char old_registry[REGISTRY_SIZE] = "";
45# endif 42# endif
@@ -51,6 +48,8 @@ static char old_registry[REGISTRY_SIZE] = "";
51 * NOTE: TTY= should be set, but since no one uses it and it's hard to 48 * NOTE: TTY= should be set, but since no one uses it and it's hard to
52 * acquire due to privsep code. We will just drop support. 49 * acquire due to privsep code. We will just drop support.
53 */ 50 */
51
52
54void 53void
55aix_usrinfo(struct passwd *pw) 54aix_usrinfo(struct passwd *pw)
56{ 55{
@@ -92,6 +91,59 @@ aix_remove_embedded_newlines(char *p)
92} 91}
93 92
94/* 93/*
94 * Test specifically for the case where SYSTEM == NONE and AUTH1 contains
95 * anything other than NONE or SYSTEM, which indicates that the admin has
96 * configured the account for purely AUTH1-type authentication.
97 *
98 * Since authenticate() doesn't check AUTH1, and sshd can't sanely support
99 * AUTH1 itself, in such a case authenticate() will allow access without
100 * authentation, which is almost certainly not what the admin intends.
101 *
102 * (The native tools, eg login, will process the AUTH1 list in addition to
103 * the SYSTEM list by using ckuserID(), however ckuserID() and AUTH1 methods
104 * have been deprecated since AIX 4.2.x and would be very difficult for sshd
105 * to support.
106 *
107 * Returns 0 if an unsupportable combination is found, 1 otherwise.
108 */
109static int
110aix_valid_authentications(const char *user)
111{
112 char *auth1, *sys, *p;
113 int valid = 1;
114
115 if (getuserattr((char *)user, S_AUTHSYSTEM, &sys, SEC_CHAR) != 0) {
116 logit("Can't retrieve attribute SYSTEM for %s: %.100s",
117 user, strerror(errno));
118 return 0;
119 }
120
121 debug3("AIX SYSTEM attribute %s", sys);
122 if (strcmp(sys, "NONE") != 0)
123 return 1; /* not "NONE", so is OK */
124
125 if (getuserattr((char *)user, S_AUTH1, &auth1, SEC_LIST) != 0) {
126 logit("Can't retrieve attribute auth1 for %s: %.100s",
127 user, strerror(errno));
128 return 0;
129 }
130
131 p = auth1;
132 /* A SEC_LIST is concatenated strings, ending with two NULs. */
133 while (p[0] != '\0' && p[1] != '\0') {
134 debug3("AIX auth1 attribute list member %s", p);
135 if (strcmp(p, "NONE") != 0 && strcmp(p, "SYSTEM")) {
136 logit("Account %s has unsupported auth1 value '%s'",
137 user, p);
138 valid = 0;
139 }
140 p += strlen(p) + 1;
141 }
142
143 return (valid);
144}
145
146/*
95 * Do authentication via AIX's authenticate routine. We loop until the 147 * Do authentication via AIX's authenticate routine. We loop until the
96 * reenter parameter is 0, but normally authenticate is called only once. 148 * reenter parameter is 0, but normally authenticate is called only once.
97 * 149 *
@@ -99,7 +151,7 @@ aix_remove_embedded_newlines(char *p)
99 * returns 0. 151 * returns 0.
100 */ 152 */
101int 153int
102sys_auth_passwd(Authctxt *ctxt, const char *password) 154sys_auth_passwd(Authctxt *ctxt, const char *password, Buffer *loginmsg)
103{ 155{
104 char *authmsg = NULL, *msg, *name = ctxt->pw->pw_name; 156 char *authmsg = NULL, *msg, *name = ctxt->pw->pw_name;
105 int authsuccess = 0, expired, reenter, result; 157 int authsuccess = 0, expired, reenter, result;
@@ -112,6 +164,9 @@ sys_auth_passwd(Authctxt *ctxt, const char *password)
112 authmsg); 164 authmsg);
113 } while (reenter); 165 } while (reenter);
114 166
167 if (!aix_valid_authentications(name))
168 result = -1;
169
115 if (result == 0) { 170 if (result == 0) {
116 authsuccess = 1; 171 authsuccess = 1;
117 172
@@ -126,7 +181,7 @@ sys_auth_passwd(Authctxt *ctxt, const char *password)
126 */ 181 */
127 expired = passwdexpired(name, &msg); 182 expired = passwdexpired(name, &msg);
128 if (msg && *msg) { 183 if (msg && *msg) {
129 buffer_append(&loginmsg, msg, strlen(msg)); 184 buffer_append(loginmsg, msg, strlen(msg));
130 aix_remove_embedded_newlines(msg); 185 aix_remove_embedded_newlines(msg);
131 } 186 }
132 debug3("AIX/passwdexpired returned %d msg %.100s", expired, msg); 187 debug3("AIX/passwdexpired returned %d msg %.100s", expired, msg);
@@ -136,7 +191,6 @@ sys_auth_passwd(Authctxt *ctxt, const char *password)
136 break; 191 break;
137 case 1: /* expired, password change required */ 192 case 1: /* expired, password change required */
138 ctxt->force_pwchange = 1; 193 ctxt->force_pwchange = 1;
139 disable_forwarding();
140 break; 194 break;
141 default: /* user can't change(2) or other error (-1) */ 195 default: /* user can't change(2) or other error (-1) */
142 logit("Password can't be changed for user %s: %.100s", 196 logit("Password can't be changed for user %s: %.100s",
@@ -160,7 +214,7 @@ sys_auth_passwd(Authctxt *ctxt, const char *password)
160 * Returns 1 if login is allowed, 0 if not allowed. 214 * Returns 1 if login is allowed, 0 if not allowed.
161 */ 215 */
162int 216int
163sys_auth_allowed_user(struct passwd *pw) 217sys_auth_allowed_user(struct passwd *pw, Buffer *loginmsg)
164{ 218{
165 char *msg = NULL; 219 char *msg = NULL;
166 int result, permitted = 0; 220 int result, permitted = 0;
@@ -187,7 +241,7 @@ sys_auth_allowed_user(struct passwd *pw)
187 if (result == -1 && errno == EPERM && stat(_PATH_NOLOGIN, &st) == 0) 241 if (result == -1 && errno == EPERM && stat(_PATH_NOLOGIN, &st) == 0)
188 permitted = 1; 242 permitted = 1;
189 else if (msg != NULL) 243 else if (msg != NULL)
190 buffer_append(&loginmsg, msg, strlen(msg)); 244 buffer_append(loginmsg, msg, strlen(msg));
191 if (msg == NULL) 245 if (msg == NULL)
192 msg = xstrdup("(none)"); 246 msg = xstrdup("(none)");
193 aix_remove_embedded_newlines(msg); 247 aix_remove_embedded_newlines(msg);
@@ -200,17 +254,18 @@ sys_auth_allowed_user(struct passwd *pw)
200} 254}
201 255
202int 256int
203sys_auth_record_login(const char *user, const char *host, const char *ttynm) 257sys_auth_record_login(const char *user, const char *host, const char *ttynm,
258 Buffer *loginmsg)
204{ 259{
205 char *msg; 260 char *msg;
206 int success = 0; 261 int success = 0;
207 262
208 aix_setauthdb(user); 263 aix_setauthdb(user);
209 if (loginsuccess((char *)user, host, ttynm, &msg) == 0) { 264 if (loginsuccess((char *)user, (char *)host, (char *)ttynm, &msg) == 0) {
210 success = 1; 265 success = 1;
211 if (msg != NULL) { 266 if (msg != NULL) {
212 debug("AIX/loginsuccess: msg %s", __func__, msg); 267 debug("AIX/loginsuccess: msg %s", msg);
213 buffer_append(&loginmsg, msg, strlen(msg)); 268 buffer_append(loginmsg, msg, strlen(msg));
214 xfree(msg); 269 xfree(msg);
215 } 270 }
216 } 271 }
@@ -223,18 +278,17 @@ sys_auth_record_login(const char *user, const char *host, const char *ttynm)
223 * record_failed_login: generic "login failed" interface function 278 * record_failed_login: generic "login failed" interface function
224 */ 279 */
225void 280void
226record_failed_login(const char *user, const char *ttyname) 281record_failed_login(const char *user, const char *hostname, const char *ttyname)
227{ 282{
228 char *hostname = (char *)get_canonical_hostname(options.use_dns);
229
230 if (geteuid() != 0) 283 if (geteuid() != 0)
231 return; 284 return;
232 285
233 aix_setauthdb(user); 286 aix_setauthdb(user);
234# ifdef AIX_LOGINFAILED_4ARG 287# ifdef AIX_LOGINFAILED_4ARG
235 loginfailed((char *)user, hostname, (char *)ttyname, AUDIT_FAIL_AUTH); 288 loginfailed((char *)user, (char *)hostname, (char *)ttyname,
289 AUDIT_FAIL_AUTH);
236# else 290# else
237 loginfailed((char *)user, hostname, (char *)ttyname); 291 loginfailed((char *)user, (char *)hostname, (char *)ttyname);
238# endif 292# endif
239 aix_restoreauthdb(); 293 aix_restoreauthdb();
240} 294}
@@ -291,4 +345,33 @@ aix_restoreauthdb(void)
291 345
292# endif /* WITH_AIXAUTHENTICATE */ 346# endif /* WITH_AIXAUTHENTICATE */
293 347
348# if defined(AIX_GETNAMEINFO_HACK) && !defined(BROKEN_ADDRINFO)
349# undef getnameinfo
350/*
351 * For some reason, AIX's getnameinfo will refuse to resolve the all-zeros
352 * IPv6 address into its textual representation ("::"), so we wrap it
353 * with a function that will.
354 */
355int
356sshaix_getnameinfo(const struct sockaddr *sa, size_t salen, char *host,
357 size_t hostlen, char *serv, size_t servlen, int flags)
358{
359 struct sockaddr_in6 *sa6;
360 u_int32_t *a6;
361
362 if (flags & (NI_NUMERICHOST|NI_NUMERICSERV) &&
363 sa->sa_family == AF_INET6) {
364 sa6 = (struct sockaddr_in6 *)sa;
365 a6 = sa6->sin6_addr.u6_addr.u6_addr32;
366
367 if (a6[0] == 0 && a6[1] == 0 && a6[2] == 0 && a6[3] == 0) {
368 strlcpy(host, "::", hostlen);
369 snprintf(serv, servlen, "%d", sa6->sin6_port);
370 return 0;
371 }
372 }
373 return getnameinfo(sa, salen, host, hostlen, serv, servlen, flags);
374}
375# endif /* AIX_GETNAMEINFO_HACK */
376
294#endif /* _AIX */ 377#endif /* _AIX */
diff --git a/openbsd-compat/port-aix.h b/openbsd-compat/port-aix.h
index 29e9751ce..a05ce9703 100644
--- a/openbsd-compat/port-aix.h
+++ b/openbsd-compat/port-aix.h
@@ -1,4 +1,4 @@
1/* $Id: port-aix.h,v 1.21 2004/08/14 14:09:12 dtucker Exp $ */ 1/* $Id: port-aix.h,v 1.24 2005/02/16 11:49:31 dtucker Exp $ */
2 2
3/* 3/*
4 * 4 *
@@ -27,6 +27,13 @@
27 27
28#ifdef _AIX 28#ifdef _AIX
29 29
30#ifdef HAVE_SYS_SOCKET_H
31# include <sys/socket.h>
32#endif
33#ifdef HAVE_UNISTD_H
34# include <unistd.h> /* for seteuid() */
35#endif
36
30#ifdef WITH_AIXAUTHENTICATE 37#ifdef WITH_AIXAUTHENTICATE
31# include <login.h> 38# include <login.h>
32# include <userpw.h> 39# include <userpw.h>
@@ -36,6 +43,28 @@
36# include <usersec.h> 43# include <usersec.h>
37#endif 44#endif
38 45
46#include "buffer.h"
47
48/* These should be in the system headers but are not. */
49int usrinfo(int, char *, int);
50int setauthdb(const char *, char *);
51/* these may or may not be in the headers depending on the version */
52#if (HAVE_DECL_AUTHENTICATE == 0)
53int authenticate(char *, char *, int *, char **);
54#endif
55#if (HAVE_DECL_LOGINFAILED == 0)
56int loginfailed(char *, char *, char *);
57#endif
58#if (HAVE_DECL_LOGINRESTRICTIONS == 0)
59int loginrestrictions(char *, int, char *, char **);
60#endif
61#if (HAVE_DECL_LOGINSUCCESS == 0)
62int loginsuccess(char *, char *, char *, char **);
63#endif
64#if (HAVE_DECL_PASSWDEXPIRED == 0)
65int passwdexpired(char *, char **);
66#endif
67
39/* Some versions define r_type in the above headers, which causes a conflict */ 68/* Some versions define r_type in the above headers, which causes a conflict */
40#ifdef r_type 69#ifdef r_type
41# undef r_type 70# undef r_type
@@ -64,14 +93,23 @@ void aix_usrinfo(struct passwd *);
64#ifdef WITH_AIXAUTHENTICATE 93#ifdef WITH_AIXAUTHENTICATE
65# define CUSTOM_SYS_AUTH_PASSWD 1 94# define CUSTOM_SYS_AUTH_PASSWD 1
66# define CUSTOM_SYS_AUTH_ALLOWED_USER 1 95# define CUSTOM_SYS_AUTH_ALLOWED_USER 1
67int sys_auth_allowed_user(struct passwd *); 96int sys_auth_allowed_user(struct passwd *, Buffer *);
68# define CUSTOM_SYS_AUTH_RECORD_LOGIN 1 97# define CUSTOM_SYS_AUTH_RECORD_LOGIN 1
69int sys_auth_record_login(const char *, const char *, const char *); 98int sys_auth_record_login(const char *, const char *, const char *, Buffer *);
70# define CUSTOM_FAILED_LOGIN 1 99# define CUSTOM_FAILED_LOGIN 1
71void record_failed_login(const char *, const char *);
72#endif 100#endif
73 101
74void aix_setauthdb(const char *); 102void aix_setauthdb(const char *);
75void aix_restoreauthdb(void); 103void aix_restoreauthdb(void);
76void aix_remove_embedded_newlines(char *); 104void aix_remove_embedded_newlines(char *);
105
106#if defined(AIX_GETNAMEINFO_HACK) && !defined(BROKEN_GETADDRINFO)
107# ifdef getnameinfo
108# undef getnameinfo
109# endif
110int sshaix_getnameinfo(const struct sockaddr *, size_t, char *, size_t,
111 char *, size_t, int);
112# define getnameinfo(a,b,c,d,e,f,g) (sshaix_getnameinfo(a,b,c,d,e,f,g))
113#endif
114
77#endif /* _AIX */ 115#endif /* _AIX */
diff --git a/openbsd-compat/realpath.c b/openbsd-compat/realpath.c
index 218fbecb2..7f73bd998 100644
--- a/openbsd-compat/realpath.c
+++ b/openbsd-compat/realpath.c
@@ -37,7 +37,7 @@
37#if !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH) 37#if !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH)
38 38
39#if defined(LIBC_SCCS) && !defined(lint) 39#if defined(LIBC_SCCS) && !defined(lint)
40static char *rcsid = "$OpenBSD: realpath.c,v 1.10 2003/08/01 21:04:59 millert Exp $"; 40static char *rcsid = "$OpenBSD: realpath.c,v 1.11 2004/11/30 15:12:59 millert Exp $";
41#endif /* LIBC_SCCS and not lint */ 41#endif /* LIBC_SCCS and not lint */
42 42
43#include <sys/param.h> 43#include <sys/param.h>
@@ -67,17 +67,25 @@ char *
67realpath(const char *path, char *resolved) 67realpath(const char *path, char *resolved)
68{ 68{
69 struct stat sb; 69 struct stat sb;
70 int fd, n, needslash, serrno = 0; 70 int fd, n, needslash, serrno;
71 char *p, *q, wbuf[MAXPATHLEN], start[MAXPATHLEN]; 71 char *p, *q, wbuf[MAXPATHLEN];
72 int symlinks = 0; 72 int symlinks = 0;
73 73
74 /* Save the starting point. */ 74 /* Save the starting point. */
75 getcwd(start,MAXPATHLEN); 75#ifndef HAVE_FCHDIR
76 char start[MAXPATHLEN];
77 /* this is potentially racy but without fchdir we have no option */
78 if (getcwd(start, sizeof(start)) == NULL) {
79 resolved[0] = '.';
80 resolved[1] = '\0';
81 return (NULL);
82 }
83#endif
76 if ((fd = open(".", O_RDONLY)) < 0) { 84 if ((fd = open(".", O_RDONLY)) < 0) {
77 (void)strlcpy(resolved, ".", MAXPATHLEN); 85 resolved[0] = '.';
86 resolved[1] = '\0';
78 return (NULL); 87 return (NULL);
79 } 88 }
80 close(fd);
81 89
82 /* Convert "." -> "" to optimize away a needless lstat() and chdir() */ 90 /* Convert "." -> "" to optimize away a needless lstat() and chdir() */
83 if (path[0] == '.' && path[1] == '\0') 91 if (path[0] == '.' && path[1] == '\0')
@@ -91,7 +99,10 @@ realpath(const char *path, char *resolved)
91 * if it is a directory, then change to that directory. 99 * if it is a directory, then change to that directory.
92 * get the current directory name and append the basename. 100 * get the current directory name and append the basename.
93 */ 101 */
94 strlcpy(resolved, path, MAXPATHLEN); 102 if (strlcpy(resolved, path, MAXPATHLEN) >= MAXPATHLEN) {
103 serrno = ENAMETOOLONG;
104 goto err2;
105 }
95loop: 106loop:
96 q = strrchr(resolved, '/'); 107 q = strrchr(resolved, '/');
97 if (q != NULL) { 108 if (q != NULL) {
@@ -114,11 +125,10 @@ loop:
114 if (*p != '\0' && lstat(p, &sb) == 0) { 125 if (*p != '\0' && lstat(p, &sb) == 0) {
115 if (S_ISLNK(sb.st_mode)) { 126 if (S_ISLNK(sb.st_mode)) {
116 if (++symlinks > MAXSYMLINKS) { 127 if (++symlinks > MAXSYMLINKS) {
117 serrno = ELOOP; 128 errno = ELOOP;
118 goto err1; 129 goto err1;
119 } 130 }
120 n = readlink(p, resolved, MAXPATHLEN-1); 131 if ((n = readlink(p, resolved, MAXPATHLEN-1)) < 0)
121 if (n < 0)
122 goto err1; 132 goto err1;
123 resolved[n] = '\0'; 133 resolved[n] = '\0';
124 goto loop; 134 goto loop;
@@ -134,8 +144,11 @@ loop:
134 * Save the last component name and get the full pathname of 144 * Save the last component name and get the full pathname of
135 * the current directory. 145 * the current directory.
136 */ 146 */
137 (void)strlcpy(wbuf, p, sizeof wbuf); 147 if (strlcpy(wbuf, p, sizeof(wbuf)) >= sizeof(wbuf)) {
138 if (getcwd(resolved, MAXPATHLEN) == 0) 148 errno = ENAMETOOLONG;
149 goto err1;
150 }
151 if (getcwd(resolved, MAXPATHLEN) == NULL)
139 goto err1; 152 goto err1;
140 153
141 /* 154 /*
@@ -149,23 +162,43 @@ loop:
149 162
150 if (*wbuf) { 163 if (*wbuf) {
151 if (strlen(resolved) + strlen(wbuf) + needslash >= MAXPATHLEN) { 164 if (strlen(resolved) + strlen(wbuf) + needslash >= MAXPATHLEN) {
152 serrno = ENAMETOOLONG; 165 errno = ENAMETOOLONG;
166 goto err1;
167 }
168 if (needslash) {
169 if (strlcat(resolved, "/", MAXPATHLEN) >= MAXPATHLEN) {
170 errno = ENAMETOOLONG;
171 goto err1;
172 }
173 }
174 if (strlcat(resolved, wbuf, MAXPATHLEN) >= MAXPATHLEN) {
175 errno = ENAMETOOLONG;
153 goto err1; 176 goto err1;
154 } 177 }
155 if (needslash)
156 strlcat(resolved, "/", MAXPATHLEN);
157 strlcat(resolved, wbuf, MAXPATHLEN);
158 } 178 }
159 179
160 /* Go back to where we came from. */ 180 /* Go back to where we came from. */
181#ifdef HAVE_FCHDIR
182 if (fchdir(fd) < 0) {
183#else
161 if (chdir(start) < 0) { 184 if (chdir(start) < 0) {
185#endif
162 serrno = errno; 186 serrno = errno;
163 goto err2; 187 goto err2;
164 } 188 }
189
190 /* It's okay if the close fails, what's an fd more or less? */
191 (void)close(fd);
165 return (resolved); 192 return (resolved);
166 193
167err1: chdir(start); 194err1: serrno = errno;
168err2: errno = serrno; 195#ifdef HAVE_FCHDIR
196 (void)fchdir(fd);
197#else
198 chdir(start);
199#endif
200err2: (void)close(fd);
201 errno = serrno;
169 return (NULL); 202 return (NULL);
170} 203}
171#endif /* !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH) */ 204#endif /* !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH) */
diff --git a/openbsd-compat/xmmap.c b/openbsd-compat/xmmap.c
index c8d59dee0..74e8a8b13 100644
--- a/openbsd-compat/xmmap.c
+++ b/openbsd-compat/xmmap.c
@@ -23,7 +23,7 @@
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26/* $Id: xmmap.c,v 1.5 2004/08/14 13:55:38 dtucker Exp $ */ 26/* $Id: xmmap.c,v 1.6 2004/10/06 13:15:44 dtucker Exp $ */
27 27
28#include "includes.h" 28#include "includes.h"
29 29
@@ -47,7 +47,7 @@ void *xmmap(size_t size)
47# endif 47# endif
48 48
49#define MM_SWAP_TEMPLATE "/var/run/sshd.mm.XXXXXXXX" 49#define MM_SWAP_TEMPLATE "/var/run/sshd.mm.XXXXXXXX"
50 if (address == MAP_FAILED) { 50 if (address == (void *)MAP_FAILED) {
51 char tmpname[sizeof(MM_SWAP_TEMPLATE)] = MM_SWAP_TEMPLATE; 51 char tmpname[sizeof(MM_SWAP_TEMPLATE)] = MM_SWAP_TEMPLATE;
52 int tmpfd; 52 int tmpfd;
53 mode_t old_umask; 53 mode_t old_umask;