From 6b495327f20269cc353ec20d424ecd0d68e58541 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 24 Aug 2012 22:38:16 -0500 Subject: Crazy cheap URL parser --- src/pam-freerdp.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src') diff --git a/src/pam-freerdp.c b/src/pam-freerdp.c index 5295098..2550767 100644 --- a/src/pam-freerdp.c +++ b/src/pam-freerdp.c @@ -86,6 +86,23 @@ get_item (pam_handle_t * pamh, int type) char * retval = responses->resp; free(responses); + + if (type == PAM_RHOST) { + if (strncmp(retval, "http://", strlen("http://")) == 0) { + char * original = retval; + char * newish = retval + strlen("http://"); + char * c; + for (c = newish; *c != '\0'; c++) { + if (*c == '/') { + *c = '\0'; + break; + } + } + retval = strdup(newish); + free(original); + } + } + return retval; } -- cgit v1.2.3 From 4262a0309076b1db2eb15adfbc04b62126e39cf1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 27 Aug 2012 15:02:23 -0500 Subject: Switch to looking for '://' in the string --- src/pam-freerdp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/pam-freerdp.c b/src/pam-freerdp.c index 2550767..440ee40 100644 --- a/src/pam-freerdp.c +++ b/src/pam-freerdp.c @@ -88,9 +88,10 @@ get_item (pam_handle_t * pamh, int type) free(responses); if (type == PAM_RHOST) { - if (strncmp(retval, "http://", strlen("http://")) == 0) { + char * subloc = NULL; + if ((subloc = strstr(retval, "://")) != NULL) { char * original = retval; - char * newish = retval + strlen("http://"); + char * newish = retval + strlen("://"); char * c; for (c = newish; *c != '\0'; c++) { if (*c == '/') { -- cgit v1.2.3 From d4ba1e134fcce95f8b7983fa9fba6d9d18f8f68b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 27 Aug 2012 15:07:36 -0500 Subject: If we've got a colon for a port number split that out --- src/freerdp-auth-check.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src') diff --git a/src/freerdp-auth-check.c b/src/freerdp-auth-check.c index 83bab2f..d50833b 100644 --- a/src/freerdp-auth-check.c +++ b/src/freerdp-auth-check.c @@ -79,6 +79,15 @@ main (int argc, char * argv[]) instance->settings->password = password; instance->settings->ignore_certificate = true; + char * colonloc = strstr(argv[1], ":"); + if (colonloc != NULL) { + /* We've got a port to deal with */ + colonloc[0] = '\0'; + colonloc++; + + instance->settings->port = strtoul(colonloc, NULL, 10); + } + if (freerdp_connect(instance)) { freerdp_disconnect(instance); return 0; -- cgit v1.2.3 From 1708318511cf61c58913e8f14a8fb56ff1510bdd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 27 Aug 2012 15:11:13 -0500 Subject: Using 'strstr' instead our own loop. --- src/pam-freerdp.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/pam-freerdp.c b/src/pam-freerdp.c index 440ee40..0277e0c 100644 --- a/src/pam-freerdp.c +++ b/src/pam-freerdp.c @@ -92,13 +92,12 @@ get_item (pam_handle_t * pamh, int type) if ((subloc = strstr(retval, "://")) != NULL) { char * original = retval; char * newish = retval + strlen("://"); - char * c; - for (c = newish; *c != '\0'; c++) { - if (*c == '/') { - *c = '\0'; - break; - } + char * c = strstr(newish, "/"); + + if (c != NULL) { + c[0] = '\0'; } + retval = strdup(newish); free(original); } -- cgit v1.2.3 From 8a85c086263fda4baea7128592fefedb61f83aee Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 27 Aug 2012 15:14:35 -0500 Subject: Cleaning up the code to make it easier to read --- src/pam-freerdp.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/pam-freerdp.c b/src/pam-freerdp.c index 0277e0c..d1a6578 100644 --- a/src/pam-freerdp.c +++ b/src/pam-freerdp.c @@ -88,14 +88,14 @@ get_item (pam_handle_t * pamh, int type) free(responses); if (type == PAM_RHOST) { - char * subloc = NULL; - if ((subloc = strstr(retval, "://")) != NULL) { + char * subloc = strstr(retval, "://"); + if (subloc != NULL) { char * original = retval; - char * newish = retval + strlen("://"); - char * c = strstr(newish, "/"); + char * newish = subloc + strlen("://"); + char * endslash = strstr(newish, "/"); - if (c != NULL) { - c[0] = '\0'; + if (endslash != NULL) { + endslash[0] = '\0'; } retval = strdup(newish); -- cgit v1.2.3