xref: /freebsd/crypto/krb5/src/ccapi/server/ccs_ccache_iterator.c (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1 /* ccapi/server/ccs_ccache_iterator.c */
2 /*
3  * Copyright 2006, 2007 Massachusetts Institute of Technology.
4  * All Rights Reserved.
5  *
6  * Export of this software from the United States of America may
7  * require a specific license from the United States Government.
8  * It is the responsibility of any person or organization contemplating
9  * export to obtain such a license before exporting.
10  *
11  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
12  * distribute this software and its documentation for any purpose and
13  * without fee is hereby granted, provided that the above copyright
14  * notice appear in all copies and that both that copyright notice and
15  * this permission notice appear in supporting documentation, and that
16  * the name of M.I.T. not be used in advertising or publicity pertaining
17  * to distribution of the software without specific, written prior
18  * permission.  Furthermore if you modify this software you must label
19  * your software as modified software and not distribute it in such a
20  * fashion that it might be confused with the original M.I.T. software.
21  * M.I.T. makes no representations about the suitability of
22  * this software for any purpose.  It is provided "as is" without express
23  * or implied warranty.
24  */
25 
26 #include "ccs_common.h"
27 
28 /* ------------------------------------------------------------------------ */
29 
ccs_ccache_iterator_release(ccs_ccache_iterator_t io_ccache_iterator,ccs_cache_collection_t io_cache_collection,k5_ipc_stream in_request_data,k5_ipc_stream io_reply_data)30 static  cc_int32 ccs_ccache_iterator_release (ccs_ccache_iterator_t  io_ccache_iterator,
31                                               ccs_cache_collection_t io_cache_collection,
32                                               k5_ipc_stream           in_request_data,
33                                               k5_ipc_stream           io_reply_data)
34 {
35     cc_int32 err = ccNoError;
36 
37     if (!io_ccache_iterator ) { err = cci_check_error (ccErrBadParam); }
38     if (!io_cache_collection) { err = cci_check_error (ccErrBadParam); }
39     if (!in_request_data    ) { err = cci_check_error (ccErrBadParam); }
40     if (!io_reply_data      ) { err = cci_check_error (ccErrBadParam); }
41 
42     if (!err) {
43         err = ccs_ccache_list_iterator_release (io_ccache_iterator);
44     }
45 
46     return cci_check_error (err);
47 }
48 
49 /* ------------------------------------------------------------------------ */
50 
ccs_ccache_iterator_next(ccs_ccache_iterator_t io_ccache_iterator,ccs_cache_collection_t io_cache_collection,k5_ipc_stream in_request_data,k5_ipc_stream io_reply_data)51 static  cc_int32 ccs_ccache_iterator_next (ccs_ccache_iterator_t  io_ccache_iterator,
52                                            ccs_cache_collection_t io_cache_collection,
53                                            k5_ipc_stream           in_request_data,
54                                            k5_ipc_stream           io_reply_data)
55 {
56     cc_int32 err = ccNoError;
57     ccs_ccache_t ccache = NULL;
58 
59     if (!io_ccache_iterator ) { err = cci_check_error (ccErrBadParam); }
60     if (!io_cache_collection) { err = cci_check_error (ccErrBadParam); }
61     if (!in_request_data    ) { err = cci_check_error (ccErrBadParam); }
62     if (!io_reply_data      ) { err = cci_check_error (ccErrBadParam); }
63 
64     if (!err) {
65         err = ccs_ccache_list_iterator_next (io_ccache_iterator, &ccache);
66     }
67 
68     if (!err) {
69         err = ccs_ccache_write (ccache, io_reply_data);
70     }
71 
72     return cci_check_error (err);
73 }
74 
75 /* ------------------------------------------------------------------------ */
76 
ccs_ccache_iterator_clone(ccs_ccache_iterator_t io_ccache_iterator,ccs_cache_collection_t io_cache_collection,k5_ipc_stream in_request_data,k5_ipc_stream io_reply_data)77 static  cc_int32 ccs_ccache_iterator_clone (ccs_ccache_iterator_t  io_ccache_iterator,
78                                             ccs_cache_collection_t io_cache_collection,
79                                             k5_ipc_stream           in_request_data,
80                                             k5_ipc_stream           io_reply_data)
81 {
82     cc_int32 err = ccNoError;
83     ccs_ccache_iterator_t ccache_iterator = NULL;
84 
85     if (!io_ccache_iterator ) { err = cci_check_error (ccErrBadParam); }
86     if (!io_cache_collection) { err = cci_check_error (ccErrBadParam); }
87     if (!in_request_data    ) { err = cci_check_error (ccErrBadParam); }
88     if (!io_reply_data      ) { err = cci_check_error (ccErrBadParam); }
89 
90     if (!err) {
91         err = ccs_ccache_list_iterator_clone (io_ccache_iterator,
92                                               &ccache_iterator);
93     }
94 
95     if (!err) {
96         err = ccs_ccache_list_iterator_write (ccache_iterator, io_reply_data);
97     }
98 
99     return cci_check_error (err);
100 }
101 
102 #ifdef TARGET_OS_MAC
103 #pragma mark -
104 #endif
105 
106 /* ------------------------------------------------------------------------ */
107 
ccs_ccache_iterator_handle_message(ccs_ccache_iterator_t io_ccache_iterator,ccs_cache_collection_t io_cache_collection,enum cci_msg_id_t in_request_name,k5_ipc_stream in_request_data,k5_ipc_stream * out_reply_data)108  cc_int32 ccs_ccache_iterator_handle_message (ccs_ccache_iterator_t  io_ccache_iterator,
109                                               ccs_cache_collection_t io_cache_collection,
110                                               enum cci_msg_id_t      in_request_name,
111                                               k5_ipc_stream           in_request_data,
112                                               k5_ipc_stream          *out_reply_data)
113 {
114     cc_int32 err = ccNoError;
115     k5_ipc_stream reply_data = NULL;
116 
117     if (!in_request_data) { err = cci_check_error (ccErrBadParam); }
118     if (!out_reply_data ) { err = cci_check_error (ccErrBadParam); }
119 
120     if (!err) {
121         err = krb5int_ipc_stream_new (&reply_data);
122     }
123 
124     if (!err) {
125         if (in_request_name == cci_ccache_iterator_release_msg_id) {
126             err = ccs_ccache_iterator_release (io_ccache_iterator,
127                                                io_cache_collection,
128                                                in_request_data,
129                                                reply_data);
130 
131         } else if (in_request_name == cci_ccache_iterator_next_msg_id) {
132             err = ccs_ccache_iterator_next (io_ccache_iterator,
133                                             io_cache_collection,
134                                             in_request_data,
135                                             reply_data);
136 
137         } else if (in_request_name == cci_ccache_iterator_clone_msg_id) {
138             err = ccs_ccache_iterator_clone (io_ccache_iterator,
139                                              io_cache_collection,
140                                              in_request_data,
141                                              reply_data);
142 
143         } else {
144             err = ccErrBadInternalMessage;
145         }
146     }
147 
148     if (!err) {
149         *out_reply_data = reply_data;
150         reply_data = NULL; /* take ownership */
151     }
152 
153     krb5int_ipc_stream_release (reply_data);
154 
155     return cci_check_error (err);
156 }
157