Skip to content

Commit

Permalink
Project: Add clang-format file, apply most of the fixes it suggested
Browse files Browse the repository at this point in the history
  • Loading branch information
russellhancox committed Mar 10, 2016
1 parent e9ec9a7 commit 0e00237
Show file tree
Hide file tree
Showing 50 changed files with 745 additions and 680 deletions.
22 changes: 22 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
BasedOnStyle: Google
Language: Cpp
Standard: Cpp11

# Disable ColumnLimit because it causes some very weird line breaks.
# For ObjC the limit is 100
# For Cpp the limit is 80
ColumnLimit: 0

# Allow short case statements to be on a single line
AllowShortCaseLabelsOnASingleLine: true

# Ban short loops and functions on a single line
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false

# Allow spaces in NSArray/NSDictionary literals @[ and @{
SpacesInContainerLiterals: true

# For pointers, always put the * next to the variable name.
DerivePointerAlignment: false
PointerAlignment: Right
12 changes: 6 additions & 6 deletions Source/SantaGUI/SNTAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {

self.configFileWatcher = [[SNTFileWatcher alloc] initWithFilePath:kDefaultConfigFilePath
handler:^{
[[SNTConfigurator configurator] reloadConfigData];
[[SNTConfigurator configurator] reloadConfigData];
}];

self.notificationManager = [[SNTNotificationManager alloc] init];
Expand All @@ -47,16 +47,16 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
object:nil
queue:[NSOperationQueue currentQueue]
usingBlock:^(NSNotification *note) {
self.listener.invalidationHandler = nil;
self.listener.rejectedHandler = nil;
[self.listener invalidate];
self.listener = nil;
self.listener.invalidationHandler = nil;
self.listener.rejectedHandler = nil;
[self.listener invalidate];
self.listener = nil;
}];
[workspaceNotifications addObserverForName:NSWorkspaceSessionDidBecomeActiveNotification
object:nil
queue:[NSOperationQueue currentQueue]
usingBlock:^(NSNotification *note) {
[self attemptReconnection];
[self attemptReconnection];
}];

[self createConnection];
Expand Down
8 changes: 4 additions & 4 deletions Source/SantaGUI/SNTMessageWindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ - (IBAction)fadeIn:(id)sender {
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:0.15f];
[[NSAnimationContext currentContext] setCompletionHandler:^{
[NSApp activateIgnoringOtherApps:YES];
[NSApp activateIgnoringOtherApps:YES];
}];
[[self animator] setAlphaValue:1.f];
[NSAnimationContext endGrouping];
Expand All @@ -43,9 +43,9 @@ - (IBAction)fadeOut:(id)sender {
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:0.15f];
[[NSAnimationContext currentContext] setCompletionHandler:^{
[weakSelf.windowController windowWillClose:sender];
[weakSelf orderOut:sender];
[weakSelf setAlphaValue:1.f];
[weakSelf.windowController windowWillClose:sender];
[weakSelf orderOut:sender];
[weakSelf setAlphaValue:1.f];
}];
[[self animator] setAlphaValue:0.f];
[NSAnimationContext endGrouping];
Expand Down
3 changes: 2 additions & 1 deletion Source/SantaGUI/SNTNotificationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ - (void)postBlockNotification:(SNTStoredEvent *)event withCustomMessage:(NSStrin
// Notifications arrive on a background thread but UI updates must happen on the main thread.
// This includes making windows.
[self performSelectorOnMainThread:@selector(postBlockNotificationMainThread:)
withObject:@{ @"event": event, @"custommsg": message }
withObject:@{ @"event" : event,
@"custommsg" : message }
waitUntilDone:NO];
}

Expand Down
26 changes: 13 additions & 13 deletions Source/common/SNTCommonEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@
typedef enum {
RULETYPE_UNKNOWN,

RULETYPE_BINARY = 1,
RULETYPE_CERT = 2,
RULETYPE_BINARY = 1,
RULETYPE_CERT = 2,

RULETYPE_MAX
} santa_ruletype_t;

