1 /* $NetBSD: nscomm.c,v 1.1.1.1 2015/07/08 15:37:48 christos Exp $ */
3 /*****************************************************************
5 ** @(#) nscomm.c (c) 2005 - 2009 Holger Zuleger hznet.de
7 ** Copyright (c) 2005 - 2009, Holger Zuleger HZnet. All rights reserved.
9 ** This software is open source.
11 ** Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions
15 ** Redistributions of source code must retain the above copyright notice,
16 ** this list of conditions and the following disclaimer.
18 ** Redistributions in binary form must reproduce the above copyright notice,
19 ** this list of conditions and the following disclaimer in the documentation
20 ** and/or other materials provided with the distribution.
22 ** Neither the name of Holger Zuleger HZnet nor the names of its contributors may
23 ** be used to endorse or promote products derived from this software without
24 ** specific prior written permission.
26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 ** TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 ** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
30 ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 ** POSSIBILITY OF SUCH DAMAGE.
38 *****************************************************************/
45 #include "config_zkt.h"
52 /*****************************************************************
53 ** dyn_update_freeze ()
54 *****************************************************************/
55 int dyn_update_freeze (const char *domain
, const zconf_t
*z
, int freeze
)
69 snprintf (str
, sizeof (str
), "\"%s\" in view \"%s\"", domain
, z
->view
);
71 snprintf (str
, sizeof (str
), "\"%s\"", domain
);
73 lg_mesg (LG_NOTICE
, "%s: %s dynamic zone", str
, action
);
74 verbmesg (1, z
, "\t%s dynamic zone %s\n", action
, str
);
77 snprintf (cmdline
, sizeof (cmdline
), "%s %s %s IN %s", RELOADCMD
, action
, domain
, z
->view
);
79 snprintf (cmdline
, sizeof (cmdline
), "%s %s %s", RELOADCMD
, action
, domain
);
81 verbmesg (2, z
, "\t Run cmd \"%s\"\n", cmdline
);
85 if ( (fp
= popen (cmdline
, "r")) == NULL
|| fgets (str
, sizeof str
, fp
) == NULL
)
90 verbmesg (2, z
, "\t rndc %s return: \"%s\"\n", action
, str_chop (str
, '\n'));
95 /*****************************************************************
96 ** distribute and reload a zone via "distribute_command"
98 ** 1 for zone distribution and relaod
99 ** 2 for key distribution (used by dynamic zoes)
100 *****************************************************************/
101 int dist_and_reload (const zone_t
*zp
, int what
)
103 char path
[MAX_PATHSIZE
+1];
111 assert (zp
->conf
->dist_cmd
!= NULL
);
112 assert ( what
== 1 || what
== 2 );
114 if ( zp
->conf
->dist_cmd
== NULL
)
117 if ( !is_exec_ok (zp
->conf
->dist_cmd
) )
121 if ( getuid () == 0 )
122 mesg
= "\tDistribution command %s not run as root\n";
124 mesg
= "\tDistribution command %s not run due to strange file mode settings\n";
126 verbmesg (1, zp
->conf
, mesg
, zp
->conf
->dist_cmd
);
127 lg_mesg (LG_ERROR
, "exec of distribution command %s disabled due to security reasons", zp
->conf
->dist_cmd
);
132 view
= ""; /* default is an empty view string */
133 if ( zp
->conf
->view
)
135 snprintf (zone
, sizeof (zone
), "\"%s\" in view \"%s\"", zp
->zone
, zp
->conf
->view
);
136 view
= zp
->conf
->view
;
139 snprintf (zone
, sizeof (zone
), "\"%s\"", zp
->zone
);
144 lg_mesg (LG_NOTICE
, "%s: key distribution triggered", zone
);
145 verbmesg (1, zp
->conf
, "\tDistribute keys for zone %s\n", zone
);
146 snprintf (cmdline
, sizeof (cmdline
), "%s distkeys %s %s %s",
147 zp
->conf
->dist_cmd
, zp
->zone
, path
, view
);
149 if ( zp
->conf
->noexec
== 0 )
151 verbmesg (2, zp
->conf
, "\t Run cmd \"%s\"\n", cmdline
);
152 if ( (fp
= popen (cmdline
, "r")) == NULL
|| fgets (str
, sizeof str
, fp
) == NULL
)
155 verbmesg (2, zp
->conf
, "\t %s distribute return: \"%s\"\n", zp
->conf
->dist_cmd
, str_chop (str
, '\n'));
161 pathname (path
, sizeof (path
), zp
->dir
, zp
->sfile
, NULL
);
163 lg_mesg (LG_NOTICE
, "%s: distribution triggered", zone
);
164 verbmesg (1, zp
->conf
, "\tDistribute zone %s\n", zone
);
165 snprintf (cmdline
, sizeof (cmdline
), "%s distribute %s %s %s", zp
->conf
->dist_cmd
, zp
->zone
, path
, view
);
168 if ( zp
->conf
->noexec
== 0 )
170 verbmesg (2, zp
->conf
, "\t Run cmd \"%s\"\n", cmdline
);
171 if ( (fp
= popen (cmdline
, "r")) == NULL
|| fgets (str
, sizeof str
, fp
) == NULL
)
174 verbmesg (2, zp
->conf
, "\t %s distribute return: \"%s\"\n", zp
->conf
->dist_cmd
, str_chop (str
, '\n'));
178 lg_mesg (LG_NOTICE
, "%s: reload triggered", zone
);
179 verbmesg (1, zp
->conf
, "\tReload zone %s\n", zone
);
180 snprintf (cmdline
, sizeof (cmdline
), "%s reload %s %s %s", zp
->conf
->dist_cmd
, zp
->zone
, path
, view
);
183 if ( zp
->conf
->noexec
== 0 )
185 verbmesg (2, zp
->conf
, "\t Run cmd \"%s\"\n", cmdline
);
186 if ( (fp
= popen (cmdline
, "r")) == NULL
|| fgets (str
, sizeof str
, fp
) == NULL
)
189 verbmesg (2, zp
->conf
, "\t %s reload return: \"%s\"\n", zp
->conf
->dist_cmd
, str_chop (str
, '\n'));
195 /*****************************************************************
196 ** reload a zone via "rndc"
197 *****************************************************************/
198 int reload_zone (const char *domain
, const zconf_t
*z
)
205 dbg_val3 ("reload_zone %d :%s: :%s:\n", z
->verbosity
, domain
, z
->view
);
207 snprintf (str
, sizeof (str
), "\"%s\" in view \"%s\"", domain
, z
->view
);
209 snprintf (str
, sizeof (str
), "\"%s\"", domain
);
211 lg_mesg (LG_NOTICE
, "%s: reload triggered", str
);
212 verbmesg (1, z
, "\tReload zone %s\n", str
);
215 snprintf (cmdline
, sizeof (cmdline
), "%s reload %s IN %s", RELOADCMD
, domain
, z
->view
);
217 snprintf (cmdline
, sizeof (cmdline
), "%s reload %s", RELOADCMD
, domain
);
220 if ( z
->noexec
== 0 )
222 verbmesg (2, z
, "\t Run cmd \"%s\"\n", cmdline
);
223 if ( (fp
= popen (cmdline
, "r")) == NULL
|| fgets (str
, sizeof str
, fp
) == NULL
)
226 verbmesg (2, z
, "\t rndc reload return: \"%s\"\n", str_chop (str
, '\n'));