Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,206 @@
/******************************************************************************
* The MIT License
* Copyright (c) 2003 Novell Inc. www.novell.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the Software), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*******************************************************************************/
//
// Novell.Directory.Ldap.Controls.LdapEntryChangeControl.cs
//
// Author:
// Sunil Kumar (Sunilk@novell.com)
//
// (C) 2003 Novell, Inc (http://www.novell.com)
//
using System;
using Novell.Directory.Ldap;
using Novell.Directory.Ldap.Asn1;
namespace Novell.Directory.Ldap.Controls
{
/// <summary> LdapEntryChangeControl is a Server Control returned at the request
/// of the client in response to a persistent search request. It
/// contains additional information about a change such as what type of
/// change occurred.
/// </summary>
public class LdapEntryChangeControl:LdapControl
{
/// <summary> returns the record number of the change in the servers change log.
///
/// </summary>
/// <returns> the record number of the change in the server's change log.
/// The server may not return a change number. In this case the return
/// value is -1
/// </returns>
virtual public bool HasChangeNumber
{
get
{
return m_hasChangeNumber;
}
}
/// <summary> returns the record number of the change in the servers change log.
///
/// </summary>
/// <returns> the record number of the change in the server's change log.
/// The server may not return a change number. In this case the return
/// value is -1
/// </returns>
virtual public int ChangeNumber
{
get
{
return m_changeNumber;
}
}
/// <summary> Returns the type of change that occured
///
/// </summary>
/// <returns> returns one of the following values indicating the type of
/// change that occurred:
/// LdapPersistSearchControl.ADD
/// LdapPersistSearchControl.DELETE
/// LdapPersistSearchControl.MODIFY
/// LdapPersistSearchControl.MODDN.
/// </returns>
virtual public int ChangeType
{
get
{
return m_changeType;
}
}
/// <summary> Returns the previous DN of the entry, if it was renamed.
///
/// </summary>
/// <returns> the previous DN of the entry if the entry was renamed (ie. if the
/// change type is LdapersistSearchControl.MODDN.
/// </returns>
virtual public System.String PreviousDN
{
get
{
return m_previousDN;
}
}
private int m_changeType;
private System.String m_previousDN;
private bool m_hasChangeNumber;
private int m_changeNumber;
/// <summary> This constructor is called by the SDK to create an
/// LdapEntryChangeControl. This constructor should NOT be called by
/// application developers. It must be public since it resides in a
/// different package than the classes that call it.
/// The Entry Change Control is defined as follows:
/// EntryChangeNotification ::= SEQUENCE {
/// changeType ENUMERATED {
/// add (1),
/// delete (2),
/// modify (4),
/// modDN (8)
/// },
/// previousDN LdapDN OPTIONAL, -- modifyDN ops. only
/// changeNumber INTEGER OPTIONAL -- if supported
/// }
///
/// </summary>
/// <param name="oid"> The OID of the control, as a dotted string.
///
/// </param>
/// <param name="critical"> True if the Ldap operation should be discarded if
/// the control is not supported. False if
/// the operation can be processed without the control.
///
/// </param>
/// <param name="value"> The control-specific data.
/// </param>
[CLSCompliantAttribute(false)]
public LdapEntryChangeControl(System.String oid, bool critical, sbyte[] value_Renamed):base(oid, critical, value_Renamed)
{
// Create a decoder objet
LBERDecoder decoder = new LBERDecoder();
if (decoder == null)
throw new System.IO.IOException("Decoding error.");
// We should get a sequence initially
Asn1Object asnObj = decoder.decode(value_Renamed);
if ((asnObj == null) || (!(asnObj is Asn1Sequence)))
throw new System.IO.IOException("Decoding error.");
Asn1Sequence sequence = (Asn1Sequence) asnObj;
// The first element in the sequence should be an enumerated type
Asn1Object asn1Obj = sequence.get_Renamed(0);
if ((asn1Obj == null) || (!(asn1Obj is Asn1Enumerated)))
throw new System.IO.IOException("Decoding error.");
m_changeType = ((Asn1Enumerated) asn1Obj).intValue();
//check for optional elements
if ((sequence.size() > 1) && (m_changeType == 8))
//8 means modifyDN
{
// get the previous DN - it is encoded as an octet string
asn1Obj = sequence.get_Renamed(1);
if ((asn1Obj == null) || (!(asn1Obj is Asn1OctetString)))
throw new System.IO.IOException("Decoding error get previous DN");
m_previousDN = ((Asn1OctetString) asn1Obj).stringValue();
}
else
{
m_previousDN = "";
}
//check for change number
if (sequence.size() == 3)
{
asn1Obj = sequence.get_Renamed(2);
if ((asn1Obj == null) || (!(asn1Obj is Asn1Integer)))
throw new System.IO.IOException("Decoding error getting change number");
m_changeNumber = ((Asn1Integer) asn1Obj).intValue();
m_hasChangeNumber = true;
}
else
m_hasChangeNumber = false;
return ;
}
/// <summary> Returns a string representation of the control for debugging.</summary>
public override System.String ToString()
{
return base.ToString();
}
} //end class LdapEntryChangeControl
}

