2 * Copyright (c) 2012, 2014-2015, JANET(UK)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of JANET(UK) nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31 * OF THE POSSIBILITY OF SUCH DAMAGE.
41 #include <tid_internal.h>
46 static int destroy_tid_req(TID_REQ *req)
48 if (req->json_references)
49 json_decref(req->json_references);
55 gss_delete_sec_context( &minor, &req->gssctx, NULL);
58 if (req->rp_realm!=NULL)
59 tr_free_name(req->rp_realm);
61 tr_free_name(req->realm);
63 tr_free_name(req->comm);
64 if (req->orig_coi!=NULL)
65 tr_free_name(req->orig_coi);
69 TID_REQ *tid_req_new()
71 TID_REQ *req = talloc_zero(NULL, TID_REQ);
74 talloc_set_destructor(req, destroy_tid_req);
75 req->json_references = json_array();
76 assert(req->json_references);
82 TID_REQ *tid_req_get_next_req(TID_REQ *req)
84 return(req->next_req);
87 void tid_req_set_next_req(TID_REQ *req, TID_REQ *next_req)
89 req->next_req = next_req;
92 int tid_req_get_resp_sent(TID_REQ *req)
94 return(req->resp_sent);
97 void tid_req_set_resp_sent(TID_REQ *req, int resp_sent)
99 req->resp_sent = resp_sent;
102 int tid_req_get_conn(TID_REQ *req)
107 void tid_req_set_conn(TID_REQ *req, int conn)
112 gss_ctx_id_t tid_req_get_gssctx(TID_REQ *req)
117 void tid_req_set_gssctx(TID_REQ *req, gss_ctx_id_t gssctx)
119 req->gssctx = gssctx;
122 int tid_req_get_resp_rcvd(TID_REQ *req)
124 return(req->resp_rcvd);
127 void tid_req_set_resp_rcvd(TID_REQ *req, int resp_rcvd)
129 req->resp_rcvd = resp_rcvd;
132 TR_NAME *tid_req_get_rp_realm(TID_REQ *req)
134 return(req->rp_realm);
137 void tid_req_set_rp_realm(TID_REQ *req, TR_NAME *rp_realm)
139 req->rp_realm = rp_realm;
142 TR_NAME *tid_req_get_realm(TID_REQ *req)
147 void tid_req_set_realm(TID_REQ *req, TR_NAME *realm)
152 TR_NAME *tid_req_get_comm(TID_REQ *req)
157 void tid_req_set_comm(TID_REQ *req, TR_NAME *comm)
162 TR_NAME *tid_req_get_orig_coi(TID_REQ *req)
164 return(req->orig_coi);
167 void tid_req_set_orig_coi(TID_REQ *req, TR_NAME *orig_coi)
169 req->orig_coi = orig_coi;
172 TIDC_RESP_FUNC *tid_req_get_resp_func(TID_REQ *req)
174 return(req->resp_func);
177 void tid_req_set_resp_func(TID_REQ *req, TIDC_RESP_FUNC *resp_func)
179 req->resp_func = resp_func;
182 void *tid_req_get_cookie(TID_REQ *req)
187 void tid_req_set_cookie(TID_REQ *req, void *cookie)
189 req->cookie = cookie;
192 /* struct is allocated in talloc null context */
193 TID_REQ *tid_dup_req (TID_REQ *orig_req)
195 TID_REQ *new_req = NULL;
197 if (NULL == (new_req = talloc_zero(NULL, TID_REQ))) {
198 tr_crit("tid_dup_req: Can't allocated duplicate request.");
202 /* Memcpy for flat fields, not valid until names are duped. */
203 memcpy(new_req, orig_req, sizeof(TID_REQ));
204 json_incref(new_req->json_references);
205 new_req->free_conn = 0;
207 if ((NULL == (new_req->rp_realm = tr_dup_name(orig_req->rp_realm))) ||
208 (NULL == (new_req->realm = tr_dup_name(orig_req->realm))) ||
209 (NULL == (new_req->comm = tr_dup_name(orig_req->comm)))) {
210 tr_crit("tid_dup_req: Can't duplicate request (names).");
213 if (orig_req->orig_coi) {
214 if (NULL == (new_req->orig_coi = tr_dup_name(orig_req->orig_coi))) {
215 tr_crit("tid_dup_req: Can't duplicate request (orig_coi).");
223 /* Adds the JSON object ref to req's list of objects to release when the
226 void tid_req_cleanup_json( TID_REQ *req, json_t *ref)
228 (void) json_array_append_new(req->json_references, ref);
231 void tid_req_free(TID_REQ *req)
236 int tid_req_add_path(TID_REQ *req,
237 const char *this_system, unsigned port)
239 char *path_element = talloc_asprintf(req, "%s:%u",
242 req->path = json_array();
245 tid_req_cleanup_json(req, req->path);
247 return json_array_append( req->path, json_string(path_element));
252 void tid_srvr_get_address(const TID_SRVR_BLK *blk,
253 const struct sockaddr **out_addr,
256 struct sockaddr_in *sa = NULL;
258 sa = talloc_zero(blk, struct sockaddr_in);
259 sa->sin_family = AF_INET;
260 inet_aton(blk->aaa_server_addr, &(sa->sin_addr));
261 sa->sin_port = htons(2083); /* radsec port */
262 *out_addr = (struct sockaddr *) sa;
263 *out_len = sizeof( struct sockaddr_in);
266 DH *tid_srvr_get_dh( TID_SRVR_BLK *blk)
269 return blk->aaa_server_dh;
272 const TR_NAME *tid_srvr_get_key_name(
273 const TID_SRVR_BLK *blk)
276 return blk->key_name;