Use selabel interfaces instead of matchpathcon
[platform/upstream/rpm.git] / system.h
1 /**
2  * \file system.h
3  */
4
5 #ifndef H_SYSTEM
6 #define H_SYSTEM
7
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif
11
12 #ifdef HAVE_SYS_PARAM_H
13 #include <sys/param.h>
14 #endif
15
16 /* <unistd.h> should be included before any preprocessor test
17    of _POSIX_VERSION.  */
18 #ifdef HAVE_UNISTD_H
19 #include <unistd.h>
20 #if !defined(__GLIBC__)
21 #ifdef __APPLE__
22 #include <crt_externs.h>
23 #define environ (*_NSGetEnviron())
24 #else
25 extern char ** environ;
26 #endif /* __APPLE__ */
27 #endif
28 #endif
29
30 #if !defined(HAVE_STPCPY)
31 char * stpcpy(char * dest, const char * src);
32 #endif
33
34 #if !defined(HAVE_STPNCPY)
35 char * stpncpy(char * dest, const char * src, size_t n);
36 #endif
37
38 #if HAVE___SECURE_GETENV
39 #define getenv(_s)      __secure_getenv(_s)
40 #endif
41
42 #ifdef HAVE_FCNTL_H
43 #include <fcntl.h>
44 #else
45 #include <sys/file.h>
46 #endif
47
48 #ifdef HAVE_DIRENT_H
49 # include <dirent.h>
50 # define NLENGTH(direct) (strlen((direct)->d_name))
51 #else /* not HAVE_DIRENT_H */
52 # define dirent direct
53 # define NLENGTH(direct) ((direct)->d_namlen)
54 # ifdef HAVE_SYS_NDIR_H
55 #  include <sys/ndir.h>
56 # endif /* HAVE_SYS_NDIR_H */
57 # ifdef HAVE_SYS_DIR_H
58 #  include <sys/dir.h>
59 # endif /* HAVE_SYS_DIR_H */
60 # ifdef HAVE_NDIR_H
61 #  include <ndir.h>
62 # endif /* HAVE_NDIR_H */
63 #endif /* HAVE_DIRENT_H */
64
65 #if HAVE_LIMITS_H
66 #include <limits.h>
67 #endif
68
69 #ifndef PATH_MAX
70 #ifdef _POSIX_PATH_MAX
71 #define PATH_MAX _POSIX_PATH_MAX
72 #elif defined MAXPATHLEN
73 #define PATH_MAX MAXPATHLEN
74 #else
75 #define PATH_MAX 256
76 #endif
77 #endif
78
79 #if WITH_SELINUX
80 #include <selinux/selinux.h>
81 #include <selinux/label.h>
82 #else
83 typedef char * security_context_t;
84
85 #define freecon(_c)
86
87 #define setfilecon(_fn, _c)     (-1)
88 #define lsetfilecon(_fn, _c)    (-1)
89
90 #define is_selinux_enabled()    (0)
91
92 #define matchpathcon_init(_fn)                  (-1)
93 #define matchpathcon_fini()                     (0)
94 #define matchpathcon(_fn, _fm, _c)              (-1)
95
96 #define selabel_lookup_raw(_hnd, _scon, _key,_type)     (-1)
97
98 #define selinux_file_context_path() (0)
99
100 #define rpm_execcon(_v, _fn, _av, _envp)        (0)
101 #endif
102
103 #include "rpmio/rpmutil.h"
104 /* compatibility macros to avoid a mass-renaming all over the codebase */
105 #define xmalloc(_size) rmalloc((_size))
106 #define xcalloc(_nmemb, _size) rcalloc((_nmemb), (_size))
107 #define xrealloc(_ptr, _size) rrealloc((_ptr), (_size))
108 #define xstrdup(_str) rstrdup((_str))
109 #define _free(_ptr) rfree((_ptr))
110
111 /* Retrofit glibc __progname */
112 #if defined __GLIBC__ && __GLIBC__ >= 2
113 #if __GLIBC_MINOR__ >= 1
114 #define __progname      __assert_program_name
115 #endif
116 #define setprogname(pn)
117 #else
118 #define __progname      program_name
119 #define setprogname(pn) \
120   { if ((__progname = strrchr(pn, '/')) != NULL) __progname++; \
121     else __progname = pn;               \
122   }
123 #endif
124 extern const char *__progname;
125
126 /* Take care of NLS matters.  */
127 #if ENABLE_NLS
128 # include <locale.h>
129 # include <libintl.h>
130 # define _(Text) dgettext (PACKAGE, Text)
131 #else
132 # define _(Text) Text
133 #endif
134
135 #define N_(Text) Text
136
137 /* ============== from misc/miscfn.h */
138
139 #if !defined(USE_GNU_GLOB) 
140 #if HAVE_FNMATCH_H
141 #include <fnmatch.h>
142 #endif
143
144 #if HAVE_GLOB_H 
145 #include <glob.h>
146 #endif
147 #else
148 #include "misc/glob.h"
149 #include "misc/fnmatch.h"
150 #endif
151
152 #include <dlfcn.h>
153
154 #endif  /* H_SYSTEM */