View File

@@ -0,0 +1,281 @@
/******************************************************************************
* The MIT License
* Copyright (c) 2003 Novell Inc. www.novell.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the Software), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*******************************************************************************/
//
// Novell.Directory.Ldap.Controls.LdapPersistSearchControl.cs
//
// Author:
// Sunil Kumar (Sunilk@novell.com)
//
// (C) 2003 Novell, Inc (http://www.novell.com)
//
using System;
using Novell.Directory.Ldap;
using Novell.Directory.Ldap.Asn1;
namespace Novell.Directory.Ldap.Controls
{
/// <summary> LdapPersistSearchControl is a Server Control that allows a client
/// to receive notifications from the server of changes to entries within
/// the searches result set. The client can be notified when an entry is
/// added to the result set, when an entry is deleted from the result set,
/// when a DN has been changed or when and attribute value has been changed.
/// </summary>
public class LdapPersistSearchControl:LdapControl
{
/// <summary> Returns the change types to be monitored as a logical OR of any or
/// all of these values: ADD, DELETE, MODIFY, and/or MODDN.
///
/// </summary>
/// <returns> the change types to be monitored. The logical or of any of
/// the following values: ADD, DELETE, MODIFY, and/or MODDN.
/// </returns>
/// <summary> Sets the change types to be monitored.
///
/// types The change types to be monitored as a logical OR of any or all
/// of these types: ADD, DELETE, MODIFY, and/or MODDN. Can also be set
/// to the value ANY which is defined as the logical OR of all of the
/// preceding values.
/// </summary>
virtual public int ChangeTypes
{
get
{
return m_changeTypes;
}
set
{
m_changeTypes = value;
m_sequence.set_Renamed(CHANGETYPES_INDEX, new Asn1Integer(m_changeTypes));
setValue();
return ;
}
}
/// <summary> Returns true if entry change controls are to be returned with the
/// search results.
///
/// </summary>
/// <returns> true if entry change controls are to be returned with the
/// search results. Otherwise, false is returned
/// </returns>
/// <summary> When set to true, requests that entry change controls be returned with
/// the search results.
///
/// </summary>
/// <param name="returnControls"> true to return entry change controls.
/// </param>
virtual public bool ReturnControls
{
get
{
return m_returnControls;
}
set
{
m_returnControls = value;
m_sequence.set_Renamed(RETURNCONTROLS_INDEX, new Asn1Boolean(m_returnControls));
setValue();
return ;
}
}
/// <summary> getChangesOnly returns true if only changes are to be returned.
/// Results from the initial search are not returned.
///
/// </summary>
/// <returns> true of only changes are to be returned
/// </returns>
/// <summary> When set to true, requests that only changes be returned, results from
/// the initial search are not returned.
/// </summary>
/// <param name="changesOnly"> true to skip results for the initial search
/// </param>
virtual public bool ChangesOnly
{
get
{
return m_changesOnly;
}
set
{
m_changesOnly = value;
m_sequence.set_Renamed(CHANGESONLY_INDEX, new Asn1Boolean(m_changesOnly));
setValue();
return ;
}
}
/* private data members */
private static int SEQUENCE_SIZE = 3;
private static int CHANGETYPES_INDEX = 0;
private static int CHANGESONLY_INDEX = 1;
private static int RETURNCONTROLS_INDEX = 2;
private static LBEREncoder s_encoder;
private int m_changeTypes;
private bool m_changesOnly;
private bool m_returnControls;
private Asn1Sequence m_sequence;
/// <summary> The requestOID of the persistent search control</summary>
private static System.String requestOID = "2.16.840.1.113730.3.4.3";
/// <summary> The responseOID of the psersistent search - entry change control</summary>
private static System.String responseOID = "2.16.840.1.113730.3.4.7";
/// <summary> Change type specifying that you want to track additions of new entries
/// to the directory.
/// </summary>
public const int ADD = 1;
/// <summary> Change type specifying that you want to track removals of entries from
/// the directory.
/// </summary>
public const int DELETE = 2;
/// <summary> Change type specifying that you want to track modifications of entries
/// in the directory.
/// </summary>
public const int MODIFY = 4;
/// <summary> Change type specifying that you want to track modifications of the DNs
/// of entries in the directory.
/// </summary>
public const int MODDN = 8;
/// <summary> Change type specifying that you want to track any of the above
/// modifications.
/// </summary>
public static readonly int ANY = ADD | DELETE | MODIFY | MODDN;
/* public constructors */
/// <summary> The default constructor. A control with changes equal to ANY,
/// isCritical equal to true, changesOnly equal to true, and
/// returnControls equal to true
/// </summary>
public LdapPersistSearchControl():this(ANY, true, true, true)
{
return ;
}
/// <summary> Constructs an LdapPersistSearchControl object according to the
/// supplied parameters. The resulting control is used to specify a
/// persistent search.
///
/// </summary>
/// <param name="changeTypes"> the change types to monitor. The bitwise OR of any
/// of the following values:
/// <li> LdapPersistSearchControl.ADD</li>
/// <li> LdapPersistSearchControl.DELETE</li>
/// <li> LdapPersistSearchControl.MODIFY</li>
/// <li> LdapPersistSearchControl.MODDN</li>
/// To track all changes the value can be set to:
/// <li> LdapPersistSearchControl.ANY</li>
///
/// </param>
/// <param name="changesOnly"> true if you do not want the server to return
/// all existing entries in the directory that match the search
/// criteria. (Use this if you just want the changed entries to be
/// returned.)
///
/// </param>
/// <param name="returnControls"> true if you want the server to return entry
/// change controls with each entry in the search results. You need to
/// return entry change controls to discover what type of change
/// and other additional information about the change.
///
/// </param>
/// <param name="isCritical"> true if this control is critical to the search
/// operation. If true and the server does not support this control,
/// the server will not perform the search at all.
/// </param>
public LdapPersistSearchControl(int changeTypes, bool changesOnly, bool returnControls, bool isCritical):base(requestOID, isCritical, null)
{
m_changeTypes = changeTypes;
m_changesOnly = changesOnly;
m_returnControls = returnControls;
m_sequence = new Asn1Sequence(SEQUENCE_SIZE);
m_sequence.add(new Asn1Integer(m_changeTypes));
m_sequence.add(new Asn1Boolean(m_changesOnly));
m_sequence.add(new Asn1Boolean(m_returnControls));
setValue();
return ;
}
public override System.String ToString()
{
sbyte[] data = m_sequence.getEncoding(s_encoder);
System.Text.StringBuilder buf = new System.Text.StringBuilder(data.Length);
for (int i = 0; i < data.Length; i++)
{
buf.Append(data[i].ToString());
if (i < data.Length - 1)
buf.Append(",");
}
return buf.ToString();
}
/// <summary> Sets the encoded value of the LdapControlClass</summary>
private void setValue()
{
base.setValue(m_sequence.getEncoding(s_encoder));
return ;
}
static LdapPersistSearchControl()
{
s_encoder = new LBEREncoder();
/*
* This is where we register the control response
*/
{
/* Register the Entry Change control class which is returned by the
* server in response to a persistent search request
*/
try
{
// Register LdapEntryChangeControl
LdapControl.register(responseOID, System.Type.GetType("Novell.Directory.Ldap.Controls.LdapEntryChangeControl"));
}
catch (System.Exception e)
{
}
}
}
} // end class LdapPersistentSearchControl
}

