[pywin32-checkins] pywin32/win32/src win32security.i,1.16,1.17
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
|
From: Roger U. <ru...@us...> - 2004-06-08 04:05:40
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25326/win32/src Modified Files: win32security.i Log Message: Return modified privileges from AdjustTokenPrivileges, some doc improvements Index: win32security.i =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32security.i,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** win32security.i 26 May 2004 02:58:33 -0000 1.16 --- win32security.i 8 Jun 2004 04:05:31 -0000 1.17 *************** *** 102,106 **** // @object PyTOKEN_PRIVILEGES|An object representing Win32 token privileges. ! // @comm This is a sequence (eg, list) of (id, attributes) %{ --- 102,109 ---- // @object PyTOKEN_PRIVILEGES|An object representing Win32 token privileges. ! // @comm This is a sequence (eg, list) of ((id, attributes),...) where id is a ! // privilege LUID as returned by <om win32security.LookupPrivilegeValue> and ! // attributes is a combination if SE_PRIVILEGE_ENABLED, SE_PRIVILEGE_ENABLED_BY_DEFAULT, ! // and SE_PRIVILEGE_USED_FOR_ACCESS %{ *************** *** 248,252 **** } ! void PyMAPIObject_FreeTOKEN_PRIVILEGES(TOKEN_PRIVILEGES *pPriv) { free(pPriv); --- 251,255 ---- } ! void PyWinObject_FreeTOKEN_PRIVILEGES(TOKEN_PRIVILEGES *pPriv) { free(pPriv); *************** *** 280,284 **** } %typemap(python,freearg) TOKEN_PRIVILEGES * { ! if ($source) PyMAPIObject_FreeTOKEN_PRIVILEGES($source); } --- 283,287 ---- } %typemap(python,freearg) TOKEN_PRIVILEGES * { ! if ($source) PyWinObject_FreeTOKEN_PRIVILEGES($source); } *************** *** 288,293 **** } ! %typemap(python,out) TOKEN_PRIVILEGES { ! $target = PyWinObject_FromTOKEN_PRIVILEGES($source); } --- 291,301 ---- } ! %typemap(python,out) TOKEN_PRIVILEGES *{ ! if ($source==NULL) ! $target=NULL; ! else{ ! $target = PyWinObject_FromTOKEN_PRIVILEGES($source); ! free($source); ! } } *************** *** 975,996 **** %} - %{ ! BOOL MyAdjustTokenPrivileges( HANDLE TokenHandle, BOOL DisableAllPrivileges, TOKEN_PRIVILEGES *NewState) { ! AdjustTokenPrivileges(TokenHandle, DisableAllPrivileges, NewState, 0, NULL, 0); // Note that AdjustTokenPrivileges may succeed, and yet // some privileges weren't actually adjusted. // You've got to check GetLastError() to be sure! DWORD rc = GetLastError(); ! return rc==0 || rc==ERROR_NOT_ALL_ASSIGNED; } %} ! // @pyswig |AdjustTokenPrivileges| ! %name(AdjustTokenPrivileges) BOOLAPI MyAdjustTokenPrivileges( HANDLE TokenHandle, // @pyparm int|handle||handle to token that contains privileges BOOL DisableAllPrivileges, // @pyparm int|bDisableAllPrivileges||Flag for disabling all privileges --- 983,1024 ---- %} %{ ! TOKEN_PRIVILEGES *MyAdjustTokenPrivileges( HANDLE TokenHandle, BOOL DisableAllPrivileges, TOKEN_PRIVILEGES *NewState) { ! DWORD origbufsize=sizeof(DWORD) + (3*sizeof(LUID_AND_ATTRIBUTES)); ! DWORD reqdbufsize=0; ! TOKEN_PRIVILEGES *PreviousState=(TOKEN_PRIVILEGES *)malloc(origbufsize); ! if (PreviousState==NULL){ ! PyErr_SetString(PyExc_MemoryError,"AdjustTokenPrivileges: unable to allocate return buffer"); ! return NULL; ! } ! ! if (!AdjustTokenPrivileges(TokenHandle, DisableAllPrivileges, NewState, origbufsize, PreviousState, &reqdbufsize)) ! if (reqdbufsize>origbufsize){ ! free(PreviousState); ! PreviousState=(TOKEN_PRIVILEGES *)malloc(reqdbufsize); ! if (PreviousState==NULL){ ! PyErr_SetString(PyExc_MemoryError,"AdjustTokenPrivileges: unable to allocate return buffer"); ! return NULL; ! } ! AdjustTokenPrivileges(TokenHandle, DisableAllPrivileges, NewState, reqdbufsize, PreviousState, &reqdbufsize); ! } // Note that AdjustTokenPrivileges may succeed, and yet // some privileges weren't actually adjusted. // You've got to check GetLastError() to be sure! DWORD rc = GetLastError(); ! if (rc==0 || rc==ERROR_NOT_ALL_ASSIGNED) ! return PreviousState; ! PyWin_SetAPIError("AdjustTokenPrivileges",rc); ! free(PreviousState); ! return NULL; } %} ! // @pyswig <o PyTOKEN_PRIVILEGES>|AdjustTokenPrivileges|Enables or disables privileges for an access token, returns modified privileges for later restoral ! %name(AdjustTokenPrivileges) TOKEN_PRIVILEGES *MyAdjustTokenPrivileges( HANDLE TokenHandle, // @pyparm int|handle||handle to token that contains privileges BOOL DisableAllPrivileges, // @pyparm int|bDisableAllPrivileges||Flag for disabling all privileges *************** *** 998,1003 **** ); - - // @pyswig <o PyTOKEN_GROUPS>|AdjustTokenGroups|Sets the groups associated to an access token,returns previous group info %native(AdjustTokenGroups) PyAdjustTokenGroups; --- 1026,1029 ---- *************** *** 1016,1026 **** &reset, // @pyparm int|ResetToDefault||Sets groups to default enabled/disabled states, &obtg)) // @pyparm PyTOKEN_GROUPS|NewState||Groups and attributes to be set for token if (!PyWinObject_AsHANDLE(obHandle, &th, FALSE)) return NULL; ! if (!PyWinObject_AsTOKEN_GROUPS(obtg, &newstate)) return NULL; DWORD bufsize = 0, origbufsize = 10; //pick a number out of a hat ! TOKEN_GROUPS *oldstate = (TOKEN_GROUPS *)malloc(origbufsize); if (oldstate==NULL) { PyErr_SetString(PyExc_MemoryError, "AdjustTokenGroups: unable to allocate memory"); --- 1042,1053 ---- &reset, // @pyparm int|ResetToDefault||Sets groups to default enabled/disabled states, &obtg)) // @pyparm PyTOKEN_GROUPS|NewState||Groups and attributes to be set for token + return NULL; if (!PyWinObject_AsHANDLE(obHandle, &th, FALSE)) return NULL; ! if (!PyWinObject_AsTOKEN_GROUPS(obtg, &newstate)) return NULL; DWORD bufsize = 0, origbufsize = 10; //pick a number out of a hat ! TOKEN_GROUPS *oldstate = (TOKEN_GROUPS *)malloc(origbufsize); if (oldstate==NULL) { PyErr_SetString(PyExc_MemoryError, "AdjustTokenGroups: unable to allocate memory"); *************** *** 1052,1057 **** %} - - // @pyswig object|GetTokenInformation|Retrieves a specified type of information about an access token. The calling process must have appropriate access rights to obtain the information. %native(GetTokenInformation) PyGetTokenInformation; --- 1079,1082 ---- *************** *** 1515,1519 **** if (!PyArg_ParseTuple(args, "Oi:LsaOpenPolicy", ! &obsystem_name, // @pyparm string/<o PyUnicode>|obsystem_name||System name, local system assumed if not specified &access_mask)) // @pyparm int|access_mask||Bitmask of requested access types return NULL; --- 1540,1544 ---- if (!PyArg_ParseTuple(args, "Oi:LsaOpenPolicy", ! &obsystem_name, // @pyparm string/<o PyUnicode>|system_name||System name, local system assumed if not specified &access_mask)) // @pyparm int|access_mask||Bitmask of requested access types return NULL; *************** *** 1539,1542 **** --- 1564,1568 ---- { PyObject *obHandle; + // @pyparm <o PyHANDLE>|PolicyHandle||An LSA policy handle as returned by <om win32security.LsaOpenPolicy> if (!PyArg_ParseTuple(args, "O:LsaClose", &obHandle)) return NULL; *************** *** 1560,1563 **** --- 1586,1591 ---- void* buf = NULL; POLICY_INFORMATION_CLASS info_class; + // @pyparm <o PyHANDLE>|PolicyHandle||An LSA policy handle as returned by <om win32security.LsaOpenPolicy> + // @pyparm int|InformationClass||POLICY_INFORMATION_CLASS value if (!PyArg_ParseTuple(args, "Oi:LsaQueryInformationPolicy", &obhandle, (long *)&info_class)) return NULL; *************** *** 1670,1673 **** --- 1698,1704 ---- void* buf = NULL; POLICY_INFORMATION_CLASS info_class; + // @pyparm <o PyHANDLE>|PolicyHandle||An LSA policy handle as returned by <om win32security.LsaOpenPolicy> + // @pyparm int|InformationClass||POLICY_INFORMATION_CLASS value + // @pyparm object|Information||Type is dependent on InformationClass if (!PyArg_ParseTuple(args, "OiO:PyLsaSetInformationPolicy", &obhandle, (long *)&info_class, &obinfo)) return NULL; *************** *** 1745,1748 **** --- 1776,1782 ---- HANDLE hpolicy; NTSTATUS err; + // @pyparm <o PyHANDLE>|PolicyHandle||An LSA policy handle as returned by <om win32security.LsaOpenPolicy> + // @pyparm <o PySID>|AccountSid||Account to which privs will be added + // @pyparm (str/unicode,...)|UserRights||List of privilege names (SE_*_NAME unicode constants) if (!PyArg_ParseTuple(args, "OOO:LsaAddAccountRights", &policy_handle, &obsid, &privs)) return NULL; *************** *** 1803,1806 **** --- 1837,1844 ---- HANDLE hpolicy; NTSTATUS err; + // @pyparm <o PyHANDLE>|PolicyHandle||An LSA policy handle as returned by <om win32security.LsaOpenPolicy> + // @pyparm <o PySID>|AccountSid||Account whose privileges will be removed + // @pyparm int|AllRights||Boolean value indicating if all privs should be removed from account + // @pyparm (str/unicode,...)|UserRights||List of privilege names to be removed (SE_*_NAME unicode constants) if (!PyArg_ParseTuple(args, "OOiO:LsaAddAccountRights", &policy_handle, &obsid, &AllRights, &privs)) return NULL; *************** *** 1860,1864 **** HANDLE hpolicy; NTSTATUS err; ! if (!PyArg_ParseTuple(args, "OO:LsaAddAccountRights", &policy_handle, &obsid)) return NULL; if (!PyWinObject_AsHANDLE(policy_handle, &hpolicy)) --- 1898,1904 ---- HANDLE hpolicy; NTSTATUS err; ! // @pyparm <o PyHANDLE>|PolicyHandle||An LSA policy handle as returned by <om win32security.LsaOpenPolicy> ! // @pyparm <o PySID>|AccountSid||Security identifier of account for which to list privs ! if (!PyArg_ParseTuple(args, "OO:LsaEnumerateAccountRights", &policy_handle, &obsid)) return NULL; if (!PyWinObject_AsHANDLE(policy_handle, &hpolicy)) *************** *** 1899,1902 **** --- 1939,1944 ---- void *buf_start; NTSTATUS err; + // @pyparm <o PyHANDLE>|PolicyHandle||An LSA policy handle as returned by <om win32security.LsaOpenPolicy> + // @pyparm str/unicode|UserRight||Name of privilege (SE_*_NAME unicode constant) if (!PyArg_ParseTuple(args, "OO:LsaEnumerateAccountsWithUserRight", &policy_handle, &obpriv)) return NULL; *************** *** 2050,2056 **** static PyObject *PyLsaStorePrivateData(PyObject *self, PyObject *args) { ! // @pyparm <o PyHANDLE>|handle||Policy handle // @pyparm string|KeyName||Registry key in which to store data ! // @pyparm int|PrivateData||Unicode string to be encrypted and stored PyObject *obpolicyhandle=NULL, *obkeyname=NULL, *obprivatedata=NULL; PyObject * ret=NULL; --- 2092,2098 ---- static PyObject *PyLsaStorePrivateData(PyObject *self, PyObject *args) { ! // @pyparm <o PyHANDLE>|PolicyHandle||An LSA policy handle as returned by <om win32security.LsaOpenPolicy> // @pyparm string|KeyName||Registry key in which to store data ! // @pyparm <o PyUNICODE>|PrivateData||Unicode string to be encrypted and stored PyObject *obpolicyhandle=NULL, *obkeyname=NULL, *obprivatedata=NULL; PyObject * ret=NULL; *************** *** 2095,2099 **** static PyObject *PyLsaRetrievePrivateData(PyObject *self, PyObject *args) { ! // @pyparm <o PyHANDLE>|handle||Policy handle // @pyparm string|KeyName||Registry key to read PyObject *obpolicyhandle=NULL, *obkeyname=NULL, *obprivatedata=NULL; --- 2137,2141 ---- static PyObject *PyLsaRetrievePrivateData(PyObject *self, PyObject *args) { ! // @pyparm <o PyHANDLE>|PolicyHandle||An LSA policy handle as returned by <om win32security.LsaOpenPolicy> // @pyparm string|KeyName||Registry key to read PyObject *obpolicyhandle=NULL, *obkeyname=NULL, *obprivatedata=NULL; *************** *** 2181,2184 **** --- 2223,2227 ---- %} + // @pyswig object|CryptEnumProviders|List cryptography providers %native(CryptEnumProviders) PyCryptEnumProviders; |