Thread: [pywin32-checkins] pywin32/win32/src win32security.i,1.34,1.35
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Roger U. <ru...@us...> - 2006-12-02 15:24:14
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19101/win32/src Modified Files: win32security.i Log Message: Add DuplicateTokenEx, and some autoduck fixes Index: win32security.i =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32security.i,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** win32security.i 28 Sep 2006 02:27:27 -0000 1.34 --- win32security.i 2 Dec 2006 15:24:11 -0000 1.35 *************** *** 684,691 **** // Patch up any kwarg functions - SWIG doesn't like them. for (PyMethodDef *pmd = win32securityMethods;pmd->ml_name;pmd++) ! if (strcmp(pmd->ml_name, "DsGetDcName")==0) { pmd->ml_flags = METH_VARARGS | METH_KEYWORDS; ! break; // only 1 name at the moment. ! } %} --- 684,691 ---- // Patch up any kwarg functions - SWIG doesn't like them. for (PyMethodDef *pmd = win32securityMethods;pmd->ml_name;pmd++) ! if ((strcmp(pmd->ml_name, "DsGetDcName")==0) || ! (strcmp(pmd->ml_name, "DuplicateTokenEx")==0)){ pmd->ml_flags = METH_VARARGS | METH_KEYWORDS; ! } %} *************** *** 1684,1693 **** %{ ! // @pyswig <o PyHandle>|SetThreadToken|Assigns an impersonation token to a thread. The function // can also cause a thread to stop using an impersonation token. static PyObject *PySetThreadToken(PyObject *self, PyObject *args) { PyObject *obThread, *obToken; ! if (!PyArg_ParseTuple(args, "OO", &obThread, &obToken)) return NULL; HANDLE *phThread; --- 1684,1695 ---- %{ ! // @pyswig |SetThreadToken|Assigns an impersonation token to a thread. The function // can also cause a thread to stop using an impersonation token. static PyObject *PySetThreadToken(PyObject *self, PyObject *args) { PyObject *obThread, *obToken; ! if (!PyArg_ParseTuple(args, "OO", ! &obThread, // @pyparm <o PyHANDLE>|Thread||Handle to a thread. Use None to indicate calling thread. ! &obToken)) // @pyparm <o PyHANDLE>|Token||Handle to an impersonation token. Use None to end impersonation. return NULL; HANDLE *phThread; *************** *** 2822,2826 **** ); ! // @pyswig |DuplicateToken|Creates a copy of an access token with specified impersonation level // @pyparm <o PyHANDLE>|ExistingTokenHandle||Handle to an access token (see <om win32security.LogonUser>,<om win32security.OpenProcessToken>) // @pyparm int|ImpersonationLevel||A value from SECURITY_IMPERSONATION_LEVEL enum --- 2824,2828 ---- ); ! // @pyswig <o PyHANDLE>|DuplicateToken|Creates a copy of an access token with specified impersonation level // @pyparm <o PyHANDLE>|ExistingTokenHandle||Handle to an access token (see <om win32security.LogonUser>,<om win32security.OpenProcessToken>) // @pyparm int|ImpersonationLevel||A value from SECURITY_IMPERSONATION_LEVEL enum *************** *** 2831,2834 **** --- 2833,2868 ---- ); + // @pyswig <o PyHANDLE>|DuplicateTokenEx|Extended version of DuplicateToken. + // @comm Accepts keyword arguments + %native(DuplicateTokenEx) pfnPyDuplicateTokenEx; + %{ + static PyObject *PyDuplicateTokenEx(PyObject *self, PyObject *args, PyObject *kwargs) + { + static char *keywords[]={"ExistingToken","ImpersonationLevel","DesiredAccess","TokenType","TokenAttributes", NULL}; + HANDLE htoken, hnewtoken; + PSECURITY_ATTRIBUTES psa; + SECURITY_IMPERSONATION_LEVEL lvl; + DWORD access; + TOKEN_TYPE tokentype; + PyObject *obtoken, *obsa=Py_None; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Okkk|O:DuplicateTokenEx", keywords, + &obtoken, // @pyparm <o PyHANDLE>|ExistingToken||Logon token opened with TOKEN_DUPLICATE access + &lvl, // @pyparm int|ImpersonationLevel||One of win32security.Security* values + &access, // @pyparm int|DesiredAccess||Type of access required for the handle, combination of win32security.TOKEN_* flags + &tokentype, // @pyparm int|TokenType||Type of token to be created, TokenPrimary or TokenImpersonation + &obsa)) // @pyparm <o PySECURITY_ATTRIBUTES>|TokenAttributes|None|Specifies security and inheritance for the new handle. None results in default DACL and no inheritance, + return NULL; + if (!PyWinObject_AsHANDLE(obtoken, &htoken, FALSE)) + return NULL; + if (!PyWinObject_AsSECURITY_ATTRIBUTES(obsa, &psa, TRUE)) + return NULL; + if (!DuplicateTokenEx(htoken, access, psa, lvl, tokentype, &hnewtoken)) + return PyWin_SetAPIError("DuplicateTokenEx"); + return PyWinObject_FromHANDLE(hnewtoken); + } + PyCFunction pfnPyDuplicateTokenEx=(PyCFunction)PyDuplicateTokenEx; + %} + // @pyswig bool|CheckTokenMembership|Checks if a SID is enabled in a token %native(CheckTokenMembership) PyCheckTokenMembership; |