Is castling legal in this position? Black to move in a game I just played. My rival and I were wondering about castling. 

Exactly:


White bishop in D6 threatens B8. Is legal for black to make long (queen) castle? (Black king and rooks have not moved)
If white bishop were in E5 threatening H8, would be legal short (king) castle?


Position:

 [title "-"]
 [fen "r3k2r/pp1nnp2/2pB2pp/3p1p2/3P4/2N3PB/PPP1PP1P/R3K2R b KQkq - 0 1"]
Yes black is allowed to castle here. The castling would be invalidated if one of the squares along the path the king has to cross (e8 to g8 or e8 to c8) was under attack by an opponent piece. In your position, for example if the bishop was on c7, or a knight was on e6 then castling wouldn't be allowed. Whereas the bishop on d6 eyeing b8 only concerns the rook's path to complete castling, so long castling remains legal. 

Similarly, if the bishop was on e5, by the same logic short castling would still be allowed.

 [title "Position"]
 [fen "r3k2r/pp1nnp2/2pB2pp/3p1p2/3P4/2N3PB/PPP1PP1P/R3K2R b KQkq - 0 1"]

 1...O-O-O