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 #ifndef Py_RETURN_NONE
24 #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
27 static int py_GUID_cmp(PyObject
*py_self
, PyObject
*py_other
)
30 struct GUID
*self
= pytalloc_get_ptr(py_self
), *other
;
31 other
= pytalloc_get_ptr(py_other
);
35 ret
= GUID_compare(self
, other
);
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
);
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
);
63 static int py_GUID_init(PyObject
*self
, PyObject
*args
, PyObject
*kwargs
)
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
))
76 if (!PyString_Check(str
)) {
77 PyErr_SetString(PyExc_TypeError
, "Expected a string argument to GUID()");
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
);
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
)
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
))
113 status
= GUID_from_string(str
, &handle
->uuid
);
114 if (!NT_STATUS_IS_OK(status
)) {
115 PyErr_SetNTSTATUS(status
);
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
);
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
);
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