Example #1
0
//--------------------------------------------------------------------------------------------------
tdb_TreeRef_t tu_GetRequestedTree
(
    tu_UserRef_t userRef,            ///< [IN] Get a tree for this user.
    tu_TreePermission_t permission,  ///< [IN] Try to get a tree with this permission.
    const char* pathPtr              ///< [IN] The path to check.
)
//--------------------------------------------------------------------------------------------------
{
    char treeName[MAX_TREE_NAME_BYTES] = "";

    // If the path has the tree name embedded, extract it now.  Otherwise, check to see if the user
    // is trying to write to the default tree.  If it is we extract the tree name for checking
    // permission just like if they explicitly specifed the tree name.  If the user is simply trying
    // to read from their default tree, then we grant it without resorting to an ACL lookup.
    if (tp_PathHasTreeSpecifier(pathPtr) == true)
    {
        tp_GetTreeName(treeName, pathPtr);
        LE_DEBUG("** Specific tree requested, '%s'.", treeName);

        // Make sure that this isn't the user's didn't just specify their own default tree.  If they
        // did and they're looking for read access, then just go ahead and grant it.
        if (   (permission == TU_TREE_READ)
            && (strcmp(treeName, userRef->treeName) == 0))
        {
            return tdb_GetTree(userRef->treeName);
        }
    }
    else if (permission == TU_TREE_WRITE)
    {
        LE_DEBUG("** Attempting write access on the default tree, '%s'.", userRef->treeName);
        strcpy(treeName, userRef->treeName);
    }
    else
    {
        LE_DEBUG("** Opening the default tree, '%s' with read only access.", userRef->treeName);
        return tdb_GetTree(userRef->treeName);
    }

    // If we got this far, it's because we have a tree that we need to do an ACL lookup on.  So do
    // so now, if that check fails, we simply bail.
    if (   (ic_CheckTreePermission(permission, userRef->userName, treeName) == false)
        && (userRef->userId != 0))
    {
        LE_ERROR("The user, '%s', id: %d, does not have %s permission on the tree '%s'.",
                 userRef->userName,
                 userRef->userId,
                 PermissionStr(permission),
                 treeName);

        return NULL;
    }

    // Looks like the user has permission, so grab the tree.
    return tdb_GetTree(treeName);
}
// -------------------------------------------------------------------------------------------------
void le_cfgAdmin_DeleteTree
(
    le_cfgAdmin_ServerCmdRef_t commandRef,  ///< [IN] Reference used to generate a reply for this
                                            ///<      request.
    const char* treeName                    ///< [IN] Name of the tree to delete.
)
// -------------------------------------------------------------------------------------------------
{
    tdb_DeleteTree(tdb_GetTree(treeName));
    le_cfgAdmin_DeleteTreeRespond(commandRef);
}