Thread: [pywin32-checkins] pywin32/win32/src win32apimodule.cpp,1.80,1.81
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Roger U. <ru...@us...> - 2008-02-07 00:05:30
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31644 Modified Files: win32apimodule.cpp Log Message: Add RegOpenCurrentUser, combine RegCreateKeyEx/RegCreateKeyTransacted Index: win32apimodule.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32apimodule.cpp,v retrieving revision 1.80 retrieving revision 1.81 diff -C2 -d -r1.80 -r1.81 *** win32apimodule.cpp 6 Feb 2008 18:42:51 -0000 1.80 --- win32apimodule.cpp 7 Feb 2008 00:05:34 -0000 1.81 *************** *** 79,83 **** typedef LONG (WINAPI *RegDeleteTreefunc)(HKEY,LPWSTR); static RegDeleteTreefunc pfnRegDeleteTree = NULL; ! /* error helper */ --- 79,84 ---- typedef LONG (WINAPI *RegDeleteTreefunc)(HKEY,LPWSTR); static RegDeleteTreefunc pfnRegDeleteTree = NULL; ! typedef LONG (WINAPI *RegOpenCurrentUserfunc)(REGSAM,PHKEY); ! static RegOpenCurrentUserfunc pfnRegOpenCurrentUser = NULL; /* error helper */ *************** *** 2923,2931 **** // @pyseeapi RegCreateKeyEx // @comm Implemented only as Unicode (RegCreateKeyExW). Accepts keyword arguments. static PyObject *PyRegCreateKeyEx(PyObject *self, PyObject *args, PyObject *kwargs) { ! static char *keywords[]={"Key","SubKey","samDesired","Class","Options","SecurityAttributes", NULL}; HKEY hKey; ! PyObject *obKey, *obsubKey, *obclass=Py_None, *obsa=Py_None, *ret=NULL; WCHAR *subKey=NULL, *class_name=NULL; PSECURITY_ATTRIBUTES psa; --- 2924,2934 ---- // @pyseeapi RegCreateKeyEx // @comm Implemented only as Unicode (RegCreateKeyExW). Accepts keyword arguments. + // @comm If a transaction handle is passed in, RegCreateKeyTransacted will be called (requires Vista or later) + // @pyseeapi RegCreateKeyTransacted static PyObject *PyRegCreateKeyEx(PyObject *self, PyObject *args, PyObject *kwargs) { ! static char *keywords[]={"Key","SubKey","samDesired","Class","Options","SecurityAttributes","Transaction", NULL}; HKEY hKey; ! PyObject *obKey, *obsubKey, *obclass=Py_None, *obsa=Py_None, *obtrans=Py_None, *ret=NULL; WCHAR *subKey=NULL, *class_name=NULL; PSECURITY_ATTRIBUTES psa; *************** *** 2933,3002 **** HKEY retKey; long rc; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOk|OkO:RegCreateKeyEx", keywords, - &obKey, // @pyparm <o PyHKEY>/int|Key||Registry key or one of win32con.HKEY_* values - &obsubKey, // @pyparm <o PyUnicode>|SubKey||Name of subkey to open or create. - &access, // @pyparm int|samDesired||Access allowed to handle, combination of win32con.KEY_* constants. Can also contain - // standard access rights such as DELETE, WRITE_OWNER, etc. - &obclass, // @pyparm <o PyUnicode>|Class|None|Name of registry key class - &options, // @pyparm int|Options|REG_OPTION_NON_VOLATILE|One of the winnt.REG_OPTION_* values - &obsa)) // @pyparm <o PySECURITY_ATTRIBUTES>|SecurityAttributes|None|Specifies security for key and handle inheritance - return NULL; - if (PyWinObject_AsHKEY(obKey, &hKey) - &&PyWinObject_AsWCHAR(obsubKey, &subKey, TRUE) - &&PyWinObject_AsWCHAR(obclass, &class_name, TRUE) - &&PyWinObject_AsSECURITY_ATTRIBUTES(obsa, &psa, TRUE)){ - rc=RegCreateKeyExW(hKey, subKey, reserved, class_name, options, - access, psa, &retKey, &disp); - if (rc!=ERROR_SUCCESS) - PyWin_SetAPIError("RegCreateKeyEx", rc); - else - ret=Py_BuildValue("Nk", PyWinObject_FromHKEY(retKey), disp); - } - - PyWinObject_FreeWCHAR(subKey); - PyWinObject_FreeWCHAR(class_name); - return ret; - } - - // @pymethod <o PyHKEY>, int|win32api|RegCreateKeyTransacted|Creates a registry key as part of a transaction - // @rdesc Returns a transacted handle and disposition flag (winnt.REG_CREATED_NEW_KEY or winnt.REG_OPENED_EXISTING_KEY) - // @pyseeapi RegCreateKeyTransacted - // @comm Accepts keyword args. - // @comm Requires Vista or later. - static PyObject *PyRegCreateKeyTransacted(PyObject *self, PyObject *args, PyObject *kwargs) - { - CHECK_PFN(RegCreateKeyTransacted); - HKEY hKey; - PyObject *obKey, *obsubKey, *obtrans, *obclass=Py_None, *obsa=Py_None, *ret=NULL; - WCHAR *subKey=NULL, *class_name=NULL; - PSECURITY_ATTRIBUTES psa; - REGSAM access; - DWORD disp, options=REG_OPTION_NON_VOLATILE, reserved=0; - PVOID extparam=NULL; // Documented as Reserved - HKEY retKey; HANDLE htrans; ! long rc; ! static char *keywords[]={"Key","SubKey","samDesired","Transaction","Class","Options","SecurityAttributes", NULL}; ! if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOkO|OkO:RegCreateKeyTransacted", keywords, &obKey, // @pyparm <o PyHKEY>/int|Key||Registry key or one of win32con.HKEY_* values &obsubKey, // @pyparm <o PyUnicode>|SubKey||Name of subkey to open or create. &access, // @pyparm int|samDesired||Access allowed to handle, combination of win32con.KEY_* constants. Can also contain // standard access rights such as DELETE, WRITE_OWNER, etc. - &obtrans, // @pyparm <o PyHANDLE>|Transaction||Handle to a transaction as returned by <om win32transaction.CreateTransaction> &obclass, // @pyparm <o PyUnicode>|Class|None|Name of registry key class &options, // @pyparm int|Options|REG_OPTION_NON_VOLATILE|One of the winnt.REG_OPTION_* values ! &obsa)) // @pyparm <o PySECURITY_ATTRIBUTES>|SecurityAttributes|None|Specifies security for key and handle inheritance return NULL; if (PyWinObject_AsHKEY(obKey, &hKey) ! &&PyWinObject_AsWCHAR(obsubKey, &subKey, FALSE) ! &&PyWinObject_AsHANDLE(obtrans, &htrans) &&PyWinObject_AsWCHAR(obclass, &class_name, TRUE) &&PyWinObject_AsSECURITY_ATTRIBUTES(obsa, &psa, TRUE)){ ! rc=(*pfnRegCreateKeyTransacted)(hKey, subKey, reserved, class_name, options, ! access, psa, &retKey, &disp, htrans, extparam); if (rc!=ERROR_SUCCESS) ! PyWin_SetAPIError("RegCreateKeyTransacted", rc); else ret=Py_BuildValue("Nk", PyWinObject_FromHKEY(retKey), disp); --- 2936,2969 ---- HKEY retKey; long rc; HANDLE htrans; ! PVOID extparam=NULL; // Documented as Reserved ! if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOk|OkOO:RegCreateKeyEx", keywords, &obKey, // @pyparm <o PyHKEY>/int|Key||Registry key or one of win32con.HKEY_* values &obsubKey, // @pyparm <o PyUnicode>|SubKey||Name of subkey to open or create. &access, // @pyparm int|samDesired||Access allowed to handle, combination of win32con.KEY_* constants. Can also contain // standard access rights such as DELETE, WRITE_OWNER, etc. &obclass, // @pyparm <o PyUnicode>|Class|None|Name of registry key class &options, // @pyparm int|Options|REG_OPTION_NON_VOLATILE|One of the winnt.REG_OPTION_* values ! &obsa, // @pyparm <o PySECURITY_ATTRIBUTES>|SecurityAttributes|None|Specifies security for key and handle inheritance ! &obtrans)) // @pyparm <o PyHANDLE>|Transaction|None|Handle to a transaction as returned by <om win32transaction.CreateTransaction> return NULL; + if (!PyWinObject_AsHANDLE(obtrans, &htrans)) + return NULL; + if (htrans!=NULL) + CHECK_PFN(RegCreateKeyTransacted); + if (PyWinObject_AsHKEY(obKey, &hKey) ! &&PyWinObject_AsWCHAR(obsubKey, &subKey, TRUE) &&PyWinObject_AsWCHAR(obclass, &class_name, TRUE) &&PyWinObject_AsSECURITY_ATTRIBUTES(obsa, &psa, TRUE)){ ! if (htrans!=NULL) ! rc=(*pfnRegCreateKeyTransacted)(hKey, subKey, reserved, class_name, options, ! access, psa, &retKey, &disp, htrans, extparam); ! else ! rc=RegCreateKeyExW(hKey, subKey, reserved, class_name, options, ! access, psa, &retKey, &disp); if (rc!=ERROR_SUCCESS) ! PyWin_SetAPIError("RegCreateKeyEx", rc); else ret=Py_BuildValue("Nk", PyWinObject_FromHKEY(retKey), disp); *************** *** 3636,3639 **** --- 3603,3625 ---- } + // @pymethod <o PyHKEY>|win32api|RegOpenCurrentUser|Opens HKEY_CURRENT_USER for impersonated user + // @pyseeapi RegOpenCurrentUser + static PyObject *PyRegOpenCurrentUser(PyObject *self, PyObject *args) + { + CHECK_PFN(RegOpenCurrentUser); + long rc; + HKEY retKey; + REGSAM sam = MAXIMUM_ALLOWED; + // @pyparm int|samDesired|MAXIMUM_ALLOWED|Desired access, combination of win32con.KEY_* + if (!PyArg_ParseTuple(args, "|k:RegOpenCurrentUser", &sam)) + return NULL; + PyW32_BEGIN_ALLOW_THREADS + rc=(*pfnRegOpenCurrentUser)(sam, &retKey); + PyW32_END_ALLOW_THREADS + if (rc!=ERROR_SUCCESS) + return ReturnAPIError("RegOpenCurrentUser", rc); + return PyWinObject_FromHKEY(retKey); + } + // @pymethod <o PyHKEY>|win32api|RegOpenKey|Opens the specified key. // @comm This funcion is implemented using <om win32api.RegOpenKeyEx>, by taking advantage *************** *** 6020,6024 **** {"RegCreateKey", PyRegCreateKey, 1}, // @pymeth RegCreateKey|Creates the specified key, or opens the key if it already exists. {"RegCreateKeyEx", (PyCFunction)PyRegCreateKeyEx, METH_KEYWORDS|METH_VARARGS}, // @pymeth RegCreateKeyEx|Extended version of RegCreateKey - {"RegCreateKeyTransacted",(PyCFunction)PyRegCreateKeyTransacted, METH_KEYWORDS|METH_VARARGS}, // @pymeth RegCreateKeyTransacted|Creates a registry key as part of a transaction {"RegDeleteKey", PyRegDeleteKey, 1}, // @pymeth RegDeleteKey|Deletes the specified key. {"RegDeleteKeyTransacted",(PyCFunction)PyRegDeleteKeyTransacted, METH_KEYWORDS|METH_VARARGS}, // @pymeth RegDeleteKeyTransacted|Deletes a registry key as part of a transaction --- 6006,6009 ---- *************** *** 6037,6040 **** --- 6022,6026 ---- {"RegGetKeySecurity", PyRegGetKeySecurity, 1}, // @pymeth RegGetKeySecurity|Retrieves the security on the specified registry key. {"RegLoadKey", PyRegLoadKey, 1}, // @pymeth RegLoadKey|Creates a subkey under HKEY_USER or HKEY_LOCAL_MACHINE and stores registration information from a specified file into that subkey. + {"RegOpenCurrentUser", PyRegOpenCurrentUser, 1}, // @pymeth RegOpenCurrentUser|Opens HKEY_CURRENT_USER for impersonated user {"RegOpenKey", PyRegOpenKey, 1}, // @pymeth RegOpenKey|Alias for <om win32api.RegOpenKeyEx> {"RegOpenKeyEx", PyRegOpenKey, 1}, // @pymeth RegOpenKeyEx|Opens the specified key. *************** *** 6214,6217 **** --- 6200,6204 ---- pfnRegCopyTree=(RegCopyTreefunc)GetProcAddress(hmodule, "RegCopyTreeW"); pfnRegDeleteTree=(RegDeleteTreefunc)GetProcAddress(hmodule, "RegDeleteTreeW"); + pfnRegOpenCurrentUser=(RegOpenCurrentUserfunc)GetProcAddress(hmodule, "RegOpenCurrentUser"); } |