2 Unix SMB/CIFS implementation.
3 Samba utility functions
4 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "librpc/gen_ndr/misc.h"
22 #ifndef Py_RETURN_NONE
23 #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
26 static int py_GUID_cmp(PyObject
*py_self
, PyObject
*py_other
)
29 struct GUID
*self
= py_talloc_get_ptr(py_self
), *other
;
30 other
= py_talloc_get_ptr(py_other
);
34 ret
= GUID_compare(self
, other
);
44 static PyObject
*py_GUID_str(PyObject
*py_self
)
46 struct GUID
*self
= py_talloc_get_ptr(py_self
);
47 char *str
= GUID_string(NULL
, self
);
48 PyObject
*ret
= PyString_FromString(str
);
53 static PyObject
*py_GUID_repr(PyObject
*py_self
)
55 struct GUID
*self
= py_talloc_get_ptr(py_self
);
56 char *str
= GUID_string(NULL
, self
);
57 PyObject
*ret
= PyString_FromFormat("GUID('%s')", str
);
62 static int py_GUID_init(PyObject
*self
, PyObject
*args
, PyObject
*kwargs
)
66 struct GUID
*guid
= py_talloc_get_ptr(self
);
67 const char *kwnames
[] = { "str", NULL
};
69 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "|s", discard_const_p(char *, kwnames
), &str
))
73 status
= GUID_from_string(str
, guid
);
74 if (!NT_STATUS_IS_OK(status
)) {
75 PyErr_SetNTSTATUS(status
);
83 static void py_GUID_patch(PyTypeObject
*type
)
85 type
->tp_init
= py_GUID_init
;
86 type
->tp_str
= py_GUID_str
;
87 type
->tp_repr
= py_GUID_repr
;
88 type
->tp_compare
= py_GUID_cmp
;
91 #define PY_GUID_PATCH py_GUID_patch
93 static int py_policy_handle_init(PyObject
*self
, PyObject
*args
, PyObject
*kwargs
)
97 struct policy_handle
*handle
= py_talloc_get_ptr(self
);
98 const char *kwnames
[] = { "uuid", "type", NULL
};
100 if (!PyArg_ParseTupleAndKeywords(args
, kwargs
, "|si", discard_const_p(char *, kwnames
), &str
, &handle
->handle_type
))
104 status
= GUID_from_string(str
, &handle
->uuid
);
105 if (!NT_STATUS_IS_OK(status
)) {
106 PyErr_SetNTSTATUS(status
);
114 static PyObject
*py_policy_handle_repr(PyObject
*py_self
)
116 struct policy_handle
*self
= py_talloc_get_ptr(py_self
);
117 char *uuid_str
= GUID_string(NULL
, &self
->uuid
);
118 PyObject
*ret
= PyString_FromFormat("policy_handle(%d, '%s')", self
->handle_type
, uuid_str
);
119 talloc_free(uuid_str
);
123 static PyObject
*py_policy_handle_str(PyObject
*py_self
)
125 struct policy_handle
*self
= py_talloc_get_ptr(py_self
);
126 char *uuid_str
= GUID_string(NULL
, &self
->uuid
);
127 PyObject
*ret
= PyString_FromFormat("%d, %s", self
->handle_type
, uuid_str
);
128 talloc_free(uuid_str
);
132 static void py_policy_handle_patch(PyTypeObject
*type
)
134 type
->tp_init
= py_policy_handle_init
;
135 type
->tp_repr
= py_policy_handle_repr
;
136 type
->tp_str
= py_policy_handle_str
;
139 #define PY_POLICY_HANDLE_PATCH py_policy_handle_patch