예제 #1
0
 public void Write(AfpStream stream)
 {
     stream.WriteEnum(flags);
     stream.WriteEnum(command);
     stream.WriteUInt16(requestId);
     stream.WriteUInt32(errorCodeOrWriteOffset);
     stream.WriteUInt32(totalDataLength);
     stream.WriteUInt32(reserved);
 }
        public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream)
        {
            UserFlags flags = requestStream.ReadEnum<UserFlags>();
            int? userId = null;

            //if (flags != UserFlags.ThisUser) {
                userId = requestStream.ReadInt32();
               // }

            UserBitmap bitmap = requestStream.ReadEnum<UserBitmap>();

            responseStream.WriteEnum(bitmap);

            foreach (UserBitmap value in bitmap.EnumerateFlags()) {
                switch (value) {
                    case UserBitmap.UserId:
                        responseStream.WriteInt32(0);
                        break;
                    case UserBitmap.Uuid:
                        responseStream.WriteBytes(new byte[16]);
                        break;
                    case UserBitmap.PrimaryGroupId:
                        responseStream.WriteInt32(0);
                        break;
                }
            }

            return AfpResultCode.FPNoErr;
        }
예제 #3
0
        public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream)
        {
            requestStream.ReadUInt8(); // Pad

            AfpVolumeBitmap volumeBitmap = requestStream.ReadEnum <AfpVolumeBitmap>();
            string          volumeName   = requestStream.ReadPascalString();

            IStorageProvider provider = session.Server.Shares
                                        .Where(s => s.Name == volumeName)
                                        .FirstOrDefault();

            if (provider == null)
            {
                return(AfpResultCode.FPObjectNotFound);
            }

            IAfpVolume volume = session.OpenVolume(provider);

            if (volume == null)
            {
                return(AfpResultCode.FPAccessDenied);
            }

            responseStream.WriteEnum(volumeBitmap);
            responseStream.WriteVolumeInfo(volume, volumeBitmap);

            return(AfpResultCode.FPNoErr);
        }
        public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream)
        {
            requestStream.ReadUInt8(); // Pad

            ushort volumeId = requestStream.ReadUInt16();
            uint fileId = requestStream.ReadUInt32();
            AfpFileDirectoryBitmap fileBitmap = requestStream.ReadEnum<AfpFileDirectoryBitmap>();

            IAfpVolume volume = session.GetVolume(volumeId);

            if (volume == null) {
                return AfpResultCode.FPObjectNotFound;
            }

            IStorageFile item = volume.GetNode(fileId) as IStorageFile;

            if (item == null) {
                return AfpResultCode.FPObjectNotFound;
            }

            responseStream.WriteEnum(fileBitmap);

            responseStream.WriteStorageFileInfo(volume, item, fileBitmap, false);

            return AfpResultCode.FPNoErr;
        }
예제 #5
0
        public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream)
        {
            requestStream.ReadUInt8(); // Pad

            ushort volumeId = requestStream.ReadUInt16();
            uint   fileId   = requestStream.ReadUInt32();
            AfpFileDirectoryBitmap fileBitmap = requestStream.ReadEnum <AfpFileDirectoryBitmap>();

            IAfpVolume volume = session.GetVolume(volumeId);

            if (volume == null)
            {
                return(AfpResultCode.FPObjectNotFound);
            }

            IStorageFile item = volume.GetNode(fileId) as IStorageFile;

            if (item == null)
            {
                return(AfpResultCode.FPObjectNotFound);
            }

            responseStream.WriteEnum(fileBitmap);

            responseStream.WriteStorageFileInfo(volume, item, fileBitmap, false);

            return(AfpResultCode.FPNoErr);
        }
        public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream)
        {
            requestStream.ReadUInt8(); // Pad

            AfpVolumeBitmap volumeBitmap = requestStream.ReadEnum<AfpVolumeBitmap>();
            string volumeName = requestStream.ReadPascalString();

            IStorageProvider provider = session.Server.Shares
                .Where(s => s.Name == volumeName)
                .FirstOrDefault();

            if (provider == null) {
                return AfpResultCode.FPObjectNotFound;
            }

            IAfpVolume volume = session.OpenVolume(provider);

            if (volume == null) {
                return AfpResultCode.FPAccessDenied;
            }

            responseStream.WriteEnum(volumeBitmap);
            responseStream.WriteVolumeInfo(volume, volumeBitmap);

            return AfpResultCode.FPNoErr;
        }
