Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dead code cleanup #638

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions internal/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,6 @@ func GetNorduserSocketFork(uid int) string {
return fmt.Sprintf("/tmp/%d-%s.sock", uid, Norduserd)
}

// GetFilesharedPid to save fileshare daemon pid
func GetFilesharedPid(uid int) string {
_, err := os.Stat(fmt.Sprintf("/run/user/%d", uid))
if uid == 0 || os.IsNotExist(err) {
return fmt.Sprintf("/run/%s/%s.pid", Fileshare, Fileshare)
}
return fmt.Sprintf("/run/user/%d/%s/%s.pid", uid, Fileshare, Fileshare)
}

func getHomeDirPath(homeDirectory string) (string, error) {
snapUserDataDir := os.Getenv("SNAP_USER_COMMON")
if snapUserDataDir != "" {
Expand Down
75 changes: 0 additions & 75 deletions internal/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,21 +264,6 @@ func FileCreate(path string, permissions os.FileMode) (*os.File, error) {
return file, nil
}

// FileCreateForUser but leave closing to the caller.
func FileCreateForUser(path string, permissions os.FileMode, uid int, gid int) (*os.File, error) {
file, err := FileCreate(path, permissions)
if err != nil {
return nil, err
}

if err := file.Chown(uid, gid); err != nil {
// #nosec G104 -- no writes were made
file.Close()
return nil, err
}
return file, nil
}

// FileRead reads all file
func FileRead(file string) ([]byte, error) {
// #nosec G304 -- no input comes from the user
Expand Down Expand Up @@ -437,66 +422,6 @@ func MachineID() uuid.UUID {
return uuid.NewSHA1(machineUUID, []byte(hostname))
}

// SystemUsers returns all non-root user names
func SystemUsers() ([]string, error) {
// get list of 'human' users on the host system
out, err := exec.Command("sh", "-c", "awk -F$':' 'BEGIN { ORS=\" \" }; { if ($3 >= 1000 && $3 < 2000) print $1; }' /etc/passwd").CombinedOutput()
if err != nil {
return nil, err
}
return strings.Split(strings.Trim(string(out), " \n"), " "), nil
}

// SystemUsersIDs returns all non-root user ids
func SystemUsersIDs() ([]int64, error) {
users, err := SystemUsers()
if err != nil {
return nil, err
}
var ids []int64
for _, u := range users {
// #nosec G204 -- input is properly sanitized
out, err := exec.Command(
"awk",
"-v", fmt.Sprintf("val=%s", u),
"-F", ":",
"$1==val{print $3}",
"/etc/passwd",
).CombinedOutput()
if err != nil {
continue
}
id, err := strconv.ParseInt(strings.Trim(string(out), "\n"), 10, 64)
if err != nil {
continue
}
ids = append(ids, id)
}
return ids, nil
}

// DBUSSessionBusAddress finds user dbus session bus address
func DBUSSessionBusAddress(id int64) (string, error) {
// #nosec G204 -- input is properly sanitized
out, err := exec.Command("ps", "-u", fmt.Sprintf("%d", id), "-o", "pid=").CombinedOutput()
if err != nil {
return "", fmt.Errorf("listing processes for uid: %w", err)
}
for _, number := range strings.Split(strings.Trim(string(out), "\n"), "\n") {
pid, err := strconv.ParseInt(strings.Trim(strings.Trim(number, "\n"), " "), 10, 64)
if err != nil {
continue
}
out, _ := os.ReadFile(fmt.Sprintf("/proc/%d/environ", pid))
for _, env := range strings.Split(string(out), "\000") {
if strings.Contains(env, "DBUS_SESSION_BUS_ADDRESS") {
return env, nil
}
}
}
return "", nil
}

type NetLink struct {
Name string
Address string
Expand Down
39 changes: 0 additions & 39 deletions internal/listener.go

This file was deleted.

11 changes: 0 additions & 11 deletions internal/timezone.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package internal

import (
"crypto/sha256"
"fmt"
"os"
"os/exec"
"strings"
Expand Down Expand Up @@ -36,12 +34,3 @@ func extractZone(input []byte) string {
}
return ""
}

// Obfuscate given string
func Obfuscate(text string) string {
// removing excess symbols which might interfere with hashing
text = strings.TrimSpace(text)

sum := sha256.Sum256([]byte(text))
return fmt.Sprintf("%x", sum[:7])
}
Loading
Loading