Esempio n. 1
0
IOReturn RootDomainUserClient::secureSleepSystemOptions(
    const void      *inOptions,
    IOByteCount     inOptionsSize,
    uint32_t        *returnCode)
{

    int             local_priv = 0;
    int             admin_priv = 0;
    IOReturn        ret = kIOReturnNotPrivileged;
    OSDictionary    *unserializedOptions =  NULL;
    OSString        *unserializeErrorString = NULL;

    ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeLocalUser);
    local_priv = (kIOReturnSuccess == ret);

    ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeAdministrator);
    admin_priv = (kIOReturnSuccess == ret);


    if (inOptions)
    {
        unserializedOptions = OSDynamicCast( OSDictionary,
                                             OSUnserializeXML((const char *)inOptions, inOptionsSize, &unserializeErrorString));

        if (!unserializedOptions) {
            IOLog("IOPMRootDomain SleepSystem unserialization failure: %s\n",
                unserializeErrorString ? unserializeErrorString->getCStringNoCopy() : "Unknown");
        }
    }

    if ( (local_priv || admin_priv) && fOwner )
    {
        proc_t p;
        p = (proc_t)get_bsdtask_info(fOwningTask);
        if (p) {
            fOwner->setProperty("SleepRequestedByPID", proc_pid(p), 32);
        }

        if (unserializedOptions)
        {
            // Publish Sleep Options in registry under root_domain
            fOwner->setProperty( kRootDomainSleepOptionsKey, unserializedOptions);

            *returnCode = fOwner->sleepSystemOptions( unserializedOptions );

            unserializedOptions->release();
        } else {
            // No options
            // Clear any pre-existing options
            fOwner->removeProperty( kRootDomainSleepOptionsKey );

            *returnCode = fOwner->sleepSystemOptions( NULL );
        }

    } else {
        *returnCode = kIOReturnNotPrivileged;
    }

    return kIOReturnSuccess;
}
Esempio n. 2
0
bool I2CUserClient::initWithTask(task_t owningTask,
		void *security_id, UInt32 type)
{
	DLOG("+I2CUserClient::initWithTask\n");

	// The user task must be running with EUID of 0 to access me
	if (clientHasPrivilege(security_id, kIOClientPrivilegeAdministrator)
			!= kIOReturnSuccess)
	{
		DLOG("-I2CUserClient::initWithTask client is not root!\n");
		return(false);
	}

	if ((!super::initWithTask(owningTask, security_id, type)) ||
	    (!owningTask))
	{
		DLOG("-I2CUserClient::initWithTask failed to init\n");
		return(false);
	}

	fOwningTask = owningTask;
	fIsOpen = false;
	fIsOpenLock = NULL;

	return(true);
}
bool AppleSmartBatteryManagerUserClient::initWithTask(task_t owningTask,
        void *security_id, UInt32 type, OSDictionary * properties)
{
    uint32_t            _pid;

    /* 1. Only root processes may open a SmartBatteryManagerUserClient.
     * 2. Attempts to create exclusive UserClients will fail if an
     *     exclusive user client is attached.
     * 3. Non-exclusive clients will not be able to perform transactions
     *     while an exclusive client is attached.
     * 3a. Only battery firmware updaters should bother being exclusive.
     */
    if ( kIOReturnSuccess !=
            clientHasPrivilege(owningTask, kIOClientPrivilegeAdministrator))
    {
        return false;
    }

    if (!super::initWithTask(owningTask, security_id, type, properties)) {
        return false;
    }

    fUserClientType = type;

    _pid = proc_selfpid();
    setProperty("pid", _pid, 32);

    fOwningTask = owningTask;
    task_reference (fOwningTask);
    return true;
}
IOReturn AppleSmartBatteryManagerUserClient::secureChargeInhibit(
    int level,
    int *return_code)
{
    int             admin_priv = 0;
    IOReturn        ret = kIOReturnNotPrivileged;

    if( !(level == 0 || level == 1))
    {
        *return_code = kIOReturnBadArgument;
        return kIOReturnSuccess;
    }

    ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeAdministrator);
    admin_priv = (kIOReturnSuccess == ret);

    if(admin_priv && fOwner) {
        *return_code = fOwner->inhibitCharging(level);
        return kIOReturnSuccess;
    } else {
        *return_code = kIOReturnNotPrivileged;
        return kIOReturnSuccess;
    }

}
IOReturn IOFramebufferSharedUserClient::clientMemoryForType( UInt32 type,
        IOOptionBits * options, IOMemoryDescriptor ** memory )
{
    IOMemoryDescriptor *        mem = 0;
    IOReturn                    err;

    switch (type)
    {
        case kIOFBCursorMemory:
            mem = owner->sharedCursor;
            mem->retain();
            *options = kIOMapReadOnly;
            break;

        case kIOFBVRAMMemory:
            if (kIOReturnSuccess == clientHasPrivilege(current_task(), kIOClientPrivilegeLocalUser))
                mem = owner->getVRAMRange();
            break;
    }

    *memory = mem;
    if (mem)
        err = kIOReturnSuccess;
    else
        err = kIOReturnBadArgument;

    return (err);
}
IOReturn IOHIDParamUserClient::extPostEvent(void*p1,void*p2,void*,void*,void*,void*)
{
    IOReturn result = clientHasPrivilege(current_task(), kIOClientPrivilegeLocalUser);
    if ( result == kIOReturnSuccess ) {
        result = owner ? owner->extPostEvent(p1, p2, NULL, NULL, NULL, NULL) : kIOReturnOffline;
    }
    return result;
}
IOReturn IOHIDParamUserClient::setProperties( OSObject * properties )
{
    OSDictionary * dict = OSDynamicCast(OSDictionary, properties);
    if (dict && dict->getObject(kIOHIDUseKeyswitchKey) &&
        ( clientHasPrivilege(current_task(), kIOClientPrivilegeAdministrator) != kIOReturnSuccess))
    {
        dict->removeObject(kIOHIDUseKeyswitchKey);
    }

    return( owner ? owner->setProperties( properties ) : kIOReturnOffline );
}
Esempio n. 8
0
IOReturn RootDomainUserClient::secureSetAggressiveness(
    unsigned long   type,
    unsigned long   newLevel,
    int             *return_code )
{
    int             local_priv = 0;
    int             admin_priv = 0;
    IOReturn        ret = kIOReturnNotPrivileged;

    ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeLocalUser);
    local_priv = (kIOReturnSuccess == ret);

    ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeAdministrator);
    admin_priv = (kIOReturnSuccess == ret);

    if((local_priv || admin_priv) && fOwner) {
        *return_code = fOwner->setAggressiveness(type, newLevel);
    } else {
        *return_code = kIOReturnNotPrivileged;
    }
    return kIOReturnSuccess;
}
Esempio n. 9
0
IOReturn RootDomainUserClient::secureGetSystemSleepType(
    uint32_t    *outSleepType)
{
    int                     admin_priv = 0;
    IOReturn                ret;

    ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeAdministrator);
    admin_priv = (kIOReturnSuccess == ret);

    if (admin_priv && fOwner) {
        ret = fOwner->getSystemSleepType(outSleepType);
    } else {
        ret = kIOReturnNotPrivileged;
    }
    return ret;
}
Esempio n. 10
0
IOReturn RootDomainUserClient::secureSetUserAssertionLevels(
    uint32_t    assertionBitfield)
{
    int                     admin_priv = 0;
    IOReturn                ret = kIOReturnNotPrivileged;

    ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeAdministrator);
    admin_priv = (kIOReturnSuccess == ret);

    if (admin_priv && fOwner) {
        ret = fOwner->setPMAssertionUserLevels(assertionBitfield);
    } else {
        ret = kIOReturnNotPrivileged;
    }
    return kIOReturnSuccess;
}
bool FakeSMCKeyStoreUserClient::initWithTask(task_t owningTask, void* securityID, UInt32 type, OSDictionary* properties)
{
    if (!owningTask) {
        return false;
    }

	if (!super::initWithTask(owningTask, securityID, type, properties)) {
        HWSensorsFatalLog("failed to initialize with task!");
        return false;
	}

    keyStore = NULL;
    clientHasAdminPrivilegue = clientHasPrivilege(securityID, kIOClientPrivilegeAdministrator);

    return true;
}
Esempio n. 12
0
IOReturn RootDomainUserClient::secureSetMaintenanceWakeCalendar(
    IOPMCalendarStruct      *inCalendar,
    uint32_t                *returnCode)
{
    int                     admin_priv = 0;
    IOReturn                ret = kIOReturnNotPrivileged;

    ret = clientHasPrivilege(fOwningTask, kIOClientPrivilegeAdministrator);
    admin_priv = (kIOReturnSuccess == ret);

    if (admin_priv && fOwner) {
        *returnCode = fOwner->setMaintenanceWakeCalendar(inCalendar);
    } else {
        *returnCode = kIOReturnNotPrivileged;
    }
    return kIOReturnSuccess;
}
Esempio n. 13
0
// ============================================================
// initWithTask is called as a result of the user process calling IOServiceOpen.
bool
org_pqrs_driver_PCKeyboardHack_UserClient_kext::initWithTask(task_t owningTask, void* securityToken, UInt32 type)
{
  if (clientHasPrivilege(owningTask, kIOClientPrivilegeLocalUser) != KERN_SUCCESS) {
    IOLOG_ERROR("UserClient_kext::initWithTask clientHasPrivilege failed\n");
    return false;
  }

  if (! super::initWithTask(owningTask, securityToken, type)) {
    IOLOG_ERROR("UserClient_kext::initWithTask super::initWithTask failed\n");
    return false;
  }

  task_     = owningTask;
  provider_ = NULL;

  return true;
}
Esempio n. 14
0
// ============================================================
// initWithTask is called as a result of the user process calling IOServiceOpen.
bool USERCLIENT_KEXT_CLASSNAME::initWithTask(task_t owningTask, void* securityToken, UInt32 type) {
  if (clientHasPrivilege(owningTask, kIOClientPrivilegeLocalUser) != KERN_SUCCESS) {
    IOLOG_ERROR("UserClient_kext::initWithTask clientHasPrivilege failed\n");
    return false;
  }

  if (!super::initWithTask(owningTask, securityToken, type)) {
    IOLOG_ERROR("UserClient_kext::initWithTask super::initWithTask failed\n");
    return false;
  }

  provider_ = nullptr;

  // Don't change static values here. (For example, notification_enabled_)
  // initWithTask is called by each IOServiceOpen.
  //
  // If IOService is opened, other client will be failed.
  // Changing static values by other IOServiceOpen may destroy the current connection.

  return true;
}