Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anon functions aren't accepted as AuthCallback #3

Open
mrvik opened this issue Jan 7, 2020 · 2 comments
Open

Anon functions aren't accepted as AuthCallback #3

mrvik opened this issue Jan 7, 2020 · 2 comments

Comments

@mrvik
Copy link

mrvik commented Jan 7, 2020

Hey, after writing some code, seems like there is a problem on the SetAuthCallback function.

Stack trace:

(I) smb-web-client Jan  7 19:31:05 Got a request type 1: {Type:1 Username:Asd Password:sdfsdfsdf}
INFO: Current debug levels:
  all: 99
  tdb: 99
  printdrivers: 99
  lanman: 99
  smb: 99
  rpc_parse: 99
  rpc_srv: 99
  rpc_cli: 99
  passdb: 99
  sam: 99
  auth: 99
  winbind: 99
  vfs: 99
  idmap: 99
  quota: 99
  acls: 99
  locking: 99
  msdfs: 99
  dmapi: 99
  registry: 99
  scavenger: 99
  dns: 99
  ldb: 99
  tevent: 99
  auth_audit: 99
  auth_json_audit: 99
  kerberos: 99
  drs_repl: 99
  smb2: 99
  smb2_credits: 99
  dsdb_audit: 99
  dsdb_json_audit: 99
  dsdb_password_audit: 99
  dsdb_password_json_audit: 99
  dsdb_transaction_audit: 99
  dsdb_transaction_json_audit: 99
  dsdb_group_audit: 99
  dsdb_group_json_audit: 99
panic: runtime error: cgo argument has Go pointer to Go pointer

goroutine 10 [running]:
github.com/mvo5/libsmbclient-go.(*Client).SetAuthCallback.func1(0xc000252120, 0xc000242040)
        /home/mrvik/go/pkg/mod/github.com/mvo5/[email protected]/libsmbclient.go:117 +0xfd
github.com/mvo5/libsmbclient-go.(*Client).SetAuthCallback(0xc000252120, 0xc0000dc420)
        /home/mrvik/go/pkg/mod/github.com/mvo5/[email protected]/libsmbclient.go:117 +0xf1
gitlab.com/mrvik/smb-web-client/sambaManager.getClient(0xc0000de130, 0x3, 0xc0000de133, 0x9, 0x857e80)
        /home/mrvik/git/rpi/smb-web-client/sambaManager/sambaExec.go:11 +0xf4
gitlab.com/mrvik/smb-web-client/sambaManager.TryAuthenticate(0x8d24ce, 0x9, 0xc0000de130, 0x3, 0xc0000de133, 0x9, 0x954100, 0x0, 0x0)
        /home/mrvik/git/rpi/smb-web-client/sambaManager/sambaExec.go:16 +0x8b
gitlab.com/mrvik/smb-web-client/sambaManager.handleRequest(0xc0002520e0)
        /home/mrvik/git/rpi/smb-web-client/sambaManager/sambaManager.go:67 +0x2f8
gitlab.com/mrvik/smb-web-client/sambaManager.Init.func1(0x959e00, 0xc00006c3c0, 0xc00006e360, 0x95bf40, 0xc00006c300)
        /home/mrvik/git/rpi/smb-web-client/sambaManager/sambaManager.go:31 +0x96
created by gitlab.com/mrvik/smb-web-client/sambaManager.Init
        /home/mrvik/git/rpi/smb-web-client/sambaManager/sambaManager.go:23 +0x13a
exit status 2

Go code:

package sambaManager;

import(
    "fmt"
    "github.com/mvo5/libsmbclient-go"
)

func getClient(user, password string) *libsmbclient.Client{
    client:=libsmbclient.New();
    client.SetDebug(99);
    client.SetAuthCallback(func(_,_ string)(string,string,string){return "", user, password});
    return client;
}

//Try to authenticate a user against the SMB server
func TryAuthenticate(host, user, password string)(ok bool, err error){
    client:=getClient(user, password);
    defer client.Close();
    userDir:=fmt.Sprintf("smb://%s/%s/", host, user); //Test for user home dir (should have the homes section enabled)
    _, err=client.Opendir(userDir);
    ok=err==nil;
    return;
}
@mvo5
Copy link
Owner

mvo5 commented Jan 7, 2020

Hey, thanks for your bugreport. I have an example smb explorer app in the tree, I moved it into 'cmd/smb/main.go` now. Could you please check if that also crashes in the same way? Please check https://github.com/mvo5/libsmbclient-go/blob/master/cmd/smb/main.go#L54 for an example usage. maybe the issue is that you use an anonymous func(). But it's ~5y since I wrote this code so I'm a bit rusty :) I kind of abandoned it after I found that libsmbclient is not thread safe at all.

Fwiw - with the example in main.go I don't get crashes.

@mrvik
Copy link
Author

mrvik commented Jan 7, 2020

Fwiw - with the example in main.go I don't get crashes.

Yes, this annoyed me at first, I tried to copy your fn from https://github.com/mvo5/libsmbclient-go/blob/master/cmd/smb/main.go#L54 and pass it instead of my anon function and it worked.

Seems like anon functions aren't working (not related to GC nor goroutine thread locking as far as I tested).
The real issue seems anon functions definitively, I'm updating the title

Thanks for your fast reply.

@mrvik mrvik changed the title cgo argument has Go Pointer to Go Pointer Anon functions aren't accepted as AuthCallback Jan 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants