For #20675 and #25977. - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/Committing-Changes.md#changes-files) for more information. - [x] A detailed QA plan exists on the associated ticket (if it isn't there, work with the product group's QA engineer to add it) - [X] Manual QA for all new/changed functionality - For Orbit and Fleet Desktop changes: - [X] Make sure fleetd is compatible with the latest released version of Fleet (see [Must rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/fleetd-development-and-release-strategy.md)). - [X] Orbit runs on macOS, Linux and Windows. Check if the orbit feature/bugfix should only apply to one platform (`runtime.GOOS`). - [X] Manual QA must be performed in the three main OSs, macOS, Windows and Linux. - [x] Auto-update manual QA, from released version of component to new version (see [tools/tuf/test](../tools/tuf/test/README.md)).
69 lines
1.6 KiB
Go
69 lines
1.6 KiB
Go
//go:build linux
|
|
// +build linux
|
|
|
|
package dconf_read
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"os/exec"
|
|
|
|
"github.com/osquery/osquery-go/plugin/table"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
// Columns is the schema of the table.
|
|
func Columns() []table.ColumnDefinition {
|
|
return []table.ColumnDefinition{
|
|
table.TextColumn("username"), // required
|
|
table.TextColumn("key"), // required
|
|
table.TextColumn("value"),
|
|
}
|
|
}
|
|
|
|
// Generate is called to return the results for the table at query time.
|
|
// Constraints for generating can be retrieved from the queryContext.
|
|
func Generate(ctx context.Context, queryContext table.QueryContext) ([]map[string]string, error) {
|
|
getFirstConstraint := func(columnName string) string {
|
|
if constraints, ok := queryContext.Constraints[columnName]; ok {
|
|
for _, constraint := range constraints.Constraints {
|
|
if constraint.Operator == table.OperatorEquals {
|
|
return constraint.Expression
|
|
}
|
|
}
|
|
}
|
|
return ""
|
|
}
|
|
|
|
username := getFirstConstraint("username")
|
|
if username == "" {
|
|
return nil, errors.New("missing username")
|
|
}
|
|
|
|
key := getFirstConstraint("key")
|
|
if key == "" {
|
|
return nil, errors.New("missing key")
|
|
}
|
|
|
|
cmd := exec.Command("/usr/bin/sudo", "-u", username, "/usr/bin/dconf", "read", key)
|
|
var (
|
|
stdout bytes.Buffer
|
|
stderr bytes.Buffer
|
|
)
|
|
cmd.Stderr = &stderr
|
|
cmd.Stdout = &stdout
|
|
log.Debug().Str("cmd", cmd.String()).Msg("running")
|
|
err := cmd.Run()
|
|
if err != nil {
|
|
return nil, fmt.Errorf("dconf read failed: %w: %s", err, stderr.String())
|
|
}
|
|
|
|
return []map[string]string{{
|
|
"username": username,
|
|
"key": key,
|
|
"value": stdout.String(),
|
|
}}, nil
|
|
}
|