A set of {@link LdapAttribute} objects. An LdapAttributeSet is a collection of LdapAttribute classes as returned from an LdapEntry on a search or read operation. LdapAttributeSet may be also used to contruct an entry to be added to a directory. If the add() or addAll() methods are called and one or more of the objects to be added is not an LdapAttribute, ClassCastException is thrown (as discussed in the documentation for java.util.Collection).
Inheritance: SupportClass.AbstractSetSupport, System.ICloneable
示例#1
0
        /// <summary>
        /// Returns the attribute value specified in the second string parameter
        /// 
        /// TODO: Need more error handling 
        /// </summary>
        /// <param name="entry">
        /// A <see cref="LdapEntry"/>
        /// </param>
        /// <param name="attr">
        /// A <see cref="System.String"/>
        /// </param>
        /// <returns>
        /// A <see cref="System.String"/>
        /// </returns>
        public static string getAttr(LdapAttributeSet attrSet, ATTRNAME attr)
        {
            string sAttr = attr.ToString();
            Logger.Debug("Requesting Attribute value of {0}", attrSet.getAttribute(sAttr));

            if (attrSet.getAttribute(sAttr) == null)
                return null;
            else {
                Logger.Debug(" Attribute {0} -> {1}", sAttr, attrSet.getAttribute(sAttr).StringValue);
                return attrSet.getAttribute(sAttr).StringValue;
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            if ( args.Length != 5)
            {
            Console.WriteLine("Usage:   mono AddEntry <host name> <ldap port>  <login dn>" + " <password> <container>");
            Console.WriteLine("Example: mono AddEntry Acme.com 389"  + " \"cn=admin,o=Acme\"" + " secret \"ou=sales,o=Acme\"");
            return;
            }

            string ldapHost = args[0];
            int ldapPort = System.Convert.ToInt32(args[1]);
            String loginDN  = args[2];
            String password = args[3];
            String containerName = args[4];

            try
            {
            LdapAttributeSet attributeSet = new LdapAttributeSet();
            attributeSet.Add(	new LdapAttribute(
                                "objectclass", "inetOrgPerson"));
                                attributeSet.Add( new LdapAttribute("cn",
                                new string[]{"James Smith", "Jim Smith", "Jimmy Smith"}));
            attributeSet.Add(	new LdapAttribute("givenname",
                                 "James"));
            attributeSet.Add(	new LdapAttribute("sn", "Smith"));
            attributeSet.Add(	new LdapAttribute("telephonenumber","1 801 555 1212"));
            attributeSet.Add(	new LdapAttribute("mail", "*****@*****.**"));
            attributeSet.Add(	new LdapAttribute("userpassword","newpassword"));

            string  dn  = "cn=KSmith," + containerName;
            LdapEntry newEntry = new LdapEntry( dn, attributeSet );
            LdapConnection conn= new LdapConnection();
            Console.WriteLine("Connecting to:" + ldapHost);
            conn.Connect(ldapHost,ldapPort);
            conn.Bind(loginDN,password);
            conn.Add( newEntry );
            Console.WriteLine("Entry:" + dn + "  Added Successfully");
            conn.Disconnect();
            }
            catch(LdapException e)
            {
            Console.WriteLine("Error:" + e.LdapErrorMessage);
            return;
            }
            catch(Exception e)
            {
            Console.WriteLine("Error:" + e.Message);
            return;
            }
        }
示例#3
0
        void createUser(string dn, string name, string pass, string sid, 
					 string flags, string uid, string gid, 
					 string urid, string grid, string gecos)
        {
            LdapAttributeSet lset = new LdapAttributeSet ();
            lset.Add (new LdapAttribute ("objectclass", new string[] {"inetOrgPerson", "sambaSAMAccount", "posixAccount", "shadowAccount"}));
            lset.Add (new LdapAttribute ("cn", name));
            lset.Add (new LdapAttribute ("sn", name));
            lset.Add (new LdapAttribute ("gidNumber", gid));
            lset.Add (new LdapAttribute ("uid", name));
            lset.Add (new LdapAttribute ("uidNumber", uid));
            lset.Add (new LdapAttribute ("homeDirectory", "/dev/null"));
            lset.Add (new LdapAttribute ("sambaPwdLastSet", "0"));
            lset.Add (new LdapAttribute ("sambaLogonTime", "0"));
            lset.Add (new LdapAttribute ("sambaLogoffTime", "2147483647"));
            lset.Add (new LdapAttribute ("sambaKickoffTime", "2147483647"));
            lset.Add (new LdapAttribute ("sambaPwdCanChange", "0"));
            lset.Add (new LdapAttribute ("sambaPwdMustChange", "2147483647"));
            lset.Add (new LdapAttribute ("sambaPrimaryGroupSID", sid + "-" + grid));
            lset.Add (new LdapAttribute ("sambaLMPassword", pass));
            lset.Add (new LdapAttribute ("sambaNTPassword", pass));
            lset.Add (new LdapAttribute ("sambaAcctFlags", flags));
            lset.Add (new LdapAttribute ("sambaSID", sid + "-" + urid));
            lset.Add (new LdapAttribute ("loginShell", "/bin/false"));
            lset.Add (new LdapAttribute ("gecos", gecos));

            LdapEntry entry = new LdapEntry (dn, lset);
            Connection conn = GetCurrentConnection ();
            Util.AddEntry (conn, entry);
        }
示例#4
0
        LdapEntry CreateEntry(string dn)
        {
            LdapAttributeSet aset = new LdapAttributeSet();

            TreeIter iter;

            if (primaryGroupComboBox.GetActiveIter (out iter)) {
                string pg = (string) primaryGroupComboBox.Model.GetValue (iter, 0);
                string gid = getGidNumber(pg);
                if (gid != null)
                    aset.Add (new LdapAttribute ("gidNumber", gid));
            }

            aset.Add (new LdapAttribute ("givenName", firstNameEntry.Text));
            aset.Add (new LdapAttribute ("sn", lastNameEntry.Text));
            aset.Add (new LdapAttribute ("uid", usernameEntry.Text));
            aset.Add (new LdapAttribute ("uidNumber", uidSpinButton.Value.ToString()));

            if (!dontRequirePasswords)
                aset.Add (new LdapAttribute ("userPassword", passwordEntry.Text));

            aset.Add (new LdapAttribute ("loginShell", shellEntry.Text));
            aset.Add (new LdapAttribute ("homeDirectory", homeDirEntry.Text));
            aset.Add (new LdapAttribute ("displayName", displayNameEntry.Text));
            aset.Add (new LdapAttribute ("cn", displayNameEntry.Text));
            aset.Add (new LdapAttribute ("gecos", displayNameEntry.Text));

            if (initialsEntry.Text != "")
                aset.Add (new LdapAttribute ("initials", initialsEntry.Text));

            if (enableSambaButton.Active) {

                aset.Add (new LdapAttribute ("objectClass", new string[] {"top", "posixaccount", "shadowaccount","inetorgperson", "person", "sambaSAMAccount"}));

                int user_rid = Convert.ToInt32 (uidSpinButton.Value) * 2 + 1000;
                LdapAttribute[] tmp = Util.CreateSambaAttributes (user_rid, smbSID, smbLM, smbNT);
                foreach (LdapAttribute a in tmp)
                    aset.Add (a);

            } else {

                if (dontRequirePasswords)
                    aset.Add (new LdapAttribute ("objectClass", new string[] {"top", "posixaccount", "inetorgperson", "person"}));
                else
                    aset.Add (new LdapAttribute ("objectClass", new string[] {"top", "posixaccount", "shadowaccount","inetorgperson", "person"}));
            }

            LdapEntry newEntry = new LdapEntry (dn, aset);
            return newEntry;
        }
		/// <summary> Creates a new attribute set containing only the attributes that have
		/// the specified subtypes.
		/// 
		/// For example, suppose an attribute set contains the following
		/// attributes:
		/// 
		/// <ul>
		/// <li>    cn</li>
		/// <li>    cn;lang-ja</li>
		/// <li>    sn;phonetic;lang-ja</li>
		/// <li>    sn;lang-us</li>
		/// </ul>
		/// 
		/// Calling the <code>getSubset</code> method and passing lang-ja as the
		/// argument, the method returns an attribute set containing the following
		/// attributes:
		/// 
		/// <ul>
		/// <li>cn;lang-ja</li>
		/// <li>sn;phonetic;lang-ja</li>
		/// </ul>
		/// 
		/// </summary>
		/// <param name="subtype">   Semi-colon delimited list of subtypes to include. For
		/// example:
		/// <ul>
		/// <li> "lang-ja" specifies only Japanese language subtypes</li>
		/// <li> "binary" specifies only binary subtypes</li>
		/// <li> "binary;lang-ja" specifies only Japanese language subtypes
		/// which also are binary</li>
		/// </ul>
		/// 
		/// Note: Novell eDirectory does not currently support language subtypes.
		/// It does support the "binary" subtype.
		/// 
		/// </param>
		/// <returns> An attribute set containing the attributes that match the
		/// specified subtype.
		/// </returns>
		public virtual LdapAttributeSet getSubset(System.String subtype)
		{
			
			// Create a new tempAttributeSet
			LdapAttributeSet tempAttributeSet = new LdapAttributeSet();
			System.Collections.IEnumerator i = this.GetEnumerator();
			
			// Cycle throught this.attributeSet
			while (i.MoveNext())
			{
				LdapAttribute attr = (LdapAttribute) i.Current;
				
				// Does this attribute have the subtype we are looking for. If
				// yes then add it to our AttributeSet, else next attribute
				if (attr.hasSubtype(subtype))
					tempAttributeSet.Add(attr.Clone());
			}
			return tempAttributeSet;
		}
		private void CommitEntry()
		{
			PropertyCollection properties = GetProperties(false);
			if(!Nflag)
			{
				System.Collections.ArrayList modList = new System.Collections.ArrayList();
				foreach (string attribute in properties.PropertyNames)
				{
					LdapAttribute attr=null;
					if (properties [attribute].Mbit)
					{
						switch (properties [attribute].Count) {
							case 0:
								attr = new LdapAttribute (attribute, new string [0]);
								modList.Add (new LdapModification (LdapModification.DELETE, attr));
								break;
							case 1:
								string val = (string) properties [attribute].Value;
								attr = new LdapAttribute (attribute, val);
								modList.Add (new LdapModification (LdapModification.REPLACE, attr));
								break;
							default:
								object [] vals = (object [])properties [attribute].Value;
								string [] aStrVals = new string [properties [attribute].Count];
								Array.Copy (vals, 0, aStrVals, 0, properties [attribute].Count);
								attr = new LdapAttribute (attribute, aStrVals);
								modList.Add (new LdapModification (LdapModification.REPLACE, attr));
								break;
						}
						properties [attribute].Mbit=false;
					}
				}
				if (modList.Count > 0) {
					LdapModification[] mods = new LdapModification[modList.Count]; 	
					Type mtype = typeof (LdapModification);
					mods = (LdapModification[])modList.ToArray(mtype);
					ModEntry(mods);
				}
			}
			else
			{
				LdapAttributeSet attributeSet = new LdapAttributeSet();
				foreach (string attribute in properties.PropertyNames)
				{
					if (properties [attribute].Count == 1)
					{
						string val = (string) properties [attribute].Value;
						attributeSet.Add(new LdapAttribute(attribute, val));                
					}
					else
					{
						object[] vals = (object []) properties [attribute].Value;
						string[] aStrVals = new string [properties [attribute].Count];
						Array.Copy (vals,0,aStrVals,0,properties [attribute].Count);
						attributeSet.Add( new LdapAttribute( attribute , aStrVals));
					}
				}
				LdapEntry newEntry = new LdapEntry( Fdn, attributeSet );
				conn.Add( newEntry );
				Nflag = false;
			}
		}
示例#7
0
        /// <summary>
        /// Iterates the ZFD Application attributes
        /// </summary>
        /// <param name="attrSet">
        /// A <see cref="LdapAttributeSet"/>
        /// </param>
        /// <param name="dn">
        /// A <see cref="System.String"/>
        /// </param>
        /// <returns>
        /// A <see cref="LDAPGroup"/>
        /// </returns>
        public static LDAPZFDApp iterZFDAppAttrs(LdapAttributeSet attrSet, string dn)
        {
            LDAPZFDApp app;
            System.Collections.IEnumerator ienum =  attrSet.GetEnumerator();

            if (attrSet.Count == 0)
                return null;

            app = new LDAPZFDApp(dn);

            while(ienum.MoveNext())
            {
                LdapAttribute attribute=(LdapAttribute)ienum.Current;
                if (AttrEquals(attribute, ATTRNAME.APPASSOCIATIONS))
                    app.setAssociations(AttributeUtil.getListofAttr(attrSet, ATTRNAME.APPASSOCIATIONS));

            }
            return app;
        }
示例#8
0
        /// <summary>
        /// Parses a group objects attributes building the LDAPGroup object
        /// Requires the group objects attribute set and the DN.
        /// </summary>
        /// <param name="attrSet">
        /// A <see cref="LdapAttributeSet"/>
        /// </param>
        /// <param name="dn">
        /// A <see cref="System.String"/>
        /// </param>
        /// <returns>
        /// A <see cref="LDAPUser"/>
        /// </returns>
        public static LDAPGroup iterGroupAttrs(LdapAttributeSet attrSet, string dn)
        {
            LDAPGroup grp;
            System.Collections.IEnumerator ienum =  attrSet.GetEnumerator();

            if (attrSet.Count == 0)
                return null;

            grp = new LDAPGroup(dn);

            while(ienum.MoveNext())
            {
                LdapAttribute attribute=(LdapAttribute)ienum.Current;
                if (AttrEquals(attribute, (ATTRNAME.SN)))
                    grp.setSN(AttributeUtil.getAttr(attrSet, ATTRNAME.SN));

                if (AttrEquals(attribute, (ATTRNAME.CN)))
                    grp.setCN(AttributeUtil.getAttr(attrSet, ATTRNAME.CN));

                if (AttrEquals(attribute, ATTRNAME.MEMBERS))
                    grp.setGroupMembers( AttributeUtil.getListofAttr(attrSet, ATTRNAME.MEMBERS));
            }
            return grp;
        }
		private void CommitEntry()
		{
			if(!Nflag)
			{
				System.Collections.ArrayList modList = new System.Collections.ArrayList();
				System.Collections.IDictionaryEnumerator id = Properties.GetEnumerator();
				while(id.MoveNext())
				{
					string attribute=(string)id.Key;
					LdapAttribute attr=null;
					if(Properties[attribute].Mbit)
					{
						if(Properties[attribute].Count==1)
						{
							String val = (String)Properties[attribute].Value;
							attr = new LdapAttribute( attribute , val);
						}
						else
						{
							Object[] vals=(Object [])Properties[attribute].Value;
							String[] aStrVals= new String[Properties[attribute].Count];
							Array.Copy(vals,0,aStrVals,0,Properties[attribute].Count);
							attr = new LdapAttribute( attribute , aStrVals);
						}
						modList.Add( new LdapModification(LdapModification.REPLACE, attr));
						Properties[attribute].Mbit=false;
					}
				}
				if (modList.Count > 0) {
					LdapModification[] mods = new LdapModification[modList.Count]; 	
					Type mtype=Type.GetType("System.DirectoryServices.LdapModification");
					mods = (LdapModification[])modList.ToArray(typeof(LdapModification));
					ModEntry(mods);
				}
			}
			else
			{
				LdapAttributeSet attributeSet = new LdapAttributeSet();
				System.Collections.IDictionaryEnumerator id = Properties.GetEnumerator();
				while(id.MoveNext())
				{
					string attribute=(string)id.Key;
					if(Properties[attribute].Count==1)
					{
						String val = (String)Properties[attribute].Value;
						attributeSet.Add(new LdapAttribute(attribute, val));                
					}
					else
					{
						Object[] vals=(Object [])Properties[attribute].Value;
						String[] aStrVals= new String[Properties[attribute].Count];
						Array.Copy(vals,0,aStrVals,0,Properties[attribute].Count);
						attributeSet.Add( new LdapAttribute( attribute , aStrVals));
					}
				}
				LdapEntry newEntry = new LdapEntry( Fdn, attributeSet );
				conn.Add( newEntry );
				Nflag = false;
			}
		}
示例#10
0
        LdapEntry CreateEntry(string dn)
        {
            LdapAttributeSet aset = new LdapAttributeSet();
            aset.Add (new LdapAttribute ("cn", groupNameEntry.Text));
            aset.Add (new LdapAttribute ("description", descriptionEntry.Text));
            aset.Add (new LdapAttribute ("gidNumber", groupIDSpinButton.Value.ToString()));

            if (currentMembers.Count >= 1)
                aset.Add (new LdapAttribute ("memberuid", currentMembers.ToArray()));

            if (enableSambaButton.Active || isSamba) {

                aset.Add (new LdapAttribute ("objectClass", new string[] {"top", "posixGroup", "sambaGroupMapping"}));
                aset.Add (new LdapAttribute ("sambaGroupType", "2"));

                int grid = Convert.ToInt32 (groupIDSpinButton.Value) * 2 + 1001;
                smbSID = conn.Data.GetLocalSID ();
                aset.Add (new LdapAttribute ("sambaSID", String.Format ("{0}-{1}", conn.Data.GetLocalSID (), grid)));

            } else {
                aset.Add (new LdapAttribute ("objectClass", new string[] {"top", "posixGroup"}));
            }

            LdapEntry newEntry = new LdapEntry (dn, aset);
            return newEntry;
        }
示例#11
0
        LdapEntry CreateEntry(string dn)
        {
            LdapAttributeSet aset = new LdapAttributeSet();
            aset.Add (new LdapAttribute ("objectClass", new string[] {"top", "ipHost", "device"}));
            aset.Add (new LdapAttribute ("cn", hostNameEntry.Text));
            aset.Add (new LdapAttribute ("ipHostNumber", ipEntry.Text));
            aset.Add (new LdapAttribute ("description", descriptionEntry.Text));

            LdapEntry newEntry = new LdapEntry (dn, aset);
            return newEntry;
        }
示例#12
0
    // add dynamic group entry
    public static bool addDynamicGroupEntry( LdapConnection lc,
        String loginDN, String entryDN, String queryURL)
    {
        bool status = true;
        LdapAttributeSet  attributeSet = new LdapAttributeSet();

        //The objectclass "dynamicGroup is used to create dynamic group entries
        attributeSet.Add( new LdapAttribute( "objectclass", "dynamicGroup" ));

        /* The memberQueryURL attribute describes the membership of the list
         * using an LdapURL, which is defined in RFC2255
         */
        attributeSet.Add( new LdapAttribute( "memberQueryURL", queryURL ) );

        /* Set the identity to use for the implied search.  loginDN is used
         * as the dgIdentity in this sample.
         */
        attributeSet.Add( new LdapAttribute( "dgIdentity", loginDN ) );

        LdapEntry newEntry = new LdapEntry( entryDN, attributeSet );

        try
        {
            lc.Add( newEntry );
            Console.WriteLine("\tEntry: " + entryDN + " added successfully." );
        }
        catch( LdapException e )
        {
            Console.WriteLine( "\t\tFailed to add dynamic group entry " +
                       entryDN);
            Console.WriteLine( "Error: " + e.ToString() );
            status = false;
        }
        return status;
    }
示例#13
0
        LdapEntry CreateEntry(string dn)
        {
            LdapAttributeSet aset = new LdapAttributeSet();
            aset.Add (new LdapAttribute ("objectClass", new string[] {"top", "group"}));
            aset.Add (new LdapAttribute ("cn", groupNameEntry.Text));
            aset.Add (new LdapAttribute ("description", descriptionEntry.Text));
            aset.Add (new LdapAttribute ("sAMAccountName", groupNameEntry.Text));
            aset.Add (new LdapAttribute ("groupType", "-2147483646"));

            if (currentMembers.Count >= 1)
                aset.Add (new LdapAttribute ("member", currentMembers.ToArray()));

            LdapEntry newEntry = new LdapEntry (dn, aset);
            return newEntry;
        }
示例#14
0
文件: ServerData.cs 项目: MrJoe/lat
        /// <summary>Adds an entry to the directory
        /// 
        /// </summary>
        /// <param name="dn">The distinguished name of the new entry.</param>
        /// <param name="attributes">An arraylist of string attributes for the 
        /// new ldap entry.</param>
        public void Add(string dn, List<LdapAttribute> attributes)
        {
            Log.Debug ("START Connection.Add ()");
            Log.Debug ("dn: {0}", dn);

            LdapAttributeSet attributeSet = new LdapAttributeSet();

            foreach (LdapAttribute attr in attributes) {

                foreach (string v in attr.StringValueArray)
                    Log.Debug ("{0}:{1}", attr.Name, v);

                attributeSet.Add (attr);
            }

            LdapEntry newEntry = new LdapEntry( dn, attributeSet );
            Add (newEntry);

            Log.Debug ("END Connection.Add ()");
        }
示例#15
0
        public void OnOkClicked(object o, EventArgs args)
        {
            string dn = String.Format ("{0},{1}", rdnEntry.Text, browseButton.Label);
            LdapAttributeSet lset = new LdapAttributeSet ();

            foreach (object[] row in attrListStore) {

                string n = (string) row[0];
                string v = (string) row[1];

                if (n == null || v == null || v == "")
                    continue;

                if (n.ToLower() == "objectclass") {
                    if (objAttr == null)
                        objAttr = new LdapAttribute (n, v);
                    else
                        objAttr.addValue (v);

                } else {

                    LdapAttribute attr = new LdapAttribute (n, v);
                    lset.Add (attr);
                }
            }

            lset.Add (objAttr);

            LdapEntry entry = new LdapEntry (dn, lset);
            if (!Util.AddEntry (conn, entry))
                errorOccured = true;
            else
                errorOccured = false;
        }
示例#16
0
        LdapEntry CreateEntry(string dn)
        {
            LdapAttributeSet aset = new LdapAttributeSet();
            aset.Add (new LdapAttribute ("objectClass", new string[] {"computer"}));
            aset.Add (new LdapAttribute ("cn", computerNameLabel.Text));
            aset.Add (new LdapAttribute ("description", descriptionEntry.Text));
            aset.Add (new LdapAttribute ("dNSHostName", dnsNameEntry.Text));
            aset.Add (new LdapAttribute ("operatingSystem", osNameEntry.Text));
            aset.Add (new LdapAttribute ("operatingSystemVersion", osVersionEntry.Text));
            aset.Add (new LdapAttribute ("operatingSystemServicePack", osServicePackEntry.Text));
            aset.Add (new LdapAttribute ("location", locationEntry.Text));
            aset.Add (new LdapAttribute ("managedBy", manNameEntry.Text));

            LdapEntry newEntry = new LdapEntry (dn, aset);
            return newEntry;
        }
示例#17
0
文件: LdapServer.cs 项目: MrJoe/lat
        /// <summary>Copy a directory entry
        /// </summary>
        /// <param name="oldDN">Distinguished name of the entry to copy</param>
        /// <param name="newRDN">New name for entry</param>
        /// <param name="parentDN">Parent name</param>
        public void Copy(string oldDN, string newRDN, string parentDN)
        {
            string newDN = string.Format ("{0},{1}", newRDN, parentDN);

            LdapEntry[] entry = Search (oldDN, LdapConnection.SCOPE_BASE, "objectclass=*", null);
            if (!(entry.Length > 0))
                return;

            LdapEntry oldEntry = entry[0];
            LdapAttributeSet attributeSet = new LdapAttributeSet();

            foreach (LdapAttribute attr in oldEntry.getAttributeSet()) {
                LdapAttribute newAttr = new LdapAttribute (attr);
                attributeSet.Add (newAttr);
            }

            LdapEntry le = new LdapEntry (newDN, attributeSet);
            conn.Add (le);
        }
示例#18
0
        /// <summary>
        /// Returns null of no attributes match the attr parameter value
        /// Returns a list of strings that contain the attribute values that were specified in the attr param
        /// </summary>
        /// <param name="attrSet">
        /// A <see cref="LdapAttributeSet"/>
        /// </param>
        /// <param name="attr">
        /// A <see cref="System.String"/>
        /// </param>
        /// <returns>
        /// A <see cref="List<System.String>"/>
        /// </returns>
        public static List<string> getListofAttr(LdapAttributeSet attrSet, ATTRNAME attr)
        {
            string sAttr = attr.ToString();
            if (attrSet.getAttribute(sAttr) == null)
                return null;

            List<string> values = null;
            System.Collections.IEnumerator ienum =  attrSet.GetEnumerator();

            while(ienum.MoveNext())
            {
                LdapAttribute attribute=(LdapAttribute)ienum.Current;
                if (AttrEquals(attribute, attr)) {
                    values = new List<string>(attrSet.getAttribute(sAttr).StringValueArray.Length);
                    values.AddRange(attrSet.getAttribute(sAttr).StringValueArray); // take the values from the array

                    if (Logger.LogLevel == Level.DEBUG) {
                        foreach (string x in values) //debug purposes
                        Logger.Debug("Values in {0} list {1}", attr, x);
                    }
                }
            }
            return values;
        }
示例#19
0
        LdapEntry CreateEntry(string dn)
        {
            LdapAttributeSet aset = new LdapAttributeSet();
            aset.Add (new LdapAttribute ("objectClass", new string[] {"top", "person", "organizationalPerson", "contact" }));
            aset.Add (new LdapAttribute ("givenName", gnFirstNameEntry.Text));
            aset.Add (new LdapAttribute ("initials", gnInitialsEntry.Text));
            aset.Add (new LdapAttribute ("sn", gnLastNameEntry.Text));
            aset.Add (new LdapAttribute ("displayName", gnDisplayName.Text));
            aset.Add (new LdapAttribute ("cn", gnDisplayName.Text));

            LdapEntry newEntry = new LdapEntry (dn, aset);
            return newEntry;
        }
示例#20
0
        /// <summary>
        /// Parses a LdapAttributeSet and the specified user DN
        /// Returns a user object.
        /// </summary>
        /// <param name="attrSet">
        /// A <see cref="LdapAttributeSet"/>
        /// </param>
        /// <param name="dn">
        /// A <see cref="System.String"/>
        /// </param>
        /// <returns>
        /// A <see cref="LDAPUser"/>
        /// </returns>
        public static LDAPUser iterUsrAttrs(LdapAttributeSet attrSet, string dn)
        {
            LDAPUser user;
            System.Collections.IEnumerator ienum =  attrSet.GetEnumerator();

            if (attrSet.Count == 0) {
                Logger.Debug("No attributes in the AttributeSet for {0}", dn);
                return null;
            }

            user = new LDAPUser(dn);

            while(ienum.MoveNext())
            {

                LdapAttribute attribute=(LdapAttribute)ienum.Current;
                Logger.Debug("Parsing {0}", attribute);

                if (AttrEquals(attribute, ATTRNAME.NDSHOMEDIRECTORY))
                    user.parseNdsHomeDirPath(AttributeUtil.getAttr(attrSet, ATTRNAME.NDSHOMEDIRECTORY));

                if (AttrEquals(attribute, ATTRNAME.SN))
                    user.setSN(AttributeUtil.getAttr(attrSet, ATTRNAME.SN));

                if (AttrEquals(attribute, ATTRNAME.GIVENNAME))
                    user.setGivenName(AttributeUtil.getAttr(attrSet, ATTRNAME.GIVENNAME));

                if (AttrEquals(attribute, ATTRNAME.TITLE))
                    user.Title = AttributeUtil.getAttr(attrSet, ATTRNAME.TITLE);

                if (AttrEquals(attribute, ATTRNAME.HOMEPHONE))
                    user.HOMEPHONE = AttributeUtil.getAttr(attrSet, ATTRNAME.HOMEPHONE);

                if (AttrEquals(attribute, ATTRNAME.DISPLAYNAME))
                    user.DISPLAYNAME = AttributeUtil.getAttr(attrSet, ATTRNAME.DISPLAYNAME);

                if (AttrEquals(attribute, ATTRNAME.NGWFID))
                    user.GW_FID = AttributeUtil.getAttr(attrSet, ATTRNAME.NGWFID);
            }
            return user;
        }
示例#21
0
        LdapEntry CreateEntry(string dn)
        {
            LdapAttributeSet aset = new LdapAttributeSet();

            // General
            aset.Add (new LdapAttribute ("cn", fullnameLabel.Text));
            aset.Add (new LdapAttribute ("displayName", fullnameLabel.Text));
            aset.Add (new LdapAttribute ("gecos", fullnameLabel.Text));
            aset.Add (new LdapAttribute ("givenName", firstNameEntry.Text));
            aset.Add (new LdapAttribute ("initials", initialsEntry.Text));
            aset.Add (new LdapAttribute ("sn", lastNameEntry.Text));
            aset.Add (new LdapAttribute ("description", descriptionEntry.Text));
            aset.Add (new LdapAttribute ("physicalDeliveryOfficeName", officeEntry.Text));
            aset.Add (new LdapAttribute ("mail", mailEntry.Text));
            aset.Add (new LdapAttribute ("telephoneNumber", phoneEntry.Text));

            // Account
            aset.Add (new LdapAttribute ("uid", usernameEntry.Text));
            aset.Add (new LdapAttribute ("uidNumber", uidSpinButton.Value.ToString()));
            aset.Add (new LdapAttribute ("homeDirectory", homeDirEntry.Text));
            aset.Add (new LdapAttribute ("loginShell", shellEntry.Text));

            if (passChanged)
                aset.Add (new LdapAttribute ("userPassword", pass));
            else {
                aset.Add (new LdapAttribute ("userPassword", conn.Data.GetAttributeValueFromEntry (currentEntry, "userPassword")));
            }

            if (smbEnableSambaButton.Active || isSamba) {

                aset.Add (new LdapAttribute ("objectClass", new string[] {"top", "posixaccount", "shadowaccount","inetorgperson", "person", "sambaSAMAccount"}));

                int user_rid = Convert.ToInt32 (uidSpinButton.Value) * 2 + 1000;
                LdapAttribute[] tmp = Util.CreateSambaAttributes (user_rid, conn.Data.GetLocalSID (), smbLM, smbNT);
                foreach (LdapAttribute a in tmp)
                    aset.Add (a);

                aset.Add (new LdapAttribute ("sambaProfilePath", smbProfilePathEntry.Text));
                aset.Add (new LdapAttribute ("sambaHomePath", smbHomePathEntry.Text));
                aset.Add (new LdapAttribute ("sambaHomeDrive", smbHomeDriveEntry.Text));
                aset.Add (new LdapAttribute ("sambaLogonScript", smbLoginScriptEntry.Text));

                double d = 0;
                if (smbExpireEntry.Text != "") {
                    d = Util.GetDateTime (smbExpireEntry.Text);
                    aset.Add (new LdapAttribute ("sambaKickoffTime", d.ToString()));
                }

                if (smbCanChangePwdEntry.Text != "") {
                    d = Util.GetDateTime (smbCanChangePwdEntry.Text);
                    aset.Add (new LdapAttribute ("sambaPwdCanChange", d.ToString()));
                }

                if (smbMustChangePwdEntry.Text != "") {
                    d = Util.GetDateTime (smbMustChangePwdEntry.Text);
                    aset.Add (new LdapAttribute ("sambaPwdMustChange", d.ToString()));
                }

            } else {

                aset.Add (new LdapAttribute ("objectClass", new string[] {"top", "posixaccount", "shadowaccount","inetorgperson", "person"}));
            }

            // Groups
            string gid = getGidNumber(primaryGroupLabel.Text);
            if (gid != null) {
                aset.Add (new LdapAttribute ("gidNumber", gid));
            } else {
                LdapAttribute la = currentEntry.getAttribute ("gidNumber");
                aset.Add (new LdapAttribute ("gidNumber", la.StringValue));
            }

            // Address
            aset.Add (new LdapAttribute ("street", adStreetTextView.Buffer.Text));
            aset.Add (new LdapAttribute ("l", adCityEntry.Text));
            aset.Add (new LdapAttribute ("st", adStateEntry.Text));
            aset.Add (new LdapAttribute ("postalCode", adZipEntry.Text));
            aset.Add (new LdapAttribute ("postOfficeBox", adPOBoxEntry.Text));

            // Telephones
            aset.Add (new LdapAttribute ("facsimileTelephoneNumber", tnFaxEntry.Text));
            aset.Add (new LdapAttribute ("pager", tnPagerEntry.Text));
            aset.Add (new LdapAttribute ("mobile", tnMobileEntry.Text));
            aset.Add (new LdapAttribute ("homePhone", tnHomeEntry.Text));
            aset.Add (new LdapAttribute ("ipPhone", tnIPPhoneEntry.Text));

            // Organization
            aset.Add (new LdapAttribute ("title", ozTitleEntry.Text));
            aset.Add (new LdapAttribute ("departmentNumber", ozDeptEntry.Text));
            aset.Add (new LdapAttribute ("o", ozCompanyEntry.Text));

            LdapEntry newEntry = new LdapEntry (dn, aset);
            return newEntry;
        }
示例#22
0
        void createDomain(string dn, string domain, string sid)
        {
            LdapAttributeSet lset = new LdapAttributeSet ();
            lset.Add (new LdapAttribute ("objectclass", new string[] {"sambaDomain"}));
            lset.Add (new LdapAttribute ("sambaDomainName", domain));
            lset.Add (new LdapAttribute ("sambaSID", sid));

            LdapEntry entry = new LdapEntry (dn, lset);
            Connection conn = GetCurrentConnection ();
            Util.AddEntry (conn, entry);
        }
示例#23
0
        void createGroup(string dn, string gid, string desc, 
					  string sid, string grid, string gtype, 
					  string memberuid)
        {
            LdapAttributeSet lset = new LdapAttributeSet ();
            lset.Add (new LdapAttribute ("objectclass", new string[] {"posixGroup", "sambaGroupMapping"}));
            lset.Add (new LdapAttribute ("gidNumber", gid));
            lset.Add (new LdapAttribute ("cn", getCN(dn)));
            lset.Add (new LdapAttribute ("description", desc));
            lset.Add (new LdapAttribute ("sambaSID", sid + "-" + grid));
            lset.Add (new LdapAttribute ("sambaGroupType", gtype));
            lset.Add (new LdapAttribute ("displayName", getCN(dn)));

            if (memberuid != "")
                lset.Add (new LdapAttribute ("memberUid", memberuid));

            LdapEntry entry = new LdapEntry (dn, lset);
            Connection conn = GetCurrentConnection ();
            Util.AddEntry (conn, entry);
        }
示例#24
0
		/// <summary> Constructs a new entry with the specified distinguished name and set
		/// of attributes.
		/// 
		/// </summary>
		/// <param name="dn">      The distinguished name of the new entry. The
		/// value is not validated. An invalid distinguished
		/// name will cause operations using this entry to fail.
		/// 
		/// </param>
		/// <param name="attrs">   The initial set of attributes assigned to the
		/// entry.
		/// </param>
		public LdapEntry(System.String dn, LdapAttributeSet attrs)
		{
			if ((System.Object) dn == null)
			{
				dn = "";
			}
			if (attrs == null)
			{
				attrs = new LdapAttributeSet();
			}
			this.dn = dn;
			this.attrs = attrs;
			return ;
		}
示例#25
0
        void createOU(string dn)
        {
            LdapAttributeSet lset = new LdapAttributeSet ();
            lset.Add (new LdapAttribute ("objectclass", new string[] {"organizationalUnit"}));
            lset.Add (new LdapAttribute ("ou", getCN(dn)));

            LdapEntry entry = new LdapEntry (dn, lset);

            Connection conn = GetCurrentConnection ();
            Util.AddEntry (conn, entry);
        }
示例#26
0
        LdapEntry CreateEntry(string dn)
        {
            LdapAttributeSet aset = new LdapAttributeSet();
            aset.Add (new LdapAttribute ("objectClass", new string[] {"top", "person", "organizationalPerson", "contact" }));
            aset.Add (new LdapAttribute ("givenName", gnFirstNameEntry.Text));
            aset.Add (new LdapAttribute ("initials", gnInitialsEntry.Text));
            aset.Add (new LdapAttribute ("sn", gnLastNameEntry.Text));
            aset.Add (new LdapAttribute ("displayName", gnDisplayName.Text));
            aset.Add (new LdapAttribute ("cn", gnDisplayName.Text));
            aset.Add (new LdapAttribute ("wWWHomePage", gnWebPageEntry.Text));
            aset.Add (new LdapAttribute ("physicalDeliveryOfficeName", gnOfficeEntry.Text));
            aset.Add (new LdapAttribute ("mail", gnEmailEntry.Text));
            aset.Add (new LdapAttribute ("description", gnDescriptionEntry.Text));
            aset.Add (new LdapAttribute ("street", adStreetTextView.Buffer.Text));
            aset.Add (new LdapAttribute ("l", adCityEntry.Text));
            aset.Add (new LdapAttribute ("st", adStateEntry.Text));
            aset.Add (new LdapAttribute ("postalCode", adZipEntry.Text));
            aset.Add (new LdapAttribute ("postOfficeBox", adPOBoxEntry.Text));
            aset.Add (new LdapAttribute ("co", adCountryEntry.Text));
            aset.Add (new LdapAttribute ("telephoneNumber", gnTelephoneNumberEntry.Text));
            aset.Add (new LdapAttribute ("facsimileTelephoneNumber", tnFaxEntry.Text));
            aset.Add (new LdapAttribute ("pager", tnPagerEntry.Text));
            aset.Add (new LdapAttribute ("mobile", tnMobileEntry.Text));
            aset.Add (new LdapAttribute ("homePhone", tnHomeEntry.Text));
            aset.Add (new LdapAttribute ("ipPhone", tnIPPhoneEntry.Text));
            aset.Add (new LdapAttribute ("title", ozTitleEntry.Text));
            aset.Add (new LdapAttribute ("department", ozDeptEntry.Text));
            aset.Add (new LdapAttribute ("company", ozCompanyEntry.Text));
            aset.Add (new LdapAttribute ("streetAddress", adStreetTextView.Buffer.Text));
            aset.Add (new LdapAttribute ("info", tnNotesTextView.Buffer.Text));

            LdapEntry newEntry = new LdapEntry (dn, aset);
            return newEntry;
        }
示例#27
0
        LdapEntry CreateEntry(string dn)
        {
            LdapAttributeSet aset = new LdapAttributeSet();
            string fullName = String.Format ("{0} {1}", firstNameEntry.Text, lastNameEntry.Text);
            aset.Add (new LdapAttribute ("cn", fullName));
            aset.Add (new LdapAttribute ("gecos", fullName));
            aset.Add (new LdapAttribute ("objectClass", new string[] {"top", "person", "organizationalPerson","user"}));
            aset.Add (new LdapAttribute ("givenName", firstNameEntry.Text));
            aset.Add (new LdapAttribute ("sn", lastNameEntry.Text));
            aset.Add (new LdapAttribute ("userPrincipalName", upnEntry.Text));
            aset.Add (new LdapAttribute ("sAMAccountName", usernameEntry.Text));
            aset.Add (new LdapAttribute ("userAccountControl", userAC.ToString()));
            aset.Add (new LdapAttribute ("displayName", displayNameEntry.Text));
            aset.Add (new LdapAttribute ("initials", initialsEntry.Text));

            LdapEntry newEntry = new LdapEntry (dn, aset);
            return newEntry;
        }