diff --git a/.gitignore b/.gitignore index a5b2d53..87597a1 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,4 @@ *.test # Output of the go coverage tool, specifically when used with LiteIDE -*.out +*.out \ No newline at end of file diff --git a/README.md b/README.md index 4b4aa7a..6c57b19 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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) \ No newline at end of file diff --git a/gosddl.go b/gosddl.go index d19d596..e40d83c 100644 --- a/gosddl.go +++ b/gosddl.go @@ -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 } @@ -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"` @@ -165,7 +166,7 @@ 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 { @@ -173,25 +174,34 @@ func (app *ACLProcessor) findGroupIndex(str string) { 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 +} \ No newline at end of file diff --git a/http.go b/http.go index d16d800..ce735bc 100644 --- a/http.go +++ b/http.go @@ -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 } } @@ -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)) -} +} \ No newline at end of file diff --git a/http_test.go b/http_test.go index 584449f..7d9e172 100644 --- a/http_test.go +++ b/http_test.go @@ -23,4 +23,4 @@ func TestGetInfo(t *testing.T) { t.Errorf("handler returned unexpected body: got %v want %v", rr.Body.String(), expected) } -} +} \ No newline at end of file diff --git a/maps.go b/maps.go index 8977600..a34ca57 100644 --- a/maps.go +++ b/maps.go @@ -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", -} +} \ No newline at end of file diff --git a/service/gosddl/main.go b/service/gosddl/main.go index d661fe7..2a94773 100644 --- a/service/gosddl/main.go +++ b/service/gosddl/main.go @@ -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) + } +} \ No newline at end of file