void tls_user_start_servers(GSList *servers) { char **user_servers; int i; nuauthdatas->tls_auth_servers = NULL; tls_user_servers_init(); /* get raw string from configuration */ user_servers = g_strsplit(nuauthconf->client_srv, " ", 0); for (i=0; user_servers[i]; i++) { /** \todo free context at program exit */ struct tls_user_context_t *context = g_new0(struct tls_user_context_t, 1); struct nuauth_thread_t *srv_thread = g_new0(struct nuauth_thread_t, 1); if (!parse_addr_port(user_servers[i], nuauthconf->userpckt_port, &context->addr, &context->port)) { log_message(FATAL, DEBUG_AREA_MAIN | DEBUG_AREA_USER, "Address parsing error at %s:%d (\"%s\")", __FILE__, __LINE__, user_servers[i]); nuauth_ask_exit(); } log_message(INFO, DEBUG_AREA_MAIN | DEBUG_AREA_USER, "Creating user socket %s:%s", context->addr, context->port); thread_new_wdata(srv_thread, "tls auth server", (gpointer) context, tls_user_authsrv); /* Append newly created server to list */ nuauthdatas->tls_auth_servers = g_slist_prepend(nuauthdatas->tls_auth_servers, srv_thread); } g_strfreev(user_servers); }
/** Entry point to tor-resolve */ int main(int argc, char **argv) { uint32_t sockshost; uint16_t socksport; int isSocks4 = 0, isVerbose = 0, isReverse = 0, force = 0; char **arg; int n_args; struct in_addr a; uint32_t result = 0; char *result_hostname = NULL; char buf[INET_NTOA_BUF_LEN]; init_logging(); arg = &argv[1]; n_args = argc-1; if (!n_args) usage(); if (!strcmp(arg[0],"--version")) { printf("Tor version %s.\n",VERSION); return 0; } while (n_args && *arg[0] == '-') { if (!strcmp("-v", arg[0])) isVerbose = 1; else if (!strcmp("-4", arg[0])) isSocks4 = 1; else if (!strcmp("-5", arg[0])) isSocks4 = 0; else if (!strcmp("-x", arg[0])) isReverse = 1; else if (!strcmp("-F", arg[0])) force = 1; else { fprintf(stderr, "Unrecognized flag '%s'\n", arg[0]); usage(); } ++arg; --n_args; } if (isSocks4 && isReverse) { fprintf(stderr, "Reverse lookups not supported with SOCKS4a\n"); usage(); } if (isVerbose) { add_stream_log(LOG_DEBUG, LOG_ERR, "<stderr>", stderr); } else { add_stream_log(LOG_WARN, LOG_ERR, "<stderr>", stderr); } if (n_args == 1) { log_debug(LD_CONFIG, "defaulting to localhost:9050"); sockshost = 0x7f000001u; /* localhost */ socksport = 9050; /* 9050 */ } else if (n_args == 2) { if (parse_addr_port(LOG_WARN, arg[1], NULL, &sockshost, &socksport)<0) { fprintf(stderr, "Couldn't parse/resolve address %s", arg[1]); return 1; } if (socksport == 0) { log_debug(LD_CONFIG, "defaulting to port 9050"); socksport = 9050; } } else { usage(); } if (!strcasecmpend(arg[0], ".onion") && !force) { fprintf(stderr, "%s is a hidden service; those don't have IP addresses.\n\n" "To connect to a hidden service, you need to send the hostname\n" "to Tor; we suggest an application that uses SOCKS 4a.\n", arg[0]); return 1; } if (network_init()<0) { log_err(LD_BUG,"Error initializing network; exiting."); return 1; } if (do_resolve(arg[0], sockshost, socksport, isReverse, isSocks4 ? 4 : 5, &result, &result_hostname)) return 1; if (result_hostname) { printf("%s\n", result_hostname); } else { a.s_addr = htonl(result); tor_inet_ntoa(&a, buf, sizeof(buf)); printf("%s\n", buf); } return 0; }
/** Entry point to tor-resolve */ int main(int argc, char **argv) { uint32_t sockshost; uint16_t socksport = 0, port_option = 0; int isSocks4 = 0, isVerbose = 0, isReverse = 0, force = 0; char **arg; int n_args; struct in_addr a; uint32_t result = 0; char *result_hostname = NULL; char buf[INET_NTOA_BUF_LEN]; log_severity_list_t *s = tor_malloc_zero(sizeof(log_severity_list_t)); init_logging(); arg = &argv[1]; n_args = argc-1; if (!n_args) usage(); if (!strcmp(arg[0],"--version")) { printf("Tor version %s.\n",VERSION); return 0; } while (n_args && *arg[0] == '-') { if (!strcmp("-v", arg[0])) isVerbose = 1; else if (!strcmp("-4", arg[0])) isSocks4 = 1; else if (!strcmp("-5", arg[0])) isSocks4 = 0; else if (!strcmp("-x", arg[0])) isReverse = 1; else if (!strcmp("-F", arg[0])) force = 1; else if (!strcmp("-p", arg[0])) { int p; if (n_args < 2) { fprintf(stderr, "No arguments given to -p\n"); usage(); } p = atoi(arg[1]); if (p<1 || p > 65535) { fprintf(stderr, "-p requires a number between 1 and 65535\n"); usage(); } port_option = (uint16_t) p; ++arg; /* skip the port */ --n_args; } else { fprintf(stderr, "Unrecognized flag '%s'\n", arg[0]); usage(); } ++arg; --n_args; } if (isSocks4 && isReverse) { fprintf(stderr, "Reverse lookups not supported with SOCKS4a\n"); usage(); } if (isVerbose) set_log_severity_config(LOG_DEBUG, LOG_ERR, s); else set_log_severity_config(LOG_WARN, LOG_ERR, s); add_stream_log(s, "<stderr>", fileno(stderr)); if (n_args == 1) { log_debug(LD_CONFIG, "defaulting to localhost"); sockshost = 0x7f000001u; /* localhost */ if (port_option) { log_debug(LD_CONFIG, "Using port %d", (int)port_option); socksport = port_option; } else { log_debug(LD_CONFIG, "defaulting to port 9050"); socksport = 9050; /* 9050 */ } } else if (n_args == 2) { if (parse_addr_port(LOG_WARN, arg[1], NULL, &sockshost, &socksport)<0) { fprintf(stderr, "Couldn't parse/resolve address %s", arg[1]); return 1; } if (socksport && port_option && socksport != port_option) { log_warn(LD_CONFIG, "Conflicting ports; using %d, not %d", (int)socksport, (int)port_option); } else if (port_option) { socksport = port_option; } else if (!socksport) { log_debug(LD_CONFIG, "defaulting to port 9050"); socksport = 9050; } } else { usage(); } if (network_init()<0) { log_err(LD_BUG,"Error initializing network; exiting."); return 1; } if (do_resolve(arg[0], sockshost, socksport, isReverse, isSocks4 ? 4 : 5, &result, &result_hostname)) return 1; if (result_hostname) { printf("%s\n", result_hostname); } else { a.s_addr = htonl(result); tor_inet_ntoa(&a, buf, sizeof(buf)); printf("%s\n", buf); } return 0; }
/** Read the command line options from <b>argc</b> and <b>argv</b>, * setting global option vars as needed. */ static int parse_commandline(int argc, char **argv) { int i; log_severity_list_t s; for (i = 1; i < argc; ++i) { if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) { show_help(); return 1; } else if (!strcmp(argv[i], "-i")) { if (i+1>=argc) { fprintf(stderr, "No argument to -i\n"); return 1; } identity_key_file = tor_strdup(argv[++i]); } else if (!strcmp(argv[i], "-s")) { if (i+1>=argc) { fprintf(stderr, "No argument to -s\n"); return 1; } signing_key_file = tor_strdup(argv[++i]); } else if (!strcmp(argv[i], "-c")) { if (i+1>=argc) { fprintf(stderr, "No argument to -c\n"); return 1; } certificate_file = tor_strdup(argv[++i]); } else if (!strcmp(argv[i], "-m")) { if (i+1>=argc) { fprintf(stderr, "No argument to -m\n"); return 1; } months_lifetime = atoi(argv[++i]); if (months_lifetime > 24 || months_lifetime < 0) { fprintf(stderr, "Lifetime (in months) was out of range."); return 1; } } else if (!strcmp(argv[i], "-r") || !strcmp(argv[i], "--reuse")) { reuse_signing_key = 1; } else if (!strcmp(argv[i], "-v")) { verbose = 1; } else if (!strcmp(argv[i], "-a")) { uint32_t addr; uint16_t port; char b[INET_NTOA_BUF_LEN]; struct in_addr in; if (i+1>=argc) { fprintf(stderr, "No argument to -a\n"); return 1; } if (parse_addr_port(LOG_ERR, argv[++i], NULL, &addr, &port)<0) return 1; in.s_addr = htonl(addr); tor_inet_ntoa(&in, b, sizeof(b)); address = tor_malloc(INET_NTOA_BUF_LEN+32); tor_snprintf(address, INET_NTOA_BUF_LEN+32, "%s:%d", b, (int)port); } else if (!strcmp(argv[i], "--create-identity-key")) { make_new_id = 1; } else if (!strcmp(argv[i], "--passphrase-fd")) { if (i+1>=argc) { fprintf(stderr, "No argument to --passphrase-fd\n"); return 1; } passphrase_fd = atoi(argv[++i]); } else { fprintf(stderr, "Unrecognized option %s\n", argv[i]); return 1; } } memset(&s, 0, sizeof(s)); if (verbose) set_log_severity_config(LOG_DEBUG, LOG_ERR, &s); else set_log_severity_config(LOG_WARN, LOG_ERR, &s); add_stream_log(&s, "<stderr>", fileno(stderr)); if (!identity_key_file) { identity_key_file = tor_strdup("./authority_identity_key"); log_info(LD_GENERAL, "No identity key file given; defaulting to %s", identity_key_file); } if (!signing_key_file) { signing_key_file = tor_strdup("./authority_signing_key"); log_info(LD_GENERAL, "No signing key file given; defaulting to %s", signing_key_file); } if (!certificate_file) { certificate_file = tor_strdup("./authority_certificate"); log_info(LD_GENERAL, "No signing key file given; defaulting to %s", certificate_file); } if (passphrase_fd >= 0) { if (load_passphrase()<0) return 1; } return 0; }
int main(int argc, char *argv[]) { int server_port = 2121; if (argc < 2) { printf("usage: %s <addr> [2121]\n", argv[0]); exit(0); } if (argc == 3) { server_port = atoi(argv[2]); } int client = new_client(ntohl(inet_addr(argv[1])), server_port); if (client < 0) { err(1, "can not connect to %s %d", argv[1], server_port); err(1, "exit ..."); exit(1); } int i, n; char buf[BUF_SIZE+1]; char tmpbuf[BUF_SIZE+1]; char cmdbuf[BUF_SIZE+1]; int data_client = -1; struct sockaddr_in data_client_addr; uint32_t addr; uint16_t port; char path[BUF_SIZE]; int code = -1; enum CLIENT_STATE state = ST_NONE; char filename[BUF_SIZE], line[BUF_SIZE]; while ((n=recv(client, buf, sizeof(buf), MSG_PEEK)) > 0) { if (!running) break; for (i=0; i<n; i++) { if (buf[i] == '\n') break; } if (buf[i] != '\n') { err(1, "no line break found"); break; } n = recv(client, buf, i+1, 0); buf[n] = 0; printf("%s", buf); fflush(stdout); parse_number(buf, &code); if (code < RPL_ERR_UNKWNCMD && state != ST_NONE) { switch(state) { case ST_PASVLIST: case ST_PASVGET: case ST_PASVPUT: if (code == RPL_PASVOK) { strcpy(tmpbuf, buf); tmpbuf[0] = tmpbuf[1] = tmpbuf[2] = tmpbuf[3] = ' '; parse_addr_port(tmpbuf, &addr, &port); switch(state) { case ST_PASVLIST: send_str(client, "LIST\r\n"); break; case ST_PASVGET: send_str(client, "RETR %s\r\n", filename); break; case ST_PASVPUT: send_str(client, "STOR %s\r\n", filename); break; } data_client = new_client(addr, port); state++; } else { state = ST_NONE; } break; case ST_PASVLIST2: case ST_PASVGET2: case ST_PASVPUT2: if (data_client < 0) { err(1, "data client not created"); } else { if (state == ST_PASVLIST2) { recv_file(data_client, stdout); } else if (state == ST_PASVGET2) { recv_path(data_client, filename, 0); } else if (state == ST_PASVPUT2) { FILE *f = fopen(filename, "rb"); if (f) { send_file(data_client, f); fclose(f); } else { err(1, "err open file %s", filename); } } info(1, "closing data socket ... %d", close(data_client)); data_client = -1; state = ST_NONE; } break; default: state = ST_NONE; break; } if (code < RPL_ERR_UNKWNCMD) continue; } if (code >= RPL_ERR_UNKWNCMD) state = ST_NONE; int valid = 0; while (!valid) { valid = 1; printf("ftp >>> "); if (!fgets(line, BUF_SIZE, stdin)){ running = 0; break; } int len = strlen(line); len --; while (line[len] == '\n' || line[len] == '\r') len--; len ++; line[len] = 0; enum USER_CMD cmd = parse_input_cmd(line, len); switch(cmd) { case USER_USER: case USER_PASS: case USER_TYPE: case USER_MKD: case USER_DELE: case USER_RNFR: case USER_RNTO: case USER_RMD: send_str(client, "%s\r\n", line); break; case USER_LS: send_str(client, "PASV\r\n"); state = ST_PASVLIST; break; case USER_CD: send_str(client, "CWD %s\r\n", &line[3]); break; case USER_PWD: send_str(client, "PWD\r\n"); break; case USER_CDUP: send_str(client, "CDUP\r\n"); break; case USER_HELP: for (i=0; i<sizeof(USER_CMD_LIST)/sizeof(USER_CMD_LIST[0]); i++) { printf("%s\n", USER_CMD_LIST[i].name); } valid = 0; break; case USER_BYE: send_str(client, "QUIT\r\n"); running = 0; break; case USER_LCD: chdir(&line[4]); valid = 0; break; case USER_LLS: getcwd(path, sizeof(path)); printf("%s\n", path); sprintf(cmdbuf, "ls -l %s", path); FILE *p2 = popen(cmdbuf, "r"); int n; while ((n=fread(tmpbuf, 1, BUF_SIZE, p2)) > 0 ) { fwrite(tmpbuf, 1, n, stdout); } pclose(p2); valid = 0; break; case USER_LPWD: getcwd(path, sizeof(path)); printf("%s\n", path); valid = 0; break; case USER_GET: send_str(client, "PASV\r\n"); strcpy(filename, &line[4]); state = ST_PASVGET; break; case USER_PUT: send_str(client, "PASV\r\n"); strcpy(filename, &line[4]); state = ST_PASVPUT; break; default: warn(1, "unknown user cmd"); valid = 0; break; } } if (!running) break; } int st = close(client); info(1, "FTP client close socket ... %d", st); info(1, "FTP client shutdown"); if (data_client > 0) { st = close(data_client); info(1, "FTP client close data socket ... %d", st); info(1, "FTP client data socket shutdown"); } return 0; }
/** Entry point to tor-resolve */ int main(int argc, char **argv) { uint32_t sockshost; uint16_t socksport; int isSocks4 = 0, isReverse = 0; char **arg; int n_args; uint32_t result = 0; char *result_hostname = NULL; char *hostname = NULL, *filename = NULL; size_t expbytes = 0; signal(SIGINT, termination_handler); arg = &argv[1]; n_args = argc-1; if (!n_args) usage(); if (!strcmp(arg[0],"--version")) { printf("Tor version 0.1\n"); return 0; } while (n_args && *arg[0] == '-') { if (!strcmp("-4", arg[0])) isSocks4 = 1; else if (!strcmp("-5", arg[0])) isSocks4 = 0; else if (!strcmp("-x", arg[0])) isReverse = 1; else { fprintf(stderr, "Unrecognized flag '%s'\n", arg[0]); usage(); } ++arg; --n_args; } if (isSocks4 && isReverse) { fprintf(stderr, "Reverse lookups not supported with SOCKS4a\n"); usage(); } if (n_args == 3) { fprintf(stderr,"defaulting to localhost:9050\n"); sockshost = 0x7f000001u; /* localhost */ socksport = 9050; /* 9050 */ hostname = arg[0]; filename = arg[1]; expbytes = (size_t) parse_long(arg[2], 10, 0, 1024*1024*1024, NULL, NULL); } else if (n_args == 4) { if (parse_addr_port(0, arg[1], NULL, &sockshost, &socksport)<0) { fprintf(stderr, "Couldn't parse/resolve address %s\n", arg[1]); return 1; } if (socksport == 0) { fprintf(stderr,"defaulting to port 9050\n"); socksport = 9050; } hostname = arg[0]; filename = arg[2]; expbytes = (size_t) parse_long(arg[3], 10, 0, 1024*1024*1024, NULL, NULL); } else { usage(); } if (do_connect(hostname, filename, sockshost, socksport, isReverse, isSocks4 ? 4 : 5, expbytes, &result, &result_hostname)) return 1; return 0; }
static int emc_setup_servers(struct ev_loop *loop, struct emc_server_context *ctx) { ev_io *server_watcher; char * bind_address_list; int server_sock; int result; char **addresses; int i; char *context_addr; char *context_port; struct emc_tls_server_context *tls_server_ctx; bind_address_list = emc_config_table_get("emc_bind_address"); if (!bind_address_list) { log_printf(DEBUG_LEVEL_FATAL, "FATAL config value emc_bind_address is required"); return -1; } addresses = g_strsplit(bind_address_list, " ", 0); for (i=0; addresses[i]; i++) { if (!parse_addr_port(addresses[i], EMC_DEFAULT_PORT, &context_addr, &context_port)) { log_printf(DEBUG_LEVEL_FATAL, "Address parsing error at %s:%d (\"%s\")", __FILE__, __LINE__, addresses[i]); return -1; } log_printf(DEBUG_LEVEL_INFO, "INFO adding server %s:%s", context_addr, context_port); server_sock = _emc_create_socket(context_addr, context_port); result = listen(server_sock, 20); if (result == -1) { close(server_sock); log_printf(DEBUG_LEVEL_FATAL, "Unable to listen() on socket, aborting"); return -1; } tls_server_ctx = g_malloc0(sizeof(struct emc_tls_server_context)); tls_server_ctx->server_sock = server_sock; result = emc_init_tls(tls_server_ctx); if (result != 0) { close(server_sock); g_free(tls_server_ctx); log_printf(DEBUG_LEVEL_FATAL, "Unable to initialize TLS, aborting"); return -1; } ctx->tls_server_list = g_list_append(ctx->tls_server_list, tls_server_ctx); server_watcher = malloc(sizeof(ev_io)); ev_io_init(server_watcher, emc_server_accept_cb, tls_server_ctx->server_sock, EV_READ); ev_io_start(loop, server_watcher); server_watcher->data = tls_server_ctx; } return 0; }