]> git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/RootDomainUserClient.cpp
xnu-792.21.3.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/IOBufferMemoryDescriptor.h>
36 #include "RootDomainUserClient.h"
37 #include <IOKit/pwr_mgt/IOPMLibDefs.h>
38
39 #define super IOUserClient
40
41 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
42
43 OSDefineMetaClassAndStructors(RootDomainUserClient, IOUserClient)
44
45 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
46
47 bool RootDomainUserClient::initWithTask(task_t owningTask, void *security_id, UInt32)
48 {
49 if (!super::init())
50 return false;
51
52 fOwningTask = owningTask;
53 task_reference (fOwningTask);
54 return true;
55 }
56
57
58 bool RootDomainUserClient::start( IOService * provider )
59 {
60 assert(OSDynamicCast(IOPMrootDomain, provider));
61 if(!super::start(provider))
62 return false;
63 fOwner = (IOPMrootDomain *)provider;
64
65
66 return true;
67 }
68
69 IOReturn RootDomainUserClient::secureSleepSystem( int *return_code )
70 {
71 int local_priv = 0;
72 int admin_priv = 0;
73 IOReturn ret = kIOReturnNotPrivileged;
74
75 ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeLocalUser);
76 local_priv = (kIOReturnSuccess == ret);
77
78 ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeAdministrator);
79 admin_priv = (kIOReturnSuccess == ret);
80
81 if((local_priv || admin_priv) && fOwner) {
82 *return_code = fOwner->sleepSystem();
83 return kIOReturnSuccess;
84 } else {
85 *return_code = kIOReturnNotPrivileged;
86 return kIOReturnSuccess;
87 }
88
89 }
90
91 IOReturn RootDomainUserClient::secureSetAggressiveness(
92 unsigned long type,
93 unsigned long newLevel,
94 int *return_code )
95 {
96 int local_priv = 0;
97 int admin_priv = 0;
98 IOReturn ret = kIOReturnNotPrivileged;
99
100 ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeLocalUser);
101 local_priv = (kIOReturnSuccess == ret);
102
103 ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeAdministrator);
104 admin_priv = (kIOReturnSuccess == ret);
105
106 if((local_priv || admin_priv) && fOwner) {
107 *return_code = fOwner->setAggressiveness(type, newLevel);
108 return kIOReturnSuccess;
109 } else {
110 *return_code = kIOReturnNotPrivileged;
111 return kIOReturnSuccess;
112 }
113
114 }
115
116
117 IOReturn RootDomainUserClient::clientClose( void )
118 {
119 detach(fOwner);
120
121 if(fOwningTask) {
122 task_deallocate(fOwningTask);
123 fOwningTask = 0;
124 }
125
126 return kIOReturnSuccess;
127 }
128
129 IOExternalMethod *
130 RootDomainUserClient::getTargetAndMethodForIndex( IOService ** targetP, UInt32 index )
131 {
132 static IOExternalMethod sMethods[] = {
133 { // kPMSetAggressiveness, 0
134 1, (IOMethod)&RootDomainUserClient::secureSetAggressiveness, kIOUCScalarIScalarO, 2, 1
135 },
136 { // kPMGetAggressiveness, 1
137 0, (IOMethod)&IOPMrootDomain::getAggressiveness, kIOUCScalarIScalarO, 1, 1
138 },
139 { // kPMSleepSystem, 2
140 1, (IOMethod)&RootDomainUserClient::secureSleepSystem, kIOUCScalarIScalarO, 0, 1
141 },
142 { // kPMAllowPowerChange, 3
143 0, (IOMethod)&IOPMrootDomain::allowPowerChange, kIOUCScalarIScalarO, 1, 0
144 },
145 { // kPMCancelPowerChange, 4
146 0, (IOMethod)&IOPMrootDomain::cancelPowerChange, kIOUCScalarIScalarO, 1, 0
147 },
148 { // kPMShutdownSystem, 5
149 0, (IOMethod)&IOPMrootDomain::shutdownSystem, kIOUCScalarIScalarO, 0, 0
150 },
151 { // kPMRestartSystem, 6
152 0, (IOMethod)&IOPMrootDomain::restartSystem, kIOUCScalarIScalarO, 0, 0
153 },
154 { // kPMSetPreventative, 7
155 1, (IOMethod) &RootDomainUserClient::setPreventative, kIOUCScalarIScalarO, 2, 0
156 },
157 };
158
159 if(index >= kNumPMMethods)
160 return NULL;
161 else {
162 if (sMethods[index].object)
163 *targetP = this;
164 else
165 *targetP = fOwner;
166
167 return &sMethods[index];
168 }
169 }
170
171 void
172 RootDomainUserClient::setPreventative(UInt32 on_off, UInt32 types_of_sleep)
173 {
174 return;
175 }
176