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"
97 *****************************************************************/
98 int dist_and_reload (const zone_t
*zp
)
100 char path
[MAX_PATHSIZE
+1];
107 assert (zp
->conf
->dist_cmd
!= NULL
);
109 if ( !is_exec_ok (zp
->conf
->dist_cmd
) )
113 if ( getuid () == 0 )
114 mesg
= "\tDistribution command %s not run as root\n";
116 mesg
= "\tDistribution command %s not run due to strange file mode settings\n";
118 verbmesg (1, zp
->conf
, mesg
, zp
->conf
->dist_cmd
);
119 lg_mesg (LG_ERROR
, "exec of distribution command %s disabled due to security reasons", zp
->conf
->dist_cmd
);
124 if ( zp
->conf
->view
)
125 snprintf (zone
, sizeof (zone
), "\"%s\" in view \"%s\"", zp
->zone
, zp
->conf
->view
);
127 snprintf (zone
, sizeof (zone
), "\"%s\"", zp
->zone
);
130 pathname (path
, sizeof (path
), zp
->dir
, zp
->sfile
, NULL
);
132 lg_mesg (LG_NOTICE
, "%s: distribution triggered", zone
);
133 verbmesg (1, zp
->conf
, "\tDistribute zone %s\n", zone
);
134 if ( zp
->conf
->view
)
135 snprintf (cmdline
, sizeof (cmdline
), "%s distribute %s %s %s", zp
->conf
->dist_cmd
, zp
->zone
, path
, zp
->conf
->view
);
137 snprintf (cmdline
, sizeof (cmdline
), "%s distribute %s %s", zp
->conf
->dist_cmd
, zp
->zone
, path
);
140 if ( zp
->conf
->noexec
== 0 )
142 verbmesg (2, zp
->conf
, "\t Run cmd \"%s\"\n", cmdline
);
143 if ( (fp
= popen (cmdline
, "r")) == NULL
|| fgets (str
, sizeof str
, fp
) == NULL
)
146 verbmesg (2, zp
->conf
, "\t %s distribute return: \"%s\"\n", zp
->conf
->dist_cmd
, str_chop (str
, '\n'));
150 lg_mesg (LG_NOTICE
, "%s: reload triggered", zone
);
151 verbmesg (1, zp
->conf
, "\tReload zone %s\n", zone
);
152 if ( zp
->conf
->view
)
153 snprintf (cmdline
, sizeof (cmdline
), "%s reload %s %s %s", zp
->conf
->dist_cmd
, zp
->zone
, path
, zp
->conf
->view
);
155 snprintf (cmdline
, sizeof (cmdline
), "%s reload %s %s", zp
->conf
->dist_cmd
, zp
->zone
, path
);
158 if ( zp
->conf
->noexec
== 0 )
160 verbmesg (2, zp
->conf
, "\t Run cmd \"%s\"\n", cmdline
);
161 if ( (fp
= popen (cmdline
, "r")) == NULL
|| fgets (str
, sizeof str
, fp
) == NULL
)
164 verbmesg (2, zp
->conf
, "\t %s reload return: \"%s\"\n", zp
->conf
->dist_cmd
, str_chop (str
, '\n'));
170 /*****************************************************************
171 ** reload a zone via "rndc"
172 *****************************************************************/
173 int reload_zone (const char *domain
, const zconf_t
*z
)
180 dbg_val3 ("reload_zone %d :%s: :%s:\n", z
->verbosity
, domain
, z
->view
);
182 snprintf (str
, sizeof (str
), "\"%s\" in view \"%s\"", domain
, z
->view
);
184 snprintf (str
, sizeof (str
), "\"%s\"", domain
);
186 lg_mesg (LG_NOTICE
, "%s: reload triggered", str
);
187 verbmesg (1, z
, "\tReload zone %s\n", str
);
190 snprintf (cmdline
, sizeof (cmdline
), "%s reload %s IN %s", RELOADCMD
, domain
, z
->view
);
192 snprintf (cmdline
, sizeof (cmdline
), "%s reload %s", RELOADCMD
, domain
);
195 if ( z
->noexec
== 0 )
197 verbmesg (2, z
, "\t Run cmd \"%s\"\n", cmdline
);
198 if ( (fp
= popen (cmdline
, "r")) == NULL
|| fgets (str
, sizeof str
, fp
) == NULL
)
201 verbmesg (2, z
, "\t rndc reload return: \"%s\"\n", str_chop (str
, '\n'));