| | 81 | } |
| | 82 | |
| | 83 | static inline BOOL installPassthroughComponent(NSFileManager *fm, NSString *passPath) |
| | 84 | { |
| | 85 | //We have a copy, must have had permission to distribute it |
| | 86 | struct statfs slashStat; |
| | 87 | if(statfs("/", &slashStat) == -1) |
| | 88 | return NO; |
| | 89 | |
| | 90 | BOOL success = YES; |
| | 91 | int status; |
| | 92 | AuthorizationItem authItems[2] = { |
| | 93 | {kAuthorizationEnvironmentUsername, strlen("frontrow"), "frontrow", 0}, |
| | 94 | {kAuthorizationEnvironmentPassword, strlen("frontrow"), "frontrow", 0}, |
| | 95 | }; |
| | 96 | AuthorizationEnvironment environ = {2, authItems}; |
| | 97 | AuthorizationItem rightSet[] = {{kAuthorizationRightExecute, 0, NULL, 0}}; |
| | 98 | AuthorizationRights rights = {1, rightSet}; |
| | 99 | AuthorizationRef auth; |
| | 100 | OSStatus result = AuthorizationCreate(&rights, &environ, kAuthorizationFlagPreAuthorize | kAuthorizationFlagExtendRights, &auth); |
| | 101 | if(result == errAuthorizationSuccess) |
| | 102 | { |
| | 103 | BOOL readonly = slashStat.f_flags & MNT_RDONLY; |
| | 104 | |
| | 105 | if(readonly) |
| | 106 | { |
| | 107 | char *command = "mount -uw /"; |
| | 108 | char *arguments[] = {"-c", command, NULL}; |
| | 109 | result = AuthorizationExecuteWithPrivileges(auth, "/bin/sh", kAuthorizationFlagDefaults, arguments, NULL); |
| | 110 | wait(&status); |
| | 111 | FrameworkLoadPrint(@"Set to read-write with status %d", status); |
| | 112 | } |
| | 113 | |
| | 114 | NSString *passDest = @"/Library/Audio/Plug-Ins/HAL/"; |
| | 115 | NSString *existingPath = [passDest stringByAppendingPathComponent:@"AC3PassthroughDevice.plugin"]; |
| | 116 | int status = 0; |
| | 117 | if([fm fileExistsAtPath:existingPath]) |
| | 118 | { |
| | 119 | char *command = "rm -Rf \"$EXISTING\""; |
| | 120 | setenv("EXISTING", [existingPath fileSystemRepresentation], 1); |
| | 121 | char *arguments[] = {"-c", command, NULL}; |
| | 122 | result = AuthorizationExecuteWithPrivileges(auth, "/bin/sh", kAuthorizationFlagDefaults, arguments, NULL); |
| | 123 | wait(&status); |
| | 124 | unsetenv("EXISTING"); |
| | 125 | FrameworkLoadPrint(@"Removed existing with status %d", status); |
| | 126 | } |
| | 127 | char *command = "cp -r \"$PASSPATH\" \"$PASSDEST\""; |
| | 128 | setenv("PASSPATH", [passPath fileSystemRepresentation], 1); |
| | 129 | setenv("PASSDEST", [passDest fileSystemRepresentation], 1); |
| | 130 | char *arguments[] = {"-c", command, NULL}; |
| | 131 | result = AuthorizationExecuteWithPrivileges(auth, "/bin/sh", kAuthorizationFlagDefaults, arguments, NULL); |
| | 132 | wait(&status); |
| | 133 | unsetenv("PASSPATH"); |
| | 134 | unsetenv("PASSDEST"); |
| | 135 | |
| | 136 | if(readonly) |
| | 137 | { |
| | 138 | char *command = "mount -ur /"; |
| | 139 | char *arguments[] = {"-c", command, NULL}; |
| | 140 | result = AuthorizationExecuteWithPrivileges(auth, "/bin/sh", kAuthorizationFlagDefaults, arguments, NULL); |
| | 141 | wait(&status); |
| | 142 | FrameworkLoadPrint(@"Set to read-only with status %d", status); |
| | 143 | } |
| | 144 | } |
| | 145 | if(result != errAuthorizationSuccess) |
| | 146 | { |
| | 147 | success = NO; |
| | 148 | FrameworkLoadPrint(@"Failed to install Passthrough component"); |
| | 149 | } |
| | 150 | AuthorizationFree(auth, kAuthorizationFlagDefaults); |
| | 151 | return success; |