2 * Copyright (c) 2012-2018, 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>
40 #include <tr_config.h>
43 static char *tr_aaa_server_to_str(TALLOC_CTX *mem_ctx, TR_AAA_SERVER *aaa)
45 return talloc_strndup(mem_ctx, aaa->hostname->buf, aaa->hostname->len);
49 char *tr_idp_realm_to_str(TALLOC_CTX *mem_ctx, TR_IDP_REALM *idp)
51 TALLOC_CTX *tmp_ctx=talloc_new(NULL);
52 char **s_aaa=NULL, *aaa_servers=NULL;
53 char **s_apc=NULL, *apcs=NULL;
54 int ii=0, aaa_servers_strlen=0, apcs_strlen=0;
55 int n_aaa_servers=tr_idp_realm_aaa_server_count(idp);
56 int n_apcs=tr_idp_realm_apc_count(idp);
57 TR_AAA_SERVER *aaa=NULL;
61 /* get the AAA servers */
63 aaa_servers=talloc_strdup(tmp_ctx, "");
65 s_aaa=talloc_array(tmp_ctx, char *, n_aaa_servers);
66 for (aaa=idp->aaa_servers,ii=0; aaa!=NULL; aaa=aaa->next,ii++) {
67 s_aaa[ii]=tr_aaa_server_to_str(s_aaa, aaa);
68 aaa_servers_strlen+=strlen(s_aaa[ii]);
71 /* add space for comma-space separators */
72 aaa_servers_strlen+=2*(n_aaa_servers-1);
74 aaa_servers=talloc_array(tmp_ctx, char, aaa_servers_strlen+1);
76 for (ii=0; ii<n_aaa_servers; ii++) {
77 strcat(aaa_servers, s_aaa[ii]);
78 if (ii<(n_aaa_servers-1))
79 strcat(aaa_servers, ", ");
86 apcs=talloc_strdup(tmp_ctx, "");
88 s_apc=talloc_array(tmp_ctx, char *, n_apcs);
89 for (apc=idp->apcs,ii=0; apc!=NULL; apc=apc->next,ii++) {
90 s_apc[ii]=tr_apc_to_str(s_apc, apc);
91 apcs_strlen+=strlen(s_apc[ii]);
94 /* add space for comma-space separators */
95 apcs_strlen+=2*(n_apcs-1);
97 apcs=talloc_array(tmp_ctx, char, apcs_strlen+1);
99 for (ii=0; ii<n_apcs; ii++) {
100 strcat(apcs, s_apc[ii]);
107 result=talloc_asprintf(mem_ctx,
108 "IDP realm: \"%.*s\""
113 idp->realm_id->len, idp->realm_id->buf,
114 (idp->shared_config)?"yes":"no",
115 (idp->origin==TR_REALM_LOCAL)?"yes":"no",
118 talloc_free(tmp_ctx);