author | John Beck <John.Beck@Oracle.COM> |
Wed, 29 Oct 2014 14:12:28 -0700 | |
changeset 2183 | 5d00686e81da |
parent 1953 | 5c1face45dc8 |
child 3869 | eb4c6284602f |
permissions | -rw-r--r-- |
1907 | 1 |
This patch provides Python RBAC support. It may be contributed upstream at |
2 |
some point, but the suitability (or lack thereof) has not yet been determined. |
|
3 |
||
4 |
diff --git Python-2.6.4/Modules/authattr.c Python-2.6.4/Modules/authattr.c |
|
5 |
new file mode 100644 |
|
6 |
--- /dev/null |
|
7 |
+++ Python-2.6.4/Modules/authattr.c |
|
8 |
@@ -0,0 +1,261 @@ |
|
9 |
+/* |
|
10 |
+ * CDDL HEADER START |
|
11 |
+ * |
|
12 |
+ * The contents of this file are subject to the terms of the |
|
13 |
+ * Common Development and Distribution License (the "License"). |
|
14 |
+ * You may not use this file except in compliance with the License. |
|
15 |
+ * |
|
16 |
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
17 |
+ * or http://www.opensolaris.org/os/licensing. |
|
18 |
+ * See the License for the specific language governing permissions |
|
19 |
+ * and limitations under the License. |
|
20 |
+ * |
|
21 |
+ * When distributing Covered Code, include this CDDL HEADER in each |
|
22 |
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
23 |
+ * If applicable, add the following below this CDDL HEADER, with the |
|
24 |
+ * fields enclosed by brackets "[]" replaced with your own identifying |
|
25 |
+ * information: Portions Copyright [yyyy] [name of copyright owner] |
|
26 |
+ * |
|
27 |
+ * CDDL HEADER END |
|
28 |
+ */ |
|
29 |
+ |
|
30 |
+/* |
|
31 |
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
|
32 |
+ */ |
|
33 |
+ |
|
34 |
+/* |
|
35 |
+ * RBAC Bindings for Python - auth_attr functions |
|
36 |
+ */ |
|
37 |
+ |
|
38 |
+#include <auth_attr.h> |
|
39 |
+#include "Python.h" |
|
40 |
+#include "pyrbac.h" |
|
41 |
+ |
|
42 |
+static PyObject* |
|
43 |
+pyrbac_setauthattr(PyObject* self, PyObject* args) { |
|
44 |
+ setauthattr(); |
|
45 |
+ return Py_None; |
|
46 |
+} |
|
47 |
+ |
|
48 |
+static PyObject* |
|
49 |
+pyrbac_endauthattr(PyObject* self, PyObject* args) { |
|
50 |
+ endauthattr(); |
|
51 |
+ return Py_None; |
|
52 |
+} |
|
53 |
+ |
|
54 |
+PyObject* |
|
55 |
+pyrbac_getauthnamattr(PyObject* self, char* authname, int mode) { |
|
56 |
+ |
|
57 |
+ |
|
58 |
+ |
|
59 |
+ authattr_t * ret_authattr = (mode == PYRBAC_NAM_MODE) ? getauthnam(authname) : getauthattr(); |
|
60 |
+ if (ret_authattr == NULL) |
|
61 |
+ return Py_None; |
|
62 |
+ |
|
63 |
+ PyObject* kv_data = PyDict_New(); |
|
64 |
+ if (kv_data == NULL) { |
|
65 |
+ free_authattr(ret_authattr); |
|
66 |
+ return NULL; |
|
67 |
+ } |
|
68 |
+ |
|
69 |
+ if(ret_authattr->attr != NULL) { |
|
70 |
+ int len; |
|
71 |
+ for(len = 0; len < ret_authattr->attr->length; len++) { |
|
72 |
+ kv_t current = ret_authattr->attr->data[len]; |
|
73 |
+ |
|
74 |
+ PyObject* set = PyList_New(NULL); |
|
75 |
+ char* saveptr; |
|
76 |
+ char* item = strtok_r(current.value, ",", &saveptr); |
|
77 |
+ PyList_Append(set, PyBytes_FromString(item)); |
|
78 |
+ |
|
79 |
+ while((item = strtok_r(NULL, ",", &saveptr)) != NULL) { |
|
80 |
+ if(PyList_Append(set, PyBytes_FromString(item)) != 0) { |
|
81 |
+ Py_XDECREF(set); |
|
82 |
+ Py_XDECREF(kv_data); |
|
83 |
+ free_authattr(ret_authattr); |
|
84 |
+ return NULL; |
|
85 |
+ } |
|
86 |
+ } |
|
87 |
+ if(PyDict_SetItemString(kv_data, current.key, set)) { |
|
88 |
+ free_authattr(ret_authattr); |
|
89 |
+ return NULL; |
|
90 |
+ } |
|
91 |
+ } |
|
92 |
+ } |
|
93 |
+ PyObject * retval = Py_BuildValue("{s:s,s:s,s:s,s:s,s:s,s:O}", |
|
94 |
+ "name",ret_authattr->name, |
|
95 |
+ "res1",ret_authattr->res1, |
|
96 |
+ "res2",ret_authattr->res2, |
|
97 |
+ "short",ret_authattr->short_desc, |
|
98 |
+ "long",ret_authattr->long_desc, |
|
99 |
+ "attributes",kv_data); |
|
100 |
+ |
|
101 |
+ free_authattr(ret_authattr); |
|
102 |
+ return retval; |
|
103 |
+ |
|
104 |
+} |
|
105 |
+ |
|
106 |
+static PyObject* |
|
107 |
+pyrbac_getauthattr(PyObject* self, PyObject* args) { |
|
108 |
+ return(pyrbac_getauthnamattr(self, NULL, PYRBAC_ATTR_MODE)); |
|
109 |
+} |
|
110 |
+ |
|
111 |
+static PyObject* |
|
112 |
+pyrbac_getauthnam(PyObject* self, PyObject* args) { |
|
113 |
+ char* name = NULL; |
|
114 |
+ if(!PyArg_ParseTuple(args, "s:getauthnam", &name)) |
|
115 |
+ return NULL; |
|
116 |
+ return(pyrbac_getauthnamattr(self, name, PYRBAC_NAM_MODE)); |
|
117 |
+} |
|
118 |
+ |
|
119 |
+static PyObject * |
|
120 |
+pyrbac_chkauthattr(PyObject* self, PyObject* args) { |
|
121 |
+ char* authstring = NULL; |
|
122 |
+ char* username = NULL; |
|
123 |
+ if(!PyArg_ParseTuple(args, "ss:chkauthattr", &authstring, &username)) |
|
124 |
+ return NULL; |
|
125 |
+ return PyBool_FromLong((long)chkauthattr(authstring, username)); |
|
126 |
+} |
|
127 |
+ |
|
128 |
+static PyObject* |
|
129 |
+pyrbac_authattr_next(PyObject* self, PyObject* args) { |
|
130 |
+ PyObject* retval = pyrbac_getauthattr(self, args); |
|
131 |
+ if( retval == Py_None ) { |
|
132 |
+ setauthattr(); |
|
133 |
+ return NULL; |
|
134 |
+ } |
|
135 |
+ return retval; |
|
136 |
+} |
|
137 |
+static PyObject* |
|
138 |
+pyrbac_authattr__iter__(PyObject* self, PyObject* args) { |
|
139 |
+ return self; |
|
140 |
+} |
|
141 |
+ |
|
142 |
+typedef struct { |
|
143 |
+ PyObject_HEAD |
|
144 |
+} Authattr; |
|
145 |
+ |
|
146 |
+static void |
|
147 |
+Authattr_dealloc(Authattr* self) { |
|
148 |
+ endauthattr(); |
|
149 |
+ Py_TYPE(self)->tp_free((PyObject*) self); |
|
150 |
+} |
|
151 |
+ |
|
152 |
+static PyObject* |
|
153 |
+Authattr_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { |
|
154 |
+ Authattr *self; |
|
155 |
+ self = (Authattr*)type->tp_alloc(type, 0); |
|
156 |
+ |
|
157 |
+ return ((PyObject *) self); |
|
158 |
+} |
|
159 |
+ |
|
160 |
+static int |
|
161 |
+Authattr_init(Authattr* self, PyObject *args, PyObject *kwargs) { |
|
162 |
+ setauthattr(); |
|
163 |
+ return 0; |
|
164 |
+} |
|
165 |
+ |
|
166 |
+static char pyrbac_authattr__doc__[]; |
|
167 |
+ |
|
168 |
+PyDoc_STRVAR(pyrbac_authattr__doc__, """provides interfaces to the auth_attr \ |
|
169 |
+database. may be iterated over to return all auth_attr entries\n\n\ |
|
170 |
+Methods provided:\n\ |
|
171 |
+setauthattr\n\ |
|
172 |
+endauthattr\n\ |
|
173 |
+getauthattr\n\ |
|
174 |
+chkauthattr\n\ |
|
175 |
+getauthnam"""); |
|
176 |
+ |
|
177 |
+static char pyrbac_setauthattr__doc__[]; |
|
178 |
+static char pyrbac_endauthattr__doc__[]; |
|
179 |
+static char pyrbac_getauthattr__doc__[]; |
|
180 |
+static char pyrbac_chkauthattr__doc__[]; |
|
181 |
+ |
|
182 |
+PyDoc_STRVAR(pyrbac_setauthattr__doc__, |
|
183 |
+"\"rewinds\" the auth_attr functions to the first entry in the db. Called \ |
|
184 |
+automatically by the constructor\n\tArguments: None\n\tReturns: None"); |
|
185 |
+ |
|
186 |
+PyDoc_STRVAR(pyrbac_endauthattr__doc__, |
|
187 |
+"closes the auth_attr database, cleans up storage. called automatically by \ |
|
188 |
+the destructor\n\tArguments: None\n\tReturns: None"); |
|
189 |
+ |
|
190 |
+PyDoc_STRVAR(pyrbac_chkauthattr__doc__, "verifies if a user has a given \ |
|
191 |
+authorization.\n\tArguments: 2 Python strings, 'authname' and 'username'\n\ |
|
192 |
+\tReturns: True if the user is authorized, False otherwise"); |
|
193 |
+ |
|
194 |
+PyDoc_STRVAR(pyrbac_getauthattr__doc__, |
|
195 |
+"return one entry from the auth_attr database\n\ |
|
196 |
+\tArguments: None\n\ |
|
197 |
+\tReturns: a dict representing the authattr_t struct:\n\ |
|
198 |
+\t\t\"name\": Authorization Name\n\ |
|
199 |
+\t\t\"res1\": reserved\n\ |
|
200 |
+\t\t\"res2\": reserved\n\ |
|
201 |
+\t\t\"short\": Short Description\n\ |
|
202 |
+\t\t\"long\": Long Description\n\ |
|
203 |
+\t\t\"attributes\": A Python dict keyed by attribute & valued as either a list \ |
|
204 |
+or a string depending on value"); |
|
205 |
+ |
|
206 |
+PyDoc_STRVAR(pyrbac_getauthnam__doc__, |
|
207 |
+"searches the auth_attr database for a given authorization name\n\ |
|
208 |
+\tArguments: a Python string containing the auth name\n\ |
|
209 |
+\tReturns: a dict representing the authattr_t struct:\n\ |
|
210 |
+\t\t\"name\": Authorization Name\n\ |
|
211 |
+\t\t\"res1\": reserved\n\ |
|
212 |
+\t\t\"res2\": reserved\n\ |
|
213 |
+\t\t\"short\": Short Description\n\ |
|
214 |
+\t\t\"long\": Long Description\n\ |
|
215 |
+\t\t\"attributes\": A Python dict keyed by attribute & valued as either a list \ |
|
216 |
+or a string depending on value"); |
|
217 |
+ |
|
218 |
+static PyMethodDef Authattr_methods[] = { |
|
219 |
+ {"setauthattr", pyrbac_setauthattr, METH_NOARGS, pyrbac_setauthattr__doc__}, |
|
220 |
+ {"endauthattr", pyrbac_endauthattr, METH_NOARGS, pyrbac_endauthattr__doc__}, |
|
221 |
+ {"chkauthattr", pyrbac_chkauthattr, METH_VARARGS, pyrbac_chkauthattr__doc__}, |
|
222 |
+ {"getauthattr", pyrbac_getauthattr, METH_NOARGS, pyrbac_getauthattr__doc__}, |
|
223 |
+ {"getauthnam", pyrbac_getauthnam, METH_VARARGS, pyrbac_getauthnam__doc__}, |
|
224 |
+ {NULL, NULL} |
|
225 |
+}; |
|
226 |
+ |
|
227 |
+PyTypeObject AuthattrType = { |
|
228 |
+ PyVarObject_HEAD_INIT(NULL, 0) |
|
229 |
+ "rbac.authattr", /*tp_name*/ |
|
230 |
+ sizeof(Authattr), /*tp_basicsize*/ |
|
231 |
+ 0, /*tp_itemsize*/ |
|
232 |
+ (destructor)Authattr_dealloc, /*tp_dealloc*/ |
|
233 |
+ 0, /*tp_print*/ |
|
234 |
+ 0, /*tp_getattr*/ |
|
235 |
+ 0, /*tp_setattr*/ |
|
236 |
+ 0, /*tp_reserved*/ |
|
237 |
+ 0, /*tp_repr*/ |
|
238 |
+ 0, /*tp_as_number*/ |
|
239 |
+ 0, /*tp_as_sequence*/ |
|
240 |
+ 0, /*tp_as_mapping*/ |
|
241 |
+ 0, /*tp_hash */ |
|
242 |
+ 0, /*tp_call*/ |
|
243 |
+ 0, /*tp_str*/ |
|
244 |
+ 0, /*tp_getattro*/ |
|
245 |
+ 0, /*tp_setattro*/ |
|
246 |
+ 0, /*tp_as_buffer*/ |
|
247 |
+ Py_TPFLAGS_DEFAULT | |
|
248 |
+ Py_TPFLAGS_BASETYPE, /*tp_flags*/ |
|
249 |
+ pyrbac_authattr__doc__, /* tp_doc */ |
|
250 |
+ 0, /* tp_traverse */ |
|
251 |
+ 0, /* tp_clear */ |
|
252 |
+ 0, /* tp_richcompare */ |
|
253 |
+ 0, /* tp_weaklistoffset */ |
|
254 |
+ pyrbac_authattr__iter__, /* tp_iter */ |
|
255 |
+ pyrbac_authattr_next, /* tp_iternext */ |
|
256 |
+ Authattr_methods, /* tp_methods */ |
|
257 |
+ 0, /* tp_members */ |
|
258 |
+ 0, /* tp_getset */ |
|
259 |
+ 0, /* tp_base */ |
|
260 |
+ 0, /* tp_dict */ |
|
261 |
+ 0, /* tp_descr_get */ |
|
262 |
+ 0, /* tp_descr_set */ |
|
263 |
+ 0, /* tp_dictoffset */ |
|
264 |
+ (initproc)Authattr_init, /* tp_init */ |
|
265 |
+ 0, /* tp_alloc */ |
|
266 |
+ Authattr_new, /* tp_new */ |
|
267 |
+ 0, /* tp_free */ |
|
268 |
+ 0, /* tp_is_gc */ |
|
269 |
+}; |
|
270 |
diff --git Python-2.6.4/Modules/execattr.c Python-2.6.4/Modules/execattr.c |
|
271 |
new file mode 100644 |
|
272 |
--- /dev/null |
|
273 |
+++ Python-2.6.4/Modules/execattr.c |
|
274 |
@@ -0,0 +1,313 @@ |
|
275 |
+/* |
|
276 |
+ * CDDL HEADER START |
|
277 |
+ * |
|
278 |
+ * The contents of this file are subject to the terms of the |
|
279 |
+ * Common Development and Distribution License (the "License"). |
|
280 |
+ * You may not use this file except in compliance with the License. |
|
281 |
+ * |
|
282 |
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
283 |
+ * or http://www.opensolaris.org/os/licensing. |
|
284 |
+ * See the License for the specific language governing permissions |
|
285 |
+ * and limitations under the License. |
|
286 |
+ * |
|
287 |
+ * When distributing Covered Code, include this CDDL HEADER in each |
|
288 |
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
289 |
+ * If applicable, add the following below this CDDL HEADER, with the |
|
290 |
+ * fields enclosed by brackets "[]" replaced with your own identifying |
|
291 |
+ * information: Portions Copyright [yyyy] [name of copyright owner] |
|
292 |
+ * |
|
293 |
+ * CDDL HEADER END |
|
294 |
+ */ |
|
295 |
+ |
|
296 |
+/* |
|
297 |
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
|
298 |
+ */ |
|
299 |
+ |
|
300 |
+/* |
|
301 |
+ * RBAC Bindings for Python - exec_attr functions |
|
302 |
+ */ |
|
303 |
+ |
|
304 |
+#include <exec_attr.h> |
|
305 |
+#include "Python.h" |
|
306 |
+#include "pyrbac.h" |
|
307 |
+ |
|
308 |
+static PyObject * |
|
309 |
+pyrbac_setexecattr(PyObject* self, PyObject* args) { |
|
310 |
+ setexecattr(); |
|
311 |
+ return Py_None; |
|
312 |
+} |
|
313 |
+ |
|
314 |
+static PyObject * |
|
315 |
+pyrbac_endexecattr(PyObject* self, PyObject* args) { |
|
316 |
+ endexecattr(); |
|
317 |
+ return Py_None; |
|
318 |
+} |
|
319 |
+ |
|
320 |
+PyObject * |
|
321 |
+pyrbac_getexecuserprofattr(PyObject* self, char* userprofname, char* type, char* id, int mode) { |
|
322 |
+ |
|
323 |
+ PyObject* ep_data = (mode == PYRBAC_ATTR_MODE) ? NULL : PyList_New(0); |
|
324 |
+ |
|
325 |
+ if (ep_data == NULL && mode != PYRBAC_ATTR_MODE ) |
|
326 |
+ return NULL; |
|
327 |
+ |
|
328 |
+ execattr_t *execprof; |
|
329 |
+ if (mode == PYRBAC_USER_MODE) |
|
330 |
+ execprof = getexecuser(userprofname, type, id, GET_ALL); |
|
331 |
+ else if (mode == PYRBAC_PROF_MODE) |
|
332 |
+ execprof = getexecprof(userprofname, type, id, GET_ALL); |
|
333 |
+ else if (mode == PYRBAC_ATTR_MODE) |
|
334 |
+ execprof = getexecattr(); |
|
335 |
+ else |
|
336 |
+ return NULL; |
|
337 |
+ |
|
338 |
+ if (execprof == NULL) |
|
339 |
+ return Py_None; |
|
340 |
+ |
|
341 |
+ execattr_t *execprof_head = execprof; |
|
342 |
+ |
|
343 |
+ while(execprof != NULL) { |
|
344 |
+ |
|
345 |
+ PyObject* kv_data = PyDict_New(); |
|
346 |
+ |
|
347 |
+ if(execprof->attr != NULL) { |
|
348 |
+ int len; |
|
349 |
+ for(len = 0; len < execprof->attr->length; len++) { |
|
350 |
+ kv_t current = execprof->attr->data[len]; |
|
351 |
+ |
|
352 |
+ PyObject* set = PyList_New(NULL); |
|
353 |
+ char* saveptr; |
|
354 |
+ char* item = strtok_r(current.value, ",", &saveptr); |
|
355 |
+ PyList_Append(set, PyBytes_FromString(item)); |
|
356 |
+ |
|
357 |
+ while((item = strtok_r(NULL, ",", &saveptr)) != NULL) { |
|
358 |
+ if(PyList_Append(set, PyBytes_FromString(item)) != 0) { |
|
359 |
+ Py_XDECREF(set); |
|
360 |
+ Py_XDECREF(kv_data); |
|
361 |
+ free_execattr(execprof_head); |
|
362 |
+ return NULL; |
|
363 |
+ } |
|
364 |
+ } |
|
365 |
+ if(PyDict_SetItemString(kv_data, current.key, set)) { |
|
366 |
+ free_execattr(execprof_head); |
|
367 |
+ return NULL; |
|
368 |
+ } |
|
369 |
+ } |
|
370 |
+ } |
|
371 |
+ PyObject* entry = Py_BuildValue("{s:s,s:s,s:s,s:s,s:s,s:s,s:O}", |
|
372 |
+ "name", execprof->name, |
|
373 |
+ "type", execprof->type, |
|
374 |
+ "policy", execprof->policy, |
|
375 |
+ "res1", execprof->res1, |
|
376 |
+ "res2", execprof->res2, |
|
377 |
+ "id", execprof->id, |
|
378 |
+ "attributes", kv_data); |
|
379 |
+ |
|
380 |
+ if (entry == NULL) { |
|
381 |
+ Py_XDECREF(kv_data); |
|
382 |
+ free_execattr(execprof_head); |
|
383 |
+ return NULL; |
|
384 |
+ } |
|
385 |
+ |
|
386 |
+ if (mode == PYRBAC_ATTR_MODE) { |
|
387 |
+ free_execattr(execprof_head); |
|
388 |
+ return(entry); |
|
389 |
+ } |
|
390 |
+ PyList_Append(ep_data, entry); |
|
391 |
+ execprof = execprof->next; |
|
392 |
+ } |
|
393 |
+ |
|
394 |
+ free_execattr(execprof_head); |
|
395 |
+ return(ep_data); |
|
396 |
+ |
|
397 |
+} |
|
398 |
+ |
|
399 |
+static PyObject * |
|
400 |
+pyrbac_getexecuser(PyObject* self, PyObject* args) { |
|
401 |
+ char* username = NULL; |
|
402 |
+ char* type = NULL; |
|
403 |
+ char* id = NULL; |
|
404 |
+ |
|
405 |
+ if(!PyArg_ParseTuple(args, "sss:getexecuser", &username, &type, &id)) |
|
406 |
+ return NULL; |
|
407 |
+ |
|
408 |
+ return (pyrbac_getexecuserprofattr(self, username, type, id, PYRBAC_USER_MODE)); |
|
409 |
+} |
|
410 |
+ |
|
411 |
+static PyObject * |
|
412 |
+pyrbac_getexecprof(PyObject* self, PyObject* args) { |
|
413 |
+ |
|
414 |
+ char* profname = NULL; |
|
415 |
+ char* type = NULL; |
|
416 |
+ char* id = NULL; |
|
417 |
+ |
|
418 |
+ if(!PyArg_ParseTuple(args, "sss:getexecprof", &profname, &type, &id)) |
|
419 |
+ return NULL; |
|
420 |
+ |
|
421 |
+ return (pyrbac_getexecuserprofattr(self, profname, type, id, PYRBAC_PROF_MODE)); |
|
422 |
+} |
|
423 |
+ |
|
424 |
+static PyObject* |
|
425 |
+pyrbac_getexecattr(PyObject* self, PyObject* args) { |
|
426 |
+ return pyrbac_getexecuserprofattr(self, NULL, NULL, NULL, PYRBAC_ATTR_MODE); |
|
427 |
+} |
|
428 |
+ |
|
429 |
+static PyObject* |
|
430 |
+pyrbac_execattr_next(PyObject* self, PyObject* args) { |
|
431 |
+ PyObject* retval = pyrbac_getexecattr(self, args); |
|
432 |
+ if( retval == Py_None ) { |
|
433 |
+ setexecattr(); |
|
434 |
+ return NULL; |
|
435 |
+ } |
|
436 |
+ return retval; |
|
437 |
+} |
|
438 |
+static PyObject* |
|
439 |
+pyrbac_execattr__iter__(PyObject* self, PyObject* args) { |
|
440 |
+ return self; |
|
441 |
+} |
|
442 |
+ |
|
443 |
+typedef struct { |
|
444 |
+ PyObject_HEAD |
|
445 |
+} Execattr; |
|
446 |
+ |
|
447 |
+static void |
|
448 |
+Execattr_dealloc(Execattr* self) { |
|
449 |
+ endexecattr(); |
|
450 |
+ Py_TYPE(self)->tp_free((PyObject*) self); |
|
451 |
+} |
|
452 |
+ |
|
453 |
+static PyObject* |
|
454 |
+Execattr_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { |
|
455 |
+ Execattr *self; |
|
456 |
+ self = (Execattr*)type->tp_alloc(type, 0); |
|
457 |
+ |
|
458 |
+ return ((PyObject *) self); |
|
459 |
+} |
|
460 |
+ |
|
461 |
+static int |
|
462 |
+Execattr_init(Execattr* self, PyObject *args, PyObject *kwargs) { |
|
463 |
+ setexecattr(); |
|
464 |
+ return 0; |
|
465 |
+} |
|
466 |
+ |
|
467 |
+static char pyrbac_execattr__doc__[]; |
|
468 |
+ |
|
469 |
+PyDoc_STRVAR(pyrbac_execattr__doc__, "provides functions for \ |
|
470 |
+interacting with the execution profiles database. May be iterated over to \ |
|
471 |
+enumerate exec_attr(4) entries\n\n\ |
|
472 |
+Methods provided:\n\ |
|
473 |
+setexecattr\n\ |
|
474 |
+endexecattr\n\ |
|
475 |
+getexecattr\n\ |
|
476 |
+getexecprof\n\ |
|
477 |
+getexecuser"); |
|
478 |
+ |
|
479 |
+ |
|
480 |
+static char pyrbac_getexecuser__doc__[]; |
|
481 |
+static char pyrbac_getexecprof__doc__[]; |
|
482 |
+static char pyrbac_getexecattr__doc__[]; |
|
483 |
+static char pyrbac_setexecattr__doc__[]; |
|
484 |
+static char pyrbac_endexecattr__doc__[]; |
|
485 |
+ |
|
486 |
+PyDoc_STRVAR(pyrbac_setexecattr__doc__, |
|
487 |
+"\"rewinds\" the exec_attr functions to the first entry in the db. Called \ |
|
488 |
+automatically by the constructor.\n\ |
|
489 |
+\tArguments: None\ |
|
490 |
+\tReturns: None"); |
|
491 |
+ |
|
492 |
+PyDoc_STRVAR(pyrbac_endexecattr__doc__, |
|
493 |
+"closes the exec_attr database, cleans up storage. called automatically by \ |
|
494 |
+the destructor.\n\ |
|
495 |
+\tArguments: None\ |
|
496 |
+\tReturns: None"); |
|
497 |
+ |
|
498 |
+PyDoc_STRVAR(pyrbac_getexecuser__doc__, "corresponds with getexecuser(3SECDB)\ |
|
499 |
+\nTakes: \'username\', \'type\', \'id\'\n\ |
|
500 |
+Return: a single exec_attr entry\n\ |
|
501 |
+\tArguments: None\n\ |
|
502 |
+\tReturns: a dict representation of an execattr_t struct:\n\ |
|
503 |
+\t\t\"name\": Authorization Name\n\ |
|
504 |
+\t\t\"type\": Profile Type\n\ |
|
505 |
+\t\t\"policy\": Policy attributes are relevant in\n\ |
|
506 |
+\t\t\"res1\": reserved\n\ |
|
507 |
+\t\t\"res2\": reserved\n\ |
|
508 |
+\t\t\"id\": unique identifier\n\ |
|
509 |
+\t\t\"attributes\": A Python dict keyed by attribute & valued as\ |
|
510 |
+either a list or a string depending on value"); |
|
511 |
+ |
|
512 |
+PyDoc_STRVAR(pyrbac_getexecprof__doc__, "corresponds with getexecprof(3SECDB)\ |
|
513 |
+\nTakes: \'profile name\', \'type\', \'id\'\n\ |
|
514 |
+\tReturns: a dict representation of an execattr_t struct:\n\ |
|
515 |
+\t\t\"name\": Authorization Name\n\ |
|
516 |
+\t\t\"type\": Profile Type\n\ |
|
517 |
+\t\t\"policy\": Policy attributes are relevant in\n\ |
|
518 |
+\t\t\"res1\": reserved\n\ |
|
519 |
+\t\t\"res2\": reserved\n\ |
|
520 |
+\t\t\"id\": unique identifier\n\ |
|
521 |
+\t\t\"attributes\": A Python dict keyed by attribute & valued as\ |
|
522 |
+either a list or a string depending on value"); |
|
523 |
+ |
|
524 |
+PyDoc_STRVAR(pyrbac_getexecattr__doc__, "corresponds with getexecattr(3SECDB)\ |
|
525 |
+\nTakes 0 arguments\n\ |
|
526 |
+\tReturns: a dict representation of an execattr_t struct:\n\ |
|
527 |
+\t\t\"name\": Authorization Name\n\ |
|
528 |
+\t\t\"type\": Profile Type\n\ |
|
529 |
+\t\t\"policy\": Policy attributes are relevant in\n\ |
|
530 |
+\t\t\"res1\": reserved\n\ |
|
531 |
+\t\t\"res2\": reserved\n\ |
|
532 |
+\t\t\"id\": unique identifier\n\ |
|
533 |
+\t\t\"attributes\": A Python dict keyed by attribute & valued as\ |
|
534 |
+either a list or a string depending on value"); |
|
535 |
+ |
|
536 |
+static PyMethodDef Execattr_methods[] = { |
|
537 |
+ {"setexecattr", pyrbac_setexecattr, METH_NOARGS, pyrbac_setexecattr__doc__}, |
|
538 |
+ {"endexecattr", pyrbac_endexecattr, METH_NOARGS, pyrbac_endexecattr__doc__}, |
|
539 |
+ {"getexecprof", pyrbac_getexecprof, METH_VARARGS, pyrbac_getexecprof__doc__}, |
|
540 |
+ {"getexecuser", pyrbac_getexecuser, METH_VARARGS, pyrbac_getexecuser__doc__}, |
|
541 |
+ {"getexecattr", pyrbac_getexecattr, METH_NOARGS, pyrbac_getexecattr__doc__}, |
|
542 |
+ {NULL, NULL} |
|
543 |
+}; |
|
544 |
+ |
|
545 |
+PyTypeObject ExecattrType = { |
|
546 |
+ PyVarObject_HEAD_INIT(NULL, 0) |
|
547 |
+ "rbac.execattr", /*tp_name*/ |
|
548 |
+ sizeof(Execattr), /*tp_basicsize*/ |
|
549 |
+ 0, /*tp_itemsize*/ |
|
550 |
+ (destructor)Execattr_dealloc, /*tp_dealloc*/ |
|
551 |
+ 0, /*tp_print*/ |
|
552 |
+ 0, /*tp_getattr*/ |
|
553 |
+ 0, /*tp_setattr*/ |
|
554 |
+ 0, /*tp_reserved*/ |
|
555 |
+ 0, /*tp_repr*/ |
|
556 |
+ 0, /*tp_as_number*/ |
|
557 |
+ 0, /*tp_as_sequence*/ |
|
558 |
+ 0, /*tp_as_mapping*/ |
|
559 |
+ 0, /*tp_hash */ |
|
560 |
+ 0, /*tp_call*/ |
|
561 |
+ 0, /*tp_str*/ |
|
562 |
+ 0, /*tp_getattro*/ |
|
563 |
+ 0, /*tp_setattro*/ |
|
564 |
+ 0, /*tp_as_buffer*/ |
|
565 |
+ Py_TPFLAGS_DEFAULT | |
|
566 |
+ Py_TPFLAGS_BASETYPE, /*tp_flags*/ |
|
567 |
+ pyrbac_execattr__doc__, /* tp_doc */ |
|
568 |
+ 0, /* tp_traverse */ |
|
569 |
+ 0, /* tp_clear */ |
|
570 |
+ 0, /* tp_richcompare */ |
|
571 |
+ 0, /* tp_weaklistoffset */ |
|
572 |
+ pyrbac_execattr__iter__, /* tp_iter */ |
|
573 |
+ pyrbac_execattr_next, /* tp_iternext */ |
|
574 |
+ Execattr_methods, /* tp_methods */ |
|
575 |
+ 0, /* tp_members */ |
|
576 |
+ 0, /* tp_getset */ |
|
577 |
+ 0, /* tp_base */ |
|
578 |
+ 0, /* tp_dict */ |
|
579 |
+ 0, /* tp_descr_get */ |
|
580 |
+ 0, /* tp_descr_set */ |
|
581 |
+ 0, /* tp_dictoffset */ |
|
582 |
+ (initproc)Execattr_init, /* tp_init */ |
|
583 |
+ 0, /* tp_alloc */ |
|
584 |
+ Execattr_new, /* tp_new */ |
|
585 |
+ 0, /* tp_free */ |
|
586 |
+ 0, /* tp_is_gc */ |
|
587 |
+}; |
|
588 |
diff --git Python-2.6.4/Modules/privileges.c Python-2.6.4/Modules/privileges.c |
|
589 |
new file mode 100644 |
|
590 |
--- /dev/null |
|
591 |
+++ Python-2.6.4/Modules/privileges.c |
|
592 |
@@ -0,0 +1,243 @@ |
|
593 |
+/* |
|
594 |
+ * CDDL HEADER START |
|
595 |
+ * |
|
596 |
+ * The contents of this file are subject to the terms of the |
|
597 |
+ * Common Development and Distribution License (the "License"). |
|
598 |
+ * You may not use this file except in compliance with the License. |
|
599 |
+ * |
|
600 |
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
601 |
+ * or http://www.opensolaris.org/os/licensing. |
|
602 |
+ * See the License for the specific language governing permissions |
|
603 |
+ * and limitations under the License. |
|
604 |
+ * |
|
605 |
+ * When distributing Covered Code, include this CDDL HEADER in each |
|
606 |
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
607 |
+ * If applicable, add the following below this CDDL HEADER, with the |
|
608 |
+ * fields enclosed by brackets "[]" replaced with your own identifying |
|
609 |
+ * information: Portions Copyright [yyyy] [name of copyright owner] |
|
610 |
+ * |
|
611 |
+ * CDDL HEADER END |
|
612 |
+ */ |
|
613 |
+ |
|
614 |
+/* |
|
615 |
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
|
616 |
+ */ |
|
617 |
+ |
|
618 |
+/* |
|
619 |
+ * privileges(5) bindings for Python |
|
620 |
+ */ |
|
621 |
+ |
|
622 |
+#include <priv.h> |
|
623 |
+#include "Python.h" |
|
624 |
+ |
|
625 |
+static PyObject * |
|
626 |
+pyprivileges_setppriv( PyObject *self, PyObject *args) { |
|
627 |
+ priv_op_t op = -1 ; |
|
628 |
+ priv_ptype_t which = NULL; |
|
629 |
+ |
|
630 |
+ PyObject* set_list = NULL; |
|
631 |
+ |
|
632 |
+ priv_set_t * set = NULL; |
|
633 |
+ |
|
634 |
+ if(!PyArg_ParseTuple(args, "iiO:setppriv", &op, &which, &set_list)) |
|
635 |
+ return NULL; |
|
636 |
+ |
|
637 |
+ if((op != PRIV_ON && op != PRIV_OFF && op != PRIV_SET) || |
|
638 |
+ (which != PRIV_PERMITTED && which != PRIV_EFFECTIVE && |
|
639 |
+ which != PRIV_INHERITABLE && which != PRIV_LIMIT)) |
|
640 |
+ return NULL; |
|
641 |
+ |
|
642 |
+ PyObject* set_string = PyList_GetItem(set_list, 0); |
|
643 |
+ int i; |
|
644 |
+ for (i = 1; i < PyList_Size(set_list); ++i) { |
|
645 |
+ PyBytes_Concat(&set_string, PyBytes_FromString(",")); |
|
646 |
+ PyBytes_Concat(&set_string, PyList_GetItem(set_list, i)); |
|
647 |
+ } |
|
648 |
+ |
|
649 |
+ set = priv_str_to_set(PyBytes_AsString(set_string), ",", NULL ); |
|
650 |
+ |
|
651 |
+ if ( set == NULL ) |
|
652 |
+ return NULL; |
|
653 |
+ |
|
654 |
+ long ret = (long) setppriv(op, which, set); |
|
655 |
+ priv_freeset(set); |
|
656 |
+ // Python inverts true & false |
|
657 |
+ if(ret) |
|
658 |
+ Py_RETURN_FALSE; |
|
659 |
+ |
|
660 |
+ Py_RETURN_TRUE; |
|
661 |
+} |
|
662 |
+ |
|
663 |
+static PyObject * |
|
664 |
+pyprivileges_getppriv( PyObject *self, PyObject *args) { |
|
665 |
+ |
|
666 |
+ char* set_str = NULL; |
|
667 |
+ priv_ptype_t which = NULL; |
|
668 |
+ priv_set_t * set = priv_allocset(); |
|
669 |
+ if (set == NULL) |
|
670 |
+ return NULL; |
|
671 |
+ |
|
672 |
+ if(!PyArg_ParseTuple(args, "i:getppriv", &which)) |
|
673 |
+ return NULL; |
|
674 |
+ |
|
675 |
+ if (which != PRIV_PERMITTED && which != PRIV_EFFECTIVE && |
|
676 |
+ which != PRIV_INHERITABLE && which != PRIV_LIMIT) |
|
677 |
+ return NULL; |
|
678 |
+ |
|
679 |
+ if (getppriv(which, set) != 0) |
|
680 |
+ return NULL; |
|
681 |
+ |
|
682 |
+ set_str = priv_set_to_str(set, ',', PRIV_STR_LIT); |
|
683 |
+ priv_freeset(set); |
|
684 |
+ |
|
685 |
+ PyObject* set_list = PyList_New(NULL); |
|
686 |
+ char* saveptr; |
|
687 |
+ char* item = strtok_r(set_str, ",", &saveptr); |
|
688 |
+ PyList_Append(set_list, PyBytes_FromString(item)); |
|
689 |
+ |
|
690 |
+ while((item = strtok_r(NULL, ",", &saveptr)) != NULL) { |
|
691 |
+ if(PyList_Append(set_list, PyBytes_FromString(item)) != 0) { |
|
692 |
+ Py_XDECREF(set_list); |
|
693 |
+ return NULL; |
|
694 |
+ } |
|
695 |
+ } |
|
696 |
+ |
|
697 |
+ return(set_list); |
|
698 |
+} |
|
699 |
+ |
|
700 |
+static PyObject * |
|
701 |
+pyprivileges_priv_inverse( PyObject *self, PyObject *args ) { |
|
702 |
+ |
|
703 |
+ PyObject* set_list_in = NULL; |
|
704 |
+ if(!PyArg_ParseTuple(args, "O:priv_inverse", &set_list_in)) |
|
705 |
+ return NULL; |
|
706 |
+ |
|
707 |
+ PyObject* set_string = PyList_GetItem(set_list_in, 0); |
|
708 |
+ int i; |
|
709 |
+ for (i = 1; i < PyList_Size(set_list_in); ++i) { |
|
710 |
+ PyBytes_Concat(set_string, PyBytes_FromString(",")); |
|
711 |
+ PyBytes_Concat(set_string, PyList_GetItem(set_list_in, i)); |
|
712 |
+ } |
|
713 |
+ |
|
714 |
+ priv_set_t * set = priv_str_to_set(PyBytes_AsString(set_string), ",", NULL); |
|
715 |
+ if (set == NULL) |
|
716 |
+ return NULL; |
|
717 |
+ priv_inverse(set); |
|
718 |
+ char * ret_str = priv_set_to_str(set, ',', PRIV_STR_LIT); |
|
719 |
+ priv_freeset(set); |
|
720 |
+ |
|
721 |
+ PyObject* set_list_out = PyList_New(NULL); |
|
722 |
+ char* saveptr; |
|
723 |
+ char* item = strtok_r(ret_str, ",", &saveptr); |
|
724 |
+ PyList_Append(set_list_out, PyBytes_FromString(item)); |
|
725 |
+ |
|
726 |
+ while((item = strtok_r(NULL, ",", &saveptr)) != NULL) { |
|
727 |
+ if(PyList_Append(set_list_out, PyBytes_FromString(item)) != 0) { |
|
728 |
+ Py_XDECREF(set_list_out); |
|
729 |
+ return NULL; |
|
730 |
+ } |
|
731 |
+ } |
|
732 |
+ |
|
733 |
+ Py_XDECREF(set_list_in); |
|
734 |
+ |
|
735 |
+ return(set_list_out); |
|
736 |
+} |
|
737 |
+ |
|
738 |
+/* priv_ineffect is a convienient wrapper to priv_get |
|
739 |
+ * however priv_set is, in the context of python, not |
|
740 |
+ * much of a convienience, so it's omitted |
|
741 |
+ */ |
|
742 |
+static PyObject * |
|
743 |
+pyprivileges_priv_ineffect(PyObject* self, PyObject* args) { |
|
744 |
+ char* privstring=NULL; |
|
745 |
+ if (!PyArg_ParseTuple(args, "s:priv_ineffect", &privstring)) |
|
746 |
+ return NULL; |
|
747 |
+ return PyBool_FromLong(priv_ineffect(privstring)); |
|
748 |
+} |
|
749 |
+ |
|
750 |
+ |
|
751 |
+static char pyprivileges__doc__[]; |
|
752 |
+PyDoc_STRVAR(pyprivileges__doc__, |
|
753 |
+"Provides functions for interacting with the Solaris privileges(5) framework\n\ |
|
754 |
+Functions provided:\n\ |
|
755 |
+setppriv\n\ |
|
756 |
+getppriv\n\ |
|
757 |
+priv_ineffect\n\ |
|
758 |
+priv_inverse"); |
|
759 |
+ |
|
760 |
+static char pyprivileges_setppriv__doc__[]; |
|
761 |
+static char pyprivileges_getppriv__doc__[]; |
|
762 |
+static char pyprivileges_priv_ineffect__doc__[]; |
|
763 |
+static char pyprivileges_priv_inverse__doc__[]; |
|
764 |
+ |
|
765 |
+PyDoc_STRVAR(pyprivileges_setppriv__doc__, |
|
766 |
+"Facilitates setting the permitted/inheritable/limit/effective privileges set\n\ |
|
767 |
+\tArguments:\n\ |
|
768 |
+\t\tone of (PRIV_ON|PRIV_OFF|PRIV_SET)\n\ |
|
769 |
+\t\tone of (PRIV_PERMITTED|PRIV_INHERITABLE|PRIV_LIMIT|PRIV_EFFECTIVE)\n\ |
|
770 |
+\t\tset of privileges: a list of strings\n\ |
|
771 |
+\tReturns: True on success, False on failure\ |
|
772 |
+"); |
|
773 |
+ |
|
774 |
+PyDoc_STRVAR(pyprivileges_getppriv__doc__, |
|
775 |
+"Return the process privilege set\n\ |
|
776 |
+\tArguments:\n\ |
|
777 |
+\t\tone of (PRIV_PERMITTED|PRIV_INHERITABLE|PRIV_LIMIT|PRIV_EFFECTIVE)\n\ |
|
778 |
+\tReturns: a Python list of strings"); |
|
779 |
+ |
|
780 |
+PyDoc_STRVAR(pyprivileges_priv_ineffect__doc__, |
|
781 |
+"Checks for a privileges presence in the effective set\n\ |
|
782 |
+\tArguments: a String\n\ |
|
783 |
+\tReturns: True if the privilege is in effect, False otherwise"); |
|
784 |
+ |
|
785 |
+PyDoc_STRVAR(pyprivileges_priv_inverse__doc__, |
|
786 |
+"The complement of the set of privileges\n\ |
|
787 |
+\tArguments: a list of strings\n\tReturns: a list of strings"); |
|
788 |
+ |
|
789 |
+static PyMethodDef module_methods[] = { |
|
790 |
+ {"setppriv", pyprivileges_setppriv, METH_VARARGS, pyprivileges_setppriv__doc__}, |
|
791 |
+ {"getppriv", pyprivileges_getppriv, METH_VARARGS, pyprivileges_getppriv__doc__}, |
|
792 |
+ {"priv_ineffect", pyprivileges_priv_ineffect, METH_VARARGS, pyprivileges_priv_ineffect__doc__}, |
|
793 |
+ {"priv_inverse", pyprivileges_priv_inverse, METH_VARARGS, pyprivileges_priv_inverse__doc__}, |
|
794 |
+ {NULL, NULL} |
|
795 |
+}; |
|
796 |
+ |
|
797 |
+ |
|
798 |
+#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */ |
|
799 |
+#define PyMODINIT_FUNC void |
|
800 |
+#endif |
|
801 |
+PyMODINIT_FUNC |
|
802 |
+PyInit_privileges (void) { |
|
803 |
+ PyObject* m; |
|
804 |
+ |
|
805 |
+ static struct PyModuleDef moduledef = { |
|
806 |
+ PyModuleDef_HEAD_INIT, |
|
807 |
+ "privileges", |
|
808 |
+ pyprivileges__doc__, |
|
809 |
+ -1, |
|
810 |
+ module_methods, |
|
811 |
+ NULL, |
|
812 |
+ NULL, |
|
813 |
+ NULL, |
|
814 |
+ NULL, |
|
815 |
+ }; |
|
816 |
+ |
|
817 |
+ m = PyModule_Create(&moduledef); |
|
818 |
+ if ( m == NULL ) |
|
819 |
+ return m; |
|
820 |
+ |
|
821 |
+ PyObject* d = PyModule_GetDict(m); |
|
822 |
+ if (d == NULL) |
|
823 |
+ return m; |
|
824 |
+ |
|
825 |
+ PyDict_SetItemString(d, "PRIV_ON", PyLong_FromLong((long)PRIV_ON)); |
|
826 |
+ PyDict_SetItemString(d, "PRIV_OFF", PyLong_FromLong((long)PRIV_OFF)); |
|
827 |
+ PyDict_SetItemString(d, "PRIV_SET", PyLong_FromLong((long)PRIV_SET)); |
|
828 |
+ |
|
829 |
+ PyDict_SetItemString(d, "PRIV_PERMITTED", PyLong_FromLong((long)PRIV_PERMITTED)); |
|
830 |
+ PyDict_SetItemString(d, "PRIV_INHERITABLE", PyLong_FromLong((long)PRIV_INHERITABLE)); |
|
831 |
+ PyDict_SetItemString(d, "PRIV_LIMIT", PyLong_FromLong((long)PRIV_LIMIT)); |
|
832 |
+ PyDict_SetItemString(d, "PRIV_EFFECTIVE", PyLong_FromLong((long)PRIV_EFFECTIVE)); |
|
833 |
+ |
|
834 |
+ return m; |
|
835 |
+} |
|
836 |
diff --git Python-2.6.4/Modules/pyrbac.c Python-2.6.4/Modules/pyrbac.c |
|
837 |
new file mode 100644 |
|
838 |
--- /dev/null |
|
839 |
+++ Python-2.6.4/Modules/pyrbac.c |
|
840 |
@@ -0,0 +1,82 @@ |
|
841 |
+/* |
|
842 |
+ * CDDL HEADER START |
|
843 |
+ * |
|
844 |
+ * The contents of this file are subject to the terms of the |
|
845 |
+ * Common Development and Distribution License (the "License"). |
|
846 |
+ * You may not use this file except in compliance with the License. |
|
847 |
+ * |
|
848 |
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
849 |
+ * or http://www.opensolaris.org/os/licensing. |
|
850 |
+ * See the License for the specific language governing permissions |
|
851 |
+ * and limitations under the License. |
|
852 |
+ * |
|
853 |
+ * When distributing Covered Code, include this CDDL HEADER in each |
|
854 |
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
855 |
+ * If applicable, add the following below this CDDL HEADER, with the |
|
856 |
+ * fields enclosed by brackets "[]" replaced with your own identifying |
|
857 |
+ * information: Portions Copyright [yyyy] [name of copyright owner] |
|
858 |
+ * |
|
859 |
+ * CDDL HEADER END |
|
860 |
+ */ |
|
861 |
+ |
|
862 |
+/* |
|
863 |
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
|
864 |
+ */ |
|
865 |
+ |
|
866 |
+/* |
|
867 |
+ * RBAC Bindings for Python |
|
868 |
+ */ |
|
869 |
+ |
|
870 |
+#include <Python.h> |
|
871 |
+#include "pyrbac.h" |
|
872 |
+ |
|
873 |
+static PyMethodDef module_methods[] = {NULL}; |
|
874 |
+static char pyrbac__doc__[]; |
|
875 |
+ |
|
876 |
+PyDoc_STRVAR(pyrbac__doc__, "provides access to some objects \ |
|
877 |
+for interaction with the Solaris Role-Based Access Control \ |
|
878 |
+framework.\n\nDynamic objects:\n\ |
|
879 |
+userattr -- for interacting with user_attr(4)\n\ |
|
880 |
+authattr -- for interacting with auth_attr(4)\n\ |
|
881 |
+execattr -- for interacting with exec_attr(4)\n"); |
|
882 |
+ |
|
883 |
+#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */ |
|
884 |
+#define PyMODINIT_FUNC void |
|
885 |
+#endif |
|
886 |
+PyMODINIT_FUNC |
|
887 |
+PyInit_rbac (void) { |
|
888 |
+ PyObject* m; |
|
889 |
+ |
|
890 |
+ if (PyType_Ready(&AuthattrType) < 0 || |
|
891 |
+ PyType_Ready(&ExecattrType) < 0 || |
|
892 |
+ PyType_Ready(&UserattrType) < 0 ) |
|
893 |
+ return NULL; |
|
894 |
+ |
|
895 |
+ static struct PyModuleDef moduledef = { |
|
896 |
+ PyModuleDef_HEAD_INIT, |
|
897 |
+ "rbac", |
|
898 |
+ pyrbac__doc__, |
|
899 |
+ -1, |
|
900 |
+ module_methods, |
|
901 |
+ NULL, |
|
902 |
+ NULL, |
|
903 |
+ NULL, |
|
904 |
+ NULL, |
|
905 |
+ }; |
|
906 |
+ |
|
907 |
+ m = PyModule_Create(&moduledef); |
|
908 |
+ if ( m == NULL ) |
|
909 |
+ return NULL; |
|
910 |
+ |
|
911 |
+ Py_INCREF(&AuthattrType); |
|
912 |
+ PyModule_AddObject(m, "authattr", (PyObject*)&AuthattrType); |
|
913 |
+ |
|
914 |
+ Py_INCREF(&ExecattrType); |
|
915 |
+ PyModule_AddObject(m, "execattr", (PyObject*)&ExecattrType); |
|
916 |
+ |
|
917 |
+ Py_INCREF(&UserattrType); |
|
918 |
+ PyModule_AddObject(m, "userattr", (PyObject*)&UserattrType); |
|
919 |
+ |
|
920 |
+ return m; |
|
921 |
+ |
|
922 |
+} |
|
923 |
diff --git Python-2.6.4/Modules/pyrbac.h Python-2.6.4/Modules/pyrbac.h |
|
924 |
new file mode 100644 |
|
925 |
--- /dev/null |
|
926 |
+++ Python-2.6.4/Modules/pyrbac.h |
|
927 |
@@ -0,0 +1,45 @@ |
|
928 |
+/* |
|
929 |
+ * CDDL HEADER START |
|
930 |
+ * |
|
931 |
+ * The contents of this file are subject to the terms of the |
|
932 |
+ * Common Development and Distribution License (the "License"). |
|
933 |
+ * You may not use this file except in compliance with the License. |
|
934 |
+ * |
|
935 |
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
936 |
+ * or http://www.opensolaris.org/os/licensing. |
|
937 |
+ * See the License for the specific language governing permissions |
|
938 |
+ * and limitations under the License. |
|
939 |
+ * |
|
940 |
+ * When distributing Covered Code, include this CDDL HEADER in each |
|
941 |
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
942 |
+ * If applicable, add the following below this CDDL HEADER, with the |
|
943 |
+ * fields enclosed by brackets "[]" replaced with your own identifying |
|
944 |
+ * information: Portions Copyright [yyyy] [name of copyright owner] |
|
945 |
+ * |
|
946 |
+ * CDDL HEADER END |
|
947 |
+ */ |
|
948 |
+ |
|
949 |
+/* |
|
950 |
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
|
951 |
+ */ |
|
952 |
+ |
|
953 |
+/* |
|
954 |
+ * RBAC bindings for python |
|
955 |
+ */ |
|
956 |
+#ifndef PYRBAC_H |
|
957 |
+#define PYRBAC_H |
|
958 |
+ |
|
959 |
+#include <secdb.h> |
|
960 |
+ |
|
961 |
+ |
|
962 |
+#define PYRBAC_USER_MODE 1 |
|
963 |
+#define PYRBAC_PROF_MODE 2 |
|
964 |
+#define PYRBAC_ATTR_MODE 3 |
|
965 |
+#define PYRBAC_NAM_MODE 4 |
|
966 |
+#define PYRBAC_UID_MODE 5 |
|
967 |
+ |
|
968 |
+PyTypeObject AuthattrType; |
|
969 |
+PyTypeObject ExecattrType; |
|
970 |
+PyTypeObject UserattrType; |
|
971 |
+ |
|
972 |
+#endif |
|
973 |
diff --git Python-2.6.4/Modules/userattr.c Python-2.6.4/Modules/userattr.c |
|
974 |
new file mode 100644 |
|
975 |
--- /dev/null |
|
976 |
+++ Python-2.6.4/Modules/userattr.c |
|
977 |
@@ -0,0 +1,308 @@ |
|
978 |
+/* |
|
979 |
+ * CDDL HEADER START |
|
980 |
+ * |
|
981 |
+ * The contents of this file are subject to the terms of the |
|
982 |
+ * Common Development and Distribution License (the "License"). |
|
983 |
+ * You may not use this file except in compliance with the License. |
|
984 |
+ * |
|
985 |
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
986 |
+ * or http://www.opensolaris.org/os/licensing. |
|
987 |
+ * See the License for the specific language governing permissions |
|
988 |
+ * and limitations under the License. |
|
989 |
+ * |
|
990 |
+ * When distributing Covered Code, include this CDDL HEADER in each |
|
991 |
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
992 |
+ * If applicable, add the following below this CDDL HEADER, with the |
|
993 |
+ * fields enclosed by brackets "[]" replaced with your own identifying |
|
994 |
+ * information: Portions Copyright [yyyy] [name of copyright owner] |
|
995 |
+ * |
|
996 |
+ * CDDL HEADER END |
|
997 |
+ */ |
|
998 |
+ |
|
999 |
+/* |
|
1000 |
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
|
1001 |
+ */ |
|
1002 |
+ |
|
1003 |
+/* |
|
1004 |
+ * RBAC Bindings for Python - user_attr functions |
|
1005 |
+ */ |
|
1006 |
+ |
|
1007 |
+#include <stdio.h> |
|
1008 |
+#include <user_attr.h> |
|
1009 |
+#include "Python.h" |
|
1010 |
+#include "pyrbac.h" |
|
1011 |
+ |
|
1012 |
+static PyObject* |
|
1013 |
+pyrbac_setuserattr(PyObject* self, PyObject* args) { |
|
1014 |
+ setuserattr(); |
|
1015 |
+ return Py_None; |
|
1016 |
+} |
|
1017 |
+ |
|
1018 |
+static PyObject* |
|
1019 |
+pyrbac_enduserattr(PyObject* self, PyObject* args) { |
|
1020 |
+ enduserattr(); |
|
1021 |
+ return Py_None; |
|
1022 |
+} |
|
1023 |
+ |
|
1024 |
+PyObject* |
|
1025 |
+pyrbac_getuseruidnamattr(PyObject* self, void* arg, int mode, char* filename) { |
|
1026 |
+ |
|
1027 |
+ userattr_t *ret_userattr; |
|
1028 |
+ |
|
1029 |
+ if (mode == PYRBAC_ATTR_MODE) { |
|
1030 |
+ if (filename != NULL) { |
|
1031 |
+ FILE* file = fopen(filename, "r"); |
|
1032 |
+ if (file == NULL) |
|
1033 |
+ return NULL; |
|
1034 |
+ ret_userattr = fgetuserattr(file); |
|
1035 |
+ if (fclose(file)) |
|
1036 |
+ return NULL; |
|
1037 |
+ } |
|
1038 |
+ else |
|
1039 |
+ ret_userattr = getuserattr(); |
|
1040 |
+ } |
|
1041 |
+ else if (mode == PYRBAC_NAM_MODE) |
|
1042 |
+ ret_userattr = getusernam((char*) arg); |
|
1043 |
+ else if (mode == PYRBAC_UID_MODE) |
|
1044 |
+ ret_userattr = getuseruid(*((uid_t*) arg)); |
|
1045 |
+ |
|
1046 |
+ if (ret_userattr == NULL) |
|
1047 |
+ return Py_None; |
|
1048 |
+ |
|
1049 |
+ PyObject* entry = PyTuple_New(5); |
|
1050 |
+ if (entry == NULL) { |
|
1051 |
+ free_userattr(ret_userattr); |
|
1052 |
+ return NULL; |
|
1053 |
+ } |
|
1054 |
+ |
|
1055 |
+ PyObject* kv_data = PyDict_New(); |
|
1056 |
+ |
|
1057 |
+ if(ret_userattr->attr != NULL) { |
|
1058 |
+ int len; |
|
1059 |
+ for(len = 0; len < ret_userattr->attr->length; len++) { |
|
1060 |
+ kv_t current = ret_userattr->attr->data[len]; |
|
1061 |
+ |
|
1062 |
+ PyObject* set = PyList_New(NULL); |
|
1063 |
+ char* saveptr; |
|
1064 |
+ char* item = strtok_r(current.value, ",", &saveptr); |
|
1065 |
+ PyList_Append(set, PyBytes_FromString(item)); |
|
1066 |
+ |
|
1067 |
+ while((item = strtok_r(NULL, ",", &saveptr)) != NULL) { |
|
1068 |
+ if(PyList_Append(set, PyBytes_FromString(item)) != 0) { |
|
1069 |
+ Py_XDECREF(set); |
|
1070 |
+ Py_XDECREF(kv_data); |
|
1071 |
+ free_userattr(ret_userattr); |
|
1072 |
+ return NULL; |
|
1073 |
+ } |
|
1074 |
+ } |
|
1075 |
+ if(PyDict_SetItemString(kv_data, current.key, set)) { |
|
1076 |
+ free_userattr(ret_userattr); |
|
1077 |
+ return NULL; |
|
1078 |
+ } |
|
1079 |
+ } |
|
1080 |
+ } |
|
1081 |
+ entry = Py_BuildValue("{s:s,s:s,s:s,s:s,s:O}", |
|
1082 |
+ "name", ret_userattr->name, |
|
1083 |
+ "qualifier", ret_userattr->qualifier, |
|
1084 |
+ "res1", ret_userattr->res1, |
|
1085 |
+ "res2", ret_userattr->res2, |
|
1086 |
+ "attributes", kv_data); |
|
1087 |
+ |
|
1088 |
+ free_userattr(ret_userattr); |
|
1089 |
+ |
|
1090 |
+ return entry; |
|
1091 |
+} |
|
1092 |
+ |
|
1093 |
+ |
|
1094 |
+static PyObject* |
|
1095 |
+pyrbac_getuserattr(PyObject* self, PyObject* args) { |
|
1096 |
+ return(pyrbac_getuseruidnamattr(self, (void*) NULL, PYRBAC_ATTR_MODE, NULL)); |
|
1097 |
+} |
|
1098 |
+ |
|
1099 |
+static PyObject* |
|
1100 |
+pyrbac_fgetuserattr(PyObject* self, PyObject* args) { |
|
1101 |
+ char* filename = NULL; |
|
1102 |
+ if(!PyArg_ParseTuple(args, "s:fgetuserattr", &filename)) |
|
1103 |
+ return NULL; |
|
1104 |
+ return(pyrbac_getuseruidnamattr(self, NULL, PYRBAC_ATTR_MODE, filename)); |
|
1105 |
+} |
|
1106 |
+ |
|
1107 |
+static PyObject* |
|
1108 |
+pyrbac_getusernam(PyObject* self, PyObject* args) { |
|
1109 |
+ char* name = NULL; |
|
1110 |
+ if(!PyArg_ParseTuple(args, "s:getusernam", &name)) |
|
1111 |
+ return NULL; |
|
1112 |
+ return(pyrbac_getuseruidnamattr(self, (void*) name, PYRBAC_NAM_MODE, NULL)); |
|
1113 |
+} |
|
1114 |
+ |
|
1115 |
+static PyObject* |
|
1116 |
+pyrbac_getuseruid(PyObject* self, PyObject* args) { |
|
1117 |
+ uid_t uid; |
|
1118 |
+ if(!PyArg_ParseTuple(args, "i:getuseruid", &uid)) |
|
1119 |
+ return NULL; |
|
1120 |
+ return(pyrbac_getuseruidnamattr(self, (void*) &uid, PYRBAC_UID_MODE, NULL)); |
|
1121 |
+} |
|
1122 |
+ |
|
1123 |
+static PyObject* |
|
1124 |
+pyrbac_userattr_next(PyObject* self, PyObject* args) { |
|
1125 |
+ PyObject* retval = pyrbac_getuserattr(self, args); |
|
1126 |
+ if( retval == Py_None ) { |
|
1127 |
+ setuserattr(); |
|
1128 |
+ return NULL; |
|
1129 |
+ } |
|
1130 |
+ return retval; |
|
1131 |
+} |
|
1132 |
+static PyObject* |
|
1133 |
+pyrbac_userattr__iter__(PyObject* self, PyObject* args) { |
|
1134 |
+ return self; |
|
1135 |
+} |
|
1136 |
+ |
|
1137 |
+typedef struct { |
|
1138 |
+ PyObject_HEAD |
|
1139 |
+} Userattr; |
|
1140 |
+ |
|
1141 |
+static void |
|
1142 |
+Userattr_dealloc(Userattr* self) { |
|
1143 |
+ enduserattr(); |
|
1144 |
+ Py_TYPE(self)->tp_free((PyObject*) self); |
|
1145 |
+} |
|
1146 |
+ |
|
1147 |
+static PyObject* |
|
1148 |
+Userattr_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { |
|
1149 |
+ Userattr *self; |
|
1150 |
+ self = (Userattr*)type->tp_alloc(type, 0); |
|
1151 |
+ |
|
1152 |
+ return ((PyObject *) self); |
|
1153 |
+} |
|
1154 |
+ |
|
1155 |
+static int |
|
1156 |
+Userattr_init(Userattr* self, PyObject *args, PyObject *kwargs) { |
|
1157 |
+ setuserattr(); |
|
1158 |
+ return 0; |
|
1159 |
+} |
|
1160 |
+ |
|
1161 |
+static char pyrbac_userattr__doc__[]; |
|
1162 |
+PyDoc_STRVAR(pyrbac_userattr__doc__, "provides functions for \ |
|
1163 |
+interacting with the extended user attributes database. May be iterated over \ |
|
1164 |
+to enumerate user_attr(4) entries\n\n\ |
|
1165 |
+Methods provided:\n\ |
|
1166 |
+setuserattr\n\ |
|
1167 |
+enduserattr\n\ |
|
1168 |
+getuserattr\n\ |
|
1169 |
+fgetuserattr\n\ |
|
1170 |
+getusernam\n\ |
|
1171 |
+getuseruid"); |
|
1172 |
+ |
|
1173 |
+static char pyrbac_setuserattr__doc__[]; |
|
1174 |
+static char pyrbac_enduserattr__doc__[]; |
|
1175 |
+static char pyrbac_getuserattr__doc__[]; |
|
1176 |
+static char pyrbac_getusernam__doc__[]; |
|
1177 |
+static char pyrbac_getuseruid__doc__[]; |
|
1178 |
+ |
|
1179 |
+PyDoc_STRVAR(pyrbac_setuserattr__doc__, "\"rewinds\" the user_attr functions \ |
|
1180 |
+to the first entry in the db. Called automatically by the constructor.\n\ |
|
1181 |
+\tArguments: None\n\ |
|
1182 |
+\tReturns: None"); |
|
1183 |
+ |
|
1184 |
+PyDoc_STRVAR(pyrbac_enduserattr__doc__, "closes the user_attr database, \ |
|
1185 |
+cleans up storage. called automatically by the destructor\n\ |
|
1186 |
+\tArguments: None\n\ |
|
1187 |
+\tReturns: None"); |
|
1188 |
+ |
|
1189 |
+PyDoc_STRVAR(pyrbac_getuserattr__doc__, "Return a single user_attr entry\n \ |
|
1190 |
+\tArguments: None\n\ |
|
1191 |
+\tReturns: a dict representation of a userattr_t struct:\n\ |
|
1192 |
+\t\t\"name\": username\n\ |
|
1193 |
+\t\t\"qualifier\": reserved\n\ |
|
1194 |
+\t\t\"res1\": reserved\n\ |
|
1195 |
+\t\t\"res2\": reserved\n\ |
|
1196 |
+\t\t\"attributes\": A Python dict keyed by attribute & valued as either a list \ |
|
1197 |
+or a string depending on value" |
|
1198 |
+); |
|
1199 |
+ |
|
1200 |
+PyDoc_STRVAR(pyrbac_fgetuserattr__doc__, "Return a single user_attr entry \ |
|
1201 |
+from a file, bypassing nsswitch.conf\n\ |
|
1202 |
+\tArguments: \'filename\'\n\ |
|
1203 |
+\tReturns: a dict representation of a userattr_t struct:\n\ |
|
1204 |
+\t\t\"name\": username\n\ |
|
1205 |
+\t\t\"qualifier\": reserved\n\ |
|
1206 |
+\t\t\"res1\": reserved\n\ |
|
1207 |
+\t\t\"res2\": reserved\n\ |
|
1208 |
+\t\t\"attributes\": A Python dict keyed by attribute & valued as either a list \ |
|
1209 |
+or a string depending on value"); |
|
1210 |
+ |
|
1211 |
+PyDoc_STRVAR(pyrbac_getusernam__doc__, "Searches for a user_attr entry with a \ |
|
1212 |
+given user name\n\ |
|
1213 |
+\tArgument: \'username\'\n\ |
|
1214 |
+\tReturns: a dict representation of a userattr_t struct:\n\ |
|
1215 |
+\t\t\"name\": username\n\ |
|
1216 |
+\t\t\"qualifier\": reserved\n\ |
|
1217 |
+\t\t\"res1\": reserved\n\ |
|
1218 |
+\t\t\"res2\": reserved\n\ |
|
1219 |
+\t\t\"attributes\": A Python dict keyed by attribute & valued as either a list \ |
|
1220 |
+or a string depending on value"); |
|
1221 |
+ |
|
1222 |
+PyDoc_STRVAR(pyrbac_getuseruid__doc__, "Searches for a user_attr entry with a \ |
|
1223 |
+given uid\n\ |
|
1224 |
+\tArgument: uid\n\ |
|
1225 |
+\tReturns: a dict representation of a userattr_t struct:\n\ |
|
1226 |
+\t\t\"name\": username\n\ |
|
1227 |
+\t\t\"qualifier\": reserved\n\ |
|
1228 |
+\t\t\"res1\": reserved\n\ |
|
1229 |
+\t\t\"res2\": reserved\n\ |
|
1230 |
+\t\t\"attributes\": A Python dict keyed by attribute & valued as either a list \ |
|
1231 |
+or a string depending on value"); |
|
1232 |
+ |
|
1233 |
+static PyMethodDef Userattr_methods[] = { |
|
1234 |
+ {"setuserattr", pyrbac_setuserattr, METH_NOARGS, pyrbac_setuserattr__doc__}, |
|
1235 |
+ {"enduserattr", pyrbac_enduserattr, METH_NOARGS, pyrbac_enduserattr__doc__}, |
|
1236 |
+ {"getuserattr", pyrbac_getuserattr, METH_NOARGS, pyrbac_getuserattr__doc__}, |
|
1237 |
+ {"fgetuserattr", pyrbac_fgetuserattr, METH_VARARGS, pyrbac_fgetuserattr__doc__}, |
|
1238 |
+ {"getusernam", pyrbac_getusernam, METH_VARARGS, pyrbac_getusernam__doc__}, |
|
1239 |
+ {"getuseruid", pyrbac_getuseruid, METH_VARARGS, pyrbac_getuseruid__doc__}, |
|
1240 |
+ {NULL, NULL} |
|
1241 |
+}; |
|
1242 |
+ |
|
1243 |
+PyTypeObject UserattrType = { |
|
1244 |
+ PyVarObject_HEAD_INIT(NULL, 0) |
|
1245 |
+ "rbac.userattr", /*tp_name*/ |
|
1246 |
+ sizeof(Userattr), /*tp_basicsize*/ |
|
1247 |
+ 0, /*tp_itemsize*/ |
|
1248 |
+ (destructor)Userattr_dealloc, /*tp_dealloc*/ |
|
1249 |
+ 0, /*tp_print*/ |
|
1250 |
+ 0, /*tp_getattr*/ |
|
1251 |
+ 0, /*tp_setattr*/ |
|
1252 |
+ 0, /*tp_reserved*/ |
|
1253 |
+ 0, /*tp_repr*/ |
|
1254 |
+ 0, /*tp_as_number*/ |
|
1255 |
+ 0, /*tp_as_sequence*/ |
|
1256 |
+ 0, /*tp_as_mapping*/ |
|
1257 |
+ 0, /*tp_hash */ |
|
1258 |
+ 0, /*tp_call*/ |
|
1259 |
+ 0, /*tp_str*/ |
|
1260 |
+ 0, /*tp_getattro*/ |
|
1261 |
+ 0, /*tp_setattro*/ |
|
1262 |
+ 0, /*tp_as_buffer*/ |
|
1263 |
+ Py_TPFLAGS_DEFAULT | |
|
1264 |
+ Py_TPFLAGS_BASETYPE, /*tp_flags*/ |
|
1265 |
+ pyrbac_userattr__doc__, /* tp_doc */ |
|
1266 |
+ 0, /* tp_traverse */ |
|
1267 |
+ 0, /* tp_clear */ |
|
1268 |
+ 0, /* tp_richcompare */ |
|
1269 |
+ 0, /* tp_weaklistoffset */ |
|
1270 |
+ pyrbac_userattr__iter__, /* tp_iter */ |
|
1271 |
+ pyrbac_userattr_next, /* tp_iternext */ |
|
1272 |
+ Userattr_methods, /* tp_methods */ |
|
1273 |
+ 0, /* tp_members */ |
|
1274 |
+ 0, /* tp_getset */ |
|
1275 |
+ 0, /* tp_base */ |
|
1276 |
+ 0, /* tp_dict */ |
|
1277 |
+ 0, /* tp_descr_get */ |
|
1278 |
+ 0, /* tp_descr_set */ |
|
1279 |
+ 0, /* tp_dictoffset */ |
|
1280 |
+ (initproc)Userattr_init, /* tp_init */ |
|
1281 |
+ 0, /* tp_alloc */ |
|
1282 |
+ Userattr_new, /* tp_new */ |
|
1283 |
+ 0, /* tp_free */ |
|
1284 |
+ 0, /* tp_is_gc */ |
|
1285 |
+}; |
|
2183
5d00686e81da
19782913 update Python to 3.4.2
John Beck <John.Beck@Oracle.COM>
parents:
1953
diff
changeset
|
1286 |
--- Python-3.4.2/setup.py.~5~ 2014-09-22 14:15:00.047444289 -0700 |
5d00686e81da
19782913 update Python to 3.4.2
John Beck <John.Beck@Oracle.COM>
parents:
1953
diff
changeset
|
1287 |
+++ Python-3.4.2/setup.py 2014-09-22 14:15:00.082157199 -0700 |
5d00686e81da
19782913 update Python to 3.4.2
John Beck <John.Beck@Oracle.COM>
parents:
1953
diff
changeset
|
1288 |
@@ -1498,6 +1498,22 @@ |
1907 | 1289 |
exts.append( Extension('dlpi', ['dlpimodule.c'], |
1290 |
libraries = ['dlpi']) ) |
|
1291 |
||
1292 |
+ # privileges module (Solaris) |
|
1293 |
+ priv_inc = find_file('priv.h', [], inc_dirs) |
|
1294 |
+ if priv_inc is not None: |
|
1295 |
+ exts.append( Extension('privileges', ['privileges.c'])) |
|
1296 |
+ |
|
1297 |
+ # rbac module (Solaris) |
|
1298 |
+ secdb_inc = find_file('secdb.h', [], inc_dirs) |
|
1299 |
+ aa_inc = find_file('auth_attr.h', [], inc_dirs) |
|
1300 |
+ ea_inc = find_file('exec_attr.h', [], inc_dirs) |
|
1301 |
+ ua_inc = find_file('user_attr.h', [], inc_dirs) |
|
1302 |
+ if secdb_inc is not None and aa_inc is not None and \ |
|
1303 |
+ ea_inc is not None and ua_inc is not None: |
|
1304 |
+ exts.append( Extension('rbac', ['pyrbac.c', 'authattr.c', \ |
|
1305 |
+ 'execattr.c', 'userattr.c'], |
|
1306 |
+ libraries = ['nsl', 'socket', 'secdb']) ) |
|
1307 |
+ |
|
1308 |
# Thomas Heller's _ctypes module |
|
1309 |
self.detect_ctypes(inc_dirs, lib_dirs) |
|
1310 |
||
1311 |
--- /dev/null 2011-02-12 03:13:57.000000000 -0600 |
|
1312 |
+++ Python-3.4.0/Lib/test/privrbactest.py 2011-01-20 13:52:42.862305331 -0600 |
|
1313 |
@@ -0,0 +1,289 @@ |
|
1314 |
+#!/usr/bin/python3.4 |
|
1315 |
+# |
|
1316 |
+# CDDL HEADER START |
|
1317 |
+# |
|
1318 |
+# The contents of this file are subject to the terms of the |
|
1319 |
+# Common Development and Distribution License (the "License"). |
|
1320 |
+# You may not use this file except in compliance with the License. |
|
1321 |
+# |
|
1322 |
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
1323 |
+# or http://www.opensolaris.org/os/licensing. |
|
1324 |
+# See the License for the specific language governing permissions |
|
1325 |
+# and limitations under the License. |
|
1326 |
+# |
|
1327 |
+# When distributing Covered Code, include this CDDL HEADER in each |
|
1328 |
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
1329 |
+# If applicable, add the following below this CDDL HEADER, with the |
|
1330 |
+# fields enclosed by brackets "[]" replaced with your own identifying |
|
1331 |
+# information: Portions Copyright [yyyy] [name of copyright owner] |
|
1332 |
+# |
|
1333 |
+# CDDL HEADER END |
|
1334 |
+# |
|
1335 |
+ |
|
1336 |
+# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
|
1337 |
+ |
|
1338 |
+import privileges |
|
1339 |
+import rbac |
|
1340 |
+import os |
|
1341 |
+import sys |
|
1342 |
+import tempfile |
|
1343 |
+ |
|
1344 |
+# privileges tests |
|
1345 |
+ |
|
1346 |
+def test_setppriv(): |
|
1347 |
+ amchild = os.fork() |
|
1348 |
+ if amchild == 0: |
|
1349 |
+ if privileges.setppriv(privileges.PRIV_OFF, privileges.PRIV_EFFECTIVE, |
|
1350 |
+ ['proc_fork']): |
|
1351 |
+ try: |
|
1352 |
+ os.fork() |
|
1353 |
+ sys.exit(1) |
|
1354 |
+ except OSError as e: |
|
1355 |
+ sys.exit(0) |
|
1356 |
+ |
|
1357 |
+ child = os.wait() |
|
1358 |
+ if child[1] is not 0: |
|
1359 |
+ print("setppriv. Bad exit status from pid %i\n" % child[0]) |
|
1360 |
+ return False |
|
1361 |
+ return True |
|
1362 |
+ |
|
1363 |
+def test_getppriv(): |
|
1364 |
+ if 'proc_fork' in privileges.getppriv(privileges.PRIV_LIMIT): |
|
1365 |
+ return True |
|
1366 |
+ print("getppriv or PRIV_PROC_FORK not in PRIV_LIMIT.\n") |
|
1367 |
+ return False |
|
1368 |
+ |
|
1369 |
+def test_priv_ineffect(): |
|
1370 |
+ if privileges.priv_ineffect('proc_fork'): |
|
1371 |
+ return True |
|
1372 |
+ print("priv_ineffect or PRIV_PROC_FORK not in effect\n") |
|
1373 |
+ return False |
|
1374 |
+ |
|
1375 |
+# authattr tests |
|
1376 |
+ |
|
1377 |
+def test_chkauthattr(): |
|
1378 |
+ try: |
|
1379 |
+ a = rbac.authattr() |
|
1380 |
+ except Exception as e: |
|
1381 |
+ print("Could not instantiate authattr object: %s\n" % e) |
|
1382 |
+ return False |
|
1383 |
+ try: |
|
1384 |
+ res = a.chkauthattr('solaris.*', 'root') |
|
1385 |
+ except Exception as e: |
|
1386 |
+ print("chkauthattr failed: %s\n" % e) |
|
1387 |
+ return False |
|
1388 |
+ if not res: |
|
1389 |
+ print("chkauthattr failed or \'root\' lacks \'solaris.*\'\n") |
|
1390 |
+ return False |
|
1391 |
+ return True |
|
1392 |
+ |
|
1393 |
+def test_getauthattr(): |
|
1394 |
+ try: |
|
1395 |
+ a = rbac.authattr() |
|
1396 |
+ except Exception as e: |
|
1397 |
+ print("Could not instantiate authattr object: %s\n" % e) |
|
1398 |
+ return False |
|
1399 |
+ try: |
|
1400 |
+ res = a.getauthattr() |
|
1401 |
+ except Exception as e: |
|
1402 |
+ print("getauthattr failed: %s\n" % e) |
|
1403 |
+ return False |
|
1404 |
+ if not 'name' in list(res.keys()): |
|
1405 |
+ print("getauthattr failed\n") |
|
1406 |
+ return False |
|
1407 |
+ return True |
|
1408 |
+ |
|
1409 |
+def test_getauthnam(): |
|
1410 |
+ try: |
|
1411 |
+ a = rbac.authattr() |
|
1412 |
+ except Exception as e: |
|
1413 |
+ print("Could not instantiate authattr object: %s\n" % e) |
|
1414 |
+ return False |
|
1415 |
+ try: |
|
1416 |
+ res = a.getauthnam('solaris.') |
|
1417 |
+ except Exception as e: |
|
1418 |
+ print("getauthnam failed: %s\n" % e) |
|
1419 |
+ return False |
|
1420 |
+ if not res: |
|
1421 |
+ print("getauthnam failed or \'solaris.\' not in auth_attr(4)\n") |
|
1422 |
+ return False |
|
1423 |
+ return True |
|
1424 |
+ |
|
1425 |
+def test_authattr_iter(): |
|
1426 |
+ try: |
|
1427 |
+ a = rbac.authattr() |
|
1428 |
+ except Exception as e: |
|
1429 |
+ print("Could not instantiate authattr object: %s\n" % e) |
|
1430 |
+ return False |
|
1431 |
+ res = next(a) |
|
1432 |
+ if not 'name' in list(res.keys()) or type(a) != type(a.__iter__()): |
|
1433 |
+ print("authattr object is not an iterable\n") |
|
1434 |
+ return False |
|
1435 |
+ return True |
|
1436 |
+ |
|
1437 |
+# execattr tests |
|
1438 |
+ |
|
1439 |
+def test_getexecattr(): |
|
1440 |
+ try: |
|
1441 |
+ a = rbac.execattr() |
|
1442 |
+ except Exception as e: |
|
1443 |
+ print("Could not instantiate execattr object: %s\n" % e) |
|
1444 |
+ return False |
|
1445 |
+ try: |
|
1446 |
+ res = a.getexecattr() |
|
1447 |
+ except Exception as e: |
|
1448 |
+ print("getexecattr failed: %s\n" % e) |
|
1449 |
+ return False |
|
1450 |
+ if not 'name' in list(res.keys()): |
|
1451 |
+ print("getexecattr failed\n") |
|
1452 |
+ return False |
|
1453 |
+ return True |
|
1454 |
+ |
|
1455 |
+def test_getexecuser(): |
|
1456 |
+ try: |
|
1457 |
+ a = rbac.execattr() |
|
1458 |
+ except Exception as e: |
|
1459 |
+ print("Could not instantiate execattr object: %s\n" % e) |
|
1460 |
+ return False |
|
1461 |
+ try: |
|
1462 |
+ res = a.getexecuser("root", "act", "*;*;*;*;*") |
|
1463 |
+ except Exception as e: |
|
1464 |
+ print("getexecuser failed: %s\n" % e) |
|
1465 |
+ return False |
|
1466 |
+ if not res: |
|
1467 |
+ print("getexecuser failed or \'root\' not assigned to \'act\', " \ |
|
1468 |
+ "\'*;*;*;*;*\' \n") |
|
1469 |
+ return False |
|
1470 |
+ return True |
|
1471 |
+ |
|
1472 |
+ |
|
1473 |
+def test_getexecprof(): |
|
1474 |
+ try: |
|
1475 |
+ a = rbac.execattr() |
|
1476 |
+ except Exception as e: |
|
1477 |
+ print("Could not instantiate execattr object: %s\n" % e) |
|
1478 |
+ return False |
|
1479 |
+ try: |
|
1480 |
+ res = a.getexecprof("All", "cmd", "*") |
|
1481 |
+ except Exception as e: |
|
1482 |
+ print("getexecprof failed: %s\n" % e) |
|
1483 |
+ return False |
|
1484 |
+ if not res: |
|
1485 |
+ print("getexecprof failed or \'All\' not granted \'cmd\' : \'*\'\n") |
|
1486 |
+ return False |
|
1487 |
+ return True |
|
1488 |
+ |
|
1489 |
+def test_execattr_iter(): |
|
1490 |
+ try: |
|
1491 |
+ a = rbac.execattr() |
|
1492 |
+ except Exception as e: |
|
1493 |
+ print("Could not instantiate execattr object: %s\n" % e) |
|
1494 |
+ return False |
|
1495 |
+ res = next(a) |
|
1496 |
+ if not 'name' in list(res.keys()) or type(a) != type(a.__iter__()): |
|
1497 |
+ print("execattr object is not an iterable\n") |
|
1498 |
+ return False |
|
1499 |
+ return True |
|
1500 |
+ |
|
1501 |
+# userattr tests |
|
1502 |
+ |
|
1503 |
+def test_getuserattr(): |
|
1504 |
+ try: |
|
1505 |
+ a = rbac.userattr() |
|
1506 |
+ except Exception as e: |
|
1507 |
+ print("Could not instantiate userattr object: %s\n" % e) |
|
1508 |
+ return False |
|
1509 |
+ try: |
|
1510 |
+ res = a.getuserattr() |
|
1511 |
+ except Exception as e: |
|
1512 |
+ print("getuserattr failed: %s\n" % e) |
|
1513 |
+ return False |
|
1514 |
+ if not 'name' in list(res.keys()): |
|
1515 |
+ print("getuserattr failed\n") |
|
1516 |
+ return False |
|
1517 |
+ return True |
|
1518 |
+ |
|
1519 |
+def test_fgetuserattr(): |
|
1520 |
+ temp = tempfile.NamedTemporaryFile() |
|
1521 |
+ temp.write("user::::profiles=Software Installation;roles=foo;"\ |
|
1522 |
+ "auths=solaris.foo.bar") |
|
1523 |
+ temp.seek(0) |
|
1524 |
+ try: |
|
1525 |
+ a = rbac.userattr() |
|
1526 |
+ except Exception as e: |
|
1527 |
+ print("Could not instantiate userattr object: %s\n" % e) |
|
1528 |
+ return False |
|
1529 |
+ try: |
|
1530 |
+ res = a.fgetuserattr(temp.name) |
|
1531 |
+ temp.close() |
|
1532 |
+ except Exception as e: |
|
1533 |
+ print("fgetuserattr failed: %s\n" % e) |
|
1534 |
+ temp.close() |
|
1535 |
+ return False |
|
1536 |
+ if not 'name' in list(res.keys()): |
|
1537 |
+ print("fgetuserattr failed\n") |
|
1538 |
+ return False |
|
1539 |
+ return True |
|
1540 |
+ |
|
1541 |
+def test_getuseruid(): |
|
1542 |
+ try: |
|
1543 |
+ a = rbac.userattr() |
|
1544 |
+ except Exception as e: |
|
1545 |
+ print("Could not instantiate userattr object: %s\n" % e) |
|
1546 |
+ return False |
|
1547 |
+ try: |
|
1548 |
+ res = a.getuseruid(0) |
|
1549 |
+ except Exception as e: |
|
1550 |
+ print("getusernam failed: %s\n" % e) |
|
1551 |
+ return False |
|
1552 |
+ if not 'name' in res: |
|
1553 |
+ print("getusernam failed or no uid 0\n") |
|
1554 |
+ return False |
|
1555 |
+ return True |
|
1556 |
+ |
|
1557 |
+def test_getusernam(): |
|
1558 |
+ try: |
|
1559 |
+ a = rbac.userattr() |
|
1560 |
+ except Exception as e: |
|
1561 |
+ print("Could not instantiate userattr object: %s\n" % e) |
|
1562 |
+ return False |
|
1563 |
+ try: |
|
1564 |
+ res = a.getusernam('root') |
|
1565 |
+ except Exception as e: |
|
1566 |
+ print("getusernam failed: %s\n" % e) |
|
1567 |
+ return False |
|
1568 |
+ if not 'name' in res: |
|
1569 |
+ print("getusernam failed or no \'root\' user\n") |
|
1570 |
+ return False |
|
1571 |
+ return True |
|
1572 |
+ |
|
1573 |
+def test_userattr_iter(): |
|
1574 |
+ try: |
|
1575 |
+ a = rbac.userattr() |
|
1576 |
+ except Exception as e: |
|
1577 |
+ print("Could not instantiate userattr object: %s\n" % e) |
|
1578 |
+ return False |
|
1579 |
+ res = next(a) |
|
1580 |
+ if not 'name' in list(res.keys()) or type(a) != type(a.__iter__()): |
|
1581 |
+ print("userattr object is not an iterable\n") |
|
1582 |
+ return False |
|
1583 |
+ return True |
|
1584 |
+ |
|
1585 |
+if not test_setppriv() or not test_getppriv() or not test_priv_ineffect(): |
|
1586 |
+ print("*** Failures detected in privileges module\n") |
|
1587 |
+ sys.exit(1) |
|
1588 |
+ |
|
1589 |
+if not test_getauthattr() or not test_chkauthattr() or not test_getauthnam() \ |
|
1590 |
+ or not test_authattr_iter: |
|
1591 |
+ print("*** Failures detected in rbac.authattr\n") |
|
1592 |
+ sys.exit(1) |
|
1593 |
+ |
|
1594 |
+if not test_getexecattr() or not test_getexecuser() or not test_getexecprof() \ |
|
1595 |
+ or not test_execattr_iter(): |
|
1596 |
+ print("*** Failures detected in rbac.execattr\n") |
|
1597 |
+ sys.exit(1) |
|
1598 |
+ |
|
1599 |
+if not test_getuserattr() or not test_fgetuserattr() or not test_getusernam()\ |
|
1600 |
+ or not test_getuseruid() or not test_userattr_iter(): |
|
1601 |
+ print("*** Failures detected in rbac.userattr\n") |
|
1602 |
+ sys.exit(1) |