2015-06-22 18:09:15 +00:00
|
|
|
/*
|
2016-02-11 19:48:58 +00:00
|
|
|
* Copyright (c) 2014-present, Facebook, Inc.
|
2015-06-22 18:09:15 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <CoreServices/CoreServices.h>
|
|
|
|
#include <IOKit/IOKitLib.h>
|
|
|
|
#include <DiskArbitration/DiskArbitration.h>
|
|
|
|
|
|
|
|
#include <boost/thread/locks.hpp>
|
|
|
|
#include <boost/thread/mutex.hpp>
|
|
|
|
#include <boost/make_shared.hpp>
|
|
|
|
|
|
|
|
#include <osquery/events.h>
|
|
|
|
#include <osquery/status.h>
|
|
|
|
|
|
|
|
namespace osquery {
|
|
|
|
|
|
|
|
#define kIOPropertyProtocolCharacteristicsKey_ "Protocol Characteristics"
|
|
|
|
#define kVirtualInterfaceLocation_ "Virtual Interface Location Path"
|
|
|
|
|
|
|
|
#define kDAAppearanceTime_ "DAAppearanceTime"
|
|
|
|
|
|
|
|
const std::string kIOHIDXClassPath_ =
|
|
|
|
"IOService:/IOResources/IOHDIXController/";
|
|
|
|
|
|
|
|
struct DiskArbitrationSubscriptionContext : public SubscriptionContext {
|
|
|
|
// Limit events for this subscription to virtual disks (DMG files)
|
2015-12-08 01:15:30 +00:00
|
|
|
bool physical_disks{false};
|
2015-06-22 18:09:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct DiskArbitrationEventContext : public EventContext {
|
|
|
|
std::string action;
|
|
|
|
std::string path;
|
|
|
|
std::string device_path;
|
|
|
|
std::string name;
|
|
|
|
std::string bsd_name;
|
|
|
|
std::string uuid;
|
|
|
|
std::string size;
|
|
|
|
std::string ejectable;
|
|
|
|
std::string mountable;
|
|
|
|
std::string writable;
|
|
|
|
std::string content;
|
|
|
|
std::string media_name;
|
|
|
|
std::string vendor;
|
|
|
|
std::string filesystem;
|
|
|
|
std::string disk_appearance_time;
|
|
|
|
std::string checksum;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::shared_ptr<DiskArbitrationEventContext>
|
|
|
|
DiskArbitrationEventContextRef;
|
|
|
|
typedef std::shared_ptr<DiskArbitrationSubscriptionContext>
|
|
|
|
DiskArbitrationSubscriptionContextRef;
|
|
|
|
|
|
|
|
class DiskArbitrationEventPublisher
|
|
|
|
: public EventPublisher<DiskArbitrationSubscriptionContext,
|
|
|
|
DiskArbitrationEventContext> {
|
|
|
|
DECLARE_PUBLISHER("diskarbitration");
|
|
|
|
|
|
|
|
public:
|
2015-12-08 01:15:30 +00:00
|
|
|
void configure() override{};
|
|
|
|
|
|
|
|
void tearDown() override;
|
2015-06-22 18:09:15 +00:00
|
|
|
|
|
|
|
bool shouldFire(const DiskArbitrationSubscriptionContextRef &sc,
|
2015-12-08 01:15:30 +00:00
|
|
|
const DiskArbitrationEventContextRef &ec) const override;
|
|
|
|
|
|
|
|
Status run() override;
|
2015-06-22 18:09:15 +00:00
|
|
|
|
2015-09-22 05:02:27 +00:00
|
|
|
// Callin for stopping the streams/run loop.
|
2015-12-08 01:15:30 +00:00
|
|
|
void end() override { stop(); }
|
2015-09-22 05:02:27 +00:00
|
|
|
|
2015-06-22 18:09:15 +00:00
|
|
|
static void DiskAppearedCallback(DADiskRef disk, void *context);
|
2015-12-08 01:15:30 +00:00
|
|
|
|
2015-06-22 18:09:15 +00:00
|
|
|
static void DiskDisappearedCallback(DADiskRef disk, void *context);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void restart();
|
2015-12-08 01:15:30 +00:00
|
|
|
|
2015-06-22 18:09:15 +00:00
|
|
|
void stop();
|
2015-12-08 01:15:30 +00:00
|
|
|
|
2015-06-22 18:09:15 +00:00
|
|
|
static std::string getProperty(const CFStringRef &property,
|
|
|
|
const CFDictionaryRef &dict);
|
2015-12-08 01:15:30 +00:00
|
|
|
|
2015-06-22 18:09:15 +00:00
|
|
|
static std::string extractUdifChecksum(const std::string &path);
|
2015-12-08 01:15:30 +00:00
|
|
|
|
2015-06-22 18:09:15 +00:00
|
|
|
static void fire(const std::string &action,
|
|
|
|
const DiskArbitrationEventContextRef &ec,
|
|
|
|
const CFDictionaryRef &dict);
|
2015-09-22 05:02:27 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
DASessionRef session_{nullptr};
|
|
|
|
CFRunLoopRef run_loop_{nullptr};
|
2015-06-22 18:09:15 +00:00
|
|
|
};
|
|
|
|
}
|