Skip to content

Commit

Permalink
License, cleanup, updated dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
nozomi-slibero committed Nov 14, 2023
1 parent 480ef8f commit 124c9f7
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 27 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
cmake-build*
cmake-build*
bin/
.vscode
build/
.cache/
59 changes: 59 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"code-block-style": {
"style": "fenced"
},
"code-fence-style": {
"style": "backtick"
},
"emphasis-style": {
"style": "asterisk"
},
"fenced-code-language": {
"allowed_languages": [
"bash",
"html",
"javascript",
"json",
"markdown",
"text"
],
"language_only": true
},
"heading-style": {
"style": "atx"
},
"hr-style": {
"style": "---"
},
"line-length": {
"strict": false,
"code_blocks": false
},
"no-duplicate-heading": {
"siblings_only": true
},
"ol-prefix": {
"style": "ordered"
},
"proper-names": {
"code_blocks": false,
"names": [
"Cake.Markdownlint",
"CommonMark",
"JavaScript",
"Markdown",
"markdown-it",
"markdownlint",
"Node.js"
]
},
"reference-links-images": {
"shortcut_syntax": true
},
"strong-style": {
"style": "asterisk"
},
"ul-style": {
"style": "dash"
}
}
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ endif()
if (${BUILD_WITH_KRB5})
message(STATUS "Kerberos support is ENABLED")
include_directories(BEFORE SYSTEM ${GSSAPI_INCLUDE_DIR})
# include_directories(BEFORE SYSTEM ${GSSAPI_INCLUDE_DIR}/gssapi)
# include_directories(BEFORE SYSTEM ${GSSAPI_INCLUDE_DIR}/krb5/)
else()
message(STATUS "Kerberos support is DISABLED")

Expand All @@ -69,7 +71,9 @@ include_directories(${LIBJSONC_DIR})
include_directories(${LIBSMB2_DIR}/include/smb2)
include_directories(${LIBSMB2_DIR}/include)


if (${BUILD_WITH_KRB5})
link_libraries(${GSSAPI_LIBRARY} ${KRB_LIBRARY} smb2 json-c)
endif()
add_executable(n2os_smb_client n2os-smb-client.c)

if (${BUILD_WITH_KRB5})
Expand Down
16 changes: 16 additions & 0 deletions COPYING
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
n2os-smb-client is released under the BSD 2-Clause License license.

Included 3rd party software
===========================
This software includes libsmb2 and json-c, with their original repositories linked
as github modules.

libsmb2 is released under LGPL 2.1 (or later) for what concerns lib and include directories,
and the 2-Clause BSD License for its examples directory.
Copyright (C) 2016 by Ronnie Sahlberg <ronniesahlberg@gmail.com>

json-c is release under the MIT license.
Copyright (c) 2009-2012 Eric Haszlakiewicz
Copyright (c) 2004, 2005 Metaparadigm Pte Ltd

See their respective subdirectories for detailed license information.
17 changes: 17 additions & 0 deletions Dockerfile.linux
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# docker build -t "smblinux:latest" -f Dockerfile.linux .
# docker run --rm -v "$PWD/bin":/usr/src/n2os-smb-client/bin:Z smblinux:latest
# docker run --rm -ti -v "$PWD/bin":/usr/src/n2os-smb-client/bin:Z smblinux:latest /bin/bash

# FROM debian:buster-slim # no upx at the moment
FROM debian:bullseye-slim

WORKDIR /usr/src/n2os-smb-client
COPY . .

