1999-07-19 13:25:18 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1999 Internet Software Consortium.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
|
|
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
|
|
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
|
|
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
|
|
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <isc/assertions.h>
|
1999-10-02 02:54:16 +00:00
|
|
|
#include <isc/net.h>
|
1999-10-16 01:34:30 +00:00
|
|
|
#include <isc/magic.h>
|
1999-07-19 13:25:18 +00:00
|
|
|
|
|
|
|
#include <dns/confctl.h>
|
|
|
|
#include <dns/confcommon.h>
|
|
|
|
|
1999-10-16 01:34:30 +00:00
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
dns_c_ctrllist_new(isc_log_t *lctx,
|
|
|
|
isc_mem_t *mem, dns_c_ctrllist_t **newlist)
|
|
|
|
{
|
|
|
|
dns_c_ctrllist_t *newl;
|
|
|
|
|
|
|
|
REQUIRE(mem != NULL);
|
|
|
|
REQUIRE (newlist != NULL);
|
|
|
|
|
|
|
|
(void) lctx;
|
|
|
|
|
|
|
|
newl = isc_mem_get(mem, sizeof *newl);
|
|
|
|
if (newl == NULL) {
|
|
|
|
/* XXXJAB logwrite */
|
|
|
|
return (ISC_R_NOMEMORY);
|
|
|
|
}
|
|
|
|
|
|
|
|
newl->mem = mem;
|
1999-12-01 16:29:00 +00:00
|
|
|
newl->magic = DNS_C_CONFCTLLIST_MAGIC;
|
1999-10-16 01:34:30 +00:00
|
|
|
|
|
|
|
ISC_LIST_INIT(newl->elements);
|
|
|
|
|
|
|
|
*newlist = newl;
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
dns_c_ctrllist_print(isc_log_t *lctx,
|
|
|
|
FILE *fp, int indent, dns_c_ctrllist_t *cl)
|
|
|
|
{
|
|
|
|
dns_c_ctrl_t *ctl;
|
|
|
|
|
|
|
|
if (cl == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-12-01 16:29:00 +00:00
|
|
|
REQUIRE(DNS_C_CONFCTLLIST_VALID(cl));
|
1999-10-16 01:34:30 +00:00
|
|
|
|
|
|
|
if (ISC_LIST_EMPTY(cl->elements)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(fp, "controls {\n");
|
|
|
|
ctl = ISC_LIST_HEAD(cl->elements);
|
|
|
|
while (ctl != NULL) {
|
|
|
|
dns_c_printtabs(lctx, fp, indent + 1);
|
|
|
|
dns_c_ctrl_print(lctx, fp, indent + 1, ctl);
|
|
|
|
ctl = ISC_LIST_NEXT(ctl, next);
|
|
|
|
}
|
|
|
|
fprintf(fp, "};\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-07-19 13:25:18 +00:00
|
|
|
|
|
|
|
isc_result_t
|
1999-10-02 21:23:11 +00:00
|
|
|
dns_c_ctrllist_delete(isc_log_t *lctx,
|
|
|
|
dns_c_ctrllist_t **list)
|
1999-07-19 13:25:18 +00:00
|
|
|
{
|
|
|
|
dns_c_ctrl_t *ctrl;
|
|
|
|
dns_c_ctrl_t *tmpctrl;
|
1999-09-03 20:48:22 +00:00
|
|
|
dns_c_ctrllist_t *clist;
|
1999-07-19 13:25:18 +00:00
|
|
|
|
|
|
|
REQUIRE(list != NULL);
|
1999-11-17 21:52:32 +00:00
|
|
|
REQUIRE(*list != NULL);
|
1999-10-16 01:34:30 +00:00
|
|
|
|
1999-07-19 13:25:18 +00:00
|
|
|
clist = *list;
|
|
|
|
|
1999-12-01 16:29:00 +00:00
|
|
|
REQUIRE(DNS_C_CONFCTLLIST_VALID(clist));
|
1999-10-16 01:34:30 +00:00
|
|
|
|
1999-07-19 13:25:18 +00:00
|
|
|
ctrl = ISC_LIST_HEAD(clist->elements);
|
|
|
|
while (ctrl != NULL) {
|
|
|
|
tmpctrl = ISC_LIST_NEXT(ctrl, next);
|
1999-10-02 21:23:11 +00:00
|
|
|
dns_c_ctrl_delete(lctx, &ctrl);
|
1999-07-19 13:25:18 +00:00
|
|
|
ctrl = tmpctrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_mem_put(clist->mem, clist, sizeof *clist);
|
|
|
|
|
|
|
|
*list = NULL;
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
isc_result_t
|
1999-10-02 21:23:11 +00:00
|
|
|
dns_c_ctrlinet_new(isc_log_t *lctx, isc_mem_t *mem, dns_c_ctrl_t **control,
|
|
|
|
isc_sockaddr_t addr, short port,
|
|
|
|
dns_c_ipmatchlist_t *iml, isc_boolean_t copy)
|
1999-07-19 13:25:18 +00:00
|
|
|
{
|
|
|
|
dns_c_ctrl_t *ctrl;
|
|
|
|
isc_result_t res;
|
|
|
|
|
|
|
|
REQUIRE(mem != NULL);
|
|
|
|
REQUIRE(control != NULL);
|
|
|
|
|
|
|
|
ctrl = isc_mem_get(mem, sizeof *ctrl);
|
|
|
|
if (ctrl == NULL) {
|
|
|
|
return (ISC_R_NOMEMORY);
|
|
|
|
}
|
|
|
|
|
1999-12-01 16:29:00 +00:00
|
|
|
ctrl->magic = DNS_C_CONFCTL_MAGIC;
|
1999-07-19 13:25:18 +00:00
|
|
|
ctrl->mem = mem;
|
|
|
|
ctrl->control_type = dns_c_inet_control;
|
|
|
|
ctrl->u.inet_v.addr = addr;
|
|
|
|
ctrl->u.inet_v.port = port;
|
|
|
|
|
|
|
|
if (copy) {
|
1999-10-02 21:23:11 +00:00
|
|
|
res = dns_c_ipmatchlist_copy(lctx, mem,
|
|
|
|
&ctrl->u.inet_v.matchlist, iml);
|
1999-07-19 13:25:18 +00:00
|
|
|
if (res != ISC_R_SUCCESS) {
|
|
|
|
isc_mem_put(mem, ctrl, sizeof *ctrl);
|
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ctrl->u.inet_v.matchlist = iml;
|
|
|
|
}
|
|
|
|
|
|
|
|
*control = ctrl;
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
isc_result_t
|
1999-10-02 21:23:11 +00:00
|
|
|
dns_c_ctrlunix_new(isc_log_t *lctx,
|
|
|
|
isc_mem_t *mem, dns_c_ctrl_t **control,
|
|
|
|
const char *path, int perm, uid_t uid, gid_t gid)
|
1999-07-19 13:25:18 +00:00
|
|
|
{
|
|
|
|
dns_c_ctrl_t *ctrl;
|
|
|
|
|
|
|
|
REQUIRE(mem != NULL);
|
|
|
|
REQUIRE(control != NULL);
|
|
|
|
|
1999-10-02 21:23:11 +00:00
|
|
|
(void) lctx;
|
|
|
|
|
1999-07-19 13:25:18 +00:00
|
|
|
ctrl = isc_mem_get(mem, sizeof *ctrl);
|
|
|
|
if (ctrl == NULL) {
|
|
|
|
return (ISC_R_NOMEMORY);
|
|
|
|
}
|
|
|
|
|
1999-12-01 16:29:00 +00:00
|
|
|
ctrl->magic = DNS_C_CONFCTL_MAGIC;
|
1999-07-19 13:25:18 +00:00
|
|
|
ctrl->mem = mem;
|
|
|
|
ctrl->control_type = dns_c_unix_control;
|
|
|
|
ctrl->u.unix_v.pathname = isc_mem_strdup(mem, path);
|
|
|
|
if (ctrl->u.unix_v.pathname == NULL) {
|
|
|
|
isc_mem_put(mem, ctrl, sizeof *ctrl);
|
1999-10-02 21:23:11 +00:00
|
|
|
/* XXXJAB logwrite */
|
1999-07-19 13:25:18 +00:00
|
|
|
return (ISC_R_NOMEMORY);
|
|
|
|
}
|
|
|
|
|
|
|
|
ctrl->u.unix_v.perm = perm;
|
|
|
|
ctrl->u.unix_v.owner = uid;
|
|
|
|
ctrl->u.unix_v.group = gid;
|
|
|
|
|
|
|
|
*control = ctrl;
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
isc_result_t
|
1999-10-02 21:23:11 +00:00
|
|
|
dns_c_ctrl_delete(isc_log_t *lctx,
|
|
|
|
dns_c_ctrl_t **control)
|
1999-07-19 13:25:18 +00:00
|
|
|
{
|
1999-10-16 01:34:30 +00:00
|
|
|
isc_result_t res = ISC_R_SUCCESS;
|
1999-07-19 13:25:18 +00:00
|
|
|
isc_result_t rval;
|
|
|
|
isc_mem_t *mem;
|
|
|
|
dns_c_ctrl_t *ctrl;
|
|
|
|
|
|
|
|
REQUIRE(control != NULL);
|
1999-11-17 21:52:32 +00:00
|
|
|
REQUIRE(*control != NULL);
|
1999-07-19 13:25:18 +00:00
|
|
|
|
|
|
|
ctrl = *control;
|
|
|
|
|
1999-12-01 16:29:00 +00:00
|
|
|
REQUIRE(DNS_C_CONFCTL_VALID(ctrl));
|
1999-10-16 01:34:30 +00:00
|
|
|
|
1999-07-19 13:25:18 +00:00
|
|
|
mem = ctrl->mem;
|
|
|
|
|
|
|
|
switch (ctrl->control_type) {
|
|
|
|
case dns_c_inet_control:
|
1999-11-17 21:52:32 +00:00
|
|
|
if (ctrl->u.inet_v.matchlist != NULL)
|
|
|
|
res = dns_c_ipmatchlist_detach(lctx,
|
|
|
|
&ctrl->u.inet_v.matchlist);
|
|
|
|
else
|
|
|
|
res = ISC_R_SUCCESS;
|
1999-07-19 13:25:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case dns_c_unix_control:
|
|
|
|
isc_mem_free(mem, ctrl->u.unix_v.pathname);
|
|
|
|
res = ISC_R_SUCCESS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rval = res;
|
|
|
|
|
1999-10-16 01:34:30 +00:00
|
|
|
ctrl->magic = 0;
|
|
|
|
|
1999-07-19 13:25:18 +00:00
|
|
|
isc_mem_put(mem, ctrl, sizeof *ctrl);
|
|
|
|
|
|
|
|
*control = NULL;
|
|
|
|
|
1999-10-16 01:34:30 +00:00
|
|
|
return (res);
|
1999-07-19 13:25:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
1999-10-02 21:23:11 +00:00
|
|
|
dns_c_ctrl_print(isc_log_t *lctx,
|
|
|
|
FILE *fp, int indent, dns_c_ctrl_t *ctl)
|
1999-07-19 13:25:18 +00:00
|
|
|
{
|
|
|
|
short port;
|
1999-09-03 20:48:22 +00:00
|
|
|
dns_c_ipmatchlist_t *iml;
|
1999-07-19 13:25:18 +00:00
|
|
|
|
1999-12-01 16:29:00 +00:00
|
|
|
REQUIRE(DNS_C_CONFCTL_VALID(ctl));
|
1999-10-16 01:34:30 +00:00
|
|
|
|
1999-07-19 13:25:18 +00:00
|
|
|
(void) indent;
|
|
|
|
|
|
|
|
if (ctl->control_type == dns_c_inet_control) {
|
|
|
|
port = ctl->u.inet_v.port;
|
|
|
|
iml = ctl->u.inet_v.matchlist;
|
|
|
|
|
|
|
|
fprintf(fp, "inet ");
|
1999-10-02 21:23:11 +00:00
|
|
|
dns_c_print_ipaddr(lctx, fp, &ctl->u.inet_v.addr);
|
1999-09-17 14:22:06 +00:00
|
|
|
|
1999-10-28 17:53:16 +00:00
|
|
|
if (port == 0) {
|
1999-07-19 13:25:18 +00:00
|
|
|
fprintf(fp, " port *\n");
|
|
|
|
} else {
|
1999-10-28 17:53:16 +00:00
|
|
|
fprintf(fp, " port %d\n", port);
|
1999-07-19 13:25:18 +00:00
|
|
|
}
|
1999-09-17 14:22:06 +00:00
|
|
|
|
1999-10-02 21:23:11 +00:00
|
|
|
dns_c_printtabs(lctx, fp, indent + 1);
|
1999-07-19 13:25:18 +00:00
|
|
|
fprintf(fp, "allow ");
|
1999-10-02 21:23:11 +00:00
|
|
|
dns_c_ipmatchlist_print(lctx, fp, indent + 2, iml);
|
1999-10-25 09:52:42 +00:00
|
|
|
fprintf(fp, ";\n");
|
1999-07-19 13:25:18 +00:00
|
|
|
} else {
|
1999-09-17 14:22:06 +00:00
|
|
|
/* The "#" means force a leading zero */
|
1999-10-29 06:19:56 +00:00
|
|
|
fprintf(fp, "unix \"%s\" perm %#o owner %lu group %lu;\n",
|
1999-07-19 13:25:18 +00:00
|
|
|
ctl->u.unix_v.pathname,
|
|
|
|
ctl->u.unix_v.perm,
|
1999-10-29 06:19:56 +00:00
|
|
|
(unsigned long)ctl->u.unix_v.owner,
|
|
|
|
(unsigned long)ctl->u.unix_v.group);
|
1999-07-19 13:25:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|