Fix wsssht argument parsing issue

- Remove leftover logic for handling positional arguments in parse_args()
- Since wsssht no longer accepts user@host arguments, remove the non-option argument handling
- Remove unused parse_hostname() and parse_target_args() functions
- Fix issue where valid options were triggering --help output
parent 60dc9f73
No preview for this file type
...@@ -66,9 +66,7 @@ void print_usage(const char *program_name) { ...@@ -66,9 +66,7 @@ void print_usage(const char *program_name) {
} }
int parse_args(int argc, char *argv[], wsssh_config_t *config, int *remaining_argc, char ***remaining_argv) { int parse_args(int argc, char *argv[], wsssh_config_t *config, int *remaining_argc, char ***remaining_argv) {
// Manually parse arguments to separate wsssht options from target // Parse wsssht options - no positional arguments expected
int target_start = 1; // Skip argv[0]
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "--clientid") == 0 && i + 1 < argc) { if (strcmp(argv[i], "--clientid") == 0 && i + 1 < argc) {
if (config->client_id) free(config->client_id); if (config->client_id) free(config->client_id);
...@@ -108,86 +106,21 @@ int parse_args(int argc, char *argv[], wsssh_config_t *config, int *remaining_ar ...@@ -108,86 +106,21 @@ int parse_args(int argc, char *argv[], wsssh_config_t *config, int *remaining_ar
} else if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) { } else if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) {
print_usage(argv[0]); print_usage(argv[0]);
return 0; return 0;
} else if (argv[i][0] == '-') {
// Unknown option
fprintf(stderr, "Error: Unknown option: %s\n", argv[i]);
return 0;
} else { } else {
// Non-option argument, start of target // Unknown option or unexpected argument
target_start = i; fprintf(stderr, "Error: Unknown option or unexpected argument: %s\n", argv[i]);
break; print_usage(argv[0]);
}
}
// Return remaining arguments (target)
*remaining_argc = argc - target_start;
*remaining_argv = &argv[target_start];
return 1;
}
int parse_hostname(const char *hostname, char **client_id, char **wssshd_host, const char *config_domain) {
char *at_pos = strchr(hostname, '@');
if (!at_pos) {
fprintf(stderr, "Error: Invalid hostname format. Expected user@host\n");
return 0; return 0;
} }
char *host_part = at_pos + 1;
char *host_copy = strdup(host_part);
if (!host_copy) {
return 0;
} }
// Remove port if present // No remaining arguments expected
char *colon_pos = strchr(host_copy, ':'); *remaining_argc = 0;
if (colon_pos) { *remaining_argv = NULL;
*colon_pos = '\0';
}
// Split host by dots to extract client_id
char *dot_pos = strchr(host_copy, '.');
if (!dot_pos) {
// No domain, use config
if (!config_domain) {
fprintf(stderr, "Error: Invalid hostname format. Expected client.domain format or domain in config\n");
free(host_copy);
return 0;
}
*client_id = strdup(host_copy);
*wssshd_host = strdup(config_domain);
} else {
*dot_pos = '\0';
*client_id = strdup(host_copy);
*wssshd_host = strdup(dot_pos + 1);
}
free(host_copy);
return 1; return 1;
} }
int parse_target_args(int argc, char *argv[], char **host, int debug) {
*host = NULL;
for (int i = 0; i < argc; i++) {
if (argv[i][0] != '-' && !*host) {
// First non-option argument should be the target host
*host = argv[i];
if (debug) {
printf("[DEBUG - Tunnel] Found target host: %s\n", *host);
fflush(stdout);
}
break;
}
}
if (!*host) {
fprintf(stderr, "Error: Could not determine target host\n");
return 0;
}
return 1;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment