Created
February 15, 2018 21:28
-
-
Save flamencist/30f0cd3e6c4f140ff8f3b5501bf3b9a5 to your computer and use it in GitHub Desktop.
linux_openldap_pinvoke
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.InteropServices; | |
namespace KerberosAuth | |
{ | |
public static class NativeMethods | |
{ | |
[DllImport("libldap-2.4.so.2")] | |
public static extern int ldap_init(string host, int port); | |
[DllImport("libldap-2.4.so.2")] | |
public static extern int ldap_simple_bind_s(int ld, string who, string cred); | |
[DllImport("libldap-2.4.so.2")] | |
public static extern int ldap_set_option(int ld, int option, [In] ref int invalue ); | |
[DllImport("libldap-2.4.so.2")] | |
public static extern int ldap_unbind_s(int ld); | |
// struct ldapmsg { | |
// ber_int_t lm_msgid; /* the message id */ | |
// ber_tag_t lm_msgtype; /* the message type */ | |
// BerElement *lm_ber; /* the ber encoded message contents */ | |
// struct ldapmsg *lm_chain; /* for search - next msg in the resp */ | |
// struct ldapmsg *lm_chain_tail; | |
// struct ldapmsg *lm_next; /* next response */ | |
// time_t lm_time; /* used to maintain cache */ | |
// }; | |
//=========================================== | |
// /* Data encoded in ASN.1 BER format */ | |
// struct berelement { | |
// struct lber_options ber_opts; | |
//#define ber_valid ber_opts.lbo_valid | |
//#define ber_options ber_opts.lbo_options | |
//#define ber_debug ber_opts.lbo_debug | |
// | |
// /* | |
// * The members below, when not NULL/LBER_DEFAULT/etc, are: | |
// * ber_buf Data buffer. Other pointers normally point into it. | |
// * ber_rwptr Read/write cursor for Sockbuf I/O. | |
// * ber_memctx Context passed to ber_memalloc() & co. | |
// * When decoding data (reading it from the BerElement): | |
// * ber_end End of BER data. | |
// * ber_ptr Read cursor, except for 1st octet of tags. | |
// * ber_tag 1st octet of next tag, saved from *ber_ptr when | |
// * ber_ptr may be pointing at a tag and is >ber_buf. | |
// * The octet *ber_ptr itself may get overwritten with | |
// * a \0, to terminate the preceding element. | |
// * When encoding data (writing it to the BerElement): | |
// * ber_end End of allocated buffer - 1 (allowing a final \0). | |
// * ber_ptr Last complete BER element (normally write cursor). | |
// * ber_sos_ptr NULL or write cursor for incomplete sequence or set. | |
// * ber_sos_inner offset(seq/set length octets) if ber_sos_ptr!=NULL. | |
// * ber_tag Default tag for next ber_printf() element. | |
// * ber_usertag Boolean set by ber_printf "!" if it sets ber_tag. | |
// * ber_len Reused for ber_sos_inner. | |
// * When output to a Sockbuf: | |
// * ber_ptr End of encoded data to write. | |
// * When input from a Sockbuf: | |
// * See ber_get_next(). | |
// */ | |
// | |
// /* Do not change the order of these 3 fields! see ber_get_next */ | |
// ber_tag_t ber_tag; | |
// ber_len_t ber_len; | |
// ber_tag_t ber_usertag; | |
// | |
// char *ber_buf; | |
// char *ber_ptr; | |
// char *ber_end; | |
// | |
// char *ber_sos_ptr; | |
//# define ber_sos_inner ber_len /* reused for binary compat */ | |
// | |
// char *ber_rwptr; | |
// void *ber_memctx; | |
// }; | |
[StructLayout(LayoutKind.Sequential)] | |
public struct BerElement | |
{ | |
public ulong ber_tag; | |
public int ber_len; | |
public ulong ber_usertag; | |
public string ber_buf; | |
public string ber_ptr; | |
public string ber_end; | |
public string ber_sos_ptr; | |
public string ber_rwptr; | |
public IntPtr ber_memctx; | |
} | |
[StructLayout(LayoutKind.Sequential)] | |
public struct LDAPMessage | |
{ | |
public int lm_msgid; | |
public ulong lm_mstype; | |
public IntPtr lm_ber; | |
public IntPtr lm_chain; | |
public IntPtr lm_chain_tail; | |
public IntPtr lm_next; | |
public int lm_time; | |
} | |
[DllImport("libldap-2.4.so.2")] | |
public static extern int ldap_search_s(int ld, string @base, int scope, string filter, string[] attrs, int attrsonly, IntPtr message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment