static void validate_int_var_ranges(fko_srv_options_t *opts) { #if FIREWALL_IPFW int is_err = FKO_SUCCESS; #endif range_check(opts, "PCAP_LOOP_SLEEP", opts->config[CONF_PCAP_LOOP_SLEEP], 1, RCHK_MAX_PCAP_LOOP_SLEEP); range_check(opts, "MAX_SPA_PACKET_AGE", opts->config[CONF_MAX_SPA_PACKET_AGE], 1, RCHK_MAX_SPA_PACKET_AGE); range_check(opts, "MAX_SNIFF_BYTES", opts->config[CONF_MAX_SNIFF_BYTES], 1, RCHK_MAX_SNIFF_BYTES); range_check(opts, "TCPSERV_PORT", opts->config[CONF_TCPSERV_PORT], 1, RCHK_MAX_TCPSERV_PORT); #if FIREWALL_IPFW range_check(opts, "IPFW_START_RULE_NUM", opts->config[CONF_IPFW_START_RULE_NUM], 0, RCHK_MAX_IPFW_START_RULE_NUM); range_check(opts, "IPFW_MAX_RULES", opts->config[CONF_IPFW_MAX_RULES], 1, RCHK_MAX_IPFW_MAX_RULES); range_check(opts, "IPFW_ACTIVE_SET_NUM", opts->config[CONF_IPFW_ACTIVE_SET_NUM], 0, RCHK_MAX_IPFW_SET_NUM); range_check(opts, "IPFW_EXPIRE_SET_NUM", opts->config[CONF_IPFW_EXPIRE_SET_NUM], 0, RCHK_MAX_IPFW_SET_NUM); range_check(opts, "IPFW_EXPIRE_PURGE_INTERVAL", opts->config[CONF_IPFW_EXPIRE_PURGE_INTERVAL], 1, RCHK_MAX_IPFW_PURGE_INTERVAL); /* Make sure the active and expire sets are not identical whenever * they are non-zero */ if((strtol_wrapper(opts->config[CONF_IPFW_ACTIVE_SET_NUM], 0, RCHK_MAX_IPFW_SET_NUM, NO_EXIT_UPON_ERR, &is_err) > 0 && strtol_wrapper(opts->config[CONF_IPFW_EXPIRE_SET_NUM], 0, RCHK_MAX_IPFW_SET_NUM, NO_EXIT_UPON_ERR, &is_err) > 0) && strtol_wrapper(opts->config[CONF_IPFW_ACTIVE_SET_NUM], 0, RCHK_MAX_IPFW_SET_NUM, NO_EXIT_UPON_ERR, &is_err) == strtol_wrapper(opts->config[CONF_IPFW_EXPIRE_SET_NUM], 0, RCHK_MAX_IPFW_SET_NUM, NO_EXIT_UPON_ERR, &is_err)) { log_msg(LOG_ERR, "[*] Cannot set identical ipfw active and expire sets."); clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE); } if(is_err != FKO_SUCCESS) { log_msg(LOG_ERR, "[*] invalid integer conversion error.\n"); clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE); } #elif FIREWALL_PF range_check(opts, "PF_EXPIRE_INTERVAL", opts->config[CONF_PF_EXPIRE_INTERVAL], 1, RCHK_MAX_PF_EXPIRE_INTERVAL); #endif /* FIREWALL type */ return; }
/* * main */ int main(int argc, char *argv[]) { int ret; char *user; progname = argv[0] ? argv[0] : "lttng"; /* For Mathieu Desnoyers a.k.a. Dr. Tracing */ user = getenv("USER"); if (user != NULL && ((strncmp(progname, "drtrace", 7) == 0 || strncmp("compudj", user, 7) == 0))) { MSG("%c[%d;%dmWelcome back Dr Tracing!%c[%dm\n", 27,1,33,27,0); } /* Thanks Mathieu */ ret = set_signal_handler(); if (ret < 0) { clean_exit(ret); } ret = parse_args(argc, argv); if (ret != 0) { clean_exit(ret); } return 0; }
char *handle_var(int state, char *key, char *value) { static char **keys = NULL; static char **values = NULL; int tmp; if (!keys && !values) { if (!(keys = malloc(sizeof(char*)))) clean_exit(8); keys[0] = NULL; if (!(values = malloc(sizeof(char*)))) clean_exit(8); values[0] = NULL; } if (state == KV_SET) return (handle_var_set(&keys, &values, key, value)); else if (state == KV_GET) { if ((tmp = search_key_values(keys, values, key)) == -1) return (NULL); return (values[tmp]); } else if (state == KV_DEL) return (delete_key(&keys, &values, key)); return (NULL); }
int unix_connect(void) { int fd; struct be_msg msg; struct sockaddr_un addr; if( (fd = socket(AF_LOCAL, SOCK_STREAM, 0)) < 0) clean_exit("Can't create client socket"); bzero(&addr, sizeof(addr)); addr.sun_family = AF_LOCAL; strncpy(addr.sun_path, BRPVC_SOCKPATH, sizeof(addr.sun_path) -1); if(connect(fd, (struct sockaddr *) &addr, sizeof(addr))) clean_exit("Can't connect to server"); bzero(&msg, sizeof(msg)); msg.msgtype = HELLO; if( send(fd, &msg, sizeof(msg), 0) < 0 ) clean_exit("Can't send HELLO message"); if( recv(fd, &msg, sizeof(msg), 0) <= 0 ) clean_exit("Can't receive receive OK response from server"); return fd; }
static void validate_vector_id(void) { int i; int vectors[MAX_NUM_VECTORS] = {0}; for (i = 0; i < genidt_header.num_entries; i++) { if (supplied_entry[i].vector_id == UNSPECIFIED_INT_VECTOR) { /* * Vector is to be allocated. No further validation to be * done at the moment. */ continue; } if (supplied_entry[i].vector_id >= num_vectors) { fprintf(stderr, "Vector ID exceeds specified # of vectors (%d).\n", num_vectors); show_entry(&supplied_entry[i]); clean_exit(-1); } if (vectors[supplied_entry[i].vector_id] != 0) { fprintf(stderr, "Duplicate vector ID found.\n"); show_entry(&supplied_entry[i]); clean_exit(-1); } vectors[supplied_entry[i].vector_id]++; } }
void load_data_v1(struct map_hdr_v1 *hdr, u_long index, u_long *buf, u_long *len) { char *compr_buf; char *exp_buf; int ret, items; uLongf destLen; if(hdr->map[index].exp_data) goto out; ret = fseek(vas_file_p, (long)((hdr->blk_offset + hdr->map[index].start_blk) * hdr->blk_size), SEEK_SET); if(ret == -1) { printf("load_data: unable to fseek, errno = %d\n", ferror(vas_file_p)); clean_exit(1); } compr_buf = (char *)malloc(2*hdr->va_per_entry); if(!compr_buf) { printf("load_data: bad ret from malloc, errno = %d\n", ferror(vas_file_p)); clean_exit(1); } items = fread((void *)compr_buf, sizeof(char), hdr->map[index].num_blks * hdr->blk_size, vas_file_p); if(items != hdr->map[index].num_blks * hdr->blk_size) { printf("unable to read blocks from errno = %d\n", ferror(vas_file_p)); clean_exit(1); } hdr->map[index].exp_data = exp_buf = (char *)malloc(hdr->va_per_entry); if(!exp_buf) { printf("load_data: bad ret from malloc, errno = %d\n", ferror(vas_file_p)); clean_exit(1); } destLen = (uLongf)(2*hdr->va_per_entry); ret = uncompress((Bytef *)exp_buf, &destLen, (const Bytef *)compr_buf, (uLong)items); /* if(destLen != hdr->va_per_entry) { printf("uncompress error\n"); exit(1); } */ if(ret) { if(ret == Z_MEM_ERROR) printf("load_data, bad ret Z_MEM_ERROR from uncompress\n"); else if(ret == Z_BUF_ERROR) printf("load_data, bad ret Z_BUF_ERROR from uncompress\n"); else if(ret == Z_DATA_ERROR) printf("load_data, bad ret Z_DATA_ERROR from uncompress\n"); else printf("load_data, bad ret %d from uncompress\n", ret); clean_exit(1); } free((void *)compr_buf); out: if(buf) *buf = (u_long)hdr->map[index].exp_data; if(len) *len = hdr->va_per_entry; return; }
/* Become a daemon: fork(), start a new session, chdir "/", * and close unneeded standard filehandles. */ static void daemonize_process(fko_srv_options_t * const opts) { pid_t pid, old_pid; /* Reset the our umask */ umask(0); if ((pid = fork()) < 0) { perror("Unable to fork: "); clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE); } else if (pid != 0) /* parent */ { clean_exit(opts, NO_FW_CLEANUP, EXIT_SUCCESS); } /* Child process from here on out */ /* Start a new session */ setsid(); //子进程成立新回话。 /* Create the PID file (or be blocked by an existing one). */ old_pid = write_pid_file(opts); if(old_pid > 0) { fprintf(stderr, "[*] An instance of fwknopd is already running: (PID=%i).\n", old_pid ); clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE); } else if(old_pid < 0) { fprintf(stderr, "[*] PID file error. The lock may not be effective.\n"); } /* Chdir to the root of the filesystem */ if ((chdir("/")) < 0) { perror("Could not chdir() to /: "); clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE); } /* Close un-needed file handles */ close(STDIN_FILENO); close(STDOUT_FILENO); close(STDERR_FILENO); return; }
/* * Initialize torsocks configuration from a given conf file or the default one. */ static void init_config(void) { int ret; const char *filename = NULL; if (!is_suid) { filename = getenv("TORSOCKS_CONF_FILE"); } ret = config_file_read(filename, &tsocks_config); if (ret < 0) { /* * Failing to get the configuration means torsocks can not function * properly so stops everything. */ clean_exit(EXIT_FAILURE); } /* * Setup configuration from config file. Use defaults if some attributes * are missing. */ if (!tsocks_config.conf_file.tor_address) { tsocks_config.conf_file.tor_address = strdup(DEFAULT_TOR_ADDRESS); if (!tsocks_config.conf_file.tor_address) { /* Most likely ENOMEM thus we can't continue. */ clean_exit(EXIT_FAILURE); } } if (tsocks_config.conf_file.tor_port == 0) { tsocks_config.conf_file.tor_port = DEFAULT_TOR_PORT; } if (tsocks_config.conf_file.tor_domain == 0) { tsocks_config.conf_file.tor_domain = DEFAULT_TOR_DOMAIN; } if (tsocks_config.conf_file.onion_base == 0) { tsocks_config.conf_file.onion_base = inet_addr(DEFAULT_ONION_ADDR_RANGE); tsocks_config.conf_file.onion_mask = atoi(DEFAULT_ONION_ADDR_MASK); } /* Create the Tor SOCKS5 connection address. */ ret = connection_addr_set(tsocks_config.conf_file.tor_domain, tsocks_config.conf_file.tor_address, tsocks_config.conf_file.tor_port, &tsocks_config.socks5_addr); if (ret < 0) { /* * Without a valid connection address object to Tor well torsocks can't * work properly at all so abort everything. */ clean_exit(EXIT_FAILURE); } /* Handle possible env. variables. */ read_env(); }
static void afl_pkt_from_stdin(fko_srv_options_t *opts) { FILE *fp = NULL; fko_ctx_t decode_ctx = NULL; unsigned char spa_pkt[AFL_MAX_PKT_SIZE] = {0}; int res = 0, es = EXIT_SUCCESS; char dump_buf[AFL_DUMP_CTX_SIZE]; fp = fdopen(STDIN_FILENO, "r"); if(fp != NULL) { if(fgets((char *)spa_pkt, AFL_MAX_PKT_SIZE, fp) == NULL) { fclose(fp); clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE); } fclose(fp); fko_new(&decode_ctx); res = fko_set_encoded_data(decode_ctx, (char *) spa_pkt, strlen((char *)spa_pkt), 0, FKO_DIGEST_SHA256); if(res == FKO_SUCCESS) res = fko_set_spa_data(decode_ctx, (const char *) spa_pkt); if(res == FKO_SUCCESS) res = fko_decode_spa_data(decode_ctx); if(res == FKO_SUCCESS) res = dump_ctx_to_buffer(decode_ctx, dump_buf, sizeof(dump_buf)); if(res == FKO_SUCCESS) log_msg(LOG_INFO, "%s", dump_buf); fko_destroy(decode_ctx); if(res == FKO_SUCCESS) { log_msg(LOG_INFO, "SPA packet decode: %s", fko_errstr(res)); es = EXIT_SUCCESS; } else { log_msg(LOG_ERR, "Could not decode SPA packet: %s", fko_errstr(res)); es = EXIT_FAILURE; } } else log_msg(LOG_ERR, "Could not acquire SPA packet from stdin."); clean_exit(opts, NO_FW_CLEANUP, es); }
static void twist_option(char *value, struct request_info *request) { if (dry_run != 0) { dry_run = 0; } else { if (resident > 0) tcpd_jump("twist option in resident process"); syslog(deny_severity, "twist %s to %s", eval_client(request), value); /* Before switching to the shell, set up stdin, stdout and stderr. */ #define maybe_dup2(from, to) ((from == to) ? to : (close(to), dup(from))) if (maybe_dup2(request->fd, 0) != 0 || maybe_dup2(request->fd, 1) != 1 || maybe_dup2(request->fd, 2) != 2) { tcpd_warn("twist_option: dup: %m"); } else { if (request->fd > 2) close(request->fd); (void) execl("/bin/sh", "sh", "-c", value, (char *) 0); tcpd_warn("twist_option: /bin/sh: %m"); } /* Something went wrong: we MUST terminate the process. */ clean_exit(request); } }
/**************************************************************************** * Makes a utmp entry ***************************************************************************/ void makeutent(char *ttyname) { struct passwd *pwent; struct utmp u; pwent=getpwuid(getuid()); /* Prevent crashing when password file is readonly :) */ if (pwent == NULL) { fprintf( stderr, "Could not read password file entry.\n" ); clean_exit(1); } memset((char *)&u, 0, sizeof(u)); /* memset? never heard of it :-) thanks Brian */ #ifndef SVR4 strcpy(u.ut_host,"\0"); /* Needs to be this way for Linux */ #endif /* and now the line: */ strcpy(u.ut_line,ttyname); /* This works at the moment. I don't think that ttyname is NULL terminated, so something more elaborate may need to be done. */ time(&u.ut_time); strncpy(u.ut_user,pwent->pw_name,sizeof(u.ut_user)); u.ut_type = USER_PROCESS; u.ut_pid = getpid(); strncpy(u.ut_id,(ttyname+3),2); // regain root privileges seteuid(0); (void) write_utmp(&u); // drop root privileges again seteuid(getuid()); }
/**************************************************************************** * Makes a utmp entry ***************************************************************************/ void makeutent(char *ttyname) { struct passwd *pwent; struct utmp u; struct timeval tp; struct timezone tzp; int l,l2; extern char *display_name; pwent=getpwuid(getuid()); /* Prevent crashing when password file is readonly :) */ if (pwent == NULL) { fprintf( stderr, "Could not read password file entry.\n" ); clean_exit(1); } memset((char *)&u, 0, sizeof(u)); /* memset? never heard of it :-) thanks Brian */ #ifndef SVR4 l = sizeof(u.ut_host); strncpy(u.ut_host,display_name,l); #endif /* and now the line: */ l = sizeof(u.ut_line); strncpy(u.ut_line,ttyname,l); if (!gettimeofday(&tp,&tzp)) u.ut_time = tp.tv_sec; strncpy(u.ut_name,pwent->pw_name,sizeof(u.ut_name)); (void) write_utmp(ttyname, &u); }
/* * raise an error */ void error_msg(char *file, const char *function, int line, char *message, ...) { va_list ap; char errmsg[ERROR_MSG_LEN + 1]; /* should be enough */ int err_code; #ifdef OS_WINDOWS err_code = GetLastError(); /* Most likely not a libc error */ if (err_code == 0) err_code = errno; #else err_code = errno; #endif va_start(ap, message); vsnprintf(errmsg, ERROR_MSG_LEN, message, ap); va_end(ap); DEBUG_MSG("ERROR : %d, %s\n[%s:%s:%d] %s \n", err_code, strerror(err_code), file, function, line, errmsg ); /* close the interface and display the error */ ui_cleanup(); fprintf(stderr, "ERROR : %d, %s\n[%s:%s:%d]\n\n %s \n\n", err_code, strerror(err_code), file, function, line, errmsg ); clean_exit(-err_code); }
// Get info about the next packet to send packet_info packet_buffer_front(void) { packet_info result; static char * lastAddress = NULL; char * thisAddress = packet_buffer_head->buffer + packet_buffer_index; if (packet_buffer_head == NULL) { printf("packet_buffer_head == NULL in front\n"); clean_exit(1); } else { read_packet_info(&result, packet_buffer_head->buffer + packet_buffer_index); } if (thisAddress != lastAddress) { logWrite(PACKET_BUFFER_DETAIL, NULL, "Looking at packet: type(%hu) value(%lu) delta(%lu) " "source_port(%hu) dest_port(%hu) ip(%s)", result.type, result.value, result.delta, result.source_port, result.dest_port, ipToString(result.ip)); } lastAddress = thisAddress; return result; }
/* * amiopenwin - opens a window if we don't already have one. */ void amiopenwin(char *termtype) { if (!IsInteractive(Input())) { /* open our own window in RAW mode */ if (isOldDOS() || (BPTR) 0 == (fh = Open(title, MODE_READWRITE))) { PutStr((UBYTE *) "Couldn't open RAW: window"); clean_exit(2); } else { oldinputFH = SelectInput(fh); oldoutputFH = SelectOutput(fh); } } inputFH = Input(); outputFH = Output(); if (!strcmp(termtype, TERMTYPE)) { amigaterm = 1; Write(outputFH, AUTOWRAP_OFF, sizeof(AUTOWRAP_OFF)); } return; }
/* * Test the data bus wiring in a memory region by performing a walking 1's * test at a fixed address within that region. The address (and hence * the memory region) is selected by the caller. * * Returns: 0 if the test succeeds. * -1 if the test fails. */ int test_data_bus(unsigned long base_addr) { unsigned long readback; unsigned long pattern; int error = 0; printf(" Test data bus at address 0x%.8lX\n", base_addr); for (pattern = 1; pattern != 0; pattern <<= 1) { if (bdmWriteLongWord(base_addr, pattern) < 0) show_error(" Write pattern in test_data_bus()"); /* * Immediate read back is okay for this test */ if (bdmReadLongWord(base_addr, &readback) < 0) show_error(" Readback in test_data_bus()"); if (readback!= pattern) { printf(" Readback failed; expected 0x%.8lX readback 0x%.8lX\n", pattern, readback); error = -1; if (stop_on_error) clean_exit(1); } } return (error); }
/* * sighandler * * Signal handler for the daemon */ static void sighandler(int sig) { int status; switch (sig) { case SIGTERM: DBG("SIGTERM caught"); clean_exit(EXIT_FAILURE); break; case SIGCHLD: DBG("SIGCHLD caught"); waitpid(sessiond_pid, &status, 0); recv_child_signal = 1; /* Indicate that the session daemon died */ sessiond_pid = 0; ERR("Session daemon died (exit status %d)", WEXITSTATUS(status)); break; case SIGUSR1: /* Notify is done */ recv_child_signal = 1; DBG("SIGUSR1 caught"); break; default: DBG("Unknown signal %d caught", sig); break; } return; }
int gerer_clavier(int keycode, void *param) { t_infos_mlx *infos_mlx; infos_mlx = param; if (keycode == 65307) clean_exit(infos_mlx); else if (keycode == 65363) move_right_map(infos_mlx); else if (keycode == 65361) move_left_map(infos_mlx); else if (keycode == 65362) move_up_map(infos_mlx); else if (keycode == 65364) move_down_map(infos_mlx); else if (keycode == 65451) zoom_map(infos_mlx, 1); else if (keycode == 65453) zoom_map(infos_mlx, 0); else if (keycode == 114) rot_map(infos_mlx); else if (keycode == 116) little_rot_map(infos_mlx); return (0); }
void considerExitingEndOfPass() { if (exit_end_of_pass) { if (!ignore_errors) { clean_exit(1); } } }
int main(int argc, char *argv[]) { startCatchingSignals(); { astlocMarker markAstLoc(0, "<internal>"); initFlags(); initChplProgram(); initPrimitive(); initPrimitiveTypes(); initTheProgram(); setupOrderedGlobals(argv[0]); compute_program_name_loc(argv[0], &(arg_state.program_name), &(arg_state.program_loc)); process_args(&arg_state, argc, argv); initCompilerGlobals(); // must follow argument parsing setupDependentVars(); setupModulePaths(); recordCodeGenStrings(argc, argv); } // astlocMarker scope printStuff(argv[0]); if (rungdb) runCompilerInGDB(argc, argv); if (fdump_html || strcmp(log_flags, "")) init_logs(); compile_all(); if (fEnableTimers) { printf("timer 1: %8.3lf\n", timer1.elapsed()); printf("timer 2: %8.3lf\n", timer2.elapsed()); printf("timer 3: %8.3lf\n", timer3.elapsed()); printf("timer 4: %8.3lf\n", timer4.elapsed()); printf("timer 5: %8.3lf\n", timer5.elapsed()); } free_args(&arg_state); clean_exit(0); return 0; }
static void vhandleError(FILE* file, BaseAST* ast, const char *fmt, va_list args) { if (err_ignore) return; bool guess = false; if (file == stderr) guess = printErrorHeader(ast); if (err_user || developer) { vfprintf(file, fmt, args); } if (fPrintIDonError && ast) fprintf(file, " [%d]", ast->id); if (file == stderr) printErrorFooter(guess); fprintf(file, "\n"); if (file == stderr) printCallStackOnError(); if (!err_user && !developer) return; if (exit_immediately) { if (ignore_errors_for_pass) { exit_end_of_pass = true; } else if (!ignore_errors) { clean_exit(1); } } }
static void runCompilerInLLDB(int argc, char* argv[]) { const char* lldbCommandFilename = createDebuggerFile("lldb", argc, argv); const char* command = astr("lldb -s ", lldbCommandFilename, " ", argv[0]); int status = mysystem(command, "running lldb", false); clean_exit(status); }
static void runCompilerInGDB(int argc, char* argv[]) { const char* gdbCommandFilename = createGDBFile(argc, argv); const char* command = astr("gdb -q ", argv[0]," -x ", gdbCommandFilename); int status = mysystem(command, "running gdb", 0); clean_exit(status); }
/* Catch a fatal signal and tidy up before quitting */ static void catch_sig(int sig) { signal(sig,SIG_DFL); clean_exit(-1); setuid(getuid()); kill(getpid(),sig); }
/* Initialise the command connection. This should be called after the X * server connection is established. */ void init_command(unsigned char *command,unsigned char **argv) { #ifdef GREEK_KBD greek_init(GreekMode); /*atexit(greek_end); not necessary */ #endif /* Enable the delete window protocol. */ wm_del_win = XInternAtom(display,"WM_DELETE_WINDOW",False); XSetWMProtocols(display,main_win,&wm_del_win,1); if ((comm_fd = run_command(command,argv)) < 0) { error("Quitting"); clean_exit(1); } x_fd = XConnectionNumber(display); #if defined(_HPUX_SOURCE) || defined(__Lynx__) fd_width = sysconf(_SC_OPEN_MAX); #else fd_width = getdtablesize(); #endif com_buf_next = com_buf_top = com_buf; }
/* * received on CTRL+C or SIGTERM */ static void signal_TERM(int sig) { #ifdef HAVE_STRSIGNAL DEBUG_MSG("Signal handler... (caught SIGNAL: %d) | %s", sig, strsignal(sig)); #else DEBUG_MSG("Signal handler... (caught SIGNAL: %d)", sig); #endif /* terminate the UI */ ui_cleanup(); if (sig == SIGINT) { fprintf(stderr, "\n\nUser requested a CTRL+C... (deprecated, next time use proper shutdown)\n\n"); } else { #ifdef HAVE_STRSIGNAL fprintf(stderr, "\n\n Shutting down %s (received SIGNAL: %d | %s)\n\n", GBL_PROGRAM, sig, strsignal(sig)); #else fprintf(stderr, "\n\n Shutting down %s (received SIGNAL: %d)\n\n", GBL_PROGRAM, sig); #endif } signal(sig, SIG_IGN); /* flush and close the log file */ log_stop(); /* make sure we exit gracefully */ clean_exit(0); }
void considerExitingEndOfPass() { if (exit_end_of_pass) { if (!ignore_errors && !(ignore_user_errors && err_user)) { clean_exit(1); } } }
/* * Lib constructor. Initialize torsocks here before the main execution of the * binary we are preloading. */ static void __attribute__((constructor)) tsocks_init(void) { int ret; /* UID and effective UID MUST be the same or else we are SUID. */ is_suid = (getuid() != geteuid()); init_logging(); /* * We need to save libc symbols *before* we override them so torsocks can * use the original libc calls. */ init_libc_symbols(); /* * Read configuration file and set the global config. */ init_config(); /* Initialize connection reigstry. */ connection_registry_init(); /* * Initalized the onion pool which maps cookie address to hidden service * onion address. */ ret = onion_pool_init(&tsocks_onion_pool, tsocks_config.conf_file.onion_base, tsocks_config.conf_file.onion_mask); if (ret < 0) { clean_exit(EXIT_FAILURE); } }
/* * Read SOCKS5 username and password environment variable and if found set them * in the configuration. If we are setuid, return gracefully. */ static void read_env(void) { int ret; const char *username, *password, *allow_in, *isolate_pid; if (is_suid) { goto end; } allow_in = getenv(DEFAULT_ALLOW_INBOUND_ENV); if (allow_in) { ret = conf_file_set_allow_inbound(allow_in, &tsocks_config); if (ret < 0) { goto error; } } isolate_pid = getenv(DEFAULT_ISOLATE_PID_ENV); if (isolate_pid) { ret = conf_file_set_isolate_pid(isolate_pid, &tsocks_config); if (ret < 0) { goto error; } } username = getenv(DEFAULT_SOCKS5_USER_ENV); password = getenv(DEFAULT_SOCKS5_PASS_ENV); if (!username && !password) { goto end; } /* * Only set the values if they were provided. It's possible that a user * wants to only set one of the values through an env. variable and the * other through the configuration file. */ if (username) { ret = conf_file_set_socks5_user(username, &tsocks_config); if (ret < 0) { goto error; } } if (password) { ret = conf_file_set_socks5_pass(password, &tsocks_config); if (ret < 0) { goto error; } } end: return; error: /* * Error while setting user/pass variable. Stop everything so the user can * be notified and fix the issue. */ clean_exit(EXIT_FAILURE); }
static void handleInterrupt(int sig) { stopCatchingSignals(); fprintf(stderr, "error: received interrupt\n"); fflush(stdout); fflush(stderr); clean_exit(1); }