node-LDAP icon indicating copy to clipboard operation
node-LDAP copied to clipboard

Error: Protocol Error on ldap.add

Open jb181991 opened this issue 8 years ago • 3 comments

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!"); } });

jb181991 avatar Nov 08 '17 18:11 jb181991

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!

ghost avatar Nov 15 '17 14:11 ghost

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 avatar Feb 20 '19 15:02 Oscar492

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

Oscar492 avatar Feb 20 '19 16:02 Oscar492