Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / bind / dist / contrib / zkt / nscomm.c
blobad106e71107250943261cc6200c843c2f7dc64d4
1 /* $NetBSD$ */
3 /*****************************************************************
4 **
5 ** @(#) nscomm.c (c) 2005 - 2009 Holger Zuleger hznet.de
6 **
7 ** Copyright (c) 2005 - 2009, Holger Zuleger HZnet. All rights reserved.
8 **
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
13 ** are met:
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 *****************************************************************/
39 # include <stdio.h>
41 #ifdef HAVE_CONFIG_H
42 # include <config.h>
43 #endif
45 #include "config_zkt.h"
46 #include "zconf.h"
47 #define extern
48 #include "nscomm.h"
49 #undef extern
52 /*****************************************************************
53 ** dyn_update_freeze ()
54 *****************************************************************/
55 int dyn_update_freeze (const char *domain, const zconf_t *z, int freeze)
57 char cmdline[254+1];
58 char str[254+1];
59 char *action;
60 FILE *fp;
62 assert (z != NULL);
63 if ( freeze )
64 action = "freeze";
65 else
66 action = "thaw";
68 if ( z->view )
69 snprintf (str, sizeof (str), "\"%s\" in view \"%s\"", domain, z->view);
70 else
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);
76 if ( z->view )
77 snprintf (cmdline, sizeof (cmdline), "%s %s %s IN %s", RELOADCMD, action, domain, z->view);
78 else
79 snprintf (cmdline, sizeof (cmdline), "%s %s %s", RELOADCMD, action, domain);
81 verbmesg (2, z, "\t Run cmd \"%s\"\n", cmdline);
82 *str = '\0';
83 if ( z->noexec == 0 )
85 if ( (fp = popen (cmdline, "r")) == NULL || fgets (str, sizeof str, fp) == NULL )
86 return -1;
87 pclose (fp);
90 verbmesg (2, z, "\t rndc %s return: \"%s\"\n", action, str_chop (str, '\n'));
92 return 0;
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];
101 char cmdline[254+1];
102 char zone[254+1];
103 char str[254+1];
104 FILE *fp;
106 assert (zp != NULL);
107 assert (zp->conf->dist_cmd != NULL);
109 if ( !is_exec_ok (zp->conf->dist_cmd) )
111 char *mesg;
113 if ( getuid () == 0 )
114 mesg = "\tDistribution command %s not run as root\n";
115 else
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);
121 return -1;
124 if ( zp->conf->view )
125 snprintf (zone, sizeof (zone), "\"%s\" in view \"%s\"", zp->zone, zp->conf->view);
126 else
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);
136 else
137 snprintf (cmdline, sizeof (cmdline), "%s distribute %s %s", zp->conf->dist_cmd, zp->zone, path);
139 *str = '\0';
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 )
144 return -2;
145 pclose (fp);
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);
154 else
155 snprintf (cmdline, sizeof (cmdline), "%s reload %s %s", zp->conf->dist_cmd, zp->zone, path);
157 *str = '\0';
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 )
162 return -2;
163 pclose (fp);
164 verbmesg (2, zp->conf, "\t %s reload return: \"%s\"\n", zp->conf->dist_cmd, str_chop (str, '\n'));
167 return 0;
170 /*****************************************************************
171 ** reload a zone via "rndc"
172 *****************************************************************/
173 int reload_zone (const char *domain, const zconf_t *z)
175 char cmdline[254+1];
176 char str[254+1];
177 FILE *fp;
179 assert (z != NULL);
180 dbg_val3 ("reload_zone %d :%s: :%s:\n", z->verbosity, domain, z->view);
181 if ( z->view )
182 snprintf (str, sizeof (str), "\"%s\" in view \"%s\"", domain, z->view);
183 else
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);
189 if ( z->view )
190 snprintf (cmdline, sizeof (cmdline), "%s reload %s IN %s", RELOADCMD, domain, z->view);
191 else
192 snprintf (cmdline, sizeof (cmdline), "%s reload %s", RELOADCMD, domain);
194 *str = '\0';
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 )
199 return -1;
200 pclose (fp);
201 verbmesg (2, z, "\t rndc reload return: \"%s\"\n", str_chop (str, '\n'));
204 return 0;