Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | const _ = require('underscore'); const User = require('../models/user'); const Group = require('../models/group'); const joinAttributes = require('./internal/service.joinAttributes'); const getRequiredLdapAttributesForGroup = require('./internal/service.getRequiredLdapAttributesForUser'); const includeGroupMembershipFor = require('./internal/service.includeGroupMembershipFor'); const search = require('./internal/service.search'); const truncateLogOutput = require('./internal/service.truncateLogOutput'); const pickAttributes = require('./internal/service.pickAttributes'); const getRequiredLdapAttributesForUser = require('./internal/service.getRequiredLdapAttributesForUser'); const isGroupResult = require('./internal/service.isGroupResult'); const isUserResult = require('./internal/service.isUserResult'); const getGroupMembershipForDN = require('./service.getGroupMembershipForDn'); let log = require('./internal/service.log'); let defaultAttributes = require('../configs/config.defaultAttributes'); /** * Perform a generic search for the specified LDAP query filter. This function will return both * groups and users that match the specified filter. Any results not recognized as a user or group * (i.e. computer accounts, etc.) can be found in the 'other' attribute / array of the result. * * @public * @param {Object} [opts] Optional LDAP query string parameters to execute. { scope: '', filter: '', attributes: [ '', '', ... ], sizeLimit: 0, timelimit: 0 }. Optionally, if only a string is provided, then the string is assumed to be an LDAP filter. * @param {Function} callback The callback to execute when completed. callback(err: {Object}, { users: [ User ], groups: [ Group ], other: [ ] ) */ function find(opts, callback) { return new Promise((resolve, reject) => { var self = this; if (typeof (opts) === 'function') { callback = opts; opts = undefined; } if (typeof (opts) === 'string') { opts = { filter: opts }; } log.trace('find(%j)', opts); var localOpts = _.defaults(_.omit(opts || {}, 'attributes'), { scope: 'sub', attributes: joinAttributes((opts || {}).attributes || [], defaultAttributes.group || [], defaultAttributes.user || [], getRequiredLdapAttributesForGroup(opts), getRequiredLdapAttributesForUser(opts), ['objectCategory']) }); search.call(self, localOpts, function onFind(err, results) { if (err) { if (callback){ callback(err); } return reject(err); } if ((!results) || (results.length === 0)) { log.warn('No results found for query "%s"', truncateLogOutput(localOpts.filter)); if (callback){ callback(null, results); } self.emit('done'); return resolve(results); } var result = { users: [], groups: [], other: [] }; for(ind in results){ let item = results[ind]; if (isGroupResult(item)) { var group = new Group(pickAttributes(item, (opts || {}).attributes || defaultAttributes.group)); result.groups.push(group); // Also retrieving user group memberships? if (includeGroupMembershipFor(opts, 'group')) { getGroupMembershipForDN.call(self, opts, group.dn, function (err, groups) { if (err){ if(callback){ callback(err); } return reject(err); } group.groups = groups; self.emit('group', group); }); } else { self.emit('group', group); } } else if (isUserResult(item)) { var user = new User(pickAttributes(item, (opts || {}).attributes || defaultAttributes.user)); result.users.push(user); // Also retrieving user group memberships? if (includeGroupMembershipFor(opts, 'user')) { getGroupMembershipForDN.call(self, opts, user.dn, function (err, groups) { if (err){ if(callback){ callback(err); } return reject(err); } user.groups = groups; self.emit('user', user); }); } else { self.emit('user', user); } } else { var other = pickAttributes(item, (opts || {}).attributes || _.union(defaultAttributes.user, defaultAttributes.group)); result.other.push(other); self.emit('other', other); } } if(callback){ callback(null, result); } return resolve(result); }); }); }; module.exports = find; |