int main (int argc, char **argv) { s_rules rr; if (argv[argc]) err(1, "bad argument list"); if (argc != 3) usage(argv[0]); if (strcmp(argv[1], "-c")) usage(argv[0]); openlog(argv[0], LOG_PID, LOG_AUTH); log_args("NEW", argc, (const char **)argv); init_package(); { const char *env_auth_id = getenv(ENV_AUTH_ID); t_sym id = sympackage_intern(&g_sympkg, env_auth_id ? env_auth_id : ""); s_symtable cmd; cmd_init(&cmd, id, argv[2]); rules_init(&rr); rules_read(&rr, "/etc/git-auth.conf"); { int auth_ok = auth(&rr, &cmd); rules_free(&rr); log_rule(auth_ok ? "ALLOW" : "DENY", &cmd); if (auth_ok) { exec_cmd(&cmd); // never reached } } log_rule("DENY", &cmd); } cleanup(); return 1; }
/* Here we go */ int main(int argc, char *argv[], char *envp[]) { char *progname; const struct futil_cmd_t *cmd; int i, errorcnt = 0; int vb_ver = VBOOT_VERSION_ALL; struct option long_opts[] = { {"vb1" , 0, &vb_ver, VBOOT_VERSION_1_0}, {"vb21", 0, &vb_ver, VBOOT_VERSION_2_1}, { 0, 0, 0, 0}, }; log_args(argc, argv); /* How were we invoked? */ progname = simple_basename(argv[0]); /* See if the program name is a command we recognize */ cmd = find_command(progname); if (cmd) /* Yep, just do that */ return run_command(cmd, argc, argv); /* Parse the global options, stopping at the first non-option. */ opterr = 0; /* quiet, you. */ while ((i = getopt_long(argc, argv, "+:", long_opts, NULL)) != -1) { switch (i) { case '?': if (optopt) fprintf(stderr, "Unrecognized option: -%c\n", optopt); else fprintf(stderr, "Unrecognized option: %s\n", argv[optind - 1]); errorcnt++; break; case ':': fprintf(stderr, "Missing argument to -%c\n", optopt); errorcnt++; break; case 0: /* handled option */ break; default: Debug("i=%d\n", i); DIE; } } vboot_version = vb_ver; /* Reset the getopt state so commands can parse their own options. */ argc -= optind; argv += optind; optind = 0; /* We require a command name. */ if (errorcnt || argc < 1) { do_help(0, 0); return 1; } /* For reasons I've forgotten, treat /blah/blah/CMD the same as CMD */ progname = simple_basename(argv[0]); /* Do we recognize the command? */ cmd = find_command(progname); if (cmd) return run_command(cmd, argc, argv); /* Nope. We've no clue what we're being asked to do. */ do_help(0, 0); return 1; }
void CheckTaskSched::CheckTaskSched_(Plugin::QueryRequestMessage::Request &request, Plugin::QueryResponseMessage::Response *response) { boost::program_options::options_description desc; std::vector<std::string> counters; std::string syntax, topSyntax, filter, arg_warn, arg_crit; bool debug = false; nscapi::program_options::add_help(desc); desc.add_options() ("warn", po::value<std::string>(&arg_warn), "Warning bounds.") ("crit", po::value<std::string>(&arg_crit), "Critical bounds.") ("MaxWarn", po::value<std::string>(), "Maximum value before a warning is returned.") ("MaxCrit", po::value<std::string>(), "Maximum value before a critical is returned.") ("MinWarn", po::value<std::string>(), "Minimum value before a warning is returned.") ("MinCrit", po::value<std::string>(), "Minimum value before a critical is returned.") ("Counter", po::value<std::vector<std::string>>(&counters), "The time to check") ("truncate", po::value<std::string>(), "Deprecated option") ("syntax", po::value<std::string>(&syntax), "Syntax (same as detail-syntax in the check_tasksched check)") ("master-syntax", po::value<std::string>(&topSyntax), "Master Syntax (same as top-syntax in the check_tasksched check)") ("filter", po::value<std::string>(&filter), "Filter (same as filter in the check_tasksched check)") ("debug", po::bool_switch(&debug), "Filter (same as filter in the check_tasksched check)") ; boost::program_options::variables_map vm; std::vector<std::string> extra; if (!nscapi::program_options::process_arguments_from_request(vm, desc, request, *response, true, extra)) return; std::string warn, crit; request.clear_arguments(); if (vm.count("MaxWarn")) warn = "warn=count > " + vm["MaxWarn"].as<std::string>(); if (vm.count("MaxCrit")) crit = "crit=count > " + vm["MaxCrit"].as<std::string>(); if (vm.count("MinWarn")) warn = "warn=count < " + vm["MinWarn"].as<std::string>(); if (vm.count("MinCrit")) crit = "crit=count > " + vm["MinCrit"].as<std::string>(); if (!arg_warn.empty()) warn = "warn=count " + arg_warn; if (!arg_crit.empty()) crit = "crit=count " + arg_crit; if (!warn.empty()) request.add_arguments(warn); if (!crit.empty()) request.add_arguments(crit); if (debug) request.add_arguments("debug"); if (!filter.empty()) request.add_arguments("filter=" + filter); if (!topSyntax.empty()) { boost::replace_all(topSyntax, "%status%", "${task_status}"); request.add_arguments("top-syntax=" + topSyntax); } if (!syntax.empty()) { boost::replace_all(syntax, "%title%", "${title}"); boost::replace_all(syntax, "%status%", "${task_status}"); boost::replace_all(syntax, "%exit_code%", "${exit_code}"); boost::replace_all(syntax, "%most_recent_run_time%", "${most_recent_run_time}"); request.add_arguments("detail-syntax=" + syntax); } log_args(request); check_tasksched(request, response); }
int main(int argc, char *argv[], char *envp[]) { char *progname; const struct futil_cmd_t *cmd; int i, errorcnt = 0; int vb_ver = VBOOT_VERSION_ALL; int helpind = 0; struct option long_opts[] = { {"debug", 0, &debugging_enabled, 1}, {"vb1" , 0, &vb_ver, VBOOT_VERSION_1_0}, {"vb21", 0, &vb_ver, VBOOT_VERSION_2_1}, {"help", 0, 0, OPT_HELP}, { 0, 0, 0, 0}, }; log_args(argc, argv); /* How were we invoked? */ progname = simple_basename(argv[0]); /* See if the program name is a command we recognize */ cmd = find_command(progname); if (cmd) { /* Yep, just do that */ return !!run_command(cmd, argc, argv); } /* Parse the global options, stopping at the first non-option. */ opterr = 0; /* quiet, you. */ while ((i = getopt_long(argc, argv, "+:", long_opts, NULL)) != -1) { switch (i) { case OPT_HELP: /* Remember where we found this option */ /* Note: this might be GNU-specific */ helpind = optind - 1; break; case '?': if (optopt) fprintf(stderr, "Unrecognized option: -%c\n", optopt); else fprintf(stderr, "Unrecognized option: %s\n", argv[optind - 1]); errorcnt++; break; case ':': fprintf(stderr, "Missing argument to -%c\n", optopt); errorcnt++; break; case 0: /* handled option */ break; default: Debug("i=%d\n", i); DIE; } } vboot_version = vb_ver; /* * Translate "--help" in the args to "help" as the first parameter, * by rearranging argv[]. */ if (helpind) { int i; optind--; for (i = helpind; i < optind; i++) argv[i] = argv[i + 1]; argv[i] = "help"; } /* We require a command name. */ if (errorcnt || argc == optind) { do_help(1, argv); return 1; } /* For reasons I've forgotten, treat /blah/blah/CMD the same as CMD */ argv[optind] = simple_basename(argv[optind]); /* Do we recognize the command? */ cmd = find_command(argv[optind]); if (cmd) { /* Reset so commands can parse their own options */ argc -= optind; argv += optind; optind = 0; return !!run_command(cmd, argc, argv); } /* Nope. We've no clue what we're being asked to do. */ do_help(1, argv); return 1; }
void client_read(client *cl) { int status, pn; status = mr_cont_receive(cl->con, &cl->req); if (status == -1) return; else if (status != MR_SUCCESS) { cl->state = CL_CLOSING; if (status != MR_NOT_CONNECTED) com_err(whoami, status, "while reading from socket"); return; } pn = cl->req.u.mr_procno; if (pn < 0 || pn > MR_MAX_PROC) { com_err(whoami, 0, "procno out of range"); client_reply(cl, MR_UNKNOWN_PROC); goto out; } log_args(procnames[pn], 2, cl->req.mr_argc, cl->req.mr_argv); if (dormant == ASLEEP && pn != MR_NOOP && pn != MR_MOTD) { client_reply(cl, MR_DOWN); com_err(whoami, MR_DOWN, "(query refused)"); goto out; } /* make sure this gets cleared before every operation */ dbms_errno = 0; switch (pn) { case MR_NOOP: client_reply(cl, MR_SUCCESS); break; case MR_AUTH: do_auth(cl); break; case MR_QUERY: do_retr(cl); break; case MR_ACCESS: do_access(cl); break; case MR_SHUTDOWN: do_shutdown(cl); break; case MR_DO_UPDATE: client_reply(cl, MR_PERM); break; case MR_MOTD: get_motd(cl); break; case MR_PROXY: do_proxy(cl); break; case MR_SETVERSION: do_version(cl); break; case MR_KRB5_AUTH: do_krb5_auth(cl); break; } out: mr_destroy_reply(cl->req); memset(&cl->req, 0, sizeof(mr_params)); }