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