util: Add a helper to get the users shell entry

This commit is contained in:
James Shubin
2025-02-07 17:13:38 -05:00
parent ecd5a0f304
commit f51a1200d1
2 changed files with 123 additions and 4 deletions

View File

@@ -42,6 +42,7 @@ import (
"github.com/purpleidea/mgmt/engine"
"github.com/purpleidea/mgmt/engine/traits"
"github.com/purpleidea/mgmt/util"
"github.com/purpleidea/mgmt/util/errwrap"
"github.com/purpleidea/mgmt/util/recwatch"
)
@@ -50,8 +51,6 @@ func init() {
engine.RegisterResource("user", func() engine.Res { return &UserRes{} })
}
const passwdFile = "/etc/passwd"
// UserRes is a user account resource.
type UserRes struct {
traits.Base // add the base methods without re-implementation
@@ -141,7 +140,7 @@ func (obj *UserRes) Cleanup() error {
// Watch is the primary listener for this resource and it outputs events.
func (obj *UserRes) Watch(ctx context.Context) error {
var err error
obj.recWatcher, err = recwatch.NewRecWatcher(passwdFile, false)
obj.recWatcher, err = recwatch.NewRecWatcher(util.EtcPasswdFile, false)
if err != nil {
return err
}
@@ -152,7 +151,7 @@ func (obj *UserRes) Watch(ctx context.Context) error {
var send = false // send event?
for {
if obj.init.Debug {
obj.init.Logf("watching: %s", passwdFile) // attempting to watch...
obj.init.Logf("watching: %s", util.EtcPasswdFile) // attempting to watch...
}
select {