Can you temporary grant a user permission to avoid captchas in drupal 7? I have a module which alters a webform's form. Depending on the user agent, I want to grant the current user the permission to skip captchas, so that the captcha block wont appear at the end of my webform. The problem is, within the init function of my module, if I enable the following line: 

if (functionWhichChecksStuff()) {
        user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('skip CAPTCHA'));
    }


the permission is being granted for ALL anons, every time since it actually grants the permission to that user role permanently.

Is there a way or function which does that dynamically and temporary?
There are basic problems with your approach:


All anon users are one user for Drupal. They share common UID 0, so they are one user. And HTTP is a stateless protocol, so you can't decide "it's the same user" basing on connection. In Drupal 7 sessions are not guaranteed for anonymous users, so you can't use them reliably for that purpose either.
If you will try to modify $user->roles, it will add a role for current http call all right, but it will not regenerate caches, like admin/reports/status/rebuild or views caches based on roles.
hook_init docs says: This hook is not run on cached pages.


So, this is no-go by design, and if you need to give some privileges or options by browser session, you need to implement your own solutions, like cookies. There is a list of modules that works that way, you can use their code for reference.