# hadolint ignore=DL3008
RUN apt-get update && \
apt-get install -y --no-install-recommends git build-essential upx-ucl cmake libssl-dev libkrb5-dev && \
apt-get clean && rm -rf /var/lib/apt/lists/* && \
ldconfig

CMD [ "./build.linux.sh" ]
24 changes: 24 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
BSD 2-Clause License

Copyright (c) 2013-2023, Nozomi Networks Inc.

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.
32 changes: 22 additions & 10 deletions readme.md → README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
# n2os-smb-client
**THIS IS IN SUPER ALPHA STAGE**

This is a custom make smb/cifs client with libsmb2 statically linked.
This is a custom smb/cifs client with libsmb2 statically linked.

We need this to avoid adding all the samba stuff to our n2os firmware.

As default libsmb2 doesn't build under FreeBSD we have forked it https://github.com/NozomiNetworks/libsmb2 and this project uses it as submodules
## Building

### FreeBSD version

## Building
Prerequisite: install kerberos
Optional prerequisite: install kerberos if you want Kerberos support
```
cd /usr/ports/security/krb5
# (there should be a single Makefile in the folder)
sudo make install clean
```


```
git submodule update --init --recursive
cmake . -DCMAKE_BUILD_TYPE=Release
make
strip -s n2os_smb_client
```

Linux version
### Linux version

```
docker run -it -v $(pwd):/n2os-smb-client debian:buster-slim /bin/bash
apt update
Expand All @@ -36,8 +33,23 @@ strip -s n2os_smb_client
upx --best n2os_smb_client
```

A [Dockerfile](Dockerfile.linux) is also provided to simplify the build.
You can use it as:

```
docker build -t "smblinux:latest" -f Dockerfile.linux .
docker run --rm -v "$PWD/bin":/usr/src/n2os-smb-client/bin:Z smblinux:latest
```

### Kerberos support

To build with kerberos support, provided that the dependencies are met, just add
to the cmake commandline `-DBUILD_WITH_KRB5=true`.

## Usage
Usage is pretty simple. This client right now can just do three simple operations: ls, get and put.

Usage is pretty simple. This client right now can just do three simple
operations: ls, get and put.

**Note that connection password can be passed using env variable N2OS_SMB_PASSWORD**

Expand Down
2 changes: 1 addition & 1 deletion build.bsd.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#/bin/sh
#!/bin/sh

git submodule update --init --recursive
cmake . -DCMAKE_BUILD_TYPE=Release
Expand Down
11 changes: 6 additions & 5 deletions build.linux.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#/bin/sh
#!/bin/sh
set -ex

apt update
apt install -y git build-essential upx cmake libssl-dev libkrb5-dev
# apt update
# apt install -y git build-essential upx-ucl cmake libssl-dev libkrb5-dev

git submodule update --init --recursive
# git submodule update --init --recursive
cmake . -DCMAKE_BUILD_TYPE=Release
make
strip -s n2os_smb_client
upx --best n2os_smb_client

cp n2os_smb_client bin/n2os_smb_client.linux
cp n2os_smb_client bin/n2os_smb_client.linux
2 changes: 1 addition & 1 deletion deps/json-c
Submodule json-c updated 183 files
19 changes: 12 additions & 7 deletions n2os-smb-client.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// n2os-smb-client Samba v2/3 custom client
// Copyright (c) 2013-2020, Nozomi Networks Inc. All rights reserved.
// Copyright (c) 2013-2023, Nozomi Networks Inc. All rights reserved.

#include <errno.h>
#include <fcntl.h>
Expand Down Expand Up @@ -34,7 +34,7 @@ enum
#define MAXBUF (1024 * 64)
#define ENV_PASSWORD_VAR "N2OS_SMB_PASSWORD"

#define VERSION "0.3.4"
#define VERSION "0.3.5"
#define ECMDLINE 4
#define ESMBINIT 5
#define ESMBPARSE 6
Expand All @@ -53,7 +53,7 @@ enum
int usage(void)
{
fprintf(stderr,
"n2os-smb-client v.%s - (c) 2020 Nozomi Networks Inc.\n\n"
"n2os-smb-client v.%s - (c) 2020-2023 Nozomi Networks Inc.\n\n"
"Usage:\n"
"n2os-smb-client ls <smb2-url>\n"
"n2os-smb-client del <smb2-url>\n"
Expand Down Expand Up @@ -141,7 +141,8 @@ int ls(struct smb2_context* smb2, const char* path)
return ESMBOPENDIR;
}

struct json_object *json_listing, *json_entry;
struct json_object *json_listing;
struct json_object *json_entry;
json_listing = json_object_new_array();

while ((ent = smb2_readdir(smb2, dir)))
Expand Down Expand Up @@ -193,7 +194,9 @@ int ls(struct smb2_context* smb2, const char* path)
int get(struct smb2_context* smb2, const char* source_file, const char* destination_file)
{
struct smb2fh* fh;
int count, result_code = 0, nwritten;
int count;
int result_code = 0;
int nwritten;
int fd;
uint8_t buf[MAXBUF];
unsigned int pos = 0;
Expand Down Expand Up @@ -278,7 +281,8 @@ int get(struct smb2_context* smb2, const char* source_file, const char* destinat

int del(struct smb2_context* smb2, const char* filename)
{
int result_code = 0, unlink_error = 0;
int result_code = 0;
int unlink_error = 0;

if ((unlink_error = smb2_unlink(smb2, filename)) != 0)
{
Expand All @@ -292,7 +296,8 @@ int put(const char* source_file, struct smb2_context* smb2, const char* destinat
{
struct smb2fh* fh;
unsigned int count;
int fd, result_code = 0;
int fd;
int result_code = 0;
uint8_t buf[MAXBUF];
unsigned int max_write = MAXBUF;

Expand Down

0 comments on commit 124c9f7

Please sign in to comment.