Add the ability to parse out the port to SMBC_parse_path().
authorJeremy Allison <jra@samba.org>
Tue, 16 Apr 2013 19:09:41 +0000 (12:09 -0700)
committerJeremy Allison <jra@samba.org>
Tue, 11 Jun 2013 17:50:41 +0000 (10:50 -0700)
Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: David Disseldorp <ddiss@samba.org>
source3/include/libsmb_internal.h
source3/libsmb/libsmb_dir.c
source3/libsmb/libsmb_file.c
source3/libsmb/libsmb_path.c
source3/libsmb/libsmb_printjob.c
source3/libsmb/libsmb_stat.c
source3/libsmb/libsmb_xattr.c

index aba159ada248beec687e04a1d2f9eca4f2e41281..bd9143892cd29a2cc7b73f3f7956879f619303b1 100644 (file)
@@ -415,6 +415,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,
index 700196c10c6fea09960e8015eb6b3962514ea921..5428b17258d7823cc89a574309108ef6ed1623ab 100644 (file)
@@ -378,6 +378,7 @@ SMBC_opendir_ctx(SMBCCTX *context,
        char *workgroup = NULL;
        char *path = NULL;
         uint16 mode;
+       uint16_t port = 0;
         char *p = NULL;
        SMBCSRV *srv  = NULL;
        SMBCFILE *dir = NULL;
@@ -404,6 +405,7 @@ SMBC_opendir_ctx(SMBCCTX *context,
                             fname,
                             &workgroup,
                             &server,
+                            &port,
                             &share,
                             &path,
                             &user,
@@ -1161,6 +1163,7 @@ SMBC_mkdir_ctx(SMBCCTX *context,
         char *workgroup = NULL;
        char *path = NULL;
        char *targetpath = NULL;
+       uint16_t port = 0;
        struct cli_state *targetcli = NULL;
        TALLOC_CTX *frame = talloc_stackframe();
        NTSTATUS status;
@@ -1184,6 +1187,7 @@ SMBC_mkdir_ctx(SMBCCTX *context,
                             fname,
                             &workgroup,
                             &server,
+                            &port,
                             &share,
                             &path,
                             &user,
@@ -1270,6 +1274,7 @@ SMBC_rmdir_ctx(SMBCCTX *context,
         char *workgroup = NULL;
        char *path = NULL;
         char *targetpath = NULL;
+       uint16_t port = 0;
        struct cli_state *targetcli = NULL;
        TALLOC_CTX *frame = talloc_stackframe();
        NTSTATUS status;
@@ -1293,6 +1298,7 @@ SMBC_rmdir_ctx(SMBCCTX *context,
                             fname,
                             &workgroup,
                             &server,
+                            &port,
                             &share,
                             &path,
                             &user,
@@ -1557,6 +1563,7 @@ SMBC_chmod_ctx(SMBCCTX *context,
        struct cli_state *targetcli = NULL;
        char *path = NULL;
        uint16 mode;
+       uint16_t port = 0;
        TALLOC_CTX *frame = talloc_stackframe();
         NTSTATUS status;
 
@@ -1580,6 +1587,7 @@ SMBC_chmod_ctx(SMBCCTX *context,
                             fname,
                             &workgroup,
                             &server,
+                            &port,
                             &share,
                             &path,
                             &user,
@@ -1648,6 +1656,7 @@ SMBC_utimes_ctx(SMBCCTX *context,
        char *path = NULL;
         time_t access_time;
         time_t write_time;
+       uint16_t port = 0;
        TALLOC_CTX *frame = talloc_stackframe();
 
        if (!context || !context->internal->initialized) {
@@ -1696,6 +1705,7 @@ SMBC_utimes_ctx(SMBCCTX *context,
                             fname,
                             &workgroup,
                             &server,
+                            &port,
                             &share,
                             &path,
                             &user,
@@ -1748,6 +1758,7 @@ SMBC_unlink_ctx(SMBCCTX *context,
         char *workgroup = NULL;
        char *path = NULL;
        char *targetpath = NULL;
+       uint16_t port = 0;
        struct cli_state *targetcli = NULL;
        SMBCSRV *srv = NULL;
        TALLOC_CTX *frame = talloc_stackframe();
@@ -1773,6 +1784,7 @@ SMBC_unlink_ctx(SMBCCTX *context,
                             fname,
                             &workgroup,
                             &server,
+                            &port,
                             &share,
                             &path,
                             &user,
@@ -1886,6 +1898,8 @@ SMBC_rename_ctx(SMBCCTX *ocontext,
        struct cli_state *targetcli1 = NULL;
         struct cli_state *targetcli2 = NULL;
        SMBCSRV *srv = NULL;
+       uint16_t port1 = 0;
+       uint16_t port2 = 0;
        TALLOC_CTX *frame = talloc_stackframe();
         NTSTATUS status;
 
@@ -1911,6 +1925,7 @@ SMBC_rename_ctx(SMBCCTX *ocontext,
                             oname,
                             &workgroup,
                             &server1,
+                            &port1,
                             &share1,
                             &path1,
                             &user1,
@@ -1935,6 +1950,7 @@ SMBC_rename_ctx(SMBCCTX *ocontext,
                             nname,
                             NULL,
                             &server2,
+                            &port2,
                             &share2,
                             &path2,
                             &user2,
index 9521542cb274a3c84fd4ff7d7b75dd450218f37a..06d09ac7bd4ec490fc4b378921153b54e3f82657 100644 (file)
@@ -49,6 +49,7 @@ SMBC_open_ctx(SMBCCTX *context,
        SMBCSRV *srv   = NULL;
        SMBCFILE *file = NULL;
        uint16_t fd;
+       uint16_t port = 0;
        NTSTATUS status = NT_STATUS_OBJECT_PATH_INVALID;
        TALLOC_CTX *frame = talloc_stackframe();
 
@@ -69,6 +70,7 @@ SMBC_open_ctx(SMBCCTX *context,
                             fname,
                             &workgroup,
                             &server,
+                            &port,
                             &share,
                             &path,
                             &user,
@@ -230,6 +232,7 @@ SMBC_read_ctx(SMBCCTX *context,
        char *path = NULL;
        char *targetpath = NULL;
        struct cli_state *targetcli = NULL;
+       uint16_t port = 0;
        TALLOC_CTX *frame = talloc_stackframe();
        NTSTATUS status;
 
@@ -274,6 +277,7 @@ SMBC_read_ctx(SMBCCTX *context,
                             file->fname,
                             NULL,
                             &server,
+                            &port,
                             &share,
                             &path,
                             &user,
@@ -327,6 +331,7 @@ SMBC_write_ctx(SMBCCTX *context,
        char *path = NULL;
        char *targetpath = NULL;
        struct cli_state *targetcli = NULL;
+       uint16_t port = 0;
        TALLOC_CTX *frame = talloc_stackframe();
        NTSTATUS status;
 
@@ -360,6 +365,7 @@ SMBC_write_ctx(SMBCCTX *context,
                             file->fname,
                             NULL,
                             &server,
+                            &port,
                             &share,
                             &path,
                             &user,
@@ -408,6 +414,7 @@ SMBC_close_ctx(SMBCCTX *context,
        char *server = NULL, *share = NULL, *user = NULL, *password = NULL;
        char *path = NULL;
        char *targetpath = NULL;
+       uint16_t port = 0;
        struct cli_state *targetcli = NULL;
        TALLOC_CTX *frame = talloc_stackframe();
        NTSTATUS status;
@@ -436,6 +443,7 @@ SMBC_close_ctx(SMBCCTX *context,
                             file->fname,
                             NULL,
                             &server,
+                            &port,
                             &share,
                             &path,
                             &user,
@@ -684,6 +692,7 @@ SMBC_lseek_ctx(SMBCCTX *context,
        char *path = NULL;
        char *targetpath = NULL;
        struct cli_state *targetcli = NULL;
+       uint16_t port = 0;
        TALLOC_CTX *frame = talloc_stackframe();
        NTSTATUS status;
 
@@ -719,6 +728,7 @@ SMBC_lseek_ctx(SMBCCTX *context,
                                     file->fname,
                                     NULL,
                                     &server,
+                                    &port,
                                     &share,
                                     &path,
                                     &user,
@@ -782,6 +792,7 @@ SMBC_ftruncate_ctx(SMBCCTX *context,
        char *password = NULL;
        char *path = NULL;
         char *targetpath = NULL;
+       uint16_t port = 0;
        struct cli_state *targetcli = NULL;
        TALLOC_CTX *frame = talloc_stackframe();
        NTSTATUS status;
@@ -810,6 +821,7 @@ SMBC_ftruncate_ctx(SMBCCTX *context,
                             file->fname,
                             NULL,
                             &server,
+                            &port,
                             &share,
                             &path,
                             &user,
index 1dcf2dd51672cd9c9b15f78938bf37a5b929696b..b286691a21a0f3f7a0450c81f622000ffe877440 100644 (file)
@@ -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 ... */
        }
index 173fa327d3ebf7f07b6ca8d2e3e7e09ae85320ef..3189463cf2878134d00e31cfec0781179ca70a98 100644 (file)
@@ -41,6 +41,7 @@ SMBC_open_print_job_ctx(SMBCCTX *context,
        char *user = NULL;
        char *password = NULL;
        char *path = NULL;
+       uint16_t port = 0;
        TALLOC_CTX *frame = talloc_stackframe();
 
        if (!context || !context->internal->initialized) {
@@ -62,6 +63,7 @@ SMBC_open_print_job_ctx(SMBCCTX *context,
                             fname,
                             NULL,
                             &server,
+                            &port,
                             &share,
                             &path,
                             &user,
@@ -190,6 +192,7 @@ SMBC_list_print_jobs_ctx(SMBCCTX *context,
        char *password = NULL;
        char *workgroup = NULL;
        char *path = NULL;
+       uint16_t port = 0;
        TALLOC_CTX *frame = talloc_stackframe();
 
        if (!context || !context->internal->initialized) {
@@ -211,6 +214,7 @@ SMBC_list_print_jobs_ctx(SMBCCTX *context,
                             fname,
                             &workgroup,
                             &server,
+                            &port,
                             &share,
                             &path,
                             &user,
@@ -266,6 +270,7 @@ SMBC_unlink_print_job_ctx(SMBCCTX *context,
        char *workgroup = NULL;
        char *path = NULL;
         int err;
+       uint16_t port = 0;
        TALLOC_CTX *frame = talloc_stackframe();
 
        if (!context || !context->internal->initialized) {
@@ -287,6 +292,7 @@ SMBC_unlink_print_job_ctx(SMBCCTX *context,
                             fname,
                             &workgroup,
                             &server,
+                            &port,
                             &share,
                             &path,
                             &user,
index 5cfbcb842c58166c7961f2ad752b4c80a78306c5..f87e2d34bd20ad4b5f040b641d7e59b3b5abd83f 100644 (file)
@@ -120,6 +120,7 @@ SMBC_stat_ctx(SMBCCTX *context,
         struct timespec change_time_ts;
        off_t size = 0;
        uint16 mode = 0;
+       uint16_t port = 0;
        SMB_INO_T ino = 0;
        TALLOC_CTX *frame = talloc_stackframe();
 
@@ -142,6 +143,7 @@ SMBC_stat_ctx(SMBCCTX *context,
                             fname,
                             &workgroup,
                             &server,
+                            &port,
                             &share,
                             &path,
                             &user,
@@ -214,6 +216,7 @@ SMBC_fstat_ctx(SMBCCTX *context,
         char *targetpath = NULL;
        struct cli_state *targetcli = NULL;
        SMB_INO_T ino = 0;
+       uint16_t port = 0;
        TALLOC_CTX *frame = talloc_stackframe();
        NTSTATUS status;
 
@@ -240,6 +243,7 @@ SMBC_fstat_ctx(SMBCCTX *context,
                             file->fname,
                             NULL,
                             &server,
+                            &port,
                             &share,
                             &path,
                             &user,
index c2ba61f88ea8ac4b469d705ec143629e3ed9a87c..89bdd25aa5f5b1b3e19ee7098751c96ab82bb882 100644 (file)
@@ -1724,6 +1724,7 @@ SMBC_setxattr_ctx(SMBCCTX *context,
                 const char * write_time_attr;
                 const char * change_time_attr;
         } attr_strings;
+       uint16_t port = 0;
         TALLOC_CTX *frame = talloc_stackframe();
 
        if (!context || !context->internal->initialized) {
@@ -1746,6 +1747,7 @@ SMBC_setxattr_ctx(SMBCCTX *context,
                             fname,
                             &workgroup,
                             &server,
+                            &port,
                             &share,
                             &path,
                             &user,
@@ -2018,6 +2020,7 @@ SMBC_getxattr_ctx(SMBCCTX *context,
                 const char * write_time_attr;
                 const char * change_time_attr;
         } attr_strings;
+       uint16_t port = 0;
        TALLOC_CTX *frame = talloc_stackframe();
 
        if (!context || !context->internal->initialized) {
@@ -2039,6 +2042,7 @@ SMBC_getxattr_ctx(SMBCCTX *context,
                             fname,
                             &workgroup,
                             &server,
+                            &port,
                             &share,
                             &path,
                             &user,
@@ -2153,6 +2157,7 @@ SMBC_removexattr_ctx(SMBCCTX *context,
        char *password = NULL;
        char *workgroup = NULL;
        char *path = NULL;
+       uint16_t port = 0;
        TALLOC_CTX *frame = talloc_stackframe();
 
        if (!context || !context->internal->initialized) {
@@ -2174,6 +2179,7 @@ SMBC_removexattr_ctx(SMBCCTX *context,
                             fname,
                             &workgroup,
                             &server,
+                            &port,
                             &share,
                             &path,
                             &user,