Guest User

Untitled

a guest
Jul 3rd, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. // Before running this script, set the LDAP_PASSWORD environment variable in
  2. // the shell. You can do this without echoing the password by running:
  3. //
  4. // read -s LDAP_PASSWORD && export LDAP_PASSWORD
  5. //
  6. // You'll also need to modify the variable definitions at the top of this file.
  7.  
  8. // == BEGIN configuration variables ===============
  9.  
  10. var url = "ldap://adtest.rstudio.com/dc=adtest,dc=rstudio,dc=com";
  11. var username = "john";
  12. var suffix = "adtest.rstudio.com";
  13.  
  14. var search_base = "cn=Users,dc=adtest,dc=rstudio,dc=com";
  15. var search_filter = "(member:1.2.840.113556.1.4.1941:=CN=John Doe,CN=Users,DC=adtest,DC=rstudio,DC=com)";
  16.  
  17. // == END configuration variables =================
  18.  
  19.  
  20.  
  21. var username = username + "@" + suffix;
  22. var password = process.env.LDAP_PASSWORD;
  23. if (!password) {
  24. console.error("LDAP_PASSWORD not set. Set it by calling 'read -s LDAP_PASSWORD && export LDAP_PASSWORD' from the shell.");
  25. process.exit(1);
  26. }
  27.  
  28. var ldapjs = require("ldapjs");
  29. var client = ldapjs.createClient({url: url});
  30. client.bind(username, password, function(err) {
  31. if (!err) {
  32. console.error("Successful bind.");
  33.  
  34. var opts = {
  35. scope: "sub",
  36. filter: search_filter,
  37. attributes: ["dn"]
  38. };
  39. client.search(search_base, opts, function(err, res) {
  40. if (err) {
  41. console.error("Error performing search:");
  42. console.error(err);
  43. process.exit(1);
  44. }
  45.  
  46. res.on('searchEntry', function(entry) {
  47. console.log('entry: ' + JSON.stringify(entry.object));
  48. });
  49. res.on('searchReference', function(referral) {
  50. console.log('referral: ' + referral.uris.join());
  51. });
  52. res.on('error', function(err) {
  53. console.error('error: ' + err.message);
  54. });
  55. res.on('end', function(result) {
  56. console.log('status: ' + result.status);
  57. client.unbind();
  58. });
  59. });
  60. } else {
  61. console.error(err);
  62. process.exit(1);
  63. }
  64. });
Add Comment
Please, Sign In to add comment