From: Amos Jeffries Date: Thu, 8 Jul 2010 11:01:47 +0000 (+1200) Subject: Helpers: upgrade digest helpers to C++ X-Git-Tag: SQUID_3_2_0_1~77 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=56ff468707b9146dc19a5c519fd421dd2b9cfcb9;p=thirdparty%2Fsquid.git Helpers: upgrade digest helpers to C++ --- diff --git a/configure.in b/configure.in index ae8e885284..a91957e291 100644 --- a/configure.in +++ b/configure.in @@ -3821,7 +3821,7 @@ AC_CONFIG_FILES([\ helpers/digest_auth/Makefile \ helpers/digest_auth/eDirectory/Makefile \ helpers/digest_auth/file/Makefile \ - helpers/digest_auth/ldap/Makefile \ + helpers/digest_auth/LDAP/Makefile \ helpers/ntlm_auth/Makefile \ helpers/ntlm_auth/fake/Makefile \ helpers/ntlm_auth/smb_lm/Makefile \ diff --git a/helpers/digest_auth/ldap/Makefile.am b/helpers/digest_auth/LDAP/Makefile.am similarity index 51% rename from helpers/digest_auth/ldap/Makefile.am rename to helpers/digest_auth/LDAP/Makefile.am index a16d39fa47..cb7ec9f522 100644 --- a/helpers/digest_auth/ldap/Makefile.am +++ b/helpers/digest_auth/LDAP/Makefile.am @@ -1,26 +1,16 @@ -# -# Makefile for the Squid Object Cache server -# -# $Id$ -# -# Uncomment and customize the following to suit your needs: -# - include $(top_srcdir)/src/Common.am ## we need our local files too (but avoid -I. at all costs) INCLUDES += -I$(srcdir) - libexec_PROGRAMS = digest_ldap_auth -digest_ldap_auth_SOURCES = digest_pw_auth.c \ +digest_ldap_auth_SOURCES = digest_pw_auth.cc \ digest_common.h \ - ldap_backend.c \ + ldap_backend.cc \ ldap_backend.h -LDADD = \ - $(top_builddir)/compat/libcompat.la \ - -L$(top_builddir)/lib -lmiscutil \ +digest_ldap_auth_LDADD = \ + $(COMPAT_LIB) \ $(LDAPLIB) \ $(LBERLIB) \ $(CRYPTLIB) \ diff --git a/helpers/digest_auth/ldap/config.test b/helpers/digest_auth/LDAP/config.test similarity index 100% rename from helpers/digest_auth/ldap/config.test rename to helpers/digest_auth/LDAP/config.test diff --git a/helpers/digest_auth/ldap/digest_common.h b/helpers/digest_auth/LDAP/digest_common.h similarity index 100% rename from helpers/digest_auth/ldap/digest_common.h rename to helpers/digest_auth/LDAP/digest_common.h diff --git a/helpers/digest_auth/eDirectory/digest_pw_auth.c b/helpers/digest_auth/LDAP/digest_pw_auth.cc similarity index 92% rename from helpers/digest_auth/eDirectory/digest_pw_auth.c rename to helpers/digest_auth/LDAP/digest_pw_auth.cc index 2f5f2016db..a83ac45bd4 100644 --- a/helpers/digest_auth/eDirectory/digest_pw_auth.c +++ b/helpers/digest_auth/LDAP/digest_pw_auth.cc @@ -29,9 +29,11 @@ * * Copyright (c) 2003 Robert Collins */ - +#include "config.h" #include "digest_common.h" +#include "helpers/defines.h" #include "ldap_backend.h" + #define PROGRAM_NAME "digest_ldap_auth" @@ -63,7 +65,7 @@ OutputHHA1(RequestData * requestData) requestData->error = 0; GetHHA1(requestData); if (requestData->error) { - printf("ERR No such user\n"); + SEND_ERR("No such user"); return; } printf("%s\n", requestData->HHA1); @@ -75,7 +77,7 @@ DoOneRequest(char *buf) RequestData requestData; ParseBuffer(buf, &requestData); if (!requestData.parsed) { - printf("ERR\n"); + SEND_ERR(""); return; } OutputHHA1(&requestData); @@ -93,10 +95,10 @@ ProcessArguments(int argc, char **argv) int main(int argc, char **argv) { - char buf[256]; + char buf[HELPER_INPUT_BUFFER]; setbuf(stdout, NULL); ProcessArguments(argc, argv); - while (fgets(buf, 256, stdin) != NULL) + while (fgets(buf, HELPER_INPUT_BUFFER, stdin) != NULL) DoOneRequest(buf); exit(0); } diff --git a/helpers/digest_auth/ldap/ldap_backend.c b/helpers/digest_auth/LDAP/ldap_backend.cc similarity index 96% rename from helpers/digest_auth/ldap/ldap_backend.c rename to helpers/digest_auth/LDAP/ldap_backend.cc index ccb70afba2..d305c01a8f 100644 --- a/helpers/digest_auth/ldap/ldap_backend.c +++ b/helpers/digest_auth/LDAP/ldap_backend.cc @@ -63,7 +63,6 @@ static int encrpass = 0; static int searchscope = LDAP_SCOPE_SUBTREE; static int persistent = 0; static int noreferrals = 0; -static int show_debug_messages = 0; static int port = LDAP_PORT; static int strip_nt_domain = 0; static int aliasderef = LDAP_DEREF_NEVER; @@ -94,7 +93,7 @@ squid_ldap_set_aliasderef(int deref) static void squid_ldap_set_referrals(int referrals) { - int *value = referrals ? LDAP_OPT_ON :LDAP_OPT_OFF; + int *value = static_cast(referrals ? LDAP_OPT_ON :LDAP_OPT_OFF); ldap_set_option(ld, LDAP_OPT_REFERRALS, value); } static void @@ -207,8 +206,7 @@ getpassword(char *login, char *realm) snprintf(filter, sizeof(filter), usersearchfilter, escaped_login, escaped_login, escaped_login, escaped_login, escaped_login, escaped_login, escaped_login, escaped_login, escaped_login, escaped_login, escaped_login, escaped_login, escaped_login, escaped_login, escaped_login, escaped_login); retrysrch: - if (show_debug_messages) - fprintf(stderr, "user filter '%s', searchbase '%s'\n", filter, searchbase); + debug("user filter '%s', searchbase '%s'\n", filter, searchbase); rc = ldap_search_s(ld, searchbase, searchscope, filter, NULL, 0, &res); if (rc != LDAP_SUCCESS) { @@ -243,8 +241,7 @@ retrysrch: snprintf(searchbase, 8192, "%s=%s, %s", userdnattr, login, userbasedn); retrydnattr: - if (show_debug_messages) - fprintf(stderr, "searchbase '%s'\n", searchbase); + debug("searchbase '%s'\n", searchbase); rc = ldap_search_s(ld, searchbase, searchscope, NULL, NULL, 0, &res); } if (rc == LDAP_SUCCESS) { @@ -256,8 +253,7 @@ retrydnattr: return NULL; } if (!values) { - if (show_debug_messages) - printf("No attribute value found\n"); + debug("No attribute value found\n"); ldap_msgfree(res); return NULL; } @@ -274,8 +270,7 @@ retrydnattr: } value++; } - if (show_debug_messages) - printf("password: %s\n", password); + debug("password: %s\n", password); if (password) password = xstrdup(password); ldap_value_free(values); @@ -389,8 +384,7 @@ ldapconnect(void) ld = NULL; } } - if (show_debug_messages) - fprintf(stderr, "Connected OK\n"); + debug("Connected OK\n"); } } int @@ -433,7 +427,7 @@ LDAPArguments(int argc, char **argv) case 'h': if (ldapServer) { int len = strlen(ldapServer) + 1 + strlen(value) + 1; - char *newhost = malloc(len); + char *newhost = (char*)malloc(len); snprintf(newhost, len, "%s %s", ldapServer, value); free(ldapServer); ldapServer = newhost; @@ -544,7 +538,7 @@ LDAPArguments(int argc, char **argv) break; #endif case 'd': - show_debug_messages = 1; + debug_enabled = 1; break; case 'E': strip_nt_domain = 1; @@ -559,7 +553,7 @@ LDAPArguments(int argc, char **argv) char *value = argv[1]; if (ldapServer) { int len = strlen(ldapServer) + 1 + strlen(value) + 1; - char *newhost = malloc(len); + char *newhost = (char*)malloc(len); snprintf(newhost, len, "%s %s", ldapServer, value); free(ldapServer); ldapServer = newhost; diff --git a/helpers/digest_auth/ldap/ldap_backend.h b/helpers/digest_auth/LDAP/ldap_backend.h similarity index 100% rename from helpers/digest_auth/ldap/ldap_backend.h rename to helpers/digest_auth/LDAP/ldap_backend.h diff --git a/helpers/digest_auth/Makefile.am b/helpers/digest_auth/Makefile.am index 56dfd86e1f..89e7bbda56 100644 --- a/helpers/digest_auth/Makefile.am +++ b/helpers/digest_auth/Makefile.am @@ -2,6 +2,6 @@ DIST_SUBDIRS= \ eDirectory \ file \ - ldap + LDAP SUBDIRS= $(DIGEST_AUTH_HELPERS) diff --git a/helpers/digest_auth/eDirectory/Makefile.am b/helpers/digest_auth/eDirectory/Makefile.am index 0a32097fb6..0997f2aca4 100644 --- a/helpers/digest_auth/eDirectory/Makefile.am +++ b/helpers/digest_auth/eDirectory/Makefile.am @@ -1,28 +1,19 @@ -# -# Makefile for the Squid Object Cache server -# -# $Id$ -# -# Uncomment and customize the following to suit your needs: -# - include $(top_srcdir)/src/Common.am ## we need our local files too (but avoid -I. at all costs) INCLUDES += -I$(srcdir) -libexec_PROGRAMS = digest_edir_auth -digest_edir_auth_SOURCES = digest_pw_auth.c \ +libexec_PROGRAMS = digest_edirectory_auth +digest_edirectory_auth_SOURCES = digest_pw_auth.cc \ digest_common.h \ - ldap_backend.c \ + ldap_backend.cc \ ldap_backend.h \ - edir_ldapext.c \ + edir_ldapext.cc \ edir_ldapext.h -LDADD = \ - $(top_builddir)/compat/libcompat.la \ - -L$(top_builddir)/lib -lmiscutil \ +digest_edirectory_auth_LDADD = \ + $(COMPAT_LIB) \ $(LDAPLIB) \ $(LBERLIB) \ $(CRYPTLIB) \ diff --git a/helpers/digest_auth/ldap/digest_pw_auth.c b/helpers/digest_auth/eDirectory/digest_pw_auth.cc similarity index 91% rename from helpers/digest_auth/ldap/digest_pw_auth.c rename to helpers/digest_auth/eDirectory/digest_pw_auth.cc index 2f5f2016db..e2359a6bc0 100644 --- a/helpers/digest_auth/ldap/digest_pw_auth.c +++ b/helpers/digest_auth/eDirectory/digest_pw_auth.cc @@ -29,11 +29,12 @@ * * Copyright (c) 2003 Robert Collins */ - +#include "config.h" #include "digest_common.h" +#include "helpers/defines.h" #include "ldap_backend.h" -#define PROGRAM_NAME "digest_ldap_auth" +#define PROGRAM_NAME "digest_edirectory_auth" static void GetHHA1(RequestData * requestData) @@ -63,7 +64,7 @@ OutputHHA1(RequestData * requestData) requestData->error = 0; GetHHA1(requestData); if (requestData->error) { - printf("ERR No such user\n"); + SEND_ERR("No such user"); return; } printf("%s\n", requestData->HHA1); @@ -75,7 +76,7 @@ DoOneRequest(char *buf) RequestData requestData; ParseBuffer(buf, &requestData); if (!requestData.parsed) { - printf("ERR\n"); + SEND_ERR(""); return; } OutputHHA1(&requestData); @@ -93,10 +94,10 @@ ProcessArguments(int argc, char **argv) int main(int argc, char **argv) { - char buf[256]; + char buf[HELPER_INPUT_BUFFER]; setbuf(stdout, NULL); ProcessArguments(argc, argv); - while (fgets(buf, 256, stdin) != NULL) + while (fgets(buf, HELPER_INPUT_BUFFER, stdin) != NULL) DoOneRequest(buf); exit(0); } diff --git a/helpers/digest_auth/eDirectory/edir_ldapext.c b/helpers/digest_auth/eDirectory/edir_ldapext.cc similarity index 84% rename from helpers/digest_auth/eDirectory/edir_ldapext.c rename to helpers/digest_auth/eDirectory/edir_ldapext.cc index f8a611afb1..713edf2caf 100644 --- a/helpers/digest_auth/eDirectory/edir_ldapext.c +++ b/helpers/digest_auth/eDirectory/edir_ldapext.cc @@ -104,7 +104,8 @@ static int berEncodePasswordData( /* Allocate a BerElement for the request parameters. */ if ((requestBer = ber_alloc()) == NULL) { err = LDAP_ENCODING_ERROR; - goto Cleanup; + ber_free(requestBer, 1); + return err; } if (password != NULL && password2 != NULL) { @@ -120,19 +121,14 @@ static int berEncodePasswordData( if (rc < 0) { err = LDAP_ENCODING_ERROR; - goto Cleanup; } else { err = 0; + /* Convert the BER we just built to a berval that we'll send with the extended request. */ + if ((ber_tag_t)ber_flatten(requestBer, requestBV) == LBER_ERROR) { + err = LDAP_ENCODING_ERROR; + } } - /* Convert the BER we just built to a berval that we'll send with the extended request. */ - if (ber_flatten(requestBer, requestBV) == LBER_ERROR) { - err = LDAP_ENCODING_ERROR; - goto Cleanup; - } - -Cleanup: - if (requestBer) { ber_free(requestBer, 1); } @@ -175,7 +171,7 @@ static int berEncodeLoginData( /* Allocate a BerElement for the request parameters. */ if ((requestBer = ber_alloc()) == NULL) { err = LDAP_ENCODING_ERROR; - goto Cleanup; + return err; } /* BER encode the NMAS Version and the objectDN */ @@ -202,18 +198,11 @@ static int berEncodeLoginData( err = (ber_printf(requestBer, "o}", utf8TagPtr, utf8TagSize) < 0) ? LDAP_ENCODING_ERROR : 0; } - if (err) { - goto Cleanup; - } - /* Convert the BER we just built to a berval that we'll send with the extended request. */ - if (ber_flatten(requestBer, requestBV) == LBER_ERROR) { + if (!err && (ber_tag_t)ber_flatten(requestBer, requestBV) == LBER_ERROR) { err = LDAP_ENCODING_ERROR; - goto Cleanup; } -Cleanup: - if (requestBer) { ber_free(requestBer, 1); } @@ -240,18 +229,14 @@ static int berDecodeLoginData( if ((replyBer = ber_init(replyBV)) == NULL) { err = LDAP_OPERATIONS_ERROR; - goto Cleanup; } - - if (retData) { + else if (retData) { retOctStrLen = *retDataLen + 1; - retOctStr = SMB_MALLOC_ARRAY(char, retOctStrLen); + retOctStr = (char*)SMB_MALLOC_ARRAY(char, retOctStrLen); if (!retOctStr) { err = LDAP_OPERATIONS_ERROR; - goto Cleanup; } - - if (ber_scanf(replyBer, "{iis}", serverVersion, &err, retOctStr, &retOctStrLen) != -1) { + else if (ber_scanf(replyBer, "{iis}", serverVersion, &err, retOctStr, &retOctStrLen) != LBER_ERROR) { if (*retDataLen >= retOctStrLen) { memcpy(retData, retOctStr, retOctStrLen); } else if (!err) { @@ -263,15 +248,13 @@ static int berDecodeLoginData( err = LDAP_DECODING_ERROR; } } else { - if (ber_scanf(replyBer, "{ii}", serverVersion, &err) == -1) { + if (ber_scanf(replyBer, "{ii}", serverVersion, &err) == LBER_ERROR) { if (!err) { err = LDAP_DECODING_ERROR; } } } -Cleanup: - if (replyBer) { ber_free(replyBer, 1); } @@ -311,44 +294,32 @@ static int getLoginConfig( err = berEncodeLoginData(&requestBV, objectDN, methodIDLen, methodID, tag, 0, NULL); if (err) { - goto Cleanup; - } - - /* Call the ldap_extended_operation (synchronously) */ - if ((err = ldap_extended_operation_s(ld, NMASLDAP_GET_LOGIN_CONFIG_REQUEST, + ; + } else if (!err && (err = ldap_extended_operation_s(ld, NMASLDAP_GET_LOGIN_CONFIG_REQUEST, requestBV, NULL, NULL, &replyOID, &replyBV))) { - goto Cleanup; - } - - /* Make sure there is a return OID */ - if (!replyOID) { + /* Call the ldap_extended_operation (synchronously) */ + ; + } else if (!replyOID) { + /* Make sure there is a return OID */ err = LDAP_NOT_SUPPORTED; - goto Cleanup; - } - - /* Is this what we were expecting to get back. */ - if (strcmp(replyOID, NMASLDAP_GET_LOGIN_CONFIG_RESPONSE)) { + } else if (strcmp(replyOID, NMASLDAP_GET_LOGIN_CONFIG_RESPONSE)) { + /* Is this what we were expecting to get back. */ err = LDAP_NOT_SUPPORTED; - goto Cleanup; - } + } else if (!replyBV) { + /* Do we have a good returned berval? */ - /* Do we have a good returned berval? */ - if (!replyBV) { /* No; returned berval means we experienced a rather drastic error. */ /* Return operations error. */ err = LDAP_OPERATIONS_ERROR; - goto Cleanup; - } + } else { - err = berDecodeLoginData(replyBV, &serverVersion, dataLen, data); + err = berDecodeLoginData(replyBV, &serverVersion, dataLen, data); - if (serverVersion != NMAS_LDAP_EXT_VERSION) { - err = LDAP_OPERATIONS_ERROR; - goto Cleanup; + if (serverVersion != NMAS_LDAP_EXT_VERSION) { + err = LDAP_OPERATIONS_ERROR; + } } -Cleanup: - if (replyBV) { ber_bvfree(replyBV); } @@ -385,7 +356,7 @@ static int nmasldap_get_simple_pwd( size_t pwdBufLen, bufferLen; bufferLen = pwdBufLen = pwdLen+2; - pwdBuf = SMB_MALLOC_ARRAY(char, pwdBufLen); /* digest and null */ + pwdBuf = (char*)SMB_MALLOC_ARRAY(char, pwdBufLen); /* digest and null */ if (pwdBuf == NULL) { return LDAP_NO_MEMORY; } @@ -451,58 +422,42 @@ static int nmasldap_get_password( } bufferLen = pwdBufLen = *pwdSize; - pwdBuf = SMB_MALLOC_ARRAY(char, pwdBufLen+2); + pwdBuf = (char*)SMB_MALLOC_ARRAY(char, pwdBufLen+2); if (pwdBuf == NULL) { return LDAP_NO_MEMORY; } err = berEncodePasswordData(&requestBV, objectDN, NULL, NULL); if (err) { - goto Cleanup; - } - - /* Call the ldap_extended_operation (synchronously) */ - if ((err = ldap_extended_operation_s(ld, NMASLDAP_GET_PASSWORD_REQUEST, requestBV, NULL, NULL, &replyOID, &replyBV))) { - goto Cleanup; - } - - /* Make sure there is a return OID */ - if (!replyOID) { + ; + } else if ((err = ldap_extended_operation_s(ld, NMASLDAP_GET_PASSWORD_REQUEST, requestBV, NULL, NULL, &replyOID, &replyBV))) { + ; /* Call the ldap_extended_operation (synchronously) */ + } else if (!replyOID) { + /* Make sure there is a return OID */ err = LDAP_NOT_SUPPORTED; - goto Cleanup; - } - - /* Is this what we were expecting to get back. */ - if (strcmp(replyOID, NMASLDAP_GET_PASSWORD_RESPONSE)) { + } else if (strcmp(replyOID, NMASLDAP_GET_PASSWORD_RESPONSE)) { + /* Is this what we were expecting to get back. */ err = LDAP_NOT_SUPPORTED; - goto Cleanup; - } - - /* Do we have a good returned berval? */ - if (!replyBV) { + } else if (!replyBV) { + /* Do we have a good returned berval? */ /* No; returned berval means we experienced a rather drastic error. */ /* Return operations error. */ err = LDAP_OPERATIONS_ERROR; - goto Cleanup; - } - - err = berDecodeLoginData(replyBV, &serverVersion, &pwdBufLen, pwdBuf); + } else { + err = berDecodeLoginData(replyBV, &serverVersion, &pwdBufLen, pwdBuf); - if (serverVersion != NMAS_LDAP_EXT_VERSION) { - err = LDAP_OPERATIONS_ERROR; - goto Cleanup; - } + if (serverVersion != NMAS_LDAP_EXT_VERSION) { + err = LDAP_OPERATIONS_ERROR; - if (!err && pwdBufLen != 0) { - if (*pwdSize >= pwdBufLen+1 && pwd != NULL) { - memcpy(pwd, pwdBuf, pwdBufLen); - pwd[pwdBufLen] = 0; /* add null termination */ + } else if (!err && pwdBufLen != 0) { + if (*pwdSize >= pwdBufLen+1 && pwd != NULL) { + memcpy(pwd, pwdBuf, pwdBufLen); + pwd[pwdBufLen] = 0; /* add null termination */ + } + *pwdSize = pwdBufLen; /* does not include null termination */ } - *pwdSize = pwdBufLen; /* does not include null termination */ } -Cleanup: - if (replyBV) { ber_bvfree(replyBV); } diff --git a/helpers/digest_auth/eDirectory/ldap_backend.c b/helpers/digest_auth/eDirectory/ldap_backend.cc similarity index 93% rename from helpers/digest_auth/eDirectory/ldap_backend.c rename to helpers/digest_auth/eDirectory/ldap_backend.cc index 1b1591234a..6d69aa9af0 100644 --- a/helpers/digest_auth/eDirectory/ldap_backend.c +++ b/helpers/digest_auth/eDirectory/ldap_backend.cc @@ -63,7 +63,6 @@ static int encrpass = 0; static int searchscope = LDAP_SCOPE_SUBTREE; static int persistent = 0; static int noreferrals = 0; -static int show_debug_messages = 0; static int port = LDAP_PORT; static int strip_nt_domain = 0; static int edir_universal_passwd = 0; @@ -95,7 +94,7 @@ squid_ldap_set_aliasderef(int deref) static void squid_ldap_set_referrals(int referrals) { - int *value = referrals ? LDAP_OPT_ON :LDAP_OPT_OFF; + int *value = static_cast(referrals ? LDAP_OPT_ON :LDAP_OPT_OFF); ldap_set_option(ld, LDAP_OPT_REFERRALS, value); } static void @@ -144,7 +143,7 @@ squid_ldap_set_timelimit(int aTimeLimit) static void squid_ldap_set_connect_timeout(int aTimeLimit) { - fprintf(stderr, "Connect timeouts not supported in your LDAP library\n"); + fprintf(stderr, "ERROR: Connect timeouts not supported in your LDAP library\n"); } static void squid_ldap_memfree(char *p) @@ -211,8 +210,7 @@ getpassword(char *login, char *realm) snprintf(filter, sizeof(filter), usersearchfilter, escaped_login, escaped_login, escaped_login, escaped_login, escaped_login, escaped_login, escaped_login, escaped_login, escaped_login, escaped_login, escaped_login, escaped_login, escaped_login, escaped_login, escaped_login, escaped_login); retrysrch: - if (show_debug_messages) - fprintf(stderr, "user filter '%s', searchbase '%s'\n", filter, searchbase); + debug("user filter '%s', searchbase '%s'\n", filter, searchbase); rc = ldap_search_s(ld, searchbase, searchscope, filter, NULL, 0, &res); if (rc != LDAP_SUCCESS) { @@ -247,31 +245,26 @@ retrysrch: snprintf(searchbase, 8192, "%s=%s, %s", userdnattr, login, userbasedn); retrydnattr: - if (show_debug_messages) - fprintf(stderr, "searchbase '%s'\n", searchbase); + debug("searchbase '%s'\n", searchbase); rc = ldap_search_s(ld, searchbase, searchscope, NULL, NULL, 0, &res); } if (rc == LDAP_SUCCESS) { entry = ldap_first_entry(ld, res); if (entry) { - if (show_debug_messages) - printf("ldap dn: %s\n", ldap_get_dn(ld, entry)); + debug("ldap dn: %s\n", ldap_get_dn(ld, entry)); if (edir_universal_passwd) { /* allocate some memory for the universal password returned by NMAS */ - universal_password = malloc(universal_password_len); - memset(universal_password, 0, universal_password_len); - values = malloc(sizeof(char *)); + universal_password = (char*)calloc(1, universal_password_len); + values = (char**)calloc(1, sizeof(char *)); /* actually talk to NMAS to get a password */ nmas_res = nds_get_password(ld, ldap_get_dn(ld, entry), &universal_password_len, universal_password); if (nmas_res == LDAP_SUCCESS && universal_password) { - if (show_debug_messages) - printf("NMAS returned value %s\n", universal_password); + debug("NMAS returned value %s\n", universal_password); values[0] = universal_password; } else { - if (show_debug_messages) - printf("Error reading Universal Password: %d = %s\n", nmas_res, ldap_err2string(nmas_res)); + debug("Error reading Universal Password: %d = %s\n", nmas_res, ldap_err2string(nmas_res)); } } else { values = ldap_get_values(ld, entry, passattr); @@ -281,8 +274,7 @@ retrydnattr: return NULL; } if (!values) { - if (show_debug_messages) - printf("No attribute value found\n"); + debug("No attribute value found\n"); if (edir_universal_passwd) free(universal_password); ldap_msgfree(res); @@ -301,8 +293,7 @@ retrydnattr: } value++; } - if (show_debug_messages) - printf("password: %s\n", password); + debug("password: %s\n", password); if (password) password = xstrdup(password); if (edir_universal_passwd) { @@ -419,8 +410,7 @@ ldapconnect(void) ld = NULL; } } - if (show_debug_messages) - fprintf(stderr, "Connected OK\n"); + debug("Connected OK\n"); } } int @@ -465,7 +455,7 @@ LDAPArguments(int argc, char **argv) case 'h': if (ldapServer) { int len = strlen(ldapServer) + 1 + strlen(value) + 1; - char *newhost = malloc(len); + char *newhost = (char*)malloc(len); snprintf(newhost, len, "%s %s", ldapServer, value); free(ldapServer); ldapServer = newhost; @@ -576,7 +566,7 @@ LDAPArguments(int argc, char **argv) break; #endif case 'd': - show_debug_messages = 1; + debug_enabled = 1; break; case 'E': strip_nt_domain = 1; @@ -594,7 +584,7 @@ LDAPArguments(int argc, char **argv) char *value = argv[1]; if (ldapServer) { int len = strlen(ldapServer) + 1 + strlen(value) + 1; - char *newhost = malloc(len); + char *newhost = (char*)malloc(len); snprintf(newhost, len, "%s %s", ldapServer, value); free(ldapServer); ldapServer = newhost;