]>
Commit | Line | Data |
---|---|---|
55e303ae A |
1 | /* |
2 | * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
37839358 A |
6 | * The contents of this file constitute Original Code as defined in and |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
55e303ae | 11 | * |
37839358 A |
12 | * This Original Code and all software distributed under the License are |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
55e303ae A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
37839358 A |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
55e303ae A |
19 | * |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* | |
23 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. | |
24 | * | |
25 | */ | |
26 | ||
27 | #include <IOKit/assert.h> | |
28 | #include <IOKit/IOLib.h> | |
29 | #include <IOKit/IOBufferMemoryDescriptor.h> | |
30 | #include "RootDomainUserClient.h" | |
31 | #include <IOKit/pwr_mgt/IOPMLibDefs.h> | |
32 | ||
33 | #define super IOUserClient | |
34 | ||
35 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
36 | ||
37 | OSDefineMetaClassAndStructors(RootDomainUserClient, IOUserClient) | |
38 | ||
39 | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
40 | ||
91447636 A |
41 | bool RootDomainUserClient::initWithTask(task_t owningTask, void *security_id, UInt32) |
42 | { | |
43 | if (!super::init()) | |
44 | return false; | |
45 | ||
46 | fOwningTask = owningTask; | |
47 | task_reference (fOwningTask); | |
48 | return true; | |
49 | } | |
50 | ||
51 | ||
55e303ae A |
52 | bool RootDomainUserClient::start( IOService * provider ) |
53 | { | |
54 | assert(OSDynamicCast(IOPMrootDomain, provider)); | |
55 | if(!super::start(provider)) | |
56 | return false; | |
57 | fOwner = (IOPMrootDomain *)provider; | |
58 | ||
59 | ||
60 | return true; | |
61 | } | |
62 | ||
91447636 A |
63 | IOReturn RootDomainUserClient::secureSleepSystem( int *return_code ) |
64 | { | |
65 | int local_priv = 0; | |
66 | int admin_priv = 0; | |
67 | IOReturn ret = kIOReturnNotPrivileged; | |
68 | ||
69 | ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeLocalUser); | |
70 | local_priv = (kIOReturnSuccess == ret); | |
71 | ||
72 | ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeAdministrator); | |
73 | admin_priv = (kIOReturnSuccess == ret); | |
74 | ||
75 | if((local_priv || admin_priv) && fOwner) { | |
76 | *return_code = fOwner->sleepSystem(); | |
77 | return kIOReturnSuccess; | |
78 | } else { | |
79 | *return_code = kIOReturnNotPrivileged; | |
80 | return kIOReturnSuccess; | |
81 | } | |
82 | ||
83 | } | |
84 | ||
85 | IOReturn RootDomainUserClient::secureSetAggressiveness( | |
86 | unsigned long type, | |
87 | unsigned long newLevel, | |
88 | int *return_code ) | |
89 | { | |
90 | int local_priv = 0; | |
91 | int admin_priv = 0; | |
92 | IOReturn ret = kIOReturnNotPrivileged; | |
93 | ||
94 | ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeLocalUser); | |
95 | local_priv = (kIOReturnSuccess == ret); | |
96 | ||
97 | ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeAdministrator); | |
98 | admin_priv = (kIOReturnSuccess == ret); | |
99 | ||
100 | if((local_priv || admin_priv) && fOwner) { | |
101 | *return_code = fOwner->setAggressiveness(type, newLevel); | |
102 | return kIOReturnSuccess; | |
103 | } else { | |
104 | *return_code = kIOReturnNotPrivileged; | |
105 | return kIOReturnSuccess; | |
106 | } | |
107 | ||
108 | } | |
109 | ||
55e303ae A |
110 | |
111 | IOReturn RootDomainUserClient::clientClose( void ) | |
112 | { | |
113 | detach(fOwner); | |
91447636 A |
114 | |
115 | if(fOwningTask) { | |
116 | task_deallocate(fOwningTask); | |
117 | fOwningTask = 0; | |
118 | } | |
119 | ||
55e303ae A |
120 | return kIOReturnSuccess; |
121 | } | |
122 | ||
123 | IOExternalMethod * | |
124 | RootDomainUserClient::getTargetAndMethodForIndex( IOService ** targetP, UInt32 index ) | |
125 | { | |
126 | static IOExternalMethod sMethods[] = { | |
127 | { // kPMSetAggressiveness, 0 | |
91447636 | 128 | 1, (IOMethod)&RootDomainUserClient::secureSetAggressiveness, kIOUCScalarIScalarO, 2, 1 |
55e303ae A |
129 | }, |
130 | { // kPMGetAggressiveness, 1 | |
131 | 0, (IOMethod)&IOPMrootDomain::getAggressiveness, kIOUCScalarIScalarO, 1, 1 | |
132 | }, | |
133 | { // kPMSleepSystem, 2 | |
91447636 | 134 | 1, (IOMethod)&RootDomainUserClient::secureSleepSystem, kIOUCScalarIScalarO, 0, 1 |
55e303ae A |
135 | }, |
136 | { // kPMAllowPowerChange, 3 | |
137 | 0, (IOMethod)&IOPMrootDomain::allowPowerChange, kIOUCScalarIScalarO, 1, 0 | |
138 | }, | |
139 | { // kPMCancelPowerChange, 4 | |
140 | 0, (IOMethod)&IOPMrootDomain::cancelPowerChange, kIOUCScalarIScalarO, 1, 0 | |
141 | }, | |
142 | { // kPMShutdownSystem, 5 | |
143 | 0, (IOMethod)&IOPMrootDomain::shutdownSystem, kIOUCScalarIScalarO, 0, 0 | |
144 | }, | |
145 | { // kPMRestartSystem, 6 | |
146 | 0, (IOMethod)&IOPMrootDomain::restartSystem, kIOUCScalarIScalarO, 0, 0 | |
147 | }, | |
148 | { // kPMSetPreventative, 7 | |
149 | 1, (IOMethod) &RootDomainUserClient::setPreventative, kIOUCScalarIScalarO, 2, 0 | |
150 | }, | |
151 | }; | |
91447636 | 152 | |
55e303ae A |
153 | if(index >= kNumPMMethods) |
154 | return NULL; | |
155 | else { | |
156 | if (sMethods[index].object) | |
157 | *targetP = this; | |
158 | else | |
159 | *targetP = fOwner; | |
160 | ||
161 | return &sMethods[index]; | |
162 | } | |
163 | } | |
164 | ||
165 | void | |
166 | RootDomainUserClient::setPreventative(UInt32 on_off, UInt32 types_of_sleep) | |
167 | { | |
168 | return; | |
169 | } | |
170 |