import "wtypes.idl";
import "shobjidl.idl";
import "unknwn.idl";

[v1_enum] typedef enum _CREDENTIAL_PROVIDER_USAGE_SCENARIO
{
    CPUS_INVALID = 0,
    CPUS_LOGON,
    CPUS_UNLOCK_WORKSTATION,
    CPUS_CHANGE_PASSWORD,
    CPUS_CREDUI,
    CPUS_PLAP,
} CREDENTIAL_PROVIDER_USAGE_SCENARIO;

[v1_enum] typedef enum _CREDENTIAL_PROVIDER_FIELD_TYPE
{
    CPFT_INVALID = 0,
    CPFT_LARGE_TEXT,
    CPFT_SMALL_TEXT,
    CPFT_COMMAND_LINK,
    CPFT_EDIT_TEXT,
    CPFT_PASSWORD_TEXT,
    CPFT_TILE_IMAGE,
    CPFT_CHECKBOX,
    CPFT_COMBOBOX,
    CPFT_SUBMIT_BUTTON,
} CREDENTIAL_PROVIDER_FIELD_TYPE;

[v1_enum] typedef enum _CREDENTIAL_PROVIDER_FIELD_STATE
{
    CPFS_HIDDEN = 0,
    CPFS_DISPLAY_IN_SELECTED_TILE,
    CPFS_DISPLAY_IN_DESELECTED_TILE,
    CPFS_DISPLAY_IN_BOTH,
} CREDENTIAL_PROVIDER_FIELD_STATE;

[v1_enum] typedef enum _CREDENTIAL_PROVIDER_FIELD_INTERACTIVE_STATE
{
    CPFIS_NONE = 0,
    CPFIS_READONLY,
    CPFIS_DISABLED,
    CPFIS_FOCUSED,
} CREDENTIAL_PROVIDER_FIELD_INTERACTIVE_STATE;

//
// Note: values for guidFieldType used by Microsoft implementations of ICredentialProvider
//       can be found in shlguid.h.
//
typedef struct _CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR
{
    DWORD dwFieldID;
    CREDENTIAL_PROVIDER_FIELD_TYPE cpft;
    LPWSTR pszLabel;
    GUID guidFieldType;
} CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR;

[v1_enum] typedef enum _CREDENTIAL_PROVIDER_GET_SERIALIZATION_RESPONSE
{
    CPGSR_NO_CREDENTIAL_NOT_FINISHED,
    CPGSR_NO_CREDENTIAL_FINISHED,
    CPGSR_RETURN_CREDENTIAL_FINISHED,
} CREDENTIAL_PROVIDER_GET_SERIALIZATION_RESPONSE;

[v1_enum] typedef enum _CREDENTIAL_PROVIDER_STATUS_ICON
{
    CPSI_NONE = 0,
    CPSI_ERROR,
    CPSI_WARNING,
    CPSI_SUCCESS,
} CREDENTIAL_PROVIDER_STATUS_ICON;

typedef struct _CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION
{
    ULONG   ulAuthenticationPackage;
    GUID    clsidCredentialProvider;
    ULONG   cbSerialization;
    [size_is(cbSerialization)] byte* rgbSerialization;
} CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION;

//
// No idl files contain NTSTATUS.  Therefore we mirror its definition in ntdef.h.
//
#ifndef NTSTATUS
typedef LONG NTSTATUS;
#endif

cpp_quote("#define CREDENTIAL_PROVIDER_NO_DEFAULT       ((DWORD)-1)")

interface ICredentialProviderCredentialEvents; // forward

[
    local,
    object,
    pointer_default(ref),
    uuid(63913a93-40c1-481a-818d-4072ff8c70cc),
]
interface ICredentialProviderCredential : IUnknown
{
    HRESULT Advise([in] ICredentialProviderCredentialEvents* pcpce);
    HRESULT UnAdvise();

    HRESULT SetSelected([out] BOOL* pbAutoLogon);
    HRESULT SetDeselected();

    HRESULT GetFieldState([in] DWORD dwFieldID,
                          [out] CREDENTIAL_PROVIDER_FIELD_STATE* pcpfs,
                          [out] CREDENTIAL_PROVIDER_FIELD_INTERACTIVE_STATE* pcpfis);

