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