int main(int argc, char *argv[]) { bool encrypt = true; const char* dir = "."; #define ARGCMP(y) (strcmp(argv[1], y) == 0) if (argc > 1) { if (ARGCMP("encrypt") || ARGCMP("-e") ) { if (argc > 2) dir = argv[2]; encrypt = true; } else if (ARGCMP("decrypt") || ARGCMP("-d")) { if (argc > 2) dir = argv[2]; encrypt = false; } else if(ARGCMP("--help") || ARGCMP("-h") || ARGCMP("-?") || ARGCMP("/?")) { print_help(); return 0; } else if (ARGCMP("-v") || ARGCMP("--version")) { print_version(); return 0; } } #undef ARGCMP EncryptFiles(dir, "*.age", encrypt); EncryptFiles(dir, "*.fni", encrypt); EncryptFiles(dir, "*.ini", encrypt); EncryptFiles(dir, "*.sdl", encrypt); EncryptFiles(dir, "*.csv", encrypt); return 0; }
int main(int argc, char **argv) { int i; int showHelp = FALSE; int invertMatch = FALSE; int lineNumber = FALSE; int quiet = FALSE; const char *pattern = argv[argc-1]; for(i = 1; i < argc - 1; i++) { #define ARGCMP(S) (strcmp(argv[i], S) == 0) if (ARGCMP("--help")) showHelp = TRUE; else if (ARGCMP("--invert-match")) invertMatch = TRUE; else if (ARGCMP("-v")) invertMatch = TRUE; else if (ARGCMP("--line-number")) lineNumber = TRUE; else if (ARGCMP("--quiet")) quiet = TRUE; else if (ARGCMP("-n")) lineNumber = TRUE; else if (ARGCMP("-q")) quiet = TRUE; else {fprintf(stderr, "error!\n"); return ERROR;} #undef ARGCMP } if (showHelp || strcmp(pattern, "--help") == 0) { printHelp(); return EXIT_SUCCESS; } if (argc == 1) {fprintf(stderr, "error!\n"); return ERROR;} char buffer [BUFFER_SIZE]; int found = FALSE; int currLine = 0; while (fgets(buffer, BUFFER_SIZE, stdin) != NULL) { currLine++; int matches = strstr(buffer, pattern) != NULL; if ((matches && !invertMatch) || (!matches && invertMatch)) { found = TRUE; if (!quiet) { if (lineNumber) printf("%d:", currLine); printf("%s", buffer); } } } return found ? 0 : 1; }
int main(int argc, char *argv[]) { char *socketpath = "socket_arduino"; char *pendulumdatapath = "data_pendulum"; char *normalisationdatapath = "data_normalisation"; int whitebg = 0; int maxframerate = 80; for (int i = 1; i < argc; i++) { if (argcmpass("--pendulum|-p", argc, argv, &i, &pendulumdatapath)) ; else if (argcmpass("--normalisation|-n", argc, argv, &i, &normalisationdatapath)) ; else if (argcmpass("--inputsocket|-i", argc, argv, &i, &socketpath)) ; else if (argcmpassint("--maxframerate|-f", argc, argv, &i, &maxframerate)) ; else if ARGCMP("--whitebg", i) whitebg = 1; else fprintf(stderr, "warning: Unknown argument ignored: \"%s\"\n", argv[i]); }
/*% main processing routine */ int main(int argc, char **argv) { int c; char *origin = NULL; char *filename = NULL; isc_log_t *lctx = NULL; isc_result_t result; char classname_in[] = "IN"; char *classname = classname_in; const char *workdir = NULL; const char *inputformatstr = NULL; const char *outputformatstr = NULL; dns_masterformat_t inputformat = dns_masterformat_text; dns_masterformat_t outputformat = dns_masterformat_text; outputstyle = &dns_master_style_full; prog_name = strrchr(argv[0], '/'); if (prog_name == NULL) prog_name = strrchr(argv[0], '\\'); if (prog_name != NULL) prog_name++; else prog_name = argv[0]; /* * Libtool doesn't preserve the program name prior to final * installation. Remove the libtool prefix ("lt-"). */ if (strncmp(prog_name, "lt-", 3) == 0) prog_name += 3; if (strcmp(prog_name, "named-checkzone") == 0) progmode = progmode_check; else if (strcmp(prog_name, "named-compilezone") == 0) progmode = progmode_compile; else INSIST(0); /* Compilation specific defaults */ if (progmode == progmode_compile) { zone_options |= (DNS_ZONEOPT_CHECKNS | DNS_ZONEOPT_FATALNS | DNS_ZONEOPT_CHECKNAMES | DNS_ZONEOPT_CHECKNAMESFAIL | DNS_ZONEOPT_CHECKWILDCARD); } #define ARGCMP(X) (strcmp(isc_commandline_argument, X) == 0) while ((c = isc_commandline_parse(argc, argv, "c:df:i:jk:m:n:qs:t:o:vw:DF:M:S:W:")) != EOF) { switch (c) { case 'c': classname = isc_commandline_argument; break; case 'd': debug++; break; case 'i': if (ARGCMP("full")) { zone_options |= DNS_ZONEOPT_CHECKINTEGRITY | DNS_ZONEOPT_CHECKSIBLING; docheckmx = ISC_TRUE; docheckns = ISC_TRUE; dochecksrv = ISC_TRUE; } else if (ARGCMP("full-sibling")) { zone_options |= DNS_ZONEOPT_CHECKINTEGRITY; zone_options &= ~DNS_ZONEOPT_CHECKSIBLING; docheckmx = ISC_TRUE; docheckns = ISC_TRUE; dochecksrv = ISC_TRUE; } else if (ARGCMP("local")) { zone_options |= DNS_ZONEOPT_CHECKINTEGRITY; zone_options |= DNS_ZONEOPT_CHECKSIBLING; docheckmx = ISC_FALSE; docheckns = ISC_FALSE; dochecksrv = ISC_FALSE; } else if (ARGCMP("local-sibling")) { zone_options |= DNS_ZONEOPT_CHECKINTEGRITY; zone_options &= ~DNS_ZONEOPT_CHECKSIBLING; docheckmx = ISC_FALSE; docheckns = ISC_FALSE; dochecksrv = ISC_FALSE; } else if (ARGCMP("none")) { zone_options &= ~DNS_ZONEOPT_CHECKINTEGRITY; zone_options &= ~DNS_ZONEOPT_CHECKSIBLING; docheckmx = ISC_FALSE; docheckns = ISC_FALSE; dochecksrv = ISC_FALSE; } else { fprintf(stderr, "invalid argument to -i: %s\n", isc_commandline_argument); exit(1); } break; case 'f': inputformatstr = isc_commandline_argument; break; case 'F': outputformatstr = isc_commandline_argument; break; case 'j': nomerge = ISC_FALSE; break; case 'k': if (ARGCMP("warn")) { zone_options |= DNS_ZONEOPT_CHECKNAMES; zone_options &= ~DNS_ZONEOPT_CHECKNAMESFAIL; } else if (ARGCMP("fail")) { zone_options |= DNS_ZONEOPT_CHECKNAMES | DNS_ZONEOPT_CHECKNAMESFAIL; } else if (ARGCMP("ignore")) { zone_options &= ~(DNS_ZONEOPT_CHECKNAMES | DNS_ZONEOPT_CHECKNAMESFAIL); } else { fprintf(stderr, "invalid argument to -k: %s\n", isc_commandline_argument); exit(1); } break; case 'n': if (ARGCMP("ignore")) { zone_options &= ~(DNS_ZONEOPT_CHECKNS| DNS_ZONEOPT_FATALNS); } else if (ARGCMP("warn")) { zone_options |= DNS_ZONEOPT_CHECKNS; zone_options &= ~DNS_ZONEOPT_FATALNS; } else if (ARGCMP("fail")) { zone_options |= DNS_ZONEOPT_CHECKNS| DNS_ZONEOPT_FATALNS; } else { fprintf(stderr, "invalid argument to -n: %s\n", isc_commandline_argument); exit(1); } break; case 'm': if (ARGCMP("warn")) { zone_options |= DNS_ZONEOPT_CHECKMX; zone_options &= ~DNS_ZONEOPT_CHECKMXFAIL; } else if (ARGCMP("fail")) { zone_options |= DNS_ZONEOPT_CHECKMX | DNS_ZONEOPT_CHECKMXFAIL; } else if (ARGCMP("ignore")) { zone_options &= ~(DNS_ZONEOPT_CHECKMX | DNS_ZONEOPT_CHECKMXFAIL); } else { fprintf(stderr, "invalid argument to -m: %s\n", isc_commandline_argument); exit(1); } break; case 'q': quiet++; break; case 't': result = isc_dir_chroot(isc_commandline_argument); if (result != ISC_R_SUCCESS) { fprintf(stderr, "isc_dir_chroot: %s: %s\n", isc_commandline_argument, isc_result_totext(result)); exit(1); } result = isc_dir_chdir("/"); if (result != ISC_R_SUCCESS) { fprintf(stderr, "isc_dir_chdir: %s\n", isc_result_totext(result)); exit(1); } break; case 's': if (ARGCMP("full")) outputstyle = &dns_master_style_full; else if (ARGCMP("relative")) { outputstyle = &dns_master_style_default; } else { fprintf(stderr, "unknown or unsupported style: %s\n", isc_commandline_argument); exit(1); } break; case 'o': output_filename = isc_commandline_argument; break; case 'v': printf(VERSION "\n"); exit(0); case 'w': workdir = isc_commandline_argument; break; case 'D': dumpzone++; break; case 'M': if (ARGCMP("fail")) { zone_options &= ~DNS_ZONEOPT_WARNMXCNAME; zone_options &= ~DNS_ZONEOPT_IGNOREMXCNAME; } else if (ARGCMP("warn")) { zone_options |= DNS_ZONEOPT_WARNMXCNAME; zone_options &= ~DNS_ZONEOPT_IGNOREMXCNAME; } else if (ARGCMP("ignore")) { zone_options |= DNS_ZONEOPT_WARNMXCNAME; zone_options |= DNS_ZONEOPT_IGNOREMXCNAME; } else { fprintf(stderr, "invalid argument to -M: %s\n", isc_commandline_argument); exit(1); } break; case 'S': if (ARGCMP("fail")) { zone_options &= ~DNS_ZONEOPT_WARNSRVCNAME; zone_options &= ~DNS_ZONEOPT_IGNORESRVCNAME; } else if (ARGCMP("warn")) { zone_options |= DNS_ZONEOPT_WARNSRVCNAME; zone_options &= ~DNS_ZONEOPT_IGNORESRVCNAME; } else if (ARGCMP("ignore")) { zone_options |= DNS_ZONEOPT_WARNSRVCNAME; zone_options |= DNS_ZONEOPT_IGNORESRVCNAME; } else { fprintf(stderr, "invalid argument to -S: %s\n", isc_commandline_argument); exit(1); } break; case 'W': if (ARGCMP("warn")) zone_options |= DNS_ZONEOPT_CHECKWILDCARD; else if (ARGCMP("ignore")) zone_options &= ~DNS_ZONEOPT_CHECKWILDCARD; break; default: usage(); } } if (progmode == progmode_compile) { dumpzone = 1; /* always dump */ if (output_filename == NULL) { fprintf(stderr, "output file required, but not specified\n"); usage(); } } if (workdir != NULL) { result = isc_dir_chdir(workdir); if (result != ISC_R_SUCCESS) { fprintf(stderr, "isc_dir_chdir: %s: %s\n", workdir, isc_result_totext(result)); exit(1); } } if (inputformatstr != NULL) { if (strcasecmp(inputformatstr, "text") == 0) inputformat = dns_masterformat_text; else if (strcasecmp(inputformatstr, "raw") == 0) inputformat = dns_masterformat_raw; else { fprintf(stderr, "unknown file format: %s\n", inputformatstr); exit(1); } } if (outputformatstr != NULL) { if (strcasecmp(outputformatstr, "text") == 0) outputformat = dns_masterformat_text; else if (strcasecmp(outputformatstr, "raw") == 0) outputformat = dns_masterformat_raw; else { fprintf(stderr, "unknown file format: %s\n", outputformatstr); exit(1); } } if (isc_commandline_index + 2 > argc) usage(); RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); if (!quiet) RUNTIME_CHECK(setup_logging(mctx, &lctx) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_entropy_create(mctx, &ectx) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE) == ISC_R_SUCCESS); dns_result_register(); origin = argv[isc_commandline_index++]; filename = argv[isc_commandline_index++]; result = load_zone(mctx, origin, filename, inputformat, classname, &zone); if (result == ISC_R_SUCCESS && dumpzone) { if (!quiet && progmode == progmode_compile) { fprintf(stdout, "dump zone to %s...", output_filename); fflush(stdout); } result = dump_zone(origin, zone, output_filename, outputformat, outputstyle); if (!quiet && progmode == progmode_compile) fprintf(stdout, "done\n"); } if (!quiet && result == ISC_R_SUCCESS) fprintf(stdout, "OK\n"); destroy(); if (lctx != NULL) isc_log_destroy(&lctx); isc_hash_destroy(); isc_entropy_detach(&ectx); isc_mem_destroy(&mctx); return ((result == ISC_R_SUCCESS) ? 0 : 1); }
int main(int argc, char *argv[]) { char *pendulumdatapath = "data_pendulum"; char *dumppath = NULL; for (int i = 1; i < argc; i++) { if (argcmpass("--pendulum|-p", argc, argv, &i, &pendulumdatapath)) ; else if (argcmpass("--datafilepath|-d", argc, argv, &i, &datafilepath)) ; else if (argcmpass("--dump|-D", argc, argv, &i, &dumppath)) ; else if (ARGCMP("--whitebg", i)) { whitebg = 1; } else if (ARGCMP("--no-show-normal-lines", i)) show_normal_lines = false; else if (argcmpassdouble("--l1", argc, argv, &i, &l1)) ; else if (argcmpassdouble("--l2b", argc, argv, &i, &l2b)) ; else fprintf(stderr, "warning: Unknown argument ignored: \"%s\"\n", argv[i]); } if (l1 <= 0 || l2b <= 0) { fprintf(stderr, "l1 and l2b must be >0\n"); exit(1); } // x11 things sf = createSHMSurface(100, 100, 500, 500); int in_fd = -1; if (dumppath == NULL) { in_fd = inotify_init(); if (in_fd == -1) { fprintf(stderr, "can't create inotify fd: %s\n", strerror(errno)); exit(1); } int in_watch = inotify_add_watch(in_fd, datafilepath, IN_CLOSE_WRITE); if (in_watch == -1) { fprintf(stderr, "can't create inotify watch: %s\n", strerror(errno)); exit(1); } } run(); if (dumppath != NULL) { int fd = open(dumppath, O_WRONLY|O_CREAT|O_TRUNC, 0777); if (fd == -1) { fprintf(stderr, "can't open \"%s\" for writing: %s\n", dumppath, strerror(errno)); exit(1); } dump_ppm(fd, sf); close(fd); return 0; } while (1) { size_t evt_size = sizeof(struct inotify_event)+NAME_MAX+1; struct inotify_event *evt = alloca(evt_size); int readres = read(in_fd, evt, evt_size); if (readres == 0) { fprintf(stderr, "inotify EOF\n"); exit(1); } if (readres == -1) { fprintf(stderr, "inotify read error: %s\n", strerror(errno)); exit(1); } // we ignore the actual inotify event – there's only one thing it could // plausibly be, and if we're wrong, we just run one more iteration run(); } }
int main(int argc, char *argv[], char *envp[]) { size_t i; u_int flags; const char *libc, *libthr, *icc_localbase; struct arglist al = { 0, NULL }; flags = 0; if (argc == 1) errx(1, "no input files"); if ((icc_localbase = getenv("ICC_LOCALBASE")) == NULL) errx(1, "can't get ICC_LOCALBASE"); #ifdef DEBUG printf("input: "); #endif #define ARGCMP(i, x) !strcmp(argv[i], (x)) /* * XXX This doesn't deal with whitespace but a) the output of the * compiler should be fixed and b) the real linker is also picky * about whitespace. */ for (i = 0; i < argc; i++) { #ifdef DEBUG printf("%s ", argv[i]); #endif if (ARGCMP(i, "-CPLUSPLUS")) { flags |= LDW_CXXICC; continue; } if (ARGCMP(i, "-MT")) { flags |= LDW_THR; continue; } if (ARGCMP(i, "-PIC")) { flags |= LDW_PIC; continue; } /* * Check if the compiler wants us to do dynamic linking, i.e. * the compiler was called with -shared or without -static. * If the compiler was called with -static we shouldn't see * "--dynamic-linker" here. * Note: According to ld(1) this is "--dynamic-linker" but * ICC passes "-dynamic-linker" to it. */ if (ARGCMP(i, "--dynamic-linker") || ARGCMP(i, "-dynamic-linker") || ARGCMP(i, "-shared")) { flags |= LDW_DYN; continue; } /* * The STLport library just can be linked once otherwise * we get problems with constructors and destructors of * global instances. */ if (!strncmp(argv[i], "-lstlport_icc", sizeof("-lstlport_icc") - 1)) { flags |= LDW_STLP; continue; } /* * Link against libc_p when "-qp" or "-p" were given, * "/usr/lib/gcrt1.o" indicates this. */ if (ARGCMP(i, "/usr/lib/gcrt1.o")) { flags |= LDW_GPROF; continue; } } /* * Allow the user to specify an alternative threads library * implementation, such as -lthr, or whatever. */ #if __FreeBSD_version >= 500016 if ((libthr = getenv("PTHREAD_LIBS")) == NULL) #if __FreeBSD_version >= 502102 libthr = "-lpthread"; #else libthr = "-lc_r"; #endif #else libthr = "-lc_r"; #endif /* * Use the appropriate libs for libc and libthr when linking static * and "-KPIC" or "-pg" where given. */ if (!(flags & LDW_DYN) && flags & (LDW_PIC | LDW_GPROF)) { /* * Let libc_p win above libc_pic when both, "-KPIC" and "-pg", * where given, GCC does the same. */ if (!(flags & LDW_GPROF)) libc = "-lc_pic"; else { char *p; libc = "-lc_p"; asprintf(&p, "%s_p", libthr); if (p == NULL) err(1, NULL); libthr = p; } } else libc = "-lc"; #ifdef DEBUG printf("\n"); #endif for (i = 0; i < argc; i++) { if (ARGCMP(i, "-CPLUSPLUS") || ARGCMP(i, "-MT") || ARGCMP(i, "-PIC")) continue; /* * Prepend "-melf_i386" and "-melf_i386_fbsd" respectively * to the commandline. */ if (i == 0) { addarg(&al, argv[0]); #if __FreeBSD_version < 500042 addarg(&al, "-melf_i386"); #else addarg(&al, "-melf_i386_fbsd"); #endif continue; } /* * Don't add "-m elf_i386" ICC passed to us. Don't add * libgcc_eh, libgcc_s or libgcc_s_32, libdl. */ if ((ARGCMP(i, "-m") && i < argc - 1 && ARGCMP(i + 1, "elf_i386")) || (ARGCMP(i, "elf_i386") && i != 0 && ARGCMP(i - 1, "-m")) || ARGCMP(i, "-lgcc_eh") || ARGCMP(i, "-lgcc_s") || ARGCMP(i, "-lgcc_s_32") || ARGCMP(i, "-ldl")) continue; /* * Replace libcprts with libstlport_icc. The Dinkumware STL * shipping with ICC has unresolvable glibc dependencies * in both, the static and the dynamic, versions. */ if (ARGCMP(i, "-lcprts")) { if (flags & LDW_CXXICC && !(flags & LDW_STLP)) { char *p; asprintf(&p, "-L%s/lib", icc_localbase); if (p == NULL) err(1, NULL); addarg(&al, p); addarg(&al, flags & LDW_DYN ? "-Bdynamic" : "-Bstatic"); addarg(&al, "-lstlport_icc"); } continue; } /* * Inject the compatibility library for ICC libs on FreeBSD. * Link against libthr when compiling multi-threaded or C++ * code and not using libstdc++ (libcxa and libunwind depend * on a threads library). */ if (ARGCMP(i, "-lc")) { addarg(&al, "-Bstatic"); addarg(&al, "-liccfbsd"); addarg(&al, flags & LDW_DYN ? "-Bdynamic" : "-Bstatic"); if (flags & (LDW_CXXICC | LDW_THR)) { addarg(&al, libthr); #if __FreeBSD_version >= 500016 addarg(&al, flags & LDW_DYN ? "-Bdynamic" : "-Bstatic"); addarg(&al, libc); #endif } else addarg(&al, libc); continue; } /* Switch Linux stuff to FreeBSD counterparts. */ if (ARGCMP(i, "/lib/ld-linux.so.2")) { #if __FreeBSD_version >= 501105 addarg(&al, "/libexec/ld-elf.so.1"); #else addarg(&al, "/usr/libexec/ld-elf.so.1"); #endif continue; } if (ARGCMP(i, "-L/usr/lib")) { addarg(&al, "-L/usr/libexec/elf"); addarg(&al, "-L/usr/libexec"); addarg(&al, "-L/usr/lib"); continue; } /* * Force libcxa, libcxaguard, libimf, libsvml and libunwind * to static linkage, since the dynamic versions have glibc * dependencies. */ if (ARGCMP(i, "-Bdynamic") && i < argc - 1 && (ARGCMP(i + 1, "-lcxa") || ARGCMP(i + 1, "-lcxaguard") || ARGCMP(i + 1, "-limf") || ARGCMP(i + 1, "-lsvml") || ARGCMP(i + 1, "-lunwind"))) { addarg(&al, "-Bstatic"); continue; } /* * Sanity check if every lib is prepended by a linkage option, * add if missing. */ if (!strncmp(argv[i], "-l", 2) && ((i != 0 && strncmp(argv[i - 1], "-B", 2)) || (al.argc > 0 && strncmp(al.argv[al.argc - 1], "-B", 2)))) { if (ARGCMP(i, "-lcxa") || ARGCMP(i, "-lcxaguard") || ARGCMP(i, "-limf") || ARGCMP(i, "-lirc") || ARGCMP(i, "-lirc_s") || ARGCMP(i, "-lsvml") || ARGCMP(i, "-lunwind")) addarg(&al, "-Bstatic"); else addarg(&al, flags & LDW_DYN ? "-Bdynamic" : "-Bstatic"); addarg(&al, argv[i]); continue; } /* default */ addarg(&al, argv[i]); } /* Still something to do? */ if (al.argc == 1) errx(1, "no input files"); #ifdef DEBUG printf("output: "); for (i = 0; i < al.argc; i++) printf("%s ", al.argv[i]); printf("\n"); #endif addarg(&al, NULL); /* Launch the real linker. */ if (execve(PATH_LD, (char **)al.argv, envp) == -1) err(1, "execing " PATH_LD); exit (1); }
/*% main processing routine */ int main(int argc, char **argv) { int c; char *origin = NULL; char *filename = NULL; isc_log_t *lctx = NULL; isc_result_t result; char classname_in[] = "IN"; char *classname = classname_in; const char *workdir = NULL; const char *inputformatstr = NULL; const char *outputformatstr = NULL; dns_masterformat_t inputformat = dns_masterformat_text; dns_masterformat_t outputformat = dns_masterformat_text; dns_masterrawheader_t header; isc_uint32_t rawversion = 1, serialnum = 0; isc_boolean_t snset = ISC_FALSE; isc_boolean_t logdump = ISC_FALSE; FILE *errout = stdout; char *endp; outputstyle = &dns_master_style_full; prog_name = strrchr(argv[0], '/'); if (prog_name == NULL) prog_name = strrchr(argv[0], '\\'); if (prog_name != NULL) prog_name++; else prog_name = argv[0]; /* * Libtool doesn't preserve the program name prior to final * installation. Remove the libtool prefix ("lt-"). */ if (strncmp(prog_name, "lt-", 3) == 0) prog_name += 3; #define PROGCMP(X) \ (strcasecmp(prog_name, X) == 0 || strcasecmp(prog_name, X ".exe") == 0) if (PROGCMP("named-checkzone")) progmode = progmode_check; else if (PROGCMP("named-compilezone")) progmode = progmode_compile; else INSIST(0); /* Compilation specific defaults */ if (progmode == progmode_compile) { zone_options |= (DNS_ZONEOPT_CHECKNS | DNS_ZONEOPT_FATALNS | DNS_ZONEOPT_CHECKSPF | DNS_ZONEOPT_CHECKDUPRR | DNS_ZONEOPT_CHECKNAMES | DNS_ZONEOPT_CHECKNAMESFAIL | DNS_ZONEOPT_CHECKWILDCARD); } else zone_options |= (DNS_ZONEOPT_CHECKDUPRR | DNS_ZONEOPT_CHECKSPF); #define ARGCMP(X) (strcmp(isc_commandline_argument, X) == 0) isc_commandline_errprint = ISC_FALSE; while ((c = isc_commandline_parse(argc, argv, "c:df:hi:jk:L:m:n:qr:s:t:o:vw:DF:M:S:T:W:")) != EOF) { switch (c) { case 'c': classname = isc_commandline_argument; break; case 'd': debug++; break; case 'i': if (ARGCMP("full")) { zone_options |= DNS_ZONEOPT_CHECKINTEGRITY | DNS_ZONEOPT_CHECKSIBLING; docheckmx = ISC_TRUE; docheckns = ISC_TRUE; dochecksrv = ISC_TRUE; } else if (ARGCMP("full-sibling")) { zone_options |= DNS_ZONEOPT_CHECKINTEGRITY; zone_options &= ~DNS_ZONEOPT_CHECKSIBLING; docheckmx = ISC_TRUE; docheckns = ISC_TRUE; dochecksrv = ISC_TRUE; } else if (ARGCMP("local")) { zone_options |= DNS_ZONEOPT_CHECKINTEGRITY; zone_options |= DNS_ZONEOPT_CHECKSIBLING; docheckmx = ISC_FALSE; docheckns = ISC_FALSE; dochecksrv = ISC_FALSE; } else if (ARGCMP("local-sibling")) { zone_options |= DNS_ZONEOPT_CHECKINTEGRITY; zone_options &= ~DNS_ZONEOPT_CHECKSIBLING; docheckmx = ISC_FALSE; docheckns = ISC_FALSE; dochecksrv = ISC_FALSE; } else if (ARGCMP("none")) { zone_options &= ~DNS_ZONEOPT_CHECKINTEGRITY; zone_options &= ~DNS_ZONEOPT_CHECKSIBLING; docheckmx = ISC_FALSE; docheckns = ISC_FALSE; dochecksrv = ISC_FALSE; } else { fprintf(stderr, "invalid argument to -i: %s\n", isc_commandline_argument); exit(1); } break; case 'f': inputformatstr = isc_commandline_argument; break; case 'F': outputformatstr = isc_commandline_argument; break; case 'j': nomerge = ISC_FALSE; break; case 'k': if (ARGCMP("warn")) { zone_options |= DNS_ZONEOPT_CHECKNAMES; zone_options &= ~DNS_ZONEOPT_CHECKNAMESFAIL; } else if (ARGCMP("fail")) { zone_options |= DNS_ZONEOPT_CHECKNAMES | DNS_ZONEOPT_CHECKNAMESFAIL; } else if (ARGCMP("ignore")) { zone_options &= ~(DNS_ZONEOPT_CHECKNAMES | DNS_ZONEOPT_CHECKNAMESFAIL); } else { fprintf(stderr, "invalid argument to -k: %s\n", isc_commandline_argument); exit(1); } break; case 'L': snset = ISC_TRUE; endp = NULL; serialnum = strtol(isc_commandline_argument, &endp, 0); if (*endp != '\0') { fprintf(stderr, "source serial number " "must be numeric"); exit(1); } break; case 'n': if (ARGCMP("ignore")) { zone_options &= ~(DNS_ZONEOPT_CHECKNS| DNS_ZONEOPT_FATALNS); } else if (ARGCMP("warn")) { zone_options |= DNS_ZONEOPT_CHECKNS; zone_options &= ~DNS_ZONEOPT_FATALNS; } else if (ARGCMP("fail")) { zone_options |= DNS_ZONEOPT_CHECKNS| DNS_ZONEOPT_FATALNS; } else { fprintf(stderr, "invalid argument to -n: %s\n", isc_commandline_argument); exit(1); } break; case 'm': if (ARGCMP("warn")) { zone_options |= DNS_ZONEOPT_CHECKMX; zone_options &= ~DNS_ZONEOPT_CHECKMXFAIL; } else if (ARGCMP("fail")) { zone_options |= DNS_ZONEOPT_CHECKMX | DNS_ZONEOPT_CHECKMXFAIL; } else if (ARGCMP("ignore")) { zone_options &= ~(DNS_ZONEOPT_CHECKMX | DNS_ZONEOPT_CHECKMXFAIL); } else { fprintf(stderr, "invalid argument to -m: %s\n", isc_commandline_argument); exit(1); } break; case 'o': output_filename = isc_commandline_argument; break; case 'q': quiet++; break; case 'r': if (ARGCMP("warn")) { zone_options |= DNS_ZONEOPT_CHECKDUPRR; zone_options &= ~DNS_ZONEOPT_CHECKDUPRRFAIL; } else if (ARGCMP("fail")) { zone_options |= DNS_ZONEOPT_CHECKDUPRR | DNS_ZONEOPT_CHECKDUPRRFAIL; } else if (ARGCMP("ignore")) { zone_options &= ~(DNS_ZONEOPT_CHECKDUPRR | DNS_ZONEOPT_CHECKDUPRRFAIL); } else { fprintf(stderr, "invalid argument to -r: %s\n", isc_commandline_argument); exit(1); } break; case 's': if (ARGCMP("full")) outputstyle = &dns_master_style_full; else if (ARGCMP("relative")) { outputstyle = &dns_master_style_default; } else { fprintf(stderr, "unknown or unsupported style: %s\n", isc_commandline_argument); exit(1); } break; case 't': result = isc_dir_chroot(isc_commandline_argument); if (result != ISC_R_SUCCESS) { fprintf(stderr, "isc_dir_chroot: %s: %s\n", isc_commandline_argument, isc_result_totext(result)); exit(1); } break; case 'v': printf(VERSION "\n"); exit(0); case 'w': workdir = isc_commandline_argument; break; case 'D': dumpzone++; break; case 'M': if (ARGCMP("fail")) { zone_options &= ~DNS_ZONEOPT_WARNMXCNAME; zone_options &= ~DNS_ZONEOPT_IGNOREMXCNAME; } else if (ARGCMP("warn")) { zone_options |= DNS_ZONEOPT_WARNMXCNAME; zone_options &= ~DNS_ZONEOPT_IGNOREMXCNAME; } else if (ARGCMP("ignore")) { zone_options |= DNS_ZONEOPT_WARNMXCNAME; zone_options |= DNS_ZONEOPT_IGNOREMXCNAME; } else { fprintf(stderr, "invalid argument to -M: %s\n", isc_commandline_argument); exit(1); } break; case 'S': if (ARGCMP("fail")) { zone_options &= ~DNS_ZONEOPT_WARNSRVCNAME; zone_options &= ~DNS_ZONEOPT_IGNORESRVCNAME; } else if (ARGCMP("warn")) { zone_options |= DNS_ZONEOPT_WARNSRVCNAME; zone_options &= ~DNS_ZONEOPT_IGNORESRVCNAME; } else if (ARGCMP("ignore")) { zone_options |= DNS_ZONEOPT_WARNSRVCNAME; zone_options |= DNS_ZONEOPT_IGNORESRVCNAME; } else { fprintf(stderr, "invalid argument to -S: %s\n", isc_commandline_argument); exit(1); } break; case 'T': if (ARGCMP("warn")) { zone_options |= DNS_ZONEOPT_CHECKSPF; } else if (ARGCMP("ignore")) { zone_options &= ~DNS_ZONEOPT_CHECKSPF; } else { fprintf(stderr, "invalid argument to -T: %s\n", isc_commandline_argument); exit(1); } break; case 'W': if (ARGCMP("warn")) zone_options |= DNS_ZONEOPT_CHECKWILDCARD; else if (ARGCMP("ignore")) zone_options &= ~DNS_ZONEOPT_CHECKWILDCARD; break; case '?': if (isc_commandline_option != '?') fprintf(stderr, "%s: invalid argument -%c\n", prog_name, isc_commandline_option); /* FALLTHROUGH */ case 'h': usage(); default: fprintf(stderr, "%s: unhandled option -%c\n", prog_name, isc_commandline_option); exit(1); } } if (workdir != NULL) { result = isc_dir_chdir(workdir); if (result != ISC_R_SUCCESS) { fprintf(stderr, "isc_dir_chdir: %s: %s\n", workdir, isc_result_totext(result)); exit(1); } } if (inputformatstr != NULL) { if (strcasecmp(inputformatstr, "text") == 0) inputformat = dns_masterformat_text; else if (strcasecmp(inputformatstr, "raw") == 0) inputformat = dns_masterformat_raw; else if (strncasecmp(inputformatstr, "raw=", 4) == 0) { inputformat = dns_masterformat_raw; fprintf(stderr, "WARNING: input format raw, version ignored\n"); } else { fprintf(stderr, "unknown file format: %s\n", inputformatstr); exit(1); } } if (outputformatstr != NULL) { if (strcasecmp(outputformatstr, "text") == 0) { outputformat = dns_masterformat_text; } else if (strcasecmp(outputformatstr, "raw") == 0) { outputformat = dns_masterformat_raw; } else if (strncasecmp(outputformatstr, "raw=", 4) == 0) { char *end; outputformat = dns_masterformat_raw; rawversion = strtol(outputformatstr + 4, &end, 10); if (end == outputformatstr + 4 || *end != '\0' || rawversion > 1U) { fprintf(stderr, "unknown raw format version\n"); exit(1); } } else { fprintf(stderr, "unknown file format: %s\n", outputformatstr); exit(1); } } if (progmode == progmode_compile) { dumpzone = 1; /* always dump */ logdump = !quiet; if (output_filename == NULL) { fprintf(stderr, "output file required, but not specified\n"); usage(); } } if (output_filename != NULL) dumpzone = 1; /* * If we are outputing to stdout then send the informational * output to stderr. */ if (dumpzone && (output_filename == NULL || strcmp(output_filename, "-") == 0 || strcmp(output_filename, "/dev/fd/1") == 0 || strcmp(output_filename, "/dev/stdout") == 0)) { errout = stderr; logdump = ISC_FALSE; } if (isc_commandline_index + 2 != argc) usage(); #ifdef _WIN32 InitSockets(); #endif RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS); if (!quiet) RUNTIME_CHECK(setup_logging(mctx, errout, &lctx) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_entropy_create(mctx, &ectx) == ISC_R_SUCCESS); RUNTIME_CHECK(isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE) == ISC_R_SUCCESS); dns_result_register(); origin = argv[isc_commandline_index++]; filename = argv[isc_commandline_index++]; result = load_zone(mctx, origin, filename, inputformat, classname, &zone); if (snset) { dns_master_initrawheader(&header); header.flags = DNS_MASTERRAW_SOURCESERIALSET; header.sourceserial = serialnum; dns_zone_setrawdata(zone, &header); } if (result == ISC_R_SUCCESS && dumpzone) { if (logdump) { fprintf(errout, "dump zone to %s...", output_filename); fflush(errout); } result = dump_zone(origin, zone, output_filename, outputformat, outputstyle, rawversion); if (logdump) fprintf(errout, "done\n"); } if (!quiet && result == ISC_R_SUCCESS) fprintf(errout, "OK\n"); destroy(); if (lctx != NULL) isc_log_destroy(&lctx); isc_hash_destroy(); isc_entropy_detach(&ectx); isc_mem_destroy(&mctx); #ifdef _WIN32 DestroySockets(); #endif return ((result == ISC_R_SUCCESS) ? 0 : 1); }