Skip to content

Commit

Permalink
Merge branch 'main' into fix-8556
Browse files Browse the repository at this point in the history
* main: (36 commits)
  lib/protocol: Ignore inode time when xattr&ownership is ignored (fixes syncthing#8654) (syncthing#8655)
  lib/fs: Try to remove read only Windows files (fixes syncthing#3744) (syncthing#8650)
  gui: Add copy to clipboard, share by email, and share by SMS buttons to device IDs (fixes syncthing#2771, ref syncthing#3868) (syncthing#7984)
  gui, man, authors: Update docs, translations, and contributors
  build: Add GitHub actions build for Windows (syncthing#8627)
  gui: Fix connection type icon width (fixes syncthing#8592) (syncthing#8644)
  gui: Adjust connection type icon size scaling and alignment (syncthing#8645)
  docker: Use healthcheck endpoint (syncthing#8640)
  lib/connections: Use adaptive write size for rate limited connections (fixes syncthing#8630) (syncthing#8631)
  gui: Mark devices that haven't connected for a long time (fixes syncthing#7703) (syncthing#8530)
  gui: Fix rescan interval when add encrypted folder with watch for changes enabled (fixes syncthing#8570) (syncthing#8571)
  gui: Always show Out of Sync Items for remote devices (syncthing#8632)
  lib/fs: Let xattr test avoid non-test attributes (fixes syncthing#8601) (syncthing#8628)
  build: Add GitHub actions build for Windows
  gui, man, authors: Update docs, translations, and contributors
  gui: Display folder and device count number (syncthing#8615)
  gui, man, authors: Update docs, translations, and contributors
  lib/model, lib/protocol: Fix file comparisons (fixes syncthing#8594) (syncthing#8603)
  lib/scanner: More sensible debug output (syncthing#8596)
  gui: Allow automatic device ID selection on WebKit browsers (ref syncthing#8544) (syncthing#8597)
  ...
  • Loading branch information
calmh committed Nov 8, 2022
2 parents 8be5288 + ce2a686 commit db49472
Show file tree
Hide file tree
Showing 99 changed files with 2,049 additions and 1,839 deletions.
117 changes: 117 additions & 0 deletions .github/workflows/build-syncthing.yaml
@@ -0,0 +1,117 @@
name: Build Syncthing

on:
pull_request:
push:

env:
# The go version to use for builds.
GO_VERSION: "1.19.3"

# Optimize compatibility on the slow archictures.
GO386: softfloat
GOARM: "5"
GOMIPS: softfloat

# Avoid hilarious amounts of obscuring log output when running tests.
LOGGER_DISCARD: "1"

# A note on actions and third party code... The actions under actions/ (like
# `uses: actions/checkout`) are maintained by GitHub, and we need to trust
# GitHub to maintain their code and infrastructure or we're in deep shit in
# general. The same doesn't necessarily apply to other actions authors, so
# some care needs to be taken when adding steps, especially in the paths
# that lead up to code being packaged and signed.

jobs:

#
# Windows, quick build and test, runs always
#

build-windows:
name: Build and test on Windows
runs-on: windows-latest
steps:
- name: Set git to use LF
# Without this, the checkout will happen with CRLF line endings,
# which is fine for the source code but messes up tests that depend
# on data on disk being as expected. Ideally, those tests should be
# fixed, but not today.
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- uses: actions/checkout@v3

- uses: actions/setup-go@v3
# `cache: true` gives us automatic caching of modules and build
# cache, speeding up builds. The cache key is dependent on the Go
# version and our go.sum contents.
with:
go-version: ${{ env.GO_VERSION }}
cache: true

- name: Build and test
run: |
go run build.go
go run build.go test
#
# Windows, build signed packages
#

package-windows:
name: Create packages for Windows
runs-on: windows-latest
# We only run this job for release pushes.
if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/release')
# This is also enforced by the environment which contains the secrets.
environment: signing
needs:
- build-windows
steps:
- name: Set git to use LF
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- uses: actions/checkout@v3
# `fetch-depth: 0` because we want to check out the entire repo
# including tags and branches, not just the latest commit which
# lacks version info.
with:
fetch-depth: 0

- uses: actions/setup-go@v3
with:
go-version: ${{ env.GO_VERSION }}

- uses: actions/cache@v3
with:
path: |
~\AppData\Local\go-build
~\go\pkg\mod
key: ${{ runner.os }}-go-${{ env.GOVERSION }}-package-${{ hashFiles('**/go.sum') }}

- name: Install dependencies
run: |
go install github.com/josephspurrier/goversioninfo/cmd/goversioninfo@v1.4.0
- name: Create packages
run: |
go run build.go -goarch amd64 zip
go run build.go -goarch arm zip
go run build.go -goarch arm64 zip
go run build.go -goarch 386 zip
env:
CODESIGN_SIGNTOOL: ${{ secrets.CODESIGN_SIGNTOOL }}
CODESIGN_CERTIFICATE_BASE64: ${{ secrets.CODESIGN_CERTIFICATE_BASE64 }}
CODESIGN_CERTIFICATE_PASSWORD: ${{ secrets.CODESIGN_CERTIFICATE_PASSWORD }}
CODESIGN_TIMESTAMP_SERVER: ${{ secrets.CODESIGN_TIMESTAMP_SERVER }}

- name: Archive artifacts
uses: actions/upload-artifact@v3
with:
name: packages
path: syncthing-windows-*.zip
3 changes: 3 additions & 0 deletions AUTHORS
Expand Up @@ -18,6 +18,7 @@ Adam Piggott (ProactiveServices) <aD@simplypeachy.co.uk> <simplypeachy@users.nor
Adel Qalieh (adelq) <aqalieh95@gmail.com> <adelq@users.noreply.github.com>
Alan Pope <alan@popey.com>
Alberto Donato <albertodonato@users.noreply.github.com>
Aleksey Vasenev <margtu-fivt@ya.ru>
Alessandro G. (alessandro.g89) <alessandro.g89@gmail.com>
Alex Lindeman <139387+aelindeman@users.noreply.github.com>
Alex Xu <alex.hello71@gmail.com>
Expand Down Expand Up @@ -100,6 +101,7 @@ Elias Jarlebring (jarlebring) <jarlebring@gmail.com>
Elliot Huffman <thelich2@gmail.com>
Emil Hessman (ceh) <emil@hessman.se>
Eng Zer Jun <engzerjun@gmail.com>
entity0xfe <109791748+entity0xfe@users.noreply.github.com>
Eric Lesiuta <elesiuta@gmail.com>
Eric P <eric@kastelo.net>
Erik Meitner (WSGCSysadmin) <e.meitner@willystreet.coop>
Expand Down Expand Up @@ -216,6 +218,7 @@ mv1005 <49659413+mv1005@users.noreply.github.com>
Nate Morrison (nrm21) <natemorrison@gmail.com>
Naveen <172697+naveensrinivasan@users.noreply.github.com>
Nicholas Rishel (PrototypeNM1) <rishel.nick@gmail.com> <PrototypeNM1@users.noreply.github.com>
Nick Busey <NickBusey@users.noreply.github.com>
Nico Stapelbroek <3368018+nstapelbroek@users.noreply.github.com>
Nicolas Braud-Santoni <nicolas@braud-santoni.eu>
Nicolas Perraut <n.perraut@gmail.com>
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Expand Up @@ -15,15 +15,15 @@ EXPOSE 8384 22000/tcp 22000/udp 21027/udp

VOLUME ["/var/syncthing"]

RUN apk add --no-cache ca-certificates su-exec tzdata libcap
RUN apk add --no-cache ca-certificates curl libcap su-exec tzdata

COPY --from=builder /src/syncthing /bin/syncthing
COPY --from=builder /src/script/docker-entrypoint.sh /bin/entrypoint.sh

ENV PUID=1000 PGID=1000 HOME=/var/syncthing PCAP=
ENV PUID=1000 PGID=1000 HOME=/var/syncthing

HEALTHCHECK --interval=1m --timeout=10s \
CMD nc -z 127.0.0.1 8384 || exit 1
CMD curl -fkLsS -m 2 127.0.0.1:8384/rest/noauth/health | grep -o --color=never OK || exit 1

ENV STGUIADDRESS=0.0.0.0:8384
ENTRYPOINT ["/bin/entrypoint.sh", "/bin/syncthing", "-home", "/var/syncthing/config"]
2 changes: 1 addition & 1 deletion Dockerfile.buildx
Expand Up @@ -5,7 +5,7 @@ EXPOSE 8384 22000/tcp 22000/udp 21027/udp

VOLUME ["/var/syncthing"]

RUN apk add --no-cache ca-certificates su-exec tzdata
RUN apk add --no-cache ca-certificates su-exec tzdata libcap

COPY ./syncthing-linux-$TARGETARCH /bin/syncthing
COPY ./script/docker-entrypoint.sh /bin/entrypoint.sh
Expand Down
30 changes: 29 additions & 1 deletion build.go
Expand Up @@ -15,6 +15,7 @@ import (
"bytes"
"compress/flate"
"compress/gzip"
"encoding/base64"
"encoding/json"
"errors"
"flag"
Expand Down Expand Up @@ -1383,6 +1384,33 @@ func windowsCodesign(file string) {
args := []string{"sign", "/fd", algo}
if f := os.Getenv("CODESIGN_CERTIFICATE_FILE"); f != "" {
args = append(args, "/f", f)
} else if b := os.Getenv("CODESIGN_CERTIFICATE_BASE64"); b != "" {
// Decode the PFX certificate from base64.
bs, err := base64.RawStdEncoding.DecodeString(b)
if err != nil {
log.Println("Codesign: signing failed: decoding base64:", err)
return
}

// Write it to a temporary file
f, err := os.CreateTemp("", "codesign-*.pfx")
if err != nil {
log.Println("Codesign: signing failed: creating temp file:", err)
return
}
_ = f.Chmod(0600) // best effort remove other users' access
defer os.Remove(f.Name())
if _, err := f.Write(bs); err != nil {
log.Println("Codesign: signing failed: writing temp file:", err)
return
}
if err := f.Close(); err != nil {
log.Println("Codesign: signing failed: closing temp file:", err)
return
}

// Use that when signing
args = append(args, "/f", f.Name())
}
if p := os.Getenv("CODESIGN_CERTIFICATE_PASSWORD"); p != "" {
args = append(args, "/p", p)
Expand All @@ -1402,7 +1430,7 @@ func windowsCodesign(file string) {

bs, err := runError(st, args...)
if err != nil {
log.Println("Codesign: signing failed:", string(bs))
log.Printf("Codesign: signing failed: %v: %s", err, string(bs))
return
}
log.Println("Codesign: successfully signed", file, "using", algo)
Expand Down
11 changes: 7 additions & 4 deletions cmd/stcrashreceiver/sentry.go
Expand Up @@ -15,7 +15,7 @@ import (
"sync"

raven "github.com/getsentry/raven-go"
"github.com/maruel/panicparse/stack"
"github.com/maruel/panicparse/v2/stack"
)

const reportServer = "https://crash.syncthing.net/report/"
Expand Down Expand Up @@ -93,10 +93,13 @@ func parseCrashReport(path string, report []byte) (*raven.Packet, error) {
}

r := bytes.NewReader(report)
ctx, err := stack.ParseDump(r, io.Discard, false)
if err != nil {
ctx, _, err := stack.ScanSnapshot(r, io.Discard, stack.DefaultOpts())
if err != nil && err != io.EOF {
return nil, err
}
if ctx == nil || len(ctx.Goroutines) == 0 {
return nil, errors.New("no goroutines found")
}

// Lock the source code loader to the version we are processing here.
if version.commit != "" {
Expand All @@ -116,7 +119,7 @@ func parseCrashReport(path string, report []byte) (*raven.Packet, error) {
if gr.First {
trace.Frames = make([]*raven.StacktraceFrame, len(gr.Stack.Calls))
for i, sc := range gr.Stack.Calls {
trace.Frames[len(trace.Frames)-1-i] = raven.NewStacktraceFrame(0, sc.Func.Name(), sc.SrcPath, sc.Line, 3, nil)
trace.Frames[len(trace.Frames)-1-i] = raven.NewStacktraceFrame(0, sc.Func.Name, sc.RemoteSrcPath, sc.Line, 3, nil)
}
break
}
Expand Down
15 changes: 12 additions & 3 deletions cmd/strelaysrv/listener.go
Expand Up @@ -23,7 +23,7 @@ var (
numConnections int64
)

func listener(_, addr string, config *tls.Config) {
func listener(_, addr string, config *tls.Config, token string) {
tcpListener, err := net.Listen("tcp", addr)
if err != nil {
log.Fatalln(err)
Expand All @@ -49,15 +49,15 @@ func listener(_, addr string, config *tls.Config) {
}

if isTLS {
go protocolConnectionHandler(conn, config)
go protocolConnectionHandler(conn, config, token)
} else {
go sessionConnectionHandler(conn)
}

}
}

func protocolConnectionHandler(tcpConn net.Conn, config *tls.Config) {
func protocolConnectionHandler(tcpConn net.Conn, config *tls.Config, token string) {
conn := tls.Server(tcpConn, config)
if err := conn.SetDeadline(time.Now().Add(messageTimeout)); err != nil {
if debug {
Expand Down Expand Up @@ -119,6 +119,15 @@ func protocolConnectionHandler(tcpConn net.Conn, config *tls.Config) {

switch msg := message.(type) {
case protocol.JoinRelayRequest:
if token != "" && msg.Token != token {
if debug {
log.Printf("invalid token %s\n", msg.Token)
}
protocol.WriteMessage(conn, protocol.ResponseWrongToken)
conn.Close()
continue
}

if atomic.LoadInt32(&overLimit) > 0 {
protocol.WriteMessage(conn, protocol.RelayFull{})
if debug {
Expand Down
8 changes: 7 additions & 1 deletion cmd/strelaysrv/main.go
Expand Up @@ -56,6 +56,7 @@ var (
networkBufferSize int

statusAddr string
token string
poolAddrs string
pools []string
providedBy string
Expand Down Expand Up @@ -89,6 +90,7 @@ func main() {
flag.IntVar(&globalLimitBps, "global-rate", globalLimitBps, "Global rate limit, in bytes/s")
flag.BoolVar(&debug, "debug", debug, "Enable debug output")
flag.StringVar(&statusAddr, "status-srv", ":22070", "Listen address for status service (blank to disable)")
flag.StringVar(&token, "token", "", "Token to restrict access to the relay (optional). Disables joining any pools.")
flag.StringVar(&poolAddrs, "pools", defaultPoolAddrs, "Comma separated list of relay pool addresses to join")
flag.StringVar(&providedBy, "provided-by", "", "An optional description about who provides the relay")
flag.StringVar(&extAddress, "ext-address", "", "An optional address to advertise as being available on.\n\tAllows listening on an unprivileged port with port forwarding from e.g. 443, and be connected to on port 443.")
Expand Down Expand Up @@ -256,6 +258,10 @@ func main() {

log.Println("URI:", uri.String())

if token != "" {
poolAddrs = ""
}

if poolAddrs == defaultPoolAddrs {
log.Println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
log.Println("!! Joining default relay pools, this relay will be available for public use. !!")
Expand All @@ -271,7 +277,7 @@ func main() {
}
}

go listener(proto, listen, tlsCfg)
go listener(proto, listen, tlsCfg, token)

sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
Expand Down

0 comments on commit db49472

Please sign in to comment.