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); } }
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); } }