]> git.saurik.com Git - apple/security.git/blob - securityd/tests/AZNTest.cpp
Security-58286.260.20.tar.gz
[apple/security.git] / securityd / tests / AZNTest.cpp
1 /*
2 * Copyright (c) 2000-2001,2003-2004 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25 /*
26 * AZNTest.cpp
27 * SecurityServer
28 *
29 * Created by michael on Fri Oct 20 2000.
30 */
31
32 #include <Security/Authorization.h>
33
34 #include <Security/AuthorizationEngine.h>
35
36 using namespace Authorization;
37
38 static const AuthorizationItem gItems[] =
39 {
40 {"login", 0, NULL, NULL},
41 {"reboot", 0, NULL, NULL},
42 {"shutdown", 0, NULL, NULL},
43 {"mount", 0, NULL, NULL},
44 {"login.reboot", 0, NULL, NULL},
45 {"login.shutdown", 0, NULL, NULL},
46 {"unmount", 0, NULL, NULL}
47 };
48
49 static const AuthorizationRights gRights =
50 {
51 7,
52 const_cast<AuthorizationItem *>(gItems)
53 };
54
55 void
56 printRights(const RightSet &rightSet)
57 {
58 for(RightSet::const_iterator it = rightSet.begin(); it != rightSet.end(); ++it)
59 {
60 printf("right: \"%s\"\n", it->rightName());
61 }
62 }
63
64 int
65 main(int argc, char **argv)
66 {
67 Engine engine("/tmp/config.plist");
68
69 const RightSet inputRights(&gRights);
70 MutableRightSet outputRights;
71 printf("InputRights:\n");
72 printRights(inputRights);
73 printf("Authorizing:\n");
74 OSStatus result = engine.authorize(inputRights, NULL,
75 kAuthorizationFlagInteractionAllowed | kAuthorizationFlagExtendRights | kAuthorizationFlagPartialRights,
76 NULL, NULL, &outputRights);
77 printf("Result: %ld\n", result);
78 printf("OutputRights:\n");
79 printRights(outputRights);
80 return 0;
81 }