s3: Pass down smb_filename to smbacl4_fill_ace4
[Samba/gebeck_regimport.git] / source4 / librpc / ndr / py_misc.c
blob4e6d62ef4828a8181486dc1790a3d15aef483d62
1 /*
2 Unix SMB/CIFS implementation.
3 Samba utility functions
5 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <Python.h>
21 #include "librpc/gen_ndr/misc.h"
23 #ifndef Py_RETURN_NONE
24 #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
25 #endif
27 static int py_GUID_cmp(PyObject *py_self, PyObject *py_other)
29 int ret;
30 struct GUID *self = pytalloc_get_ptr(py_self), *other;
31 other = pytalloc_get_ptr(py_other);
32 if (other == NULL)
33 return -1;
35 ret = GUID_compare(self, other);
36 if (ret < 0) {
37 return -1;
38 } else if (ret > 0) {
39 return 1;
40 } else {
41 return 0;
45 static PyObject *py_GUID_str(PyObject *py_self)
47 struct GUID *self = pytalloc_get_ptr(py_self);
48 char *str = GUID_string(NULL, self);
49 PyObject *ret = PyString_FromString(str);
50 talloc_free(str);
51 return ret;
54 static PyObject *py_GUID_repr(PyObject *py_self)
56 struct GUID *self = pytalloc_get_ptr(py_self);
57 char *str = GUID_string(NULL, self);
58 PyObject *ret = PyString_FromFormat("GUID('%s')", str);
59 talloc_free(str);
60 return ret;
63 static int py_GUID_init(PyObject *self, PyObject *args, PyObject *kwargs)
65 PyObject *str = NULL;
66 NTSTATUS status;
67 struct GUID *guid = pytalloc_get_ptr(self);
68 const char *kwnames[] = { "str", NULL };
70 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O", discard_const_p(char *, kwnames), &str))
71 return -1;
73 if (str != NULL) {
74 DATA_BLOB guid_val;
76 if (!PyString_Check(str)) {
77 PyErr_SetString(PyExc_TypeError, "Expected a string argument to GUID()");
78 return -1;
80 guid_val.data = (uint8_t *)PyString_AsString(str);
81 guid_val.length = PyString_Size(str);
82 status = GUID_from_data_blob(&guid_val, guid);
83 if (!NT_STATUS_IS_OK(status)) {
84 PyErr_SetNTSTATUS(status);
85 return -1;
89 return 0;
92 static void py_GUID_patch(PyTypeObject *type)
94 type->tp_init = py_GUID_init;
95 type->tp_str = py_GUID_str;
96 type->tp_repr = py_GUID_repr;
97 type->tp_compare = py_GUID_cmp;
100 #define PY_GUID_PATCH py_GUID_patch
102 static int py_policy_handle_init(PyObject *self, PyObject *args, PyObject *kwargs)
104 char *str = NULL;
105 NTSTATUS status;
106 struct policy_handle *handle = pytalloc_get_ptr(self);
107 const char *kwnames[] = { "uuid", "type", NULL };
109 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|si", discard_const_p(char *, kwnames), &str, &handle->handle_type))
110 return -1;
112 if (str != NULL) {
113 status = GUID_from_string(str, &handle->uuid);
114 if (!NT_STATUS_IS_OK(status)) {
115 PyErr_SetNTSTATUS(status);
116 return -1;
120 return 0;
123 static PyObject *py_policy_handle_repr(PyObject *py_self)
125 struct policy_handle *self = pytalloc_get_ptr(py_self);
126 char *uuid_str = GUID_string(NULL, &self->uuid);
127 PyObject *ret = PyString_FromFormat("policy_handle(%d, '%s')", self->handle_type, uuid_str);
128 talloc_free(uuid_str);
129 return ret;
132 static PyObject *py_policy_handle_str(PyObject *py_self)
134 struct policy_handle *self = pytalloc_get_ptr(py_self);
135 char *uuid_str = GUID_string(NULL, &self->uuid);
136 PyObject *ret = PyString_FromFormat("%d, %s", self->handle_type, uuid_str);
137 talloc_free(uuid_str);
138 return ret;
141 static void py_policy_handle_patch(PyTypeObject *type)
143 type->tp_init = py_policy_handle_init;
144 type->tp_repr = py_policy_handle_repr;
145 type->tp_str = py_policy_handle_str;
148 #define PY_POLICY_HANDLE_PATCH py_policy_handle_patch