diff --git a/build-aux/snap/snapcraft.yaml b/build-aux/snap/snapcraft.yaml index b41a287f243b..5040b4e6dac1 100644 --- a/build-aux/snap/snapcraft.yaml +++ b/build-aux/snap/snapcraft.yaml @@ -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 @@ -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}" @@ -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})" diff --git a/client/apps.go b/client/apps.go index 9611a06420dc..0c3360260df8 100644 --- a/client/apps.go +++ b/client/apps.go @@ -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" ) diff --git a/client/apps_test.go b/client/apps_test.go index baae65ea6219..68ef611998f3 100644 --- a/client/apps_test.go +++ b/client/apps_test.go @@ -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 { diff --git a/client/login.go b/client/login.go index 21edcaca8d43..6f44445e7089 100644 --- a/client/login.go +++ b/client/login.go @@ -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. diff --git a/cmd/snap/cmd_routine_file_access_test.go b/cmd/snap/cmd_routine_file_access_test.go index aaae749f1a11..79e74b8ba40c 100644 --- a/cmd/snap/cmd_routine_file_access_test.go +++ b/cmd/snap/cmd_routine_file_access_test.go @@ -23,7 +23,6 @@ import ( "fmt" "net/http" "net/url" - "os/user" "path/filepath" "strings" @@ -31,6 +30,7 @@ import ( "github.com/snapcore/snapd/client" snap "github.com/snapcore/snapd/cmd/snap" + "github.com/snapcore/snapd/osutil/user" ) type SnapRoutineFileAccessSuite struct { diff --git a/cmd/snap/cmd_run.go b/cmd/snap/cmd_run.go index 65496a910017..a1a3fbba4f71 100644 --- a/cmd/snap/cmd_run.go +++ b/cmd/snap/cmd_run.go @@ -28,7 +28,6 @@ import ( "net" "os" "os/exec" - "os/user" "path/filepath" "regexp" "strconv" @@ -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" diff --git a/cmd/snap/cmd_run_test.go b/cmd/snap/cmd_run_test.go index a80b56b368a5..aef1e757d78e 100644 --- a/cmd/snap/cmd_run_test.go +++ b/cmd/snap/cmd_run_test.go @@ -26,7 +26,6 @@ import ( "fmt" "net/http" "os" - "os/user" "path/filepath" "strings" "time" @@ -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" + "github.com/snapcore/snapd/progress/progresstest" "github.com/snapcore/snapd/sandbox/cgroup" "github.com/snapcore/snapd/sandbox/selinux" "github.com/snapcore/snapd/snap" diff --git a/cmd/snap/cmd_userd_test.go b/cmd/snap/cmd_userd_test.go index fc375a62b280..b733201d5b66 100644 --- a/cmd/snap/cmd_userd_test.go +++ b/cmd/snap/cmd_userd_test.go @@ -25,7 +25,6 @@ import ( "net" "net/http" "os" - "os/user" "path" "path/filepath" "strings" @@ -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" ) diff --git a/cmd/snap/error.go b/cmd/snap/error.go index 57cb6915a4c3..a3b4eeaed98b 100644 --- a/cmd/snap/error.go +++ b/cmd/snap/error.go @@ -25,7 +25,6 @@ import ( "fmt" "go/doc" "os" - "os/user" "strings" "text/tabwriter" @@ -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" ) diff --git a/cmd/snap/export_test.go b/cmd/snap/export_test.go index 61a7e45e7599..86ce6fb0d3c7 100644 --- a/cmd/snap/export_test.go +++ b/cmd/snap/export_test.go @@ -22,7 +22,6 @@ package main import ( "context" "os" - "os/user" "time" "github.com/jessevdk/go-flags" @@ -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" diff --git a/daemon/api_apps.go b/daemon/api_apps.go index cb359268174c..7d4b97569dde 100644 --- a/daemon/api_apps.go +++ b/daemon/api_apps.go @@ -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 @@ -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" diff --git a/daemon/api_apps_test.go b/daemon/api_apps_test.go index afe5c2549513..1b445ea40e6e 100644 --- a/daemon/api_apps_test.go +++ b/daemon/api_apps_test.go @@ -29,7 +29,6 @@ import ( "math" "net/http" "net/http/httptest" - "os/user" "sort" "strconv" "strings" @@ -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" diff --git a/daemon/api_base_test.go b/daemon/api_base_test.go index 547cf84746b7..cf613f28a0b6 100644 --- a/daemon/api_base_test.go +++ b/daemon/api_base_test.go @@ -25,7 +25,6 @@ import ( "fmt" "net/http" "os" - "os/user" "path/filepath" "time" @@ -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" diff --git a/daemon/api_users_test.go b/daemon/api_users_test.go index 3afeec44f9c1..45bd43e9c8bb 100644 --- a/daemon/api_users_test.go +++ b/daemon/api_users_test.go @@ -23,7 +23,6 @@ import ( "bytes" "fmt" "net/http" - "os/user" "time" "gopkg.in/check.v1" @@ -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" diff --git a/daemon/export_api_apps_test.go b/daemon/export_api_apps_test.go index 3eb3185a5509..356e7fd545a5 100644 --- a/daemon/export_api_apps_test.go +++ b/daemon/export_api_apps_test.go @@ -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" diff --git a/daemon/export_test.go b/daemon/export_test.go index 05a7d5e12242..1faa3977385c 100644 --- a/daemon/export_test.go +++ b/daemon/export_test.go @@ -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 @@ -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" diff --git a/desktop/portal/document.go b/desktop/portal/document.go index 22fa593ac71e..14359954ff32 100644 --- a/desktop/portal/document.go +++ b/desktop/portal/document.go @@ -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 ( diff --git a/desktop/portal/document_test.go b/desktop/portal/document_test.go index 874cb55746a5..c40029b936b5 100644 --- a/desktop/portal/document_test.go +++ b/desktop/portal/document_test.go @@ -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" ) diff --git a/desktop/portal/export_test.go b/desktop/portal/export_test.go index 167415f93771..d652e7bbed3a 100644 --- a/desktop/portal/export_test.go +++ b/desktop/portal/export_test.go @@ -20,10 +20,10 @@ package portal import ( - "os/user" "time" "github.com/snapcore/snapd/dirs" + "github.com/snapcore/snapd/osutil/user" ) const ( diff --git a/osutil/export_test.go b/osutil/export_test.go index 1c66470becac..332376525b5a 100644 --- a/osutil/export_test.go +++ b/osutil/export_test.go @@ -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" ) diff --git a/osutil/group.go b/osutil/group.go index 3ad6393e1738..906858fe3c13 100644 --- a/osutil/group.go +++ b/osutil/group.go @@ -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 diff --git a/osutil/group_test.go b/osutil/group_test.go index cf5809038e32..390fb30b9faf 100644 --- a/osutil/group_test.go +++ b/osutil/group_test.go @@ -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" ) diff --git a/osutil/strace/strace.go b/osutil/strace/strace.go index de7cb2ef5279..c0ce8b695d20 100644 --- a/osutil/strace/strace.go +++ b/osutil/strace/strace.go @@ -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 diff --git a/osutil/strace/strace_test.go b/osutil/strace/strace_test.go index d5c3a2a06d77..1e836b43072b 100644 --- a/osutil/strace/strace_test.go +++ b/osutil/strace/strace_test.go @@ -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" ) diff --git a/osutil/user.go b/osutil/user.go index 1e55c42ba240..5e0f9e2a5f76 100644 --- a/osutil/user.go +++ b/osutil/user.go @@ -23,7 +23,6 @@ import ( "fmt" "os" "os/exec" - "os/user" "path/filepath" "regexp" "strconv" @@ -31,6 +30,7 @@ import ( "syscall" "github.com/snapcore/snapd/osutil/sys" + "github.com/snapcore/snapd/osutil/user" ) var ( diff --git a/osutil/user/user.go b/osutil/user/user.go new file mode 100644 index 000000000000..932127a252bd --- /dev/null +++ b/osutil/user/user.go @@ -0,0 +1,28 @@ +//go:build !snap + +package user + +import ( + origUser "os/user" +) + +type User = origUser.User +type Group = origUser.Group +type UnknownUserError = origUser.UnknownUserError +type UnknownGroupError = origUser.UnknownGroupError + +func Current() (*User, error) { + return origUser.Current() +} + +func Lookup(username string) (*User, error) { + return origUser.Lookup(username) +} + +func LookupId(uid string) (*User, error) { + return origUser.LookupId(uid) +} + +func LookupGroup(groupname string) (*Group, error) { + return origUser.LookupGroup(groupname) +} diff --git a/osutil/user/user_from_snap.go b/osutil/user/user_from_snap.go new file mode 100644 index 000000000000..21de8d06c20a --- /dev/null +++ b/osutil/user/user_from_snap.go @@ -0,0 +1,209 @@ +//go:build snap && osusergo + +package user + +import ( + "bufio" + "io" + "os" + "strconv" + "strings" + + origUser "os/user" + + "github.com/snapcore/snapd/release" +) + +type User = origUser.User +type Group = origUser.Group +type UnknownUserError = origUser.UnknownUserError +type UnknownGroupError = origUser.UnknownGroupError + +func classicCurrent() (*User, error) { + return origUser.Current() +} + +func classicLookup(username string) (*User, error) { + return origUser.Lookup(username) +} + +func classicLookupId(uid string) (*User, error) { + return origUser.LookupId(uid) +} + +func classicLookupGroup(groupname string) (*Group, error) { + return origUser.LookupGroup(groupname) +} + +func lookupExtraGroup(index int, expectedValue string) (*Group, error) { + f, err := os.Open("/var/lib/extrausers/group") + if err != nil { + if os.IsNotExist(err) { + return nil, nil + } else { + return nil, err + } + } + defer f.Close() + rd := bufio.NewReader(f) + for { + var line []byte + for { + chunk, isPrefix, err := rd.ReadLine() + if err != nil { + if err == io.EOF { + return nil, nil + } + return nil, err + } + line = append(line, chunk...) + if !isPrefix { + break + } + } + + if len(line) == 0 || line[0] == '#' { + continue + } + components := strings.SplitN(string(line), ":", 4) + if len(components) != 4 { + continue + } + + if components[index] != expectedValue { + continue + } + + return &Group{ + Name: components[0], + Gid: components[2], + }, nil + } + return nil, nil +} + +func lookupExtraUser(index int, expectedValue string) (*User, error) { + f, err := os.Open("/var/lib/extrausers/passwd") + if err != nil { + if os.IsNotExist(err) { + return nil, nil + } else { + return nil, err + } + } + defer f.Close() + rd := bufio.NewReader(f) + for { + var line []byte + for { + chunk, isPrefix, err := rd.ReadLine() + if err != nil { + if err == io.EOF { + return nil, nil + } + return nil, err + } + line = append(line, chunk...) + if !isPrefix { + break + } + } + + if len(line) == 0 || line[0] == '#' { + continue + } + components := strings.SplitN(string(line), ":", 7) + if len(components) != 7 { + continue + } + + if components[index] != expectedValue { + continue + } + + return &User{ + Username: components[0], + Uid: components[2], + Gid: components[3], + Name: components[4], + HomeDir: components[5], + }, nil + } + return nil, nil +} + +func coreCurrent() (*User, error) { + foundExtraUser, err := lookupExtraUser(2, strconv.Itoa(os.Getuid())) + if err != nil { + return nil, err + } + if foundExtraUser != nil { + return foundExtraUser, nil + } + return origUser.Current() +} + +func coreLookup(username string) (*User, error) { + foundExtraUser, err := lookupExtraUser(0, username) + if err != nil { + return nil, err + } + if foundExtraUser != nil { + return foundExtraUser, nil + } + return origUser.Lookup(username) +} + +func coreLookupId(uid string) (*User, error) { + foundExtraUser, err := lookupExtraUser(2, uid) + if err != nil { + return nil, err + } + if foundExtraUser != nil { + return foundExtraUser, nil + } + return origUser.LookupId(uid) +} + +func coreLookupGroup(groupname string) (*Group, error) { + foundExtraGroup, err := lookupExtraGroup(0, groupname) + if err != nil { + return nil, err + } + if foundExtraGroup != nil { + return foundExtraGroup, nil + } + return origUser.LookupGroup(groupname) +} + +func Current() (*User, error) { + if release.OnClassic { + return classicCurrent() + } else { + return coreCurrent() + } +} + +func Lookup(username string) (*User, error) { + if release.OnClassic { + return classicLookup(username) + } else { + return coreLookup(username) + } +} + +func LookupId(uid string) (*User, error) { + if release.OnClassic { + return classicLookupId(uid) + } else { + return coreLookupId(uid) + } +} + +func LookupGroup(groupname string) (*Group, error) { + if release.OnClassic { + return classicLookupGroup(groupname) + } else { + return coreLookupGroup(groupname) + } +} diff --git a/osutil/user_test.go b/osutil/user_test.go index 6e46c0695d6f..89b6f29c0719 100644 --- a/osutil/user_test.go +++ b/osutil/user_test.go @@ -22,7 +22,6 @@ package osutil_test import ( "fmt" "os" - "os/user" "path/filepath" "strconv" @@ -30,6 +29,7 @@ import ( "github.com/snapcore/snapd/osutil" "github.com/snapcore/snapd/osutil/sys" + "github.com/snapcore/snapd/osutil/user" "github.com/snapcore/snapd/testutil" ) diff --git a/overlord/devicestate/export_test.go b/overlord/devicestate/export_test.go index 0235ef9797e4..e2f6863644c5 100644 --- a/overlord/devicestate/export_test.go +++ b/overlord/devicestate/export_test.go @@ -23,7 +23,6 @@ import ( "context" "fmt" "net/http" - "os/user" "time" "github.com/snapcore/snapd/asserts" @@ -33,6 +32,7 @@ import ( "github.com/snapcore/snapd/httputil" "github.com/snapcore/snapd/kernel/fde" "github.com/snapcore/snapd/osutil" + "github.com/snapcore/snapd/osutil/user" "github.com/snapcore/snapd/overlord/snapstate" "github.com/snapcore/snapd/overlord/state" "github.com/snapcore/snapd/overlord/storecontext" diff --git a/overlord/devicestate/users.go b/overlord/devicestate/users.go index a74630d2c783..135b2b199222 100644 --- a/overlord/devicestate/users.go +++ b/overlord/devicestate/users.go @@ -22,13 +22,13 @@ import ( "encoding/json" "errors" "fmt" - "os/user" "path/filepath" "time" "github.com/snapcore/snapd/asserts" "github.com/snapcore/snapd/logger" "github.com/snapcore/snapd/osutil" + "github.com/snapcore/snapd/osutil/user" "github.com/snapcore/snapd/overlord/assertstate" "github.com/snapcore/snapd/overlord/auth" "github.com/snapcore/snapd/overlord/snapstate" diff --git a/overlord/devicestate/users_test.go b/overlord/devicestate/users_test.go index 68164aec075a..083798bdeb94 100644 --- a/overlord/devicestate/users_test.go +++ b/overlord/devicestate/users_test.go @@ -21,7 +21,6 @@ package devicestate_test import ( "fmt" - "os/user" "path/filepath" "sort" "time" @@ -33,6 +32,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/overlord/assertstate" "github.com/snapcore/snapd/overlord/assertstate/assertstatetest" "github.com/snapcore/snapd/overlord/auth" diff --git a/overlord/hookstate/ctlcmd/export_test.go b/overlord/hookstate/ctlcmd/export_test.go index e8f861617cc4..48a2486f7b07 100644 --- a/overlord/hookstate/ctlcmd/export_test.go +++ b/overlord/hookstate/ctlcmd/export_test.go @@ -1,7 +1,7 @@ // -*- Mode: Go; indent-tabs-mode: t -*- /* - * Copyright (C) 2016 Canonical Ltd + * Copyright (C) 2016, 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 @@ -22,7 +22,6 @@ package ctlcmd import ( "context" "fmt" - "os/user" "github.com/snapcore/snapd/asserts" "github.com/snapcore/snapd/client/clientutil" diff --git a/overlord/hookstate/ctlcmd/services_test.go b/overlord/hookstate/ctlcmd/services_test.go index c95c68e93323..2c186c83ca2c 100644 --- a/overlord/hookstate/ctlcmd/services_test.go +++ b/overlord/hookstate/ctlcmd/services_test.go @@ -22,7 +22,6 @@ package ctlcmd_test import ( "context" "fmt" - "os/user" "sort" . "gopkg.in/check.v1" @@ -33,6 +32,7 @@ import ( "github.com/snapcore/snapd/client/clientutil" "github.com/snapcore/snapd/dirs" "github.com/snapcore/snapd/interfaces" + "github.com/snapcore/snapd/osutil/user" "github.com/snapcore/snapd/overlord/auth" "github.com/snapcore/snapd/overlord/hookstate" "github.com/snapcore/snapd/overlord/hookstate/ctlcmd" diff --git a/overlord/managers_test.go b/overlord/managers_test.go index ea68d4e80966..10f178f1f32a 100644 --- a/overlord/managers_test.go +++ b/overlord/managers_test.go @@ -32,7 +32,6 @@ import ( "net/http/httptest" "net/url" "os" - "os/user" "path" "path/filepath" "runtime" @@ -66,6 +65,7 @@ import ( "github.com/snapcore/snapd/osutil" "github.com/snapcore/snapd/osutil/disks" "github.com/snapcore/snapd/osutil/kcmdline" + "github.com/snapcore/snapd/osutil/user" "github.com/snapcore/snapd/overlord" "github.com/snapcore/snapd/overlord/assertstate" "github.com/snapcore/snapd/overlord/assertstate/assertstatetest" diff --git a/overlord/servicestate/servicestate.go b/overlord/servicestate/servicestate.go index 176e2791deb7..d314b24989a3 100644 --- a/overlord/servicestate/servicestate.go +++ b/overlord/servicestate/servicestate.go @@ -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 @@ -24,7 +24,6 @@ import ( "errors" "fmt" "io" - "os/user" "path/filepath" "sort" "strconv" diff --git a/overlord/servicestate/servicestate_test.go b/overlord/servicestate/servicestate_test.go index cd5a07a34b90..0b199400d12b 100644 --- a/overlord/servicestate/servicestate_test.go +++ b/overlord/servicestate/servicestate_test.go @@ -26,7 +26,6 @@ import ( "fmt" "io" "os" - "os/user" "path/filepath" "strings" @@ -35,6 +34,7 @@ import ( "github.com/snapcore/snapd/client" "github.com/snapcore/snapd/dirs" "github.com/snapcore/snapd/gadget/quantity" + "github.com/snapcore/snapd/osutil/user" "github.com/snapcore/snapd/overlord/configstate/config" "github.com/snapcore/snapd/overlord/servicestate" "github.com/snapcore/snapd/overlord/servicestate/servicestatetest" diff --git a/overlord/snapshotstate/backend/backend_test.go b/overlord/snapshotstate/backend/backend_test.go index c713c522fd38..5bb3cbbae097 100644 --- a/overlord/snapshotstate/backend/backend_test.go +++ b/overlord/snapshotstate/backend/backend_test.go @@ -32,7 +32,6 @@ import ( "io" "os" "os/exec" - "os/user" "path" "path/filepath" "sort" @@ -47,6 +46,7 @@ import ( "github.com/snapcore/snapd/logger" "github.com/snapcore/snapd/osutil" "github.com/snapcore/snapd/osutil/sys" + "github.com/snapcore/snapd/osutil/user" "github.com/snapcore/snapd/overlord/snapshotstate/backend" "github.com/snapcore/snapd/snap" "github.com/snapcore/snapd/testutil" diff --git a/overlord/snapshotstate/backend/export_test.go b/overlord/snapshotstate/backend/export_test.go index b36d89105f55..c0dcf9517097 100644 --- a/overlord/snapshotstate/backend/export_test.go +++ b/overlord/snapshotstate/backend/export_test.go @@ -22,12 +22,12 @@ package backend import ( "os" "os/exec" - "os/user" "time" "github.com/snapcore/snapd/client" "github.com/snapcore/snapd/dirs" "github.com/snapcore/snapd/osutil/sys" + "github.com/snapcore/snapd/osutil/user" "github.com/snapcore/snapd/snap" "github.com/snapcore/snapd/testutil" ) diff --git a/overlord/snapshotstate/backend/helpers.go b/overlord/snapshotstate/backend/helpers.go index 22dcef7909f6..b61db34f9e6e 100644 --- a/overlord/snapshotstate/backend/helpers.go +++ b/overlord/snapshotstate/backend/helpers.go @@ -25,7 +25,6 @@ import ( "io" "os" "os/exec" - "os/user" "path/filepath" "strings" @@ -33,6 +32,7 @@ import ( "github.com/snapcore/snapd/dirs" "github.com/snapcore/snapd/logger" "github.com/snapcore/snapd/osutil/sys" + "github.com/snapcore/snapd/osutil/user" "github.com/snapcore/snapd/snap" ) diff --git a/overlord/snapshotstate/snapshotstate_test.go b/overlord/snapshotstate/snapshotstate_test.go index 16208fb8ebb8..524529b7676f 100644 --- a/overlord/snapshotstate/snapshotstate_test.go +++ b/overlord/snapshotstate/snapshotstate_test.go @@ -28,7 +28,6 @@ import ( "io" "os" "os/exec" - "os/user" "path/filepath" "sort" "strings" @@ -42,6 +41,7 @@ import ( "github.com/snapcore/snapd/client" "github.com/snapcore/snapd/dirs" "github.com/snapcore/snapd/osutil/sys" + "github.com/snapcore/snapd/osutil/user" "github.com/snapcore/snapd/overlord" "github.com/snapcore/snapd/overlord/configstate/config" "github.com/snapcore/snapd/overlord/snapshotstate" diff --git a/overlord/snapstate/backend/copydata.go b/overlord/snapstate/backend/copydata.go index 4fef7480922b..9f3b1522e831 100644 --- a/overlord/snapstate/backend/copydata.go +++ b/overlord/snapstate/backend/copydata.go @@ -23,12 +23,12 @@ import ( "errors" "fmt" "os" - "os/user" "path/filepath" "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/progress" "github.com/snapcore/snapd/snap" "github.com/snapcore/snapd/strutil" diff --git a/overlord/snapstate/backend/copydata_test.go b/overlord/snapstate/backend/copydata_test.go index 5a6819528778..9b1ccb3e5592 100644 --- a/overlord/snapstate/backend/copydata_test.go +++ b/overlord/snapstate/backend/copydata_test.go @@ -23,7 +23,6 @@ import ( "errors" "fmt" "os" - "os/user" "path/filepath" "regexp" "strconv" @@ -35,6 +34,7 @@ import ( "github.com/snapcore/snapd/logger" "github.com/snapcore/snapd/osutil" "github.com/snapcore/snapd/osutil/sys" + "github.com/snapcore/snapd/osutil/user" "github.com/snapcore/snapd/overlord/snapstate/backend" "github.com/snapcore/snapd/progress" "github.com/snapcore/snapd/snap" diff --git a/overlord/snapstate/check_snap_test.go b/overlord/snapstate/check_snap_test.go index 468626baef47..237d5b5940d1 100644 --- a/overlord/snapstate/check_snap_test.go +++ b/overlord/snapstate/check_snap_test.go @@ -22,7 +22,6 @@ package snapstate_test import ( "errors" "fmt" - "os/user" . "gopkg.in/check.v1" @@ -30,6 +29,7 @@ import ( "github.com/snapcore/snapd/asserts" "github.com/snapcore/snapd/dirs" "github.com/snapcore/snapd/osutil" + "github.com/snapcore/snapd/osutil/user" "github.com/snapcore/snapd/overlord/snapstate" "github.com/snapcore/snapd/overlord/snapstate/snapstatetest" "github.com/snapcore/snapd/overlord/state" diff --git a/snap/helpers.go b/snap/helpers.go index ce6b1649a51b..e8e816bfe6c1 100644 --- a/snap/helpers.go +++ b/snap/helpers.go @@ -20,13 +20,13 @@ package snap import ( - "os/user" "path/filepath" "strconv" "syscall" "github.com/snapcore/snapd/dirs" "github.com/snapcore/snapd/snap/naming" + "github.com/snapcore/snapd/osutil/user" ) var ( diff --git a/snap/snapenv/snapenv.go b/snap/snapenv/snapenv.go index 470d6a7f4e49..f827c9e1c34f 100644 --- a/snap/snapenv/snapenv.go +++ b/snap/snapenv/snapenv.go @@ -22,7 +22,6 @@ package snapenv import ( "fmt" "os" - "os/user" "path/filepath" "github.com/snapcore/snapd/arch" @@ -31,6 +30,7 @@ import ( "github.com/snapcore/snapd/logger" "github.com/snapcore/snapd/osutil" "github.com/snapcore/snapd/osutil/sys" + "github.com/snapcore/snapd/osutil/user" "github.com/snapcore/snapd/snap" ) diff --git a/snap/snapenv/snapenv_test.go b/snap/snapenv/snapenv_test.go index 951fa43fd31f..9bab6cc58884 100644 --- a/snap/snapenv/snapenv_test.go +++ b/snap/snapenv/snapenv_test.go @@ -22,7 +22,6 @@ package snapenv import ( "fmt" "os" - "os/user" "path/filepath" "testing" @@ -33,6 +32,7 @@ import ( "github.com/snapcore/snapd/features" "github.com/snapcore/snapd/osutil" "github.com/snapcore/snapd/osutil/sys" + "github.com/snapcore/snapd/osutil/user" "github.com/snapcore/snapd/snap" "github.com/snapcore/snapd/testutil" ) diff --git a/usersession/autostart/autostart.go b/usersession/autostart/autostart.go index 10a8abb8e877..9bdd7ab8adcb 100644 --- a/usersession/autostart/autostart.go +++ b/usersession/autostart/autostart.go @@ -25,7 +25,6 @@ import ( "log/syslog" "os" "os/exec" - "os/user" "path/filepath" "sort" "strings" @@ -33,6 +32,7 @@ import ( "github.com/snapcore/snapd/desktop/desktopentry" "github.com/snapcore/snapd/logger" "github.com/snapcore/snapd/osutil" + "github.com/snapcore/snapd/osutil/user" "github.com/snapcore/snapd/snap" "github.com/snapcore/snapd/systemd" ) diff --git a/usersession/autostart/autostart_test.go b/usersession/autostart/autostart_test.go index c0cde935465b..c2a56d089d1a 100644 --- a/usersession/autostart/autostart_test.go +++ b/usersession/autostart/autostart_test.go @@ -21,7 +21,6 @@ package autostart_test import ( "os" - "os/user" "path" "path/filepath" "strings" @@ -33,6 +32,7 @@ import ( "github.com/snapcore/snapd/snap" "github.com/snapcore/snapd/snap/snaptest" "github.com/snapcore/snapd/testutil" + "github.com/snapcore/snapd/osutil/user" "github.com/snapcore/snapd/usersession/autostart" ) diff --git a/wrappers/export_test.go b/wrappers/export_test.go index a46a7ea0b7c8..e8d4f35bbc38 100644 --- a/wrappers/export_test.go +++ b/wrappers/export_test.go @@ -20,10 +20,10 @@ package wrappers import ( - "os/user" "time" "github.com/snapcore/snapd/osutil" + "github.com/snapcore/snapd/osutil/user" "github.com/snapcore/snapd/testutil" ) diff --git a/wrappers/services.go b/wrappers/services.go index 03b0edfb3a44..7f17facbf03e 100644 --- a/wrappers/services.go +++ b/wrappers/services.go @@ -23,7 +23,6 @@ import ( "context" "fmt" "os" - "os/user" "path/filepath" "sort" "strconv" @@ -32,6 +31,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/progress" "github.com/snapcore/snapd/snap" "github.com/snapcore/snapd/snap/quota" diff --git a/wrappers/services_test.go b/wrappers/services_test.go index 1dabc392fe59..cf0399da69d5 100644 --- a/wrappers/services_test.go +++ b/wrappers/services_test.go @@ -23,7 +23,6 @@ import ( "errors" "fmt" "os" - "os/user" "path/filepath" "regexp" "runtime" @@ -39,6 +38,7 @@ import ( // imported to ensure actual interfaces are defined (in production this is guaranteed by ifacestate) _ "github.com/snapcore/snapd/interfaces/builtin" "github.com/snapcore/snapd/osutil" + "github.com/snapcore/snapd/osutil/user" "github.com/snapcore/snapd/progress" "github.com/snapcore/snapd/snap" "github.com/snapcore/snapd/snap/quota"