mirror of
https://github.com/PowerShell/openssh-portable.git
synced 2025-07-28 08:14:24 +02:00
- (djm) Sync openbsd-compat with OpenBSD -current
This commit is contained in:
parent
c34e03e471
commit
71eb0c1550
@ -1,3 +1,6 @@
|
|||||||
|
20020911
|
||||||
|
- (djm) Sync openbsd-compat with OpenBSD -current
|
||||||
|
|
||||||
20020910
|
20020910
|
||||||
- (djm) Bug #365: Read /.ssh/environment properly under CygWin.
|
- (djm) Bug #365: Read /.ssh/environment properly under CygWin.
|
||||||
Patch from Mark Bradshaw <bradshaw@staff.crosswalk.com>
|
Patch from Mark Bradshaw <bradshaw@staff.crosswalk.com>
|
||||||
@ -1614,4 +1617,4 @@
|
|||||||
- (stevesk) entropy.c: typo in debug message
|
- (stevesk) entropy.c: typo in debug message
|
||||||
- (djm) ssh-keygen -i needs seeded RNG; report from markus@
|
- (djm) ssh-keygen -i needs seeded RNG; report from markus@
|
||||||
|
|
||||||
$Id: ChangeLog,v 1.2450 2002/09/10 12:26:17 djm Exp $
|
$Id: ChangeLog,v 1.2451 2002/09/11 00:29:11 djm Exp $
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD: base64.c,v 1.3 1997/11/08 20:46:55 deraadt Exp $ */
|
/* $OpenBSD: base64.c,v 1.4 2002/01/02 23:00:10 deraadt Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1996 by Internet Software Consortium.
|
* Copyright (c) 1996 by Internet Software Consortium.
|
||||||
@ -60,6 +60,7 @@
|
|||||||
|
|
||||||
#include "base64.h"
|
#include "base64.h"
|
||||||
|
|
||||||
|
/* XXX abort illegal in library */
|
||||||
#define Assert(Cond) if (!(Cond)) abort()
|
#define Assert(Cond) if (!(Cond)) abort()
|
||||||
|
|
||||||
static const char Base64[] =
|
static const char Base64[] =
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD: dirname.c,v 1.6 2001/06/28 04:27:19 pjanzen Exp $ */
|
/* $OpenBSD: dirname.c,v 1.7 2002/05/24 21:22:37 deraadt Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
|
* Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
@ -31,7 +31,7 @@
|
|||||||
#ifndef HAVE_DIRNAME
|
#ifndef HAVE_DIRNAME
|
||||||
|
|
||||||
#if defined(LIBC_SCCS) && !defined(lint)
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
static char rcsid[] = "$OpenBSD: dirname.c,v 1.6 2001/06/28 04:27:19 pjanzen Exp $";
|
static char rcsid[] = "$OpenBSD: dirname.c,v 1.7 2002/05/24 21:22:37 deraadt Exp $";
|
||||||
#endif /* LIBC_SCCS and not lint */
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -47,7 +47,7 @@ dirname(path)
|
|||||||
|
|
||||||
/* Empty or NULL string gets treated as "." */
|
/* Empty or NULL string gets treated as "." */
|
||||||
if (path == NULL || *path == '\0') {
|
if (path == NULL || *path == '\0') {
|
||||||
(void)strcpy(bname, ".");
|
(void)strlcpy(bname, ".", sizeof bname);
|
||||||
return(bname);
|
return(bname);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ dirname(path)
|
|||||||
|
|
||||||
/* Either the dir is "/" or there are no slashes */
|
/* Either the dir is "/" or there are no slashes */
|
||||||
if (endp == path) {
|
if (endp == path) {
|
||||||
(void)strcpy(bname, *endp == '/' ? "/" : ".");
|
(void)strlcpy(bname, *endp == '/' ? "/" : ".", sizeof bname);
|
||||||
return(bname);
|
return(bname);
|
||||||
} else {
|
} else {
|
||||||
do {
|
do {
|
||||||
|
@ -56,7 +56,7 @@ get_arg_max(void)
|
|||||||
#if 0
|
#if 0
|
||||||
static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93";
|
static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93";
|
||||||
#else
|
#else
|
||||||
static char rcsid[] = "$OpenBSD: glob.c,v 1.16 2001/04/05 18:36:12 deraadt Exp $";
|
static char rcsid[] = "$OpenBSD: glob.c,v 1.20 2002/06/14 21:34:58 todd Exp $";
|
||||||
#endif
|
#endif
|
||||||
#endif /* LIBC_SCCS and not lint */
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
@ -137,32 +137,32 @@ typedef char Char;
|
|||||||
#define ismeta(c) (((c)&M_QUOTE) != 0)
|
#define ismeta(c) (((c)&M_QUOTE) != 0)
|
||||||
|
|
||||||
|
|
||||||
static int compare __P((const void *, const void *));
|
static int compare(const void *, const void *);
|
||||||
static int g_Ctoc __P((const Char *, char *, u_int));
|
static int g_Ctoc(const Char *, char *, u_int);
|
||||||
static int g_lstat __P((Char *, struct stat *, glob_t *));
|
static int g_lstat(Char *, struct stat *, glob_t *);
|
||||||
static DIR *g_opendir __P((Char *, glob_t *));
|
static DIR *g_opendir(Char *, glob_t *);
|
||||||
static Char *g_strchr __P((Char *, int));
|
static Char *g_strchr(Char *, int);
|
||||||
static int g_stat __P((Char *, struct stat *, glob_t *));
|
static int g_stat(Char *, struct stat *, glob_t *);
|
||||||
static int glob0 __P((const Char *, glob_t *));
|
static int glob0(const Char *, glob_t *);
|
||||||
static int glob1 __P((Char *, Char *, glob_t *, size_t *));
|
static int glob1(Char *, Char *, glob_t *, size_t *);
|
||||||
static int glob2 __P((Char *, Char *, Char *, Char *, Char *, Char *,
|
static int glob2(Char *, Char *, Char *, Char *, Char *, Char *,
|
||||||
glob_t *, size_t *));
|
glob_t *, size_t *);
|
||||||
static int glob3 __P((Char *, Char *, Char *, Char *, Char *, Char *,
|
static int glob3(Char *, Char *, Char *, Char *, Char *, Char *,
|
||||||
Char *, Char *, glob_t *, size_t *));
|
Char *, Char *, glob_t *, size_t *);
|
||||||
static int globextend __P((const Char *, glob_t *, size_t *));
|
static int globextend(const Char *, glob_t *, size_t *);
|
||||||
static const Char *
|
static const Char *
|
||||||
globtilde __P((const Char *, Char *, size_t, glob_t *));
|
globtilde(const Char *, Char *, size_t, glob_t *);
|
||||||
static int globexp1 __P((const Char *, glob_t *));
|
static int globexp1(const Char *, glob_t *);
|
||||||
static int globexp2 __P((const Char *, const Char *, glob_t *, int *));
|
static int globexp2(const Char *, const Char *, glob_t *, int *);
|
||||||
static int match __P((Char *, Char *, Char *));
|
static int match(Char *, Char *, Char *);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
static void qprintf __P((const char *, Char *));
|
static void qprintf(const char *, Char *);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int
|
int
|
||||||
glob(pattern, flags, errfunc, pglob)
|
glob(pattern, flags, errfunc, pglob)
|
||||||
const char *pattern;
|
const char *pattern;
|
||||||
int flags, (*errfunc) __P((const char *, int));
|
int flags, (*errfunc)(const char *, int);
|
||||||
glob_t *pglob;
|
glob_t *pglob;
|
||||||
{
|
{
|
||||||
const u_char *patnext;
|
const u_char *patnext;
|
||||||
@ -677,7 +677,7 @@ glob3(pathbuf, pathbuf_last, pathend, pathend_last, pattern, pattern_last,
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Extend the gl_pathv member of a glob_t structure to accomodate a new item,
|
* Extend the gl_pathv member of a glob_t structure to accommodate a new item,
|
||||||
* add the new item, and update gl_pathc.
|
* add the new item, and update gl_pathc.
|
||||||
*
|
*
|
||||||
* This assumes the BSD realloc, which only copies the block when its size
|
* This assumes the BSD realloc, which only copies the block when its size
|
||||||
@ -822,7 +822,7 @@ g_opendir(str, pglob)
|
|||||||
char buf[MAXPATHLEN];
|
char buf[MAXPATHLEN];
|
||||||
|
|
||||||
if (!*str)
|
if (!*str)
|
||||||
strcpy(buf, ".");
|
strlcpy(buf, ".", sizeof buf);
|
||||||
else {
|
else {
|
||||||
if (g_Ctoc(str, buf, sizeof(buf)))
|
if (g_Ctoc(str, buf, sizeof(buf)))
|
||||||
return(NULL);
|
return(NULL);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD: glob.h,v 1.5 2001/03/18 17:18:58 deraadt Exp $ */
|
/* $OpenBSD: glob.h,v 1.7 2002/02/17 19:42:21 millert Exp $ */
|
||||||
/* $NetBSD: glob.h,v 1.5 1994/10/26 00:55:56 cgd Exp $ */
|
/* $NetBSD: glob.h,v 1.5 1994/10/26 00:55:56 cgd Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -53,18 +53,18 @@ typedef struct {
|
|||||||
int gl_flags; /* Copy of flags parameter to glob. */
|
int gl_flags; /* Copy of flags parameter to glob. */
|
||||||
char **gl_pathv; /* List of paths matching pattern. */
|
char **gl_pathv; /* List of paths matching pattern. */
|
||||||
/* Copy of errfunc parameter to glob. */
|
/* Copy of errfunc parameter to glob. */
|
||||||
int (*gl_errfunc) __P((const char *, int));
|
int (*gl_errfunc)(const char *, int);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Alternate filesystem access methods for glob; replacement
|
* Alternate filesystem access methods for glob; replacement
|
||||||
* versions of closedir(3), readdir(3), opendir(3), stat(2)
|
* versions of closedir(3), readdir(3), opendir(3), stat(2)
|
||||||
* and lstat(2).
|
* and lstat(2).
|
||||||
*/
|
*/
|
||||||
void (*gl_closedir) __P((void *));
|
void (*gl_closedir)(void *);
|
||||||
struct dirent *(*gl_readdir) __P((void *));
|
struct dirent *(*gl_readdir)(void *);
|
||||||
void *(*gl_opendir) __P((const char *));
|
void *(*gl_opendir)(const char *);
|
||||||
int (*gl_lstat) __P((const char *, struct stat *));
|
int (*gl_lstat)(const char *, struct stat *);
|
||||||
int (*gl_stat) __P((const char *, struct stat *));
|
int (*gl_stat)(const char *, struct stat *);
|
||||||
} glob_t;
|
} glob_t;
|
||||||
|
|
||||||
/* Flags */
|
/* Flags */
|
||||||
@ -91,8 +91,8 @@ typedef struct {
|
|||||||
#define GLOB_NOSYS (-4) /* Function not supported. */
|
#define GLOB_NOSYS (-4) /* Function not supported. */
|
||||||
#define GLOB_ABEND GLOB_ABORTED
|
#define GLOB_ABEND GLOB_ABORTED
|
||||||
|
|
||||||
int glob __P((const char *, int, int (*)(const char *, int), glob_t *));
|
int glob(const char *, int, int (*)(const char *, int), glob_t *);
|
||||||
void globfree __P((glob_t *));
|
void globfree(glob_t *);
|
||||||
|
|
||||||
#endif /* !_GLOB_H_ */
|
#endif /* !_GLOB_H_ */
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
#if defined(BROKEN_INET_NTOA) || !defined(HAVE_INET_NTOA)
|
#if defined(BROKEN_INET_NTOA) || !defined(HAVE_INET_NTOA)
|
||||||
|
|
||||||
#if defined(LIBC_SCCS) && !defined(lint)
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
static char rcsid[] = "$OpenBSD: inet_ntoa.c,v 1.2 1996/08/19 08:29:16 tholo Exp $";
|
static char rcsid[] = "$OpenBSD: inet_ntoa.c,v 1.3 2002/06/27 10:14:01 itojun Exp $";
|
||||||
#endif /* LIBC_SCCS and not lint */
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -57,7 +57,7 @@ char *inet_ntoa(struct in_addr in)
|
|||||||
p = (char *)∈
|
p = (char *)∈
|
||||||
#define UC(b) (((int)b)&0xff)
|
#define UC(b) (((int)b)&0xff)
|
||||||
(void)snprintf(b, sizeof(b),
|
(void)snprintf(b, sizeof(b),
|
||||||
"%d.%d.%d.%d", UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3]));
|
"%u.%u.%u.%u", UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3]));
|
||||||
return (b);
|
return (b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD: inet_ntop.c,v 1.1 1997/03/13 19:07:32 downsj Exp $ */
|
/* $OpenBSD: inet_ntop.c,v 1.5 2002/08/23 16:27:31 itojun Exp $ */
|
||||||
|
|
||||||
/* Copyright (c) 1996 by Internet Software Consortium.
|
/* Copyright (c) 1996 by Internet Software Consortium.
|
||||||
*
|
*
|
||||||
@ -24,7 +24,7 @@
|
|||||||
#if 0
|
#if 0
|
||||||
static char rcsid[] = "$From: inet_ntop.c,v 8.7 1996/08/05 08:41:18 vixie Exp $";
|
static char rcsid[] = "$From: inet_ntop.c,v 8.7 1996/08/05 08:41:18 vixie Exp $";
|
||||||
#else
|
#else
|
||||||
static char rcsid[] = "$OpenBSD: inet_ntop.c,v 1.1 1997/03/13 19:07:32 downsj Exp $";
|
static char rcsid[] = "$OpenBSD: inet_ntop.c,v 1.5 2002/08/23 16:27:31 itojun Exp $";
|
||||||
#endif
|
#endif
|
||||||
#endif /* LIBC_SCCS and not lint */
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
@ -54,8 +54,8 @@ static char rcsid[] = "$OpenBSD: inet_ntop.c,v 1.1 1997/03/13 19:07:32 downsj Ex
|
|||||||
* sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
|
* sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static const char *inet_ntop4 __P((const u_char *src, char *dst, size_t size));
|
static const char *inet_ntop4(const u_char *src, char *dst, size_t size);
|
||||||
static const char *inet_ntop6 __P((const u_char *src, char *dst, size_t size));
|
static const char *inet_ntop6(const u_char *src, char *dst, size_t size);
|
||||||
|
|
||||||
/* char *
|
/* char *
|
||||||
* inet_ntop(af, src, dst, size)
|
* inet_ntop(af, src, dst, size)
|
||||||
@ -103,13 +103,14 @@ inet_ntop4(src, dst, size)
|
|||||||
{
|
{
|
||||||
static const char fmt[] = "%u.%u.%u.%u";
|
static const char fmt[] = "%u.%u.%u.%u";
|
||||||
char tmp[sizeof "255.255.255.255"];
|
char tmp[sizeof "255.255.255.255"];
|
||||||
|
int l;
|
||||||
|
|
||||||
if (snprintf(tmp, sizeof(tmp), fmt, src[0], src[1], src[2],
|
l = snprintf(tmp, size, fmt, src[0], src[1], src[2], src[3]);
|
||||||
src[3]) > size) {
|
if (l <= 0 || l >= size) {
|
||||||
errno = ENOSPC;
|
errno = ENOSPC;
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
strcpy(dst, tmp);
|
strlcpy(dst, tmp, size);
|
||||||
return (dst);
|
return (dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,10 +133,12 @@ inet_ntop6(src, dst, size)
|
|||||||
* Keep this in mind if you think this function should have been coded
|
* Keep this in mind if you think this function should have been coded
|
||||||
* to use pointer overlays. All the world's not a VAX.
|
* to use pointer overlays. All the world's not a VAX.
|
||||||
*/
|
*/
|
||||||
char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp;
|
char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"];
|
||||||
|
char *tp, *ep;
|
||||||
struct { int base, len; } best, cur;
|
struct { int base, len; } best, cur;
|
||||||
u_int words[IN6ADDRSZ / INT16SZ];
|
u_int words[IN6ADDRSZ / INT16SZ];
|
||||||
int i;
|
int i;
|
||||||
|
int advance;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Preprocess:
|
* Preprocess:
|
||||||
@ -172,31 +175,45 @@ inet_ntop6(src, dst, size)
|
|||||||
* Format the result.
|
* Format the result.
|
||||||
*/
|
*/
|
||||||
tp = tmp;
|
tp = tmp;
|
||||||
for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) {
|
ep = tmp + sizeof(tmp);
|
||||||
|
for (i = 0; i < (IN6ADDRSZ / INT16SZ) && tp < ep; i++) {
|
||||||
/* Are we inside the best run of 0x00's? */
|
/* Are we inside the best run of 0x00's? */
|
||||||
if (best.base != -1 && i >= best.base &&
|
if (best.base != -1 && i >= best.base &&
|
||||||
i < (best.base + best.len)) {
|
i < (best.base + best.len)) {
|
||||||
if (i == best.base)
|
if (i == best.base) {
|
||||||
|
if (tp + 1 >= ep)
|
||||||
|
return (NULL);
|
||||||
*tp++ = ':';
|
*tp++ = ':';
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* Are we following an initial run of 0x00s or any real hex? */
|
/* Are we following an initial run of 0x00s or any real hex? */
|
||||||
if (i != 0)
|
if (i != 0) {
|
||||||
|
if (tp + 1 >= ep)
|
||||||
|
return (NULL);
|
||||||
*tp++ = ':';
|
*tp++ = ':';
|
||||||
|
}
|
||||||
/* Is this address an encapsulated IPv4? */
|
/* Is this address an encapsulated IPv4? */
|
||||||
if (i == 6 && best.base == 0 &&
|
if (i == 6 && best.base == 0 &&
|
||||||
(best.len == 6 || (best.len == 5 && words[5] == 0xffff))) {
|
(best.len == 6 || (best.len == 5 && words[5] == 0xffff))) {
|
||||||
if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp)))
|
if (!inet_ntop4(src+12, tp, (size_t)(ep - tp)))
|
||||||
return (NULL);
|
return (NULL);
|
||||||
tp += strlen(tp);
|
tp += strlen(tp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
snprintf(tp, sizeof(tmp - (tp - tmp)), "%x", words[i]);
|
advance = snprintf(tp, ep - tp, "%x", words[i]);
|
||||||
tp += strlen(tp);
|
if (advance <= 0 || advance >= ep - tp)
|
||||||
|
return (NULL);
|
||||||
|
tp += advance;
|
||||||
}
|
}
|
||||||
/* Was it a trailing run of 0x00's? */
|
/* Was it a trailing run of 0x00's? */
|
||||||
if (best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ))
|
if (best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ)) {
|
||||||
|
if (tp + 1 >= ep)
|
||||||
|
return (NULL);
|
||||||
*tp++ = ':';
|
*tp++ = ':';
|
||||||
|
}
|
||||||
|
if (tp + 1 >= ep)
|
||||||
|
return (NULL);
|
||||||
*tp++ = '\0';
|
*tp++ = '\0';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -206,7 +223,7 @@ inet_ntop6(src, dst, size)
|
|||||||
errno = ENOSPC;
|
errno = ENOSPC;
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
strcpy(dst, tmp);
|
strlcpy(dst, tmp, size);
|
||||||
return (dst);
|
return (dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
#ifndef HAVE_MKDTEMP
|
#ifndef HAVE_MKDTEMP
|
||||||
|
|
||||||
#if defined(LIBC_SCCS) && !defined(lint)
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
static char rcsid[] = "$OpenBSD: mktemp.c,v 1.14 2002/01/02 20:18:32 deraadt Exp $";
|
static char rcsid[] = "$OpenBSD: mktemp.c,v 1.16 2002/05/27 18:20:45 millert Exp $";
|
||||||
#endif /* LIBC_SCCS and not lint */
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
#ifdef HAVE_CYGWIN
|
#ifdef HAVE_CYGWIN
|
||||||
@ -102,11 +102,11 @@ _gettemp(path, doopen, domkdir, slen)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
pid = getpid();
|
pid = getpid();
|
||||||
while (*trv == 'X' && pid != 0) {
|
while (trv >= path && *trv == 'X' && pid != 0) {
|
||||||
*trv-- = (pid % 10) + '0';
|
*trv-- = (pid % 10) + '0';
|
||||||
pid /= 10;
|
pid /= 10;
|
||||||
}
|
}
|
||||||
while (*trv == 'X') {
|
while (trv >= path && *trv == 'X') {
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
pid = (arc4random() & 0xffff) % (26+26);
|
pid = (arc4random() & 0xffff) % (26+26);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/* $OpenBSD: readpassphrase.c,v 1.12 2001/12/15 05:41:00 millert Exp $ */
|
/* $OpenBSD: readpassphrase.c,v 1.14 2002/06/28 01:43:58 millert Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2000 Todd C. Miller <Todd.Miller@courtesan.com>
|
* Copyright (c) 2000-2002 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@ -28,7 +28,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(LIBC_SCCS) && !defined(lint)
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
static const char rcsid[] = "$OpenBSD: readpassphrase.c,v 1.12 2001/12/15 05:41:00 millert Exp $";
|
static const char rcsid[] = "$OpenBSD: readpassphrase.c,v 1.14 2002/06/28 01:43:58 millert Exp $";
|
||||||
#endif /* LIBC_SCCS and not lint */
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
#include "includes.h"
|
#include "includes.h"
|
||||||
@ -60,8 +60,8 @@ readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags)
|
|||||||
int input, output, save_errno;
|
int input, output, save_errno;
|
||||||
char ch, *p, *end;
|
char ch, *p, *end;
|
||||||
struct termios term, oterm;
|
struct termios term, oterm;
|
||||||
struct sigaction sa, saveint, savehup, savequit, saveterm;
|
struct sigaction sa, savealrm, saveint, savehup, savequit, saveterm;
|
||||||
struct sigaction savetstp, savettin, savettou;
|
struct sigaction savetstp, savettin, savettou, savepipe;
|
||||||
|
|
||||||
/* I suppose we could alloc on demand in this case (XXX). */
|
/* I suppose we could alloc on demand in this case (XXX). */
|
||||||
if (bufsiz == 0) {
|
if (bufsiz == 0) {
|
||||||
@ -70,11 +70,13 @@ readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
restart:
|
restart:
|
||||||
|
signo = 0;
|
||||||
/*
|
/*
|
||||||
* Read and write to /dev/tty if available. If not, read from
|
* Read and write to /dev/tty if available. If not, read from
|
||||||
* stdin and write to stderr unless a tty is required.
|
* stdin and write to stderr unless a tty is required.
|
||||||
*/
|
*/
|
||||||
if ((input = output = open(_PATH_TTY, O_RDWR)) == -1) {
|
if ((flags & RPP_STDIN) ||
|
||||||
|
(input = output = open(_PATH_TTY, O_RDWR)) == -1) {
|
||||||
if (flags & RPP_REQUIRE_TTY) {
|
if (flags & RPP_REQUIRE_TTY) {
|
||||||
errno = ENOTTY;
|
errno = ENOTTY;
|
||||||
return(NULL);
|
return(NULL);
|
||||||
@ -86,13 +88,15 @@ restart:
|
|||||||
/*
|
/*
|
||||||
* Catch signals that would otherwise cause the user to end
|
* Catch signals that would otherwise cause the user to end
|
||||||
* up with echo turned off in the shell. Don't worry about
|
* up with echo turned off in the shell. Don't worry about
|
||||||
* things like SIGALRM and SIGPIPE for now.
|
* things like SIGXCPU and SIGVTALRM for now.
|
||||||
*/
|
*/
|
||||||
sigemptyset(&sa.sa_mask);
|
sigemptyset(&sa.sa_mask);
|
||||||
sa.sa_flags = 0; /* don't restart system calls */
|
sa.sa_flags = 0; /* don't restart system calls */
|
||||||
sa.sa_handler = handler;
|
sa.sa_handler = handler;
|
||||||
(void)sigaction(SIGINT, &sa, &saveint);
|
(void)sigaction(SIGALRM, &sa, &savealrm);
|
||||||
(void)sigaction(SIGHUP, &sa, &savehup);
|
(void)sigaction(SIGHUP, &sa, &savehup);
|
||||||
|
(void)sigaction(SIGINT, &sa, &saveint);
|
||||||
|
(void)sigaction(SIGPIPE, &sa, &savepipe);
|
||||||
(void)sigaction(SIGQUIT, &sa, &savequit);
|
(void)sigaction(SIGQUIT, &sa, &savequit);
|
||||||
(void)sigaction(SIGTERM, &sa, &saveterm);
|
(void)sigaction(SIGTERM, &sa, &saveterm);
|
||||||
(void)sigaction(SIGTSTP, &sa, &savetstp);
|
(void)sigaction(SIGTSTP, &sa, &savetstp);
|
||||||
@ -100,7 +104,7 @@ restart:
|
|||||||
(void)sigaction(SIGTTOU, &sa, &savettou);
|
(void)sigaction(SIGTTOU, &sa, &savettou);
|
||||||
|
|
||||||
/* Turn off echo if possible. */
|
/* Turn off echo if possible. */
|
||||||
if (tcgetattr(input, &oterm) == 0) {
|
if (input != STDIN_FILENO && tcgetattr(input, &oterm) == 0) {
|
||||||
memcpy(&term, &oterm, sizeof(term));
|
memcpy(&term, &oterm, sizeof(term));
|
||||||
if (!(flags & RPP_ECHO_ON))
|
if (!(flags & RPP_ECHO_ON))
|
||||||
term.c_lflag &= ~(ECHO | ECHONL);
|
term.c_lflag &= ~(ECHO | ECHONL);
|
||||||
@ -111,9 +115,12 @@ restart:
|
|||||||
(void)tcsetattr(input, _T_FLUSH, &term);
|
(void)tcsetattr(input, _T_FLUSH, &term);
|
||||||
} else {
|
} else {
|
||||||
memset(&term, 0, sizeof(term));
|
memset(&term, 0, sizeof(term));
|
||||||
|
term.c_lflag |= ECHO;
|
||||||
memset(&oterm, 0, sizeof(oterm));
|
memset(&oterm, 0, sizeof(oterm));
|
||||||
|
oterm.c_lflag |= ECHO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(flags & RPP_STDIN))
|
||||||
(void)write(output, prompt, strlen(prompt));
|
(void)write(output, prompt, strlen(prompt));
|
||||||
end = buf + bufsiz - 1;
|
end = buf + bufsiz - 1;
|
||||||
for (p = buf; (nr = read(input, &ch, 1)) == 1 && ch != '\n' && ch != '\r';) {
|
for (p = buf; (nr = read(input, &ch, 1)) == 1 && ch != '\n' && ch != '\r';) {
|
||||||
@ -137,13 +144,14 @@ restart:
|
|||||||
/* Restore old terminal settings and signals. */
|
/* Restore old terminal settings and signals. */
|
||||||
if (memcmp(&term, &oterm, sizeof(term)) != 0)
|
if (memcmp(&term, &oterm, sizeof(term)) != 0)
|
||||||
(void)tcsetattr(input, _T_FLUSH, &oterm);
|
(void)tcsetattr(input, _T_FLUSH, &oterm);
|
||||||
(void)sigaction(SIGINT, &saveint, NULL);
|
(void)sigaction(SIGALRM, &savealrm, NULL);
|
||||||
(void)sigaction(SIGHUP, &savehup, NULL);
|
(void)sigaction(SIGHUP, &savehup, NULL);
|
||||||
|
(void)sigaction(SIGINT, &saveint, NULL);
|
||||||
(void)sigaction(SIGQUIT, &savequit, NULL);
|
(void)sigaction(SIGQUIT, &savequit, NULL);
|
||||||
|
(void)sigaction(SIGPIPE, &savepipe, NULL);
|
||||||
(void)sigaction(SIGTERM, &saveterm, NULL);
|
(void)sigaction(SIGTERM, &saveterm, NULL);
|
||||||
(void)sigaction(SIGTSTP, &savetstp, NULL);
|
(void)sigaction(SIGTSTP, &savetstp, NULL);
|
||||||
(void)sigaction(SIGTTIN, &savettin, NULL);
|
(void)sigaction(SIGTTIN, &savettin, NULL);
|
||||||
(void)sigaction(SIGTTOU, &savettou, NULL);
|
|
||||||
if (input != STDIN_FILENO)
|
if (input != STDIN_FILENO)
|
||||||
(void)close(input);
|
(void)close(input);
|
||||||
|
|
||||||
@ -157,7 +165,6 @@ restart:
|
|||||||
case SIGTSTP:
|
case SIGTSTP:
|
||||||
case SIGTTIN:
|
case SIGTTIN:
|
||||||
case SIGTTOU:
|
case SIGTTOU:
|
||||||
signo = 0;
|
|
||||||
goto restart;
|
goto restart;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD: readpassphrase.h,v 1.1 2000/11/21 00:48:38 millert Exp $ */
|
/* $OpenBSD: readpassphrase.h,v 1.3 2002/06/28 12:32:22 millert Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2000 Todd C. Miller <Todd.Miller@courtesan.com>
|
* Copyright (c) 2000 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||||
@ -40,6 +40,7 @@
|
|||||||
#define RPP_FORCELOWER 0x04 /* Force input to lower case. */
|
#define RPP_FORCELOWER 0x04 /* Force input to lower case. */
|
||||||
#define RPP_FORCEUPPER 0x08 /* Force input to upper case. */
|
#define RPP_FORCEUPPER 0x08 /* Force input to upper case. */
|
||||||
#define RPP_SEVENBIT 0x10 /* Strip the high bit from input. */
|
#define RPP_SEVENBIT 0x10 /* Strip the high bit from input. */
|
||||||
|
#define RPP_STDIN 0x20 /* Read from stdin, not /dev/tty */
|
||||||
|
|
||||||
char * readpassphrase(const char *, char *, size_t, int);
|
char * readpassphrase(const char *, char *, size_t, int);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user