libsmb2-6.2/ 0000775 0001750 0001750 00000000000 14732155517 012017 5 ustar polpy polpy libsmb2-6.2/packaging/ 0000775 0001750 0001750 00000000000 14732155517 013743 5 ustar polpy polpy libsmb2-6.2/packaging/RPM/ 0000775 0001750 0001750 00000000000 14732155517 014401 5 ustar polpy polpy libsmb2-6.2/packaging/RPM/libsmb2.spec.in 0000664 0001750 0001750 00000006372 14732155517 017224 0 ustar polpy polpy Name: libsmb2
Summary: SMB2/3 client library
Vendor: Ronnie Sahlberg
Packager: ronniesahlberg@gmail.com
Version: @VERSION@
Release: 1
Epoch: 0
License: GNU LGPL version 2.1
Group: System Environment/Libraries
URL: http://www.github.com/sahlberg/libsmb2
Source: libsmb2-%{version}.tar.gz
Provides: lib = %{version}
Prefix: /usr
BuildRoot: %{_tmppath}/%{name}-%{version}-root
%description
Libsmb2 is a SMB2/3 client library
#######################################################################
%prep
%setup -q
# setup the init script and sysconfig file
%setup -T -D -n libsmb2-%{version} -q
%build
## check for ccache
if ccache -h >/dev/null 2>&1 ; then
CC="ccache gcc"
else
CC="gcc"
fi
export CC
## always run autogen.sh
aclocal
autoheader
autoconf
libtoolize -c -f -i
automake --add-missing
CFLAGS="$RPM_OPT_FLAGS $EXTRA -O2 -D_GNU_SOURCE" %configure
%install
# Clean up in case there is trash left from a previous build
rm -rf $RPM_BUILD_ROOT
# Create the target build directory hierarchy
make DESTDIR=$RPM_BUILD_ROOT install
# Remove "*.old" files
find $RPM_BUILD_ROOT -name "*.old" -exec rm -f {} \;
%clean
rm -rf $RPM_BUILD_ROOT
#######################################################################
## Files section ##
#######################################################################
%files
%defattr(-,root,root)
%{_libdir}/libsmb2.so*
%package devel
Summary: Development libraries for LibSMB2
Group: Development
%description devel
development libraries for LibSMB2
%files devel
%defattr(-,root,root)
%{_includedir}/smb2/libsmb2.h
%{_includedir}/smb2/libsmb2-raw.h
%{_includedir}/smb2/libsmb2-dcerpc.h
%{_includedir}/smb2/libsmb2-dcerpc-lsa.h
%{_includedir}/smb2/libsmb2-dcerpc-srvsvc.h
%{_includedir}/smb2/smb2.h
%{_includedir}/smb2/smb2-errors.h
%{_libdir}/libsmb2.a
%{_libdir}/pkgconfig/libsmb2.pc
%changelog
* Mon Dec 16 2024 : Version 6.1.0
- Fix return code for smb2-ls on failure
- Fix memory errors in smb2_opendir()
- Add a macro te test for the version of the share-enum api
* Wed Dec 11 2024 : Version 6.0.0
- Major rewrites to DCE-RPC
- Initial support for building servers
* Mon Jan 17 2022 : Version 4.0.0
- Add support for SMB3 encryption
- Add support for Anonymous NTLMSSP logins
- Add support for readlink.
- Add API to notify application of changes to which filehandles are used by
libsmb2.
- Add support for Big Endian DCERPC and allow it to be controlled from the
URL.
- Add support for 3.1.1 signing
- Add support for PS2(EE) and PS3
- Fixes to UCS2 when compose characters are used.
- Various MacOS fixes
- Fix a few NULL dereferences
* Mon Jun 10 2019 : Version 3.0.0
- ESP32 support
- Support specifying the port number in an SMB URL.
- Add creation time to smb_stat
- Abort all commands when the context is destroyed.
- Free all file and directory handles when the context is destroyed.
- Fix handling of O_TRUNC
- Add more error codes.
- Add support for SMB2_IOCTL
- Handle DCE/RPC fragment reassembly for IOCTL().
* Sat Jul 7 2018 : Version 2.0.0
- SMB2/3 signing
- Kerberos authentication
- Builtin NTLMSSP authentication for when libkrb5 is not available
- Share enumeration
- CMake support
- Various bugfixes
* Sun Mar 5 2017 : Version 1.0.0
- Initial version
libsmb2-6.2/packaging/RPM/makerpms.sh 0000775 0001750 0001750 00000005726 14732155517 016571 0 ustar polpy polpy #!/bin/sh
#
# makerpms.sh - build RPM packages from the git sources
#
# Copyright (C) John H Terpstra 1998-2002
# Copyright (C) Gerald (Jerry) Carter 2003
# Copyright (C) Jim McDonough 2007
# Copyright (C) Andrew Tridgell 2007
# Copyright (C) Michael Adam 2008-2009
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, see .
#
#
# The following allows environment variables to override the target directories
# the alternative is to have a file in your home directory called .rpmmacros
# containing the following:
# %_topdir /home/mylogin/redhat
#
# Note: Under this directory rpm expects to find the same directories that are under the
# /usr/src/redhat directory
#
EXTRA_OPTIONS="$1"
DIRNAME=$(dirname $0)
TOPDIR=${DIRNAME}/../..
SPECDIR=`rpm --eval %_specdir`
SRCDIR=`rpm --eval %_sourcedir`
SPECFILE="libsmb2.spec"
SPECFILE_IN="libsmb2.spec.in"
RPMBUILD="rpmbuild"
# We use tags and determine the version, as follows:
# libsmb2-0.9.1 (First release of 0.9).
# libsmb2-0.9.23 (23rd minor release of the 112 version)
#
# If we're not directly on a tag, this is a devel release; we append
# .0...devel to the release.
TAG=`git describe`
case "$TAG" in
libsmb2-*)
TAG=${TAG##libsmb2-}
case "$TAG" in
*-*-g*) # 0.9-168-ge6cf0e8
# Not exactly on tag: devel version.
VERSION=`echo "$TAG" | sed 's/\([^-]\+\)-\([0-9]\+\)-\(g[0-9a-f]\+\)/\1.0.\2.\3.devel/'`
;;
*)
# An actual release version
VERSION=$TAG
;;
esac
;;
*)
echo Invalid tag "$TAG" >&2
exit 1
;;
esac
sed -e s/@VERSION@/$VERSION/g \
< ${DIRNAME}/${SPECFILE_IN} \
> ${DIRNAME}/${SPECFILE}
VERSION=$(grep ^Version ${DIRNAME}/${SPECFILE} | sed -e 's/^Version:\ \+//')
if echo | gzip -c --rsyncable - > /dev/null 2>&1 ; then
GZIP="gzip -9 --rsyncable"
else
GZIP="gzip -9"
fi
pushd ${TOPDIR}
echo -n "Creating libsmb2-${VERSION}.tar.gz ... "
mkdir -p "${SRCDIR}"
git archive --prefix=libsmb2-${VERSION}/ HEAD | ${GZIP} > ${SRCDIR}/libsmb2-${VERSION}.tar.gz
RC=$?
popd
echo "Done."
if [ $RC -ne 0 ]; then
echo "Build failed!"
exit 1
fi
# At this point the SPECDIR and SRCDIR variables must have a value!
##
## copy additional source files
##
mkdir -p ${SPECDIR}
cp -p ${DIRNAME}/${SPECFILE} ${SPECDIR}
##
## Build
##
echo "$(basename $0): Getting Ready to build release package"
${RPMBUILD} -ba --clean --rmsource ${EXTRA_OPTIONS} ${SPECDIR}/${SPECFILE} || exit 1
echo "$(basename $0): Done."
exit 0
libsmb2-6.2/utils/ 0000775 0001750 0001750 00000000000 14732155517 013157 5 ustar polpy polpy libsmb2-6.2/utils/smb2-cp.c 0000664 0001750 0001750 00000014335 14732155517 014574 0 ustar polpy polpy /*
Copyright (C) by Ronnie Sahlberg 2024
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see .
*/
#define _FILE_OFFSET_BITS 64
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include
#if !defined(__amigaos4__) && !defined(__AMIGA__) && !defined(__AROS__)
#include
#endif
#include
#include
#include
#include
#include
#include
#include
#include
#include "smb2.h"
#include "libsmb2.h"
#include "libsmb2-raw.h"
#ifdef __AROS__
#include "asprintf.h"
#endif
struct file_context {
int is_smb2;
int fd;
struct smb2_context *smb2;
struct smb2fh *smb2fh;
struct smb2_url *url;
};
void usage(void)
{
fprintf(stderr, "Usage: smb2-cp \n");
fprintf(stderr, ", can either be a local file or "
"an smb2 URL.\n");
exit(0);
}
static void
free_file_context(struct file_context *file_context)
{
if (file_context->fd != -1) {
close(file_context->fd);
}
if (file_context->smb2fh != NULL) {
smb2_close(file_context->smb2, file_context->smb2fh);
}
if (file_context->smb2 != NULL) {
smb2_destroy_context(file_context->smb2);
}
smb2_destroy_url(file_context->url);
free(file_context);
}
static int
fstat_file(struct file_context *fc, struct stat *st)
{
if (fc->is_smb2 == 0) {
return fstat(fc->fd, st);
} else {
int res;
struct smb2_stat_64 smb2_st;
res = smb2_fstat(fc->smb2, fc->smb2fh, &smb2_st);
st->st_dev = 0;
st->st_ino = (ino_t)smb2_st.smb2_ino;
#ifndef WIN32
st->st_mode = 0;
st->st_nlink = (nlink_t)smb2_st.smb2_nlink;
st->st_blksize = 4096;
st->st_blocks = (smb2_st.smb2_size + 4096 - 1) % 4096;
#endif
st->st_uid = 0;
st->st_gid = 0;
st->st_rdev = 0;
st->st_size = (off_t)smb2_st.smb2_size;
st->st_atime = smb2_st.smb2_atime;
st->st_mtime = smb2_st.smb2_mtime;
st->st_ctime = smb2_st.smb2_ctime;
return res;
}
}
static ssize_t
file_pread(struct file_context *fc, uint8_t *buf, size_t count, off_t off)
{
if (fc->is_smb2 == 0) {
lseek(fc->fd, off, SEEK_SET);
return read(fc->fd, buf, count);
} else {
return smb2_pread(fc->smb2, fc->smb2fh, buf, count, off);
}
}
static ssize_t
file_pwrite(struct file_context *fc, uint8_t *buf, size_t count, off_t off)
{
if (fc->is_smb2 == 0) {
lseek(fc->fd, off, SEEK_SET);
return write(fc->fd, buf, count);
} else {
return smb2_pwrite(fc->smb2, fc->smb2fh, buf, count, off);
}
}
static struct file_context *
open_file(const char *url, int flags)
{
struct file_context *file_context;
file_context = malloc(sizeof(struct file_context));
if (file_context == NULL) {
fprintf(stderr, "Failed to malloc file_context\n");
return NULL;
}
file_context->is_smb2 = 0;
file_context->fd = -1;
file_context->smb2 = NULL;
file_context->smb2fh = NULL;
file_context->url = NULL;
if (strncmp(url, "smb://", 6)) {
file_context->is_smb2 = 0;
file_context->fd = open(url, flags, 0660);
if (file_context->fd == -1) {
fprintf(stderr, "Failed to open %s\n", url);
free_file_context(file_context);
return NULL;
}
return file_context;
}
file_context->is_smb2 = 1;
file_context->smb2 = smb2_init_context();
if (file_context->smb2 == NULL) {
fprintf(stderr, "failed to init context\n");
free_file_context(file_context);
return NULL;
}
file_context->url = smb2_parse_url(file_context->smb2, url);
if (file_context->url == NULL) {
fprintf(stderr, "%s\n", smb2_get_error(file_context->smb2));
free_file_context(file_context);
return NULL;
}
if (smb2_connect_share(file_context->smb2, file_context->url->server,
file_context->url->share,
file_context->url->user) != 0) {
fprintf(stderr, "Failed to mount smb2 share : %s\n",
smb2_get_error(file_context->smb2));
free_file_context(file_context);
return NULL;
}
file_context->smb2fh = smb2_open(file_context->smb2, file_context->url->path, flags);
if (file_context->smb2fh == NULL) {
fprintf(stderr, "Failed to open file %s: %s\n",
file_context->url->path,
smb2_get_error(file_context->smb2));
free_file_context(file_context);
return NULL;
}
return file_context;
}
#define BUFSIZE 1024*1024
static uint8_t buf[BUFSIZE];
int main(int argc, char *argv[])
{
struct stat st;
struct file_context *src;
struct file_context *dst;
off_t off;
ssize_t count;
#ifdef WIN32
if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0) {
printf("Failed to start Winsock2\n");
return 10;
}
#endif
#ifdef AROS
aros_init_socket();
#endif
if (argc != 3) {
usage();
}
src = open_file(argv[1], O_RDONLY);
if (src == NULL) {
fprintf(stderr, "Failed to open %s\n", argv[1]);
return 10;
}
dst = open_file(argv[2], O_WRONLY|O_CREAT|O_TRUNC);
if (dst == NULL) {
fprintf(stderr, "Failed to open %s\n", argv[2]);
free_file_context(src);
return 10;
}
if (fstat_file(src, &st) != 0) {
fprintf(stderr, "Failed to fstat source file\n");
free_file_context(src);
free_file_context(dst);
return 10;
}
off = 0;
while (off < st.st_size) {
count = (size_t)(st.st_size - off);
if (count > BUFSIZE) {
count = BUFSIZE;
}
count = file_pread(src, buf, count, off);
if (count < 0) {
fprintf(stderr, "Failed to read from source file\n");
free_file_context(src);
free_file_context(dst);
return 10;
}
count = file_pwrite(dst, buf, count, off);
if (count < 0) {
fprintf(stderr, "Failed to write to dest file\n");
free_file_context(src);
free_file_context(dst);
return 10;
}
off += count;
}
printf("copied %d bytes\n", (int)off);
free_file_context(src);
free_file_context(dst);
return 0;
}
libsmb2-6.2/utils/Makefile.am 0000664 0001750 0001750 00000000407 14732155517 015214 0 ustar polpy polpy noinst_PROGRAMS = smb2-cp smb2-ls
AM_CPPFLAGS = \
-I$(abs_top_srcdir)/include \
-I$(abs_top_srcdir)/include/smb2 \
"-D_U_=__attribute__((unused))" \
-Wall -Werror
COMMON_LIBS = ../lib/libsmb2.la
smb2_ls_LDADD = $(COMMON_LIBS)
smb2_cp_LDADD = $(COMMON_LIBS)
libsmb2-6.2/utils/smb2-ls.c 0000664 0001750 0001750 00000011703 14732155517 014604 0 ustar polpy polpy /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */
/*
Copyright (C) 2016 by Ronnie Sahlberg
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include
#if !defined(__amigaos4__) && !defined(__AMIGA__) && !defined(__AROS__)
#include
#endif
#include
#include
#include
#include
#include
#include "smb2.h"
#include "libsmb2.h"
#include "libsmb2-raw.h"
#ifdef __AROS__
#include "asprintf.h"
#endif
int usage(void)
{
fprintf(stderr, "Usage:\n"
"smb2-ls-sync \n\n"
"URL format: "
"smb://[@][:]//\n");
exit(1);
}
int main(int argc, char *argv[])
{
struct smb2_context *smb2;
struct smb2_url *url;
struct smb2dir *dir;
struct smb2dirent *ent;
char *link;
int rc = 1;
if (argc < 2) {
usage();
}
smb2 = smb2_init_context();
if (smb2 == NULL) {
fprintf(stderr, "Failed to init context\n");
exit(1);
}
url = smb2_parse_url(smb2, argv[1]);
if (url == NULL) {
fprintf(stderr, "Failed to parse url: %s\n",
smb2_get_error(smb2));
exit(1);
}
smb2_set_security_mode(smb2, SMB2_NEGOTIATE_SIGNING_ENABLED);
if (smb2_connect_share(smb2, url->server, url->share, url->user) < 0) {
printf("smb2_connect_share failed. %s\n", smb2_get_error(smb2));
goto out_context;
}
dir = smb2_opendir(smb2, url->path);
if (dir == NULL) {
printf("smb2_opendir failed. %s\n", smb2_get_error(smb2));
goto out_disconnect;
}
while ((ent = smb2_readdir(smb2, dir))) {
char *type;
time_t t;
t = (time_t)ent->st.smb2_mtime;
switch (ent->st.smb2_type) {
case SMB2_TYPE_LINK:
type = "LINK";
break;
case SMB2_TYPE_FILE:
type = "FILE";
break;
case SMB2_TYPE_DIRECTORY:
type = "DIRECTORY";
break;
default:
type = "unknown";
break;
}
printf("%-20s %-9s %15"PRIu64" %s", ent->name, type, ent->st.smb2_size, asctime(localtime(&t)));
if (ent->st.smb2_type == SMB2_TYPE_LINK) {
char buf[256];
if (url->path && url->path[0]) {
if (asprintf(&link, "%s/%s", url->path, ent->name) < 0) {
printf("asprintf failed\n");
goto out_disconnect;
}
} else {
if (asprintf(&link, "%s", ent->name) < 0) {
printf("asprintf failed\n");
goto out_disconnect;
}
}
if (smb2_readlink(smb2, link, buf, 256) == 0) {
printf(" -> [%s]\n", buf);
} else {
printf(" readlink failed\n");
}
free(link);
}
}
rc = 0;
smb2_closedir(smb2, dir);
out_disconnect:
smb2_disconnect_share(smb2);
out_context:
smb2_destroy_url(url);
smb2_destroy_context(smb2);
return rc;
}
libsmb2-6.2/libsmb2.pc.in 0000664 0001750 0001750 00000000447 14732155517 014307 0 ustar polpy polpy # libsmb2 pkg-config file
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: libsmb2
Description: libsmb2 is a client library for accessing SMB shares over a network.
Version: @VERSION@
Requires:
Conflicts:
Libs: -L${libdir} -lsmb2
Cflags: -I${includedir}
libsmb2-6.2/component.mk 0000664 0001750 0001750 00000000162 14732155517 014351 0 ustar polpy polpy
COMPONENT_SRCDIRS=lib
COMPONENT_PRIV_INCLUDEDIRS=lib include/esp
COMPONENT_ADD_INCLUDEDIRS=include include/smb2
libsmb2-6.2/examples/ 0000775 0001750 0001750 00000000000 14732155517 013635 5 ustar polpy polpy libsmb2-6.2/examples/smb2-ftruncate-sync.c 0000664 0001750 0001750 00000006205 14732155517 017612 0 ustar polpy polpy /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */
/*
Copyright (C) 2016 by Ronnie Sahlberg
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define _GNU_SOURCE
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "smb2.h"
#include "libsmb2.h"
#include "libsmb2-raw.h"
int usage(void)
{
fprintf(stderr, "Usage:\n"
"smb2-ftruncate-sync \n\n"
"URL format: "
"smb://[@][:]//\n");
exit(1);
}
int main(int argc, char *argv[])
{
struct smb2_context *smb2;
struct smb2_url *url;
struct smb2fh *fh;
if (argc < 3) {
usage();
}
smb2 = smb2_init_context();
if (smb2 == NULL) {
fprintf(stderr, "Failed to init context\n");
exit(0);
}
url = smb2_parse_url(smb2, argv[1]);
if (url == NULL) {
fprintf(stderr, "Failed to parse url: %s\n",
smb2_get_error(smb2));
exit(0);
}
smb2_set_security_mode(smb2, SMB2_NEGOTIATE_SIGNING_ENABLED);
if (smb2_connect_share(smb2, url->server, url->share, url->user) != 0) {
printf("smb2_connect_share failed. %s\n", smb2_get_error(smb2));
exit(10);
}
fh = smb2_open(smb2, url->path, O_RDWR);
if (fh == NULL) {
printf("smb2_open failed. %s\n", smb2_get_error(smb2));
exit(10);
}
if (smb2_ftruncate(smb2, fh, strtoll(argv[2], NULL, 10)) < 0) {
printf("smb2_ftruncate failed. %s\n", smb2_get_error(smb2));
smb2_close(smb2, fh);
exit(10);
}
smb2_close(smb2, fh);
smb2_disconnect_share(smb2);
smb2_destroy_url(url);
smb2_destroy_context(smb2);
return 0;
}
libsmb2-6.2/examples/smb2-cat-sync.c 0000664 0001750 0001750 00000007155 14732155517 016373 0 ustar polpy polpy /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */
/*
Copyright (C) 2016 by Ronnie Sahlberg
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define _GNU_SOURCE
#include
#include
#if !defined(__amigaos4__) && !defined(__AMIGA__) && !defined(__AROS__)
#include
#endif
#include
#include
#include
#include
#include
#include
#include
#include "smb2.h"
#include "libsmb2.h"
#include "libsmb2-raw.h"
#define MAXBUF 16 * 1024 * 1024
uint8_t buf[MAXBUF];
uint32_t pos;
int usage(void)
{
fprintf(stderr, "Usage:\n"
"smb2-cat-sync \n\n"
"URL format: "
"smb://[@][:]//\n");
exit(1);
}
int main(int argc, char *argv[])
{
struct smb2_context *smb2;
struct smb2_url *url;
struct smb2fh *fh;
int count, rc = 0;
if (argc < 2) {
usage();
}
smb2 = smb2_init_context();
if (smb2 == NULL) {
fprintf(stderr, "Failed to init context\n");
exit(0);
}
url = smb2_parse_url(smb2, argv[1]);
if (url == NULL) {
fprintf(stderr, "Failed to parse url: %s\n",
smb2_get_error(smb2));
exit(0);
}
smb2_set_security_mode(smb2, SMB2_NEGOTIATE_SIGNING_ENABLED);
if (smb2_connect_share(smb2, url->server, url->share, url->user) != 0) {
printf("smb2_connect_share failed. %s\n", smb2_get_error(smb2));
exit(10);
}
fh = smb2_open(smb2, url->path, O_RDONLY);
if (fh == NULL) {
printf("smb2_open failed. %s\n", smb2_get_error(smb2));
exit(10);
}
while ((count = smb2_pread(smb2, fh, buf, MAXBUF, pos)) != 0) {
if (count == -EAGAIN) {
continue;
}
if (count < 0) {
fprintf(stderr, "Failed to read file. %s\n",
smb2_get_error(smb2));
rc = 1;
break;
}
write(STDOUT_FILENO, buf, count);
pos += count;
};
smb2_close(smb2, fh);
smb2_disconnect_share(smb2);
smb2_destroy_url(url);
smb2_destroy_context(smb2);
return rc;
}
libsmb2-6.2/examples/smb2-ls-async.c 0000664 0001750 0001750 00000013156 14732155517 016401 0 ustar polpy polpy /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */
/*
Copyright (C) 2016 by Ronnie Sahlberg
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define _GNU_SOURCE
#include
#if !defined(__amigaos4__) && !defined(__AMIGA__) && !defined(__AROS__)
#include
#endif
#include
#include
#include
#include
#include
#include "smb2.h"
#include "libsmb2.h"
#include "libsmb2-raw.h"
#ifdef __AROS__
#include "asprintf.h"
#endif
#if defined(__amigaos4__) || defined(__AMIGA__) || defined(__AROS__)
struct pollfd {
int fd;
short events;
short revents;
};
int poll(struct pollfd *fds, unsigned int nfds, int timo);
#endif
int is_finished;
int usage(void)
{
fprintf(stderr, "Usage:\n"
"smb2-ls-async \n\n"
"URL format: "
"smb://[@]>[:]//\n");
exit(1);
}
void dc_cb(struct smb2_context *smb2, int status,
void *command_data _U_, void *private_data)
{
is_finished = 1;
}
void od_cb(struct smb2_context *smb2, int status,
void *command_data, void *private_data)
{
struct smb2dir *dir = command_data;
struct smb2dirent *ent;
if (status) {
printf("failed to create/open directory (%s) %s\n",
strerror(-status), smb2_get_error(smb2));
exit(10);
}
while ((ent = smb2_readdir(smb2, dir))) {
char *type;
time_t t;
switch (ent->st.smb2_type) {
case SMB2_TYPE_LINK:
type = "LINK";
break;
case SMB2_TYPE_FILE:
type = "FILE";
break;
case SMB2_TYPE_DIRECTORY:
type = "DIRECTORY";
break;
default:
type = "unknown";
break;
}
t = (time_t)ent->st.smb2_mtime;
printf("%-20s %-9s %15"PRIu64" %s\n", ent->name, type, ent->st.smb2_size, asctime(localtime(&t)));
}
smb2_closedir(smb2, dir);
smb2_disconnect_share_async(smb2, dc_cb, NULL);
}
void cf_cb(struct smb2_context *smb2, int status,
void *command_data, void *private_data)
{
if (status) {
printf("failed to connect share (%s) %s\n",
strerror(-status), smb2_get_error(smb2));
exit(10);
}
if (smb2_opendir_async(smb2, private_data, od_cb, NULL) < 0) {
printf("Failed to call opendir_async()\n");
exit(10);
}
}
static int cfd = -1;
void fd_cb(struct smb2_context *smb2, int fd, int cmd)
{
if (cmd == SMB2_ADD_FD) {
cfd = fd;
}
if (cmd == SMB2_DEL_FD) {
cfd = -1;
}
}
static int cevents = 0;
void events_cb(struct smb2_context *smb2, int fd, int events)
{
cevents = events;
}
int main(int argc, char *argv[])
{
struct smb2_context *smb2;
struct smb2_url *url;
struct pollfd pfd;
if (argc < 2) {
usage();
}
smb2 = smb2_init_context();
if (smb2 == NULL) {
fprintf(stderr, "Failed to init context\n");
exit(0);
}
smb2_fd_event_callbacks(smb2, fd_cb, events_cb);
url = smb2_parse_url(smb2, argv[1]);
if (url == NULL) {
fprintf(stderr, "Failed to parse url: %s\n",
smb2_get_error(smb2));
exit(0);
}
smb2_set_security_mode(smb2, SMB2_NEGOTIATE_SIGNING_ENABLED);
if (smb2_connect_share_async(smb2, url->server, url->share, url->user, cf_cb, (void *)url->path) != 0) {
printf("smb2_connect_share failed. %s\n", smb2_get_error(smb2));
exit(10);
}
while (!is_finished) {
pfd.fd = cfd;
pfd.events = cevents;
if (poll(&pfd, 1, 1000) < 0) {
printf("Poll failed");
exit(10);
}
if (pfd.revents == 0) {
continue;
}
if (smb2_service(smb2, pfd.revents) < 0) {
printf("smb2_service failed with : %s\n",
smb2_get_error(smb2));
break;
}
}
smb2_destroy_url(url);
smb2_destroy_context(smb2);
return 0;
}
libsmb2-6.2/examples/smb2-put-async.c 0000664 0001750 0001750 00000012503 14732155517 016566 0 ustar polpy polpy /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */
/*
Copyright (C) 2016 by Ronnie Sahlberg
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define _GNU_SOURCE
#include
#include
#if !defined(__amigaos4__) && !defined(__AMIGA__) && !defined(__AROS__)
#include
#endif
#include
#include
#include
#include
#include
#include
#include
#include "smb2.h"
#include "libsmb2.h"
#include "libsmb2-raw.h"
#if defined(__amigaos4__) || defined(__AMIGA__) || defined(__AROS__)
struct pollfd {
int fd;
short events;
short revents;
};
int poll(struct pollfd *fds, unsigned int nfds, int timo);
#endif
uint8_t buf[256 * 1024];
int usage(void)
{
fprintf(stderr, "Usage:\n"
"smb2-put-async \n\n"
"URL format: "
"smb://[@]>[:]//\n");
exit(1);
}
struct cb_data {
int is_finished;
int fd;
struct smb2fh *fh;
uint32_t pos;
};
void write_cb(struct smb2_context *smb2, int status,
void *command_data, void *private_data)
{
struct cb_data *data = private_data;
int count;
if (status < 0) {
printf("failed to write to share (%s) %s\n",
strerror(-status), smb2_get_error(smb2));
exit(10);
}
if (status == 0) {
data->is_finished = 1;
return;
}
printf("write_cb:%d\n", status);
data->pos += status;
count = read(data->fd, buf, 1024);
if (count <= 0) {
exit(10);
}
if (smb2_pwrite_async(smb2, data->fh, buf, count, data->pos, write_cb,
data) < 0) {
printf("smb2_write_async failed. %s\n", smb2_get_error(smb2));
exit(10);
};
}
int main(int argc, char *argv[])
{
struct smb2_context *smb2;
struct smb2_url *url;
struct cb_data data;
struct pollfd pfd;
int count;
data.is_finished = 0;
data.pos = 0;
if (argc < 2) {
usage();
}
data.fd = open(argv[1], O_RDONLY);
if (data.fd == -1) {
printf("Failed to open local file %s (%s)\n", argv[1],
strerror(errno));
exit(10);
}
smb2 = smb2_init_context();
if (smb2 == NULL) {
fprintf(stderr, "Failed to init context\n");
exit(0);
}
url = smb2_parse_url(smb2, argv[2]);
if (url == NULL) {
fprintf(stderr, "Failed to parse url: %s\n",
smb2_get_error(smb2));
exit(0);
}
smb2_set_security_mode(smb2, SMB2_NEGOTIATE_SIGNING_ENABLED);
if (smb2_connect_share(smb2, url->server, url->share, url->user) != 0) {
printf("smb2_connect_share failed. %s\n", smb2_get_error(smb2));
exit(10);
}
data.fh = smb2_open(smb2, url->path, O_WRONLY|O_CREAT);
if (data.fh == NULL) {
printf("smb2_open failed. %s\n", smb2_get_error(smb2));
exit(10);
}
count = read(data.fd, buf, 1024);
if (count <= 0) {
exit(10);
}
if (smb2_pwrite_async(smb2, data.fh, buf, count, data.pos, write_cb,
&data) < 0) {
printf("smb2_write_async failed. %s\n", smb2_get_error(smb2));
exit(10);
};
while (!data.is_finished) {
pfd.fd = smb2_get_fd(smb2);
pfd.events = smb2_which_events(smb2);
if (poll(&pfd, 1, 1000) < 0) {
printf("Poll failed");
exit(10);
}
if (pfd.revents == 0) {
continue;
}
if (smb2_service(smb2, pfd.revents) < 0) {
printf("smb2_service failed with : %s\n",
smb2_get_error(smb2));
break;
}
}
close(data.fd);
smb2_close(smb2, data.fh);
smb2_disconnect_share(smb2);
smb2_destroy_url(url);
smb2_destroy_context(smb2);
return 0;
}
libsmb2-6.2/examples/smb2-CMD-FIND.c 0000664 0001750 0001750 00000030301 14732155517 015760 0 ustar polpy polpy /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */
/*
Copyright (C) 2022 by Ronnie Sahlberg
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define _GNU_SOURCE
#include
#include
#include
#include
#include
#include
#include
#include "smb2.h"
#include "libsmb2.h"
#include "libsmb2-raw.h"
int is_finished;
int usage(void)
{
fprintf(stderr, "Usage:\n"
"smb2-CMD-FIND \n\n"
"URL format: "
"smb://[@]>[:]/\n");
exit(1);
}
struct app_data {
smb2_file_id file_id;
uint32_t index_1, index_2;
const char *name_1, *name_2;
};
void qd_3_cb(struct smb2_context *smb2, int status,
void *command_data, void *private_data)
{
struct smb2_query_directory_reply *rep = command_data;
struct app_data *data = private_data;
struct smb2_iovec vec;
struct smb2_fileidfulldirectoryinformation fs;
if (status) {
printf("Restarting scan of directory using SMB2_INDEX_SPECIFIED failed (%s) %s\n",
strerror(-status), smb2_get_error(smb2));
printf("ERROR: server does not support SMB2_INDEX_SPECIFIED\n");
exit(10);
}
printf("Third scan of directory done.\n");
vec.buf = rep->output_buffer;
vec.len = rep->output_buffer_length;
if (smb2_decode_fileidfulldirectoryinformation(smb2, &fs, &vec)) {
printf("Failed to decode directory entry\n");
printf("ERROR: restarting the scan using SMB2_RESTART_SCAN broken\n");
exit(10);
}
printf("Index of first entry after restarting the scan at the second index: 0x%08x\n", fs.file_index);
printf("Name of first entry after restarting the scan at the second index %s\n", fs.name);
if (strcmp(fs.name, data->name_2)) {
printf("ERROR: restarting the scan using SMB2_INDEX_SPECIFIED did not return the expected second entry.\n");
printf("ERROR: server does not support SMB2_INDEX_SPECIFIED.\n");
exit(10);
}
}
void qd_2_cb(struct smb2_context *smb2, int status,
void *command_data, void *private_data)
{
struct smb2_query_directory_reply *rep = command_data;
struct smb2_query_directory_request req;
struct smb2_pdu *pdu;
struct app_data *data = private_data;
struct smb2_iovec vec;
struct smb2_fileidfulldirectoryinformation fs;
if (status) {
printf("Restarting scan of directory using SMB2_RESTART_SCAN failed (%s) %s\n",
strerror(-status), smb2_get_error(smb2));
printf("ERROR: server does not support SMB2_RESTART_SCAN\n");
exit(10);
}
printf("Second scan of directory done.\n");
vec.buf = rep->output_buffer;
vec.len = rep->output_buffer_length;
if (smb2_decode_fileidfulldirectoryinformation(smb2, &fs, &vec)) {
printf("Failed to decode directory entry\n");
printf("ERROR: restarting the scan using SMB2_RESTART_SCAN broken\n");
exit(10);
}
printf("Index of first entry after restarting the scan: 0x%08x\n", fs.file_index);
printf("Name of first entry after restarting the scan %s\n", fs.name);
if (strcmp(fs.name, data->name_1)) {
printf("ERROR: restarting the scan using SMB2_RESTART_SCAN did not return the name of the first entry.\n");
exit(10);
}
printf("Try restarting scan at the second entry using SMB2_INDEX_SPECIFIED\n");
memset(&req, 0, sizeof(struct smb2_query_directory_request));
req.file_information_class = SMB2_FILE_ID_FULL_DIRECTORY_INFORMATION;
req.flags = SMB2_INDEX_SPECIFIED;
req.file_index = data->index_2;
memcpy(req.file_id, data->file_id, SMB2_FD_SIZE);
req.output_buffer_length = 8 * 1024;
req.name = "*";
pdu = smb2_cmd_query_directory_async(smb2, &req, qd_2_cb, data);
if (pdu == NULL) {
printf("Failed to queue QUERY_DIRECTORY\n");
exit(10);
}
smb2_queue_pdu(smb2, pdu);
}
void qd_1_cb(struct smb2_context *smb2, int status,
void *command_data, void *private_data)
{
struct smb2_query_directory_reply *rep = command_data;
struct smb2_query_directory_request req;
struct smb2_pdu *pdu;
struct app_data *data = private_data;
struct smb2_iovec vec, tmp_vec;
struct smb2_fileidfulldirectoryinformation fs;
uint32_t offset = 0;
if (status) {
printf("failed to query directory (%s) %s\n",
strerror(-status), smb2_get_error(smb2));
exit(10);
}
printf("Initial scan of directory done.\n");
vec.buf = rep->output_buffer;
vec.len = rep->output_buffer_length;
tmp_vec.buf = &vec.buf[offset];
tmp_vec.len = vec.len - offset;
if (smb2_decode_fileidfulldirectoryinformation(smb2, &fs, &tmp_vec)) {
printf("Failed to decode directory entry\n");
exit(10);
}
data->name_1 = strdup(fs.name);
data->index_1 = fs.file_index;
printf("First file in directory: %s\n", data->name_1);
printf("Index of first file in directory: 0x%08x\n", fs.file_index);
offset += fs.next_entry_offset;
tmp_vec.buf = &vec.buf[offset];
tmp_vec.len = vec.len - offset;
if (smb2_decode_fileidfulldirectoryinformation(smb2, &fs, &tmp_vec)) {
printf("Failed to decode directory entry\n");
exit(10);
}
data->name_2 = strdup(fs.name);
data->index_2 = fs.file_index;
printf("Second file in directory: %s\n", data->name_2);
printf("Index of second file in directory: 0x%08x\n", fs.file_index);
if (data->index_1 == data->index_2) {
printf("ERROR: broken server returns same file_index for first two entries in the directory\n");
printf("ERROR: This server does not support SMB2_INDEX_SPECIFIED queries\n");
}
printf("Try restarting scan of directory using SMB2_RESTART_SCAN\n");
memset(&req, 0, sizeof(struct smb2_query_directory_request));
req.file_information_class = SMB2_FILE_ID_FULL_DIRECTORY_INFORMATION;
req.flags = SMB2_RESTART_SCANS;
memcpy(req.file_id, data->file_id, SMB2_FD_SIZE);
req.output_buffer_length = 8 * 1024;
req.name = "*";
pdu = smb2_cmd_query_directory_async(smb2, &req, qd_2_cb, data);
if (pdu == NULL) {
printf("Failed to queue QUERY_DIRECTORY\n");
exit(10);
}
smb2_queue_pdu(smb2, pdu);
}
void cr_cb(struct smb2_context *smb2, int status,
void *command_data, void *private_data)
{
struct smb2_create_reply *rep = command_data;
struct smb2_query_directory_request req;
struct smb2_pdu *pdu;
struct app_data *data = private_data;
if (status) {
printf("failed to open root of share (%s) %s\n",
strerror(-status), smb2_get_error(smb2));
exit(10);
}
printf("Opened root of the share\n");
memcpy(data->file_id, rep->file_id, SMB2_FD_SIZE);
memset(&req, 0, sizeof(struct smb2_query_directory_request));
req.file_information_class = SMB2_FILE_ID_FULL_DIRECTORY_INFORMATION;
req.flags = 0;
memcpy(req.file_id, data->file_id, SMB2_FD_SIZE);
req.output_buffer_length = 8 * 1024;
req.name = "*";
printf("Performing initial scan of directory\n");
pdu = smb2_cmd_query_directory_async(smb2, &req, qd_1_cb, data);
if (pdu == NULL) {
printf("Failed to queue QUERY_DIRECTORY\n");
exit(10);
}
smb2_queue_pdu(smb2, pdu);
}
void cf_cb(struct smb2_context *smb2, int status,
void *command_data, void *private_data)
{
struct smb2_create_request cr_req;
struct smb2_pdu *pdu;
struct add_data *data = private_data;
if (status) {
printf("failed to connect share (%s) %s\n",
strerror(-status), smb2_get_error(smb2));
exit(10);
}
/* CREATE command */
memset(&cr_req, 0, sizeof(struct smb2_create_request));
cr_req.requested_oplock_level = SMB2_OPLOCK_LEVEL_NONE;
cr_req.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION;
cr_req.file_attributes = SMB2_FILE_ATTRIBUTE_DIRECTORY;
cr_req.desired_access = SMB2_FILE_LIST_DIRECTORY | SMB2_FILE_READ_ATTRIBUTES;
cr_req.share_access = SMB2_FILE_SHARE_READ | SMB2_FILE_SHARE_WRITE;
cr_req.create_disposition = SMB2_FILE_OPEN;
cr_req.create_options = SMB2_FILE_DIRECTORY_FILE;
cr_req.name = "";
pdu = smb2_cmd_create_async(smb2, &cr_req, cr_cb, data);
if (pdu == NULL) {
fprintf(stderr, "Failed to create create command\n");
exit(10);
}
smb2_queue_pdu(smb2, pdu);
}
static int cfd = -1;
void fd_cb(struct smb2_context *smb2, int fd, int cmd)
{
if (cmd == SMB2_ADD_FD) {
cfd = fd;
}
if (cmd == SMB2_DEL_FD) {
cfd = -1;
}
}
static int cevents = 0;
void events_cb(struct smb2_context *smb2, int fd, int events)
{
cevents = events;
}
int main(int argc, char *argv[])
{
struct smb2_context *smb2;
struct smb2_url *url;
struct pollfd pfd;
struct app_data data;
if (argc < 2) {
usage();
}
smb2 = smb2_init_context();
if (smb2 == NULL) {
fprintf(stderr, "Failed to init context\n");
exit(0);
}
smb2_fd_event_callbacks(smb2, fd_cb, events_cb);
url = smb2_parse_url(smb2, argv[1]);
if (url == NULL) {
fprintf(stderr, "Failed to parse url: %s\n",
smb2_get_error(smb2));
exit(0);
}
smb2_set_security_mode(smb2, SMB2_NEGOTIATE_SIGNING_ENABLED);
if (smb2_connect_share_async(smb2, url->server, url->share, url->user,
cf_cb, &data) != 0) {
printf("smb2_connect_share failed. %s\n", smb2_get_error(smb2));
exit(10);
}
while (!is_finished) {
pfd.fd = cfd;
pfd.events = cevents;
if (poll(&pfd, 1, 1000) < 0) {
printf("Poll failed");
exit(10);
}
if (pfd.revents == 0) {
continue;
}
if (smb2_service(smb2, pfd.revents) < 0) {
printf("smb2_service failed with : %s\n",
smb2_get_error(smb2));
break;
}
}
smb2_destroy_url(url);
smb2_destroy_context(smb2);
return 0;
}
libsmb2-6.2/examples/smb2-stat-sync.c 0000664 0001750 0001750 00000007264 14732155517 016600 0 ustar polpy polpy /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */
/*
Copyright (C) 2016 by Ronnie Sahlberg
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define _GNU_SOURCE
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "smb2.h"
#include "libsmb2.h"
#include "libsmb2-raw.h"
int usage(void)
{
fprintf(stderr, "Usage:\n"
"smb2-stat-sync \n\n"
"URL format: "
"smb://[@]>[:]//\n");
exit(1);
}
int main(int argc, char *argv[])
{
struct smb2_context *smb2;
struct smb2_url *url;
struct smb2_stat_64 st;
time_t t;
if (argc < 2) {
usage();
}
smb2 = smb2_init_context();
if (smb2 == NULL) {
fprintf(stderr, "Failed to init context\n");
exit(0);
}
url = smb2_parse_url(smb2, argv[1]);
if (url == NULL) {
fprintf(stderr, "Failed to parse url: %s\n",
smb2_get_error(smb2));
exit(0);
}
smb2_set_security_mode(smb2, SMB2_NEGOTIATE_SIGNING_ENABLED);
if (smb2_connect_share(smb2, url->server, url->share, url->user) != 0) {
printf("smb2_connect_share failed. %s\n", smb2_get_error(smb2));
exit(10);
}
if (smb2_stat(smb2, url->path, &st) < 0) {
printf("smb2_stat failed. %s\n", smb2_get_error(smb2));
exit(10);
}
switch (st.smb2_type) {
case SMB2_TYPE_FILE:
printf("Type:FILE\n");
break;
case SMB2_TYPE_DIRECTORY:
printf("Type:DIRECTORY\n");
break;
default:
printf("Type:unknown\n");
break;
}
printf("Size:%"PRIu64"\n", st.smb2_size);
printf("Inode:0x%"PRIx64"\n", st.smb2_ino);
printf("Links:%"PRIu32"\n", st.smb2_nlink);
t = (time_t)st.smb2_atime;
printf("Atime:%s", asctime(localtime(&t)));
t = (time_t)st.smb2_mtime;
printf("Mtime:%s", asctime(localtime(&t)));
t = (time_t)st.smb2_ctime;
printf("Ctime:%s", asctime(localtime(&t)));
t = (time_t)st.smb2_btime;
printf("Btime:%s", asctime(localtime(&t)));
smb2_disconnect_share(smb2);
smb2_destroy_url(url);
smb2_destroy_context(smb2);
return 0;
}
libsmb2-6.2/examples/smb2-cat-async.c 0000664 0001750 0001750 00000013163 14732155517 016530 0 ustar polpy polpy /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */
/*
Copyright (C) 2016 by Ronnie Sahlberg
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define _GNU_SOURCE
#include
#if !defined(__amigaos4__) && !defined(__AMIGA__) && !defined(__AROS__)
#include
#endif
#include
#include
#include
#include
#include
#include
#include
#include "smb2.h"
#include "libsmb2.h"
#include "libsmb2-raw.h"
#if defined(__amigaos4__) || defined(__AMIGA__) || defined(__AROS__)
struct pollfd {
int fd;
short events;
short revents;
};
int poll(struct pollfd *fds, unsigned int nfds, int timo);
#endif
int is_finished;
uint8_t buf[256 * 1024];
uint32_t pos;
int usage(void)
{
fprintf(stderr, "Usage:\n"
"smb2-cat-async \n\n"
"URL format: "
"smb://[@][:]//\n");
exit(1);
}
void dc_cb(struct smb2_context *smb2, int status,
void *command_data _U_, void *private_data)
{
is_finished = 1;
}
void cl_cb(struct smb2_context *smb2, int status,
void *command_data, void *private_data)
{
smb2_disconnect_share_async(smb2, dc_cb, NULL);
}
void pr_cb(struct smb2_context *smb2, int status,
void *command_data, void *private_data)
{
struct smb2fh *fh = private_data;
if (status < 0) {
printf("failed to read file (%s) %s\n",
strerror(-status), smb2_get_error(smb2));
exit(10);
}
if (status == 0) {
if (smb2_close_async(smb2, fh, cl_cb, NULL) < 0) {
printf("Failed to call smb2_close_async()\n");
exit(10);
}
return;
}
write(STDOUT_FILENO, buf, status);
pos += status;
if (smb2_pread_async(smb2, fh, buf, 102400, pos, pr_cb, fh) < 0) {
printf("Failed to call smb2_pread_async()\n");
exit(10);
}
}
void of_cb(struct smb2_context *smb2, int status,
void *command_data, void *private_data)
{
struct smb2fh *fh = command_data;
if (status) {
printf("failed to open file (%s) %s\n",
strerror(-status), smb2_get_error(smb2));
exit(10);
}
if (smb2_pread_async(smb2, fh, buf, 102400, 0, pr_cb, fh) < 0) {
printf("Failed to call smb2_pread_async()\n");
exit(10);
}
}
void cf_cb(struct smb2_context *smb2, int status,
void *command_data, void *private_data)
{
if (status) {
printf("failed to connect share (%s) %s\n",
strerror(-status), smb2_get_error(smb2));
exit(10);
}
if (smb2_open_async(smb2, private_data, O_RDONLY,
of_cb, NULL) < 0) {
printf("Failed to call smb2_open_async()\n");
exit(10);
}
}
int main(int argc, char *argv[])
{
struct smb2_context *smb2;
struct smb2_url *url;
struct pollfd pfd;
if (argc < 2) {
usage();
}
smb2 = smb2_init_context();
if (smb2 == NULL) {
fprintf(stderr, "Failed to init context\n");
exit(0);
}
url = smb2_parse_url(smb2, argv[1]);
if (url == NULL) {
fprintf(stderr, "Failed to parse url: %s\n",
smb2_get_error(smb2));
exit(0);
}
smb2_set_security_mode(smb2, SMB2_NEGOTIATE_SIGNING_ENABLED);
if (smb2_connect_share_async(smb2, url->server, url->share, url->user,
cf_cb, (void *)url->path) != 0) {
printf("smb2_connect_share failed. %s\n", smb2_get_error(smb2));
exit(10);
}
while (!is_finished) {
pfd.fd = smb2_get_fd(smb2);
pfd.events = smb2_which_events(smb2);
if (poll(&pfd, 1, 1000) < 0) {
printf("Poll failed");
exit(10);
}
if (pfd.revents == 0) {
continue;
}
if (smb2_service(smb2, pfd.revents) < 0) {
printf("smb2_service failed with : %s\n",
smb2_get_error(smb2));
break;
}
}
smb2_destroy_url(url);
smb2_destroy_context(smb2);
return 0;
}
libsmb2-6.2/examples/picow/ 0000775 0001750 0001750 00000000000 14732155517 014756 5 ustar polpy polpy libsmb2-6.2/examples/picow/main.cpp 0000664 0001750 0001750 00000006433 14732155517 016414 0 ustar polpy polpy #include "pico/cyw43_arch.h"
#include "pico/stdio.h"
#include "pico/stdlib.h"
#include "FreeRTOS.h"
#include "task.h"
#include "smb2.h"
#include "libsmb2.h"
int smb2_ls_sync(char* user_url)
{
struct smb2_context *smb2;
struct smb2_url *url;
struct smb2dir *dir;
struct smb2dirent *ent;
char link[1024];
smb2 = smb2_init_context();
if (smb2 == NULL) {
printf("Failed to init context\n");
exit(0);
}
url = smb2_parse_url(smb2, user_url);
if (url == NULL) {
printf("Failed to parse url: %s\n",
smb2_get_error(smb2));
exit(0);
}
smb2_set_security_mode(smb2, SMB2_NEGOTIATE_SIGNING_ENABLED);
if (smb2_connect_share(smb2, url->server, url->share, url->user) < 0) {
printf("smb2_connect_share failed. %s\n", smb2_get_error(smb2));
exit(10);
}
dir = smb2_opendir(smb2, url->path);
if (dir == NULL) {
printf("smb2_opendir failed. %s\n", smb2_get_error(smb2));
exit(10);
}
while ((ent = smb2_readdir(smb2, dir))) {
const char *type;
time_t t;
t = (time_t)ent->st.smb2_mtime;
switch (ent->st.smb2_type) {
case SMB2_TYPE_LINK:
type = "LINK";
break;
case SMB2_TYPE_FILE:
type = "FILE";
break;
case SMB2_TYPE_DIRECTORY:
type = "DIRECTORY";
break;
default:
type = "unknown";
break;
}
printf("%-20s %-9s %15u\n", ent->name, type, ent->st.smb2_size);
if (ent->st.smb2_type == SMB2_TYPE_LINK) {
char buf[256];
if (url->path && url->path[0]) {
sprintf(link, "%s/%s", url->path, ent->name);
} else {
sprintf(link, "%s", ent->name);
}
smb2_readlink(smb2, link, buf, 256);
printf(" -> [%s]\n", buf);
}
}
smb2_closedir(smb2, dir);
smb2_disconnect_share(smb2);
smb2_destroy_url(url);
smb2_destroy_context(smb2);
return 0;
}
static void main_task(__unused void *params)
{
if (cyw43_arch_init())
{
printf("Failed to initialise Pico W\n");
return;
}
cyw43_arch_enable_sta_mode();
printf("Connecting to WiFi...\n");
if (cyw43_arch_wifi_connect_timeout_ms(WIFI_SSID, WIFI_PASSWORD, CYW43_AUTH_WPA2_AES_PSK, 30000))
{
printf("Failed to connect.\n");
return;
}
ip4_addr_t *address = &(cyw43_state.netif[0].ip_addr);
printf("Connected to %s as %d.%d.%d.%d as host %s\n", WIFI_SSID, ip4_addr1_16(address), ip4_addr2_16(address), ip4_addr3_16(address), ip4_addr4_16(address), cyw43_state.netif[0].hostname);
smb2_ls_sync(SMB2_URL);
vTaskDelete(NULL);
}
int main(void)
{
TaskHandle_t task;
stdio_init_all();
xTaskCreate(main_task, "MainThread", configMINIMAL_STACK_SIZE, NULL, 1, &task);
vTaskStartScheduler();
return 0;
}
libsmb2-6.2/examples/picow/CMakeLists.txt 0000664 0001750 0001750 00000004543 14732155517 017524 0 ustar polpy polpy cmake_minimum_required(VERSION 3.24)
# Some user configuration needed below
# Get the Pico SDK from https://github.com/raspberrypi/pico-sdk.git tested on TAG 1.4.0
# Get FreeRTOS from https://github.com/FreeRTOS/FreeRTOS-Kernel.git tested on TAG V10.5.0
# Replace the /path/to's below with appropriate paths
# Something like /home/me/dve/github/pico_sdk, but wherever you put the pico-sdk or freertos-kernel
set(PICO_SDK_PATH /path/to/pick-sdk)
set(FREERTOS_KERNEL_PATH /path/to/freertos-kernel)
set(LIBSMB2_PATH ${CMAKE_CURRENT_LIST_DIR}/../..)
# Replace with the name of your WiFi (SSID) and the password to join that WiFi
set(WIFI_SSID ssid_name)
set(WIFI_PASSWORD wifi_name)
# Put in the URL of the server/share you want to see the directory of
set(SMB2_URL smb://myserver.lan/myshare)
# No other configuration needed, below this
# Name the project and prepare it to be a pico_w project, using FreeRTOS and lwip
set(PROJECT_NAME libsmb2-picow-ls)
set(PICO_BOARD pico_w)
include(${PICO_SDK_PATH}/pico_sdk_init.cmake)
include(${FREERTOS_KERNEL_PATH}/portable/ThirdParty/GCC/RP2040/FreeRTOS_Kernel_import.cmake)
project(${PROJECT_NAME} C CXX ASM)
pico_sdk_init()
# Add a couple of definitions that all projects/libraries can/should use
add_definitions(-DPICO_PLATFORM=${PICO_PLATFORM})
add_definitions(-DHAVE_CONFIG_H)
# Build libsmb2 as a library
add_subdirectory(${LIBSMB2_PATH} libsmb2)
# The example
set(PROJECT_NAME smb2-ls-sync)
project(${PROJECT_NAME} C CXX ASM)
# Application, including in the FreeRTOS-Kernel
add_executable(${PROJECT_NAME} main.cpp)
# Build the app
include_directories(
${CMAKE_CURRENT_LIST_DIR}
${FREERTOS_KERNEL_PATH}/include
${LIBSMB2_PATH}/include
${LIBSMB2_PATH}/include/smb2
${LIBSMB2_PATH}/include/picow
)
pico_enable_stdio_usb(${PROJECT_NAME} 1)
pico_enable_stdio_uart(${PROJECT_NAME} 0)
pico_enable_stdio_semihosting(${PROJECT_NAME} ENABLED)
target_compile_definitions(${PROJECT_NAME} PRIVATE
WIFI_SSID=\"${WIFI_SSID}\"
WIFI_PASSWORD=\"${WIFI_PASSWORD}\"
SMB2_URL=\"${SMB2_URL}\"
NO_SYS=0 # don't want NO_SYS (generally this would be in your lwipopts.h)
)
target_link_libraries(${PROJECT_NAME}
pico_cyw43_arch_lwip_sys_freertos
FreeRTOS-Kernel
pico_stdlib
libsmb2
FreeRTOS-Kernel-Heap4
)
pico_add_extra_outputs(${PROJECT_NAME})
libsmb2-6.2/examples/picow/README.md 0000664 0001750 0001750 00000000413 14732155517 016233 0 ustar polpy polpy # Pico W sample
This is the smb-ls-sync.c example adapted to run on a Pico W. You will need the Pico-SDK and FreeRTOS-Kernel installed for this to work. See the CMakeLists.txt file - there's some user configuration needed before the sample can be compiled and run.
libsmb2-6.2/examples/picow/smb-ls-sync.c 0000664 0001750 0001750 00000000000 14732155517 017257 0 ustar polpy polpy libsmb2-6.2/examples/smb2-lseek-sync.c 0000664 0001750 0001750 00000007133 14732155517 016723 0 ustar polpy polpy /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */
/*
Copyright (C) 2020 by Ronnie Sahlberg
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define _GNU_SOURCE
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "smb2.h"
#include "libsmb2.h"
#include "libsmb2-raw.h"
int usage(void)
{
fprintf(stderr, "Usage:\n"
"smb2-lseek-sync \n\n"
"URL format: "
"smb://[@]>[:]//\n");
exit(1);
}
int main(int argc, char *argv[])
{
struct smb2_context *smb2;
struct smb2_url *url;
struct smb2fh *fh;
struct smb2_stat_64 st;
int64_t pos;
if (argc < 2) {
usage();
}
smb2 = smb2_init_context();
if (smb2 == NULL) {
fprintf(stderr, "Failed to init context\n");
exit(0);
}
url = smb2_parse_url(smb2, argv[1]);
if (url == NULL) {
fprintf(stderr, "Failed to parse url: %s\n",
smb2_get_error(smb2));
exit(0);
}
smb2_set_security_mode(smb2, SMB2_NEGOTIATE_SIGNING_ENABLED);
if (smb2_connect_share(smb2, url->server, url->share, url->user) != 0) {
printf("smb2_connect_share failed. %s\n", smb2_get_error(smb2));
exit(10);
}
fh = smb2_open(smb2, url->path, O_RDONLY);
if (fh == NULL) {
printf("smb2_open failed. %s\n", smb2_get_error(smb2));
exit(10);
}
if (smb2_fstat(smb2, fh, &st) < 0) {
printf("smb2_fstat failed. %s\n", smb2_get_error(smb2));
exit(10);
}
printf("SIZE:%"PRIu64"\n", st.smb2_size);
pos = smb2_lseek(smb2, fh, st.smb2_size, SEEK_SET, NULL);
printf("SEEK_SET to eof:%"PRIu64"\n", pos);
pos = smb2_lseek(smb2, fh, 0, SEEK_SET, NULL);
printf("SEEK_SET to bof:%"PRIu64"\n", pos);
pos = smb2_lseek(smb2, fh, 0, SEEK_END, NULL);
if (pos < 0) {
printf("%s\n", smb2_get_error(smb2));
}
printf("SEEK_END with offset == 0 :%"PRIu64"\n", pos);
smb2_close(smb2, fh);
smb2_disconnect_share(smb2);
smb2_destroy_url(url);
smb2_destroy_context(smb2);
return 0;
}
libsmb2-6.2/examples/smb2-raw-fsstat-async.c 0000664 0001750 0001750 00000030567 14732155517 020063 0 ustar polpy polpy /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */
/*
Copyright (C) 2017 by Ronnie Sahlberg
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define _GNU_SOURCE
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "smb2.h"
#include "libsmb2.h"
#include "libsmb2-raw.h"
int info_level;
int usage(void)
{
fprintf(stderr, "Usage:\n"
"smb2-raw-fsstat-async \n\n"
"URL format: "
"smb://[@][:]//\n");
exit(1);
}
struct sync_cb_data {
int is_finished;
int status;
void *ptr;
};
static int wait_for_reply(struct smb2_context *smb2,
struct sync_cb_data *cb_data)
{
while (!cb_data->is_finished) {
struct pollfd pfd;
pfd.fd = smb2_get_fd(smb2);
pfd.events = smb2_which_events(smb2);
if (poll(&pfd, 1, 1000) < 0) {
fprintf(stderr, "Poll failed");
return -1;
}
if (pfd.revents == 0) {
continue;
}
if (smb2_service(smb2, pfd.revents) < 0) {
fprintf(stderr, "smb2_service failed with : "
"%s\n", smb2_get_error(smb2));
return -1;
}
}
return 0;
}
static void generic_status_cb(struct smb2_context *smb2, int status,
void *command_data, void *private_data)
{
struct sync_cb_data *cb_data = private_data;
cb_data->is_finished = 1;
cb_data->status = status;
cb_data->ptr = command_data;
}
struct stat_cb_data {
smb2_command_cb cb;
void *cb_data;
uint32_t status;
};
static void
stat_cb_3(struct smb2_context *smb2, int status,
void *command_data _U_, void *private_data)
{
struct stat_cb_data *stat_data = private_data;
if (stat_data->status == SMB2_STATUS_SUCCESS) {
stat_data->status = status;
}
stat_data->cb(smb2, -nterror_to_errno(stat_data->status),
0, stat_data->cb_data);
free(stat_data);
}
static void
stat_cb_2(struct smb2_context *smb2, int status,
void *command_data, void *private_data)
{
struct stat_cb_data *stat_data = private_data;
struct smb2_query_info_reply *rep = command_data;
struct smb2_file_fs_size_info *fs_size;
struct smb2_file_fs_device_info *fs_dev;
struct smb2_file_fs_control_info *fs_ct;
struct smb2_file_fs_full_size_info *fs_full_size;
struct smb2_file_fs_volume_info *fs_vol;
if (stat_data->status == SMB2_STATUS_SUCCESS) {
stat_data->status = status;
}
if (stat_data->status != SMB2_STATUS_SUCCESS) {
return;
}
switch (info_level) {
case SMB2_FILE_FS_VOLUME_INFORMATION:
fs_vol = rep->output_buffer;
printf("VolumeSerialNumber: 0x%0x\n",
fs_vol->volume_serial_number);
printf("VolumeLabel: %s\n",
fs_vol->volume_label);
break;
case SMB2_FILE_FS_SIZE_INFORMATION:
fs_size = rep->output_buffer;
printf("TotalAllocationUnits: %" PRIu64 "\n",
fs_size->total_allocation_units);
printf("AvailableAllocationUnits: %" PRIu64 "\n",
fs_size->available_allocation_units);
printf("SectorsPerAllocationUnit: %u\n",
fs_size->sectors_per_allocation_unit);
printf("BytesPerSector: %u\n",
fs_size->bytes_per_sector);
break;
case SMB2_FILE_FS_DEVICE_INFORMATION:
fs_dev = rep->output_buffer;
printf("DeviceType: %u\n",
fs_dev->device_type);
printf("Characteristics: 0x%08x\n",
fs_dev->characteristics);
break;
case SMB2_FILE_FS_CONTROL_INFORMATION:
fs_ct = rep->output_buffer;
printf("FreeSpaceStartFiltering: %" PRIu64 "\n",
fs_ct->free_space_start_filtering);
printf("FreeSpaceThreshold: %" PRIu64 "\n",
fs_ct->free_space_threshold);
printf("FreeSpaceStopFiltering: %" PRIu64 "\n",
fs_ct->free_space_stop_filtering);
printf("DefaultQuotaThreshold: %" PRIu64 "\n",
fs_ct->default_quota_threshold);
printf("DefaultQuotaLimit: %" PRIu64 "\n",
fs_ct->default_quota_limit);
printf("Characteristics: 0x%08x\n",
fs_ct->file_system_control_flags);
break;
case SMB2_FILE_FS_FULL_SIZE_INFORMATION:
fs_full_size = rep->output_buffer;
printf("TotalAllocationUnits: %" PRIu64 "\n",
fs_full_size->total_allocation_units);
printf("CallerAvailableAllocationUnits: %" PRIu64 "\n",
fs_full_size->caller_available_allocation_units);
printf("ActualAvailableAllocationUnits: %" PRIu64 "\n",
fs_full_size->actual_available_allocation_units);
printf("SectorsPerAllocationUnit: %u\n",
fs_full_size->sectors_per_allocation_unit);
printf("BytesPerSector: %u\n",
fs_full_size->bytes_per_sector);
break;
}
}
static void
stat_cb_1(struct smb2_context *smb2, int status,
void *command_data _U_, void *private_data)
{
struct stat_cb_data *stat_data = private_data;
if (stat_data->status == SMB2_STATUS_SUCCESS) {
stat_data->status = status;
}
}
int send_compound_stat(struct smb2_context *smb2, const char *path,
smb2_command_cb cb, void *cb_data)
{
struct stat_cb_data *stat_data;
struct smb2_create_request cr_req;
struct smb2_query_info_request qi_req;
struct smb2_close_request cl_req;
struct smb2_pdu *pdu, *next_pdu;
stat_data = malloc(sizeof(struct stat_cb_data));
if (stat_data == NULL) {
fprintf(stderr, "Failed to allocate create_data");
return -1;
}
memset(stat_data, 0, sizeof(struct stat_cb_data));
stat_data->cb = cb;
stat_data->cb_data = cb_data;
/* CREATE command */
memset(&cr_req, 0, sizeof(struct smb2_create_request));
cr_req.requested_oplock_level = SMB2_OPLOCK_LEVEL_NONE;
cr_req.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION;
cr_req.desired_access = SMB2_FILE_READ_ATTRIBUTES | SMB2_FILE_READ_EA;
cr_req.file_attributes = 0;
cr_req.share_access = SMB2_FILE_SHARE_READ | SMB2_FILE_SHARE_WRITE;
cr_req.create_disposition = SMB2_FILE_OPEN;
cr_req.create_options = 0;
cr_req.name = path;
pdu = smb2_cmd_create_async(smb2, &cr_req, stat_cb_1, stat_data);
if (pdu == NULL) {
fprintf(stderr, "Failed to create create command\n");
free(stat_data);
return -1;
}
/* QUERY INFO command */
memset(&qi_req, 0, sizeof(struct smb2_query_info_request));
qi_req.info_type = SMB2_0_INFO_FILESYSTEM;
qi_req.file_info_class = info_level;
qi_req.output_buffer_length = 65535;
qi_req.additional_information = 0;
qi_req.flags = 0;
memcpy(qi_req.file_id, compound_file_id, SMB2_FD_SIZE);
next_pdu = smb2_cmd_query_info_async(smb2, &qi_req,
stat_cb_2, stat_data);
if (next_pdu == NULL) {
fprintf(stderr, "Failed to create query command\n");
free(stat_data);
smb2_free_pdu(smb2, pdu);
return -1;
}
smb2_add_compound_pdu(smb2, pdu, next_pdu);
/* CLOSE command */
memset(&cl_req, 0, sizeof(struct smb2_close_request));
cl_req.flags = SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB;
memcpy(cl_req.file_id, compound_file_id, SMB2_FD_SIZE);
next_pdu = smb2_cmd_close_async(smb2, &cl_req, stat_cb_3, stat_data);
if (next_pdu == NULL) {
fprintf(stderr, "Failed to create CLOSE command\n");
free(stat_data);
smb2_free_pdu(smb2, pdu);
return -1;
}
smb2_add_compound_pdu(smb2, pdu, next_pdu);
smb2_queue_pdu(smb2, pdu);
return 0;
}
int main(int argc, char *argv[])
{
struct smb2_context *smb2;
struct smb2_url *url;
struct sync_cb_data cb_data;
struct smb2_file_all_info *fs;
if (argc < 3) {
usage();
}
if (!strncmp(argv[2], "0x", 2)) {
info_level = strtol(argv[2], NULL, 16);
} else {
info_level = strtol(argv[2], NULL, 10);
}
switch (info_level) {
case SMB2_FILE_FS_VOLUME_INFORMATION:
printf("InfoLevel:%d FileFsVolmeInformation\n", info_level);
break;
case SMB2_FILE_FS_SIZE_INFORMATION:
printf("InfoLevel:%d FileFsSizeInformation\n", info_level);
break;
case SMB2_FILE_FS_DEVICE_INFORMATION:
printf("InfoLevel:%d FileFsDeviceInformation\n", info_level);
break;
case SMB2_FILE_FS_CONTROL_INFORMATION:
printf("InfoLevel:%d FileFsControlInformation\n", info_level);
break;
case SMB2_FILE_FS_FULL_SIZE_INFORMATION:
printf("InfoLevel:%d FileFsFullSizeInformation\n", info_level);
break;
}
smb2 = smb2_init_context();
if (smb2 == NULL) {
fprintf(stderr, "Failed to init context\n");
exit(0);
}
url = smb2_parse_url(smb2, argv[1]);
if (url == NULL) {
fprintf(stderr, "Failed to parse url: %s\n",
smb2_get_error(smb2));
exit(0);
}
if (url->user) {
smb2_set_user(smb2, url->user);
}
smb2_set_security_mode(smb2, SMB2_NEGOTIATE_SIGNING_ENABLED);
if (smb2_connect_share(smb2, url->server, url->share, url->user) != 0) {
printf("smb2_connect_share failed. %s\n", smb2_get_error(smb2));
exit(10);
}
memset(&cb_data, 0, sizeof(cb_data));
if (send_compound_stat(smb2, url->path,
generic_status_cb, &cb_data) != 0) {
printf("sending compound stat failed. %s\n",
smb2_get_error(smb2));
exit(10);
}
if (wait_for_reply(smb2, &cb_data) < 0) {
printf("failed waiting for a reply. %s\n",
smb2_get_error(smb2));
exit(10);
}
if (cb_data.status != 0) {
printf("Compound command sequence returned error 0x%08x\n",
cb_data.status);
exit(10);
}
fs = cb_data.ptr;
smb2_free_data(smb2, fs);
smb2_disconnect_share(smb2);
smb2_destroy_url(url);
smb2_destroy_context(smb2);
return 0;
}
libsmb2-6.2/examples/smb2-raw-stat-async.c 0000664 0001750 0001750 00000036531 14732155517 017527 0 ustar polpy polpy /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */
/*
Copyright (C) 2017 by Ronnie Sahlberg
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define _GNU_SOURCE
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "smb2.h"
#include "libsmb2.h"
#include "libsmb2-raw.h"
int usage(void)
{
fprintf(stderr, "Usage:\n"
"smb2-raw-stat-async \n\n"
"URL format: "
"smb://[@]>[:]//\n");
exit(1);
}
struct sync_cb_data {
int is_finished;
int status;
void *ptr;
};
static int wait_for_reply(struct smb2_context *smb2,
struct sync_cb_data *cb_data)
{
while (!cb_data->is_finished) {
struct pollfd pfd;
pfd.fd = smb2_get_fd(smb2);
pfd.events = smb2_which_events(smb2);
if (poll(&pfd, 1, 1000) < 0) {
fprintf(stderr, "Poll failed");
return -1;
}
if (pfd.revents == 0) {
continue;
}
if (smb2_service(smb2, pfd.revents) < 0) {
fprintf(stderr, "smb2_service failed with : "
"%s\n", smb2_get_error(smb2));
return -1;
}
}
return 0;
}
static void generic_status_cb(struct smb2_context *smb2, int status,
void *command_data, void *private_data)
{
struct sync_cb_data *cb_data = private_data;
cb_data->is_finished = 1;
cb_data->status = status;
cb_data->ptr = command_data;
}
struct stat_cb_data {
smb2_command_cb cb;
void *cb_data;
uint32_t status;
struct smb2_file_all_info *fs;
};
static void
stat_cb_3(struct smb2_context *smb2, int status,
void *command_data _U_, void *private_data)
{
struct stat_cb_data *stat_data = private_data;
if (stat_data->status == SMB2_STATUS_SUCCESS) {
stat_data->status = status;
}
stat_data->cb(smb2, -nterror_to_errno(stat_data->status),
stat_data->fs, stat_data->cb_data);
free(stat_data);
}
static void
stat_cb_2(struct smb2_context *smb2, int status,
void *command_data, void *private_data)
{
struct stat_cb_data *stat_data = private_data;
struct smb2_query_info_reply *rep = command_data;
struct smb2_file_all_info *fs = rep->output_buffer;
if (stat_data->status == SMB2_STATUS_SUCCESS) {
stat_data->status = status;
}
if (stat_data->status != SMB2_STATUS_SUCCESS) {
return;
}
/* Remember the fs structure so we can pass it back to the caller */
stat_data->fs = fs;
}
static void
stat_cb_1(struct smb2_context *smb2, int status,
void *command_data _U_, void *private_data)
{
struct stat_cb_data *stat_data = private_data;
if (stat_data->status == SMB2_STATUS_SUCCESS) {
stat_data->status = status;
}
}
int send_compound_stat(struct smb2_context *smb2, const char *path,
smb2_command_cb cb, void *cb_data)
{
struct stat_cb_data *stat_data;
struct smb2_create_request cr_req;
struct smb2_query_info_request qi_req;
struct smb2_close_request cl_req;
struct smb2_pdu *pdu, *next_pdu;
stat_data = malloc(sizeof(struct stat_cb_data));
if (stat_data == NULL) {
fprintf(stderr, "Failed to allocate create_data");
return -1;
}
memset(stat_data, 0, sizeof(struct stat_cb_data));
stat_data->cb = cb;
stat_data->cb_data = cb_data;
/* CREATE command */
memset(&cr_req, 0, sizeof(struct smb2_create_request));
cr_req.requested_oplock_level = SMB2_OPLOCK_LEVEL_NONE;
cr_req.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION;
cr_req.desired_access = SMB2_FILE_READ_ATTRIBUTES | SMB2_FILE_READ_EA;
cr_req.file_attributes = 0;
cr_req.share_access = SMB2_FILE_SHARE_READ | SMB2_FILE_SHARE_WRITE;
cr_req.create_disposition = SMB2_FILE_OPEN;
cr_req.create_options = 0;
cr_req.name = path;
pdu = smb2_cmd_create_async(smb2, &cr_req, stat_cb_1, stat_data);
if (pdu == NULL) {
fprintf(stderr, "Failed to create create command\n");
free(stat_data);
return -1;
}
/* QUERY INFO command */
memset(&qi_req, 0, sizeof(struct smb2_query_info_request));
qi_req.info_type = SMB2_0_INFO_FILE;
qi_req.file_info_class = SMB2_FILE_ALL_INFORMATION;
qi_req.output_buffer_length = 65535;
qi_req.additional_information = 0;
qi_req.flags = 0;
memcpy(qi_req.file_id, compound_file_id, SMB2_FD_SIZE);
next_pdu = smb2_cmd_query_info_async(smb2, &qi_req,
stat_cb_2, stat_data);
if (next_pdu == NULL) {
fprintf(stderr, "Failed to create query command\n");
free(stat_data);
smb2_free_pdu(smb2, pdu);
return -1;
}
smb2_add_compound_pdu(smb2, pdu, next_pdu);
/* CLOSE command */
memset(&cl_req, 0, sizeof(struct smb2_close_request));
cl_req.flags = SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB;
memcpy(cl_req.file_id, compound_file_id, SMB2_FD_SIZE);
next_pdu = smb2_cmd_close_async(smb2, &cl_req, stat_cb_3, stat_data);
if (next_pdu == NULL) {
fprintf(stderr, "Failed to create CLOSE command\n");
free(stat_data);
smb2_free_pdu(smb2, pdu);
return -1;
}
smb2_add_compound_pdu(smb2, pdu, next_pdu);
smb2_queue_pdu(smb2, pdu);
return 0;
}
int main(int argc, char *argv[])
{
struct smb2_context *smb2;
struct smb2_url *url;
struct sync_cb_data cb_data;
struct smb2_file_all_info *fs;
time_t t;
if (argc < 2) {
usage();
}
smb2 = smb2_init_context();
if (smb2 == NULL) {
fprintf(stderr, "Failed to init context\n");
exit(0);
}
url = smb2_parse_url(smb2, argv[1]);
if (url == NULL) {
fprintf(stderr, "Failed to parse url: %s\n",
smb2_get_error(smb2));
exit(0);
}
if (url->user) {
smb2_set_user(smb2, url->user);
}
smb2_set_security_mode(smb2, SMB2_NEGOTIATE_SIGNING_ENABLED);
if (smb2_connect_share(smb2, url->server, url->share, url->user) != 0) {
printf("smb2_connect_share failed. %s\n", smb2_get_error(smb2));
exit(10);
}
memset(&cb_data, 0, sizeof(cb_data));
if (send_compound_stat(smb2, url->path,
generic_status_cb, &cb_data) != 0) {
printf("sending compound stat failed. %s\n",
smb2_get_error(smb2));
exit(10);
}
if (wait_for_reply(smb2, &cb_data) < 0) {
printf("failed waiting for a reply. %s\n",
smb2_get_error(smb2));
exit(10);
}
if (cb_data.status != 0) {
printf("Compound command sequence returned error 0x%08x\n",
cb_data.status);
exit(10);
}
fs = cb_data.ptr;
/* Print the file_all_info structure */
printf("Attributes: ");
if (fs->basic.file_attributes & SMB2_FILE_ATTRIBUTE_READONLY) {
printf("READONLY ");
}
if (fs->basic.file_attributes & SMB2_FILE_ATTRIBUTE_HIDDEN) {
printf("HIDDEN ");
}
if (fs->basic.file_attributes & SMB2_FILE_ATTRIBUTE_SYSTEM) {
printf("SYSTEM ");
}
if (fs->basic.file_attributes & SMB2_FILE_ATTRIBUTE_DIRECTORY) {
printf("DIRECTORY ");
}
if (fs->basic.file_attributes & SMB2_FILE_ATTRIBUTE_ARCHIVE) {
printf("ARCHIVE ");
}
if (fs->basic.file_attributes & SMB2_FILE_ATTRIBUTE_NORMAL) {
printf("NORMAL ");
}
if (fs->basic.file_attributes & SMB2_FILE_ATTRIBUTE_TEMPORARY) {
printf("TMP ");
}
if (fs->basic.file_attributes & SMB2_FILE_ATTRIBUTE_SPARSE_FILE) {
printf("SPARSE ");
}
if (fs->basic.file_attributes & SMB2_FILE_ATTRIBUTE_REPARSE_POINT) {
printf("REPARSE ");
}
if (fs->basic.file_attributes & SMB2_FILE_ATTRIBUTE_COMPRESSED) {
printf("COMPRESSED ");
}
if (fs->basic.file_attributes & SMB2_FILE_ATTRIBUTE_OFFLINE) {
printf("OFFLINE ");
}
if (fs->basic.file_attributes & SMB2_FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) {
printf("NOT_CONTENT_INDEXED ");
}
if (fs->basic.file_attributes & SMB2_FILE_ATTRIBUTE_ENCRYPTED) {
printf("ENCRYPTED ");
}
if (fs->basic.file_attributes & SMB2_FILE_ATTRIBUTE_INTEGRITY_STREAM) {
printf("INTEGRITY_STREAM ");
}
if (fs->basic.file_attributes & SMB2_FILE_ATTRIBUTE_NO_SCRUB_DATA) {
printf("NO_SCRUB_DATA ");
}
printf("\n");
t = fs->basic.creation_time.tv_sec;
printf("Creation Time: %s", asctime(localtime(&t)));
t = fs->basic.last_access_time.tv_sec;
printf("Last Access Time: %s", asctime(localtime(&t)));
t = fs->basic.last_write_time.tv_sec;
printf("Last Write Time: %s", asctime(localtime(&t)));
t = fs->basic.change_time.tv_sec;
printf("Change Time: %s", asctime(localtime(&t)));
printf("Allocation Size: %" PRIu64 "\n", fs->standard.allocation_size);
printf("End Of File: %" PRIu64 "\n", fs->standard.end_of_file);
printf("Number Of Links: %d\n", fs->standard.number_of_links);
printf("Delete Pending: %s\n", fs->standard.delete_pending ?
"YES" : "NO");
printf("Directory: %s\n", fs->standard.directory ?
"YES" : "NO");
printf("Index Number: 0x%016" PRIx64 "\n", fs->index_number);
printf("EA Size : %d\n", fs->ea_size);
printf("Access Flags: ");
if (fs->standard.directory) {
if (fs->access_flags & SMB2_FILE_LIST_DIRECTORY) {
printf("LIST_DIRECTORY ");
}
if (fs->access_flags & SMB2_FILE_ADD_FILE) {
printf("ADD_FILE ");
}
if (fs->access_flags & SMB2_FILE_ADD_SUBDIRECTORY) {
printf("ADD_SUBDIRECTORY ");
}
if (fs->access_flags & SMB2_FILE_TRAVERSE) {
printf("TRAVERSE ");
}
} else {
if (fs->access_flags & SMB2_FILE_READ_DATA) {
printf("READ_DATA ");
}
if (fs->access_flags & SMB2_FILE_WRITE_DATA) {
printf("WRITE_DATA ");
}
if (fs->access_flags & SMB2_FILE_APPEND_DATA) {
printf("APPEND_DATA ");
}
if (fs->access_flags & SMB2_FILE_EXECUTE) {
printf("FILE_EXECUTE ");
}
}
if (fs->access_flags & SMB2_FILE_READ_EA) {
printf("READ_EA ");
}
if (fs->access_flags & SMB2_FILE_WRITE_EA) {
printf("WRITE_EA ");
}
if (fs->access_flags & SMB2_FILE_READ_ATTRIBUTES) {
printf("READ_ATTRIBUTES ");
}
if (fs->access_flags & SMB2_FILE_WRITE_ATTRIBUTES) {
printf("WRITE_ATTRIBUTES ");
}
if (fs->access_flags & SMB2_FILE_DELETE_CHILD) {
printf("DELETE_CHILD ");
}
if (fs->access_flags & SMB2_DELETE) {
printf("DELETE ");
}
if (fs->access_flags & SMB2_READ_CONTROL) {
printf("READ_CONTROL ");
}
if (fs->access_flags & SMB2_WRITE_DACL) {
printf("WRITE_DACL ");
}
if (fs->access_flags & SMB2_WRITE_OWNER) {
printf("WRITE_OWNER ");
}
if (fs->access_flags & SMB2_SYNCHRONIZE) {
printf("SYNCHRONIZE ");
}
if (fs->access_flags & SMB2_ACCESS_SYSTEM_SECURITY) {
printf("ACCESS_SYSTEM_SECURITY ");
}
if (fs->access_flags & SMB2_MAXIMUM_ALLOWED) {
printf("MAXIMUM_ALLOWED ");
}
if (fs->access_flags & SMB2_GENERIC_ALL) {
printf("GENERIC_ALL ");
}
if (fs->access_flags & SMB2_GENERIC_EXECUTE) {
printf("GENERIC_EXECUTE ");
}
if (fs->access_flags & SMB2_GENERIC_WRITE) {
printf("GENERIC_WRITE ");
}
if (fs->access_flags & SMB2_GENERIC_READ) {
printf("GENERIC_READ ");
}
printf("\n");
printf("Current Byte Offset: %" PRIu64 "\n", fs->current_byte_offset);
printf("Mode: ");
if (fs->access_flags & SMB2_FILE_WRITE_THROUGH) {
printf("WRITE_THROUGH ");
}
if (fs->access_flags & SMB2_FILE_SEQUENTIAL_ONLY) {
printf("SEQUENTIAL_ONLY ");
}
if (fs->access_flags & SMB2_FILE_NO_INTERMEDIATE_BUFFERING) {
printf("NO_INTERMEDIATE_BUFFERING ");
}
if (fs->access_flags & SMB2_FILE_SYNCHRONOUS_IO_ALERT) {
printf("SYNCHRONOUS_IO_ALERT ");
}
if (fs->access_flags & SMB2_FILE_SYNCHRONOUS_IO_NONALERT) {
printf("SYNCHRONOUS_IO_NONALERT ");
}
if (fs->access_flags & SMB2_FILE_DELETE_ON_CLOSE) {
printf("DELETE_ON_CLOSE ");
}
printf("\n");
printf("Alignment Requirement: %d\n", fs->alignment_requirement);
printf("Name: %s\n", fs->name);
smb2_free_data(smb2, fs);
smb2_disconnect_share(smb2);
smb2_destroy_url(url);
smb2_destroy_context(smb2);
return 0;
}
libsmb2-6.2/examples/smb2-truncate-sync.c 0000664 0001750 0001750 00000005577 14732155517 017457 0 ustar polpy polpy /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */
/*
Copyright (C) 2016 by Ronnie Sahlberg
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define _GNU_SOURCE
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "smb2.h"
#include "libsmb2.h"
#include "libsmb2-raw.h"
int usage(void)
{
fprintf(stderr, "Usage:\n"
"smb2-truncate-sync \n\n"
"URL format: "
"smb://[@]>[:]//\n");
exit(1);
}
int main(int argc, char *argv[])
{
struct smb2_context *smb2;
struct smb2_url *url;
if (argc < 3) {
usage();
}
smb2 = smb2_init_context();
if (smb2 == NULL) {
fprintf(stderr, "Failed to init context\n");
exit(0);
}
url = smb2_parse_url(smb2, argv[1]);
if (url == NULL) {
fprintf(stderr, "Failed to parse url: %s\n",
smb2_get_error(smb2));
exit(0);
}
smb2_set_security_mode(smb2, SMB2_NEGOTIATE_SIGNING_ENABLED);
if (smb2_connect_share(smb2, url->server, url->share, url->user) != 0) {
printf("smb2_connect_share failed. %s\n", smb2_get_error(smb2));
exit(10);
}
if (smb2_truncate(smb2, url->path, strtoll(argv[2], NULL, 10)) < 0) {
printf("smb2_truncate failed. %s\n", smb2_get_error(smb2));
exit(10);
}
smb2_disconnect_share(smb2);
smb2_destroy_url(url);
smb2_destroy_context(smb2);
return 0;
}
libsmb2-6.2/examples/Makefile.am 0000664 0001750 0001750 00000002536 14732155517 015677 0 ustar polpy polpy noinst_PROGRAMS = smb2-cat-async smb2-cat-sync \
smb2-ftruncate-sync \
smb2-ls-async \
smb2-put-async \
smb2-put-sync \
smb2-raw-fsstat-async \
smb2-raw-getsd-async \
smb2-raw-stat-async \
smb2-readlink \
smb2-lsa-lookupsids \
smb2-lseek-sync \
smb2-share-enum \
smb2-share-info \
smb2-stat-sync \
smb2-statvfs-sync \
smb2-truncate-sync \
smb2-rename-sync \
smb2-CMD-FIND \
smb2-server-sync
AM_CPPFLAGS = \
-I$(abs_top_srcdir)/include \
-I$(abs_top_srcdir)/include/smb2 \
"-D_U_=__attribute__((unused))" \
-Wall -Werror
COMMON_LIBS = ../lib/libsmb2.la
smb2_cat_async_LDADD = $(COMMON_LIBS)
smb2_cat_sync_LDADD = $(COMMON_LIBS)
smb2_ftruncate_sync_LDADD = $(COMMON_LIBS)
smb2_ls_async_LDADD = $(COMMON_LIBS)
smb2_put_async_LDADD = $(COMMON_LIBS)
smb2_put_sync_LDADD = $(COMMON_LIBS)
smb2_raw_fsstat_async_LDADD = $(COMMON_LIBS)
smb2_raw_getsd_async_LDADD = $(COMMON_LIBS)
smb2_raw_stat_async_LDADD = $(COMMON_LIBS)
smb2_readlink_LDADD = $(COMMON_LIBS)
smb2_lsa_lookupsids_LDADD = $(COMMON_LIBS)
smb2_lseek_sync_LDADD = $(COMMON_LIBS)
smb2_share_enum_LDADD = $(COMMON_LIBS)
smb2_share_info_LDADD = $(COMMON_LIBS)
smb2_stat_sync_LDADD = $(COMMON_LIBS)
smb2_statvfs_sync_LDADD = $(COMMON_LIBS)
smb2_truncate_sync_LDADD = $(COMMON_LIBS)
smb2_rename_sync_LDADD = $(COMMON_LIBS)
smb2_CMD_FIND_LDADD = $(COMMON_LIBS)
smb2_server_sync_LDADD = $(COMMON_LIBS)
libsmb2-6.2/examples/smb2-rename-sync.c 0000664 0001750 0001750 00000005700 14732155517 017065 0 ustar polpy polpy /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */
/*
Copyright (C) 2022 by Ronnie Sahlberg
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define _GNU_SOURCE
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "smb2.h"
#include "libsmb2.h"
#include "libsmb2-raw.h"
int usage(void)
{
fprintf(stderr, "Usage:\n"
"smb2-rename-sync \n\n"
"URL format: "
"smb://[@]>[:]//\n");
exit(1);
}
int main(int argc, char *argv[])
{
struct smb2_context *smb2;
struct smb2_url *url;
if (argc < 4) {
usage();
}
smb2 = smb2_init_context();
if (smb2 == NULL) {
fprintf(stderr, "Failed to init context\n");
exit(0);
}
url = smb2_parse_url(smb2, argv[1]);
if (url == NULL) {
fprintf(stderr, "Failed to parse url: %s\n",
smb2_get_error(smb2));
exit(0);
}
smb2_set_security_mode(smb2, SMB2_NEGOTIATE_SIGNING_ENABLED);
if (smb2_connect_share(smb2, url->server, url->share, url->user) != 0) {
printf("smb2_connect_share failed. %s\n", smb2_get_error(smb2));
exit(10);
}
printf("Renaming %s -> %s\n", argv[2], argv[3]);
if (smb2_rename(smb2, argv[2], argv[3]) < 0) {
printf("smb2_rename failed. %s\n", smb2_get_error(smb2));
exit(10);
}
smb2_disconnect_share(smb2);
smb2_destroy_url(url);
smb2_destroy_context(smb2);
return 0;
}
libsmb2-6.2/examples/smb2-raw-getsd-async.c 0000664 0001750 0001750 00000030232 14732155517 017652 0 ustar polpy polpy /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */
/*
Copyright (C) 2017 by Ronnie Sahlberg
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define _GNU_SOURCE
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "smb2.h"
#include "libsmb2.h"
#include "libsmb2-raw.h"
int usage(void)
{
fprintf(stderr, "Usage:\n"
"smb2-raw-getsd-async \n\n"
"URL format: "
"smb://[@]>[:]//\n");
exit(1);
}
struct sync_cb_data {
int is_finished;
int status;
void *ptr;
};
static int wait_for_reply(struct smb2_context *smb2,
struct sync_cb_data *cb_data)
{
while (!cb_data->is_finished) {
struct pollfd pfd;
pfd.fd = smb2_get_fd(smb2);
pfd.events = smb2_which_events(smb2);
if (poll(&pfd, 1, 1000) < 0) {
fprintf(stderr, "Poll failed");
return -1;
}
if (pfd.revents == 0) {
continue;
}
if (smb2_service(smb2, pfd.revents) < 0) {
fprintf(stderr, "smb2_service failed with : "
"%s\n", smb2_get_error(smb2));
return -1;
}
}
return 0;
}
static void generic_status_cb(struct smb2_context *smb2, int status,
void *command_data, void *private_data)
{
struct sync_cb_data *cb_data = private_data;
cb_data->is_finished = 1;
cb_data->status = status;
cb_data->ptr = command_data;
}
struct stat_cb_data {
smb2_command_cb cb;
void *cb_data;
uint32_t status;
struct smb2_security_descriptor *sd;
};
static void
stat_cb_3(struct smb2_context *smb2, int status,
void *command_data _U_, void *private_data)
{
struct stat_cb_data *stat_data = private_data;
if (stat_data->status == SMB2_STATUS_SUCCESS) {
stat_data->status = status;
}
stat_data->cb(smb2, -nterror_to_errno(stat_data->status),
stat_data->sd, stat_data->cb_data);
free(stat_data);
}
static void
stat_cb_2(struct smb2_context *smb2, int status,
void *command_data, void *private_data)
{
struct stat_cb_data *stat_data = private_data;
struct smb2_query_info_reply *rep = command_data;
struct smb2_security_descriptor *sd = rep->output_buffer;
if (stat_data->status == SMB2_STATUS_SUCCESS) {
stat_data->status = status;
}
if (stat_data->status != SMB2_STATUS_SUCCESS) {
return;
}
/* Remember the sd structure so we can pass it back to the caller */
stat_data->sd = sd;
}
static void
stat_cb_1(struct smb2_context *smb2, int status,
void *command_data _U_, void *private_data)
{
struct stat_cb_data *stat_data = private_data;
if (stat_data->status == SMB2_STATUS_SUCCESS) {
stat_data->status = status;
}
}
static int
send_compound_stat(struct smb2_context *smb2, const char *path,
smb2_command_cb cb, void *cb_data)
{
struct stat_cb_data *stat_data;
struct smb2_create_request cr_req;
struct smb2_query_info_request qi_req;
struct smb2_close_request cl_req;
struct smb2_pdu *pdu, *next_pdu;
stat_data = malloc(sizeof(struct stat_cb_data));
if (stat_data == NULL) {
fprintf(stderr, "Failed to allocate create_data");
return -1;
}
memset(stat_data, 0, sizeof(struct stat_cb_data));
stat_data->cb = cb;
stat_data->cb_data = cb_data;
/* CREATE command */
memset(&cr_req, 0, sizeof(struct smb2_create_request));
cr_req.requested_oplock_level = SMB2_OPLOCK_LEVEL_NONE;
cr_req.impersonation_level = SMB2_IMPERSONATION_IMPERSONATION;
cr_req.desired_access = SMB2_READ_CONTROL;
cr_req.file_attributes = 0;
cr_req.share_access = SMB2_FILE_SHARE_READ | SMB2_FILE_SHARE_WRITE;
cr_req.create_disposition = SMB2_FILE_OPEN;
cr_req.create_options = 0;
cr_req.name = path;
pdu = smb2_cmd_create_async(smb2, &cr_req, stat_cb_1, stat_data);
if (pdu == NULL) {
fprintf(stderr, "Failed to create create command\n");
free(stat_data);
return -1;
}
/* QUERY INFO command */
memset(&qi_req, 0, sizeof(struct smb2_query_info_request));
qi_req.info_type = SMB2_0_INFO_SECURITY;
qi_req.output_buffer_length = 65535;
qi_req.additional_information =
SMB2_OWNER_SECURITY_INFORMATION |
SMB2_GROUP_SECURITY_INFORMATION |
SMB2_DACL_SECURITY_INFORMATION;
memcpy(qi_req.file_id, compound_file_id, SMB2_FD_SIZE);
next_pdu = smb2_cmd_query_info_async(smb2, &qi_req,
stat_cb_2, stat_data);
if (next_pdu == NULL) {
fprintf(stderr, "Failed to create query command\n");
free(stat_data);
smb2_free_pdu(smb2, pdu);
return -1;
}
smb2_add_compound_pdu(smb2, pdu, next_pdu);
/* CLOSE command */
memset(&cl_req, 0, sizeof(struct smb2_close_request));
cl_req.flags = SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB;
memcpy(cl_req.file_id, compound_file_id, SMB2_FD_SIZE);
next_pdu = smb2_cmd_close_async(smb2, &cl_req, stat_cb_3, stat_data);
if (next_pdu == NULL) {
fprintf(stderr, "Failed to create close command\n");
free(stat_data);
smb2_free_pdu(smb2, pdu);
return -1;
}
smb2_add_compound_pdu(smb2, pdu, next_pdu);
smb2_queue_pdu(smb2, pdu);
return 0;
}
static void
print_sid(struct smb2_sid *sid)
{
int i;
uint64_t ia = 0;
if (sid == NULL) {
printf("No SID");
return;
}
printf("S-1");
for(i = 0; i < SID_ID_AUTH_LEN; i++) {
ia <<= 8;
ia |= sid->id_auth[i];
}
if (ia <= 0xffffffff) {
printf("-%" PRIu64, ia);
} else {
printf("-0x%012" PRIx64, ia);
}
for (i = 0; i < sid->sub_auth_count; i++) {
printf("-%u", sid->sub_auth[i]);
}
}
static void
print_ace(struct smb2_ace *ace)
{
printf("ACE: ");
printf("Type:%d ", ace->ace_type);
printf("Flags:0x%02x ", ace->ace_flags);
switch (ace->ace_type) {
case SMB2_ACCESS_ALLOWED_ACE_TYPE:
case SMB2_ACCESS_DENIED_ACE_TYPE:
case SMB2_SYSTEM_AUDIT_ACE_TYPE:
case SMB2_SYSTEM_MANDATORY_LABEL_ACE_TYPE:
printf("Mask:0x%08x ", ace->mask);
print_sid(ace->sid);
break;
default:
printf("can't print this type");
}
printf("\n");
}
static void
print_acl(struct smb2_acl *acl)
{
struct smb2_ace *ace;
printf("Revision: %d\n", acl->revision);
printf("Ace count: %d\n", acl->ace_count);
for (ace = acl->aces; ace; ace = ace->next) {
print_ace(ace);
}
};
static void
print_security_descriptor(struct smb2_security_descriptor *sd)
{
printf("Revision: %d\n", sd->revision);
printf("Control: (0x%08x) ", sd->control);
if (sd->control & SMB2_SD_CONTROL_SR) {
printf("SR ");
}
if (sd->control & SMB2_SD_CONTROL_RM) {
printf("RM ");
}
if (sd->control & SMB2_SD_CONTROL_PS) {
printf("PS ");
}
if (sd->control & SMB2_SD_CONTROL_PD) {
printf("PD ");
}
if (sd->control & SMB2_SD_CONTROL_SI) {
printf("SI ");
}
if (sd->control & SMB2_SD_CONTROL_DI) {
printf("DI ");
}
if (sd->control & SMB2_SD_CONTROL_SC) {
printf("SC ");
}
if (sd->control & SMB2_SD_CONTROL_DC) {
printf("DC ");
}
if (sd->control & SMB2_SD_CONTROL_DT) {
printf("DT ");
}
if (sd->control & SMB2_SD_CONTROL_SS) {
printf("SS ");
}
if (sd->control & SMB2_SD_CONTROL_SD) {
printf("SD ");
}
if (sd->control & SMB2_SD_CONTROL_SP) {
printf("SP ");
}
if (sd->control & SMB2_SD_CONTROL_DD) {
printf("DD ");
}
if (sd->control & SMB2_SD_CONTROL_DP) {
printf("DP ");
}
if (sd->control & SMB2_SD_CONTROL_GD) {
printf("GD ");
}
if (sd->control & SMB2_SD_CONTROL_OD) {
printf("OD ");
}
printf("\n");
if (sd->owner) {
printf("Owner SID: ");
print_sid(sd->owner);
printf("\n");
}
if (sd->group) {
printf("Group SID: ");
print_sid(sd->group);
printf("\n");
}
if (sd->dacl) {
printf("DACL:\n");
print_acl(sd->dacl);
}
}
int main(int argc, char *argv[])
{
struct smb2_context *smb2;
struct smb2_url *url;
struct sync_cb_data cb_data;
struct smb2_security_descriptor *sd;
if (argc < 2) {
usage();
}
smb2 = smb2_init_context();
if (smb2 == NULL) {
fprintf(stderr, "Failed to init context\n");
exit(0);
}
url = smb2_parse_url(smb2, argv[1]);
if (url == NULL) {
fprintf(stderr, "Failed to parse url: %s\n",
smb2_get_error(smb2));
exit(0);
}
smb2_set_security_mode(smb2, SMB2_NEGOTIATE_SIGNING_ENABLED);
if (smb2_connect_share(smb2, url->server, url->share, url->user) != 0) {
printf("smb2_connect_share failed. %s\n", smb2_get_error(smb2));
exit(10);
}
memset(&cb_data, 0, sizeof(cb_data));
if (send_compound_stat(smb2, url->path,
generic_status_cb, &cb_data) != 0) {
printf("sending compound stat failed. %s\n",
smb2_get_error(smb2));
exit(10);
}
if (wait_for_reply(smb2, &cb_data) < 0) {
printf("failed waiting for a reply. %s\n",
smb2_get_error(smb2));
exit(10);
}
if (cb_data.status != 0) {
printf("Compound command sequence returned error 0x%08x\n",
cb_data.status);
exit(10);
}
sd = cb_data.ptr;
print_security_descriptor(sd);
smb2_free_data(smb2, sd);
smb2_disconnect_share(smb2);
smb2_destroy_url(url);
smb2_destroy_context(smb2);
return 0;
}
libsmb2-6.2/examples/smb2-share-info.c 0000664 0001750 0001750 00000015201 14732155517 016674 0 ustar polpy polpy /* -*- mode:c; tab-width:8; c-basic-offset:8; indent-tabs-mode:nil; -*- */
/*
Copyright (C) 2020 by Ronnie Sahlberg
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define _GNU_SOURCE
#include
#include
#include
#include
#include
#include
#include