    HRESULT GetStringValue([in] DWORD dwFieldID, [out, string] LPWSTR* ppsz);
    HRESULT GetBitmapValue([in] DWORD dwFieldID, [out] HBITMAP* phbmp);
    HRESULT GetCheckboxValue([in] DWORD dwFieldID, [out] BOOL* pbChecked, [out, string] LPWSTR* ppszLabel);
    HRESULT GetSubmitButtonValue([in] DWORD dwFieldID, [out] DWORD* pdwAdjacentTo);

    HRESULT GetComboBoxValueCount([in] DWORD dwFieldID, [out] DWORD* pcItems, [out] DWORD* pdwSelectedItem);
    HRESULT GetComboBoxValueAt([in] DWORD dwFieldID, DWORD dwItem, [out, string] LPWSTR* ppszItem);

    HRESULT SetStringValue([in] DWORD dwFieldID, [in, string] LPCWSTR psz);
    HRESULT SetCheckboxValue([in] DWORD dwFieldID, [in] BOOL bChecked);
    HRESULT SetComboBoxSelectedValue([in] DWORD dwFieldID, [in] DWORD dwSelectedItem);
    HRESULT CommandLinkClicked([in] DWORD dwFieldID);

    HRESULT GetSerialization([out] CREDENTIAL_PROVIDER_GET_SERIALIZATION_RESPONSE* pcpgsr,
                             [out] CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION* pcpcs,
                             [out] LPWSTR* ppszOptionalStatusText,
                             [out] CREDENTIAL_PROVIDER_STATUS_ICON* pcpsiOptionalStatusIcon);
    HRESULT ReportResult([in] NTSTATUS ntsStatus,
                         [in] NTSTATUS ntsSubstatus,
                         [out] LPWSTR* ppszOptionalStatusText,
                         [out] CREDENTIAL_PROVIDER_STATUS_ICON* pcpsiOptionalStatusIcon);
};

[
    local,
    object,
    pointer_default(ref),
    uuid(9090be5b-502b-41fb-bccc-0049a6c7254b),
]
interface IQueryContinueWithStatus : IQueryContinue
{
    HRESULT SetStatusMessage([in, string] LPCWSTR psz);
};

[
    local,
    object,
    pointer_default(ref),
    uuid(9387928b-ac75-4bf9-8ab2-2b93c4a55290),
]
interface IConnectableCredentialProviderCredential : ICredentialProviderCredential
{
    HRESULT Connect([in] IQueryContinueWithStatus* pqcws);
    HRESULT Disconnect();
};

[
    local,
    object,
    pointer_default(ref),
    uuid(fa6fa76b-66b7-4b11-95f1-86171118e816),
]
interface ICredentialProviderCredentialEvents : IUnknown
{
    HRESULT SetFieldState([in] ICredentialProviderCredential* pcpc,
                          [in] DWORD dwFieldID,
                          [in] CREDENTIAL_PROVIDER_FIELD_STATE cpfs);
    HRESULT SetFieldInteractiveState([in] ICredentialProviderCredential* pcpc,
                                     [in] DWORD dwFieldID,
                                     [in] CREDENTIAL_PROVIDER_FIELD_INTERACTIVE_STATE cpfis);

    HRESULT SetFieldString([in] ICredentialProviderCredential* pcpc,
                           [in] DWORD dwFieldID,
                           [in, string, unique] LPCWSTR psz);
    HRESULT SetFieldCheckbox([in] ICredentialProviderCredential* pcpc,
                             [in] DWORD dwFieldID,
                             [in] BOOL bChecked,
                             [in] LPCWSTR pszLabel);
    HRESULT SetFieldBitmap([in] ICredentialProviderCredential* pcpc,
                           [in] DWORD dwFieldID,
                           [in] HBITMAP hbmp);

    HRESULT SetFieldComboBoxSelectedItem([in] ICredentialProviderCredential* pcpc,
                                         [in] DWORD dwFieldID,
                                         [in] DWORD dwSelectedItem);
    HRESULT DeleteFieldComboBoxItem([in] ICredentialProviderCredential* pcpc,
                                    [in] DWORD dwFieldID,
                                    [in] DWORD dwItem);
    HRESULT AppendFieldComboBoxItem([in] ICredentialProviderCredential* pcpc,
                                    [in] DWORD dwFieldID,
                                    [in, string] LPCWSTR pszItem);

    HRESULT SetFieldSubmitButton([in] ICredentialProviderCredential* pcpc,
                                 [in] DWORD dwFieldID,
                                 [in] DWORD dwAdjacentTo);
    HRESULT OnCreatingWindow([out] HWND* phwndOwner);
};

