Permalink
Browse files

added ubuntu segfault-fixing compiler args

turned off debug messages, added macro for turning them back on
  • Loading branch information...
1 parent 2fc7244 commit bdd25a2b037abeed44ff7406b543b9e092d955e8 Gareth Jones committed May 31, 2011
Showing with 35 additions and 19 deletions.
  1. +4 −4 example/example.js
  2. +30 −14 ldapauth.cc
  3. BIN ldapauth.node
  4. +1 −1 wscript
View
@@ -3,11 +3,11 @@
var sys = require('sys'),
ldapauth = require('../ldapauth'); // Path to ldapauth.node
-var ldap_host = 'localhost',
+var ldap_host = 'ldap.test.com',
ldap_port = 389,
-username = 'cn=username,o=USERS',
-password = 'password',
-groups = 'ou=CMS,o=GROUPS';
+username = 'cn=AUser,o=USERS',
+password = 'secret',
+groups = 'ou=PEOPLE,o=GROUPS';
timeout = 10;
ldapauth.authenticate(ldap_host, ldap_port, username, password, groups, timeout,
View
@@ -47,6 +47,8 @@ Invoke user supplied JS callback
using namespace v8;
#define THROW(message) ThrowException(Exception::TypeError(String::New(message)))
+//#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
+#define DEBUG(...)
// Data passed between threads
struct auth_request
@@ -68,56 +70,62 @@ struct auth_request
// Runs on background thread, performing the actual LDAP request.
static int EIO_Authenticate(eio_req *req)
{
+ DEBUG("in EIO_Authenticate\n");
+
struct auth_request *auth_req = (struct auth_request*)(req->data);
// Node: OpenLDAP does actually provide _some_ async API calls,
// But ldap_open does NOT have an async equivalent, so we have to
// do this in a background thread. Seeing as we're in a background
// thread anyway, it's just simpler to call the rest of the calls
// synchronously.
+
+ DEBUG( "before ldap_init\n");
+ DEBUG( "ldap port is %i\n", auth_req->port);
+ DEBUG( "ldap host is %s\n", auth_req->host);
// Connect to LDAP server (use ldap_init instead of ldap_open, so that we can set the timeout)
LDAP *ldap = ldap_init(auth_req->host, auth_req->port);
- //fprintf(stderr, "ldap_init called\n");
+ DEBUG( "ldap_init called\n");
struct timeval timeout;
timeout.tv_sec = auth_req->timeout_secs;
timeout.tv_usec = 0;
ldap_set_option(ldap, LDAP_OPT_TIMEOUT, &timeout);
ldap_set_option(ldap, LDAP_OPT_NETWORK_TIMEOUT, &timeout);
- //fprintf(stderr, "timeouts set\n");
+ DEBUG( "timeouts set\n");
if (ldap == NULL) {
- //fprintf(stderr, "ldap thing is null\n");
+ DEBUG( "ldap thing is null\n");
auth_req->connected = false;
auth_req->authenticated = false;
} else {
- //fprintf(stderr, "going for the bind\n");
+ DEBUG( "going for the bind\n");
// Bind with credentials, passing result into auth_request struct
int ldap_result = ldap_simple_bind_s(ldap, auth_req->username, auth_req->password);
- //fprintf(stderr, "authenticated with ldap\n");
+ DEBUG( "authenticated with ldap\n");
if (ldap_result == LDAP_SUCCESS) {
auth_req->connected = true;
char *filter;
asprintf(&filter, "(member=%s)", auth_req->username);
- //fprintf(stderr, "Using this filter: %s\n", filter);
+ DEBUG( "Using this filter: %s\n", filter);
LDAPMessage *searchResult;
int search_success = ldap_search_ext_s(ldap, auth_req->groups, LDAP_SCOPE_SUBTREE, filter, NULL, 0, NULL, NULL, NULL, LDAP_NO_LIMIT, &searchResult);
- //fprintf(stderr, "search done with search_success = %i, LDAP_SUCCESS = %i\n", search_success, LDAP_SUCCESS);
- //fprintf(stderr, "ldap_count_entries = %i\n", ldap_count_entries(ldap, searchResult));
+ DEBUG( "search done with search_success = %i, LDAP_SUCCESS = %i\n", search_success, LDAP_SUCCESS);
+ DEBUG( "ldap_count_entries = %i\n", ldap_count_entries(ldap, searchResult));
auth_req->authenticated = (search_success == LDAP_SUCCESS) && (ldap_count_entries(ldap, searchResult) > 0);
free(filter);
ldap_msgfree(searchResult);
} else if (ldap_result == LDAP_TIMEOUT) {
auth_req->connected = false;
auth_req->authenticated = false;
} else {
- //fprintf(stderr, "ldap result was %i\n", ldap_result);
+ DEBUG( "ldap result was %i\n", ldap_result);
auth_req->authenticated = false;
}
// Disconnect
ldap_unbind(ldap);
- //fprintf(stderr, "leaving the ldap parts now with auth_req->authenticated = %i\n", auth_req->authenticated);
+ DEBUG( "leaving the ldap parts now with auth_req->authenticated = %i\n", auth_req->authenticated);
}
return 0;
@@ -130,15 +138,15 @@ static int EIO_AfterAuthenticate(eio_req *req)
HandleScope scope;
struct auth_request *auth_req = (struct auth_request *)(req->data);
- //fprintf(stderr, "In after authenticate, with auth_req->connected = %i, auth_req->authenticated = %i\n", auth_req->connected, auth_req->authenticated);
+ DEBUG( "In after authenticate, with auth_req->connected = %i, auth_req->authenticated = %i\n", auth_req->connected, auth_req->authenticated);
// Invoke callback JS function
Handle<Value> callback_args[2];
callback_args[0] = auth_req->connected ? (Handle<Value>)Undefined() : Exception::Error(String::New("LDAP connection failed"));
callback_args[1] = Boolean::New(auth_req->authenticated);
- //fprintf(stderr, "just before the js callback\n");
+ DEBUG( "just before the js callback\n");
auth_req->callback->Call(Context::GetCurrent()->Global(), 2, callback_args);
- //fprintf(stderr, "after the js callback\n");
+ DEBUG( "after the js callback\n");
// Cleanup auth_request struct
auth_req->callback.Dispose();
free(auth_req);
@@ -150,6 +158,8 @@ static int EIO_AfterAuthenticate(eio_req *req)
static Handle<Value> Authenticate(const Arguments& args)
{
HandleScope scope;
+
+ DEBUG( "validating args\n");
// Validate args.
if (args.Length() < 7) return THROW("Required arguments: ldap_host, ldap_port, username, password, groups, timeout_secs, callback");
@@ -170,7 +180,9 @@ static Handle<Value> Authenticate(const Arguments& args)
int timeout_secs = args[5]->Int32Value();
Local<Function> callback = Local<Function>::Cast(args[6]);
-
+ DEBUG( "setting up the request struct\n");
+ DEBUG( "host is %s\n", *host);
+
// Store all parameters in auth_request struct, which shall be passed across threads.
struct auth_request *auth_req = (struct auth_request*) calloc(1, sizeof(struct auth_request));
auth_req->host = strdup(*host);
@@ -181,10 +193,14 @@ static Handle<Value> Authenticate(const Arguments& args)
auth_req->timeout_secs = timeout_secs;
auth_req->callback = Persistent<Function>::New(callback);
+ DEBUG( "before the libeio calls\n");
+ DEBUG( "auth_req->host is %s\n", auth_req->host);
// Use libeio to invoke EIO_Authenticate() in background thread pool
// and call EIO_AfterAuthenticate in the foreground when done
eio_custom(EIO_Authenticate, EIO_PRI_DEFAULT, EIO_AfterAuthenticate, auth_req);
+ DEBUG( "after eio_custom\n");
ev_ref(EV_DEFAULT_UC);
+ DEBUG( "after ev_ref\n");
return Undefined();
}
View
Binary file not shown.
View
@@ -11,7 +11,7 @@ def configure(conf):
def build(bld):
obj = bld.new_task_gen('cxx', 'shlib', 'node_addon')
- obj.cxxflags = ['-DLDAP_DEPRECATED']
+ obj.cxxflags = ['-DLDAP_DEPRECATED', '-D_FILE_OFFSET_BITS=64', '-D_LARGEFILE_SOURCE']
obj.target = 'ldapauth'
obj.source = 'ldapauth.cc'
obj.lib = ['ldap']

0 comments on commit bdd25a2

Please sign in to comment.