Skeleton for SAMR module.
[samba.git] / source3 / python / py_samr.c
1 /* 
2    Python wrappers for DCERPC/SMB client routines.
3
4    Copyright (C) Tim Potter, 2002
5    
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 2 of the License, or
9    (at your option) any later version.
10    
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.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "includes.h"
22 #include "Python.h"
23
24 #include "python/py_samr.h"
25
26 PyObject *new_samr_connect_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx,
27                                       POLICY_HND *pol)
28 {
29         samr_connect_hnd_object *o;
30
31         o = PyObject_New(samr_connect_hnd_object, &samr_connect_hnd_type);
32
33         o->cli = cli;
34         o->mem_ctx = mem_ctx;
35         memcpy(&o->pol, pol, sizeof(POLICY_HND));
36
37         return (PyObject*)o;
38 }
39
40 /* 
41  * Exceptions raised by this module 
42  */
43
44 PyObject *samr_error;           /* This indicates a non-RPC related error
45                                    such as name lookup failure */
46
47 PyObject *samr_ntstatus;        /* This exception is raised when a RPC call
48                                    returns a status code other than
49                                    NT_STATUS_OK */
50
51 static void py_samr_connect_hnd_dealloc(PyObject* self)
52 {
53         PyObject_Del(self);
54 }
55
56 #if 0
57
58 static PyObject *py_samr_connect_hnd_getattr(PyObject *self, char *attrname)
59 {
60         return Py_FindMethod(samr_connect_methods, self, attrname);
61 }
62
63 #endif
64
65 PyTypeObject samr_connect_hnd_type = {
66         PyObject_HEAD_INIT(NULL)
67         0,
68         "SAMR Connect Handle",
69         sizeof(samr_connect_hnd_object),
70         0,
71         py_samr_connect_hnd_dealloc, /*tp_dealloc*/
72         0,          /*tp_print*/
73 //      py_samr_connect_hnd_getattr,          /*tp_getattr*/
74         0,          /*tp_setattr*/
75         0,          /*tp_compare*/
76         0,          /*tp_repr*/
77         0,          /*tp_as_number*/
78         0,          /*tp_as_sequence*/
79         0,          /*tp_as_mapping*/
80         0,          /*tp_hash */
81 };
82
83 PyTypeObject samr_domain_hnd_type = {
84         PyObject_HEAD_INIT(NULL)
85         0,
86         "SAMR Domain Handle",
87         sizeof(samr_connect_hnd_object),
88         0,
89         py_samr_connect_hnd_dealloc, /*tp_dealloc*/
90         0,          /*tp_print*/
91 //      py_samr_connect_hnd_getattr,          /*tp_getattr*/
92         0,          /*tp_setattr*/
93         0,          /*tp_compare*/
94         0,          /*tp_repr*/
95         0,          /*tp_as_number*/
96         0,          /*tp_as_sequence*/
97         0,          /*tp_as_mapping*/
98         0,          /*tp_hash */
99 };
100
101 PyTypeObject samr_user_hnd_type = {
102         PyObject_HEAD_INIT(NULL)
103         0,
104         "SAMR User Handle",
105         sizeof(samr_connect_hnd_object),
106         0,
107         py_samr_connect_hnd_dealloc, /*tp_dealloc*/
108         0,          /*tp_print*/
109 //      py_samr_connect_hnd_getattr,          /*tp_getattr*/
110         0,          /*tp_setattr*/
111         0,          /*tp_compare*/
112         0,          /*tp_repr*/
113         0,          /*tp_as_number*/
114         0,          /*tp_as_sequence*/
115         0,          /*tp_as_mapping*/
116         0,          /*tp_hash */
117 };
118
119 PyTypeObject samr_group_hnd_type = {
120         PyObject_HEAD_INIT(NULL)
121         0,
122         "SAMR Group Handle",
123         sizeof(samr_connect_hnd_object),
124         0,
125         py_samr_connect_hnd_dealloc, /*tp_dealloc*/
126         0,          /*tp_print*/
127 //      py_samr_connect_hnd_getattr,          /*tp_getattr*/
128         0,          /*tp_setattr*/
129         0,          /*tp_compare*/
130         0,          /*tp_repr*/
131         0,          /*tp_as_number*/
132         0,          /*tp_as_sequence*/
133         0,          /*tp_as_mapping*/
134         0,          /*tp_hash */
135 };
136
137 PyTypeObject samr_alias_hnd_type = {
138         PyObject_HEAD_INIT(NULL)
139         0,
140         "SAMR Alias Handle",
141         sizeof(samr_connect_hnd_object),
142         0,
143         py_samr_connect_hnd_dealloc, /*tp_dealloc*/
144         0,          /*tp_print*/
145 //      py_samr_connect_hnd_getattr,          /*tp_getattr*/
146         0,          /*tp_setattr*/
147         0,          /*tp_compare*/
148         0,          /*tp_repr*/
149         0,          /*tp_as_number*/
150         0,          /*tp_as_sequence*/
151         0,          /*tp_as_mapping*/
152         0,          /*tp_hash */
153 };
154
155 static PyMethodDef samr_methods[] = {
156
157         /* Open/close samr connect handles */
158         
159 #if 0
160         { "connect", lsa_open_policy, METH_VARARGS | METH_KEYWORDS, 
161           "Open a connect handle" },
162         
163         { "close", lsa_close, METH_VARARGS, "Close a policy handle" },
164 #endif
165
166         { NULL }
167 };
168
169 /*
170  * Module initialisation 
171 */
172
173 void initsamr(void)
174 {
175         PyObject *module, *dict;
176
177         /* Initialise module */
178
179         module = Py_InitModule("samr", samr_methods);
180         dict = PyModule_GetDict(module);
181
182         samr_error = PyErr_NewException("samr.error", NULL, NULL);
183         PyDict_SetItemString(dict, "error", samr_error);
184
185         samr_ntstatus = PyErr_NewException("samr.ntstatus", NULL, NULL);
186         PyDict_SetItemString(dict, "ntstatus", samr_ntstatus);
187
188         /* Initialise policy handle object */
189
190         samr_connect_hnd_type.ob_type = &PyType_Type;
191         samr_domain_hnd_type.ob_type = &PyType_Type;
192         samr_user_hnd_type.ob_type = &PyType_Type;
193         samr_group_hnd_type.ob_type = &PyType_Type;
194         samr_alias_hnd_type.ob_type = &PyType_Type;
195
196         /* Initialise constants */
197
198 //      const_init(dict);
199
200         /* Do samba initialisation */
201
202         py_samba_init();
203
204         setup_logging("samr", True);
205         DEBUGLEVEL = 10;
206 }