summaryrefslogtreecommitdiff
path: root/openbsd-compat
diff options
context:
space:
mode:
Diffstat (limited to 'openbsd-compat')
-rw-r--r--openbsd-compat/Makefile.in4
-rw-r--r--openbsd-compat/bsd-arc4random.c12
-rw-r--r--openbsd-compat/bsd-closefrom.c100
-rw-r--r--openbsd-compat/bsd-misc.c7
-rw-r--r--openbsd-compat/bsd-misc.h2
-rw-r--r--openbsd-compat/getrrsetbyname.c4
-rw-r--r--openbsd-compat/openbsd-compat.h6
-rw-r--r--openbsd-compat/port-aix.c88
-rw-r--r--openbsd-compat/port-aix.h6
-rw-r--r--openbsd-compat/sys-queue.h19
-rw-r--r--openbsd-compat/xmmap.c11
11 files changed, 226 insertions, 33 deletions
diff --git a/openbsd-compat/Makefile.in b/openbsd-compat/Makefile.in
index 5de20abbc..0f34f2240 100644
--- a/openbsd-compat/Makefile.in
+++ b/openbsd-compat/Makefile.in
@@ -1,4 +1,4 @@
1# $Id: Makefile.in,v 1.30 2004/01/21 06:07:23 djm Exp $ 1# $Id: Makefile.in,v 1.31 2004/08/15 08:41:00 djm Exp $
2 2
3sysconfdir=@sysconfdir@ 3sysconfdir=@sysconfdir@
4piddir=@piddir@ 4piddir=@piddir@
@@ -18,7 +18,7 @@ LDFLAGS=-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 strtoul.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-openpty.o bsd-snprintf.o bsd-waitpid.o fake-rfc2553.o xmmap.o xcrypt.o 21COMPAT=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
22 22
23PORTS=port-irix.o port-aix.o 23PORTS=port-irix.o port-aix.o
24 24
diff --git a/openbsd-compat/bsd-arc4random.c b/openbsd-compat/bsd-arc4random.c
index 22003ff0a..5284e1af8 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.8 2004/02/17 05:49:55 djm Exp $"); 20RCSID("$Id: bsd-arc4random.c,v 1.9 2004/07/18 23:30:40 djm Exp $");
21 21
22#ifndef HAVE_ARC4RANDOM 22#ifndef HAVE_ARC4RANDOM
23 23
@@ -56,13 +56,21 @@ unsigned int arc4random(void)
56void arc4random_stir(void) 56void arc4random_stir(void)
57{ 57{
58 unsigned char rand_buf[SEED_SIZE]; 58 unsigned char rand_buf[SEED_SIZE];
59 int i;
59 60
60 memset(&rc4, 0, sizeof(rc4)); 61 memset(&rc4, 0, sizeof(rc4));
61 if (RAND_bytes(rand_buf, sizeof(rand_buf)) <= 0) 62 if (RAND_bytes(rand_buf, sizeof(rand_buf)) <= 0)
62 fatal("Couldn't obtain random bytes (error %ld)", 63 fatal("Couldn't obtain random bytes (error %ld)",
63 ERR_get_error()); 64 ERR_get_error());
64 RC4_set_key(&rc4, sizeof(rand_buf), rand_buf); 65 RC4_set_key(&rc4, sizeof(rand_buf), rand_buf);
65 RC4(&rc4, sizeof(rand_buf), rand_buf, rand_buf); 66
67 /*
68 * Discard early keystream, as per recommendations in:
69 * http://www.wisdom.weizmann.ac.il/~itsik/RC4/Papers/Rc4_ksa.ps
70 */
71 for(i = 0; i <= 256; i += sizeof(rand_buf))
72 RC4(&rc4, sizeof(rand_buf), rand_buf, rand_buf);
73
66 memset(rand_buf, 0, sizeof(rand_buf)); 74 memset(rand_buf, 0, sizeof(rand_buf));
67 75
68 rc4_ready = REKEY_BYTES; 76 rc4_ready = REKEY_BYTES;
diff --git a/openbsd-compat/bsd-closefrom.c b/openbsd-compat/bsd-closefrom.c
new file mode 100644
index 000000000..61a9fa391
--- /dev/null
+++ b/openbsd-compat/bsd-closefrom.c
@@ -0,0 +1,100 @@
1/*
2 * Copyright (c) 2004 Todd C. Miller <Todd.Miller@courtesan.com>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include "includes.h"
18
19#ifndef HAVE_CLOSEFROM
20
21#include <sys/types.h>
22#include <sys/param.h>
23#include <unistd.h>
24#include <stdio.h>
25#include <limits.h>
26#include <stdlib.h>
27#include <stddef.h>
28#ifdef HAVE_DIRENT_H
29# include <dirent.h>
30# define NAMLEN(dirent) strlen((dirent)->d_name)
31#else
32# define dirent direct
33# define NAMLEN(dirent) (dirent)->d_namlen
34# ifdef HAVE_SYS_NDIR_H
35# include <sys/ndir.h>
36# endif
37# ifdef HAVE_SYS_DIR_H
38# include <sys/dir.h>
39# endif
40# ifdef HAVE_NDIR_H
41# include <ndir.h>
42# endif
43#endif
44
45#ifndef OPEN_MAX
46# define OPEN_MAX 256
47#endif
48
49RCSID("$Id: bsd-closefrom.c,v 1.1 2004/08/15 08:41:00 djm Exp $");
50
51#ifndef lint
52static const char sudorcsid[] = "$Sudo: closefrom.c,v 1.6 2004/06/01 20:51:56 millert Exp $";
53#endif /* lint */
54
55/*
56 * Close all file descriptors greater than or equal to lowfd.
57 */
58void
59closefrom(int lowfd)
60{
61 long fd, maxfd;
62#if defined(HAVE_DIRFD) && defined(HAVE_PROC_PID)
63 char fdpath[PATH_MAX], *endp;
64 struct dirent *dent;
65 DIR *dirp;
66 int len;
67
68 /* Check for a /proc/$$/fd directory. */
69 len = snprintf(fdpath, sizeof(fdpath), "/proc/%ld/fd", (long)getpid());
70 if (len != -1 && len <= sizeof(fdpath) && (dirp = opendir(fdpath))) {
71 while ((dent = readdir(dirp)) != NULL) {
72 fd = strtol(dent->d_name, &endp, 10);
73 if (dent->d_name != endp && *endp == '\0' &&
74 fd >= 0 && fd < INT_MAX && fd >= lowfd && fd != dirfd(dirp))
75 (void) close((int) fd);
76 }
77 (void) closedir(dirp);
78 } else
79#endif
80 {
81 /*
82 * Fall back on sysconf() or getdtablesize(). We avoid checking
83 * resource limits since it is possible to open a file descriptor
84 * and then drop the rlimit such that it is below the open fd.
85 */
86#ifdef HAVE_SYSCONF
87 maxfd = sysconf(_SC_OPEN_MAX);
88#else
89 maxfd = getdtablesize();
90#endif /* HAVE_SYSCONF */
91 if (maxfd < 0)
92 maxfd = OPEN_MAX;
93
94 for (fd = lowfd; fd < maxfd; fd++)
95 (void) close((int) fd);
96 }
97}
98
99#endif /* HAVE_CLOSEFROM */
100
diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c
index 7b06786f5..1b276b4f4 100644
--- a/openbsd-compat/bsd-misc.c
+++ b/openbsd-compat/bsd-misc.c
@@ -1,3 +1,4 @@
1
1/* 2/*
2 * Copyright (c) 1999-2004 Damien Miller <djm@mindrot.org> 3 * Copyright (c) 1999-2004 Damien Miller <djm@mindrot.org>
3 * 4 *
@@ -17,7 +18,11 @@
17#include "includes.h" 18#include "includes.h"
18#include "xmalloc.h" 19#include "xmalloc.h"
19 20
20RCSID("$Id: bsd-misc.c,v 1.21 2004/02/17 05:49:55 djm Exp $"); 21RCSID("$Id: bsd-misc.c,v 1.25 2004/08/15 08:41:00 djm Exp $");
22
23#ifndef HAVE___PROGNAME
24char *__progname;
25#endif
21 26
22/* 27/*
23 * NB. duplicate __progname in case it is an alias for argv[0] 28 * NB. duplicate __progname in case it is an alias for argv[0]
diff --git a/openbsd-compat/bsd-misc.h b/openbsd-compat/bsd-misc.h
index 009739b14..33a1d707f 100644
--- a/openbsd-compat/bsd-misc.h
+++ b/openbsd-compat/bsd-misc.h
@@ -1,4 +1,4 @@
1/* $Id: bsd-misc.h,v 1.15 2004/03/08 11:59:03 dtucker Exp $ */ 1/* $Id: bsd-misc.h,v 1.17 2004/08/15 08:41:00 djm 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>
diff --git a/openbsd-compat/getrrsetbyname.c b/openbsd-compat/getrrsetbyname.c
index 66d18142e..660427c1f 100644
--- a/openbsd-compat/getrrsetbyname.c
+++ b/openbsd-compat/getrrsetbyname.c
@@ -53,6 +53,10 @@
53 53
54#define ANSWER_BUFFER_SIZE 1024*64 54#define ANSWER_BUFFER_SIZE 1024*64
55 55
56#if defined(HAVE_DECL_H_ERRNO) && !HAVE_DECL_H_ERRNO
57extern int h_errno;
58#endif
59
56struct dns_query { 60struct dns_query {
57 char *name; 61 char *name;
58 u_int16_t type; 62 u_int16_t type;
diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h
index 6be1bcda4..89d1454e0 100644
--- a/openbsd-compat/openbsd-compat.h
+++ b/openbsd-compat/openbsd-compat.h
@@ -1,4 +1,4 @@
1/* $Id: openbsd-compat.h,v 1.25 2004/01/21 06:07:23 djm Exp $ */ 1/* $Id: openbsd-compat.h,v 1.26 2004/08/15 08:41:00 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.
@@ -48,6 +48,10 @@ char *basename(const char *path);
48int bindresvport_sa(int sd, struct sockaddr *sa); 48int bindresvport_sa(int sd, struct sockaddr *sa);
49#endif 49#endif
50 50
51#ifndef HAVE_CLOSEFROM
52void closefrom(int);
53#endif
54
51#ifndef HAVE_GETCWD 55#ifndef HAVE_GETCWD
52char *getcwd(char *pt, size_t size); 56char *getcwd(char *pt, size_t size);
53#endif 57#endif
diff --git a/openbsd-compat/port-aix.c b/openbsd-compat/port-aix.c
index 2895f0d44..78f4faea3 100644
--- a/openbsd-compat/port-aix.c
+++ b/openbsd-compat/port-aix.c
@@ -101,7 +101,7 @@ aix_remove_embedded_newlines(char *p)
101int 101int
102sys_auth_passwd(Authctxt *ctxt, const char *password) 102sys_auth_passwd(Authctxt *ctxt, const char *password)
103{ 103{
104 char *authmsg = NULL, *host, *msg, *name = ctxt->pw->pw_name; 104 char *authmsg = NULL, *msg, *name = ctxt->pw->pw_name;
105 int authsuccess = 0, expired, reenter, result; 105 int authsuccess = 0, expired, reenter, result;
106 106
107 do { 107 do {
@@ -115,30 +115,21 @@ sys_auth_passwd(Authctxt *ctxt, const char *password)
115 if (result == 0) { 115 if (result == 0) {
116 authsuccess = 1; 116 authsuccess = 1;
117 117
118 host = (char *)get_canonical_hostname(options.use_dns);
119
120 /* 118 /*
121 * Record successful login. We don't have a pty yet, so just 119 * Record successful login. We don't have a pty yet, so just
122 * label the line as "ssh" 120 * label the line as "ssh"
123 */ 121 */
124 aix_setauthdb(name); 122 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 123
133 /* 124 /*
134 * Check if the user's password is expired. 125 * Check if the user's password is expired.
135 */ 126 */
136 expired = passwdexpired(name, &msg); 127 expired = passwdexpired(name, &msg);
137 if (msg && *msg) { 128 if (msg && *msg) {
138 buffer_append(&loginmsg, msg, strlen(msg)); 129 buffer_append(&loginmsg, msg, strlen(msg));
139 aix_remove_embedded_newlines(msg); 130 aix_remove_embedded_newlines(msg);
140 } 131 }
141 debug3("AIX/passwdexpired returned %d msg %.100s", expired, msg); 132 debug3("AIX/passwdexpired returned %d msg %.100s", expired, msg);
142 133
143 switch (expired) { 134 switch (expired) {
144 case 0: /* password not expired */ 135 case 0: /* password not expired */
@@ -163,7 +154,70 @@ sys_auth_passwd(Authctxt *ctxt, const char *password)
163 154
164 return authsuccess; 155 return authsuccess;
165} 156}
166 157
158/*
159 * Check if specified account is permitted to log in.
160 * Returns 1 if login is allowed, 0 if not allowed.
161 */
162int
163sys_auth_allowed_user(struct passwd *pw)
164{
165 char *msg = NULL;
166 int result, permitted = 0;
167 struct stat st;
168
169 /*
170 * Don't perform checks for root account (PermitRootLogin controls
171 * logins via * ssh) or if running as non-root user (since
172 * loginrestrictions will always fail due to insufficient privilege).
173 */
174 if (pw->pw_uid == 0 || geteuid() != 0) {
175 debug3("%s: not checking", __func__);
176 return 1;
177 }
178
179 result = loginrestrictions(pw->pw_name, S_RLOGIN, NULL, &msg);
180 if (result == 0)
181 permitted = 1;
182 /*
183 * If restricted because /etc/nologin exists, the login will be denied
184 * in session.c after the nologin message is sent, so allow for now
185 * and do not append the returned message.
186 */
187 if (result == -1 && errno == EPERM && stat(_PATH_NOLOGIN, &st) == 0)
188 permitted = 1;
189 else if (msg != NULL)
190 buffer_append(&loginmsg, msg, strlen(msg));
191 if (msg == NULL)
192 msg = xstrdup("(none)");
193 aix_remove_embedded_newlines(msg);
194 debug3("AIX/loginrestrictions returned %d msg %.100s", result, msg);
195
196 if (!permitted)
197 logit("Login restricted for %s: %.100s", pw->pw_name, msg);
198 xfree(msg);
199 return permitted;
200}
201
202int
203sys_auth_record_login(const char *user, const char *host, const char *ttynm)
204{
205 char *msg;
206 int success = 0;
207
208 aix_setauthdb(user);
209 if (loginsuccess((char *)user, host, ttynm, &msg) == 0) {
210 success = 1;
211 if (msg != NULL) {
212 debug("AIX/loginsuccess: msg %s", __func__, msg);
213 buffer_append(&loginmsg, msg, strlen(msg));
214 xfree(msg);
215 }
216 }
217 aix_restoreauthdb();
218 return (success);
219}
220
167# ifdef CUSTOM_FAILED_LOGIN 221# ifdef CUSTOM_FAILED_LOGIN
168/* 222/*
169 * record_failed_login: generic "login failed" interface function 223 * record_failed_login: generic "login failed" interface function
diff --git a/openbsd-compat/port-aix.h b/openbsd-compat/port-aix.h
index 3118af9a9..29e9751ce 100644
--- a/openbsd-compat/port-aix.h
+++ b/openbsd-compat/port-aix.h
@@ -1,4 +1,4 @@
1/* $Id: port-aix.h,v 1.19 2004/02/10 04:27:35 dtucker Exp $ */ 1/* $Id: port-aix.h,v 1.21 2004/08/14 14:09:12 dtucker Exp $ */
2 2
3/* 3/*
4 * 4 *
@@ -63,6 +63,10 @@ void aix_usrinfo(struct passwd *);
63 63
64#ifdef WITH_AIXAUTHENTICATE 64#ifdef WITH_AIXAUTHENTICATE
65# define CUSTOM_SYS_AUTH_PASSWD 1 65# define CUSTOM_SYS_AUTH_PASSWD 1
66# define CUSTOM_SYS_AUTH_ALLOWED_USER 1
67int sys_auth_allowed_user(struct passwd *);
68# define CUSTOM_SYS_AUTH_RECORD_LOGIN 1
69int sys_auth_record_login(const char *, const char *, const char *);
66# define CUSTOM_FAILED_LOGIN 1 70# define CUSTOM_FAILED_LOGIN 1
67void record_failed_login(const char *, const char *); 71void record_failed_login(const char *, const char *);
68#endif 72#endif
diff --git a/openbsd-compat/sys-queue.h b/openbsd-compat/sys-queue.h
index 8ff19e452..c49a94650 100644
--- a/openbsd-compat/sys-queue.h
+++ b/openbsd-compat/sys-queue.h
@@ -1,6 +1,6 @@
1/* OPENBSD ORIGINAL: sys/sys/queue.h */ 1/* OPENBSD ORIGINAL: sys/sys/queue.h */
2 2
3/* $OpenBSD: queue.h,v 1.23 2003/06/02 23:28:21 millert Exp $ */ 3/* $OpenBSD: queue.h,v 1.25 2004/04/08 16:08:21 henning Exp $ */
4/* $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 $ */
5 5
6/* 6/*
@@ -38,12 +38,13 @@
38#define _FAKE_QUEUE_H_ 38#define _FAKE_QUEUE_H_
39 39
40/* 40/*
41 * Ignore all <sys/queue.h> since older platforms have broken/incomplete 41 * Require for OS/X and other platforms that have old/broken/incomplete
42 * <sys/queue.h> that are too hard to work around. 42 * <sys/queue.h>.
43 */ 43 */
44#undef SLIST_HEAD 44#undef SLIST_HEAD
45#undef SLIST_HEAD_INITIALIZER 45#undef SLIST_HEAD_INITIALIZER
46#undef SLIST_ENTRY 46#undef SLIST_ENTRY
47#undef SLIST_FOREACH_PREVPTR
47#undef SLIST_FIRST 48#undef SLIST_FIRST
48#undef SLIST_END 49#undef SLIST_END
49#undef SLIST_EMPTY 50#undef SLIST_EMPTY
@@ -54,6 +55,7 @@
54#undef SLIST_INSERT_HEAD 55#undef SLIST_INSERT_HEAD
55#undef SLIST_REMOVE_HEAD 56#undef SLIST_REMOVE_HEAD
56#undef SLIST_REMOVE 57#undef SLIST_REMOVE
58#undef SLIST_REMOVE_NEXT
57#undef LIST_HEAD 59#undef LIST_HEAD
58#undef LIST_HEAD_INITIALIZER 60#undef LIST_HEAD_INITIALIZER
59#undef LIST_ENTRY 61#undef LIST_ENTRY
@@ -194,6 +196,11 @@ struct { \
194 (var) != SLIST_END(head); \ 196 (var) != SLIST_END(head); \
195 (var) = SLIST_NEXT(var, field)) 197 (var) = SLIST_NEXT(var, field))
196 198
199#define SLIST_FOREACH_PREVPTR(var, varp, head, field) \
200 for ((varp) = &SLIST_FIRST((head)); \
201 ((var) = *(varp)) != SLIST_END(head); \
202 (varp) = &SLIST_NEXT((var), field))
203
197/* 204/*
198 * Singly-linked List functions. 205 * Singly-linked List functions.
199 */ 206 */
@@ -211,6 +218,10 @@ struct { \
211 (head)->slh_first = (elm); \ 218 (head)->slh_first = (elm); \
212} while (0) 219} while (0)
213 220
221#define SLIST_REMOVE_NEXT(head, elm, field) do { \
222 (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \
223} while (0)
224
214#define SLIST_REMOVE_HEAD(head, field) do { \ 225#define SLIST_REMOVE_HEAD(head, field) do { \
215 (head)->slh_first = (head)->slh_first->field.sle_next; \ 226 (head)->slh_first = (head)->slh_first->field.sle_next; \
216} while (0) 227} while (0)
@@ -400,7 +411,7 @@ struct { \
400 (var) != TAILQ_END(head); \ 411 (var) != TAILQ_END(head); \
401 (var) = TAILQ_NEXT(var, field)) 412 (var) = TAILQ_NEXT(var, field))
402 413
403#define TAILQ_FOREACH_REVERSE(var, head, field, headname) \ 414#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
404 for((var) = TAILQ_LAST(head, headname); \ 415 for((var) = TAILQ_LAST(head, headname); \
405 (var) != TAILQ_END(head); \ 416 (var) != TAILQ_END(head); \
406 (var) = TAILQ_PREV(var, headname, field)) 417 (var) = TAILQ_PREV(var, headname, field))
diff --git a/openbsd-compat/xmmap.c b/openbsd-compat/xmmap.c
index 9dc4340a7..c8d59dee0 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.3 2003/06/02 02:25:27 tim Exp $ */ 26/* $Id: xmmap.c,v 1.5 2004/08/14 13:55:38 dtucker Exp $ */
27 27
28#include "includes.h" 28#include "includes.h"
29 29
@@ -40,25 +40,28 @@ void *xmmap(size_t size)
40#ifdef HAVE_MMAP 40#ifdef HAVE_MMAP
41# ifdef MAP_ANON 41# ifdef MAP_ANON
42 address = mmap(NULL, size, PROT_WRITE|PROT_READ, MAP_ANON|MAP_SHARED, 42 address = mmap(NULL, size, PROT_WRITE|PROT_READ, MAP_ANON|MAP_SHARED,
43 -1, 0); 43 -1, (off_t)0);
44# else 44# else
45 address = mmap(NULL, size, PROT_WRITE|PROT_READ, MAP_SHARED, 45 address = mmap(NULL, size, PROT_WRITE|PROT_READ, MAP_SHARED,
46 open("/dev/zero", O_RDWR), 0); 46 open("/dev/zero", O_RDWR), (off_t)0);
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 == 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 54
55 old_umask = umask(0177);
54 tmpfd = mkstemp(tmpname); 56 tmpfd = mkstemp(tmpname);
57 umask(old_umask);
55 if (tmpfd == -1) 58 if (tmpfd == -1)
56 fatal("mkstemp(\"%s\"): %s", 59 fatal("mkstemp(\"%s\"): %s",
57 MM_SWAP_TEMPLATE, strerror(errno)); 60 MM_SWAP_TEMPLATE, strerror(errno));
58 unlink(tmpname); 61 unlink(tmpname);
59 ftruncate(tmpfd, size); 62 ftruncate(tmpfd, size);
60 address = mmap(NULL, size, PROT_WRITE|PROT_READ, MAP_SHARED, 63 address = mmap(NULL, size, PROT_WRITE|PROT_READ, MAP_SHARED,
61 tmpfd, 0); 64 tmpfd, (off_t)0);
62 close(tmpfd); 65 close(tmpfd);
63 } 66 }
64 67