Git Product home page Git Product logo

libsmb2's Issues

Handle unknown ACEs better

We currently drop any ACEs we do not understand.
We should probably keep these as-is as blobs so that we will be able to
fetch/mutate-some-aces/store without loss of ACEs.

Add backup intent support

Currently there is no support to add backup intent flag in SMB2 CREATE request.

Wonder what is the right way to do this? Add an extra API to set some flag in smb2_context?

gss-ntlmssp dependency

Hi

Documentation states this project dependents on gss-ntlmssp but I could not find how and where. Would you mind clarifying if this library is dependent on that or not?

Support server:port syntax?

The port to use is hardwired in socket.cc to be CIFS_PORT (445).
In order to support a server accessed through an SSH tunnel, I'd like
to be able to specify a port for the SMB server.

Would you be willing to accept a code change to accept an optional :port suffix
after the host name?

smb2_lseek behaviour is different from nfs_lseek

I'm not sure if this was intended but it seems that libsmb2 is missing a current_offset argument. This is used by Kodi to get the current position. see, https://github.com/xbmc/xbmc/blob/master/xbmc/filesystem/NFSFile.cpp#L519-L534

libsmb2

int smb2_lseek(struct smb2_context *smb2, struct smb2fh *fh,
               int64_t offset, int whence);

lbnfs

EXTERN int nfs_lseek(struct nfs_context *nfs, struct nfsfh *nfsfh,
                     int64_t offset, int whence, uint64_t *current_offset);

Releasing on the iOS App Store

Greetings Ronnie!

I randomly found this library from discussions on the libdsm repo about SMB client libraries that support version 2 and up. This library looks absolutely fantastic!

I've been working on an app for iPhone and iPad and one of my dream features is adding SMB2 support so I can easily access files on my NAS over WiFi directly from the device. I wrote a wrapper around libdsm so it could be built and deployed on iOS devices, however libdsm only supports SMB1 at the moment, and given how different the two protocol standards are, I'm not sure if libdsm will ever get SMB2 support.

I'm curious to try building and deploying libsmb2 for iOS, but before that, I thought I'd better ask you.

While being able to dynamically link frameworks on iOS solves most of the conditions of the LGPL, the fact that customers can't easily replace the dynamic framework on their devices themselves means shipping LGPL software on the iOS App Store is still somewhat ambiguous. From what I've seen, it usually depends on the original author's views of the LGPL.

What would your thoughts be on this? Would it be acceptable to use this library in shipping iOS software? Or would you prefer not?

Thanks for your time!

SMB3 fails to sign when path is delimited by slash

HI,

When I try to connect to my macOS smb server which is SMB 3.02, All / delimiters in path must be replaced by \ otherwise the operation will fail with Failure to add signature message.

EDIT: This issue is limited to macOS 10.13.4 High Sierra. Windows 10 and Samba on Linux has no issue with dialect 3.02 signing.

missing smb2_truncate

libnfs has nfs_truncate

EXTERN int nfs_truncate(struct nfs_context *nfs, const char *path,
                        uint64_t length);

A similar function seems to be missing from libsmb2

Error in write/pwrite function

Hi,

I'm developing a wrapper Swift framework for libsmb2. I successfully have run it on my iOS device but when I try write a file, after opening file with O_WRONLY | O_CREAT | O_TRUNC flag. Either using smb2_write() or smb2_pwrite() I get result -1. I also tried other flags combination for writing.

I've tried to use async version, thus I reimplemented wait_for_reply in Swift. It worked without issue for smb2_rename_async() (as I didn't find sync version).

In async version, smb2_service() returns negative value and smb2_get_error() prints POLLHUP error.

I reiterate this issue is only exist in writing functions and other functions work without any issue.

Thanks for this life saving library by the way. I also wrote building scripts and I can publish framework in Github after this issue got resolved.

EDIT: There is some minor issues in your code in apple platform which I will create a PR later to address them.

EDIT 2: An empty file is created in server every time I execute, if the file does not exist.

smb2_service() failure and pending callbacks

When smb2_service() encounters error (say socket error), does libsmb2 issues callbacks to the pending async calls? It looks the code does not do so (smb2_service() simply returns error).

