Changeset 988 for vendor/current/source4/auth/pyauth.c
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source4/auth/pyauth.c
r740 r988 31 31 #include <tevent.h> 32 32 #include "librpc/rpc/pyrpc_util.h" 33 #include "lib/events/events.h" 34 35 void initauth(void); 33 36 34 37 staticforward PyTypeObject PyAuthContext; 35 38 36 /* There's no Py_ssize_t in 2.4, apparently */ 37 #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 5 38 typedef int Py_ssize_t; 39 typedef inquiry lenfunc; 40 typedef intargfunc ssizeargfunc; 41 #endif 42 43 #ifndef Py_RETURN_NONE 44 #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None 45 #endif 46 47 static PyObject *py_auth_session_get_security_token(PyObject *self, void *closure) 48 { 49 struct auth_session_info *session = py_talloc_get_type(self, struct auth_session_info); 50 PyObject *py_security_token; 51 py_security_token = py_return_ndr_struct("samba.dcerpc.security", "token", 52 session->security_token, session->security_token); 53 return py_security_token; 54 } 55 56 static int py_auth_session_set_security_token(PyObject *self, PyObject *value, void *closure) 57 { 58 struct auth_session_info *session = py_talloc_get_type(self, struct auth_session_info); 59 session->security_token = talloc_reference(session, py_talloc_get_ptr(value)); 60 return 0; 61 } 62 63 static PyObject *py_auth_session_get_session_key(PyObject *self, void *closure) 64 { 65 struct auth_session_info *session = py_talloc_get_type(self, struct auth_session_info); 66 return PyString_FromStringAndSize((char *)session->session_key.data, session->session_key.length); 67 } 68 69 static int py_auth_session_set_session_key(PyObject *self, PyObject *value, void *closure) 70 { 71 DATA_BLOB val; 72 struct auth_session_info *session = py_talloc_get_type(self, struct auth_session_info); 73 val.data = (uint8_t *)PyString_AsString(value); 74 val.length = PyString_Size(value); 75 76 session->session_key = data_blob_talloc(session, val.data, val.length); 77 return 0; 78 } 79 80 static PyObject *py_auth_session_get_credentials(PyObject *self, void *closure) 81 { 82 struct auth_session_info *session = py_talloc_get_type(self, struct auth_session_info); 83 PyObject *py_credentials; 84 /* This is evil, as the credentials are not IDL structures */ 85 py_credentials = py_return_ndr_struct("samba.credentials", "Credentials", session->credentials, session->credentials); 86 return py_credentials; 87 } 88 89 static int py_auth_session_set_credentials(PyObject *self, PyObject *value, void *closure) 90 { 91 struct auth_session_info *session = py_talloc_get_type(self, struct auth_session_info); 92 session->credentials = talloc_reference(session, PyCredentials_AsCliCredentials(value)); 93 return 0; 94 } 95 96 static PyGetSetDef py_auth_session_getset[] = { 97 { discard_const_p(char, "security_token"), (getter)py_auth_session_get_security_token, (setter)py_auth_session_set_security_token, NULL }, 98 { discard_const_p(char, "session_key"), (getter)py_auth_session_get_session_key, (setter)py_auth_session_set_session_key, NULL }, 99 { discard_const_p(char, "credentials"), (getter)py_auth_session_get_credentials, (setter)py_auth_session_set_credentials, NULL }, 100 { NULL } 101 }; 102 103 static PyTypeObject PyAuthSession = { 104 .tp_name = "AuthSession", 105 .tp_basicsize = sizeof(py_talloc_Object), 106 .tp_flags = Py_TPFLAGS_DEFAULT, 107 .tp_getset = py_auth_session_getset, 108 }; 109 110 PyObject *PyAuthSession_FromSession(struct auth_session_info *session) 111 { 112 return py_talloc_reference(&PyAuthSession, session); 39 static PyObject *PyAuthSession_FromSession(struct auth_session_info *session) 40 { 41 return py_return_ndr_struct("samba.dcerpc.auth", "session_info", session, session); 113 42 } 114 43 … … 208 137 } 209 138 210 ldb_ctx = PyLdb_AsLdbContext(py_ldb);139 ldb_ctx = pyldb_Ldb_AsLdbContext(py_ldb); 211 140 212 141 if (py_dn == Py_None) { 213 142 user_dn = NULL; 214 143 } else { 215 if (! PyObject_AsDn(ldb_ctx, py_dn, ldb_ctx, &user_dn)) {144 if (!pyldb_Object_AsDn(ldb_ctx, py_dn, ldb_ctx, &user_dn)) { 216 145 talloc_free(mem_ctx); 217 146 return NULL; … … 267 196 } 268 197 269 static PyObject *PyAuthContext_FromContext(struct auth _context *auth_context)270 { 271 return py _talloc_reference(&PyAuthContext, auth_context);198 static PyObject *PyAuthContext_FromContext(struct auth4_context *auth_context) 199 { 200 return pytalloc_reference(&PyAuthContext, auth_context); 272 201 } 273 202 … … 276 205 PyObject *py_lp_ctx = Py_None; 277 206 PyObject *py_ldb = Py_None; 278 PyObject *py_ messaging_ctx = Py_None;207 PyObject *py_imessaging_ctx = Py_None; 279 208 PyObject *py_auth_context = Py_None; 280 209 PyObject *py_methods = Py_None; 281 210 TALLOC_CTX *mem_ctx; 282 struct auth _context *auth_context;283 struct messaging_context *messaging_context = NULL;211 struct auth4_context *auth_context; 212 struct imessaging_context *imessaging_context = NULL; 284 213 struct loadparm_context *lp_ctx; 285 214 struct tevent_context *ev; 286 struct ldb_context *ldb ;215 struct ldb_context *ldb = NULL; 287 216 NTSTATUS nt_status; 288 217 const char **methods; … … 292 221 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|OOOO", 293 222 discard_const_p(char *, kwnames), 294 &py_lp_ctx, &py_ messaging_ctx, &py_ldb, &py_methods))223 &py_lp_ctx, &py_imessaging_ctx, &py_ldb, &py_methods)) 295 224 return NULL; 296 225 … … 302 231 303 232 if (py_ldb != Py_None) { 304 ldb = PyLdb_AsLdbContext(py_ldb);233 ldb = pyldb_Ldb_AsLdbContext(py_ldb); 305 234 } 306 235 307 236 lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx); 308 309 ev = tevent_context_init(mem_ctx); 237 if (lp_ctx == NULL) { 238 PyErr_NoMemory(); 239 return NULL; 240 } 241 242 ev = s4_event_context_init(mem_ctx); 310 243 if (ev == NULL) { 311 244 PyErr_NoMemory(); … … 313 246 } 314 247 315 if (py_ messaging_ctx != Py_None) {316 messaging_context = py_talloc_get_type(py_messaging_ctx, structmessaging_context);248 if (py_imessaging_ctx != Py_None) { 249 imessaging_context = pytalloc_get_type(py_imessaging_ctx, struct imessaging_context); 317 250 } 318 251 319 252 if (py_methods == Py_None && py_ldb == Py_None) { 320 nt_status = auth_context_create(mem_ctx, ev, messaging_context, lp_ctx, &auth_context);253 nt_status = auth_context_create(mem_ctx, ev, imessaging_context, lp_ctx, &auth_context); 321 254 } else { 322 255 if (py_methods != Py_None) { … … 330 263 } 331 264 nt_status = auth_context_create_methods(mem_ctx, methods, ev, 332 messaging_context, lp_ctx,265 imessaging_context, lp_ctx, 333 266 ldb, &auth_context); 334 267 } … … 360 293 static PyTypeObject PyAuthContext = { 361 294 .tp_name = "AuthContext", 362 .tp_basicsize = sizeof(py_talloc_Object),363 295 .tp_flags = Py_TPFLAGS_DEFAULT, 364 296 .tp_new = py_auth_context_new, 365 .tp_basicsize = sizeof(py_talloc_Object),366 297 }; 367 298 … … 377 308 PyObject *m; 378 309 379 PyAuthSession.tp_base = PyTalloc_GetObjectType(); 380 if (PyAuthSession.tp_base == NULL) 381 return; 382 383 if (PyType_Ready(&PyAuthSession) < 0) 384 return; 385 386 PyAuthContext.tp_base = PyTalloc_GetObjectType(); 387 if (PyAuthContext.tp_base == NULL) 388 return; 389 390 if (PyType_Ready(&PyAuthContext) < 0) 310 if (pytalloc_BaseObject_PyType_Ready(&PyAuthContext) < 0) 391 311 return; 392 312 … … 396 316 return; 397 317 398 Py_INCREF(&PyAuthSession);399 PyModule_AddObject(m, "AuthSession", (PyObject *)&PyAuthSession);400 318 Py_INCREF(&PyAuthContext); 401 319 PyModule_AddObject(m, "AuthContext", (PyObject *)&PyAuthContext);
Note:
See TracChangeset
for help on using the changeset viewer.