[PATCH] Fix bug 9796 - libsmbclient does not accept non-standard port.

Jeremy Allison jra at samba.org
Mon Jun 10 17:50:06 MDT 2013


This has been requested and tested by the Gnome gvfs
developers, and they have confirmed it works for them.

Please review and push to master if you're happy.

Jeremy.
-------------- next part --------------
From 101062615358ec340419cb65a0b1c212efb75ea0 Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Tue, 16 Apr 2013 12:09:41 -0700
Subject: [PATCH 1/5] Add the ability to parse out the port to
 SMBC_parse_path().

Signed-off-by: Jeremy Allison <jra at samba.org>
---
 source3/include/libsmb_internal.h |    1 +
 source3/libsmb/libsmb_dir.c       |   16 ++++++++++++++++
 source3/libsmb/libsmb_file.c      |   12 ++++++++++++
 source3/libsmb/libsmb_path.c      |   24 ++++++++++++++++++++++++
 source3/libsmb/libsmb_printjob.c  |    6 ++++++
 source3/libsmb/libsmb_stat.c      |    4 ++++
 source3/libsmb/libsmb_xattr.c     |    6 ++++++
 7 files changed, 69 insertions(+)

diff --git a/source3/include/libsmb_internal.h b/source3/include/libsmb_internal.h
index aba159a..bd91438 100644
--- a/source3/include/libsmb_internal.h
+++ b/source3/include/libsmb_internal.h
@@ -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,
diff --git a/source3/libsmb/libsmb_dir.c b/source3/libsmb/libsmb_dir.c
index 700196c..5428b17 100644
--- a/source3/libsmb/libsmb_dir.c
+++ b/source3/libsmb/libsmb_dir.c
@@ -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,
diff --git a/source3/libsmb/libsmb_file.c b/source3/libsmb/libsmb_file.c
index 9521542..06d09ac 100644
--- a/source3/libsmb/libsmb_file.c
+++ b/source3/libsmb/libsmb_file.c
@@ -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,
diff --git a/source3/libsmb/libsmb_path.c b/source3/libsmb/libsmb_path.c
index 1dcf2dd..b286691 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 ... */
 	}
diff --git a/source3/libsmb/libsmb_printjob.c b/source3/libsmb/libsmb_printjob.c
index 173fa32..3189463 100644
--- a/source3/libsmb/libsmb_printjob.c
+++ b/source3/libsmb/libsmb_printjob.c
@@ -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,
diff --git a/source3/libsmb/libsmb_stat.c b/source3/libsmb/libsmb_stat.c
index 5cfbcb8..f87e2d3 100644
--- a/source3/libsmb/libsmb_stat.c
+++ b/source3/libsmb/libsmb_stat.c
@@ -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,
diff --git a/source3/libsmb/libsmb_xattr.c b/source3/libsmb/libsmb_xattr.c
index c2ba61f..89bdd25 100644
--- a/source3/libsmb/libsmb_xattr.c
+++ b/source3/libsmb/libsmb_xattr.c
@@ -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,
-- 
1.7.10.4


From ad7d0428d64251deee84e8ff3b41bb6d5f1a6657 Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Tue, 16 Apr 2013 12:22:11 -0700
Subject: [PATCH 2/5] Add port argument to SMBC_attr_server(). Does nothing as
 yet.

