/*1* Copyright (c) 1997-2005 Kungliga Tekniska Högskolan2* (Royal Institute of Technology, Stockholm, Sweden).3* All rights reserved.4*5* Portions Copyright (c) 2009 Apple Inc. All rights reserved.6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions9* are met:10*11* 1. Redistributions of source code must retain the above copyright12* notice, this list of conditions and the following disclaimer.13*14* 2. Redistributions in binary form must reproduce the above copyright15* notice, this list of conditions and the following disclaimer in the16* documentation and/or other materials provided with the distribution.17*18* 3. Neither the name of the Institute nor the names of its contributors19* may be used to endorse or promote products derived from this software20* without specific prior written permission.21*22* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND23* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE24* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE25* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE26* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL27* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS28* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)29* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT30* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY31* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF32* SUCH DAMAGE.33*/3435#include "kcm_locl.h"3637void38kcm_service(void *ctx, const heim_idata *req,39const heim_icred cred,40heim_ipc_complete complete,41heim_sipc_call cctx)42{43kcm_client peercred;44krb5_error_code ret;45krb5_data request, rep;46unsigned char *buf;47size_t len;4849krb5_data_zero(&rep);5051peercred.uid = heim_ipc_cred_get_uid(cred);52peercred.gid = heim_ipc_cred_get_gid(cred);53peercred.pid = heim_ipc_cred_get_pid(cred);54peercred.session = heim_ipc_cred_get_session(cred);5556if (req->length < 4) {57kcm_log(1, "malformed request from process %d (too short)",58peercred.pid);59(*complete)(cctx, EINVAL, NULL);60return;61}6263buf = req->data;64len = req->length;6566if (buf[0] != KCM_PROTOCOL_VERSION_MAJOR ||67buf[1] != KCM_PROTOCOL_VERSION_MINOR) {68kcm_log(1, "incorrect protocol version %d.%d from process %d",69buf[0], buf[1], peercred.pid);70(*complete)(cctx, EINVAL, NULL);71return;72}7374request.data = buf + 2;75request.length = len - 2;7677/* buf is now pointing at opcode */7879ret = kcm_dispatch(kcm_context, &peercred, &request, &rep);8081(*complete)(cctx, ret, &rep);82krb5_data_free(&rep);83}848586