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 \
-#
-# 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) \
*
* Copyright (c) 2003 Robert Collins <robertc@squid-cache.org>
*/
-
+#include "config.h"
#include "digest_common.h"
+#include "helpers/defines.h"
#include "ldap_backend.h"
+
#define PROGRAM_NAME "digest_ldap_auth"
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);
RequestData requestData;
ParseBuffer(buf, &requestData);
if (!requestData.parsed) {
- printf("ERR\n");
+ SEND_ERR("");
return;
}
OutputHHA1(&requestData);
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);
}
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;
static void
squid_ldap_set_referrals(int referrals)
{
- int *value = referrals ? LDAP_OPT_ON :LDAP_OPT_OFF;
+ int *value = static_cast<int*>(referrals ? LDAP_OPT_ON :LDAP_OPT_OFF);
ldap_set_option(ld, LDAP_OPT_REFERRALS, value);
}
static void
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) {
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) {
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;
}
}
value++;
}
- if (show_debug_messages)
- printf("password: %s\n", password);
+ debug("password: %s\n", password);
if (password)
password = xstrdup(password);
ldap_value_free(values);
ld = NULL;
}
}
- if (show_debug_messages)
- fprintf(stderr, "Connected OK\n");
+ debug("Connected OK\n");
}
}
int
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;
break;
#endif
case 'd':
- show_debug_messages = 1;
+ debug_enabled = 1;
break;
case 'E':
strip_nt_domain = 1;
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;
DIST_SUBDIRS= \
eDirectory \
file \
- ldap
+ LDAP
SUBDIRS= $(DIGEST_AUTH_HELPERS)
-#
-# 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) \
*
* Copyright (c) 2003 Robert Collins <robertc@squid-cache.org>
*/
-
+#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)
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);
RequestData requestData;
ParseBuffer(buf, &requestData);
if (!requestData.parsed) {
- printf("ERR\n");
+ SEND_ERR("");
return;
}
OutputHHA1(&requestData);
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);
}
/* 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) {
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);
}
/* 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 */
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);
}
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) {
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);
}
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);
}
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;
}
}
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);
}
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;
static void
squid_ldap_set_referrals(int referrals)
{
- int *value = referrals ? LDAP_OPT_ON :LDAP_OPT_OFF;
+ int *value = static_cast<int*>(referrals ? LDAP_OPT_ON :LDAP_OPT_OFF);
ldap_set_option(ld, LDAP_OPT_REFERRALS, value);
}
static void
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)
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) {
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);
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);
}
value++;
}
- if (show_debug_messages)
- printf("password: %s\n", password);
+ debug("password: %s\n", password);
if (password)
password = xstrdup(password);
if (edir_universal_passwd) {
ld = NULL;
}
}
- if (show_debug_messages)
- fprintf(stderr, "Connected OK\n");
+ debug("Connected OK\n");
}
}
int
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;
break;
#endif
case 'd':
- show_debug_messages = 1;
+ debug_enabled = 1;
break;
case 'E':
strip_nt_domain = 1;
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;