[PR PATCH] Correctly set cli->raw_status for libsmbclient in SMB2 code

github at samba.org github at samba.org
Sat Apr 9 12:37:48 UTC 2016


There is a new pull request by Xenopathic against master on the Samba Samba Github repository

https://github.com/Xenopathic/samba cli_smb2_status
https://github.com/samba-team/samba/pull/59

Correctly set cli->raw_status for libsmbclient in SMB2 code
The SMB2 file handling code wasn't correctly setting raw_status, which is used by libsmbclient to report file open errors etc.

The bug was originally found when attempting to do a `stat()` on a non-existing file behind a DFS link. Before this patch, the code returned was 22 (EINVAL), rather than the expected 2 (ENOENT), since the SMB result status wasn't set into the cli object. The easiest way to demonstrate this is to run the attached test program against a Samba server configured with DFS (for an easy test environment, run `docker pull xenopathic/samba-dfs && docker run -e SMB_USER=test -e SMB_PASSWORD=test --rm xenopathic/samba-dfs`). Make sure smb.conf contains `client max protocol = SMB2` or higher of course.

The fix for the actual noticed bug is the line added to `cli_smb2_create_fnum_recv()`, but I added similar lines to all other `cli_smb2_*_recv()` functions since the behaviour should be the same.

Test program:

```
#include <libsmbclient.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>

const char *guser = "test";
const char *gpass = "test";
const char *url = "smb://172.17.0.2/dfs/public/Test.pdf";

void authfn(SMBCCTX *ctx, const char *server, const char *share, char *wkgp, int wkgplen, char *user, int userlen, char *pass, int passlen) {
	strcpy(user, guser);
	strcpy(pass, gpass);
}

int main() {
	SMBCCTX *ctx = smbc_new_context();
	smbc_setFunctionAuthDataWithContext(ctx, authfn);
	ctx = smbc_init_context(ctx);

	smbc_stat_fn smbc_stat = smbc_getFunctionStat(ctx);

	struct stat statbuf;
	printf("smbc_stat(): %d\n", smbc_stat(ctx, url, &statbuf));
	printf("errno: %d\n", errno);

	smbc_free_context(ctx, 1);

	return 0;
}
```

Signed-off-by: Robin McCorkell <robin at mccorkell.me.uk>

A patch file from https://github.com/samba-team/samba/pull/59.patch is attached
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: github-pr-cli_smb2_status-59.patch
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20160409/8dd40128/github-pr-cli_smb2_status-59.patch>


More information about the samba-technical mailing list