From 97ed08861ad36710891689a102e06abf49a87395 Mon Sep 17 00:00:00 2001
From: maltewirz <32659282+maltewirz@users.noreply.github.com>
Date: Thu, 10 Dec 2020 14:36:17 +0100
Subject: [PATCH 1/2] Update guide.md

Dear authors, many thanks for your project. When following your guide, the code crashed when i tried to add a user from the ldif file. I needed the code to change as seen above (the object includes a "attrs" key).
---
 docs/guide.md | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/docs/guide.md b/docs/guide.md
index 1c56a34..5d403a4 100644
--- a/docs/guide.md
+++ b/docs/guide.md
@@ -400,10 +400,10 @@ the following code in as another handler (you'll need a
 `var spawn = require('child_process').spawn;` at the top of your file):
 
     server.add('ou=users, o=myhost', pre, function(req, res, next) {
-      if (!req.dn.rdns[0].cn)
+      if (!req.dn.rdns[0].attrs.cn)
         return next(new ldap.ConstraintViolationError('cn required'));
 
-      if (req.users[req.dn.rdns[0].cn])
+      if (req.users[req.dn.rdns[0].attrs.cn])
         return next(new ldap.EntryAlreadyExistsError(req.dn.toString()));
 
       var entry = req.toObject().attributes;
@@ -487,10 +487,10 @@ Let's confirm he got added with an ldapsearch:
 As before, here's a breakdown of the code:
 
     server.add('ou=users, o=myhost', pre, function(req, res, next) {
-      if (!req.dn.rdns[0].cn)
+      if (!req.dn.rdns[0].attrs.cn)
         return next(new ldap.ConstraintViolationError('cn required'));
 
-      if (req.users[req.dn.rdns[0].cn])
+      if (req.users[req.dn.rdns[0].attrs.cn])
         return next(new ldap.EntryAlreadyExistsError(req.dn.toString()));
 
       var entry = req.toObject().attributes;
@@ -532,13 +532,13 @@ RFC, so appending, removing, or replacing a single attribute is pretty natural.
 Go ahead and add the following code into your source file:
 
     server.modify('ou=users, o=myhost', pre, function(req, res, next) {
-      if (!req.dn.rdns[0].cn || !req.users[req.dn.rdns[0].cn])
+      if (!req.dn.rdns[0].attrs.cn || !req.users[req.dn.rdns[0].attrs.cn])
         return next(new ldap.NoSuchObjectError(req.dn.toString()));
 
       if (!req.changes.length)
         return next(new ldap.ProtocolError('changes required'));
 
-      var user = req.users[req.dn.rdns[0].cn].attributes;
+      var user = req.users[req.dn.rdns[0].attrs.cn].attributes;
       var mod;
 
       for (var i = 0; i < req.changes.length; i++) {
@@ -594,7 +594,7 @@ Delete is pretty straightforward. The client gives you a dn to delete, and you
 delete it :).  Add the following code into your server:
 
     server.del('ou=users, o=myhost', pre, function(req, res, next) {
-      if (!req.dn.rdns[0].cn || !req.users[req.dn.rdns[0].cn])
+      if (!req.dn.rdns[0].attrs.cn || !req.users[req.dn.rdns[0].attrs.cn])
         return next(new ldap.NoSuchObjectError(req.dn.toString()));
 
       var userdel = spawn('userdel', ['-f', req.dn.rdns[0].cn]);

From d8c25249fe821e781c07406a95ba629b18b212ed Mon Sep 17 00:00:00 2001
From: Tony Brix <tony@brix.ninja>
Date: Thu, 10 Dec 2020 10:03:29 -0600
Subject: [PATCH 2/2] docs: attr value

---
 docs/guide.md | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/docs/guide.md b/docs/guide.md
index 5d403a4..13bce6c 100644
--- a/docs/guide.md
+++ b/docs/guide.md
@@ -403,7 +403,7 @@ the following code in as another handler (you'll need a
       if (!req.dn.rdns[0].attrs.cn)
         return next(new ldap.ConstraintViolationError('cn required'));
 
-      if (req.users[req.dn.rdns[0].attrs.cn])
+      if (req.users[req.dn.rdns[0].attrs.cn.value])
         return next(new ldap.EntryAlreadyExistsError(req.dn.toString()));
 
       var entry = req.toObject().attributes;
@@ -490,7 +490,7 @@ As before, here's a breakdown of the code:
       if (!req.dn.rdns[0].attrs.cn)
         return next(new ldap.ConstraintViolationError('cn required'));
 
-      if (req.users[req.dn.rdns[0].attrs.cn])
+      if (req.users[req.dn.rdns[0].attrs.cn.value])
         return next(new ldap.EntryAlreadyExistsError(req.dn.toString()));
 
       var entry = req.toObject().attributes;
@@ -532,13 +532,13 @@ RFC, so appending, removing, or replacing a single attribute is pretty natural.
 Go ahead and add the following code into your source file:
 
     server.modify('ou=users, o=myhost', pre, function(req, res, next) {
-      if (!req.dn.rdns[0].attrs.cn || !req.users[req.dn.rdns[0].attrs.cn])
+      if (!req.dn.rdns[0].attrs.cn || !req.users[req.dn.rdns[0].attrs.cn.value])
         return next(new ldap.NoSuchObjectError(req.dn.toString()));
 
       if (!req.changes.length)
         return next(new ldap.ProtocolError('changes required'));
 
-      var user = req.users[req.dn.rdns[0].attrs.cn].attributes;
+      var user = req.users[req.dn.rdns[0].attrs.cn.value].attributes;
       var mod;
 
       for (var i = 0; i < req.changes.length; i++) {
@@ -594,10 +594,10 @@ Delete is pretty straightforward. The client gives you a dn to delete, and you
 delete it :).  Add the following code into your server:
 
     server.del('ou=users, o=myhost', pre, function(req, res, next) {
-      if (!req.dn.rdns[0].attrs.cn || !req.users[req.dn.rdns[0].attrs.cn])
+      if (!req.dn.rdns[0].attrs.cn || !req.users[req.dn.rdns[0].attrs.cn.value])
         return next(new ldap.NoSuchObjectError(req.dn.toString()));
 
-      var userdel = spawn('userdel', ['-f', req.dn.rdns[0].cn]);
+      var userdel = spawn('userdel', ['-f', req.dn.rdns[0].attrs.cn.value]);
 
       var messages = [];
       userdel.stdout.on('data', function(data) {