Signed-off-by: Jeremy Allison <jra at samba.org>
---
 source3/include/libsmb_internal.h |    1 +
 source3/libsmb/libsmb_server.c    |    1 +
 source3/libsmb/libsmb_xattr.c     |    6 +++---
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/source3/include/libsmb_internal.h b/source3/include/libsmb_internal.h
index bd91438..5a3df14 100644
--- a/source3/include/libsmb_internal.h
+++ b/source3/include/libsmb_internal.h
@@ -483,6 +483,7 @@ SMBCSRV *
 SMBC_attr_server(TALLOC_CTX *ctx,
                  SMBCCTX *context,
                  const char *server,
+                 uint16_t port,
                  const char *share,
                  char **pp_workgroup,
                  char **pp_username,
diff --git a/source3/libsmb/libsmb_server.c b/source3/libsmb/libsmb_server.c
index 0d39245..92a3691 100644
--- a/source3/libsmb/libsmb_server.c
+++ b/source3/libsmb/libsmb_server.c
@@ -680,6 +680,7 @@ SMBCSRV *
 SMBC_attr_server(TALLOC_CTX *ctx,
                  SMBCCTX *context,
                  const char *server,
+                 uint16_t port,
                  const char *share,
                  char **pp_workgroup,
                  char **pp_username,
diff --git a/source3/libsmb/libsmb_xattr.c b/source3/libsmb/libsmb_xattr.c
index 89bdd25..62cf4a1 100644
--- a/source3/libsmb/libsmb_xattr.c
+++ b/source3/libsmb/libsmb_xattr.c
@@ -1775,7 +1775,7 @@ SMBC_setxattr_ctx(SMBCCTX *context,
 	}
 
         if (! srv->no_nt_session) {
-                ipc_srv = SMBC_attr_server(frame, context, server, share,
+                ipc_srv = SMBC_attr_server(frame, context, server, port, share,
                                            &workgroup, &user, &password);
                 if (! ipc_srv) {
                         srv->no_nt_session = True;
@@ -2070,7 +2070,7 @@ SMBC_getxattr_ctx(SMBCCTX *context,
         }
 
         if (! srv->no_nt_session) {
-                ipc_srv = SMBC_attr_server(frame, context, server, share,
+                ipc_srv = SMBC_attr_server(frame, context, server, port, share,
                                            &workgroup, &user, &password);
                 if (! ipc_srv) {
                         srv->no_nt_session = True;
@@ -2207,7 +2207,7 @@ SMBC_removexattr_ctx(SMBCCTX *context,
         }
 
         if (! srv->no_nt_session) {
-                ipc_srv = SMBC_attr_server(frame, context, server, share,
+                ipc_srv = SMBC_attr_server(frame, context, server, port, share,
                                            &workgroup, &user, &password);
                 if (! ipc_srv) {
                         srv->no_nt_session = True;
-- 
1.7.10.4


From 33704dacd5c59bc07cc78d02f7d49a41986bcee3 Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Tue, 16 Apr 2013 14:11:08 -0700
Subject: [PATCH 3/5] Add the port argument to SMBC_server().

Signed-off-by: Jeremy Allison <jra at samba.org>
---
 source3/include/libsmb_internal.h |    1 +
 source3/libsmb/libsmb_dir.c       |   22 +++++++++++-----------
 source3/libsmb/libsmb_file.c      |    2 +-
 source3/libsmb/libsmb_printjob.c  |    4 ++--
 source3/libsmb/libsmb_server.c    |    3 ++-
 source3/libsmb/libsmb_stat.c      |    2 +-
 source3/libsmb/libsmb_xattr.c     |    6 +++---
 7 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/source3/include/libsmb_internal.h b/source3/include/libsmb_internal.h
index 5a3df14..bd06b53 100644
--- a/source3/include/libsmb_internal.h
+++ b/source3/include/libsmb_internal.h
@@ -474,6 +474,7 @@ SMBC_server(TALLOC_CTX *ctx,
             SMBCCTX *context,
             bool connect_if_not_found,
             const char *server,
+            uint16_t port,
             const char *share,
             char **pp_workgroup,
             char **pp_username,
diff --git a/source3/libsmb/libsmb_dir.c b/source3/libsmb/libsmb_dir.c
index 5428b17..87e10d8 100644
--- a/source3/libsmb/libsmb_dir.c
+++ b/source3/libsmb/libsmb_dir.c
@@ -581,7 +581,7 @@ SMBC_opendir_ctx(SMBCCTX *context,
                          * workgroups/domains that it knows about.
                          */
 
-                        srv = SMBC_server(frame, context, True, server, "IPC$",
+                        srv = SMBC_server(frame, context, True, server, port, "IPC$",
                                           &workgroup, &user, &password);
                         if (!srv) {
                                 continue;
@@ -636,7 +636,7 @@ SMBC_opendir_ctx(SMBCCTX *context,
                          * exist.
                          */
                         srv = SMBC_server(frame, context, False,
-                                          server, "IPC$",
+                                          server, port, "IPC$",
                                           &workgroup, &user, &password);
 
                         /*
@@ -685,7 +685,7 @@ SMBC_opendir_ctx(SMBCCTX *context,
                                  * we do not already have one
                                  */
 				srv = SMBC_server(frame, context, True,
-                                                  buserver, "IPC$",
+                                                  buserver, port, "IPC$",
                                                   &workgroup,
                                                   &user, &password);
 				if (!srv) {
@@ -721,7 +721,7 @@ SMBC_opendir_ctx(SMBCCTX *context,
                                  */
                                 if (!srv) {
                                         srv = SMBC_server(frame, context, True,
-                                                          server, "IPC$",
+                                                          server, port, "IPC$",
                                                           &workgroup,
                                                           &user, &password);
                                 }
@@ -783,7 +783,7 @@ SMBC_opendir_ctx(SMBCCTX *context,
 			/* We connect to the server and list the directory */
 			dir->dir_type = SMBC_FILE_SHARE;
 
-			srv = SMBC_server(frame, context, True, server, share,
+			srv = SMBC_server(frame, context, True, server, port, share,
                                           &workgroup, &user, &password);
 
 			if (!srv) {
@@ -1208,7 +1208,7 @@ SMBC_mkdir_ctx(SMBCCTX *context,
 	}
 
 	srv = SMBC_server(frame, context, True,
-                          server, share, &workgroup, &user, &password);
+                          server, port, share, &workgroup, &user, &password);
 
 	if (!srv) {
 
@@ -1319,7 +1319,7 @@ SMBC_rmdir_ctx(SMBCCTX *context,
 	}
 
 	srv = SMBC_server(frame, context, True,
-                          server, share, &workgroup, &user, &password);
+                          server, port, share, &workgroup, &user, &password);
 
 	if (!srv) {
 
@@ -1608,7 +1608,7 @@ SMBC_chmod_ctx(SMBCCTX *context,
 	}
 
 	srv = SMBC_server(frame, context, True,
-                          server, share, &workgroup, &user, &password);
+                          server, port, share, &workgroup, &user, &password);
 
 	if (!srv) {
 		TALLOC_FREE(frame);
@@ -1726,7 +1726,7 @@ SMBC_utimes_ctx(SMBCCTX *context,
 	}
 
 	srv = SMBC_server(frame, context, True,
-                          server, share, &workgroup, &user, &password);
+                          server, port, share, &workgroup, &user, &password);
 
 	if (!srv) {
 		TALLOC_FREE(frame);
@@ -1805,7 +1805,7 @@ SMBC_unlink_ctx(SMBCCTX *context,
 	}
 
 	srv = SMBC_server(frame, context, True,
-                          server, share, &workgroup, &user, &password);
+                          server, port, share, &workgroup, &user, &password);
 
 	if (!srv) {
 		TALLOC_FREE(frame);
@@ -1979,7 +1979,7 @@ SMBC_rename_ctx(SMBCCTX *ocontext,
 	}
 
 	srv = SMBC_server(frame, ocontext, True,
-                          server1, share1, &workgroup, &user1, &password1);
+                          server1, port1, share1, &workgroup, &user1, &password1);
 	if (!srv) {
 		TALLOC_FREE(frame);
 		return -1;
diff --git a/source3/libsmb/libsmb_file.c b/source3/libsmb/libsmb_file.c
index 06d09ac..822491b 100644
--- a/source3/libsmb/libsmb_file.c
+++ b/source3/libsmb/libsmb_file.c
@@ -91,7 +91,7 @@ SMBC_open_ctx(SMBCCTX *context,
 	}
 
 	srv = SMBC_server(frame, context, True,
-                          server, share, &workgroup, &user, &password);
+                          server, port, share, &workgroup, &user, &password);
 	if (!srv) {
 		if (errno == EPERM) errno = EACCES;
 		TALLOC_FREE(frame);
diff --git a/source3/libsmb/libsmb_printjob.c b/source3/libsmb/libsmb_printjob.c
index 3189463..3f6be3e 100644
--- a/source3/libsmb/libsmb_printjob.c
+++ b/source3/libsmb/libsmb_printjob.c
@@ -235,7 +235,7 @@ SMBC_list_print_jobs_ctx(SMBCCTX *context,
 	}
 
         srv = SMBC_server(frame, context, True,
-                          server, share, &workgroup, &user, &password);
+                          server, port, share, &workgroup, &user, &password);
 
         if (!srv) {
 		TALLOC_FREE(frame);
@@ -313,7 +313,7 @@ SMBC_unlink_print_job_ctx(SMBCCTX *context,
 	}
 
         srv = SMBC_server(frame, context, True,
-                          server, share, &workgroup, &user, &password);
+                          server, port, share, &workgroup, &user, &password);
 
         if (!srv) {
 		TALLOC_FREE(frame);
diff --git a/source3/libsmb/libsmb_server.c b/source3/libsmb/libsmb_server.c
index 92a3691..91859fa 100644
--- a/source3/libsmb/libsmb_server.c
+++ b/source3/libsmb/libsmb_server.c
@@ -629,6 +629,7 @@ SMBC_server(TALLOC_CTX *ctx,
 		SMBCCTX *context,
 		bool connect_if_not_found,
 		const char *server,
+		uint16_t port,
 		const char *share,
 		char **pp_workgroup,
 		char **pp_username,
@@ -699,7 +700,7 @@ SMBC_attr_server(TALLOC_CTX *ctx,
 	 * i.e., a normal share or a referred share from
 	 * 'msdfs proxy' share.
 	 */
-	srv = SMBC_server(ctx, context, true, server, share,
+	srv = SMBC_server(ctx, context, true, server, port, share,
 			pp_workgroup, pp_username, pp_password);
 	if (!srv) {
 		return NULL;
diff --git a/source3/libsmb/libsmb_stat.c b/source3/libsmb/libsmb_stat.c
index f87e2d3..9c5be33 100644
--- a/source3/libsmb/libsmb_stat.c
+++ b/source3/libsmb/libsmb_stat.c
@@ -164,7 +164,7 @@ SMBC_stat_ctx(SMBCCTX *context,
 	}
 
 	srv = SMBC_server(frame, context, True,
-                          server, share, &workgroup, &user, &password);
+                          server, port, share, &workgroup, &user, &password);
 	if (!srv) {
 		TALLOC_FREE(frame);
 		return -1;  /* errno set by SMBC_server */
diff --git a/source3/libsmb/libsmb_xattr.c b/source3/libsmb/libsmb_xattr.c
index 62cf4a1..22ffa8f 100644
--- a/source3/libsmb/libsmb_xattr.c
+++ b/source3/libsmb/libsmb_xattr.c
@@ -1768,7 +1768,7 @@ SMBC_setxattr_ctx(SMBCCTX *context,
 	}
 
 	srv = SMBC_server(frame, context, True,
-                          server, share, &workgroup, &user, &password);
+                          server, port, share, &workgroup, &user, &password);
 	if (!srv) {
 		TALLOC_FREE(frame);
 		return -1;  /* errno set by SMBC_server */
@@ -2063,7 +2063,7 @@ SMBC_getxattr_ctx(SMBCCTX *context,
 	}
 
         srv = SMBC_server(frame, context, True,
-                          server, share, &workgroup, &user, &password);
+                          server, port, share, &workgroup, &user, &password);
         if (!srv) {
 		TALLOC_FREE(frame);
                 return -1;  /* errno set by SMBC_server */
@@ -2200,7 +2200,7 @@ SMBC_removexattr_ctx(SMBCCTX *context,
 	}
 
         srv = SMBC_server(frame, context, True,
-                          server, share, &workgroup, &user, &password);
+                          server, port, share, &workgroup, &user, &password);
         if (!srv) {
 		TALLOC_FREE(frame);
                 return -1;  /* errno set by SMBC_server */
-- 
1.7.10.4


From 5f3bd4f38a9221c3ebe22d180489b3c73aed4484 Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Tue, 16 Apr 2013 14:13:57 -0700
Subject: [PATCH 4/5] Plumb the 'port' parameter into the connect code.

Signed-off-by: Jeremy Allison <jra at samba.org>
---
 source3/libsmb/libsmb_server.c |   19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/source3/libsmb/libsmb_server.c b/source3/libsmb/libsmb_server.c
index 91859fa..1fe8fd0 100644
--- a/source3/libsmb/libsmb_server.c
+++ b/source3/libsmb/libsmb_server.c
@@ -239,6 +239,7 @@ SMBC_server_internal(TALLOC_CTX *ctx,
             SMBCCTX *context,
             bool connect_if_not_found,
             const char *server,
+            uint16_t port,
             const char *share,
             char **pp_workgroup,
             char **pp_username,
@@ -421,20 +422,22 @@ SMBC_server_internal(TALLOC_CTX *ctx,
 		flags |= CLI_FULL_CONNECTION_USE_NT_HASH;
 	}
 
-        if (share == NULL || *share == '\0' || is_ipc) {
-		/*
-		 * Try 139 first for IPC$
-		 */
-		status = cli_connect_nb(server_n, NULL, NBT_SMB_PORT, 0x20,
+	if (port == 0) {
+	        if (share == NULL || *share == '\0' || is_ipc) {
+			/*
+			 * Try 139 first for IPC$
+			 */
+			status = cli_connect_nb(server_n, NULL, NBT_SMB_PORT, 0x20,
 					smbc_getNetbiosName(context),
 					SMB_SIGNING_DEFAULT, flags, &c);
+		}
 	}
 
 	if (!NT_STATUS_IS_OK(status)) {
 		/*
 		 * No IPC$ or 139 did not work
 		 */
-		status = cli_connect_nb(server_n, NULL, 0, 0x20,
+		status = cli_connect_nb(server_n, NULL, port, 0x20,
 					smbc_getNetbiosName(context),
 					SMB_SIGNING_DEFAULT, flags, &c);
 	}
@@ -506,7 +509,7 @@ SMBC_server_internal(TALLOC_CTX *ctx,
 				*pp_workgroup)) {
 		cli_shutdown(c);
 		srv = SMBC_server_internal(ctx, context, connect_if_not_found,
-				newserver, newshare, pp_workgroup,
+				newserver, port, newshare, pp_workgroup,
 				pp_username, pp_password, in_cache);
 		TALLOC_FREE(newserver);
 		TALLOC_FREE(newshare);
@@ -639,7 +642,7 @@ SMBC_server(TALLOC_CTX *ctx,
 	bool in_cache = false;
 
 	srv = SMBC_server_internal(ctx, context, connect_if_not_found,
-			server, share, pp_workgroup,
+			server, port, share, pp_workgroup,
 			pp_username, pp_password, &in_cache);
 
 	if (!srv) {
-- 
1.7.10.4


From 73589a1c3b058c994a0d3781b8c1bf89e1a7a7e6 Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Tue, 16 Apr 2013 14:53:09 -0700
Subject: [PATCH 5/5] Add smbc_getPort(), smbc_setPort(). Bump the .so minor
 number. Signed-off-by: Jeremy Allison <jra at samba.org>

---
 source3/include/libsmb_internal.h       |    1 +
 source3/include/libsmbclient.h          |   14 ++++++++++++++
 source3/libsmb/ABI/smbclient-0.1.0.sigs |    2 ++
 source3/libsmb/libsmb_context.c         |    1 +
 source3/libsmb/libsmb_path.c            |    2 +-
 source3/libsmb/libsmb_setget.c          |   19 +++++++++++++++++++
 source3/libsmb/wscript                  |    2 +-
 7 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/source3/include/libsmb_internal.h b/source3/include/libsmb_internal.h
index bd06b53..7ce37d2 100644
--- a/source3/include/libsmb_internal.h
+++ b/source3/include/libsmb_internal.h
@@ -244,6 +244,7 @@ struct SMBC_internal_data {
         }               smb;
 
 #endif
+	uint16_t	port;
 };	
 
 /* Functions in libsmb_cache.c */
diff --git a/source3/include/libsmbclient.h b/source3/include/libsmbclient.h
index 61ff6a3..5846e9b 100644
--- a/source3/include/libsmbclient.h
+++ b/source3/include/libsmbclient.h
@@ -76,6 +76,7 @@ extern "C" {
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/statvfs.h>
+#include <stdint.h>
 #include <fcntl.h>
 #include <utime.h>
 
@@ -507,6 +508,19 @@ void
 smbc_setTimeout(SMBCCTX *c, int timeout);
 
 
+/**
+ * Get the TCP port used to connect (0 means default).
+ */
+uint16_t
+smbc_getPort(SMBCCTX *c);
+
+/**
+ * Set the TCP port used to connect (0 means default).
+ */
+void
+smbc_setPort(SMBCCTX *c, uint16_t port);
+
+
 
 /***********************************
  * Getters and setters for OPTIONS *
diff --git a/source3/libsmb/ABI/smbclient-0.1.0.sigs b/source3/libsmb/ABI/smbclient-0.1.0.sigs
index bbd7700..3dea59c 100644
--- a/source3/libsmb/ABI/smbclient-0.1.0.sigs
+++ b/source3/libsmb/ABI/smbclient-0.1.0.sigs
@@ -67,6 +67,7 @@ smbc_getOptionUseKerberos: smbc_bool (SMBCCTX *)
 smbc_getOptionUserData: void *(SMBCCTX *)
 smbc_getServerCacheData: struct smbc_server_cache *(SMBCCTX *)
 smbc_getTimeout: int (SMBCCTX *)
+smbc_getPort: uint16_t (SMBCCTX *)
 smbc_getUser: char *(SMBCCTX *)
 smbc_getWorkgroup: char *(SMBCCTX *)
 smbc_getdents: int (unsigned int, struct smbc_dirent *, int)
@@ -151,6 +152,7 @@ smbc_setOptionUseKerberos: void (SMBCCTX *, smbc_bool)
 smbc_setOptionUserData: void (SMBCCTX *, void *)
 smbc_setServerCacheData: void (SMBCCTX *, struct smbc_server_cache *)
 smbc_setTimeout: void (SMBCCTX *, int)
+smbc_setPort: void (SMBCCTX *, uint16_t)
 smbc_setUser: void (SMBCCTX *, char *)
 smbc_setWorkgroup: void (SMBCCTX *, char *)
 smbc_set_context: SMBCCTX *(SMBCCTX *)
diff --git a/source3/libsmb/libsmb_context.c b/source3/libsmb/libsmb_context.c
index b529cbe..6eb2996 100644
--- a/source3/libsmb/libsmb_context.c
+++ b/source3/libsmb/libsmb_context.c
@@ -169,6 +169,7 @@ smbc_new_context(void)
 
         smbc_setDebug(context, 0);
         smbc_setTimeout(context, 20000);
+        smbc_setPort(context, 0);
 
         smbc_setOptionFullTimeNames(context, False);
         smbc_setOptionOpenShareMode(context, SMBC_SHAREMODE_DENY_NONE);
diff --git a/source3/libsmb/libsmb_path.c b/source3/libsmb/libsmb_path.c
index b286691..6208f02 100644
--- a/source3/libsmb/libsmb_path.c
+++ b/source3/libsmb/libsmb_path.c
@@ -239,7 +239,7 @@ SMBC_parse_path(TALLOC_CTX *ctx,
 
 	/* Ensure these returns are at least valid pointers. */
 	*pp_server = talloc_strdup(ctx, "");
-	*p_port = 0;
+	*p_port = smbc_getPort(context);
 	*pp_share = talloc_strdup(ctx, "");
 	*pp_path = talloc_strdup(ctx, "");
 	*pp_user = talloc_strdup(ctx, "");
diff --git a/source3/libsmb/libsmb_setget.c b/source3/libsmb/libsmb_setget.c
index 60bbc8b..0bd5290 100644
--- a/source3/libsmb/libsmb_setget.c
+++ b/source3/libsmb/libsmb_setget.c
@@ -116,6 +116,25 @@ smbc_setTimeout(SMBCCTX *c, int timeout)
         c->timeout = timeout;
 }
 
+/**
+ * Get the TCP port used to connect.
+ */
+uint16_t
+smbc_getPort(SMBCCTX *c)
+{
+        return c->internal->port;
+}
+
+/**
+ * Set the TCP port used to connect.
+ */
+void
+smbc_setPort(SMBCCTX *c, uint16_t port)
+{
+        c->internal->port = port;
+}
+
+
 /** Get whether to log to standard error instead of standard output */
 smbc_bool
 smbc_getOptionDebugToStderr(SMBCCTX *c)
diff --git a/source3/libsmb/wscript b/source3/libsmb/wscript
index c5444b0..9750ed3 100644
--- a/source3/libsmb/wscript
+++ b/source3/libsmb/wscript
@@ -27,5 +27,5 @@ def build(bld):
                        public_headers='../include/libsmbclient.h',
                        abi_directory='ABI',
                        abi_match='smbc_*',
-                       vnum='0.2.0',
+                       vnum='0.2.1',
                        pc_files='smbclient.pc')
-- 
1.7.10.4



More information about the samba-technical mailing list