From 534cf516ed17d90bbd851fd8e190811a055aa5f0 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 16 Apr 2013 12:09:41 -0700 Subject: Add the ability to parse out the port to SMBC_parse_path(). Signed-off-by: Jeremy Allison Reviewed-by: David Disseldorp --- source3/libsmb/libsmb_path.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'source3/libsmb/libsmb_path.c') diff --git a/source3/libsmb/libsmb_path.c b/source3/libsmb/libsmb_path.c index 1dcf2dd516..b286691a21 100644 --- a/source3/libsmb/libsmb_path.c +++ b/source3/libsmb/libsmb_path.c @@ -224,6 +224,7 @@ SMBC_parse_path(TALLOC_CTX *ctx, const char *fname, char **pp_workgroup, char **pp_server, + uint16_t *p_port, char **pp_share, char **pp_path, char **pp_user, @@ -238,6 +239,7 @@ SMBC_parse_path(TALLOC_CTX *ctx, /* Ensure these returns are at least valid pointers. */ *pp_server = talloc_strdup(ctx, ""); + *p_port = 0; *pp_share = talloc_strdup(ctx, ""); *pp_path = talloc_strdup(ctx, ""); *pp_user = talloc_strdup(ctx, ""); @@ -363,6 +365,28 @@ SMBC_parse_path(TALLOC_CTX *ctx, return -1; } + /* + * Does *pp_server contain a ':' ? If so + * this denotes the port. + */ + q = strchr_m(*pp_server, ':'); + if (q != NULL) { + long int port; + char *endptr = NULL; + *q = '\0'; + q++; + if (*q == '\0') { + /* Bad port. */ + return -1; + } + port = strtol(q, &endptr, 10); + if (*endptr != '\0') { + /* Bad port. */ + return -1; + } + *p_port = (uint16_t)port; + } + if (*p == (char)0) { goto decoding; /* That's it ... */ } -- cgit