main (int argc, char *argv[]) { char *optstr; int val; progname = *argv; config = loadconfig ("", (zconf_t *) NULL); /* load built in defaults */ while ( --argc >= 1 ) { optstr = *++argv; config = loadconfig_fromstr (optstr, config); } val = 1; setconfigpar (config, "-v", &val); val = 2; setconfigpar (config, "verboselog", &val); val = 1; setconfigpar (config, "recursive", &val); val = 1200; setconfigpar (config, "propagation", &val); printconfig ("stdout", config); }
int main (int argc, char *argv[]) { int c; int opt_index; int action; int major; int minor; const char *file; const char *defconfname = NULL; const char *confname = NULL; char *p; char str[254+1]; zconf_t *refconfig = NULL; zconf_t *config; progname = *argv; if ( (p = strrchr (progname, '/')) ) progname = ++p; view = getnameappendix (progname, "zkt-conf"); defconfname = getdefconfname (view); dbg_val0 ("Load built in config \"%s\"\n"); config = loadconfig ("", (zconf_t *)NULL); /* load built in config */ if ( fileexist (defconfname) ) /* load default config file */ { dbg_val ("Load site wide config file \"%s\"\n", defconfname); config = loadconfig (defconfname, config); } if ( config == NULL ) fatal ("Out of memory\n"); confname = defconfname; opterr = 0; opt_index = 0; action = 0; setconfigversion (100); #if defined(HAVE_GETOPT_LONG) && HAVE_GETOPT_LONG while ( (c = getopt_long (argc, argv, short_options, long_options, &opt_index)) != -1 ) #else while ( (c = getopt (argc, argv, short_options)) != -1 ) #endif { switch ( c ) { case 'V': /* view name */ view = optarg; defconfname = getdefconfname (view); if ( fileexist (defconfname) ) /* load default config file */ config = loadconfig (defconfname, config); if ( config == NULL ) fatal ("Out of memory\n"); confname = defconfname; break; case 'O': /* read option from commandline */ config = loadconfig_fromstr (optarg, config); break; case 'C': switch ( sscanf (optarg, "%d.%d", &major, &minor) ) { case 2: major = major * 100 + minor; case 1: break; default: usage ("illegal release number"); } setconfigversion (major); break; case 'c': if ( *optarg == '\0' ) usage ("empty config file name"); config = loadconfig (optarg, config); if ( *optarg == '-' || strcmp (optarg, "stdin") == 0 ) confname = "stdout"; else confname = optarg; break; case 'd': /* built-in default config */ config = loadconfig ("", config); /* load built-in config */ confname = defconfname; break; case 's': /* side wide config */ /* this is the default **/ break; case 'a': /* set all flag */ allflag = 1; break; case 'l': /* local config file */ refconfig = dupconfig (config); /* duplicate current config */ confname = LOCALCONF_FILE; if ( fileexist (LOCALCONF_FILE) ) /* try to load local config file */ { dbg_val ("Load local config file \"%s\"\n", LOCALCONF_FILE); config = loadconfig (LOCALCONF_FILE, config); } else if ( !writeflag ) usage ("error: no local config file found"); break; case 't': /* test config */ testflag = 1; break; case 'v': /* version */ fprintf (stderr, "%s version %s compiled for BIND version %d\n", progname, ZKT_VERSION, BIND_VERSION); fprintf (stderr, "ZKT %s\n", ZKT_COPYRIGHT); return 0; break; case 'w': /* write back conf file */ writeflag = 1; break; case 'h': /* print help */ usage (""); break; case ':': snprintf (str, sizeof(str), "option \"-%c\" requires an argument.", optopt); usage (str); break; case '?': if ( isprint (optopt) ) snprintf (str, sizeof(str), "Unknown option \"-%c\".", optopt); else snprintf (str, sizeof (str), "Unknown option char \\x%x.", optopt); usage (str); break; default: abort(); } } c = optind; if ( c >= argc ) /* no arguments given on commandline */ { if ( testflag ) { if ( checkconfig (config) ) fprintf (stderr, "All config file parameter seems to be ok\n"); } else { if ( !writeflag ) /* print to stdout */ confname = "stdout"; if ( refconfig ) /* have we seen a local config file ? */ if ( allflag ) printconfig (confname, config); else printconfigdiff (confname, refconfig, config); else printconfig (confname, config); } } else /* command line argument found: use it as name of zone file */ { long minttl; long maxttl; int keydbfound; char *dnskeydb; file = argv[c++]; dnskeydb = config->keyfile; minttl = 0x7FFFFFFF; maxttl = 0; keydbfound = parsezonefile (file, &minttl, &maxttl, dnskeydb); if ( keydbfound < 0 ) error ("can't parse zone file %s\n", file); if ( dnskeydb && !keydbfound ) { if ( writeflag ) { addkeydb (file, dnskeydb); printf ("\"$INCLUDE %s\" directive added to \"%s\"\n", dnskeydb, file); } else printf ("\"$INCLUDE %s\" should be added to \"%s\" (run with option -w)\n", dnskeydb, file); } if ( minttl < (10 * MINSEC) ) fprintf (stderr, "Min_TTL of %s (%ld seconds) is too low to use it in a signed zone (see RFC4641)\n", timeint2str (minttl), minttl); else fprintf (stderr, "Min_TTL:\t%s\t# (%ld seconds)\n", timeint2str (minttl), minttl); fprintf (stdout, "Max_TTL:\t%s\t# (%ld seconds)\n", timeint2str (maxttl), maxttl); if ( writeflag ) { refconfig = dupconfig (config); /* duplicate current config */ confname = LOCALCONF_FILE; if ( fileexist (LOCALCONF_FILE) ) /* try to load local config file */ { dbg_val ("Load local config file \"%s\"\n", LOCALCONF_FILE); config = loadconfig (LOCALCONF_FILE, config); } setconfigpar (config, "Max_TTL", &maxttl); printconfigdiff (confname, refconfig, config); } } return 0; }
void gvinum_printconfig(int argc, char **argv) { printconfig(stdout, ""); }
void gvinum_create(int argc, char **argv) { struct gctl_req *req; struct gv_drive *d; struct gv_plex *p; struct gv_sd *s; struct gv_volume *v; FILE *tmp; int drives, errors, fd, flags, i, line, plexes, plex_in_volume; int sd_in_plex, status, subdisks, tokens, undeffd, volumes; const char *errstr; char buf[BUFSIZ], buf1[BUFSIZ], commandline[BUFSIZ], *ed, *sdname; char original[BUFSIZ], tmpfile[20], *token[GV_MAXARGS]; char plex[GV_MAXPLEXNAME], volume[GV_MAXVOLNAME]; tmp = NULL; flags = 0; for (i = 1; i < argc; i++) { /* Force flag used to ignore already created drives. */ if (!strcmp(argv[i], "-f")) { flags |= GV_FLAG_F; /* Else it must be a file. */ } else { if ((tmp = fopen(argv[1], "r")) == NULL) { warn("can't open '%s' for reading", argv[1]); return; } } } /* We didn't get a file. */ if (tmp == NULL) { snprintf(tmpfile, sizeof(tmpfile), "/tmp/gvinum.XXXXXX"); if ((fd = mkstemp(tmpfile)) == -1) { warn("temporary file not accessible"); return; } if ((tmp = fdopen(fd, "w")) == NULL) { warn("can't open '%s' for writing", tmpfile); return; } printconfig(tmp, "# "); fclose(tmp); ed = getenv("EDITOR"); if (ed == NULL) ed = _PATH_VI; snprintf(commandline, sizeof(commandline), "%s %s", ed, tmpfile); status = system(commandline); if (status != 0) { warn("couldn't exec %s; status: %d", ed, status); return; } if ((tmp = fopen(tmpfile, "r")) == NULL) { warn("can't open '%s' for reading", tmpfile); return; } } req = gctl_get_handle(); gctl_ro_param(req, "class", -1, "VINUM"); gctl_ro_param(req, "verb", -1, "create"); gctl_ro_param(req, "flags", sizeof(int), &flags); drives = volumes = plexes = subdisks = 0; plex_in_volume = sd_in_plex = undeffd = 0; plex[0] = '\0'; errors = 0; line = 1; while ((fgets(buf, BUFSIZ, tmp)) != NULL) { /* Skip empty lines and comments. */ if (*buf == '\0' || *buf == '#') { line++; continue; } /* Kill off the newline. */ buf[strlen(buf) - 1] = '\0'; /* * Copy the original input line in case we need it for error * output. */ strlcpy(original, buf, sizeof(original)); tokens = gv_tokenize(buf, token, GV_MAXARGS); if (tokens <= 0) { line++; continue; } /* Volume definition. */ if (!strcmp(token[0], "volume")) { v = gv_new_volume(tokens, token); if (v == NULL) { warnx("line %d: invalid volume definition", line); warnx("line %d: '%s'", line, original); errors++; line++; continue; } /* Reset plex count for this volume. */ plex_in_volume = 0; /* * Set default volume name for following plex * definitions. */ strlcpy(volume, v->name, sizeof(volume)); snprintf(buf1, sizeof(buf1), "volume%d", volumes); gctl_ro_param(req, buf1, sizeof(*v), v); volumes++; /* Plex definition. */ } else if (!strcmp(token[0], "plex")) { p = gv_new_plex(tokens, token); if (p == NULL) { warnx("line %d: invalid plex definition", line); warnx("line %d: '%s'", line, original); errors++; line++; continue; } /* Reset subdisk count for this plex. */ sd_in_plex = 0; /* Default name. */ if (strlen(p->name) == 0) { snprintf(p->name, sizeof(p->name), "%s.p%d", volume, plex_in_volume++); } /* Default volume. */ if (strlen(p->volume) == 0) { snprintf(p->volume, sizeof(p->volume), "%s", volume); } /* * Set default plex name for following subdisk * definitions. */ strlcpy(plex, p->name, sizeof(plex)); snprintf(buf1, sizeof(buf1), "plex%d", plexes); gctl_ro_param(req, buf1, sizeof(*p), p); plexes++; /* Subdisk definition. */ } else if (!strcmp(token[0], "sd")) { s = gv_new_sd(tokens, token); if (s == NULL) { warnx("line %d: invalid subdisk " "definition:", line); warnx("line %d: '%s'", line, original); errors++; line++; continue; } /* Default name. */ if (strlen(s->name) == 0) { if (strlen(plex) == 0) { sdname = find_name("gvinumsubdisk.p", GV_TYPE_SD, GV_MAXSDNAME); snprintf(s->name, sizeof(s->name), "%s.s%d", sdname, undeffd++); free(sdname); } else { snprintf(s->name, sizeof(s->name), "%s.s%d",plex, sd_in_plex++); } } /* Default plex. */ if (strlen(s->plex) == 0) snprintf(s->plex, sizeof(s->plex), "%s", plex); snprintf(buf1, sizeof(buf1), "sd%d", subdisks); gctl_ro_param(req, buf1, sizeof(*s), s); subdisks++; /* Subdisk definition. */ } else if (!strcmp(token[0], "drive")) { d = gv_new_drive(tokens, token); if (d == NULL) { warnx("line %d: invalid drive definition:", line); warnx("line %d: '%s'", line, original); errors++; line++; continue; } snprintf(buf1, sizeof(buf1), "drive%d", drives); gctl_ro_param(req, buf1, sizeof(*d), d); drives++; /* Everything else is bogus. */ } else { warnx("line %d: invalid definition:", line); warnx("line %d: '%s'", line, original); errors++; } line++; } fclose(tmp); unlink(tmpfile); if (!errors && (volumes || plexes || subdisks || drives)) { gctl_ro_param(req, "volumes", sizeof(int), &volumes); gctl_ro_param(req, "plexes", sizeof(int), &plexes); gctl_ro_param(req, "subdisks", sizeof(int), &subdisks); gctl_ro_param(req, "drives", sizeof(int), &drives); errstr = gctl_issue(req); if (errstr != NULL) warnx("create failed: %s", errstr); } gctl_free(req); }
static void gvinum_printconfig(int argc, char * const *argv) { printconfig(stdout, ""); }
int main(int argc, char *argv[]) { int c; char *buf; char *key, *value; int x,found; while((c = getopt(argc, argv, "fthc:vsd::C:S:")) != -1) { switch(c) { case 'c': filename=optarg; break; case 'h': usage(argv[0], 0); break; case '?': usage(argv[0], 1); break; case 'v': verbose++; break; case 'f': force++; break; case 't': fo_real = 0; break; case 's': stopmode = 1; break; case 'C': if (!chan_restrict(optarg)) usage(argv[0], 1); break; case 'S': if (!span_restrict(optarg)) usage(argv[0], 1); break; case 'd': if (optarg) debug = atoi(optarg); else debug = 1; break; } } if (verbose) { fprintf(stderr, "%s\n", dahdi_tools_version); } if (fd == -1) fd = open(MASTER_DEVICE, O_RDWR); if (fd < 0) { error("Unable to open master device '%s'\n", MASTER_DEVICE); goto finish; } cf = fopen(filename, "r"); if (cf) { while((buf = readline())) { if (*buf == 10) /* skip new line */ continue; if (debug & DEBUG_READER) fprintf(stderr, "Line %d: %s\n", lineno, buf); if ((value = strchr(buf, '='))) { *value++ = '\0'; value = trim(value); key = trim(buf); } if (!value || !*value || !*key) { error("Syntax error. Should be <keyword>=<value>\n"); continue; } if (debug & DEBUG_PARSER) fprintf(stderr, "Keyword: [%s], Value: [%s]\n", key, value); found = 0; for (x = 0; x < sizeof(handlers) / sizeof(handlers[0]); x++) { if (!strcasecmp(key, handlers[x].keyword)) { found++; handlers[x].func(key, value); break; } } if (!found) error("Unknown keyword '%s'\n", key); } if (debug & DEBUG_READER) fprintf(stderr, "<End of File>\n"); /* fclose(cf); // causes seg fault (double free) */ } else { error("Unable to open configuration file '%s'\n", filename); } finish: if (errcnt) { fprintf(stderr, "\n%d error(s) detected\n\n", errcnt); exit(1); } if (verbose) { printconfig(fd); } if (!fo_real) exit(0); if (debug & DEBUG_APPLY) { printf("About to open Master device\n"); fflush(stdout); } for (x=0;x<numdynamic;x++) { /* destroy them all */ ioctl(fd, DAHDI_DYNAMIC_DESTROY, &zds[x]); } if (stopmode) { for (x=0;x<spans;x++) { if (only_span && lc[x].span != only_span) continue; if (ioctl(fd, DAHDI_SHUTDOWN, &lc[x].span)) { fprintf(stderr, "DAHDI shutdown failed: %s\n", strerror(errno)); close(fd); exit(1); } } exit(1); } for (x=0;x<spans;x++) { if (only_span && lc[x].span != only_span) continue; if (ioctl(fd, DAHDI_SPANCONFIG, lc + x)) { fprintf(stderr, "DAHDI_SPANCONFIG failed on span %d: %s (%d)\n", lc[x].span, strerror(errno), errno); close(fd); exit(1); } } for (x=0;x<numdynamic;x++) { if (ioctl(fd, DAHDI_DYNAMIC_CREATE, &zds[x])) { fprintf(stderr, "DAHDI dynamic span creation failed: %s\n", strerror(errno)); close(fd); exit(1); } } for (x=1;x<DAHDI_MAX_CHANNELS;x++) { struct dahdi_params current_state; int master; int needupdate = force; if (skip_channel(x)) { if (debug & DEBUG_APPLY) { printf("Skip device %d\n", x); fflush(stdout); } continue; } if (debug & DEBUG_APPLY) { printf("Configuring device %d\n", x); fflush(stdout); } if (!cc[x].sigtype) continue; if (!needupdate) { memset(¤t_state, 0, sizeof(current_state)); current_state.channo = cc[x].chan | DAHDI_GET_PARAMS_RETURN_MASTER; if (ioctl(fd, DAHDI_GET_PARAMS, ¤t_state)) needupdate = 1; } if (!needupdate) { master = current_state.channo >> 16; if (cc[x].sigtype != current_state.sigtype) { needupdate++; if (verbose > 1) printf("Changing signalling on channel %d from %s to %s\n", cc[x].chan, sigtype_to_str(current_state.sigtype), sigtype_to_str(cc[x].sigtype)); } if ((cc[x].deflaw != DAHDI_LAW_DEFAULT) && (cc[x].deflaw != current_state.curlaw)) { needupdate++; if (verbose > 1) printf("Changing law on channel %d from %s to %s\n", cc[x].chan, laws[current_state.curlaw], laws[cc[x].deflaw]); } if (cc[x].master != master) { needupdate++; if (verbose > 1) printf("Changing master of channel %d from %d to %d\n", cc[x].chan, master, cc[x].master); } if (cc[x].idlebits != current_state.idlebits) { needupdate++; if (verbose > 1) printf("Changing idle bits of channel %d from %d to %d\n", cc[x].chan, current_state.idlebits, cc[x].idlebits); } } if (needupdate && ioctl(fd, DAHDI_CHANCONFIG, &cc[x])) { fprintf(stderr, "DAHDI_CHANCONFIG failed on channel %d: %s (%d)\n", x, strerror(errno), errno); if (errno == EINVAL) { /* give helpful suggestions on signaling errors */ fprintf(stderr, "Selected signaling not " "supported\n"); fprintf(stderr, "Possible causes:\n"); switch(cc[x].sigtype) { case DAHDI_SIG_FXOKS: case DAHDI_SIG_FXOLS: case DAHDI_SIG_FXOGS: fprintf(stderr, "\tFXO signaling is " "being used on a FXO interface" " (use a FXS signaling variant" ")\n"); fprintf(stderr, "\tRBS signaling is " "being used on a E1 CCS span" "\n"); break; case DAHDI_SIG_FXSKS: case DAHDI_SIG_FXSLS: case DAHDI_SIG_FXSGS: fprintf(stderr, "\tFXS signaling is " "being used on a FXS interface" " (use a FXO signaling variant" ")\n"); fprintf(stderr, "\tRBS signaling is " "being used on a E1 CCS span" "\n"); break; case DAHDI_SIG_EM: fprintf(stderr, "\te&m signaling is " "being used on a E1 line (use" " e&me1)\n"); break; case DAHDI_SIG_EM_E1: fprintf(stderr, "\te&me1 signaling is " "being used on a T1 line (use " "e&m)\n"); fprintf(stderr, "\tRBS signaling is " "being used on a E1 CCS span" "\n"); break; case DAHDI_SIG_HARDHDLC: fprintf(stderr, "\thardhdlc is being " "used on a TE12x (use dchan)\n" ); break; case DAHDI_SIG_HDLCFCS: fprintf(stderr, "\tdchan is being used" " on a BRI span (use hardhdlc)" "\n"); break; default: break; } fprintf(stderr, "\tSignaling is being assigned" " to channel 16 of an E1 CAS span\n"); } close(fd); exit(1); } ae[x].chan = x; if (verbose) { printf("Setting echocan for channel %d to %s\n", ae[x].chan, ae[x].echocan[0] ? ae[x].echocan : "none"); } if (ioctl(fd, DAHDI_ATTACH_ECHOCAN, &ae[x])) { fprintf(stderr, "DAHDI_ATTACH_ECHOCAN failed on channel %d: %s (%d)\n", x, strerror(errno), errno); close(fd); exit(1); } }