Models are normally not permitted to shoot at enemies that are engaged in close combat. The exception is if a unit is within 4" of an unengaged arc of an enemy unit in close combat. However, for each '1' rolled when rolling to Hit, a missile manages to go awry and hit the friendly unit instead. You are only allowed to fire into combat if the target is at Unit Strength 5 or more.
Some war machine weapons, particularly those that use templates, can accidentally hit friends whilst aiming at the enemy. The key word here is 'accidentally' – you cannot purposefully aim a template so that some of your models will be hit. Note that you may never target enemies engaged in close combat with templates, even if they are within 4".