@pymethod |pythoncom|CoInitializeSecurity|Registers security and sets the default security values.
| 293 | |
| 294 | // @pymethod |pythoncom|CoInitializeSecurity|Registers security and sets the default security values. |
| 295 | static PyObject *pythoncom_CoInitializeSecurity(PyObject *self, PyObject *args) |
| 296 | { |
| 297 | CHECK_PFN(CoInitializeSecurity); |
| 298 | DWORD cAuthSvc; |
| 299 | SOLE_AUTHENTICATION_SERVICE *pAS = NULL; |
| 300 | DWORD dwAuthnLevel; |
| 301 | DWORD dwImpLevel; |
| 302 | DWORD dwCapabilities; |
| 303 | PSECURITY_DESCRIPTOR pSD=NULL, pSD_absolute=NULL; |
| 304 | IID appid; |
| 305 | IAccessControl *pIAC = NULL; |
| 306 | PyObject *obSD, *obAuthSvc, *obReserved1, *obReserved2, *obAuthInfo; |
| 307 | if (!PyArg_ParseTuple(args, "OOOiiOiO:CoInitializeSecurity", |
| 308 | &obSD, // @pyparm <o PySECURITY_DESCRIPTOR>|sd||Security descriptor containing access permissions for process' objects, can be None. |
| 309 | // <nl>If Capabilities contains EOAC_APPID, sd should be an AppId (guid), or None to use server executable. |
| 310 | // <nl>If Capabilities contains EOAC_ACCESS_CONTROL, sd parameter should be an IAccessControl interface. |
| 311 | &obAuthSvc, // @pyparm object|authSvc||A value of None tells COM to choose which authentication services to use. An empty list means use no services. |
| 312 | &obReserved1,// @pyparm object|reserved1||Must be None |
| 313 | &dwAuthnLevel, // @pyparm int|authnLevel||One of pythoncom.RPC_C_AUTHN_LEVEL_* values. The default authentication level for proxies. On the server side, COM will fail calls that arrive at a lower level. All calls to AddRef�and Release are made at this level. |
| 314 | &dwImpLevel, // @pyparm int|impLevel||One of pythoncom.RPC_C_IMP_LEVEL_* values. The default impersonation level for proxies. This value is not checked on the server side. AddRef�and Release�calls are made with this impersonation level so even security aware apps should set this carefully. Setting IUnknown�security only affects calls to QueryInterface, not AddRef�or Release. |
| 315 | &obAuthInfo, // @pyparm object|authInfo||Must be None |
| 316 | &dwCapabilities, // @pyparm int|capabilities||Authentication capabilities, combination of pythoncom.EOAC_* flags. |
| 317 | &obReserved2)) // @pyparm object|reserved2||Must be None |
| 318 | return NULL; |
| 319 | if (obReserved1 != Py_None || obReserved2 != Py_None || obAuthInfo != Py_None) { |
| 320 | PyErr_SetString(PyExc_TypeError, "Not all of the 'None' arguments are None!"); |
| 321 | return NULL; |
| 322 | } |
| 323 | |
| 324 | if (obAuthSvc==Py_None) |
| 325 | cAuthSvc = (DWORD)-1; |
| 326 | else if (PySequence_Check(obAuthSvc)) { |
| 327 | cAuthSvc = 0; |
| 328 | } else { |
| 329 | PyErr_SetString(PyExc_TypeError, "obAuthSvc must be None or an empty sequence."); |
| 330 | return NULL; |
| 331 | } |
| 332 | |
| 333 | // Depending on capabilities flags, first arg can be one of: |
| 334 | // AppId (or NULL to lookup server executable in APPID registry key) |
| 335 | // IAccessControl interface (cannot be NULL) |
| 336 | // Absolute security descriptor (or NULL to use a default SD) |
| 337 | if (dwCapabilities & EOAC_APPID){ |
| 338 | if (obSD != Py_None){ |
| 339 | if (!PyWinObject_AsIID(obSD, &appid)) |
| 340 | return NULL; |
| 341 | pSD = (PSECURITY_DESCRIPTOR)&appid; |
| 342 | } |
| 343 | } |
| 344 | else if (dwCapabilities & EOAC_ACCESS_CONTROL){ |
| 345 | if (!PyCom_InterfaceFromPyObject(obSD, IID_IAccessControl, (void **)&pIAC, FALSE)) |
| 346 | return NULL; |
| 347 | pSD = (PSECURITY_DESCRIPTOR)pIAC; |
| 348 | } |
| 349 | else{ |
| 350 | if (!PyWinObject_AsSECURITY_DESCRIPTOR(obSD, &pSD, /*BOOL bNoneOK = */TRUE)) |
| 351 | return NULL; |
| 352 | // Security descriptor must be in absolute form |
nothing calls this directly
no test coverage detected