UNPKG

1.47 kBJavaScriptView Raw
1const ldap = require('ldapjs')
2
3function encodePassword (password) {
4 var newPassword = ''
5 password = "\"" + password + "\""
6 for(var i = 0; i < password.length; i++){
7 newPassword += String.fromCharCode( password.charCodeAt(i) & 0xFF,(password.charCodeAt(i) >>> 8) & 0xFF)
8 }
9 return newPassword
10}
11
12//some useful constants from lmaccess.h used for setting LDAP user attributes
13const UF_ACCOUNTDISABLE = 0x0002
14const UF_PASSWD_NOTREQD = 0x0020
15const UF_PASSWD_CANT_CHANGE = 0x0040
16const UF_NORMAL_ACCOUNT = 0x0200
17const UF_DONT_EXPIRE_PASSWD = 0x10000
18const UF_PASSWORD_EXPIRED = 0x800000
19
20module.exports = {
21 replacePassword (password) {
22 return new ldap.Change({
23 operation: 'replace',
24 modification: {
25 unicodePwd: encodePassword(password)
26 }
27 })
28 },
29 deletePassword(password) {
30 return new ldap.Change({
31 operation: 'delete',
32 modification: {
33 unicodePwd: encodePassword(password)
34 }
35 })
36 },
37 addPassword(password) {
38 return new ldap.Change({
39 operation: 'add',
40 modification: {
41 unicodePwd: encodePassword(password)
42 }
43 })
44 },
45 enableUser() {
46 return new ldap.Change({
47 operation: 'replace',
48 modification: {
49 userAccountControl: String(UF_NORMAL_ACCOUNT)
50 }
51 })
52 },
53 disableUser() {
54 return new ldap.Change({
55 operation: 'replace',
56 modification: {
57 userAccountControl: String(UF_ACCOUNTDISABLE)
58 }
59 })
60 }
61}