View File

@@ -0,0 +1,131 @@
/******************************************************************************
* The MIT License
* Copyright (c) 2003 Novell Inc. www.novell.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the Software), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*******************************************************************************/
//
// Novell.Directory.Ldap.Controls.LdapSortControl.cs
//
// Author:
// Sunil Kumar (Sunilk@novell.com)
//
// (C) 2003 Novell, Inc (http://www.novell.com)
//
using System;
using Novell.Directory.Ldap;
using Novell.Directory.Ldap.Asn1;
namespace Novell.Directory.Ldap.Controls
{
/// <summary> LdapSortControl is a Server Control to specify how search results are
/// to be sorted by the server. If a server does not support
/// sorting in general or for a particular query, the results will be
/// returned unsorted, along with a control indicating why they were not
/// sorted (or that sort controls are not supported). If the control was
/// marked "critical", the whole search operation will fail if the sort
/// control is not supported.
/// </summary>
public class LdapSortControl:LdapControl
{
private static int ORDERING_RULE = 0;
private static int REVERSE_ORDER = 1;
/// <summary> The requestOID of the sort control</summary>
private static System.String requestOID = "1.2.840.113556.1.4.473";
/// <summary> The responseOID of the sort control</summary>
private static System.String responseOID = "1.2.840.113556.1.4.474";
/// <summary> Constructs a sort control with a single key.
///
/// </summary>
/// <param name="key"> A sort key object, which specifies attribute,
/// order, and optional matching rule.
///
/// </param>
/// <param name="critical True">if the search operation is to fail if the
/// server does not support this control.
/// </param>
public LdapSortControl(LdapSortKey key, bool critical):this(new LdapSortKey[]{key}, critical)
{
return ;
}
/// <summary> Constructs a sort control with multiple sort keys.
///
/// </summary>
/// <param name="keys An">array of sort key objects, to be processed in
/// order.
///
/// </param>
/// <param name="critical True">if the search operation is to fail if the
/// server does not support this control.
/// </param>
public LdapSortControl(LdapSortKey[] keys, bool critical):base(requestOID, critical, null)
{
Asn1SequenceOf sortKeyList = new Asn1SequenceOf();
for (int i = 0; i < keys.Length; i++)
{
Asn1Sequence key = new Asn1Sequence();
key.add(new Asn1OctetString(keys[i].Key));
if ((System.Object) keys[i].MatchRule != null)
{
key.add(new Asn1Tagged(new Asn1Identifier(Asn1Identifier.CONTEXT, false, ORDERING_RULE), new Asn1OctetString(keys[i].MatchRule), false));
}
if (keys[i].Reverse == true)
{
// only add if true
key.add(new Asn1Tagged(new Asn1Identifier(Asn1Identifier.CONTEXT, false, REVERSE_ORDER), new Asn1Boolean(true), false));
}
sortKeyList.add(key);
}
setValue(sortKeyList.getEncoding(new LBEREncoder()));
return ;
}
static LdapSortControl()
{
/*
* This is where we register the control responses
*/
{
/*
* Register the Server Sort Control class which is returned by the
* server in response to a Sort Request
*/
try
{
LdapControl.register(responseOID, System.Type.GetType("Novell.Directory.Ldap.Controls.LdapSortResponse"));
}
catch (System.Exception e)
{
}
}
}
}
}

