458
|
1 |
diff --git Python-2.6.4/Modules/authattr.c Python-2.6.4/Modules/authattr.c
|
|
2 |
new file mode 100644
|
|
3 |
--- /dev/null
|
|
4 |
+++ Python-2.6.4/Modules/authattr.c
|
|
5 |
@@ -0,0 +1,261 @@
|
|
6 |
+/*
|
|
7 |
+ * CDDL HEADER START
|
|
8 |
+ *
|
|
9 |
+ * The contents of this file are subject to the terms of the
|
|
10 |
+ * Common Development and Distribution License (the "License").
|
|
11 |
+ * You may not use this file except in compliance with the License.
|
|
12 |
+ *
|
|
13 |
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
|
14 |
+ * or http://www.opensolaris.org/os/licensing.
|
|
15 |
+ * See the License for the specific language governing permissions
|
|
16 |
+ * and limitations under the License.
|
|
17 |
+ *
|
|
18 |
+ * When distributing Covered Code, include this CDDL HEADER in each
|
|
19 |
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
20 |
+ * If applicable, add the following below this CDDL HEADER, with the
|
|
21 |
+ * fields enclosed by brackets "[]" replaced with your own identifying
|
|
22 |
+ * information: Portions Copyright [yyyy] [name of copyright owner]
|
|
23 |
+ *
|
|
24 |
+ * CDDL HEADER END
|
|
25 |
+ */
|
|
26 |
+
|
|
27 |
+/*
|
|
28 |
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
|
|
29 |
+ */
|
|
30 |
+
|
|
31 |
+/*
|
|
32 |
+ * RBAC Bindings for Python - auth_attr functions
|
|
33 |
+ */
|
|
34 |
+
|
|
35 |
+#include <auth_attr.h>
|
|
36 |
+#include "Python.h"
|
|
37 |
+#include "pyrbac.h"
|
|
38 |
+
|
|
39 |
+static PyObject*
|
|
40 |
+pyrbac_setauthattr(PyObject* self, PyObject* args) {
|
|
41 |
+ setauthattr();
|
|
42 |
+ return Py_None;
|
|
43 |
+}
|
|
44 |
+
|
|
45 |
+static PyObject*
|
|
46 |
+pyrbac_endauthattr(PyObject* self, PyObject* args) {
|
|
47 |
+ endauthattr();
|
|
48 |
+ return Py_None;
|
|
49 |
+}
|
|
50 |
+
|
|
51 |
+PyObject*
|
|
52 |
+pyrbac_getauthnamattr(PyObject* self, char* authname, int mode) {
|
|
53 |
+
|
|
54 |
+
|
|
55 |
+
|
|
56 |
+ authattr_t * ret_authattr = (mode == PYRBAC_NAM_MODE) ? getauthnam(authname) : getauthattr();
|
|
57 |
+ if (ret_authattr == NULL)
|
|
58 |
+ return Py_None;
|
|
59 |
+
|
|
60 |
+ PyObject* kv_data = PyDict_New();
|
|
61 |
+ if (kv_data == NULL) {
|
|
62 |
+ free_authattr(ret_authattr);
|
|
63 |
+ return NULL;
|
|
64 |
+ }
|
|
65 |
+
|
|
66 |
+ if(ret_authattr->attr != NULL) {
|
|
67 |
+ int len;
|
|
68 |
+ for(len = 0; len < ret_authattr->attr->length; len++) {
|
|
69 |
+ kv_t current = ret_authattr->attr->data[len];
|
|
70 |
+
|
|
71 |
+ PyObject* set = PyList_New(NULL);
|
|
72 |
+ char* saveptr;
|
|
73 |
+ char* item = strtok_r(current.value, ",", &saveptr);
|
|
74 |
+ PyList_Append(set, PyString_FromString(item));
|
|
75 |
+
|
|
76 |
+ while((item = strtok_r(NULL, ",", &saveptr)) != NULL) {
|
|
77 |
+ if(PyList_Append(set, PyString_FromString(item)) != 0) {
|
|
78 |
+ Py_XDECREF(set);
|
|
79 |
+ Py_XDECREF(kv_data);
|
|
80 |
+ free_authattr(ret_authattr);
|
|
81 |
+ return NULL;
|
|
82 |
+ }
|
|
83 |
+ }
|
|
84 |
+ if(PyDict_SetItemString(kv_data, current.key, set)) {
|
|
85 |
+ free_authattr(ret_authattr);
|
|
86 |
+ return NULL;
|
|
87 |
+ }
|
|
88 |
+ }
|
|
89 |
+ }
|
|
90 |
+ PyObject * retval = Py_BuildValue("{s:s,s:s,s:s,s:s,s:s,s:O}",
|
|
91 |
+ "name",ret_authattr->name,
|
|
92 |
+ "res1",ret_authattr->res1,
|
|
93 |
+ "res2",ret_authattr->res2,
|
|
94 |
+ "short",ret_authattr->short_desc,
|
|
95 |
+ "long",ret_authattr->long_desc,
|
|
96 |
+ "attributes",kv_data);
|
|
97 |
+
|
|
98 |
+ free_authattr(ret_authattr);
|
|
99 |
+ return retval;
|
|
100 |
+
|
|
101 |
+}
|
|
102 |
+
|
|
103 |
+static PyObject*
|
|
104 |
+pyrbac_getauthattr(PyObject* self, PyObject* args) {
|
|
105 |
+ return(pyrbac_getauthnamattr(self, NULL, PYRBAC_ATTR_MODE));
|
|
106 |
+}
|
|
107 |
+
|
|
108 |
+static PyObject*
|
|
109 |
+pyrbac_getauthnam(PyObject* self, PyObject* args) {
|
|
110 |
+ char* name = NULL;
|
|
111 |
+ if(!PyArg_ParseTuple(args, "s:getauthnam", &name))
|
|
112 |
+ return NULL;
|
|
113 |
+ return(pyrbac_getauthnamattr(self, name, PYRBAC_NAM_MODE));
|
|
114 |
+}
|
|
115 |
+
|
|
116 |
+static PyObject *
|
|
117 |
+pyrbac_chkauthattr(PyObject* self, PyObject* args) {
|
|
118 |
+ char* authstring = NULL;
|
|
119 |
+ char* username = NULL;
|
|
120 |
+ if(!PyArg_ParseTuple(args, "ss:chkauthattr", &authstring, &username))
|
|
121 |
+ return NULL;
|
|
122 |
+ return PyBool_FromLong((long)chkauthattr(authstring, username));
|
|
123 |
+}
|
|
124 |
+
|
|
125 |
+static PyObject*
|
|
126 |
+pyrbac_authattr_next(PyObject* self, PyObject* args) {
|
|
127 |
+ PyObject* retval = pyrbac_getauthattr(self, args);
|
|
128 |
+ if( retval == Py_None ) {
|
|
129 |
+ setauthattr();
|
|
130 |
+ return NULL;
|
|
131 |
+ }
|
|
132 |
+ return retval;
|
|
133 |
+}
|
|
134 |
+static PyObject*
|
|
135 |
+pyrbac_authattr__iter__(PyObject* self, PyObject* args) {
|
|
136 |
+ return self;
|
|
137 |
+}
|
|
138 |
+
|
|
139 |
+typedef struct {
|
|
140 |
+ PyObject_HEAD
|
|
141 |
+} Authattr;
|
|
142 |
+
|
|
143 |
+static void
|
|
144 |
+Authattr_dealloc(Authattr* self) {
|
|
145 |
+ endauthattr();
|
|
146 |
+ self->ob_type->tp_free((PyObject*) self);
|
|
147 |
+}
|
|
148 |
+
|
|
149 |
+static PyObject*
|
|
150 |
+Authattr_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
|
|
151 |
+ Authattr *self;
|
|
152 |
+ self = (Authattr*)type->tp_alloc(type, 0);
|
|
153 |
+
|
|
154 |
+ return ((PyObject *) self);
|
|
155 |
+}
|
|
156 |
+
|
|
157 |
+static int
|
|
158 |
+Authattr_init(Authattr* self, PyObject *args, PyObject *kwargs) {
|
|
159 |
+ setauthattr();
|
|
160 |
+ return 0;
|
|
161 |
+}
|
|
162 |
+
|
|
163 |
+static char pyrbac_authattr__doc__[];
|
|
164 |
+
|
|
165 |
+PyDoc_STRVAR(pyrbac_authattr__doc__, """provides interfaces to the auth_attr \
|
|
166 |
+database. may be iterated over to return all auth_attr entries\n\n\
|
|
167 |
+Methods provided:\n\
|
|
168 |
+setauthattr\n\
|
|
169 |
+endauthattr\n\
|
|
170 |
+getauthattr\n\
|
|
171 |
+chkauthattr\n\
|
|
172 |
+getauthnam""");
|
|
173 |
+
|
|
174 |
+static char pyrbac_setauthattr__doc__[];
|
|
175 |
+static char pyrbac_endauthattr__doc__[];
|
|
176 |
+static char pyrbac_getauthattr__doc__[];
|
|
177 |
+static char pyrbac_chkauthattr__doc__[];
|
|
178 |
+
|
|
179 |
+PyDoc_STRVAR(pyrbac_setauthattr__doc__,
|
|
180 |
+"\"rewinds\" the auth_attr functions to the first entry in the db. Called \
|
|
181 |
+automatically by the constructor\n\tArguments: None\n\tReturns: None");
|
|
182 |
+
|
|
183 |
+PyDoc_STRVAR(pyrbac_endauthattr__doc__,
|
|
184 |
+"closes the auth_attr database, cleans up storage. called automatically by \
|
|
185 |
+the destructor\n\tArguments: None\n\tReturns: None");
|
|
186 |
+
|
|
187 |
+PyDoc_STRVAR(pyrbac_chkauthattr__doc__, "verifies if a user has a given \
|
|
188 |
+authorization.\n\tArguments: 2 Python strings, 'authname' and 'username'\n\
|
|
189 |
+\tReturns: True if the user is authorized, False otherwise");
|
|
190 |
+
|
|
191 |
+PyDoc_STRVAR(pyrbac_getauthattr__doc__,
|
|
192 |
+"return one entry from the auth_attr database\n\
|
|
193 |
+\tArguments: None\n\
|
|
194 |
+\tReturns: a dict representing the authattr_t struct:\n\
|
|
195 |
+\t\t\"name\": Authorization Name\n\
|
|
196 |
+\t\t\"res1\": reserved\n\
|
|
197 |
+\t\t\"res2\": reserved\n\
|
|
198 |
+\t\t\"short\": Short Description\n\
|
|
199 |
+\t\t\"long\": Long Description\n\
|
|
200 |
+\t\t\"attributes\": A Python dict keyed by attribute & valued as either a list \
|
|
201 |
+or a string depending on value");
|
|
202 |
+
|
|
203 |
+PyDoc_STRVAR(pyrbac_getauthnam__doc__,
|
|
204 |
+"searches the auth_attr database for a given authorization name\n\
|
|
205 |
+\tArguments: a Python string containing the auth name\n\
|
|
206 |
+\tReturns: a dict representing the authattr_t struct:\n\
|
|
207 |
+\t\t\"name\": Authorization Name\n\
|
|
208 |
+\t\t\"res1\": reserved\n\
|
|
209 |
+\t\t\"res2\": reserved\n\
|
|
210 |
+\t\t\"short\": Short Description\n\
|
|
211 |
+\t\t\"long\": Long Description\n\
|
|
212 |
+\t\t\"attributes\": A Python dict keyed by attribute & valued as either a list \
|
|
213 |
+or a string depending on value");
|
|
214 |
+
|
|
215 |
+static PyMethodDef Authattr_methods[] = {
|
|
216 |
+ {"setauthattr", pyrbac_setauthattr, METH_NOARGS, pyrbac_setauthattr__doc__},
|
|
217 |
+ {"endauthattr", pyrbac_endauthattr, METH_NOARGS, pyrbac_endauthattr__doc__},
|
|
218 |
+ {"chkauthattr", pyrbac_chkauthattr, METH_VARARGS, pyrbac_chkauthattr__doc__},
|
|
219 |
+ {"getauthattr", pyrbac_getauthattr, METH_NOARGS, pyrbac_getauthattr__doc__},
|
|
220 |
+ {"getauthnam", pyrbac_getauthnam, METH_VARARGS, pyrbac_getauthnam__doc__},
|
|
221 |
+ {NULL}
|
|
222 |
+};
|
|
223 |
+
|
|
224 |
+PyTypeObject AuthattrType = {
|
|
225 |
+ PyObject_HEAD_INIT(NULL)
|
|
226 |
+ 0, /*ob_size*/
|
|
227 |
+ "rbac.authattr", /*tp_name*/
|
|
228 |
+ sizeof(Authattr), /*tp_basicsize*/
|
|
229 |
+ 0, /*tp_itemsize*/
|
|
230 |
+ (destructor)Authattr_dealloc, /*tp_dealloc*/
|
|
231 |
+ 0, /*tp_print*/
|
|
232 |
+ 0, /*tp_getattr*/
|
|
233 |
+ 0, /*tp_setattr*/
|
|
234 |
+ 0, /*tp_compare*/
|
|
235 |
+ 0, /*tp_repr*/
|
|
236 |
+ 0, /*tp_as_number*/
|
|
237 |
+ 0, /*tp_as_sequence*/
|
|
238 |
+ 0, /*tp_as_mapping*/
|
|
239 |
+ 0, /*tp_hash */
|
|
240 |
+ 0, /*tp_call*/
|
|
241 |
+ 0, /*tp_str*/
|
|
242 |
+ 0, /*tp_getattro*/
|
|
243 |
+ 0, /*tp_setattro*/
|
|
244 |
+ 0, /*tp_as_buffer*/
|
|
245 |
+ Py_TPFLAGS_DEFAULT |
|
|
246 |
+ Py_TPFLAGS_BASETYPE |
|
|
247 |
+ Py_TPFLAGS_HAVE_ITER, /*tp_flags*/
|
|
248 |
+ pyrbac_authattr__doc__, /* tp_doc */
|
|
249 |
+ 0, /* tp_traverse */
|
|
250 |
+ 0, /* tp_clear */
|
|
251 |
+ 0, /* tp_richcompare */
|
|
252 |
+ 0, /* tp_weaklistoffset */
|
|
253 |
+ pyrbac_authattr__iter__, /* tp_iter */
|
|
254 |
+ pyrbac_authattr_next, /* tp_iternext */
|
|
255 |
+ Authattr_methods, /* tp_methods */
|
|
256 |
+ 0, /* tp_members */
|
|
257 |
+ 0, /* tp_getset */
|
|
258 |
+ 0, /* tp_base */
|
|
259 |
+ 0, /* tp_dict */
|
|
260 |
+ 0, /* tp_descr_get */
|
|
261 |
+ 0, /* tp_descr_set */
|
|
262 |
+ 0, /* tp_dictoffset */
|
|
263 |
+ (initproc)Authattr_init, /* tp_init */
|
|
264 |
+ 0, /* tp_alloc */
|
|
265 |
+ Authattr_new, /* tp_new */
|
|
266 |
+};
|
|
267 |
diff --git Python-2.6.4/Modules/execattr.c Python-2.6.4/Modules/execattr.c
|
|
268 |
new file mode 100644
|
|
269 |
--- /dev/null
|
|
270 |
+++ Python-2.6.4/Modules/execattr.c
|
|
271 |
@@ -0,0 +1,313 @@
|
|
272 |
+/*
|
|
273 |
+ * CDDL HEADER START
|
|
274 |
+ *
|
|
275 |
+ * The contents of this file are subject to the terms of the
|
|
276 |
+ * Common Development and Distribution License (the "License").
|
|
277 |
+ * You may not use this file except in compliance with the License.
|
|
278 |
+ *
|
|
279 |
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
|
280 |
+ * or http://www.opensolaris.org/os/licensing.
|
|
281 |
+ * See the License for the specific language governing permissions
|
|
282 |
+ * and limitations under the License.
|
|
283 |
+ *
|
|
284 |
+ * When distributing Covered Code, include this CDDL HEADER in each
|
|
285 |
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
286 |
+ * If applicable, add the following below this CDDL HEADER, with the
|
|
287 |
+ * fields enclosed by brackets "[]" replaced with your own identifying
|
|
288 |
+ * information: Portions Copyright [yyyy] [name of copyright owner]
|
|
289 |
+ *
|
|
290 |
+ * CDDL HEADER END
|
|
291 |
+ */
|
|
292 |
+
|
|
293 |
+/*
|
|
294 |
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
|
|
295 |
+ */
|
|
296 |
+
|
|
297 |
+/*
|
|
298 |
+ * RBAC Bindings for Python - exec_attr functions
|
|
299 |
+ */
|
|
300 |
+
|
|
301 |
+#include <exec_attr.h>
|
|
302 |
+#include "Python.h"
|
|
303 |
+#include "pyrbac.h"
|
|
304 |
+
|
|
305 |
+static PyObject *
|
|
306 |
+pyrbac_setexecattr(PyObject* self, PyObject* args) {
|
|
307 |
+ setexecattr();
|
|
308 |
+ return Py_None;
|
|
309 |
+}
|
|
310 |
+
|
|
311 |
+static PyObject *
|
|
312 |
+pyrbac_endexecattr(PyObject* self, PyObject* args) {
|
|
313 |
+ endexecattr();
|
|
314 |
+ return Py_None;
|
|
315 |
+}
|
|
316 |
+
|
|
317 |
+PyObject *
|
|
318 |
+pyrbac_getexecuserprofattr(PyObject* self, char* userprofname, char* type, char* id, int mode) {
|
|
319 |
+
|
|
320 |
+ PyObject* ep_data = (mode == PYRBAC_ATTR_MODE) ? NULL : PyList_New(0);
|
|
321 |
+
|
|
322 |
+ if (ep_data == NULL && mode != PYRBAC_ATTR_MODE )
|
|
323 |
+ return NULL;
|
|
324 |
+
|
|
325 |
+ execattr_t *execprof;
|
|
326 |
+ if (mode == PYRBAC_USER_MODE)
|
|
327 |
+ execprof = getexecuser(userprofname, type, id, GET_ALL);
|
|
328 |
+ else if (mode == PYRBAC_PROF_MODE)
|
|
329 |
+ execprof = getexecprof(userprofname, type, id, GET_ALL);
|
|
330 |
+ else if (mode == PYRBAC_ATTR_MODE)
|
|
331 |
+ execprof = getexecattr();
|
|
332 |
+ else
|
|
333 |
+ return NULL;
|
|
334 |
+
|
|
335 |
+ if (execprof == NULL)
|
|
336 |
+ return Py_None;
|
|
337 |
+
|
|
338 |
+ execattr_t *execprof_head = execprof;
|
|
339 |
+
|
|
340 |
+ while(execprof != NULL) {
|
|
341 |
+
|
|
342 |
+ PyObject* kv_data = PyDict_New();
|
|
343 |
+
|
|
344 |
+ if(execprof->attr != NULL) {
|
|
345 |
+ int len;
|
|
346 |
+ for(len = 0; len < execprof->attr->length; len++) {
|
|
347 |
+ kv_t current = execprof->attr->data[len];
|
|
348 |
+
|
|
349 |
+ PyObject* set = PyList_New(NULL);
|
|
350 |
+ char* saveptr;
|
|
351 |
+ char* item = strtok_r(current.value, ",", &saveptr);
|
|
352 |
+ PyList_Append(set, PyString_FromString(item));
|
|
353 |
+
|
|
354 |
+ while((item = strtok_r(NULL, ",", &saveptr)) != NULL) {
|
|
355 |
+ if(PyList_Append(set, PyString_FromString(item)) != 0) {
|
|
356 |
+ Py_XDECREF(set);
|
|
357 |
+ Py_XDECREF(kv_data);
|
|
358 |
+ free_execattr(execprof_head);
|
|
359 |
+ return NULL;
|
|
360 |
+ }
|
|
361 |
+ }
|
|
362 |
+ if(PyDict_SetItemString(kv_data, current.key, set)) {
|
|
363 |
+ free_execattr(execprof_head);
|
|
364 |
+ return NULL;
|
|
365 |
+ }
|
|
366 |
+ }
|
|
367 |
+ }
|
|
368 |
+ PyObject* entry = Py_BuildValue("{s:s,s:s,s:s,s:s,s:s,s:s,s:O}",
|
|
369 |
+ "name", execprof->name,
|
|
370 |
+ "type", execprof->type,
|
|
371 |
+ "policy", execprof->policy,
|
|
372 |
+ "res1", execprof->res1,
|
|
373 |
+ "res2", execprof->res2,
|
|
374 |
+ "id", execprof->id,
|
|
375 |
+ "attributes", kv_data);
|
|
376 |
+
|
|
377 |
+ if (entry == NULL) {
|
|
378 |
+ Py_XDECREF(kv_data);
|
|
379 |
+ free_execattr(execprof_head);
|
|
380 |
+ return NULL;
|
|
381 |
+ }
|
|
382 |
+
|
|
383 |
+ if (mode == PYRBAC_ATTR_MODE) {
|
|
384 |
+ free_execattr(execprof_head);
|
|
385 |
+ return(entry);
|
|
386 |
+ }
|
|
387 |
+ PyList_Append(ep_data, entry);
|
|
388 |
+ execprof = execprof->next;
|
|
389 |
+ }
|
|
390 |
+
|
|
391 |
+ free_execattr(execprof_head);
|
|
392 |
+ return(ep_data);
|
|
393 |
+
|
|
394 |
+}
|
|
395 |
+
|
|
396 |
+static PyObject *
|
|
397 |
+pyrbac_getexecuser(PyObject* self, PyObject* args) {
|
|
398 |
+ char* username = NULL;
|
|
399 |
+ char* type = NULL;
|
|
400 |
+ char* id = NULL;
|
|
401 |
+
|
|
402 |
+ if(!PyArg_ParseTuple(args, "sss:getexecuser", &username, &type, &id))
|
|
403 |
+ return NULL;
|
|
404 |
+
|
|
405 |
+ return (pyrbac_getexecuserprofattr(self, username, type, id, PYRBAC_USER_MODE));
|
|
406 |
+}
|
|
407 |
+
|
|
408 |
+static PyObject *
|
|
409 |
+pyrbac_getexecprof(PyObject* self, PyObject* args) {
|
|
410 |
+
|
|
411 |
+ char* profname = NULL;
|
|
412 |
+ char* type = NULL;
|
|
413 |
+ char* id = NULL;
|
|
414 |
+
|
|
415 |
+ if(!PyArg_ParseTuple(args, "sss:getexecprof", &profname, &type, &id))
|
|
416 |
+ return NULL;
|
|
417 |
+
|
|
418 |
+ return (pyrbac_getexecuserprofattr(self, profname, type, id, PYRBAC_PROF_MODE));
|
|
419 |
+}
|
|
420 |
+
|
|
421 |
+static PyObject*
|
|
422 |
+pyrbac_getexecattr(PyObject* self, PyObject* args) {
|
|
423 |
+ return pyrbac_getexecuserprofattr(self, NULL, NULL, NULL, PYRBAC_ATTR_MODE);
|
|
424 |
+}
|
|
425 |
+
|
|
426 |
+static PyObject*
|
|
427 |
+pyrbac_execattr_next(PyObject* self, PyObject* args) {
|
|
428 |
+ PyObject* retval = pyrbac_getexecattr(self, args);
|
|
429 |
+ if( retval == Py_None ) {
|
|
430 |
+ setexecattr();
|
|
431 |
+ return NULL;
|
|
432 |
+ }
|
|
433 |
+ return retval;
|
|
434 |
+}
|
|
435 |
+static PyObject*
|
|
436 |
+pyrbac_execattr__iter__(PyObject* self, PyObject* args) {
|
|
437 |
+ return self;
|
|
438 |
+}
|
|
439 |
+
|
|
440 |
+typedef struct {
|
|
441 |
+ PyObject_HEAD
|
|
442 |
+} Execattr;
|
|
443 |
+
|
|
444 |
+static void
|
|
445 |
+Execattr_dealloc(Execattr* self) {
|
|
446 |
+ endexecattr();
|
|
447 |
+ self->ob_type->tp_free((PyObject*) self);
|
|
448 |
+}
|
|
449 |
+
|
|
450 |
+static PyObject*
|
|
451 |
+Execattr_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
|
|
452 |
+ Execattr *self;
|
|
453 |
+ self = (Execattr*)type->tp_alloc(type, 0);
|
|
454 |
+
|
|
455 |
+ return ((PyObject *) self);
|
|
456 |
+}
|
|
457 |
+
|
|
458 |
+static int
|
|
459 |
+Execattr_init(Execattr* self, PyObject *args, PyObject *kwargs) {
|
|
460 |
+ setexecattr();
|
|
461 |
+ return 0;
|
|
462 |
+}
|
|
463 |
+
|
|
464 |
+static char pyrbac_execattr__doc__[];
|
|
465 |
+
|
|
466 |
+PyDoc_STRVAR(pyrbac_execattr__doc__, "provides functions for \
|
|
467 |
+interacting with the execution profiles database. May be iterated over to \
|
|
468 |
+enumerate exec_attr(4) entries\n\n\
|
|
469 |
+Methods provided:\n\
|
|
470 |
+setexecattr\n\
|
|
471 |
+endexecattr\n\
|
|
472 |
+getexecattr\n\
|
|
473 |
+getexecprof\n\
|
|
474 |
+getexecuser");
|
|
475 |
+
|
|
476 |
+
|
|
477 |
+static char pyrbac_getexecuser__doc__[];
|
|
478 |
+static char pyrbac_getexecprof__doc__[];
|
|
479 |
+static char pyrbac_getexecattr__doc__[];
|
|
480 |
+static char pyrbac_setexecattr__doc__[];
|
|
481 |
+static char pyrbac_endexecattr__doc__[];
|
|
482 |
+
|
|
483 |
+PyDoc_STRVAR(pyrbac_setexecattr__doc__,
|
|
484 |
+"\"rewinds\" the exec_attr functions to the first entry in the db. Called \
|
|
485 |
+automatically by the constructor.\n\
|
|
486 |
+\tArguments: None\
|
|
487 |
+\tReturns: None");
|
|
488 |
+
|
|
489 |
+PyDoc_STRVAR(pyrbac_endexecattr__doc__,
|
|
490 |
+"closes the exec_attr database, cleans up storage. called automatically by \
|
|
491 |
+the destructor.\n\
|
|
492 |
+\tArguments: None\
|
|
493 |
+\tReturns: None");
|
|
494 |
+
|
|
495 |
+PyDoc_STRVAR(pyrbac_getexecuser__doc__, "corresponds with getexecuser(3SECDB)\
|
|
496 |
+\nTakes: \'username\', \'type\', \'id\'\n\
|
|
497 |
+Return: a single exec_attr entry\n\
|
|
498 |
+\tArguments: None\n\
|
|
499 |
+\tReturns: a dict representation of an execattr_t struct:\n\
|
|
500 |
+\t\t\"name\": Authorization Name\n\
|
|
501 |
+\t\t\"type\": Profile Type\n\
|
|
502 |
+\t\t\"policy\": Policy attributes are relevant in\n\
|
|
503 |
+\t\t\"res1\": reserved\n\
|
|
504 |
+\t\t\"res2\": reserved\n\
|
|
505 |
+\t\t\"id\": unique identifier\n\
|
|
506 |
+\t\t\"attributes\": A Python dict keyed by attribute & valued as\
|
|
507 |
+either a list or a string depending on value");
|
|
508 |
+
|
|
509 |
+PyDoc_STRVAR(pyrbac_getexecprof__doc__, "corresponds with getexecprof(3SECDB)\
|
|
510 |
+\nTakes: \'profile name\', \'type\', \'id\'\n\
|
|
511 |
+\tReturns: a dict representation of an execattr_t struct:\n\
|
|
512 |
+\t\t\"name\": Authorization Name\n\
|
|
513 |
+\t\t\"type\": Profile Type\n\
|
|
514 |
+\t\t\"policy\": Policy attributes are relevant in\n\
|
|
515 |
+\t\t\"res1\": reserved\n\
|
|
516 |
+\t\t\"res2\": reserved\n\
|
|
517 |
+\t\t\"id\": unique identifier\n\
|
|
518 |
+\t\t\"attributes\": A Python dict keyed by attribute & valued as\
|
|
519 |
+either a list or a string depending on value");
|
|
520 |
+
|
|
521 |
+PyDoc_STRVAR(pyrbac_getexecattr__doc__, "corresponds with getexecattr(3SECDB)\
|
|
522 |
+\nTakes 0 arguments\n\
|
|
523 |
+\tReturns: a dict representation of an execattr_t struct:\n\
|
|
524 |
+\t\t\"name\": Authorization Name\n\
|
|
525 |
+\t\t\"type\": Profile Type\n\
|
|
526 |
+\t\t\"policy\": Policy attributes are relevant in\n\
|
|
527 |
+\t\t\"res1\": reserved\n\
|
|
528 |
+\t\t\"res2\": reserved\n\
|
|
529 |
+\t\t\"id\": unique identifier\n\
|
|
530 |
+\t\t\"attributes\": A Python dict keyed by attribute & valued as\
|
|
531 |
+either a list or a string depending on value");
|
|
532 |
+
|
|
533 |
+static PyMethodDef Execattr_methods[] = {
|
|
534 |
+ {"setexecattr", pyrbac_setexecattr, METH_NOARGS, pyrbac_setexecattr__doc__},
|
|
535 |
+ {"endexecattr", pyrbac_endexecattr, METH_NOARGS, pyrbac_endexecattr__doc__},
|
|
536 |
+ {"getexecprof", pyrbac_getexecprof, METH_VARARGS, pyrbac_getexecprof__doc__},
|
|
537 |
+ {"getexecuser", pyrbac_getexecuser, METH_VARARGS, pyrbac_getexecuser__doc__},
|
|
538 |
+ {"getexecattr", pyrbac_getexecattr, METH_NOARGS, pyrbac_getexecattr__doc__},
|
|
539 |
+ {NULL}
|
|
540 |
+};
|
|
541 |
+
|
|
542 |
+PyTypeObject ExecattrType = {
|
|
543 |
+ PyObject_HEAD_INIT(NULL)
|
|
544 |
+ 0, /*ob_size*/
|
|
545 |
+ "rbac.execattr", /*tp_name*/
|
|
546 |
+ sizeof(Execattr), /*tp_basicsize*/
|
|
547 |
+ 0, /*tp_itemsize*/
|
|
548 |
+ (destructor)Execattr_dealloc, /*tp_dealloc*/
|
|
549 |
+ 0, /*tp_print*/
|
|
550 |
+ 0, /*tp_getattr*/
|
|
551 |
+ 0, /*tp_setattr*/
|
|
552 |
+ 0, /*tp_compare*/
|
|
553 |
+ 0, /*tp_repr*/
|
|
554 |
+ 0, /*tp_as_number*/
|
|
555 |
+ 0, /*tp_as_sequence*/
|
|
556 |
+ 0, /*tp_as_mapping*/
|
|
557 |
+ 0, /*tp_hash */
|
|
558 |
+ 0, /*tp_call*/
|
|
559 |
+ 0, /*tp_str*/
|
|
560 |
+ 0, /*tp_getattro*/
|
|
561 |
+ 0, /*tp_setattro*/
|
|
562 |
+ 0, /*tp_as_buffer*/
|
|
563 |
+ Py_TPFLAGS_DEFAULT |
|
|
564 |
+ Py_TPFLAGS_BASETYPE |
|
|
565 |
+ Py_TPFLAGS_HAVE_ITER, /*tp_flags*/
|
|
566 |
+ pyrbac_execattr__doc__, /* tp_doc */
|
|
567 |
+ 0, /* tp_traverse */
|
|
568 |
+ 0, /* tp_clear */
|
|
569 |
+ 0, /* tp_richcompare */
|
|
570 |
+ 0, /* tp_weaklistoffset */
|
|
571 |
+ pyrbac_execattr__iter__, /* tp_iter */
|
|
572 |
+ pyrbac_execattr_next, /* tp_iternext */
|
|
573 |
+ Execattr_methods, /* tp_methods */
|
|
574 |
+ 0, /* tp_members */
|
|
575 |
+ 0, /* tp_getset */
|
|
576 |
+ 0, /* tp_base */
|
|
577 |
+ 0, /* tp_dict */
|
|
578 |
+ 0, /* tp_descr_get */
|
|
579 |
+ 0, /* tp_descr_set */
|
|
580 |
+ 0, /* tp_dictoffset */
|
|
581 |
+ (initproc)Execattr_init, /* tp_init */
|
|
582 |
+ 0, /* tp_alloc */
|
|
583 |
+ Execattr_new, /* tp_new */
|
|
584 |
+};
|
|
585 |
diff --git Python-2.6.4/Modules/privileges.c Python-2.6.4/Modules/privileges.c
|
|
586 |
new file mode 100644
|
|
587 |
--- /dev/null
|
|
588 |
+++ Python-2.6.4/Modules/privileges.c
|
|
589 |
@@ -0,0 +1,229 @@
|
|
590 |
+/*
|
|
591 |
+ * CDDL HEADER START
|
|
592 |
+ *
|
|
593 |
+ * The contents of this file are subject to the terms of the
|
|
594 |
+ * Common Development and Distribution License (the "License").
|
|
595 |
+ * You may not use this file except in compliance with the License.
|
|
596 |
+ *
|
|
597 |
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
|
598 |
+ * or http://www.opensolaris.org/os/licensing.
|
|
599 |
+ * See the License for the specific language governing permissions
|
|
600 |
+ * and limitations under the License.
|
|
601 |
+ *
|
|
602 |
+ * When distributing Covered Code, include this CDDL HEADER in each
|
|
603 |
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
604 |
+ * If applicable, add the following below this CDDL HEADER, with the
|
|
605 |
+ * fields enclosed by brackets "[]" replaced with your own identifying
|
|
606 |
+ * information: Portions Copyright [yyyy] [name of copyright owner]
|
|
607 |
+ *
|
|
608 |
+ * CDDL HEADER END
|
|
609 |
+ */
|
|
610 |
+
|
|
611 |
+/*
|
|
612 |
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
|
|
613 |
+ */
|
|
614 |
+
|
|
615 |
+/*
|
|
616 |
+ * privileges(5) bindings for Python
|
|
617 |
+ */
|
|
618 |
+
|
|
619 |
+#include <priv.h>
|
|
620 |
+#include "Python.h"
|
|
621 |
+
|
|
622 |
+static PyObject *
|
|
623 |
+pyprivileges_setppriv( PyObject *self, PyObject *args) {
|
|
624 |
+ priv_op_t op = -1 ;
|
|
625 |
+ priv_ptype_t which = NULL;
|
|
626 |
+
|
|
627 |
+ PyObject* set_list = NULL;
|
|
628 |
+
|
|
629 |
+ priv_set_t * set = NULL;
|
|
630 |
+
|
|
631 |
+ if(!PyArg_ParseTuple(args, "iiO:setppriv", &op, &which, &set_list))
|
|
632 |
+ return NULL;
|
|
633 |
+
|
|
634 |
+ if((op != PRIV_ON && op != PRIV_OFF && op != PRIV_SET) ||
|
|
635 |
+ (which != PRIV_PERMITTED && which != PRIV_EFFECTIVE &&
|
|
636 |
+ which != PRIV_INHERITABLE && which != PRIV_LIMIT))
|
|
637 |
+ return NULL;
|
|
638 |
+
|
|
639 |
+ PyObject* set_string = PyList_GetItem(set_list, 0);
|
|
640 |
+ int i;
|
|
641 |
+ for (i = 1; i < PyList_Size(set_list); ++i) {
|
|
642 |
+ PyString_Concat(&set_string, PyString_FromString(","));
|
|
643 |
+ PyString_Concat(&set_string, PyList_GetItem(set_list, i));
|
|
644 |
+ }
|
|
645 |
+
|
|
646 |
+ set = priv_str_to_set(PyString_AsString(set_string), ",", NULL );
|
|
647 |
+
|
|
648 |
+ if ( set == NULL )
|
|
649 |
+ return NULL;
|
|
650 |
+
|
|
651 |
+ long ret = (long) setppriv(op, which, set);
|
|
652 |
+ priv_freeset(set);
|
|
653 |
+ // Python inverts true & false
|
|
654 |
+ if(ret)
|
|
655 |
+ Py_RETURN_FALSE;
|
|
656 |
+
|
|
657 |
+ Py_RETURN_TRUE;
|
|
658 |
+}
|
|
659 |
+
|
|
660 |
+static PyObject *
|
|
661 |
+pyprivileges_getppriv( PyObject *self, PyObject *args) {
|
|
662 |
+
|
|
663 |
+ char* set_str = NULL;
|
|
664 |
+ priv_ptype_t which = NULL;
|
|
665 |
+ priv_set_t * set = priv_allocset();
|
|
666 |
+ if (set == NULL)
|
|
667 |
+ return NULL;
|
|
668 |
+
|
|
669 |
+ if(!PyArg_ParseTuple(args, "i:getppriv", &which))
|
|
670 |
+ return NULL;
|
|
671 |
+
|
|
672 |
+ if (which != PRIV_PERMITTED && which != PRIV_EFFECTIVE &&
|
|
673 |
+ which != PRIV_INHERITABLE && which != PRIV_LIMIT)
|
|
674 |
+ return NULL;
|
|
675 |
+
|
|
676 |
+ if (getppriv(which, set) != 0)
|
|
677 |
+ return NULL;
|
|
678 |
+
|
|
679 |
+ set_str = priv_set_to_str(set, ',', PRIV_STR_LIT);
|
|
680 |
+ priv_freeset(set);
|
|
681 |
+
|
|
682 |
+ PyObject* set_list = PyList_New(NULL);
|
|
683 |
+ char* saveptr;
|
|
684 |
+ char* item = strtok_r(set_str, ",", &saveptr);
|
|
685 |
+ PyList_Append(set_list, PyString_FromString(item));
|
|
686 |
+
|
|
687 |
+ while((item = strtok_r(NULL, ",", &saveptr)) != NULL) {
|
|
688 |
+ if(PyList_Append(set_list, PyString_FromString(item)) != 0) {
|
|
689 |
+ Py_XDECREF(set_list);
|
|
690 |
+ return NULL;
|
|
691 |
+ }
|
|
692 |
+ }
|
|
693 |
+
|
|
694 |
+ return(set_list);
|
|
695 |
+}
|
|
696 |
+
|
|
697 |
+static PyObject *
|
|
698 |
+pyprivileges_priv_inverse( PyObject *self, PyObject *args ) {
|
|
699 |
+
|
|
700 |
+ PyObject* set_list_in = NULL;
|
|
701 |
+ if(!PyArg_ParseTuple(args, "O:priv_inverse", &set_list_in))
|
|
702 |
+ return NULL;
|
|
703 |
+
|
|
704 |
+ PyObject* set_string = PyList_GetItem(set_list_in, 0);
|
|
705 |
+ int i;
|
|
706 |
+ for (i = 1; i < PyList_Size(set_list_in); ++i) {
|
|
707 |
+ PyString_Concat(set_string, PyString_FromString(","));
|
|
708 |
+ PyString_Concat(set_string, PyList_GetItem(set_list_in, i));
|
|
709 |
+ }
|
|
710 |
+
|
|
711 |
+ priv_set_t * set = priv_str_to_set(PyString_AsString(set_string), ",", NULL);
|
|
712 |
+ if (set == NULL)
|
|
713 |
+ return NULL;
|
|
714 |
+ priv_inverse(set);
|
|
715 |
+ char * ret_str = priv_set_to_str(set, ',', PRIV_STR_LIT);
|
|
716 |
+ priv_freeset(set);
|
|
717 |
+
|
|
718 |
+ PyObject* set_list_out = PyList_New(NULL);
|
|
719 |
+ char* saveptr;
|
|
720 |
+ char* item = strtok_r(ret_str, ",", &saveptr);
|
|
721 |
+ PyList_Append(set_list_out, PyString_FromString(item));
|
|
722 |
+
|
|
723 |
+ while((item = strtok_r(NULL, ",", &saveptr)) != NULL) {
|
|
724 |
+ if(PyList_Append(set_list_out, PyString_FromString(item)) != 0) {
|
|
725 |
+ Py_XDECREF(set_list_out);
|
|
726 |
+ return NULL;
|
|
727 |
+ }
|
|
728 |
+ }
|
|
729 |
+
|
|
730 |
+ Py_XDECREF(set_list_in);
|
|
731 |
+
|
|
732 |
+ return(set_list_out);
|
|
733 |
+}
|
|
734 |
+
|
|
735 |
+/* priv_ineffect is a convienient wrapper to priv_get
|
|
736 |
+ * however priv_set is, in the context of python, not
|
|
737 |
+ * much of a convienience, so it's omitted
|
|
738 |
+ */
|
|
739 |
+static PyObject *
|
|
740 |
+pyprivileges_priv_ineffect(PyObject* self, PyObject* args) {
|
|
741 |
+ char* privstring=NULL;
|
|
742 |
+ if (!PyArg_ParseTuple(args, "s:priv_ineffect", &privstring))
|
|
743 |
+ return NULL;
|
|
744 |
+ return PyBool_FromLong(priv_ineffect(privstring));
|
|
745 |
+}
|
|
746 |
+
|
|
747 |
+
|
|
748 |
+static char pyprivileges__doc__[];
|
|
749 |
+PyDoc_STRVAR(pyprivileges__doc__,
|
|
750 |
+"Provides functions for interacting with the Solaris privileges(5) framework\n\
|
|
751 |
+Functions provided:\n\
|
|
752 |
+setppriv\n\
|
|
753 |
+getppriv\n\
|
|
754 |
+priv_ineffect\n\
|
|
755 |
+priv_inverse");
|
|
756 |
+
|
|
757 |
+static char pyprivileges_setppriv__doc__[];
|
|
758 |
+static char pyprivileges_getppriv__doc__[];
|
|
759 |
+static char pyprivileges_priv_ineffect__doc__[];
|
|
760 |
+static char pyprivileges_priv_inverse__doc__[];
|
|
761 |
+
|
|
762 |
+PyDoc_STRVAR(pyprivileges_setppriv__doc__,
|
|
763 |
+"Facilitates setting the permitted/inheritable/limit/effective privileges set\n\
|
|
764 |
+\tArguments:\n\
|
|
765 |
+\t\tone of (PRIV_ON|PRIV_OFF|PRIV_SET)\n\
|
|
766 |
+\t\tone of (PRIV_PERMITTED|PRIV_INHERITABLE|PRIV_LIMIT|PRIV_EFFECTIVE)\n\
|
|
767 |
+\t\tset of privileges: a list of strings\n\
|
|
768 |
+\tReturns: True on success, False on failure\
|
|
769 |
+");
|
|
770 |
+
|
|
771 |
+PyDoc_STRVAR(pyprivileges_getppriv__doc__,
|
|
772 |
+"Return the process privilege set\n\
|
|
773 |
+\tArguments:\n\
|
|
774 |
+\t\tone of (PRIV_PERMITTED|PRIV_INHERITABLE|PRIV_LIMIT|PRIV_EFFECTIVE)\n\
|
|
775 |
+\tReturns: a Python list of strings");
|
|
776 |
+
|
|
777 |
+PyDoc_STRVAR(pyprivileges_priv_ineffect__doc__,
|
|
778 |
+"Checks for a privileges presence in the effective set\n\
|
|
779 |
+\tArguments: a String\n\
|
|
780 |
+\tReturns: True if the privilege is in effect, False otherwise");
|
|
781 |
+
|
|
782 |
+PyDoc_STRVAR(pyprivileges_priv_inverse__doc__,
|
|
783 |
+"The complement of the set of privileges\n\
|
|
784 |
+\tArguments: a list of strings\n\tReturns: a list of strings");
|
|
785 |
+
|
|
786 |
+static PyMethodDef module_methods[] = {
|
|
787 |
+ {"setppriv", pyprivileges_setppriv, METH_VARARGS, pyprivileges_setppriv__doc__},
|
|
788 |
+ {"getppriv", pyprivileges_getppriv, METH_VARARGS, pyprivileges_getppriv__doc__},
|
|
789 |
+ {"priv_ineffect", pyprivileges_priv_ineffect, METH_VARARGS, pyprivileges_priv_ineffect__doc__},
|
|
790 |
+ {"priv_inverse", pyprivileges_priv_inverse, METH_VARARGS, pyprivileges_priv_inverse__doc__},
|
|
791 |
+ {NULL}
|
|
792 |
+};
|
|
793 |
+
|
|
794 |
+
|
|
795 |
+#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */
|
|
796 |
+#define PyMODINIT_FUNC void
|
|
797 |
+#endif
|
|
798 |
+PyMODINIT_FUNC
|
|
799 |
+initprivileges(void) {
|
|
800 |
+ PyObject* m;
|
|
801 |
+
|
|
802 |
+ m = Py_InitModule3("privileges", module_methods, pyprivileges__doc__);
|
|
803 |
+ if ( m == NULL )
|
|
804 |
+ return;
|
|
805 |
+
|
|
806 |
+ PyObject* d = PyModule_GetDict(m);
|
|
807 |
+ if (d == NULL)
|
|
808 |
+ return;
|
|
809 |
+
|
|
810 |
+ PyDict_SetItemString(d, "PRIV_ON", PyInt_FromLong((long)PRIV_ON));
|
|
811 |
+ PyDict_SetItemString(d, "PRIV_OFF", PyInt_FromLong((long)PRIV_OFF));
|
|
812 |
+ PyDict_SetItemString(d, "PRIV_SET", PyInt_FromLong((long)PRIV_SET));
|
|
813 |
+
|
|
814 |
+ PyDict_SetItemString(d, "PRIV_PERMITTED", PyInt_FromLong((long)PRIV_PERMITTED));
|
|
815 |
+ PyDict_SetItemString(d, "PRIV_INHERITABLE", PyInt_FromLong((long)PRIV_INHERITABLE));
|
|
816 |
+ PyDict_SetItemString(d, "PRIV_LIMIT", PyInt_FromLong((long)PRIV_LIMIT));
|
|
817 |
+ PyDict_SetItemString(d, "PRIV_EFFECTIVE", PyInt_FromLong((long)PRIV_EFFECTIVE));
|
|
818 |
+}
|
|
819 |
diff --git Python-2.6.4/Modules/pyrbac.c Python-2.6.4/Modules/pyrbac.c
|
|
820 |
new file mode 100644
|
|
821 |
--- /dev/null
|
|
822 |
+++ Python-2.6.4/Modules/pyrbac.c
|
|
823 |
@@ -0,0 +1,68 @@
|
|
824 |
+/*
|
|
825 |
+ * CDDL HEADER START
|
|
826 |
+ *
|
|
827 |
+ * The contents of this file are subject to the terms of the
|
|
828 |
+ * Common Development and Distribution License (the "License").
|
|
829 |
+ * You may not use this file except in compliance with the License.
|
|
830 |
+ *
|
|
831 |
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
|
832 |
+ * or http://www.opensolaris.org/os/licensing.
|
|
833 |
+ * See the License for the specific language governing permissions
|
|
834 |
+ * and limitations under the License.
|
|
835 |
+ *
|
|
836 |
+ * When distributing Covered Code, include this CDDL HEADER in each
|
|
837 |
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
838 |
+ * If applicable, add the following below this CDDL HEADER, with the
|
|
839 |
+ * fields enclosed by brackets "[]" replaced with your own identifying
|
|
840 |
+ * information: Portions Copyright [yyyy] [name of copyright owner]
|
|
841 |
+ *
|
|
842 |
+ * CDDL HEADER END
|
|
843 |
+ */
|
|
844 |
+
|
|
845 |
+/*
|
|
846 |
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
|
|
847 |
+ */
|
|
848 |
+
|
|
849 |
+/*
|
|
850 |
+ * RBAC Bindings for Python
|
|
851 |
+ */
|
|
852 |
+
|
|
853 |
+#include <Python.h>
|
|
854 |
+#include "pyrbac.h"
|
|
855 |
+
|
|
856 |
+static PyMethodDef module_methods[] = {NULL};
|
|
857 |
+static char pyrbac__doc__[];
|
|
858 |
+
|
|
859 |
+PyDoc_STRVAR(pyrbac__doc__, "provides access to some objects \
|
|
860 |
+for interaction with the Solaris Role-Based Access Control \
|
|
861 |
+framework.\n\nDynamic objects:\n\
|
|
862 |
+userattr -- for interacting with user_attr(4)\n\
|
|
863 |
+authattr -- for interacting with auth_attr(4)\n\
|
|
864 |
+execattr -- for interacting with exec_attr(4)\n");
|
|
865 |
+
|
|
866 |
+#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */
|
|
867 |
+#define PyMODINIT_FUNC void
|
|
868 |
+#endif
|
|
869 |
+PyMODINIT_FUNC
|
|
870 |
+initrbac(void) {
|
|
871 |
+ PyObject* m;
|
|
872 |
+ if (PyType_Ready(&AuthattrType) < 0 ||
|
|
873 |
+ PyType_Ready(&ExecattrType) < 0 ||
|
|
874 |
+ PyType_Ready(&UserattrType) < 0 )
|
|
875 |
+ return;
|
|
876 |
+
|
|
877 |
+ m = Py_InitModule3("rbac", module_methods, pyrbac__doc__);
|
|
878 |
+ if ( m == NULL )
|
|
879 |
+ return;
|
|
880 |
+
|
|
881 |
+ Py_INCREF(&AuthattrType);
|
|
882 |
+ PyModule_AddObject(m, "authattr", (PyObject*)&AuthattrType);
|
|
883 |
+
|
|
884 |
+ Py_INCREF(&ExecattrType);
|
|
885 |
+ PyModule_AddObject(m, "execattr", (PyObject*)&ExecattrType);
|
|
886 |
+
|
|
887 |
+ Py_INCREF(&UserattrType);
|
|
888 |
+ PyModule_AddObject(m, "userattr", (PyObject*)&UserattrType);
|
|
889 |
+
|
|
890 |
+}
|
|
891 |
+
|
|
892 |
diff --git Python-2.6.4/Modules/pyrbac.h Python-2.6.4/Modules/pyrbac.h
|
|
893 |
new file mode 100644
|
|
894 |
--- /dev/null
|
|
895 |
+++ Python-2.6.4/Modules/pyrbac.h
|
|
896 |
@@ -0,0 +1,45 @@
|
|
897 |
+/*
|
|
898 |
+ * CDDL HEADER START
|
|
899 |
+ *
|
|
900 |
+ * The contents of this file are subject to the terms of the
|
|
901 |
+ * Common Development and Distribution License (the "License").
|
|
902 |
+ * You may not use this file except in compliance with the License.
|
|
903 |
+ *
|
|
904 |
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
|
905 |
+ * or http://www.opensolaris.org/os/licensing.
|
|
906 |
+ * See the License for the specific language governing permissions
|
|
907 |
+ * and limitations under the License.
|
|
908 |
+ *
|
|
909 |
+ * When distributing Covered Code, include this CDDL HEADER in each
|
|
910 |
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
911 |
+ * If applicable, add the following below this CDDL HEADER, with the
|
|
912 |
+ * fields enclosed by brackets "[]" replaced with your own identifying
|
|
913 |
+ * information: Portions Copyright [yyyy] [name of copyright owner]
|
|
914 |
+ *
|
|
915 |
+ * CDDL HEADER END
|
|
916 |
+ */
|
|
917 |
+
|
|
918 |
+/*
|
|
919 |
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
|
|
920 |
+ */
|
|
921 |
+
|
|
922 |
+/*
|
|
923 |
+ * RBAC bindings for python
|
|
924 |
+ */
|
|
925 |
+#ifndef PYRBAC_H
|
|
926 |
+#define PYRBAC_H
|
|
927 |
+
|
|
928 |
+#include <secdb.h>
|
|
929 |
+
|
|
930 |
+
|
|
931 |
+#define PYRBAC_USER_MODE 1
|
|
932 |
+#define PYRBAC_PROF_MODE 2
|
|
933 |
+#define PYRBAC_ATTR_MODE 3
|
|
934 |
+#define PYRBAC_NAM_MODE 4
|
|
935 |
+#define PYRBAC_UID_MODE 5
|
|
936 |
+
|
|
937 |
+PyTypeObject AuthattrType;
|
|
938 |
+PyTypeObject ExecattrType;
|
|
939 |
+PyTypeObject UserattrType;
|
|
940 |
+
|
|
941 |
+#endif
|
|
942 |
diff --git Python-2.6.4/Modules/userattr.c Python-2.6.4/Modules/userattr.c
|
|
943 |
new file mode 100644
|
|
944 |
--- /dev/null
|
|
945 |
+++ Python-2.6.4/Modules/userattr.c
|
|
946 |
@@ -0,0 +1,308 @@
|
|
947 |
+/*
|
|
948 |
+ * CDDL HEADER START
|
|
949 |
+ *
|
|
950 |
+ * The contents of this file are subject to the terms of the
|
|
951 |
+ * Common Development and Distribution License (the "License").
|
|
952 |
+ * You may not use this file except in compliance with the License.
|
|
953 |
+ *
|
|
954 |
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
|
955 |
+ * or http://www.opensolaris.org/os/licensing.
|
|
956 |
+ * See the License for the specific language governing permissions
|
|
957 |
+ * and limitations under the License.
|
|
958 |
+ *
|
|
959 |
+ * When distributing Covered Code, include this CDDL HEADER in each
|
|
960 |
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
961 |
+ * If applicable, add the following below this CDDL HEADER, with the
|
|
962 |
+ * fields enclosed by brackets "[]" replaced with your own identifying
|
|
963 |
+ * information: Portions Copyright [yyyy] [name of copyright owner]
|
|
964 |
+ *
|
|
965 |
+ * CDDL HEADER END
|
|
966 |
+ */
|
|
967 |
+
|
|
968 |
+/*
|
|
969 |
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
|
|
970 |
+ */
|
|
971 |
+
|
|
972 |
+/*
|
|
973 |
+ * RBAC Bindings for Python - user_attr functions
|
|
974 |
+ */
|
|
975 |
+
|
|
976 |
+#include <stdio.h>
|
|
977 |
+#include <user_attr.h>
|
|
978 |
+#include "Python.h"
|
|
979 |
+#include "pyrbac.h"
|
|
980 |
+
|
|
981 |
+static PyObject*
|
|
982 |
+pyrbac_setuserattr(PyObject* self, PyObject* args) {
|
|
983 |
+ setuserattr();
|
|
984 |
+ return Py_None;
|
|
985 |
+}
|
|
986 |
+
|
|
987 |
+static PyObject*
|
|
988 |
+pyrbac_enduserattr(PyObject* self, PyObject* args) {
|
|
989 |
+ enduserattr();
|
|
990 |
+ return Py_None;
|
|
991 |
+}
|
|
992 |
+
|
|
993 |
+PyObject*
|
|
994 |
+pyrbac_getuseruidnamattr(PyObject* self, void* arg, int mode, char* filename) {
|
|
995 |
+
|
|
996 |
+ userattr_t *ret_userattr;
|
|
997 |
+
|
|
998 |
+ if (mode == PYRBAC_ATTR_MODE) {
|
|
999 |
+ if (filename != NULL) {
|
|
1000 |
+ FILE* file = fopen(filename, "r");
|
|
1001 |
+ if (file == NULL)
|
|
1002 |
+ return NULL;
|
|
1003 |
+ ret_userattr = fgetuserattr(file);
|
|
1004 |
+ if (fclose(file))
|
|
1005 |
+ return NULL;
|
|
1006 |
+ }
|
|
1007 |
+ else
|
|
1008 |
+ ret_userattr = getuserattr();
|
|
1009 |
+ }
|
|
1010 |
+ else if (mode == PYRBAC_NAM_MODE)
|
|
1011 |
+ ret_userattr = getusernam((char*) arg);
|
|
1012 |
+ else if (mode == PYRBAC_UID_MODE)
|
|
1013 |
+ ret_userattr = getuseruid(*((uid_t*) arg));
|
|
1014 |
+
|
|
1015 |
+ if (ret_userattr == NULL)
|
|
1016 |
+ return Py_None;
|
|
1017 |
+
|
|
1018 |
+ PyObject* entry = PyTuple_New(5);
|
|
1019 |
+ if (entry == NULL) {
|
|
1020 |
+ free_userattr(ret_userattr);
|
|
1021 |
+ return NULL;
|
|
1022 |
+ }
|
|
1023 |
+
|
|
1024 |
+ PyObject* kv_data = PyDict_New();
|
|
1025 |
+
|
|
1026 |
+ if(ret_userattr->attr != NULL) {
|
|
1027 |
+ int len;
|
|
1028 |
+ for(len = 0; len < ret_userattr->attr->length; len++) {
|
|
1029 |
+ kv_t current = ret_userattr->attr->data[len];
|
|
1030 |
+
|
|
1031 |
+ PyObject* set = PyList_New(NULL);
|
|
1032 |
+ char* saveptr;
|
|
1033 |
+ char* item = strtok_r(current.value, ",", &saveptr);
|
|
1034 |
+ PyList_Append(set, PyString_FromString(item));
|
|
1035 |
+
|
|
1036 |
+ while((item = strtok_r(NULL, ",", &saveptr)) != NULL) {
|
|
1037 |
+ if(PyList_Append(set, PyString_FromString(item)) != 0) {
|
|
1038 |
+ Py_XDECREF(set);
|
|
1039 |
+ Py_XDECREF(kv_data);
|
|
1040 |
+ free_userattr(ret_userattr);
|
|
1041 |
+ return NULL;
|
|
1042 |
+ }
|
|
1043 |
+ }
|
|
1044 |
+ if(PyDict_SetItemString(kv_data, current.key, set)) {
|
|
1045 |
+ free_userattr(ret_userattr);
|
|
1046 |
+ return NULL;
|
|
1047 |
+ }
|
|
1048 |
+ }
|
|
1049 |
+ }
|
|
1050 |
+ entry = Py_BuildValue("{s:s,s:s,s:s,s:s,s:O}",
|
|
1051 |
+ "name", ret_userattr->name,
|
|
1052 |
+ "qualifier", ret_userattr->qualifier,
|
|
1053 |
+ "res1", ret_userattr->res1,
|
|
1054 |
+ "res2", ret_userattr->res2,
|
|
1055 |
+ "attributes", kv_data);
|
|
1056 |
+
|
|
1057 |
+ free_userattr(ret_userattr);
|
|
1058 |
+
|
|
1059 |
+ return entry;
|
|
1060 |
+}
|
|
1061 |
+
|
|
1062 |
+
|
|
1063 |
+static PyObject*
|
|
1064 |
+pyrbac_getuserattr(PyObject* self, PyObject* args) {
|
|
1065 |
+ return(pyrbac_getuseruidnamattr(self, (void*) NULL, PYRBAC_ATTR_MODE, NULL));
|
|
1066 |
+}
|
|
1067 |
+
|
|
1068 |
+static PyObject*
|
|
1069 |
+pyrbac_fgetuserattr(PyObject* self, PyObject* args) {
|
|
1070 |
+ char* filename = NULL;
|
|
1071 |
+ if(!PyArg_ParseTuple(args, "s:fgetuserattr", &filename))
|
|
1072 |
+ return NULL;
|
|
1073 |
+ return(pyrbac_getuseruidnamattr(self, NULL, PYRBAC_ATTR_MODE, filename));
|
|
1074 |
+}
|
|
1075 |
+
|
|
1076 |
+static PyObject*
|
|
1077 |
+pyrbac_getusernam(PyObject* self, PyObject* args) {
|
|
1078 |
+ char* name = NULL;
|
|
1079 |
+ if(!PyArg_ParseTuple(args, "s:getusernam", &name))
|
|
1080 |
+ return NULL;
|
|
1081 |
+ return(pyrbac_getuseruidnamattr(self, (void*) name, PYRBAC_NAM_MODE, NULL));
|
|
1082 |
+}
|
|
1083 |
+
|
|
1084 |
+static PyObject*
|
|
1085 |
+pyrbac_getuseruid(PyObject* self, PyObject* args) {
|
|
1086 |
+ uid_t uid;
|
|
1087 |
+ if(!PyArg_ParseTuple(args, "i:getuseruid", &uid))
|
|
1088 |
+ return NULL;
|
|
1089 |
+ return(pyrbac_getuseruidnamattr(self, (void*) &uid, PYRBAC_UID_MODE, NULL));
|
|
1090 |
+}
|
|
1091 |
+
|
|
1092 |
+static PyObject*
|
|
1093 |
+pyrbac_userattr_next(PyObject* self, PyObject* args) {
|
|
1094 |
+ PyObject* retval = pyrbac_getuserattr(self, args);
|
|
1095 |
+ if( retval == Py_None ) {
|
|
1096 |
+ setuserattr();
|
|
1097 |
+ return NULL;
|
|
1098 |
+ }
|
|
1099 |
+ return retval;
|
|
1100 |
+}
|
|
1101 |
+static PyObject*
|
|
1102 |
+pyrbac_userattr__iter__(PyObject* self, PyObject* args) {
|
|
1103 |
+ return self;
|
|
1104 |
+}
|
|
1105 |
+
|
|
1106 |
+typedef struct {
|
|
1107 |
+ PyObject_HEAD
|
|
1108 |
+} Userattr;
|
|
1109 |
+
|
|
1110 |
+static void
|
|
1111 |
+Userattr_dealloc(Userattr* self) {
|
|
1112 |
+ enduserattr();
|
|
1113 |
+ self->ob_type->tp_free((PyObject*) self);
|
|
1114 |
+}
|
|
1115 |
+
|
|
1116 |
+static PyObject*
|
|
1117 |
+Userattr_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
|
|
1118 |
+ Userattr *self;
|
|
1119 |
+ self = (Userattr*)type->tp_alloc(type, 0);
|
|
1120 |
+
|
|
1121 |
+ return ((PyObject *) self);
|
|
1122 |
+}
|
|
1123 |
+
|
|
1124 |
+static int
|
|
1125 |
+Userattr_init(Userattr* self, PyObject *args, PyObject *kwargs) {
|
|
1126 |
+ setuserattr();
|
|
1127 |
+ return 0;
|
|
1128 |
+}
|
|
1129 |
+
|
|