FreeBSD/sys/netsmb/smb_conn.c
/*
 * Allocate share structure and attach it to the given VC
 * Connection expected to be locked on entry. Share will be returned
 * in locked state.
 */
Allocate share structure and attach it to the given VC
Connection expected to be locked on entry. Share will be returned
in locked state.
Allocate share structure and attach it to the given VC Connection expected to be locked on entry . Share will be returned in locked state .
int
smb_share_create(struct smb_vc *vcp, struct smb_sharespec *shspec,
	struct smb_cred *scred, struct smb_share **sspp)
{
	struct smb_share *ssp;
	struct ucred *cred = scred->scr_cred;
	uid_t realuid = cred->cr_uid;
	uid_t uid = shspec->owner;
	gid_t gid = shspec->group;
	int error, isroot;
	isroot = smb_suser(cred) == 0;
	if (uid != SMBM_ANY_OWNER && uid != realuid && !isroot)
		return EPERM;
	if (gid != SMBM_ANY_GROUP && !groupmember(gid, cred) && !isroot)
		return EPERM;
	error = smb_vc_lookupshare(vcp, shspec, scred, &ssp);
	if (!error) {
		smb_share_put(ssp, scred);
		return EEXIST;
	}
	if (uid == SMBM_ANY_OWNER)
		uid = realuid;
	if (gid == SMBM_ANY_GROUP)
		gid = cred->cr_groups[0];
	ssp = smb_zmalloc(sizeof(*ssp), M_SMBCONN, M_WAITOK);
	smb_co_init(SSTOCP(ssp), SMBL_SHARE, "smbss ilock", "smbss");
	ssp->obj.co_free = smb_share_free;
	ssp->obj.co_gone = smb_share_gone;
	smb_sl_init(&ssp->ss_stlock, "ssstlock");
	ssp->ss_name = smb_strdup(shspec->name);
	if (shspec->pass && shspec->pass[0])
		ssp->ss_pass = smb_strdup(shspec->pass);
	ssp->ss_type = shspec->stype;
	ssp->ss_tid = SMB_TID_UNKNOWN;
	ssp->ss_uid = uid;
	ssp->ss_grp = gid;
	ssp->ss_mode = shspec->rights & SMBM_MASK;
	smb_co_addchild(VCTOCP(vcp), SSTOCP(ssp));
	*sspp = ssp;
	return 0;
}
int smb_share_create ( struct smb_vc * vcp , struct smb_sharespec * shspec , struct smb_cred * scred , struct smb_share * * sspp ) { struct smb_share * ssp ; struct ucred * cred = scred -> scr_cred ; uid_t realuid = cred -> cr_uid ; uid_t uid = shspec -> owner ; gid_t gid = shspec -> group ; int error , isroot ; isroot = smb_suser ( cred ) == 0 ; if ( uid != SMBM_ANY_OWNER && uid != realuid && ! isroot ) return EPERM ; if ( gid != SMBM_ANY_GROUP && ! groupmember ( gid , cred ) && ! isroot ) return EPERM ; error = smb_vc_lookupshare ( vcp , shspec , scred , & ssp ) ; if ( ! error ) { smb_share_put ( ssp , scred ) ; return EEXIST ; } if ( uid == SMBM_ANY_OWNER ) uid = realuid ; if ( gid == SMBM_ANY_GROUP ) gid = cred -> cr_groups [ 0 ] ; ssp = smb_zmalloc ( sizeof ( * ssp ) , M_SMBCONN , M_WAITOK ) ; smb_co_init ( SSTOCP ( ssp ) , SMBL_SHARE , " " , " " ) ; ssp -> obj . co_free = smb_share_free ; ssp -> obj . co_gone = smb_share_gone ; smb_sl_init ( & ssp -> ss_stlock , " " ) ; ssp -> ss_name = smb_strdup ( shspec -> name ) ; if ( shspec -> pass && shspec -> pass [ 0 ] ) ssp -> ss_pass = smb_strdup ( shspec -> pass ) ; ssp -> ss_type = shspec -> stype ; ssp -> ss_tid = SMB_TID_UNKNOWN ; ssp -> ss_uid = uid ; ssp -> ss_grp = gid ; ssp -> ss_mode = shspec -> rights & SMBM_MASK ; smb_co_addchild ( VCTOCP ( vcp ) , SSTOCP ( ssp ) ) ; * sspp = ssp ; return 0 ; }
Allocate share structure and attach it to the given VC
 Connection expected to be locked on entry.
Allocate share structure and attach it to the given VC Connection expected to be locked on entry .
/*
	 * Only superuser can create shares with different uid and gid
	 */