View File

@@ -0,0 +1,168 @@
/******************************************************************************
* The MIT License
* Copyright (c) 2003 Novell Inc. www.novell.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the Software), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*******************************************************************************/
//
// Novell.Directory.Ldap.Controls.LdapSortKey.cs
//
// Author:
// Sunil Kumar (Sunilk@novell.com)
//
// (C) 2003 Novell, Inc (http://www.novell.com)
//
using System;
namespace Novell.Directory.Ldap.Controls
{
/// <summary> Encapsulates parameters for sorting search results.
/// </summary>
public class LdapSortKey
{
/// <summary> Returns the attribute to used for sorting.
///
/// </summary>
/// <returns> The name of the attribute used for sorting.
/// </returns>
virtual public System.String Key
{
get
{
return key;
}
}
/// <summary> Returns the sorting order, ascending or descending.
///
/// </summary>
/// <returns> True if the sorting is done is descending order; false, if the
/// sorting is done is ascending order.
/// </returns>
virtual public bool Reverse
{
get
{
return reverse;
}
}
/// <summary> Returns the OID to be used as a matching rule.
///
/// </summary>
/// <returns> The OID to be used as matching rule, or null if none is to be
/// used.
/// </returns>
virtual public System.String MatchRule
{
get
{
return matchRule;
}
}
private System.String key;
private bool reverse;
private System.String matchRule;
// Constructors
/// <summary> Constructs a new LdapSortKey object using an attribute as the sort key.
///
/// </summary>
/// <param name="keyDescription">The single attribute to use for sorting. If the
/// name is preceded by a minus sign (-), the sorting
/// is done in reverse (descending) order.
/// An OID for a matching rule may be appended
/// following a ":".
///
/// Examples:
/// <ul>
/// <li> "cn" (sorts in ascending order by the cn attribute)</li>
/// <li> "-cn" (sorts in descending order by the cn attribute) </li>
/// <li> "cn:1.2.3.4.5" (sorts in ascending order by the cn attribute
/// using the matching rule 1.2.3.4.5) </li>
/// </ul>
/// </param>
public LdapSortKey(System.String keyDescription)
{
matchRule = null;
reverse = false;
System.String myKey = keyDescription;
if (myKey[0] == '-')
{
myKey = myKey.Substring(1);
this.reverse = true;
}
int pos = myKey.IndexOf(":");
if (pos != - 1)
{
this.key = myKey.Substring(0, (pos) - (0));
this.matchRule = myKey.Substring(pos + 1);
}
else
{
this.key = myKey;
}
return ;
}
/// <summary> Constructs a new LdapSortKey object with the specified attribute name
/// and sort order.
///
/// </summary>
/// <param name="key"> The single attribute to use for sorting.
///
/// </param>
/// <param name="reverse">If true, sorting is done in descending order. If false,
/// sorting is done in ascending order.
/// </param>
public LdapSortKey(System.String key, bool reverse):this(key, reverse, null)
{
return ;
}
/// <summary> Constructs a new LdapSortKey object with the specified attribute name,
/// sort order, and a matching rule.
///
/// </summary>
/// <param name="key"> The attribute name (for example, "cn") to use for sorting.
///
/// </param>
/// <param name="reverse"> If true, sorting is done in descending order. If false,
/// sorting is done in ascending order.
///
/// </param>
/// <param name="matchRule"> The object ID (OID) of a matching rule used for
/// collation. If the object will be used to request
/// server-side sorting of search results, it should
/// be the OID of a matching rule known to be
/// supported by that server.
/// </param>
public LdapSortKey(System.String key, bool reverse, System.String matchRule)
{
this.key = key;
this.reverse = reverse;
this.matchRule = matchRule;
return ;
}
}
}

