mirror of
https://github.com/tailscale/tailscale.git
synced 2026-02-10 16:01:40 -05:00
This file was never truly necessary and has never actually been used in the history of Tailscale's open source releases. A Brief History of AUTHORS files --- The AUTHORS file was a pattern developed at Google, originally for Chromium, then adopted by Go and a bunch of other projects. The problem was that Chromium originally had a copyright line only recognizing Google as the copyright holder. Because Google (and most open source projects) do not require copyright assignemnt for contributions, each contributor maintains their copyright. Some large corporate contributors then tried to add their own name to the copyright line in the LICENSE file or in file headers. This quickly becomes unwieldy, and puts a tremendous burden on anyone building on top of Chromium, since the license requires that they keep all copyright lines intact. The compromise was to create an AUTHORS file that would list all of the copyright holders. The LICENSE file and source file headers would then include that list by reference, listing the copyright holder as "The Chromium Authors". This also become cumbersome to simply keep the file up to date with a high rate of new contributors. Plus it's not always obvious who the copyright holder is. Sometimes it is the individual making the contribution, but many times it may be their employer. There is no way for the proejct maintainer to know. Eventually, Google changed their policy to no longer recommend trying to keep the AUTHORS file up to date proactively, and instead to only add to it when requested: https://opensource.google/docs/releasing/authors. They are also clear that: > Adding contributors to the AUTHORS file is entirely within the > project's discretion and has no implications for copyright ownership. It was primarily added to appease a small number of large contributors that insisted that they be recognized as copyright holders (which was entirely their right to do). But it's not truly necessary, and not even the most accurate way of identifying contributors and/or copyright holders. In practice, we've never added anyone to our AUTHORS file. It only lists Tailscale, so it's not really serving any purpose. It also causes confusion because Tailscalars put the "Tailscale Inc & AUTHORS" header in other open source repos which don't actually have an AUTHORS file, so it's ambiguous what that means. Instead, we just acknowledge that the contributors to Tailscale (whoever they are) are copyright holders for their individual contributions. We also have the benefit of using the DCO (developercertificate.org) which provides some additional certification of their right to make the contribution. The source file changes were purely mechanical with: git ls-files | xargs sed -i -e 's/\(Tailscale Inc &\) AUTHORS/\1 contributors/g' Updates #cleanup Change-Id: Ia101a4a3005adb9118051b3416f5a64a4a45987d Signed-off-by: Will Norris <will@tailscale.com>
183 lines
4.6 KiB
Go
183 lines
4.6 KiB
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
// Package deb extracts metadata from Debian packages.
|
|
package deb
|
|
|
|
import (
|
|
"archive/tar"
|
|
"bufio"
|
|
"bytes"
|
|
"compress/gzip"
|
|
"crypto/md5"
|
|
"crypto/sha1"
|
|
"crypto/sha256"
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"path/filepath"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// Info is the Debian package metadata needed to integrate the package
|
|
// into a repository.
|
|
type Info struct {
|
|
// Version is the version of the package, as reported by dpkg.
|
|
Version string
|
|
// Arch is the Debian CPU architecture the package is for.
|
|
Arch string
|
|
// Control is the entire contents of the package's control file,
|
|
// with leading and trailing whitespace removed.
|
|
Control []byte
|
|
// MD5 is the MD5 hash of the package file.
|
|
MD5 []byte
|
|
// SHA1 is the SHA1 hash of the package file.
|
|
SHA1 []byte
|
|
// SHA256 is the SHA256 hash of the package file.
|
|
SHA256 []byte
|
|
}
|
|
|
|
// ReadFile returns Debian package metadata from the .deb file at path.
|
|
func ReadFile(path string) (*Info, error) {
|
|
f, err := os.Open(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return Read(f)
|
|
}
|
|
|
|
// Read returns Debian package metadata from the .deb file in r.
|
|
func Read(r io.Reader) (*Info, error) {
|
|
b := bufio.NewReader(r)
|
|
|
|
m5, s1, s256 := md5.New(), sha1.New(), sha256.New()
|
|
summers := io.MultiWriter(m5, s1, s256)
|
|
r = io.TeeReader(b, summers)
|
|
|
|
t, err := findControlTar(r)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("searching for control.tar.gz: %w", err)
|
|
}
|
|
|
|
control, err := findControlFile(t)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("searching for control file in control.tar.gz: %w", err)
|
|
}
|
|
|
|
arch, version, err := findArchAndVersion(control)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("extracting version and architecture from control file: %w", err)
|
|
}
|
|
|
|
// Exhaust the remainder of r, so that the summers see the entire file.
|
|
if _, err := io.Copy(io.Discard, r); err != nil {
|
|
return nil, fmt.Errorf("hashing file: %w", err)
|
|
}
|
|
|
|
return &Info{
|
|
Version: version,
|
|
Arch: arch,
|
|
Control: control,
|
|
MD5: m5.Sum(nil),
|
|
SHA1: s1.Sum(nil),
|
|
SHA256: s256.Sum(nil),
|
|
}, nil
|
|
}
|
|
|
|
// findControlTar reads r as an `ar` archive, finds a tarball named
|
|
// `control.tar.gz` within, and returns a reader for that file.
|
|
func findControlTar(r io.Reader) (tarReader io.Reader, err error) {
|
|
var magic [8]byte
|
|
if _, err := io.ReadFull(r, magic[:]); err != nil {
|
|
return nil, fmt.Errorf("reading ar magic: %w", err)
|
|
}
|
|
if string(magic[:]) != "!<arch>\n" {
|
|
return nil, fmt.Errorf("not an ar file (bad magic %q)", magic)
|
|
}
|
|
|
|
for {
|
|
var hdr [60]byte
|
|
if _, err := io.ReadFull(r, hdr[:]); err != nil {
|
|
return nil, fmt.Errorf("reading file header: %w", err)
|
|
}
|
|
filename := strings.TrimSpace(string(hdr[:16]))
|
|
size, err := strconv.ParseInt(strings.TrimSpace(string(hdr[48:58])), 10, 64)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("reading size of file %q: %w", filename, err)
|
|
}
|
|
if filename == "control.tar.gz" {
|
|
return io.LimitReader(r, size), nil
|
|
}
|
|
|
|
// files in ar are padded out to 2 bytes.
|
|
if size%2 == 1 {
|
|
size++
|
|
}
|
|
if _, err := io.CopyN(io.Discard, r, size); err != nil {
|
|
return nil, fmt.Errorf("seeking past file %q: %w", filename, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
// findControlFile reads r as a tar.gz archive, finds a file named
|
|
// `control` within, and returns its contents.
|
|
func findControlFile(r io.Reader) (control []byte, err error) {
|
|
gz, err := gzip.NewReader(r)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("decompressing control.tar.gz: %w", err)
|
|
}
|
|
defer gz.Close()
|
|
|
|
tr := tar.NewReader(gz)
|
|
for {
|
|
hdr, err := tr.Next()
|
|
if err != nil {
|
|
if errors.Is(err, io.EOF) {
|
|
return nil, errors.New("EOF while looking for control file in control.tar.gz")
|
|
}
|
|
return nil, fmt.Errorf("reading tar header: %w", err)
|
|
}
|
|
|
|
if filepath.Clean(hdr.Name) != "control" {
|
|
continue
|
|
}
|
|
|
|
// Found control file
|
|
break
|
|
}
|
|
|
|
bs, err := io.ReadAll(tr)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("reading control file: %w", err)
|
|
}
|
|
|
|
return bytes.TrimSpace(bs), nil
|
|
}
|
|
|
|
var (
|
|
archKey = []byte("Architecture:")
|
|
versionKey = []byte("Version:")
|
|
)
|
|
|
|
// findArchAndVersion extracts the architecture and version strings
|
|
// from the given control file.
|
|
func findArchAndVersion(control []byte) (arch string, version string, err error) {
|
|
b := bytes.NewBuffer(control)
|
|
for {
|
|
ln, err := b.ReadBytes('\n')
|
|
if err != nil {
|
|
return "", "", err
|
|
}
|
|
if bytes.HasPrefix(ln, archKey) {
|
|
arch = string(bytes.TrimSpace(ln[len(archKey):]))
|
|
} else if bytes.HasPrefix(ln, versionKey) {
|
|
version = string(bytes.TrimSpace(ln[len(versionKey):]))
|
|
}
|
|
if arch != "" && version != "" {
|
|
return arch, version, nil
|
|
}
|
|
}
|
|
}
|