atsign-foundation / noports

Connect to any device with no external listening ports open
https://noports.com
BSD 3-Clause "New" or "Revised" License
263 stars 15 forks source link

C daemon doesn't statically link cjson #1100

Closed cpswan closed 1 month ago

cpswan commented 1 month ago

Describe the bug

./sshnpd: error while loading shared libraries: libcjson.so.1: cannot open shared object file: No such file or directory

Steps to reproduce

  1. First I clone this repo to a clean build VM (Debian 12 with OpenWRT build tools)
  2. Then I git switch c_daemon
  3. And then follow the build instructions
  4. Then copy the resulting sshnpd binary to a clean (Ubuntu 24.04 cloud image) test VM
  5. chmod +x sshnpd then ./sshnpd

Expected behavior

sshnpd shows help

Additional context

If I install cjson with sudo apt install libcjson1 then I can get usage info from the daemon:

Usage:
Version : 0.1.0

    --help                        show this help message and exit
    -k, --key-file=<str>          Path to the key file
    -a, --atsign=<str>            Atsign to use (mandatory)
    -m, --manager=<str>           Manager to use (mandatory)
    -d, --device=<str>            Device to use
    -s, --sshpublickey            Generate ssh public key
    -h, --hide                    Hide device from device entry (still responds to pings)
    -v, --verbose                 Verbose output
    --permit-open=<str>           Manager to use (mandatory)
    --ssh-algorithm=<str>         SSH algorithm to use
    --ephemeral-permission=<str>  Ephemeral permission to use
    --root-domain=<str>           Root domain to use
    --local-sshd-port=<int>       Local sshd port to use

Invalid Argument(s): Option atsign is mandatory
cpswan commented 1 month ago

Weirdly it seems that sshnpd does run on the build VM despite it seemingly not having libcjson1 installed.

XavierChanth commented 1 month ago

We are deferring the cjson build via cmake: https://github.com/atsign-foundation/at_c/blob/trunk/cmake/find_cjson.cmake

I believe you can modify the behaviour of the cjson build to be explicitly static: https://github.com/DaveGamble/cJSON/blob/324973008ced4ea03d1626a00915d0399ecbd9db/CMakeLists.txt#L117-L120

Based on what I saw in the cjson repo, you should be able to turn this off: https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html

and it should build statically:

cmake -B build -S . -DBUILD_SHARED_LIBS=off ...

XavierChanth commented 1 month ago

This should be off by default (undefined actually), but it is possible another project on your build machine has created a cache entry for cjson with it turned on.

cpswan commented 1 month ago

Confirmed that -DBUILD_SHARED_LIBS=off gets me a binary that works without installing libcjson1 :)