Skip to content

Instantly share code, notes, and snippets.

@jouyouyun
Last active August 29, 2015 13:56
Show Gist options
  • Save jouyouyun/9181226 to your computer and use it in GitHub Desktop.
Save jouyouyun/9181226 to your computer and use it in GitHub Desktop.
Test PolicyKit
type polkitSubject struct {
/*
* The following kinds of subjects are known:
* Unix Process: should be set to unix-process with keys
* pid (of type uint32) and
* start-time (of type uint64)
* Unix Session: should be set to unix-session with the key
* session-id (of type string)
* System Bus Name: should be set to system-bus-name with the key
* name (of type string)
*/
subjectKind string
subjectDetails map[string]interface{}
}
func authWithPolkit(actionId string) {
var (
objPolkit *polkit.Authority
//objDbus *freedbus.DBusDaemon
err error
)
objPolkit, err = polkit.NewAuthority(POLKIT_PATH)
if err != nil {
fmt.Println("New Authority Failed:", err)
panic(err)
}
pid := os.Getpid()
subject := polkitSubject{}
subject.subjectKind = "unix-process"
subject.subjectDetails = make(map[string]interface{})
subject.subjectDetails["pid"] = uint32(pid)
subject.subjectDetails["start-time"] = uint64(0)
details := make(map[string]string)
flags := uint32(1)
cancelId := ""
infaces := []interface{}{}
infaces = append(infaces, subject)
_, err = objPolkit.CheckAuthorization(infaces, actionId, details, flags, cancelId)
if err != nil {
fmt.Println("CheckAuthorization Failed:", err)
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment