Search in sources :

Example 1 with XrootdException

use of org.dcache.xrootd.core.XrootdException in project dcache by dCache.

the class XrootdRedirectHandler method doOnStatx.

@Override
protected XrootdResponse<StatxRequest> doOnStatx(ChannelHandlerContext ctx, StatxRequest req) throws XrootdException {
    if (req.getPaths().length == 0) {
        throw new XrootdException(kXR_ArgMissing, "no paths specified");
    }
    try {
        FsPath[] paths = new FsPath[req.getPaths().length];
        for (int i = 0; i < paths.length; i++) {
            paths[i] = createFullPath(req.getPaths()[i]);
        }
        LoginSessionInfo loginSessionInfo = sessionInfo();
        Subject subject = loginSessionInfo.getSubject();
        Restriction restriction = loginSessionInfo.getRestriction();
        return new StatxResponse(req, _door.getMultipleFileStatuses(paths, subject, restriction));
    } catch (TimeoutCacheException e) {
        throw xrootdException(e.getRc(), "Internal timeout");
    } catch (PermissionDeniedCacheException e) {
        throw xrootdException(e);
    } catch (CacheException e) {
        throw xrootdException(e.getRc(), String.format("Failed to open file (%s [%d])", e.getMessage(), e.getRc()));
    }
}
Also used : Restriction(org.dcache.auth.attributes.Restriction) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) NotFileCacheException(diskCacheV111.util.NotFileCacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) CacheException(diskCacheV111.util.CacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) StatxResponse(org.dcache.xrootd.protocol.messages.StatxResponse) XrootdException(org.dcache.xrootd.core.XrootdException) Subject(javax.security.auth.Subject) FsPath(diskCacheV111.util.FsPath) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Example 2 with XrootdException

use of org.dcache.xrootd.core.XrootdException in project dcache by dCache.

the class XrootdRedirectHandler method doOnDirList.

@Override
protected XrootdResponse<DirListRequest> doOnDirList(ChannelHandlerContext ctx, DirListRequest request) throws XrootdException {
    try {
        String listPath = request.getPath();
        if (listPath.isEmpty()) {
            throw new XrootdException(kXR_ArgMissing, "no source path specified");
        }
        _log.info("Listing directory {}", listPath);
        FsPath fullListPath = createFullPath(listPath);
        if (!_door.isReadAllowed(fullListPath)) {
            throw new PermissionDeniedCacheException("Permission denied.");
        }
        LoginSessionInfo loginSessionInfo = sessionInfo();
        Subject subject = loginSessionInfo.getSubject();
        Restriction restriction = loginSessionInfo.getRestriction();
        if (request.isDirectoryStat()) {
            _door.listPath(fullListPath, subject, restriction, new StatListCallback(request, subject, restriction, fullListPath, ctx), _door.getRequiredAttributesForFileStatus());
        } else {
            _door.listPath(fullListPath, subject, restriction, new ListCallback(request, ctx), EnumSet.noneOf(FileAttribute.class));
        }
        return null;
    } catch (PermissionDeniedCacheException e) {
        throw xrootdException(e);
    }
}
Also used : Restriction(org.dcache.auth.attributes.Restriction) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) XrootdException(org.dcache.xrootd.core.XrootdException) Subject(javax.security.auth.Subject) FsPath(diskCacheV111.util.FsPath) FileAttribute(org.dcache.namespace.FileAttribute)

Example 3 with XrootdException

use of org.dcache.xrootd.core.XrootdException in project dcache by dCache.

the class AbstractXrootdRequestHandler method selectChecksum.

protected QueryResponse selectChecksum(ChecksumInfo info, Set<Checksum> checksums, QueryRequest msg) throws XrootdException {
    if (!checksums.isEmpty()) {
        /**
         * xrdcp expects lower case names for checksum algorithms
         * https://github.com/xrootd/xrootd/issues/459
         * TODO: remove toLowerCase() call when above issue is addressed
         */
        Optional<String> type = info.getType();
        if (type.isPresent()) {
            Optional<Checksum> result = checksums.stream().filter((c) -> type.get().equalsIgnoreCase(c.getType().getName())).findFirst();
            if (result.isPresent()) {
                Checksum checksum = result.get();
                return new QueryResponse(msg, checksum.getType().getName().toLowerCase() + " " + checksum.getValue());
            }
            throw new XrootdException(kXR_Unsupported, "Checksum exists, " + "but not of the requested type.");
        }
        Checksum checksum = Checksums.preferredOrder().min(checksums);
        return new QueryResponse(msg, checksum.getType().getName().toLowerCase() + " " + checksum.getValue());
    }
    throw new XrootdException(kXR_Unsupported, "No checksum available " + "for this file.");
}
Also used : ChecksumInfo(org.dcache.xrootd.util.ChecksumInfo) Logger(org.slf4j.Logger) QueryRequest(org.dcache.xrootd.protocol.messages.QueryRequest) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) QueryResponse(org.dcache.xrootd.protocol.messages.QueryResponse) Checksum(org.dcache.util.Checksum) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) XrootdException(org.dcache.xrootd.core.XrootdException) LocateRequest(org.dcache.xrootd.protocol.messages.LocateRequest) SetRequest(org.dcache.xrootd.protocol.messages.SetRequest) XrootdResponse(org.dcache.xrootd.protocol.messages.XrootdResponse) XrootdProtocol.kXR_Unsupported(org.dcache.xrootd.protocol.XrootdProtocol.kXR_Unsupported) XrootdProtocolRequestHandler(org.dcache.xrootd.core.XrootdProtocolRequestHandler) Optional(java.util.Optional) Checksums(org.dcache.util.Checksums) SetResponse(org.dcache.xrootd.protocol.messages.SetResponse) LocateResponse(org.dcache.xrootd.protocol.messages.LocateResponse) Checksum(org.dcache.util.Checksum) QueryResponse(org.dcache.xrootd.protocol.messages.QueryResponse) XrootdException(org.dcache.xrootd.core.XrootdException)

