summaryrefslogtreecommitdiffstats
path: root/contrib/smbfs/lib/smb/ctx.c
diff options
context:
space:
mode:
authorbp <bp@FreeBSD.org>2005-10-02 08:32:49 +0000
committerbp <bp@FreeBSD.org>2005-10-02 08:32:49 +0000
commit0d80e85872c1b891d25d1e3681b1d40f02959b22 (patch)
tree0b9bbf8d7863d1bf2dc5b60082d7c5e3ef85746a /contrib/smbfs/lib/smb/ctx.c
parent1becc1ee390faaa609b04a998f1538c4f6723d02 (diff)
downloadFreeBSD-src-0d80e85872c1b891d25d1e3681b1d40f02959b22.zip
FreeBSD-src-0d80e85872c1b891d25d1e3681b1d40f02959b22.tar.gz
Allow user to override default port numbers used by communication
protocols. This is very useful for tunneled SMB connections. MFC after: 4 weeks
Diffstat (limited to 'contrib/smbfs/lib/smb/ctx.c')
-rw-r--r--contrib/smbfs/lib/smb/ctx.c47
1 files changed, 44 insertions, 3 deletions
diff --git a/contrib/smbfs/lib/smb/ctx.c b/contrib/smbfs/lib/smb/ctx.c
index 9abe9ca..0709b6b 100644
--- a/contrib/smbfs/lib/smb/ctx.c
+++ b/contrib/smbfs/lib/smb/ctx.c
@@ -77,6 +77,7 @@ smb_ctx_init(struct smb_ctx *ctx, int argc, char *argv[],
ctx->ct_parsedlevel = SMBL_NONE;
ctx->ct_minlevel = minlevel;
ctx->ct_maxlevel = maxlevel;
+ ctx->ct_smbtcpport = SMB_TCP_PORT;
ctx->ct_ssn.ioc_opt = SMBVOPT_CREATE;
ctx->ct_ssn.ioc_timeout = 15;
@@ -167,14 +168,14 @@ getsubstring(const char *p, u_char sep, char *dest, int maxlen, const char **nex
}
/*
- * Here we expect something like "[proto:]//[user@]host[/share][/path]"
+ * Here we expect something like "[proto:]//[user@]host[:psmb[:pnb]][/share][/path]"
*/
int
smb_ctx_parseunc(struct smb_ctx *ctx, const char *unc, int sharetype,
const char **next)
{
const char *p = unc;
- char *p1;
+ char *p1, *psmb, *pnb;
char tmp[1024];
int error ;
@@ -211,6 +212,27 @@ smb_ctx_parseunc(struct smb_ctx *ctx, const char *unc, int sharetype,
smb_error("empty server name", 0);
return EINVAL;
}
+ /*
+ * Check for port number specification.
+ */
+ psmb = strchr(tmp, ':');
+ if (psmb) {
+ *psmb++ = '\0';
+ pnb = strchr(psmb, ':');
+ if (pnb) {
+ *pnb++ = '\0';
+ error = smb_ctx_setnbport(ctx, atoi(pnb));
+ if (error) {
+ smb_error("Invalid NetBIOS port number", 0);
+ return error;
+ }
+ }
+ error = smb_ctx_setsmbport(ctx, atoi(psmb));
+ if (error) {
+ smb_error("Invalid SMB port number", 0);
+ return error;
+ }
+ }
error = smb_ctx_setserver(ctx, tmp);
if (error)
return error;
@@ -284,6 +306,25 @@ smb_ctx_setserver(struct smb_ctx *ctx, const char *name)
}
int
+smb_ctx_setnbport(struct smb_ctx *ctx, int port)
+{
+ if (port < 1 || port > 0xffff)
+ return EINVAL;
+ ctx->ct_nb->nb_nmbtcpport = port;
+ return 0;
+}
+
+int
+smb_ctx_setsmbport(struct smb_ctx *ctx, int port)
+{
+ if (port < 1 || port > 0xffff)
+ return EINVAL;
+ ctx->ct_smbtcpport = port;
+ ctx->ct_nb->nb_smbtcpport = port;
+ return 0;
+}
+
+int
smb_ctx_setuser(struct smb_ctx *ctx, const char *name)
{
if (strlen(name) > SMB_MAXUSERNAMELEN) {
@@ -507,7 +548,7 @@ smb_ctx_resolve(struct smb_ctx *ctx)
if (error) return error;
}
if (ctx->ct_srvaddr) {
- error = nb_resolvehost_in(ctx->ct_srvaddr, &sap);
+ error = nb_resolvehost_in(ctx->ct_srvaddr, &sap, ctx->ct_smbtcpport);
} else {
error = nbns_resolvename(ssn->ioc_srvname, ctx->ct_nb, &sap);
}
OpenPOWER on IntegriCloud