namespace Vanara.PInvoke; /// Items from the DavClnt.dll. public static partial class DavClnt { private const string Lib_DavClnt = "DavClnt.dll"; /// /// The WebDAV client calls the application-defined DavAuthCallback callback function to prompt the user for credentials. /// /// The PFNDAVAUTHCALLBACK type defines a pointer to this callback function. DavAuthCallback is a placeholder for the /// application-defined function name. /// /// /// A pointer to a NULL-terminated Unicode string that contains the name of the target server. /// A pointer to a NULL-terminated Unicode string that contains the name of the network resource. /// /// A bitmask of flags that specify the authentication schemes to be used. /// /// /// Value /// Meaning /// /// /// DAV_AUTHN_SCHEME_BASIC 0x00000001 /// Basic authentication is to be used. /// /// /// DAV_AUTHN_SCHEME_NTLM 0x00000002 /// Microsoft NTLM authentication is to be used. /// /// /// DAV_AUTHN_SCHEME_PASSPORT 0x00000004 /// Passport authentication is to be used. /// /// /// DAV_AUTHN_SCHEME_DIGEST 0x00000008 /// Microsoft Digest authentication is to be used. /// /// /// DAV_AUTHN_SCHEME_NEGOTIATE 0x00000010 /// Microsoft Negotiate is to be used. /// /// /// DAV_AUTHN_SCHEME_CERT 0x00010000 /// Certificate authentication is to be used. /// /// /// DAV_AUTHN_SCHEME_FBA 0x00100000 /// Forms-based authentication is to be used. /// /// /// /// /// The flags that the WebDAV service passed in the dwFlags parameter when it called the NPAddConnection3 function. /// /// A pointer to a DAV_CALLBACK_CRED structure. /// The next step. /// The p free cred. /// /// If the function succeeds, the return value is ERROR_SUCCESS. /// If the function fails, the return value is a system error code. /// /// /// The DavAuthCallback callback function must be registered by calling the DavRegisterAuthCallback function. /// To unregister this callback function, use the DavUnregisterAuthCallback function. /// /// This callback function should prompt the user for credentials (either a user name and password or an authentication BLOB) and /// store this information in the appropriate member of the DAV_CALLBACK_CRED structure that the pCallbackCred parameter points to. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/davclnt/nc-davclnt-pfndavauthcallback PFNDAVAUTHCALLBACK Pfndavauthcallback; // DWORD Pfndavauthcallback( LPWSTR lpwzServerName, LPWSTR lpwzRemoteName, DWORD dwAuthScheme, DWORD dwFlags, PDAV_CALLBACK_CRED // pCallbackCred, AUTHNEXTSTEP *NextStep, PFNDAVAUTHCALLBACK_FREECRED *pFreeCred ) {...} [PInvokeData("davclnt.h", MSDNShortId = "6ac191ac-e63f-431f-893b-92c69320db58")] [UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet = CharSet.Unicode)] public delegate Win32Error DavAuthCallback(string lpwzServerName, string lpwzRemoteName, DAV_AUTHN_SCHEME dwAuthScheme, uint dwFlags, ref DAV_CALLBACK_CRED pCallbackCred, ref AUTHNEXTSTEP NextStep, out DavFreeCredCallback pFreeCred); /// /// /// The WebDAV client calls the application-defined DavFreeCredCallback callback function to free the credential information that was /// retrieved by the DavAuthCallback callback function. /// /// /// The PFNDAVAUTHCALLBACK_FREECRED type defines a pointer to this callback function. DavFreeCredCallback is a placeholder for the /// application-defined function name. /// /// /// /// A pointer to the DAV_CALLBACK_AUTH_UNP or DAV_CALLBACK_AUTH_BLOB structure that was used in the DavAuthCallback callback function. /// /// /// If the function succeeds, the return value is ERROR_SUCCESS. /// If the function fails, the return value is a system error code. /// /// /// The DavFreeCredCallback callback function must be registered by calling the DavRegisterAuthCallback function. /// /// This callback function should free only the buffer that the pBuffer member of the DAV_CALLBACK_AUTH_UNP or /// DAV_CALLBACK_AUTH_BLOB structure points to, not the entire structure. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/davclnt/nc-davclnt-pfndavauthcallback_freecred PFNDAVAUTHCALLBACK_FREECRED // PfndavauthcallbackFreecred; DWORD PfndavauthcallbackFreecred( PVOID pbuffer ) {...} [PInvokeData("davclnt.h", MSDNShortId = "96bacda5-8f24-4119-b0ae-82ff8aff54b4")] [UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet = CharSet.Unicode)] public delegate Win32Error DavFreeCredCallback(IntPtr pbuffer); /// /// Specifies the next action that the WebDAV client should take after a successful call to the DavAuthCallback callback function. /// /// /// This enumeration provides the values for the NextStep parameter of the DavAuthCallback callback function. /// // https://docs.microsoft.com/en-us/windows/desktop/api/davclnt/ne-davclnt-__unnamed_enum_0 typedef enum { DefaultBehavior, // RetryRequest, CancelRequest } ; [PInvokeData("davclnt.h", MSDNShortId = "e9ce9e61-c395-4f6b-843c-c1caa13ac3b4")] public enum AUTHNEXTSTEP { /// /// Retry the connection request without using the DavAuthCallback callback function. This is the same as the default behavior if /// no callback function is registered. /// DefaultBehavior, /// Retry the connection request using the credentials that were retrieved by the DavAuthCallback function. RetryRequest, /// Cancel the connection request. CancelRequest, } /// Authentication scheme. [PInvokeData("davclnt.h", MSDNShortId = "6ac191ac-e63f-431f-893b-92c69320db58")] [Flags] public enum DAV_AUTHN_SCHEME { /// Basic authentication is to be used. DAV_AUTHN_SCHEME_BASIC = 0x00000001, /// Microsoft NTLM authentication is to be used. DAV_AUTHN_SCHEME_NTLM = 0x00000002, /// Passport authentication is to be used. DAV_AUTHN_SCHEME_PASSPORT = 0x00000004, /// Microsoft Digest authentication is to be used. DAV_AUTHN_SCHEME_DIGEST = 0x00000008, /// Microsoft Negotiate is to be used. DAV_AUTHN_SCHEME_NEGOTIATE = 0x00000010, /// Certificate authentication is to be used. DAV_AUTHN_SCHEME_CERT = 0x00010000, /// Forms-based authentication is to be used. DAV_AUTHN_SCHEME_FBA = 0x00100000, } /// Creates a secure connection to a WebDAV server or to a remote file or directory on a WebDAV server. /// A pointer to a variable that receives the connection handle. /// /// A pointer to a null-terminated Unicode string that contains the path to the remote file or directory. This string must /// begin with the "https://" prefix. /// /// /// A pointer to a null-terminated Unicode string that contains the user name to be used for the connection. This parameter is /// optional and can be NULL. /// /// /// A pointer to a null-terminated Unicode string that contains the password to be used for the connection. This parameter is /// optional and can be NULL. /// /// /// A pointer to a buffer that contains the client certificate to be used for the connection. The certificate must be in a serialized form. /// /// Size, in bytes, of the client certificate. /// /// If the function succeeds, the return value is ERROR_SUCCESS. /// If the function fails, the return value is a system error code. /// /// /// To close the connection, use the DavDeleteConnection function. /// /// Use this function when you are connecting to a WebDAV server using the Secure Sockets Layer (SSL) protocol and therefore must /// specify a certificate. To connect to a WebDAV server without specifying a certificate, use a Windows networking function such as /// WNetAddConnection2 or WNetAddConnection3. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/davclnt/nf-davclnt-davaddconnection DWORD DavAddConnection( HANDLE // *ConnectionHandle, LPCWSTR RemoteName, LPCWSTR UserName, LPCWSTR Password, PBYTE ClientCert, DWORD CertSize ); [DllImport(Lib_DavClnt, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("davclnt.h", MSDNShortId = "d69cba04-503c-4d21-b762-3094c0921e28")] public static extern Win32Error DavAddConnection(out SafeDavConnectionHandle ConnectionHandle, string RemoteName, string? UserName, string? Password, IntPtr ClientCert, uint CertSize); /// Closes all connections to a WebDAV server or a remote file or directory on a WebDAV server. /// /// /// Pointer to a null-terminated Unicode string that contains the name of the remote file or server. This string must be in one of /// the following formats: /// /// /// /// http://server/path /// /// /// \\server\path /// /// /// server /// /// /// where /// server /// is the name of a WebDAV server, and /// path /// is the path to a remote file or directory on the server. /// /// /// A Boolean value that specifies whether the connection should be closed if there are open files. Set this parameter to /// FALSE if the connection should be closed only if there are no open files. Set this parameter to TRUE if the /// connection should be closed even if there are open files. /// /// /// If the function succeeds, the return value is ERROR_SUCCESS. /// If the function fails, the return value is a system error code or network error code such as one of the following values. /// /// /// Return code /// Description /// /// /// ERROR_INVALID_PARAMETER /// The lpName parameter contained a value that was not valid. /// /// /// WN_BAD_NETNAME /// The lpName parameter contained a value that was not a valid remote file name. /// /// /// WN_NOT_CONNECTED /// No connections to the remote file or server were found. /// /// /// WN_OPEN_FILES /// There are open files on the connection, and fForce parameter was set to FALSE. /// /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/davclnt/nf-davclnt-davcancelconnectionstoserver DWORD // DavCancelConnectionsToServer( LPWSTR lpName, BOOL fForce ); [DllImport(Lib_DavClnt, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("davclnt.h", MSDNShortId = "6eb3b011-4cd3-45ec-a07e-c8743d35a176")] public static extern Win32Error DavCancelConnectionsToServer(string lpName, [MarshalAs(UnmanagedType.Bool)] bool fForce); /// Closes a connection that was created by using the DavAddConnection function. /// A handle to an open connection that was created by using the DavAddConnection function. /// /// If the function succeeds, the return value is ERROR_SUCCESS. /// If the function fails, the return value is a system error code. /// // https://docs.microsoft.com/en-us/windows/desktop/api/davclnt/nf-davclnt-davdeleteconnection DWORD DavDeleteConnection( HANDLE // ConnectionHandle ); [DllImport(Lib_DavClnt, SetLastError = false, ExactSpelling = true)] [PInvokeData("davclnt.h", MSDNShortId = "736b8a16-30db-410e-8295-97730297d04b")] public static extern Win32Error DavDeleteConnection(HANDLE ConnectionHandle); /// Flushes the data from the local version of a remote file to the WebDAV server. /// /// A handle to an open file on a WebDAV server. /// The file handle must have the GENERIC_WRITE access right. For more information, see File Security and Access Rights. /// /// /// If the function succeeds, or if hFile is a handle to an encrypted file, the return value is ERROR_SUCCESS. /// If the function fails, the return value is a system error code. /// /// /// /// When an application creates or opens a remote file on a WebDAV server, the WebDAV service downloads the file to the local /// computer, and the application receives a handle to the open file on the server. Any changes that the application makes to the /// local file have no effect on the remote file until the file handle is closed and the local version of the file is uploaded to the /// server. Because the file handle is closed at the same time that the file is saved to the server, the application cannot check /// whether the file was saved successfully. /// /// /// To avoid this problem, use the DavFlushFile function to flush the data from the local version of the file to the remote /// file on the WebDAV server. If the function succeeds, this means that the file was saved successfully. /// /// /// This function does not flush encrypted files. If hFile is a handle to an encrypted file, DavFlushFile returns /// ERROR_SUCCESS without flushing the file data. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/davclnt/nf-davclnt-davflushfile DWORD DavFlushFile( HANDLE hFile ); [DllImport(Lib_DavClnt, SetLastError = false, ExactSpelling = true)] [PInvokeData("davclnt.h", MSDNShortId = "0022a5ba-a4b2-4289-91be-db7f52e62f91")] public static extern Win32Error DavFlushFile(HANDLE hFile); /// Retrieves the extended error code information that the WebDAV server returned for the previous failed I/O operation. /// /// A handle to an open file for which the previous I/O operation has failed. If the previous operation is a failed create operation, /// in which case there is no open file handle, specify INVALID_HANDLE_VALUE for this parameter. /// /// Pointer to a variable that receives the extended error code. /// /// Pointer to a buffer that receives the extended error information as a null-terminated Unicode string. /// /// /// /// A pointer to a variable that on input specifies the size, in Unicode characters, of the buffer that the ExtErrorString parameter /// points to. This value must be at least 1024 characters. /// /// /// If the function succeeds, on output the variable receives the number of characters that are actually copied into the buffer. If /// the function fails with ERROR_INSUFFICIENT_BUFFER, the variable receives 1024, but no characters are copied into the /// ExtErrorString buffer. /// /// /// /// If the function succeeds, the return value is ERROR_SUCCESS. /// If the function fails, the return value is a system error code, such as one of the following values. /// /// /// Return code /// Description /// /// /// ERROR_INVALID_PARAMETER /// One or more parameter values were not valid. /// /// /// ERROR_INSUFFICIENT_BUFFER /// The value that the cChSize parameter points to was less than 1024. /// /// /// /// If you call this function for a file handle whose previous I/O operation was successful, it returns ERROR_INVALID_PARAMETER. // https://docs.microsoft.com/en-us/windows/desktop/api/davclnt/nf-davclnt-davgetextendederror DWORD DavGetExtendedError( HANDLE // hFile, DWORD *ExtError, LPWSTR ExtErrorString, DWORD *cChSize ); [DllImport(Lib_DavClnt, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("davclnt.h", MSDNShortId = "939b6163-b7ae-4ab7-9bcc-a02cbf34ca63")] public static extern Win32Error DavGetExtendedError(HANDLE hFile, out Win32Error ExtError, StringBuilder ExtErrorString, ref uint cChSize); /// Converts the specified UNC path to an equivalent HTTP path. /// /// A pointer to a null-terminated Unicode string that contains the UNC path. This path must be in the following format: /// \server[@SSL][@port][<i>path] /// where /// /// /// server is the server name. /// /// /// @SSL is optional and indicates a request for an SSL connection. /// /// /// port is an optional port number. The standard ports are 80 for http and 443 for https (SSL). /// /// /// path is optional and specifies a path to a remote file or directory on the server. /// /// /// /// A pointer to a caller-allocated buffer that receives the HTTP path as a null-terminated Unicode string. /// /// A pointer to a variable that on input specifies the maximum size, in Unicode characters, of the buffer that the HttpPath /// parameter points to. If the function succeeds, on output the variable receives the number of characters that were copied into the /// buffer. If the function fails with ERROR_INSUFFICIENT_BUFFER, on output the variable receives the number of characters needed to /// store the HTTP path, including the "http://" or "https://" prefix and the terminating NULL character. /// /// /// If the function succeeds, the return value is ERROR_SUCCESS. /// If the function fails, the return value is a system error code, such as the following value. /// /// /// Return code /// Description /// /// /// ERROR_INSUFFICIENT_BUFFER /// The buffer that the HttpPath parameter points to was not large enough to store the HTTP path. /// /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/davclnt/nf-davclnt-davgethttpfromuncpath DWORD DavGetHTTPFromUNCPath( LPCWSTR // UncPath, LPWSTR Url, LPDWORD lpSize ); [DllImport(Lib_DavClnt, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("davclnt.h", MSDNShortId = "caa83e54-a029-45aa-9681-26b2be54fea3")] public static extern Win32Error DavGetHTTPFromUNCPath(string UncPath, StringBuilder Url, ref uint lpSize); /// Returns the file lock owner for a file that is locked on a WebDAV server. /// /// /// A pointer to a null-terminated Unicode string that contains the name of a locked file on the WebDAV server. This string /// must be in one of the following formats: /// /// /// /// \\server\path\filename /// /// /// drive:\filename /// /// /// where /// server /// is the name of a server, /// path /// is the path to a remote file on the server, /// filename /// is a valid file name, and /// drive /// is the drive letter that a remote share is mapped to on the local computer. (A /// share /// is a directory on a server that is made available to users over the network.) /// /// /// A pointer to a caller-allocated buffer that receives the name of the owner of the file lock. This parameter is optional and can /// be NULL. If it is NULL, the LockOwnerNameLengthInBytes parameter must point to zero on input. /// /// /// A pointer to a variable that on input specifies the maximum size, in Unicode characters, of the buffer that the LockOwnerName /// parameter points to. If the function succeeds, on output the variable receives the number of characters that were copied into the /// buffer. If the function fails with ERROR_INSUFFICIENT_BUFFER, on output the variable receives the number of characters needed to /// store the lock owner name, including the terminating NULL character. /// /// /// If the function succeeds, the return value is ERROR_SUCCESS. /// If the function fails, the return value is a system error code, such as one of the following values. /// /// /// Return code /// Description /// /// /// ERROR_INSUFFICIENT_BUFFER /// The buffer that the LockOwnerName parameter points to was not large enough to store the lock owner name. /// /// /// ERROR_INVALID_PARAMETER /// /// One or more parameter values were not valid. For example, this error code is returned if the FileName parameter is a null pointer. /// /// /// /// /// /// /// If a call to a function such as CreateFile for a file on a WebDAV server fails with ERROR_LOCK_VIOLATION, you can use the /// DavGetTheLockOwnerOfTheFile function to determine the owner of the file lock. /// /// /// To obtain the required buffer length for the LockOwnerName buffer, call DavGetTheLockOwnerOfTheFile with LockOwnerName set /// to NULL and LockOwnerNameLengthInBytes set to zero. The return value is ERROR_INSUFFICIENT_BUFFER, and on output the /// LockOwnerNameLengthInBytes parameter receives the required buffer length. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/davclnt/nf-davclnt-davgetthelockownerofthefile DWORD // DavGetTheLockOwnerOfTheFile( LPCWSTR FileName, PWSTR LockOwnerName, PULONG LockOwnerNameLengthInBytes ); [DllImport(Lib_DavClnt, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("davclnt.h", MSDNShortId = "94a4607c-2770-4656-8710-987d6b951e0e")] public static extern Win32Error DavGetTheLockOwnerOfTheFile(string FileName, StringBuilder? LockOwnerName, ref uint LockOwnerNameLengthInBytes); /// Converts the specified HTTP path to an equivalent UNC path. /// /// /// A pointer to a null-terminated Unicode string that contains the HTTP path. This string can be in any of the following /// formats, where server is the server name and path is the path to a remote file or directory on the server: /// /// /// /// http://server/path /// /// /// http://server /// /// /// \\http://server/path /// /// /// \\http://server /// /// /// https://server/path /// /// /// https://server /// /// /// \\https://server/path /// /// /// \\https://server /// /// /// \\server\path /// /// /// \\server /// /// /// /// /// A pointer to a caller-allocated buffer that receives the UNC path as a null-terminated Unicode string. /// /// /// A pointer to a variable that on input specifies the maximum size, in Unicode characters, of the buffer that the UncPath parameter /// points to. If the function succeeds, on output the variable receives the number of characters that were copied into the buffer, /// including the terminating NULL character. If the function fails with ERROR_INSUFFICIENT_BUFFER, on output the variable /// receives the number of characters needed to store the UNC path, including the terminating NULL character. /// /// /// If the function succeeds, the return value is ERROR_SUCCESS. /// If the function fails, the return value is a system error code, such as the following value. /// /// /// Return code /// Description /// /// /// ERROR_INSUFFICIENT_BUFFER /// The buffer that the UncPath parameter points to was not large enough to store the UNC path. /// /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/davclnt/nf-davclnt-davgetuncfromhttppath DWORD DavGetUNCFromHTTPPath( LPCWSTR // Url, LPWSTR UncPath, LPDWORD lpSize ); [DllImport(Lib_DavClnt, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("davclnt.h", MSDNShortId = "e9613e4a-5ba1-4954-bc7a-7843249f031e")] public static extern Win32Error DavGetUNCFromHTTPPath(string Url, StringBuilder UncPath, ref uint lpSize); /// Invalidates the contents of the local cache for a remote file on a WebDAV server. /// /// A pointer to a Unicode string that contains the name of a remote file on a WebDAV server. This name can be an HTTP path name /// (URL) or a UNC path name. /// /// /// If the function succeeds, the return value is ERROR_SUCCESS. /// If the function fails, the return value is a system error code. /// /// /// /// The DavInvalidateCache function marks the contents of the locally cached file (for the specified URL) for deletion. If /// this function succeeds, the local file cache is no longer valid. This function fails if there are any handles opened against the /// file either by the same process or by a different process on the local computer. /// /// /// If the item that is named in the URLName parameter is not present in the cache, DavInvalidateCache returns ERROR_SUCCESS /// without invalidating the cache. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/davclnt/nf-davclnt-davinvalidatecache DWORD DavInvalidateCache( LPCWSTR // URLName ); [DllImport(Lib_DavClnt, SetLastError = false, ExactSpelling = true)] [PInvokeData("davclnt.h", MSDNShortId = "f111b19c-5472-463a-b33d-7d2188d224e8")] public static extern Win32Error DavInvalidateCache([MarshalAs(UnmanagedType.LPWStr)] string URLName); /// Registers an application-defined callback function that the WebDAV client can use to prompt the user for credentials. /// A pointer to a function of type PFNDAVAUTHCALLBACK. /// This parameter is reserved for future use. /// /// If the function succeeds, the return value is an opaque handle. Note that OPAQUE_HANDLE is defined to be a DWORD value. /// /// /// The WebDAV client uses the callback function when it is unable to connect to a remote resource using default credentials. /// /// To unregister the callback function, use the DavUnregisterAuthCallback function, passing the returned opaque handle in the /// hCallback parameter. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/davclnt/nf-davclnt-davregisterauthcallback OPAQUE_HANDLE // DavRegisterAuthCallback( PFNDAVAUTHCALLBACK CallBack, ULONG Version ); [DllImport(Lib_DavClnt, SetLastError = false, ExactSpelling = true)] [PInvokeData("davclnt.h", MSDNShortId = "7b381929-174f-4b7b-aa22-dc7a2c3e3b4d")] public static extern uint DavRegisterAuthCallback(DavAuthCallback CallBack, uint Version); /// Unregisters a registered callback function that the WebDAV client uses to prompt the user for credentials. /// The opaque handle that was returned by the DavRegisterAuthCallback function. /// To register the callback function, use the DavRegisterAuthCallback function. // https://docs.microsoft.com/en-us/windows/desktop/api/davclnt/nf-davclnt-davunregisterauthcallback void DavUnregisterAuthCallback( // OPAQUE_HANDLE hCallback ); [DllImport(Lib_DavClnt, SetLastError = false, ExactSpelling = true)] [PInvokeData("davclnt.h", MSDNShortId = "5277d9ce-22e6-49d5-9a9c-c02993605bdf")] public static extern void DavUnregisterAuthCallback(uint hCallback); /// Stores an authentication BLOB that was retrieved by the DavAuthCallback callback function. /// /// This structure is included as a member in the DAV_CALLBACK_CRED structure. /// /// The DavFreeCredCallback callback function should free only the buffer that the pBuffer member points to, not the entire structure. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/davclnt/ns-davclnt-_dav_callback_auth_blob typedef struct // _DAV_CALLBACK_AUTH_BLOB { PVOID pBuffer; ULONG ulSize; ULONG ulType; } DAV_CALLBACK_AUTH_BLOB, *PDAV_CALLBACK_AUTH_BLOB; [PInvokeData("davclnt.h", MSDNShortId = "59976cb0-ed68-4db0-b8f8-cfe5e778916b")] [StructLayout(LayoutKind.Sequential)] public struct DAV_CALLBACK_AUTH_BLOB { /// A pointer to a buffer that receives the authentication BLOB. public IntPtr pBuffer; /// The size, in bytes, of the buffer that the pBuffer member points to. public uint ulSize; /// /// The data type of the buffer that the pBuffer member points to. /// /// /// Value /// Meaning /// /// /// 1 /// PCCERT_CONTEXT /// /// /// public uint ulType; } /// Stores user name and password information that was retrieved by the DavAuthCallback callback function. /// /// This structure is included as a member in the DAV_CALLBACK_CRED structure. /// /// The DavFreeCredCallback callback function should free only the buffer that the pBuffer member points to, not the entire structure. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/davclnt/ns-davclnt-_dav_callback_auth_unp typedef struct // _DAV_CALLBACK_AUTH_UNP { LPWSTR pszUserName; ULONG ulUserNameLength; LPWSTR pszPassword; ULONG ulPasswordLength; } // DAV_CALLBACK_AUTH_UNP, *PDAV_CALLBACK_AUTH_UNP; [PInvokeData("davclnt.h", MSDNShortId = "47420a67-bf3f-40d9-bfc4-ac2cb2776a40")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct DAV_CALLBACK_AUTH_UNP { /// /// A pointer to a string that contains the user name. This string is allocated by the DavAuthCallback callback function. /// [MarshalAs(UnmanagedType.LPWStr)] public string pszUserName; /// The length, in WCHAR, of the user name, not including the terminating NULL character. public uint ulUserNameLength; /// A pointer to a string that contains the password. This string is allocated by DavAuthCallback. [MarshalAs(UnmanagedType.LPWStr)] public string pszPassword; /// The length, in WCHAR, of the password, not including the terminating NULL character. public uint ulPasswordLength; } /// Stores user credential information that was retrieved by the DavAuthCallback callback function. /// This structure is used by the DavAuthCallback callback function. // https://docs.microsoft.com/en-us/windows/desktop/api/davclnt/ns-davclnt-_dav_callback_cred typedef struct _DAV_CALLBACK_CRED { // DAV_CALLBACK_AUTH_BLOB AuthBlob; DAV_CALLBACK_AUTH_UNP UNPBlob; BOOL bAuthBlobValid; BOOL bSave; } DAV_CALLBACK_CRED, *PDAV_CALLBACK_CRED; [PInvokeData("davclnt.h", MSDNShortId = "5414d7b5-b506-4d0a-a4b8-89ab7878d674")] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct DAV_CALLBACK_CRED { /// /// If the bAuthBlobValid member is TRUE, this member is a DAV_CALLBACK_AUTH_BLOB structure that contains the user /// credential information. /// public DAV_CALLBACK_AUTH_BLOB AuthBlob; /// /// If the bAuthBlobValid member is FALSE, this member is a DAV_CALLBACK_AUTH_UNP structure that contains the user /// credential information. /// public DAV_CALLBACK_AUTH_UNP UNPBlob; /// /// TRUE if the credential information is stored in the AuthBlob member, and the UNPBlob member should be /// ignored. FALSE if it is stored in the UNPBlob member, and the AuthBlob member should be ignored. /// [MarshalAs(UnmanagedType.Bool)] public bool bAuthBlobValid; /// TRUE if the credential information was written to the credential manager, or FALSE otherwise. [MarshalAs(UnmanagedType.Bool)] public bool bSave; } /// Provides a for a WebDAV connection that is disposed using . public class SafeDavConnectionHandle : SafeHANDLE { /// Initializes a new instance of the class and assigns an existing handle. /// An object that represents the pre-existing handle to use. /// /// to reliably release the handle during the finalization phase; otherwise, (not recommended). /// public SafeDavConnectionHandle(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { } /// Initializes a new instance of the class. private SafeDavConnectionHandle() : base() { } /// protected override bool InternalReleaseHandle() => DavDeleteConnection(handle).Succeeded; } }