Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions LDAPCnx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ void LDAPCnx::Init(Local<Object> exports) {
Nan::SetPrototypeMethod(tpl, "starttls", StartTLS);
Nan::SetPrototypeMethod(tpl, "checktls", CheckTLS);

constructor.Reset(tpl->GetFunction());
exports->Set(Nan::New("LDAPCnx").ToLocalChecked(), tpl->GetFunction());
v8::Local<v8::Context> context = exports->CreationContext();


constructor.Reset(tpl->GetFunction(context).ToLocalChecked());
exports->Set(Nan::New("LDAPCnx").ToLocalChecked(), tpl->GetFunction(context).ToLocalChecked());
}

void LDAPCnx::New(const Nan::FunctionCallbackInfo<Value>& info) {
Expand All @@ -51,17 +54,20 @@ void LDAPCnx::New(const Nan::FunctionCallbackInfo<Value>& info) {
LDAPCnx* ld = new LDAPCnx();
ld->Wrap(info.Holder());


v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext();

ld->callback = new Nan::Callback(info[0].As<Function>());
ld->reconnect_callback = new Nan::Callback(info[1].As<Function>());
ld->disconnect_callback = new Nan::Callback(info[2].As<Function>());
ld->handle = NULL;

Nan::Utf8String url(info[3]);
int ver = LDAP_VERSION3;
int timeout = info[4]->NumberValue();
int debug = info[5]->NumberValue();
int verifycert = info[6]->NumberValue();
int referrals = info[7]->NumberValue();
int timeout = info[4]->NumberValue(context).FromJust();
int debug = info[5]->NumberValue(context).FromJust();
int verifycert = info[6]->NumberValue(context).FromJust();
int referrals = info[7]->NumberValue(context).FromJust();
int zero = 0;

ld->ldap_callback = (ldap_conncb *)malloc(sizeof(ldap_conncb));
Expand Down Expand Up @@ -318,8 +324,8 @@ void LDAPCnx::CheckTLS(const Nan::FunctionCallbackInfo<Value>& info) {

void LDAPCnx::Abandon(const Nan::FunctionCallbackInfo<Value>& info) {
LDAPCnx* ld = ObjectWrap::Unwrap<LDAPCnx>(info.Holder());

info.GetReturnValue().Set(ldap_abandon(ld->ld, info[0]->NumberValue()));
v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext();
info.GetReturnValue().Set(ldap_abandon(ld->ld, info[0]->NumberValue(context).FromJust()));
}

void LDAPCnx::GetErrNo(const Nan::FunctionCallbackInfo<Value>& info) {
Expand Down Expand Up @@ -366,11 +372,12 @@ void LDAPCnx::Rename(const Nan::FunctionCallbackInfo<Value>& info) {

void LDAPCnx::Search(const Nan::FunctionCallbackInfo<Value>& info) {
LDAPCnx* ld = ObjectWrap::Unwrap<LDAPCnx>(info.Holder());
v8::Local<v8::Context> context = info.GetIsolate()->GetCurrentContext();
Nan::Utf8String base(info[0]);
Nan::Utf8String filter(info[1]);
Nan::Utf8String attrs(info[2]);
int scope = info[3]->NumberValue();
int pagesize = info[4]->NumberValue();;
int scope = info[3]->NumberValue(context).FromJust();
int pagesize = info[4]->NumberValue(context).FromJust();;
LDAPCookie* cookie = NULL;

int msgid = 0;
Expand All @@ -388,8 +395,8 @@ void LDAPCnx::Search(const Nan::FunctionCallbackInfo<Value>& info) {
page_control[0] = NULL;
page_control[1] = NULL;
if (pagesize > 0) {
if (info[5]->IsObject() && !info[5]->ToObject().IsEmpty())
cookie = Nan::ObjectWrap::Unwrap<LDAPCookie>(info[5]->ToObject());
if (info[5]->IsObject() && !info[5]->ToObject(context).IsEmpty())
cookie = Nan::ObjectWrap::Unwrap<LDAPCookie>(info[5]->ToObject(context).ToLocalChecked());
if (cookie) {
ldap_create_page_control(ld->ld, pagesize, cookie->GetCookie(), 0, &page_control[0]);
} else {
Expand Down Expand Up @@ -423,7 +430,7 @@ void LDAPCnx::Modify(const Nan::FunctionCallbackInfo<Value>& info) {

ldapmods[i] = (LDAPMod *) malloc(sizeof(LDAPMod));

String::Utf8Value mod_op(modHandle->Get(Nan::New("op").ToLocalChecked()));
Nan::Utf8String mod_op(modHandle->Get(Nan::New("op").ToLocalChecked()));

if (!strcmp(*mod_op, "add")) {
ldapmods[i]->mod_op = LDAP_MOD_ADD;
Expand All @@ -433,7 +440,7 @@ void LDAPCnx::Modify(const Nan::FunctionCallbackInfo<Value>& info) {
ldapmods[i]->mod_op = LDAP_MOD_REPLACE;
}

String::Utf8Value mod_type(modHandle->Get(Nan::New("attr").ToLocalChecked()));
Nan::Utf8String mod_type(modHandle->Get(Nan::New("attr").ToLocalChecked()));
ldapmods[i]->mod_type = strdup(*mod_type);

Local<Array> modValsHandle =
Expand Down Expand Up @@ -474,7 +481,7 @@ void LDAPCnx::Add(const Nan::FunctionCallbackInfo<Value>& info) {
ldapmods[i]->mod_op = LDAP_MOD_ADD;

// Step 2: mod_type
String::Utf8Value mod_type(attrHandle->Get(Nan::New("attr").ToLocalChecked()));
Nan::Utf8String mod_type(attrHandle->Get(Nan::New("attr").ToLocalChecked()));
ldapmods[i]->mod_type = strdup(*mod_type);

// Step 3: mod_vals
Expand Down
6 changes: 6 additions & 0 deletions LDAPCnx.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
#include <nan.h>
#include <ldap.h>


namespace v8 {
template <class T>
using Handle = Local<T>;
}

class LDAPCnx : public Nan::ObjectWrap {
public:
static void Init(v8::Local<v8::Object> exports);
Expand Down
3 changes: 2 additions & 1 deletion LDAPCookie.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ LDAPCookie::~LDAPCookie() {

void LDAPCookie::Init(v8::Local<v8::Object> exports) {
Nan::HandleScope scope;
v8::Local<v8::Context> context = exports->CreationContext();
v8::Local<v8::FunctionTemplate> tpl = Nan::New<v8::FunctionTemplate>(New);
// legal? No idea, just an attempt to prevent polluting javascript global namespace with
// something that doesn't make sense to construct from JS side. Appears to work (doesn't
// crash, paging works).
// tpl->SetClassName(Nan::New("LDAPInternalCookie").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
constructor.Reset(tpl->GetFunction());
constructor.Reset(tpl->GetFunction(context).ToLocalChecked());
}

v8::Local<v8::Object> LDAPCookie::NewInstance() {
Expand Down
4 changes: 2 additions & 2 deletions LDAPSASL.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ void LDAPCnx::SASLBind(const Nan::FunctionCallbackInfo<Value>& info) {
Nan::ThrowError("LDAP connection has not been established");
}

v8::String::Utf8Value mechanism(SASLDefaults::Get(info[0]));
Nan::Utf8String mechanism(SASLDefaults::Get(info[0]));
SASLDefaults defaults(info[1], info[2], info[3], info[4]);
v8::String::Utf8Value sec_props(SASLDefaults::Get(info[5]));
Nan::Utf8String sec_props(SASLDefaults::Get(info[5]));

if(*sec_props) {
int res = ldap_set_option(ld->ld, LDAP_OPT_X_SASL_SECPROPS, *sec_props);
Expand Down
8 changes: 4 additions & 4 deletions SASLDefaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ struct SASLDefaults {

static int Callback(LDAP *ld, unsigned flags, void *defaults, void *in);

v8::String::Utf8Value user;
v8::String::Utf8Value password;
v8::String::Utf8Value realm;
v8::String::Utf8Value proxy_user;
Nan::Utf8String user;
Nan::Utf8String password;
Nan::Utf8String realm;
Nan::Utf8String proxy_user;

private:
void Set(unsigned flags, sasl_interact_t *interact);
Expand Down
14 changes: 9 additions & 5 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
"<!(node -e \"require('nan')\")",
"/usr/local/include"
],
"libraries": [
"-lldap"
],
"defines": [
"LDAP_DEPRECATED"
],
Expand All @@ -24,12 +21,19 @@
"conditions": [
[ "SASL==\"n\"", { "sources!":
["LDAPSASL.cc", "SASLDefaults.cc"] } ],
[ "SASL==\"y\"", { "sources!": ["LDAPXSASL.cc"] } ]
[ "SASL==\"y\"", { "sources!": ["LDAPXSASL.cc"] } ],
['OS=="linux" and NODE_VERSION > 9', {
"libraries": [ "../deps/libldap.a", "../deps/liblber.a", "-lresolv", "-lsasl2" ],
"include_dirs": [ "deps/include" ]
}, {
"libraries": [ "-lldap" ]
}]
]
}
],
"variables": {
"SASL": "<!(test -f /usr/include/sasl/sasl.h && echo y || echo n)"
"SASL": "<!(test -f /usr/include/sasl/sasl.h && echo y || echo n)",
"NODE_VERSION": "<!(node --version | cut -d. -f1 | cut -dv -f2)"
},
"conditions": [
[
Expand Down
43 changes: 43 additions & 0 deletions deps/include/ac/alloca.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* Generic alloca.h */
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
* Copyright 1998-2020 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* <http://www.OpenLDAP.org/license.html>.
*/

#ifndef _AC_ALLOCA_H
#define _AC_ALLOCA_H

/*
* use of alloca is disallowed as it is machine dependent
*/
#error "alloca() not supported, use malloc()"

/* AIX requires this to be the first thing in the file. */
#ifdef __GNUC__
# define alloca __builtin_alloca
#else
# ifdef HAVE_ALLOCA_H
# include <alloca.h>
# else
# ifdef _AIX
#pragma alloca
# else
# ifndef alloca /* predefined by HP cc +Olibcalls */
extern char *(alloca)();
# endif
# endif
# endif
#endif


#endif /* _AC_ALLOCA_H */
57 changes: 57 additions & 0 deletions deps/include/ac/assert.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* Generic assert.h */
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
* Copyright 1998-2020 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* <http://www.OpenLDAP.org/license.html>.
*/

#ifndef _AC_ASSERT_H
#define _AC_ASSERT_H

#undef assert

#ifdef LDAP_DEBUG

#if defined( HAVE_ASSERT_H ) || defined( STDC_HEADERS )

#undef NDEBUG
#include <assert.h>

#else /* !(HAVE_ASSERT_H || STDC_HEADERS) */

#define LDAP_NEED_ASSERT 1

/*
* no assert()... must be a very old compiler.
* create a replacement and hope it works
*/

LBER_F (void) ber_pvt_assert LDAP_P(( const char *file, int line,
const char *test ));

/* Can't use LDAP_STRING(test), that'd expand to "test" */
#if defined(__STDC__) || defined(__cplusplus)
#define assert(test) \
((test) ? (void)0 : ber_pvt_assert( __FILE__, __LINE__, #test ) )
#else
#define assert(test) \
((test) ? (void)0 : ber_pvt_assert( __FILE__, __LINE__, "test" ) )
#endif

#endif /* (HAVE_ASSERT_H || STDC_HEADERS) */

#else /* !LDAP_DEBUG */
/* no asserts */
#define assert(test) ((void)0)
#endif /* LDAP_DEBUG */

#endif /* _AC_ASSERT_H */
78 changes: 78 additions & 0 deletions deps/include/ac/bytes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/* Generic bytes.h */
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
* Copyright 1998-2020 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted only as authorized by the OpenLDAP
* Public License.
*
* A copy of this license is available in file LICENSE in the
* top-level directory of the distribution or, alternatively, at
* <http://www.OpenLDAP.org/license.html>.
*/

#ifndef _AC_BYTES_H
#define _AC_BYTES_H

/* cross compilers should define both AC_INT{2,4}_TYPE in CPPFLAGS */

#if !defined( AC_INT4_TYPE )
/* use autoconf defines to provide sized typedefs */
# if SIZEOF_LONG == 4
# define AC_INT4_TYPE long
# elif SIZEOF_INT == 4
# define AC_INT4_TYPE int
# elif SIZEOF_SHORT == 4
# define AC_INT4_TYPE short
# else
# error "AC_INT4_TYPE?"
# endif
#endif

typedef AC_INT4_TYPE ac_int4;
typedef signed AC_INT4_TYPE ac_sint4;
typedef unsigned AC_INT4_TYPE ac_uint4;

#if !defined( AC_INT2_TYPE )
# if SIZEOF_SHORT == 2
# define AC_INT2_TYPE short
# elif SIZEOF_INT == 2
# define AC_INT2_TYPE int
# elif SIZEOF_LONG == 2
# define AC_INT2_TYPE long
# else
# error "AC_INT2_TYPE?"
# endif
#endif

#if defined( AC_INT2_TYPE )
typedef AC_INT2_TYPE ac_int2;
typedef signed AC_INT2_TYPE ac_sint2;
typedef unsigned AC_INT2_TYPE ac_uint2;
#endif

#ifndef BYTE_ORDER
/* cross compilers should define BYTE_ORDER in CPPFLAGS */

/*
* Definitions for byte order, according to byte significance from low
* address to high.
*/
#define LITTLE_ENDIAN 1234 /* LSB first: i386, vax */
#define BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */
#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */

/* assume autoconf's AC_C_BIGENDIAN has been ran */
/* if it hasn't, we assume (maybe falsely) the order is LITTLE ENDIAN */
# ifdef WORDS_BIGENDIAN
# define BYTE_ORDER BIG_ENDIAN
# else
# define BYTE_ORDER LITTLE_ENDIAN
# endif

#endif /* BYTE_ORDER */

#endif /* _AC_BYTES_H */
Loading