ctx.c (148815) | ctx.c (150802) |
---|---|
1/* 2 * Copyright (c) 2000-2002, Boris Popov 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 16 unchanged lines hidden (view full) --- 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * $Id: ctx.c,v 1.24 2002/04/13 14:35:28 bp Exp $ | 1/* 2 * Copyright (c) 2000-2002, Boris Popov 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 16 unchanged lines hidden (view full) --- 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * $Id: ctx.c,v 1.24 2002/04/13 14:35:28 bp Exp $ |
33 * $FreeBSD: head/contrib/smbfs/lib/smb/ctx.c 148815 2005-08-07 08:46:56Z imura $ | 33 * $FreeBSD: head/contrib/smbfs/lib/smb/ctx.c 150802 2005-10-02 08:32:49Z bp $ |
34 */ 35#include <sys/param.h> 36#include <sys/sysctl.h> 37#include <sys/ioctl.h> 38#include <sys/time.h> 39#include <sys/mount.h> 40#include <fcntl.h> 41#include <ctype.h> --- 30 unchanged lines hidden (view full) --- 72 bzero(ctx,sizeof(*ctx)); 73 error = nb_ctx_create(&ctx->ct_nb); 74 if (error) 75 return error; 76 ctx->ct_fd = -1; 77 ctx->ct_parsedlevel = SMBL_NONE; 78 ctx->ct_minlevel = minlevel; 79 ctx->ct_maxlevel = maxlevel; | 34 */ 35#include <sys/param.h> 36#include <sys/sysctl.h> 37#include <sys/ioctl.h> 38#include <sys/time.h> 39#include <sys/mount.h> 40#include <fcntl.h> 41#include <ctype.h> --- 30 unchanged lines hidden (view full) --- 72 bzero(ctx,sizeof(*ctx)); 73 error = nb_ctx_create(&ctx->ct_nb); 74 if (error) 75 return error; 76 ctx->ct_fd = -1; 77 ctx->ct_parsedlevel = SMBL_NONE; 78 ctx->ct_minlevel = minlevel; 79 ctx->ct_maxlevel = maxlevel; |
80 ctx->ct_smbtcpport = SMB_TCP_PORT; |
|
80 81 ctx->ct_ssn.ioc_opt = SMBVOPT_CREATE; 82 ctx->ct_ssn.ioc_timeout = 15; 83 ctx->ct_ssn.ioc_retrycount = 4; 84 ctx->ct_ssn.ioc_owner = SMBM_ANY_OWNER; 85 ctx->ct_ssn.ioc_group = SMBM_ANY_GROUP; 86 ctx->ct_ssn.ioc_mode = SMBM_EXEC; 87 ctx->ct_ssn.ioc_rights = SMBM_DEFAULT; --- 74 unchanged lines hidden (view full) --- 162 *dest = *p; 163 } 164 *dest = 0; 165 *next = *p ? p + 1 : p; 166 return 0; 167} 168 169/* | 81 82 ctx->ct_ssn.ioc_opt = SMBVOPT_CREATE; 83 ctx->ct_ssn.ioc_timeout = 15; 84 ctx->ct_ssn.ioc_retrycount = 4; 85 ctx->ct_ssn.ioc_owner = SMBM_ANY_OWNER; 86 ctx->ct_ssn.ioc_group = SMBM_ANY_GROUP; 87 ctx->ct_ssn.ioc_mode = SMBM_EXEC; 88 ctx->ct_ssn.ioc_rights = SMBM_DEFAULT; --- 74 unchanged lines hidden (view full) --- 163 *dest = *p; 164 } 165 *dest = 0; 166 *next = *p ? p + 1 : p; 167 return 0; 168} 169 170/* |
170 * Here we expect something like "[proto:]//[user@]host[/share][/path]" | 171 * Here we expect something like "[proto:]//[user@]host[:psmb[:pnb]][/share][/path]" |
171 */ 172int 173smb_ctx_parseunc(struct smb_ctx *ctx, const char *unc, int sharetype, 174 const char **next) 175{ 176 const char *p = unc; | 172 */ 173int 174smb_ctx_parseunc(struct smb_ctx *ctx, const char *unc, int sharetype, 175 const char **next) 176{ 177 const char *p = unc; |
177 char *p1; | 178 char *p1, *psmb, *pnb; |
178 char tmp[1024]; 179 int error ; 180 181 ctx->ct_parsedlevel = SMBL_NONE; 182 if (*p++ != '/' || *p++ != '/') { 183 smb_error("UNC should start with '//'", 0); 184 return EINVAL; 185 } --- 20 unchanged lines hidden (view full) --- 206 smb_error("no server name found", 0); 207 return error; 208 } 209 } 210 if (*p1 == 0) { 211 smb_error("empty server name", 0); 212 return EINVAL; 213 } | 179 char tmp[1024]; 180 int error ; 181 182 ctx->ct_parsedlevel = SMBL_NONE; 183 if (*p++ != '/' || *p++ != '/') { 184 smb_error("UNC should start with '//'", 0); 185 return EINVAL; 186 } --- 20 unchanged lines hidden (view full) --- 207 smb_error("no server name found", 0); 208 return error; 209 } 210 } 211 if (*p1 == 0) { 212 smb_error("empty server name", 0); 213 return EINVAL; 214 } |
215 /* 216 * Check for port number specification. 217 */ 218 psmb = strchr(tmp, ':'); 219 if (psmb) { 220 *psmb++ = '\0'; 221 pnb = strchr(psmb, ':'); 222 if (pnb) { 223 *pnb++ = '\0'; 224 error = smb_ctx_setnbport(ctx, atoi(pnb)); 225 if (error) { 226 smb_error("Invalid NetBIOS port number", 0); 227 return error; 228 } 229 } 230 error = smb_ctx_setsmbport(ctx, atoi(psmb)); 231 if (error) { 232 smb_error("Invalid SMB port number", 0); 233 return error; 234 } 235 } |
|
214 error = smb_ctx_setserver(ctx, tmp); 215 if (error) 216 return error; 217 if (sharetype == SMB_ST_NONE) { 218 *next = p; 219 return 0; 220 } 221 if (*p != 0 && ctx->ct_maxlevel < SMBL_SHARE) { --- 57 unchanged lines hidden (view full) --- 279 smb_error("server name '%s' too long", 0, name); 280 return ENAMETOOLONG; 281 } 282 nls_str_upper(ctx->ct_ssn.ioc_srvname, name); 283 return 0; 284} 285 286int | 236 error = smb_ctx_setserver(ctx, tmp); 237 if (error) 238 return error; 239 if (sharetype == SMB_ST_NONE) { 240 *next = p; 241 return 0; 242 } 243 if (*p != 0 && ctx->ct_maxlevel < SMBL_SHARE) { --- 57 unchanged lines hidden (view full) --- 301 smb_error("server name '%s' too long", 0, name); 302 return ENAMETOOLONG; 303 } 304 nls_str_upper(ctx->ct_ssn.ioc_srvname, name); 305 return 0; 306} 307 308int |
309smb_ctx_setnbport(struct smb_ctx *ctx, int port) 310{ 311 if (port < 1 || port > 0xffff) 312 return EINVAL; 313 ctx->ct_nb->nb_nmbtcpport = port; 314 return 0; 315} 316 317int 318smb_ctx_setsmbport(struct smb_ctx *ctx, int port) 319{ 320 if (port < 1 || port > 0xffff) 321 return EINVAL; 322 ctx->ct_smbtcpport = port; 323 ctx->ct_nb->nb_smbtcpport = port; 324 return 0; 325} 326 327int |
|
287smb_ctx_setuser(struct smb_ctx *ctx, const char *name) 288{ 289 if (strlen(name) > SMB_MAXUSERNAMELEN) { 290 smb_error("user name '%s' too long", 0, name); 291 return ENAMETOOLONG; 292 } 293 nls_str_upper(ctx->ct_ssn.ioc_user, name); 294 return 0; --- 207 unchanged lines hidden (view full) --- 502 if (error) 503 return error; 504 if (ssn->ioc_servercs[0] != 0) { 505 error = kiconv_add_xlat16_cspairs 506 (ssn->ioc_servercs, ssn->ioc_localcs); 507 if (error) return error; 508 } 509 if (ctx->ct_srvaddr) { | 328smb_ctx_setuser(struct smb_ctx *ctx, const char *name) 329{ 330 if (strlen(name) > SMB_MAXUSERNAMELEN) { 331 smb_error("user name '%s' too long", 0, name); 332 return ENAMETOOLONG; 333 } 334 nls_str_upper(ctx->ct_ssn.ioc_user, name); 335 return 0; --- 207 unchanged lines hidden (view full) --- 543 if (error) 544 return error; 545 if (ssn->ioc_servercs[0] != 0) { 546 error = kiconv_add_xlat16_cspairs 547 (ssn->ioc_servercs, ssn->ioc_localcs); 548 if (error) return error; 549 } 550 if (ctx->ct_srvaddr) { |
510 error = nb_resolvehost_in(ctx->ct_srvaddr, &sap); | 551 error = nb_resolvehost_in(ctx->ct_srvaddr, &sap, ctx->ct_smbtcpport); |
511 } else { 512 error = nbns_resolvename(ssn->ioc_srvname, ctx->ct_nb, &sap); 513 } 514 if (error) { 515 smb_error("can't get server address", error); 516 return error; 517 } 518 nn.nn_scope = ctx->ct_nb->nb_scope; --- 253 unchanged lines hidden --- | 552 } else { 553 error = nbns_resolvename(ssn->ioc_srvname, ctx->ct_nb, &sap); 554 } 555 if (error) { 556 smb_error("can't get server address", error); 557 return error; 558 } 559 nn.nn_scope = ctx->ct_nb->nb_scope; --- 253 unchanged lines hidden --- |