#include "csprocess.h"
#include "cskernel.h"
#include <securityd_client/ssclient.h>
#include <System/sys/codesign.h>
namespace Security {
namespace CodeSigning {
ProcessCode::ProcessCode(pid_t pid, const audit_token_t* token, PidDiskRep *pidDiskRep )
: GenericCode(KernelCode::active()), mPid(pid), mPidBased(pidDiskRep)
{
if (token)
mAudit = new audit_token_t(*token);
else
mAudit = NULL;
}
mach_port_t ProcessCode::getHostingPort()
{
return SecurityServer::ClientSession().hostingPort(pid());
}
int ProcessCode::csops(unsigned int ops, void *addr, size_t size)
{
if (mAudit)
return ::csops_audittoken(mPid, ops, addr, size, mAudit);
else
return ::csops(mPid, ops, addr, size);
}
ProcessDynamicCode::ProcessDynamicCode(ProcessCode *guest)
: SecStaticCode(guest->pidBased()), mGuest(guest)
{
}
CFDataRef ProcessDynamicCode::component(CodeDirectory::SpecialSlot slot, OSStatus fail )
{
if (slot == cdInfoSlot && !mGuest->pidBased()->supportInfoPlist())
return NULL;
else if (slot == cdResourceDirSlot)
return NULL;
return SecStaticCode::component(slot, fail);
}
CFDictionaryRef ProcessDynamicCode::infoDictionary()
{
if (mGuest->pidBased()->supportInfoPlist())
return SecStaticCode::infoDictionary();
return makeCFDictionary(0);
}
void ProcessDynamicCode::validateComponent(CodeDirectory::SpecialSlot slot, OSStatus fail )
{
if (slot == cdInfoSlot && !mGuest->pidBased()->supportInfoPlist())
return;
else if (slot == cdResourceDirSlot)
return;
SecStaticCode::validateComponent(slot, fail);
}
} }