xref: /freebsd/crypto/krb5/src/ccapi/lib/ccapi_ipc.c (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1*7f2fe78bSCy Schubert /* ccapi/lib/ccapi_ipc.c */
2*7f2fe78bSCy Schubert /*
3*7f2fe78bSCy Schubert  * Copyright 2006 Massachusetts Institute of Technology.
4*7f2fe78bSCy Schubert  * All Rights Reserved.
5*7f2fe78bSCy Schubert  *
6*7f2fe78bSCy Schubert  * Export of this software from the United States of America may
7*7f2fe78bSCy Schubert  * require a specific license from the United States Government.
8*7f2fe78bSCy Schubert  * It is the responsibility of any person or organization contemplating
9*7f2fe78bSCy Schubert  * export to obtain such a license before exporting.
10*7f2fe78bSCy Schubert  *
11*7f2fe78bSCy Schubert  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
12*7f2fe78bSCy Schubert  * distribute this software and its documentation for any purpose and
13*7f2fe78bSCy Schubert  * without fee is hereby granted, provided that the above copyright
14*7f2fe78bSCy Schubert  * notice appear in all copies and that both that copyright notice and
15*7f2fe78bSCy Schubert  * this permission notice appear in supporting documentation, and that
16*7f2fe78bSCy Schubert  * the name of M.I.T. not be used in advertising or publicity pertaining
17*7f2fe78bSCy Schubert  * to distribution of the software without specific, written prior
18*7f2fe78bSCy Schubert  * permission.  Furthermore if you modify this software you must label
19*7f2fe78bSCy Schubert  * your software as modified software and not distribute it in such a
20*7f2fe78bSCy Schubert  * fashion that it might be confused with the original M.I.T. software.
21*7f2fe78bSCy Schubert  * M.I.T. makes no representations about the suitability of
22*7f2fe78bSCy Schubert  * this software for any purpose.  It is provided "as is" without express
23*7f2fe78bSCy Schubert  * or implied warranty.
24*7f2fe78bSCy Schubert  */
25*7f2fe78bSCy Schubert 
26*7f2fe78bSCy Schubert #include "ccapi_ipc.h"
27*7f2fe78bSCy Schubert #include "ccapi_os_ipc.h"
28*7f2fe78bSCy Schubert 
29*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
30*7f2fe78bSCy Schubert 
cci_ipc_process_init(void)31*7f2fe78bSCy Schubert cc_int32 cci_ipc_process_init (void)
32*7f2fe78bSCy Schubert {
33*7f2fe78bSCy Schubert     return cci_os_ipc_process_init ();
34*7f2fe78bSCy Schubert }
35*7f2fe78bSCy Schubert 
36*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
37*7f2fe78bSCy Schubert 
cci_ipc_thread_init(void)38*7f2fe78bSCy Schubert cc_int32 cci_ipc_thread_init (void)
39*7f2fe78bSCy Schubert {
40*7f2fe78bSCy Schubert     return cci_os_ipc_thread_init ();
41*7f2fe78bSCy Schubert }
42*7f2fe78bSCy Schubert 
43*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
44*7f2fe78bSCy Schubert 
_cci_ipc_send(enum cci_msg_id_t in_request_name,cc_int32 in_launch_server,cci_identifier_t in_identifier,k5_ipc_stream in_request_data,k5_ipc_stream * out_reply_data)45*7f2fe78bSCy Schubert static cc_int32 _cci_ipc_send (enum cci_msg_id_t  in_request_name,
46*7f2fe78bSCy Schubert                                cc_int32           in_launch_server,
47*7f2fe78bSCy Schubert                                cci_identifier_t   in_identifier,
48*7f2fe78bSCy Schubert                                k5_ipc_stream       in_request_data,
49*7f2fe78bSCy Schubert                                k5_ipc_stream      *out_reply_data)
50*7f2fe78bSCy Schubert {
51*7f2fe78bSCy Schubert     cc_int32 err = ccNoError;
52*7f2fe78bSCy Schubert     k5_ipc_stream request = NULL;
53*7f2fe78bSCy Schubert     k5_ipc_stream reply = NULL;
54*7f2fe78bSCy Schubert     cc_int32 reply_error = 0;
55*7f2fe78bSCy Schubert 
56*7f2fe78bSCy Schubert     if (!in_identifier) { err = cci_check_error (ccErrBadParam); }
57*7f2fe78bSCy Schubert     /* in_request_data may be NULL */
58*7f2fe78bSCy Schubert     /* out_reply_data may be NULL */
59*7f2fe78bSCy Schubert 
60*7f2fe78bSCy Schubert     if (!err) {
61*7f2fe78bSCy Schubert         err = cci_message_new_request_header (&request,
62*7f2fe78bSCy Schubert                                               in_request_name,
63*7f2fe78bSCy Schubert                                               in_identifier);
64*7f2fe78bSCy Schubert     }
65*7f2fe78bSCy Schubert 
66*7f2fe78bSCy Schubert     if (!err && in_request_data) {
67*7f2fe78bSCy Schubert         err = krb5int_ipc_stream_write (request,
68*7f2fe78bSCy Schubert                                 krb5int_ipc_stream_data (in_request_data),
69*7f2fe78bSCy Schubert                                 krb5int_ipc_stream_size (in_request_data));
70*7f2fe78bSCy Schubert     }
71*7f2fe78bSCy Schubert 
72*7f2fe78bSCy Schubert     if (!err) {
73*7f2fe78bSCy Schubert         err = cci_os_ipc (in_launch_server, request, &reply);
74*7f2fe78bSCy Schubert 
75*7f2fe78bSCy Schubert         if (!err && krb5int_ipc_stream_size (reply) > 0) {
76*7f2fe78bSCy Schubert             err = cci_message_read_reply_header (reply, &reply_error);
77*7f2fe78bSCy Schubert         }
78*7f2fe78bSCy Schubert     }
79*7f2fe78bSCy Schubert 
80*7f2fe78bSCy Schubert     if (!err && reply_error) {
81*7f2fe78bSCy Schubert         err = reply_error;
82*7f2fe78bSCy Schubert     }
83*7f2fe78bSCy Schubert 
84*7f2fe78bSCy Schubert     if (!err && out_reply_data) {
85*7f2fe78bSCy Schubert         *out_reply_data = reply;
86*7f2fe78bSCy Schubert         reply = NULL; /* take ownership */
87*7f2fe78bSCy Schubert     }
88*7f2fe78bSCy Schubert 
89*7f2fe78bSCy Schubert     krb5int_ipc_stream_release (request);
90*7f2fe78bSCy Schubert     krb5int_ipc_stream_release (reply);
91*7f2fe78bSCy Schubert 
92*7f2fe78bSCy Schubert     return cci_check_error (err);
93*7f2fe78bSCy Schubert }
94*7f2fe78bSCy Schubert 
95*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
96*7f2fe78bSCy Schubert 
cci_ipc_send(enum cci_msg_id_t in_request_name,cci_identifier_t in_identifier,k5_ipc_stream in_request_data,k5_ipc_stream * out_reply_data)97*7f2fe78bSCy Schubert cc_int32 cci_ipc_send (enum cci_msg_id_t  in_request_name,
98*7f2fe78bSCy Schubert                        cci_identifier_t   in_identifier,
99*7f2fe78bSCy Schubert                        k5_ipc_stream       in_request_data,
100*7f2fe78bSCy Schubert                        k5_ipc_stream      *out_reply_data)
101*7f2fe78bSCy Schubert {
102*7f2fe78bSCy Schubert     return cci_check_error (_cci_ipc_send (in_request_name, 1,
103*7f2fe78bSCy Schubert                                            in_identifier,
104*7f2fe78bSCy Schubert                                            in_request_data,
105*7f2fe78bSCy Schubert                                            out_reply_data));
106*7f2fe78bSCy Schubert }
107*7f2fe78bSCy Schubert 
108*7f2fe78bSCy Schubert /* ------------------------------------------------------------------------ */
109*7f2fe78bSCy Schubert 
cci_ipc_send_no_launch(enum cci_msg_id_t in_request_name,cci_identifier_t in_identifier,k5_ipc_stream in_request_data,k5_ipc_stream * out_reply_data)110*7f2fe78bSCy Schubert cc_int32 cci_ipc_send_no_launch (enum cci_msg_id_t  in_request_name,
111*7f2fe78bSCy Schubert                                  cci_identifier_t   in_identifier,
112*7f2fe78bSCy Schubert                                  k5_ipc_stream       in_request_data,
113*7f2fe78bSCy Schubert                                  k5_ipc_stream      *out_reply_data)
114*7f2fe78bSCy Schubert {
115*7f2fe78bSCy Schubert     return cci_check_error (_cci_ipc_send (in_request_name, 0,
116*7f2fe78bSCy Schubert                                            in_identifier,
117*7f2fe78bSCy Schubert                                            in_request_data,
118*7f2fe78bSCy Schubert                                            out_reply_data));
119*7f2fe78bSCy Schubert }
120