static MonitorEventRequest() { /* * Register the extendedresponse class which is returned by the * server in response to a MonitorEventRequest */ try { LdapExtendedResponse.register(EventOids.NLDAP_MONITOR_EVENTS_RESPONSE, Type.GetType("Novell.Directory.Ldap.Events.Edir.MonitorEventResponse", true)); } catch (TypeLoadException e) { // TODO: put something in the Debug... } catch (Exception e) { // TODO: put something in the Debug... } //Also try to register EdirEventIntermediateResponse try { LdapIntermediateResponse.register(EventOids.NLDAP_EVENT_NOTIFICATION, Type.GetType("Novell.Directory.Ldap.Events.Edir.EdirEventIntermediateResponse", true)); } catch (TypeLoadException e) { // TODO: put something in the Debug... } catch (Exception e) { // TODO: put something in the Debug... } } // end of static constructor
static GetBindDNRequest() { /* * Register the extendedresponse class which is returned by the * server in response to a ListReplicasRequest */ LdapExtendedResponse.register(ReplicationConstants.GET_IDENTITY_NAME_RES, typeof(GetBindDNResponse)); }
static ListReplicasRequest() { /* * Register the extendedresponse class which is returned by the * server in response to a ListReplicasRequest */ LdapExtendedResponse.register(ReplicationConstants.LIST_REPLICAS_RES, typeof(ListReplicasResponse)); }
static LdapBackupRequest() { /* * Register the extendedresponse class which is returned by the server * in response to a LdapBackupRequest */ LdapExtendedResponse.register(BackupRestoreConstants.NLDAP_LDAP_BACKUP_RESPONSE, typeof(LdapBackupResponse)); }
/// <summary> /// Used to Convert an RfcLdapMessage object to the appropriate /// LdapExtendedResponse object depending on the operation being performed. /// </summary> /// <param name="inResponse"> /// The LdapExtendedReponse object as returned by the /// extendedOperation method in the LdapConnection object. /// </param> /// <returns> /// An object of base class LdapExtendedResponse. The actual child /// class of this returned object depends on the operation being /// performed. /// </returns> public static LdapExtendedResponse convertToExtendedResponse(RfcLdapMessage inResponse) { var tempResponse = new LdapExtendedResponse(inResponse); // Get the oid stored in the Extended response var inOID = tempResponse.ID; var regExtResponses = LdapExtendedResponse.RegisteredResponses; try { var extRespClass = regExtResponses.findResponseExtension(inOID); if (extRespClass == null) { return(tempResponse); } Type[] argsClass = { typeof(RfcLdapMessage) }; object[] args = { inResponse }; Exception ex; try { var extConstructor = extRespClass.GetConstructor(argsClass); try { object resp = null; resp = extConstructor.Invoke(args); return((LdapExtendedResponse)resp); } catch (UnauthorizedAccessException e) { ex = e; } catch (TargetInvocationException e) { ex = e; } catch (Exception e) { // Could not create the ResponseControl object // All possible exceptions are ignored. We fall through // and create a default LdapControl object ex = e; } } catch (MethodAccessException e) { // bad class was specified, fall through and return a // default LdapExtendedResponse object ex = e; } } catch (FieldAccessException ex) { Logger.Log.LogWarning("Exception swallowed", ex); } // If we get here we did not have a registered extendedresponse // for this oid. Return a default LdapExtendedResponse object. return(tempResponse); }
/// <summary> Used to Convert an RfcLdapMessage object to the appropriate /// LdapExtendedResponse object depending on the operation being performed. /// /// </summary> /// <param name="inResponse"> The LdapExtendedReponse object as returned by the /// extendedOperation method in the LdapConnection object. /// </param> /// <returns> An object of base class LdapExtendedResponse. The actual child /// class of this returned object depends on the operation being /// performed. /// </returns> static public LdapExtendedResponse convertToExtendedResponse(RfcLdapMessage inResponse) { LdapExtendedResponse tempResponse = new LdapExtendedResponse(inResponse); // Get the oid stored in the Extended response System.String inOID = tempResponse.ID; RespExtensionSet regExtResponses = LdapExtendedResponse.RegisteredResponses; try { System.Type extRespClass = regExtResponses.findResponseExtension(inOID); if (extRespClass == null) { return(tempResponse); } System.Type[] argsClass = new System.Type[] { typeof(RfcLdapMessage) }; System.Object[] args = new System.Object[] { inResponse }; System.Exception ex; try { System.Reflection.ConstructorInfo extConstructor = extRespClass.GetConstructor(argsClass); try { System.Object resp = null; resp = extConstructor.Invoke(args); return((LdapExtendedResponse)resp); } catch (System.UnauthorizedAccessException e) { ex = e; } catch (System.Reflection.TargetInvocationException e) { ex = e; } catch (System.Exception e) { // Could not create the ResponseControl object // All possible exceptions are ignored. We fall through // and create a default LdapControl object ex = e; } } catch (System.MethodAccessException e) { // bad class was specified, fall through and return a // default LdapExtendedResponse object ex = e; } } catch (System.FieldAccessException e) { } // If we get here we did not have a registered extendedresponse // for this oid. Return a default LdapExtendedResponse object. return(tempResponse); }
static PartitionEntryCountRequest() { /* * Register the extendedresponse class which is returned by the * server in response to a ListReplicasRequest */ LdapExtendedResponse.register(ReplicationConstants.NAMING_CONTEXT_COUNT_RES, typeof(PartitionEntryCountResponse)); }
/** * * Constructs an extended operation object for getting data about any Object * and make a call to ld.ExtendedOperation to get the response <br> * */ public static ArrayList backup(LdapConnection ld, String objectDN, byte[] passwd, String stateInfo) { int intInfo; String strInfo; byte[] returnedBuffer; //Actual data blob returned as byte[] ArrayList objectBuffer = new ArrayList(4); objectBuffer.Insert(0, new Integer32(-1)); //Mark the rc default as failed backup try { LdapExtendedOperation request = new LdapBackupRequest(objectDN, passwd, stateInfo); LdapExtendedResponse response = ld.ExtendedOperation(request); int result = response.ResultCode; objectBuffer.Remove(0); objectBuffer.Insert(0, new Integer32(result)); if ((result == LdapException.SUCCESS) && (response is LdapBackupResponse)) { Console.WriteLine("Backup Info:"); strInfo = ((LdapBackupResponse)response).getStatusInfo(); Console.WriteLine(" Status Info: " + strInfo); intInfo = ((LdapBackupResponse)response).getBufferLength(); Console.WriteLine(" Buffer length: " + intInfo); objectBuffer.Insert(1, new Integer32(intInfo)); strInfo = ((LdapBackupResponse)response).getChunkSizesString(); Console.WriteLine(" Chunk sizes: " + strInfo); objectBuffer.Insert(2, strInfo); returnedBuffer = ((LdapBackupResponse)response).getReturnedBuffer(); objectBuffer.Insert(3, returnedBuffer); Console.WriteLine("\nInformation backed up successfully\n"); } else { Console.WriteLine("Could not backup the information.\n"); throw new LdapException(response.ErrorMessage, response.ResultCode, (String)null); } } catch (LdapException e) { Console.WriteLine("Error: " + e.ToString()); } catch (System.Exception e) { Console.WriteLine("Error: " + e.ToString()); } return(objectBuffer); }
static GetEffectivePrivilegesRequest() { /* * Register the extendedresponse class which is returned by the * server in response to a ListReplicasRequest */ LdapExtendedResponse.register(ReplicationConstants.GET_EFFECTIVE_PRIVILEGES_RES, typeof(GetEffectivePrivilegesResponse)); }
static GetReplicationFilterRequest() { /* * Register the extendedresponse class which is returned by the * server in response to a ListReplicasRequest */ LdapExtendedResponse.register(ReplicationConstants.GET_REPLICATION_FILTER_RES, typeof(GetReplicationFilterResponse)); }
static MonitorEventRequest() { /* * Register the extendedresponse class which is returned by the * server in response to a MonitorEventRequest */ LdapExtendedResponse.register(EventOids.NLDAP_MONITOR_EVENTS_RESPONSE, typeof(MonitorEventResponse)); //Also try to register EdirEventIntermediateResponse LdapIntermediateResponse.register(EventOids.NLDAP_EVENT_NOTIFICATION, typeof(EdirEventIntermediateResponse)); } // end of static constructor
/// <summary> /// Returns the effective rights of one object to a list of attributes of another object. /// /// To use this class, you must instantiate an object of this class and then /// call the extendedOperation method with this object as the required /// LdapExtendedOperation parameter. /// /// The returned LdapExtendedResponse object can then be converted to /// a GetEffectivePrivilegesListResponse object with the ExtendedResponseFactory class. /// The GetEffectivePrivilegesListResponse class contains methods for /// retrieving the list of effective rights. /// /// The getEffectivePrivilegesRequest extension uses the following OID: /// 2.16.840.1.113719.1.27.100.103 /// /// The requestValue has the following format: /// /// requestValue ::= /// dn LdapDN /// trusteeDN LdapDN /// SEQUENCE of attrNames LdapDN /// </summary> static GetEffectivePrivilegesListRequest() { try { LdapExtendedResponse.register(ReplicationConstants.GET_EFFECTIVE_LIST_PRIVILEGES_RES, Type.GetType("Novell.Directory.Ldap.Extensions.GetEffectivePrivilegesListResponse")); } catch (Exception e) { Console.Error.WriteLine("Could not register Extended Response -" + " Class not found"); } }
static GetBindDNRequest() { /* * Register the extendedresponse class which is returned by the * server in response to a ListReplicasRequest */ try { LdapExtendedResponse.register(ReplicationConstants.GET_IDENTITY_NAME_RES, System.Type.GetType("Novell.Directory.Ldap.Extensions.GetBindDNResponse")); } catch (System.Exception e) { System.Console.Error.WriteLine("Could not register Extended Response -" + " Class not found"); } }
static GetEffectivePrivilegesRequest() { /* * Register the extendedresponse class which is returned by the * server in response to a ListReplicasRequest */ try { LdapExtendedResponse.register(ReplicationConstants.GET_EFFECTIVE_PRIVILEGES_RES, System.Type.GetType("Novell.Directory.Ldap.Extensions.GetEffectivePrivilegesResponse")); } catch (System.Exception e) { System.Console.Error.WriteLine("Could not register Extended Response -" + " Class not found"); } }
static PartitionEntryCountRequest() { /* * Register the extendedresponse class which is returned by the * server in response to a ListReplicasRequest */ try { LdapExtendedResponse.register(ReplicationConstants.NAMING_CONTEXT_COUNT_RES, System.Type.GetType("Novell.Directory.Ldap.Extensions.PartitionEntryCountResponse")); } catch (System.Exception e) { System.Console.Error.WriteLine("Could not register Extended Response -" + " Class not found"); } }
static GetReplicaInfoRequest() { /* * Register the extendedresponse class which is returned by the * server in response to a ListReplicasRequest */ try { LdapExtendedResponse.register(ReplicationConstants.GET_REPLICA_INFO_RES, Type.GetType("Novell.Directory.Ldap.Extensions.GetReplicaInfoResponse")); } catch (Exception e) { Console.Error.WriteLine("Could not register Extended Response -" + " Class not found"); } }
static void Main(string[] args) { if (args.Length != 7) { Console.WriteLine("Usage: mono AddReplica <host name> <ldap port> <login dn>" + " <password> <replica dn> <replica type> <server dn> "); Console.WriteLine("Example: mono AddReplica Acme.com 389" + " \"cn=admin,o=Acme\"" + " secret \"ou=Sales,o=Acme\" 1 \"cn=myServer,o=Acme\""); return; } string ldapHost = args[0]; int ldapPort = System.Convert.ToInt32(args[1]); String loginDN = args[2]; String password = args[3]; String replicaDN = args[4]; int replicaType = System.Convert.ToInt32(args[5]); String serverDN = args[6]; try { LdapConnection conn = new LdapConnection(); Console.WriteLine("Connecting to:" + ldapHost); conn.Connect(ldapHost, ldapPort); conn.Bind(loginDN, password); LdapExtendedOperation request = new AddReplicaRequest(replicaDN, serverDN, replicaType, ReplicationConstants.Ldap_ENSURE_SERVERS_UP); LdapExtendedResponse response = conn.ExtendedOperation(request); if (response.ResultCode == LdapException.SUCCESS) { Console.WriteLine("Add Replica Request succeeded\n"); } conn.Disconnect(); } catch (LdapException e) { Console.WriteLine("Error:" + e.LdapErrorMessage); return; } catch (Exception e) { Console.WriteLine("Error:" + e.Message); return; } }
/** * * Constructs an extended operation object for restoring data of retreived * Object and make a call to ld.extendedOperation to get the response <br> * */ public static void restore(LdapConnection ld, String objectDN, byte[] passwd, ArrayList objectBuffer) { try { if (((Integer32)objectBuffer[0]).intValue != 0) { Console.WriteLine("Note: The test program did not proceed " + "with restore since backup was not proper"); Environment.Exit(0); } LdapExtendedOperation request = new LdapRestoreRequest( objectDN, passwd, (((Integer32)objectBuffer[1]).intValue), (string)objectBuffer[2], (byte[])objectBuffer[3]); LdapExtendedResponse response = ld.ExtendedOperation(request); if (response.ResultCode == LdapException.SUCCESS) { Console.WriteLine("Object restored successfully\n"); } else { Console.WriteLine("Restore Request Failed"); throw new LdapException(response.ErrorMessage, response.ResultCode, (string)null); } } catch (LdapException e) { Console.WriteLine("Error: " + e.ToString()); } catch (System.Exception e) { Console.WriteLine("Error: " + e.ToString()); } }
static LdapBackupRequest() { /* * Register the extendedresponse class which is returned by the server * in response to a LdapBackupRequest */ try { LdapExtendedResponse.register( BackupRestoreConstants.NLDAP_LDAP_BACKUP_RESPONSE, Type.GetType("Novell.Directory.Ldap.Extensions.LdapBackupResponse")); } catch (TypeLoadException e) { Console.Error.WriteLine("Could not register Extended Response - Class not found"); } catch (Exception e) { Console.Error.WriteLine(e.StackTrace); } }
static void Main(string[] args) { if (args.Length != 4) { Console.WriteLine("Usage: mono RefreshLdapServer <host name> <ldap port> <login dn>" + " <password> "); Console.WriteLine("Example: mono RefreshLdapServer Acme.com 389" + " \"cn=admin,o=Acme\"" + " secret "); return; } string ldapHost = args[0]; int ldapPort = System.Convert.ToInt32(args[1]); String loginDN = args[2]; String password = args[3]; try { LdapConnection conn = new LdapConnection(); Console.WriteLine("Connecting to:" + ldapHost); conn.Connect(ldapHost, ldapPort); conn.Bind(loginDN, password); LdapExtendedOperation request = new RefreshLdapServerRequest(); LdapExtendedResponse response = conn.ExtendedOperation(request); if (response.ResultCode == LdapException.SUCCESS) { Console.WriteLine("Refresh Ldap Server Request succeeded\n"); } conn.Disconnect(); } catch (LdapException e) { Console.WriteLine("Error:" + e.LdapErrorMessage); return; } catch (Exception e) { Console.WriteLine("Error:" + e.Message); return; } }
public static void Main(System.String[] args) { if (args.Length != 6) { System.Console.Error.WriteLine("Usage: mono GetEffectivePrivileges " + "<host Name> <port number> <login dn> " + "\n <password> <object dn> <trustee dn>"); System.Console.Error.WriteLine("Example: mono GetEffectivePrivileges Acme.com 389 " + "\"cn=Admin,o=Acme\" secret\n " + "\"cn=james,o=Acme\" " + "\"cn=admin,o=Acme\""); System.Environment.Exit(1); } int LdapVersion = LdapConnection.Ldap_V3; System.String LdapHost = args[0]; int LdapPort = System.Int32.Parse(args[1]); System.String loginDN = args[2]; System.String password = args[3]; System.String objectDN = args[4]; System.String trusteeDN = args[5]; int iRight = 0; System.String sRight = null; LdapConnection ld = new LdapConnection(); try { // connect to the server ld.Connect(LdapHost, LdapPort); // bind to the server ld.Bind(LdapVersion, loginDN, password); System.Console.Out.WriteLine("\nLogin succeeded"); // user can choose from: // 1. object rights(represented as [Entry Rights]); // 2. attribute rights(represented as [All Attributes Rights]; // 3. a single attribute name like 'acl' //String rightName = "[Entry Rights]" //String rightName = "[All Attributes Rights]"; System.String rightName = "acl"; LdapExtendedOperation request = new GetEffectivePrivilegesRequest(objectDN, trusteeDN, rightName); LdapExtendedResponse response = ld.ExtendedOperation(request); if (response.ResultCode == LdapException.SUCCESS && (response is GetEffectivePrivilegesResponse)) { iRight = ((GetEffectivePrivilegesResponse)response).Privileges; if (rightName.ToUpper().Equals("[Entry Rights]".ToUpper())) { sRight = "object rights"; } else if (rightName.ToUpper().Equals("[All Attributes Rights]".ToUpper())) { sRight = "attribute rights"; } else { sRight = rightName; } System.Console.Out.WriteLine("\"" + trusteeDN + "\" has the following" + " rights on \"" + objectDN + "\"s '" + sRight + "':"); PrintRights(rightName, iRight); System.Console.Out.WriteLine("\nGet Effective Privileges succeeded"); } else { System.Console.Out.WriteLine("Get Effective Privileges Failed"); throw new LdapException(response.ErrorMessage, response.ResultCode, (System.String)null); } /* Done, so disconnect */ if (ld.Connected) { ld.Disconnect(); } } catch (LdapException e) { System.Console.Out.WriteLine("Error: " + e.LdapErrorMessage); } }
static void Main(string[] args) { if (args.Length != 6) { System.Console.Error.WriteLine("Usage: mono GetEffectivePrivilegesList " + "<host Name> <port number> <login dn> " + "\n <password> <object dn> <trustee dn>"); System.Console.Error.WriteLine("Example: mono GetEffectivePrivilegesList Acme.com 389 " + "\"cn=Admin,o=Acme\" secret\n " + "\"cn=james,o=Acme\" " + "\"cn=admin,o=Acme\""); System.Environment.Exit(1); } int ldapVersion = LdapConnection.Ldap_V3; System.String ldapHost = args[0]; int ldapPort = System.Int32.Parse(args[1]); System.String loginDN = args[2]; System.String password = args[3]; System.String objectDN = args[4]; System.String trusteeDN = args[5]; int[] iRight = { 0 }; System.String[] sRight = null; LdapConnection ld = new LdapConnection(); try { // connect to the server ld.Connect(ldapHost, ldapPort); // bind to the server ld.Bind(ldapVersion, loginDN, password); System.Console.Out.WriteLine("\nLogin succeeded"); // user can choose from: // 1. object rights(represented as [Entry Rights]); // 2. attribute rights(represented as [All Attributes Rights]; // 3. a single attribute name like 'acl' //String rightName = "{[Entry Rights],null}" //String rightName = "{[All Attributes Rights],null}"; //String rightName = "{attr1,attr2,attr3,.... ,null}" System.String[] rightName = { "acl", "cn", "dn", null }; LdapExtendedOperation request = new GetEffectivePrivilegesListRequest(objectDN, trusteeDN, rightName); LdapExtendedResponse response = ld.ExtendedOperation(request); if (response.ResultCode == LdapException.SUCCESS && (response is GetEffectivePrivilegesListResponse)) { iRight = ((GetEffectivePrivilegesListResponse)response).getPrivileges(); if (iRight.Length == (rightName.Length - 1)) { sRight = new System.String[iRight.Length]; for (int i = 0; rightName[i] != null; i++) { if (rightName[i].ToUpper().Equals("[Entry Rights]".ToUpper())) { sRight[i] = "object rights"; } else if (rightName[i].ToUpper().Equals("[All Attributes Rights]".ToUpper())) { sRight[i] = "attribute rights"; } else { sRight[i] = rightName[i]; } } System.Console.WriteLine("\"" + trusteeDN + "\" has the following rights on \"" + objectDN + "\'s "); for (int i = 0; rightName[i] != null; i++) { System.Console.WriteLine("'" + sRight[i] + "':"); PrintRights(rightName[i], iRight[i]); System.Console.WriteLine("\nGet Effective Privileges succeeded"); } } else { System.Console.WriteLine("You have provided the wrong input in terms of attribute list"); } } else { System.Console.WriteLine("Get Effective Privileges List Failed"); throw new LdapException(response.ErrorMessage, response.ResultCode, (System.String)null); } /* Done, so disconnect */ if (ld.Connected) { ld.Disconnect(); } } catch (LdapException e) { System.Console.Out.WriteLine("Error: " + e.LdapErrorMessage); } }
static ExtensionRegistrations() { LdapExtendedResponse.Register(LdapKnownOids.Extensions.WhoAmI, typeof(LdapWhoAmIResponse)); }
/// <summary> /// Returns the effective rights of one object to a list of attributes of another object. /// To use this class, you must instantiate an object of this class and then /// call the extendedOperation method with this object as the required /// LdapExtendedOperation parameter. /// The returned LdapExtendedResponse object can then be converted to /// a GetEffectivePrivilegesListResponse object with the ExtendedResponseFactory class. /// The GetEffectivePrivilegesListResponse class contains methods for /// retrieving the list of effective rights. /// The getEffectivePrivilegesRequest extension uses the following OID: /// 2.16.840.1.113719.1.27.100.103 /// The requestValue has the following format: /// requestValue ::= /// dn LdapDN /// trusteeDN LdapDN /// SEQUENCE of attrNames LdapDN /// </summary> static GetEffectivePrivilegesListRequest() { LdapExtendedResponse.register(ReplicationConstants.GET_EFFECTIVE_LIST_PRIVILEGES_RES, typeof(GetEffectivePrivilegesListResponse)); }