186ed60a6SMatthew Dillon /*
286ed60a6SMatthew Dillon * rconfig - Remote configurator
386ed60a6SMatthew Dillon *
486ed60a6SMatthew Dillon * rconfig [-W workingdir] [server_ip[:tag]]
586ed60a6SMatthew Dillon * rconfig [-f configfile] -s
686ed60a6SMatthew Dillon *
77a25b4e0SMatthew Dillon * Copyright (c) 2003,2004 The DragonFly Project. All rights reserved.
87a25b4e0SMatthew Dillon *
97a25b4e0SMatthew Dillon * This code is derived from software contributed to The DragonFly Project
107a25b4e0SMatthew Dillon * by Matthew Dillon <dillon@backplane.com>
117a25b4e0SMatthew Dillon *
127a25b4e0SMatthew Dillon * Redistribution and use in source and binary forms, with or without
137a25b4e0SMatthew Dillon * modification, are permitted provided that the following conditions
147a25b4e0SMatthew Dillon * are met:
157a25b4e0SMatthew Dillon *
167a25b4e0SMatthew Dillon * 1. Redistributions of source code must retain the above copyright
177a25b4e0SMatthew Dillon * notice, this list of conditions and the following disclaimer.
187a25b4e0SMatthew Dillon * 2. Redistributions in binary form must reproduce the above copyright
197a25b4e0SMatthew Dillon * notice, this list of conditions and the following disclaimer in
207a25b4e0SMatthew Dillon * the documentation and/or other materials provided with the
217a25b4e0SMatthew Dillon * distribution.
227a25b4e0SMatthew Dillon * 3. Neither the name of The DragonFly Project nor the names of its
237a25b4e0SMatthew Dillon * contributors may be used to endorse or promote products derived
247a25b4e0SMatthew Dillon * from this software without specific, prior written permission.
257a25b4e0SMatthew Dillon *
267a25b4e0SMatthew Dillon * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
277a25b4e0SMatthew Dillon * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
287a25b4e0SMatthew Dillon * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
297a25b4e0SMatthew Dillon * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
307a25b4e0SMatthew Dillon * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
317a25b4e0SMatthew Dillon * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
327a25b4e0SMatthew Dillon * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
337a25b4e0SMatthew Dillon * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
347a25b4e0SMatthew Dillon * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
357a25b4e0SMatthew Dillon * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
367a25b4e0SMatthew Dillon * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
377a25b4e0SMatthew Dillon * SUCH DAMAGE.
387a25b4e0SMatthew Dillon *
3986ed60a6SMatthew Dillon */
4086ed60a6SMatthew Dillon
4186ed60a6SMatthew Dillon #include "defs.h"
4286ed60a6SMatthew Dillon
4386ed60a6SMatthew Dillon const char *WorkDir = "/tmp";
4486ed60a6SMatthew Dillon const char *ConfigFiles = "/etc/defaults/rconfig.conf:/etc/rconfig.conf";
4586ed60a6SMatthew Dillon const char *TagDir = "/usr/local/etc/rconfig";
4686ed60a6SMatthew Dillon tag_t AddrBase;
4786ed60a6SMatthew Dillon tag_t VarBase;
4886ed60a6SMatthew Dillon int VerboseOpt;
4986ed60a6SMatthew Dillon
5086ed60a6SMatthew Dillon static void usage(int code);
5186ed60a6SMatthew Dillon static void addTag(tag_t *basep, const char *tag, int flags);
5286ed60a6SMatthew Dillon
5386ed60a6SMatthew Dillon int
main(int ac,char ** av)5486ed60a6SMatthew Dillon main(int ac, char **av)
5586ed60a6SMatthew Dillon {
5686ed60a6SMatthew Dillon int ch;
5786ed60a6SMatthew Dillon int i;
5886ed60a6SMatthew Dillon int serverMode = 0;
5986ed60a6SMatthew Dillon
6018f423d7SAntonio Huete Jimenez while ((ch = getopt(ac, av, "aW:T:C:sv")) != -1) {
6186ed60a6SMatthew Dillon switch(ch) {
6286ed60a6SMatthew Dillon case 'a': /* auto tag / standard broadcast */
6386ed60a6SMatthew Dillon addTag(&AddrBase, NULL, 0);
6486ed60a6SMatthew Dillon break;
6586ed60a6SMatthew Dillon case 'W': /* specify working directory */
6686ed60a6SMatthew Dillon WorkDir = optarg;
6786ed60a6SMatthew Dillon break;
6886ed60a6SMatthew Dillon case 'T':
6986ed60a6SMatthew Dillon TagDir = optarg;
7086ed60a6SMatthew Dillon break;
7186ed60a6SMatthew Dillon case 'C': /* specify server config file(s) (colon delimited) */
7286ed60a6SMatthew Dillon ConfigFiles = optarg;
7386ed60a6SMatthew Dillon break;
7486ed60a6SMatthew Dillon case 's': /* run as server using config file */
7586ed60a6SMatthew Dillon serverMode = 1;
7686ed60a6SMatthew Dillon break;
7786ed60a6SMatthew Dillon case 'v':
7886ed60a6SMatthew Dillon VerboseOpt = 1;
7986ed60a6SMatthew Dillon break;
8086ed60a6SMatthew Dillon default:
8186ed60a6SMatthew Dillon usage(1);
8286ed60a6SMatthew Dillon /* not reached */
8386ed60a6SMatthew Dillon }
8486ed60a6SMatthew Dillon }
8586ed60a6SMatthew Dillon for (i = optind; i < ac; ++i) {
8686ed60a6SMatthew Dillon if (strchr(av[i], '='))
8786ed60a6SMatthew Dillon addTag(&VarBase, av[i], 0);
8886ed60a6SMatthew Dillon else
8986ed60a6SMatthew Dillon addTag(&AddrBase, av[i], 0);
9086ed60a6SMatthew Dillon }
9186ed60a6SMatthew Dillon if (AddrBase == NULL)
9286ed60a6SMatthew Dillon usage(1);
93b942d70cSMatthew Dillon if (AddrBase && AddrBase->name == NULL && AddrBase->next) {
94b942d70cSMatthew Dillon fprintf(stderr,
95b942d70cSMatthew Dillon "You cannot specify both -a AND a list of hosts. If you want\n"
960e1245dbSSascha Wildner "to use auto-broadcast mode with a tag other than 'auto',\n"
97b942d70cSMatthew Dillon "just specify the tag without a host, e.g. ':<tag>'\n");
98b942d70cSMatthew Dillon exit(1);
99b942d70cSMatthew Dillon }
10086ed60a6SMatthew Dillon if (serverMode)
10186ed60a6SMatthew Dillon doServer();
10286ed60a6SMatthew Dillon else
10386ed60a6SMatthew Dillon doClient();
10486ed60a6SMatthew Dillon return(0);
10586ed60a6SMatthew Dillon }
10686ed60a6SMatthew Dillon
10786ed60a6SMatthew Dillon static
10886ed60a6SMatthew Dillon void
addTag(tag_t * basep,const char * name,int flags)10986ed60a6SMatthew Dillon addTag(tag_t *basep, const char *name, int flags)
11086ed60a6SMatthew Dillon {
11186ed60a6SMatthew Dillon tag_t tag = calloc(sizeof(struct tag), 1);
11286ed60a6SMatthew Dillon
11386ed60a6SMatthew Dillon while ((*basep) != NULL)
11486ed60a6SMatthew Dillon basep = &(*basep)->next;
11586ed60a6SMatthew Dillon
11686ed60a6SMatthew Dillon tag->name = name;
11786ed60a6SMatthew Dillon tag->flags = flags;
11886ed60a6SMatthew Dillon *basep = tag;
11986ed60a6SMatthew Dillon }
12086ed60a6SMatthew Dillon
12186ed60a6SMatthew Dillon static void
usage(int code)12286ed60a6SMatthew Dillon usage(int code)
12386ed60a6SMatthew Dillon {
124*ad330ab8SAaron LI fprintf(stderr,
125*ad330ab8SAaron LI "rconfig [-a] [-v] [-W workdir] [host[:tag] ...]\n"
126*ad330ab8SAaron LI "rconfig -s [-C configfiles] [-W workdir] [-T tagdir] "
127*ad330ab8SAaron LI "[-v] [bind_address ...]\n");
12886ed60a6SMatthew Dillon exit(code);
12986ed60a6SMatthew Dillon }
13086ed60a6SMatthew Dillon
131