Description of problem: When using this small program to use libsmbclient to open a samba share (also on F-16) requiring authentication, the authentication fails. When using the equivalent 'smbclient' command line, authentication succeeds. Version-Release number of selected component (if applicable): libsmbclient-3.6.1-77.fc16.x86_64 How reproducible: 100% Steps to Reproduce: 1.Set up a samba share on Fedora 16 like this: [aaron] comment = Aaron path = /var/spool/samba browseable = yes printable = yes guest ok = no user = tim 2.On a Fedora 16 client machine, attempt to connect using smbclient: smbclient -U tim //cyberelk/aaron 3.Now try using a libsmbclient program: #include <error.h> #include <errno.h> #include <string.h> #include <libsmbclient.h> static void auth_fn (SMBCCTX *ctx, const char *server, const char *share, char *workgroup, int wgmaxlen, char *username, int unmaxlen, char *password, int pwmaxlen) { strncpy (username, "tim", unmaxlen); strncpy (password, "password-goes-here", pwmaxlen); } int main () { SMBCFILE *file; smbc_open_fn ofn; smbc_close_fn cfn; SMBCCTX *ctx = smbc_new_context (); if (ctx == NULL) error (1, errno, "Failed to create context"); if (smbc_init_context (ctx) == NULL) error (2, errno, "Failed to init context"); smbc_setFunctionAuthDataWithContext (ctx, auth_fn); ofn = smbc_getFunctionOpen (ctx); file = (*ofn) (ctx, "smb://cyberelk/aaron", 0, 0); if (!file) error (1, errno, "Failed to open URI"); cfn = smbc_getFunctionClose (ctx); (*cfn) (ctx, file); smbc_free_context (ctx, 0); return 0; } Actual results: The libsmbclient program fails: ./test: Failed to open URI: Permission denied Expected results: Should succeed, just like the smbclient command line does.
Hi Tim, smb://cyberelk/aaron is a share and not a file. You have to use opendir() and not open() to open a share and normally you do a stat first if you don't know if it is a directory, share or file. Please read the API documentation and look at the examples.
Thanks. I now get a different error though (Invalid argument). (Note that it is a shared print queue and not a directory.) I would love a pointer to the API documentation and examples. All I saw in the manpage for libsmbclient was this: PROGRAMMERS GUIDE Watch this space for future updates.
less /usr/include/libsmbclient.h The header file is very well documented. The example are in the Samba source code in the directory: examples/libsmbclient/ To access printers you need to use the spoolss rpc protocol.
Please stop closing this bug -- I don't think you've actually tried it. Neither open() nor opendir() work correctly for this, and open() used to (e.g. for "writing a file" ie. submitting a job for printing). Is there some reason neither should work now? I don't see any documentation for spoolss in samba-doc. All I'm trying to do is determine whether the credentials are valid. Using list_print_jobs() gives no indication of whether the credentials are valid.
Tim, your auth_fn seem to be failing to fill in the workgroup, also can you please check the logs on the target server to see if it gives any clue about why the authentication is failing ? (you probably want to raise the log level)
It doesn't seem to make any difference whether the workgroup is filled in or not.
Created attachment 556317 [details] smbd-log.txt Here's the log from the server. The client said: ./test: Failed to open URI: Permission denied
Looking at the documentation it looks like the order should be ctx = smbc_new_context(); smbc_setFunctionAuthDataWithContext (ctx, auth_fn); smbc_setDebug(context, 10); // get some debugging ... smbc_init_context(ctx); ...
OK, thanks. Where did you find that in the documentation? All I could see was a statement that I read to mean the opposite: /**@ingroup misc * Initialize a SBMCCTX (a context). * * Must be called before using any SMBCCTX API function [...] In any case, I modified my test program (see attached) but it still fails, whereas "smbclient -W MYGROUP -U tim //cyberelk/aaron" works fine, copying and pasting the password from test.c to make sure it isn't just a typo or something.
Created attachment 557170 [details] test.c
Created attachment 557171 [details] output from test program (debugging set to 10)
Created attachment 557172 [details] smbd log file, log level set to 10
As you can see, you're successfully authenticated, but the server says permission denied. From the first post it looks like /aaron is a share and not a file. So open is the wrong function to call.