1import xcffib
2import struct
3import six
4MAJOR_VERSION = 1
5MINOR_VERSION = 0
6key = xcffib.ExtensionKey("SELinux")
7_events = {}
8_errors = {}
9from . import xproto
10class QueryVersionReply(xcffib.Reply):
11    def __init__(self, unpacker):
12        if isinstance(unpacker, xcffib.Protobj):
13            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
14        xcffib.Reply.__init__(self, unpacker)
15        base = unpacker.offset
16        self.server_major, self.server_minor = unpacker.unpack("xx2x4xHH")
17        self.bufsize = unpacker.offset - base
18class QueryVersionCookie(xcffib.Cookie):
19    reply_type = QueryVersionReply
20class GetDeviceCreateContextReply(xcffib.Reply):
21    def __init__(self, unpacker):
22        if isinstance(unpacker, xcffib.Protobj):
23            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
24        xcffib.Reply.__init__(self, unpacker)
25        base = unpacker.offset
26        self.context_len, = unpacker.unpack("xx2x4xI20x")
27        self.context = xcffib.List(unpacker, "c", self.context_len)
28        self.bufsize = unpacker.offset - base
29class GetDeviceCreateContextCookie(xcffib.Cookie):
30    reply_type = GetDeviceCreateContextReply
31class GetDeviceContextReply(xcffib.Reply):
32    def __init__(self, unpacker):
33        if isinstance(unpacker, xcffib.Protobj):
34            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
35        xcffib.Reply.__init__(self, unpacker)
36        base = unpacker.offset
37        self.context_len, = unpacker.unpack("xx2x4xI20x")
38        self.context = xcffib.List(unpacker, "c", self.context_len)
39        self.bufsize = unpacker.offset - base
40class GetDeviceContextCookie(xcffib.Cookie):
41    reply_type = GetDeviceContextReply
42class GetWindowCreateContextReply(xcffib.Reply):
43    def __init__(self, unpacker):
44        if isinstance(unpacker, xcffib.Protobj):
45            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
46        xcffib.Reply.__init__(self, unpacker)
47        base = unpacker.offset
48        self.context_len, = unpacker.unpack("xx2x4xI20x")
49        self.context = xcffib.List(unpacker, "c", self.context_len)
50        self.bufsize = unpacker.offset - base
51class GetWindowCreateContextCookie(xcffib.Cookie):
52    reply_type = GetWindowCreateContextReply
53class GetWindowContextReply(xcffib.Reply):
54    def __init__(self, unpacker):
55        if isinstance(unpacker, xcffib.Protobj):
56            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
57        xcffib.Reply.__init__(self, unpacker)
58        base = unpacker.offset
59        self.context_len, = unpacker.unpack("xx2x4xI20x")
60        self.context = xcffib.List(unpacker, "c", self.context_len)
61        self.bufsize = unpacker.offset - base
62class GetWindowContextCookie(xcffib.Cookie):
63    reply_type = GetWindowContextReply
64class ListItem(xcffib.Struct):
65    def __init__(self, unpacker):
66        if isinstance(unpacker, xcffib.Protobj):
67            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
68        xcffib.Struct.__init__(self, unpacker)
69        base = unpacker.offset
70        self.name, self.object_context_len, self.data_context_len = unpacker.unpack("III")
71        self.object_context = xcffib.List(unpacker, "c", self.object_context_len)
72        unpacker.pad("c")
73        self.data_context = xcffib.List(unpacker, "c", self.data_context_len)
74        self.bufsize = unpacker.offset - base
75    def pack(self):
76        buf = six.BytesIO()
77        buf.write(struct.pack("=III", self.name, self.object_context_len, self.data_context_len))
78        buf.write(xcffib.pack_list(self.object_context, "c"))
79        buf.write(xcffib.pack_list(self.data_context, "c"))
80        return buf.getvalue()
81    @classmethod
82    def synthetic(cls, name, object_context_len, data_context_len, object_context, data_context):
83        self = cls.__new__(cls)
84        self.name = name
85        self.object_context_len = object_context_len
86        self.data_context_len = data_context_len
87        self.object_context = object_context
88        self.data_context = data_context
89        return self
90class GetPropertyCreateContextReply(xcffib.Reply):
91    def __init__(self, unpacker):
92        if isinstance(unpacker, xcffib.Protobj):
93            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
94        xcffib.Reply.__init__(self, unpacker)
95        base = unpacker.offset
96        self.context_len, = unpacker.unpack("xx2x4xI20x")
97        self.context = xcffib.List(unpacker, "c", self.context_len)
98        self.bufsize = unpacker.offset - base
99class GetPropertyCreateContextCookie(xcffib.Cookie):
100    reply_type = GetPropertyCreateContextReply
101class GetPropertyUseContextReply(xcffib.Reply):
102    def __init__(self, unpacker):
103        if isinstance(unpacker, xcffib.Protobj):
104            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
105        xcffib.Reply.__init__(self, unpacker)
106        base = unpacker.offset
107        self.context_len, = unpacker.unpack("xx2x4xI20x")
108        self.context = xcffib.List(unpacker, "c", self.context_len)
109        self.bufsize = unpacker.offset - base
110class GetPropertyUseContextCookie(xcffib.Cookie):
111    reply_type = GetPropertyUseContextReply
112class GetPropertyContextReply(xcffib.Reply):
113    def __init__(self, unpacker):
114        if isinstance(unpacker, xcffib.Protobj):
115            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
116        xcffib.Reply.__init__(self, unpacker)
117        base = unpacker.offset
118        self.context_len, = unpacker.unpack("xx2x4xI20x")
119        self.context = xcffib.List(unpacker, "c", self.context_len)
120        self.bufsize = unpacker.offset - base
121class GetPropertyContextCookie(xcffib.Cookie):
122    reply_type = GetPropertyContextReply
123class GetPropertyDataContextReply(xcffib.Reply):
124    def __init__(self, unpacker):
125        if isinstance(unpacker, xcffib.Protobj):
126            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
127        xcffib.Reply.__init__(self, unpacker)
128        base = unpacker.offset
129        self.context_len, = unpacker.unpack("xx2x4xI20x")
130        self.context = xcffib.List(unpacker, "c", self.context_len)
131        self.bufsize = unpacker.offset - base
132class GetPropertyDataContextCookie(xcffib.Cookie):
133    reply_type = GetPropertyDataContextReply
134class ListPropertiesReply(xcffib.Reply):
135    def __init__(self, unpacker):
136        if isinstance(unpacker, xcffib.Protobj):
137            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
138        xcffib.Reply.__init__(self, unpacker)
139        base = unpacker.offset
140        self.properties_len, = unpacker.unpack("xx2x4xI20x")
141        self.properties = xcffib.List(unpacker, ListItem, self.properties_len)
142        self.bufsize = unpacker.offset - base
143class ListPropertiesCookie(xcffib.Cookie):
144    reply_type = ListPropertiesReply
145class GetSelectionCreateContextReply(xcffib.Reply):
146    def __init__(self, unpacker):
147        if isinstance(unpacker, xcffib.Protobj):
148            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
149        xcffib.Reply.__init__(self, unpacker)
150        base = unpacker.offset
151        self.context_len, = unpacker.unpack("xx2x4xI20x")
152        self.context = xcffib.List(unpacker, "c", self.context_len)
153        self.bufsize = unpacker.offset - base
154class GetSelectionCreateContextCookie(xcffib.Cookie):
155    reply_type = GetSelectionCreateContextReply
156class GetSelectionUseContextReply(xcffib.Reply):
157    def __init__(self, unpacker):
158        if isinstance(unpacker, xcffib.Protobj):
159            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
160        xcffib.Reply.__init__(self, unpacker)
161        base = unpacker.offset
162        self.context_len, = unpacker.unpack("xx2x4xI20x")
163        self.context = xcffib.List(unpacker, "c", self.context_len)
164        self.bufsize = unpacker.offset - base
165class GetSelectionUseContextCookie(xcffib.Cookie):
166    reply_type = GetSelectionUseContextReply
167class GetSelectionContextReply(xcffib.Reply):
168    def __init__(self, unpacker):
169        if isinstance(unpacker, xcffib.Protobj):
170            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
171        xcffib.Reply.__init__(self, unpacker)
172        base = unpacker.offset
173        self.context_len, = unpacker.unpack("xx2x4xI20x")
174        self.context = xcffib.List(unpacker, "c", self.context_len)
175        self.bufsize = unpacker.offset - base
176class GetSelectionContextCookie(xcffib.Cookie):
177    reply_type = GetSelectionContextReply
178class GetSelectionDataContextReply(xcffib.Reply):
179    def __init__(self, unpacker):
180        if isinstance(unpacker, xcffib.Protobj):
181            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
182        xcffib.Reply.__init__(self, unpacker)
183        base = unpacker.offset
184        self.context_len, = unpacker.unpack("xx2x4xI20x")
185        self.context = xcffib.List(unpacker, "c", self.context_len)
186        self.bufsize = unpacker.offset - base
187class GetSelectionDataContextCookie(xcffib.Cookie):
188    reply_type = GetSelectionDataContextReply
189class ListSelectionsReply(xcffib.Reply):
190    def __init__(self, unpacker):
191        if isinstance(unpacker, xcffib.Protobj):
192            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
193        xcffib.Reply.__init__(self, unpacker)
194        base = unpacker.offset
195        self.selections_len, = unpacker.unpack("xx2x4xI20x")
196        self.selections = xcffib.List(unpacker, ListItem, self.selections_len)
197        self.bufsize = unpacker.offset - base
198class ListSelectionsCookie(xcffib.Cookie):
199    reply_type = ListSelectionsReply
200class GetClientContextReply(xcffib.Reply):
201    def __init__(self, unpacker):
202        if isinstance(unpacker, xcffib.Protobj):
203            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
204        xcffib.Reply.__init__(self, unpacker)
205        base = unpacker.offset
206        self.context_len, = unpacker.unpack("xx2x4xI20x")
207        self.context = xcffib.List(unpacker, "c", self.context_len)
208        self.bufsize = unpacker.offset - base
209class GetClientContextCookie(xcffib.Cookie):
210    reply_type = GetClientContextReply
211class xselinuxExtension(xcffib.Extension):
212    def QueryVersion(self, client_major, client_minor, is_checked=True):
213        buf = six.BytesIO()
214        buf.write(struct.pack("=xx2xBB", client_major, client_minor))
215        return self.send_request(0, buf, QueryVersionCookie, is_checked=is_checked)
216    def SetDeviceCreateContext(self, context_len, context, is_checked=False):
217        buf = six.BytesIO()
218        buf.write(struct.pack("=xx2xI", context_len))
219        buf.write(xcffib.pack_list(context, "c"))
220        return self.send_request(1, buf, is_checked=is_checked)
221    def GetDeviceCreateContext(self, is_checked=True):
222        buf = six.BytesIO()
223        buf.write(struct.pack("=xx2x"))
224        return self.send_request(2, buf, GetDeviceCreateContextCookie, is_checked=is_checked)
225    def SetDeviceContext(self, device, context_len, context, is_checked=False):
226        buf = six.BytesIO()
227        buf.write(struct.pack("=xx2xII", device, context_len))
228        buf.write(xcffib.pack_list(context, "c"))
229        return self.send_request(3, buf, is_checked=is_checked)
230    def GetDeviceContext(self, device, is_checked=True):
231        buf = six.BytesIO()
232        buf.write(struct.pack("=xx2xI", device))
233        return self.send_request(4, buf, GetDeviceContextCookie, is_checked=is_checked)
234    def SetWindowCreateContext(self, context_len, context, is_checked=False):
235        buf = six.BytesIO()
236        buf.write(struct.pack("=xx2xI", context_len))
237        buf.write(xcffib.pack_list(context, "c"))
238        return self.send_request(5, buf, is_checked=is_checked)
239    def GetWindowCreateContext(self, is_checked=True):
240        buf = six.BytesIO()
241        buf.write(struct.pack("=xx2x"))
242        return self.send_request(6, buf, GetWindowCreateContextCookie, is_checked=is_checked)
243    def GetWindowContext(self, window, is_checked=True):
244        buf = six.BytesIO()
245        buf.write(struct.pack("=xx2xI", window))
246        return self.send_request(7, buf, GetWindowContextCookie, is_checked=is_checked)
247    def SetPropertyCreateContext(self, context_len, context, is_checked=False):
248        buf = six.BytesIO()
249        buf.write(struct.pack("=xx2xI", context_len))
250        buf.write(xcffib.pack_list(context, "c"))
251        return self.send_request(8, buf, is_checked=is_checked)
252    def GetPropertyCreateContext(self, is_checked=True):
253        buf = six.BytesIO()
254        buf.write(struct.pack("=xx2x"))
255        return self.send_request(9, buf, GetPropertyCreateContextCookie, is_checked=is_checked)
256    def SetPropertyUseContext(self, context_len, context, is_checked=False):
257        buf = six.BytesIO()
258        buf.write(struct.pack("=xx2xI", context_len))
259        buf.write(xcffib.pack_list(context, "c"))
260        return self.send_request(10, buf, is_checked=is_checked)
261    def GetPropertyUseContext(self, is_checked=True):
262        buf = six.BytesIO()
263        buf.write(struct.pack("=xx2x"))
264        return self.send_request(11, buf, GetPropertyUseContextCookie, is_checked=is_checked)
265    def GetPropertyContext(self, window, property, is_checked=True):
266        buf = six.BytesIO()
267        buf.write(struct.pack("=xx2xII", window, property))
268        return self.send_request(12, buf, GetPropertyContextCookie, is_checked=is_checked)
269    def GetPropertyDataContext(self, window, property, is_checked=True):
270        buf = six.BytesIO()
271        buf.write(struct.pack("=xx2xII", window, property))
272        return self.send_request(13, buf, GetPropertyDataContextCookie, is_checked=is_checked)
273    def ListProperties(self, window, is_checked=True):
274        buf = six.BytesIO()
275        buf.write(struct.pack("=xx2xI", window))
276        return self.send_request(14, buf, ListPropertiesCookie, is_checked=is_checked)
277    def SetSelectionCreateContext(self, context_len, context, is_checked=False):
278        buf = six.BytesIO()
279        buf.write(struct.pack("=xx2xI", context_len))
280        buf.write(xcffib.pack_list(context, "c"))
281        return self.send_request(15, buf, is_checked=is_checked)
282    def GetSelectionCreateContext(self, is_checked=True):
283        buf = six.BytesIO()
284        buf.write(struct.pack("=xx2x"))
285        return self.send_request(16, buf, GetSelectionCreateContextCookie, is_checked=is_checked)
286    def SetSelectionUseContext(self, context_len, context, is_checked=False):
287        buf = six.BytesIO()
288        buf.write(struct.pack("=xx2xI", context_len))
289        buf.write(xcffib.pack_list(context, "c"))
290        return self.send_request(17, buf, is_checked=is_checked)
291    def GetSelectionUseContext(self, is_checked=True):
292        buf = six.BytesIO()
293        buf.write(struct.pack("=xx2x"))
294        return self.send_request(18, buf, GetSelectionUseContextCookie, is_checked=is_checked)
295    def GetSelectionContext(self, selection, is_checked=True):
296        buf = six.BytesIO()
297        buf.write(struct.pack("=xx2xI", selection))
298        return self.send_request(19, buf, GetSelectionContextCookie, is_checked=is_checked)
299    def GetSelectionDataContext(self, selection, is_checked=True):
300        buf = six.BytesIO()
301        buf.write(struct.pack("=xx2xI", selection))
302        return self.send_request(20, buf, GetSelectionDataContextCookie, is_checked=is_checked)
303    def ListSelections(self, is_checked=True):
304        buf = six.BytesIO()
305        buf.write(struct.pack("=xx2x"))
306        return self.send_request(21, buf, ListSelectionsCookie, is_checked=is_checked)
307    def GetClientContext(self, resource, is_checked=True):
308        buf = six.BytesIO()
309        buf.write(struct.pack("=xx2xI", resource))
310        return self.send_request(22, buf, GetClientContextCookie, is_checked=is_checked)
311xcffib._add_ext(key, xselinuxExtension, _events, _errors)
312