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