According to Joining a Grapple, if the PC wants to help his ally during the octopus wrestling contest, the PC can just (ahem) dive right in:
If your target is already grappling someone else, you can use an attack to start a grapple, as above, except that the target doesn’t get an attack of opportunity against you, and your grab automatically succeeds. You still have to make a successful opposed grapple check to become part of the grapple. (Player's Handbook 157)
That the grab automatically succeeds is crucial here, as that should let the PC who wants to join the grapple do so without the 50% miss chance and other effects resultant from the octopus's ink cloud. However, the DM does have house rules for accidentally striking the wrong foe if they share spaces and have concealment, so, depending on those house rules, the PC may find himself accidentally grappling with his ally rather than the octopus! Fortunately, this, too, should be inconsequential as Joining a Grapple continues, saying, "If there are multiple opponents involved in the grapple, you pick one to make the opposed grapple check against" (ibid.), and that should leave the PC in the thick of things, part of an ally-octopus-PC grapple ball.1
Assuming the PC successfully joins the grapple, for the remainder of his turn and while he continues grappling the PC has all the standard grapple options, but pinning the ally will be of little help (except to the octopus!): a pinned creature is "held immobile" (PH 157), that does not mean the ally cannot be moved but that the ally can't himself move! The octopus can, for example, take a standard action to make opposed grapple checks against both the PC's ally (likely pretty easy) and PC (likely a little more difficult) and, if both checks turn out in the octopus's favor, move them both!
The better option is—if the PC insists on joining the grapple—for the PC to make opposed grapple checks against the octopus (it's grapple check bonus a whopping +2!) to Damage Your Opponent and—in true action hero fashion—simply squeeze the octopus into unconsciousness, therefore freeing the PC's ally.
There's no D&D 3.5e rule that I'm aware of for yanking free an ally that's been grappled, the game seeming to assume such rescues will be facilitated through either base violence (slaying the octopus does, indeed, free the ally from the grapple, after all) or magic (e.g. the 1st-level Sor/Wiz spell benign transposition [conj] (SpC 27)) rather than tug-of-war.
A house rule alternative: bull rush one of them!
Because the grapple rules so favor the monsters, this DM allows a creature not in a grapple to make a bull rush attempt against any creature in a grapple. Success allows the bull rush to end the grapple for the target if the result's sufficient to shove the targeted creature out of the grappled creature's space (that is, the space of the creature whose sspace was entered by the creature starting the grapple). While the octopus may be able to grab again the PC's ally next turn (especially with a low bull rush result), it's also possible the PC ends up between the octopus and the ally, ready to defend his helpless friend.
1 A hyperlegalistic DM may rule that the attempt to join the grapple fails if his house rules make it so the PC would have accidentally ended up making the opposed grapple check against the PC's ally (rather than against—as the sentence mandates—the PC's octopus opponent). This, however, is so pedantic that this player would be sorely tempted to buy from the local market some octopus and, next session, yell, "Grapple check!" and throw it at the DM.