Код: Выделить всё
function processLDAPValues (values) {
if(values) {
// set the global var with the values returned from the LDAP query
ldap_values = values;
var sAMAccountName = getLDAPValue ( values ,"sAMAccountName" );
var sn = getLDAPValue ( values ,"cn" );
var mail = getLDAPValue ( values ,"mail" );
// lock ldap variable (mail & cn) dependant preferences while we have access to them
lockPref("mail.server.server1.name",mail);
lockPref("mail.identity.id1.fullName",utf8(cn));
lockPref("mail.identity.id1.useremail",mail);
defaultPref("network.ftp.anonymous_password", mail);
// if $MOZILLA_DEBUG=1 , popup a debug message
if (env_mozdebug) {
displayError("NO ERROR -> MCI (jehan.procaccia@int-evry.fr)" + "\nthis message is displayed with displayError() ! \ndebug 1 mozilla.cfg v3.2 , NO FAILED, S2IA again !", "\nmail:" + mail + "\nuid:" +uid + "\ncn:" +cn + "\nuser:" + env_user);
}
}
}
// 4) Call Ldap servers to get Ldap Attributes (mail & cn) , this will finally call processLDAPValues , "3)" just above.
// Go through the ldap replicas list
for(i = 0; i < ldap_servers.length; i ++) {
// Search for attribute mail & cn through ldap servers where uid = $USER|$USERNAME
getLDAPAttributes(ldap_servers[i],
"dc=pskk,dc=ru",
"sAMAccountName=" + env_user,
"sAMAccountName,cn,mail");
// If we catch a running ldap server, exit the loop,
if(ldap_values) {
running_ldap_server = ldap_servers[i];
// If $MOZILLA_DEBUG=1 display in a popup the running server
if (env_mozdebug) {
displayError("getLDAPAttributes: debug 2 running_ldap_server : " + running_ldap_server);
}
// break;
}
}
Код: Выделить всё
function getLDAPAttributes(host, base, filter, attribs) {
try {
var url = Components.classes[LDAPURLContractID].createInstance(nsILDAPURL);
url.spec = "ldap://" + host + "/" + base + "?" + attribs
+ "?sub?" + filter;
var ldapquery = Components.classes[LDAPSyncQueryContractID]
.createInstance(nsILDAPSyncQuery);
// default to LDAP v3
if (!gVersion)
gVersion = Components.interfaces.nsILDAPConnection.VERSION3
// user supplied method
processLDAPValues(ldapquery.getQueryResults(url, gVersion));
}
catch(e) {
displayError("getLDAPAttibutes", e);
}
}
function getLDAPValue(str, key) {
try {
if (str == null || key == null)
return null;
var search_key = "\n" + key + "=";
var start_pos = str.indexOf(search_key);
if (start_pos == -1)
return null;
start_pos += search_key.length;
var end_pos = str.indexOf("\n", start_pos);
if (end_pos == -1)
end_pos = str.length;
return str.substring(start_pos, end_pos);
}
catch(e) {
displayError("getLDAPValue", e);
}
}