1 /************************************************************
2 
3 Author: Eamon Walsh <ewalsh@tycho.nsa.gov>
4 
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 this permission notice appear in supporting documentation.  This permission
8 notice shall be included in all copies or substantial portions of the
9 Software.
10 
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
14 AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
15 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
16 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 
18 ********************************************************/
19 
20 #ifndef _XACE_H
21 #define _XACE_H
22 
23 #ifdef XACE
24 
25 #define XACE_MAJOR_VERSION		2
26 #define XACE_MINOR_VERSION		0
27 
28 #include "pixmap.h"
29 #include "region.h"
30 #include "window.h"
31 #include "property.h"
32 #include "selection.h"
33 
34 /* Default window background */
35 #define XaceBackgroundNoneState(w) ((w)->forcedBG ? BackgroundPixel : None)
36 
37 /* security hooks */
38 /* Constants used to identify the available security hooks
39  */
40 #define XACE_CORE_DISPATCH		0
41 #define XACE_EXT_DISPATCH		1
42 #define XACE_RESOURCE_ACCESS		2
43 #define XACE_DEVICE_ACCESS		3
44 #define XACE_PROPERTY_ACCESS		4
45 #define XACE_SEND_ACCESS		5
46 #define XACE_RECEIVE_ACCESS		6
47 #define XACE_CLIENT_ACCESS		7
48 #define XACE_EXT_ACCESS			8
49 #define XACE_SERVER_ACCESS		9
50 #define XACE_SELECTION_ACCESS		10
51 #define XACE_SCREEN_ACCESS		11
52 #define XACE_SCREENSAVER_ACCESS		12
53 #define XACE_AUTH_AVAIL			13
54 #define XACE_KEY_AVAIL			14
55 #define XACE_NUM_HOOKS			15
56 
57 extern _X_EXPORT CallbackListPtr XaceHooks[XACE_NUM_HOOKS];
58 
59 /* Entry point for hook functions.  Called by Xserver.
60  * Required by libdbe and libextmod
61  */
62 extern _X_EXPORT int XaceHook(int /*hook */ ,
63                               ...       /*appropriate args for hook */
64     );
65 
66 /* determine whether any callbacks are present for the XACE hook */
67 extern _X_EXPORT int XaceHookIsSet(int hook);
68 
69 /* Special-cased hook functions
70  */
71 extern _X_EXPORT int XaceHookDispatch(ClientPtr ptr, int major);
72 #define XaceHookDispatch(c, m) \
73     ((XaceHooks[XACE_EXT_DISPATCH] && (m) >= EXTENSION_BASE) ? \
74     XaceHookDispatch((c), (m)) : \
75     Success)
76 
77 extern _X_EXPORT int XaceHookPropertyAccess(ClientPtr ptr, WindowPtr pWin,
78                                             PropertyPtr *ppProp,
79                                             Mask access_mode);
80 extern _X_EXPORT int XaceHookSelectionAccess(ClientPtr ptr, Selection ** ppSel,
81                                              Mask access_mode);
82 
83 /* Register a callback for a given hook.
84  */
85 #define XaceRegisterCallback(hook,callback,data) \
86     AddCallback(XaceHooks+(hook), callback, data)
87 
88 /* Unregister an existing callback for a given hook.
89  */
90 #define XaceDeleteCallback(hook,callback,data) \
91     DeleteCallback(XaceHooks+(hook), callback, data)
92 
93 /* XTrans wrappers for use by security modules
94  */
95 extern _X_EXPORT int XaceGetConnectionNumber(ClientPtr ptr);
96 extern _X_EXPORT int XaceIsLocal(ClientPtr ptr);
97 
98 /* From the original Security extension...
99  */
100 
101 extern _X_EXPORT void XaceCensorImage(ClientPtr client,
102                                       RegionPtr pVisibleRegion,
103                                       long widthBytesLine,
104                                       DrawablePtr pDraw,
105                                       int x, int y, int w, int h,
106                                       unsigned int format, char *pBuf);
107 
108 #else                           /* XACE */
109 
110 /* Default window background */
111 #define XaceBackgroundNoneState(w)		None
112 
113 /* Define calls away when XACE is not being built. */
114 
115 #ifdef __GNUC__
116 #define XaceHook(args...) Success
117 #define XaceHookIsSet(args...) 0
118 #define XaceHookDispatch(args...) Success
119 #define XaceHookPropertyAccess(args...) Success
120 #define XaceHookSelectionAccess(args...) Success
121 #define XaceCensorImage(args...) { ; }
122 #else
123 #define XaceHook(...) Success
124 #define XaceHookIsSet(...) 0
125 #define XaceHookDispatch(...) Success
126 #define XaceHookPropertyAccess(...) Success
127 #define XaceHookSelectionAccess(...) Success
128 #define XaceCensorImage(...) { ; }
129 #endif
130 
131 #endif                          /* XACE */
132 
133 #endif                          /* _XACE_H */
134