View File

@@ -0,0 +1,145 @@
/******************************************************************************
* The MIT License
* Copyright (c) 2003 Novell Inc. www.novell.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the Software), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*******************************************************************************/
//
// Novell.Directory.Ldap.Controls.LdapSortResponse.cs
//
// Author:
// Sunil Kumar (Sunilk@novell.com)
//
// (C) 2003 Novell, Inc (http://www.novell.com)
//
using System;
using Novell.Directory.Ldap;
using Novell.Directory.Ldap.Asn1;
namespace Novell.Directory.Ldap.Controls
{
/// <summary> LdapSortResponse - will be added in newer version of Ldap
/// Controls draft
/// </summary>
public class LdapSortResponse:LdapControl
{
/// <summary> If not null, this returns the attribute that caused the sort
/// operation to fail.
/// </summary>
virtual public System.String FailedAttribute
{
get
{
return failedAttribute;
}
}
/// <summary> Returns the result code from the sort</summary>
virtual public int ResultCode
{
get
{
return resultCode;
}
}
private System.String failedAttribute;
private int resultCode;
/// <summary> This constructor is usually called by the SDK to instantiate an
/// a LdapControl corresponding to the Server response to a Ldap
/// Sort Control request. Application programmers should not have
/// any reason to call the constructor. This constructor besides
/// constructing a LdapControl object parses the contents of the response
/// control.
///
/// RFC 2891 defines this response control as follows:
///
/// The controlValue is an OCTET STRING, whose
/// value is the BER encoding of a value of the following SEQUENCE:
/// SortResult ::= SEQUENCE {
/// sortResult ENUMERATED {
/// success (0), -- results are sorted
/// operationsError (1), -- server internal failure
/// timeLimitExceeded (3), -- timelimit reached before
/// -- sorting was completed
/// strongAuthRequired (8), -- refused to return sorted
/// -- results via insecure
/// -- protocol
/// adminLimitExceeded (11), -- too many matching entries
/// -- for the server to sort
/// noSuchAttribute (16), -- unrecognized attribute
/// -- type in sort key
/// inappropriateMatching (18), -- unrecognized or
/// -- inappropriate matching
/// -- rule in sort key
/// insufficientAccessRights (50), -- refused to return sorted
/// -- results to this client
/// busy (51), -- too busy to process
/// unwillingToPerform (53), -- unable to sort
/// other (80)
/// },
/// attributeType [0] AttributeDescription OPTIONAL }
///
///
/// </summary>
/// <param name="oid"> The OID of the control, as a dotted string.
///
/// </param>
/// <param name="critical"> True if the Ldap operation should be discarded if
/// the control is not supported. False if
/// the operation can be processed without the control.
///
/// </param>
/// <param name="values"> The control-specific data.
/// </param>
[CLSCompliantAttribute(false)]
public LdapSortResponse(System.String oid, bool critical, sbyte[] values):base(oid, critical, values)
{
// Create a decoder object
LBERDecoder decoder = new LBERDecoder();
if (decoder == null)
throw new System.IO.IOException("Decoding error");
// We should get back an enumerated type
Asn1Object asnObj = decoder.decode(values);
if ((asnObj == null) || (!(asnObj is Asn1Sequence)))
throw new System.IO.IOException("Decoding error");
Asn1Object asn1Enum = ((Asn1Sequence) asnObj).get_Renamed(0);
if ((asn1Enum != null) && (asn1Enum is Asn1Enumerated))
resultCode = ((Asn1Enumerated) asn1Enum).intValue();
// Second element is the attributeType
if (((Asn1Sequence) asnObj).size() > 1)
{
Asn1Object asn1String = ((Asn1Sequence) asnObj).get_Renamed(1);
if ((asn1String != null) && (asn1String is Asn1OctetString))
failedAttribute = ((Asn1OctetString) asn1String).stringValue();
}
return ;
}
}
}