In such case, how would caller do clean up work? Say caller has an open file handle. It can call smb2_destroy_context() to destroy the smb2_context but what about the open file handle? How to free the handle? Should it call smb2_close? But the context is already in bad state. And there is no API to directly close the file handle. This seems like a potential source of memory leak.

statvfs() issues

Hi,

Thanks for fast implementation of statvfs(), Here are two issues I found

  1. An strange behavior in linux I found when I implemented apple/swift-corelibs-foundation#1250 was statvfs() populates f_frsize in Linux with correct block size, whereas old-school statfs() (in Darwin) function populates f_bsize! I suggest you to fill both with same value for the sake of compatibility.

  2. f_blocks and a_bavail are set to UINT64_MAX when server doesn't command. Is this expected behavior?

[Enhancement] Implementing smb_cmd_fsctl

Hi

Current implementation does not support FSCTL commands. We need it for two main purposes:

  1. Enumerating shares: while I successfully implemented listing shares using file interface, official way to support this capability is to use FSCTL_PIPE_TRANSCEIVE (0x0011c017) command.

    • Listing shares on macOS 10.13 SMB3 server throws Failure to add signature error, similiar to #46.
  2. Server-side copy: Currently we have to download then upload data to copy a file. With FSCTL_SRV_COPYCHUNK & FSCTL_SRV_COPYCHUNK_WRITE commands we can duplicate folder/file on server without roundtrip see details.

Guest access, failure to connect

Has Guest access been verified for smb2/3 (built with --without-libkrb5) ?

Seeing failure to connect and just starting to dig into it.

Multicast DNS name resolving doesn't work

