summaryrefslogtreecommitdiff
path: root/openbsd-compat
diff options
context:
space:
mode:
Diffstat (limited to 'openbsd-compat')
-rw-r--r--openbsd-compat/dirname.c6
-rw-r--r--openbsd-compat/fake-queue.h15
-rw-r--r--openbsd-compat/mktemp.c5
-rw-r--r--openbsd-compat/readpassphrase.c133
-rw-r--r--openbsd-compat/realpath.c8
-rw-r--r--openbsd-compat/setenv.c5
-rw-r--r--openbsd-compat/setproctitle.c2
7 files changed, 105 insertions, 69 deletions
diff --git a/openbsd-compat/dirname.c b/openbsd-compat/dirname.c
index a76a1dc13..391b2dd81 100644
--- a/openbsd-compat/dirname.c
+++ b/openbsd-compat/dirname.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dirname.c,v 1.5 2001/06/27 00:58:54 lebel Exp $ */ 1/* $OpenBSD: dirname.c,v 1.6 2001/06/28 04:27:19 pjanzen Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com> 4 * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -31,7 +31,7 @@
31#ifndef HAVE_DIRNAME 31#ifndef HAVE_DIRNAME
32 32
33#if defined(LIBC_SCCS) && !defined(lint) 33#if defined(LIBC_SCCS) && !defined(lint)
34static char rcsid[] = "$OpenBSD: dirname.c,v 1.5 2001/06/27 00:58:54 lebel Exp $"; 34static char rcsid[] = "$OpenBSD: dirname.c,v 1.6 2001/06/28 04:27:19 pjanzen Exp $";
35#endif /* LIBC_SCCS and not lint */ 35#endif /* LIBC_SCCS and not lint */
36 36
37#include <errno.h> 37#include <errno.h>
@@ -70,7 +70,7 @@ dirname(path)
70 } while (endp > path && *endp == '/'); 70 } while (endp > path && *endp == '/');
71 } 71 }
72 72
73 if (endp - path + 1 > sizeof(bname)) { 73 if (endp - path + 2 > sizeof(bname)) {
74 errno = ENAMETOOLONG; 74 errno = ENAMETOOLONG;
75 return(NULL); 75 return(NULL);
76 } 76 }
diff --git a/openbsd-compat/fake-queue.h b/openbsd-compat/fake-queue.h
index 269af413c..c85bb240c 100644
--- a/openbsd-compat/fake-queue.h
+++ b/openbsd-compat/fake-queue.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: queue.h,v 1.16 2000/09/07 19:47:59 art Exp $ */ 1/* $OpenBSD: queue.h,v 1.22 2001/06/23 04:39:35 angelos Exp $ */
2/* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */ 2/* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */
3 3
4/* 4/*
@@ -136,6 +136,19 @@ struct { \
136 (head)->slh_first = (head)->slh_first->field.sle_next; \ 136 (head)->slh_first = (head)->slh_first->field.sle_next; \
137} while (0) 137} while (0)
138 138
139#define SLIST_REMOVE(head, elm, type, field) do { \
140 if ((head)->slh_first == (elm)) { \
141 SLIST_REMOVE_HEAD((head), field); \
142 } \
143 else { \
144 struct type *curelm = (head)->slh_first; \
145 while( curelm->field.sle_next != (elm) ) \
146 curelm = curelm->field.sle_next; \
147 curelm->field.sle_next = \
148 curelm->field.sle_next->field.sle_next; \
149 } \
150} while (0)
151
139/* 152/*
140 * List definitions. 153 * List definitions.
141 */ 154 */
diff --git a/openbsd-compat/mktemp.c b/openbsd-compat/mktemp.c
index 9ed1bc80f..d69dc5c24 100644
--- a/openbsd-compat/mktemp.c
+++ b/openbsd-compat/mktemp.c
@@ -39,7 +39,7 @@
39#ifndef HAVE_MKDTEMP 39#ifndef HAVE_MKDTEMP
40 40
41#if defined(LIBC_SCCS) && !defined(lint) 41#if defined(LIBC_SCCS) && !defined(lint)
42static char rcsid[] = "$OpenBSD: mktemp.c,v 1.13 1998/06/30 23:03:13 deraadt Exp $"; 42static char rcsid[] = "$OpenBSD: mktemp.c,v 1.14 2002/01/02 20:18:32 deraadt Exp $";
43#endif /* LIBC_SCCS and not lint */ 43#endif /* LIBC_SCCS and not lint */
44 44
45#ifdef HAVE_CYGWIN 45#ifdef HAVE_CYGWIN
@@ -84,7 +84,8 @@ _gettemp(path, doopen, domkdir, slen)
84{ 84{
85 register char *start, *trv, *suffp; 85 register char *start, *trv, *suffp;
86 struct stat sbuf; 86 struct stat sbuf;
87 int pid, rval; 87 int rval;
88 pid_t pid;
88 89
89 if (doopen && domkdir) { 90 if (doopen && domkdir) {
90 errno = EINVAL; 91 errno = EINVAL;
diff --git a/openbsd-compat/readpassphrase.c b/openbsd-compat/readpassphrase.c
index fdef15809..4e63b6189 100644
--- a/openbsd-compat/readpassphrase.c
+++ b/openbsd-compat/readpassphrase.c
@@ -1,3 +1,5 @@
1/* $OpenBSD: readpassphrase.c,v 1.12 2001/12/15 05:41:00 millert Exp $ */
2
1/* 3/*
2 * Copyright (c) 2000 Todd C. Miller <Todd.Miller@courtesan.com> 4 * Copyright (c) 2000 Todd C. Miller <Todd.Miller@courtesan.com>
3 * All rights reserved. 5 * All rights reserved.
@@ -26,7 +28,7 @@
26 */ 28 */
27 29
28#if defined(LIBC_SCCS) && !defined(lint) 30#if defined(LIBC_SCCS) && !defined(lint)
29static char rcsid[] = "$OpenBSD: readpassphrase.c,v 1.5 2001/06/27 13:23:30 djm Exp $"; 31static const char rcsid[] = "$OpenBSD: readpassphrase.c,v 1.12 2001/12/15 05:41:00 millert Exp $";
30#endif /* LIBC_SCCS and not lint */ 32#endif /* LIBC_SCCS and not lint */
31 33
32#include "includes.h" 34#include "includes.h"
@@ -47,20 +49,19 @@ static char rcsid[] = "$OpenBSD: readpassphrase.c,v 1.5 2001/06/27 13:23:30 djm
47# define _POSIX_VDISABLE VDISABLE 49# define _POSIX_VDISABLE VDISABLE
48#endif 50#endif
49 51
52static volatile sig_atomic_t signo;
53
54static void handler(int);
55
50char * 56char *
51readpassphrase(prompt, buf, bufsiz, flags) 57readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags)
52 const char *prompt;
53 char *buf;
54 size_t bufsiz;
55 int flags;
56{ 58{
57 struct termios term; 59 ssize_t nr;
60 int input, output, save_errno;
58 char ch, *p, *end; 61 char ch, *p, *end;
59#ifdef _POSIX_VDISABLE 62 struct termios term, oterm;
60 u_char status; 63 struct sigaction sa, saveint, savehup, savequit, saveterm;
61#endif 64 struct sigaction savetstp, savettin, savettou;
62 int echo, input, output;
63 sigset_t oset, nset;
64 65
65 /* I suppose we could alloc on demand in this case (XXX). */ 66 /* I suppose we could alloc on demand in this case (XXX). */
66 if (bufsiz == 0) { 67 if (bufsiz == 0) {
@@ -68,6 +69,7 @@ readpassphrase(prompt, buf, bufsiz, flags)
68 return(NULL); 69 return(NULL);
69 } 70 }
70 71
72restart:
71 /* 73 /*
72 * Read and write to /dev/tty if available. If not, read from 74 * Read and write to /dev/tty if available. If not, read from
73 * stdin and write to stderr unless a tty is required. 75 * stdin and write to stderr unless a tty is required.
@@ -82,44 +84,39 @@ readpassphrase(prompt, buf, bufsiz, flags)
82 } 84 }
83 85
84 /* 86 /*
85 * We block SIGINT and SIGTSTP so the terminal is not left 87 * Catch signals that would otherwise cause the user to end
86 * in an inconsistent state (ie: no echo). It would probably 88 * up with echo turned off in the shell. Don't worry about
87 * be better to simply catch these though. 89 * things like SIGALRM and SIGPIPE for now.
88 */ 90 */
89 sigemptyset(&nset); 91 sigemptyset(&sa.sa_mask);
90 sigaddset(&nset, SIGINT); 92 sa.sa_flags = 0; /* don't restart system calls */
91 sigaddset(&nset, SIGTSTP); 93 sa.sa_handler = handler;
92 (void)sigprocmask(SIG_BLOCK, &nset, &oset); 94 (void)sigaction(SIGINT, &sa, &saveint);
95 (void)sigaction(SIGHUP, &sa, &savehup);
96 (void)sigaction(SIGQUIT, &sa, &savequit);
97 (void)sigaction(SIGTERM, &sa, &saveterm);
98 (void)sigaction(SIGTSTP, &sa, &savetstp);
99 (void)sigaction(SIGTTIN, &sa, &savettin);
100 (void)sigaction(SIGTTOU, &sa, &savettou);
93 101
94 /* Turn off echo if possible. */ 102 /* Turn off echo if possible. */
95 echo = 0; 103 if (tcgetattr(input, &oterm) == 0) {
96#ifdef _POSIX_VDISABLE 104 memcpy(&term, &oterm, sizeof(term));
97 status = _POSIX_VDISABLE; 105 if (!(flags & RPP_ECHO_ON))
98#endif 106 term.c_lflag &= ~(ECHO | ECHONL);
99 if (tcgetattr(input, &term) == 0) {
100 if (!(flags & RPP_ECHO_ON) && (term.c_lflag & ECHO)) {
101 echo = 1;
102 term.c_lflag &= ~ECHO;
103 }
104#ifdef VSTATUS 107#ifdef VSTATUS
105 if (term.c_cc[VSTATUS] != _POSIX_VDISABLE) { 108 if (term.c_cc[VSTATUS] != _POSIX_VDISABLE)
106 status = term.c_cc[VSTATUS];
107 term.c_cc[VSTATUS] = _POSIX_VDISABLE; 109 term.c_cc[VSTATUS] = _POSIX_VDISABLE;
108 }
109#endif 110#endif
110 (void)tcsetattr(input, _T_FLUSH, &term); 111 (void)tcsetattr(input, _T_FLUSH, &term);
111 } 112 } else {
112 if (!(flags & RPP_ECHO_ON)) { 113 memset(&term, 0, sizeof(term));
113 if (tcgetattr(input, &term) == 0 && (term.c_lflag & ECHO)) { 114 memset(&oterm, 0, sizeof(oterm));
114 echo = 1;
115 term.c_lflag &= ~ECHO;
116 (void)tcsetattr(input, _T_FLUSH, &term);
117 }
118 } 115 }
119 116
120 (void)write(output, prompt, strlen(prompt)); 117 (void)write(output, prompt, strlen(prompt));
121 end = buf + bufsiz - 1; 118 end = buf + bufsiz - 1;
122 for (p = buf; read(input, &ch, 1) == 1 && ch != '\n' && ch != '\r';) { 119 for (p = buf; (nr = read(input, &ch, 1)) == 1 && ch != '\n' && ch != '\r';) {
123 if (p < end) { 120 if (p < end) {
124 if ((flags & RPP_SEVENBIT)) 121 if ((flags & RPP_SEVENBIT))
125 ch &= 0x7f; 122 ch &= 0x7f;
@@ -133,35 +130,55 @@ readpassphrase(prompt, buf, bufsiz, flags)
133 } 130 }
134 } 131 }
135 *p = '\0'; 132 *p = '\0';
136#ifdef _POSIX_VDISABLE 133 save_errno = errno;
137 if (echo || status != _POSIX_VDISABLE) { 134 if (!(term.c_lflag & ECHO))
138#else 135 (void)write(output, "\n", 1);
139 if (echo) { 136
140#endif 137 /* Restore old terminal settings and signals. */
141 if (echo) { 138 if (memcmp(&term, &oterm, sizeof(term)) != 0)
142 (void)write(output, "\n", 1);
143 term.c_lflag |= ECHO;
144 }
145#ifdef VSTATUS
146 if (status != _POSIX_VDISABLE)
147 term.c_cc[VSTATUS] = status;
148#endif
149 (void)tcsetattr(input, _T_FLUSH, &term); 139 (void)tcsetattr(input, _T_FLUSH, &term);
150 } 140 (void)sigaction(SIGINT, &saveint, NULL);
151 (void)sigprocmask(SIG_SETMASK, &oset, NULL); 141 (void)sigaction(SIGHUP, &savehup, NULL);
142 (void)sigaction(SIGQUIT, &savequit, NULL);
143 (void)sigaction(SIGTERM, &saveterm, NULL);
144 (void)sigaction(SIGTSTP, &savetstp, NULL);
145 (void)sigaction(SIGTTIN, &savettin, NULL);
146 (void)sigaction(SIGTTOU, &savettou, NULL);
152 if (input != STDIN_FILENO) 147 if (input != STDIN_FILENO)
153 (void)close(input); 148 (void)close(input);
154 return(buf); 149
150 /*
151 * If we were interrupted by a signal, resend it to ourselves
152 * now that we have restored the signal handlers.
153 */
154 if (signo) {
155 kill(getpid(), signo);
156 switch (signo) {
157 case SIGTSTP:
158 case SIGTTIN:
159 case SIGTTOU:
160 signo = 0;
161 goto restart;
162 }
163 }
164
165 errno = save_errno;
166 return(nr == -1 ? NULL : buf);
155} 167}
156#endif /* HAVE_READPASSPHRASE */ 168#endif /* HAVE_READPASSPHRASE */
157 169
158#if 0 170#if 0
159char * 171char *
160getpass(prompt) 172getpass(const char *prompt)
161 const char *prompt;
162{ 173{
163 static char buf[_PASSWORD_LEN + 1]; 174 static char buf[_PASSWORD_LEN + 1];
164 175
165 return(readpassphrase(prompt, buf, sizeof(buf), RPP_ECHO_OFF)); 176 return(readpassphrase(prompt, buf, sizeof(buf), RPP_ECHO_OFF));
166} 177}
167#endif 178#endif
179
180static void handler(int s)
181{
182
183 signo = s;
184}
diff --git a/openbsd-compat/realpath.c b/openbsd-compat/realpath.c
index ec801d498..b4a05db95 100644
--- a/openbsd-compat/realpath.c
+++ b/openbsd-compat/realpath.c
@@ -32,7 +32,7 @@
32#if !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH) 32#if !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH)
33 33
34#if defined(LIBC_SCCS) && !defined(lint) 34#if defined(LIBC_SCCS) && !defined(lint)
35static char *rcsid = "$OpenBSD: realpath.c,v 1.5 2001/06/27 00:58:56 lebel Exp $"; 35static char *rcsid = "$OpenBSD: realpath.c,v 1.6 2002/01/12 16:24:35 millert Exp $";
36#endif /* LIBC_SCCS and not lint */ 36#endif /* LIBC_SCCS and not lint */
37 37
38#include <sys/param.h> 38#include <sys/param.h>
@@ -74,6 +74,10 @@ realpath(const char *path, char *resolved)
74 } 74 }
75 close(fd); 75 close(fd);
76 76
77 /* Convert "." -> "" to optimize away a needless lstat() and chdir() */
78 if (path[0] == '.' && path[1] == '\0')
79 path = "";
80
77 /* 81 /*
78 * Find the dirname and basename from the path to be resolved. 82 * Find the dirname and basename from the path to be resolved.
79 * Change directory to the dirname component. 83 * Change directory to the dirname component.
@@ -102,7 +106,7 @@ loop:
102 p = resolved; 106 p = resolved;
103 107
104 /* Deal with the last component. */ 108 /* Deal with the last component. */
105 if (lstat(p, &sb) == 0) { 109 if (*p != '\0' && lstat(p, &sb) == 0) {
106 if (S_ISLNK(sb.st_mode)) { 110 if (S_ISLNK(sb.st_mode)) {
107 if (++symlinks > MAXSYMLINKS) { 111 if (++symlinks > MAXSYMLINKS) {
108 serrno = ELOOP; 112 serrno = ELOOP;
diff --git a/openbsd-compat/setenv.c b/openbsd-compat/setenv.c
index ac9670baf..6c2d5cd31 100644
--- a/openbsd-compat/setenv.c
+++ b/openbsd-compat/setenv.c
@@ -35,7 +35,7 @@
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.3 1998/02/02 22:44:53 millert Exp $"; 38static char *rcsid = "$OpenBSD: setenv.c,v 1.4 2001/07/09 06:57:45 deraadt 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>
@@ -101,7 +101,8 @@ setenv(name, value, rewrite)
101 if (!rewrite) 101 if (!rewrite)
102 return (0); 102 return (0);
103 if (strlen(C) >= l_value) { /* old larger; copy over */ 103 if (strlen(C) >= l_value) { /* old larger; copy over */
104 while ((*C++ = *value++)); 104 while ((*C++ = *value++))
105 ;
105 return (0); 106 return (0);
106 } 107 }
107 } else { /* create new slot */ 108 } else { /* create new slot */
diff --git a/openbsd-compat/setproctitle.c b/openbsd-compat/setproctitle.c
index 38eca9ad7..e165dd13c 100644
--- a/openbsd-compat/setproctitle.c
+++ b/openbsd-compat/setproctitle.c
@@ -35,7 +35,7 @@
35 */ 35 */
36 36
37#if defined(LIBC_SCCS) && !defined(lint) 37#if defined(LIBC_SCCS) && !defined(lint)
38static char rcsid[] = "$OpenBSD: setproctitle.c,v 1.7 1999/02/25 22:10:12 art Exp $"; 38static char rcsid[] = "$OpenBSD: setproctitle.c,v 1.8 2001/11/06 19:21:40 art Exp $";
39#endif /* LIBC_SCCS and not lint */ 39#endif /* LIBC_SCCS and not lint */
40 40
41#include "includes.h" 41#include "includes.h"