cmd/fuserdb: generate group entries
Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
This commit is contained in:
parent
6a6d30af1f
commit
2e23cef7bb
|
@ -2,7 +2,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -46,18 +45,9 @@ func main() {
|
||||||
fmsg.Fatalf("cannot create output: %v", err)
|
fmsg.Fatalf("cannot create output: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
type payload struct {
|
|
||||||
UserName string `json:"userName"`
|
|
||||||
Uid int `json:"uid"`
|
|
||||||
Gid int `json:"gid"`
|
|
||||||
RealName string `json:"realName"`
|
|
||||||
HomeDirectory string `json:"homeDirectory"`
|
|
||||||
Shell string `json:"shell"`
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, u := range users {
|
for _, u := range users {
|
||||||
fidString := strconv.Itoa(u.fid)
|
fidString := strconv.Itoa(u.fid)
|
||||||
for aid := 0; aid < 9999; aid++ {
|
for aid := 0; aid < 10000; aid++ {
|
||||||
userName := fmt.Sprintf("u%d_a%d", u.fid, aid)
|
userName := fmt.Sprintf("u%d_a%d", u.fid, aid)
|
||||||
uid := 1000000 + u.fid*10000 + aid
|
uid := 1000000 + u.fid*10000 + aid
|
||||||
us := strconv.Itoa(uid)
|
us := strconv.Itoa(uid)
|
||||||
|
@ -69,27 +59,11 @@ func main() {
|
||||||
homeDirectory = varEmpty
|
homeDirectory = varEmpty
|
||||||
}
|
}
|
||||||
|
|
||||||
fileName := userName + ".user"
|
writeUser(userName, uid, us, realName, homeDirectory, *shell, *out)
|
||||||
if f, err := os.OpenFile(path.Join(*out, fileName), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644); err != nil {
|
writeGroup(userName, uid, us, nil, *out)
|
||||||
fmsg.Fatalf("cannot create %s: %v", userName, err)
|
|
||||||
} else if err = json.NewEncoder(f).Encode(&payload{
|
|
||||||
UserName: userName,
|
|
||||||
Uid: uid,
|
|
||||||
Gid: uid,
|
|
||||||
RealName: realName,
|
|
||||||
HomeDirectory: homeDirectory,
|
|
||||||
Shell: *shell,
|
|
||||||
}); err != nil {
|
|
||||||
fmsg.Fatalf("cannot serialise %s: %v", userName, err)
|
|
||||||
} else if err = f.Close(); err != nil {
|
|
||||||
fmsg.Printf("cannot close %s: %v", userName, err)
|
|
||||||
}
|
|
||||||
if err := os.Symlink(fileName, path.Join(*out, us+".user")); err != nil {
|
|
||||||
fmsg.Fatalf("cannot link %s: %v", userName, err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmsg.Printf("created %d entries", len(users)*10000)
|
fmsg.Printf("created %d entries", len(users)*2*10000)
|
||||||
fmsg.Exit(0)
|
fmsg.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
|
||||||
|
"git.ophivana.moe/security/fortify/internal/fmsg"
|
||||||
|
)
|
||||||
|
|
||||||
|
type payloadU struct {
|
||||||
|
UserName string `json:"userName"`
|
||||||
|
Uid int `json:"uid"`
|
||||||
|
Gid int `json:"gid"`
|
||||||
|
MemberOf []string `json:"memberOf,omitempty"`
|
||||||
|
RealName string `json:"realName"`
|
||||||
|
HomeDirectory string `json:"homeDirectory"`
|
||||||
|
Shell string `json:"shell"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeUser(userName string, uid int, us string, realName, homeDirectory, shell string, out string) {
|
||||||
|
userFileName := userName + ".user"
|
||||||
|
if f, err := os.OpenFile(path.Join(out, userFileName), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644); err != nil {
|
||||||
|
fmsg.Fatalf("cannot create %s: %v", userName, err)
|
||||||
|
} else if err = json.NewEncoder(f).Encode(&payloadU{
|
||||||
|
UserName: userName,
|
||||||
|
Uid: uid,
|
||||||
|
Gid: uid,
|
||||||
|
RealName: realName,
|
||||||
|
HomeDirectory: homeDirectory,
|
||||||
|
Shell: shell,
|
||||||
|
}); err != nil {
|
||||||
|
fmsg.Fatalf("cannot serialise %s: %v", userName, err)
|
||||||
|
} else if err = f.Close(); err != nil {
|
||||||
|
fmsg.Printf("cannot close %s: %v", userName, err)
|
||||||
|
}
|
||||||
|
if err := os.Symlink(userFileName, path.Join(out, us+".user")); err != nil {
|
||||||
|
fmsg.Fatalf("cannot link %s: %v", userName, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type payloadG struct {
|
||||||
|
GroupName string `json:"groupName"`
|
||||||
|
Gid int `json:"gid"`
|
||||||
|
Members []string `json:"members,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeGroup(groupName string, gid int, gs string, members []string, out string) {
|
||||||
|
groupFileName := groupName + ".group"
|
||||||
|
if f, err := os.OpenFile(path.Join(out, groupFileName), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644); err != nil {
|
||||||
|
fmsg.Fatalf("cannot create %s: %v", groupName, err)
|
||||||
|
} else if err = json.NewEncoder(f).Encode(&payloadG{
|
||||||
|
GroupName: groupName,
|
||||||
|
Gid: gid,
|
||||||
|
Members: members,
|
||||||
|
}); err != nil {
|
||||||
|
fmsg.Fatalf("cannot serialise %s: %v", groupName, err)
|
||||||
|
} else if err = f.Close(); err != nil {
|
||||||
|
fmsg.Printf("cannot close %s: %v", groupName, err)
|
||||||
|
}
|
||||||
|
if err := os.Symlink(groupFileName, path.Join(out, gs+".group")); err != nil {
|
||||||
|
fmsg.Fatalf("cannot link %s: %v", groupName, err)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue