Ticket #40082: certsync.m.diff
File certsync.m.diff, 2.5 KB (added by danielluke (Daniel J. Luke), 11 years ago) |
---|
-
files/certsync.m
33 33 34 34 #import <objc/message.h> 35 35 36 #define errSecSuccess 0 37 36 38 /* A wrapper class that may be used to pass configuration through the 37 39 * FSEvent callback API */ 38 40 @interface MPCertSyncConfig : NSObject { … … 215 217 for (id certObj in result) { 216 218 CFErrorRef cferror = NULL; 217 219 CFStringRef subject; 220 OSStatus err; 221 218 222 219 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_6223 #if 0 && MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_6 220 224 if (SecCertificateCopyShortDescription != NULL) { 221 225 subject = PLCFAutorelease(SecCertificateCopyShortDescription(NULL, (SecCertificateRef) certObj, &cferror)); 222 226 } else { … … 223 227 subject = PLCFAutorelease(SecCertificateCopySubjectSummary((SecCertificateRef) certObj)); 224 228 } 225 229 #else 226 subject = PLCFAutorelease(SecCertificateCopySubjectSummary((SecCertificateRef) certObj)); 230 err = SecCertificateCopyCommonName((SecCertificateRef) certObj, &subject); 231 PLCFAutorelease(subject); 227 232 #endif 228 233 229 if ( subject == NULL) {234 if (err != 0 && subject == NULL) { 230 235 nsfprintf(stderr, @"Failed to extract certificate description: %@\n", cferror); 231 236 [pool release]; 232 237 return EXIT_FAILURE; … … 242 247 OSStatus err; 243 248 244 249 /* Prefer the non-deprecated SecItemExport on Mac OS X >= 10.7. We use an ifdef to keep the code buildable with earlier SDKs, too. */ 245 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_6250 #if 0 && MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_6 246 251 if (SecItemExport != NULL) { 247 252 err = SecItemExport((CFArrayRef) anchors, kSecFormatPEMSequence, kSecItemPemArmour, NULL, &pemData); 248 253 } else { … … 263 268 NSString *str = [[[NSString alloc] initWithData: (NSData *) pemData encoding:NSUTF8StringEncoding] autorelease]; 264 269 nsfprintf(stdout, @"%@", str); 265 270 } else { 266 if (![(NSData *) pemData writeToFile: outputFile options: NSDataWritingAtomic error: &error]) {267 nsfprintf(stderr, @"Failed to write to pem output file : %@\n", error);271 if (![(NSData *) pemData writeToFile: outputFile atomically: YES]) { 272 nsfprintf(stderr, @"Failed to write to pem output file.\n"); 268 273 [pool release]; 269 274 return EXIT_FAILURE; 270 275 }