diff options
-rw-r--r-- | lib/libcurses/Makefile | 4 | ||||
-rw-r--r-- | lib/libcurses/access.c | 55 | ||||
-rw-r--r-- | lib/libcurses/curs_insstr.3 | 4 | ||||
-rw-r--r-- | lib/libcurses/curses.h | 4 | ||||
-rw-r--r-- | lib/libcurses/curses.priv.h | 5 | ||||
-rw-r--r-- | lib/libcurses/lib_screen.c | 13 | ||||
-rw-r--r-- | lib/libcurses/lib_termcap.c | 10 | ||||
-rw-r--r-- | lib/libcurses/lib_trace.c | 8 | ||||
-rw-r--r-- | lib/libcurses/read_entry.c | 8 | ||||
-rw-r--r-- | lib/libcurses/read_termcap.c | 60 | ||||
-rw-r--r-- | lib/libcurses/write_entry.c | 10 |
11 files changed, 126 insertions, 55 deletions
diff --git a/lib/libcurses/Makefile b/lib/libcurses/Makefile index 1ce85c14c16..9e884d581f8 100644 --- a/lib/libcurses/Makefile +++ b/lib/libcurses/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.23 1998/07/23 21:23:40 millert Exp $ +# $OpenBSD: Makefile,v 1.24 1998/07/27 03:37:26 millert Exp $ # Uncomment this to enable tracing in libcurses #CURSESTRACE=-DTRACE @@ -10,7 +10,7 @@ FALLBACK_LIST= AWK?= /usr/bin/awk LIB= curses -SRCS= alloc_entry.c captoinfo.c codes.c comp_captab.c comp_error.c \ +SRCS= access.c alloc_entry.c captoinfo.c codes.c comp_captab.c comp_error.c \ comp_expand.c comp_hash.c comp_parse.c comp_scan.c define_key.c \ expanded.c fallback.c hardscroll.c hashmap.c keyok.c lib_acs.c \ lib_adabind.c lib_addch.c lib_addstr.c lib_baudrate.c \ diff --git a/lib/libcurses/access.c b/lib/libcurses/access.c new file mode 100644 index 00000000000..1060467caf9 --- /dev/null +++ b/lib/libcurses/access.c @@ -0,0 +1,55 @@ +/**************************************************************************** + * Copyright (c) 1998 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + +/**************************************************************************** + * Author: Thomas E. Dickey <dickey@clark.net> 1998 * + ****************************************************************************/ + + +#include <curses.priv.h> + +MODULE_ID("$Id: access.c,v 1.1 1998/07/27 03:37:27 millert Exp $") + +int _nc_access(const char *path, int mode) +{ + if (access(path, mode) < 0) { + if ((mode & W_OK) != 0 + && errno == ENOENT) { + char head[PATH_MAX]; + char *leaf = strrchr(strcpy(head, path), '/'); + if (leaf == 0) + leaf = head; + *leaf = '\0'; + if (head == leaf) + (void)strcpy(head, "."); + return access(head, R_OK|W_OK|X_OK); + } + return -1; + } + return 0; +} diff --git a/lib/libcurses/curs_insstr.3 b/lib/libcurses/curs_insstr.3 index 805cb0e7bba..b479c5cc468 100644 --- a/lib/libcurses/curs_insstr.3 +++ b/lib/libcurses/curs_insstr.3 @@ -26,8 +26,8 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $From: curs_insstr.3x,v 1.9 1998/03/11 21:12:53 juergen Exp $ -.\" $OpenBSD: curs_insstr.3,v 1.6 1998/07/23 21:17:47 millert Exp $ +.\" $From: curs_insstr.3x,v 1.10 1998/07/25 20:32:57 Todd.Miller Exp $ +.\" $OpenBSD: curs_insstr.3,v 1.7 1998/07/27 03:37:27 millert Exp $ .TH curs_insstr 3 "" .SH NAME \fBinsstr\fR, \fBinsnstr\fR, \fBwinsstr\fR, \fBwinsnstr\fR, diff --git a/lib/libcurses/curses.h b/lib/libcurses/curses.h index 9428998f79d..748322b93dd 100644 --- a/lib/libcurses/curses.h +++ b/lib/libcurses/curses.h @@ -1,4 +1,4 @@ -/* $OpenBSD: curses.h,v 1.8 1998/07/23 21:18:11 millert Exp $ */ +/* $OpenBSD: curses.h,v 1.9 1998/07/27 03:37:28 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -50,7 +50,7 @@ /* These are defined only in curses.h, and are used for conditional compiles */ #define NCURSES_VERSION_MAJOR 4 #define NCURSES_VERSION_MINOR 2 -#define NCURSES_VERSION_PATCH 980718 +#define NCURSES_VERSION_PATCH 980725 /* This is defined in more than one ncurses header, for identification */ #undef NCURSES_VERSION diff --git a/lib/libcurses/curses.priv.h b/lib/libcurses/curses.priv.h index a7106714b2d..a0762f9ba03 100644 --- a/lib/libcurses/curses.priv.h +++ b/lib/libcurses/curses.priv.h @@ -1,4 +1,4 @@ -/* $OpenBSD: curses.priv.h,v 1.6 1998/07/23 21:18:12 millert Exp $ */ +/* $OpenBSD: curses.priv.h,v 1.7 1998/07/27 03:37:30 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -35,7 +35,7 @@ /* - * $From: curses.priv.h,v 1.105 1998/06/28 00:11:47 tom Exp $ + * $From: curses.priv.h,v 1.106 1998/07/25 20:07:29 tom Exp $ * * curses.priv.h * @@ -645,6 +645,7 @@ extern WINDOW *_nc_makenew(int, int, int, int, int); extern char *_nc_trace_buf(int, size_t); extern chtype _nc_background(WINDOW *); extern chtype _nc_render(WINDOW *, chtype); +extern int _nc_access(const char *, int); extern int _nc_keypad(bool); extern int _nc_outch(int); extern int _nc_setupscreen(short, short const, FILE *); diff --git a/lib/libcurses/lib_screen.c b/lib/libcurses/lib_screen.c index a3b83ce6934..6e7c6727d40 100644 --- a/lib/libcurses/lib_screen.c +++ b/lib/libcurses/lib_screen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_screen.c,v 1.5 1998/07/23 21:19:19 millert Exp $ */ +/* $OpenBSD: lib_screen.c,v 1.6 1998/07/27 03:37:31 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -40,7 +40,7 @@ #include <time.h> #include <term.h> /* exit_ca_mode, non_rev_rmcup */ -MODULE_ID("$From: lib_screen.c,v 1.11 1998/02/11 12:13:56 tom Exp $") +MODULE_ID("$From: lib_screen.c,v 1.13 1998/07/25 20:10:48 tom Exp $") static time_t dumptime; @@ -131,7 +131,8 @@ int scr_restore(const char *file) T((T_CALLED("scr_restore(%s)"), _nc_visbuf(file))); - if ((fp = fopen(file, "rb")) == 0) + if (_nc_access(file, R_OK) < 0 + || (fp = fopen(file, "rb")) == 0) returnCode(ERR); else { @@ -148,7 +149,8 @@ int scr_dump(const char *file) T((T_CALLED("scr_dump(%s)"), _nc_visbuf(file))); - if ((fp = fopen(file, "wb")) == 0) + if (_nc_access(file, W_OK) < 0 + || (fp = fopen(file, "wb")) == 0) returnCode(ERR); else { @@ -171,7 +173,8 @@ int scr_init(const char *file) returnCode(ERR); #endif /* exit_ca_mode */ - if ((fp = fopen(file, "rb")) == 0) + if (_nc_access(file, R_OK) < 0 + || (fp = fopen(file, "rb")) == 0) returnCode(ERR); else if (fstat(STDOUT_FILENO, &stb) || stb.st_mtime > dumptime) returnCode(ERR); diff --git a/lib/libcurses/lib_termcap.c b/lib/libcurses/lib_termcap.c index a28911d72fc..bfab90e9c0c 100644 --- a/lib/libcurses/lib_termcap.c +++ b/lib/libcurses/lib_termcap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_termcap.c,v 1.1 1998/07/23 21:19:37 millert Exp $ */ +/* $OpenBSD: lib_termcap.c,v 1.2 1998/07/27 03:37:32 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -41,7 +41,7 @@ #define __INTERNAL_CAPS_VISIBLE #include <term.h> -MODULE_ID("$From: lib_termcap.c,v 1.20 1998/07/18 02:15:40 tom Exp $") +MODULE_ID("$From: lib_termcap.c,v 1.21 1998/07/25 20:58:56 tom Exp $") /* some of the code in here was contributed by: @@ -177,7 +177,7 @@ int i; T(("tgetflag: %s", id)); if (cur_term != 0) { for (i = 0; i < BOOLCOUNT; i++) { - if (!strcmp(id, boolcodes[i])) { + if (!strncmp(id, boolcodes[i], 2)) { if (!VALID_BOOLEAN(cur_term->type.Booleans[i])) return 0; return cur_term->type.Booleans[i]; @@ -203,7 +203,7 @@ int i; T(("tgetnum: %s", id)); if (cur_term != 0) { for (i = 0; i < NUMCOUNT; i++) { - if (!strcmp(id, numcodes[i])) { + if (!strncmp(id, numcodes[i], 2)) { if (!VALID_NUMERIC(cur_term->type.Numbers[i])) return -1; return cur_term->type.Numbers[i]; @@ -230,7 +230,7 @@ int i; if (cur_term != 0) { for (i = 0; i < STRCOUNT; i++) { T(("trying %s", strcodes[i])); - if (!strcmp(id, strcodes[i])) { + if (!strncmp(id, strcodes[i], 2)) { T(("found match : %s", _nc_visbuf(cur_term->type.Strings[i]))); if (!VALID_STRING(cur_term->type.Strings[i])) return 0; diff --git a/lib/libcurses/lib_trace.c b/lib/libcurses/lib_trace.c index 80b8f6619be..f2e4bff596e 100644 --- a/lib/libcurses/lib_trace.c +++ b/lib/libcurses/lib_trace.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_trace.c,v 1.3 1998/07/23 21:19:38 millert Exp $ */ +/* $OpenBSD: lib_trace.c,v 1.4 1998/07/27 03:37:33 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -40,7 +40,7 @@ #include <curses.priv.h> #include <tic.h> -MODULE_ID("$From: lib_trace.c,v 1.27 1998/07/18 02:18:45 tom Exp $") +MODULE_ID("$From: lib_trace.c,v 1.29 1998/07/25 20:11:02 tom Exp $") #include <ctype.h> #if HAVE_FCNTL_H @@ -61,12 +61,14 @@ void trace(const unsigned int tracelevel GCC_UNUSED) { #ifdef TRACE static bool been_here = FALSE; +static char my_name[] = "trace"; _nc_tracing = tracelevel; if (! been_here && tracelevel) { been_here = TRUE; - if ((tracefp = fopen("trace", "w")) == 0) { + if (_nc_access(my_name, W_OK) < 0 + || (tracefp = fopen(my_name, "w")) == 0) { perror("curses: Can't open 'trace' file: "); exit(EXIT_FAILURE); } diff --git a/lib/libcurses/read_entry.c b/lib/libcurses/read_entry.c index 113ef7ad506..f4457941f37 100644 --- a/lib/libcurses/read_entry.c +++ b/lib/libcurses/read_entry.c @@ -1,4 +1,4 @@ -/* $OpenBSD: read_entry.c,v 1.1 1998/07/23 21:19:59 millert Exp $ */ +/* $OpenBSD: read_entry.c,v 1.2 1998/07/27 03:37:34 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -45,12 +45,11 @@ #if HAVE_FCNTL_H #include <fcntl.h> #endif -#include <sys/stat.h> #include <term.h> #include <tic.h> -MODULE_ID("$From: read_entry.c,v 1.38 1998/06/06 22:47:24 tom Exp $") +MODULE_ID("$From: read_entry.c,v 1.40 1998/07/25 20:11:11 tom Exp $") #ifndef O_BINARY #define O_BINARY 0 @@ -100,7 +99,8 @@ int _nc_read_file_entry(const char *const filename, TERMTYPE *ptr) int i, fd, numread; char buf[MAX_ENTRY_SIZE]; - if ((fd = open(filename, O_RDONLY|O_BINARY)) < 0) + if (_nc_access(filename, R_OK) < 0 + || (fd = open(filename, O_RDONLY|O_BINARY)) < 0) return(0); T(("read terminfo %s", filename)); diff --git a/lib/libcurses/read_termcap.c b/lib/libcurses/read_termcap.c index 6d334b58de4..bed10b8b456 100644 --- a/lib/libcurses/read_termcap.c +++ b/lib/libcurses/read_termcap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: read_termcap.c,v 1.1 1998/07/23 21:19:59 millert Exp $ */ +/* $OpenBSD: read_termcap.c,v 1.2 1998/07/27 03:37:35 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -63,7 +63,7 @@ #include <fcntl.h> #endif -MODULE_ID("$From: read_termcap.c,v 1.30 1998/05/30 23:49:12 Todd.Miller Exp $") +MODULE_ID("$From: read_termcap.c,v 1.33 1998/07/25 20:22:11 tom Exp $") #ifndef PURE_TERMINFO @@ -324,15 +324,14 @@ _nc_getent( */ if (fd >= 0) { (void)lseek(fd, (off_t)0, SEEK_SET); + } else if (_nc_access(db_array[current], R_OK) < 0 + || (fd = open(db_array[current], O_RDONLY, 0) < 0)) { + /* No error on unfound file. */ + if (errno == ENOENT) + continue; + free(record); + return (TC_SYS_ERR); } else { - fd = open(db_array[current], O_RDONLY, 0); - if (fd < 0) { - /* No error on unfound file. */ - if (errno == ENOENT) - continue; - free(record); - return (TC_SYS_ERR); - } myfd = TRUE; } lineno = 0; @@ -899,6 +898,24 @@ _nc_tgetent(char *bp, char **sourcename, int *lineno, const char *name) #endif /* USE_BSD_TGETENT */ #endif /* USE_GETCAP */ +#define MAXPATHS 32 + +/* + * Add a filename to the list in 'termpaths[]', checking that we really have + * a right to open the file. + */ +#if !USE_GETCAP +static int add_tc(char *termpaths[], char *path, int count) +{ + if (count < MAXPATHS + && _nc_access(path, R_OK) == 0) + termpaths[count++] = path; + termpaths[count] = 0; + return count; +} +#define ADD_TC(path, count) filecount = add_tc(termpaths, path, count) +#endif /* !USE_GETCAP */ + int _nc_read_termcap_entry(const char *const tn, TERMTYPE *const tp) { int found = FALSE; @@ -946,19 +963,18 @@ int _nc_read_termcap_entry(const char *const tn, TERMTYPE *const tp) * if the database is not accessible. */ FILE *fp; -#define MAXPATHS 32 char *tc, *termpaths[MAXPATHS]; int filecount = 0; bool use_buffer = FALSE; char tc_buf[1024]; char pathbuf[PATH_MAX]; + termpaths[filecount] = 0; if ((tc = getenv("TERMCAP")) != 0) { if (is_pathname(tc)) /* interpret as a filename */ { - termpaths[0] = tc; - termpaths[filecount = 1] = 0; + ADD_TC(tc, 0); } else if (_nc_name_match(tc, tn, "|:")) /* treat as a capability file */ { @@ -975,13 +991,9 @@ int _nc_read_termcap_entry(const char *const tn, TERMTYPE *const tp) *cp = '\0'; else if (cp == tc || cp[-1] == '\0') { - if (filecount >= MAXPATHS - 1) - return(-1); - - termpaths[filecount++] = cp; + ADD_TC(cp, filecount); } } - termpaths[filecount] = 0; } } else /* normal case */ @@ -994,20 +1006,18 @@ int _nc_read_termcap_entry(const char *const tn, TERMTYPE *const tp) * Probably /etc/termcap is a symlink to /usr/share/misc/termcap. * Avoid reading the same file twice. */ - if (access("/etc/termcap", R_OK) == 0) - termpaths[filecount++] = "/etc/termcap"; - else if (access("/usr/share/misc/termcap", R_OK) == 0) - termpaths[filecount++] = "/usr/share/misc/termcap"; + if (_nc_access("/etc/termcap", F_OK) == 0) + ADD_TC("/etc/termcap", filecount); + else + ADD_TC("/usr/share/misc/termcap", filecount); if ((h = getenv("HOME")) != NULL && strlen(h) + 9 < PATH_MAX) { /* user's .termcap, if any, should override it */ (void) strcpy(envhome, h); (void) sprintf(pathbuf, "%s/.termcap", envhome); - termpaths[filecount++] = pathbuf; + ADD_TC(pathbuf, filecount); } - - termpaths[filecount] = 0; } /* parse the sources */ diff --git a/lib/libcurses/write_entry.c b/lib/libcurses/write_entry.c index 459885a1680..ccf93dd25ac 100644 --- a/lib/libcurses/write_entry.c +++ b/lib/libcurses/write_entry.c @@ -1,4 +1,4 @@ -/* $OpenBSD: write_entry.c,v 1.1 1998/07/23 21:20:12 millert Exp $ */ +/* $OpenBSD: write_entry.c,v 1.2 1998/07/27 03:37:37 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998 Free Software Foundation, Inc. * @@ -51,7 +51,7 @@ #define S_ISDIR(mode) ((mode & S_IFMT) == S_IFDIR) #endif -MODULE_ID("$From: write_entry.c,v 1.25 1998/07/18 16:52:22 tom Exp $") +MODULE_ID("$From: write_entry.c,v 1.28 1998/07/25 20:11:51 tom Exp $") static int total_written; @@ -59,7 +59,7 @@ static int write_object(FILE *, TERMTYPE *); static void write_file(char *filename, TERMTYPE *tp) { - FILE *fp = fopen(filename, "wb"); + FILE *fp = (_nc_access(filename, W_OK) == 0) ? fopen(filename, "wb") : 0; if (fp == 0) { perror(filename); _nc_syserr_abort("can't open %s/%s", _nc_tic_dir(0), filename); @@ -97,7 +97,7 @@ const char *destination = _nc_tic_dir(0); if ((rc = stat(path, &statbuf)) < 0) { rc = mkdir(path, 0777); } else { - if (access(path, R_OK|W_OK|X_OK) < 0) { + if (_nc_access(path, R_OK|W_OK|X_OK) < 0) { rc = -1; /* permission denied */ } else if (!(S_ISDIR(statbuf.st_mode))) { rc = -1; /* not a directory */ @@ -305,7 +305,7 @@ static time_t start_time; /* time at start of writes */ { _nc_warning("alias %s multiply defined.", ptr); } - else + else if (_nc_access(linkname, W_OK) == 0) #if HAVE_LINK { #if USE_SYMLINKS |