forked from jjhoughton/node-LDAP
-
Notifications
You must be signed in to change notification settings - Fork 1
/
LDAPSASL.cc
64 lines (49 loc) · 1.61 KB
/
LDAPSASL.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <sasl/sasl.h>
#include "LDAPCnx.h"
#include "SASLDefaults.h"
using namespace v8;
void LDAPCnx::SASLBind(const Nan::FunctionCallbackInfo<Value>& info) {
LDAPCnx* ld = ObjectWrap::Unwrap<LDAPCnx>(info.Holder());
if (ld->ld == NULL) {
Nan::ThrowError("LDAP connection has not been established");
}
Nan::Utf8String mechanism(SASLDefaults::Get(info[0]));
SASLDefaults defaults(info[1], info[2], info[3], info[4]);
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);
if(res != LDAP_SUCCESS) {
Nan::ThrowError(ldap_err2string(res));
}
}
int msgid;
LDAPControl** sctrlsp = NULL;
LDAPMessage* message = NULL;
ld->sasl_mechanism = NULL;
int res = ldap_sasl_interactive_bind(ld->ld, NULL, *mechanism,
sctrlsp, NULL, LDAP_SASL_QUIET, &SASLDefaults::Callback, &defaults,
message, &ld->sasl_mechanism, &msgid);
if(res != LDAP_SASL_BIND_IN_PROGRESS && res != LDAP_SUCCESS) {
Nan::ThrowError(ldap_err2string(res));
}
info.GetReturnValue().Set(msgid);
}
int LDAPCnx::SASLBindNext(LDAPMessage** message) {
LDAPControl** sctrlsp = NULL;
int res;
int msgid;
while(true) {
res = ldap_sasl_interactive_bind(ld, NULL, NULL,
sctrlsp, NULL, LDAP_SASL_QUIET, NULL, NULL,
*message, &sasl_mechanism, &msgid);
if(res != LDAP_SASL_BIND_IN_PROGRESS) {
break;
}
ldap_msgfree(*message);
if(ldap_result(ld, msgid, LDAP_MSG_ALL, NULL, message) == -1) {
ldap_get_option(ld, LDAP_OPT_RESULT_CODE, &res);
break;
}
}
return res;
}