From 891ef5b06e92532e725121122f0436cf0cf90636 Mon Sep 17 00:00:00 2001 From: tlyu Date: Tue, 22 Aug 2006 21:45:17 +0000 Subject: [PATCH] ticket: 4147 version_fixed: 1.4.4 pull up r18464 from trunk r18464@cathode-dark-space: jaltman | 2006-08-16 21:21:00 -0400 ticket: new subject: NetIDMgr Credential Provider Sample Code and Documentation tags: pullup This commit provides a template for a Network Identity Manager Credential Provider. It doesn't provide any real functionality but it does provide all of the functions that need to be specified and filled in as part of the process of producing a NetIdMgr plug-in. This code should be pulled up to 1.4.x for inclusion in the KFW 3.1 SDK as well as to 1.5.x. git-svn-id: svn://anonsvn.mit.edu/krb5/branches/krb5-1-4@18490 dc483132-0cff-0310-8789-dd5450dbe970 --- .../sample/templates/credprov/Makefile | 278 ++++++++++++ .../identity/sample/templates/credprov/README | 250 +++++++++++ .../sample/templates/credprov/config_id.c | 118 +++++ .../sample/templates/credprov/config_ids.c | 96 +++++ .../sample/templates/credprov/config_main.c | 99 +++++ .../sample/templates/credprov/credacq.c | 405 ++++++++++++++++++ .../sample/templates/credprov/credprov.h | 176 ++++++++ .../sample/templates/credprov/credtype.c | 52 +++ .../templates/credprov/images/plugin.ico | Bin 0 -> 9110 bytes .../templates/credprov/lang/en_us/langres.rc | 204 +++++++++ .../sample/templates/credprov/langres.h | 34 ++ .../identity/sample/templates/credprov/main.c | 171 ++++++++ .../sample/templates/credprov/plugin.c | 382 +++++++++++++++++ .../sample/templates/credprov/proppage.c | 59 +++ .../sample/templates/credprov/version.rc | 94 ++++ 15 files changed, 2418 insertions(+) create mode 100644 src/windows/identity/sample/templates/credprov/Makefile create mode 100644 src/windows/identity/sample/templates/credprov/README create mode 100644 src/windows/identity/sample/templates/credprov/config_id.c create mode 100644 src/windows/identity/sample/templates/credprov/config_ids.c create mode 100644 src/windows/identity/sample/templates/credprov/config_main.c create mode 100644 src/windows/identity/sample/templates/credprov/credacq.c create mode 100644 src/windows/identity/sample/templates/credprov/credprov.h create mode 100644 src/windows/identity/sample/templates/credprov/credtype.c create mode 100644 src/windows/identity/sample/templates/credprov/images/plugin.ico create mode 100644 src/windows/identity/sample/templates/credprov/lang/en_us/langres.rc create mode 100644 src/windows/identity/sample/templates/credprov/langres.h create mode 100644 src/windows/identity/sample/templates/credprov/main.c create mode 100644 src/windows/identity/sample/templates/credprov/plugin.c create mode 100644 src/windows/identity/sample/templates/credprov/proppage.c create mode 100644 src/windows/identity/sample/templates/credprov/version.rc diff --git a/src/windows/identity/sample/templates/credprov/Makefile b/src/windows/identity/sample/templates/credprov/Makefile new file mode 100644 index 0000000000..e536210599 --- /dev/null +++ b/src/windows/identity/sample/templates/credprov/Makefile @@ -0,0 +1,278 @@ +# +# Copyright (c) 2006 Secure Endpoints Inc. +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation files +# (the "Software"), to deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, +# publish, distribute, sublicense, and/or sell copies of the Software, +# and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +# Environment variables +# --------------------- +# +# Before running the makefile, set the environment variable KFWSDKDIR +# to the directory containing the Kerberos for Windows SDK version 3.1 +# or later. The path should not end in a backslash. + +# Configuration settings +# ---------------------- + +# Declare a few things about our plug-in. + +# TODO: Change the plug-in name +PLUGINNAME=MyPlugin + +# TODO: Change the module name +MODULENAME=MyModule + +# TODO: Change the credtype name +CREDTYPENAME=MyCred + +# TODO: Change this as appropriate +DLLBASENAME=myplugin + +# Version info + +# TODO: Change the version numbers +VERMAJOR=0 +VERMINOR=1 +VERAUX =0 +VERPATCH=0 + +# Leave these as-is +VERLIST=$(VERMAJOR).$(VERMINOR).$(VERAUX).$(VERPATCH) +VERLISTC=$(VERMAJOR),$(VERMINOR),$(VERAUX),$(VERPATCH) + +# Various checks + +!ifndef MSSDK +! error Platform SDK environment variables not set. +!endif + +!ifndef KFWSDKDIR +! error KFWSDKDIR environment variable not set. +!endif + +# Directories + +BUILDROOT=. + +!ifdef NODEBUG +BUILDTYPE=release +!else +BUILDTYPE=debug +!endif + +!ifndef CPU +!error Environment variable 'CPU' is not defined. +!endif + +DEST=$(BUILDROOT)\dest\$(CPU)_$(BUILDTYPE) +OBJ=$(BUILDROOT)\obj\$(CPU)_$(BUILDTYPE) + +!ifndef NIDMRAWDIRS +KFWINCDIR=$(KFWSDKDIR)\inc +NIDMINCDIR=$(KFWINCDIR)\netidmgr +NIDMLIBDIR=$(KFWSDKDIR)\lib\$(CPU) +!else +NIDMINCDIR=$(KFWSDKDIR)\inc +NIDMLIBDIR=$(KFWSDKDIR) +!endif + +# Win32.mak + +!include + +# Program macros + +CD=cd +RM=del /q +MKDIR=mkdir +RMDIR=rmdir +ECHO=echo +CP=copy /y +LINK=link +MC=mc + +# Lots more macros + +incflags = -I$(NIDMINCDIR) -I$(OBJ) -I. +rincflags = /i $(NIDMINCDIR) /i $(OBJ) /i . + +ldebug = $(ldebug) /DEBUG +cdebug = $(cdebug) -Os -Zi + +cdefines = $(cdefines) -DUNICODE -D_UNICODE + +C2OBJ=$(CC) $(cdebug) $(cflags) $(incflags) $(cdefines) /Fo"$@" /c $** + +DLLGUILINK=$(LINK) /NOLOGO $(ldebug) $(dlllflags) $(guilibsmt) /OUT:$@ /IMPLIB:$(DEST)\$(@B).lib $** + +DLLRESLINK=$(LINK) /NOLOGO /DLL /NOENTRY /MACHINE:$(PROCESSOR_ARCHITECTURE) /OUT:$@ $** + +RC2RES=$(RC) $(RFLAGS) $(rincflags) /fo $@ $** + +MC2RC=$(MC) $(MCFLAGS) -h $(OBJ)\ -m 1024 -r $(OBJ)\ -x $(OBJ)\ $** + +{}.c{$(OBJ)}.obj: + $(C2OBJ) + +{$(OBJ)}.c{$(OBJ)}.obj: + $(C2OBJ) + +{}.rc{$(OBJ)}.res: + $(RC2RES) + +mkdirs:: +!if !exist($(DEST)) + $(MKDIR) $(DEST) +!endif +!if !exist($(OBJ)) + $(MKDIR) $(OBJ) +!endif + +clean:: + $(RM) $(OBJ)\*.* + $(RM) $(DEST)\*.* + +.SUFFIXES: .h + +# +# Manifest handling +# +# Starting with Visual Studio 8, the C compiler and the linker +# generate manifests so that the applications will link with the +# correct side-by-side DLLs at run-time. These are required for +# correct operation under Windows XP. We also have custom manifests +# which need to be merged with the manifests that VS creates. +# +# The syntax for invoking the _VC_MANIFEST_EMBED_foo macro is: +# $(_VC_MANIFEST_EMBED_???) +# + +!ifndef MT +MT=mt.exe -nologo +!endif + +_VC_MANIFEST_EMBED_EXE= \ +if exist $@.manifest $(MT) -outputresource:$@;1 -manifest $@.manifest + +_VC_MANIFEST_EMBED_DLL=$(_VC_MANIFEST_EMBED_EXE) + +# Note that if you are merging manifests, then the VS generated +# manifest should be cleaned up after calling _VC_MANIFEST_EMBED_???. +# This ensures that even if the DLL or EXE is executed in-place, the +# embedded manifest will be used. Otherwise the $@.manifest file will +# be used. +_VC_MANIFEST_CLEAN= \ +if exist $@.manifest $(RM) $@.manifest + +# End of manifest handling + + +# Now for the actual build stuff + +DLL=$(DEST)\$(DLLBASENAME).dll + +LIBFILES= \ + $(NIDMLIBDIR)\nidmgr32.lib + +OBJFILES= \ + $(OBJ)\credacq.obj \ + $(OBJ)\credtype.obj \ + $(OBJ)\main.obj \ + $(OBJ)\plugin.obj \ + $(OBJ)\proppage.obj \ + $(OBJ)\config_main.obj \ + $(OBJ)\config_id.obj \ + $(OBJ)\config_ids.obj + +DLLRESFILE=$(OBJ)\version.res + +CONFIGHEADER=$(OBJ)\credacq_config.h + +all: mkdirs $(CONFIGHEADER) $(DLL) lang + +$(CONFIGHEADER): Makefile + $(CP) << $@ +/* This is a generated file. Do not modify directly. */ + +#pragma once + +#define MYPLUGIN_DLLBASE "$(DLLBASENAME)" + +#define MYPLUGIN_NAME "$(PLUGINNAME)" + +#define MYMODULE_NAME "$(MODULENAME)" + +#define MYCREDTYPE_NAME "$(CREDTYPENAME)" + +#define VERSION_MAJOR $(VERMAJOR) +#define VERSION_MINOR $(VERMINOR) +#define VERSION_AUX $(VERAUX) +#define VERSION_PATCH $(VERPATCH) + +#define VERSION_LIST $(VERLIST) +#define VERSION_LISTC $(VERLISTC) +#define VERSION_STRING "$(VERLIST)" + +<< + +clean:: + $(RM) $(CONFIGHEADER) + +$(DLL): $(OBJFILES) $(DLLRESFILE) + $(DLLGUILINK) $(LIBFILES) + $(_VC_MANIFEST_EMBED_DLL) + $(_VC_MANIFEST_CLEAN) + +clean:: + $(RM) $(DLL) + +# Language specific resources + +# (repeat the following block as needed, redefining LANG for each +# supported language) + +# English-US +LANG=en_us + +LANGDLL=$(DEST)\$(DLLBASENAME)_$(LANG).dll + +lang:: $(LANGDLL) + +$(LANGDLL): $(OBJ)\langres_$(LANG).res $(OBJ)\version_$(LANG).res + $(DLLRESLINK) + $(_VC_MANIFEST_EMBED_DLL) + $(_VC_MANIFEST_CLEAN) + +clean:: + $(RM) $(LANGDLL) + +$(OBJ)\version_$(LANG).res: version.rc + $(RC) $(RFLAGS) $(rincflags) /d LANGRES /d LANG_$(LANG) /fo $@ $** + +clean:: + $(RM) $(OBJ)\version_$(LANG).res + +$(OBJ)\langres_$(LANG).res: lang\$(LANG)\langres.rc + $(RC2RES) + +clean:: + $(RM) $(OBJ)\langres_$(LANG).res + +# /English-US diff --git a/src/windows/identity/sample/templates/credprov/README b/src/windows/identity/sample/templates/credprov/README new file mode 100644 index 0000000000..f091143c81 --- /dev/null +++ b/src/windows/identity/sample/templates/credprov/README @@ -0,0 +1,250 @@ + + Network Identity Manager + + Credentials Provider Plug-in Template + +------------------------------------------------------------------ + + CONTENTS + + 1. INTRODUCTION + 2. COPYRIGHT AND LICENSE + 3. ROADMAP OF THE TEMPLATE + 4. BUILD REQUIREMENTS + 5. BUILDING + 6. RUNNING THE PLUG-IN + 7. KNOWN ISSUES + 8. SUPPORT / BUG REPORTS + +------------------------------------------------------------------ + +1. INTRODUCTION + + This directory and subdirectories contain a plug-in template for + creating a credentials provider plug-in for Network Identity + Manager. A credentials manager plug-in provides knowledge of a + specifc credentials type to the NetIDMgr application and manages + those credentials on behalf of NetIDMgr. + + This version of the template adheres to the following version + constraints: + + Network Identity Manager API version : 5 + + (This API version corresponds to the MIT Kerberos for Windows + version 3.1). + + The source files in this template can be used to build the plug-in + DLL and the US English resource DLL for the plug-in. In its + current form, the plug-in doesn't do any credentials management. + However, it implements a number of stub functions that can be + filled in to perform the necessary credentials management + operations. + +------------------------------------------------------------------ + +2. COPYRIGHT AND LICENSE + + Copyright (c) 2006 Secure Endpoints Inc. + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation + files (the "Software"), to deal in the Software without + restriction, including without limitation the rights to use, copy, + modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + +------------------------------------------------------------------ + +3. ROADMAP OF THE TEMPLATE + + The template consists of the following files and directories: + + .\README + + This file. + + .\Makefile + + The primary (and only) Makefile used by 'nmake' to build the + plug-in. In addition to providing build directives, it also + contains a set of macros which defines the names and version + information that is used throughout the plug-in code. + + Look for the 'Configuration Settings' section of the Makefile + for the macros. If you are basing a plug-in on this template, + you will want to change these macros. These macros will be + used to generate 'credacq_config.h', a header file included by + 'credprov.h' so that the values of the macros can be used in C + code. + + .\credprov.h + + The main header file for all the C source files in the + plug-in. + + .\main.c + + Provides the entry points for the module. + + .\plugin.c + + Provides the message processing functions and support routines + for implementing the plug-in. Note that some of the message + processing routines have been moved to other sources files + based on their use. + + .\credtype.c + + Functions for handling our credentials type. + + .\credacq.c + + Handlers for the credentials acquisition messages including + handling the user interface for the new credentials dialogs. + + .\proppage.c + + Dialog procedures and support code for displaying property + sheets for credentials that belong to our credentials type. + + .\config_main.c + + Dialog procedures and support code for providing the general + configuration panel for this plug-in. + + .\config_id.c + + Dialog procedures and support code for providing per-identity + configuration for this plug-in. + + .\config_ids.c + + Dialog procedures and support code for providing configuration + for defaults across all identities. + + .\version.rc + + Version information for the plug-in as well as all the + language resource DLLs. + + .\langres.h + + Declarations for the language resources (see below). In its + current form, it was generated via Visual Studio while editing + the language resouces file. + + .\images\plugin.ico + + A generic plug-in icon. + + .\lang\en_us\langres.rc + + US-English language resources. This will be used to create + the language resource DLL. + +------------------------------------------------------------------ + +4. BUILD REQUIREMENTS + + Microsoft(R) Platform SDK (Windows Server 2003 or later) + + (http://www.microsoft.com/msdownload/platformsdk/sdkupdate/) + + Microsoft(R) Visual C++ (Visual Studio 2003 or later) + + Although not tested, the template should build using the + Microsoft Visual C++ toolkit. + + MIT Kerberos for Windows (version 3.1 or later) SDK + + At the current time, version 3.1 is still in beta. However, + the template will not work with the 3.0 SDK due to a number of + changes that were made to the NetIDMgr API between 3.0 and + 3.1. + +------------------------------------------------------------------ + +5. BUILDING + + The build process is fairly starightforward. The source is set up + to build using 'nmake', a build tool distributed with the Platform + SDK as well as with Visual Studio. + + 1. Open a command prompt with a suitable build environment. + + From a plain command prompt, you can set up a debug build + environment targetting Windows XP (32-bit) with: + + > "%PROGRAMFILES%\Microsoft Platform SDK\SetEnv.Cmd" /XP32 /DEBUG + + 2. Set the environment variable KFWSDKDIR to point to the root of + the Kerberos for Windows 3.1 SDK. (i.e. %KFWSDKDIR%\inc + should be the include directory of the SDK) + + > SET KFWSDKDIR=%PROGRAMFILES%\MIT\Kerberos + + 3. Start the build: + + > NMAKE all + + The build target 'all' builds the plug-in and the language + resources. There is an additional build target 'clean' which + removes the temporary files and the binaries generated during + the build. + + Assuming everything goes well, the plug-in binaries should be + created under a subdirectory under 'dest'. The name of the + subdirectory reflects the target architecture and the build + type ('debug' or 'release'). + +------------------------------------------------------------------ + +6. RUNNING THE PLUG-IN + + Once the binaries for the plug-in have been built, you need to + register the plug-in with NetIDMgr by adding a registry value as + follows: + + [HKEY_CURRENT_USER\Software\MIT\NetIDMgr\PluginManager\Modules\] + "ImagePath"="" + + The should be the full path to the plug-in DLL. + + is the name of the module that you built. The + default value specified in the template is 'MyModule'. This is + the value of the macro 'MODULENAME' defined in the 'Makefile'. + + Once this is done, you need to restart NetIDMgr so that it will + pick up the new plug-in. + +------------------------------------------------------------------ + +7. KNOWN ISSUES + + 1. With the current MIT Kerberos for Windows 3.1 beta, NetIDMgr + will fail to load the plug-in when tries to load the plug-in + for the first time. Restarting NetIDMgr will fix the problem. + This will be fixed in a future beta and the final release of + KfW 3.1 + +------------------------------------------------------------------ + +8. SUPPORT / BUG REPORTS + + Problems should be sent to netidmgr@secure-endpoints.com + +------------------------------------------------------------------ diff --git a/src/windows/identity/sample/templates/credprov/config_id.c b/src/windows/identity/sample/templates/credprov/config_id.c new file mode 100644 index 0000000000..ed5b3e4c3d --- /dev/null +++ b/src/windows/identity/sample/templates/credprov/config_id.c @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2006 Secure Endpoints Inc. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* $Id$ */ + +#include "credprov.h" +#include + +/* Dialog procedures and support functions for handling configuration + dialogs for per-identity configuration. When the configuration + dialog is activated, an instance of this dialog will be created for + each identity that the user touches. */ + +/* The structure that we use to hold state information for the + dialog. */ +typedef struct tag_config_id_dlg_data { + khui_config_init_data cfg; /* instance information for this + dialog */ + + khm_handle ident; /* handle to the identity for this + dialog */ + + /* TODO: Add any fields for holding state here */ +} config_id_dlg_data; + +INT_PTR CALLBACK +config_id_dlgproc(HWND hwnd, + UINT uMsg, + WPARAM wParam, + LPARAM lParam) { + + config_id_dlg_data * d; + + switch (uMsg) { + case WM_INITDIALOG: + { + wchar_t idname[KCDB_IDENT_MAXCCH_NAME]; + khm_size cb; + khm_int32 rv; + + d = malloc(sizeof(*d)); + assert(d); + ZeroMemory(d, sizeof(*d)); + + /* for subpanels, lParam is a pointer to a + khui_config_init_data strucutre that provides the + instance and context information. It's not a + persistent strucutre, so we have to make a copy. */ + d->cfg = *((khui_config_init_data *) lParam); + + cb = sizeof(idname); + rv = khui_cfg_get_name(d->cfg.ctx_node, idname, &cb); + assert(KHM_SUCCEEDED(rv)); + + rv = kcdb_identity_create(idname, 0, &d->ident); + assert(KHM_SUCCEEDED(rv)); + + /* TODO: perform any other required initialization */ + +#pragma warning(push) +#pragma warning(disable: 4244) + SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR) d); +#pragma warning(pop) + } + break; + + case KHUI_WM_CFG_NOTIFY: + d = (config_id_dlg_data *) + GetWindowLongPtr(hwnd, DWLP_USER); + + if (HIWORD(wParam) == WMCFG_APPLY) { + /* TODO: apply changes */ + + return TRUE; + } + break; + + case WM_DESTROY: + { + d = (config_id_dlg_data *) + GetWindowLongPtr(hwnd, DWLP_USER); + + if (d) { + if (d->ident) + kcdb_identity_release(d->ident); + + /* TODO: perform any other required uninitialization */ + + free(d); + } + } + break; + } + + return FALSE; + +} diff --git a/src/windows/identity/sample/templates/credprov/config_ids.c b/src/windows/identity/sample/templates/credprov/config_ids.c new file mode 100644 index 0000000000..4139512079 --- /dev/null +++ b/src/windows/identity/sample/templates/credprov/config_ids.c @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2006 Secure Endpoints Inc. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* $Id$ */ + +#include "credprov.h" +#include + +/* Dialog procedures and support functions for handling configuration + dialogs for all identities. */ + +/* The structure that we use to hold state information for the + dialog. */ +typedef struct tag_config_ids_dlg_data { + khui_config_init_data cfg; /* instance information for this + dialog */ + + /* TODO: Add any fields for holding state here */ +} config_ids_dlg_data; + +INT_PTR CALLBACK +config_ids_dlgproc(HWND hwnd, + UINT uMsg, + WPARAM wParam, + LPARAM lParam) { + + config_ids_dlg_data * d; + + switch (uMsg) { + case WM_INITDIALOG: + { + d = malloc(sizeof(*d)); + assert(d); + ZeroMemory(d, sizeof(*d)); + + /* for subpanels, lParam is a pointer to a + khui_config_init_data strucutre that provides the + instance and context information. It's not a + persistent strucutre, so we have to make a copy. */ + d->cfg = *((khui_config_init_data *) lParam); + + /* TODO: perform any additional initialization */ + +#pragma warning(push) +#pragma warning(disable: 4244) + SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR) d); +#pragma warning(pop) + } + break; + + case KHUI_WM_CFG_NOTIFY: + d = (config_ids_dlg_data *) + GetWindowLongPtr(hwnd, DWLP_USER); + + if (HIWORD(wParam) == WMCFG_APPLY) { + /* TODO: apply changes */ + + return TRUE; + } + break; + + case WM_DESTROY: + d = (config_ids_dlg_data *) + GetWindowLongPtr(hwnd, DWLP_USER); + + if (d) { + /* TODO: Perform any additional uninitialization */ + + free (d); + } + break; + } + + return FALSE; +} diff --git a/src/windows/identity/sample/templates/credprov/config_main.c b/src/windows/identity/sample/templates/credprov/config_main.c new file mode 100644 index 0000000000..3461ac0ccc --- /dev/null +++ b/src/windows/identity/sample/templates/credprov/config_main.c @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2006 Secure Endpoints Inc. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* $Id$ */ + +#include "credprov.h" +#include + +/* Dialog procedures and support functions for handling configuration + dialogs for general plug-in configuration. */ + +/* Structure for holding dialog data for the configuration window. */ +typedef struct tag_config_main_dlg_data { + khui_config_node cnode; + + /* TODO: add fields as needed */ +} config_main_dlg_data; + +INT_PTR CALLBACK +config_dlgproc(HWND hwnd, + UINT uMsg, + WPARAM wParam, + LPARAM lParam) { + + config_main_dlg_data * d; + + switch (uMsg) { + case WM_INITDIALOG: + d = malloc(sizeof(*d)); + assert(d); + ZeroMemory(d, sizeof(*d)); + + /* for configuration panels that are not subpanels, lParam is + a held handle to the configuration node. The handle will + be held for the lifetime of the window. */ + + d->cnode = (khui_config_node) lParam; + + /* TODO: perform any other required initialization stuff + here */ + +#pragma warning(push) +#pragma warning(disable: 4244) + SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR) d); +#pragma warning(pop) + + break; + + case KHUI_WM_CFG_NOTIFY: + { + d = (config_main_dlg_data *) + GetWindowLongPtr(hwnd, DWLP_USER); + + /* WMCFG_APPLY is the only notification we care about */ + + if (HIWORD(wParam) == WMCFG_APPLY) { + /* TODO: Apply changes and update the state */ + + return TRUE; + } + } + break; + + case WM_DESTROY: + d = (config_main_dlg_data *) + GetWindowLongPtr(hwnd, DWLP_USER); + + /* TODO: perform any other required uninitialization here */ + + if (d) + free(d); + + break; + } + + return FALSE; + +} diff --git a/src/windows/identity/sample/templates/credprov/credacq.c b/src/windows/identity/sample/templates/credprov/credacq.c new file mode 100644 index 0000000000..da07756dad --- /dev/null +++ b/src/windows/identity/sample/templates/credprov/credacq.c @@ -0,0 +1,405 @@ +/* + * Copyright (c) 2006 Secure Endpoints Inc. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* $Id$ */ + +#include "credprov.h" +#include + +/* This file provides handlers for the credentials acquisition + messages including handling the user interface for the new + credentials dialogs. */ + +/********************************************************************* + +These are stubs for the Window message for the dialog panel. This +dialog panel is the one that is added to the new credentials window +for obtaining new credentials. + +Note that all the UI callbacks run under the UI thread. + + *********************************************************************/ + +/* This structure will hold all the state information we will need to + access from the new credentials panel for our credentials type. */ +struct nc_dialog_data { + khui_new_creds * nc; + khui_new_creds_by_type * nct; + + /* TODO: add any other state information here */ +}; + +/* Note: This callback runs under the UI thread */ +INT_PTR +handle_wm_initdialog(HWND hwnd, WPARAM wParam, LPARAM lParam) { + khui_new_creds * nc = NULL; + khui_new_creds_by_type * nct = NULL; + struct nc_dialog_data * d = NULL; + + nc = (khui_new_creds *) lParam; + khui_cw_find_type(nc, credtype_id, &nct); + + assert(nct); + + d = malloc(sizeof(*d)); + ZeroMemory(d, sizeof(*d)); + + d->nc = nc; + d->nct = nct; + +#pragma warning(push) +#pragma warning(disable: 4244) + SetWindowLongPtr(hwnd, DWLP_USER, (LPARAM) d); +#pragma warning(pop) + + nct->aux = (LPARAM) d; /* we can use the auxiliary field to + hold a pointer to d */ + + /* TODO: Perform any additional initialization here */ + + return FALSE; +} + +/* Note: This callback runs under the UI thread */ +INT_PTR +handle_khui_wm_nc_notify(HWND hwnd, WPARAM wParam, LPARAM lParam) { + + struct nc_dialog_data * d; + + /* Refer to the khui_wm_nc_notifications enumeration in the + NetIDMgr SDK for the full list of notification messages that + can be sent. */ + + d = (struct nc_dialog_data *) GetWindowLongPtr(hwnd, DWLP_USER); + + if (!d) + return TRUE; + + /* these should be set by now */ + assert(d->nc); + assert(d->nct); + + switch (HIWORD(wParam)) { + case WMNC_UPDATE_CREDTEXT: + { + wchar_t fmt[KHUI_MAXCCH_LONG_DESC]; + wchar_t tbuf[256]; + + /* we are being requested to update the credentials + text. We already allocated a buffer when we created the + nct structure. So we can just set the text here.*/ + + /* TODO: The credtext should reflect the credentials that + will be obtained when the new credentials operation + completes. */ + + LoadString(hResModule, IDS_NC_CT_TEMPLATE, + fmt, ARRAYLENGTH(fmt)); + + LoadString(hResModule, IDS_GEN_NONE, + tbuf, ARRAYLENGTH(tbuf)); + + assert(d->nct->credtext); + + StringCbPrintf(d->nct->credtext, KHUI_MAXCB_LONG_DESC, + fmt, tbuf); + } + break; + + case WMNC_CREDTEXT_LINK: + break; + + case WMNC_IDENTITY_CHANGE: + break; + + case WMNC_DIALOG_PREPROCESS: + break; + } + + return TRUE; +} + +/* Note: This callback runs under the UI thread */ +INT_PTR +handle_wm_command(HWND hwnd, WPARAM wParam, LPARAM lParam) { + + struct nc_dialog_data * d; + + d = (struct nc_dialog_data *) GetWindowLongPtr(hwnd, DWLP_USER); + + /* TODO: handle WM_COMMAND */ + return FALSE; +} + +/* Note: This callback runs under the UI thread */ +INT_PTR +handle_wm_destroy(HWND hwnd, WPARAM wParam, LPARAM lParam) { + + struct nc_dialog_data * d; + + d = (struct nc_dialog_data *) GetWindowLongPtr(hwnd, DWLP_USER); + + if (d) { + d->nc = NULL; + d->nct = NULL; + + free(d); + } + + /* TODO: Perform any additional uninitialization */ + + return FALSE; +} + +/* Dialog procedure for the new credentials panel for our credentials + type. We just dispatch messages here to other functions here. + + Note that this procedure runs under the UI thread. + */ +INT_PTR CALLBACK +nc_dlg_proc(HWND hwnd, + UINT uMsg, + WPARAM wParam, + LPARAM lParam) { + + switch (uMsg) { + case WM_INITDIALOG: + return handle_wm_initdialog(hwnd, wParam, lParam); + + case WM_COMMAND: + return handle_wm_command(hwnd, wParam, lParam); + + case KHUI_WM_NC_NOTIFY: + return handle_khui_wm_nc_notify(hwnd, wParam, lParam); + + case WM_DESTROY: + return handle_wm_destroy(hwnd, wParam, lParam); + + /* TODO: add code for handling other windows messages here. */ + } + + return FALSE; +} + +/******************************************************************* + +The following section contains function stubs for each of the +credentials messages that a credentials provider is likely to want to +handle. It doesn't include a few messages, but they should be easy to +add. Please see the documentation for each of the KMSG_CRED_* +messages for documentation on how to handle each of the messages. + +********************************************************************/ + + +/* Handler for KMSG_CRED_NEW_CREDS */ +khm_int32 +handle_kmsg_cred_new_creds(khui_new_creds * nc) { + + wchar_t wshortdesc[KHUI_MAXCCH_SHORT_DESC]; + size_t cb = 0; + khui_new_creds_by_type * nct = NULL; + + /* This is a minimal handler that just adds a dialog pane to the + new credentials window to handle new credentials acquisition + for this credentials type. */ + + /* TODO: add additional initialization etc. as needed */ + + nct = malloc(sizeof(*nct)); + ZeroMemory(nct, sizeof(*nct)); + + nct->type = credtype_id; + nct->ordinal = -1; + + LoadString(hResModule, IDS_CT_SHORT_DESC, + wshortdesc, ARRAYLENGTH(wshortdesc)); + StringCbLength(wshortdesc, sizeof(wshortdesc), &cb); +#ifdef DEBUG + assert(cb > 0); +#endif + cb += sizeof(wchar_t); + + nct->name = malloc(cb); + StringCbCopy(nct->name, cb, wshortdesc); + + /* while we are at it, we should also allocate space for the + credential text. */ + nct->credtext = malloc(KHUI_MAXCB_LONG_DESC); + ZeroMemory(nct->credtext, KHUI_MAXCB_LONG_DESC); + + nct->h_module = hResModule; + nct->dlg_proc = nc_dlg_proc; + nct->dlg_template = MAKEINTRESOURCE(IDD_NEW_CREDS); + + khui_cw_add_type(nc, nct); + + return KHM_ERROR_SUCCESS; +} + +/* Handler for KMSG_CRED_RENEW_CREDS */ +khm_int32 +handle_kmsg_cred_renew_creds(khui_new_creds * nc) { + + khui_new_creds_by_type * nct; + + /* This is a minimal handler that just adds this credential type + to the list of credential types that are participating in this + renewal operation. */ + + /* TODO: add additional initialization etc. as needed */ + + nct = malloc(sizeof(*nct)); + ZeroMemory(nct, sizeof(*nct)); + + nct->type = credtype_id; + + khui_cw_add_type(nc, nct); + + return KHM_ERROR_SUCCESS; +} + +/* Handler for KMSG_CRED_DIALOG_PRESTART */ +khm_int32 +handle_kmsg_cred_dialog_prestart(khui_new_creds * nc) { + /* TODO: Handle this message */ + + /* The message is sent after the dialog has been created. The + window handle for the created dialog can be accessed through + the hwnd_panel member of the khui_new_creds_by_type structure + that was added for this credentials type. */ + return KHM_ERROR_SUCCESS; +} + +/* Handler for KMSG_CRED_DIALOG_NEW_IDENTITY */ +/* Not a message sent out by NetIDMgr. See documentation of + KMSG_CRED_DIALOG_NEW_IDENTITY */ +khm_int32 +handle_kmsg_cred_dialog_new_identity(khm_ui_4 uparam, + void * vparam) { + /* TODO: Handle this message */ + return KHM_ERROR_SUCCESS; +} + +/* Handler for KMSG_CRED_DIALOG_NEW_OPTIONS */ +/* Not a message sent out by NetIDMgr. See documentation of + KMSG_CRED_DIALOG_NEW_OPTIONS */ +khm_int32 +handle_kmsg_cred_dialog_new_options(khm_ui_4 uparam, + void * vparam) { + /* TODO: Handle this message */ + return KHM_ERROR_SUCCESS; +} + +/* Handler for KMSG_CRED_PROCESS */ +khm_int32 +handle_kmsg_cred_process(khui_new_creds * nc) { + /* TODO: Handle this message */ + + /* This is where the credentials acquisition should be performed + as determined by the UI. Note that this message is sent even + when the user clicks 'cancel'. The value of nc->result should + be checked before performing any credentials acquisition. If + the value is KHUI_NC_RESULT_CANCEL, then no credentials should + be acquired. Otherwise, the value would be + KHUI_NC_RESULT_PROCESS. */ + + return KHM_ERROR_SUCCESS; +} + +/* Handler for KMSG_CRED_END */ +khm_int32 +handle_kmsg_cred_end(khui_new_creds * nc) { + + khui_new_creds_by_type * nct = NULL; + + /* TODO: Perform any additional uninitialization as needed. */ + + khui_cw_find_type(nc, credtype_id, &nct); + + if (nct) { + + khui_cw_del_type(nc, credtype_id); + + if (nct->name) + free(nct->name); + if (nct->credtext) + free(nct->credtext); + + free(nct); + + } + + return KHM_ERROR_SUCCESS; +} + +/* Handler for KMSG_CRED_IMPORT */ +khm_int32 +handle_kmsg_cred_import(void) { + + /* TODO: Handle this message */ + + return KHM_ERROR_SUCCESS; +} + + +/****************************************************** + Dispatch each message to individual handlers above. + */ +khm_int32 KHMAPI +handle_cred_acq_msg(khm_int32 msg_type, + khm_int32 msg_subtype, + khm_ui_4 uparam, + void * vparam) { + + khm_int32 rv = KHM_ERROR_SUCCESS; + + switch(msg_subtype) { + case KMSG_CRED_NEW_CREDS: + return handle_kmsg_cred_new_creds((khui_new_creds *) vparam); + + case KMSG_CRED_RENEW_CREDS: + return handle_kmsg_cred_renew_creds((khui_new_creds *) vparam); + + case KMSG_CRED_DIALOG_PRESTART: + return handle_kmsg_cred_dialog_prestart((khui_new_creds *) vparam); + + case KMSG_CRED_PROCESS: + return handle_kmsg_cred_process((khui_new_creds *) vparam); + + case KMSG_CRED_DIALOG_NEW_IDENTITY: + return handle_kmsg_cred_dialog_new_identity(uparam, vparam); + + case KMSG_CRED_DIALOG_NEW_OPTIONS: + return handle_kmsg_cred_dialog_new_options(uparam, vparam); + + case KMSG_CRED_END: + return handle_kmsg_cred_end((khui_new_creds *) vparam); + + case KMSG_CRED_IMPORT: + return handle_kmsg_cred_import(); + } + + return rv; +} diff --git a/src/windows/identity/sample/templates/credprov/credprov.h b/src/windows/identity/sample/templates/credprov/credprov.h new file mode 100644 index 0000000000..1851eaa4b4 --- /dev/null +++ b/src/windows/identity/sample/templates/credprov/credprov.h @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2006 Secure Endpoints Inc. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* $Id$ */ + +/* only include this header file once */ +#pragma once + +#ifndef _UNICODE +#ifndef RC_INVOKED +/* This template relies on _UNICODE being defined to call the correct + APIs. */ +#error This template needs to be compiled with _UNICODE +#endif +#endif + +/* Pull in configuration macros from the Makefile */ +#include "credacq_config.h" + +/* declare a few macros about our plugin */ + +/* The following macro will be used throughout the template to refer + to the name of the plugin. The macro is actually defined the + Makefile generated configuration header file. Modify the + PLUGINNAME Makefile macro.*/ +#ifndef MYPLUGIN_NAME +#error MYPLUGIN_NAME not defined +#endif + +/* Also define the unicde equivalent of the name. In general strings + in NetIDMgr are unicode. */ +#define MYPLUGIN_NAMEW _T(MYPLUGIN_NAME) + +/* The name of the module. This is distinct from the name of the + plugin for several reasons. One of which is that a single module + can provide multiple plugins. Also, having a module name distinct + from a plugin name allows multiple vendors to provide the same + plugin. For example, the module name for the MIT Kerberos 5 plugin + is MITKrb5 while the plugin name is Krb5Cred. The macro is + actually defined in the Makefile generated configuration header + file. Modify the MODULENAME Makefile macro.*/ +#ifndef MYMODULE_NAME +#error MYMODULE_NAME not defined +#endif + +#define MYMODULE_NAMEW _T(MYMODULE_NAME) + +/* When logging events from our plugin, the event logging API can + optionally take a facility name to provide a friendly label to + identify where each event came from. We will default to the plugin + name, although it can be anything. */ +#define MYPLUGIN_FACILITYW MYPLUGIN_NAMEW + +/* Base name of the DLL that will be providing the plugin. We use it + to construct names of the DLLs that will contain localized + resources. This is defined in the Makefile and fed in to the build + through there. The macro to change in the Makefile is + DLLBASENAME. */ +#ifndef MYPLUGIN_DLLBASE +#error MYPLUGIN_DLLBASE Not defined! +#endif + +#define MYPLUGIN_DLLBASEW _T(MYPLUGIN_DLLBASE) + +/* Name of the credentials type that will be registered by the plugin. + This macro is actually defined in the Makefile generated + configuration header file. Change the CREDTYPENAME macro in the + Makefile. */ +#ifndef MYCREDTYPE_NAME +#error MYCREDTYPE_NAME not defined +#endif + +#define MYCREDTYPE_NAMEW _T(MYCREDTYPE_NAME) + +/* Configuration node names. We just concatenate a few strings + together, although you should feel free to completely define your + own. */ + +#define CONFIGNODE_MAIN MYCREDTYPE_NAMEW L"Config" +#define CONFIGNODE_ALL_ID MYCREDTYPE_NAMEW L"AllIdents" +#define CONFIGNODE_PER_ID MYCREDTYPE_NAMEW L"PerIdent" + +#include +/* include the standard NetIDMgr header files */ +#include +#include + +/* declarations for language resources */ +#include "langres.h" + +#ifndef NOSTRSAFE +#include +#endif + +/*************************************************** + Externals +***************************************************/ + +extern kmm_module h_khModule; +extern HINSTANCE hInstance; +extern HMODULE hResModule; + +extern const wchar_t * my_facility; + +extern khm_int32 credtype_id; + +/* Function declarations */ + +/* in plugin.c */ +khm_int32 KHMAPI +plugin_msg_proc(khm_int32 msg_type, + khm_int32 msg_subtype, + khm_ui_4 uparam, + void * vparam); + +/* in credtype.c */ +khm_int32 KHMAPI +cred_is_equal(khm_handle cred1, + khm_handle cred2, + void * rock); + +/* in credacq.c */ +khm_int32 KHMAPI +handle_cred_acq_msg(khm_int32 msg_type, + khm_int32 msg_subtype, + khm_ui_4 uparam, + void * vparam); + +/* in proppage.c */ +INT_PTR CALLBACK +pp_cred_dlg_proc(HWND hwnd, + UINT uMsg, + WPARAM wParam, + LPARAM lParam); + +/* in config_id.c */ +INT_PTR CALLBACK +config_id_dlgproc(HWND hwndDlg, + UINT uMsg, + WPARAM wParam, + LPARAM lParam); + +/* in config_ids.c */ +INT_PTR CALLBACK +config_ids_dlgproc(HWND hwndDlg, + UINT uMsg, + WPARAM wParam, + LPARAM lParam); + +/* in config_main.c */ +INT_PTR CALLBACK +config_dlgproc(HWND hwndDlg, + UINT uMsg, + WPARAM wParam, + LPARAM lParam); diff --git a/src/windows/identity/sample/templates/credprov/credtype.c b/src/windows/identity/sample/templates/credprov/credtype.c new file mode 100644 index 0000000000..039c644542 --- /dev/null +++ b/src/windows/identity/sample/templates/credprov/credtype.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2006 Secure Endpoints Inc. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AND + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* $Id$ */ + +#include "credprov.h" + +/* Functions for handling our credentials type. +*/ + +khm_int32 KHMAPI +cred_is_equal(khm_handle cred1, + khm_handle cred2, + void * rock) { + + khm_int32 result; + + /* TODO: Check any additional fields to determine if the two + credentials are equal or not. */ + + /* Note that this is actually a comparison function. It should + return 0 if the credentials are found to be equal, and non-zero + if they are not. We just set this to 0 if we don't need to + check any additional fields and accept the two credentials as + being equal. By the time this function is called, the + identity, name and type of the credentials have already been + found to be equal. */ + result = 0; + + return result; +} diff --git a/src/windows/identity/sample/templates/credprov/images/plugin.ico b/src/windows/identity/sample/templates/credprov/images/plugin.ico new file mode 100644 index 0000000000000000000000000000000000000000..99ffbc411b5f9cf6244bd011297fdb6194a5478b GIT binary patch literal 9110 zcmeHM3s_Xw5k3fk6^swm1Q8S=paD^XsBu?;l4PrBXg<=AN-8MnM~p$Vv;kriw`qg7 zCWSU>Ff}Pg(-4CQ5#HGv}VO3u7kCoH;m*Wkf9_7z@LF>{yAPVZxZdDTAD(jO~#z7G*|qiC^;oV^bb9 zkdI<4&e}i@-C0u^n*ntPG#@k*hRz|Rh2y;{y5geJKB%;e3LOOn1xzG4E~559)H0&f zLDC<{XR)`a#qocJL5Q7(lty`oHh{4B23u`1EEa~?O zTMhY`LHtWXT$B(aiZlr669(bIZO&t~u$Sl=3MAJ#gOG;s38IV?$Pm;AO(u0{O?c`I zG^7cm4jm??^xq+A^0KQ>Eg@1ceLA4(3Yc#5Z!6S(x)j8F& z1KNMG&M_yPHeehJJZ(S@`5nbW_h^}*;tIHP4H;!w6)nhwtzm+&1oyb!7+fL8q|x6W z`ql`tt!ub^%~nzuR6;NCSDB+Yv@}M#qtsVUgy?&b3K<{#K9CK^(awsiuRjY&E@fq9 zr7SWsg0;0Zv*5f=mYbW!LW6@?U0oIPicMmLg-6+~TiwhnID+looy5}8(%3uk@hm7T zf>l*ju?Nv8=PRld08eR$N@n z{K6txN=gdz^YdeQd3mhAzn>*0zQY0|HbTD)x^3vsWua@=!ln*3g)BKanPp_8v81FO z%*!tTewVSp$XNK@2A^}`Zyi&{r@`Ms_;$y%-7E!J}0s$q7EC4wdKxCU4iV(Lab&4{NI z@uVS^0UkplVu)pH;dcuB&C1ANyOWYw1$^yC0s6_TNfQj*e0eZyv5@5U3$z**rX<(1 z;o)39MdslxDRB7|nVlYx%e`&QW|+_MKqr@5j`IjIcOll?@@WV2DYo+QcH_p4x3jXd zn`AzJj?CUnCm-Wr>tSbSXRT0pOvlB}dV!OZlZ}m&!gevYAG7R{NiWzha`o~BP4s~Z zDJ-xuvr{M(z+d*rle2={-K?FJpb&F~!fF8&Y@Fx{3McW>nGQaWj#Mg5!sctcfzO|8 z{3Y>d_r<<2pXTg5_F*!!S>OSe2#8yccAqo?a^(Xw#&Rw<(<%@+#6DcUc1eg*Insgb z7eN8OIBCUm=fK|NImHqnOeVSgBD3kFAX(3Kw59Q9T0N$dyV@^8UKCawe6FMSY#=My z^N3>JXynIAW+4=D&M){7y=#VRHNdZ1e z)^3&ndPpv-o})8XC;^W?x?~CXbBgd%5F$FMfuh zGeA^S6mwAq^7DzS+?Vg`bgqzNKc)RRF)@)T_KNGI@4_2xRJT~1@ZI5z`y{D zz*us*obTyVJmkRlXCA-`2n^z9o_L&{?$iAY+|R(b%fN^sG}Fm~lhaIzEZt2xxm!v! z+02A^6SK(@InJ0!{KOfK5?NbY5YGtYK}T!rY124QeWot6t*6bM%X!)82dLw*xvs99 zw{i0vj}8l0dwb4XxVh2Y!rs=F^HbbLJxaXoq;Yn*o0^OrjjM~zqzMkhO5|eUJYnQi z?*7A878X_><|9Ww^e>uDkMqV1qIo~;_dy#e>G&<_KK(ytAT;=e->hFJy!rc`fBzsm z^FV3IX>~)x&6_uj<{~uYm%rVx{*Q5Qew6fKcGkhtuSy!#P`+tYS?XN9GAJ@4+z`J} zt%eCs8N;ns!fT$oj4B(&KV5XHwx+thz5V#HBVXiXmz_J?*4o;C`?gkj zF#hS{qPp6ej*gC9JChFO=A17pYj1D6ty4CN57^3!6)i0-d0!p^{`s$>Yb8K6pPhWzV56vf)g{h4SjEOINNmX*8Nkmn!kWbC*Vg z>9}^SL(|!rlXVb&o+>|(`*j`nuR98lN0y1Kis z_w;nPwY7G1v|sPi-011S2jE>@8vING_wL-m=g!xhz(N@yXG*^s;y>`;{Y%33_ukFQ zJaFOs`KHFk=H@F6^_P_aE9Qo6(SKZ)hh%4G1HAh>#_honeSLkH5g_;W_TISB)7o+s z$0kV0vF>htekAZ6?{81~a0dd+*q>fpbQ1mtuHO_^BI-ZO|CXPVlf%KgZ{D~8e86G| z%p)Q|ASgDJkkrGYyCaFSUOhh0ny*|zm7)kS z%h#`8zrp9|c3+=S@WY34%g>kT@sa=S+qc6j455!=^XAP4_%|CH)hN8y))v&WMni>! zArO}|q58DIbAadPeTh}3$A{aWCMTl^12=3o#K$B`O8_%lUw;|3eYLq63mNYUtWErS zh)P4X3acO(eWfoaqu?c{i)(9Y=yjw)F?1nJst4WjF|160gHZDq%F8P&FV<97U%p(YRyXL& zX}ISA$Krw~v|cbx{DmXE6Z(34Z{NnkxvkGU!13)2FSoLD=TH)tE>+glRM%g=jO|G( zr=nAZ2Qxm;%-Elkm3cTfC;!XC$Bq;f9zRxg_6*+Am^H54Kof`ZYiXf3DvF$khSe&K z4*yX$wY4=B6&I>5RU&qjQzI`YX&3nTqom}IcYXHhC;Rq(wm*Ge=7Ee8$BvvmQ;Ih{ zc}0QK^pTai;Yw2ziUg&ONxas91%=mw25Smw!~^CRAz&;jr^ZGJU%CPxyUgeNQW4Ry zBl%~(Dmi!d3>F$*?A)trB#m3CkzN!De8#q--8FQvV5TUXwl>rfK8EAB@?GovNSM`{_25q`fB+>?inZkn7?MgkEEa_c}1P;f)-}B$hfZ^{zx@YbG z_Ph&BRHoG6k74`H?iIj-CYt|`PdAA6KKTE84$v}AFRosd5V|Tv{9bMKD$TlA)@tU+ zy~Sysi;XstLFb+=`qfuOg-FVLayb6t~ODJSb8#W-otoDX*r4gaq-a zxK9URkUrTJa^lIhxTuJ?p>m3Kwzrborl+Tiu1i-88=q{;%gaTa z5JcCfR}PYsJwN+da z@cgiOCLO2Qo+5rj)ywGlnZOldNl6K}BU|hV>DU;=Z`1HKW0)Rxh0rK9D4*9O}V U#!gL^-VAqF8Gl23W3Smi0oL6$(EtDd literal 0 HcmV?d00001 diff --git a/src/windows/identity/sample/templates/credprov/lang/en_us/langres.rc b/src/windows/identity/sample/templates/credprov/lang/en_us/langres.rc new file mode 100644 index 0000000000..7e37027924 --- /dev/null +++ b/src/windows/identity/sample/templates/credprov/lang/en_us/langres.rc @@ -0,0 +1,204 @@ +// Microsoft Visual C++ generated resource script. +// +#include "..\..\langres.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "..\\..\\langres.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +IDI_PLUGIN ICON "..\\..\\images\\plugin.ico" + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog +// + +IDD_PP_CRED DIALOGEX 0, 0, 235, 156 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_DISABLED | WS_CAPTION +CAPTION "Property Page" +FONT 8, "MS Shell Dlg", 0, 0, 0x0 +BEGIN + LTEXT "TODO: layout property page",IDC_STATIC,60,73,110,8 +END + +IDD_PP_IDENT DIALOGEX 0, 0, 235, 156 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_DISABLED | WS_CAPTION +CAPTION "Property Page" +FONT 8, "MS Shell Dlg", 0, 0, 0x0 +BEGIN + LTEXT "TODO: layout property page",IDC_STATIC,60,73,106,8 +END + +IDD_NEW_CREDS DIALOGEX 0, 0, 300, 166 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN + CONTROL "My Cred Options",IDC_STATIC,"Static",SS_LEFTNOWORDWRAP | SS_SUNKEN | WS_GROUP,7,7,286,11 +END + +IDD_CONFIG DIALOGEX 0, 0, 255, 182 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_SYSMENU +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN +END + +IDD_CONFIG_ID DIALOGEX 0, 0, 235, 151 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_SYSMENU +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN +END + +IDD_CONFIG_IDS DIALOGEX 0, 0, 235, 151 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_SYSMENU +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN +END + + +///////////////////////////////////////////////////////////////////////////// +// +// DESIGNINFO +// + +#ifdef APSTUDIO_INVOKED +GUIDELINES DESIGNINFO +BEGIN + IDD_PP_CRED, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 228 + TOPMARGIN, 7 + BOTTOMMARGIN, 149 + END + + IDD_PP_IDENT, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 228 + TOPMARGIN, 7 + BOTTOMMARGIN, 149 + END + + IDD_NEW_CREDS, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 293 + TOPMARGIN, 7 + BOTTOMMARGIN, 159 + END + + IDD_CONFIG, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 248 + TOPMARGIN, 7 + BOTTOMMARGIN, 175 + END + + IDD_CONFIG_ID, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 228 + TOPMARGIN, 7 + BOTTOMMARGIN, 144 + END + + IDD_CONFIG_IDS, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 228 + TOPMARGIN, 7 + BOTTOMMARGIN, 144 + END +END +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// String Table +// + +STRINGTABLE +BEGIN + IDS_PLUGIN_DESC "My Credentials Provider Plugin" + IDS_CT_SHORT_DESC "My Cred" + IDS_CT_LONG_DESC "My Credential" +END + +STRINGTABLE +BEGIN + IDS_NC_CT_TEMPLATE "

My Cred: %s

" + IDS_NC_CT_TEMPLATE_NL "

%s

" + IDS_GEN_NONE "(none)" + IDS_CFG_SHORT_DESC "My Creds" + IDS_CFG_LONG_DESC "My Creds Options" + IDS_CFG_IDS_SHORT_DESC "My Creds" + IDS_CFG_IDS_LONG_DESC "My Creds Options for all identities" + IDS_CFG_ID_SHORT_DESC "My Creds" + IDS_CFG_ID_LONG_DESC "My Creds Options for this identity" +END + +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/src/windows/identity/sample/templates/credprov/langres.h b/src/windows/identity/sample/templates/credprov/langres.h new file mode 100644 index 0000000000..2b81c554de --- /dev/null +++ b/src/windows/identity/sample/templates/credprov/langres.h @@ -0,0 +1,34 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by C:\work\pismere\athena\auth\krb5\src\windows\identity\sample\templates\credprov\lang\en_us\langres.rc +// +#define IDD_PP_CRED 106 +#define IDD_PP_IDENT 107 +#define IDS_PLUGIN_DESC 109 +#define IDS_CT_SHORT_DESC 110 +#define IDI_PLUGIN 110 +#define IDS_CT_LONG_DESC 111 +#define IDD_NEW_CREDS 112 +#define IDS_NC_CT_TEMPLATE 112 +#define IDS_NC_CT_TEMPLATE_NL 113 +#define IDD_CONFIG 113 +#define IDS_GEN_NONE 114 +#define IDD_CONFIG_ID 114 +#define IDS_CFG_SHORT_DESC 115 +#define IDD_CONFIG_IDS 115 +#define IDS_CFG_LONG_DESC 116 +#define IDS_CFG_IDS_SHORT_DESC 117 +#define IDS_CFG_IDS_LONG_DESC 118 +#define IDS_CFG_ID_SHORT_DESC 119 +#define IDS_CFG_ID_LONG_DESC 120 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 116 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1039 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/src/windows/identity/sample/templates/credprov/main.c b/src/windows/identity/sample/templates/credprov/main.c new file mode 100644 index 0000000000..7a50205739 --- /dev/null +++ b/src/windows/identity/sample/templates/credprov/main.c @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2006 Secure Endpoints Inc. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* $Id$ */ + +#include "credprov.h" + +/* This file provides the entry points for the module. The purpose of + each entry point is explained below. +*/ + +kmm_module h_khModule; /* KMM's handle to this module */ +HINSTANCE hInstance; /* handle to our DLL */ +HMODULE hResModule; /* handle to DLL containing language specific resources */ + +const wchar_t * my_facility = MYPLUGIN_FACILITYW; + +/* locales and n_locales are used to provide information to NetIDMgr + about the locales that we support. Each locale that is supported + is represented by a single line below. NetIDMgr will pick a + suitable locale from this list as described in the documentation + for kmm_set_locale_info(). */ +kmm_module_locale locales[] = { + + /* there needs to be at least one language that is supported. + Here we declare that to be US English, and make it the + default. */ + LOCALE_DEF(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US), + MYPLUGIN_DLLBASEW L"_en_us.dll", /* this is the name of + the DLL. We paste a + trailer to basename + of the DLL. This + DLL should reside in + the same directory + as the plugin + DLL. */ + KMM_MLOC_FLAG_DEFAULT) +}; +int n_locales = ARRAYLENGTH(locales); + +/******************************************************************* + init_module + ***************************************************************** + + This is the entry point for the module. Each module can provide + multiple plugins and each plugin will need a separate entry point. + Generally, the module entry point will set up localized resources + and register the plugins. + +*/ +KHMEXP khm_int32 KHMAPI init_module(kmm_module h_module) { + + khm_int32 rv = KHM_ERROR_SUCCESS; + kmm_plugin_reg pi; + wchar_t description[KMM_MAXCCH_DESC]; + int t; + + h_khModule = h_module; + + rv = kmm_set_locale_info(h_module, locales, n_locales); + if(KHM_SUCCEEDED(rv)) { + /* if the call succeeded, then NetIDMgr has picked a localized + resource DLL for us to use. */ + hResModule = kmm_get_resource_hmodule(h_module); + } else + goto _exit; + + /* TODO: Perform any other required initialization operations. */ + + /* register our plugin */ + ZeroMemory(&pi, sizeof(pi)); + + pi.name = MYPLUGIN_NAMEW; /* name of the plugin */ + pi.type = KHM_PITYPE_CRED; /* type. This is a credentials + provider. Setting this type has + the effect of having the plugin + entrypoint being automatically + subscribed to credentials provider + messages. */ + + /* An icon is optional, but we provide one anyway. */ + pi.icon = LoadImage(hResModule, MAKEINTRESOURCE(IDI_PLUGIN), + IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_DEFAULTSIZE); + pi.flags = 0; + pi.msg_proc = plugin_msg_proc; + pi.description = description; + pi.dependencies = NULL; + t = LoadString(hResModule, IDS_PLUGIN_DESC, + description, ARRAYLENGTH(description)); + if (!t) + description[0] = L'\0'; + else + description[ARRAYLENGTH(description) - 1] = L'\0'; + + rv = kmm_provide_plugin(h_module, &pi); + + /* TODO: register any additional plugins */ + + /* Returning a successful code (KHM_ERROR_SUCCESS) will cause the + plugins to be initialized. If no plugin is successfully + registered while processing init_module or if a code other than + KHM_ERROR_SUCCESS is returned, the module will be immediately + unloaded. */ + + _exit: + return rv; +} + +/********************************************************** + Exit module + ******************************************************** + + Called by the NetIDMgr module manager when unloading the module. + This will get called even if the module is being unloaded due to an + error code returned by init_module(). This callback is required. */ +KHMEXP khm_int32 KHMAPI exit_module(kmm_module h_module) { + + /* Unregistering the plugin is not required at this point. */ + + /* TODO: Perform any other required cleanup here. */ + + return KHM_ERROR_SUCCESS; /* the return code is ignored */ +} + +/* General DLL initialization. It is advisable to not do anything + here and also keep in mind that the plugin will be loaded at a time + where some threads have already started. So DLL_THREAD_ATTACH will + not fire for every thread. In addition, the plugin will be + unloaded before the application and all the threads terminate. */ +BOOL WINAPI DllMain(HINSTANCE hinstDLL, + DWORD fdwReason, + LPVOID lpvReserved) +{ + switch(fdwReason) { + case DLL_PROCESS_ATTACH: + hInstance = hinstDLL; + break; + + case DLL_PROCESS_DETACH: + break; + + case DLL_THREAD_ATTACH: + break; + + case DLL_THREAD_DETACH: + break; + } + + return TRUE; +} diff --git a/src/windows/identity/sample/templates/credprov/plugin.c b/src/windows/identity/sample/templates/credprov/plugin.c new file mode 100644 index 0000000000..31c9626a55 --- /dev/null +++ b/src/windows/identity/sample/templates/credprov/plugin.c @@ -0,0 +1,382 @@ +/* + * Copyright (c) 2006 Secure Endpoints Inc. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* $Id$ */ + +#include "credprov.h" +#include + +/* This file provides the message processing function and the support + routines for implementing our plugin. Note that some of the + message processing routines have been moved to other source files + based on their use. +*/ + +khm_int32 credtype_id = KCDB_CREDTYPE_INVALID; +khm_handle g_credset = NULL; + +/* Handler for system messages. The only two we handle are + KMSG_SYSTEM_INIT and KMSG_SYSTEM_EXIT. */ +khm_int32 KHMAPI +handle_kmsg_system(khm_int32 msg_type, + khm_int32 msg_subtype, + khm_ui_4 uparam, + void * vparam) { + khm_int32 rv = KHM_ERROR_SUCCESS; + + switch (msg_subtype) { + + /* This is the first message that will be received by a + plugin. We use it to perform initialization operations + such as registering any credential types, data types and + attributes. */ + case KMSG_SYSTEM_INIT: + { + kcdb_credtype ct; + wchar_t short_desc[KCDB_MAXCCH_SHORT_DESC]; + wchar_t long_desc[KCDB_MAXCCH_LONG_DESC]; + khui_config_node cnode; + khui_config_node_reg creg; + + /* First and foremost, we need to register a credential + type. */ + ZeroMemory(&ct, sizeof(ct)); + ct.id = KCDB_CREDTYPE_AUTO; + ct.name = MYCREDTYPE_NAMEW; + + short_desc[0] = L'\0'; + LoadString(hResModule, IDS_CT_SHORT_DESC, + short_desc, ARRAYLENGTH(short_desc)); + + long_desc[0] = L'\0'; + LoadString(hResModule, IDS_CT_LONG_DESC, + long_desc, ARRAYLENGTH(long_desc)); + + ct.icon = NULL; /* We skip the icon for now, but you + can assign a handle to an icon + here. The icon will be used to + represent the credentials type.*/ + + kmq_create_subscription(plugin_msg_proc, &ct.sub); + + ct.is_equal = cred_is_equal; + + rv = kcdb_credtype_register(&ct, &credtype_id); + + /* We create a global credential set that we use in the + plug-in thread. This alleviates the need to create one + everytime we need one. Keep in mind that this should + only be used in the plug-in thread and should not be + touched from the UI thread or any other thread. */ + kcdb_credset_create(&g_credset); + + /* TODO: Perform additional initialization operations. */ + + /* TODO: Also list out the credentials of this type that + already exist. */ + + /* Now we register our configuration panels. */ + + + /* This configuration panel is the one that controls + general options. We leave the identity specific and + identity defaults for other configuration panels. */ + + ZeroMemory(&creg, sizeof(creg)); + + short_desc[0] = L'\0'; + + LoadString(hResModule, IDS_CFG_SHORT_DESC, + short_desc, ARRAYLENGTH(short_desc)); + + long_desc[0] = L'\0'; + + LoadString(hResModule, IDS_CFG_LONG_DESC, + long_desc, ARRAYLENGTH(long_desc)); + + creg.name = CONFIGNODE_MAIN; + creg.short_desc = short_desc; + creg.long_desc = long_desc; + creg.h_module = hResModule; + creg.dlg_template = MAKEINTRESOURCE(IDD_CONFIG); + creg.dlg_proc = config_dlgproc; + creg.flags = 0; + + khui_cfg_register(NULL, &creg); + + /* Now we do the identity specific and identity default + configuration panels. "KhmIdentities" is a predefined + configuration node under which all the identity spcific + configuration is managed. */ + + if (KHM_FAILED(khui_cfg_open(NULL, L"KhmIdentities", &cnode))) { + /* this should always work */ + assert(FALSE); + rv = KHM_ERROR_NOT_FOUND; + break; + } + + /* First the tab panel for defaults for all identities */ + + ZeroMemory(&creg, sizeof(creg)); + + short_desc[0] = L'\0'; + LoadString(hResModule, IDS_CFG_IDS_SHORT_DESC, + short_desc, ARRAYLENGTH(short_desc)); + long_desc[0] = L'\0'; + LoadString(hResModule, IDS_CFG_IDS_LONG_DESC, + long_desc, ARRAYLENGTH(long_desc)); + + creg.name = CONFIGNODE_ALL_ID; + creg.short_desc = short_desc; + creg.long_desc = long_desc; + creg.h_module = hResModule; + creg.dlg_template = MAKEINTRESOURCE(IDD_CONFIG_IDS); + creg.dlg_proc = config_ids_dlgproc; + creg.flags = KHUI_CNFLAG_SUBPANEL; + + khui_cfg_register(cnode, &creg); + + /* Now the panel for per identity configuration */ + + ZeroMemory(&creg, sizeof(creg)); + + short_desc[0] = L'\0'; + LoadString(hResModule, IDS_CFG_ID_SHORT_DESC, + short_desc, ARRAYLENGTH(short_desc)); + long_desc[0] = L'\0'; + LoadString(hResModule, IDS_CFG_ID_LONG_DESC, + long_desc, ARRAYLENGTH(long_desc)); + + creg.name = CONFIGNODE_PER_ID; + creg.short_desc = short_desc; + creg.long_desc = long_desc; + creg.h_module = hResModule; + creg.dlg_template = MAKEINTRESOURCE(IDD_CONFIG_ID); + creg.dlg_proc = config_id_dlgproc; + creg.flags = KHUI_CNFLAG_SUBPANEL | KHUI_CNFLAG_PLURAL; + + khui_cfg_register(cnode, &creg); + + khui_cfg_release(cnode); + } + break; + + /* This is the last message that will be received by the + plugin. */ + case KMSG_SYSTEM_EXIT: + { + khui_config_node cnode; + khui_config_node cn_idents; + + /* It should not be assumed that initialization of the + plugin went well at this point since we receive a + KMSG_SYSTEM_EXIT even if the initialization failed. */ + + if (credtype_id != KCDB_CREDTYPE_INVALID) { + kcdb_credtype_unregister(credtype_id); + credtype_id = KCDB_CREDTYPE_INVALID; + } + + if (g_credset) { + kcdb_credset_delete(g_credset); + g_credset = NULL; + } + + /* Now unregister any configuration nodes we registered. */ + + if (KHM_SUCCEEDED(khui_cfg_open(NULL, CONFIGNODE_MAIN, &cnode))) { + khui_cfg_remove(cnode); + khui_cfg_release(cnode); + } + + if (KHM_SUCCEEDED(khui_cfg_open(NULL, L"KhmIdentities", &cn_idents))) { + if (KHM_SUCCEEDED(khui_cfg_open(cn_idents, + CONFIGNODE_ALL_ID, + &cnode))) { + khui_cfg_remove(cnode); + khui_cfg_release(cnode); + } + + if (KHM_SUCCEEDED(khui_cfg_open(cn_idents, + CONFIGNODE_PER_ID, + &cnode))) { + khui_cfg_remove(cnode); + khui_cfg_release(cnode); + } + + khui_cfg_release(cn_idents); + } + + /* TODO: Perform additional uninitialization + operations. */ + } + break; + } + + return rv; +} + +/* Handler for credentials the refresh message. */ +khm_int32 +handle_kmsg_cred_refresh(void) { + /* TODO: Re-enumerate the credentials of our credentials type */ + + /* + Re-enumerating credentials would look something like this: + + - flush all credentials from g_credset (kcdb_credset_flush()) + + - list out the credentials and add them to g_credset + + - collect the credentials from g_credset to the root credentials + set. (kcdb_credset_collect()) + + Note that when listing credentials, each credential must be + populated with enough information to locate the actual + credential at a later time. + */ + + return KHM_ERROR_SUCCESS; +} + +/* Handler for destroying credentials */ +khm_int32 +handle_kmsg_cred_destroy_creds(khui_action_context * ctx) { + /* TODO: Destroy credentials of our type as specified by the + action context passed in through vparam. */ + + /* The credential set in ctx->credset contains the credentials + that are to be destroyed. */ + + return KHM_ERROR_SUCCESS; +} + +/* Begin a property sheet */ +khm_int32 +handle_kmsg_cred_pp_begin(khui_property_sheet * ps) { + + /* TODO: Provide the information necessary to show a property + page for a credentials belonging to our credential type. */ + + PROPSHEETPAGE *p; + + if (ps->credtype == credtype_id && + ps->cred) { + /* We have been requested to show a property sheet for one of + our credentials. */ + p = malloc(sizeof(*p)); + ZeroMemory(p, sizeof(*p)); + + p->dwSize = sizeof(*p); + p->dwFlags = 0; + p->hInstance = hResModule; + p->pszTemplate = MAKEINTRESOURCE(IDD_PP_CRED); + p->pfnDlgProc = pp_cred_dlg_proc; + p->lParam = (LPARAM) ps; + khui_ps_add_page(ps, credtype_id, 0, p, NULL); + } + + return KHM_ERROR_SUCCESS; +} + +/* End a property sheet */ +khm_int32 +handle_kmsg_cred_pp_end(khui_property_sheet * ps) { + /* TODO: Handle the end of a property sheet. */ + + khui_property_page * p = NULL; + + khui_ps_find_page(ps, credtype_id, &p); + if (p) { + if (p->p_page) + free(p->p_page); + p->p_page = NULL; + } + + return KHM_ERROR_SUCCESS; +} + +/* IP address change notification */ +khm_int32 +handle_kmsg_cred_addr_change(void) { + /* TODO: Handle this message. */ + + return KHM_ERROR_SUCCESS; +} + +/* Message dispatcher for credentials messages. */ +khm_int32 KHMAPI +handle_kmsg_cred(khm_int32 msg_type, + khm_int32 msg_subtype, + khm_ui_4 uparam, + void * vparam) { + khm_int32 rv = KHM_ERROR_SUCCESS; + + switch(msg_subtype) { + case KMSG_CRED_REFRESH: + return handle_kmsg_cred_refresh(); + + case KMSG_CRED_DESTROY_CREDS: + return handle_kmsg_cred_destroy_creds((khui_action_context *) vparam); + + case KMSG_CRED_PP_BEGIN: + return handle_kmsg_cred_pp_begin((khui_property_sheet *) vparam); + + case KMSG_CRED_PP_END: + return handle_kmsg_cred_pp_end((khui_property_sheet *) vparam); + + case KMSG_CRED_ADDR_CHANGE: + return handle_kmsg_cred_addr_change(); + + default: + /* Credentials acquisition messages are all handled in a + different source file. */ + if (IS_CRED_ACQ_MSG(msg_subtype)) + return handle_cred_acq_msg(msg_type, msg_subtype, + uparam, vparam); + } + + return rv; +} + + +/* This is the main message handler for our plugin. All the plugin + messages end up here where we either handle it directly or dispatch + it to other handlers. */ +khm_int32 KHMAPI plugin_msg_proc(khm_int32 msg_type, + khm_int32 msg_subtype, + khm_ui_4 uparam, + void * vparam) { + + switch(msg_type) { + case KMSG_SYSTEM: + return handle_kmsg_system(msg_type, msg_subtype, uparam, vparam); + + case KMSG_CRED: + return handle_kmsg_cred(msg_type, msg_subtype, uparam, vparam); + } + + return KHM_ERROR_SUCCESS; +} diff --git a/src/windows/identity/sample/templates/credprov/proppage.c b/src/windows/identity/sample/templates/credprov/proppage.c new file mode 100644 index 0000000000..734a58ee4c --- /dev/null +++ b/src/windows/identity/sample/templates/credprov/proppage.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2006 Secure Endpoints Inc. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* $Id$ */ + +#include "credprov.h" + +/* Dialog procedure and support code for displaying property sheets + for credentials of type MyCred. */ + +/* Dialog procedure for the property sheet. This will run under the + UI thread when a property sheet is being displayed for one of our + credentials.. */ +INT_PTR CALLBACK +pp_cred_dlg_proc(HWND hwnd, + UINT uMsg, + WPARAM wParam, + LPARAM lParam) { + + switch (uMsg) { + case WM_INITDIALOG: + { + khui_property_sheet * ps; + PROPSHEETPAGE * p; + + p = (PROPSHEETPAGE *) lParam; + ps = (khui_property_sheet *) p->lParam; + + /* TODO: Populate the property sheet controls with values + extracted from the credential. (ps->cred) */ + + return FALSE; + } + } + + return FALSE; +} + diff --git a/src/windows/identity/sample/templates/credprov/version.rc b/src/windows/identity/sample/templates/credprov/version.rc new file mode 100644 index 0000000000..c27766761d --- /dev/null +++ b/src/windows/identity/sample/templates/credprov/version.rc @@ -0,0 +1,94 @@ +/* Copyright (c) 2006 Secure Endpoints Inc. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +/* $Id$ */ + +#include "credprov.h" +#include + +/* We use the same version.rc file for the main plugin DLL as well as + for the localized resource DLLs.*/ + +#ifndef LANGVER + +#define STR_FILEDESC "My Credentials Provider Plugin for NetIDMgr" +#define STR_INTNAME MYPLUGIN_NAME +#define STR_ORIGNAME MYPLUGIN_DLLBASE ".dll" + +#else + +#ifdef LANG_en_us + +#define STR_FILEDESC "English(US) language resources for My Credentials Provider" +#define STR_INTNAME MYPLUGIN_DLLBASE "_en_us" +#define STR_ORIGNAME MYPLUGIN_DLLBASE "_en_us.dll" + +#else + +#error Unknown langugae + +#endif + +#endif + +1 VERSIONINFO + FILEVERSION VERSION_LISTC + PRODUCTVERSION VERSION_LISTC + FILEFLAGSMASK KH_VER_FILEFLAGMASK + FILEFLAGS KH_VER_FILEFLAGS + FILEOS KH_VER_FILEOS + FILETYPE KH_VER_FILETYPEDLL + FILESUBTYPE 0 + { + + BLOCK "StringFileInfo" + { + BLOCK "040904b0" + { + VALUE "CompanyName", "My Company" + VALUE "FileDescription", "My Credentials Provider Plugin" + VALUE "FileVersion", VERSION_STRING + VALUE "InternalName", STR_INTNAME + VALUE "LegalCopyright", "(C) 2006 My Company" + VALUE "OriginalFilename", STR_ORIGNAME + VALUE "ProductName", "My Plugin Product" + VALUE "ProductVersion", VERSION_STRING +#ifndef LANGVER + VALUE NIMV_MODULE, MYMODULE_NAME + +/* if more than one plugin is provided by this module, then all of + those plugins should be listed here separated by commas. */ + VALUE NIMV_PLUGINS, MYPLUGIN_NAME + + VALUE NIMV_APIVER, KH_VERSION_STRINGAPI + VALUE NIMV_SUPPORT, "http://example.com/myplugin" +#endif + } + } + + BLOCK "VarFileInfo" + { + VALUE "Translation", 0x409, 1200 + } + }