1 /*
2 Copyright (C) 2015-2021, Dirk Krause
3 SPDX-License-Identifier: BSD-3-Clause
4 */
5 
6 /*
7 	WARNING: This file was generated by the dkct program (see
8 	http://dktools.sourceforge.net/ for details).
9 	Changes you make here will be lost if dkct is run again!
10 	You should modify the original source and run dkct on it.
11 	Original source: dk4fopd.ctr
12 */
13 
14 #ifndef DK4FOPD_H_INCLUDED
15 /** Avoid multiple inclusions. */
16 #define DK4FOPD_H_INCLUDED 1
17 
18 
19 /**	@file
20 	Open file with additional security
21 	checks, file name is specified in dkChar characters.
22 */
23 
24 #ifndef	DK4CONF_H_INCLUDED
25 #if DK4_BUILDING_DKTOOLS4
26 #include "dk4conf.h"
27 #else
28 #include <dktools-4/dk4conf.h>
29 #endif
30 #endif
31 
32 #ifndef	DK4FOPC8_H_INCLUDED
33 #if DK4_BUILDING_DKTOOLS4
34 #include <libdk4c/dk4fopc8.h>
35 #else
36 #include <dktools-4/dk4fopc8.h>
37 #endif
38 #endif
39 
40 #if DK4_CHAR_SIZE > 1
41 #ifndef	DK4FOPWC_H_INCLUDED
42 #if DK4_BUILDING_DKTOOLS4
43 #include <libdk4c/dk4fopwc.h>
44 #else
45 #include <dktools-4/dk4fopwc.h>
46 #endif
47 #endif
48 #endif
49 
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
55 /**	Open a file after doing security checks.
56 	CRT on Windows: Required.
57 	@param	name	File name to open.
58 	@param	mode	Opening mode.
59 	@param	tests	Set of tests, see dk4fopc8.h.
60 	@param	erp	Error report, may be NULL.
61 	@return	Pointer to open file on success, NULL on error.
62 
63 	Error codes:
64 	- DK4_E_INVALID_ARGUMENTS<br>
65 	  if name is NULL,
66 	- DK4_E_SYNTAX<br>
67 	  if name does not refer to a regular file,
68 	- DK4_E_SEC_CHECK<br>
69 	  with failed check id in iDetails1 if access is denied by additional
70 	  security checks,
71 	- DK4_E_OPEN_WRITE_FAILED<br>
72 	  or DK4_E_OPEN_READ_FAILED with errno value in iDetails1 if fopen()
73 	  failed.
74 
75 */
76 FILE *
77 dk4fopen(const dkChar *name, const dkChar *mode, int tests, dk4_er_t *erp);
78 
79 /**	Check whether we can allow to open the file.
80 	The file must be a regular file.
81 	Only POSIX: For root we deny opening for writing via symlink.
82 	For all users we deny opening for writing via symlink
83 	if the link owner is not the real file owner.
84 
85 	CRT on Windows: Required.
86 	@param	name	File name to check.
87 	@param	ww	Flag: Write access wanted.
88 	@param	tests	Set of tests.
89 	@param	erp	Error report, may be NULL.
90 	@return	1 if opening the file is allowed, 0 otherwise.
91 
92 	Error codes:
93 	- DK4_E_INVALID_ARGUMENTS<br>
94 	  if name is NULL,
95 	- DK4_E_SYNTAX<br>
96 	  if name is not a regular file,
97 	- DK4_E_SEC_CHECK<br>
98 	  if access to a symlink target is denied symlink owner and target
99 	  owner differ.
100 
101 */
102 int
103 dk4fopen_check(const dkChar *name, int ww, int tests, dk4_er_t *erp);
104 
105 #ifdef __cplusplus
106 }
107 #endif
108 
109 
110 #endif
111