Exemplo n.º 1
0
        internal static SMB1Command GetTreeConnectResponse(SMB1Header header, TreeConnectAndXRequest request, SMB1ConnectionState state, NamedPipeShare services, SMBShareCollection shares)
        {
            SMB1Session          session    = state.GetSession(header.UID);
            bool                 isExtended = (request.Flags & TreeConnectFlags.ExtendedResponse) > 0;
            string               shareName  = ServerPathUtils.GetShareName(request.Path);
            ISMBShare            share;
            ServiceName          serviceName;
            OptionalSupportFlags supportFlags;

            if (String.Equals(shareName, NamedPipeShare.NamedPipeShareName, StringComparison.InvariantCultureIgnoreCase))
            {
                share        = services;
                serviceName  = ServiceName.NamedPipe;
                supportFlags = OptionalSupportFlags.SMB_SUPPORT_SEARCH_BITS | OptionalSupportFlags.SMB_CSC_NO_CACHING;
            }
            else
            {
                share        = shares.GetShareFromName(shareName);
                serviceName  = ServiceName.DiskShare;
                supportFlags = OptionalSupportFlags.SMB_SUPPORT_SEARCH_BITS | OptionalSupportFlags.SMB_CSC_CACHE_MANUAL_REINT;
                if (share == null)
                {
                    header.Status = NTStatus.STATUS_OBJECT_PATH_NOT_FOUND;
                    return(new ErrorResponse(request.CommandName));
                }

                if (!((FileSystemShare)share).HasReadAccess(session.SecurityContext, @"\"))
                {
                    state.LogToServer(Severity.Verbose, "Tree Connect to '{0}' failed. User '{1}' was denied access.", share.Name, session.UserName);
                    header.Status = NTStatus.STATUS_ACCESS_DENIED;
                    return(new ErrorResponse(request.CommandName));
                }
            }
            ushort?treeID = session.AddConnectedTree(share);

            if (!treeID.HasValue)
            {
                header.Status = NTStatus.STATUS_INSUFF_SERVER_RESOURCES;
                return(new ErrorResponse(request.CommandName));
            }
            state.LogToServer(Severity.Information, "Tree Connect: User '{0}' connected to '{1}'", session.UserName, share.Name);
            header.TID = treeID.Value;
            if (isExtended)
            {
                return(CreateTreeConnectResponseExtended(serviceName, supportFlags));
            }
            else
            {
                return(CreateTreeConnectResponse(serviceName, supportFlags));
            }
        }