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/base64.c9
-rw-r--r--openbsd-compat/base64.h11
-rw-r--r--openbsd-compat/basename.c73
-rw-r--r--openbsd-compat/basename.h12
-rw-r--r--openbsd-compat/bsd-arc4random.c4
-rw-r--r--openbsd-compat/bsd-cray.h6
-rw-r--r--openbsd-compat/bsd-cygwin_util.c72
-rw-r--r--openbsd-compat/bsd-getpeereid.c4
-rw-r--r--openbsd-compat/bsd-misc.c43
-rw-r--r--openbsd-compat/bsd-misc.h11
-rw-r--r--openbsd-compat/fake-getaddrinfo.c28
-rw-r--r--openbsd-compat/fake-getaddrinfo.h2
-rw-r--r--openbsd-compat/getcwd.c4
-rw-r--r--openbsd-compat/getopt.c5
-rw-r--r--openbsd-compat/mktemp.c4
-rw-r--r--openbsd-compat/mktemp.h6
-rw-r--r--openbsd-compat/openbsd-compat.h4
-rw-r--r--openbsd-compat/port-aix.h11
-rw-r--r--openbsd-compat/setenv.c5
-rw-r--r--openbsd-compat/setproctitle.c281
-rw-r--r--openbsd-compat/setproctitle.h3
-rw-r--r--openbsd-compat/sys-tree.h8
-rw-r--r--openbsd-compat/vis.c232
-rw-r--r--openbsd-compat/vis.h91
25 files changed, 812 insertions, 121 deletions
diff --git a/openbsd-compat/Makefile.in b/openbsd-compat/Makefile.in
index 5229e7e20..8615e3633 100644
--- a/openbsd-compat/Makefile.in
+++ b/openbsd-compat/Makefile.in
@@ -1,4 +1,4 @@
1# $Id: Makefile.in,v 1.23 2002/09/12 00:33:02 djm Exp $ 1# $Id: Makefile.in,v 1.25 2003/02/24 01:55:56 djm Exp $
2 2
3sysconfdir=@sysconfdir@ 3sysconfdir=@sysconfdir@
4piddir=@piddir@ 4piddir=@piddir@
@@ -16,7 +16,7 @@ RANLIB=@RANLIB@
16INSTALL=@INSTALL@ 16INSTALL=@INSTALL@
17LDFLAGS=-L. @LDFLAGS@ 17LDFLAGS=-L. @LDFLAGS@
18 18
19OPENBSD=base64.o bindresvport.o daemon.o dirname.o getcwd.o getgrouplist.o getopt.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 19OPENBSD=base64.o basename.o bindresvport.o daemon.o dirname.o getcwd.o getgrouplist.o getopt.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o readpassphrase.o realpath.o rresvport.o setenv.o setproctitle.o sigact.o strlcat.o strlcpy.o strmode.o strsep.o vis.o
20 20
21COMPAT=bsd-arc4random.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o bsd-misc.o bsd-nextstep.o bsd-snprintf.o bsd-waitpid.o fake-getaddrinfo.o fake-getnameinfo.o xmmap.o 21COMPAT=bsd-arc4random.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o bsd-misc.o bsd-nextstep.o bsd-snprintf.o bsd-waitpid.o fake-getaddrinfo.o fake-getnameinfo.o xmmap.o
22 22
diff --git a/openbsd-compat/base64.c b/openbsd-compat/base64.c
index 005170b80..91a5ab0ed 100644
--- a/openbsd-compat/base64.c
+++ b/openbsd-compat/base64.c
@@ -44,7 +44,7 @@
44 44
45#include "includes.h" 45#include "includes.h"
46 46
47#if !defined(HAVE_B64_NTOP) && !defined(HAVE___B64_NTOP) 47#if (!defined(HAVE_B64_NTOP) && !defined(HAVE___B64_NTOP)) || (!defined(HAVE_B64_PTON) && !defined(HAVE___B64_PTON))
48 48
49#include <sys/types.h> 49#include <sys/types.h>
50#include <sys/param.h> 50#include <sys/param.h>
@@ -130,6 +130,7 @@ static const char Pad64 = '=';
130 characters followed by one "=" padding character. 130 characters followed by one "=" padding character.
131 */ 131 */
132 132
133#if !defined(HAVE_B64_NTOP) && !defined(HAVE___B64_NTOP)
133int 134int
134b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize) 135b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize)
135{ 136{
@@ -190,6 +191,9 @@ b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize)
190 target[datalength] = '\0'; /* Returned value doesn't count \0. */ 191 target[datalength] = '\0'; /* Returned value doesn't count \0. */
191 return (datalength); 192 return (datalength);
192} 193}
194#endif /* !defined(HAVE_B64_NTOP) && !defined(HAVE___B64_NTOP) */
195
196#if !defined(HAVE_B64_PTON) && !defined(HAVE___B64_PTON)
193 197
194/* skips all whitespace anywhere. 198/* skips all whitespace anywhere.
195 converts characters, four at a time, starting at (or after) 199 converts characters, four at a time, starting at (or after)
@@ -314,4 +318,5 @@ b64_pton(char const *src, u_char *target, size_t targsize)
314 return (tarindex); 318 return (tarindex);
315} 319}
316 320
317#endif /* !defined(HAVE_B64_NTOP) && !defined(HAVE___B64_NTOP) */ 321#endif /* !defined(HAVE_B64_PTON) && !defined(HAVE___B64_PTON) */
322#endif
diff --git a/openbsd-compat/base64.h b/openbsd-compat/base64.h
index c92e70ea0..72db3ffc7 100644
--- a/openbsd-compat/base64.h
+++ b/openbsd-compat/base64.h
@@ -1,4 +1,4 @@
1/* $Id: base64.h,v 1.3 2002/02/26 16:59:59 stevesk Exp $ */ 1/* $Id: base64.h,v 1.4 2003/02/24 04:45:43 djm Exp $ */
2 2
3#ifndef _BSD_BASE64_H 3#ifndef _BSD_BASE64_H
4#define _BSD_BASE64_H 4#define _BSD_BASE64_H
@@ -9,10 +9,15 @@
9# ifndef HAVE_B64_NTOP 9# ifndef HAVE_B64_NTOP
10int b64_ntop(u_char const *src, size_t srclength, char *target, 10int b64_ntop(u_char const *src, size_t srclength, char *target,
11 size_t targsize); 11 size_t targsize);
12int b64_pton(char const *src, u_char *target, size_t targsize);
13# endif /* !HAVE_B64_NTOP */ 12# endif /* !HAVE_B64_NTOP */
14# define __b64_ntop b64_ntop 13# define __b64_ntop b64_ntop
15# define __b64_pton b64_pton
16#endif /* HAVE___B64_NTOP */ 14#endif /* HAVE___B64_NTOP */
17 15
16#ifndef HAVE___B64_PTON
17# ifndef HAVE_B64_PTON
18int b64_pton(char const *src, u_char *target, size_t targsize);
19# endif /* !HAVE_B64_PTON */
20# define __b64_pton b64_pton
21#endif /* HAVE___B64_PTON */
22
18#endif /* _BSD_BASE64_H */ 23#endif /* _BSD_BASE64_H */
diff --git a/openbsd-compat/basename.c b/openbsd-compat/basename.c
new file mode 100644
index 000000000..5a3823bc5
--- /dev/null
+++ b/openbsd-compat/basename.c
@@ -0,0 +1,73 @@
1/* $OpenBSD: basename.c,v 1.8 2002/06/09 05:03:59 deraadt Exp $ */
2
3/*
4 * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
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. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29#include "includes.h"
30
31#if !defined(HAVE_BASENAME)
32
33#ifndef lint
34static char rcsid[] = "$OpenBSD: basename.c,v 1.8 2002/06/09 05:03:59 deraadt Exp $";
35#endif /* not lint */
36
37char *
38basename(const char *path)
39{
40 static char bname[MAXPATHLEN];
41 register const char *endp, *startp;
42
43 /* Empty or NULL string gets treated as "." */
44 if (path == NULL || *path == '\0') {
45 (void)strlcpy(bname, ".", sizeof bname);
46 return(bname);
47 }
48
49 /* Strip trailing slashes */
50 endp = path + strlen(path) - 1;
51 while (endp > path && *endp == '/')
52 endp--;
53
54 /* All slashes become "/" */
55 if (endp == path && *endp == '/') {
56 (void)strlcpy(bname, "/", sizeof bname);
57 return(bname);
58 }
59
60 /* Find the start of the base */
61 startp = endp;
62 while (startp > path && *(startp - 1) != '/')
63 startp--;
64
65 if (endp - startp + 2 > sizeof(bname)) {
66 errno = ENAMETOOLONG;
67 return(NULL);
68 }
69 strlcpy(bname, startp, endp - startp + 2);
70 return(bname);
71}
72
73#endif /* !defined(HAVE_BASENAME) */
diff --git a/openbsd-compat/basename.h b/openbsd-compat/basename.h
new file mode 100644
index 000000000..a8bd6c17c
--- /dev/null
+++ b/openbsd-compat/basename.h
@@ -0,0 +1,12 @@
1/* $Id: basename.h,v 1.3 2003/02/25 03:32:16 djm Exp $ */
2
3#ifndef _BASENAME_H
4#define _BASENAME_H
5#include "config.h"
6
7#if !defined(HAVE_BASENAME)
8
9char *basename(const char *path);
10
11#endif /* !defined(HAVE_BASENAME) */
12#endif /* _BASENAME_H */
diff --git a/openbsd-compat/bsd-arc4random.c b/openbsd-compat/bsd-arc4random.c
index ab4e1431e..dd08130d5 100644
--- a/openbsd-compat/bsd-arc4random.c
+++ b/openbsd-compat/bsd-arc4random.c
@@ -25,7 +25,7 @@
25#include "includes.h" 25#include "includes.h"
26#include "log.h" 26#include "log.h"
27 27
28RCSID("$Id: bsd-arc4random.c,v 1.5 2002/05/08 22:57:18 tim Exp $"); 28RCSID("$Id: bsd-arc4random.c,v 1.6 2003/03/17 05:13:53 djm Exp $");
29 29
30#ifndef HAVE_ARC4RANDOM 30#ifndef HAVE_ARC4RANDOM
31 31
@@ -66,7 +66,7 @@ void arc4random_stir(void)
66 unsigned char rand_buf[SEED_SIZE]; 66 unsigned char rand_buf[SEED_SIZE];
67 67
68 memset(&rc4, 0, sizeof(rc4)); 68 memset(&rc4, 0, sizeof(rc4));
69 if (!RAND_bytes(rand_buf, sizeof(rand_buf))) 69 if (RAND_bytes(rand_buf, sizeof(rand_buf)) <= 0)
70 fatal("Couldn't obtain random bytes (error %ld)", 70 fatal("Couldn't obtain random bytes (error %ld)",
71 ERR_get_error()); 71 ERR_get_error());
72 RC4_set_key(&rc4, sizeof(rand_buf), rand_buf); 72 RC4_set_key(&rc4, sizeof(rand_buf), rand_buf);
diff --git a/openbsd-compat/bsd-cray.h b/openbsd-compat/bsd-cray.h
index 8868b4364..68947c92f 100644
--- a/openbsd-compat/bsd-cray.h
+++ b/openbsd-compat/bsd-cray.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * $Id: bsd-cray.h,v 1.5 2002/09/26 00:38:51 tim Exp $ 2 * $Id: bsd-cray.h,v 1.6.2.1 2003/03/21 01:07:45 mouring Exp $
3 * 3 *
4 * bsd-cray.h 4 * bsd-cray.h
5 * 5 *
@@ -49,6 +49,10 @@ extern char cray_tmpdir[]; /* cray tmpdir */
49#ifndef MAXHOSTNAMELEN 49#ifndef MAXHOSTNAMELEN
50#define MAXHOSTNAMELEN 64 50#define MAXHOSTNAMELEN 64
51#endif 51#endif
52#ifndef _CRAYT3E
53#include <sys/ttold.h>
54#define TIOCGPGRP (tIOC|20)
55#endif
52#endif 56#endif
53 57
54#endif /* _BSD_CRAY_H */ 58#endif /* _BSD_CRAY_H */
diff --git a/openbsd-compat/bsd-cygwin_util.c b/openbsd-compat/bsd-cygwin_util.c
index 2396a6e6b..0fa5964bc 100644
--- a/openbsd-compat/bsd-cygwin_util.c
+++ b/openbsd-compat/bsd-cygwin_util.c
@@ -31,7 +31,7 @@
31 31
32#include "includes.h" 32#include "includes.h"
33 33
34RCSID("$Id: bsd-cygwin_util.c,v 1.8 2002/04/15 22:00:52 stevesk Exp $"); 34RCSID("$Id: bsd-cygwin_util.c,v 1.9 2002/11/09 15:59:29 mouring Exp $");
35 35
36#ifdef HAVE_CYGWIN 36#ifdef HAVE_CYGWIN
37 37
@@ -43,6 +43,7 @@ RCSID("$Id: bsd-cygwin_util.c,v 1.8 2002/04/15 22:00:52 stevesk Exp $");
43#define is_winnt (GetVersion() < 0x80000000) 43#define is_winnt (GetVersion() < 0x80000000)
44 44
45#define ntsec_on(c) ((c) && strstr((c),"ntsec") && !strstr((c),"nontsec")) 45#define ntsec_on(c) ((c) && strstr((c),"ntsec") && !strstr((c),"nontsec"))
46#define ntsec_off(c) ((c) && strstr((c),"nontsec"))
46#define ntea_on(c) ((c) && strstr((c),"ntea") && !strstr((c),"nontea")) 47#define ntea_on(c) ((c) && strstr((c),"ntea") && !strstr((c),"nontea"))
47 48
48#if defined(open) && open == binary_open 49#if defined(open) && open == binary_open
@@ -74,6 +75,56 @@ int binary_pipe(int fd[2])
74 return ret; 75 return ret;
75} 76}
76 77
78#define HAS_CREATE_TOKEN 1
79#define HAS_NTSEC_BY_DEFAULT 2
80
81static int has_capability(int what)
82{
83 /* has_capability() basically calls uname() and checks if
84 specific capabilities of Cygwin can be evaluated from that.
85 This simplifies the calling functions which only have to ask
86 for a capability using has_capability() instead of having
87 to figure that out by themselves. */
88 static int inited;
89 static int has_create_token;
90 static int has_ntsec_by_default;
91
92 if (!inited) {
93 struct utsname uts;
94 char *c;
95
96 if (!uname(&uts)) {
97 int major_high = 0;
98 int major_low = 0;
99 int minor = 0;
100 int api_major_version = 0;
101 int api_minor_version = 0;
102 char *c;
103
104 sscanf(uts.release, "%d.%d.%d", &major_high,
105 &major_low, &minor);
106 c = strchr(uts.release, '(');
107 if (c)
108 sscanf(c + 1, "%d.%d", &api_major_version,
109 &api_minor_version);
110 if (major_high > 1 ||
111 (major_high == 1 && (major_low > 3 ||
112 (major_low == 3 && minor >= 2))))
113 has_create_token = 1;
114 if (api_major_version > 0 || api_minor_version >= 56)
115 has_ntsec_by_default = 1;
116 inited = 1;
117 }
118 }
119 switch (what) {
120 case HAS_CREATE_TOKEN:
121 return has_create_token;
122 case HAS_NTSEC_BY_DEFAULT:
123 return has_ntsec_by_default;
124 }
125 return 0;
126}
127
77int check_nt_auth(int pwd_authenticated, struct passwd *pw) 128int check_nt_auth(int pwd_authenticated, struct passwd *pw)
78{ 129{
79 /* 130 /*
@@ -93,19 +144,14 @@ int check_nt_auth(int pwd_authenticated, struct passwd *pw)
93 return 0; 144 return 0;
94 if (is_winnt) { 145 if (is_winnt) {
95 if (has_create_token < 0) { 146 if (has_create_token < 0) {
96 struct utsname uts;
97 int major_high = 0, major_low = 0, minor = 0;
98 char *cygwin = getenv("CYGWIN"); 147 char *cygwin = getenv("CYGWIN");
99 148
100 has_create_token = 0; 149 has_create_token = 0;
101 if (ntsec_on(cygwin) && !uname(&uts)) { 150 if (has_capability(HAS_CREATE_TOKEN) &&
102 sscanf(uts.release, "%d.%d.%d", 151 (ntsec_on(cygwin) ||
103 &major_high, &major_low, &minor); 152 (has_capability(HAS_NTSEC_BY_DEFAULT) &&
104 if (major_high > 1 || 153 !ntsec_off(cygwin))))
105 (major_high == 1 && (major_low > 3 || 154 has_create_token = 1;
106 (major_low == 3 && minor >= 2))))
107 has_create_token = 1;
108 }
109 } 155 }
110 if (has_create_token < 1 && 156 if (has_create_token < 1 &&
111 !pwd_authenticated && geteuid() != pw->pw_uid) 157 !pwd_authenticated && geteuid() != pw->pw_uid)
@@ -128,7 +174,9 @@ int check_ntsec(const char *filename)
128 /* Evaluate current CYGWIN settings. */ 174 /* Evaluate current CYGWIN settings. */
129 cygwin = getenv("CYGWIN"); 175 cygwin = getenv("CYGWIN");
130 allow_ntea = ntea_on(cygwin); 176 allow_ntea = ntea_on(cygwin);
131 allow_ntsec = ntsec_on(cygwin); 177 allow_ntsec = ntsec_on(cygwin) ||
178 (has_capability(HAS_NTSEC_BY_DEFAULT) &&
179 !ntsec_off(cygwin));
132 180
133 /* 181 /*
134 * `ntea' is an emulation of POSIX attributes. It doesn't support 182 * `ntea' is an emulation of POSIX attributes. It doesn't support
diff --git a/openbsd-compat/bsd-getpeereid.c b/openbsd-compat/bsd-getpeereid.c
index c7876823d..3f554e72a 100644
--- a/openbsd-compat/bsd-getpeereid.c
+++ b/openbsd-compat/bsd-getpeereid.c
@@ -24,7 +24,7 @@
24 24
25#include "includes.h" 25#include "includes.h"
26 26
27RCSID("$Id: bsd-getpeereid.c,v 1.1 2002/09/12 00:33:02 djm Exp $"); 27RCSID("$Id: bsd-getpeereid.c,v 1.1.4.1 2003/03/26 05:02:47 djm Exp $");
28 28
29#if !defined(HAVE_GETPEEREID) 29#if !defined(HAVE_GETPEEREID)
30 30
@@ -33,7 +33,7 @@ int
33getpeereid(int s, uid_t *euid, gid_t *gid) 33getpeereid(int s, uid_t *euid, gid_t *gid)
34{ 34{
35 struct ucred cred; 35 struct ucred cred;
36 size_t len = sizeof(cred); 36 socklen_t len = sizeof(cred);
37 37
38 if (getsockopt(s, SOL_SOCKET, SO_PEERCRED, &cred, &len) < 0) 38 if (getsockopt(s, SOL_SOCKET, SO_PEERCRED, &cred, &len) < 0)
39 return (-1); 39 return (-1);
diff --git a/openbsd-compat/bsd-misc.c b/openbsd-compat/bsd-misc.c
index 1c1e43a52..b8e9996d5 100644
--- a/openbsd-compat/bsd-misc.c
+++ b/openbsd-compat/bsd-misc.c
@@ -23,15 +23,20 @@
23 */ 23 */
24 24
25#include "includes.h" 25#include "includes.h"
26#include "xmalloc.h"
26 27
27RCSID("$Id: bsd-misc.c,v 1.10 2002/07/08 21:09:41 mouring Exp $"); 28RCSID("$Id: bsd-misc.c,v 1.12 2003/03/18 18:21:41 tim Exp $");
28 29
30/*
31 * NB. duplicate __progname in case it is an alias for argv[0]
32 * Otherwise it may get clobbered by setproctitle()
33 */
29char *get_progname(char *argv0) 34char *get_progname(char *argv0)
30{ 35{
31#ifdef HAVE___PROGNAME 36#ifdef HAVE___PROGNAME
32 extern char *__progname; 37 extern char *__progname;
33 38
34 return __progname; 39 return xstrdup(__progname);
35#else 40#else
36 char *p; 41 char *p;
37 42
@@ -42,7 +47,8 @@ char *get_progname(char *argv0)
42 p = argv0; 47 p = argv0;
43 else 48 else
44 p++; 49 p++;
45 return p; 50
51 return xstrdup(p);
46#endif 52#endif
47} 53}
48 54
@@ -129,3 +135,34 @@ setgroups(size_t size, const gid_t *list)
129} 135}
130#endif 136#endif
131 137
138#if !defined(HAVE_NANOSLEEP) && !defined(HAVE_NSLEEP)
139int nanosleep(const struct timespec *req, struct timespec *rem)
140{
141 int rc, saverrno;
142 extern int errno;
143 struct timeval tstart, tstop, tremain, time2wait;
144
145 TIMESPEC_TO_TIMEVAL(&time2wait, req)
146 (void) gettimeofday(&tstart, NULL);
147 rc = select(0, NULL, NULL, NULL, &time2wait);
148 if (rc == -1) {
149 saverrno = errno;
150 (void) gettimeofday (&tstop, NULL);
151 errno = saverrno;
152 tremain.tv_sec = time2wait.tv_sec -
153 (tstop.tv_sec - tstart.tv_sec);
154 tremain.tv_usec = time2wait.tv_usec -
155 (tstop.tv_usec - tstart.tv_usec);
156 tremain.tv_sec += tremain.tv_usec / 1000000L;
157 tremain.tv_usec %= 1000000L;
158 } else {
159 tremain.tv_sec = 0;
160 tremain.tv_usec = 0;
161 }
162 TIMEVAL_TO_TIMESPEC(&tremain, rem)
163
164 return(rc);
165}
166
167#endif
168
diff --git a/openbsd-compat/bsd-misc.h b/openbsd-compat/bsd-misc.h
index 981196044..78d9ccdd4 100644
--- a/openbsd-compat/bsd-misc.h
+++ b/openbsd-compat/bsd-misc.h
@@ -22,7 +22,7 @@
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */ 23 */
24 24
25/* $Id: bsd-misc.h,v 1.6 2002/06/13 21:34:58 mouring Exp $ */ 25/* $Id: bsd-misc.h,v 1.7 2003/03/18 18:21:41 tim Exp $ */
26 26
27#ifndef _BSD_MISC_H 27#ifndef _BSD_MISC_H
28#define _BSD_MISC_H 28#define _BSD_MISC_H
@@ -80,5 +80,14 @@ int truncate (const char *path, off_t length);
80int setgroups(size_t size, const gid_t *list); 80int setgroups(size_t size, const gid_t *list);
81#endif 81#endif
82 82
83#if !defined(HAVE_NANOSLEEP) && !defined(HAVE_NSLEEP)
84#ifndef HAVE_STRUCT_TIMESPEC
85struct timespec {
86 time_t tv_sec;
87 long tv_nsec;
88};
89#endif
90int nanosleep(const struct timespec *req, struct timespec *rem);
91#endif
83 92
84#endif /* _BSD_MISC_H */ 93#endif /* _BSD_MISC_H */
diff --git a/openbsd-compat/fake-getaddrinfo.c b/openbsd-compat/fake-getaddrinfo.c
index 67e9eb788..bc58f30a6 100644
--- a/openbsd-compat/fake-getaddrinfo.c
+++ b/openbsd-compat/fake-getaddrinfo.c
@@ -12,7 +12,7 @@
12#include "includes.h" 12#include "includes.h"
13#include "ssh.h" 13#include "ssh.h"
14 14
15RCSID("$Id: fake-getaddrinfo.c,v 1.2 2001/02/09 01:55:36 djm Exp $"); 15RCSID("$Id: fake-getaddrinfo.c,v 1.4.2.1 2003/03/26 05:03:06 djm Exp $");
16 16
17#ifndef HAVE_GAI_STRERROR 17#ifndef HAVE_GAI_STRERROR
18char *gai_strerror(int ecode) 18char *gai_strerror(int ecode)
@@ -67,16 +67,30 @@ int getaddrinfo(const char *hostname, const char *servname,
67{ 67{
68 struct addrinfo *cur, *prev = NULL; 68 struct addrinfo *cur, *prev = NULL;
69 struct hostent *hp; 69 struct hostent *hp;
70 struct servent *sp;
70 struct in_addr in; 71 struct in_addr in;
71 int i, port; 72 int i;
73 long int port;
74 u_long addr;
72 75
73 if (servname) 76 port = 0;
74 port = htons(atoi(servname)); 77 if (servname != NULL) {
75 else 78 char *cp;
76 port = 0; 79
80 port = strtol(servname, &cp, 10);
81 if (port > 0 && port <= 65535 && *cp == '\0')
82 port = htons(port);
83 else if ((sp = getservbyname(servname, NULL)) != NULL)
84 port = sp->s_port;
85 else
86 port = 0;
87 }
77 88
78 if (hints && hints->ai_flags & AI_PASSIVE) { 89 if (hints && hints->ai_flags & AI_PASSIVE) {
79 if (NULL != (*res = malloc_ai(port, htonl(0x00000000)))) 90 addr = htonl(0x00000000);
91 if (hostname && inet_aton(hostname, &in) != 0)
92 addr = in.s_addr;
93 if (NULL != (*res = malloc_ai(port, addr)))
80 return 0; 94 return 0;
81 else 95 else
82 return EAI_MEMORY; 96 return EAI_MEMORY;
diff --git a/openbsd-compat/fake-getaddrinfo.h b/openbsd-compat/fake-getaddrinfo.h
index afd0226e2..6943378e9 100644
--- a/openbsd-compat/fake-getaddrinfo.h
+++ b/openbsd-compat/fake-getaddrinfo.h
@@ -1,4 +1,4 @@
1/* $Id: fake-getaddrinfo.h,v 1.2 2001/02/09 01:55:36 djm Exp $ */ 1/* $Id: fake-getaddrinfo.h,v 1.4 2003/02/24 01:35:09 djm Exp $ */
2 2
3#ifndef _FAKE_GETADDRINFO_H 3#ifndef _FAKE_GETADDRINFO_H
4#define _FAKE_GETADDRINFO_H 4#define _FAKE_GETADDRINFO_H
diff --git a/openbsd-compat/getcwd.c b/openbsd-compat/getcwd.c
index 6fd8543a5..f4b98e824 100644
--- a/openbsd-compat/getcwd.c
+++ b/openbsd-compat/getcwd.c
@@ -29,7 +29,7 @@
29#if !defined(HAVE_GETCWD) 29#if !defined(HAVE_GETCWD)
30 30
31#if defined(LIBC_SCCS) && !defined(lint) 31#if defined(LIBC_SCCS) && !defined(lint)
32static char rcsid[] = "$OpenBSD: getcwd.c,v 1.6 2000/07/19 15:25:13 deraadt Exp $"; 32static char rcsid[] = "$OpenBSD: getcwd.c,v 1.7 2002/11/24 01:52:27 cloder Exp $";
33#endif /* LIBC_SCCS and not lint */ 33#endif /* LIBC_SCCS and not lint */
34 34
35#include <sys/param.h> 35#include <sys/param.h>
@@ -127,7 +127,7 @@ getcwd(char *pt,size_t size)
127 /* 127 /*
128 * Build pointer to the parent directory, allocating memory 128 * Build pointer to the parent directory, allocating memory
129 * as necessary. Max length is 3 for "../", the largest 129 * as necessary. Max length is 3 for "../", the largest
130 * possible component name, plus a trailing NULL. 130 * possible component name, plus a trailing NUL.
131 */ 131 */
132 if (bup + 3 + MAXNAMLEN + 1 >= eup) { 132 if (bup + 3 + MAXNAMLEN + 1 >= eup) {
133 char *nup; 133 char *nup;
diff --git a/openbsd-compat/getopt.c b/openbsd-compat/getopt.c
index 4a5cfe5f0..a3fe807ee 100644
--- a/openbsd-compat/getopt.c
+++ b/openbsd-compat/getopt.c
@@ -35,7 +35,7 @@
35#if !defined(HAVE_GETOPT) || !defined(HAVE_GETOPT_OPTRESET) 35#if !defined(HAVE_GETOPT) || !defined(HAVE_GETOPT_OPTRESET)
36 36
37#if defined(LIBC_SCCS) && !defined(lint) 37#if defined(LIBC_SCCS) && !defined(lint)
38static char *rcsid = "$OpenBSD: getopt.c,v 1.2 1996/08/19 08:33:32 tholo Exp $"; 38static char *rcsid = "$OpenBSD: getopt.c,v 1.4 2002/12/08 22:57:14 millert Exp $";
39#endif /* LIBC_SCCS and not lint */ 39#endif /* LIBC_SCCS and not lint */
40 40
41#include <stdio.h> 41#include <stdio.h>
@@ -66,6 +66,9 @@ BSDgetopt(nargc, nargv, ostr)
66 static char *place = EMSG; /* option letter processing */ 66 static char *place = EMSG; /* option letter processing */
67 char *oli; /* option letter list index */ 67 char *oli; /* option letter list index */
68 68
69 if (ostr == NULL)
70 return (-1);
71
69 if (BSDoptreset || !*place) { /* update scanning pointer */ 72 if (BSDoptreset || !*place) { /* update scanning pointer */
70 BSDoptreset = 0; 73 BSDoptreset = 0;
71 if (BSDoptind >= nargc || *(place = nargv[BSDoptind]) != '-') { 74 if (BSDoptind >= nargc || *(place = nargv[BSDoptind]) != '-') {
diff --git a/openbsd-compat/mktemp.c b/openbsd-compat/mktemp.c
index d256ee448..c951050c0 100644
--- a/openbsd-compat/mktemp.c
+++ b/openbsd-compat/mktemp.c
@@ -36,7 +36,7 @@
36 36
37#include "includes.h" 37#include "includes.h"
38 38
39#ifndef HAVE_MKDTEMP 39#if !defined(HAVE_MKDTEMP) || defined(HAVE_STRICT_MKSTEMP)
40 40
41#if defined(LIBC_SCCS) && !defined(lint) 41#if defined(LIBC_SCCS) && !defined(lint)
42static char rcsid[] = "$OpenBSD: mktemp.c,v 1.16 2002/05/27 18:20:45 millert Exp $"; 42static char rcsid[] = "$OpenBSD: mktemp.c,v 1.16 2002/05/27 18:20:45 millert Exp $";
@@ -181,4 +181,4 @@ _gettemp(path, doopen, domkdir, slen)
181 /*NOTREACHED*/ 181 /*NOTREACHED*/
182} 182}
183 183
184#endif /* !HAVE_MKDTEMP */ 184#endif /* !defined(HAVE_MKDTEMP) || defined(HAVE_STRICT_MKSTEMP) */
diff --git a/openbsd-compat/mktemp.h b/openbsd-compat/mktemp.h
index 6a96f6fa6..505ca6a1f 100644
--- a/openbsd-compat/mktemp.h
+++ b/openbsd-compat/mktemp.h
@@ -1,13 +1,13 @@
1/* $Id: mktemp.h,v 1.2 2001/02/09 01:55:36 djm Exp $ */ 1/* $Id: mktemp.h,v 1.3 2003/01/07 04:18:33 djm Exp $ */
2 2
3#ifndef _BSD_MKTEMP_H 3#ifndef _BSD_MKTEMP_H
4#define _BSD_MKTEMP_H 4#define _BSD_MKTEMP_H
5 5
6#include "config.h" 6#include "config.h"
7#ifndef HAVE_MKDTEMP 7#if !defined(HAVE_MKDTEMP) || defined(HAVE_STRICT_MKSTEMP)
8int mkstemps(char *path, int slen); 8int mkstemps(char *path, int slen);
9int mkstemp(char *path); 9int mkstemp(char *path);
10char *mkdtemp(char *path); 10char *mkdtemp(char *path);
11#endif /* !HAVE_MKDTEMP */ 11#endif /* !defined(HAVE_MKDTEMP) || defined(HAVE_STRICT_MKSTEMP) */
12 12
13#endif /* _BSD_MKTEMP_H */ 13#endif /* _BSD_MKTEMP_H */
diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h
index ae18afd34..c3e19b9cb 100644
--- a/openbsd-compat/openbsd-compat.h
+++ b/openbsd-compat/openbsd-compat.h
@@ -1,4 +1,4 @@
1/* $Id: openbsd-compat.h,v 1.17 2002/09/12 00:33:02 djm Exp $ */ 1/* $Id: openbsd-compat.h,v 1.19 2003/02/24 01:55:56 djm Exp $ */
2 2
3#ifndef _OPENBSD_H 3#ifndef _OPENBSD_H
4#define _OPENBSD_H 4#define _OPENBSD_H
@@ -6,6 +6,7 @@
6#include "config.h" 6#include "config.h"
7 7
8/* OpenBSD function replacements */ 8/* OpenBSD function replacements */
9#include "basename.h"
9#include "bindresvport.h" 10#include "bindresvport.h"
10#include "getcwd.h" 11#include "getcwd.h"
11#include "realpath.h" 12#include "realpath.h"
@@ -26,6 +27,7 @@
26#include "glob.h" 27#include "glob.h"
27#include "readpassphrase.h" 28#include "readpassphrase.h"
28#include "getopt.h" 29#include "getopt.h"
30#include "vis.h"
29 31
30/* Home grown routines */ 32/* Home grown routines */
31#include "bsd-arc4random.h" 33#include "bsd-arc4random.h"
diff --git a/openbsd-compat/port-aix.h b/openbsd-compat/port-aix.h
index 79570a206..4abe00316 100644
--- a/openbsd-compat/port-aix.h
+++ b/openbsd-compat/port-aix.h
@@ -25,5 +25,16 @@
25 */ 25 */
26 26
27#ifdef _AIX 27#ifdef _AIX
28
29/* AIX 4.2.x doesn't have nanosleep but does have nsleep which is equivalent */
30#if !defined(HAVE_NANOSLEEP) && defined(HAVE_NSLEEP)
31# define nanosleep(a,b) nsleep(a,b)
32#endif
33
34/* For struct timespec on AIX 4.2.x */
35#ifdef HAVE_SYS_TIMERS_H
36# include <sys/timers.h>
37#endif
38
28void aix_usrinfo(struct passwd *pw); 39void aix_usrinfo(struct passwd *pw);
29#endif /* _AIX */ 40#endif /* _AIX */
diff --git a/openbsd-compat/setenv.c b/openbsd-compat/setenv.c
index 1dff15c73..e5c5de62e 100644
--- a/openbsd-compat/setenv.c
+++ b/openbsd-compat/setenv.c
@@ -35,12 +35,14 @@
35#ifndef HAVE_SETENV 35#ifndef HAVE_SETENV
36 36
37#if defined(LIBC_SCCS) && !defined(lint) 37#if defined(LIBC_SCCS) && !defined(lint)
38static char *rcsid = "$OpenBSD: setenv.c,v 1.4 2001/07/09 06:57:45 deraadt Exp $"; 38static char *rcsid = "$OpenBSD: setenv.c,v 1.5 2002/12/10 22:44:13 mickey Exp $";
39#endif /* LIBC_SCCS and not lint */ 39#endif /* LIBC_SCCS and not lint */
40 40
41#include <stdlib.h> 41#include <stdlib.h>
42#include <string.h> 42#include <string.h>
43 43
44char *__findenv(const char *name, int *offset);
45
44/* 46/*
45 * __findenv -- 47 * __findenv --
46 * Returns pointer to value associated with name, if any, else NULL. 48 * Returns pointer to value associated with name, if any, else NULL.
@@ -92,7 +94,6 @@ setenv(name, value, rewrite)
92 static int alloced; /* if allocated space before */ 94 static int alloced; /* if allocated space before */
93 register char *C; 95 register char *C;
94 int l_value, offset; 96 int l_value, offset;
95 char *__findenv();
96 97
97 if (*value == '=') /* no `=' in value */ 98 if (*value == '=') /* no `=' in value */
98 ++value; 99 ++value;
diff --git a/openbsd-compat/setproctitle.c b/openbsd-compat/setproctitle.c
index e165dd13c..07af7e9c0 100644
--- a/openbsd-compat/setproctitle.c
+++ b/openbsd-compat/setproctitle.c
@@ -1,102 +1,243 @@
1/* 1/*
2 * Modified for OpenSSH by Kevin Steves 2 * Based on src/backend/utils/misc/pg_status.c from
3 * October 2000 3 * PostgreSQL Database Management System
4 *
5 * Portions Copyright (c) 1996-2001, The PostgreSQL Global Development Group
6 *
7 * Portions Copyright (c) 1994, The Regents of the University of California
8 *
9 * Permission to use, copy, modify, and distribute this software and its
10 * documentation for any purpose, without fee, and without a written agreement
11 * is hereby granted, provided that the above copyright notice and this
12 * paragraph and the following two paragraphs appear in all copies.
13 *
14 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
15 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
16 * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
17 * DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE
18 * POSSIBILITY OF SUCH DAMAGE.
19 *
20 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
21 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
23 * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO
24 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
4 */ 25 */
5 26
6/* 27/*--------------------------------------------------------------------
7 * Copyright (c) 1994, 1995 Christopher G. Demetriou 28 * ps_status.c
8 * All rights reserved. 29 *
30 * Routines to support changing the ps display of PostgreSQL backends
31 * to contain some useful information. Mechanism differs wildly across
32 * platforms.
9 * 33 *
10 * Redistribution and use in source and binary forms, with or without 34 * $Header: /var/cvs/openssh/openbsd-compat/setproctitle.c,v 1.5 2003/01/20 02:15:11 djm Exp $
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by Christopher G. Demetriou
21 * for the NetBSD Project.
22 * 4. The name of the author may not be used to endorse or promote products
23 * derived from this software without specific prior written permission
24 * 35 *
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 36 * Copyright 2000 by PostgreSQL Global Development Group
26 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 37 * various details abducted from various places
27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 38 *--------------------------------------------------------------------
28 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */ 39 */
36 40
37#if defined(LIBC_SCCS) && !defined(lint)
38static char rcsid[] = "$OpenBSD: setproctitle.c,v 1.8 2001/11/06 19:21:40 art Exp $";
39#endif /* LIBC_SCCS and not lint */
40
41#include "includes.h" 41#include "includes.h"
42 42
43#ifndef HAVE_SETPROCTITLE 43#ifndef HAVE_SETPROCTITLE
44 44
45#define SPT_NONE 0 45#include <unistd.h>
46#define SPT_PSTAT 1 46#ifdef HAVE_SYS_PSTAT_H
47#include <sys/pstat.h> /* for HP-UX */
48#endif
49#ifdef HAVE_PS_STRINGS
50#include <machine/vmparam.h> /* for old BSD */
51#include <sys/exec.h>
52#endif
53
54/*------
55 * Alternative ways of updating ps display:
56 *
57 * SETPROCTITLE_STRATEGY == PS_USE_PSTAT
58 * use the pstat(PSTAT_SETCMD, )
59 * (HPUX)
60 * SETPROCTITLE_STRATEGY == PS_USE_PS_STRINGS
61 * assign PS_STRINGS->ps_argvstr = "string"
62 * (some BSD systems)
63 * SETPROCTITLE_STRATEGY == PS_USE_CHANGE_ARGV
64 * assign argv[0] = "string"
65 * (some other BSD systems)
66 * SETPROCTITLE_STRATEGY == PS_USE_CLOBBER_ARGV
67 * write over the argv and environment area
68 * (most SysV-like systems)
69 * SETPROCTITLE_STRATEGY == PS_USE_NONE
70 * don't update ps display
71 * (This is the default, as it is safest.)
72 */
73
74#define PS_USE_NONE 0
75#define PS_USE_PSTAT 1
76#define PS_USE_PS_STRINGS 2
77#define PS_USE_CHANGE_ARGV 3
78#define PS_USE_CLOBBER_ARGV 4
47 79
48#ifndef SPT_TYPE 80#ifndef SETPROCTITLE_STRATEGY
49#define SPT_TYPE SPT_NONE 81# define SETPROCTITLE_STRATEGY PS_USE_NONE
50#endif 82#endif
51 83
52#if SPT_TYPE == SPT_PSTAT 84#ifndef SETPROCTITLE_PS_PADDING
53#include <sys/param.h> 85# define SETPROCTITLE_PS_PADDING ' '
54#include <sys/pstat.h> 86#endif
55#endif /* SPT_TYPE == SPT_PSTAT */ 87#endif /* HAVE_SETPROCTITLE */
56 88
57#define MAX_PROCTITLE 2048 89extern char **environ;
90
91/*
92 * argv clobbering uses existing argv space, all other methods need a buffer
93 */
94#if SETPROCTITLE_STRATEGY != PS_USE_CLOBBER_ARGV
95static char ps_buffer[256];
96static const size_t ps_buffer_size = sizeof(ps_buffer);
97#else
98static char *ps_buffer; /* will point to argv area */
99static size_t ps_buffer_size; /* space determined at run time */
100#endif
101
102/* save the original argv[] location here */
103static int save_argc;
104static char **save_argv;
58 105
59extern char *__progname; 106extern char *__progname;
60 107
108#ifndef HAVE_SETPROCTITLE
61/* 109/*
62 * Set Process Title (SPT) defines. Modeled after sendmail's 110 * Call this to update the ps status display to a fixed prefix plus an
63 * SPT type definition strategy. 111 * indication of what you're currently doing passed in the argument.
64 *
65 * SPT_TYPE:
66 *
67 * SPT_NONE: Don't set the process title. Default.
68 * SPT_PSTAT: Use pstat(PSTAT_SETCMD). HP-UX specific.
69 */ 112 */
70
71void 113void
72setproctitle(const char *fmt, ...) 114setproctitle(const char *fmt, ...)
73{ 115{
74#if SPT_TYPE != SPT_NONE 116#if SETPROCTITLE_STRATEGY == PS_USE_PSTAT
117 union pstun pst;
118#endif
119#if SETPROCTITLE_STRATEGY != PS_USE_NONE
120 ssize_t used;
75 va_list ap; 121 va_list ap;
76
77 char buf[MAX_PROCTITLE];
78 size_t used;
79 122
80#if SPT_TYPE == SPT_PSTAT 123 /* no ps display if you didn't call save_ps_display_args() */
81 union pstun pst; 124 if (save_argv == NULL)
82#endif /* SPT_TYPE == SPT_PSTAT */ 125 return;
126#if SETPROCTITLE_STRATEGY == PS_USE_CLOBBER_ARGV
127 /* If ps_buffer is a pointer, it might still be null */
128 if (ps_buffer == NULL)
129 return;
130#endif /* PS_USE_CLOBBER_ARGV */
131
132 /*
133 * Overwrite argv[] to point at appropriate space, if needed
134 */
135#if SETPROCTITLE_STRATEGY == PS_USE_CHANGE_ARGV
136 save_argv[0] = ps_buffer;
137 save_argv[1] = NULL;
138#endif /* PS_USE_CHANGE_ARGV */
139
140#if SETPROCTITLE_STRATEGY == PS_USE_CLOBBER_ARGV
141 save_argv[1] = NULL;
142#endif /* PS_USE_CLOBBER_ARGV */
143
144 /*
145 * Make fixed prefix of ps display.
146 */
83 147
84 va_start(ap, fmt); 148 va_start(ap, fmt);
85 if (fmt != NULL) { 149 if (fmt == NULL)
86 used = snprintf(buf, MAX_PROCTITLE, "%s: ", __progname); 150 snprintf(ps_buffer, ps_buffer_size, "%s", __progname);
87 if (used >= MAX_PROCTITLE) 151 else {
88 used = MAX_PROCTITLE - 1; 152 used = snprintf(ps_buffer, ps_buffer_size, "%s: ", __progname);
89 (void)vsnprintf(buf + used, MAX_PROCTITLE - used, fmt, ap); 153 if (used == -1 || used >= ps_buffer_size)
90 } else 154 used = ps_buffer_size;
91 (void)snprintf(buf, MAX_PROCTITLE, "%s", __progname); 155 vsnprintf(ps_buffer + used, ps_buffer_size - used, fmt, ap);
156 }
92 va_end(ap); 157 va_end(ap);
93 used = strlen(buf);
94 158
95#if SPT_TYPE == SPT_PSTAT 159#if SETPROCTITLE_STRATEGY == PS_USE_PSTAT
96 pst.pst_command = buf; 160 pst.pst_command = ps_buffer;
97 pstat(PSTAT_SETCMD, pst, used, 0, 0); 161 pstat(PSTAT_SETCMD, pst, strlen(ps_buffer), 0, 0);
98#endif /* SPT_TYPE == SPT_PSTAT */ 162#endif /* PS_USE_PSTAT */
99 163
100#endif /* SPT_TYPE != SPT_NONE */ 164#if SETPROCTITLE_STRATEGY == PS_USE_PS_STRINGS
165 PS_STRINGS->ps_nargvstr = 1;
166 PS_STRINGS->ps_argvstr = ps_buffer;
167#endif /* PS_USE_PS_STRINGS */
168
169#if SETPROCTITLE_STRATEGY == PS_USE_CLOBBER_ARGV
170 /* pad unused memory */
171 used = strlen(ps_buffer);
172 memset(ps_buffer + used, SETPROCTITLE_PS_PADDING,
173 ps_buffer_size - used);
174#endif /* PS_USE_CLOBBER_ARGV */
175
176#endif /* PS_USE_NONE */
101} 177}
178
102#endif /* HAVE_SETPROCTITLE */ 179#endif /* HAVE_SETPROCTITLE */
180
181/*
182 * Call this early in startup to save the original argc/argv values.
183 *
184 * argv[] will not be overwritten by this routine, but may be overwritten
185 * during setproctitle. Also, the physical location of the environment
186 * strings may be moved, so this should be called before any code that
187 * might try to hang onto a getenv() result.
188 */
189void
190compat_init_setproctitle(int argc, char *argv[])
191{
192#if SETPROCTITLE_STRATEGY == PS_USE_CLOBBER_ARGV
193 char *end_of_area = NULL;
194 char **new_environ;
195 int i;
196#endif
197
198 save_argc = argc;
199 save_argv = argv;
200
201#if SETPROCTITLE_STRATEGY == PS_USE_CLOBBER_ARGV
202 /*
203 * If we're going to overwrite the argv area, count the available
204 * space. Also move the environment to make additional room.
205 */
206
207 /*
208 * check for contiguous argv strings
209 */
210 for (i = 0; i < argc; i++) {
211 if (i == 0 || end_of_area + 1 == argv[i])
212 end_of_area = argv[i] + strlen(argv[i]);
213 }
214
215 /* probably can't happen? */
216 if (end_of_area == NULL) {
217 ps_buffer = NULL;
218 ps_buffer_size = 0;
219 return;
220 }
221
222 /*
223 * check for contiguous environ strings following argv
224 */
225 for (i = 0; environ[i] != NULL; i++) {
226 if (end_of_area + 1 == environ[i])
227 end_of_area = environ[i] + strlen(environ[i]);
228 }
229
230 ps_buffer = argv[0];
231 ps_buffer_size = end_of_area - argv[0] - 1;
232
233 /*
234 * Duplicate and move the environment out of the way
235 */
236 new_environ = malloc(sizeof(char *) * (i + 1));
237 for (i = 0; environ[i] != NULL; i++)
238 new_environ[i] = strdup(environ[i]);
239 new_environ[i] = NULL;
240 environ = new_environ;
241#endif /* PS_USE_CLOBBER_ARGV */
242}
243
diff --git a/openbsd-compat/setproctitle.h b/openbsd-compat/setproctitle.h
index 8261bd0ee..48d26c6ea 100644
--- a/openbsd-compat/setproctitle.h
+++ b/openbsd-compat/setproctitle.h
@@ -1,4 +1,4 @@
1/* $Id: setproctitle.h,v 1.2 2001/02/09 01:55:36 djm Exp $ */ 1/* $Id: setproctitle.h,v 1.3 2003/01/09 22:53:13 djm Exp $ */
2 2
3#ifndef _BSD_SETPROCTITLE_H 3#ifndef _BSD_SETPROCTITLE_H
4#define _BSD_SETPROCTITLE_H 4#define _BSD_SETPROCTITLE_H
@@ -7,6 +7,7 @@
7 7
8#ifndef HAVE_SETPROCTITLE 8#ifndef HAVE_SETPROCTITLE
9void setproctitle(const char *fmt, ...); 9void setproctitle(const char *fmt, ...);
10void compat_init_setproctitle(int argc, char *argv[]);
10#endif 11#endif
11 12
12#endif /* _BSD_SETPROCTITLE_H */ 13#endif /* _BSD_SETPROCTITLE_H */
diff --git a/openbsd-compat/sys-tree.h b/openbsd-compat/sys-tree.h
index 0a58710c9..927ca04cd 100644
--- a/openbsd-compat/sys-tree.h
+++ b/openbsd-compat/sys-tree.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: tree.h,v 1.6 2002/06/11 22:09:52 provos Exp $ */ 1/* $OpenBSD: tree.h,v 1.7 2002/10/17 21:51:54 art Exp $ */
2/* 2/*
3 * Copyright 2002 Niels Provos <provos@citi.umich.edu> 3 * Copyright 2002 Niels Provos <provos@citi.umich.edu>
4 * All rights reserved. 4 * All rights reserved.
@@ -343,12 +343,13 @@ struct { \
343 RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \ 343 RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \
344 else \ 344 else \
345 RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \ 345 RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \
346 RB_AUGMENT(RB_PARENT(elm, field)); \
347 } else \ 346 } else \
348 (head)->rbh_root = (tmp); \ 347 (head)->rbh_root = (tmp); \
349 RB_LEFT(tmp, field) = (elm); \ 348 RB_LEFT(tmp, field) = (elm); \
350 RB_PARENT(elm, field) = (tmp); \ 349 RB_PARENT(elm, field) = (tmp); \
351 RB_AUGMENT(tmp); \ 350 RB_AUGMENT(tmp); \
351 if ((RB_PARENT(tmp, field))) \
352 RB_AUGMENT(RB_PARENT(tmp, field)); \
352} while (0) 353} while (0)
353 354
354#define RB_ROTATE_RIGHT(head, elm, tmp, field) do { \ 355#define RB_ROTATE_RIGHT(head, elm, tmp, field) do { \
@@ -362,12 +363,13 @@ struct { \
362 RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \ 363 RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \
363 else \ 364 else \
364 RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \ 365 RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \
365 RB_AUGMENT(RB_PARENT(elm, field)); \
366 } else \ 366 } else \
367 (head)->rbh_root = (tmp); \ 367 (head)->rbh_root = (tmp); \
368 RB_RIGHT(tmp, field) = (elm); \ 368 RB_RIGHT(tmp, field) = (elm); \
369 RB_PARENT(elm, field) = (tmp); \ 369 RB_PARENT(elm, field) = (tmp); \
370 RB_AUGMENT(tmp); \ 370 RB_AUGMENT(tmp); \
371 if ((RB_PARENT(tmp, field))) \
372 RB_AUGMENT(RB_PARENT(tmp, field)); \
371} while (0) 373} while (0)
372 374
373/* Generates prototypes and inline functions */ 375/* Generates prototypes and inline functions */
diff --git a/openbsd-compat/vis.c b/openbsd-compat/vis.c
new file mode 100644
index 000000000..fc5741390
--- /dev/null
+++ b/openbsd-compat/vis.c
@@ -0,0 +1,232 @@
1/*-
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. 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 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33#include "config.h"
34#if !defined(HAVE_STRNVIS)
35
36#if defined(LIBC_SCCS) && !defined(lint)
37static char rcsid[] = "$OpenBSD: vis.c,v 1.8 2002/02/19 19:39:36 millert Exp $";
38#endif /* LIBC_SCCS and not lint */
39
40#include <ctype.h>
41
42#include "vis.h"
43
44#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
45#define isvisible(c) (((u_int)(c) <= UCHAR_MAX && isascii((u_char)(c)) && \
46 isgraph((u_char)(c))) || \
47 ((flag & VIS_SP) == 0 && (c) == ' ') || \
48 ((flag & VIS_TAB) == 0 && (c) == '\t') || \
49 ((flag & VIS_NL) == 0 && (c) == '\n') || \
50 ((flag & VIS_SAFE) && \
51 ((c) == '\b' || (c) == '\007' || (c) == '\r')))
52
53/*
54 * vis - visually encode characters
55 */
56char *
57vis(dst, c, flag, nextc)
58 register char *dst;
59 int c, nextc;
60 register int flag;
61{
62 if (isvisible(c)) {
63 *dst++ = c;
64 if (c == '\\' && (flag & VIS_NOSLASH) == 0)
65 *dst++ = '\\';
66 *dst = '\0';
67 return (dst);
68 }
69
70 if (flag & VIS_CSTYLE) {
71 switch(c) {
72 case '\n':
73 *dst++ = '\\';
74 *dst++ = 'n';
75 goto done;
76 case '\r':
77 *dst++ = '\\';
78 *dst++ = 'r';
79 goto done;
80 case '\b':
81 *dst++ = '\\';
82 *dst++ = 'b';
83 goto done;
84 case '\a':
85 *dst++ = '\\';
86 *dst++ = 'a';
87 goto done;
88 case '\v':
89 *dst++ = '\\';
90 *dst++ = 'v';
91 goto done;
92 case '\t':
93 *dst++ = '\\';
94 *dst++ = 't';
95 goto done;
96 case '\f':
97 *dst++ = '\\';
98 *dst++ = 'f';
99 goto done;
100 case ' ':
101 *dst++ = '\\';
102 *dst++ = 's';
103 goto done;
104 case '\0':
105 *dst++ = '\\';
106 *dst++ = '0';
107 if (isoctal(nextc)) {
108 *dst++ = '0';
109 *dst++ = '0';
110 }
111 goto done;
112 }
113 }
114 if (((c & 0177) == ' ') || (flag & VIS_OCTAL)) {
115 *dst++ = '\\';
116 *dst++ = ((u_char)c >> 6 & 07) + '0';
117 *dst++ = ((u_char)c >> 3 & 07) + '0';
118 *dst++ = ((u_char)c & 07) + '0';
119 goto done;
120 }
121 if ((flag & VIS_NOSLASH) == 0)
122 *dst++ = '\\';
123 if (c & 0200) {
124 c &= 0177;
125 *dst++ = 'M';
126 }
127 if (iscntrl(c)) {
128 *dst++ = '^';
129 if (c == 0177)
130 *dst++ = '?';
131 else
132 *dst++ = c + '@';
133 } else {
134 *dst++ = '-';
135 *dst++ = c;
136 }
137done:
138 *dst = '\0';
139 return (dst);
140}
141
142/*
143 * strvis, strnvis, strvisx - visually encode characters from src into dst
144 *
145 * Dst must be 4 times the size of src to account for possible
146 * expansion. The length of dst, not including the trailing NULL,
147 * is returned.
148 *
149 * Strnvis will write no more than siz-1 bytes (and will NULL terminate).
150 * The number of bytes needed to fully encode the string is returned.
151 *
152 * Strvisx encodes exactly len bytes from src into dst.
153 * This is useful for encoding a block of data.
154 */
155int
156strvis(dst, src, flag)
157 register char *dst;
158 register const char *src;
159 int flag;
160{
161 register char c;
162 char *start;
163
164 for (start = dst; (c = *src);)
165 dst = vis(dst, c, flag, *++src);
166 *dst = '\0';
167 return (dst - start);
168}
169
170int
171strnvis(dst, src, siz, flag)
172 register char *dst;
173 register const char *src;
174 size_t siz;
175 int flag;
176{
177 register char c;
178 char *start, *end;
179
180 for (start = dst, end = start + siz - 1; (c = *src) && dst < end; ) {
181 if (isvisible(c)) {
182 *dst++ = c;
183 if (c == '\\' && (flag & VIS_NOSLASH) == 0) {
184 /* need space for the extra '\\' */
185 if (dst < end)
186 *dst++ = '\\';
187 else {
188 dst--;
189 break;
190 }
191 }
192 src++;
193 } else {
194 /* vis(3) requires up to 4 chars */
195 if (dst + 3 < end)
196 dst = vis(dst, c, flag, *++src);
197 else
198 break;
199 }
200 }
201 *dst = '\0';
202 if (dst >= end) {
203 char tbuf[5];
204
205 /* adjust return value for truncation */
206 while ((c = *src))
207 dst += vis(tbuf, c, flag, *++src) - tbuf;
208 }
209 return (dst - start);
210}
211
212int
213strvisx(dst, src, len, flag)
214 register char *dst;
215 register const char *src;
216 register size_t len;
217 int flag;
218{
219 register char c;
220 char *start;
221
222 for (start = dst; len > 1; len--) {
223 c = *src;
224 dst = vis(dst, c, flag, *++src);
225 }
226 if (len)
227 dst = vis(dst, *src, flag, '\0');
228 *dst = '\0';
229 return (dst - start);
230}
231
232#endif
diff --git a/openbsd-compat/vis.h b/openbsd-compat/vis.h
new file mode 100644
index 000000000..5df6f3694
--- /dev/null
+++ b/openbsd-compat/vis.h
@@ -0,0 +1,91 @@
1/* $OpenBSD: vis.h,v 1.5 2002/02/16 21:27:17 millert Exp $ */
2/* $NetBSD: vis.h,v 1.4 1994/10/26 00:56:41 cgd Exp $ */
3
4/*-
5 * Copyright (c) 1990 The Regents of the University of California.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)vis.h 5.9 (Berkeley) 4/3/91
37 */
38#include "config.h"
39#if !defined(HAVE_STRNVIS)
40
41#ifndef _VIS_H_
42#define _VIS_H_
43
44#include <sys/types.h>
45#include <limits.h>
46
47/*
48 * to select alternate encoding format
49 */
50#define VIS_OCTAL 0x01 /* use octal \ddd format */
51#define VIS_CSTYLE 0x02 /* use \[nrft0..] where appropriate */
52
53/*
54 * to alter set of characters encoded (default is to encode all
55 * non-graphic except space, tab, and newline).
56 */
57#define VIS_SP 0x04 /* also encode space */
58#define VIS_TAB 0x08 /* also encode tab */
59#define VIS_NL 0x10 /* also encode newline */
60#define VIS_WHITE (VIS_SP | VIS_TAB | VIS_NL)
61#define VIS_SAFE 0x20 /* only encode "unsafe" characters */
62
63/*
64 * other
65 */
66#define VIS_NOSLASH 0x40 /* inhibit printing '\' */
67
68/*
69 * unvis return codes
70 */
71#define UNVIS_VALID 1 /* character valid */
72#define UNVIS_VALIDPUSH 2 /* character valid, push back passed char */
73#define UNVIS_NOCHAR 3 /* valid sequence, no character produced */
74#define UNVIS_SYNBAD -1 /* unrecognized escape sequence */
75#define UNVIS_ERROR -2 /* decoder in unknown state (unrecoverable) */
76
77/*
78 * unvis flags
79 */
80#define UNVIS_END 1 /* no more characters */
81
82char *vis(char *, int, int, int);
83int strvis(char *, const char *, int);
84int strnvis(char *, const char *, size_t, int);
85int strvisx(char *, const char *, size_t, int);
86int strunvis(char *, const char *);
87int unvis(char *, char, int *, int);
88
89#endif /* !_VIS_H_ */
90
91#endif /* !HAVE_STRNVIS */