/* * after parsing configuration, start the dns_server */ void dns_start (void) { printf ("Starting DNS server.\n"); openlog ("simple-dns", LOG_PID, LOG_LOCAL0); open_sockets (); }
int main(int argc, char* argv[]) { if (argc < 1) { printf("Pass filename of socket file as argument.\n"); exit(EXIT_FAILURE); } open_sockets(argv[1]); }
int receiver(McastResult** test_results, int n_addr, int n_stream, int test_inc, char *start_addr, int start_port, int buf_len, int mbps, int timeout, int verbose){ // test_inc = 0, just do one test // test_inc = n, test 1,1+n, 1+2n... n_addr addresses. int n_tests; n_tests = 3 + n_addr/(test_inc); sockets = malloc(sizeof(int) * n_addr * n_stream + sizeof(int)); sockets[n_addr * n_stream] = -1; int j, ind = 0; open_sockets(n_addr, n_stream,start_port, start_addr); j = 1; //test level. n_tests = 0; int jitterSize = 0; while(j <= n_addr ){ /* hack needed for vms... */ if (n_tests > 0 && n_tests % 15 == 0){ close_sockets(); open_sockets(n_addr, n_stream,start_port, start_addr); } int tout = timeout; if (n_tests == 0 && restarted == 0) tout = 300; test_results[ind] = run_tests(j, n_stream, start_addr, start_port, buf_len, &jitterSize, tout,verbose); if (test_results[ind] == NULL){ break; } if (verbose == 1) disp_results(test_results[ind]); n_tests++; ind++; if (j == n_addr) break; if (j == 1 && test_inc != 1) j = 0; j += test_inc; if (j > n_addr) j = n_addr; } close_sockets(); free(sockets); restarted = 1; return n_tests; }
int main(int argc,char **argv) { mons = monitor_struct_alloc(PORTS_NR); init_monitor_struct(mons,monitored_ports); open_sockets(mons); atexit(terminate); apply_bpf_filters(mons); signal(SIGINT,sigint_handler); monitor_all(); return 0; }
int main() { char iface[] = "eth1"; struct debconfclient *client = debconfclient_new(); debconf_x_loadtemplate(client, "set-essid.templates"); open_sockets(); int ret = netcfg_wireless_set_essid(client, iface, "high"); if (ret == GO_BACK) { /* Just go back... */ fprintf(stderr, "GO BACK\n"); } return 0; }
void setup_fds(void) { /* If we have victim files, don't worry about sockets. */ if (victim_path == NULL) open_sockets(); open_pipes(); open_perf_fds(); open_epoll_fds(); open_eventfd_fds(); if (no_files == FALSE) { generate_filelist(); if (files_in_index == 0) /* Something bad happened. Crappy -V maybe? */ return; // FIXME: We should log something here probably. open_files(); } }
unsigned int setup_fds(void) { int ret = TRUE; /* If we have victim files, don't worry about sockets. */ if (victim_path == NULL) { ret = open_sockets(); if (ret == FALSE) return FALSE; } open_pipes(); open_perf_fds(); open_epoll_fds(); open_eventfd_fds(); if (no_files == FALSE) ret = open_files(); return ret; }
int main(int argc, char *argv[]) { int num_interfaces = 0; enum { BACKUP, GET_INTERFACE, GET_HOSTNAME_ONLY, GET_METHOD, GET_DHCP, GET_STATIC, WCONFIG, WCONFIG_ESSID, WCONFIG_SECURITY_TYPE, WCONFIG_WEP, WCONFIG_WPA, START_WPA, QUIT } state = GET_INTERFACE; static struct debconfclient *client; static int requested_wireless_tools = 0; char **ifaces; char *defiface = NULL, *defwireless = NULL; response_t res; struct netcfg_interface interface; #ifdef NM struct nm_config_info nmconf; #endif /* initialize libd-i */ di_system_init("netcfg"); netcfg_interface_init(&interface); if (strcmp(basename(argv[0]), "ptom") != 0) di_info("Starting netcfg v.%s", NETCFG_VERSION); parse_args (argc, argv); reap_old_files (); open_sockets(); /* initialize debconf */ client = debconfclient_new(); debconf_capb(client, "backup"); /* Check to see if netcfg should be run at all */ debconf_get(client, "netcfg/enable"); if (!strcmp(client->value, "false")) { netcfg_get_hostname(client, "netcfg/get_hostname", hostname, 0); netcfg_write_common("", hostname, NULL); return 0; } /* always always always default back to autoconfig, unless you've specified * disable_autoconfig on the command line. */ debconf_get(client, "netcfg/disable_autoconfig"); if (!strcmp(client->value, "true")) debconf_set(client, "netcfg/use_autoconfig", "false"); else debconf_set(client, "netcfg/use_autoconfig", "true"); /* also support disable_dhcp for compatibility */ debconf_get(client, "netcfg/disable_dhcp"); if (!strcmp(client->value, "true")) debconf_set(client, "netcfg/use_autoconfig", "false"); for (;;) { switch(state) { case BACKUP: return RETURN_TO_MAIN; case GET_INTERFACE: /* If we have returned from outside of netcfg and want to * reconfigure networking, check to see if wpasupplicant is * running, and kill it if it is. If left running when * the interfaces are taken up and down, it appears to * leave it in an inconsistant state */ kill_wpa_supplicant(); /* Choose a default by looking for link */ if (get_all_ifs(1, &ifaces) > 1) { while (*ifaces) { struct netcfg_interface link_interface; if (check_kill_switch(*ifaces)) { debconf_subst(client, "netcfg/kill_switch_enabled", "iface", *ifaces); debconf_input(client, "high", "netcfg/kill_switch_enabled"); if (debconf_go(client) == CMD_GOBACK) { state = BACKUP; break; } /* Is it still enabled? */ if (check_kill_switch(*ifaces)) { ifaces++; continue; } } interface_up(*ifaces); netcfg_interface_init(&link_interface); link_interface.name = strdup(*ifaces); if (netcfg_detect_link (client, &link_interface) == 1) /* CONNECTED */ { /* CONNECTED */ di_info("found link on interface %s, making it the default.", *ifaces); defiface = strdup(*ifaces); free(link_interface.name); break; } else { #ifdef WIRELESS struct wireless_config wc; #endif /* WIRELESS */ di_info("found no link on interface %s.", *ifaces); #ifdef WIRELESS if (iw_get_basic_config(wfd, *ifaces, &wc) == 0) { wc.essid[0] = '\0'; wc.essid_on = 0; iw_set_basic_config(wfd, *ifaces, &wc); sleep(1); iw_get_basic_config(wfd, *ifaces, &wc); if (!empty_str(wc.essid)) { di_info("%s is associated with %s. Selecting as default", *ifaces, wc.essid); defiface = strdup(*ifaces); interface_down(*ifaces); break; } else { di_info("%s is not associated. Relegating to defwireless", *ifaces); if (defwireless != NULL) free (defwireless); defwireless = strdup(*ifaces); } } else di_info("%s is not a wireless interface. Continuing.", *ifaces); interface_down(*ifaces); #endif } free(link_interface.name); interface_down(*ifaces); ifaces++; } } if (state == BACKUP) break; if (!defiface && defwireless) defiface = defwireless; if(netcfg_get_interface(client, &(interface.name), &num_interfaces, defiface)) state = BACKUP; else if (! interface.name || ! num_interfaces) state = GET_HOSTNAME_ONLY; else { if (is_wireless_iface (interface.name)) state = WCONFIG; else state = GET_METHOD; } break; case GET_HOSTNAME_ONLY: if(netcfg_get_hostname(client, "netcfg/get_hostname", hostname, 0)) state = BACKUP; else { netcfg_write_common("", hostname, NULL); state = QUIT; } break; case GET_METHOD: if ((res = netcfg_get_method(client)) == GO_BACK) state = (num_interfaces == 1) ? BACKUP : GET_INTERFACE; else { if (netcfg_method == DHCP) state = GET_DHCP; else state = GET_STATIC; } break; case GET_DHCP: switch (netcfg_activate_dhcp(client, &interface)) { case 0: state = QUIT; break; case RETURN_TO_MAIN: /* * It doesn't make sense to go back to GET_METHOD because * the user has already been asked whether they want to * try an alternate method. */ state = (num_interfaces == 1) ? BACKUP : GET_INTERFACE; break; case CONFIGURE_MANUALLY: state = GET_STATIC; break; default: return 1; } break; case GET_STATIC: { int ret; /* Misnomer - this should actually take care of activation */ if ((ret = netcfg_get_static(client, &interface)) == RETURN_TO_MAIN) state = GET_INTERFACE; else if (ret) state = GET_METHOD; else state = QUIT; break; } case WCONFIG: if (requested_wireless_tools == 0) { di_exec_shell_log("apt-install iw wireless-tools"); requested_wireless_tools = 1; } state = WCONFIG_ESSID; break; case WCONFIG_ESSID: if (netcfg_wireless_set_essid(client, &interface) == GO_BACK) state = BACKUP; else { init_wpa_supplicant_support(&interface); if (interface.wpa_supplicant_status == WPA_UNAVAIL) state = WCONFIG_WEP; else state = WCONFIG_SECURITY_TYPE; } break; case WCONFIG_SECURITY_TYPE: { int ret; ret = wireless_security_type(client, interface.name); if (ret == GO_BACK) state = WCONFIG_ESSID; else if (ret == REPLY_WPA) { state = WCONFIG_WPA; interface.wifi_security = REPLY_WPA; } else { state = WCONFIG_WEP; interface.wifi_security = REPLY_WEP; } break; } case WCONFIG_WEP: if (netcfg_wireless_set_wep(client, &interface) == GO_BACK) if (interface.wpa_supplicant_status == WPA_UNAVAIL) state = WCONFIG_ESSID; else state = WCONFIG_SECURITY_TYPE; else state = GET_METHOD; break; case WCONFIG_WPA: if (interface.wpa_supplicant_status == WPA_OK) { di_exec_shell_log("apt-install wpasupplicant"); interface.wpa_supplicant_status = WPA_QUEUED; } if (netcfg_set_passphrase(client, &interface) == GO_BACK) state = WCONFIG_SECURITY_TYPE; else state = START_WPA; break; case START_WPA: if (wpa_supplicant_start(client, &interface) == GO_BACK) state = WCONFIG_ESSID; else state = GET_METHOD; break; case QUIT: #ifdef NM if (num_interfaces > 0) { nm_get_configuration(&interface, &nmconf); nm_write_configuration(nmconf); } #endif netcfg_update_entropy(); return 0; } } }
/**************************************************************************** main program ****************************************************************************/ int main(int argc, const char *argv[]) { int opt; unsigned int lookup_type = 0x0; fstring lookup; static bool find_master=False; static bool lookup_by_ip = False; poptContext pc = NULL; TALLOC_CTX *frame = talloc_stackframe(); int rc = 0; struct poptOption long_options[] = { POPT_AUTOHELP { "broadcast", 'B', POPT_ARG_STRING, NULL, 'B', "Specify address to use for broadcasts", "BROADCAST-ADDRESS" }, { "flags", 'f', POPT_ARG_NONE, NULL, 'f', "List the NMB flags returned" }, { "unicast", 'U', POPT_ARG_STRING, NULL, 'U', "Specify address to use for unicast" }, { "master-browser", 'M', POPT_ARG_NONE, NULL, 'M', "Search for a master browser" }, { "recursion", 'R', POPT_ARG_NONE, NULL, 'R', "Set recursion desired in package" }, { "status", 'S', POPT_ARG_NONE, NULL, 'S', "Lookup node status as well" }, { "translate", 'T', POPT_ARG_NONE, NULL, 'T', "Translate IP addresses into names" }, { "root-port", 'r', POPT_ARG_NONE, NULL, 'r', "Use root port 137 (Win95 only replies to this)" }, { "lookup-by-ip", 'A', POPT_ARG_NONE, NULL, 'A', "Do a node status on <name> as an IP Address" }, POPT_COMMON_SAMBA POPT_COMMON_CONNECTION { 0, 0, 0, 0 } }; *lookup = 0; load_case_tables(); setup_logging(argv[0], DEBUG_STDOUT); pc = poptGetContext("nmblookup", argc, argv, long_options, POPT_CONTEXT_KEEP_FIRST); poptSetOtherOptionHelp(pc, "<NODE> ..."); while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case 'f': give_flags = true; break; case 'M': find_master = true; break; case 'R': recursion_desired = true; break; case 'S': find_status = true; break; case 'r': RootPort = true; break; case 'A': lookup_by_ip = true; break; case 'B': if (interpret_string_addr(&bcast_addr, poptGetOptArg(pc), NI_NUMERICHOST)) { got_bcast = True; use_bcast = True; } break; case 'U': if (interpret_string_addr(&bcast_addr, poptGetOptArg(pc), 0)) { got_bcast = True; use_bcast = False; } break; case 'T': translate_addresses = !translate_addresses; break; } } poptGetArg(pc); /* Remove argv[0] */ if(!poptPeekArg(pc)) { poptPrintUsage(pc, stderr, 0); rc = 1; goto out; } if (!lp_load_global(get_dyn_CONFIGFILE())) { fprintf(stderr, "Can't load %s - run testparm to debug it\n", get_dyn_CONFIGFILE()); } load_interfaces(); if (!open_sockets()) { rc = 1; goto out; } while(poptPeekArg(pc)) { char *p; struct in_addr ip; fstrcpy(lookup,poptGetArg(pc)); if(lookup_by_ip) { struct sockaddr_storage ss; ip = interpret_addr2(lookup); in_addr_to_sockaddr_storage(&ss, ip); fstrcpy(lookup,"*"); if (!do_node_status(lookup, lookup_type, &ss)) { rc = 1; } continue; } if (find_master) { if (*lookup == '-') { fstrcpy(lookup,"\01\02__MSBROWSE__\02"); lookup_type = 1; } else { lookup_type = 0x1d; } } p = strchr_m(lookup,'#'); if (p) { *p = '\0'; sscanf(++p,"%x",&lookup_type); } if (!query_one(lookup, lookup_type)) { rc = 1; d_printf( "name_query failed to find name %s", lookup ); if( 0 != lookup_type ) { d_printf( "#%02x", lookup_type ); } d_printf( "\n" ); } } out: poptFreeContext(pc); TALLOC_FREE(frame); return rc; }
int main(int argc, const char *argv[]) { static bool is_daemon; static bool opt_interactive; static bool Fork = true; static bool no_process_group; static bool log_stdout; poptContext pc; char *p_lmhosts = NULL; int opt; enum { OPT_DAEMON = 1000, OPT_INTERACTIVE, OPT_FORK, OPT_NO_PROCESS_GROUP, OPT_LOG_STDOUT }; struct poptOption long_options[] = { POPT_AUTOHELP {"daemon", 'D', POPT_ARG_NONE, NULL, OPT_DAEMON, "Become a daemon(default)" }, {"interactive", 'i', POPT_ARG_NONE, NULL, OPT_INTERACTIVE, "Run interactive (not a daemon)" }, {"foreground", 'F', POPT_ARG_NONE, NULL, OPT_FORK, "Run daemon in foreground (for daemontools & etc)" }, {"no-process-group", 0, POPT_ARG_NONE, NULL, OPT_NO_PROCESS_GROUP, "Don't create a new process group" }, {"log-stdout", 'S', POPT_ARG_NONE, NULL, OPT_LOG_STDOUT, "Log to stdout" }, {"hosts", 'H', POPT_ARG_STRING, &p_lmhosts, 0, "Load a netbios hosts file"}, {"port", 'p', POPT_ARG_INT, &global_nmb_port, 0, "Listen on the specified port" }, POPT_COMMON_SAMBA { NULL } }; TALLOC_CTX *frame; NTSTATUS status; /* * Do this before any other talloc operation */ talloc_enable_null_tracking(); frame = talloc_stackframe(); setup_logging(argv[0], DEBUG_DEFAULT_STDOUT); load_case_tables(); global_nmb_port = NMB_PORT; pc = poptGetContext("nmbd", argc, argv, long_options, 0); while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { case OPT_DAEMON: is_daemon = true; break; case OPT_INTERACTIVE: opt_interactive = true; break; case OPT_FORK: Fork = false; break; case OPT_NO_PROCESS_GROUP: no_process_group = true; break; case OPT_LOG_STDOUT: log_stdout = true; break; default: d_fprintf(stderr, "\nInvalid option %s: %s\n\n", poptBadOption(pc, 0), poptStrerror(opt)); poptPrintUsage(pc, stderr, 0); exit(1); } }; poptFreeContext(pc); global_in_nmbd = true; StartupTime = time(NULL); sys_srandom(time(NULL) ^ sys_getpid()); if (!override_logfile) { char *lfile = NULL; if (asprintf(&lfile, "%s/log.nmbd", get_dyn_LOGFILEBASE()) < 0) { exit(1); } lp_set_logfile(lfile); SAFE_FREE(lfile); } fault_setup(); dump_core_setup("nmbd", lp_logfile()); /* POSIX demands that signals are inherited. If the invoking process has * these signals masked, we will have problems, as we won't receive them. */ BlockSignals(False, SIGHUP); BlockSignals(False, SIGUSR1); BlockSignals(False, SIGTERM); #if defined(SIGFPE) /* we are never interested in SIGFPE */ BlockSignals(True,SIGFPE); #endif /* We no longer use USR2... */ #if defined(SIGUSR2) BlockSignals(True, SIGUSR2); #endif if ( opt_interactive ) { Fork = False; log_stdout = True; } if ( log_stdout && Fork ) { DEBUG(0,("ERROR: Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n")); exit(1); } if (log_stdout) { setup_logging(argv[0], DEBUG_STDOUT); } else { setup_logging( argv[0], DEBUG_FILE); } reopen_logs(); DEBUG(0,("nmbd version %s started.\n", samba_version_string())); DEBUGADD(0,("%s\n", COPYRIGHT_STARTUP_MESSAGE)); if (!lp_load_initial_only(get_dyn_CONFIGFILE())) { DEBUG(0, ("error opening config file '%s'\n", get_dyn_CONFIGFILE())); exit(1); } if (nmbd_messaging_context() == NULL) { return 1; } if ( !reload_nmbd_services(False) ) return(-1); if(!init_names()) return -1; reload_nmbd_services( True ); if (strequal(lp_workgroup(),"*")) { DEBUG(0,("ERROR: a workgroup name of * is no longer supported\n")); exit(1); } set_samba_nb_type(); if (!is_daemon && !is_a_socket(0)) { DEBUG(0,("standard input is not a socket, assuming -D option\n")); is_daemon = True; } if (is_daemon && !opt_interactive) { DEBUG( 2, ( "Becoming a daemon.\n" ) ); become_daemon(Fork, no_process_group, log_stdout); } #if HAVE_SETPGID /* * If we're interactive we want to set our own process group for * signal management. */ if (opt_interactive && !no_process_group) setpgid( (pid_t)0, (pid_t)0 ); #endif if (nmbd_messaging_context() == NULL) { return 1; } #ifndef SYNC_DNS /* Setup the async dns. We do it here so it doesn't have all the other stuff initialised and thus chewing memory and sockets */ if(lp_we_are_a_wins_server() && lp_dns_proxy()) { start_async_dns(); } #endif if (!directory_exist(lp_lockdir())) { mkdir(lp_lockdir(), 0755); } pidfile_create("nmbd"); status = reinit_after_fork(nmbd_messaging_context(), nmbd_event_context(), procid_self(), false); if (!NT_STATUS_IS_OK(status)) { DEBUG(0,("reinit_after_fork() failed\n")); exit(1); } if (!nmbd_setup_sig_term_handler()) exit(1); if (!nmbd_setup_sig_hup_handler()) exit(1); /* get broadcast messages */ if (!serverid_register(procid_self(), FLAG_MSG_GENERAL | FLAG_MSG_NMBD | FLAG_MSG_DBWRAP)) { DEBUG(1, ("Could not register myself in serverid.tdb\n")); exit(1); } messaging_register(nmbd_messaging_context(), NULL, MSG_FORCE_ELECTION, nmbd_message_election); #if 0 /* Until winsrepl is done. */ messaging_register(nmbd_messaging_context(), NULL, MSG_WINS_NEW_ENTRY, nmbd_wins_new_entry); #endif messaging_register(nmbd_messaging_context(), NULL, MSG_SHUTDOWN, nmbd_terminate); messaging_register(nmbd_messaging_context(), NULL, MSG_SMB_CONF_UPDATED, msg_reload_nmbd_services); messaging_register(nmbd_messaging_context(), NULL, MSG_SEND_PACKET, msg_nmbd_send_packet); TimeInit(); DEBUG( 3, ( "Opening sockets %d\n", global_nmb_port ) ); if ( !open_sockets( is_daemon, global_nmb_port ) ) { kill_async_dns_child(); return 1; } /* Determine all the IP addresses we have. */ load_interfaces(); /* Create an nmbd subnet record for each of the above. */ if( False == create_subnets() ) { DEBUG(0,("ERROR: Failed when creating subnet lists. Exiting.\n")); kill_async_dns_child(); exit(1); } /* Load in any static local names. */ if (p_lmhosts) { set_dyn_LMHOSTSFILE(p_lmhosts); } load_lmhosts_file(get_dyn_LMHOSTSFILE()); DEBUG(3,("Loaded hosts file %s\n", get_dyn_LMHOSTSFILE())); /* If we are acting as a WINS server, initialise data structures. */ if( !initialise_wins() ) { DEBUG( 0, ( "nmbd: Failed when initialising WINS server.\n" ) ); kill_async_dns_child(); exit(1); } /* * Register nmbd primary workgroup and nmbd names on all * the broadcast subnets, and on the WINS server (if specified). * Also initiate the startup of our primary workgroup (start * elections if we are setup as being able to be a local * master browser. */ if( False == register_my_workgroup_and_names() ) { DEBUG(0,("ERROR: Failed when creating my my workgroup. Exiting.\n")); kill_async_dns_child(); exit(1); } if (!initialize_nmbd_proxy_logon()) { DEBUG(0,("ERROR: Failed setup nmbd_proxy_logon.\n")); kill_async_dns_child(); exit(1); } if (!nmbd_init_packet_server()) { kill_async_dns_child(); exit(1); } TALLOC_FREE(frame); process(); kill_async_dns_child(); return(0); }
/**************************************************************************** ** main program **************************************************************************** */ int main(int argc, const char *argv[]) { pstring logfile; static BOOL opt_interactive; poptContext pc; static char *p_lmhosts = dyn_LMHOSTSFILE; static BOOL no_process_group = False; struct poptOption long_options[] = { POPT_AUTOHELP {"daemon", 'D', POPT_ARG_VAL, &is_daemon, True, "Become a daemon(default)" }, {"interactive", 'i', POPT_ARG_VAL, &opt_interactive, True, "Run interactive (not a daemon)" }, {"foreground", 'F', POPT_ARG_VAL, &Fork, False, "Run daemon in foreground (for daemontools & etc)" }, {"no-process-group", 0, POPT_ARG_VAL, &no_process_group, True, "Don't create a new process group" }, {"log-stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" }, {"hosts", 'H', POPT_ARG_STRING, &p_lmhosts, 'H', "Load a netbios hosts file"}, {"port", 'p', POPT_ARG_INT, &global_nmb_port, NMB_PORT, "Listen on the specified port" }, POPT_COMMON_SAMBA { NULL } }; load_case_tables(); global_nmb_port = NMB_PORT; pc = poptGetContext("nmbd", argc, argv, long_options, 0); while (poptGetNextOpt(pc) != -1) {}; poptFreeContext(pc); global_in_nmbd = True; StartupTime = time(NULL); sys_srandom(time(NULL) ^ sys_getpid()); if (!override_logfile) { slprintf(logfile, sizeof(logfile)-1, "%s/log.nmbd", dyn_LOGFILEBASE); lp_set_logfile(logfile); } fault_setup((void (*)(void *))fault_continue ); dump_core_setup("nmbd"); /* POSIX demands that signals are inherited. If the invoking process has * these signals masked, we will have problems, as we won't receive them. */ BlockSignals(False, SIGHUP); BlockSignals(False, SIGUSR1); BlockSignals(False, SIGTERM); CatchSignal( SIGHUP, SIGNAL_CAST sig_hup ); CatchSignal( SIGTERM, SIGNAL_CAST sig_term ); #if defined(SIGFPE) /* we are never interested in SIGFPE */ BlockSignals(True,SIGFPE); #endif /* We no longer use USR2... */ #if defined(SIGUSR2) BlockSignals(True, SIGUSR2); #endif if ( opt_interactive ) { Fork = False; log_stdout = True; } if ( log_stdout && Fork ) { DEBUG(0,("ERROR: Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n")); exit(1); } setup_logging( argv[0], log_stdout ); reopen_logs(); DEBUG( 0, ( "Netbios nameserver version %s started.\n", SAMBA_VERSION_STRING) ); DEBUGADD( 0, ( "%s\n", COPYRIGHT_STARTUP_MESSAGE ) ); if ( !reload_nmbd_services(False) ) return(-1); if(!init_names()) return -1; reload_nmbd_services( True ); if (strequal(lp_workgroup(),"*")) { DEBUG(0,("ERROR: a workgroup name of * is no longer supported\n")); exit(1); } set_samba_nb_type(); if (!is_daemon && !is_a_socket(0)) { DEBUG(0,("standard input is not a socket, assuming -D option\n")); is_daemon = True; } if (is_daemon && !opt_interactive) { DEBUG( 2, ( "Becoming a daemon.\n" ) ); become_daemon(Fork, no_process_group); } #if HAVE_SETPGID /* * If we're interactive we want to set our own process group for * signal management. */ if (opt_interactive && !no_process_group) setpgid( (pid_t)0, (pid_t)0 ); #endif #ifndef SYNC_DNS /* Setup the async dns. We do it here so it doesn't have all the other stuff initialised and thus chewing memory and sockets */ if(lp_we_are_a_wins_server() && lp_dns_proxy()) { start_async_dns(); } #endif if (!directory_exist(lp_lockdir(), NULL)) { mkdir(lp_lockdir(), 0755); } pidfile_create("nmbd"); message_init(); message_register(MSG_FORCE_ELECTION, nmbd_message_election, NULL); #if 0 /* Until winsrepl is done. */ message_register(MSG_WINS_NEW_ENTRY, nmbd_wins_new_entry, NULL); #endif message_register(MSG_SHUTDOWN, nmbd_terminate, NULL); message_register(MSG_SMB_CONF_UPDATED, msg_reload_nmbd_services, NULL); message_register(MSG_SEND_PACKET, msg_nmbd_send_packet, NULL); TimeInit(); DEBUG( 3, ( "Opening sockets %d\n", global_nmb_port ) ); if ( !open_sockets( is_daemon, global_nmb_port ) ) { kill_async_dns_child(); return 1; } /* Determine all the IP addresses we have. */ load_interfaces(); /* Create an nmbd subnet record for each of the above. */ if( False == create_subnets() ) { DEBUG(0,("ERROR: Failed when creating subnet lists. Exiting.\n")); kill_async_dns_child(); exit(1); } /* Load in any static local names. */ load_lmhosts_file(p_lmhosts); DEBUG(3,("Loaded hosts file %s\n", p_lmhosts)); /* If we are acting as a WINS server, initialise data structures. */ if( !initialise_wins() ) { DEBUG( 0, ( "nmbd: Failed when initialising WINS server.\n" ) ); kill_async_dns_child(); exit(1); } /* * Register nmbd primary workgroup and nmbd names on all * the broadcast subnets, and on the WINS server (if specified). * Also initiate the startup of our primary workgroup (start * elections if we are setup as being able to be a local * master browser. */ if( False == register_my_workgroup_and_names() ) { DEBUG(0,("ERROR: Failed when creating my my workgroup. Exiting.\n")); kill_async_dns_child(); exit(1); } /* We can only take signals in the select. */ BlockSignals( True, SIGTERM ); process(); if (dbf) x_fclose(dbf); kill_async_dns_child(); return(0); }
/* * The actual main function. */ int sntp_main ( int argc, char **argv, const char *sntpVersion ) { int i; int exitcode; int optct; struct event_config * evcfg; /* Initialize logging system - sets up progname */ sntp_init_logging(argv[0]); if (!libevent_version_ok()) exit(EX_SOFTWARE); init_lib(); init_auth(); optct = ntpOptionProcess(&sntpOptions, argc, argv); argc -= optct; argv += optct; debug = OPT_VALUE_SET_DEBUG_LEVEL; TRACE(2, ("init_lib() done, %s%s\n", (ipv4_works) ? "ipv4_works " : "", (ipv6_works) ? "ipv6_works " : "")); ntpver = OPT_VALUE_NTPVERSION; steplimit = OPT_VALUE_STEPLIMIT / 1e3; gap.tv_usec = max(0, OPT_VALUE_GAP * 1000); gap.tv_usec = min(gap.tv_usec, 999999); if (HAVE_OPT(LOGFILE)) open_logfile(OPT_ARG(LOGFILE)); msyslog(LOG_INFO, "%s", sntpVersion); if (0 == argc && !HAVE_OPT(BROADCAST) && !HAVE_OPT(CONCURRENT)) { printf("%s: Must supply at least one of -b hostname, -c hostname, or hostname.\n", progname); exit(EX_USAGE); } /* ** Eventually, we probably want: ** - separate bcst and ucst timeouts (why?) ** - multiple --timeout values in the commandline */ response_timeout = OPT_VALUE_TIMEOUT; response_tv.tv_sec = response_timeout; response_tv.tv_usec = 0; /* IPv6 available? */ if (isc_net_probeipv6() != ISC_R_SUCCESS) { ai_fam_pref = AF_INET; TRACE(1, ("No ipv6 support available, forcing ipv4\n")); } else { /* Check for options -4 and -6 */ if (HAVE_OPT(IPV4)) ai_fam_pref = AF_INET; else if (HAVE_OPT(IPV6)) ai_fam_pref = AF_INET6; } /* TODO: Parse config file if declared */ /* ** Init the KOD system. ** For embedded systems with no writable filesystem, ** -K /dev/null can be used to disable KoD storage. */ kod_init_kod_db(OPT_ARG(KOD), FALSE); // HMS: Should we use arg-defalt for this too? if (HAVE_OPT(KEYFILE)) auth_init(OPT_ARG(KEYFILE), &keys); /* ** Considering employing a variable that prevents functions of doing ** anything until everything is initialized properly ** ** HMS: What exactly does the above mean? */ event_set_log_callback(&sntp_libevent_log_cb); if (debug > 0) event_enable_debug_mode(); #ifdef WORK_THREAD evthread_use_pthreads(); /* we use libevent from main thread only, locks should be academic */ if (debug > 0) evthread_enable_lock_debuging(); #endif evcfg = event_config_new(); if (NULL == evcfg) { printf("%s: event_config_new() failed!\n", progname); return -1; } #ifndef HAVE_SOCKETPAIR event_config_require_features(evcfg, EV_FEATURE_FDS); #endif /* all libevent calls are from main thread */ /* event_config_set_flag(evcfg, EVENT_BASE_FLAG_NOLOCK); */ base = event_base_new_with_config(evcfg); event_config_free(evcfg); if (NULL == base) { printf("%s: event_base_new() failed!\n", progname); return -1; } /* wire into intres resolver */ worker_per_query = TRUE; addremove_io_fd = &sntp_addremove_fd; open_sockets(); if (HAVE_OPT(BROADCAST)) { int cn = STACKCT_OPT( BROADCAST ); const char ** cp = STACKLST_OPT( BROADCAST ); while (cn-- > 0) { handle_lookup(*cp, CTX_BCST); cp++; } } if (HAVE_OPT(CONCURRENT)) { int cn = STACKCT_OPT( CONCURRENT ); const char ** cp = STACKLST_OPT( CONCURRENT ); while (cn-- > 0) { handle_lookup(*cp, CTX_UCST | CTX_CONC); cp++; } } for (i = 0; i < argc; ++i) handle_lookup(argv[i], CTX_UCST); gettimeofday_cached(base, &start_tv); event_base_dispatch(base); event_base_free(base); if (!time_adjusted && (ENABLED_OPT(STEP) || ENABLED_OPT(SLEW))) exitcode = 1; else exitcode = 0; return exitcode; }
int main(int argc, char** argv) { int num_interfaces = 0; static struct debconfclient *client; static int requested_wireless_tools = 0; struct netcfg_interface interface; enum { BACKUP, GET_INTERFACE, GET_HOSTNAME_ONLY, GET_STATIC, WCONFIG, WCONFIG_ESSID, WCONFIG_WEP, QUIT} state = GET_INTERFACE; /* initialize libd-i */ di_system_init("netcfg-static"); if (strcmp(basename(argv[0]), "ptom") != 0) di_info("Starting netcfg v.%s (built %s)", NETCFG_VERSION, NETCFG_BUILD_DATE); parse_args(argc, argv); reap_old_files(); open_sockets(); /* initialize debconf */ client = debconfclient_new(); debconf_capb(client, "backup"); while (1) { switch(state) { case BACKUP: return 10; case GET_INTERFACE: if (netcfg_get_interface(client, &(interface.name), &num_interfaces, NULL)) state = BACKUP; else if (! interface.name || ! num_interfaces) state = GET_HOSTNAME_ONLY; else { if (is_wireless_iface(interface.name)) state = WCONFIG; else state = GET_STATIC; } break; case GET_HOSTNAME_ONLY: if(netcfg_get_hostname(client, "netcfg/get_hostname", hostname, 0)) state = BACKUP; else { netcfg_write_common("", hostname, NULL); return 0; } break; case GET_STATIC: if (netcfg_get_static(client, &interface)) state = (num_interfaces == 1) ? BACKUP : GET_INTERFACE; else state = QUIT; break; case WCONFIG: if (requested_wireless_tools == 0) { requested_wireless_tools = 1; di_exec_shell("apt-install wireless-tools"); } state = WCONFIG_ESSID; break; case WCONFIG_ESSID: if (netcfg_wireless_set_essid (client, &interface, NULL)) state = BACKUP; else state = WCONFIG_WEP; break; case WCONFIG_WEP: if (netcfg_wireless_set_wep (client, &interface)) state = WCONFIG_ESSID; else state = GET_STATIC; break; case QUIT: netcfg_update_entropy(); return 0; } } return 0; }
/**************************************************************************** main program ****************************************************************************/ int main(int argc,char *argv[]) { int opt; unsigned int lookup_type = 0x0; pstring lookup; extern int optind; extern char *optarg; BOOL find_master=False; int i; static pstring servicesf = CONFIGFILE; BOOL lookup_by_ip = False; DEBUGLEVEL = 1; /* Prevent smb.conf setting from overridding */ AllowDebugChange = False; *lookup = 0; TimeInit(); setup_logging(argv[0],True); charset_initialise(); while ((opt = getopt(argc, argv, "d:fB:U:i:s:SMrhART")) != EOF) switch (opt) { case 'B': bcast_addr = *interpret_addr2(optarg); got_bcast = True; use_bcast = True; break; case 'f': give_flags = True; break; case 'U': bcast_addr = *interpret_addr2(optarg); got_bcast = True; use_bcast = False; break; case 'T': translate_addresses = !translate_addresses; break; case 'i': { extern pstring global_scope; pstrcpy(global_scope,optarg); strupper(global_scope); } break; case 'M': find_master = True; break; case 'S': find_status = True; break; case 'R': recursion_desired = True; break; case 'd': DEBUGLEVEL = atoi(optarg); break; case 's': pstrcpy(servicesf, optarg); break; case 'r': RootPort = True; break; case 'h': usage(); exit(0); break; case 'A': lookup_by_ip = True; break; default: usage(); exit(1); } if (argc < 2) { usage(); exit(1); } if (!lp_load(servicesf,True,False,False)) { fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf); } load_interfaces(); if (!open_sockets()) return(1); for (i=optind;i<argc;i++) { char *p; struct in_addr ip; fstrcpy(lookup,argv[i]); if(lookup_by_ip) { fstrcpy(lookup,"*"); ip = *interpret_addr2(argv[i]); do_node_status(ServerFD, lookup, lookup_type, ip); continue; } if (find_master) { if (*lookup == '-') { fstrcpy(lookup,"\01\02__MSBROWSE__\02"); lookup_type = 1; } else { lookup_type = 0x1d; } } p = strchr(lookup,'#'); if (p) { *p = '\0'; sscanf(++p,"%x",&lookup_type); } if (!query_one(lookup, lookup_type)) { printf( "name_query failed to find name %s", lookup ); if( 0 != lookup_type ) printf( "#%02x", lookup_type ); printf( "\n" ); } } return(0); }