- int sockfd, numbytes, i, interactive, received, ret;
- struct hostent *he;
- struct sockaddr_in their_addr;
- char *command = NULL;
- char buf[8192];
- char *auth_str;
- char *key_file, *config_file;
- long unsigned challenge_nr;
- char *line;
-
- get_options(argc, argv, &config_file, &key_file);
- if (args_info.loglevel_arg <= NOTICE)
- cmdline_parser_print_version();
- PARA_INFO_LOG(
- "current loglevel: %d\n"
- "using config_file: %s\n"
- "using key_file: %s\n"
- "connecting to %s:%d\n",
- args_info.loglevel_arg,
- config_file,
- key_file,
- args_info.hostname_arg,
- args_info.server_port_arg
- );
- interactive = args_info.inputs_num == 0? 1 : 0;
- if (interactive) {
- PARA_NOTICE_LOG("%s", "no command, entering interactive mode\n");
- signal(SIGINT, sigint_handler);
- } else {
- /* not interactive, concat args */
- for (i = 0; i < args_info.inputs_num; i++)
- append_str(&command, args_info.inputs[i]);
- }
-interactive_loop:
- crypt_function_recv = NULL;
- crypt_function_send = NULL;
- if (interactive) {
- int i = 0;
- char *p;
-
- rl_save_prompt();
- rl_message("\n");
- rl_kill_full_line(0, 0);
- rl_free_line_state();
- /* read a line via readline */
- line = rl_gets();
- if (!line)
- return 0;
- if (!line[0])
- goto interactive_loop;
- p = line;
- while (sscanf(p, "%200s%n", buf, &i) == 1) {
- append_str(&command, buf);
- p += i;
- }
- }
- /* get the host info */
- PARA_NOTICE_LOG("getting host info of %s\n",
- args_info.hostname_arg);
- if (!(he = get_host_info(args_info.hostname_arg)))
- exit(EXIT_FAILURE);
- /* get new socket */
- if ((sockfd = get_socket()) < 0)
- exit(EXIT_FAILURE);
- /* init their_addr */
- init_sockaddr(&their_addr, args_info.server_port_arg, he);
- /* Connect */
- PARA_NOTICE_LOG("connecting to %s...\n",
- args_info.hostname_arg);
- if (para_connect(sockfd, &their_addr) < 0)
- exit(EXIT_FAILURE);
- /* Receive Welcome message */
- if ((numbytes = recv_buffer(sockfd, buf, sizeof(buf))) < 0)
- exit(EXIT_FAILURE);
- /* send auth command */
- auth_str = make_message("auth %s%s", args_info.plain_given? "" : "rc4 ",
- args_info.user_arg);
- PARA_INFO_LOG("<-- %s--> %s\n", buf, auth_str);
- if (send_buffer(sockfd, auth_str) < 0)
- exit(EXIT_FAILURE);
- /* receive challenge number */
- if ((numbytes = recv_buffer(sockfd, buf, sizeof(buf))) < 0)
- exit(EXIT_FAILURE);
- if (numbytes != 64) {
- PARA_EMERG_LOG("did not receive valid challenge (got %i bytes)\n",
- numbytes);
- buf[numbytes] = '\0';
- PARA_ERROR_LOG("received the following instead: %s\n", buf);
- goto write_out;
- }
- PARA_INFO_LOG("<-- [challenge (%i bytes)]\n", numbytes);
- /* decrypt challenge number */
- ret = para_decrypt_challenge(key_file, &challenge_nr, (unsigned char *) buf,
- numbytes);
+ int ret;
+ static struct sched s;
+
+ init_random_seed_or_die();
+ s.default_timeout.tv_sec = 1;
+ s.default_timeout.tv_usec = 0;
+ /*
+ * We add buffer tree nodes for stdin and stdout even though
+ * only one of them will be needed. This simplifies the code
+ * a bit wrt. to the buffer tree setup.
+ */
+ sit.btrn = btr_new_node(&(struct btr_node_description)
+ EMBRACE(.name = "stdin"));
+ ret = client_open(argc, argv, &ct, &client_loglevel, sit.btrn, NULL);
+ if (ret < 0)
+ goto out;
+ sot.btrn = btr_new_node(&(struct btr_node_description)
+ EMBRACE(.name = "stdout", .parent = ct->btrn));
+ register_task(&svt);
+ ret = schedule(&s);
+out:
+ client_close(ct);
+ btr_free_node(sit.btrn);
+ btr_free_node(sot.btrn);