#include <stdio.h> #include <stdlib.h> #include <ldap.h> #define AUTH_METHOD LDAP_AUTH_SIMPLE int requested_version = LDAP_VERSION3; int authCheck( char *host, char *port, char* bind_dn, char* bind_pw); int main(int argc, char **argv); main(int argc, char **argv) { char oldPassword[128]; if( argc != 4 ) { printf( "Wrong number of arguments!\n" ); printf( "Usage: p4authenticate [IP] [Port] [user]\n"); printf( "Example: p4authenticate 1.2.3.4 389 bob \n"); exit( -1 ); } if(strlen(argv[3]) == 0) { printf("Error: NULL user names are not allowed.\n"); exit (-1); } /* read the password from <stdin> and truncate the newline */ if( fgets( oldPassword, 128, stdin ) == NULL ) { printf( "Didn't receive old password!\n" ); exit( -1 ); } oldPassword[ strlen(oldPassword) - 1 ] = '\0'; if(strlen(oldPassword) == 0) { printf("Error: NULL passwords are not allowed.\n"); exit (-1); } return( authCheck( argv[1], argv[2], argv[3], oldPassword) ); } int authCheck( char *host, char *port, char* bind_dn, char* bind_pw) { LDAP *ld; int rc; int portnumber = atoi( port ); /* Get a handle to an LDAP connection. */ if( ( ld = ldap_init( host, portnumber ) ) == NULL ) { printf( "Can't initialize connection to %s : %d\n" , host, portnumber ); return( -1 ); } ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &requested_version ); /* bind */ rc = ldap_bind_s( ld, bind_dn, bind_pw, AUTH_METHOD ); /* check result, report errors */ if ( rc != LDAP_SUCCESS ) { if (strcasecmp("Invalid credentials", ldap_err2string(rc)) == 0) { printf( "Error: Password incorrect (%s).\n", ldap_err2string(rc) ); } else { printf("Error: %s.\n",ldap_err2string(rc)); } return( -1 ); } printf("Success: Password verified.\n"); ldap_unbind( ld ); return( 0 ); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 5974 | Ashish Melanta | Pulling in the Perforce utils into my guest branch | ||
//guest/perforce_software/triggers/auth/p4auth_ad-unix-no_null.cpp | |||||
#1 | 5478 | dsteele |
Triggers that do not accept null passwords. The other trigger doesn't work With null passwords in some environments. In those environments this trigger should be used instead. |