jeremycx / node-LDAP

LDAP binding for node.js
MIT License
221 stars 43 forks source link

Error: Protocol Error on ldap.add #105

Open jb181991 opened 6 years ago

jb181991 commented 6 years ago

I get Protocol Error when I add user but successful in binding to admin. Please let me know what did I missed. Here is my code:

var LDAP = require('ldap-client');

var ldap = new LDAP({ uri: 'ldap://192.168.1.250' // optional function to call when disconnect occurs }, function(err) { ldap.bind({ binddn: 'cn=admin,dc=sample,dc=com', password: 'p1n0yak0m3' }, function(err, data){ if(err) { console.log(err); }else{ console.log("success binding"); } }); });

var attrs = [ { attr: 'gidNumber', vals: [ '501' ] }, { attr: 'objectClass', vals: [ 'posixAccount', 'top', 'inetOrgPerson' ] }, { attr: 'uidNumber', vals: [ '1000' ] }, { attr: 'userPassword', vals: [ 'password' ] }, { attr: 'homeDirectory', vals: [ '/home/fsmith' ] }, { attr: 'cn', vals: [ 'fred smith' ] }, { attr: 'sn', vals: [ 'smith' ] }, { attr: 'loginShell', vals: ['/bin/bash'] }, { attr: 'dn', vals: ['cn=fred smith,cn=Investor,ou=arcana,dc=sample,dc=com'] } ];

ldap.add('cn=fred smith,cn=Investor,ou=arcana,dc=sample,dc=com', [attrs], function(err){ if(err) { console.log(err); }else{ console.log("Success!"); } });

ghost commented 6 years ago

I have the same error, trying to add a person....

i have no problem for bind, search and everything execpt adding a user with this : var attrs = [ { attr: 'objectClass', vals: [ 'top', 'person' ] }, { attr: 'sn', vals: [ 'testingBot' ] }, { attr: 'badattr', vals: [ 'Fried' ] }, { attr: 'userPassword', vals: [ 'testing' ] } ]

ldap.add("cn=test,ou=users,dc=exemple,dc=com", [attrs], function(err){ if (err) { console.log(err); ldap.close(); } else { console.log('succes?'); ldap.close(); } });

Someone fix it ? or know from here the probleme become ? Thanks all!

Oscar492 commented 5 years ago

solved!, just remove the [ ] from your call to ldap.add("cn=test,ou=users,dc=exemple,dc=com", [attrs],...) and it will work. Otherwise you create a list of a list ;) I had the same problem btw

Oscar492 commented 5 years ago

check out the tests that comes with in the library, they are pretty helpful when someone wants to get how to use the functions. All functions work just fine, so far