The same url (e.g. smb://timecapsule/) doesn't work in libsmb2 while it works correctly in Samba library when using mDNS. In libsmb2 only smb://timecapsule.local/ URL is working, which results in problems with porting from Samba to libsmb2.

why not support number of links

in "libsmb2.c" I can see we set the "ent->dirent.st.smb2_nlink = 0;", is this a limitation? I though this might help to get child file count of a directory, but now I can only get a "0"

smb2_cmd_ioctl_async reply corrupted

I implemented server-side copy using ioctl command. Occasionally smb2_ioctl_reply returned by async handler is corrupted and output_count has weird values like 2939741608. In this condition, when I try to free output memory using smb2_free_data(), I get SIGABRT.

This issue always happens when I try to copy two files simultaneously using same smb2_context.

Unfortunately I can't ignore reply otherwise I will have memory leaks.

Furthermore, reply's ctl_code always mismatch with request's one.

Error is: malloc: *** error for object 0x1c81575f8: pointer being freed was not allocated

[Request] Timeout functionality

Hi,

I am trying to add a timeout for one of the library functions in libsmb2 but have been unable to find an implementation within the library. I am also using the libnfs library and found a way to timeout a call here. Does some sort of timeout system exist within libsmb2 and if so, does it follow a similar pattern?

Thanks!

fatal error: smb2-errors.h: No such file

I'm having an issue with this include

/usr/local/include/smb2/smb2.h:22:25: fatal error: smb2-errors.h: No such file or directory
compilation terminated.
In file included from /home/lukas/Documents/git/vfs.smb/src/SMBConnection.cpp:25:0:
/usr/local/include/smb2/smb2.h:22:25: fatal error: smb2-errors.h: No such file or directory
compilation terminated.

if I change it to

#include <smb2/smb2-errors.h>

or

#include "smb2-errors.h"

it works

smb2_share_enum_async (NetShareEnumAll) fails on macOS SMB Server (10.13.6)

smb2_share_enum_async returns Error -22 (Invalid argument) against an macOS SMB Server (10.13.6). It works fine with any other samba server I tested. All other operations (connect, dirlisting) work fine with the macOS SMB server. After some further investigation this issue seems to be related by dcerpc decoding not working for dcerpc responses delivered in multiple fragments.

  1. My samba test server returns the dceprc response in one fragement => decoding works fine
  2. The macOS SMB Server returns the dcerpc response in multiple fragments with a maximum fragment size of 256 bytes => decoding fails

I have not a full overview how libsmb2 internals work yet, but I assume the fragments (if they are multiple) need to be assembled before decoding, which is currently missing or buggy.
I attached a Wireshark trace for the NetShareEnumAll session against the macOS SMB Server
NetShareEnumAll_macOSHighSierra.pcapng.zip

If I can assist any further, please let me know.

Listing Shares

Hi,

How can we list available shares on a server?

Thanks a lot

Double free on dcerpc_call_cb and dcerpc_decode_pdu

Greetings,
There are some use after free / double frees in the libsmb2 library.
I have forgotten some of them, but this one has been the primary one to cause me the trouble:

dcerpc.c --

dcerpc_decode_pdu:
default: smb2_set_error(ctx->smb2, "DCERPC No decoder for PDU type %d", pdu->hdr.PTYPE); dcerpc_free_pdu(ctx, pdu); // pdu is freed once here, and returns -1 return -1; }

dcerpc_call_cb:

ret = dcerpc_decode_pdu(dce, pdu, &iov);
        if (ret < 0) { // if ret == -1
                pdu->cb(dce, -EINVAL, NULL, pdu->cb_data);
                smb2_free_data(dce->smb2, rep->output);
                dcerpc_free_pdu(dce, pdu); // pdu is freed twice
                return;
        }
        smb2_free_data(dce->smb2, rep->output);

        if (pdu->hdr.PTYPE != PDU_TYPE_RESPONSE) {
                smb2_set_error(dce->smb2, "DCERPC response was not a RESPONSE");
                pdu->cb(dce, -EINVAL, NULL, pdu->cb_data);
                dcerpc_free_pdu(dce, pdu);
                return;
        }

smb2_parse_url parse has bug when no domain.

Smb2_parse_url parse has a bug, when there is no domain in url bug path has ';' or '@',

"smb2_parse_url" should first extract the smb:// to the path between smb://domain;user:ip/path, and then analyze the domain and user pwd and ip.

struct smb2_url *smb2_parse_url(struct smb2_context *smb2, const char *url)
{
struct smb2_url *u;
char *ptr, *tmp, str[MAX_URL_SIZE];
char *args;

    if (strncmp(url, "smb://", 6)) {
            smb2_set_error(smb2, "URL does not start with 'smb://'");
            return NULL;
    }
    if (strlen(url + 6) >= MAX_URL_SIZE) {
            smb2_set_error(smb2, "URL is too long");
            return NULL;
    }
strncpy(str, url + 6, MAX_URL_SIZE);

    args = strchr(str, '?');
    if (args) {
            *(args++) = '\0';
            if (smb2_parse_args(smb2, args) != 0) {
                    return NULL;
            }
    }

    u = malloc(sizeof(struct smb2_url));
    if (u == NULL) {
            smb2_set_error(smb2, "Failed to allocate smb2_url");
            return NULL;
    }
    memset(u, 0, sizeof(struct smb2_url));

    ptr = str;

    /* domain */
    if ((tmp = strchr(ptr, ';')) != NULL) {  //this will be bug when path is smb://192.168.1.200/path/1;abc.txt
            *(tmp++) = '\0';
            u->domain = strdup(ptr);
            ptr = tmp;
    }
    /* user */
    if ((tmp = strchr(ptr, '@')) != NULL) { // the same bug like above.
            *(tmp++) = '\0';
            u->user = strdup(ptr);
            ptr = tmp;
}
    /* server */
    if ((tmp = strchr(ptr, '/')) != NULL) {
            *(tmp++) = '\0';
            u->server = strdup(ptr);
            ptr = tmp;
    }

    /* Do we just have a share or do we have both a share and an object */
    tmp = strchr(ptr, '/');
    
    /* We only have a share */
    if (tmp == NULL) {
            u->share = strdup(ptr);
            return u;
    }

    /* we have both share and object path */
    *(tmp++) = '\0';
    u->share = strdup(ptr);
    u->path = strdup(tmp);

    return u;

}

smb2_rename_async failed

this works:

smb2_rename_async(smb2, "abc.txt.tmp", "abc.txt", smb2_rename_cb, NULL); // succeed

but the following failed:

// failed with status == -5 in smb2_rename_cb
smb2_rename_async(smb2, "123/abc.txt.tmp", "123/abc.txt", smb2_rename_cb, NULL);

what does the error -5 mean ?

Query server for shares.

Hi,

can I use libsmb2 to query a server for the different shares (and other services).
I've tried to use smb2_connect_async to connect to a server and then call smb2_opendir_async with directory "/", but it hangs. (I've modified the example smb2_ls_async).