예제 #7
0
        public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream)
        {
            UserFlags flags  = requestStream.ReadEnum <UserFlags>();
            int?      userId = null;

            //if (flags != UserFlags.ThisUser) {
            userId = requestStream.ReadInt32();
            // }

            UserBitmap bitmap = requestStream.ReadEnum <UserBitmap>();

            responseStream.WriteEnum(bitmap);

            foreach (UserBitmap value in bitmap.EnumerateFlags())
            {
                switch (value)
                {
                case UserBitmap.UserId:
                    responseStream.WriteInt32(0);
                    break;

                case UserBitmap.Uuid:
                    responseStream.WriteBytes(new byte[16]);
                    break;

                case UserBitmap.PrimaryGroupId:
                    responseStream.WriteInt32(0);
                    break;
                }
            }

            return(AfpResultCode.FPNoErr);
        }
        public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream)
        {
            requestStream.ReadUInt8(); // Pad

            ushort volumeId = requestStream.ReadUInt16();
            AfpVolumeBitmap bitmap = requestStream.ReadEnum<AfpVolumeBitmap>();

            IAfpVolume volume = session.GetVolume(volumeId);

            if (volume == null) {
                return AfpResultCode.FPObjectNotFound;
            }

            responseStream.WriteEnum(bitmap);
            responseStream.WriteVolumeInfo(volume, bitmap);

            return AfpResultCode.FPNoErr;
        }
        public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream)
        {
            requestStream.ReadUInt8(); // Pad

            ushort          volumeId = requestStream.ReadUInt16();
            AfpVolumeBitmap bitmap   = requestStream.ReadEnum <AfpVolumeBitmap>();

            IAfpVolume volume = session.GetVolume(volumeId);

            if (volume == null)
            {
                return(AfpResultCode.FPObjectNotFound);
            }

            responseStream.WriteEnum(bitmap);
            responseStream.WriteVolumeInfo(volume, bitmap);

            return(AfpResultCode.FPNoErr);
        }
        public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream)
        {
            requestStream.ReadUInt8(); // Padding

            ushort volumeId = requestStream.ReadUInt16();
            uint directoryId = requestStream.ReadUInt32();
            AfpFileDirectoryBitmap fileBitmap = requestStream.ReadEnum<AfpFileDirectoryBitmap>();
            AfpFileDirectoryBitmap directoryBitmap = requestStream.ReadEnum<AfpFileDirectoryBitmap>();

            short reqCount = requestStream.ReadInt16();
            int startIndex = requestStream.ReadInt32();
            int maxReplySize = requestStream.ReadInt32();

            AfpPathType pathType = requestStream.ReadEnum<AfpPathType>();
            string path = null;

            switch (pathType) {
                case AfpPathType.kFPLongName:
                case AfpPathType.kFPShortName:
                    path = requestStream.ReadPascalString();
                    break;
                case AfpPathType.kFPUTF8Name:
                    path = requestStream.ReadUTF8StringWithHint();
                    break;
            }

            IAfpVolume volume = session.GetVolume(volumeId);

            if (volume == null) {
                return AfpResultCode.FPObjectNotFound;
            }

            IStorageContainer container = null;

            if (directoryId == 2) {
                container = volume.StorageProvider;
            } else {
                container = (volume.GetNode(directoryId) as IStorageContainer);
            }

            if (container == null) {
                return AfpResultCode.FPObjectNotFound;
            }

            IStorageContainer lookAtContainer = null;

            if (string.IsNullOrEmpty(path)) {
                lookAtContainer = container;
            } else {
                lookAtContainer = (container.Content(path) as IStorageContainer);
            }

            if (lookAtContainer == null) {
                return AfpResultCode.FPObjectNotFound;
            }

            var useContents = lookAtContainer.Contents();

            if (fileBitmap == 0) {
                useContents = useContents.OfType<IStorageContainer>();
            } else if (directoryBitmap == 0) {
                useContents = useContents.OfType<IStorageFile>();
            }

            useContents = useContents
                .Skip(startIndex-1)
                .Take(reqCount);

            var contents = useContents.ToList();

            if (contents.Count == 0) {
                return AfpResultCode.FPObjectNotFound;
            }

            responseStream.WriteEnum<AfpFileDirectoryBitmap>(fileBitmap);
            responseStream.WriteEnum<AfpFileDirectoryBitmap>(directoryBitmap);
            responseStream.WriteInt16((short)contents.Count);

            foreach (IStorageItem item in contents) {
                AfpStream resultRecord = new AfpStream();

                resultRecord.WriteUInt16(0); // Length

                if (item is IStorageContainer) {
                    resultRecord.WriteStorageContainerInfo(volume, (IStorageContainer)item, directoryBitmap);
                } else {
                    resultRecord.WriteStorageFileInfo(volume, (IStorageFile)item, fileBitmap);
                }

                resultRecord.WritePadding();

                resultRecord.Stream.Position = 0;
                resultRecord.WriteUInt16((byte)resultRecord.Stream.Length);

                byte[] recordData = resultRecord.ToByteArray();
                responseStream.WriteBytes(recordData);
            }

            return AfpResultCode.FPNoErr;
        }
        public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream)
        {
            requestStream.ReadUInt8(); // Pad

            ushort volumeId = requestStream.ReadUInt16();
            uint directoryID = requestStream.ReadUInt32();
            AfpFileDirectoryBitmap fileBitmap = requestStream.ReadEnum<AfpFileDirectoryBitmap>();
            AfpFileDirectoryBitmap directoryBitmap = requestStream.ReadEnum<AfpFileDirectoryBitmap>();
            AfpPathType pathType = requestStream.ReadEnum<AfpPathType>();
            string pathname = null;

            switch (pathType) {
                case AfpPathType.kFPLongName:
                case AfpPathType.kFPShortName:
                    pathname = requestStream.ReadPascalString();
                    break;
                case AfpPathType.kFPUTF8Name:
                    pathname = requestStream.ReadUTF8StringWithHint();
                    break;
            }

            IAfpVolume volume = session.GetVolume(volumeId);

            if (volume == null) {
                return AfpResultCode.FPObjectNotFound;
            }

            IStorageContainer container = null;

            if (directoryID == 2) {
                container = volume.StorageProvider;
            } else if (directoryID == 1) {
                if (pathname == volume.StorageProvider.Name) {
                    container = volume.StorageProvider;
                }
            } else {
                container = volume.GetNode(directoryID) as IStorageContainer;
            }

            if (container == null) {
                return AfpResultCode.FPObjectNotFound;
            }

            IStorageItem item = null;

            if (directoryID == 1) {
                item = container;
            } else {
                if (string.IsNullOrEmpty(pathname)) {
                    item = container;
                } else {
                    item = container.Content(pathname);
                }
            }

            if (item == null) {
                return AfpResultCode.FPObjectNotFound;
            }

            responseStream.WriteEnum(fileBitmap);
            responseStream.WriteEnum(directoryBitmap);

            if (item is IStorageContainer) {
                responseStream.WriteStorageContainerInfo(volume, (IStorageContainer)item, directoryBitmap);
            } else {
                responseStream.WriteStorageFileInfo(volume, (IStorageFile)item, fileBitmap);
            }

            return AfpResultCode.FPNoErr;
        }
        public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream)
        {
            requestStream.ReadUInt8(); // Pad

            ushort volumeId    = requestStream.ReadUInt16();
            uint   directoryID = requestStream.ReadUInt32();
            AfpFileDirectoryBitmap fileBitmap      = requestStream.ReadEnum <AfpFileDirectoryBitmap>();
            AfpFileDirectoryBitmap directoryBitmap = requestStream.ReadEnum <AfpFileDirectoryBitmap>();
            AfpPathType            pathType        = requestStream.ReadEnum <AfpPathType>();
            string pathname = null;

            switch (pathType)
            {
            case AfpPathType.kFPLongName:
            case AfpPathType.kFPShortName:
                pathname = requestStream.ReadPascalString();
                break;

            case AfpPathType.kFPUTF8Name:
                pathname = requestStream.ReadUTF8StringWithHint();
                break;
            }

            IAfpVolume volume = session.GetVolume(volumeId);

            if (volume == null)
            {
                return(AfpResultCode.FPObjectNotFound);
            }

            IStorageContainer container = null;

            if (directoryID == 2)
            {
                container = volume.StorageProvider;
            }
            else if (directoryID == 1)
            {
                if (pathname == volume.StorageProvider.Name)
                {
                    container = volume.StorageProvider;
                }
            }
            else
            {
                container = volume.GetNode(directoryID) as IStorageContainer;
            }

            if (container == null)
            {
                return(AfpResultCode.FPObjectNotFound);
            }

            IStorageItem item = null;

            if (directoryID == 1)
            {
                item = container;
            }
            else
            {
                if (string.IsNullOrEmpty(pathname))
                {
                    item = container;
                }
                else
                {
                    item = container.Content(pathname);
                }
            }

            if (item == null)
            {
                return(AfpResultCode.FPObjectNotFound);
            }

            responseStream.WriteEnum(fileBitmap);
            responseStream.WriteEnum(directoryBitmap);

            if (item is IStorageContainer)
            {
                responseStream.WriteStorageContainerInfo(volume, (IStorageContainer)item, directoryBitmap);
            }
            else
            {
                responseStream.WriteStorageFileInfo(volume, (IStorageFile)item, fileBitmap);
            }

            return(AfpResultCode.FPNoErr);
        }
        public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream)
        {
            byte flag = requestStream.ReadUInt8();
            ushort volumeId = requestStream.ReadUInt16();
            uint directoryId = requestStream.ReadUInt32();

            bool resourceFork = (flag == 0x80);

            if (resourceFork) {
                Log.Add(this, EntryType.Error, "Session '{0}' attempted to open resource fork, failing...", session);
                return AfpResultCode.FPMiscErr;
            }

            AfpFileDirectoryBitmap bitmap = requestStream.ReadEnum<AfpFileDirectoryBitmap>();
            AfpAccessModes accessMode = requestStream.ReadEnum<AfpAccessModes>();
            AfpPathType pathType = requestStream.ReadEnum<AfpPathType>();
            string path = null;

            switch (pathType) {
                case AfpPathType.kFPLongName:
                case AfpPathType.kFPShortName:
                    path = requestStream.ReadPascalString();
                    break;
                case AfpPathType.kFPUTF8Name:
                    path = requestStream.ReadUTF8StringWithHint();
                    break;
            }

            IAfpVolume volume = session.GetVolume(volumeId);

            if (volume == null) {
                throw new StorageItemNotFoundException();
            }

            IStorageContainer container = null;

            if (directoryId == 2) {
                container = volume.StorageProvider;
            } else {
                container = (volume.GetNode(directoryId) as IStorageContainer);
            }

            if (container == null) {
                throw new StorageItemNotFoundException();
            }

            IStorageFile file = (container.Content(path) as IStorageFile);

            if (file == null) {
                throw new StorageItemNotFoundException();
            }

            IAfpFork info = session.OpenFork(file, accessMode);

            if (info == null) {
                throw new StorageItemNotFoundException();
            }

            responseStream.WriteEnum<AfpFileDirectoryBitmap>(bitmap);
            responseStream.WriteInt16(info.Identifier);
            responseStream.WriteStorageFileInfo(volume, file, bitmap);

            return AfpResultCode.FPNoErr;
        }