typedef enum {
RULESTATE_UNKNOWN,

RULESTATE_WHITELIST = 1,
RULESTATE_BLACKLIST = 2,
RULESTATE_WHITELIST = 1,
RULESTATE_BLACKLIST = 2,
RULESTATE_SILENT_BLACKLIST = 3,
RULESTATE_REMOVE = 4,
RULESTATE_REMOVE = 4,

RULESTATE_MAX
} santa_rulestate_t;

typedef enum {
CLIENTMODE_UNKNOWN,

CLIENTMODE_MONITOR = 1,
CLIENTMODE_MONITOR = 1,
CLIENTMODE_LOCKDOWN = 2,

CLIENTMODE_MAX
Expand All @@ -52,17 +52,17 @@ typedef enum {
typedef enum {
EVENTSTATE_UNKNOWN,

EVENTSTATE_ALLOW_UNKNOWN = 1,
EVENTSTATE_ALLOW_BINARY = 2,
EVENTSTATE_ALLOW_UNKNOWN = 1,
EVENTSTATE_ALLOW_BINARY = 2,
EVENTSTATE_ALLOW_CERTIFICATE = 3,
EVENTSTATE_ALLOW_SCOPE = 4,
EVENTSTATE_ALLOW_SCOPE = 4,

EVENTSTATE_BLOCK_UNKNOWN = 5,
EVENTSTATE_BLOCK_BINARY = 6,
EVENTSTATE_BLOCK_UNKNOWN = 5,
EVENTSTATE_BLOCK_BINARY = 6,
EVENTSTATE_BLOCK_CERTIFICATE = 7,
EVENTSTATE_BLOCK_SCOPE = 8,
EVENTSTATE_BLOCK_SCOPE = 8,

EVENTSTATE_RELATED_BINARY = 9,
EVENTSTATE_RELATED_BINARY = 9,

EVENTSTATE_MAX
} santa_eventstate_t;
Expand Down
2 changes: 1 addition & 1 deletion Source/common/SNTConfigurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@interface SNTConfigurator : NSObject

/// Default config file path
extern NSString * const kDefaultConfigFilePath;
extern NSString *const kDefaultConfigFilePath;

#pragma mark - Daemon Settings

Expand Down
64 changes: 32 additions & 32 deletions Source/common/SNTConfigurator.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,39 +33,39 @@ @interface SNTConfigurator ()
@implementation SNTConfigurator

/// The hard-coded path to the config file
NSString * const kDefaultConfigFilePath = @"/var/db/santa/config.plist";
NSString *const kDefaultConfigFilePath = @"/var/db/santa/config.plist";

/// The keys in the config file
static NSString * const kClientModeKey = @"ClientMode";
static NSString * const kFileChangesRegexKey = @"FileChangesRegex";
static NSString * const kWhitelistRegexKey = @"WhitelistRegex";
static NSString * const kBlacklistRegexKey = @"BlacklistRegex";
static NSString * const kEnablePageZeroProtectionKey = @"EnablePageZeroProtection";

static NSString * const kMoreInfoURLKey = @"MoreInfoURL";
static NSString * const kEventDetailURLKey = @"EventDetailURL";
static NSString * const kEventDetailTextKey = @"EventDetailText";
static NSString * const kUnknownBlockMessage = @"UnknownBlockMessage";
static NSString * const kBannedBlockMessage = @"BannedBlockMessage";

static NSString * const kSyncBaseURLKey = @"SyncBaseURL";
static NSString * const kSyncLastSuccess = @"SyncLastSuccess";
static NSString * const kSyncCleanRequired = @"SyncCleanRequired";
static NSString * const kClientAuthCertificateFileKey = @"ClientAuthCertificateFile";
static NSString * const kClientAuthCertificatePasswordKey = @"ClientAuthCertificatePassword";
static NSString * const kClientAuthCertificateCNKey = @"ClientAuthCertificateCN";
static NSString * const kClientAuthCertificateIssuerKey = @"ClientAuthCertificateIssuerCN";
static NSString * const kServerAuthRootsDataKey = @"ServerAuthRootsData";
static NSString * const kServerAuthRootsFileKey = @"ServerAuthRootsFile";

static NSString * const kMachineOwnerKey = @"MachineOwner";
static NSString * const kMachineIDKey = @"MachineID";

static NSString * const kMachineOwnerPlistFileKey = @"MachineOwnerPlist";
static NSString * const kMachineOwnerPlistKeyKey = @"MachineOwnerKey";

static NSString * const kMachineIDPlistFileKey = @"MachineIDPlist";
static NSString * const kMachineIDPlistKeyKey = @"MachineIDKey";
static NSString *const kClientModeKey = @"ClientMode";
static NSString *const kFileChangesRegexKey = @"FileChangesRegex";
static NSString *const kWhitelistRegexKey = @"WhitelistRegex";
static NSString *const kBlacklistRegexKey = @"BlacklistRegex";
static NSString *const kEnablePageZeroProtectionKey = @"EnablePageZeroProtection";

static NSString *const kMoreInfoURLKey = @"MoreInfoURL";
static NSString *const kEventDetailURLKey = @"EventDetailURL";
static NSString *const kEventDetailTextKey = @"EventDetailText";
static NSString *const kUnknownBlockMessage = @"UnknownBlockMessage";
static NSString *const kBannedBlockMessage = @"BannedBlockMessage";

static NSString *const kSyncBaseURLKey = @"SyncBaseURL";
static NSString *const kSyncLastSuccess = @"SyncLastSuccess";
static NSString *const kSyncCleanRequired = @"SyncCleanRequired";
static NSString *const kClientAuthCertificateFileKey = @"ClientAuthCertificateFile";
static NSString *const kClientAuthCertificatePasswordKey = @"ClientAuthCertificatePassword";
static NSString *const kClientAuthCertificateCNKey = @"ClientAuthCertificateCN";
static NSString *const kClientAuthCertificateIssuerKey = @"ClientAuthCertificateIssuerCN";
static NSString *const kServerAuthRootsDataKey = @"ServerAuthRootsData";
static NSString *const kServerAuthRootsFileKey = @"ServerAuthRootsFile";

static NSString *const kMachineOwnerKey = @"MachineOwner";
static NSString *const kMachineIDKey = @"MachineID";

static NSString *const kMachineOwnerPlistFileKey = @"MachineOwnerPlist";
static NSString *const kMachineOwnerPlistKeyKey = @"MachineOwnerKey";

static NSString *const kMachineIDPlistFileKey = @"MachineIDPlist";
static NSString *const kMachineIDPlistKeyKey = @"MachineIDKey";

- (instancetype)initWithFilePath:(NSString *)filePath {
self = [super init];
Expand All @@ -82,7 +82,7 @@ + (instancetype)configurator {
static SNTConfigurator *sharedConfigurator = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedConfigurator = [[SNTConfigurator alloc] initWithFilePath:kDefaultConfigFilePath];
sharedConfigurator = [[SNTConfigurator alloc] initWithFilePath:kDefaultConfigFilePath];
});
return sharedConfigurator;
}
Expand Down
30 changes: 16 additions & 14 deletions Source/common/SNTFileInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ - (instancetype)initWithPath:(NSString *)path error:(NSError **)error {
if (path) errStr = [@"Unable to resolve path: " stringByAppendingString:path];
*error = [NSError errorWithDomain:@"com.google.santa.fileinfo"
code:260
userInfo:@{ NSLocalizedDescriptionKey: errStr }];
userInfo:@{NSLocalizedDescriptionKey : errStr}];
}
return nil;
}
Expand Down Expand Up @@ -97,7 +97,7 @@ - (instancetype)initWithPath:(NSString *)path {
return [self initWithPath:path error:NULL];
}