interface ICredentialProviderEvents; // forward

[
    local,
    object,
    pointer_default(ref),
    uuid(d27c3481-5a1c-45b2-8aaa-c20ebbe8229e),
]
interface ICredentialProvider : IUnknown
{
    HRESULT SetUsageScenario([in] CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus,
                             [in] DWORD dwFlags);
    HRESULT SetSerialization([in] const CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION* pcpcs);

    HRESULT Advise([in] ICredentialProviderEvents* pcpe, [in] UINT_PTR upAdviseContext);
    HRESULT UnAdvise();

    HRESULT GetFieldDescriptorCount([out] DWORD* pdwCount);
    HRESULT GetFieldDescriptorAt([in] DWORD dwIndex,
                                 [out] CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR** ppcpfd);

    HRESULT GetCredentialCount([out] DWORD* pdwCount,
                               [out] DWORD* pdwDefault,
                               [out] BOOL* pbAutoLogonWithDefault);
    HRESULT GetCredentialAt([in] DWORD dwIndex,
                            [out] ICredentialProviderCredential** ppcpc);
};

[
    object,
    pointer_default(ref),
    uuid(34201e5a-a787-41a3-a5a4-bd6dcf2a854e),
]
interface ICredentialProviderEvents : IUnknown
{
    HRESULT CredentialsChanged([in] UINT_PTR upAdviseContext);
};

[
    local,
    object,
    pointer_default(ref),
    uuid(a5da53f9-d475-4080-a120-910c4a739880),
]
interface ICredentialProviderFilter : IUnknown
{
    HRESULT Filter([in] CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus,
                   [in] DWORD dwFlags,
                   [in, size_is(cProviders)] GUID* rgclsidProviders,
                   [in, out, size_is(cProviders)] BOOL* rgbAllow,
                   [in] DWORD cProviders);
    HRESULT UpdateRemoteCredential([in] const CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION* pcpcsIn,
                                   [out] CREDENTIAL_PROVIDER_CREDENTIAL_SERIALIZATION* pcpcsOut);
};

//
// This typelib contains the CLSIDs of Microsoft's ICredentialProvider implementations.
//
[
    uuid(d545db01-e522-4a63-af83-d8ddf954004f), // LIBID_CredentialProviders
]
library CredentialProviders
{
    // CLSID_PasswordCredentialProvider
    [ uuid(6f45dc1e-5384-457a-bc13-2cd81b0d28ed) ] coclass PasswordCredentialProvider { interface ICredentialProvider; }

    // CLSID_NPCredentialProvider
    [ uuid(3dd6bec0-8193-4ffe-ae25-e08e39ea4063) ] coclass NPCredentialProvider { interface ICredentialProvider; }

    // CLSID_SmartcardCredentialProvider
    [ uuid(8bf9a910-a8ff-457f-999f-a5ca10b4a885) ] coclass SmartcardCredentialProvider { interface ICredentialProvider; }

    // CLSID_SmartcardPinProvider
    [ uuid(94596c7e-3744-41ce-893e-bbf09122f76a) ] coclass SmartcardPinProvider { interface ICredentialProvider; }

    // CLSID_GenericCredentialProvider
    [ uuid(25CBB996-92ED-457e-B28C-4774084BD562) ] coclass GenericCredentialProvider { interface ICredentialProvider; }

    // CLSID_RASProvider
    [ uuid(5537E283-B1E7-4EF8-9C6E-7AB0AFE5056D) ] coclass RASProvider { interface ICredentialProvider; }

    // CLSID_OnexCredentialProvider
    [ uuid(07AA0886-CC8D-4e19-A410-1C75AF686E62) ] coclass OnexCredentialProvider { interface ICredentialProvider; }

    // CLSID_OnexPlapSmartcardCredentialProvider
    [ uuid(33c86cd6-705f-4ba1-9adb-67070b837775) ] coclass OnexPlapSmartcardCredentialProvider { interface ICredentialProvider; }

    // CLSID_VaultProvider
    [ uuid(503739d0-4c5e-4cfd-b3ba-d881334f0df2) ] coclass VaultProvider { interface ICredentialProvider; }

    // CLSID_WinBioCredentialProvider
    [ uuid(AC3AC249-E820-4343-A65B-377AC634DC09) ] coclass WinBioCredentialProvider { interface ICredentialProvider; }
};

