public static void Main(System.String[] args) { if (args.Length != 5) { System.Console.Error.WriteLine("Usage: mono ListReplicas <host Name> " + "<port number> <login dn> <password>" + "\n <server ND>"); System.Console.Error.WriteLine("Example: mono ListReplicas Acme.com 389 " + "\"cn=Admin,o=Acme\" secret" + "\n \"cn=myServer,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 serverDN = args[4]; 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"); LdapExtendedOperation request = new ListReplicasRequest(serverDN); LdapExtendedResponse response = ld.ExtendedOperation(request); if ((response.ResultCode == LdapException.SUCCESS) && (response is ListReplicasResponse)) { System.Console.Out.WriteLine("Replica List: "); System.String[] rList = ((ListReplicasResponse)response).ReplicaList; int len = rList.Length; for (int i = 0; i < len; i++) { System.Console.Out.WriteLine(rList[i]); } System.Console.Out.WriteLine("\nList replica request succeeded\n"); } else { System.Console.Out.WriteLine("List Replicas request failed." + response.ResultCode); // 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("\nError: " + e.ToString()); } }
/// <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; }
public static void Main(System.String[] args) { if (args.Length != 4) { System.Console.Error.WriteLine("Usage: mono GetBindDN " + "<host Name> <port number> <login dn>" + "\n <password>"); System.Console.Error.WriteLine("Example: mono GetBindDN Acme.com " + "389 \"cn=Admin,o=Acme\" secret"); 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]; 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"); LdapExtendedOperation request = new GetBindDNRequest(); LdapExtendedResponse response = ld.ExtendedOperation(request); if (((response.ResultCode) == LdapException.SUCCESS) && (response is GetBindDNResponse)) { System.Console.Out.WriteLine("You were logged in as: " + ((GetBindDNResponse)response).Identity); System.Console.Out.WriteLine("\nGetBindDN succeeded.\n"); } else { System.Console.Out.WriteLine("GetBindDN failed.\n"); 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("\nError: " + e.LdapErrorMessage); } }
static ExtensionRegistrations() { LdapExtendedResponse.Register(LdapKnownOids.Extensions.WhoAmI, typeof(LdapWhoAmIResponse)); }
private void notifyAllUnsolicitedListeners(RfcLdapMessage message) { // MISSING: If this is a shutdown notification from the server // set a flag in the Connection class so that we can throw an // appropriate LdapException to the application LdapMessage extendedLdapMessage = new LdapExtendedResponse(message); System.String notificationOID = ((LdapExtendedResponse) extendedLdapMessage).ID; if (notificationOID.Equals(LdapConnection.SERVER_SHUTDOWN_OID)) { unsolSvrShutDnNotification = true; } int numOfListeners = unsolicitedListeners.Count; // Cycle through all the listeners for (int i = 0; i < numOfListeners; i++) { // Get next listener LdapUnsolicitedNotificationListener listener = (LdapUnsolicitedNotificationListener) unsolicitedListeners[i]; // Create a new ExtendedResponse each time as we do not want each listener // to have its own copy of the message LdapExtendedResponse tempLdapMessage = new LdapExtendedResponse(message); // Spawn a new thread for each listener to go process the message // The reason we create a new thread rather than just call the // the messageReceived method directly is beacuse we do not know // what kind of processing the notification listener class will // do. We do not want our deamon thread to block waiting for // the notification listener method to return. UnsolicitedListenerThread u = new UnsolicitedListenerThread(this, listener, tempLdapMessage); u.Start(); } return ; }
/* package */ internal UnsolicitedListenerThread(Connection enclosingInstance, LdapUnsolicitedNotificationListener l, LdapExtendedResponse m) { InitBlock(enclosingInstance); this.listenerObj = l; this.unsolicitedMsg = m; return ; }
public static void Main(System.String[] args) { if (args.Length != 6) { System.Console.Error.WriteLine("Usage: mono GetReplicaInfo <host Name> " + "<port number> <login dn> <password>\n " + " <partition DN> <server ND>"); System.Console.Error.WriteLine("Example: mono GetReplicaInfo Acme.com 389 " + "\"cn=Admin,o=Acme\" secret\n " + "\"ou=Sales,o=Acme\" \"cn=myServer,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 partitionDN = args[4]; System.String serverDN = args[5]; int intInfo; System.String strInfo; 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"); LdapExtendedOperation request = new GetReplicaInfoRequest(serverDN, partitionDN); LdapExtendedResponse response = ld.ExtendedOperation(request); if ((response.ResultCode == LdapException.SUCCESS) && (response is GetReplicaInfoResponse)) { System.Console.Out.WriteLine("Repica Info:"); strInfo = ((GetReplicaInfoResponse)response).getpartitionDN(); System.Console.Out.WriteLine(" Partition DN: " + strInfo); intInfo = ((GetReplicaInfoResponse)response).getpartitionID(); System.Console.Out.WriteLine(" Partition ID: " + intInfo); intInfo = ((GetReplicaInfoResponse)response).getreplicaState(); System.Console.Out.WriteLine(" Replica state: " + intInfo); intInfo = ((GetReplicaInfoResponse)response).getmodificationTime(); System.Console.Out.WriteLine(" Modification Time: " + intInfo); intInfo = ((GetReplicaInfoResponse)response).getpurgeTime(); System.Console.Out.WriteLine(" Purge Time: " + intInfo); intInfo = ((GetReplicaInfoResponse)response).getlocalPartitionID(); System.Console.Out.WriteLine(" Local partition ID: " + intInfo); intInfo = ((GetReplicaInfoResponse)response).getreplicaType(); System.Console.Out.WriteLine(" Replica Type: " + intInfo); intInfo = ((GetReplicaInfoResponse)response).getflags(); System.Console.Out.WriteLine(" Flags: " + intInfo); System.Console.Out.WriteLine("\nget replica information succeeded\n"); } else { System.Console.Out.WriteLine("Could not get replica information.\n"); 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.ToString()); } }
public static void Main(System.String[] args) { if (args.Length != 5) { System.Console.Error.WriteLine("Usage: mono PartitionEntryCount <host Name> " + "<port number> <login dn> <password>" + "\n <partition dn>"); System.Console.Error.WriteLine("Example: mono PartitionEntryCount Acme.com 389 " + "\"cn=Admin,o=Acme\" secret" + "\n \"ou=Sales,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 partitionDN = args[4]; int count = 0; 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"); LdapExtendedOperation request = new PartitionEntryCountRequest(partitionDN); LdapExtendedResponse response = ld.ExtendedOperation(request); if ((response.ResultCode == LdapException.SUCCESS) && (response is PartitionEntryCountResponse)) { count = ((PartitionEntryCountResponse)response).Count; System.Console.Out.WriteLine("\n Entry count of partition " + partitionDN + " is: " + count); System.Console.Out.WriteLine("\nPartitionEntryCount succeeded\n"); } else { System.Console.Out.WriteLine("\nPartitionEntryCount 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); } catch (Exception e) { Console.WriteLine("Error:" + e.Message); return; } }