Changeset 745 for trunk/server/source4/auth/pyauth.c
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
source4/auth/pyauth.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/source4/auth/pyauth.c
r414 r745 2 2 Unix SMB/CIFS implementation. 3 3 Copyright (C) Jelmer Vernooij <[email protected]> 2007-2008 4 4 Copyright (C) Andrew Bartlett <[email protected]> 2011 5 5 6 This program is free software; you can redistribute it and/or modify 6 7 it under the terms of the GNU General Public License as published by … … 17 18 */ 18 19 20 19 21 #include "includes.h" 22 20 23 #include "param/param.h" 21 24 #include "pyauth.h" 25 22 26 #include "auth/system_session_proto.h" 27 23 28 #include "param/pyparam.h" 24 29 #include "libcli/security/security.h" 25 26 27 PyTypeObject PyAuthSession = { 30 #include "auth/credentials/pycredentials.h" 31 #include <tevent.h> 32 #include "librpc/rpc/pyrpc_util.h" 33 34 staticforward PyTypeObject PyAuthContext; 35 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 = { 28 104 .tp_name = "AuthSession", 29 105 .tp_basicsize = sizeof(py_talloc_Object), 30 .tp_dealloc = py_talloc_dealloc,31 106 .tp_flags = Py_TPFLAGS_DEFAULT, 32 .tp_ repr = py_talloc_default_repr,107 .tp_, 33 108 }; 34 109 … … 43 118 struct loadparm_context *lp_ctx = NULL; 44 119 struct auth_session_info *session; 120 45 121 if (!PyArg_ParseTuple(args, "|O", &py_lp_ctx)) 46 122 return NULL; 47 123 48 lp_ctx = lp_from_py_object(py_lp_ctx); 49 if (lp_ctx == NULL) 50 return NULL; 51 52 session = system_session(NULL, lp_ctx); 124 mem_ctx = talloc_new(NULL); 125 if (mem_ctx == NULL) { 126 PyErr_NoMemory(); 127 return NULL; 128 } 129 130 lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx); 131 if (lp_ctx == NULL) { 132 talloc_free(mem_ctx); 133 return NULL; 134 } 135 136 session = system_session(lp_ctx); 137 138 talloc_free(mem_ctx); 53 139 54 140 return PyAuthSession_FromSession(session); 55 141 } 56 142 57 58 static PyObject *py_system_session_anon(PyObject *module, PyObject *args)59 {60 PyObject *py_lp_ctx = Py_None;61 struct loadparm_context *lp_ctx;62 struct auth_session_info *session;63 if (!PyArg_ParseTuple(args, "|O", &py_lp_ctx))64 return NULL;65 66 lp_ctx = lp_from_py_object(py_lp_ctx);67 if (lp_ctx == NULL)68 return NULL;69 70 session = system_session_anon(NULL, lp_ctx);71 72 return PyAuthSession_FromSession(session);73 }74 143 75 144 static PyObject *py_admin_session(PyObject *module, PyObject *args) … … 80 149 struct auth_session_info *session; 81 150 struct dom_sid *domain_sid = NULL; 151 152 82 153 if (!PyArg_ParseTuple(args, "OO", &py_lp_ctx, &py_sid)) 83 154 return NULL; 84 155 85 lp_ctx = lp_from_py_object(py_lp_ctx); 86 if (lp_ctx == NULL) 87 return NULL; 88 89 domain_sid = dom_sid_parse_talloc(NULL, PyString_AsString(py_sid)); 156 mem_ctx = talloc_new(NULL); 157 if (mem_ctx == NULL) { 158 PyErr_NoMemory(); 159 return NULL; 160 } 161 162 lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx); 163 if (lp_ctx == NULL) { 164 talloc_free(mem_ctx); 165 return NULL; 166 } 167 168 domain_sid = dom_sid_parse_talloc(mem_ctx, PyString_AsString(py_sid)); 169 if (domain_sid == NULL) { 170 PyErr_Format(PyExc_RuntimeError, "Unable to parse sid %s", 171 PyString_AsString(py_sid)); 172 talloc_free(mem_ctx); 173 return NULL; 174 } 90 175 session = admin_session(NULL, lp_ctx, domain_sid); 176 91 177 92 178 return PyAuthSession_FromSession(session); 93 179 } 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 94 367 95 368 static PyMethodDef py_auth_methods[] = { 96 369 { "system_session", (PyCFunction)py_system_session, METH_VARARGS, NULL }, 97 { "system_session_anonymous", (PyCFunction)py_system_session_anon, METH_VARARGS, NULL },98 370 { "admin_session", (PyCFunction)py_admin_session, METH_VARARGS, NULL }, 371 99 372 { NULL }, 100 373 }; … … 104 377 PyObject *m; 105 378 379 380 381 382 106 383 if (PyType_Ready(&PyAuthSession) < 0) 107 384 return; 108 385 109 m = Py_InitModule3("auth", py_auth_methods, "Authentication and authorization support."); 386 PyAuthContext.tp_base = PyTalloc_GetObjectType(); 387 if (PyAuthContext.tp_base == NULL) 388 return; 389 390 if (PyType_Ready(&PyAuthContext) < 0) 391 return; 392 393 m = Py_InitModule3("auth", py_auth_methods, 394 "Authentication and authorization support."); 110 395 if (m == NULL) 111 396 return; … … 113 398 Py_INCREF(&PyAuthSession); 114 399 PyModule_AddObject(m, "AuthSession", (PyObject *)&PyAuthSession); 115 } 400 Py_INCREF(&PyAuthContext); 401 PyModule_AddObject(m, "AuthContext", (PyObject *)&PyAuthContext); 402 403 #define ADD_FLAG(val) PyModule_AddObject(m, #val, PyInt_FromLong(val)) 404 ADD_FLAG(AUTH_SESSION_INFO_DEFAULT_GROUPS); 405 ADD_FLAG(AUTH_SESSION_INFO_AUTHENTICATED); 406 ADD_FLAG(AUTH_SESSION_INFO_SIMPLE_PRIVILEGES); 407 408 }
Note:
See TracChangeset
for help on using the changeset viewer.
