Beispiel #1
0
int
rsCollCreate( rsComm_t *rsComm, collInp_t *collCreateInp ) {
    int status;
    rodsServerHost_t *rodsServerHost = NULL;
    ruleExecInfo_t rei;
    collInfo_t collInfo;
    specCollCache_t *specCollCache = NULL;
    dataObjInfo_t *dataObjInfo = NULL;

    irods::error ret = validate_logical_path( collCreateInp->collName );
    if ( !ret.ok() ) {
        if ( rsComm->rError.len < MAX_ERROR_MESSAGES ) {
            char error_msg[ERR_MSG_LEN];
            snprintf(error_msg, ERR_MSG_LEN, "%s", ret.user_result().c_str());
            addRErrorMsg( &rsComm->rError, ret.code(), error_msg );
        }
        irods::log( ret );
        return SYS_INVALID_INPUT_PARAM;
    }

    // Issue 3913: retain status in case string too long
    status = resolveLinkedPath( rsComm, collCreateInp->collName, &specCollCache,
                       &collCreateInp->condInput );

    // Issue 3913: retain status in case string too long
    if (status == USER_STRLEN_TOOLONG) {
        return USER_STRLEN_TOOLONG;
    }
    status = getAndConnRcatHost(
                 rsComm,
                 MASTER_RCAT,
                 ( const char* )collCreateInp->collName,
                 &rodsServerHost );

    if ( status < 0 || rodsServerHost == NULL ) { // JMC cppcheck
        return status;
    }

    if ( rodsServerHost->localFlag == LOCAL_HOST ) {
        initReiWithCollInp( &rei, rsComm, collCreateInp, &collInfo );

        status = applyRule( "acPreprocForCollCreate", NULL, &rei, NO_SAVE_REI );

        if ( status < 0 ) {
            if ( rei.status < 0 ) {
                status = rei.status;
            }
            rodsLog( LOG_ERROR,
                     "rsCollCreate:acPreprocForCollCreate error for %s,stat=%d",
                     collCreateInp->collName, status );
            return status;
        }

        if ( getValByKey( &collCreateInp->condInput, RECURSIVE_OPR__KW ) !=
                NULL ) {
            status = rsMkCollR( rsComm, "/", collCreateInp->collName );
            return status;
        }
        std::string svc_role;
        irods::error ret = get_catalog_service_role(svc_role);
        if(!ret.ok()) {
            irods::log(PASS(ret));
            return ret.code();
        }

        if( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) {
            /* for STRUCT_FILE_COLL to make a directory in the structFile, the
             * COLLECTION_TYPE_KW must be set */

            status = resolvePathInSpecColl( rsComm, collCreateInp->collName,
                                            WRITE_COLL_PERM, 0, &dataObjInfo );
            if ( status >= 0 ) {
                freeDataObjInfo( dataObjInfo );
                if ( status == COLL_OBJ_T ) {
                    return 0;
                }
                else if ( status == DATA_OBJ_T ) {
                    return USER_INPUT_PATH_ERR;
                }
            }
            else if ( status == SYS_SPEC_COLL_OBJ_NOT_EXIST ) {
                /* for STRUCT_FILE_COLL to make a directory in the structFile, the
                 * COLLECTION_TYPE_KW must be set */
                if ( dataObjInfo != NULL && dataObjInfo->specColl != NULL &&
                        dataObjInfo->specColl->collClass == LINKED_COLL ) {
                    /*  should not be here because if has been translated */
                    return SYS_COLL_LINK_PATH_ERR;
                }
                else {
                    status = l3Mkdir( rsComm, dataObjInfo );
                }
                freeDataObjInfo( dataObjInfo );
                return status;
            }
            else {
                if ( isColl( rsComm, collCreateInp->collName, NULL ) >= 0 ) {
                    return CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME;
                }
                status = _rsRegColl( rsComm, collCreateInp );
            }
            rei.status = status;
            if ( status >= 0 ) {
                rei.status = applyRule( "acPostProcForCollCreate", NULL, &rei,
                                        NO_SAVE_REI );

                if ( rei.status < 0 ) {
                    rodsLog( LOG_ERROR,
                             "rsCollCreate:acPostProcForCollCreate error for %s,stat=%d",
                             collCreateInp->collName, status );
                }
            }
        } else if( irods::CFG_SERVICE_ROLE_CONSUMER == svc_role ) {
            status = SYS_NO_RCAT_SERVER_ERR;
        } else {
            rodsLog(
                LOG_ERROR,
                "role not supported [%s]",
                svc_role.c_str() );
            status = SYS_SERVICE_ROLE_NOT_SUPPORTED;
        }
    }
    else {
        status = rcCollCreate( rodsServerHost->conn, collCreateInp );
    }
    return status;
}
Beispiel #2
0
int
rsRmColl( rsComm_t *rsComm, collInp_t *rmCollInp,
          collOprStat_t **collOprStat ) {
    int status;
    ruleExecInfo_t rei;
    collInfo_t collInfo;
    rodsServerHost_t *rodsServerHost = NULL;
    specCollCache_t *specCollCache = NULL;

    resolveLinkedPath( rsComm, rmCollInp->collName, &specCollCache,
                       &rmCollInp->condInput );
    status = getAndConnRcatHost(
                 rsComm,
                 MASTER_RCAT,
                 ( const char* )rmCollInp->collName,
                 &rodsServerHost );

    if ( status < 0 || NULL == rodsServerHost )  { // JMC cppcheck - nullptr
        return status;
    }
    else if ( rodsServerHost->rcatEnabled == REMOTE_ICAT ) {
        int retval;
        retval = _rcRmColl( rodsServerHost->conn, rmCollInp, collOprStat );
        status = svrSendZoneCollOprStat( rsComm, rodsServerHost->conn,
                                         *collOprStat, retval );
        return status;
    }

    initReiWithCollInp( &rei, rsComm, rmCollInp, &collInfo );

    status = applyRule( "acPreprocForRmColl", NULL, &rei, NO_SAVE_REI );

    if ( status < 0 ) {
        if ( rei.status < 0 ) {
            status = rei.status;
        }
        rodsLog( LOG_ERROR,
                 "rsRmColl:acPreprocForRmColl error for %s,stat=%d",
                 rmCollInp->collName, status );
        return status;
    }

    if ( collOprStat != NULL ) {
        *collOprStat = NULL;
    }
    if ( getValByKey( &rmCollInp->condInput, RECURSIVE_OPR__KW ) == NULL ) {
        status = _rsRmColl( rsComm, rmCollInp, collOprStat );
    }
    else {
        if ( isTrashPath( rmCollInp->collName ) == False &&
                getValByKey( &rmCollInp->condInput, FORCE_FLAG_KW ) != NULL ) {
            rodsLog( LOG_NOTICE,
                     "rsRmColl: Recursively removing %s.",
                     rmCollInp->collName );
        }
        status = _rsRmCollRecur( rsComm, rmCollInp, collOprStat );
    }
    rei.status = status;
    rei.status = applyRule( "acPostProcForRmColl", NULL, &rei,
                            NO_SAVE_REI );

    if ( rei.status < 0 ) {
        rodsLog( LOG_ERROR,
                 "rsRmColl:acPostProcForRmColl error for %s,stat=%d",
                 rmCollInp->collName, status );
    }

    return status;
}
Beispiel #3
0
int
rsCollCreate( rsComm_t *rsComm, collInp_t *collCreateInp ) {
    int status;
    rodsServerHost_t *rodsServerHost = NULL;
    ruleExecInfo_t rei;
    collInfo_t collInfo;
    specCollCache_t *specCollCache = NULL;
#ifdef RODS_CAT
    dataObjInfo_t *dataObjInfo = NULL;
#endif

    irods::error ret = validate_collection_path( collCreateInp->collName );
    if ( !ret.ok() ) {
        irods::log( ret );
        return SYS_INVALID_INPUT_PARAM;
    }

    resolveLinkedPath( rsComm, collCreateInp->collName, &specCollCache,
                       &collCreateInp->condInput );
    status = getAndConnRcatHost(
                 rsComm,
                 MASTER_RCAT,
                 ( const char* )collCreateInp->collName,
                 &rodsServerHost );
    if ( status < 0 || rodsServerHost == NULL ) { // JMC cppcheck
        return status;
    }

    if ( rodsServerHost->localFlag == LOCAL_HOST ) {
        initReiWithCollInp( &rei, rsComm, collCreateInp, &collInfo );

        status = applyRule( "acPreprocForCollCreate", NULL, &rei, NO_SAVE_REI );

        if ( status < 0 ) {
            if ( rei.status < 0 ) {
                status = rei.status;
            }
            rodsLog( LOG_ERROR,
                     "rsCollCreate:acPreprocForCollCreate error for %s,stat=%d",
                     collCreateInp->collName, status );
            return status;
        }

        if ( getValByKey( &collCreateInp->condInput, RECURSIVE_OPR__KW ) !=
                NULL ) {
            status = rsMkCollR( rsComm, "/", collCreateInp->collName );
            return status;
        }
#ifdef RODS_CAT

        /* for STRUCT_FILE_COLL to make a directory in the structFile, the
         * COLLECTION_TYPE_KW must be set */

        status = resolvePathInSpecColl( rsComm, collCreateInp->collName,
                                        WRITE_COLL_PERM, 0, &dataObjInfo );
        if ( status >= 0 ) {
            freeDataObjInfo( dataObjInfo );
            if ( status == COLL_OBJ_T ) {
                return 0;
            }
            else if ( status == DATA_OBJ_T ) {
                return USER_INPUT_PATH_ERR;
            }
        }
        else if ( status == SYS_SPEC_COLL_OBJ_NOT_EXIST ) {
            /* for STRUCT_FILE_COLL to make a directory in the structFile, the
             * COLLECTION_TYPE_KW must be set */
            if ( dataObjInfo != NULL && dataObjInfo->specColl != NULL &&
                    dataObjInfo->specColl->collClass == LINKED_COLL ) {
                /*  should not be here because if has been translated */
                return SYS_COLL_LINK_PATH_ERR;
            }
            else {
                status = l3Mkdir( rsComm, dataObjInfo );
            }
            freeDataObjInfo( dataObjInfo );
            return status;
        }
        else {
            if ( isColl( rsComm, collCreateInp->collName, NULL ) >= 0 ) {
                return CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME;
            }
            status = _rsRegColl( rsComm, collCreateInp );
        }
        rei.status = status;
        if ( status >= 0 ) {
            rei.status = applyRule( "acPostProcForCollCreate", NULL, &rei,
                                    NO_SAVE_REI );

            if ( rei.status < 0 ) {
                rodsLog( LOG_ERROR,
                         "rsCollCreate:acPostProcForCollCreate error for %s,stat=%d",
                         collCreateInp->collName, status );
            }
        }

#else
        status = SYS_NO_RCAT_SERVER_ERR;
#endif
    }
    else {
        status = rcCollCreate( rodsServerHost->conn, collCreateInp );
    }

    return status;
}
Beispiel #4
0
int
_rsPhyRmColl( rsComm_t *rsComm, collInp_t *rmCollInp,
              dataObjInfo_t *dataObjInfo, collOprStat_t **collOprStat ) {

    char *tmpValue;
    int status;
    collInp_t openCollInp;
    collEnt_t *collEnt;
    int handleInx;
    dataObjInp_t dataObjInp;
    collInp_t tmpCollInp;
    int rmtrashFlag = 0;
    int savedStatus = 0;
    int fileCntPerStatOut = FILE_CNT_PER_STAT_OUT;
    int entCnt = 0;
    ruleExecInfo_t rei;
    collInfo_t collInfo;

    memset( &openCollInp, 0, sizeof( openCollInp ) );
    rstrcpy( openCollInp.collName, rmCollInp->collName, MAX_NAME_LEN );
    /* cannot query recur because collection is sorted in wrong order */
    openCollInp.flags = 0;
    handleInx = rsOpenCollection( rsComm, &openCollInp );
    if ( handleInx < 0 ) {
        rodsLog( LOG_ERROR,
                 "_rsPhyRmColl: rsOpenCollection of %s error. status = %d",
                 openCollInp.collName, handleInx );
        return handleInx;
    }

    memset( &dataObjInp, 0, sizeof( dataObjInp ) );
    memset( &tmpCollInp, 0, sizeof( tmpCollInp ) );
    /* catch the UNREG_OPR */
    dataObjInp.oprType = tmpCollInp.oprType = rmCollInp->oprType;

    if ( ( tmpValue = getValByKey( &rmCollInp->condInput, AGE_KW ) ) != NULL ) {
        if ( CollHandle[handleInx].rodsObjStat != NULL ) {
            /* when a collection is moved, the modfiyTime of the object in
              * the collectin does not change. So, we'll depend on the
              * modfiyTime of the collection */
            int ageLimit = atoi( tmpValue ) * 60;
            int modifyTime =
                atoi( CollHandle[handleInx].rodsObjStat->modifyTime );
            if ( ( time( 0 ) - modifyTime ) < ageLimit ) {
                rsCloseCollection( rsComm, &handleInx );
                return 0;
            }
        }
        addKeyVal( &dataObjInp.condInput, AGE_KW, tmpValue );
        addKeyVal( &tmpCollInp.condInput, AGE_KW, tmpValue );
    }
    addKeyVal( &dataObjInp.condInput, FORCE_FLAG_KW, "" );
    addKeyVal( &tmpCollInp.condInput, FORCE_FLAG_KW, "" );

    if ( ( tmpValue = getValByKey( &rmCollInp->condInput, AGE_KW ) ) != NULL ) {
        addKeyVal( &dataObjInp.condInput, AGE_KW, tmpValue );
        addKeyVal( &tmpCollInp.condInput, AGE_KW, tmpValue );
    }

    if ( collOprStat != NULL && *collOprStat == NULL ) {
        *collOprStat = ( collOprStat_t* )malloc( sizeof( collOprStat_t ) );
        memset( *collOprStat, 0, sizeof( collOprStat_t ) );
    }



    if ( getValByKey( &rmCollInp->condInput, ADMIN_RMTRASH_KW ) != NULL ) {
        if ( isTrashPath( rmCollInp->collName ) == False ) {
            return SYS_INVALID_FILE_PATH;
        }
        if ( rsComm->clientUser.authInfo.authFlag != LOCAL_PRIV_USER_AUTH ) {
            return CAT_INSUFFICIENT_PRIVILEGE_LEVEL;
        }
        addKeyVal( &tmpCollInp.condInput, ADMIN_RMTRASH_KW, "" );
        addKeyVal( &dataObjInp.condInput, ADMIN_RMTRASH_KW, "" );
        rmtrashFlag = 2;
    }
    else if ( getValByKey( &rmCollInp->condInput, RMTRASH_KW ) != NULL ) {
        if ( isTrashPath( rmCollInp->collName ) == False ) {
            return SYS_INVALID_FILE_PATH;
        }
        addKeyVal( &tmpCollInp.condInput, RMTRASH_KW, "" );
        addKeyVal( &dataObjInp.condInput, RMTRASH_KW, "" );
        rmtrashFlag = 1;
    }
    // =-=-=-=-=-=-=-
    // JMC - backport 4552
    if ( getValByKey( &rmCollInp->condInput, EMPTY_BUNDLE_ONLY_KW ) != NULL ) {
        addKeyVal( &tmpCollInp.condInput, EMPTY_BUNDLE_ONLY_KW, "" );
        addKeyVal( &dataObjInp.condInput, EMPTY_BUNDLE_ONLY_KW, "" );
    }
    // =-=-=-=-=-=-=-
    while ( ( status = rsReadCollection( rsComm, &handleInx, &collEnt ) ) >= 0 ) {
        if ( entCnt == 0 ) {
            entCnt ++;
            /* cannot rm non-empty home collection */
            if ( isHomeColl( rmCollInp->collName ) ) {
                return CANT_RM_NON_EMPTY_HOME_COLL;
            }
        }
        if ( collEnt->objType == DATA_OBJ_T ) {
            snprintf( dataObjInp.objPath, MAX_NAME_LEN, "%s/%s",
                      collEnt->collName, collEnt->dataName );

            status = rsDataObjUnlink( rsComm, &dataObjInp );
            if ( status < 0 ) {
                rodsLog( LOG_ERROR,
                         "_rsPhyRmColl:rsDataObjUnlink failed for %s. stat = %d",
                         dataObjInp.objPath, status );
                /* need to set global error here */
                savedStatus = status;
            }
            else if ( collOprStat != NULL ) {
                ( *collOprStat )->filesCnt ++;
                if ( ( *collOprStat )->filesCnt >= fileCntPerStatOut ) {
                    rstrcpy( ( *collOprStat )->lastObjPath, dataObjInp.objPath,
                             MAX_NAME_LEN );
                    status = svrSendCollOprStat( rsComm, *collOprStat );
                    if ( status < 0 ) {
                        rodsLogError( LOG_ERROR, status,
                                      "_rsPhyRmColl: svrSendCollOprStat failed for %s. status = %d",
                                      rmCollInp->collName, status );
                        *collOprStat = NULL;
                        savedStatus = status;
                        break;
                    }
                    *collOprStat = ( collOprStat_t* )malloc( sizeof( collOprStat_t ) );
                    memset( *collOprStat, 0, sizeof( collOprStat_t ) );
                }
            }
        }
        else if ( collEnt->objType == COLL_OBJ_T ) {
            if ( strcmp( collEnt->collName, rmCollInp->collName ) == 0 ) {
                continue;    /* duplicate */
            }
            rstrcpy( tmpCollInp.collName, collEnt->collName, MAX_NAME_LEN );
            if ( collEnt->specColl.collClass != NO_SPEC_COLL ) {
                if ( strcmp( collEnt->collName, collEnt->specColl.collection )
                        == 0 ) {
                    continue;    /* no mount point */
                }
            }
            initReiWithCollInp( &rei, rsComm, &tmpCollInp, &collInfo );
            status = applyRule( "acPreprocForRmColl", NULL, &rei, NO_SAVE_REI );
            if ( status < 0 ) {
                if ( rei.status < 0 ) {
                    status = rei.status;
                }
                rodsLog( LOG_ERROR,
                         "_rsPhyRmColl:acPreprocForRmColl error for %s,stat=%d",
                         tmpCollInp.collName, status );
                return status;
            }
            status = _rsRmCollRecur( rsComm, &tmpCollInp, collOprStat );
            rei.status = status;
            rei.status = applyRule( "acPostProcForRmColl", NULL, &rei,
                                    NO_SAVE_REI );
            if ( rei.status < 0 ) {
                rodsLog( LOG_ERROR,
                         "_rsRmColl:acPostProcForRmColl error for %s,stat=%d",
                         tmpCollInp.collName, status );
            }
        }
        if ( status < 0 ) {
            savedStatus = status;
        }
        free( collEnt );    /* just free collEnt but not content */
    }
    rsCloseCollection( rsComm, &handleInx );

    if ( ( rmtrashFlag > 0 && ( isTrashHome( rmCollInp->collName ) > 0 || // JMC - backport 4561
                                isOrphanPath( rmCollInp->collName ) == is_ORPHAN_HOME ) )   ||
            ( isBundlePath( rmCollInp->collName ) == True                 &&
              getValByKey( &rmCollInp->condInput, EMPTY_BUNDLE_ONLY_KW ) != NULL ) ) {
        /* don't rm user's home trash coll or orphan collection */
        status = 0;
    }
    else {
        if ( dataObjInfo != NULL && dataObjInfo->specColl != NULL ) {
            if ( dataObjInfo->specColl->collClass == LINKED_COLL ) {
                rstrcpy( rmCollInp->collName, dataObjInfo->objPath,
                         MAX_NAME_LEN );
                status = svrUnregColl( rsComm, rmCollInp );
            }
            else {
                status = l3Rmdir( rsComm, dataObjInfo );
            }
        }
        else {
            status = svrUnregColl( rsComm, rmCollInp );
            if ( status < 0 ) {
                savedStatus = status;
            }
        }
    }
    clearKeyVal( &tmpCollInp.condInput );
    clearKeyVal( &dataObjInp.condInput );

    return savedStatus;
}