| 1 |
/****************************************************************************** |
| 2 |
* The MIT License |
| 3 |
* Copyright (c) 2006 Novell Inc. www.novell.com |
| 4 |
* |
| 5 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 |
* of this software and associated documentation files (the Software), to deal |
| 7 |
* in the Software without restriction, including without limitation the rights |
| 8 |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 |
* copies of the Software, and to permit persons to whom the Software is |
| 10 |
* furnished to do so, subject to the following conditions: |
| 11 |
* |
| 12 |
* The above copyright notice and this permission notice shall be included in |
| 13 |
* all copies or substantial portions of the Software. |
| 14 |
* |
| 15 |
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 |
* SOFTWARE. |
| 22 |
*******************************************************************************/ |
| 23 |
// |
| 24 |
// Novell.Directory.Ldap.Extensions.BackupRestoreConstants.cs |
| 25 |
// |
| 26 |
// Author: |
| 27 |
// Palaniappan N ([email protected]) |
| 28 |
// |
| 29 |
// (C) 2006 Novell, Inc (http://www.novell.com) |
| 30 |
// |
| 31 |
|
| 32 |
|
| 33 |
using System; |
| 34 |
using System.IO; |
| 35 |
|
| 36 |
using Novell.Directory.Ldap; |
| 37 |
using Novell.Directory.Ldap.Asn1; |
| 38 |
|
| 39 |
/** |
| 40 |
* |
| 41 |
* This class provides an LDAP interface for object based |
| 42 |
* restore of eDirectory objects. |
| 43 |
* |
| 44 |
* <p>The information need for restore includes such items as object DN, |
| 45 |
* data buffer length, string containing the number of chunks and each chunk |
| 46 |
* elements representing the size of each chunk, data blob in byte[]. The API |
| 47 |
* support restoring of both non-encrypted and encrypted objects. |
| 48 |
* </p> |
| 49 |
* |
| 50 |
* <p>To send this request to eDirectory, you must |
| 51 |
* create an instance of this class and then call the |
| 52 |
* extendedOperation method with this object as the required |
| 53 |
* LdapExtendedOperation parameter.</p><br> |
| 54 |
* |
| 55 |
* <p>The getLdapRestoreRequest extension uses the following OID:<br> |
| 56 |
* 2.16.840.1.113719.1.27.100.98</p><br> |
| 57 |
* |
| 58 |
* <p>The requestValue has the following format:<br> |
| 59 |
* |
| 60 |
* <p>requestValue ::=<br> |
| 61 |
* objectDN ::= LDAPDN<br> |
| 62 |
* passwd ::= OCTET STRING<br> |
| 63 |
* bufferLength ::= INTEGER<br> |
| 64 |
* retunedBuffer::= OCTET STRING<br> |
| 65 |
* dataChunkSizes ::=<br> |
| 66 |
* SEQUENCE {<br> |
| 67 |
* noOfChunks INTEGER<br> |
| 68 |
* SET of [<br> |
| 69 |
* SEQUENCE of {eacChunksize INTEGER}]<br> |
| 70 |
* }<br> </p> |
| 71 |
*/ |
| 72 |
|
| 73 |
namespace Novell.Directory.Ldap.Extensions |
| 74 |
{ |
| 75 |
public class LdapRestoreRequest : LdapExtendedOperation |
| 76 |
{ |
| 77 |
/** |
| 78 |
* |
| 79 |
* Constructs an extended operations object which contains the ber encoded |
| 80 |
* restore data. |
| 81 |
* |
| 82 |
* @param objectDN The object DN to restore |
| 83 |
* <br> |
| 84 |
* @param passwd The encrypted password required for the object to |
| 85 |
* be backed up |
| 86 |
* <br> |
| 87 |
* @param bufferLength The length of backed up data |
| 88 |
* <br> |
| 89 |
* @param chunkSizesString The String containing number of chunks and |
| 90 |
* each chunk elements representing chunk sizes |
| 91 |
* <br> |
| 92 |
* @param returnedBuffer The actual data in byte[] |
| 93 |
* <br><br> |
| 94 |
* @exception LdapException A general exception which includes an error |
| 95 |
* message and an LDAP error code. |
| 96 |
*/ |
| 97 |
|
| 98 |
public LdapRestoreRequest(String objectDN, byte[] passwd, |
| 99 |
int bufferLength, String chunkSizesString, byte[] returnedBuffer): |
| 100 |
base(BackupRestoreConstants.NLDAP_LDAP_RESTORE_REQUEST, null) |
| 101 |
{ |
| 102 |
try |
| 103 |
{ |
| 104 |
//Verify the validity of arguments |
| 105 |
if (objectDN == null || bufferLength == 0 || |
| 106 |
chunkSizesString == null || returnedBuffer == null) |
| 107 |
throw new ArgumentException("PARAM_ERROR"); |
| 108 |
|
| 109 |
//If encrypted password has null reference make it null String |
| 110 |
if(passwd == null) |
| 111 |
passwd = System.Text.Encoding.UTF8.GetBytes(""); |
| 112 |
|
| 113 |
/* |
| 114 |
* From the input argument chunkSizesString get:: |
| 115 |
* chunkSize => Represents the number of chunks of data returned from server |
| 116 |
* sizeOf each chunk => int represents the size of each chunk |
| 117 |
*/ |
| 118 |
int index; |
| 119 |
int chunkSize; |
| 120 |
int[] chunks = null; |
| 121 |
index = chunkSizesString.IndexOf(';'); |
| 122 |
try |
| 123 |
{ |
| 124 |
chunkSize = int.Parse(chunkSizesString.Substring(0, index)); |
| 125 |
} |
| 126 |
catch (FormatException e) |
| 127 |
{ |
| 128 |
throw new LdapLocalException( |
| 129 |
"Invalid data buffer send in the request", |
| 130 |
LdapException.ENCODING_ERROR); |
| 131 |
} |
| 132 |
//Return exception if chunkSize == 0 |
| 133 |
if (chunkSize == 0) |
| 134 |
throw new ArgumentException("PARAM_ERROR"); |
| 135 |
|
| 136 |
chunkSizesString = chunkSizesString.Substring(index + 1); |
| 137 |
|
| 138 |
int chunkIndex; |
| 139 |
//Construct chunks array |
| 140 |
chunks = new int[chunkSize]; |
| 141 |
/* |
| 142 |
* Iterate through each member in buffer and |
| 143 |
* assign to chunks array elements |
| 144 |
*/ |
| 145 |
for (int i = 0; i < chunkSize; i++) |
| 146 |
{ |
| 147 |
chunkIndex = chunkSizesString.IndexOf(';'); |
| 148 |
if(chunkIndex == -1) |
| 149 |
{ |
| 150 |
chunks[i] = int.Parse(chunkSizesString); |
| 151 |
break; |
| 152 |
} |
| 153 |
chunks[i] = int.Parse(chunkSizesString.Substring(0, |
| 154 |
chunkIndex)); |
| 155 |
chunkSizesString = chunkSizesString.Substring(chunkIndex + 1); |
| 156 |
} |
| 157 |
|
| 158 |
MemoryStream encodedData = new MemoryStream(); |
| 159 |
LBEREncoder encoder = new LBEREncoder(); |
| 160 |
|
| 161 |
//Form objectDN, passwd, bufferLength, data byte[] as ASN1 Objects |
| 162 |
Asn1OctetString asn1_objectDN = new Asn1OctetString(objectDN); |
| 163 |
Asn1OctetString asn1_passwd = new Asn1OctetString(SupportClass.ToSByteArray(passwd)); |
| 164 |
Asn1Integer asn1_bufferLength = new Asn1Integer(bufferLength); |
| 165 |
Asn1OctetString asn1_buffer = new Asn1OctetString(SupportClass.ToSByteArray(returnedBuffer)); |
| 166 |
|
| 167 |
//Form the chunks sequence to be passed to Server |
| 168 |
Asn1Sequence asn1_chunksSeq = new Asn1Sequence(); |
| 169 |
asn1_chunksSeq.add(new Asn1Integer(chunkSize)); |
| 170 |
Asn1Set asn1_chunksSet = new Asn1Set(); |
| 171 |
for (int i = 0; i < chunkSize; i++) |
| 172 |
{ |
| 173 |
Asn1Integer tmpChunk = new Asn1Integer(chunks[i]); |
| 174 |
Asn1Sequence tmpSeq = new Asn1Sequence(); |
| 175 |
tmpSeq.add(tmpChunk); |
| 176 |
asn1_chunksSet.add(tmpSeq); |
| 177 |
} |
| 178 |
asn1_chunksSeq.add(asn1_chunksSet); |
| 179 |
|
| 180 |
//Encode data to send to server |
| 181 |
asn1_objectDN.encode(encoder, encodedData); |
| 182 |
asn1_passwd.encode(encoder, encodedData); |
| 183 |
asn1_bufferLength.encode(encoder, encodedData); |
| 184 |
asn1_buffer.encode(encoder, encodedData); |
| 185 |
asn1_chunksSeq.encode(encoder, encodedData); |
| 186 |
|
| 187 |
// set the value of operation specific data |
| 188 |
setValue(SupportClass.ToSByteArray(encodedData.ToArray())); |
| 189 |
|
| 190 |
} |
| 191 |
catch (IOException ioe) |
| 192 |
{ |
| 193 |
throw new LdapException("ENCODING_ERROR", LdapException.ENCODING_ERROR, (String) null); |
| 194 |
} |
| 195 |
} |
| 196 |
} |
| 197 |
} |