/// <summary> Constructs an LdapSearchResult object from an LdapEntry. /// /// </summary> /// <param name="entry">the LdapEntry represented by this search result. /// /// </param> /// <param name="cont">controls associated with the search result /// </param> public LdapSearchResult(LdapEntry entry, LdapControl[] cont) : base() { if (entry == null) { throw new System.ArgumentException("Argument \"entry\" cannot be null"); } this.entry = entry; return ; }
/// <summary> Creates an LdapMessage when sending a protocol operation and sends /// some optional controls with the message. /// /// </summary> /// <param name="op">The operation type of message. /// /// </param> /// <param name="controls">The controls to use with the operation. /// /// </param> /// <seealso cref="Type"> /// </seealso> /*package*/ internal LdapMessage(int type, RfcRequest op, LdapControl[] controls) { // Get a unique number for this request message messageType = type; RfcControls asn1Ctrls = null; if (controls != null) { // Move LdapControls into an RFC 2251 Controls object. asn1Ctrls = new RfcControls(); for (int i = 0; i < controls.Length; i++) { // asn1Ctrls.add(null); asn1Ctrls.add(controls[i].Asn1Object); } } // create RFC 2251 LdapMessage message = new RfcLdapMessage(op, asn1Ctrls); return ; }
/// <summary> Constructs an Ldap Modify request. /// /// </summary> /// <param name="dn"> The distinguished name of the entry to modify. /// /// </param> /// <param name="mods"> The changes to be made to the entry. /// /// </param> /// <param name="cont"> Any controls that apply to the modify request, /// or null if none. /// </param> public LdapModifyRequest(System.String dn, LdapModification[] mods, LdapControl[] cont) : base(LdapMessage.MODIFY_REQUEST, new RfcModifyRequest(new RfcLdapDN(dn), encodeModifications(mods)), cont) { return ; }
/// <summary> Constructs an LdapExtendedRequest. /// /// </summary> /// <param name="op"> The object which contains (1) an identifier of an extended /// operation which should be recognized by the particular Ldap /// server this client is connected to, and (2) an operation- /// specific sequence of octet strings or BER-encoded values. /// /// </param> /// <param name="cont">Any controls that apply to the extended request /// or null if none. /// </param> public LdapExtendedRequest(LdapExtendedOperation op, LdapControl[] cont) : base(LdapMessage.EXTENDED_REQUEST, new RfcExtendedRequest(new RfcLdapOID(op.getID()), (op.getValue() != null)?new Asn1OctetString(op.getValue()):null), cont) { return ; }
public LdapCompareRequest(System.String dn, System.String name, sbyte[] value_Renamed, LdapControl[] cont) : base(LdapMessage.COMPARE_REQUEST, new RfcCompareRequest(new RfcLdapDN(dn), new RfcAttributeValueAssertion(new RfcAttributeDescription(name), new RfcAssertionValue(value_Renamed))), cont) { return ; }
public LdapBindRequest(int version, System.String dn, sbyte[] passwd, LdapControl[] cont):base(LdapMessage.BIND_REQUEST, new RfcBindRequest(new Asn1Integer(version), new RfcLdapDN(dn), new RfcAuthenticationChoice(new Asn1Tagged(new Asn1Identifier(Asn1Identifier.CONTEXT, false, 0), new Asn1OctetString(passwd), false))), cont) { return ; }
public static void Main( String[] args ) { if (args.Length != 6) { Console.Error.WriteLine("Usage: mono SimplePassword <host Name> " + "<port number> <login dn> <password> <user dn>" + " <new user password>"); Console.Error.WriteLine("\n Example: mono SimplePassword Acme.com 389" + " \"cn=Admin,o=Acme\" secret\n" + " \"cn=JSmith,ou=sales,o=Acme\" userPWD"); Environment.Exit(1); } int ldapVersion = LdapConnection.Ldap_V3; String ldapHost = args[0]; int ldapPort = int.Parse(args[1]); String loginDN = args[2]; String password = args[3]; String userDN = args[4]; String userPWD = args[5]; /* Simple Password control. There is no value associated with this control, * just an OID and criticality. Setting the criticality to TRUE means the * server will return an error if it does not recognize or is unable to * perform the control. */ LdapControl cont = new LdapControl(simplePassOID, true, null); LdapConstraints lcons = new LdapConstraints(); lcons.setControls(cont); LdapConnection lc = new LdapConnection(); try { // connect to the server lc.Connect( ldapHost, ldapPort ); // bind to the server lc.Bind( ldapVersion, loginDN, password ); // Modify the 'userpassword' attribute, with the Simple // Password control. LdapModification[] modifications = new LdapModification[1]; LdapAttribute sPassword = new LdapAttribute( "userPassword",userPWD); modifications[0] = new LdapModification( LdapModification.REPLACE, sPassword); lc.Modify( userDN, modifications,lcons); Console.WriteLine("Your Simple password has been modified."); lc.Disconnect(); } catch( LdapException e ) { Console.Error.WriteLine("SimplePassword example failed"); Console.Error.WriteLine( "Error: " + e.ToString() ); Environment.Exit(1); } catch( Exception e ) { Console.WriteLine( "Error: " + e.ToString() ); } Environment.Exit(0); }
/// <summary> Creates a response LdapMessage from parameters. Typically the data /// comes from a source other than a BER encoded Ldap message, /// such as from DSML. /// /// </summary> /// <param name="type"> The message type as defined in LdapMessage. /// /// </param> /// <param name="resultCode"> The result code as defined in LdapException. /// /// </param> /// <param name="matchedDN"> The name of the lowest entry that was matched /// for some error result codes, an empty string /// or <code>null</code> if none. /// /// </param> /// <param name="serverMessage"> A diagnostic message returned by the server, /// an empty string or <code>null</code> if none. /// /// </param> /// <param name="referrals"> The referral URLs returned for a REFERRAL result /// code or <code>null</code> if none. /// /// </param> /// <param name="controls"> Any controls returned by the server or /// <code>null</code> if none. /// /// </param> /// <seealso cref="LdapMessage"> /// </seealso> /// <seealso cref="LdapException"> /// </seealso> public LdapResponse(int type, int resultCode, System.String matchedDN, System.String serverMessage, System.String[] referrals, LdapControl[] controls) : base(new RfcLdapMessage(RfcResultFactory(type, resultCode, matchedDN, serverMessage, referrals))) { return ; }
/// <summary> Constructs a request to add an entry to the directory. /// /// </summary> /// <param name="entry">The LdapEntry to add to the directory. /// /// </param> /// <param name="cont">Any controls that apply to the add request, /// or null if none. /// </param> public LdapAddRequest(LdapEntry entry, LdapControl[] cont):base(LdapMessage.ADD_REQUEST, new RfcAddRequest(new RfcLdapDN(entry.DN), makeRfcAttrList(entry)), cont) { return ; }
/// <summary> Constructs an Ldap Search Request with a filter in Asn1 format. /// /// </summary> /// <param name="base"> The base distinguished name to search from. /// /// </param> /// <param name="scope"> The scope of the entries to search. The following /// are the valid options: /// <ul> /// <li>SCOPE_BASE - searches only the base DN</li> /// /// <li>SCOPE_ONE - searches only entries under the base DN</li> /// /// <li>SCOPE_SUB - searches the base DN and all entries /// within its subtree</li> /// </ul> /// </param> /// <param name="filter"> The search filter specifying the search criteria. /// /// </param> /// <param name="attrs"> The names of attributes to retrieve. /// operation exceeds the time limit. /// /// </param> /// <param name="dereference">Specifies when aliases should be dereferenced. /// Must be either one of the constants defined in /// LdapConstraints, which are DEREF_NEVER, /// DEREF_FINDING, DEREF_SEARCHING, or DEREF_ALWAYS. /// /// </param> /// <param name="maxResults">The maximum number of search results to return /// for a search request. /// The search operation will be terminated by the server /// with an LdapException.SIZE_LIMIT_EXCEEDED if the /// number of results exceed the maximum. /// /// </param> /// <param name="serverTimeLimit">The maximum time in seconds that the server /// should spend returning search results. This is a /// server-enforced limit. A value of 0 means /// no time limit. /// /// </param> /// <param name="typesOnly"> If true, returns the names but not the values of /// the attributes found. If false, returns the /// names and values for attributes found. /// /// </param> /// <param name="cont"> Any controls that apply to the search request. /// or null if none. /// /// </param> /// <seealso cref="Novell.Directory.Ldap.LdapConnection.Search"> /// </seealso> /// <seealso cref="Novell.Directory.Ldap.LdapSearchConstraints"> /// </seealso> public LdapSearchRequest(System.String base_Renamed, int scope, RfcFilter filter, System.String[] attrs, int dereference, int maxResults, int serverTimeLimit, bool typesOnly, LdapControl[] cont) : base(LdapMessage.SEARCH_REQUEST, new RfcSearchRequest(new RfcLdapDN(base_Renamed), new Asn1Enumerated(scope), new Asn1Enumerated(dereference), new Asn1Integer(maxResults), new Asn1Integer(serverTimeLimit), new Asn1Boolean(typesOnly), filter, new RfcAttributeDescriptionList(attrs)), cont) { return ; }
/// <summary> Constructs a request to delete an entry from the directory /// /// </summary> /// <param name="dn">the dn of the entry to delete. /// /// </param> /// <param name="cont">Any controls that apply to the abandon request /// or null if none. /// </param> public LdapDeleteRequest(System.String dn, LdapControl[] cont):base(LdapMessage.DEL_REQUEST, new RfcDelRequest(dn), cont) { return ; }
/// <summary> Sets controls to be sent to the server. /// /// </summary> /// <param name="controls"> An array of controls to be sent to the server or /// null if none. /// </param> public virtual void setControls(LdapControl[] controls) { if ((controls == null) || (controls.Length == 0)) { this.controls = null; return ; } this.controls = new LdapControl[controls.Length]; for (int i = 0; i < controls.Length; i++) { this.controls[i] = (LdapControl) controls[i].Clone(); } return ; }
/// <summary> Sets a single control to be sent to the server. /// /// </summary> /// <param name="control"> A single control to be sent to the server or /// null if none. /// </param> public virtual void setControls(LdapControl control) { if (control == null) { this.controls = null; return ; } this.controls = new LdapControl[1]; this.controls[0] = (LdapControl) control.Clone(); return ; }
/// <summary> Constructs an LdapSearchConstraints object initialized with values /// from an existing constraints object (LdapConstraints /// or LdapSearchConstraints). /// </summary> public LdapSearchConstraints(LdapConstraints cons) : base(cons.TimeLimit, cons.ReferralFollowing, cons.getReferralHandler(), cons.HopLimit) { InitBlock(); LdapControl[] lsc = cons.getControls(); if (lsc != null) { LdapControl[] generated_var = new LdapControl[lsc.Length]; lsc.CopyTo(generated_var, 0); base.setControls(generated_var); } System.Collections.Hashtable lp = cons.Properties; if (lp != null) { base.Properties = (System.Collections.Hashtable) lp.Clone(); } if (cons is LdapSearchConstraints) { LdapSearchConstraints scons = (LdapSearchConstraints) cons; this.serverTimeLimit = scons.ServerTimeLimit; this.dereference = scons.Dereference; this.maxResults = scons.MaxResults; this.batchSize = scons.BatchSize; } // Get a unique connection name for debug return ; }
/// <summary> Constructs a ModifyDN (rename) Request. /// /// </summary> /// <param name="dn"> The current distinguished name of the entry. /// /// </param> /// <param name="newRdn"> The new relative distinguished name for the entry. /// /// </param> /// <param name="newParentdn"> The distinguished name of an existing entry which /// is to be the new parent of the entry. /// /// </param> /// <param name="deleteOldRdn"> If true, the old name is not retained as an /// attribute value. If false, the old name is /// retained as an attribute value. /// /// </param> /// <param name="cont"> Any controls that apply to the modifyDN request, /// or null if none. /// </param> public LdapModifyDNRequest(System.String dn, System.String newRdn, System.String newParentdn, bool deleteOldRdn, LdapControl[] cont):base(LdapMessage.MODIFY_RDN_REQUEST, new RfcModifyDNRequest(new RfcLdapDN(dn), new RfcRelativeLdapDN(newRdn), new Asn1Boolean(deleteOldRdn), ((System.Object) newParentdn != null)?new RfcLdapSuperDN(newParentdn):null), cont) { return ; }
/// <summary> Constructs an Ldap Unbind Request. /// /// </summary> /// <param name="cont">Any controls that apply to the unbind request /// </param> public LdapUnbindRequest(LdapControl[] cont):base(LdapMessage.UNBIND_REQUEST, new RfcUnbindRequest(), cont) { return ; }
public LdapBindRequest(int version, System.String dn, String mechanism, sbyte[] credentials, LdapControl[] cont):base(LdapMessage.BIND_REQUEST, new RfcBindRequest(version, dn, mechanism, credentials), cont) { return ; }
/// <summary> Construct an Ldap Abandon Request. /// /// </summary> /// <param name="id">The ID of the operation to abandon. /// /// </param> /// <param name="cont">Any controls that apply to the abandon request /// or null if none. /// </param> public LdapAbandonRequest(int id, LdapControl[] cont):base(LdapMessage.ABANDON_REQUEST, new RfcAbandonRequest(id), cont) { return ; }
public static void Main(System.String[] args) { /* Check if we have the correct number of command line arguments */ if (args.Length != 4) { System.Console.Error.WriteLine("Usage: mono VLVControl <host name> <login dn>" + " <password> <container>"); System.Console.Error.WriteLine("Example: mono VLVControl Acme.com \"cn=admin,o=Acme\" secret" + " \"ou=Sales,o=Acme\""); System.Environment.Exit(1); } /* Parse the command line arguments */ System.String LdapHost = args[0]; System.String loginDN = args[1]; System.String password = args[2]; System.String searchBase = args[3]; int LdapPort = LdapConnection.DEFAULT_PORT; int LdapVersion = LdapConnection.Ldap_V3; LdapConnection conn = new LdapConnection(); try { // connect to the server conn.Connect(LdapHost, LdapPort); // bind to the server conn.Bind(LdapVersion, loginDN, password); System.Console.Out.WriteLine("Succesfully logged in to server: " + LdapHost); /* Set default filter - Change this line if you need a different set * of search restrictions. Read the "NDS and Ldap Integration Guide" * for information on support by Novell eDirectory of this * functionaliry. */ System.String MY_FILTER = "cn=*"; /* We are requesting that the givenname and cn fields for each * object be returned */ System.String[] attrs = new System.String[2]; attrs[0] = "givenname"; attrs[1] = "cn"; // We will be sending two controls to the server LdapControl[] requestControls = new LdapControl[2]; /* Create the sort key to be used by the sort control * Results should be sorted based on the cn attribute. * See the "NDS and Ldap Integration Guide" for information on * Novell eDirectory support of this functionaliry. */ LdapSortKey[] keys = new LdapSortKey[1]; keys[0] = new LdapSortKey("cn"); // Create the sort control requestControls[0] = new LdapSortControl(keys, true); /* Create the VLV Control. * These two fields in the VLV Control identify the before and * after count of entries to be returned */ int beforeCount = 0; int afterCount = 2; /* The VLV control request can specify the index * using one of the two methods described below: * * TYPED INDEX: Here we request all objects that have cn greater * than or equal to the letter "a" */ requestControls[1] = new LdapVirtualListControl("a", beforeCount, afterCount); /* The following code needs to be enabled to specify the index * directly * int offset = 0; - offset of the index * int contentCount = 3; - our estimate of the search result size * requestControls[1] = new LdapVirtualListControl(offset, * beforeCount, afterCount, contentCount); */ // Set the controls to be sent as part of search request LdapSearchConstraints cons = conn.SearchConstraints; cons.setControls(requestControls); conn.Constraints = cons; // Send the search request - Synchronous Search is being used here System.Console.Out.WriteLine("Calling Asynchronous Search..."); LdapSearchResults res = conn.Search(searchBase, LdapConnection.SCOPE_SUB, MY_FILTER, attrs, false, (LdapSearchConstraints) null); // Loop through the results and print them out while (res.hasMore()) { /* Get next returned entry. Note that we should expect a Ldap- *Exception object as well just in case something goes wrong */ LdapEntry nextEntry=null; try { nextEntry = res.next(); } catch (LdapException e) { if (e is LdapReferralException) continue; else { System.Console.Out.WriteLine("Search stopped with exception " + e.ToString()); break; } } /* Print out the returned Entries distinguished name. */ System.Console.Out.WriteLine(); System.Console.Out.WriteLine(nextEntry.DN); /* Get the list of attributes for the current entry */ LdapAttributeSet findAttrs = nextEntry.getAttributeSet(); /* Convert attribute list to Enumeration */ System.Collections.IEnumerator enumAttrs = findAttrs.GetEnumerator(); System.Console.Out.WriteLine("Attributes: "); /* Loop through all attributes in the enumeration */ while (enumAttrs.MoveNext()) { LdapAttribute anAttr = (LdapAttribute) enumAttrs.Current; /* Print out the attribute name */ System.String attrName = anAttr.Name; System.Console.Out.WriteLine("" + attrName); // Loop through all values for this attribute and print them System.Collections.IEnumerator enumVals = anAttr.StringValues; while (enumVals.MoveNext()) { System.String aVal = (System.String) enumVals.Current; System.Console.Out.WriteLine("" + aVal); } } } // Server should send back a control irrespective of the // status of the search request LdapControl[] controls = res.ResponseControls; if (controls == null) { System.Console.Out.WriteLine("No controls returned"); } else { // We are likely to have multiple controls returned for (int i = 0; i < controls.Length; i++) { /* Is this the Sort Response Control. */ if (controls[i] is LdapSortResponse) { System.Console.Out.WriteLine("Received Ldap Sort Control from " + "Server"); /* We could have an error code and maybe a string * identifying erring attribute in the response control. */ System.String bad = ((LdapSortResponse) controls[i]).FailedAttribute; int result = ((LdapSortResponse) controls[i]).ResultCode; // Print out error code (0 if no error) and any // returned attribute System.Console.Out.WriteLine("Error code: " + result); if ((System.Object) bad != null) System.Console.Out.WriteLine("Offending " + "attribute: " + bad); else System.Console.Out.WriteLine("No offending " + "attribute " + "returned"); } /* Is this a VLV Response Control */ if (controls[i] is LdapVirtualListResponse) { System.Console.Out.WriteLine("Received VLV Response Control from " + "Server..."); /* Get all returned fields */ int firstPosition = ((LdapVirtualListResponse) controls[i]).FirstPosition; int ContentCount = ((LdapVirtualListResponse) controls[i]).ContentCount; int resultCode = ((LdapVirtualListResponse) controls[i]).ResultCode; System.String context = ((LdapVirtualListResponse) controls[i]).Context; /* Print out the returned fields. Typically you would * have used these fields to reissue another VLV request * or to display the list on a GUI */ System.Console.Out.WriteLine("Result Code => " + resultCode); System.Console.Out.WriteLine("First Position => " + firstPosition); System.Console.Out.WriteLine("Content Count => " + ContentCount); if ((System.Object) context != null) System.Console.Out.WriteLine("Context String => " + context); else System.Console.Out.WriteLine("No Context String in returned" + " control"); } } } /* We are done - disconnect */ if (conn.Connected) conn.Disconnect(); } catch (LdapException e) { System.Console.Out.WriteLine(e.ToString()); } catch (System.IO.IOException e) { System.Console.Out.WriteLine("Error: " + e.ToString()); } catch(Exception e) { System.Console.WriteLine("Error: " + e.Message); } }