This repository has been archived by the owner on Sep 25, 2020. It is now read-only.
forked from ldapjs/node-ldapjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial working client/server version
- Loading branch information
Mark Cavage
committed
Aug 4, 2011
0 parents
commit ca1443f
Showing
82 changed files
with
8,304 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
*.log | ||
*.ldif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2011 Mark Cavage, All rights reserved. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
node-ldapjs will blow your mind. Docs coming soon. | ||
|
||
## Installation | ||
|
||
npm install ldapjs | ||
|
||
## License | ||
|
||
MIT. | ||
|
||
## Bugs | ||
|
||
See <https://github.com/mcavage/node-ldapjs/issues>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// Copyright 2011 Mark Cavage, Inc. All rights reserved. | ||
|
||
var assert = require('assert'); | ||
|
||
var Protocol = require('./protocol'); | ||
|
||
|
||
|
||
///--- API | ||
|
||
function Attribute(options) { | ||
if (options) { | ||
if (typeof(options) !== 'object') | ||
throw new TypeError('options must be an object'); | ||
if (options.type && typeof(options.type) !== 'string') | ||
throw new TypeError('options.type must be a string'); | ||
if (options.vals && !Array.isArray(options.vals)) | ||
throw new TypeErrr('options.vals must be an array[string]'); | ||
if (options.vals && options.vals.length) { | ||
options.vals.forEach(function(v) { | ||
if (typeof(v) !== 'string') | ||
throw new TypeErrr('options.vals must be an array[string]'); | ||
}); | ||
} | ||
} else { | ||
options = {}; | ||
} | ||
|
||
this.type = options.type || ''; | ||
this.vals = options.vals ? options.vals.slice(0) : []; | ||
|
||
var self = this; | ||
this.__defineGetter__('json', function() { | ||
return { | ||
type: self.type, | ||
vals: self.vals | ||
}; | ||
}); | ||
} | ||
module.exports = Attribute; | ||
|
||
|
||
Attribute.prototype.addValue = function(val) { | ||
if (typeof(val) !== 'string') | ||
throw new TypeError('val (string) required'); | ||
|
||
this.vals.push(val); | ||
}; | ||
|
||
|
||
Attribute.prototype.parse = function(ber) { | ||
assert.ok(ber); | ||
|
||
ber.readSequence(); | ||
this.type = ber.readString(); | ||
|
||
|
||
if (ber.readSequence(Protocol.LBER_SET)) { | ||
var end = ber.offset + ber.length; | ||
while (ber.offset < end) { | ||
var val = ber.readString(); | ||
this.vals.push(val); | ||
} | ||
} | ||
|
||
return true; | ||
}; | ||
|
||
|
||
Attribute.prototype.toBer = function(ber) { | ||
assert.ok(ber); | ||
|
||
ber.startSequence(); | ||
ber.writeString(this.type); | ||
if (this.vals && this.vals.length) { | ||
ber.startSequence(Protocol.LBER_SET); | ||
ber.writeStringArray(this.vals); | ||
ber.endSequence(); | ||
} | ||
ber.endSequence(); | ||
|
||
return ber; | ||
}; | ||
|
||
Attribute.toBer = function(attr, ber) { | ||
return Attribute.prototype.toBer.call(attr, ber); | ||
}; | ||
|
||
|
||
Attribute.isAttribute = function(attr) { | ||
if (typeof(attr) !== 'object') return false; | ||
if (attr instanceof Attribute) return true; | ||
if (!attr.type || typeof(attr.type) !== 'string') return false; | ||
if (!attr.vals || !Array.isArray(attr.vals)) return false; | ||
for (var i = 0; i < attr.vals.length; i++) | ||
if (typeof(attr.vals[i]) !== 'string') return false; | ||
|
||
return true; | ||
}; | ||
|
||
|
||
Attribute.prototype.toString = function() { | ||
return JSON.stringify(this.json); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright 2011 Mark Cavage, Inc. All rights reserved. | ||
|
||
var assert = require('assert'); | ||
|
||
var Attribute = require('./attribute'); | ||
var Protocol = require('./protocol'); | ||
|
||
|
||
|
||
///--- API | ||
|
||
function Change(options) { | ||
if (options) { | ||
if (typeof(options) !== 'object') | ||
throw new TypeError('options must be an object'); | ||
if (options.operation && typeof(options.operation) !== 'string') | ||
throw new TypeError('options.operation must be a string'); | ||
if (options.modification && !(options.modification instanceof Attribute)) | ||
throw new TypeErrr('options.modification must be an Attribute'); | ||
} else { | ||
options = {}; | ||
} | ||
|
||
var self = this; | ||
this.__defineGetter__('operation', function() { | ||
switch (self._operation) { | ||
case 0x00: return 'Add'; | ||
case 0x01: return 'Delete'; | ||
case 0x02: return 'Replace'; | ||
default: return 'Invalid'; | ||
} | ||
}); | ||
this.__defineSetter__('operation', function(val) { | ||
if (typeof(val) !== 'string') | ||
throw new TypeError('operation must be a string'); | ||
|
||
switch (val.toLowerCase()) { | ||
case 'add': | ||
self._operation = 0x00; | ||
break; | ||
case 'delete': | ||
self._operation = 0x01; | ||
break; | ||
case 'replace': | ||
self._operation = 0x02; | ||
break; | ||
default: | ||
throw new Error('Invalid operation type: 0x' + val.toString(16)); | ||
} | ||
}); | ||
|
||
this.__defineGetter__('json', function() { | ||
return { | ||
operation: self.operation, | ||
modification: self.modification ? self.modification.json : {} | ||
}; | ||
}); | ||
|
||
this.operation = options.operation || 'add'; | ||
this.modification = options.modification || null; | ||
} | ||
module.exports = Change; | ||
|
||
|
||
Change.prototype.parse = function(ber) { | ||
assert.ok(ber); | ||
|
||
ber.readSequence(); | ||
this._operation = ber.readEnumeration(); | ||
this.modification = new Attribute(); | ||
this.modification.parse(ber); | ||
|
||
return true; | ||
}; | ||
|
||
|
||
Change.prototype.toBer = function(ber) { | ||
assert.ok(ber); | ||
|
||
ber.startSequence(); | ||
ber.writeEnumeration(this._operation); | ||
ber = this.modification.toBer(ber); | ||
ber.endSequence(); | ||
|
||
return ber; | ||
}; |
Oops, something went wrong.