-
-
Save fuzzamos/3bec3fde5d26c1ef90588ce18e6786b4 to your computer and use it in GitHub Desktop.
Revisions
-
saelo created this gist
Jul 6, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ import Foundation let rightname = "sys.openfile.readonly./tmp/cantread.txt" var status: OSStatus var authref: AuthorizationRef? let flags = AuthorizationFlags([.interactionAllowed, .extendRights, .preAuthorize]) status = AuthorizationCreate(nil, nil, flags, &authref) assert(status == errAuthorizationSuccess) var item = AuthorizationItem(name: rightname, valueLength: 0, value: nil, flags: 0) var rights = AuthorizationRights(count: 1, items: &item) status = AuthorizationCopyRights(authref!, &rights, nil, flags, nil) assert(status == errAuthorizationSuccess) var token = AuthorizationExternalForm() status = AuthorizationMakeExternalForm(authref!, &token) assert(status == errAuthorizationSuccess) let data = NSData(bytes: &token.bytes, length: kAuthorizationExternalFormLength) data.write(toFile: "./token", atomically: true) print("External form written to ./token") print("Press enter to quit") let _ = readLine()