1 /* ccapi/server/ccs_credentials_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 30 static cc_int32 ccs_credentials_iterator_release (ccs_credentials_iterator_t io_credentials_iterator, 31 ccs_ccache_t io_ccache, 32 k5_ipc_stream in_request_data, 33 k5_ipc_stream io_reply_data) 34 { 35 cc_int32 err = ccNoError; 36 37 if (!io_credentials_iterator) { err = cci_check_error (ccErrBadParam); } 38 if (!io_ccache ) { 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_credentials_list_iterator_release (io_credentials_iterator); 44 } 45 46 return cci_check_error (err); 47 } 48 49 /* ------------------------------------------------------------------------ */ 50 51 static cc_int32 ccs_credentials_iterator_next (ccs_credentials_iterator_t io_credentials_iterator, 52 ccs_ccache_t io_ccache, 53 k5_ipc_stream in_request_data, 54 k5_ipc_stream io_reply_data) 55 { 56 cc_int32 err = ccNoError; 57 ccs_credentials_t credentials = NULL; 58 59 if (!io_credentials_iterator) { err = cci_check_error (ccErrBadParam); } 60 if (!io_ccache ) { 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_credentials_list_iterator_next (io_credentials_iterator, 66 &credentials); 67 } 68 69 if (!err) { 70 err = ccs_credentials_write (credentials, io_reply_data); 71 } 72 73 return cci_check_error (err); 74 } 75 76 /* ------------------------------------------------------------------------ */ 77 78 static cc_int32 ccs_credentials_iterator_clone (ccs_credentials_iterator_t io_credentials_iterator, 79 ccs_ccache_t io_ccache, 80 k5_ipc_stream in_request_data, 81 k5_ipc_stream io_reply_data) 82 { 83 cc_int32 err = ccNoError; 84 ccs_credentials_iterator_t credentials_iterator = NULL; 85 86 if (!io_credentials_iterator) { err = cci_check_error (ccErrBadParam); } 87 if (!io_ccache ) { err = cci_check_error (ccErrBadParam); } 88 if (!in_request_data ) { err = cci_check_error (ccErrBadParam); } 89 if (!io_reply_data ) { err = cci_check_error (ccErrBadParam); } 90 91 if (!err) { 92 err = ccs_credentials_list_iterator_clone (io_credentials_iterator, 93 &credentials_iterator); 94 } 95 96 if (!err) { 97 err = ccs_credentials_list_iterator_write (credentials_iterator, 98 io_reply_data); 99 } 100 101 return cci_check_error (err); 102 } 103 104 #ifdef TARGET_OS_MAC 105 #pragma mark - 106 #endif 107 108 /* ------------------------------------------------------------------------ */ 109 110 cc_int32 ccs_credentials_iterator_handle_message (ccs_credentials_iterator_t io_credentials_iterator, 111 ccs_ccache_t io_ccache, 112 enum cci_msg_id_t in_request_name, 113 k5_ipc_stream in_request_data, 114 k5_ipc_stream *out_reply_data) 115 { 116 cc_int32 err = ccNoError; 117 k5_ipc_stream reply_data = NULL; 118 119 if (!in_request_data) { err = cci_check_error (ccErrBadParam); } 120 if (!out_reply_data ) { err = cci_check_error (ccErrBadParam); } 121 122 if (!err) { 123 err = krb5int_ipc_stream_new (&reply_data); 124 } 125 126 if (!err) { 127 if (in_request_name == cci_credentials_iterator_release_msg_id) { 128 err = ccs_credentials_iterator_release (io_credentials_iterator, 129 io_ccache, 130 in_request_data, 131 reply_data); 132 133 } else if (in_request_name == cci_credentials_iterator_next_msg_id) { 134 err = ccs_credentials_iterator_next (io_credentials_iterator, 135 io_ccache, 136 in_request_data, 137 reply_data); 138 139 } else if (in_request_name == cci_credentials_iterator_clone_msg_id) { 140 err = ccs_credentials_iterator_clone (io_credentials_iterator, 141 io_ccache, 142 in_request_data, 143 reply_data); 144 145 } else { 146 err = ccErrBadInternalMessage; 147 } 148 } 149 150 if (!err) { 151 *out_reply_data = reply_data; 152 reply_data = NULL; /* take ownership */ 153 } 154 155 krb5int_ipc_stream_release (reply_data); 156 157 return cci_check_error (err); 158 } 159