diff options
Diffstat (limited to 'openbsd-compat')
-rw-r--r-- | openbsd-compat/Makefile.in | 8 | ||||
-rw-r--r-- | openbsd-compat/bsd-cygwin_util.c | 2 | ||||
-rw-r--r-- | openbsd-compat/bsd-misc.c | 20 | ||||
-rw-r--r-- | openbsd-compat/fake-rfc2553.h | 16 | ||||
-rw-r--r-- | openbsd-compat/getrrsetbyname.c | 4 | ||||
-rw-r--r-- | openbsd-compat/openbsd-compat.h | 7 | ||||
-rw-r--r-- | openbsd-compat/openssl-compat.c | 46 | ||||
-rw-r--r-- | openbsd-compat/openssl-compat.h | 65 | ||||
-rw-r--r-- | openbsd-compat/port-aix.c | 16 | ||||
-rw-r--r-- | openbsd-compat/port-aix.h | 15 | ||||
-rw-r--r-- | openbsd-compat/port-uw.c | 134 | ||||
-rw-r--r-- | openbsd-compat/port-uw.h | 30 | ||||
-rw-r--r-- | openbsd-compat/realpath.c | 266 | ||||
-rw-r--r-- | openbsd-compat/strtoll.c | 151 | ||||
-rw-r--r-- | openbsd-compat/strtonum.c | 69 | ||||
-rw-r--r-- | openbsd-compat/xcrypt.c | 5 |
16 files changed, 689 insertions, 165 deletions
diff --git a/openbsd-compat/Makefile.in b/openbsd-compat/Makefile.in index 0f34f2240..6f5ee2845 100644 --- a/openbsd-compat/Makefile.in +++ b/openbsd-compat/Makefile.in | |||
@@ -1,4 +1,4 @@ | |||
1 | # $Id: Makefile.in,v 1.31 2004/08/15 08:41:00 djm Exp $ | 1 | # $Id: Makefile.in,v 1.35 2005/08/26 20:15:20 tim Exp $ |
2 | 2 | ||
3 | sysconfdir=@sysconfdir@ | 3 | sysconfdir=@sysconfdir@ |
4 | piddir=@piddir@ | 4 | piddir=@piddir@ |
@@ -16,11 +16,11 @@ RANLIB=@RANLIB@ | |||
16 | INSTALL=@INSTALL@ | 16 | INSTALL=@INSTALL@ |
17 | LDFLAGS=-L. @LDFLAGS@ | 17 | LDFLAGS=-L. @LDFLAGS@ |
18 | 18 | ||
19 | OPENBSD=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 | 19 | OPENBSD=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 strtonum.o strtoll.o strtoul.o vis.o |
20 | 20 | ||
21 | COMPAT=bsd-arc4random.o bsd-closefrom.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 | 21 | COMPAT=bsd-arc4random.o bsd-closefrom.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 openssl-compat.o xmmap.o xcrypt.o |
22 | 22 | ||
23 | PORTS=port-irix.o port-aix.o | 23 | PORTS=port-irix.o port-aix.o port-uw.o |
24 | 24 | ||
25 | .c.o: | 25 | .c.o: |
26 | $(CC) $(CFLAGS) $(CPPFLAGS) -c $< | 26 | $(CC) $(CFLAGS) $(CPPFLAGS) -c $< |
diff --git a/openbsd-compat/bsd-cygwin_util.c b/openbsd-compat/bsd-cygwin_util.c index ff394ec17..b5e3cc52b 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 | ||
32 | RCSID("$Id: bsd-cygwin_util.c,v 1.13.4.1 2005/05/25 09:42:40 dtucker Exp $"); | 32 | RCSID("$Id: bsd-cygwin_util.c,v 1.14 2005/05/25 09:42:11 dtucker Exp $"); |
33 | 33 | ||
34 | #ifdef HAVE_CYGWIN | 34 | #ifdef HAVE_CYGWIN |
35 | 35 | ||
diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c index 41f92cce9..6ba9bd986 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 | ||
21 | RCSID("$Id: bsd-misc.c,v 1.26 2005/02/25 23:07:38 dtucker Exp $"); | 21 | RCSID("$Id: bsd-misc.c,v 1.27 2005/05/27 11:13:41 dtucker Exp $"); |
22 | 22 | ||
23 | #ifndef HAVE___PROGNAME | 23 | #ifndef HAVE___PROGNAME |
24 | char *__progname; | 24 | char *__progname; |
@@ -212,3 +212,21 @@ mysignal(int sig, mysig_t act) | |||
212 | return (signal(sig, act)); | 212 | return (signal(sig, act)); |
213 | #endif | 213 | #endif |
214 | } | 214 | } |
215 | |||
216 | #ifndef HAVE_STRDUP | ||
217 | char * | ||
218 | strdup(const char *str) | ||
219 | { | ||
220 | size_t len; | ||
221 | char *cp; | ||
222 | |||
223 | len = strlen(str) + 1; | ||
224 | cp = malloc(len); | ||
225 | if (cp != NULL) | ||
226 | if (strlcpy(cp, str, len) != len) { | ||
227 | free(cp); | ||
228 | return NULL; | ||
229 | } | ||
230 | return cp; | ||
231 | } | ||
232 | #endif | ||
diff --git a/openbsd-compat/fake-rfc2553.h b/openbsd-compat/fake-rfc2553.h index 636792ed7..cbcf7f727 100644 --- a/openbsd-compat/fake-rfc2553.h +++ b/openbsd-compat/fake-rfc2553.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Id: fake-rfc2553.h,v 1.10 2005/02/11 07:32:13 dtucker Exp $ */ | 1 | /* $Id: fake-rfc2553.h,v 1.12 2005/08/03 05:36:21 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. |
@@ -114,10 +114,16 @@ struct sockaddr_in6 { | |||
114 | #endif /* !NI_MAXHOST */ | 114 | #endif /* !NI_MAXHOST */ |
115 | 115 | ||
116 | #ifndef EAI_NODATA | 116 | #ifndef EAI_NODATA |
117 | # define EAI_NODATA 1 | 117 | # define EAI_NODATA (INT_MAX - 1) |
118 | # define EAI_MEMORY 2 | 118 | #endif |
119 | # define EAI_NONAME 3 | 119 | #ifndef EAI_MEMORY |
120 | # define EAI_SYSTEM 4 | 120 | # define EAI_MEMORY (INT_MAX - 2) |
121 | #endif | ||
122 | #ifndef EAI_NONAME | ||
123 | # define EAI_NONAME (INT_MAX - 3) | ||
124 | #endif | ||
125 | #ifndef EAI_SYSTEM | ||
126 | # define EAI_SYSTEM (INT_MAX - 4) | ||
121 | #endif | 127 | #endif |
122 | 128 | ||
123 | #ifndef HAVE_STRUCT_ADDRINFO | 129 | #ifndef HAVE_STRUCT_ADDRINFO |
diff --git a/openbsd-compat/getrrsetbyname.c b/openbsd-compat/getrrsetbyname.c index 4e869c4df..2016ffe31 100644 --- a/openbsd-compat/getrrsetbyname.c +++ b/openbsd-compat/getrrsetbyname.c | |||
@@ -144,6 +144,8 @@ _getshort(msgp) | |||
144 | GETSHORT(u, msgp); | 144 | GETSHORT(u, msgp); |
145 | return (u); | 145 | return (u); |
146 | } | 146 | } |
147 | #elif defined(HAVE_DECL__GETSHORT) && (HAVE_DECL__GETSHORT == 0) | ||
148 | u_int16_t _getshort(register const u_char *); | ||
147 | #endif | 149 | #endif |
148 | 150 | ||
149 | #ifndef HAVE__GETLONG | 151 | #ifndef HAVE__GETLONG |
@@ -156,6 +158,8 @@ _getlong(msgp) | |||
156 | GETLONG(u, msgp); | 158 | GETLONG(u, msgp); |
157 | return (u); | 159 | return (u); |
158 | } | 160 | } |
161 | #elif defined(HAVE_DECL__GETLONG) && (HAVE_DECL__GETLONG == 0) | ||
162 | u_int32_t _getlong(register const u_char *); | ||
159 | #endif | 163 | #endif |
160 | 164 | ||
161 | int | 165 | int |
diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h index 89d1454e0..ba68bc27e 100644 --- a/openbsd-compat/openbsd-compat.h +++ b/openbsd-compat/openbsd-compat.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $Id: openbsd-compat.h,v 1.26 2004/08/15 08:41:00 djm Exp $ */ | 1 | /* $Id: openbsd-compat.h,v 1.30 2005/08/26 20:15:20 tim 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. |
@@ -152,6 +152,10 @@ int openpty(int *, int *, char *, struct termios *, struct winsize *); | |||
152 | int snprintf(char *, size_t, const char *, ...); | 152 | int snprintf(char *, size_t, const char *, ...); |
153 | #endif | 153 | #endif |
154 | 154 | ||
155 | #ifndef HAVE_STRTONUM | ||
156 | long long strtonum(const char *, long long, long long, const char **); | ||
157 | #endif | ||
158 | |||
155 | #ifndef HAVE_VSNPRINTF | 159 | #ifndef HAVE_VSNPRINTF |
156 | int vsnprintf(char *, size_t, const char *, va_list); | 160 | int vsnprintf(char *, size_t, const char *, va_list); |
157 | #endif | 161 | #endif |
@@ -169,5 +173,6 @@ char *shadow_pw(struct passwd *pw); | |||
169 | #include "bsd-cygwin_util.h" | 173 | #include "bsd-cygwin_util.h" |
170 | #include "port-irix.h" | 174 | #include "port-irix.h" |
171 | #include "port-aix.h" | 175 | #include "port-aix.h" |
176 | #include "port-uw.h" | ||
172 | 177 | ||
173 | #endif /* _OPENBSD_COMPAT_H */ | 178 | #endif /* _OPENBSD_COMPAT_H */ |
diff --git a/openbsd-compat/openssl-compat.c b/openbsd-compat/openssl-compat.c new file mode 100644 index 000000000..b690e8fe6 --- /dev/null +++ b/openbsd-compat/openssl-compat.c | |||
@@ -0,0 +1,46 @@ | |||
1 | /* $Id: openssl-compat.c,v 1.2 2005/06/17 11:15:21 dtucker Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2005 Darren Tucker <dtucker@zip.com.au> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER | ||
15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING | ||
16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include "includes.h" | ||
20 | |||
21 | #define SSH_DONT_REDEF_EVP | ||
22 | #include "openssl-compat.h" | ||
23 | |||
24 | #ifdef SSH_OLD_EVP | ||
25 | int | ||
26 | ssh_EVP_CipherInit(EVP_CIPHER_CTX *evp, const EVP_CIPHER *type, | ||
27 | unsigned char *key, unsigned char *iv, int enc) | ||
28 | { | ||
29 | EVP_CipherInit(evp, type, key, iv, enc); | ||
30 | return 1; | ||
31 | } | ||
32 | |||
33 | int | ||
34 | ssh_EVP_Cipher(EVP_CIPHER_CTX *evp, char *dst, char *src, int len) | ||
35 | { | ||
36 | EVP_Cipher(evp, dst, src, len); | ||
37 | return 1; | ||
38 | } | ||
39 | |||
40 | int | ||
41 | ssh_EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *evp) | ||
42 | { | ||
43 | EVP_CIPHER_CTX_cleanup(evp); | ||
44 | return 1; | ||
45 | } | ||
46 | #endif | ||
diff --git a/openbsd-compat/openssl-compat.h b/openbsd-compat/openssl-compat.h new file mode 100644 index 000000000..d9b2fa55f --- /dev/null +++ b/openbsd-compat/openssl-compat.h | |||
@@ -0,0 +1,65 @@ | |||
1 | /* $Id: openssl-compat.h,v 1.1 2005/06/09 11:45:11 dtucker Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 2005 Darren Tucker <dtucker@zip.com.au> | ||
5 | * | ||
6 | * Permission to use, copy, modify, and distribute this software for any | ||
7 | * purpose with or without fee is hereby granted, provided that the above | ||
8 | * copyright notice and this permission notice appear in all copies. | ||
9 | * | ||
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
14 | * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER | ||
15 | * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING | ||
16 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
17 | */ | ||
18 | |||
19 | #include "includes.h" | ||
20 | #include <openssl/evp.h> | ||
21 | |||
22 | #if OPENSSL_VERSION_NUMBER < 0x00906000L | ||
23 | # define SSH_OLD_EVP | ||
24 | # define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data) | ||
25 | #endif | ||
26 | |||
27 | #if OPENSSL_VERSION_NUMBER < 0x00907000L | ||
28 | # define EVP_aes_128_cbc evp_rijndael | ||
29 | # define EVP_aes_192_cbc evp_rijndael | ||
30 | # define EVP_aes_256_cbc evp_rijndael | ||
31 | extern const EVP_CIPHER *evp_rijndael(void); | ||
32 | extern void ssh_rijndael_iv(EVP_CIPHER_CTX *, int, u_char *, u_int); | ||
33 | #endif | ||
34 | |||
35 | #if !defined(EVP_CTRL_SET_ACSS_MODE) | ||
36 | # if (OPENSSL_VERSION_NUMBER >= 0x00907000L) | ||
37 | # define USE_CIPHER_ACSS 1 | ||
38 | extern const EVP_CIPHER *evp_acss(void); | ||
39 | # define EVP_acss evp_acss | ||
40 | # else | ||
41 | # define EVP_acss NULL | ||
42 | # endif | ||
43 | #endif | ||
44 | |||
45 | /* | ||
46 | * insert comment here | ||
47 | */ | ||
48 | #ifdef SSH_OLD_EVP | ||
49 | |||
50 | # ifndef SSH_DONT_REDEF_EVP | ||
51 | |||
52 | # ifdef EVP_Cipher | ||
53 | # undef EVP_Cipher | ||
54 | # endif | ||
55 | |||
56 | # define EVP_CipherInit(a,b,c,d,e) ssh_EVP_CipherInit((a),(b),(c),(d),(e)) | ||
57 | # define EVP_Cipher(a,b,c,d) ssh_EVP_Cipher((a),(b),(c),(d)) | ||
58 | # define EVP_CIPHER_CTX_cleanup(a) ssh_EVP_CIPHER_CTX_cleanup((a)) | ||
59 | # endif | ||
60 | |||
61 | int ssh_EVP_CipherInit(EVP_CIPHER_CTX *, const EVP_CIPHER *, unsigned char *, | ||
62 | unsigned char *, int); | ||
63 | int ssh_EVP_Cipher(EVP_CIPHER_CTX *, char *, char *, int); | ||
64 | int ssh_EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *); | ||
65 | #endif | ||
diff --git a/openbsd-compat/port-aix.c b/openbsd-compat/port-aix.c index cf5d4b9a3..81d8124e0 100644 --- a/openbsd-compat/port-aix.c +++ b/openbsd-compat/port-aix.c | |||
@@ -1,7 +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 | * Copyright (c) 2003,2004,2005 Darren Tucker. All rights reserved. |
5 | * | 5 | * |
6 | * Redistribution and use in source and binary forms, with or without | 6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions | 7 | * modification, are permitted provided that the following conditions |
@@ -42,14 +42,12 @@ static char old_registry[REGISTRY_SIZE] = ""; | |||
42 | # endif | 42 | # endif |
43 | 43 | ||
44 | /* | 44 | /* |
45 | * AIX has a "usrinfo" area where logname and other stuff is stored - | 45 | * AIX has a "usrinfo" area where logname and other stuff is stored - |
46 | * a few applications actually use this and die if it's not set | 46 | * a few applications actually use this and die if it's not set |
47 | * | 47 | * |
48 | * 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 |
49 | * acquire due to privsep code. We will just drop support. | 49 | * acquire due to privsep code. We will just drop support. |
50 | */ | 50 | */ |
51 | |||
52 | |||
53 | void | 51 | void |
54 | aix_usrinfo(struct passwd *pw) | 52 | aix_usrinfo(struct passwd *pw) |
55 | { | 53 | { |
@@ -60,7 +58,7 @@ aix_usrinfo(struct passwd *pw) | |||
60 | len = sizeof("LOGNAME= NAME= ") + (2 * strlen(pw->pw_name)); | 58 | len = sizeof("LOGNAME= NAME= ") + (2 * strlen(pw->pw_name)); |
61 | cp = xmalloc(len); | 59 | cp = xmalloc(len); |
62 | 60 | ||
63 | i = snprintf(cp, len, "LOGNAME=%s%cNAME=%s%c", pw->pw_name, '\0', | 61 | i = snprintf(cp, len, "LOGNAME=%s%cNAME=%s%c", pw->pw_name, '\0', |
64 | pw->pw_name, '\0'); | 62 | pw->pw_name, '\0'); |
65 | if (usrinfo(SETUINFO, cp, i) == -1) | 63 | if (usrinfo(SETUINFO, cp, i) == -1) |
66 | fatal("Couldn't set usrinfo: %s", strerror(errno)); | 64 | fatal("Couldn't set usrinfo: %s", strerror(errno)); |
@@ -153,14 +151,14 @@ aix_valid_authentications(const char *user) | |||
153 | int | 151 | int |
154 | sys_auth_passwd(Authctxt *ctxt, const char *password) | 152 | sys_auth_passwd(Authctxt *ctxt, const char *password) |
155 | { | 153 | { |
156 | char *authmsg = NULL, *msg, *name = ctxt->pw->pw_name; | 154 | char *authmsg = NULL, *msg = NULL, *name = ctxt->pw->pw_name; |
157 | int authsuccess = 0, expired, reenter, result; | 155 | int authsuccess = 0, expired, reenter, result; |
158 | 156 | ||
159 | do { | 157 | do { |
160 | result = authenticate((char *)name, (char *)password, &reenter, | 158 | result = authenticate((char *)name, (char *)password, &reenter, |
161 | &authmsg); | 159 | &authmsg); |
162 | aix_remove_embedded_newlines(authmsg); | 160 | aix_remove_embedded_newlines(authmsg); |
163 | debug3("AIX/authenticate result %d, msg %.100s", result, | 161 | debug3("AIX/authenticate result %d, authmsg %.100s", result, |
164 | authmsg); | 162 | authmsg); |
165 | } while (reenter); | 163 | } while (reenter); |
166 | 164 | ||
@@ -170,7 +168,7 @@ sys_auth_passwd(Authctxt *ctxt, const char *password) | |||
170 | if (result == 0) { | 168 | if (result == 0) { |
171 | authsuccess = 1; | 169 | authsuccess = 1; |
172 | 170 | ||
173 | /* | 171 | /* |
174 | * Record successful login. We don't have a pty yet, so just | 172 | * Record successful login. We don't have a pty yet, so just |
175 | * label the line as "ssh" | 173 | * label the line as "ssh" |
176 | */ | 174 | */ |
@@ -257,7 +255,7 @@ int | |||
257 | sys_auth_record_login(const char *user, const char *host, const char *ttynm, | 255 | sys_auth_record_login(const char *user, const char *host, const char *ttynm, |
258 | Buffer *loginmsg) | 256 | Buffer *loginmsg) |
259 | { | 257 | { |
260 | char *msg; | 258 | char *msg = NULL; |
261 | int success = 0; | 259 | int success = 0; |
262 | 260 | ||
263 | aix_setauthdb(user); | 261 | aix_setauthdb(user); |
diff --git a/openbsd-compat/port-aix.h b/openbsd-compat/port-aix.h index 9e3dce4dd..37b2c12b0 100644 --- a/openbsd-compat/port-aix.h +++ b/openbsd-compat/port-aix.h | |||
@@ -1,8 +1,9 @@ | |||
1 | /* $Id: port-aix.h,v 1.25 2005/03/21 11:46:34 dtucker Exp $ */ | 1 | /* $Id: port-aix.h,v 1.26 2005/05/28 10:28:40 dtucker Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * | 4 | * |
5 | * Copyright (c) 2001 Gert Doering. All rights reserved. | 5 | * Copyright (c) 2001 Gert Doering. All rights reserved. |
6 | * Copyright (c) 2004, 2005 Darren Tucker. All rights reserved. | ||
6 | * | 7 | * |
7 | * Redistribution and use in source and binary forms, with or without | 8 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | 9 | * modification, are permitted provided that the following conditions |
@@ -47,23 +48,23 @@ | |||
47 | 48 | ||
48 | /* These should be in the system headers but are not. */ | 49 | /* These should be in the system headers but are not. */ |
49 | int usrinfo(int, char *, int); | 50 | int usrinfo(int, char *, int); |
50 | #if (HAVE_DECL_SETAUTHDB == 0) | 51 | #if defined(HAVE_DECL_SETAUTHDB) && (HAVE_DECL_SETAUTHDB == 0) |
51 | int setauthdb(const char *, char *); | 52 | int setauthdb(const char *, char *); |
52 | #endif | 53 | #endif |
53 | /* these may or may not be in the headers depending on the version */ | 54 | /* these may or may not be in the headers depending on the version */ |
54 | #if (HAVE_DECL_AUTHENTICATE == 0) | 55 | #if defined(HAVE_DECL_AUTHENTICATE) && (HAVE_DECL_AUTHENTICATE == 0) |
55 | int authenticate(char *, char *, int *, char **); | 56 | int authenticate(char *, char *, int *, char **); |
56 | #endif | 57 | #endif |
57 | #if (HAVE_DECL_LOGINFAILED == 0) | 58 | #if defined(HAVE_DECL_LOGINFAILED) && (HAVE_DECL_LOGINFAILED == 0) |
58 | int loginfailed(char *, char *, char *); | 59 | int loginfailed(char *, char *, char *); |
59 | #endif | 60 | #endif |
60 | #if (HAVE_DECL_LOGINRESTRICTIONS == 0) | 61 | #if defined(HAVE_DECL_LOGINRESTRICTIONS) && (HAVE_DECL_LOGINRESTRICTIONS == 0) |
61 | int loginrestrictions(char *, int, char *, char **); | 62 | int loginrestrictions(char *, int, char *, char **); |
62 | #endif | 63 | #endif |
63 | #if (HAVE_DECL_LOGINSUCCESS == 0) | 64 | #if defined(HAVE_DECL_LOGINSUCCESS) && (HAVE_DECL_LOGINSUCCESS == 0) |
64 | int loginsuccess(char *, char *, char *, char **); | 65 | int loginsuccess(char *, char *, char *, char **); |
65 | #endif | 66 | #endif |
66 | #if (HAVE_DECL_PASSWDEXPIRED == 0) | 67 | #if defined(HAVE_DECL_PASSWDEXPIRED) && (HAVE_DECL_PASSWDEXPIRED == 0) |
67 | int passwdexpired(char *, char **); | 68 | int passwdexpired(char *, char **); |
68 | #endif | 69 | #endif |
69 | 70 | ||
diff --git a/openbsd-compat/port-uw.c b/openbsd-compat/port-uw.c new file mode 100644 index 000000000..d881ff028 --- /dev/null +++ b/openbsd-compat/port-uw.c | |||
@@ -0,0 +1,134 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2005 The SCO Group. All rights reserved. | ||
3 | * Copyright (c) 2005 Tim Rice. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * 1. Redistributions of source code must retain the above copyright | ||
9 | * notice, this list of conditions and the following disclaimer. | ||
10 | * 2. Redistributions in binary form must reproduce the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer in the | ||
12 | * documentation and/or other materials provided with the distribution. | ||
13 | * | ||
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
17 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
24 | */ | ||
25 | |||
26 | #include "includes.h" | ||
27 | |||
28 | #if defined(HAVE_LIBIAF) && !defined(BROKEN_LIBIAF) | ||
29 | #ifdef HAVE_CRYPT_H | ||
30 | #include <crypt.h> | ||
31 | #endif | ||
32 | #include "packet.h" | ||
33 | #include "buffer.h" | ||
34 | #include "log.h" | ||
35 | #include "servconf.h" | ||
36 | #include "auth.h" | ||
37 | #include "auth-options.h" | ||
38 | |||
39 | int nischeck(char *); | ||
40 | |||
41 | int | ||
42 | sys_auth_passwd(Authctxt *authctxt, const char *password) | ||
43 | { | ||
44 | struct passwd *pw = authctxt->pw; | ||
45 | char *encrypted_password; | ||
46 | char *salt; | ||
47 | int result; | ||
48 | |||
49 | /* Just use the supplied fake password if authctxt is invalid */ | ||
50 | char *pw_password = authctxt->valid ? shadow_pw(pw) : pw->pw_passwd; | ||
51 | |||
52 | /* Check for users with no password. */ | ||
53 | if (strcmp(pw_password, "") == 0 && strcmp(password, "") == 0) | ||
54 | return (1); | ||
55 | |||
56 | /* Encrypt the candidate password using the proper salt. */ | ||
57 | salt = (pw_password[0] && pw_password[1]) ? pw_password : "xx"; | ||
58 | #ifdef UNIXWARE_LONG_PASSWORDS | ||
59 | if (!nischeck(pw->pw_name)) | ||
60 | encrypted_password = bigcrypt(password, salt); | ||
61 | else | ||
62 | #endif /* UNIXWARE_LONG_PASSWORDS */ | ||
63 | encrypted_password = xcrypt(password, salt); | ||
64 | |||
65 | /* | ||
66 | * Authentication is accepted if the encrypted passwords | ||
67 | * are identical. | ||
68 | */ | ||
69 | result = (strcmp(encrypted_password, pw_password) == 0); | ||
70 | |||
71 | if (authctxt->valid) | ||
72 | free(pw_password); | ||
73 | return(result); | ||
74 | } | ||
75 | |||
76 | #ifdef UNIXWARE_LONG_PASSWORDS | ||
77 | int | ||
78 | nischeck(char *namep) | ||
79 | { | ||
80 | char password_file[] = "/etc/passwd"; | ||
81 | FILE *fd; | ||
82 | struct passwd *ent = NULL; | ||
83 | |||
84 | if ((fd = fopen (password_file, "r")) == NULL) { | ||
85 | /* | ||
86 | * If the passwd file has dissapeared we are in a bad state. | ||
87 | * However, returning 0 will send us back through the | ||
88 | * authentication scheme that has checked the ia database for | ||
89 | * passwords earlier. | ||
90 | */ | ||
91 | return(0); | ||
92 | } | ||
93 | |||
94 | /* | ||
95 | * fgetpwent() only reads from password file, so we know for certain | ||
96 | * that the user is local. | ||
97 | */ | ||
98 | while (ent = fgetpwent(fd)) { | ||
99 | if (strcmp (ent->pw_name, namep) == 0) { | ||
100 | /* Local user */ | ||
101 | fclose (fd); | ||
102 | return(0); | ||
103 | } | ||
104 | } | ||
105 | |||
106 | fclose (fd); | ||
107 | return (1); | ||
108 | } | ||
109 | |||
110 | #endif /* UNIXWARE_LONG_PASSWORDS */ | ||
111 | |||
112 | /* | ||
113 | NOTE: ia_get_logpwd() allocates memory for arg 2 | ||
114 | functions that call shadow_pw() will need to free | ||
115 | */ | ||
116 | |||
117 | char * | ||
118 | get_iaf_password(struct passwd *pw) | ||
119 | { | ||
120 | char *pw_password = NULL; | ||
121 | |||
122 | uinfo_t uinfo; | ||
123 | if (!ia_openinfo(pw->pw_name,&uinfo)) { | ||
124 | ia_get_logpwd(uinfo, &pw_password); | ||
125 | if (pw_password == NULL) | ||
126 | fatal("ia_get_logpwd: Unable to get the shadow passwd"); | ||
127 | ia_closeinfo(uinfo); | ||
128 | return pw_password; | ||
129 | } | ||
130 | else | ||
131 | fatal("ia_openinfo: Unable to open the shadow passwd file"); | ||
132 | } | ||
133 | #endif /* HAVE_LIBIAF && !BROKEN_LIBIAF */ | ||
134 | |||
diff --git a/openbsd-compat/port-uw.h b/openbsd-compat/port-uw.h new file mode 100644 index 000000000..3589b2e44 --- /dev/null +++ b/openbsd-compat/port-uw.h | |||
@@ -0,0 +1,30 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2005 Tim Rice. All rights reserved. | ||
3 | * | ||
4 | * Redistribution and use in source and binary forms, with or without | ||
5 | * modification, are permitted provided that the following conditions | ||
6 | * are met: | ||
7 | * 1. Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * 2. Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * | ||
13 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
14 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
15 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
16 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
17 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
18 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
19 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
20 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
21 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
22 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
23 | */ | ||
24 | |||
25 | #include "includes.h" | ||
26 | |||
27 | #if defined(HAVE_LIBIAF) && !defined(BROKEN_LIBIAF) | ||
28 | char * get_iaf_password(struct passwd *pw); | ||
29 | #endif | ||
30 | |||
diff --git a/openbsd-compat/realpath.c b/openbsd-compat/realpath.c index 7f73bd998..8430bec24 100644 --- a/openbsd-compat/realpath.c +++ b/openbsd-compat/realpath.c | |||
@@ -1,11 +1,7 @@ | |||
1 | /* OPENBSD ORIGINAL: lib/libc/stdlib/realpath.c */ | 1 | /* OPENBSD ORIGINAL: lib/libc/stdlib/realpath.c */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 1994 | 4 | * Copyright (c) 2003 Constantin S. Svintsoff <kostik@iclub.nsu.ru> |
5 | * The Regents of the University of California. All rights reserved. | ||
6 | * | ||
7 | * This code is derived from software contributed to Berkeley by | ||
8 | * Jan-Simon Pendry. | ||
9 | * | 5 | * |
10 | * Redistribution and use in source and binary forms, with or without | 6 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | 7 | * modification, are permitted provided that the following conditions |
@@ -15,14 +11,14 @@ | |||
15 | * 2. Redistributions in binary form must reproduce the above copyright | 11 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in the | 12 | * notice, this list of conditions and the following disclaimer in the |
17 | * documentation and/or other materials provided with the distribution. | 13 | * documentation and/or other materials provided with the distribution. |
18 | * 3. Neither the name of the University nor the names of its contributors | 14 | * 3. The names of the authors may not be used to endorse or promote |
19 | * may be used to endorse or promote products derived from this software | 15 | * products derived from this software without specific prior written |
20 | * without specific prior written permission. | 16 | * permission. |
21 | * | 17 | * |
22 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 24 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
@@ -36,169 +32,165 @@ | |||
36 | 32 | ||
37 | #if !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH) | 33 | #if !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH) |
38 | 34 | ||
39 | #if defined(LIBC_SCCS) && !defined(lint) | ||
40 | static char *rcsid = "$OpenBSD: realpath.c,v 1.11 2004/11/30 15:12:59 millert Exp $"; | ||
41 | #endif /* LIBC_SCCS and not lint */ | ||
42 | |||
43 | #include <sys/param.h> | 35 | #include <sys/param.h> |
44 | #include <sys/stat.h> | 36 | #include <sys/stat.h> |
45 | 37 | ||
46 | #include <errno.h> | 38 | #include <errno.h> |
47 | #include <fcntl.h> | ||
48 | #include <stdlib.h> | 39 | #include <stdlib.h> |
49 | #include <string.h> | 40 | #include <string.h> |
50 | #include <unistd.h> | 41 | #include <unistd.h> |
51 | 42 | ||
52 | /* | 43 | /* |
53 | * MAXSYMLINKS | 44 | * char *realpath(const char *path, char resolved[PATH_MAX]); |
54 | */ | ||
55 | #ifndef MAXSYMLINKS | ||
56 | #define MAXSYMLINKS 5 | ||
57 | #endif | ||
58 | |||
59 | /* | ||
60 | * char *realpath(const char *path, char resolved_path[MAXPATHLEN]); | ||
61 | * | 45 | * |
62 | * Find the real name of path, by removing all ".", ".." and symlink | 46 | * Find the real name of path, by removing all ".", ".." and symlink |
63 | * components. Returns (resolved) on success, or (NULL) on failure, | 47 | * components. Returns (resolved) on success, or (NULL) on failure, |
64 | * in which case the path which caused trouble is left in (resolved). | 48 | * in which case the path which caused trouble is left in (resolved). |
65 | */ | 49 | */ |
66 | char * | 50 | char * |
67 | realpath(const char *path, char *resolved) | 51 | realpath(const char *path, char resolved[PATH_MAX]) |
68 | { | 52 | { |
69 | struct stat sb; | 53 | struct stat sb; |
70 | int fd, n, needslash, serrno; | 54 | char *p, *q, *s; |
71 | char *p, *q, wbuf[MAXPATHLEN]; | 55 | size_t left_len, resolved_len; |
72 | int symlinks = 0; | 56 | unsigned symlinks; |
73 | 57 | int serrno, slen; | |
74 | /* Save the starting point. */ | 58 | char left[PATH_MAX], next_token[PATH_MAX], symlink[PATH_MAX]; |
75 | #ifndef HAVE_FCHDIR | 59 | |
76 | char start[MAXPATHLEN]; | 60 | serrno = errno; |
77 | /* this is potentially racy but without fchdir we have no option */ | 61 | symlinks = 0; |
78 | if (getcwd(start, sizeof(start)) == NULL) { | 62 | if (path[0] == '/') { |
79 | resolved[0] = '.'; | 63 | resolved[0] = '/'; |
80 | resolved[1] = '\0'; | 64 | resolved[1] = '\0'; |
81 | return (NULL); | 65 | if (path[1] == '\0') |
66 | return (resolved); | ||
67 | resolved_len = 1; | ||
68 | left_len = strlcpy(left, path + 1, sizeof(left)); | ||
69 | } else { | ||
70 | if (getcwd(resolved, PATH_MAX) == NULL) { | ||
71 | strlcpy(resolved, ".", PATH_MAX); | ||
72 | return (NULL); | ||
73 | } | ||
74 | resolved_len = strlen(resolved); | ||
75 | left_len = strlcpy(left, path, sizeof(left)); | ||
82 | } | 76 | } |
83 | #endif | 77 | if (left_len >= sizeof(left) || resolved_len >= PATH_MAX) { |
84 | if ((fd = open(".", O_RDONLY)) < 0) { | 78 | errno = ENAMETOOLONG; |
85 | resolved[0] = '.'; | ||
86 | resolved[1] = '\0'; | ||
87 | return (NULL); | 79 | return (NULL); |
88 | } | 80 | } |
89 | 81 | ||
90 | /* Convert "." -> "" to optimize away a needless lstat() and chdir() */ | ||
91 | if (path[0] == '.' && path[1] == '\0') | ||
92 | path = ""; | ||
93 | |||
94 | /* | 82 | /* |
95 | * Find the dirname and basename from the path to be resolved. | 83 | * Iterate over path components in `left'. |
96 | * Change directory to the dirname component. | ||
97 | * lstat the basename part. | ||
98 | * if it is a symlink, read in the value and loop. | ||
99 | * if it is a directory, then change to that directory. | ||
100 | * get the current directory name and append the basename. | ||
101 | */ | 84 | */ |
102 | if (strlcpy(resolved, path, MAXPATHLEN) >= MAXPATHLEN) { | 85 | while (left_len != 0) { |
103 | serrno = ENAMETOOLONG; | 86 | /* |
104 | goto err2; | 87 | * Extract the next path component and adjust `left' |
105 | } | 88 | * and its length. |
106 | loop: | 89 | */ |
107 | q = strrchr(resolved, '/'); | 90 | p = strchr(left, '/'); |
108 | if (q != NULL) { | 91 | s = p ? p : left + left_len; |
109 | p = q + 1; | 92 | if (s - left >= sizeof(next_token)) { |
110 | if (q == resolved) | 93 | errno = ENAMETOOLONG; |
111 | q = "/"; | 94 | return (NULL); |
112 | else { | ||
113 | do { | ||
114 | --q; | ||
115 | } while (q > resolved && *q == '/'); | ||
116 | q[1] = '\0'; | ||
117 | q = resolved; | ||
118 | } | 95 | } |
119 | if (chdir(q) < 0) | 96 | memcpy(next_token, left, s - left); |
120 | goto err1; | 97 | next_token[s - left] = '\0'; |
121 | } else | 98 | left_len -= s - left; |
122 | p = resolved; | 99 | if (p != NULL) |
123 | 100 | memmove(left, s + 1, left_len + 1); | |
124 | /* Deal with the last component. */ | 101 | if (resolved[resolved_len - 1] != '/') { |
125 | if (*p != '\0' && lstat(p, &sb) == 0) { | 102 | if (resolved_len + 1 >= PATH_MAX) { |
126 | if (S_ISLNK(sb.st_mode)) { | 103 | errno = ENAMETOOLONG; |
127 | if (++symlinks > MAXSYMLINKS) { | 104 | return (NULL); |
128 | errno = ELOOP; | ||
129 | goto err1; | ||
130 | } | 105 | } |
131 | if ((n = readlink(p, resolved, MAXPATHLEN-1)) < 0) | 106 | resolved[resolved_len++] = '/'; |
132 | goto err1; | 107 | resolved[resolved_len] = '\0'; |
133 | resolved[n] = '\0'; | ||
134 | goto loop; | ||
135 | } | 108 | } |
136 | if (S_ISDIR(sb.st_mode)) { | 109 | if (next_token[0] == '\0') |
137 | if (chdir(p) < 0) | 110 | continue; |
138 | goto err1; | 111 | else if (strcmp(next_token, ".") == 0) |
139 | p = ""; | 112 | continue; |
113 | else if (strcmp(next_token, "..") == 0) { | ||
114 | /* | ||
115 | * Strip the last path component except when we have | ||
116 | * single "/" | ||
117 | */ | ||
118 | if (resolved_len > 1) { | ||
119 | resolved[resolved_len - 1] = '\0'; | ||
120 | q = strrchr(resolved, '/') + 1; | ||
121 | *q = '\0'; | ||
122 | resolved_len = q - resolved; | ||
123 | } | ||
124 | continue; | ||
140 | } | 125 | } |
141 | } | ||
142 | |||
143 | /* | ||
144 | * Save the last component name and get the full pathname of | ||
145 | * the current directory. | ||
146 | */ | ||
147 | if (strlcpy(wbuf, p, sizeof(wbuf)) >= sizeof(wbuf)) { | ||
148 | errno = ENAMETOOLONG; | ||
149 | goto err1; | ||
150 | } | ||
151 | if (getcwd(resolved, MAXPATHLEN) == NULL) | ||
152 | goto err1; | ||
153 | |||
154 | /* | ||
155 | * Join the two strings together, ensuring that the right thing | ||
156 | * happens if the last component is empty, or the dirname is root. | ||
157 | */ | ||
158 | if (resolved[0] == '/' && resolved[1] == '\0') | ||
159 | needslash = 0; | ||
160 | else | ||
161 | needslash = 1; | ||
162 | 126 | ||
163 | if (*wbuf) { | 127 | /* |
164 | if (strlen(resolved) + strlen(wbuf) + needslash >= MAXPATHLEN) { | 128 | * Append the next path component and lstat() it. If |
129 | * lstat() fails we still can return successfully if | ||
130 | * there are no more path components left. | ||
131 | */ | ||
132 | resolved_len = strlcat(resolved, next_token, PATH_MAX); | ||
133 | if (resolved_len >= PATH_MAX) { | ||
165 | errno = ENAMETOOLONG; | 134 | errno = ENAMETOOLONG; |
166 | goto err1; | 135 | return (NULL); |
167 | } | 136 | } |
168 | if (needslash) { | 137 | if (lstat(resolved, &sb) != 0) { |
169 | if (strlcat(resolved, "/", MAXPATHLEN) >= MAXPATHLEN) { | 138 | if (errno == ENOENT && p == NULL) { |
170 | errno = ENAMETOOLONG; | 139 | errno = serrno; |
171 | goto err1; | 140 | return (resolved); |
172 | } | 141 | } |
142 | return (NULL); | ||
173 | } | 143 | } |
174 | if (strlcat(resolved, wbuf, MAXPATHLEN) >= MAXPATHLEN) { | 144 | if (S_ISLNK(sb.st_mode)) { |
175 | errno = ENAMETOOLONG; | 145 | if (symlinks++ > MAXSYMLINKS) { |
176 | goto err1; | 146 | errno = ELOOP; |
177 | } | 147 | return (NULL); |
178 | } | 148 | } |
149 | slen = readlink(resolved, symlink, sizeof(symlink) - 1); | ||
150 | if (slen < 0) | ||
151 | return (NULL); | ||
152 | symlink[slen] = '\0'; | ||
153 | if (symlink[0] == '/') { | ||
154 | resolved[1] = 0; | ||
155 | resolved_len = 1; | ||
156 | } else if (resolved_len > 1) { | ||
157 | /* Strip the last path component. */ | ||
158 | resolved[resolved_len - 1] = '\0'; | ||
159 | q = strrchr(resolved, '/') + 1; | ||
160 | *q = '\0'; | ||
161 | resolved_len = q - resolved; | ||
162 | } | ||
179 | 163 | ||
180 | /* Go back to where we came from. */ | 164 | /* |
181 | #ifdef HAVE_FCHDIR | 165 | * If there are any path components left, then |
182 | if (fchdir(fd) < 0) { | 166 | * append them to symlink. The result is placed |
183 | #else | 167 | * in `left'. |
184 | if (chdir(start) < 0) { | 168 | */ |
185 | #endif | 169 | if (p != NULL) { |
186 | serrno = errno; | 170 | if (symlink[slen - 1] != '/') { |
187 | goto err2; | 171 | if (slen + 1 >= sizeof(symlink)) { |
172 | errno = ENAMETOOLONG; | ||
173 | return (NULL); | ||
174 | } | ||
175 | symlink[slen] = '/'; | ||
176 | symlink[slen + 1] = 0; | ||
177 | } | ||
178 | left_len = strlcat(symlink, left, sizeof(left)); | ||
179 | if (left_len >= sizeof(left)) { | ||
180 | errno = ENAMETOOLONG; | ||
181 | return (NULL); | ||
182 | } | ||
183 | } | ||
184 | left_len = strlcpy(left, symlink, sizeof(left)); | ||
185 | } | ||
188 | } | 186 | } |
189 | 187 | ||
190 | /* It's okay if the close fails, what's an fd more or less? */ | 188 | /* |
191 | (void)close(fd); | 189 | * Remove trailing slash except when the resolved pathname |
190 | * is a single "/". | ||
191 | */ | ||
192 | if (resolved_len > 1 && resolved[resolved_len - 1] == '/') | ||
193 | resolved[resolved_len - 1] = '\0'; | ||
192 | return (resolved); | 194 | return (resolved); |
193 | |||
194 | err1: serrno = errno; | ||
195 | #ifdef HAVE_FCHDIR | ||
196 | (void)fchdir(fd); | ||
197 | #else | ||
198 | chdir(start); | ||
199 | #endif | ||
200 | err2: (void)close(fd); | ||
201 | errno = serrno; | ||
202 | return (NULL); | ||
203 | } | 195 | } |
204 | #endif /* !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH) */ | 196 | #endif /* !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH) */ |
diff --git a/openbsd-compat/strtoll.c b/openbsd-compat/strtoll.c new file mode 100644 index 000000000..60c276f8a --- /dev/null +++ b/openbsd-compat/strtoll.c | |||
@@ -0,0 +1,151 @@ | |||
1 | /* OPENBSD ORIGINAL: lib/libc/stdlib/strtoll.c */ | ||
2 | |||
3 | /*- | ||
4 | * Copyright (c) 1992 The 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_STRTOLL | ||
34 | |||
35 | #if defined(LIBC_SCCS) && !defined(lint) | ||
36 | static const char rcsid[] = "$OpenBSD: strtoll.c,v 1.4 2005/03/30 18:51:49 pat Exp $"; | ||
37 | #endif /* LIBC_SCCS and not lint */ | ||
38 | |||
39 | #include <sys/types.h> | ||
40 | |||
41 | #include <ctype.h> | ||
42 | #include <errno.h> | ||
43 | #include <limits.h> | ||
44 | #include <stdlib.h> | ||
45 | |||
46 | /* | ||
47 | * Convert a string to a long long. | ||
48 | * | ||
49 | * Ignores `locale' stuff. Assumes that the upper and lower case | ||
50 | * alphabets and digits are each contiguous. | ||
51 | */ | ||
52 | long long | ||
53 | strtoll(const char *nptr, char **endptr, int base) | ||
54 | { | ||
55 | const char *s; | ||
56 | long long acc, cutoff; | ||
57 | int c; | ||
58 | int neg, any, cutlim; | ||
59 | |||
60 | /* | ||
61 | * Skip white space and pick up leading +/- sign if any. | ||
62 | * If base is 0, allow 0x for hex and 0 for octal, else | ||
63 | * assume decimal; if base is already 16, allow 0x. | ||
64 | */ | ||
65 | s = nptr; | ||
66 | do { | ||
67 | c = (unsigned char) *s++; | ||
68 | } while (isspace(c)); | ||
69 | if (c == '-') { | ||
70 | neg = 1; | ||
71 | c = *s++; | ||
72 | } else { | ||
73 | neg = 0; | ||
74 | if (c == '+') | ||
75 | c = *s++; | ||
76 | } | ||
77 | if ((base == 0 || base == 16) && | ||
78 | c == '0' && (*s == 'x' || *s == 'X')) { | ||
79 | c = s[1]; | ||
80 | s += 2; | ||
81 | base = 16; | ||
82 | } | ||
83 | if (base == 0) | ||
84 | base = c == '0' ? 8 : 10; | ||
85 | |||
86 | /* | ||
87 | * Compute the cutoff value between legal numbers and illegal | ||
88 | * numbers. That is the largest legal value, divided by the | ||
89 | * base. An input number that is greater than this value, if | ||
90 | * followed by a legal input character, is too big. One that | ||
91 | * is equal to this value may be valid or not; the limit | ||
92 | * between valid and invalid numbers is then based on the last | ||
93 | * digit. For instance, if the range for long longs is | ||
94 | * [-9223372036854775808..9223372036854775807] and the input base | ||
95 | * is 10, cutoff will be set to 922337203685477580 and cutlim to | ||
96 | * either 7 (neg==0) or 8 (neg==1), meaning that if we have | ||
97 | * accumulated a value > 922337203685477580, or equal but the | ||
98 | * next digit is > 7 (or 8), the number is too big, and we will | ||
99 | * return a range error. | ||
100 | * | ||
101 | * Set any if any `digits' consumed; make it negative to indicate | ||
102 | * overflow. | ||
103 | */ | ||
104 | cutoff = neg ? LLONG_MIN : LLONG_MAX; | ||
105 | cutlim = cutoff % base; | ||
106 | cutoff /= base; | ||
107 | if (neg) { | ||
108 | if (cutlim > 0) { | ||
109 | cutlim -= base; | ||
110 | cutoff += 1; | ||
111 | } | ||
112 | cutlim = -cutlim; | ||
113 | } | ||
114 | for (acc = 0, any = 0;; c = (unsigned char) *s++) { | ||
115 | if (isdigit(c)) | ||
116 | c -= '0'; | ||
117 | else if (isalpha(c)) | ||
118 | c -= isupper(c) ? 'A' - 10 : 'a' - 10; | ||
119 | else | ||
120 | break; | ||
121 | if (c >= base) | ||
122 | break; | ||
123 | if (any < 0) | ||
124 | continue; | ||
125 | if (neg) { | ||
126 | if (acc < cutoff || (acc == cutoff && c > cutlim)) { | ||
127 | any = -1; | ||
128 | acc = LLONG_MIN; | ||
129 | errno = ERANGE; | ||
130 | } else { | ||
131 | any = 1; | ||
132 | acc *= base; | ||
133 | acc -= c; | ||
134 | } | ||
135 | } else { | ||
136 | if (acc > cutoff || (acc == cutoff && c > cutlim)) { | ||
137 | any = -1; | ||
138 | acc = LLONG_MAX; | ||
139 | errno = ERANGE; | ||
140 | } else { | ||
141 | any = 1; | ||
142 | acc *= base; | ||
143 | acc += c; | ||
144 | } | ||
145 | } | ||
146 | } | ||
147 | if (endptr != 0) | ||
148 | *endptr = (char *) (any ? s - 1 : nptr); | ||
149 | return (acc); | ||
150 | } | ||
151 | #endif /* HAVE_STRTOLL */ | ||
diff --git a/openbsd-compat/strtonum.c b/openbsd-compat/strtonum.c new file mode 100644 index 000000000..b681ed83b --- /dev/null +++ b/openbsd-compat/strtonum.c | |||
@@ -0,0 +1,69 @@ | |||
1 | /* OPENBSD ORIGINAL: lib/libc/stdlib/strtonum.c */ | ||
2 | |||
3 | /* $OpenBSD: strtonum.c,v 1.6 2004/08/03 19:38:01 millert Exp $ */ | ||
4 | |||
5 | /* | ||
6 | * Copyright (c) 2004 Ted Unangst and Todd Miller | ||
7 | * All rights reserved. | ||
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 | #include "includes.h" | ||
23 | #ifndef HAVE_STRTONUM | ||
24 | #include <limits.h> | ||
25 | |||
26 | #define INVALID 1 | ||
27 | #define TOOSMALL 2 | ||
28 | #define TOOLARGE 3 | ||
29 | |||
30 | long long | ||
31 | strtonum(const char *numstr, long long minval, long long maxval, | ||
32 | const char **errstrp) | ||
33 | { | ||
34 | long long ll = 0; | ||
35 | char *ep; | ||
36 | int error = 0; | ||
37 | struct errval { | ||
38 | const char *errstr; | ||
39 | int err; | ||
40 | } ev[4] = { | ||
41 | { NULL, 0 }, | ||
42 | { "invalid", EINVAL }, | ||
43 | { "too small", ERANGE }, | ||
44 | { "too large", ERANGE }, | ||
45 | }; | ||
46 | |||
47 | ev[0].err = errno; | ||
48 | errno = 0; | ||
49 | if (minval > maxval) | ||
50 | error = INVALID; | ||
51 | else { | ||
52 | ll = strtoll(numstr, &ep, 10); | ||
53 | if (numstr == ep || *ep != '\0') | ||
54 | error = INVALID; | ||
55 | else if ((ll == LLONG_MIN && errno == ERANGE) || ll < minval) | ||
56 | error = TOOSMALL; | ||
57 | else if ((ll == LLONG_MAX && errno == ERANGE) || ll > maxval) | ||
58 | error = TOOLARGE; | ||
59 | } | ||
60 | if (errstrp != NULL) | ||
61 | *errstrp = ev[error].errstr; | ||
62 | errno = ev[error].err; | ||
63 | if (error) | ||
64 | ll = 0; | ||
65 | |||
66 | return (ll); | ||
67 | } | ||
68 | |||
69 | #endif /* HAVE_STRTONUM */ | ||
diff --git a/openbsd-compat/xcrypt.c b/openbsd-compat/xcrypt.c index c3cea3c86..9afa0b9f2 100644 --- a/openbsd-compat/xcrypt.c +++ b/openbsd-compat/xcrypt.c | |||
@@ -93,6 +93,11 @@ shadow_pw(struct passwd *pw) | |||
93 | if (spw != NULL) | 93 | if (spw != NULL) |
94 | pw_password = spw->sp_pwdp; | 94 | pw_password = spw->sp_pwdp; |
95 | # endif | 95 | # endif |
96 | |||
97 | #if defined(HAVE_LIBIAF) && !defined(BROKEN_LIBIAF) | ||
98 | return(get_iaf_password(pw)); | ||
99 | #endif | ||
100 | |||
96 | # if defined(HAVE_GETPWANAM) && !defined(DISABLE_SHADOW) | 101 | # if defined(HAVE_GETPWANAM) && !defined(DISABLE_SHADOW) |
97 | struct passwd_adjunct *spw; | 102 | struct passwd_adjunct *spw; |
98 | if (issecure() && (spw = getpwanam(pw->pw_name)) != NULL) | 103 | if (issecure() && (spw = getpwanam(pw->pw_name)) != NULL) |