# pragma mark Hashing
#pragma mark Hashing

- (NSString *)SHA1 {
const int chunkSize = 4096;
Expand Down Expand Up @@ -126,7 +126,7 @@ - (NSString *)SHA1 {
CC_SHA1_Final(sha1, &c);

NSMutableString *buf = [[NSMutableString alloc] initWithCapacity:CC_SHA1_DIGEST_LENGTH * 2];
for (int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++) {
for (int i = 0; i < CC_SHA1_DIGEST_LENGTH; ++i) {
[buf appendFormat:@"%02x", (unsigned char)sha1[i]];
}

Expand Down Expand Up @@ -160,20 +160,19 @@ - (NSString *)SHA256 {
CC_SHA256_Final(sha256, &c);

NSMutableString *buf = [[NSMutableString alloc] initWithCapacity:CC_SHA256_DIGEST_LENGTH * 2];
for (int i = 0; i < CC_SHA256_DIGEST_LENGTH; i++) {
for (int i = 0; i < CC_SHA256_DIGEST_LENGTH; ++i) {
[buf appendFormat:@"%02x", (unsigned char)sha256[i]];
}

return buf;
}

# pragma mark File Type Info
#pragma mark File Type Info

- (NSArray *)architectures {
return [self.machHeaders allKeys];
}


- (BOOL)isExecutable {
struct mach_header *mach_header = [self firstMachHeader];
if (mach_header && mach_header->filetype == MH_EXECUTE) return YES;
Expand Down Expand Up @@ -371,7 +370,7 @@ - (NSDictionary *)machHeaders {
NSMutableData *fatArchs = [[self safeSubdataWithRange:range] mutableCopy];
if (fatArchs) {
struct fat_arch *fat_arch = (struct fat_arch *)[fatArchs mutableBytes];
for (int i = 0; i < nfat_arch; i++) {
for (int i = 0; i < nfat_arch; ++i) {
int offset = OSSwapBigToHostInt32(fat_arch[i].offset);
int size = OSSwapBigToHostInt32(fat_arch[i].size);
int cputype = OSSwapBigToHostInt(fat_arch[i].cputype);
Expand Down Expand Up @@ -434,7 +433,7 @@ - (NSDictionary *)embeddedPlist {
offset += sz_header;

// Loop through the load commands looking for the segment named __TEXT
for (uint32_t i = 0; i < ncmds; i++) {
for (uint32_t i = 0; i < ncmds; ++i) {
NSData *cmdData = [self safeSubdataWithRange:NSMakeRange(offset, sz_segment)];
if (!cmdData) return nil;
struct segment_command_64 *lc = (struct segment_command_64 *)[cmdData bytes];
Expand All @@ -449,7 +448,7 @@ - (NSDictionary *)embeddedPlist {
}

// Loop through the sections in the __TEXT segment looking for an __info_plist section.
for (uint32_t i = 0; i < nsects; i++) {
for (uint32_t i = 0; i < nsects; ++i) {
NSData *sectData = [self safeSubdataWithRange:NSMakeRange(offset, sz_section)];
if (!sectData) return nil;
struct section_64 *sect = (struct section_64 *)[sectData bytes];
Expand Down Expand Up @@ -527,14 +526,17 @@ - (NSDictionary *)quarantineData {
}

NSURL *dbPath = [NSURL fileURLWithPathComponents:@[
fileOwnerHomeDir, @"Library", @"Preferences",
@"com.apple.LaunchServices.QuarantineEventsV2" ]];
fileOwnerHomeDir,
@"Library",
@"Preferences",
@"com.apple.LaunchServices.QuarantineEventsV2"
]];
FMDatabase *db = [FMDatabase databaseWithPath:[dbPath absoluteString]];
db.logsErrors = NO;
if ([db open]) {
FMResultSet *rs = [db executeQuery:@"SELECT * FROM LSQuarantineEvent "
@"WHERE LSQuarantineEventIdentifier=?",
d[@"LSQuarantineEventIdentifier"]];
@"WHERE LSQuarantineEventIdentifier=?",
d[@"LSQuarantineEventIdentifier"]];
if ([rs next]) {
NSString *agentBundleID = [rs stringForColumn:@"LSQuarantineAgentBundleIdentifier"];
NSString *dataURLString = [rs stringForColumn:@"LSQuarantineDataURLString"];
Expand Down
Loading

0 comments on commit 0e00237

Please sign in to comment.