Example 4 with XrootdException

use of org.dcache.xrootd.core.XrootdException in project dcache by dCache.

the class XrootdPoolRequestHandler method doOnOpen.

/**
 * Obtains the right mover channel using an opaque token in the request. The mover channel is
 * wrapped by a file descriptor. The file descriptor is stored for subsequent access.
 * <p>
 * In the case that this is a write request as destination in a third party copy, a third-party
 * client is started.  The client issues login, open and read requests to the source server, and
 * writes the responses to the file descriptor.
 * <p>
 * The third-party client also sends a sync response back to the client when the transfer has
 * completed.
 */
@Override
protected XrootdResponse<OpenRequest> doOnOpen(ChannelHandlerContext ctx, OpenRequest msg) throws XrootdException {
    try {
        Map<String, String> opaqueMap = getOpaqueMap(msg.getOpaque());
        UUID uuid = getUuid(opaqueMap);
        if (uuid == null) {
            _log.info("Request to open {} contains no UUID.", msg.getPath());
            throw new XrootdException(kXR_NotAuthorized, "Request lacks the " + UUID_PREFIX + " property.");
        }
        enforceClientTlsIfDestinationRequiresItForTpc(opaqueMap);
        NettyTransferService<XrootdProtocolInfo>.NettyMoverChannel file = _server.openFile(uuid, false);
        if (file == null) {
            _log.info("No mover found for {} with UUID {}.", msg.getPath(), uuid);
            return redirectToDoor(ctx, msg, () -> {
                throw new XrootdException(kXR_NotAuthorized, UUID_PREFIX + " is no longer valid.");
            });
        }
        /*
             *  Stop any timer in case this is a reconnect.
             */
        _server.cancelReconnectTimeoutForMover(uuid);
        _log.debug("doOnOpen, called cancel on reconnect timers for {}", uuid);
        XrootdProtocolInfo protocolInfo = file.getProtocolInfo();
        try {
            FileDescriptor descriptor;
            boolean isWrite = file.getIoMode().contains(StandardOpenOption.WRITE);
            if (msg.isNew() && !isWrite) {
                throw new XrootdException(kXR_FileNotOpen, "File exists.");
            } else if (msg.isDelete() && !isWrite) {
                throw new XrootdException(kXR_Unsupported, "File exists.");
            /*
                     *  Some clients express only kXR_delete when then intend to write
                     *  so we need to consider delete as a write request here.
                     */
            } else if ((msg.isNew() || msg.isReadWrite() || msg.isDelete()) && isWrite) {
                boolean posc = (msg.getOptions() & kXR_posc) == kXR_posc || protocolInfo.getFlags().contains(XrootdProtocolInfo.Flags.POSC);
                if (opaqueMap.containsKey("tpc.src")) {
                    _log.debug("Request to open {} is as third-party destination.", msg);
                    XrootdTpcInfo tpcInfo = new XrootdTpcInfo(opaqueMap);
                    tpcInfo.setDelegatedProxy(protocolInfo.getDelegatedCredential());
                    tpcInfo.setUid(protocolInfo.getTpcUid());
                    tpcInfo.setGid(protocolInfo.getTpcGid());
                    descriptor = new TpcWriteDescriptor(file, posc, ctx, _server, opaqueMap.get("org.dcache.xrootd.client"), tpcInfo, tlsSessionInfo);
                } else {
                    descriptor = new WriteDescriptor(file, posc);
                }
            } else {
                descriptor = new ReadDescriptor(file);
            }
            FileStatus stat = msg.isRetStat() ? stat(file) : null;
            int fd = addDescriptor(descriptor);
            _redirectingDoor = protocolInfo.getDoorAddress();
            file = null;
            _hasOpenedFiles = true;
            return new OpenResponse(msg, fd, null, null, stat);
        } finally {
            if (file != null) {
                file.release();
            }
        }
    } catch (ParseException e) {
        throw new XrootdException(kXR_ArgInvalid, e.getMessage());
    } catch (IOException e) {
        throw new XrootdException(kXR_IOError, e.getMessage());
    }
}
Also used : NettyTransferService(org.dcache.pool.movers.NettyTransferService) FileStatus(org.dcache.xrootd.util.FileStatus) XrootdProtocolInfo(org.dcache.vehicles.XrootdProtocolInfo) IOException(java.io.IOException) TpcWriteDescriptor(org.dcache.xrootd.tpc.TpcWriteDescriptor) XrootdTpcInfo(org.dcache.xrootd.tpc.XrootdTpcInfo) OpenResponse(org.dcache.xrootd.protocol.messages.OpenResponse) ParseException(org.dcache.xrootd.util.ParseException) UUID(java.util.UUID) XrootdException(org.dcache.xrootd.core.XrootdException) TpcWriteDescriptor(org.dcache.xrootd.tpc.TpcWriteDescriptor)

