ExtendedOperation() public method

Provides a synchronous means to access extended, non-mandatory operations offered by a particular Ldapv3 compliant server.
LdapException A general exception which includes an error /// message and an Ldap error code. ///
public ExtendedOperation ( LdapExtendedOperation op ) : LdapExtendedResponse
op LdapExtendedOperation The object which contains (1) an identifier of an extended /// operation which should be recognized by the particular Ldap /// server this client is connected to and (2) /// an operation-specific sequence of octet strings /// or BER-encoded values. /// ///
return LdapExtendedResponse
Exemplo n.º 1
0
    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());
        }
    }
    /**
     *
     * 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;
    }
Exemplo n.º 3
0
    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());
        }
    }
Exemplo n.º 4
0
    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);
        }
    }
Exemplo n.º 5
0
    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);
        }
    }
Exemplo n.º 6
0
        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;
            }
        }
Exemplo n.º 7
0
        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;
            }
        }
Exemplo n.º 8
0
    public static void Main(String[] args)
    {
        if (args.Length != 3)
        {
            Console.WriteLine(
                "Usage:   mono EdirEventSample <host name> <login dn>"
                + " <password> ");
            Console.WriteLine(
                "Example: mono EdirEventSample Acme.com \"cn=admin,o=Acme\""
                + " secret ");
            Environment.Exit(0);
        }

        int ldapPort = LdapConnection.DEFAULT_PORT;
        int ldapVersion = LdapConnection.Ldap_V3;
        String ldapHost = args[0];
        String loginDN = args[1];
        String password = args[2];

        LdapResponseQueue queue = null;

        LdapConnection lc = new LdapConnection();

        try
        {
            // connect to the server
            lc.Connect(ldapHost, ldapPort);

            // authenticate to the server
            lc.Bind(ldapVersion, loginDN, password);

            //Create an Array of EdirEventSpecifier
            EdirEventSpecifier[] specifier = new EdirEventSpecifier[1];

            //Register for all Add Value events.
            specifier[0] =
                new EdirEventSpecifier(EdirEventType.EVT_CREATE_ENTRY,
                //Generate an Value Event of Type Add Value
                EdirEventResultType.EVT_STATUS_ALL
                //Generate Event for all status
                );

            //Create an MonitorEventRequest using the specifiers.
            MonitorEventRequest requestoperation =
                new MonitorEventRequest(specifier);

            //Send the request to server and get the response queue.
            queue = lc.ExtendedOperation(requestoperation, null, null);

        }

        catch (LdapException e)
        {
            Console.WriteLine("Error: " + e.ToString());
            try
            {
                lc.Disconnect();
            }
            catch (LdapException e2)
            {
                Console.WriteLine("Error: " + e2.ToString());
            }
            Environment.Exit(1);
        }

        catch (Exception e)
        {
            Console.WriteLine("Error: " + e.ToString());
        }

        Console.WriteLine("Monitoring the events for {0} minutes..", TIME_OUT_IN_MINUTES );
        Console.WriteLine();

        //Set the timeout value
        timeOut= DateTime.Now.AddMinutes(TIME_OUT_IN_MINUTES);

        try
        {
            //Monitor till the timeout happens
            while (DateTime.Now.CompareTo(timeOut) < 0)
            {
                if (!checkForAChange(queue))
                    break;
                System.Threading.Thread.Sleep(10);
            }
        }

        catch (System.IO.IOException e)
        {
            Console.WriteLine(e.Message);
        }

        catch (System.Threading.ThreadInterruptedException e)
        {
            Console.WriteLine(e.Message);
        }

        //disconnect from the server before exiting
        try
        {
            lc.Abandon(queue); //abandon the search
            lc.Disconnect();
        }

        catch (LdapException e)
        {
            Console.WriteLine();
            Console.WriteLine("Error: " + e.ToString());
        }

        Environment.Exit(0);
    }
Exemplo n.º 9
0
    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 != 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);
            }
        }
    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;
        }
    }
Exemplo n.º 13
0
    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());
        }
    }
Exemplo n.º 14
0
    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;
        }
    }
Exemplo n.º 15
0
    /**
     *
     * 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());
        }
    }