-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDebugPref.m
More file actions
180 lines (139 loc) · 5.81 KB
/
Copy pathDebugPref.m
File metadata and controls
180 lines (139 loc) · 5.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
//
// DebugPref.m
// Debug
//
// Created by Timothy Perfitt on 11/6/09.
// Copyright (c) 2013 twocanoes. All rights reserved.
//
#import "DebugPref.h"
@implementation DebugPref
@synthesize isEnabled,isDSDebugging,isLoggingDNS,isDoingNetworkTrace,isTracingDNS,
isTracingKerberos,isTracingLDAP,isSyslogDebug,hasUnappledChanges;
-(IBAction)compressAndSendToDesktop:(id)sender{
NSTask *task=[[NSTask alloc] init];
[task setLaunchPath:@"/usr/bin/zip"];
NSString *desktopFile=@"~/Desktop/debug.zip";
[task setArguments:[NSArray arrayWithObjects:@"-r",[desktopFile stringByExpandingTildeInPath],
@"/Library/Logs",@"/var/log",nil]];
[task launch];
[task waitUntilExit];
}
-(NSString *)interface{
return [[NSUserDefaults standardUserDefaults] valueForKey:@"interface"];
}
-(void)setDefaults{
NSFileManager *fm=[NSFileManager defaultManager];
// [self setInterface:@"en0"];
[self setHasUnappledChanges:NO];
if ([fm fileExistsAtPath:@"/Library/LaunchDaemons/com.twocanoes.debug.plist"]) [self setIsEnabled:YES];
else [self setIsEnabled:NO];
if ([fm fileExistsAtPath:@"/Library/Preferences/DirectoryService/.DSLogDebugAtStart"]) [self setIsDSDebugging:YES];
else [self setIsDSDebugging:NO];
if ([fm fileExistsAtPath:@"/tmp/.dnsdebugging"]) [self setIsLoggingDNS:YES];
else [self setIsLoggingDNS:NO];
if ([fm fileExistsAtPath:@"/tmp/.syslogverbose"]) [self setIsSyslogDebug:YES];
else [self setIsSyslogDebug:NO];
if ([fm fileExistsAtPath:@"/tmp/.tcpdumprunning"]) [self setIsDoingNetworkTrace:YES];
else [self setIsDoingNetworkTrace:NO];
if ([fm fileExistsAtPath:@"/tmp/.tracedns"]) [self setIsTracingDNS:YES];
else [self setIsTracingDNS:NO];
if ([fm fileExistsAtPath:@"/tmp/.tracekerberos"]) [self setIsTracingKerberos:YES];
else [self setIsTracingKerberos:NO];
if ([fm fileExistsAtPath:@"/tmp/.traceldap"]) [self setIsTracingLDAP:YES];
else [self setIsTracingLDAP:NO];
}
- (void) mainViewDidLoad
{
[lockView setDelegate:self];
[lockView setString:"system.privilege.admin"];
[lockView setAutoupdate:YES];
[lockView updateStatus:self];
authorization=nil;
[self setDefaults];
}
-(IBAction)apply:(id)sender{
[self save];
}
-(void)save{
NSFileManager *fm=[NSFileManager defaultManager];
authorization=[[lockView authorization] authorizationRef];
NSString *scriptPath;
NSBundle *thisBundle = [NSBundle bundleForClass:[self class]];
scriptPath = [thisBundle pathForResource:@"debug" ofType:@"perl"];
const char *pathToTool=[scriptPath UTF8String];
AuthorizationFlags flags = kAuthorizationFlagDefaults |
kAuthorizationFlagInteractionAllowed |
kAuthorizationFlagPreAuthorize |
kAuthorizationFlagExtendRights;
int curArg=2;
char **arguments = calloc(10 , sizeof(char *));
if ([self isEnabled]==YES) {
if ([self isDSDebugging]==YES) {
NSLog(@"adding ds at %i",curArg);
arguments[curArg++]="-ds";
}
if ([self isDoingNetworkTrace]==YES) {
NSMutableArray *ports=[NSMutableArray arrayWithCapacity:4];
arguments[curArg++]="-tcpdump";
arguments[curArg++]=(char *)[[self interface] UTF8String];
[fm createFileAtPath:@"/tmp/.tracedns" contents:nil attributes:nil];
[ports addObject:@"port 53"];
[ports addObject:@"port 5353"];
[ports addObject:@"port 464"];
[ports addObject:@"port 88"];
[ports addObject:@"port 389"];
[ports addObject:@"port 636"];
if ([ports count]>0) {
arguments[curArg++]="-ports";
NSString *optionsObject=[ports componentsJoinedByString:@" or "];
char *options=calloc([optionsObject length]+1, sizeof (char));
strncpy(options,(char *)[optionsObject UTF8String],sizeof(char)*([optionsObject length]+1));
arguments[curArg++]=options;
}
}
if ([self isLoggingDNS]==YES) {
arguments[curArg++]="-dns";
}
if ([self isSyslogDebug]==YES) {
arguments[curArg++]="-syslog";
}
}
if (curArg==2) {
arguments[curArg++]="-disable";
}
// either disabled or nothing selected
AuthorizationItem right = {kAuthorizationRightExecute, 0, NULL, 0};
AuthorizationRights rights = {1, &right};
OSStatus status;
// Call AuthorizationCopyRights to determine or extend the allowable rights.
status = AuthorizationCopyRights(authorization, &rights, NULL, flags, NULL);
if (status != errAuthorizationSuccess)
NSLog(@"Copy Rights Unsuccessful: %d", status);
NSLog(@"path is %s",pathToTool);
arguments[0]=(char *)pathToTool;
arguments[1]="-install";
int i;
for (i=0;i<curArg;i++) {
NSLog(@"arg[%i] is %s",i,arguments[i]);
}
status=AuthorizationExecuteWithPrivileges (
authorization,
"/usr/bin/perl",
kAuthorizationFlagDefaults,
arguments,
nil);
if (status != errAuthorizationSuccess)
NSLog(@"AuthorizationExecuteWithPrivileges Unsuccessful: %d", status);
[self setHasUnappledChanges:NO];
/* NSRunInformationalAlertPanel(@"Restart Required",
@"Logging will now take affect on restart.",
@"OK", nil,nil);
*/
}
-(IBAction)optionChanged:(id)sender{
[self setHasUnappledChanges:YES];
}
-(IBAction)revert:(id)sender{
[self setDefaults];
}
@end