예제 #14
0
        public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream)
        {
            byte   flag        = requestStream.ReadUInt8();
            ushort volumeId    = requestStream.ReadUInt16();
            uint   directoryId = requestStream.ReadUInt32();

            bool resourceFork = (flag == 0x80);

            if (resourceFork)
            {
                Log.Add(this, EntryType.Error, "Session '{0}' attempted to open resource fork, failing...", session);
                return(AfpResultCode.FPMiscErr);
            }

            AfpFileDirectoryBitmap bitmap     = requestStream.ReadEnum <AfpFileDirectoryBitmap>();
            AfpAccessModes         accessMode = requestStream.ReadEnum <AfpAccessModes>();
            AfpPathType            pathType   = requestStream.ReadEnum <AfpPathType>();
            string path = null;

            switch (pathType)
            {
            case AfpPathType.kFPLongName:
            case AfpPathType.kFPShortName:
                path = requestStream.ReadPascalString();
                break;

            case AfpPathType.kFPUTF8Name:
                path = requestStream.ReadUTF8StringWithHint();
                break;
            }

            IAfpVolume volume = session.GetVolume(volumeId);

            if (volume == null)
            {
                throw new StorageItemNotFoundException();
            }

            IStorageContainer container = null;

            if (directoryId == 2)
            {
                container = volume.StorageProvider;
            }
            else
            {
                container = (volume.GetNode(directoryId) as IStorageContainer);
            }

            if (container == null)
            {
                throw new StorageItemNotFoundException();
            }

            IStorageFile file = (container.Content(path) as IStorageFile);

            if (file == null)
            {
                throw new StorageItemNotFoundException();
            }

            IAfpFork info = session.OpenFork(file, accessMode);

            if (info == null)
            {
                throw new StorageItemNotFoundException();
            }

            responseStream.WriteEnum <AfpFileDirectoryBitmap>(bitmap);
            responseStream.WriteInt16(info.Identifier);
            responseStream.WriteStorageFileInfo(volume, file, bitmap);

            return(AfpResultCode.FPNoErr);
        }
