int main(int argc, char **argv){ char *optstr = "bc:d:f:ghmno:p:q:s:S:v"; int status = 0; set_progname(basename(argv[0])); process_args(argc, argv, optstr, 1); if(optind < argc - 1) log_errx(1, "Too many arguments."); else if(optind == argc - 1) { if(g.opt_filesize != 0) { log_errx(1, "Option [-S] is not valid when a file argument is given."); } g.input_fname = argv[optind++]; } else if((g.opt_filesize != 0) && (g.opt_prodid == NULL)) log_errx(1, "Option [-p] is mandatory if [-S] is given."); else if((g.opt_filesize == 0) && (g.opt_prodid != NULL)) log_errx(1, "Option [-p] requires [-S] or a file argument"); if(g.opt_background == 1) set_usesyslog(); if(atexit(cleanup) != 0) log_err(1, "atexit"); init(); if(g.input_fname != NULL) status = process_file(); else if(g.opt_filesize != 0) status = process_file(); else status = process_stdin(); return(status != 0 ? 1 : 0); }
int main(int argc, char **argv) { int count, status, goal = argc; state *s; TCHAR *fn, *cwd; #ifndef __GLIBC__ __progname = basename(argv[0]); #endif s = (state *)malloc(sizeof(state)); if (NULL == s) fatal_error("%s: Unable to allocate state variable", __progname); if (initialize_state(s)) fatal_error("%s: Unable to initialize state variable", __progname); process_cmd_line(s,argc,argv); #ifdef _WIN32 if (prepare_windows_command_line(s)) fatal_error("%s: Unable to process command line arguments", __progname); #else s->argc = argc; s->argv = argv; #endif // Anything left on the command line at this point is a file // or directory we're supposed to process. If there's nothing // specified, we should tackle standard input if (optind == argc) { status = process_stdin(s); } else { MD5DEEP_ALLOC(TCHAR,fn,PATH_MAX); MD5DEEP_ALLOC(TCHAR,cwd,PATH_MAX); cwd = _tgetcwd(cwd,PATH_MAX); if (NULL == cwd) fatal_error("%s: %s", __progname, strerror(errno)); count = optind; // The signature comparsion mode needs to use the command line // arguments and argument count. We don't do wildcard expansion // on it on Win32 (i.e. where it matters). The setting of 'goal' // to the original argc occured at the start of main(), so we just // need to update it if we're *not* in signature compare mode. if (!(s->mode & mode_sigcompare)) { goal = s->argc; } while (count < goal) { if (MODE(mode_sigcompare)) match_load(s,argv[count]); else if (MODE(mode_compare_unknown)) match_compare_unknown(s,argv[count]); else { generate_filename(s,fn,cwd,s->argv[count]); #ifdef _WIN32 status = process_win32(s,fn); #else status = process_normal(s,fn); #endif } ++count; } // If we processed files, but didn't find anything large enough // to be meaningful, we should display a warning message to the user. // This happens mostly when people are testing very small files // e.g. $ echo "hello world" > foo && ssdeep foo if ( ! s->found_meaningful_file && s->processed_file) { print_error(s,"%s: Did not process files large enough to produce meaningful results", __progname); } } // If the user has requested us to compare signature files, use // our existng code to pretty-print directory matching to do the // work for us. if (s->mode & mode_sigcompare) s->mode |= mode_match_pretty; if (s->mode & mode_match_pretty) match_pretty(s); return (EXIT_SUCCESS); }
int main(int argc, char *argv[]) { struct daemon_conf config; struct rlimit limit; int rc; /* Check params and build regexpr */ setlocale (LC_ALL, ""); if (check_params(argc, argv)) return 1; /* Raise the rlimits in case we're being started from a shell * with restrictions. Not a fatal error. */ limit.rlim_cur = RLIM_INFINITY; limit.rlim_max = RLIM_INFINITY; setrlimit(RLIMIT_FSIZE, &limit); setrlimit(RLIMIT_CPU, &limit); set_aumessage_mode(MSG_STDERR, DBG_NO); (void) umask( umask( 077 ) | 027 ); very_first_event.sec = 0; reset_counters(); if (user_file == NULL) { /* Load config so we know where logs are */ if (load_config(&config, TEST_SEARCH)) fprintf(stderr, "NOTE - using built-in logs: %s\n", config.log_file); } else { config.sender_ctx = NULL; config.log_file = NULL; config.dispatcher = NULL; config.node_name = NULL; config.space_left_exe = NULL; config.action_mail_acct = NULL; config.admin_space_left_exe = NULL; config.disk_full_exe = NULL; config.disk_error_exe = NULL; config.krb5_principal = NULL; config.krb5_key_file = NULL; } print_title(); lol_create(&lo); if (user_file) rc = process_file(user_file); else if (force_logs) rc = process_logs(&config); else if (is_pipe(0)) rc = process_stdin(); else rc = process_logs(&config); lol_clear(&lo); if (rc) { free_config(&config); return rc; } if (!found && report_detail == D_DETAILED && report_type != RPT_TIME) { printf("<no events of interest were found>\n\n"); destroy_counters(); aulookup_destroy_uid_list(); aulookup_destroy_gid_list(); free_config(&config); return 1; } else print_wrap_up(); destroy_counters(); aulookup_destroy_uid_list(); aulookup_destroy_gid_list(); free_config(&config); free(user_file); return 0; }
int main(int argc, char *argv[]) { struct rlimit limit; int rc; /* Check params and build regexpr */ setlocale (LC_ALL, ""); if (check_params(argc, argv)) return 1; /* Raise the rlimits in case we're being started from a shell * with restrictions. Not a fatal error. */ limit.rlim_cur = RLIM_INFINITY; limit.rlim_max = RLIM_INFINITY; setrlimit(RLIMIT_FSIZE, &limit); setrlimit(RLIMIT_CPU, &limit); set_aumessage_mode(MSG_STDERR, DBG_NO); (void) umask( umask( 077 ) | 027 ); very_first_event.sec = 0; reset_counters(); print_title(); lol_create(&lo); if (user_file) { struct stat sb; if (stat(user_file, &sb) == -1) { perror("stat"); return 1; } else { switch (sb.st_mode & S_IFMT) { case S_IFDIR: userfile_is_dir = 1; rc = process_logs(); break; case S_IFREG: default: rc = process_file(user_file); break; } } } else if (force_logs) rc = process_logs(); else if (is_pipe(0)) rc = process_stdin(); else rc = process_logs(); lol_clear(&lo); if (rc) return rc; if (!found && report_detail == D_DETAILED && report_type != RPT_TIME) { printf("<no events of interest were found>\n\n"); destroy_counters(); aulookup_destroy_uid_list(); aulookup_destroy_gid_list(); return 1; } else print_wrap_up(); destroy_counters(); aulookup_destroy_uid_list(); aulookup_destroy_gid_list(); free(user_file); return 0; }
int main(int argc, char *argv[]) { int arg; char *current_name = NULL, *cp = NULL; oid name[MAX_OID_LEN]; size_t name_length; int description = 0; int print = 0; int find_all = 0; int width = 1000000; /* * usage: snmptranslate name */ while ((arg = getopt(argc, argv, "Vhm:M:w:D:P:T:O:I:L:")) != EOF) { switch (arg) { case 'h': usage(); exit(1); case 'm': setenv("MIBS", optarg, 1); break; case 'M': setenv("MIBDIRS", optarg, 1); break; case 'D': debug_register_tokens(optarg); snmp_set_do_debugging(1); break; case 'V': fprintf(stderr, "NET-SNMP version: %s\n", netsnmp_get_version()); exit(0); break; case 'w': width = atoi(optarg); if (width <= 0) { fprintf(stderr, "Invalid width specification: %s\n", optarg); exit (1); } break; #ifndef NETSNMP_DISABLE_MIB_LOADING case 'P': cp = snmp_mib_toggle_options(optarg); if (cp != NULL) { fprintf(stderr, "Unknown parser option to -P: %c.\n", *cp); usage(); exit(1); } break; #endif /* NETSNMP_DISABLE_MIB_LOADING */ case 'O': cp = snmp_out_toggle_options(optarg); if (cp != NULL) { fprintf(stderr, "Unknown OID option to -O: %c.\n", *cp); usage(); exit(1); } break; case 'I': cp = snmp_in_toggle_options(optarg); if (cp != NULL) { fprintf(stderr, "Unknown OID option to -I: %c.\n", *cp); usage(); exit(1); } break; case 'T': for (cp = optarg; *cp; cp++) { switch (*cp) { #ifndef NETSNMP_DISABLE_MIB_LOADING case 'l': print = 3; print_oid_report_enable_labeledoid(); break; case 'o': print = 3; print_oid_report_enable_oid(); break; case 's': print = 3; print_oid_report_enable_symbolic(); break; case 't': print = 3; print_oid_report_enable_suffix(); break; case 'z': print = 3; print_oid_report_enable_mibchildoid(); break; #endif /* NETSNMP_DISABLE_MIB_LOADING */ case 'd': description = 1; netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_SAVE_MIB_DESCRS, 1); break; case 'B': find_all = 1; break; case 'p': print = 1; break; case 'a': print = 2; break; default: fprintf(stderr, "Invalid -T<lostpad> character: %c\n", *cp); usage(); exit(1); break; } } break; case 'L': if (snmp_log_options(optarg, argc, argv) < 0) { return (-1); } break; default: fprintf(stderr, "invalid option: -%c\n", arg); usage(); exit(1); break; } } init_snmp("snmpapp"); if (optind < argc) current_name = argv[optind]; if (current_name == NULL) { switch (print) { default: usage(); exit(1); #ifndef NETSNMP_DISABLE_MIB_LOADING case 1: print_mib_tree(stdout, get_tree_head(), width); break; case 2: print_ascii_dump(stdout); break; case 3: print_oid_report(stdout); break; #endif /* NETSNMP_DISABLE_MIB_LOADING */ } exit(0); } do { if ( strcmp( current_name, "-" ) == 0 && ( print == 0 ) ) { process_stdin(); current_name = argv[++optind]; continue; } name_length = MAX_OID_LEN; if (netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_RANDOM_ACCESS)) { #ifndef NETSNMP_DISABLE_MIB_LOADING if (!get_node(current_name, name, &name_length)) { #endif /* NETSNMP_DISABLE_MIB_LOADING */ fprintf(stderr, "Unknown object identifier: %s\n", current_name); exit(2); #ifndef NETSNMP_DISABLE_MIB_LOADING } #endif /* NETSNMP_DISABLE_MIB_LOADING */ } else if (find_all) { if (0 == show_all_matched_objects(stdout, current_name, name, &name_length, description, width)) { fprintf(stderr, "Unable to find a matching object identifier for \"%s\"\n", current_name); exit(1); } exit(0); } else if (netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_REGEX_ACCESS)) { #ifndef NETSNMP_DISABLE_MIB_LOADING if (0 == get_wild_node(current_name, name, &name_length)) { #endif /* NETSNMP_DISABLE_MIB_LOADING */ fprintf(stderr, "Unable to find a matching object identifier for \"%s\"\n", current_name); exit(1); #ifndef NETSNMP_DISABLE_MIB_LOADING } #endif /* NETSNMP_DISABLE_MIB_LOADING */ } else { if (!read_objid(current_name, name, &name_length)) { snmp_perror(current_name); exit(2); } } if (print == 1) { #ifndef NETSNMP_DISABLE_MIB_LOADING struct tree *tp; tp = get_tree(name, name_length, get_tree_head()); if (tp == NULL) { #endif /* NETSNMP_DISABLE_MIB_LOADING */ snmp_log(LOG_ERR, "Unable to find a matching object identifier for \"%s\"\n", current_name); exit(1); #ifndef NETSNMP_DISABLE_MIB_LOADING } print_mib_tree(stdout, tp, width); #endif /* NETSNMP_DISABLE_MIB_LOADING */ } else { print_objid(name, name_length); if (description) { #ifndef NETSNMP_DISABLE_MIB_LOADING print_description(name, name_length, width); #endif /* NETSNMP_DISABLE_MIB_LOADING */ } } current_name = argv[++optind]; if (current_name != NULL) printf("\n"); } while (optind < argc); return (0); }