]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
LDAP GSSAPI log improvements 4477/head
authorGrégory Oestreicher <greg@kamago.net>
Fri, 16 Sep 2016 09:16:20 +0000 (11:16 +0200)
committerGrégory Oestreicher <greg@kamago.net>
Tue, 28 Feb 2017 21:38:32 +0000 (22:38 +0100)
modules/ldapbackend/ldapauthenticator.cc
modules/ldapbackend/ldapauthenticator_p.hh

index b2944cdc34b23856e204153185a51fe35e684e62..c2fa875c206ad9e7f975056a394ee2d31a618c79 100644 (file)
@@ -83,7 +83,7 @@ static int ldapGssapiAuthenticatorSaslInteractCallback( LDAP *conn, unsigned fla
 }
 
 LdapGssapiAuthenticator::LdapGssapiAuthenticator( const std::string& kt, const std::string &ccache, int tmout )
-  : keytabFile( kt ), cCacheFile( ccache ), timeout( tmout )
+  : logPrefix( "[LDAP GSSAPI] " ), keytabFile( kt ), cCacheFile( ccache ), timeout( tmout )
 {
 }
 
@@ -96,11 +96,11 @@ bool LdapGssapiAuthenticator::authenticate( LDAP *conn )
   }
   else if ( code == -2 ) {
     // Here it may be possible to retry after obtainting a fresh ticket
-    L<<Logger::Debug << "LDAP GSSAPI" << "No TGT found, trying to acquire a new one" << std::endl;
+    L<<Logger::Debug << logPrefix << "No TGT found, trying to acquire a new one" << std::endl;
     code = updateTgt();
 
     if ( attemptAuth( conn ) != 0 ) {
-      L<<Logger::Error << "LDAP GSSAPI" << "Failed to acquire a TGT" << std::endl;
+      L<<Logger::Error << logPrefix << "Failed to acquire a TGT" << std::endl;
       return false;
     }
   }
@@ -145,7 +145,7 @@ int LdapGssapiAuthenticator::attemptAuth( LDAP *conn )
   int rc = ldap_sasl_interactive_bind_s( conn, "", defaults.mech.c_str(),
                                          NULL, NULL, LDAP_SASL_QUIET,
                                          ldapGssapiAuthenticatorSaslInteractCallback, &defaults );
-  L<<Logger::Debug << "LDAP GSSAPI" << "ldap_sasl_interactive_bind_s returned " << rc << std::endl;
+  L<<Logger::Debug << logPrefix << "ldap_sasl_interactive_bind_s returned " << rc << std::endl;
 
   if ( rc == LDAP_LOCAL_ERROR ) {
     // This may mean that the ticket has expired, so let the caller know
@@ -171,7 +171,7 @@ int LdapGssapiAuthenticator::updateTgt()
   krb5_get_init_creds_opt *options;
 
   if ( ( code = krb5_init_context( &context ) ) != 0 ) {
-    L<<Logger::Error << "LDAP GSSAPI" << "Failed to init krb5 context" << std::endl;
+    L<<Logger::Error << logPrefix << "Failed to init krb5 context" << std::endl;
     return code;
   }
 
@@ -184,14 +184,14 @@ int LdapGssapiAuthenticator::updateTgt()
   }
   
   if ( code != 0 ) {
-    L<<Logger::Error << "LDAP GSSAPI" << "krb5 error: " << std::string( krb5_get_error_message( context, code ) ) << std::endl;
+    L<<Logger::Error << logPrefix << "krb5 error when locating the keytab file: " << std::string( krb5_get_error_message( context, code ) ) << std::endl;
     return code;
   }
 
   // Extract the principal name from the keytab
   krb5_kt_cursor cursor;
   if ( ( code = krb5_kt_start_seq_get( context, keytab, &cursor ) ) != 0 ) {
-    L<<Logger::Error << "LDAP GSSAPI" << "krb5 error: " << std::string( krb5_get_error_message( context, code ) ) << std::endl;
+    L<<Logger::Error << logPrefix << "krb5 error when initiating keytab search: " << std::string( krb5_get_error_message( context, code ) ) << std::endl;
     krb5_kt_close( context, keytab );
     return code;
   }
@@ -204,7 +204,7 @@ int LdapGssapiAuthenticator::updateTgt()
 
   krb5_kt_end_seq_get( context, keytab, &cursor );
   if ( code != 0 ) {
-    L<<Logger::Error << "LDAP GSSAPI" << "krb5 error: " << std::string( krb5_get_error_message( context, code ) ) << std::endl;
+    L<<Logger::Error << logPrefix << "krb5 error when extracting principal information: " << std::string( krb5_get_error_message( context, code ) ) << std::endl;
     krb5_kt_close( context, keytab );
     krb5_free_principal( context, principal );
     return code;
@@ -220,7 +220,7 @@ int LdapGssapiAuthenticator::updateTgt()
   }
 
   if ( code != 0 ) {
-    L<<Logger::Error << "LDAP GSSAPI" << "krb5 error: " << std::string( krb5_get_error_message( context, code ) ) << std::endl;
+    L<<Logger::Error << logPrefix << "krb5 error when locating the credentials cache file: " << std::string( krb5_get_error_message( context, code ) ) << std::endl;
     krb5_kt_close( context, keytab );
     krb5_free_principal( context, principal );
     return code;
@@ -228,14 +228,14 @@ int LdapGssapiAuthenticator::updateTgt()
 
   // Initialize the credentials cache file
   if ( ( code = krb5_cc_initialize( context, ccache, principal ) ) != 0 ) {
-    L<<Logger::Error << "LDAP GSSAPI" << "krb5 error: " << std::string( krb5_get_error_message( context, code ) ) << std::endl;
+    L<<Logger::Error << logPrefix << "krb5 error when initializing the credentials cache file: " << std::string( krb5_get_error_message( context, code ) ) << std::endl;
     krb5_kt_close( context, keytab );
     krb5_free_principal( context, principal );
     return code;
   }
 
   if ( ( code = krb5_get_init_creds_opt_alloc( context, &options ) ) != 0 ) {
-    L<<Logger::Error << "LDAP GSSAPI" << "krb5 error: " << std::string( krb5_get_error_message( context, code ) ) << std::endl;
+    L<<Logger::Error << logPrefix << "krb5 error when allocating credentials cache structure: " << std::string( krb5_get_error_message( context, code ) ) << std::endl;
     krb5_kt_close( context, keytab );
     krb5_free_principal( context, principal );
     return code;
@@ -249,7 +249,7 @@ int LdapGssapiAuthenticator::updateTgt()
   krb5_free_principal( context, principal );
 
   if ( code == 0 ) {
-    L<<Logger::Error << "LDAP GSSAPI" << "krb5 error: " << std::string( krb5_get_error_message( context, code ) ) << std::endl;
+    L<<Logger::Error << logPrefix << "krb5 error when getting the TGT: " << std::string( krb5_get_error_message( context, code ) ) << std::endl;
     code = krb5_cc_store_cred( context, ccache, &credentials );
     krb5_free_cred_contents( context, &credentials );
     krb5_cc_close( context, ccache );
index 9c3029222322679b43cf13597c611a1031d3712c..e3fff8c4a443a109c9fe79bf42e8970f9372d3db 100644 (file)
@@ -42,6 +42,7 @@ class LdapSimpleAuthenticator : public LdapAuthenticator
 
 class LdapGssapiAuthenticator : public LdapAuthenticator
 {
+    std::string logPrefix;
     std::string keytabFile;
     std::string cCacheFile;
     int timeout;