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

Use master.password file and format on freebsd platform #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion cmd/localize/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func main() {
baseIdentity.MergePasswd()
baseIdentity.MergeGroup()

if err := renameio.WriteFile(filepath.Join(*baseDir, "passwd"), baseIdentity.PasswdBytes(), 0644); err != nil {
if err := renameio.WriteFile(filepath.Join(*baseDir, base.PasswdDB), baseIdentity.PasswdBytes(), 0644); err != nil {
log.Error("Error writing passwd", "error", err)
os.Exit(2)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/maps/base/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (b *Base) loadShells() error {
// manipulation. No filtering is done on load, all filtering is
// handled during patching.
func (b *Base) loadPasswd() error {
pf, err := os.Open(filepath.Join(b.baseDir, "passwd"))
pf, err := os.Open(filepath.Join(b.baseDir, PasswdDB))
if err != nil {
return err
}
Expand Down
27 changes: 0 additions & 27 deletions pkg/maps/base/netauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package base

import (
"context"
"path/filepath"

"github.com/netauth/netauth/pkg/netauth"
"github.com/the-maldridge/shadow"
Expand Down Expand Up @@ -135,32 +134,6 @@ func (b *Base) findMembers(ctx context.Context) error {
return nil
}

// MergePasswd removes all entries above the minimum UID and then adds
// NetAuth entities that were filtered above.
func (b *Base) MergePasswd() {
b.passwd.Del(b.passwd.FilterUID(func(i int) bool {
return i >= int(b.minUID)
}))

tmp := make([]*shadow.PasswdEntry, len(b.entities))
idx := 0
for i := range b.entities {
e := shadow.PasswdEntry{
Login: b.entities[i].GetID(),
Password: "*",
UID: int(b.entities[i].GetNumber()),
GID: int(b.pgroups[b.entities[i].GetMeta().GetPrimaryGroup()]),
Comment: b.entities[i].GetMeta().GetGECOS(),
Home: filepath.Join(b.baseHome, b.entities[i].GetID()),
Shell: b.shell(b.entities[i].GetMeta().GetShell()),
}
tmp[idx] = &e
idx++
}

b.passwd.Add(tmp)
}

// MergeGroup removes all group entries above the minimum GID and then
// adds the NetAuth groups that were filtered above.
func (b *Base) MergeGroup() {
Expand Down
38 changes: 38 additions & 0 deletions pkg/maps/base/netauth_freebsd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package base

import (
"path/filepath"

"github.com/the-maldridge/shadow"
)

const (
PasswdDB = "master.passwd"
)

func (b *Base) MergePasswd() {
b.passwd.Del(b.passwd.FilterUID(func(i int) bool {
return i >= int(b.minUID)
}))

tmp := make([]*shadow.PasswdEntry, len(b.entities))
idx := 0
for i := range b.entities {
e := shadow.PasswdEntry{
Login: b.entities[i].GetID(),
Password: "*",
UID: int(b.entities[i].GetNumber()),
GID: int(b.pgroups[b.entities[i].GetMeta().GetPrimaryGroup()]),
Class: "",
Change: "0",
Expire: "0",
Comment: b.entities[i].GetMeta().GetGECOS(),
Home: filepath.Join(b.baseHome, b.entities[i].GetID()),
Shell: b.shell(b.entities[i].GetMeta().GetShell()),
}
tmp[idx] = &e
idx++
}

b.passwd.Add(tmp)
}
37 changes: 37 additions & 0 deletions pkg/maps/base/netauth_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package base

import (
"path/filepath"

"github.com/the-maldridge/shadow"
)

const (
PasswdDB = "passwd"
)

// MergePasswd removes all entries above the minimum UID and then adds
// NetAuth entities that were filtered above.
func (b *Base) MergePasswd() {
b.passwd.Del(b.passwd.FilterUID(func(i int) bool {
return i >= int(b.minUID)
}))

tmp := make([]*shadow.PasswdEntry, len(b.entities))
idx := 0
for i := range b.entities {
e := shadow.PasswdEntry{
Login: b.entities[i].GetID(),
Password: "*",
UID: int(b.entities[i].GetNumber()),
GID: int(b.pgroups[b.entities[i].GetMeta().GetPrimaryGroup()]),
Comment: b.entities[i].GetMeta().GetGECOS(),
Home: filepath.Join(b.baseHome, b.entities[i].GetID()),
Shell: b.shell(b.entities[i].GetMeta().GetShell()),
}
tmp[idx] = &e
idx++
}

b.passwd.Add(tmp)
}