]> git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/RootDomainUserClient.cpp
cec08ad97e1aa6089faade75cdffae7e06396df4
[apple/xnu.git] / iokit / Kernel / RootDomainUserClient.cpp
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_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. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
32 *
33 */
34
35 #include <IOKit/assert.h>
36 #include <IOKit/IOLib.h>
37 #include <IOKit/IOKitKeys.h>
38 #include <IOKit/IOBufferMemoryDescriptor.h>
39 #include "RootDomainUserClient.h"
40 #include <IOKit/pwr_mgt/IOPMLibDefs.h>
41
42 #define super IOUserClient
43
44 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
45
46 OSDefineMetaClassAndStructors(RootDomainUserClient, IOUserClient)
47
48 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
49
50 bool RootDomainUserClient::initWithTask(task_t owningTask, void *security_id,
51 UInt32 type, OSDictionary * properties)
52 {
53 if (properties)
54 properties->setObject(kIOUserClientCrossEndianCompatibleKey, kOSBooleanTrue);
55
56 if (!super::initWithTask(owningTask, security_id, type, properties))
57 return false;
58
59 fOwningTask = owningTask;
60 task_reference (fOwningTask);
61 return true;
62 }
63
64
65 bool RootDomainUserClient::start( IOService * provider )
66 {
67 assert(OSDynamicCast(IOPMrootDomain, provider));
68 if(!super::start(provider))
69 return false;
70 fOwner = (IOPMrootDomain *)provider;
71
72
73 return true;
74 }
75
76 IOReturn RootDomainUserClient::secureSleepSystem( int *return_code )
77 {
78 int local_priv = 0;
79 int admin_priv = 0;
80 IOReturn ret = kIOReturnNotPrivileged;
81
82 ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeLocalUser);
83 local_priv = (kIOReturnSuccess == ret);
84
85 ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeAdministrator);
86 admin_priv = (kIOReturnSuccess == ret);
87
88 if((local_priv || admin_priv) && fOwner) {
89 *return_code = fOwner->sleepSystem();
90 return kIOReturnSuccess;
91 } else {
92 *return_code = kIOReturnNotPrivileged;
93 return kIOReturnSuccess;
94 }
95
96 }
97
98 IOReturn RootDomainUserClient::secureSetAggressiveness(
99 unsigned long type,
100 unsigned long newLevel,
101 int *return_code )
102 {
103 int local_priv = 0;
104 int admin_priv = 0;
105 IOReturn ret = kIOReturnNotPrivileged;
106
107 ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeLocalUser);
108 local_priv = (kIOReturnSuccess == ret);
109
110 ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeAdministrator);
111 admin_priv = (kIOReturnSuccess == ret);
112
113 if((local_priv || admin_priv) && fOwner) {
114 *return_code = fOwner->setAggressiveness(type, newLevel);
115 return kIOReturnSuccess;
116 } else {
117 *return_code = kIOReturnNotPrivileged;
118 return kIOReturnSuccess;
119 }
120
121 }
122
123
124 IOReturn RootDomainUserClient::clientClose( void )
125 {
126 detach(fOwner);
127
128 if(fOwningTask) {
129 task_deallocate(fOwningTask);
130 fOwningTask = 0;
131 }
132
133 return kIOReturnSuccess;
134 }
135
136 IOExternalMethod *
137 RootDomainUserClient::getTargetAndMethodForIndex( IOService ** targetP, UInt32 index )
138 {
139 static IOExternalMethod sMethods[] = {
140 { // kPMSetAggressiveness, 0
141 (IOService *)1, (IOMethod)&RootDomainUserClient::secureSetAggressiveness, kIOUCScalarIScalarO, 2, 1
142 },
143 { // kPMGetAggressiveness, 1
144 0, (IOMethod)&IOPMrootDomain::getAggressiveness, kIOUCScalarIScalarO, 1, 1
145 },
146 { // kPMSleepSystem, 2
147 (IOService *)1, (IOMethod)&RootDomainUserClient::secureSleepSystem, kIOUCScalarIScalarO, 0, 1
148 },
149 { // kPMAllowPowerChange, 3
150 0, (IOMethod)&IOPMrootDomain::allowPowerChange, kIOUCScalarIScalarO, 1, 0
151 },
152 { // kPMCancelPowerChange, 4
153 0, (IOMethod)&IOPMrootDomain::cancelPowerChange, kIOUCScalarIScalarO, 1, 0
154 },
155 { // kPMShutdownSystem, 5
156 0, (IOMethod)&IOPMrootDomain::shutdownSystem, kIOUCScalarIScalarO, 0, 0
157 },
158 { // kPMRestartSystem, 6
159 0, (IOMethod)&IOPMrootDomain::restartSystem, kIOUCScalarIScalarO, 0, 0
160 },
161 { // kPMSetPreventative, 7
162 (IOService *)1, (IOMethod)&RootDomainUserClient::setPreventative, kIOUCScalarIScalarO, 2, 0
163 },
164 };
165
166 if(index >= kNumPMMethods)
167 return NULL;
168 else {
169 if (sMethods[index].object)
170 *targetP = this;
171 else
172 *targetP = fOwner;
173
174 return &sMethods[index];
175 }
176 }
177
178 void
179 RootDomainUserClient::setPreventative(UInt32 on_off, UInt32 types_of_sleep)
180 {
181 return;
182 }
183