Ticket #40082: certsync.m.diff

File certsync.m.diff, 2.5 KB (added by danielluke (Daniel J. Luke), 11 years ago)
  • files/certsync.m

     
    3333
    3434#import <objc/message.h>
    3535
     36#define errSecSuccess 0
     37
    3638/* A wrapper class that may be used to pass configuration through the
    3739 * FSEvent callback API */
    3840@interface MPCertSyncConfig : NSObject {
     
    215217    for (id certObj in result) {
    216218        CFErrorRef cferror = NULL;
    217219        CFStringRef subject;
     220                OSStatus err;
     221               
    218222
    219 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_6
     223#if 0 && MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_6
    220224        if (SecCertificateCopyShortDescription != NULL) {
    221225            subject = PLCFAutorelease(SecCertificateCopyShortDescription(NULL, (SecCertificateRef) certObj, &cferror));
    222226        } else {
     
    223227            subject = PLCFAutorelease(SecCertificateCopySubjectSummary((SecCertificateRef) certObj));
    224228        }
    225229#else
    226         subject = PLCFAutorelease(SecCertificateCopySubjectSummary((SecCertificateRef) certObj));
     230                err = SecCertificateCopyCommonName((SecCertificateRef) certObj, &subject);
     231                PLCFAutorelease(subject);
    227232#endif
    228233
    229         if (subject == NULL) {
     234        if (err != 0 && subject == NULL) {
    230235            nsfprintf(stderr, @"Failed to extract certificate description: %@\n", cferror);
    231236            [pool release];
    232237            return EXIT_FAILURE;
     
    242247    OSStatus err;
    243248   
    244249    /* 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_6
     250#if 0 && MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_6
    246251    if (SecItemExport != NULL) {
    247252        err = SecItemExport((CFArrayRef) anchors, kSecFormatPEMSequence, kSecItemPemArmour, NULL, &pemData);
    248253    } else {
     
    263268        NSString *str = [[[NSString alloc] initWithData: (NSData *) pemData encoding:NSUTF8StringEncoding] autorelease];
    264269        nsfprintf(stdout, @"%@", str);
    265270    } 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");
    268273            [pool release];
    269274            return EXIT_FAILURE;
    270275        }