Skip to content

Commit 7068458

Browse files
committed
Refactored code
1 parent 06cfc6c commit 7068458

File tree

7 files changed

+34
-16
lines changed

7 files changed

+34
-16
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
*.test
1212

1313
# Output of the go coverage tool, specifically when used with LiteIDE
14-
*.out
14+
*.out

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ GoSDDL (Security Descriptor Definition Language)
33
[![Build Status](https://travis-ci.org/MonaxGT/gosddl.svg?branch=master)](https://travis-ci.org/MonaxGT/gosddl)
44
[![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)
55
[![Maintainability](https://api.codeclimate.com/v1/badges/69e05e119408b9f830d4/maintainability)](https://codeclimate.com/github/MonaxGT/gosddl/maintainability)
6+
[![Go Report Card](https://goreportcard.com/badge/github.com/MonaxGT/gosddl)](https://goreportcard.com/report/github.com/MonaxGT/gosddl)
67

78
Converter from SDDL-string to user-friendly JSON. SDDL consist of four part: Owner, Primary Group, DACL, SACL.
89
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
5758

5859
Links:
5960

60-
[Source](https://docs.microsoft.com/en-us/windows/desktop/secauthz/security-descriptor-definition-language)
61+
[Source](https://docs.microsoft.com/en-us/windows/desktop/secauthz/security-descriptor-definition-language)

gosddl.go

+18-8
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import (
99
"strings"
1010

1111
"encoding/json"
12+
"github.com/pkg/errors"
1213
)
1314

1415
// ACLProcessor main struct with methods
1516
type ACLProcessor struct {
16-
Rights Permissons
17+
Rights permissons
1718
File string
1819
}
1920

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

29-
type Permissons struct {
30+
type permissons struct {
3031
Owner string `json:"owner,omitempty"`
3132
Primary string `json:"primary,omitempty"`
3233
Dacl []entryACL `json:"dacl,omitempty"`
@@ -165,33 +166,42 @@ func (app *ACLProcessor) sliceSDDL(indecs []int, str string) {
165166
}
166167

167168
// FindGroupIndex used for find index of group Owner, Primary, DACL, SACL
168-
func (app *ACLProcessor) findGroupIndex(str string) {
169+
func (app *ACLProcessor) findGroupIndex(str string) error {
169170
groups := []string{"O:", "G:", "D:", "S:"}
170171
var result []int
171172
for _, i := range groups {
172173
if strings.Index(str, i) != -1 {
173174
result = append(result, strings.Index(str, i))
174175
}
175176
}
177+
if result == nil {
178+
return errors.New("Can't find any group")
179+
}
176180
result = append(result, len(str))
177181
app.sliceSDDL(result, str)
182+
return nil
178183
}
179184

180185
// Processor main function in gosddl package
181-
func Processor(api bool, port string, file string) {
186+
func Processor(api bool, port string, file string) error {
182187
var app ACLProcessor
183188
app.File = file
184189
if api {
185190
fmt.Println("API Interface started on port", port)
186191
app.httpHandler(port)
187192
} else if flag.Args() != nil {
188-
app.findGroupIndex(flag.Args()[0])
193+
err := app.findGroupIndex(flag.Args()[0])
194+
if err != nil {
195+
return err
196+
}
189197
body, err := json.Marshal(app.Rights)
190198
if err != nil {
191199
log.Fatal(err)
200+
return err
192201
}
193202
fmt.Println(string(body))
194-
} else {
195-
log.Fatal("You should give me SDDL string or use API mode")
203+
return nil
196204
}
197-
}
205+
log.Fatal("You should give me SDDL string or use API mode")
206+
return nil
207+
}

http.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ func (app *ACLProcessor) decode(w http.ResponseWriter, r *http.Request) {
1616
params := mux.Vars(r)
1717
if params["sddl"] != "" {
1818
sddl := params["sddl"]
19-
app.findGroupIndex(sddl)
19+
err := app.findGroupIndex(sddl)
20+
if err != nil {
21+
log.Println("Wrong SDDL string")
22+
}
2023
json.NewEncoder(w).Encode(app.Rights)
24+
app.Rights = permissons{}
2125
return
2226
}
2327
}
@@ -27,4 +31,4 @@ func (app *ACLProcessor) httpHandler(port string) {
2731
router.HandleFunc("/sddl", getInfo).Methods("GET")
2832
router.HandleFunc("/sddl/{sddl}", app.decode).Methods("GET")
2933
log.Fatal(http.ListenAndServe(port, router))
30-
}
34+
}

http_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ func TestGetInfo(t *testing.T) {
2323
t.Errorf("handler returned unexpected body: got %v want %v",
2424
rr.Body.String(), expected)
2525
}
26-
}
26+
}

maps.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,4 @@ var sddlWellKnownSidsRep = map[string]string{
181181
"S-1-5-32-579": "BUILTIN\\Access Control Assistance Operators",
182182
"S-1-5-32-580": "BUILTIN\\Remote Management Users",
183183
"S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464": "Trusted Installer",
184-
}
184+
}

service/gosddl/main.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@ func main() {
1111
apiPortPtr := flag.String("port", ":8000", "Default port 8000")
1212
fileSIDs := flag.String("f", "", "File with users's SIDs")
1313
flag.Parse()
14-
gosddl.Processor(*apiPtr, *apiPortPtr, *fileSIDs)
15-
}
14+
err := gosddl.Processor(*apiPtr, *apiPortPtr, *fileSIDs)
15+
if err != nil {
16+
panic(err)
17+
}
18+
}

0 commit comments

Comments
 (0)