Thanks in advance,
Stef

Porting to ESP32

Hi,
I'm trying to port libsmb2 to an ESP32. Unfortunately the ESP32 does not support poll() at this time. Although configure checks for HAVE_POLL_H, libsmb2 does not compile without that header file. I think it should be possible to revert to a strictly synchronous API in that case. Any guidance on how to go about that? Simply marking the socket as blocking and doing a no-op in wait_for_reply() doesn't work.
TIA,
AP

Problems using examples

I'm trying to use the examples to make sure the code works properly but I can't seem to connect to my share

$ ./smb2-ls-sync smb://192.168.1.106/concerts/
smb2_connect_share failed. gss_init_sec_context: (Unspecified GSS failure.  Minor code may provide more information,  SPNEGO cannot find mechanisms to negotiate)

I'm just trying to use anonymous guest but I'm not sure about the url
I've tried a bunch of various urls with no success

smb://Guest:@192.168.1.106/concerts/
smb://guest:@192.168.1.106/concerts/
smb://192.168.1.106/concerts/

Any ideas about what I'm doing wrong would be great

Release request/process

What is your process/policy for cutting a new release of libsmb2?
Would you accept a request to cut a minor release soon?
I'm interested in getting recent changes into a release so that they can
be picked up by videolan.
Thanks for your help!

Is libsmb2 thread safe?

Hi,

Is it safe to use smb2_context in multiple concurrent threads in order to execute file operation functions? What about smb2fh and smb2dir?

In other words, is it safe to call 2 different functions on same context from two different threads?

Writes truncate files

It looks like we have the following code for file open:

    /* Create disposition */
    if (flags & O_CREAT) {
            if (flags & O_EXCL) {
                    create_disposition = SMB2_FILE_CREATE;
            } else {
                    create_disposition = SMB2_FILE_OVERWRITE_IF;
            }
    } else {
            if (flags & (O_WRONLY | O_RDWR)) {
                    create_disposition = SMB2_FILE_OVERWRITE;
            } else {
                    create_disposition = SMB2_FILE_OPEN;
            }
    }

This is a bug as it causes all writes to truncate files.

O_WRONLY | O_RDWR should be O_TRUNC

smb2_lseek breaks on large files

smb2_lseek returns -EINVAL on error, else the resulting offset. But if the seek is past 31 bits, then the return value flips negative as it overflows an int. While the seek was good, an error will be signaled (neg return value) and a seek failure will result on app side.

  1. Either make current_offset pointer parameter mandatory and only return status ( -EINVAL or 0)
  2. Or change the return from int to int64_t, this will not match file->offset (uint64_t) but it has to be signed to signal an error. 1) seems better.

smb2_cmd_create_async failed on xcode 10.2

Hi sahlberg
I have been using AMSMB2 which is based on this repo for a long time, it works great, but with the update on Xcode10.2, the list share API failed. I ran the test case of func testShareEnum() of AMSMB2's test case. The case success on xcode10.1 but failed on xcode10.2. After some debug, I found it was caused by smb2_cmd_create_async API.
Screenshot 2019-03-29 at 2 26 05 PM
Can you please take a look? Is it a xcode issue and do we have a workaround?

uninitialized const when using C++

Having the following issue compiling with C++

In file included from /home/lukas/Documents/git/vfs.smb/src/SMBFile.cpp:30:0:
/usr/local/include/smb2/libsmb2-raw.h:32:20: error: uninitialized const ‘compound_file_id’ [-fpermissive]
 const smb2_file_id compound_file_id;
                    ^
In file included from /home/lukas/Documents/git/vfs.smb/src/SMBConnection.cpp:27:0:
/usr/local/include/smb2/libsmb2-raw.h:32:20: error: uninitialized const ‘compound_file_id’ [-fpermissive]
 const smb2_file_id compound_file_id;
                    ^

I can fix the error with the following, but not sure what a proper fix would be

const smb2_file_id compound_file_id = {0};

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.