Deleted Added
sdiff udiff text old ( 116189 ) new ( 119376 )
full compact
1/*
2 * Copyright (c) 2000-2001 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

--- 21 unchanged lines hidden (view full) ---

30 * SUCH DAMAGE.
31 */
32
33/*
34 * Connection engine.
35 */
36
37#include <sys/cdefs.h>
38__FBSDID("$FreeBSD: head/sys/netsmb/smb_conn.c 119376 2003-08-23 21:43:33Z marcel $");
39
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/kernel.h>
43#include <sys/malloc.h>
44#include <sys/proc.h>
45#include <sys/lock.h>
46#include <sys/sysctl.h>

--- 76 unchanged lines hidden (view full) ---

123 int error;
124
125 vcspec->shspec = shspec;
126 error = ENOENT;
127 SMBCO_FOREACH((struct smb_connobj*)vcp, &smb_vclist) {
128 error = smb_vc_lock(vcp, LK_EXCLUSIVE, td);
129 if (error)
130 continue;
131
132 if ((vcp->obj.co_flags & SMBV_PRIVATE) ||
133 !CONNADDREQ(vcp->vc_paddr, vcspec->sap) ||
134 strcmp(vcp->vc_username, vcspec->username) != 0)
135 goto err1;
136 if (vcspec->owner != SMBM_ANY_OWNER) {
137 if (vcp->vc_uid != vcspec->owner)
138 goto err1;
139 } else
140 exact = 0;
141 if (vcspec->group != SMBM_ANY_GROUP) {
142 if (vcp->vc_grp != vcspec->group)
143 goto err1;
144 } else
145 exact = 0;
146 if (vcspec->mode & SMBM_EXACT) {
147 if (!exact || (vcspec->mode & SMBM_MASK) !=
148 vcp->vc_mode)
149 goto err1;
150 }
151 if (smb_vc_access(vcp, scred, vcspec->mode) != 0)
152 goto err1;
153 vcspec->ssp = NULL;
154 if (shspec) {
155 error = (int)smb_vc_lookupshare(vcp, shspec, scred,
156 &vcspec->ssp);
157 if (error)
158 goto fail;
159 }
160 error = 0;
161 break;
162 err1:
163 error = 1;
164 fail:
165 smb_vc_unlock(vcp, 0, td);
166 }
167 if (vcp) {
168 smb_vc_ref(vcp);
169 *vcpp = vcp;
170 }
171 return (error);
172}
173
174int
175smb_sm_lookup(struct smb_vcspec *vcspec, struct smb_sharespec *shspec,
176 struct smb_cred *scred, struct smb_vc **vcpp)
177{
178 struct thread *td = scred->scr_td;
179 struct smb_vc *vcp;

--- 229 unchanged lines hidden (view full) ---

409 if (uid == SMBM_ANY_OWNER)
410 uid = realuid;
411 if (gid == SMBM_ANY_GROUP)
412 gid = cred->cr_groups[0];
413 vcp->vc_uid = uid;
414 vcp->vc_grp = gid;
415
416 smb_sl_init(&vcp->vc_stlock, "vcstlock");
417 error = ENOMEM;
418
419 vcp->vc_paddr = dup_sockaddr(vcspec->sap, 1);
420 if (vcp->vc_paddr == NULL)
421 goto fail;
422 vcp->vc_laddr = dup_sockaddr(vcspec->lap, 1);
423 if (vcp->vc_laddr == NULL)
424 goto fail;
425 vcp->vc_pass = smb_strdup(vcspec->pass);
426 if (vcp->vc_pass == NULL)
427 goto fail;
428 vcp->vc_domain = smb_strdup((domain && domain[0]) ? domain :
429 "NODOMAIN");
430 if (vcp->vc_domain == NULL)
431 goto fail;
432 vcp->vc_srvname = smb_strdup(vcspec->srvname);
433 if (vcp->vc_srvname == NULL)
434 goto fail;
435 vcp->vc_username = smb_strdup(vcspec->username);
436 if (vcp->vc_username == NULL)
437 goto fail;
438 error = (int)iconv_open("tolower", vcspec->localcs, &vcp->vc_tolower);
439 if (error)
440 goto fail;
441 error = (int)iconv_open("toupper", vcspec->localcs, &vcp->vc_toupper);
442 if (error)
443 goto fail;
444 if (vcspec->servercs[0]) {
445 error = (int)iconv_open(vcspec->servercs, vcspec->localcs,
446 &vcp->vc_toserver);
447 if (error)
448 goto fail;
449 error = (int)iconv_open(vcspec->localcs, vcspec->servercs,
450 &vcp->vc_tolocal);
451 if (error)
452 goto fail;
453 }
454 error = (int)smb_iod_create(vcp);
455 if (error)
456 goto fail;
457 *vcpp = vcp;
458 smb_co_addchild(&smb_vclist, VCTOCP(vcp));
459 return (0);
460
461 fail:
462 smb_vc_put(vcp, scred);
463 return (error);
464}
465
466static void
467smb_vc_free(struct smb_connobj *cp)
468{
469 struct smb_vc *vcp = CPTOVC(cp);
470
471 if (vcp->vc_iod)

--- 418 unchanged lines hidden ---