xref: /openbsd-src/lib/libcurses/nc_access.h (revision c7ef0cfc17afcba97172c25e1e3a943e893bc632)
1*c7ef0cfcSnicm /****************************************************************************
2*c7ef0cfcSnicm  * Copyright 2021,2023 Thomas E. Dickey                                     *
3*c7ef0cfcSnicm  *                                                                          *
4*c7ef0cfcSnicm  * Permission is hereby granted, free of charge, to any person obtaining a  *
5*c7ef0cfcSnicm  * copy of this software and associated documentation files (the            *
6*c7ef0cfcSnicm  * "Software"), to deal in the Software without restriction, including      *
7*c7ef0cfcSnicm  * without limitation the rights to use, copy, modify, merge, publish,      *
8*c7ef0cfcSnicm  * distribute, distribute with modifications, sublicense, and/or sell       *
9*c7ef0cfcSnicm  * copies of the Software, and to permit persons to whom the Software is    *
10*c7ef0cfcSnicm  * furnished to do so, subject to the following conditions:                 *
11*c7ef0cfcSnicm  *                                                                          *
12*c7ef0cfcSnicm  * The above copyright notice and this permission notice shall be included  *
13*c7ef0cfcSnicm  * in all copies or substantial portions of the Software.                   *
14*c7ef0cfcSnicm  *                                                                          *
15*c7ef0cfcSnicm  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
16*c7ef0cfcSnicm  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
17*c7ef0cfcSnicm  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
18*c7ef0cfcSnicm  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
19*c7ef0cfcSnicm  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
20*c7ef0cfcSnicm  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
21*c7ef0cfcSnicm  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
22*c7ef0cfcSnicm  *                                                                          *
23*c7ef0cfcSnicm  * Except as contained in this notice, the name(s) of the above copyright   *
24*c7ef0cfcSnicm  * holders shall not be used in advertising or otherwise to promote the     *
25*c7ef0cfcSnicm  * sale, use or other dealings in this Software without prior written       *
26*c7ef0cfcSnicm  * authorization.                                                           *
27*c7ef0cfcSnicm  ****************************************************************************/
28*c7ef0cfcSnicm 
29*c7ef0cfcSnicm /* $Id: nc_access.h,v 1.1 2023/10/17 09:52:08 nicm Exp $ */
30*c7ef0cfcSnicm 
31*c7ef0cfcSnicm #ifndef NC_ACCESS_included
32*c7ef0cfcSnicm #define NC_ACCESS_included 1
33*c7ef0cfcSnicm /* *INDENT-OFF* */
34*c7ef0cfcSnicm 
35*c7ef0cfcSnicm #include <ncurses_cfg.h>
36*c7ef0cfcSnicm #include <curses.h>
37*c7ef0cfcSnicm #include <sys/types.h>
38*c7ef0cfcSnicm 
39*c7ef0cfcSnicm #ifdef __cplusplus
40*c7ef0cfcSnicm extern "C" {
41*c7ef0cfcSnicm #endif
42*c7ef0cfcSnicm 
43*c7ef0cfcSnicm /*
44*c7ef0cfcSnicm  * Turn off the 'use_terminfo_vars()' symbol to limit access to environment
45*c7ef0cfcSnicm  * variables when running with privileges.
46*c7ef0cfcSnicm  */
47*c7ef0cfcSnicm #if defined(USE_ROOT_ENVIRON) && defined(USE_SETUID_ENVIRON)
48*c7ef0cfcSnicm #define use_terminfo_vars() 1
49*c7ef0cfcSnicm #else
50*c7ef0cfcSnicm #define use_terminfo_vars() _nc_env_access()
51*c7ef0cfcSnicm #endif
52*c7ef0cfcSnicm 
53*c7ef0cfcSnicm extern NCURSES_EXPORT(int) _nc_env_access (void);
54*c7ef0cfcSnicm 
55*c7ef0cfcSnicm /*
56*c7ef0cfcSnicm  * Turn off this symbol to limit access to files when running setuid.
57*c7ef0cfcSnicm  */
58*c7ef0cfcSnicm #ifdef USE_ROOT_ACCESS
59*c7ef0cfcSnicm 
60*c7ef0cfcSnicm #define safe_fopen(name,mode)       fopen(name,mode)
61*c7ef0cfcSnicm #define safe_open2(name,flags)      open(name,flags)
62*c7ef0cfcSnicm #define safe_open3(name,flags,mode) open(name,flags,mode)
63*c7ef0cfcSnicm 
64*c7ef0cfcSnicm #else
65*c7ef0cfcSnicm 
66*c7ef0cfcSnicm #define safe_fopen(name,mode)       _nc_safe_fopen(name,mode)
67*c7ef0cfcSnicm #define safe_open2(name,flags)      _nc_safe_open3(name,flags,0)
68*c7ef0cfcSnicm #define safe_open3(name,flags,mode) _nc_safe_open3(name,flags,mode)
69*c7ef0cfcSnicm extern NCURSES_EXPORT(FILE *)       _nc_safe_fopen (const char *, const char *);
70*c7ef0cfcSnicm extern NCURSES_EXPORT(int)          _nc_safe_open3 (const char *, int, mode_t);
71*c7ef0cfcSnicm 
72*c7ef0cfcSnicm #endif
73*c7ef0cfcSnicm 
74*c7ef0cfcSnicm #ifdef __cplusplus
75*c7ef0cfcSnicm }
76*c7ef0cfcSnicm #endif
77*c7ef0cfcSnicm 
78*c7ef0cfcSnicm /* *INDENT-ON* */
79*c7ef0cfcSnicm 
80*c7ef0cfcSnicm #endif /* NC_ACCESS_included */
81