The infinite loop you are noticing is caused from the fact that `menu_get_object()` causes Drupal to verify the currently logged-in user has access to the node, which causes your implementation of `hook_node_grants()` to be invoked again, which calls `menu_get_object()`, which causes your implementation of `hook_node_grants()` to be invoked again, which….

It is [hook_node_access_records()][1] that has access to the node object; the code you are using in `hook_node_grants()` should be used in `hook_node_access_records()`.

See [Node access rights][2] for more information. In short, `hook_node_grants()` returns a `realm => GID` array, while `hook_node_access_records()` return an array containing realm, GID, priority, and three 0/1 values for the view/update/delete permissions the current user has.


  [1]: http://api.drupal.org/api/drupal/modules!node!node.api.php/function/hook_node_access_records/7
  [2]: http://api.drupal.org/api/drupal/modules!node!node.module/group/node_access/7