sdlz_helper.c revision dc64df4479df5e7cb3ed1dead21888b5af98f67e
ca41b452ede6feaa9d8739ec3cae19389a7b0d03Bob Halley * Copyright (C) 2002 Stichting NLnet, Netherlands, stichting@nlnet.nl.
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * Permission to use, copy, modify, and distribute this software for any
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * purpose with or without fee is hereby granted, provided that the
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * above copyright notice and this permission notice appear in all
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * THE SOFTWARE IS PROVIDED "AS IS" AND STICHTING NLNET
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * STICHTING NLNET BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * USE OR PERFORMANCE OF THIS SOFTWARE.
d25afd60ee2286cb171c4960a790f3d7041b6f85Bob Halley * The development of Dynamically Loadable Zones (DLZ) for Bind 9 was
d25afd60ee2286cb171c4960a790f3d7041b6f85Bob Halley * conceived and contributed by Rob Butler.
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley * Permission to use, copy, modify, and distribute this software for any
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley * purpose with or without fee is hereby granted, provided that the
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley * above copyright notice and this permission notice appear in all
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley * THE SOFTWARE IS PROVIDED "AS IS" AND ROB BUTLER
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley * ROB BUTLER BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrence * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrence * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrence * USE OR PERFORMANCE OF THIS SOFTWARE.
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrence * Copyright (C) 1999-2001 Internet Software Consortium.
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrence * Permission to use, copy, modify, and distribute this software for any
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrence * purpose with or without fee is hereby granted, provided that the above
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley * copyright notice and this permission notice appear in all copies.
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
ea872078bfa9473cfe9c89b474dae2496377797bDavid Lawrence * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
ea872078bfa9473cfe9c89b474dae2496377797bDavid Lawrence * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
ea872078bfa9473cfe9c89b474dae2496377797bDavid Lawrence * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley * sdlz helper methods
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley * properly destroys a querylist by de-allocating the
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley * memory for each query segment, and then the list itself
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halleydestroy_querylist(isc_mem_t *mctx, query_list_t **querylist)
ea872078bfa9473cfe9c89b474dae2496377797bDavid Lawrence /* if query list is null, nothing to do */
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence /* start at the top of the list */
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence while (nseg != NULL) { /* loop, until end of list */
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence * free the query segment's text string but only if it
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence * was really a query segment, and not a pointer to
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence * %zone%, or %record%, or %client%
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence if (tseg->sql != NULL && tseg->direct == isc_boolean_true)
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence /* get the next query segment, before we destroy this one. */
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence /* deallocate this query segment. */
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence isc_mem_put(mctx, tseg, sizeof(query_segment_t));
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence /* deallocate the query segment list */
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence isc_mem_put(mctx, *querylist, sizeof(query_list_t));
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley/*% constructs a query list by parsing a string into query segments */
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halleybuild_querylist(isc_mem_t *mctx, const char *query_str, char **zone,
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley char **record, char **client, query_list_t **querylist,
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley unsigned int flags)
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley REQUIRE(querylist != NULL && *querylist == NULL);
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrence /* if query string is null, or zero length */
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrence if (query_str == NULL || strlen(query_str) < 1) {
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley /* we don't need it were ok. */
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley /* we did need it, PROBLEM!!! */
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley /* allocate memory for query list */
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley /* couldn't allocate memory. Problem!! */
9fbefe0ace2ae7dba287f914b278153004bef428Bob Halley /* initialize the query segment list */
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley /* make a copy of query_str so we can chop it up */
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence temp_str = right_str = isc_mem_strdup(mctx, query_str);
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence /* couldn't make a copy, problem!! */
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence /* loop through the string and chop it up */
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence /* allocate memory for tseg */
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence tseg = isc_mem_get(mctx, sizeof(query_segment_t));
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence if (tseg == NULL) { /* no memory, clean everything up. */
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence /* initialize the query segment link */
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence /* append the query segment to the list */
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence * split string at the first "$". set query segment to
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence * left portion
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley /* no memory, clean everything up. */
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley /* tseg->sql points directly to a string. */
b592e197fe354d7258dc4166fce0a9425a338b0bBob Halley /* check if we encountered "$zone$" token */
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley * we don't really need, or want the "zone"
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley * text, so get rid of it.
b592e197fe354d7258dc4166fce0a9425a338b0bBob Halley /* set tseg->sql to in-direct zone string */
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence /* tseg->sql points in-directly to a string */
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence /* check if we encountered "$record$" token */
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley } else if (strcasecmp(tseg->sql, "record") == 0) {
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley * we don't really need, or want the "record"
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence * text, so get rid of it.
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley /* set tseg->sql to in-direct record string */
0fc87fa2f38df7b293b650deacfa5e6c3d50eff9Bob Halley /* tseg->sql points in-directly poinsts to a string */
b592e197fe354d7258dc4166fce0a9425a338b0bBob Halley /* check if we encountered "$client$" token */
b592e197fe354d7258dc4166fce0a9425a338b0bBob Halley } else if (strcasecmp(tseg->sql, "client") == 0) {
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence * we don't really need, or want the "client"
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence * text, so get rid of it.
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence /* set tseg->sql to in-direct record string */
4d6964d70a114b53a11a3bd778d9b8f5179a7934Bob Halley /* tseg->sql points in-directly poinsts to a string */
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence /* we don't need temp_str any more */
b592e197fe354d7258dc4166fce0a9425a338b0bBob Halley * add checks later to verify zone and record are found if
b592e197fe354d7258dc4166fce0a9425a338b0bBob Halley /* if this query requires %client%, make sure we found it */
b592e197fe354d7258dc4166fce0a9425a338b0bBob Halley if (((flags & SDLZH_REQUIRE_CLIENT) != 0) && (!foundclient) ) {
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence /* Write error message to log */
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
d5069ac954d067aa45ad395fc338f7e499b834c1David Lawrence "Required token $client$ not found.");
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrence /* if this query requires %record%, make sure we found it */
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrence if (((flags & SDLZH_REQUIRE_RECORD) != 0) && (!foundrecord) ) {
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrence /* Write error message to log */
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrence isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence "Required token $record$ not found.");
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrence /* if this query requires %zone%, make sure we found it */
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrence if (((flags & SDLZH_REQUIRE_ZONE) != 0) && (!foundzone) ) {
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrence /* Write error message to log */
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrence isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrence "Required token $zone$ not found.");
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence /* pass back the query list */
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrence /* return success */
11d732daac76a24a0f3e5948a2758a4b866a0825David Lawrence /* get rid of temp_str */
return result;
* used to be in our queries from named.conf
unsigned int length = 0;
return NULL;
return qs;
return (ISC_R_NOMEMORY);
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
return (ISC_R_SUCCESS);
return (ISC_R_FAILURE);
int keylen;
char *keystart;
return NULL;
return NULL;
return NULL;