Exemplo n.º 1
0
        private Native.LdapSaslDefaults GetSaslDefaults(SafeHandle ld)
        {
            var defaults = new Native.LdapSaslDefaults {
                mech = Native.LdapAuthMechanism.GSSAPI
            };

            ThrowIfError(ldap_get_option(ld, (int)Native.LdapOption.LDAP_OPT_X_SASL_REALM, ref defaults.realm), nameof(ldap_get_option));
            ThrowIfError(ldap_get_option(ld, (int)Native.LdapOption.LDAP_OPT_X_SASL_AUTHCID, ref defaults.authcid), nameof(ldap_get_option));
            ThrowIfError(ldap_get_option(ld, (int)Native.LdapOption.LDAP_OPT_X_SASL_AUTHZID, ref defaults.authzid), nameof(ldap_get_option));
            return(defaults);
        }
Exemplo n.º 2
0
 private Native.LdapSaslDefaults GetSaslDefaults(SafeHandle ld, string mech)
 {
     var defaults = new Native.LdapSaslDefaults {mech = mech};
     ThrowIfError(ldap_get_option(ld, (int) Native.LdapOption.LDAP_OPT_X_SASL_REALM, ref defaults.realm),
         nameof(ldap_get_option));
     ThrowIfError(ldap_get_option(ld, (int) Native.LdapOption.LDAP_OPT_X_SASL_AUTHCID, ref defaults.authcid),
         nameof(ldap_get_option));
     ThrowIfError(ldap_get_option(ld, (int) Native.LdapOption.LDAP_OPT_X_SASL_AUTHZID, ref defaults.authzid),
         nameof(ldap_get_option));
     return defaults;
 }
Exemplo n.º 3
0
        internal static IntPtr GetSaslCredentials(LdapCredential ldapCredential, Native.LdapSaslDefaults saslDefaults)
        {
            if (!string.IsNullOrWhiteSpace(ldapCredential?.UserName))
            {
                saslDefaults.authcid = ldapCredential.UserName;
            }

            if (!string.IsNullOrWhiteSpace(ldapCredential?.Password))
            {
                saslDefaults.passwd = ldapCredential.Password;
            }

            if (!string.IsNullOrWhiteSpace(ldapCredential?.AuthorizationId))
            {
                saslDefaults.authzid = ldapCredential?.AuthorizationId;
            }

            var ptr = Marshal.AllocHGlobal(Marshal.SizeOf(saslDefaults));

            Marshal.StructureToPtr(saslDefaults, ptr, false);
            return(ptr);
        }
Exemplo n.º 4
0
        private static int SaslInteraction(uint flags, Native.SaslInteract interact, Native.LdapSaslDefaults defaults)
        {
            var noecho = false;

            switch (interact.id)
            {
            case (int)Native.SaslCb.SASL_CB_GETREALM:
                if (!defaults.IsEmpty())
                {
                    interact.defresult = defaults.realm;
                }

                break;

            case (int)Native.SaslCb.SASL_CB_AUTHNAME:
                if (!defaults.IsEmpty())
                {
                    interact.defresult = defaults.authcid;
                }

                break;

            case (int)Native.SaslCb.SASL_CB_PASS:
                if (!defaults.IsEmpty())
                {
                    interact.defresult = defaults.passwd;
                }

                break;

            case (int)Native.SaslCb.SASL_CB_USER:
                if (!defaults.IsEmpty())
                {
                    interact.defresult = defaults.authzid;
                }

                break;

            case (int)Native.SaslCb.SASL_CB_NOECHOPROMPT:
                noecho = true;
                break;

            case (int)Native.SaslCb.SASL_CB_ECHOPROMPT:
                break;
            }

            if (flags != (uint)Native.LdapInteractionFlags.LDAP_SASL_INTERACTIVE &&
                (interact.id == (int)Native.SaslCb.SASL_CB_USER || !string.IsNullOrEmpty(interact.defresult)))
            {
                interact.result = Encoder.Instance.StringToPtr(interact.defresult);
                interact.len    = interact.defresult != null ? (uint)interact.defresult.Length : 0;
                return((int)Native.ResultCode.Success);
            }

            if (flags == (int)Native.LdapInteractionFlags.LDAP_SASL_QUIET)
            {
                return((int)Native.ResultCode.Other);
            }

            if (noecho)
            {
                interact.result = Encoder.Instance.StringToPtr(interact.prompt);
                interact.len    = (ushort)interact.prompt.Length;
            }
            else
            {
                return((int)Native.ResultCode.LDAP_NOT_SUPPORTED);
            }

            if (interact.len > 0)
            {
                /*
                 *
                 */
            }
            else
            {
                interact.result = Encoder.Instance.StringToPtr(interact.defresult);
                interact.len    = interact.defresult != null ? (ushort)interact.defresult.Length : (ushort)0;
            }

            return((int)Native.ResultCode.Success);
        }