static int ssh_session2(void) { int id = -1; /* XXX should be pre-session */ ssh_init_forwarding(); if (!no_shell_flag || (datafellows & SSH_BUG_DUMMYCHAN)) id = ssh_session2_open(); /* If we don't expect to open a new session, then disallow it */ if (options.control_master == SSHCTL_MASTER_NO && (datafellows & SSH_NEW_OPENSSH)) { debug("Requesting [email protected]"); packet_start(SSH2_MSG_GLOBAL_REQUEST); packet_put_cstring("*****@*****.**"); packet_put_char(0); packet_send(); } /* Execute a local command */ if (options.local_command != NULL && options.permit_local_command) ssh_local_cmd(options.local_command); /* Start listening for multiplex clients */ muxserver_listen(); if (options.use_roaming) request_roaming(); return client_loop(tty_flag, tty_flag ? options.escape_char : SSH_ESCAPECHAR_NONE, id); }
int event_timer(const EatEvent_st* event) { switch (event->data.timer.timer_id) { case TIMER_WATCHDOG: LOG_INFO("TIMER_WATCHDOG expire!"); feedWatchdog(); eat_timer_start(event->data.timer.timer_id, 50000); break; case TIMER_AT_CMD: LOG_INFO("TIMER_AT_CMD expire!"); eat_modem_write("AT+CGATT?\n", 10); eat_timer_start(event->data.timer.timer_id, 5000); break; case TIMER_GPS_SEND: LOG_INFO("TIMER_GPS_SEND expire!"); eat_timer_start(event->data.timer.timer_id, setting.gps_timer_period); client_loop(); break; default: LOG_ERROR ("timer(%d) not processed", event->data.timer.timer_id); break; } return 0; }
void client_autorun() { print(PSTR("client autorun\n\r")); rf_client_hack(); client_init(); while(!uart_read_ready()) { client_loop(); } }
int main(int ac, char **av) { int sockfd; if (ac < 3) print_usage(); sockfd = connect_to(av[1], av[2]); printf("sockfd : %d\n", sockfd); client_loop(sockfd); printf("Bye bye !\n"); return (0); }
void change_server(int sc, char **res, int port) { int i; i = -1; while (res[++i] != NULL); if (i > 3) { printf("USAGE : /server host [port]\n"); return ; } if (i == 2 && port != htons(atoi("4242"))) { connect_server(&sc, htons(atoi("4242")), res); client_loop(sc, htons(atoi("4242"))); } else if (i == 3 && port != htons(atoi(res[2]))) { connect_server(&sc, htons(atoi(res[2])), res); client_loop(sc, htons(atoi(res[2]))); } else printf("You are connected on the same port\n"); }
void create_client(char *host, char *port) { int sc; struct sockaddr_in sin_client; sc = create_socket(); sin_client.sin_family = AF_INET; sin_client.sin_port = htons(atoi(port)); sin_client.sin_addr.s_addr = inet_addr(host); if (connect(sc, (const struct sockaddr *)&sin_client, sizeof(sin_client)) == -1) my_error("Cannot connect to server", -1, sc); printf("Welcome on my (presque) perfect IRC\n"); client_loop(sc, sin_client.sin_port); return ; }
int main(int ac, char **av) { int port; int sock; if (ac != 3) usage(av[0]); port = ft_atoi(av[2]); sock = create_client(av[1], port); while (42) { if (client_loop(sock) == 1) break ; } close(sock); return (0); }
static void client_task (void *args) { client_state* state = (client_state*) args; void *frontend = zsocket_new (state->context, ZMQ_DEALER); zsocket_set_identity (frontend, state->identity); zsocket_connect (frontend,state->server_url); void *backend = zsocket_new (state->context, ZMQ_DEALER); zsocket_bind (backend, "inproc://backend"); zthread_fork (state->context, worker_task, state); client_loop(state, frontend, backend); zsocket_destroy(state->context, &frontend); zsocket_destroy(state->context, &backend); zctx_destroy (&state->context); }
int main(int ac, char **av) { t_client *clt; if ((clt = malloc(sizeof(t_client))) == NULL) return (err_msg(": malloc fail")); if (ac != 3) { printf("Usage: ./client <ip server> <port nb>\n"); return (-1); } if (client_init(clt, av) == -1) return (-1); if (client_loop(clt) == -1) return (-1); close(clt->fd); free(clt->line); free(clt->srv_ret); return (1); }
void server_loop(int fd, char *client_ip) { int client_fd; socklen_t socket_size; struct sockaddr_in socket_client; socket_size = sizeof(socket_client); while (1) { client_fd = accept(fd, (struct sockaddr *)&socket_client, &socket_size); client_ip = inet_ntoa(socket_client.sin_addr); if (client_fd == -1) xclose_exit_nwrite(fd, "Error : accept failed\n"); if (fork() == 0) { xclose(fd); client_loop(client_fd, client_ip); } else xclose(client_fd); } }
static int ssh_session2(void) { int id = -1; /* XXX should be pre-session */ ssh_init_forwarding(); if (!no_shell_flag || (datafellows & SSH_BUG_DUMMYCHAN)) id = ssh_session2_open(); /* If we don't expect to open a new session, then disallow it */ if (options.control_master == SSHCTL_MASTER_NO && (datafellows & SSH_NEW_OPENSSH)) { debug("Requesting [email protected]"); packet_start(SSH2_MSG_GLOBAL_REQUEST); packet_put_cstring("*****@*****.**"); packet_put_char(0); packet_send(); } /* Execute a local command */ if (options.local_command != NULL && options.permit_local_command) ssh_local_cmd(options.local_command); /* Start listening for multiplex clients */ muxserver_listen(); /* If requested, let ssh continue in the background. */ if (fork_after_authentication_flag) { fork_after_authentication_flag = 0; if (daemon(1, 1) < 0) fatal("daemon() failed: %.200s", strerror(errno)); } return client_loop(tty_flag, tty_flag ? options.escape_char : SSH_ESCAPECHAR_NONE, id); }
int main(int argc, char *argv[]) { char *cp; struct sockaddr_in addr_in; int sockfd,connectionfd,rc,afunix,lv; afunix=0; #ifndef __linux__ if (argv[1][0] == '-') { cp = &argv[1][1]; if (strcmp(cp, "h") == 0) { usage(); exit (0); } else { usage(); exit (0); } argc--; argv++; } else if (argc == 2) { usage(); exit (0); } #endif lv=10; if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { perror("socket error"); exit(-1); } memset(&addr_in, 0, sizeof(addr_in)); addr_in.sin_family = AF_INET; addr_in.sin_addr.s_addr = htons(INADDR_ANY); addr_in.sin_port = htons(23); if (bind(sockfd, (struct sockaddr*)&addr_in, sizeof(addr_in)) == -1) { perror("bind error"); exit(-1); } if (listen(sockfd, lv) == -1) { perror("listen error"); close(sockfd); exit(-1); } while (1) { connectionfd = accept (sockfd, (struct sockaddr *) NULL, NULL); if (connectionfd < 0) { perror ("accept"); break; } term_init (); client_loop (connectionfd, tfd); kill (pid, SIGKILL); close (connectionfd); close (tfd); } close (sockfd); return 0; }
uint8_t client_do_prompt() { char cmd[17]; //scanf("%16s",cmd); scan_key(cmd,17); if (strcmp(cmd,"init")==0) { client_init(); print_ok_nl(); return 1; } if (strcmp(cmd,"loop")==0) { uint16_t count = scan_uint16(); if (count == 0) { print(PSTR("client loop....")); while(!uart_read_ready()) { client_loop(); } print(PSTR(" end\n\r")); } else { while(count--) { print_char('.'); client_loop(); } } return 1; } if (strcmp(cmd,"autotune")==0) { client_autotune(); return 1; } if (strcmp(cmd,"channel")==0) { uint8_t c = scan_uint8(); client_select_channel(c); return 1; } if (strcmp(cmd,"check")==0) { uint8_t c = scan_uint8(); if (client_check_for_server(c)) { print(PSTR("ok\r\n")); } else { print(PSTR("fail\r\n")); } return 1; } if (strcmp(cmd,"pad")==0) { uint8_t l = client_read_pad(); print_hb(0,l); while(!uart_read_ready()) { uint8_t d = client_read_pad(); if (d!=l) { l = d; print_hb(PSTR(" "), d); } } return 1; } if (strcmp(cmd,"reset_stats")==0) { stats_ok = 0; stats_inv_seq = 0; stats_bad_crc = 0; stats_timeout = 0; print(PSTR("stat reset ok")); return 1; } if (strcmp(cmd,"stats")==0) { print_dw(PSTR("ok: "), stats_ok); print_dw(PSTR(" inv_seq: "), stats_inv_seq); print_dw(PSTR(" bad_crc: "), stats_bad_crc); print_dw(PSTR(" timeout: "), stats_timeout); print_nl(); return 1; } return 1; }
int main(int argc, char* argv[]) { #ifdef HAVE_EXECINFO_H signal(SIGSEGV, crash_sig); signal(SIGABRT, crash_sig); signal(SIGPIPE, SIG_IGN); #endif #ifdef WIN32 HANDLE localfd; WSADATA wsa; enum_device_t devs[MAX_DEVICE_COUNT]; #else int localfd; #endif char cmd[1024]; int remotefd; library_conf_t conf; int opt; struct in_addr a; struct option long_options[] = { { "conf", 1, NULL, 'c' }, { NULL, 0, NULL, 0 } }; char short_options[512] = {0}; longopt2shortopt(long_options, sizeof(long_options) / sizeof(struct option), short_options); #ifdef HAVE_SYSLOG_H openlog(argv[0], LOG_PERROR | LOG_CONS | LOG_PID, LOG_LOCAL0); #endif qtun = calloc(sizeof(*qtun), 1); #ifdef WIN32 remotefd = -1; localfd = INVALID_HANDLE_VALUE; #else localfd = remotefd = -1; #endif { char path[MAX_PATH] = {0}; #ifdef WIN32 strcpy(path, argv[0]); #elif defined(__APPLE__) char tmp_path[sizeof(path)] = {0}; uint32_t len = sizeof(path); if (_NSGetExecutablePath(tmp_path, &len) == -1) { perror("_NSGetExecutablePath"); return 1; } if (readlink(tmp_path, path, sizeof(path)) == -1) { if (errno == EINVAL) strcpy(path, tmp_path); else { perror("readlink"); return 1; } } #else if (readlink("/proc/self/exe", path, sizeof(path)) == -1) { perror("readlink"); return 1; } #endif init_path(path); } conf_init(&conf); while ((opt = getopt_long(argc, argv, short_options, long_options, NULL)) != -1) { switch (opt) { case 'c': { char* path = realpath(optarg, NULL); if (path == NULL) { perror("realpath"); return 1; } strcpy(conf.conf_file, path); free(path); } break; default: fprintf(stderr, "param error\n"); return 1; } } #ifdef WIN32 { size_t count = enum_devices(devs); if (count == 0) { fprintf(stderr, "have no QTun Virtual Adapter\n"); return 1; } else if (count == 1) { strcpy(conf.dev_symbol, devs[0].dev_path); strcpy(conf.dev_name, devs[0].dev_name); } else { size_t i; char str[20] = { 0 }; int n = -1; printf("Have Adapters:\n"); for (i = 0; i < count; ++i) { printf("%lu: %s\n", i + 1, devs[i].dev_name); } printf("Choose One[1]: "); while (n == -1) { if (str[0] == '\n' && str[1] == 0) n = 1; else { if (!is_int(str, sizeof(str))) continue; n = atoi(str); if (n < 1 || n > (int)count) { fprintf(stderr, "Invalid Number must >= 1 and <= %lu\n", count); n = -1; continue; } } } strcpy(conf.dev_symbol, devs[n].dev_path); strcpy(conf.dev_name, devs[n].dev_name); } } #endif init_lua(); show_logo(); script_load_config(qtun->lua, &conf, conf.conf_file); #ifdef WIN32 if (strlen(conf.dev_symbol) == 0) { fprintf(stderr, "Missing param [-e] or [--device]\n"); return 1; } #endif #ifdef WIN32 localfd = tun_open(conf.dev_symbol); if (localfd == INVALID_HANDLE_VALUE) return 1; fprintf(stdout, "%s opened\n", conf.dev_name); #else memset(qtun->dev_name, 0, IFNAMSIZ); localfd = tun_open(qtun->dev_name); if (localfd == -1) return 1; syslog(LOG_INFO, "%s opened\n", qtun->dev_name); #endif a.s_addr = conf.localip; #ifdef WIN32 WSAStartup(MAKEWORD(2, 2), &wsa); #endif if (strlen(conf.server) == 0) { if (conf.netmask == 0 || conf.netmask > 31) { #ifdef WIN32 WSACleanup(); #endif fprintf(stderr, "netmask must > 0 and <= 31\n"); return 1; } library_init(conf); if (conf.localip == 0) { fprintf(stderr, "localip is zero\n"); return 1; } if (strlen(conf.signature_file) == 0) { fprintf(stderr, "missing signature file\n"); return 1; } qtun->is_server = 1; remotefd = bind_and_listen(conf.server_port); if (remotefd == -1) { #ifdef WIN32 WSACleanup(); #endif return 1; } #ifdef WIN32 { a.s_addr = conf.localip; sprintf(cmd, "netsh interface ip set address name=\"%s\" static %s %s", conf.dev_name, inet_ntoa(a), STR_LEN2MASK(conf.netmask)); SYSTEM_EXIT(cmd); } #elif defined(__APPLE__) { sprintf(cmd, "ifconfig %s %s/%u up", qtun->dev_name, inet_ntoa(a), conf.netmask); SYSTEM_EXIT(cmd); a.s_addr = conf.localip & LEN2MASK(conf.netmask); sprintf(cmd, "route add -net %s/%u %s", inet_ntoa(a), conf.netmask, inet_ntoa(a)); SYSTEM_EXIT(cmd); } #else { sprintf(cmd, "ifconfig %s %s/%u up", qtun->dev_name, inet_ntoa(a), conf.netmask); SYSTEM_EXIT(cmd); a.s_addr = conf.localip & LEN2MASK(conf.netmask); sprintf(cmd, "route add -net %s/%u dev %s", inet_ntoa(a), conf.netmask, qtun->dev_name); SYSTEM_EXIT(cmd); } #endif server_loop(remotefd, localfd); } else { #ifdef unix unsigned char mask; #endif int inited = 0; library_init(conf); qtun->is_server = 0; while (1) { remotefd = connect_server(conf.server, conf.server_port); if (remotefd == -1) { SLEEP(5); continue; } a.s_addr = qtun->localip; if (qtun->localip == 0) { fprintf(stderr, "localip is zero\n"); return 1; } if (strlen(conf.signature_file) == 0) { fprintf(stderr, "missing signature file\n"); return 1; } if (!inited) { #ifdef WIN32 { sprintf(cmd, "netsh interface ip set address name=\"%s\" static %s %s", conf.dev_name, inet_ntoa(a), STR_LEN2MASK(conf.netmask)); SYSTEM_EXIT(cmd); } #elif defined(__APPLE__) { char ip1[16], ip2[16]; a.s_addr = qtun->localip; strcpy(ip1, inet_ntoa(a)); a.s_addr = qtun->client.local_ip; strcpy(ip2, inet_ntoa(a)); sprintf(cmd, "ifconfig %s inet %s %s up", qtun->dev_name, ip1, ip2); SYSTEM_EXIT(cmd); mask = netmask(); a.s_addr = qtun->localip & LEN2MASK(mask); sprintf(cmd, "route add -net %s/%u %s", inet_ntoa(a), mask, ip2); SYSTEM_EXIT(cmd); } #else { sprintf(cmd, "ifconfig %s %s up", qtun->dev_name, inet_ntoa(a)); SYSTEM_EXIT(cmd); mask = netmask(); a.s_addr = qtun->localip & LEN2MASK(mask); sprintf(cmd, "route add -net %s/%u dev %s", inet_ntoa(a), mask, qtun->dev_name); SYSTEM_EXIT(cmd); } #endif inited = 1; } client_loop(remotefd, localfd); close(remotefd); SYSLOG(LOG_WARNING, "retry"); } } #ifdef WIN32 WSACleanup(); #endif #ifdef HAVE_SYSLOG_H closelog(); #endif library_free(); return 0; }
static int ssh_session(void) { int type; int interactive = 0; int have_tty = 0; struct winsize ws; char *cp; const char *display; /* Enable compression if requested. */ if (options.compression) { debug("Requesting compression at level %d.", options.compression_level); if (options.compression_level < 1 || options.compression_level > 9) fatal("Compression level must be from 1 (fast) to " "9 (slow, best)."); /* Send the request. */ packet_start(SSH_CMSG_REQUEST_COMPRESSION); packet_put_int(options.compression_level); packet_send(); packet_write_wait(); type = packet_read(); if (type == SSH_SMSG_SUCCESS) packet_start_compression(options.compression_level); else if (type == SSH_SMSG_FAILURE) logit("Warning: Remote host refused compression."); else packet_disconnect("Protocol error waiting for " "compression response."); } /* Allocate a pseudo tty if appropriate. */ if (tty_flag) { debug("Requesting pty."); /* Start the packet. */ packet_start(SSH_CMSG_REQUEST_PTY); /* Store TERM in the packet. There is no limit on the length of the string. */ cp = getenv("TERM"); if (!cp) cp = ""; packet_put_cstring(cp); /* Store window size in the packet. */ if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) < 0) memset(&ws, 0, sizeof(ws)); packet_put_int((u_int)ws.ws_row); packet_put_int((u_int)ws.ws_col); packet_put_int((u_int)ws.ws_xpixel); packet_put_int((u_int)ws.ws_ypixel); /* Store tty modes in the packet. */ tty_make_modes(fileno(stdin), NULL); /* Send the packet, and wait for it to leave. */ packet_send(); packet_write_wait(); /* Read response from the server. */ type = packet_read(); if (type == SSH_SMSG_SUCCESS) { interactive = 1; have_tty = 1; } else if (type == SSH_SMSG_FAILURE) logit("Warning: Remote host failed or refused to " "allocate a pseudo tty."); else packet_disconnect("Protocol error waiting for pty " "request response."); } /* Request X11 forwarding if enabled and DISPLAY is set. */ display = getenv("DISPLAY"); if (options.forward_x11 && display != NULL) { char *proto, *data; /* Get reasonable local authentication information. */ client_x11_get_proto(display, options.xauth_location, options.forward_x11_trusted, options.forward_x11_timeout, &proto, &data); /* Request forwarding with authentication spoofing. */ debug("Requesting X11 forwarding with authentication " "spoofing."); x11_request_forwarding_with_spoofing(0, display, proto, data, 0); /* Read response from the server. */ type = packet_read(); if (type == SSH_SMSG_SUCCESS) { interactive = 1; } else if (type == SSH_SMSG_FAILURE) { logit("Warning: Remote host denied X11 forwarding."); } else { packet_disconnect("Protocol error waiting for X11 " "forwarding"); } } /* Tell the packet module whether this is an interactive session. */ packet_set_interactive(interactive, options.ip_qos_interactive, options.ip_qos_bulk); /* Request authentication agent forwarding if appropriate. */ check_agent_present(); if (options.forward_agent) { debug("Requesting authentication agent forwarding."); auth_request_forwarding(); /* Read response from the server. */ type = packet_read(); packet_check_eom(); if (type != SSH_SMSG_SUCCESS) logit("Warning: Remote host denied authentication agent forwarding."); } /* Initiate port forwardings. */ ssh_init_stdio_forwarding(); ssh_init_forwarding(); /* Execute a local command */ if (options.local_command != NULL && options.permit_local_command) ssh_local_cmd(options.local_command); /* * If requested and we are not interested in replies to remote * forwarding requests, then let ssh continue in the background. */ if (fork_after_authentication_flag) { if (options.exit_on_forward_failure && options.num_remote_forwards > 0) { debug("deferring postauth fork until remote forward " "confirmation received"); } else fork_postauth(); } /* * If a command was specified on the command line, execute the * command now. Otherwise request the server to start a shell. */ if (buffer_len(&command) > 0) { int len = buffer_len(&command); if (len > 900) len = 900; debug("Sending command: %.*s", len, (u_char *)buffer_ptr(&command)); packet_start(SSH_CMSG_EXEC_CMD); packet_put_string(buffer_ptr(&command), buffer_len(&command)); packet_send(); packet_write_wait(); } else { debug("Requesting shell."); packet_start(SSH_CMSG_EXEC_SHELL); packet_send(); packet_write_wait(); } /* Enter the interactive session. */ return client_loop(have_tty, tty_flag ? options.escape_char : SSH_ESCAPECHAR_NONE, 0); }
void *client_thread (void *arg) { struct client *cl = (struct client *)arg; client_loop(cl->fd); free(cl); return(NULL); }
int main() { if (client_init(NULL, 0, function_read) == -1) return (-1); client_loop(); }
int main(int argc, char* argv[]) { signal(SIGSEGV, crash_sig); signal(SIGABRT, crash_sig); signal(SIGPIPE, SIG_IGN); char cmd[1024]; int localfd, remotefd; library_conf_t conf; int opt; char* ip = NULL; unsigned int port = 6687; struct in_addr a; struct option long_options[] = { {"aes", 1, NULL, 'a'}, {"des", 1, NULL, 'd'}, {"gzip", 0, NULL, 'g'}, {"mask", 1, NULL, 'm'}, {"localip", 1, NULL, 'l'}, {"server", 1, NULL, 's'}, {"port", 1, NULL, 'p'}, {NULL, 0, NULL, 0} }; char short_options[512] = {0}; longopt2shortopt(long_options, sizeof(long_options) / sizeof(struct option), short_options); conf.localip = 0; conf.netmask = 24; conf.use_gzip = 0; conf.use_aes = 0; conf.aes_key_file = NULL; conf.use_des = 0; conf.des_key_file = NULL; while ((opt = getopt_long(argc, argv, short_options, long_options, NULL)) != -1) { switch (opt) { case 'a': conf.use_aes = 1; conf.aes_key_file = optarg; break; case 'd': conf.use_des = 1; conf.des_key_file = optarg; break; case 'g': conf.use_gzip = 1; break; case 'l': conf.localip = inet_addr(optarg); break; case 's': ip = optarg; break; case 'm': conf.netmask = atoi(optarg); break; case 'p': port = atoi(optarg); break; default: fprintf(stderr, "param error\n"); return 1; } } if (conf.localip == 0) { fprintf(stderr, "localip is zero\n"); return 1; } if (port == 0) { fprintf(stderr, "port is zero\n"); return 1; } memset(this.dev_name, 0, IFNAMSIZ); localfd = tun_open(this.dev_name); if (localfd == -1) return 1; fprintf(stdout, "%s opened\n", this.dev_name); a.s_addr = conf.localip; if (ip == NULL) { if (conf.netmask == 0 || conf.netmask > 31) { fprintf(stderr, "netmask must > 0 and <= 31\n"); return 1; } library_init(conf); remotefd = bind_and_listen(port); if (remotefd == -1) return 1; sprintf(cmd, "ifconfig %s %s/%u up", this.dev_name, inet_ntoa(a), conf.netmask); SYSTEM_EXIT(cmd); a.s_addr = conf.localip & LEN2MASK(conf.netmask); sprintf(cmd, "route add -net %s/%u dev %s", inet_ntoa(a), conf.netmask, this.dev_name); SYSTEM_EXIT(cmd); server_loop(remotefd, localfd); } else { unsigned char mask; int inited = 0; library_init(conf); while (1) { remotefd = connect_server(ip, port); if (remotefd == -1) { sleep(5); continue; } if (!inited) { sprintf(cmd, "ifconfig %s %s up", this.dev_name, inet_ntoa(a)); SYSTEM_EXIT(cmd); mask = netmask(); a.s_addr = conf.localip & LEN2MASK(mask); sprintf(cmd, "route add -net %s/%u dev %s", inet_ntoa(a), mask, this.dev_name); SYSTEM_EXIT(cmd); inited = 1; } client_loop(remotefd, localfd); close(remotefd); fprintf(stderr, "retry\n"); } } return 0; }
static int ssh_session2(void) { int id = -1; /* XXX should be pre-session */ if (!options.control_persist) ssh_init_stdio_forwarding(); ssh_init_forwarding(); /* Start listening for multiplex clients */ muxserver_listen(); /* * If we are in control persist mode and have a working mux listen * socket, then prepare to background ourselves and have a foreground * client attach as a control slave. * NB. we must save copies of the flags that we override for * the backgrounding, since we defer attachment of the slave until * after the connection is fully established (in particular, * async rfwd replies have been received for ExitOnForwardFailure). */ if (options.control_persist && muxserver_sock != -1) { ostdin_null_flag = stdin_null_flag; ono_shell_flag = no_shell_flag; orequest_tty = options.request_tty; otty_flag = tty_flag; stdin_null_flag = 1; no_shell_flag = 1; tty_flag = 0; if (!fork_after_authentication_flag) need_controlpersist_detach = 1; fork_after_authentication_flag = 1; } /* * ControlPersist mux listen socket setup failed, attempt the * stdio forward setup that we skipped earlier. */ if (options.control_persist && muxserver_sock == -1) ssh_init_stdio_forwarding(); if (!no_shell_flag || (datafellows & SSH_BUG_DUMMYCHAN)) id = ssh_session2_open(); /* If we don't expect to open a new session, then disallow it */ if (options.control_master == SSHCTL_MASTER_NO && (datafellows & SSH_NEW_OPENSSH)) { debug("Requesting [email protected]"); packet_start(SSH2_MSG_GLOBAL_REQUEST); packet_put_cstring("*****@*****.**"); packet_put_char(0); packet_send(); } /* Execute a local command */ if (options.local_command != NULL && options.permit_local_command) ssh_local_cmd(options.local_command); /* * If requested and we are not interested in replies to remote * forwarding requests, then let ssh continue in the background. */ if (fork_after_authentication_flag) { if (options.exit_on_forward_failure && options.num_remote_forwards > 0) { debug("deferring postauth fork until remote forward " "confirmation received"); } else fork_postauth(); } if (options.use_roaming) request_roaming(); return client_loop(tty_flag, tty_flag ? options.escape_char : SSH_ESCAPECHAR_NONE, id); }
int main(int argc, char *argv[], char *envp[]) { int in[2], out[2], err[2]; int status; int ssh_stdinfd, ssh_stdoutfd, ssh_stderrfd; if (argc < 2) { printf("***ERROR: This program shouldn't be used directly.\n"); exit(1); } if (strcmp(argv[1], "--noStrictHostKeyChecking") == 0) { noStrictHostKeyChecking = 1; argv++; } createStdioFds(in, out, err); listenSock = openListenSocket(); signal(SIGCHLD, signal_handler); pid_t sshChildPid = fork(); if (sshChildPid == 0) { char buf[PATH_MAX + 80]; char hostname[80]; int port = getport(listenSock); close(listenSock); close(in[1]); close(out[0]); close(err[0]); dup2(in[0], STDIN_FILENO); dup2(out[1], STDOUT_FILENO); dup2(err[1], STDERR_FILENO); unsetenv("LD_PRELOAD"); // Replace dmtcp_sshd replace with "dmtcp_sshd --host <host> --port <port>" struct in_addr saddr; if (dmtcp_get_local_ip_addr == NULL) { printf("ERROR: Unable to find dmtcp_get_local_ip_addr.\n"); abort(); } dmtcp_get_local_ip_addr(&saddr); char *hostip = inet_ntoa(saddr); strcpy(hostname, hostip); size_t i = 0; while (argv[i] != NULL) { // "dmtcp_sshd" may be embedded deep inside the command line. char *ptr = strstr(argv[i], SSHD_BINARY); if (ptr != NULL) { ptr += strlen(SSHD_BINARY); if (*ptr != '\0') { *ptr = '\0'; ptr++; } snprintf(buf, sizeof buf, "%s --host %s --port %d %s", argv[i], hostip, port, ptr); argv[i] = buf; } i++; } execvp(argv[1], &argv[1]); printf("%s:%d DMTCP Error detected. Failed to exec.", __FILE__, __LINE__); abort(); } int childSock = waitForConnection(listenSock); close(in[0]); close(out[1]); close(err[1]); ssh_stdinfd = in[1]; ssh_stdoutfd = out[0]; ssh_stderrfd = err[0]; assert(dmtcp_ssh_register_fds != NULL); dmtcp_ssh_register_fds(false, ssh_stdinfd, ssh_stdoutfd, ssh_stderrfd, childSock, noStrictHostKeyChecking); client_loop(ssh_stdinfd, ssh_stdoutfd, ssh_stderrfd, childSock); wait(&status); return status; }