Example 5 with XrootdException

use of org.dcache.xrootd.core.XrootdException in project dcache by dCache.

the class XrootdPoolRequestHandler method doOnQuery.

@Override
protected XrootdResponse<QueryRequest> doOnQuery(ChannelHandlerContext ctx, QueryRequest msg) throws XrootdException {
    switch(msg.getReqcode()) {
        case kXR_Qconfig:
            StringBuilder s = new StringBuilder();
            for (String name : msg.getArgs().split(" ")) {
                switch(name) {
                    case "bind_max":
                        s.append(0);
                        break;
                    case "readv_ior_max":
                        s.append(_maxFrameSize - ReadVResponse.READ_LIST_HEADER_SIZE);
                        break;
                    case "readv_iov_max":
                        s.append(READV_IOV_MAX);
                        break;
                    case "version":
                        s.append("dCache ").append(Version.of(XrootdPoolRequestHandler.class).getVersion());
                        break;
                    case "tpc":
                        /**
                         * Indicate support for third-party copy by responding
                         * with the protocol version.
                         */
                        s.append(XrootdProtocol.TPC_VERSION);
                        break;
                    case "tpcdlg":
                        s.append("gsi");
                        break;
                    default:
                        s.append(_queryConfig.getOrDefault(name, name));
                        break;
                }
                s.append('\n');
            }
            return new QueryResponse(msg, s.toString());
        case kXR_Qcksum:
            String opaque = msg.getOpaque();
            if (opaque == null) {
                return redirectToDoor(ctx, msg);
            }
            UUID uuid = getUuid(getOpaqueMap(opaque));
            if (uuid == null) {
                /* The spec isn't clear about whether the path includes the opaque information or not.
                     * Thus we cannot rely on there being a uuid and without the uuid we cannot lookup the
                     * file attributes in the pool.
                     */
                return redirectToDoor(ctx, msg);
            }
            FileAttributes attributes = _server.getFileAttributes(uuid);
            if (attributes == null) {
                return redirectToDoor(ctx, msg);
            }
            if (attributes.isUndefined(FileAttribute.CHECKSUM)) {
                throw new XrootdException(kXR_Unsupported, "No checksum available for this file.");
            }
            return selectChecksum(new ChecksumInfo(msg.getPath(), opaque), attributes.getChecksums(), msg);
        default:
            return unsupported(ctx, msg);
    }
}
Also used : QueryResponse(org.dcache.xrootd.protocol.messages.QueryResponse) ChecksumInfo(org.dcache.xrootd.util.ChecksumInfo) UUID(java.util.UUID) XrootdException(org.dcache.xrootd.core.XrootdException) FileAttributes(org.dcache.vehicles.FileAttributes)

Aggregations

XrootdException (org.dcache.xrootd.core.XrootdException)61 IOException (java.io.IOException)21 ChannelId (io.netty.channel.ChannelId)11 ByteBuf (io.netty.buffer.ByteBuf)8 GeneralSecurityException (java.security.GeneralSecurityException)7 Subject (javax.security.auth.Subject)7 InvalidKeyException (java.security.InvalidKeyException)6 XrootdTpcInfo (org.dcache.xrootd.tpc.XrootdTpcInfo)6 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)5 RandomAccessFile (java.io.RandomAccessFile)5 X509Certificate (java.security.cert.X509Certificate)5 TLSSessionInfo (org.dcache.xrootd.security.TLSSessionInfo)5 BucketType (org.dcache.xrootd.security.XrootdSecurityProtocol.BucketType)5 ParseException (org.dcache.xrootd.util.ParseException)5 CacheException (diskCacheV111.util.CacheException)4 File (java.io.File)4 UUID (java.util.UUID)4 OkResponse (org.dcache.xrootd.protocol.messages.OkResponse)4 FileStatus (org.dcache.xrootd.util.FileStatus)4 FsPath (diskCacheV111.util.FsPath)3