예제 #15
0
        public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream)
        {
            requestStream.ReadUInt8(); // Padding

            ushort volumeId    = requestStream.ReadUInt16();
            uint   directoryId = requestStream.ReadUInt32();
            AfpFileDirectoryBitmap fileBitmap      = requestStream.ReadEnum <AfpFileDirectoryBitmap>();
            AfpFileDirectoryBitmap directoryBitmap = requestStream.ReadEnum <AfpFileDirectoryBitmap>();

            short reqCount     = requestStream.ReadInt16();
            int   startIndex   = requestStream.ReadInt32();
            int   maxReplySize = requestStream.ReadInt32();

            AfpPathType pathType = requestStream.ReadEnum <AfpPathType>();
            string      path     = null;

            switch (pathType)
            {
            case AfpPathType.kFPLongName:
            case AfpPathType.kFPShortName:
                path = requestStream.ReadPascalString();
                break;

            case AfpPathType.kFPUTF8Name:
                path = requestStream.ReadUTF8StringWithHint();
                break;
            }

            IAfpVolume volume = session.GetVolume(volumeId);

            if (volume == null)
            {
                return(AfpResultCode.FPObjectNotFound);
            }

            IStorageContainer container = null;

            if (directoryId == 2)
            {
                container = volume.StorageProvider;
            }
            else
            {
                container = (volume.GetNode(directoryId) as IStorageContainer);
            }

            if (container == null)
            {
                return(AfpResultCode.FPObjectNotFound);
            }

            IStorageContainer lookAtContainer = null;

            if (string.IsNullOrEmpty(path))
            {
                lookAtContainer = container;
            }
            else
            {
                lookAtContainer = (container.Content(path) as IStorageContainer);
            }

            if (lookAtContainer == null)
            {
                return(AfpResultCode.FPObjectNotFound);
            }

            var useContents = lookAtContainer.Contents();

            if (fileBitmap == 0)
            {
                useContents = useContents.OfType <IStorageContainer>();
            }
            else if (directoryBitmap == 0)
            {
                useContents = useContents.OfType <IStorageFile>();
            }

            useContents = useContents
                          .Skip(startIndex - 1)
                          .Take(reqCount);

            var contents = useContents.ToList();

            if (contents.Count == 0)
            {
                return(AfpResultCode.FPObjectNotFound);
            }

            responseStream.WriteEnum <AfpFileDirectoryBitmap>(fileBitmap);
            responseStream.WriteEnum <AfpFileDirectoryBitmap>(directoryBitmap);
            responseStream.WriteInt16((short)contents.Count);

            foreach (IStorageItem item in contents)
            {
                AfpStream resultRecord = new AfpStream();

                resultRecord.WriteUInt16(0); // Length

                if (item is IStorageContainer)
                {
                    resultRecord.WriteStorageContainerInfo(volume, (IStorageContainer)item, directoryBitmap);
                }
                else
                {
                    resultRecord.WriteStorageFileInfo(volume, (IStorageFile)item, fileBitmap);
                }

                resultRecord.WritePadding();

                resultRecord.Stream.Position = 0;
                resultRecord.WriteUInt16((byte)resultRecord.Stream.Length);

                byte[] recordData = resultRecord.ToByteArray();
                responseStream.WriteBytes(recordData);
            }

            return(AfpResultCode.FPNoErr);
        }