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) {
}
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
int target_start = 1; // Skip argv[0]
// Parse wsssht options - no positional arguments expected
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "--clientid") == 0 && i + 1 < argc) {
if (config->client_id) free(config->client_id);
......@@ -108,83 +106,17 @@ 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) {
print_usage(argv[0]);
return 0;
} else if (argv[i][0] == '-') {
// Unknown option
fprintf(stderr, "Error: Unknown option: %s\n", argv[i]);
return 0;
} else {
// Non-option argument, start of target
target_start = i;
break;
}
}
// 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;
}
char *host_part = at_pos + 1;
char *host_copy = strdup(host_part);
if (!host_copy) {
return 0;
}
// Remove port if present
char *colon_pos = strchr(host_copy, ':');
if (colon_pos) {
*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);
// Unknown option or unexpected argument
fprintf(stderr, "Error: Unknown option or unexpected argument: %s\n", argv[i]);
print_usage(argv[0]);
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;
}
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;
}
// No remaining arguments expected
*remaining_argc = 0;
*remaining_argv = NULL;
return 1;
}
......@@ -192,6 +124,7 @@ int parse_target_args(int argc, char *argv[], char **host, int debug) {
int main(int argc, char *argv[]) {
// Read config from wsssht.conf
char *config_domain = read_config_value_from_file("wssshd-host", "wsssht");
......
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