etc/services - sync with NetBSD-8
[minix.git] / crypto / external / bsd / heimdal / dist / kcm / connect.c
blob7190c2a52e68d568834d925ef9cda4c36a8b3126
1 /* $NetBSD: connect.c,v 1.1.1.2 2014/04/24 12:45:27 pettai Exp $ */
3 /*
4 * Copyright (c) 1997-2005 Kungliga Tekniska Högskolan
5 * (Royal Institute of Technology, Stockholm, Sweden).
6 * All rights reserved.
8 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the Institute nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
38 #include "kcm_locl.h"
40 void
41 kcm_service(void *ctx, const heim_idata *req,
42 const heim_icred cred,
43 heim_ipc_complete complete,
44 heim_sipc_call cctx)
46 kcm_client peercred;
47 krb5_error_code ret;
48 krb5_data request, rep;
49 unsigned char *buf;
50 size_t len;
52 krb5_data_zero(&rep);
54 peercred.uid = heim_ipc_cred_get_uid(cred);
55 peercred.gid = heim_ipc_cred_get_gid(cred);
56 peercred.pid = heim_ipc_cred_get_pid(cred);
57 peercred.session = heim_ipc_cred_get_session(cred);
59 if (req->length < 4) {
60 kcm_log(1, "malformed request from process %d (too short)",
61 peercred.pid);
62 (*complete)(cctx, EINVAL, NULL);
63 return;
66 buf = req->data;
67 len = req->length;
69 if (buf[0] != KCM_PROTOCOL_VERSION_MAJOR ||
70 buf[1] != KCM_PROTOCOL_VERSION_MINOR) {
71 kcm_log(1, "incorrect protocol version %d.%d from process %d",
72 buf[0], buf[1], peercred.pid);
73 (*complete)(cctx, EINVAL, NULL);
74 return;
77 request.data = buf + 2;
78 request.length = len - 2;
80 /* buf is now pointing at opcode */
82 ret = kcm_dispatch(kcm_context, &peercred, &request, &rep);
84 (*complete)(cctx, ret, &rep);
85 krb5_data_free(&rep);