Allow user to override default port numbers used by communication
protocols. This is very useful for tunneled SMB connections. MFC after: 4 weeks
This commit is contained in:
parent
8862edf857
commit
ef29b0f6a1
@ -30,6 +30,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: nb_lib.h,v 1.2 2000/07/17 01:49:27 bp Exp $
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#ifndef _NETSMB_NB_LIB_H_
|
||||
#define _NETSMB_NB_LIB_H_
|
||||
@ -63,6 +64,8 @@ struct nb_ctx {
|
||||
char * nb_nsname; /* name server */
|
||||
struct sockaddr_in nb_ns; /* ip addr of name server */
|
||||
struct sockaddr_in nb_lastns;
|
||||
long nb_nmbtcpport; /* default: NMB_TCP_PORT = 137 */
|
||||
long nb_smbtcpport; /* default: SMB_TCP_PORT = 139 */
|
||||
};
|
||||
|
||||
/*
|
||||
@ -128,7 +131,7 @@ int nb_snballoc(int namelen, struct sockaddr_nb **);
|
||||
void nb_snbfree(struct sockaddr*);
|
||||
int nb_sockaddr(struct sockaddr *, struct nb_name *, struct sockaddr_nb **);
|
||||
|
||||
int nb_resolvehost_in(const char *, struct sockaddr **);
|
||||
int nb_resolvehost_in(const char *, struct sockaddr **, long);
|
||||
int nbns_resolvename(const char *, struct nb_ctx *, struct sockaddr **);
|
||||
int nb_getlocalname(char *name);
|
||||
int nb_enum_if(struct nb_ifdesc **, int);
|
||||
|
@ -109,6 +109,7 @@ struct smb_ctx {
|
||||
struct nb_ctx * ct_nb;
|
||||
struct smbioc_ossn ct_ssn;
|
||||
struct smbioc_oshare ct_sh;
|
||||
long ct_smbtcpport;
|
||||
};
|
||||
|
||||
#define SMBCF_NOPWD 0x0001 /* don't ask for a password */
|
||||
@ -175,6 +176,8 @@ void smb_ctx_done(struct smb_ctx *);
|
||||
int smb_ctx_parseunc(struct smb_ctx *, const char *, int, const char **);
|
||||
int smb_ctx_setcharset(struct smb_ctx *, const char *);
|
||||
int smb_ctx_setserver(struct smb_ctx *, const char *);
|
||||
int smb_ctx_setnbport(struct smb_ctx *, int);
|
||||
int smb_ctx_setsmbport(struct smb_ctx *, int);
|
||||
int smb_ctx_setuser(struct smb_ctx *, const char *);
|
||||
int smb_ctx_setshare(struct smb_ctx *, const char *, int);
|
||||
int smb_ctx_setscope(struct smb_ctx *, const char *);
|
||||
|
@ -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;
|
||||
@ -283,6 +305,25 @@ smb_ctx_setserver(struct smb_ctx *ctx, const char *name)
|
||||
return 0;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
@ -24,7 +24,9 @@
|
||||
.Op Fl n Ar opt
|
||||
.Op Fl u Ar uid
|
||||
.Sm off
|
||||
.No // Ar user No @ Ar server No / Ar share
|
||||
.No // Ar user No @ Ar server
|
||||
.Op Ar :port1 Op Ar :port2
|
||||
.No / Ar share
|
||||
.Sm on
|
||||
.Ar node
|
||||
.Sh DESCRIPTION
|
||||
@ -110,7 +112,7 @@ server.
|
||||
User ID and group ID assigned to files.
|
||||
The default are owner and group IDs from
|
||||
the directory where the volume is mounted.
|
||||
.It No // Ns Ar user Ns @ Ns Ar server Ns / Ns Ar share
|
||||
.It No // Ns Ar user Ns @ Ns Ar server Ns Oo Ar :port1 Ns Oo Ar :port2 Oc Oc Ns No / Ns Ar share
|
||||
The
|
||||
.Nm
|
||||
command will use
|
||||
@ -120,6 +122,17 @@ as the NetBIOS name of remote computer,
|
||||
as the remote user name and
|
||||
.Ar share
|
||||
as the resource name on a remote server.
|
||||
Optional
|
||||
.Ar port1
|
||||
and
|
||||
.Ar port2
|
||||
arguments can be used to override default values of port numbers used
|
||||
by communication protocols.
|
||||
For SMB over NetBIOS default value for
|
||||
.Ar port1
|
||||
are 139, and
|
||||
.Ar port2
|
||||
are 137.
|
||||
.It Ar node
|
||||
Path to mount point.
|
||||
.El
|
||||
|
@ -45,6 +45,8 @@
|
||||
#include <netipx/ipx.h>
|
||||
#endif
|
||||
|
||||
#define NMB_TCP_PORT 137
|
||||
|
||||
#define NBPROTO_TCPSSN 1 /* NETBIOS session over TCP */
|
||||
#define NBPROTO_IPXSSN 11 /* NETBIOS over IPX */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user