Commit 6cc13fbf authored by Marvin S. Addison's avatar Marvin S. Addison
Browse files

Add ED-ID WinLDAP sample.


git-svn-id: https://svn.middleware.vt.edu/svn/ed/edsamples@10068 fa4a4108-76f2-0310-9f0d-ba9fffaf4ff6
parent c16f22ba
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="EdIdSample"
ProjectGUID="{F5E35542-CFBA-4C02-840D-20C270E50EF9}"
RootNamespace="EdIdSample"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="4"
CompileAs="1"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalOptions="/VERBOSE"
AdditionalDependencies="&quot;C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib\Wldap32.lib&quot;"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="1"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="1"
GenerateDebugInformation="true"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\edid.c"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
/**
* edid.c
* This code is an example of how to connect to ED-ID, do a
* SASL EXTERNAL bind with a client certificate, search for a user,
* print out the user's attributes, and then determine if the user
* has the proper affiliation specified. This is but the tip of the
* iceberg for authorization that can be done with ED-ID.
*
* Notes: * You must have a client certificate that has been issued
* by the VT Middleware CA to connect to ED-ID.
* * You must have a service entry that corresponds to your
* client certificate to be able to view entries
* * The VT Root CA certificate must be installed into the Local Machine
* certificate store prior to running this sample.
* Root certificate is available at http://www.pki.vt.edu/download/root/cacert.crt.
* * Your client certificate must be installed into the Local Machine
* certificate store prior to running this sample.
* * You must link this against wldap32.lib
*/
#include <windows.h>
#include <ntldap.h>
#include <winldap.h>
#include <stdio.h>
#include <winber.h>
/**
* Do a SASL EXTERNAL bind, search for the user with the supplied UUPID,
* print all attributes for the person, determine if the person has the
* specified affiliation.
*/
int main(int argc, char* argv[])
{
LDAP* ld = NULL;
INT retVal = 0;
PCHAR pHost = "id.directory.vt.edu";
int port = 636;
char* base = "ou=people,dc=vt,dc=edu";
char* filter = "(uupid=UUPID)";
LDAPMessage *result, *entry;
char *dn;
char *cmpAttr = "virginiaTechAffiliation";
char *cmpVal = "VT-ACTIVE-MEMBER";
struct berval cred;
struct berval *servercredp;
ULONG version = LDAP_VERSION3;
char *attribute;
BerElement *ber;
char **values;
int i;
cred.bv_val = "";
cred.bv_len = strlen(cred.bv_val)*sizeof(char);
printf("\nConnecting to %s:%d ...\n", pHost, port);
// Create an LDAP session.
ld = ldap_sslinit(pHost, port, 1);
if (ld == NULL)
{
printf( "ldap_sslinit failed with 0x%x.\n",GetLastError());
return -1;
}
// Specify version 3; the default is version 2.
printf("Setting Protocol version to 3.\n");
retVal = ldap_set_option(ld,
LDAP_OPT_PROTOCOL_VERSION,
(void*)&version);
retVal = ldap_set_option(ld,LDAP_OPT_SSL,LDAP_OPT_ON);
// Connect to the server.
retVal = ldap_connect(ld, NULL);
if(retVal == LDAP_SUCCESS)
printf("ldap_connect succeeded \n");
else
{
printf("ldap_connect failed with 0x%x.\n",retVal);
return 1;
}
// Perform a SASL EXTERNAL bind. The CN of your client certificate
// will be your service's UUSID
retVal = ldap_sasl_bind_s(ld, "", "EXTERNAL" , &cred, NULL, NULL, &servercredp);
if(retVal != LDAP_SUCCESS)
printf("ldap_sasl_bind_s failed with 0x%x\n", retVal);
else
printf("ldap_sasl_bind_s succeeded\n");
// Search for a person by UUPID
retVal = ldap_search_s(ld, base, LDAP_SCOPE_SUBTREE, filter, NULL, NULL, &result);
if(retVal != LDAP_SUCCESS)
printf("ldap_search_s failed with 0x%x.\n",retVal);
// Get the first entry and its DN
entry = ldap_first_entry(ld, result);
dn = ldap_get_dn(ld, entry);
// Print out all viewable attributes for the person
if(entry != NULL)
{
for(attribute = ldap_first_attribute(ld, entry, &ber);
attribute != NULL;
attribute = ldap_next_attribute(ld, entry, ber))
{
if((values = ldap_get_values(ld, entry, attribute)) != NULL)
{
for(i = 0; values[i] != NULL; i++)
{
printf("%s: %s\n", attribute, values[i]);
}
ldap_value_free(values);
}
ldap_memfree(attribute);
}
if(ber != NULL)
{
ber_free(ber, 0);
}
}
ldap_msgfree(result);
// Determine if the person has the specified affiliation
retVal = ldap_compare_s(ld, dn, cmpAttr, cmpVal);
if(retVal != LDAP_COMPARE_TRUE)
printf("ldap_compare_s failed with 0x%x.\n",retVal);
else
printf("\n%s == %s", cmpAttr, cmpVal);
ldap_memfree(dn);
ldap_unbind_s(ld);
return 0;
}
......@@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "EdAuthSample", "EdAuthSample\EdAuthSample.vcproj", "{6819D686-0A93-408F-8693-B1458A877AEE}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "EdIdSample", "EdIdSample\EdIdSample.vcproj", "{F5E35542-CFBA-4C02-840D-20C270E50EF9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
......@@ -13,6 +15,10 @@ Global
{6819D686-0A93-408F-8693-B1458A877AEE}.Debug|Win32.Build.0 = Debug|Win32
{6819D686-0A93-408F-8693-B1458A877AEE}.Release|Win32.ActiveCfg = Release|Win32
{6819D686-0A93-408F-8693-B1458A877AEE}.Release|Win32.Build.0 = Release|Win32
{F5E35542-CFBA-4C02-840D-20C270E50EF9}.Debug|Win32.ActiveCfg = Debug|Win32
{F5E35542-CFBA-4C02-840D-20C270E50EF9}.Debug|Win32.Build.0 = Debug|Win32
{F5E35542-CFBA-4C02-840D-20C270E50EF9}.Release|Win32.ActiveCfg = Release|Win32
{F5E35542-CFBA-4C02-840D-20C270E50EF9}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment