[Mono-dev] P/Invoking libsmbclient from OSX

Alfred Hall ahall at ahall.org
Tue Dec 6 14:53:40 EST 2011


Good afternoon!

I have been trying to P/Invoke into libsmbclient on OSX 10.6 running
64 bit kernel. I compile the samba library myself (version 3.6.0) with
-m32 and managed to get a simple stub working in C/C++:

static void
auth_fn(const char *server, const char *share,
    char *workgroup, int wgmaxlen, char *username, int unmaxlen,
    char *password, int pwmaxlen)
{
}

smbc_init(auth_fn, 10);
smbc_opendir("smb://myuser:mypass@192.168.x.x/c$");

This works fine, then I created the P/Invokes:

        public static void SmbInit()
        {
            smbc_init(CallBackAuth, 0);
        }


        public static void CallBackAuth(IntPtr server,
                                        IntPtr share,
                                        IntPtr workgroup,
                                        int wgmaxlen,
                                        IntPtr username,
                                        int unmaxlen,
                                        IntPtr password,
                                        int pwmaxlen)
        {
            Console.WriteLine("MeeMa");
        }

        public delegate void SmbCGetAuthDataFn(IntPtr server,
                                               IntPtr share,
                                               IntPtr workgroup,
                                               int wgmaxlen,
                                               IntPtr username,
                                               int unmaxlen,
                                               IntPtr password,
                                               int pwmaxlen);


        [DllImport("libsmbclient")] extern internal static int
smbc_init(SmbCGetAuthDataFn callBackAuth, int debug);
        [DllImport("libsmbclient")] extern internal static int
smbc_opendir([In, MarshalAs(UnmanagedType.LPStr)]string durl);


Then simple calling into:
    SambaWrapper.SmbInit();
    SambaWrapper.smbc_opendir(@"smb://username:password@somehostname/someshare");

Then I got this beautiful stacktrace here:
http://paste.pocoo.org/show/517187/. I have made sure it's calling
into the libsmbclient library I compiled and not the one that comes
with OSX. I have also tried
it against the one that comes with OSX but that one just blows up with
a different trace.

I was debugging this with Alan on IRC today and we thought it might be
the delete being free'd but we tried adding a new smbc_init function
into smb that
looks like this:

void
myauth_fn(const char *server, const char *share,
        char *workgroup, int wgmaxlen, char *username, int unmaxlen,
       char *password, int pwmaxlen)
{
}

int
smbc_init2(int debug)
{
    smbc_init(myauth_fn, debug);
    smbc_opendir("smb://user:pass@192.168.212.133/c$");
}

And then tried to P/Invoke smbc_init2 only and P/Invoke:

[DllImport("libsmbclient", CallingConvention =
CallingConvention.Cdecl)] extern internal static int smbc_init2(int
debug);

When calling into smbc_init2() it blows up with exactly the same
stacktrace. I tried again a C++ program that calls into smbc2_init()
and it worked fine.

Anyone here got any idea how to proceed further with this?

Many thanks,
Alfred


More information about the Mono-devel-list mailing list