Lines Matching +full:parent +full:- +full:locked

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2000-2001 Boris Popov
92 SMBERROR("%d connections still active\n", smb_vclist.co_usecount - 1); in smb_sm_done()
129 vcspec->shspec = shspec; in smb_sm_lookupint()
138 if ((vcp->obj.co_flags & SMBV_PRIVATE) || in smb_sm_lookupint()
139 !CONNADDREQ(vcp->vc_paddr, vcspec->sap) || in smb_sm_lookupint()
140 strcmp(vcp->vc_username, vcspec->username) != 0) in smb_sm_lookupint()
142 if (vcspec->owner != SMBM_ANY_OWNER) { in smb_sm_lookupint()
143 if (vcp->vc_uid != vcspec->owner) in smb_sm_lookupint()
147 if (vcspec->group != SMBM_ANY_GROUP) { in smb_sm_lookupint()
148 if (vcp->vc_grp != vcspec->group) in smb_sm_lookupint()
152 if (vcspec->mode & SMBM_EXACT) { in smb_sm_lookupint()
153 if (!exact || (vcspec->mode & SMBM_MASK) != in smb_sm_lookupint()
154 vcp->vc_mode) in smb_sm_lookupint()
157 if (smb_vc_access(vcp, scred, vcspec->mode) != 0) in smb_sm_lookupint()
159 vcspec->ssp = NULL; in smb_sm_lookupint()
162 &vcspec->ssp); in smb_sm_lookupint()
194 if (error == 0 || (vcspec->flags & SMBV_CREATE) == 0) { in smb_sm_lookup()
214 vcspec->ssp = ssp; in smb_sm_lookup()
234 SLIST_INIT(&cp->co_children); in smb_co_init()
235 sx_init_flags(&cp->co_interlock, ilockname, SX_RECURSE); in smb_co_init()
236 cv_init(&cp->co_lock, "smblock"); in smb_co_init()
237 cp->co_lockcnt = 0; in smb_co_init()
238 cp->co_locker = NULL; in smb_co_init()
239 cp->co_level = level; in smb_co_init()
240 cp->co_usecount = 1; in smb_co_init()
241 sx_xlock(&cp->co_interlock); in smb_co_init()
243 sx_unlock(&cp->co_interlock); in smb_co_init()
250 sx_destroy(&cp->co_interlock); in smb_co_done()
251 cv_destroy(&cp->co_lock); in smb_co_done()
252 cp->co_locker = NULL; in smb_co_done()
253 cp->co_flags = 0; in smb_co_done()
254 cp->co_lockcnt = 0; in smb_co_done()
260 struct smb_connobj *parent; in smb_co_gone() local
262 if (cp->co_gone) in smb_co_gone()
263 cp->co_gone(cp, scred); in smb_co_gone()
264 parent = cp->co_parent; in smb_co_gone()
265 if (parent) { in smb_co_gone()
266 sx_xlock(&parent->co_interlock); in smb_co_gone()
267 smb_co_lock(parent); in smb_co_gone()
268 sx_unlock(&parent->co_interlock); in smb_co_gone()
269 SLIST_REMOVE(&parent->co_children, cp, smb_connobj, co_next); in smb_co_gone()
270 smb_co_put(parent, scred); in smb_co_gone()
272 if (cp->co_free) in smb_co_gone()
273 cp->co_free(cp); in smb_co_gone()
280 sx_xlock(&cp->co_interlock); in smb_co_ref()
281 cp->co_usecount++; in smb_co_ref()
282 sx_unlock(&cp->co_interlock); in smb_co_ref()
289 sx_xlock(&cp->co_interlock); in smb_co_rele()
291 if (cp->co_usecount > 1) { in smb_co_rele()
292 cp->co_usecount--; in smb_co_rele()
293 sx_unlock(&cp->co_interlock); in smb_co_rele()
296 if (cp->co_usecount == 0) { in smb_co_rele()
297 SMBERROR("negative use_count for object %d", cp->co_level); in smb_co_rele()
298 sx_unlock(&cp->co_interlock); in smb_co_rele()
301 cp->co_usecount--; in smb_co_rele()
302 cp->co_flags |= SMBO_GONE; in smb_co_rele()
303 sx_unlock(&cp->co_interlock); in smb_co_rele()
312 MPASS(sx_xholder(&cp->co_interlock) == curthread); in smb_co_get()
313 cp->co_usecount++; in smb_co_get()
316 cp->co_usecount--; in smb_co_get()
324 sx_xlock(&cp->co_interlock); in smb_co_put()
325 if (cp->co_usecount > 1) { in smb_co_put()
326 cp->co_usecount--; in smb_co_put()
327 } else if (cp->co_usecount == 1) { in smb_co_put()
328 cp->co_usecount--; in smb_co_put()
329 cp->co_flags |= SMBO_GONE; in smb_co_put()
334 sx_unlock(&cp->co_interlock); in smb_co_put()
335 if ((cp->co_flags & SMBO_GONE) == 0) in smb_co_put()
344 MPASS(sx_xholder(&cp->co_interlock) == curthread); in smb_co_lock()
346 if (cp->co_flags & SMBO_GONE) in smb_co_lock()
348 if (cp->co_locker == NULL) { in smb_co_lock()
349 cp->co_locker = curthread; in smb_co_lock()
352 if (cp->co_locker == curthread) { in smb_co_lock()
353 cp->co_lockcnt++; in smb_co_lock()
356 cv_wait(&cp->co_lock, &cp->co_interlock); in smb_co_lock()
364 MPASS(sx_xholder(&cp->co_interlock) == curthread); in smb_co_unlock()
365 MPASS(cp->co_locker == curthread); in smb_co_unlock()
366 if (cp->co_lockcnt != 0) { in smb_co_unlock()
367 cp->co_lockcnt--; in smb_co_unlock()
370 cp->co_locker = NULL; in smb_co_unlock()
371 cv_signal(&cp->co_lock); in smb_co_unlock()
375 smb_co_addchild(struct smb_connobj *parent, struct smb_connobj *child) in smb_co_addchild() argument
378 smb_co_ref(parent); in smb_co_addchild()
379 SLIST_INSERT_HEAD(&parent->co_children, child, co_next); in smb_co_addchild()
380 child->co_parent = parent; in smb_co_addchild()
392 struct ucred *cred = scred->scr_cred; in smb_vc_create()
393 uid_t uid = vcspec->owner; in smb_vc_create()
394 gid_t gid = vcspec->group; in smb_vc_create()
395 uid_t realuid = cred->cr_uid; in smb_vc_create()
396 char *domain = vcspec->domain; in smb_vc_create()
410 vcp->obj.co_free = smb_vc_free; in smb_vc_create()
411 vcp->obj.co_gone = smb_vc_gone; in smb_vc_create()
412 vcp->vc_number = smb_vcnext++; in smb_vc_create()
413 vcp->vc_timo = SMB_DEFRQTIMO; in smb_vc_create()
414 vcp->vc_smbuid = SMB_UID_UNKNOWN; in smb_vc_create()
415 vcp->vc_mode = vcspec->rights & SMBM_MASK; in smb_vc_create()
416 vcp->obj.co_flags = vcspec->flags & (SMBV_PRIVATE | SMBV_SINGLESHARE); in smb_vc_create()
417 vcp->vc_tdesc = &smb_tran_nbtcp_desc; in smb_vc_create()
418 vcp->vc_seqno = 0; in smb_vc_create()
419 vcp->vc_mackey = NULL; in smb_vc_create()
420 vcp->vc_mackeylen = 0; in smb_vc_create()
425 gid = cred->cr_gid; in smb_vc_create()
426 vcp->vc_uid = uid; in smb_vc_create()
427 vcp->vc_grp = gid; in smb_vc_create()
429 smb_sl_init(&vcp->vc_stlock, "vcstlock"); in smb_vc_create()
432 vcp->vc_paddr = sodupsockaddr(vcspec->sap, M_WAITOK); in smb_vc_create()
433 if (vcp->vc_paddr == NULL) in smb_vc_create()
435 vcp->vc_laddr = sodupsockaddr(vcspec->lap, M_WAITOK); in smb_vc_create()
436 if (vcp->vc_laddr == NULL) in smb_vc_create()
438 vcp->vc_pass = smb_strdup(vcspec->pass); in smb_vc_create()
439 if (vcp->vc_pass == NULL) in smb_vc_create()
441 vcp->vc_domain = smb_strdup((domain && domain[0]) ? domain : in smb_vc_create()
443 if (vcp->vc_domain == NULL) in smb_vc_create()
445 vcp->vc_srvname = smb_strdup(vcspec->srvname); in smb_vc_create()
446 if (vcp->vc_srvname == NULL) in smb_vc_create()
448 vcp->vc_username = smb_strdup(vcspec->username); in smb_vc_create()
449 if (vcp->vc_username == NULL) in smb_vc_create()
451 error = (int)iconv_open("tolower", vcspec->localcs, &vcp->vc_tolower); in smb_vc_create()
454 error = (int)iconv_open("toupper", vcspec->localcs, &vcp->vc_toupper); in smb_vc_create()
457 if (vcspec->servercs[0]) { in smb_vc_create()
458 error = (int)iconv_open(vcspec->servercs, vcspec->localcs, in smb_vc_create()
459 &vcp->vc_cp_toserver); in smb_vc_create()
462 error = (int)iconv_open(vcspec->localcs, vcspec->servercs, in smb_vc_create()
463 &vcp->vc_cp_tolocal); in smb_vc_create()
466 vcp->vc_toserver = vcp->vc_cp_toserver; in smb_vc_create()
467 vcp->vc_tolocal = vcp->vc_cp_tolocal; in smb_vc_create()
470 error = (int)iconv_open(SMB_UNICODE_NAME, vcspec->localcs, in smb_vc_create()
471 &vcp->vc_ucs_toserver); in smb_vc_create()
473 error = (int)iconv_open(vcspec->localcs, SMB_UNICODE_NAME, in smb_vc_create()
474 &vcp->vc_ucs_tolocal); in smb_vc_create()
477 if (vcp->vc_ucs_toserver) in smb_vc_create()
478 iconv_close(vcp->vc_ucs_toserver); in smb_vc_create()
479 vcp->vc_ucs_toserver = NULL; in smb_vc_create()
480 vcp->vc_ucs_tolocal = NULL; in smb_vc_create()
500 if (vcp->vc_iod) in smb_vc_free()
501 smb_iod_destroy(vcp->vc_iod); in smb_vc_free()
502 SMB_STRFREE(vcp->vc_username); in smb_vc_free()
503 SMB_STRFREE(vcp->vc_srvname); in smb_vc_free()
504 SMB_STRFREE(vcp->vc_pass); in smb_vc_free()
505 SMB_STRFREE(vcp->vc_domain); in smb_vc_free()
506 if (vcp->vc_mackey) in smb_vc_free()
507 free(vcp->vc_mackey, M_SMBTEMP); in smb_vc_free()
508 if (vcp->vc_paddr) in smb_vc_free()
509 free(vcp->vc_paddr, M_SONAME); in smb_vc_free()
510 if (vcp->vc_laddr) in smb_vc_free()
511 free(vcp->vc_laddr, M_SONAME); in smb_vc_free()
512 if (vcp->vc_tolower) in smb_vc_free()
513 iconv_close(vcp->vc_tolower); in smb_vc_free()
514 if (vcp->vc_toupper) in smb_vc_free()
515 iconv_close(vcp->vc_toupper); in smb_vc_free()
516 if (vcp->vc_tolocal) in smb_vc_free()
517 vcp->vc_tolocal = NULL; in smb_vc_free()
518 if (vcp->vc_toserver) in smb_vc_free()
519 vcp->vc_toserver = NULL; in smb_vc_free()
520 if (vcp->vc_cp_tolocal) in smb_vc_free()
521 iconv_close(vcp->vc_cp_tolocal); in smb_vc_free()
522 if (vcp->vc_cp_toserver) in smb_vc_free()
523 iconv_close(vcp->vc_cp_toserver); in smb_vc_free()
524 if (vcp->vc_ucs_tolocal) in smb_vc_free()
525 iconv_close(vcp->vc_ucs_tolocal); in smb_vc_free()
526 if (vcp->vc_ucs_toserver) in smb_vc_free()
527 iconv_close(vcp->vc_ucs_toserver); in smb_vc_free()
529 smb_sl_destroy(&vcp->vc_stlock); in smb_vc_free()
563 sx_xlock(&cp->co_interlock); in smb_vc_get()
565 sx_unlock(&cp->co_interlock); in smb_vc_get()
582 sx_xlock(&cp->co_interlock); in smb_vc_lock()
584 sx_unlock(&cp->co_interlock); in smb_vc_lock()
595 sx_xlock(&cp->co_interlock); in smb_vc_unlock()
597 sx_unlock(&cp->co_interlock); in smb_vc_unlock()
603 struct ucred *cred = scred->scr_cred; in smb_vc_access()
605 if (smb_suser(cred) == 0 || cred->cr_uid == vcp->vc_uid) in smb_vc_access()
608 if (!groupmember(vcp->vc_grp, cred)) in smb_vc_access()
610 return (vcp->vc_mode & mode) == mode ? 0 : EACCES; in smb_vc_access()
618 if (strcmp(ssp->ss_name, dp->name) != 0) in smb_vc_cmpshare()
620 if (dp->owner != SMBM_ANY_OWNER) { in smb_vc_cmpshare()
621 if (ssp->ss_uid != dp->owner) in smb_vc_cmpshare()
625 if (dp->group != SMBM_ANY_GROUP) { in smb_vc_cmpshare()
626 if (ssp->ss_grp != dp->group) in smb_vc_cmpshare()
631 if (dp->mode & SMBM_EXACT) { in smb_vc_cmpshare()
634 return (dp->mode & SMBM_MASK) == ssp->ss_mode ? 0 : 1; in smb_vc_cmpshare()
636 if (smb_share_access(ssp, dp->scred, dp->mode) != 0) in smb_vc_cmpshare()
642 * Lookup share in the given VC. Share referenced and locked on return.
643 * VC expected to be locked on entry and will be left locked on exit.
654 dp->scred = scred; in smb_vc_lookupshare()
677 return smb_iod_request(vcp->vc_iod, SMBIOD_EV_CONNECT | SMBIOD_EV_SYNC, NULL); in smb_vc_connect()
682 * Transport should be locked on entry.
688 if (vcp->vc_iod != NULL) in smb_vc_disconnect()
689 smb_iod_request(vcp->vc_iod, SMBIOD_EV_DISCONNECT | in smb_vc_disconnect()
699 if (vcp->vc_pass) in smb_vc_getpass()
700 return vcp->vc_pass; in smb_vc_getpass()
708 vip->itype = SMB_INFO_VC; in smb_vc_getinfo()
709 vip->usecount = vcp->obj.co_usecount; in smb_vc_getinfo()
710 vip->uid = vcp->vc_uid; in smb_vc_getinfo()
711 vip->gid = vcp->vc_grp; in smb_vc_getinfo()
712 vip->mode = vcp->vc_mode; in smb_vc_getinfo()
713 vip->flags = vcp->obj.co_flags; in smb_vc_getinfo()
714 vip->sopt = vcp->vc_sopt; in smb_vc_getinfo()
715 vip->iodstate = vcp->vc_iod->iod_state; in smb_vc_getinfo()
716 bzero(&vip->sopt.sv_skey, sizeof(vip->sopt.sv_skey)); in smb_vc_getinfo()
717 snprintf(vip->srvname, sizeof(vip->srvname), "%s", vcp->vc_srvname); in smb_vc_getinfo()
718 snprintf(vip->vcname, sizeof(vip->vcname), "%s", vcp->vc_username); in smb_vc_getinfo()
727 sx_xlock(&vcp->obj.co_interlock); in smb_vc_nextmid()
728 r = vcp->vc_mid++; in smb_vc_nextmid()
729 sx_unlock(&vcp->obj.co_interlock); in smb_vc_nextmid()
738 * Connection expected to be locked on entry. Share will be returned
739 * in locked state.
746 struct ucred *cred = scred->scr_cred; in smb_share_create()
747 uid_t realuid = cred->cr_uid; in smb_share_create()
748 uid_t uid = shspec->owner; in smb_share_create()
749 gid_t gid = shspec->group; in smb_share_create()
768 gid = cred->cr_gid; in smb_share_create()
771 ssp->obj.co_free = smb_share_free; in smb_share_create()
772 ssp->obj.co_gone = smb_share_gone; in smb_share_create()
773 smb_sl_init(&ssp->ss_stlock, "ssstlock"); in smb_share_create()
774 ssp->ss_name = smb_strdup(shspec->name); in smb_share_create()
775 if (shspec->pass && shspec->pass[0]) in smb_share_create()
776 ssp->ss_pass = smb_strdup(shspec->pass); in smb_share_create()
777 ssp->ss_type = shspec->stype; in smb_share_create()
778 ssp->ss_tid = SMB_TID_UNKNOWN; in smb_share_create()
779 ssp->ss_uid = uid; in smb_share_create()
780 ssp->ss_grp = gid; in smb_share_create()
781 ssp->ss_mode = shspec->rights & SMBM_MASK; in smb_share_create()
792 SMB_STRFREE(ssp->ss_name); in smb_share_free()
793 SMB_STRFREE(ssp->ss_pass); in smb_share_free()
794 smb_sl_destroy(&ssp->ss_stlock); in smb_share_free()
825 sx_xlock(&cp->co_interlock); in smb_share_get()
827 sx_unlock(&cp->co_interlock); in smb_share_get()
845 sx_xlock(&cp->co_interlock); in smb_share_lock()
847 sx_unlock(&cp->co_interlock); in smb_share_lock()
857 sx_xlock(&cp->co_interlock); in smb_share_unlock()
859 sx_unlock(&cp->co_interlock); in smb_share_unlock()
865 struct ucred *cred = scred->scr_cred; in smb_share_access()
867 if (smb_suser(cred) == 0 || cred->cr_uid == ssp->ss_uid) in smb_share_access()
870 if (!groupmember(ssp->ss_grp, cred)) in smb_share_access()
872 return (ssp->ss_mode & mode) == mode ? 0 : EACCES; in smb_share_access()
878 ssp->ss_tid = SMB_TID_UNKNOWN; in smb_share_invalidate()
884 return ssp->ss_tid != SMB_TID_UNKNOWN && in smb_share_valid()
885 ssp->ss_vcgenid == SSTOVC(ssp)->vc_genid; in smb_share_valid()
893 if (ssp->ss_pass) in smb_share_getpass()
894 return ssp->ss_pass; in smb_share_getpass()
896 if (vcp->vc_pass) in smb_share_getpass()
897 return vcp->vc_pass; in smb_share_getpass()
905 sip->itype = SMB_INFO_SHARE; in smb_share_getinfo()
906 sip->usecount = ssp->obj.co_usecount; in smb_share_getinfo()
907 sip->tid = ssp->ss_tid; in smb_share_getinfo()
908 sip->type= ssp->ss_type; in smb_share_getinfo()
909 sip->uid = ssp->ss_uid; in smb_share_getinfo()
910 sip->gid = ssp->ss_grp; in smb_share_getinfo()
911 sip->mode= ssp->ss_mode; in smb_share_getinfo()
912 sip->flags = ssp->obj.co_flags; in smb_share_getinfo()
913 snprintf(sip->sname, sizeof(sip->sname), "%s", ssp->ss_name); in smb_share_getinfo()