diff options
author | bp <bp@FreeBSD.org> | 2005-10-02 08:32:49 +0000 |
---|---|---|
committer | bp <bp@FreeBSD.org> | 2005-10-02 08:32:49 +0000 |
commit | 0d80e85872c1b891d25d1e3681b1d40f02959b22 (patch) | |
tree | 0b9bbf8d7863d1bf2dc5b60082d7c5e3ef85746a /contrib/smbfs/lib/smb | |
parent | 1becc1ee390faaa609b04a998f1538c4f6723d02 (diff) | |
download | FreeBSD-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')
-rw-r--r-- | contrib/smbfs/lib/smb/ctx.c | 47 | ||||
-rw-r--r-- | contrib/smbfs/lib/smb/nb.c | 8 | ||||
-rw-r--r-- | contrib/smbfs/lib/smb/nb_net.c | 6 | ||||
-rw-r--r-- | contrib/smbfs/lib/smb/nbns_rq.c | 5 |
4 files changed, 56 insertions, 10 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); } diff --git a/contrib/smbfs/lib/smb/nb.c b/contrib/smbfs/lib/smb/nb.c index 2be9ab0..652a057 100644 --- a/contrib/smbfs/lib/smb/nb.c +++ b/contrib/smbfs/lib/smb/nb.c @@ -30,6 +30,7 @@ * SUCH DAMAGE. * * $Id: nb.c,v 1.4 2001/04/16 04:33:01 bp Exp $ + * $FreeBSD$ */ #include <sys/param.h> #include <sys/socket.h> @@ -57,6 +58,9 @@ nb_ctx_create(struct nb_ctx **ctxpp) if (ctx == NULL) return ENOMEM; bzero(ctx, sizeof(struct nb_ctx)); + ctx->nb_nmbtcpport = NMB_TCP_PORT; + ctx->nb_smbtcpport = SMB_TCP_PORT; + *ctxpp = ctx; return 0; } @@ -111,7 +115,7 @@ nb_ctx_resolve(struct nb_ctx *ctx) if (ctx->nb_nsname == NULL) { ctx->nb_ns.sin_addr.s_addr = htonl(INADDR_BROADCAST); } else { - error = nb_resolvehost_in(ctx->nb_nsname, &sap); + error = nb_resolvehost_in(ctx->nb_nsname, &sap, ctx->nb_smbtcpport); if (error) { smb_error("can't resolve %s", error, ctx->nb_nsname); return error; @@ -123,7 +127,7 @@ nb_ctx_resolve(struct nb_ctx *ctx) bcopy(sap, &ctx->nb_ns, sizeof(ctx->nb_ns)); free(sap); } - ctx->nb_ns.sin_port = htons(137); + ctx->nb_ns.sin_port = htons(ctx->nb_nmbtcpport); ctx->nb_ns.sin_family = AF_INET; ctx->nb_ns.sin_len = sizeof(ctx->nb_ns); ctx->nb_flags |= NBCF_RESOLVED; diff --git a/contrib/smbfs/lib/smb/nb_net.c b/contrib/smbfs/lib/smb/nb_net.c index 62390ef..41fc384 100644 --- a/contrib/smbfs/lib/smb/nb_net.c +++ b/contrib/smbfs/lib/smb/nb_net.c @@ -66,7 +66,7 @@ nb_getlocalname(char *name) } int -nb_resolvehost_in(const char *name, struct sockaddr **dest) +nb_resolvehost_in(const char *name, struct sockaddr **dest, long smbtcpport) { struct hostent* h; struct sockaddr_in *sinp; @@ -94,7 +94,7 @@ nb_resolvehost_in(const char *name, struct sockaddr **dest) sinp->sin_len = len; sinp->sin_family = h->h_addrtype; memcpy(&sinp->sin_addr.s_addr, h->h_addr, 4); - sinp->sin_port = htons(SMB_TCP_PORT); + sinp->sin_port = htons(smbtcpport); *dest = (struct sockaddr*)sinp; return 0; } @@ -164,7 +164,7 @@ nb_hostlookup(struct nb_name *np, const char *server, const char *hint, return error; do { if (hint) { - error = nb_resolvehost_in(host, snb); + error = nb_resolvehost_in(host, snb, SMB_TCP_PORT); if (error) break; } else { diff --git a/contrib/smbfs/lib/smb/nbns_rq.c b/contrib/smbfs/lib/smb/nbns_rq.c index 5ea22f1..9d55b25 100644 --- a/contrib/smbfs/lib/smb/nbns_rq.c +++ b/contrib/smbfs/lib/smb/nbns_rq.c @@ -30,6 +30,7 @@ * SUCH DAMAGE. * * $Id: nbns_rq.c,v 1.5 2001/02/17 03:07:24 bp Exp $ + * $FreeBSD$ */ #include <sys/param.h> #include <sys/socket.h> @@ -86,7 +87,7 @@ nbns_resolvename(const char *name, struct nb_ctx *ctx, struct sockaddr **adpp) dest->sin_family = AF_INET; dest->sin_len = sizeof(*dest); if (dest->sin_port == 0) - dest->sin_port = htons(137); + dest->sin_port = htons(ctx->nb_nmbtcpport); if (dest->sin_addr.s_addr == INADDR_ANY) dest->sin_addr.s_addr = htonl(INADDR_BROADCAST); if (dest->sin_addr.s_addr == INADDR_BROADCAST) @@ -131,7 +132,7 @@ nbns_resolvename(const char *name, struct nb_ctx *ctx, struct sockaddr **adpp) dest->sin_len = len; dest->sin_family = AF_INET; bcopy(rr.rr_data + 2, &dest->sin_addr.s_addr, 4); - dest->sin_port = htons(SMB_TCP_PORT); + dest->sin_port = htons(ctx->nb_smbtcpport); *adpp = (struct sockaddr*)dest; ctx->nb_lastns = rqp->nr_sender; break; |