s3/libsmb: adjust smb2 code for new idl structs & generated ndr push/pull funcs.
[samba.git] / source3 / libsmb / libsmb_path.c
index 64a956d9ee4ee25e2dbb8a6dd984dbf61a0a024a..01b0a61e483f2f403175c7e99317543a5233d3d4 100644 (file)
@@ -1,10 +1,10 @@
-/* 
+/*
    Unix SMB/Netbios implementation.
    SMB client library implementation
    Copyright (C) Andrew Tridgell 1998
    Copyright (C) Richard Sharpe 2000, 2002
    Copyright (C) John Terpstra 2000
-   Copyright (C) Tom Jansen (Ninja ISD) 2002 
+   Copyright (C) Tom Jansen (Ninja ISD) 2002
    Copyright (C) Derrell Lipman 2003-2008
    Copyright (C) Jeremy Allison 2007, 2008
 
@@ -28,7 +28,7 @@
 
 
 /* Used by urldecode_talloc() */
-static int 
+static int
 hex2int( unsigned int _char )
 {
         if ( _char >= 'A' && _char <='F')
@@ -88,7 +88,7 @@ urldecode_talloc(TALLOC_CTX *ctx, char **pp_dest, const char *src)
                newlen++;
        }
 
-       dest = TALLOC_ARRAY(ctx, char, newlen);
+       dest = talloc_array(ctx, char, newlen);
        if (!dest) {
                return err_count;
        }
@@ -188,7 +188,8 @@ smbc_urlencode(char *dest,
  *
  *
  * We accept:
- *  smb://[[[domain;]user[:password]@]server[/share[/path[/file]]]][?options]
+ *  smb://[[[domain;]user[:password]@]server[:port][/share[/path[/file]]]]
+ *                                                             [?options]
  *
  * Meaning of URLs:
  *
@@ -224,6 +225,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 +240,7 @@ SMBC_parse_path(TALLOC_CTX *ctx,
 
        /* Ensure these returns are at least valid pointers. */
        *pp_server = talloc_strdup(ctx, "");
+       *p_port = smbc_getPort(context);
        *pp_share = talloc_strdup(ctx, "");
        *pp_path = talloc_strdup(ctx, "");
        *pp_user = talloc_strdup(ctx, "");
@@ -363,6 +366,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 ... */
        }