2 * Copyright (c) 2016, 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.
38 #include <tr_name_internal.h>
39 #include <trp_internal.h>
42 static int trp_req_destructor(void *object)
44 TRP_REQ *req=talloc_get_type_abort(object, TRP_REQ);
46 /* clean up TR_NAME data, which are not managed by talloc */
47 if (req->comm != NULL)
48 tr_free_name(req->comm);
50 if (req->realm != NULL)
51 tr_free_name(req->realm);
53 if (req->peer != NULL)
54 tr_free_name(req->peer);
59 TRP_REQ *trp_req_new(TALLOC_CTX *mem_ctx)
61 TRP_REQ *new_req=talloc(mem_ctx, TRP_REQ);
63 if (new_req != NULL) {
69 talloc_set_destructor((void *)new_req, trp_req_destructor);
73 void trp_req_free(TRP_REQ *req)
79 TR_NAME *trp_req_get_comm(TRP_REQ *req)
87 void trp_req_set_comm(TRP_REQ *req, TR_NAME *comm)
93 TR_NAME *trp_req_get_realm(TRP_REQ *req)
102 void trp_req_set_realm(TRP_REQ *req, TR_NAME *realm)
108 TR_NAME *trp_req_get_peer(TRP_REQ *req)
117 void trp_req_set_peer(TRP_REQ *req, TR_NAME *peer)
123 /* Defines what we use as a wildcard for realm or community name.
124 * Must not be a valid name for either of those. Currently, we
125 * use the empty string. */
126 static int trp_req_name_is_wildcard(TR_NAME *name)
128 return (name!=NULL) && (name->len==0);
131 int trp_req_is_wildcard(TRP_REQ *req)
133 return (req!=NULL) && trp_req_name_is_wildcard(req->comm) && trp_req_name_is_wildcard(req->realm);
136 TRP_RC trp_req_make_wildcard(TRP_REQ *req)
141 req->comm=tr_new_name("");
145 req->realm=tr_new_name("");
146 if (req->realm==NULL) {
147 tr_free_name(req->comm);