Skip to content

Commit

Permalink
Merge pull request #7 from MonaxGT/develop
Browse files Browse the repository at this point in the history
Refactored code
  • Loading branch information
MonaxGT authored Dec 28, 2018
2 parents 06cfc6c + 7068458 commit 059b023
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
*.out
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ GoSDDL (Security Descriptor Definition Language)
[![Build Status](https://travis-ci.org/MonaxGT/gosddl.svg?branch=master)](https://travis-ci.org/MonaxGT/gosddl)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/70d6bf54dd2547d894ee7ba7a9247285)](https://app.codacy.com/app/MonaxGT/gosddl?utm_source=github.com&utm_medium=referral&utm_content=MonaxGT/gosddl&utm_campaign=Badge_Grade_Dashboard)
[![Maintainability](https://api.codeclimate.com/v1/badges/69e05e119408b9f830d4/maintainability)](https://codeclimate.com/github/MonaxGT/gosddl/maintainability)
[![Go Report Card](https://goreportcard.com/badge/github.com/MonaxGT/gosddl)](https://goreportcard.com/report/github.com/MonaxGT/gosddl)

Converter from SDDL-string to user-friendly JSON. SDDL consist of four part: Owner, Primary Group, DACL, SACL.
This converter works with two mode:
Expand Down Expand Up @@ -57,4 +58,4 @@ docker run --rm -it -v $PWD/store:/app/data gosddl "O:BAG:SYD:(D;;GA;;;AN)(D;;GA

Links:

[Source](https://docs.microsoft.com/en-us/windows/desktop/secauthz/security-descriptor-definition-language)
[Source](https://docs.microsoft.com/en-us/windows/desktop/secauthz/security-descriptor-definition-language)
26 changes: 18 additions & 8 deletions gosddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import (
"strings"

"encoding/json"
"github.com/pkg/errors"
)

// ACLProcessor main struct with methods
type ACLProcessor struct {
Rights Permissons
Rights permissons
File string
}

Expand All @@ -26,7 +27,7 @@ type entryACL struct {
InheritObjectGUID string `json:"inheritObjectGUID,omitempty"`
}

type Permissons struct {
type permissons struct {
Owner string `json:"owner,omitempty"`
Primary string `json:"primary,omitempty"`
Dacl []entryACL `json:"dacl,omitempty"`
Expand Down Expand Up @@ -165,33 +166,42 @@ func (app *ACLProcessor) sliceSDDL(indecs []int, str string) {
}

// FindGroupIndex used for find index of group Owner, Primary, DACL, SACL
func (app *ACLProcessor) findGroupIndex(str string) {
func (app *ACLProcessor) findGroupIndex(str string) error {
groups := []string{"O:", "G:", "D:", "S:"}
var result []int
for _, i := range groups {
if strings.Index(str, i) != -1 {
result = append(result, strings.Index(str, i))
}
}
if result == nil {
return errors.New("Can't find any group")
}
result = append(result, len(str))
app.sliceSDDL(result, str)
return nil
}

// Processor main function in gosddl package
func Processor(api bool, port string, file string) {
func Processor(api bool, port string, file string) error {
var app ACLProcessor
app.File = file
if api {
fmt.Println("API Interface started on port", port)
app.httpHandler(port)
} else if flag.Args() != nil {
app.findGroupIndex(flag.Args()[0])
err := app.findGroupIndex(flag.Args()[0])
if err != nil {
return err
}
body, err := json.Marshal(app.Rights)
if err != nil {
log.Fatal(err)
return err
}
fmt.Println(string(body))
} else {
log.Fatal("You should give me SDDL string or use API mode")
return nil
}
}
log.Fatal("You should give me SDDL string or use API mode")
return nil
}
8 changes: 6 additions & 2 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ func (app *ACLProcessor) decode(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
if params["sddl"] != "" {
sddl := params["sddl"]
app.findGroupIndex(sddl)
err := app.findGroupIndex(sddl)
if err != nil {
log.Println("Wrong SDDL string")
}
json.NewEncoder(w).Encode(app.Rights)
app.Rights = permissons{}
return
}
}
Expand All @@ -27,4 +31,4 @@ func (app *ACLProcessor) httpHandler(port string) {
router.HandleFunc("/sddl", getInfo).Methods("GET")
router.HandleFunc("/sddl/{sddl}", app.decode).Methods("GET")
log.Fatal(http.ListenAndServe(port, router))
}
}
2 changes: 1 addition & 1 deletion http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ func TestGetInfo(t *testing.T) {
t.Errorf("handler returned unexpected body: got %v want %v",
rr.Body.String(), expected)
}
}
}
2 changes: 1 addition & 1 deletion maps.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,4 @@ var sddlWellKnownSidsRep = map[string]string{
"S-1-5-32-579": "BUILTIN\\Access Control Assistance Operators",
"S-1-5-32-580": "BUILTIN\\Remote Management Users",
"S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464": "Trusted Installer",
}
}
7 changes: 5 additions & 2 deletions service/gosddl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ func main() {
apiPortPtr := flag.String("port", ":8000", "Default port 8000")
fileSIDs := flag.String("f", "", "File with users's SIDs")
flag.Parse()
gosddl.Processor(*apiPtr, *apiPortPtr, *fileSIDs)
}
err := gosddl.Processor(*apiPtr, *apiPortPtr, *fileSIDs)
if err != nil {
panic(err)
}
}

0 comments on commit 059b023

Please sign in to comment.