Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ bazel_dep(name = "xxhash", version = "0.8.2")
bazel_dep(name = "protos", version = "1.0.1", repo_name = "northpolesec_protos")
git_override(
module_name = "protos",
commit = "bd61ba67c96bb8983e1b1ecf51f0af0d9308ac63",
commit = "704246489aa55e6e2b60b47133a8668bc3656105",
remote = "https://github.com/northpolesec/protos",
)

Expand Down
5 changes: 5 additions & 0 deletions Source/common/SNTConfigurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,11 @@
///
@property(nullable, readonly, nonatomic) NSString *machineOwner;

///
/// The machine owner's groups.
///
@property(nullable, readonly, nonatomic) NSArray<NSString *> *machineOwnerGroups;

///
/// The last date of a successful full sync.
///
Expand Down
30 changes: 29 additions & 1 deletion Source/common/SNTConfigurator.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ @implementation SNTConfigurator
static NSString *const kStatsOrganizationID = @"StatsOrganizationID";

static NSString *const kMachineOwnerKey = @"MachineOwner";
static NSString *const kMachineOwnerGroupsKey = @"MachineOwnerGroups";
static NSString *const kMachineIDKey = @"MachineID";
static NSString *const kMachineOwnerPlistFileKey = @"MachineOwnerPlist";
static NSString *const kMachineOwnerPlistKeyKey = @"MachineOwnerKey";
static NSString *const kMachineOwnerGroupsPlistKeyKey = @"MachineOwnerGroupsKey";
static NSString *const kMachineIDPlistFileKey = @"MachineIDPlist";
static NSString *const kMachineIDPlistKeyKey = @"MachineIDKey";

Expand Down Expand Up @@ -284,9 +286,11 @@ - (instancetype)initWithSyncStateFile:(NSString *)syncStateFilePath
kEnableStatsCollectionKey : number,
kStatsOrganizationID : string,
kMachineOwnerKey : string,
kMachineOwnerGroupsKey : array,
kMachineIDKey : string,
kMachineOwnerPlistFileKey : string,
kMachineOwnerPlistKeyKey : string,
kMachineOwnerGroupsPlistKeyKey : string,
kMachineIDPlistFileKey : string,
kMachineIDPlistKeyKey : string,
kEventLogType : string,
Expand Down Expand Up @@ -542,6 +546,10 @@ + (NSSet *)keyPathsForValuesAffectingMachineOwner {
return [self configStateSet];
}

+ (NSSet *)keyPathsForValuesAffectingMachineOwnerGroups {
return [self configStateSet];
}

+ (NSSet *)keyPathsForValuesAffectingMachineID {
return [self configStateSet];
}
Expand Down Expand Up @@ -1031,14 +1039,34 @@ - (NSString *)machineOwner {

NSString *plistPath = self.configState[kMachineOwnerPlistFileKey];
NSString *plistKey = self.configState[kMachineOwnerPlistKeyKey];
if (plistPath && plistKey) {
if (plistPath.length && plistKey.length) {
NSDictionary *plist = [NSDictionary dictionaryWithContentsOfFile:plistPath];
machineOwner = [plist[plistKey] isKindOfClass:[NSString class]] ? plist[plistKey] : nil;
}

return machineOwner ?: @"";
}

- (NSArray<NSString *> *)machineOwnerGroups {
NSArray<NSString *> *machineOwnerGroups = self.configState[kMachineOwnerGroupsKey];
if (machineOwnerGroups.count) return machineOwnerGroups;

NSString *plistPath = self.configState[kMachineOwnerPlistFileKey];
NSString *plistKey = self.configState[kMachineOwnerGroupsPlistKeyKey];
if (plistPath.length && plistKey.length) {
NSDictionary *plist = [NSDictionary dictionaryWithContentsOfFile:plistPath];
machineOwnerGroups = [plist[plistKey] isKindOfClass:[NSArray class]] ? plist[plistKey] : nil;
for (NSString *group in machineOwnerGroups) {
if (![group isKindOfClass:[NSString class]]) {
machineOwnerGroups = nil;
break;
}
}
}

return machineOwnerGroups;
}

- (NSString *)machineID {
NSString *machineId = self.configState[kMachineIDKey];
if (machineId) return machineId;
Expand Down
1 change: 1 addition & 0 deletions Source/santasyncservice/SNTSyncManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ - (SNTSyncState *)createSyncStateWithStatus:(SNTSyncStatusType *)status {
syncState.machineOwner = @"";
SLOGW(@"Missing Machine Owner.");
}
syncState.machineOwnerGroups = config.machineOwnerGroups;

syncState.xsrfToken = self.xsrfToken;
syncState.xsrfTokenHeader = self.xsrfTokenHeader;
Expand Down
6 changes: 6 additions & 0 deletions Source/santasyncservice/SNTSyncPreflight.mm
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ - (BOOL)sync {
req->set_model_identifier(NSStringToUTF8String([SNTSystemInfo modelIdentifier]));
req->set_santa_version(NSStringToUTF8String([SNTSystemInfo santaFullVersion]));
req->set_primary_user(NSStringToUTF8String(self.syncState.machineOwner));
if (self.syncState.machineOwnerGroups.count) {
google::protobuf::RepeatedPtrField<std::string> *groups = req->mutable_primary_user_groups();
for (NSString *group in self.syncState.machineOwnerGroups) {
groups->Add(NSStringToUTF8String(group));
}
}
req->set_sip_status([SNTSIPStatus currentStatus]);

if (self.syncState.pushNotificationsToken) {
Expand Down
1 change: 1 addition & 0 deletions Source/santasyncservice/SNTSyncState.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
/// Machine identifier and owner.
@property(copy) NSString *machineID;
@property(copy) NSString *machineOwner;
@property(copy) NSArray<NSString *> *machineOwnerGroups;

/// Settings sent from server during preflight that are set during postflight.
@property SNTClientMode clientMode;
Expand Down