1/* 2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24#import <Cocoa/Cocoa.h> 25#import <Foundation/Foundation.h> 26#include <stdio.h> 27#include <stdlib.h> 28#include <unistd.h> 29#include <Security/oidscert.h> 30#include <Security/cssmapi.h> 31#include <Security/cssmapple.h> 32#include <Security/certextensions.h> 33#include <CoreFoundation/CFPropertyList.h> 34#include <CoreFoundation/CFData.h> 35#include <CoreFoundation/CFArray.h> 36#include <SystemConfiguration/SCValidation.h> 37#include <string.h> 38#include <AssertMacros.h> 39 40static void * 41read_fd(int fd, size_t * ret_size) 42{ 43 void *buf; 44 size_t offset; 45 size_t remaining; 46 size_t size; 47 48 size = 4096; 49 buf = malloc(size); 50 require(buf != NULL, malloc); 51 52 offset = 0; 53 remaining = size - offset; 54 while ( TRUE ) 55 { 56 size_t read_count; 57 58 if (remaining == 0) 59 { 60 size *= 2; 61 buf = reallocf(buf, size); 62 require(buf != NULL, reallocf); 63 64 remaining = size - offset; 65 } 66 67 read_count = read(fd, buf + offset, remaining); 68 require(read_count >= 0, read); 69 70 if (read_count == 0) 71 { 72 /* EOF */ 73 break; 74 } 75 76 offset += read_count; 77 remaining -= read_count; 78 } 79 80 require(offset != 0, no_input); 81 82 *ret_size = offset; 83 return ( buf ); 84 85 86 /* error cases handled here */ 87 88no_input: 89read: 90 91 free(buf); 92 93reallocf: 94malloc: 95 96 *ret_size = 0; 97 return ( NULL ); 98} 99 100CFPropertyListRef 101my_CFPropertyListCreateFromFileDescriptor(int fd) 102{ 103 void *buf; 104 size_t bufsize; 105 CFDataRef data; 106 CFPropertyListRef plist; 107 108 plist = NULL; 109 110 buf = read_fd(fd, &bufsize); 111 require(buf != NULL, read_fd); 112 113 data = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, buf, bufsize, kCFAllocatorNull); 114 require(data != NULL, CFDataCreateWithBytesNoCopy); 115 116 plist = CFPropertyListCreateFromXMLData(kCFAllocatorDefault, data, kCFPropertyListImmutable, NULL); 117 118 CFRelease(data); 119 120CFDataCreateWithBytesNoCopy: 121 122 free(buf); 123 124read_fd: 125 126 return (plist); 127} 128 129CFDictionaryRef the_dict; 130 131/* 132 * This program exits with one of the following values: 133 * 0 = Continue button selected 134 * 1 = Cancel button selected 135 * 2 = an unexpected error was encountered 136 */ 137int main(int argc, char *argv[]) 138{ 139 the_dict = my_CFPropertyListCreateFromFileDescriptor(STDIN_FILENO); 140 if (isA_CFDictionary(the_dict) == NULL) 141 { 142 return ( 2 ); 143 } 144 else 145 { 146 return ( NSApplicationMain(argc, (const char **) argv) ); 147 } 148} 149