public getAttribute ( System attrName ) : |
||
attrName | System | The name of the attribute or attributes to return. /// /// |
return |
public static string[] CheckRequiredAttributes(Connection conn, LdapEntry entry) { List<string> missingAttributes = new List<string> (); LdapAttribute objAttr = entry.getAttribute ("objectClass"); if (objAttr == null) return null; foreach (string o in objAttr.StringValueArray) { if (o.Equals ("top")) continue; string[] reqs = conn.Data.GetRequiredAttrs (o); if (reqs == null) continue; foreach (string r in reqs) { if (r.Equals ("cn")) continue; if (IsAttributeEmpty (entry.getAttribute (r))) { missingAttributes.Add (r); continue; } } } return missingAttributes.ToArray(); }
/// <summary> Compares the the attributes of the first LdapEntry to the second. /// Only the values of the attributes named at the construction of this /// object will be compared. Multi-valued attributes compare on the first /// value only. /// /// </summary> /// <param name="object1"> Target entry for comparison. /// /// </param> /// <param name="object2"> Entry to be compared to. /// /// </param> /// <returns> Negative value if the first entry is less than the second and /// positive if the first is greater than the second. Zero is returned if all /// attributes to be compared are the same. /// </returns> public virtual int Compare(object object1, object object2) { LdapEntry entry1 = (LdapEntry)object1; LdapEntry entry2 = (LdapEntry)object2; LdapAttribute one, two; string[] first; //multivalued attributes are ignored. string[] second; //we just use the first element int compare, i = 0; if (collator == null) { //using default locale collator = System.Globalization.CultureInfo.CurrentCulture.CompareInfo; } do { //while first and second are equal one = entry1.getAttribute(sortByNames[i]); two = entry2.getAttribute(sortByNames[i]); if ((one != null) && (two != null)) { first = one.StringValueArray; second = two.StringValueArray; compare = collator.Compare(first[0], second[0]); } //We could also use the other multivalued attributes to break ties. //one of the entries was null else { if (one != null) { compare = -1; } //one is greater than two else if (two != null) { compare = 1; } //one is lesser than two else { compare = 0; //tie - break it with the next attribute name } } i++; }while ((compare == 0) && (i < sortByNames.Length)); if (sortAscending[i - 1]) { // return the normal ascending comparison. return(compare); } // negate the comparison for a descending comparison. return(-compare); }
private void addTelephoneNumber(NameValueCollection collection, LdapEntry entry, string name, string attributeName) { LdapAttribute attribute; attribute = entry.getAttribute(attributeName); if(attribute != null) collection.Add(name, Contact.NormaliseTelephoneNumber(attribute.StringValue)); }
public static bool CheckSamba(LdapEntry le) { bool retVal = false; LdapAttribute la = le.getAttribute ("objectClass"); if (la == null) return retVal; foreach (string s in la.StringValueArray) if (s.ToLower() == "sambasamaccount") retVal = true; return retVal; }
public CreateEntryDialog(Connection connection, LdapEntry le) { if (connection == null) throw new ArgumentNullException("connection"); if (le == null) throw new ArgumentNullException("le"); conn = connection; Init (); LdapAttribute la = le.getAttribute ("objectClass"); foreach (string s in la.StringValueArray) { attrListStore.AppendValues ("objectClass", s, "Optional"); _objectClass.Add (s); } showAttributes (); createEntryDialog.Run (); while (errorOccured) createEntryDialog.Run (); createEntryDialog.Destroy (); }
private string GetAttributeSafe(LdapEntry entry, string attributeName) { string ret = string.Empty; if (entry != null && !String.IsNullOrEmpty(attributeName)) { LdapAttribute attr = entry.getAttribute(attributeName); if (attr != null) ret = attr.StringValue; } return ret; }
public void Run(LdapEntry lhs, LdapEntry rhs) { Log.Debug ("Starting LdapEntryAnalyzer"); if (lhs.CompareTo (rhs) != 0) { Log.Debug ("Entry DNs don't match\nlhs: {0}\nrhs: {1}", lhs.DN, rhs.DN); return; } LdapAttributeSet las = lhs.getAttributeSet (); foreach (LdapAttribute la in las) { LdapAttribute rla = rhs.getAttribute (la.Name); if (rla == null){ Log.Debug ("Delete attribute {0} from {1}", la.Name, lhs.DN); LdapAttribute a = new LdapAttribute (la.Name); LdapModification m = new LdapModification (LdapModification.DELETE, a); mods.Add (m); } else { if (rla.StringValueArray.Length > 1) { Log.Debug ("Replacing attribute {0} with multiple values", la.Name); LdapAttribute a = new LdapAttribute (la.Name, rla.StringValueArray); LdapModification m = new LdapModification (LdapModification.REPLACE, a); mods.Add (m); } else if (la.StringValue != rla.StringValue) { LdapAttribute newattr; LdapModification lm; if (rla.StringValue == "" || rla.StringValue == null) { Log.Debug ("Delete attribute {0} from {1}", la.Name, lhs.DN); newattr = new LdapAttribute (la.Name); lm = new LdapModification (LdapModification.DELETE, newattr); } else { Log.Debug ("Replace attribute {0} value from {1} to {2} ", la.Name, la.StringValue, rla.StringValue); newattr = new LdapAttribute (la.Name, rla.StringValue); lm = new LdapModification (LdapModification.REPLACE, newattr); } mods.Add (lm); } } } LdapAttributeSet rlas = rhs.getAttributeSet (); foreach (LdapAttribute la in rlas) { LdapAttribute lla = lhs.getAttribute (la.Name); if (lla == null && la.StringValue != string.Empty) { Log.Debug ("Add attribute {0} value [{1}] to {2}", la.Name, la.StringValue, lhs.DN); LdapAttribute a = new LdapAttribute (la.Name, la.StringValue); LdapModification m = new LdapModification (LdapModification.ADD, a); mods.Add (m); } } Log.Debug ("End LdapEntryAnalyzer"); }
public GroupsViewDialog(Connection connection, LdapEntry le) : base(connection, null) { currentEntry = le; isEdit = true; isSamba = checkSamba (currentEntry); Init (); string groupName = conn.Data.GetAttributeValueFromEntry (currentEntry, "cn"); groupDialog.Title = groupName + " Properties"; groupNameEntry.Text = groupName; descriptionEntry.Text = conn.Data.GetAttributeValueFromEntry (currentEntry, "description"); try { groupIDSpinButton.Value = int.Parse (conn.Data.GetAttributeValueFromEntry (currentEntry, "gidNumber")); } catch {} LdapAttribute attr = currentEntry.getAttribute ("memberuid"); if (attr != null) { foreach (string s in attr.StringValueArray) { currentMemberStore.AppendValues (s); currentMembers.Add (s); } } populateUsers (); groupDialog.Run (); while (missingValues || errorOccured){ if (missingValues) missingValues = false; else if (errorOccured) errorOccured = false; groupDialog.Run (); } groupDialog.Destroy (); }
private void SetActiveDirectoryInfo(LdapEntry dse) { LdapAttribute a = dse.getAttribute ("dnsHostName"); adInfo.DnsHostName = a.StringValue; LdapAttribute b = dse.getAttribute ("domainControllerFunctionality"); if (b.StringValue == "0") adInfo.DomainControllerFunctionality = "Windows 2000 Mode"; else if (b.StringValue == "2") adInfo.DomainControllerFunctionality = "Windows Server 2003 Mode"; else adInfo.DomainControllerFunctionality = ""; LdapAttribute c = dse.getAttribute ("forestFunctionality"); if (c.StringValue == "0") adInfo.ForestFunctionality = "Windows 2000 Forest Mode"; else if (c.StringValue == "1") adInfo.ForestFunctionality = "Windows Server 2003 Interim Forest Mode"; else if (c.StringValue == "2") adInfo.ForestFunctionality = "Windows Server 2003 Forest Mode"; else adInfo.ForestFunctionality = ""; LdapAttribute d = dse.getAttribute ("domainFunctionality"); if (d.StringValue == "0") adInfo.DomainFunctionality = "Windows 2000 Domain Mode"; else if (d.StringValue == "1") adInfo.DomainFunctionality = "Windows Server 2003 Interim Domain Mode"; else if (d.StringValue == "2") adInfo.DomainFunctionality = "Windows Server 2003 Domain Mode"; else adInfo.DomainFunctionality = ""; LdapAttribute e = dse.getAttribute ("isGlobalCatalogReady"); adInfo.IsGlobalCatalogReady = bool.Parse (e.StringValue); LdapAttribute f = dse.getAttribute ("isSynchronized"); adInfo.IsSynchronized = bool.Parse (f.StringValue); }
bool checkSamba(LdapEntry le) { bool retVal = false; LdapAttribute la = le.getAttribute ("objectClass"); if (la == null) return retVal; foreach (string s in la.StringValueArray) if (s.ToLower() == "sambagroupmapping") retVal = true; return retVal; }
public GroupsViewDialog(Connection connection, LdapEntry le) : base(connection, null) { currentEntry = le; isEdit = true; Init (); string groupName = conn.Data.GetAttributeValueFromEntry (currentEntry, "cn"); groupDialog.Title = groupName + " Properties"; groupNameEntry.Text = groupName; descriptionEntry.Text = conn.Data.GetAttributeValueFromEntry (currentEntry, "description"); LdapAttribute attr = currentEntry.getAttribute ("member"); if (attr != null) { foreach (string s in attr.StringValueArray) { LdapEntry userEntry = conn.Data.GetEntry (s); LdapAttribute userNameAttribute = userEntry.getAttribute ("name"); currentMemberStore.AppendValues (userNameAttribute.StringValue); currentMembers.Add (userNameAttribute.StringValue); } } populateUsers (); groupDialog.Run (); while (missingValues || errorOccured){ if (missingValues) missingValues = false; else if (errorOccured) errorOccured = false; groupDialog.Run (); } groupDialog.Destroy (); }
/// <summary>Gets the value of the given attribute for the given /// entry. /// </summary> /// <param name="le">LdapEntry</param> /// <param name="attrs">List of attributes to lookup</param> /// <returns>A list of attribute values</returns> public string[] GetAttributeValuesFromEntry(LdapEntry le, string[] attrs) { if (le == null || attrs == null) throw new ArgumentNullException (); List<string> retVal = new List<string> (); foreach (string n in attrs) { LdapAttribute la = le.getAttribute (n); if (la != null) retVal.Add (la.StringValue); else retVal.Add (""); } return retVal.ToArray (); }
/// <summary>Gets the value of an attribute for the given /// entry. /// </summary> /// <param name="le">LdapEntry</param> /// <param name="attr">Attribute to lookup type</param> /// <returns>The value of the attribute (or an empty string if there is /// no value).</returns> public string GetAttributeValueFromEntry(LdapEntry le, string attr) { LdapAttribute la = le.getAttribute (attr); if (la != null) return la.StringValue; return ""; }
public void Show(Connection connection, LdapEntry entry, bool showAll) { displayAll = showAll; conn = connection; currentDN = entry.DN; currentAttributes = new NameValueCollection (); // FIXME: crashes after an apply if I don't re-create the store; store = new ListStore (typeof (string), typeof(string)); store.SetSortColumnId (0, SortType.Ascending); tv.Model = store; // store.Clear (); allAttrs = new List<string> (); LdapAttribute a = entry.getAttribute ("objectClass"); for (int i = 0; i < a.StringValueArray.Length; i++) { string o = (string) a.StringValueArray[i]; store.AppendValues ("objectClass", o); currentAttributes.Add ("objectClass", o); string[] attrs = conn.Data.GetAllAttributes (o); if (attrs != null) { foreach (string at in attrs) if (!allAttrs.Contains (at)) allAttrs.Add (at); } else { Log.Debug("Could not retrieve any attribute for objectClass " + o); } } LdapAttributeSet attributeSet = entry.getAttributeSet (); // Fedora Directory Server supports an Access Control Item (ACI) // but it is not listed as "allowed attribute" for any objectClass // found in Fedora's LDAP schema. if (showAll && conn.Settings.ServerType == LdapServerType.FedoraDirectory) { LdapEntry[] acientries = conn.Data.Search( currentDN, LdapConnection.SCOPE_BASE, "objectclass=*", new string[] {"aci"} ); if (acientries.Length > 0) { LdapEntry acientry = acientries[0]; LdapAttribute aciattr = acientry.getAttribute("aci"); if (aciattr != null) if (attributeSet.Add(aciattr) == false) Log.Debug ("Could not add ACI attribute."); } } foreach (LdapAttribute attr in attributeSet) { if (allAttrs.Contains (attr.Name)) allAttrs.Remove (attr.Name); if (attr.Name.ToLower() == "objectclass") continue; try { foreach (string s in attr.StringValueArray) { store.AppendValues (attr.Name, s); currentAttributes.Add (attr.Name, s); } } catch (ArgumentOutOfRangeException e) { // FIXME: this only happens with gmcs store.AppendValues (attr.Name, ""); Log.Debug ("Show attribute arugment out of range: {0}", attr.Name); Log.Debug (e.Message); } } if (!showAll) return; foreach (string n in allAttrs) store.AppendValues (n, ""); }