Skip to content

Commit

Permalink
many: do not use nss when looking up for users/groups from snapd snap
Browse files Browse the repository at this point in the history
  • Loading branch information
valentindavid committed May 31, 2024
1 parent f95aa7e commit 3bf27fb
Show file tree
Hide file tree
Showing 51 changed files with 290 additions and 58 deletions.
6 changes: 2 additions & 4 deletions build-aux/snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ parts:
- squashfs-tools
- xdelta3
- zlib1g
# This is needed for using os/user on Ubuntu Core
# TODO: do not use os/user, but io.systemd.NameServiceSwitch through dbus
- libnss-extrausers
stage:
- -usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR/ld*.so*
- -lib32
Expand All @@ -112,9 +109,9 @@ parts:
- -usr/share/man
- -usr/share/lintian
- -usr/share/lintian/**
- -usr/lib/$CRAFT_ARCH_TRIPLET_BUILD_FOR/libnss_*.so.2
override-build: |
craftctl default
mv "${CRAFT_PART_INSTALL}/usr/lib/libnss_extrausers.so.2" "${CRAFT_PART_INSTALL}/usr/lib/${CRAFT_ARCH_TRIPLET_BUILD_FOR}/"
cp -rT "${CRAFT_PART_INSTALL}/lib/${CRAFT_ARCH_TRIPLET_BUILD_FOR}" "${CRAFT_PART_INSTALL}/usr/lib/${CRAFT_ARCH_TRIPLET_BUILD_FOR}"
rm -rf "${CRAFT_PART_INSTALL}/lib/${CRAFT_ARCH_TRIPLET_BUILD_FOR}"
rm -f "${CRAFT_PART_INSTALL}/lib/${DYNAMIC_LINKER}"
Expand Down Expand Up @@ -279,6 +276,7 @@ parts:
esac
;;
esac
TAGS+=(snap osusergo)
output="${CRAFT_PART_INSTALL}/usr/${cmd}"
go build -mod=vendor -tags "${TAGS[*]}" "${GO_LD_FLAGS[@]}" ${EXTRA_GO_FLAGS-} -o "${output}" "github.com/snapcore/snapd/cmd/$(basename ${cmd})"
Expand Down
2 changes: 1 addition & 1 deletion client/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import (
"errors"
"fmt"
"net/url"
"os/user"
"strconv"
"strings"
"time"

"github.com/snapcore/snapd/osutil/user"
"github.com/snapcore/snapd/snap"
)

Expand Down
2 changes: 1 addition & 1 deletion client/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ package client_test
import (
"encoding/json"
"fmt"
"os/user"
"strconv"
"strings"

"gopkg.in/check.v1"

"github.com/snapcore/snapd/client"
"github.com/snapcore/snapd/osutil/user"
)

func mksvc(snap, app string) *client.AppInfo {
Expand Down
2 changes: 1 addition & 1 deletion client/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
"encoding/json"
"fmt"
"os"
"os/user"
"path/filepath"

"github.com/snapcore/snapd/osutil"
"github.com/snapcore/snapd/osutil/sys"
"github.com/snapcore/snapd/osutil/user"
)

// User holds logged in user information.
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap/cmd_routine_file_access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import (
"fmt"
"net/http"
"net/url"
"os/user"
"path/filepath"
"strings"

. "gopkg.in/check.v1"

"github.com/snapcore/snapd/client"
snap "github.com/snapcore/snapd/cmd/snap"
"github.com/snapcore/snapd/osutil/user"
)

type SnapRoutineFileAccessSuite struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap/cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"net"
"os"
"os/exec"
"os/user"
"path/filepath"
"regexp"
"strconv"
Expand All @@ -49,6 +48,7 @@ import (
"github.com/snapcore/snapd/logger"
"github.com/snapcore/snapd/osutil"
"github.com/snapcore/snapd/osutil/strace"
"github.com/snapcore/snapd/osutil/user"
"github.com/snapcore/snapd/sandbox/cgroup"
"github.com/snapcore/snapd/sandbox/selinux"
"github.com/snapcore/snapd/snap"
Expand Down
3 changes: 2 additions & 1 deletion cmd/snap/cmd_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"fmt"
"net/http"
"os"
"os/user"
"path/filepath"
"strings"
"time"
Expand All @@ -40,6 +39,8 @@ import (
"github.com/snapcore/snapd/logger"
"github.com/snapcore/snapd/osutil"
"github.com/snapcore/snapd/osutil/strace"
"github.com/snapcore/snapd/progress"

Check failure on line 42 in cmd/snap/cmd_run_test.go

View workflow job for this annotation

GitHub Actions / static-checks (latest/stable)

"github.com/snapcore/snapd/progress" imported and not used (typecheck)
"github.com/snapcore/snapd/progress/progresstest"

Check failure on line 43 in cmd/snap/cmd_run_test.go

View workflow job for this annotation

GitHub Actions / static-checks (latest/stable)

"github.com/snapcore/snapd/progress/progresstest" imported and not used (typecheck)
"github.com/snapcore/snapd/sandbox/cgroup"
"github.com/snapcore/snapd/sandbox/selinux"
"github.com/snapcore/snapd/snap"
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap/cmd_userd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"net"
"net/http"
"os"
"os/user"
"path"
"path/filepath"
"strings"
Expand All @@ -38,6 +37,7 @@ import (
"github.com/snapcore/snapd/dirs"
"github.com/snapcore/snapd/logger"
"github.com/snapcore/snapd/osutil"
"github.com/snapcore/snapd/osutil/user"
"github.com/snapcore/snapd/testutil"
"github.com/snapcore/snapd/usersession/autostart"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"fmt"
"go/doc"
"os"
"os/user"
"strings"
"text/tabwriter"

Expand All @@ -35,6 +34,7 @@ import (
"github.com/snapcore/snapd/i18n"
"github.com/snapcore/snapd/logger"
"github.com/snapcore/snapd/osutil"
"github.com/snapcore/snapd/osutil/user"
"github.com/snapcore/snapd/snap/channel"
"github.com/snapcore/snapd/strutil"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package main
import (
"context"
"os"
"os/user"
"time"

"github.com/jessevdk/go-flags"
Expand All @@ -31,6 +30,7 @@ import (
"github.com/snapcore/snapd/cmd/snaplock/runinhibit"
"github.com/snapcore/snapd/image"
"github.com/snapcore/snapd/osutil"
"github.com/snapcore/snapd/osutil/user"
"github.com/snapcore/snapd/sandbox/cgroup"
"github.com/snapcore/snapd/sandbox/selinux"
"github.com/snapcore/snapd/seed/seedwriter"
Expand Down
4 changes: 2 additions & 2 deletions daemon/api_apps.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -*- Mode: Go; indent-tabs-mode: t -*-

/*
* Copyright (C) 2015-2020 Canonical Ltd
* Copyright (C) 2015-2024 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
Expand All @@ -26,12 +26,12 @@ import (
"io"
"net/http"
"net/url"
"os/user"
"sort"
"strconv"
"strings"

"github.com/snapcore/snapd/client/clientutil"
"github.com/snapcore/snapd/osutil/user"
"github.com/snapcore/snapd/overlord/auth"
"github.com/snapcore/snapd/overlord/servicestate"
"github.com/snapcore/snapd/overlord/state"
Expand Down
2 changes: 1 addition & 1 deletion daemon/api_apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"math"
"net/http"
"net/http/httptest"
"os/user"
"sort"
"strconv"
"strings"
Expand All @@ -39,6 +38,7 @@ import (
"github.com/snapcore/snapd/client"
"github.com/snapcore/snapd/client/clientutil"
"github.com/snapcore/snapd/daemon"
"github.com/snapcore/snapd/osutil/user"
"github.com/snapcore/snapd/overlord/hookstate"
"github.com/snapcore/snapd/overlord/servicestate"
"github.com/snapcore/snapd/overlord/snapstate"
Expand Down
2 changes: 1 addition & 1 deletion daemon/api_base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"fmt"
"net/http"
"os"
"os/user"
"path/filepath"
"time"

Expand All @@ -40,6 +39,7 @@ import (
"github.com/snapcore/snapd/daemon"
"github.com/snapcore/snapd/dirs"
"github.com/snapcore/snapd/osutil"
"github.com/snapcore/snapd/osutil/user"
"github.com/snapcore/snapd/overlord"
"github.com/snapcore/snapd/overlord/assertstate"
"github.com/snapcore/snapd/overlord/assertstate/assertstatetest"
Expand Down
2 changes: 1 addition & 1 deletion daemon/api_users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"bytes"
"fmt"
"net/http"
"os/user"
"time"

"gopkg.in/check.v1"
Expand All @@ -32,6 +31,7 @@ import (
"github.com/snapcore/snapd/asserts/assertstest"
"github.com/snapcore/snapd/client"
"github.com/snapcore/snapd/daemon"
"github.com/snapcore/snapd/osutil/user"
"github.com/snapcore/snapd/overlord/assertstate/assertstatetest"
"github.com/snapcore/snapd/overlord/auth"
"github.com/snapcore/snapd/overlord/configstate/config"
Expand Down
3 changes: 1 addition & 2 deletions daemon/export_api_apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
package daemon

import (
"os/user"

"github.com/snapcore/snapd/osutil/user"
"github.com/snapcore/snapd/overlord/hookstate"
"github.com/snapcore/snapd/overlord/servicestate"
"github.com/snapcore/snapd/overlord/state"
Expand Down
4 changes: 1 addition & 3 deletions daemon/export_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// -*- Mode: Go; indent-tabs-mode: t -*-

/*
* Copyright (C) 2018-2022 Canonical Ltd
* Copyright (C) 2018-2024 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
Expand All @@ -22,14 +22,12 @@ package daemon
import (
"context"
"net/http"
"os/user"
"time"

"github.com/gorilla/mux"

"github.com/snapcore/snapd/asserts/snapasserts"
"github.com/snapcore/snapd/boot"
"github.com/snapcore/snapd/client/clientutil"
"github.com/snapcore/snapd/overlord"
"github.com/snapcore/snapd/overlord/assertstate"
"github.com/snapcore/snapd/overlord/restart"
Expand Down
2 changes: 1 addition & 1 deletion desktop/portal/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ package portal

import (
"fmt"
"os/user"
"path/filepath"
"strings"

"github.com/snapcore/snapd/dbusutil"
"github.com/snapcore/snapd/dirs"
"github.com/snapcore/snapd/i18n"
"github.com/snapcore/snapd/osutil/user"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion desktop/portal/document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ package portal_test
import (
"errors"
"os"
"os/user"
"path/filepath"
"sync"

"github.com/godbus/dbus"
. "gopkg.in/check.v1"

"github.com/snapcore/snapd/osutil/user"
"github.com/snapcore/snapd/desktop/portal"
"github.com/snapcore/snapd/testutil"
)
Expand Down
2 changes: 1 addition & 1 deletion desktop/portal/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
package portal

import (
"os/user"
"time"

"github.com/snapcore/snapd/dirs"
"github.com/snapcore/snapd/osutil/user"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion osutil/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
"io"
"os"
"os/exec"
"os/user"
"syscall"
"time"

"github.com/snapcore/snapd/osutil/sys"
"github.com/snapcore/snapd/osutil/user"
"github.com/snapcore/snapd/strutil"
"github.com/snapcore/snapd/testutil"
)
Expand Down
3 changes: 2 additions & 1 deletion osutil/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ package osutil
import (
"bytes"
"fmt"
"os/user"
"strconv"

"github.com/snapcore/snapd/osutil/user"
)

// FindUid returns the identifier of the given UNIX user name. It will
Expand Down
2 changes: 1 addition & 1 deletion osutil/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ package osutil_test

import (
"fmt"
"os/user"

"gopkg.in/check.v1"

"github.com/snapcore/snapd/osutil"
"github.com/snapcore/snapd/osutil/user"
"github.com/snapcore/snapd/testutil"
)

Expand Down
2 changes: 1 addition & 1 deletion osutil/strace/strace.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ package strace
import (
"fmt"
"os/exec"
"os/user"
"path/filepath"
"runtime"

"github.com/snapcore/snapd/dirs"
"github.com/snapcore/snapd/osutil"
"github.com/snapcore/snapd/osutil/user"
)

// These syscalls are excluded because they make strace hang on all or
Expand Down
2 changes: 1 addition & 1 deletion osutil/strace/strace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ package strace_test

import (
"os"
"os/user"
"path/filepath"
"testing"

. "gopkg.in/check.v1"

"github.com/snapcore/snapd/dirs"
"github.com/snapcore/snapd/osutil/user"
"github.com/snapcore/snapd/osutil/strace"
"github.com/snapcore/snapd/testutil"
)
Expand Down
2 changes: 1 addition & 1 deletion osutil/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import (
"fmt"
"os"
"os/exec"
"os/user"
"path/filepath"
"regexp"
"strconv"
"strings"
"syscall"

"github.com/snapcore/snapd/osutil/sys"
"github.com/snapcore/snapd/osutil/user"
)

var (
Expand Down
Loading

0 comments on commit 3bf27fb

Please sign in to comment.