View File

@@ -0,0 +1,200 @@
/******************************************************************************
* The MIT License
* Copyright (c) 2003 Novell Inc. www.novell.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the Software), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*******************************************************************************/
//
// Novell.Directory.Ldap.Controls.LdapVirtualListResponse.cs
//
// Author:
// Sunil Kumar (Sunilk@novell.com)
//
// (C) 2003 Novell, Inc (http://www.novell.com)
//
using System;
using Novell.Directory.Ldap;
using Novell.Directory.Ldap.Asn1;
namespace Novell.Directory.Ldap.Controls
{
/// <summary>
/// LdapVirtualListResponse is a Server Control returned by the server in
/// response to a virtual list search request.
/// </summary>
/// <summary>
/// In response to a VLV Search request the server returns an error code
/// and if the search was successful returns the following information:
/// <li> an index into the search results from where the returned list begins</li>
/// <li> an estimate of the total number of elements in the search result</li>
/// <li> an optional context field to be returned to the server with
/// subsequent VLV request.</li>
///
/// </summary>
public class LdapVirtualListResponse:LdapControl
{
/// <summary> Returns the size of the virtual search results list. This integer as
/// the servers current estimate of what the search result size.
/// </summary>
virtual public int ContentCount
{
get
{
return m_ContentCount;
}
}
/// <summary> Returns the index of the first entry in the returned list. The server uses
/// the clients request information in conjunction with its current search result
/// list to estimate what list of entries the client is requesting. This integer
/// is the index into the search results that is returned to the client.
/// </summary>
virtual public int FirstPosition
{
get
{
return m_firstPosition;
}
}
/// <summary> Returns the result code for the virtual list search request.</summary>
virtual public int ResultCode
{
get
{
return m_resultCode;
}
}
/// <summary> Returns the cookie used by some servers to optimize the processing of
/// virtual list requests. Subsequent VLV requests to the same server
/// should return this String to the server.
/// </summary>
virtual public System.String Context
{
get
{
return m_context;
}
}
/* The parsed fields are stored in these private variables */
private int m_firstPosition;
private int m_ContentCount;
private int m_resultCode;
/* The context field if one was returned by the server */
private System.String m_context = null;
/// <summary> This constructor is usually called by the SDK to instantiate an
/// a LdapControl corresponding to the Server response to a Ldap
/// VLV Control request. Application programmers should not have
/// any reason to call the constructor. This constructor besides
/// constructing a LdapVirtualListResponse control object also
/// parses the contents of the response into local variables.
///
/// RFC 2891 defines this response control as follows:
///
/// The controlValue is an OCTET STRING, whose value is the BER
/// encoding of a value of the following ASN.1:
///
/// VirtualListViewResponse ::= SEQUENCE {
/// targetPosition INTEGER (0 .. maxInt),
/// contentCount INTEGER (0 .. maxInt),
/// virtualListViewResult ENUMERATED {
/// success (0),
/// operationsError (1),
/// unwillingToPerform (53),
/// insufficientAccessRights (50),
/// busy (51),
/// timeLimitExceeded (3),
/// adminLimitExceeded (11),
/// sortControlMissing (60),
/// offsetRangeError (61),
/// other (80) },
/// contextID OCTET STRING OPTIONAL }
///
///
/// </summary>
/// <param name="oid"> The OID of the control, as a dotted string.
///
/// </param>
/// <param name="critical"> True if the Ldap operation should be discarded if
/// the control is not supported. False if
/// the operation can be processed without the control.
///
/// </param>
/// <param name="values"> The control-specific data.
/// </param>
[CLSCompliantAttribute(false)]
public LdapVirtualListResponse(System.String oid, bool critical, sbyte[] values):base(oid, critical, values)
{
/* Create a decoder object */
LBERDecoder decoder = new LBERDecoder();
if (decoder == null)
throw new System.IO.IOException("Decoding error");
/* We should get back an ASN.1 Sequence object */
Asn1Object asnObj = decoder.decode(values);
if ((asnObj == null) || (!(asnObj is Asn1Sequence)))
throw new System.IO.IOException("Decoding error");
/* Else we got back a ASN.1 sequence - print it if running debug code */
/* Get the 1st element which should be an integer containing the
* targetPosition (firstPosition)
*/
Asn1Object asn1firstPosition = ((Asn1Sequence) asnObj).get_Renamed(0);
if ((asn1firstPosition != null) && (asn1firstPosition is Asn1Integer))
m_firstPosition = ((Asn1Integer) asn1firstPosition).intValue();
else
throw new System.IO.IOException("Decoding error");
/* Get the 2nd element which should be an integer containing the
* current estimate of the contentCount
*/
Asn1Object asn1ContentCount = ((Asn1Sequence) asnObj).get_Renamed(1);
if ((asn1ContentCount != null) && (asn1ContentCount is Asn1Integer))
m_ContentCount = ((Asn1Integer) asn1ContentCount).intValue();
else
throw new System.IO.IOException("Decoding error");
/* The 3rd element is an enum containing the errorcode */
Asn1Object asn1Enum = ((Asn1Sequence) asnObj).get_Renamed(2);
if ((asn1Enum != null) && (asn1Enum is Asn1Enumerated))
m_resultCode = ((Asn1Enumerated) asn1Enum).intValue();
else
throw new System.IO.IOException("Decoding error");
/* Optional 4th element could be the context string that the server
* wants the client to send back with each subsequent VLV request
*/
if (((Asn1Sequence) asnObj).size() > 3)
{
Asn1Object asn1String = ((Asn1Sequence) asnObj).get_Renamed(3);
if ((asn1String != null) && (asn1String is Asn1OctetString))
m_context = ((Asn1OctetString) asn1String).stringValue();
}
return ;
}
}
}