[pywin32-checkins] pywin32/win32/src win32file.i,1.75,1.76
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Roger U. <ru...@us...> - 2007-03-18 11:53:56
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15569/win32/src Modified Files: win32file.i Log Message: Add DuplicateEncryptionInfoFile, standardize function pointer loading Index: win32file.i =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32file.i,v retrieving revision 1.75 retrieving revision 1.76 diff -C2 -d -r1.75 -r1.76 *** win32file.i 15 Mar 2007 17:54:01 -0000 1.75 --- win32file.i 17 Mar 2007 03:41:53 -0000 1.76 *************** *** 2665,2678 **** static GetVolumePathNamesForVolumeNamefunc pfnGetVolumePathNamesForVolumeName = NULL; ! static BOOL (WINAPI *pfnEncryptFile)(WCHAR *)=NULL; ! static BOOL (WINAPI *pfnDecryptFile)(WCHAR *, DWORD)=NULL; ! static BOOL (WINAPI *pfnEncryptionDisable)(WCHAR *, BOOL)=NULL; ! static BOOL (WINAPI *pfnFileEncryptionStatus)(WCHAR *, LPDWORD)=NULL; ! static DWORD (WINAPI *pfnQueryUsersOnEncryptedFile)(WCHAR *, PENCRYPTION_CERTIFICATE_HASH_LIST *)=NULL; ! static BOOL (WINAPI *pfnFreeEncryptionCertificateHashList)(PENCRYPTION_CERTIFICATE_HASH_LIST)=NULL; ! static DWORD (WINAPI *pfnQueryRecoveryAgentsOnEncryptedFile)(WCHAR *, PENCRYPTION_CERTIFICATE_HASH_LIST *)=NULL; ! static DWORD (WINAPI *pfnRemoveUsersFromEncryptedFile)(WCHAR *, PENCRYPTION_CERTIFICATE_HASH_LIST)=NULL; ! static DWORD (WINAPI *pfnAddUsersToEncryptedFile)(WCHAR *, PENCRYPTION_CERTIFICATE_LIST)=NULL; ! typedef BOOL (WINAPI *CreateHardLinkfunc)(LPWSTR, LPWSTR, LPSECURITY_ATTRIBUTES); --- 2665,2688 ---- static GetVolumePathNamesForVolumeNamefunc pfnGetVolumePathNamesForVolumeName = NULL; ! typedef BOOL (WINAPI *EncryptFilefunc)(WCHAR *); ! static EncryptFilefunc pfnEncryptFile=NULL; ! typedef BOOL (WINAPI *DecryptFilefunc)(WCHAR *, DWORD); ! static DecryptFilefunc pfnDecryptFile=NULL; ! typedef BOOL (WINAPI *EncryptionDisablefunc)(WCHAR *, BOOL); ! static EncryptionDisablefunc pfnEncryptionDisable=NULL; ! typedef BOOL (WINAPI *FileEncryptionStatusfunc)(WCHAR *, LPDWORD); ! static FileEncryptionStatusfunc pfnFileEncryptionStatus=NULL; ! typedef DWORD (WINAPI *QueryUsersOnEncryptedFilefunc)(WCHAR *, PENCRYPTION_CERTIFICATE_HASH_LIST *); ! static QueryUsersOnEncryptedFilefunc pfnQueryUsersOnEncryptedFile=NULL; ! typedef BOOL (WINAPI *FreeEncryptionCertificateHashListfunc)(PENCRYPTION_CERTIFICATE_HASH_LIST); ! static FreeEncryptionCertificateHashListfunc pfnFreeEncryptionCertificateHashList=NULL; ! typedef DWORD (WINAPI *QueryRecoveryAgentsOnEncryptedFilefunc)(WCHAR *, PENCRYPTION_CERTIFICATE_HASH_LIST *); ! static QueryRecoveryAgentsOnEncryptedFilefunc pfnQueryRecoveryAgentsOnEncryptedFile=NULL; ! typedef DWORD (WINAPI *RemoveUsersFromEncryptedFilefunc)(WCHAR *, PENCRYPTION_CERTIFICATE_HASH_LIST); ! static RemoveUsersFromEncryptedFilefunc pfnRemoveUsersFromEncryptedFile=NULL; ! typedef DWORD (WINAPI *AddUsersToEncryptedFilefunc)(WCHAR *, PENCRYPTION_CERTIFICATE_LIST); ! static AddUsersToEncryptedFilefunc pfnAddUsersToEncryptedFile=NULL; ! typedef DWORD (WINAPI *DuplicateEncryptionInfoFilefunc)(LPWSTR,LPWSTR,DWORD,DWORD,LPSECURITY_ATTRIBUTES); ! static DuplicateEncryptionInfoFilefunc pfnDuplicateEncryptionInfoFile = NULL; typedef BOOL (WINAPI *CreateHardLinkfunc)(LPWSTR, LPWSTR, LPSECURITY_ATTRIBUTES); *************** *** 2868,2872 **** static char *keywords[]={"FileName","BufferLength", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|l:GetVolumePathName", keywords, ! &obpath, // @pyparm <o PyUnicode|FileName||File/dir for which to return volume mount point &bufsize)) // @pyparm int|BufferLength|0|Optional parm to allocate extra space for returned string return NULL; --- 2878,2882 ---- static char *keywords[]={"FileName","BufferLength", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|l:GetVolumePathName", keywords, ! &obpath, // @pyparm <o PyUnicode>|FileName||File/dir for which to return volume mount point &bufsize)) // @pyparm int|BufferLength|0|Optional parm to allocate extra space for returned string return NULL; *************** *** 3093,3113 **** py_EncryptFile(PyObject *self, PyObject *args) { ! // @pyparm string/unicode|filename||File to encrypt - PyObject *ret=NULL, *obfname=NULL; - WCHAR *fname = NULL; - if (pfnEncryptFile==NULL) - return PyErr_Format(PyExc_NotImplementedError,"EncryptFile not supported by this version of Windows"); if (!PyArg_ParseTuple(args,"O:EncryptFile", &obfname)) ! return NULL; ! if (!PyWinObject_AsWCHAR(obfname, &fname, FALSE)) ! return NULL; if (!(*pfnEncryptFile)(fname)) ! PyWin_SetAPIError("EncryptFile"); ! else ! ret=Py_None; ! PyWinObject_FreeWCHAR(fname); ! Py_XINCREF(ret); ! return ret; } --- 3103,3122 ---- py_EncryptFile(PyObject *self, PyObject *args) { ! CHECK_PFN(EncryptFile); ! // @pyparm string/unicode|filename||File to encrypt ! PyObject *ret=NULL, *obfname=NULL; ! WCHAR *fname = NULL; if (!PyArg_ParseTuple(args,"O:EncryptFile", &obfname)) ! return NULL; ! if (!PyWinObject_AsWCHAR(obfname, &fname, FALSE)) ! return NULL; if (!(*pfnEncryptFile)(fname)) ! PyWin_SetAPIError("EncryptFile"); ! else ! ret=Py_None; ! PyWinObject_FreeWCHAR(fname); ! Py_XINCREF(ret); ! return ret; } *************** *** 3116,3125 **** py_DecryptFile(PyObject *self, PyObject *args) { // @pyparm string/unicode|filename||File to decrypt PyObject *ret=NULL, *obfname=NULL; WCHAR *fname = NULL; DWORD reserved=0; ! if (pfnDecryptFile==NULL) ! return PyErr_Format(PyExc_NotImplementedError,"DecryptFile not supported by this version of Windows"); if (!PyArg_ParseTuple(args,"O:DecryptFile", &obfname)) return NULL; --- 3125,3134 ---- py_DecryptFile(PyObject *self, PyObject *args) { + CHECK_PFN(DecryptFile); // @pyparm string/unicode|filename||File to decrypt PyObject *ret=NULL, *obfname=NULL; WCHAR *fname = NULL; DWORD reserved=0; ! if (!PyArg_ParseTuple(args,"O:DecryptFile", &obfname)) return NULL; *************** *** 3139,3160 **** py_EncryptionDisable(PyObject *self, PyObject *args) { ! // @pyparm string/unicode|DirName||Directory to enable or disable // @pyparm boolean|Disable||Set to False to enable encryption ! PyObject *ret=NULL, *obfname=NULL; ! WCHAR *fname = NULL; BOOL Disable; ! if (pfnEncryptionDisable==NULL) ! return PyErr_Format(PyExc_NotImplementedError,"EncryptionDisable not supported by this version of Windows"); if (!PyArg_ParseTuple(args,"Oi:EncryptionDisable", &obfname, &Disable)) ! return NULL; ! if (!PyWinObject_AsWCHAR(obfname, &fname, FALSE)) ! return NULL; if (!(*pfnEncryptionDisable)(fname,Disable)) ! PyWin_SetAPIError("EncryptionDisable"); ! else ! ret=Py_None; ! PyWinObject_FreeWCHAR(fname); ! Py_XINCREF(ret); ! return ret; } --- 3148,3169 ---- py_EncryptionDisable(PyObject *self, PyObject *args) { ! CHECK_PFN(EncryptionDisable); ! // @pyparm string/unicode|DirName||Directory to enable or disable // @pyparm boolean|Disable||Set to False to enable encryption ! PyObject *ret=NULL, *obfname=NULL; ! WCHAR *fname = NULL; BOOL Disable; ! if (!PyArg_ParseTuple(args,"Oi:EncryptionDisable", &obfname, &Disable)) ! return NULL; ! if (!PyWinObject_AsWCHAR(obfname, &fname, FALSE)) ! return NULL; if (!(*pfnEncryptionDisable)(fname,Disable)) ! PyWin_SetAPIError("EncryptionDisable"); ! else ! ret=Py_None; ! PyWinObject_FreeWCHAR(fname); ! Py_XINCREF(ret); ! return ret; } *************** *** 3168,3187 **** py_FileEncryptionStatus(PyObject *self, PyObject *args) { ! // @pyparm string/unicode|FileName||file to query ! PyObject *ret=NULL, *obfname=NULL; ! WCHAR *fname = NULL; DWORD Status=0; ! if (pfnFileEncryptionStatus==NULL) ! return PyErr_Format(PyExc_NotImplementedError,"FileEncryptionStatus not supported by this version of Windows"); if (!PyArg_ParseTuple(args,"O:FileEncryptionStatus", &obfname)) ! return NULL; ! if (!PyWinObject_AsWCHAR(obfname, &fname, FALSE)) ! return NULL; if (!(*pfnFileEncryptionStatus)(fname, &Status)) ! PyWin_SetAPIError("FileEncryptionStatus"); ! else ! ret=Py_BuildValue("i",Status); ! PyWinObject_FreeWCHAR(fname); ! return ret; } --- 3177,3196 ---- py_FileEncryptionStatus(PyObject *self, PyObject *args) { ! CHECK_PFN(FileEncryptionStatus); ! // @pyparm string/unicode|FileName||file to query ! PyObject *ret=NULL, *obfname=NULL; ! WCHAR *fname = NULL; DWORD Status=0; ! if (!PyArg_ParseTuple(args,"O:FileEncryptionStatus", &obfname)) ! return NULL; ! if (!PyWinObject_AsWCHAR(obfname, &fname, FALSE)) ! return NULL; if (!(*pfnFileEncryptionStatus)(fname, &Status)) ! PyWin_SetAPIError("FileEncryptionStatus"); ! else ! ret=Py_BuildValue("i",Status); ! PyWinObject_FreeWCHAR(fname); ! return ret; } *************** *** 3456,3462 **** py_QueryUsersOnEncryptedFile(PyObject *self, PyObject *args) { ! // @pyparm string/unicode|FileName||file to query ! if ((pfnQueryUsersOnEncryptedFile==NULL)||(pfnFreeEncryptionCertificateHashList==NULL)) ! return PyErr_Format(PyExc_NotImplementedError,"QueryUsersOnEncryptedFile not supported by this version of Windows"); PyObject *ret=NULL, *obfname=NULL, *ret_item=NULL; WCHAR *fname=NULL; --- 3465,3470 ---- py_QueryUsersOnEncryptedFile(PyObject *self, PyObject *args) { ! CHECK_PFN(QueryUsersOnEncryptedFile); ! // @pyparm string/unicode|FileName||file to query PyObject *ret=NULL, *obfname=NULL, *ret_item=NULL; WCHAR *fname=NULL; *************** *** 3488,3494 **** py_QueryRecoveryAgentsOnEncryptedFile(PyObject *self, PyObject *args) { ! // @pyparm string/unicode|FileName||file to query ! if ((pfnQueryRecoveryAgentsOnEncryptedFile==NULL)||(pfnFreeEncryptionCertificateHashList==NULL)) ! return PyErr_Format(PyExc_NotImplementedError,"QueryRecoveryAgentsOnEncryptedFile not supported by this version of Windows"); PyObject *ret=NULL, *obfname=NULL, *ret_item=NULL; WCHAR *fname=NULL; --- 3496,3501 ---- py_QueryRecoveryAgentsOnEncryptedFile(PyObject *self, PyObject *args) { ! CHECK_PFN(QueryRecoveryAgentsOnEncryptedFile); ! // @pyparm string/unicode|FileName||file to query PyObject *ret=NULL, *obfname=NULL, *ret_item=NULL; WCHAR *fname=NULL; *************** *** 3509,3516 **** if (fname!=NULL) ! PyWinObject_FreeWCHAR(fname); if (pechl!=NULL) (*pfnFreeEncryptionCertificateHashList)(pechl); ! return ret; } --- 3516,3523 ---- if (fname!=NULL) ! PyWinObject_FreeWCHAR(fname); if (pechl!=NULL) (*pfnFreeEncryptionCertificateHashList)(pechl); ! return ret; } *************** *** 3519,3526 **** py_RemoveUsersFromEncryptedFile(PyObject *self, PyObject *args) { ! // @pyparm string/unicode|FileName||File from which to remove users // @pyparm ((<o PySID>,string,unicode),...)|pHashes||Sequence representing an ENCRYPTION_CERTIFICATE_HASH_LIST structure, as returned by QueryUsersOnEncryptedFile - if (pfnRemoveUsersFromEncryptedFile==NULL) - return PyErr_Format(PyExc_NotImplementedError,"RemoveUsersFromEncryptedFile not supported by this version of Windows"); PyObject *ret=NULL, *obfname=NULL, *obechl=NULL; WCHAR *fname=NULL; --- 3526,3532 ---- py_RemoveUsersFromEncryptedFile(PyObject *self, PyObject *args) { ! CHECK_PFN(RemoveUsersFromEncryptedFile); ! // @pyparm string/unicode|FileName||File from which to remove users // @pyparm ((<o PySID>,string,unicode),...)|pHashes||Sequence representing an ENCRYPTION_CERTIFICATE_HASH_LIST structure, as returned by QueryUsersOnEncryptedFile PyObject *ret=NULL, *obfname=NULL, *obechl=NULL; WCHAR *fname=NULL; *************** *** 3545,3549 **** PyWinObject_FreeWCHAR(fname); Py_XINCREF(ret); ! return ret; } --- 3551,3555 ---- PyWinObject_FreeWCHAR(fname); Py_XINCREF(ret); ! return ret; } *************** *** 3552,3555 **** --- 3558,3562 ---- py_AddUsersToEncryptedFile(PyObject *self, PyObject *args) { + CHECK_PFN(AddUsersToEncryptedFile); // @pyparm string/unicode|FileName||File that additional users will be allowed to decrypt // @pyparm ((<o PySID>,string,int),...)|pUsers||Sequence representing *************** *** 3557,3562 **** // users' Sid, encoded EFS certficate (user must export a .cer to obtain // this data), and encoding type (usually 1 for X509_ASN_ENCODING) - if (pfnAddUsersToEncryptedFile==NULL) - return PyErr_Format(PyExc_NotImplementedError,"AddUsersToEncryptedFile not supported by this version of Windows"); PyObject *ret=NULL, *obfname=NULL, *obecl=NULL; WCHAR *fname=NULL; --- 3564,3567 ---- *************** *** 3577,3586 **** ret=Py_None; if (fname!=NULL) ! PyWinObject_FreeWCHAR(fname); PyWinObject_FreePENCRYPTION_CERTIFICATE_LIST(&ecl); Py_XINCREF(ret); ! return ret; } // @pyswig (int, buffer, int)|BackupRead|Reads streams of data from a file // @comm Returns number of bytes read, data buffer, and context pointer for next operation --- 3582,3629 ---- ret=Py_None; if (fname!=NULL) ! PyWinObject_FreeWCHAR(fname); PyWinObject_FreePENCRYPTION_CERTIFICATE_LIST(&ecl); Py_XINCREF(ret); ! return ret; } + // @pyswig |DuplicateEncryptionInfoFile|Duplicates EFS encryption from one file to another + // @pyseeapi DuplicateEncryptionInfoFile + // @comm Requires Windows XP or later + // @comm Accepts keyword arguments. + static PyObject *py_DuplicateEncryptionInfoFile(PyObject *self, PyObject *args, PyObject *kwargs) + { + CHECK_PFN(DuplicateEncryptionInfoFile); + WCHAR *src=NULL, *dst=NULL; + PSECURITY_ATTRIBUTES psa; + PyObject *obsrc, *obdst, *obsa=Py_None, *ret=NULL; + DWORD disp, attr; + static char *keywords[]={"SrcFileName","DstFileName","CreationDisposition","Attributes","SecurityAttributes", NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOkk|O:DuplicateEncryptionInfoFile", keywords, + &obsrc, // @pyparm <o PyUnicode>|SrcFileName||Encrypted file to read EFS metadata from + &obdst, // @pyparm <o PyUnicode>|DstFileName||File to be encrypted using EFS data from source file + &disp, // @pyparm int|CreationDisposition||Specifies whether an existing file should be overwritten (CREATE_NEW or CREATE_ALWAYS) + &attr, // @pyparm int|Attributes||File attributes + &obsa)) // @pyparm <o PySECURITY_ATTRIBUTES>|SecurityAttributes|None|Specifies security for destination file + return NULL; + + if (PyWinObject_AsWCHAR(obsrc, &src, FALSE) + &&PyWinObject_AsWCHAR(obdst, &dst, FALSE) + &&PyWinObject_AsSECURITY_ATTRIBUTES(obsa, &psa, TRUE)){ + DWORD err=(*pfnDuplicateEncryptionInfoFile)(src, dst, disp, attr, psa); + if (err==ERROR_SUCCESS){ + Py_INCREF(Py_None); + ret=Py_None; + } + else + PyWin_SetAPIError("DuplicateEncryptionInfoFile", err); + } + PyWinObject_FreeWCHAR(src); + PyWinObject_FreeWCHAR(dst); + return ret; + } + PyCFunction pfnpy_DuplicateEncryptionInfoFile=(PyCFunction)py_DuplicateEncryptionInfoFile; + // @pyswig (int, buffer, int)|BackupRead|Reads streams of data from a file // @comm Returns number of bytes read, data buffer, and context pointer for next operation *************** *** 4760,4763 **** --- 4803,4808 ---- %native (RemoveUsersFromEncryptedFile) py_RemoveUsersFromEncryptedFile; %native (AddUsersToEncryptedFile) py_AddUsersToEncryptedFile; + %native (DuplicateEncryptionInfoFile) pfnpy_DuplicateEncryptionInfoFile; + %native (BackupRead) py_BackupRead; %native (BackupSeek) py_BackupSeek; *************** *** 4813,4816 **** --- 4858,4862 ---- ||(strcmp(pmd->ml_name, "GetVolumePathName")==0) ||(strcmp(pmd->ml_name, "GetVolumePathNamesForVolumeName")==0) + ||(strcmp(pmd->ml_name, "DuplicateEncryptionInfoFile")==0) ||(strcmp(pmd->ml_name, "GetFullPathNameTransacted")==0) // not impl yet ||(strcmp(pmd->ml_name, "GetLongPathNameTransacted")==0) // not impl yet *************** *** 4823,4857 **** HMODULE hmodule; - FARPROC fp; hmodule=GetModuleHandle("AdvAPI32.dll"); if (hmodule==NULL) hmodule=LoadLibrary("AdvAPI32.dll"); if (hmodule){ ! fp=GetProcAddress(hmodule,"EncryptFileW"); ! if (fp) pfnEncryptFile=(BOOL (WINAPI *)(WCHAR *))(fp); ! ! fp=GetProcAddress(hmodule,"DecryptFileW"); ! if (fp) pfnDecryptFile=(BOOL (WINAPI *)(WCHAR *, DWORD))(fp); ! ! fp=GetProcAddress(hmodule,"EncryptionDisable"); ! if (fp) pfnEncryptionDisable=(BOOL (WINAPI *)(WCHAR *, BOOL))(fp); ! ! fp=GetProcAddress(hmodule,"FileEncryptionStatusW"); ! if (fp) pfnFileEncryptionStatus=(BOOL (WINAPI *)(WCHAR *, LPDWORD))(fp); ! ! fp=GetProcAddress(hmodule,"QueryUsersOnEncryptedFile"); ! if (fp) pfnQueryUsersOnEncryptedFile=(DWORD (WINAPI *)(WCHAR *, PENCRYPTION_CERTIFICATE_HASH_LIST *))(fp); ! ! fp=GetProcAddress(hmodule,"FreeEncryptionCertificateHashList"); ! if (fp) pfnFreeEncryptionCertificateHashList=(BOOL (WINAPI *)(PENCRYPTION_CERTIFICATE_HASH_LIST))(fp); ! ! fp=GetProcAddress(hmodule,"QueryRecoveryAgentsOnEncryptedFile"); ! if (fp) pfnQueryRecoveryAgentsOnEncryptedFile=(DWORD (WINAPI *)(WCHAR *,PENCRYPTION_CERTIFICATE_HASH_LIST *))(fp); ! ! fp=GetProcAddress(hmodule,"RemoveUsersFromEncryptedFile"); ! if (fp) pfnRemoveUsersFromEncryptedFile=(DWORD (WINAPI *)(WCHAR *,PENCRYPTION_CERTIFICATE_HASH_LIST))(fp); ! ! fp=GetProcAddress(hmodule,"AddUsersToEncryptedFile"); ! if (fp) pfnAddUsersToEncryptedFile=(DWORD (WINAPI *)(WCHAR *,PENCRYPTION_CERTIFICATE_LIST))(fp); pfnOpenEncryptedFileRaw=(OpenEncryptedFileRawfunc)GetProcAddress(hmodule, "OpenEncryptedFileRawW"); --- 4869,4886 ---- HMODULE hmodule; hmodule=GetModuleHandle("AdvAPI32.dll"); if (hmodule==NULL) hmodule=LoadLibrary("AdvAPI32.dll"); if (hmodule){ ! pfnEncryptFile=(EncryptFilefunc)GetProcAddress(hmodule, "EncryptFileW"); ! pfnDecryptFile=(DecryptFilefunc)GetProcAddress(hmodule, "DecryptFileW"); ! pfnEncryptionDisable=(EncryptionDisablefunc)GetProcAddress(hmodule, "EncryptionDisable"); ! pfnFileEncryptionStatus=(FileEncryptionStatusfunc)GetProcAddress(hmodule, "FileEncryptionStatusW"); ! pfnQueryUsersOnEncryptedFile=(QueryUsersOnEncryptedFilefunc)GetProcAddress(hmodule, "QueryUsersOnEncryptedFile"); ! pfnFreeEncryptionCertificateHashList=(FreeEncryptionCertificateHashListfunc)GetProcAddress(hmodule, "FreeEncryptionCertificateHashList"); ! pfnQueryRecoveryAgentsOnEncryptedFile=(QueryRecoveryAgentsOnEncryptedFilefunc)GetProcAddress(hmodule, "QueryRecoveryAgentsOnEncryptedFile"); ! pfnRemoveUsersFromEncryptedFile=(RemoveUsersFromEncryptedFilefunc)GetProcAddress(hmodule, "RemoveUsersFromEncryptedFile"); ! pfnAddUsersToEncryptedFile=(AddUsersToEncryptedFilefunc)GetProcAddress(hmodule, "AddUsersToEncryptedFile"); ! pfnDuplicateEncryptionInfoFile=(DuplicateEncryptionInfoFilefunc)GetProcAddress(hmodule, "DuplicateEncryptionInfoFile"); pfnOpenEncryptedFileRaw=(OpenEncryptedFileRawfunc)GetProcAddress(hmodule, "OpenEncryptedFileRawW"); |