Perforce Public Knowledge Base - Authentication Triggers: Compiling the Examples
× PRODUCTS SOLUTIONS CUSTOMERS LEARN SUPPORT
Downloads Blog Company Integrations Careers Contact Try Free
Menu Search
Perforce
Reset Search
 

 

Article

Authentication Triggers: Compiling the Examples

« Go Back

Information

 
Problem

What do I need to compile the LDAP trigger examples?

What are the dependencies?

Solution

TASK

What do I need to compile the LDAP trigger examples?

What are the dependencies?

 

DETAILS

Perl (required for p4authenticate.pl)

Confirm that you have these two modules installed before you run the p4authenticate.pl Perl script:

You can obtain both modules, if missing, from the Comprehensive Perl Archive Network (CPAN).

Module installation under Unix/Cygwin/Mac OS X

To install Perl modules, enter the following commands:

perl -MCPAN -e 'install "Net::LDAP"'
perl -MCPAN -e 'install "Authen::SASL"'

To see what modules you already have installed, paste the following code into a new text document:

#!/usr/local/bin/perl

use ExtUtils::Installed;
my $instmod = ExtUtils::Installed->new();
foreach my $module ($instmod->modules()) {
my $version = $instmod->version($module) || "???";
       print "$module -- $version\n";
}

Save this text file as "checkmod.pl".

Run the following script from the command line:

perl checkmod.pl

You now have a list of installed modules. If you have a large number of modules installed, you can pare down the listing by piping through "grep". For example:

perl checkmod.pl | grep -E 'LDAP|SASL'

Module installation under Windows using ActivePerl for Windows

To install Perl modules, enter these commands:

ppm install Net::LDAP
ppm install Authen::SASL

You can check a list of installed modules with the command:

ppm list

C/C++ (required for p4authenticate.c and p4auth_ad and p4auth_ad-no_null.cpp)

UNIX/Linux/CygWin/MacOS X

To properly compile the C example, you need to have a compatible LDAP library. You can obtain one from a variety of sources, including OpenLDAP, which comes installed on many systems.

To compile p4authenticate.c or p4auth_ad.cpp or p4auth_ad-no_null.cpp enter the following command:

g++ -o p4authenticate p4authenticate.c -lldap
or
g++ p4auth_ad.cpp -lldap -o p4auth_ad
or
g++ p4auth_ad-no_null.cpp -lldap -o p4auth_ad-no_null

Troubleshooting
 

The command:

g++ p4auth_ad.cpp -lldap

Returns:

p4auth_ad.cpp: In function 'int authCheck(char*, char*, char*, char*, char*)':                          
p4auth_ad.cpp:52: error: 'ldap_init' was not declared in this scope                                     
p4auth_ad.cpp:62: error: 'ldap_bind_s' was not declared in this scope                                   
p4auth_ad.cpp:108: error: 'ldap_unbind' was not declared in this scope 

Fixed by adding "-DLDAP_DEPRECATED" to the "g++" options.

$ g++ p4auth_ad.cpp -DLDAP_DEPRECATED -lldap -o p4auth_ad
$
$ ./p4auth_ad 192.168.100.80 389 DC=ad,DC=foo,DC=com bruno
<password>
Success:  Password verified.

where ad.foo.com is the Active Directory server and bruno is a valid name on the Active Directory server and <password> and the enter key is pressed after the command is run (there will be no prompt).

The command:

gcc p4auth_ad-debug4.cpp -DLDAP_DEPRECATED -lldap

Returns:

/tmp/cctXiSGp.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

Fixed by using "g++" instead of "gcc".
 

Solaris (required for p4auth_ad-no_null.cpp)

perforce p-perforce02 /home/perforce: g++ -o p4auth_ad
p4auth_ad-unix-no_null.cpp
p4auth_ad-unix-no_null.cpp: In function `int main(int, char**)':
p4auth_ad-unix-no_null.cpp:23: error: `strlen' undeclared (first use this function)
p4auth_ad-unix-no_null.cpp:23: error: (Each undeclared identifier is reported only once for each function it appears in.)
p4auth_ad-unix-no_null.cpp: In function `int authCheck(char*, char*, char*, char*)':
p4auth_ad-unix-no_null.cpp:76: error: `strcasecmp' undeclared (first use thisfunction)
  1. If you get undeclared variables errors like the following:
You can fix them by adding
#include <string.h>
to the top of the .cpp file.
 

Windows

The LDAP dll that the trigger is compiled against should exist on W2K, XP and 2K3 platforms in the form of wldap32.dll. If the dll is not present, you might get a pop-up error when running the trigger manually, or it does not work at all. If you have the wrong version, you might see the error "invalid ordinal 330 in winldap.dll" or similar when you try to run p4authenticate.exe.

You need the Microsoft Platform SDK, which should come with an MS Visual Studio installation. You can download the SDK if it did not come with your Visual Studio installation. Note that the free version of the MS Visual C compiler has trouble with the header files included with the Platform SDK, so if possible, use MSVS.

To build

First run vcvars32.bat to set the environment:

C:\build>vcvars32.bat

Then compile:

C:\build>cl /EHs p4authenticate.cpp /link Wldap32.Lib

Some debug information if your environment is broken:

C:\build>more vcvars32.bat
"%VS71COMNTOOLS%vsvars32.bat"

C:\build>env | grep -i vs71comntools

VS71COMNTOOLS=C:\Program Files\Microsoft Visual Studio .NET 2003\Common7Tools
  • The next errors you will receive are
    perforce p-perforce02 /home/perforce: g++ -o p4auth_ad
    p4auth_ad-unix-no_null.cpp
    Undefined                       first referenced
     symbol                             in file
    ldap_err2string                     /var/tmp//cccnKTQB.o
    ldap_bind_s                         /var/tmp//cccnKTQB.o
    ldap_unbind                         /var/tmp//cccnKTQB.o
    ldap_init                           /var/tmp//cccnKTQB.o
    ldap_set_option                     /var/tmp//cccnKTQB.o
    ld: fatal: Symbol referencing errors. No output written to p4auth_ad
    collect2: ld returned 1 exit status
    
    which can be fixed by adding -lldap
    g++ -o p4auth_ad p4auth_ad-unix-no_null.cpp -lldap
    
Related Links
ActivePerl for Windows (External site)
Authen::SASL Perl Module (External site)
Comprehensive Perl Archive Network (CPAN) (External site)
CygWin (External Site)
Net::LDAP Perl Module (External site)
OpenLDAP (External site)
p4authenticate.c (Example authentication trigger)
p4authenticate.pl (Example authentication trigger)

Feedback

 

Was this article helpful?


   

Feedback

Please tell us how we can make this article more useful.

Characters Remaining: 255