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/>.
21 #include "librpc/gen_ndr/misc.h"
23 static int py_GUID_cmp(PyObject
*py_self
, PyObject
*py_other
)
26 struct GUID
*self
= pytalloc_get_ptr(py_self
), *other
;
27 other
= pytalloc_get_ptr(py_other
);
31 ret
= GUID_compare(self
, other
);
41 static PyObject
*py_GUID_str(PyObject
*py_self
)
43 struct GUID
*self
= pytalloc_get_ptr(py_self
);
44 char *str
= GUID_string(NULL
, self
);
45 PyObject
*ret
= PyString_FromString(str
);
50 static PyObject
*py_GUID_repr(PyObject
*py_self
)
52 struct GUID
*self
= pytalloc_get_ptr(py_self
);
53 char *str
= GUID_string(NULL
, self
);
54 PyObject
*ret
= PyString_FromFormat("GUID('%s')", str
);
59 static int py_GUID_init(PyObject
*self
, PyObject
*args
, PyObject
*kwargs
)
63 struct GUID
*guid
= pytalloc_get_ptr(self
);
64 const char *kwnames
[] = { "str", NULL
};
66 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "|O", discard_const_p(char *, kwnames
), &str
))
72 if (!PyString_Check(str
)) {
73 PyErr_SetString(PyExc_TypeError
, "Expected a string argument to GUID()");
76 guid_val
.data
= (uint8_t *)PyString_AsString(str
);
77 guid_val
.length
= PyString_Size(str
);
78 status
= GUID_from_data_blob(&guid_val
, guid
);
79 if (!NT_STATUS_IS_OK(status
)) {
80 PyErr_SetNTSTATUS(status
);
88 static void py_GUID_patch(PyTypeObject
*type
)
90 type
->tp_init
= py_GUID_init
;
91 type
->tp_str
= py_GUID_str
;
92 type
->tp_repr
= py_GUID_repr
;
93 type
->tp_compare
= py_GUID_cmp
;
96 #define PY_GUID_PATCH py_GUID_patch
98 static int py_policy_handle_init(PyObject
*self
, PyObject
*args
, PyObject
*kwargs
)
102 struct policy_handle
*handle
= pytalloc_get_ptr(self
);
103 const char *kwnames
[] = { "uuid", "type", NULL
};
105 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "|si", discard_const_p(char *, kwnames
), &str
, &handle
->handle_type
))
109 status
= GUID_from_string(str
, &handle
->uuid
);
110 if (!NT_STATUS_IS_OK(status
)) {
111 PyErr_SetNTSTATUS(status
);
119 static PyObject
*py_policy_handle_repr(PyObject
*py_self
)
121 struct policy_handle
*self
= pytalloc_get_ptr(py_self
);
122 char *uuid_str
= GUID_string(NULL
, &self
->uuid
);
123 PyObject
*ret
= PyString_FromFormat("policy_handle(%d, '%s')", self
->handle_type
, uuid_str
);
124 talloc_free(uuid_str
);
128 static PyObject
*py_policy_handle_str(PyObject
*py_self
)
130 struct policy_handle
*self
= pytalloc_get_ptr(py_self
);
131 char *uuid_str
= GUID_string(NULL
, &self
->uuid
);
132 PyObject
*ret
= PyString_FromFormat("%d, %s", self
->handle_type
, uuid_str
);
133 talloc_free(uuid_str
);
137 static void py_policy_handle_patch(PyTypeObject
*type
)
139 type
->tp_init
= py_policy_handle_init
;
140 type
->tp_repr
= py_policy_handle_repr
;
141 type
->tp_str
= py_policy_handle_str
;
144 #define PY_POLICY_HANDLE_PATCH py_policy_handle_patch