Debian Codegraph @

mcs/class/Novell.Directory.Ldap/Novell.Directory.Ldap.Extensions/LdapBackupRequest.cs

raw
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 backup
42 * of eDirectory objects. The backup API not only get the objects
43 * but all the DS level attributes associated with the objects.
44 *
45 * <p>The information available includes such items as modification timestamp,
46 * revision,data blob consisting of backup data of any eDirectory Object. The API
47 * support backing of both non-encrypted and encrypted objects
48 * </p>
49 *
50 * <p>To get information about any eDirectory Object, 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>
54 *
55 * <p>The getLdapBackupRequest extension uses the following OID:<br>
56 * &nbsp;&nbsp;&nbsp;2.16.840.1.113719.1.27.100.96</p><br>
57 *
58 * <p>The requestValue has the following format:<br>
59 *
60 * requestValue ::=<br>
61 * &nbsp;&nbsp;&nbsp;&nbsp; objectDN&nbsp;&nbsp;&nbsp; LDAPDN<br>
62 * &nbsp;&nbsp;&nbsp;&nbsp; mts(modification timestamp) INTEGER<br>
63 * &nbsp;&nbsp;&nbsp;&nbsp; revision&nbsp;&nbsp;&nbsp; INTEGER<br>
64 * &nbsp;&nbsp;&nbsp;&nbsp; passwd&nbsp;&nbsp;&nbsp; OCTET STRING</p>
65 */
66
67 namespace Novell.Directory.Ldap.Extensions
68 {
69 public class LdapBackupRequest: LdapExtendedOperation
70 {
71
72 static LdapBackupRequest()
73 {
74 /*
75 * Register the extendedresponse class which is returned by the server
76 * in response to a LdapBackupRequest
77 */
78 try
79 {
80 LdapExtendedResponse.register(
81 BackupRestoreConstants.NLDAP_LDAP_BACKUP_RESPONSE,
82 Type.GetType("Novell.Directory.Ldap.Extensions.LdapBackupResponse"));
83 }
84 catch (TypeLoadException e)
85 {
86 Console.Error.WriteLine("Could not register Extended Response - Class not found");
87 }
88 catch (Exception e)
89 {
90 Console.Error.WriteLine(e.StackTrace);
91 }
92 }
93
94 /**
95 *
96 * Constructs an extended operations object for getting data about any Object.
97 *
98 * @param objectDN The DN of the object to be backed up
99 * <br>
100 * @param passwd The encrypted password required for the object to
101 * be backed up
102 * <br>
103 * @param stateInfo The state information of the object to backup.
104 * This parameter is a String which contains combination of modification
105 * timestamp and revision number of object being backed up. The format
106 * of both modification time stamp and revision should pertain to eDirectoty
107 * standard format of taking modification timestamp and revision.
108 * Separator being used between these two is a '+' character.<br>
109 *
110 *
111 * @exception LdapException A general exception which includes an error
112 * message and an LDAP error code.
113 */
114 public LdapBackupRequest(String objectDN, byte[] passwd, String stateInfo):
115 base(BackupRestoreConstants.NLDAP_LDAP_BACKUP_REQUEST, null)
116 {
117
118 int mts; // Modifaction time stamp of the Object
119 int revision; // Revision number of the Object
120 String mtsStr, revisionStr;
121
122 try
123 {
124 if (objectDN == null)
125 throw new ArgumentException("PARAM_ERROR");
126
127 //If encrypted password has null reference make it null String
128 if(passwd == null)
129 passwd = System.Text.Encoding.UTF8.GetBytes("");
130
131
132 if (stateInfo == null)
133 {
134 // If null reference is passed in stateInfo initialize both
135 // mts and revision
136 mts = 0;
137 revision = 0;
138 }
139 else
140 {
141 // Parse the passed stateInfo to obtain mts and revision
142 stateInfo = stateInfo.Trim();
143 int index = stateInfo.IndexOf('+');
144 if(index == -1)
145 throw new ArgumentException("PARAM_ERROR");
146 mtsStr = stateInfo.Substring(0, index);
147 revisionStr = stateInfo.Substring(index + 1);
148 try
149 {
150 mts = int.Parse(mtsStr);
151 }
152 catch (FormatException e)
153 {
154 throw new LdapLocalException("Invalid Modification Timestamp send in the request", LdapException.ENCODING_ERROR);
155 }
156 try
157 {
158 revision = int.Parse(revisionStr);
159 }
160 catch (FormatException e)
161 {
162 throw new LdapLocalException(
163 "Invalid Revision send in the request",
164 LdapException.ENCODING_ERROR);
165 }
166 }
167
168 MemoryStream encodedData = new MemoryStream();
169 LBEREncoder encoder = new LBEREncoder();
170
171 // Encode data of objectDN, mts and revision
172 Asn1OctetString asn1_objectDN = new Asn1OctetString(objectDN);
173 Asn1Integer asn1_mts = new Asn1Integer(mts);
174 Asn1Integer asn1_revision = new Asn1Integer(revision);
175 Asn1OctetString asn1_passwd = new Asn1OctetString(SupportClass.ToSByteArray(passwd));
176
177 asn1_objectDN.encode(encoder, encodedData);
178 asn1_mts.encode(encoder, encodedData);
179 asn1_revision.encode(encoder, encodedData);
180 asn1_passwd.encode(encoder, encodedData);
181
182 // set the value of operation specific data
183 setValue(SupportClass.ToSByteArray(encodedData.ToArray()));
184
185 }
186 catch (IOException ioe)
187 {
188 throw new LdapException("ENCODING_ERROR", LdapException.ENCODING_ERROR, (String) null);
189 }
190 }
191 }
192 }