2  * Copyright (c) 2007 Apple Inc. All Rights Reserved. 
   4  * @APPLE_LICENSE_HEADER_START@ 
   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 
  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. 
  21  * @APPLE_LICENSE_HEADER_END@ 
  23 //#include <Security/SecCodeHostLib.h> 
  24 #include "SecCodeHostLib.h" 
  25 #include <Security/Security.h> 
  26 #include <Security/AuthSession.h> 
  27 #include <securityd_client/ucsp.h> 
  28 #include <servers/bootstrap.h> 
  34 mach_port_t gServerPort
; 
  35 SecCSFlags gInitFlags
; 
  39 // Framing macros and facilities 
  41 #define UCSP_ARGS       gServerPort, mig_get_reply_port(), &securitydCreds, &rcode 
  42 #define ATTRDATA(attr) (void *)(attr), (attr) ? strlen((attr)) : 0 
  45         security_token_t securitydCreds; \ 
  47         if (KERN_SUCCESS != func) \ 
  48                 return errSecCSInternalError; \ 
  49         if (securitydCreds.val[0] != 0) \ 
  50                 return CSSM_ERRCODE_VERIFICATION_FAILURE; \ 
  56 // Mandatory initialization call 
  58 OSStatus 
SecHostLibInit(SecCSFlags flags
) 
  60         if (gServerPort 
!= MACH_PORT_NULL
)      // re-initialization attempt 
  61                 return errSecCSInternalError
; 
  63         mach_port_t bootstrapPort
; 
  64         if (KERN_SUCCESS 
!= task_get_bootstrap_port(mach_task_self(), &bootstrapPort
)) 
  65                 return errSecCSInternalError
; 
  66         static char serverName
[BOOTSTRAP_MAX_NAME_LEN
] = SECURITYSERVER_BOOTSTRAP_NAME
; 
  67         if (KERN_SUCCESS 
!= bootstrap_look_up(bootstrapPort
, 
  68                 serverName
, &gServerPort
)) 
  69                 return errSecCSInternalError
; 
  71         ClientSetupInfo info 
= { 0x1234, SSPROTOVERSION 
}; 
  72         CALL(ucsp_client_setup(UCSP_ARGS
, mach_task_self(), info
, "?:unspecified")); 
  78 // At this time, this ONLY supports the creation of (one) dedicated guest. 
  80 OSStatus 
SecHostLibCreateGuest(SecGuestRef host
, 
  81         uint32_t status
, const char *path
, const char *attributeXML
, 
  82         SecCSFlags flags
, SecGuestRef 
*newGuest
) 
  84         if (flags 
!= kSecCSDedicatedHost
) 
  85                 return errSecCSInvalidFlags
; 
  87         CALL(ucsp_client_createGuest(UCSP_ARGS
, host
, status
, path
, 
  88                 ATTRDATA(attributeXML
), flags
, newGuest
)); 
  93 // Update the status of a guest. 
  95 OSStatus 
SecHostLibSetGuestStatus(SecGuestRef guestRef
, 
  96         uint32_t status
, const char *attributeXML
, 
  99         CALL(ucsp_client_setGuestStatus(UCSP_ARGS
, guestRef
, status
, ATTRDATA(attributeXML
))); 
 104 // Enable dynamic hosting mode. 
 106 OSStatus 
SecHostSetHostingPort(mach_port_t hostingPort
, SecCSFlags flags
) 
 108         CALL(ucsp_client_registerHosting(UCSP_ARGS
, hostingPort
, flags
));