#include <Security/Authorization.h>
#include <Security/AuthorizationEngine.h>
using namespace Authorization;
static const AuthorizationItem gItems[] =
{
{"login", 0, NULL, NULL},
{"reboot", 0, NULL, NULL},
{"shutdown", 0, NULL, NULL},
{"mount", 0, NULL, NULL},
{"login.reboot", 0, NULL, NULL},
{"login.shutdown", 0, NULL, NULL},
{"unmount", 0, NULL, NULL}
};
static const AuthorizationRights gRights =
{
7,
const_cast<AuthorizationItem *>(gItems)
};
void
printRights(const RightSet &rightSet)
{
for(RightSet::const_iterator it = rightSet.begin(); it != rightSet.end(); ++it)
{
printf("right: \"%s\"\n", it->rightName());
}
}
int
main(int argc, char **argv)
{
Engine engine("/tmp/config.plist");
const RightSet inputRights(&gRights);
MutableRightSet outputRights;
printf("InputRights:\n");
printRights(inputRights);
printf("Authorizing:\n");
OSStatus result = engine.authorize(inputRights, NULL,
kAuthorizationFlagInteractionAllowed | kAuthorizationFlagExtendRights | kAuthorizationFlagPartialRights,
NULL, NULL, &outputRights);
printf("Result: %ld\n", result);
printf("OutputRights:\n");
printRights(outputRights);
return 0;
}