Bug 767673 - Authentication issue with libsmbclient
Summary: Authentication issue with libsmbclient
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: samba
Version: 16
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Guenther Deschner
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2011-12-14 16:22 UTC by Tim Waugh
Modified: 2012-10-26 16:16 UTC (History)
4 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2012-10-26 16:16:02 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)
smbd-log.txt (28.78 KB, text/plain)
2012-01-19 16:06 UTC, Tim Waugh
no flags Details
test.c (1.03 KB, text/plain)
2012-01-24 09:42 UTC, Tim Waugh
no flags Details
output from test program (debugging set to 10) (13.81 KB, text/plain)
2012-01-24 09:43 UTC, Tim Waugh
no flags Details
smbd log file, log level set to 10 (28.78 KB, text/plain)
2012-01-24 09:43 UTC, Tim Waugh
no flags Details

Description Tim Waugh 2011-12-14 16:22:30 UTC
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.

Comment 1 Andreas Schneider 2011-12-15 14:44:12 UTC
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.

Comment 2 Tim Waugh 2011-12-16 13:15:08 UTC
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.

Comment 3 Andreas Schneider 2011-12-16 14:51:50 UTC
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.

Comment 4 Tim Waugh 2011-12-16 17:18:29 UTC
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.

Comment 5 Simo Sorce 2011-12-17 21:59:13 UTC
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)

Comment 6 Tim Waugh 2012-01-19 16:05:56 UTC
It doesn't seem to make any difference whether the workgroup is filled in or not.

Comment 7 Tim Waugh 2012-01-19 16:06:43 UTC
Created attachment 556317 [details]
smbd-log.txt

Here's the log from the server.  The client said:

./test: Failed to open URI: Permission denied

Comment 8 Andreas Schneider 2012-01-23 18:56:19 UTC
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);

...

Comment 9 Tim Waugh 2012-01-24 09:42:06 UTC
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.

Comment 10 Tim Waugh 2012-01-24 09:42:28 UTC
Created attachment 557170 [details]
test.c

Comment 11 Tim Waugh 2012-01-24 09:43:15 UTC
Created attachment 557171 [details]
output from test program (debugging set to 10)

Comment 12 Tim Waugh 2012-01-24 09:43:54 UTC
Created attachment 557172 [details]
smbd log file, log level set to 10

Comment 13 Andreas Schneider 2012-01-26 11:36:15 UTC
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.


Note You need to log in before you can comment on or make changes to this bug.