[p4perl] Impersonating a user (p4perl 2007.3)

Tony Smith tony at smee.org
Thu Jul 10 03:12:32 PDT 2008

Hi Guillaume,

> How can users who have password-protected accounts be impersonated,
> using p4perl 2007.3 ?
> I get a "password invalid" error when running
> $p4->RunLogin($user_to_impersonate) even if a superuser has been
> specified with SetUser, so no ticket gets generated.

Have you got a valid ticket for the super-user? You have to prove you are the 
super-user before you can run 'p4 login <otheruser>'. Can you run other 
commands as that super-user?

> Another related question: the only method I found to impersonate users
> (without password protection), is a bit convoluted: for each user, I
> have to use P4::SetUser($user_to_impersonate), which means have to
> P4::Connect() and therefore P4::Disconnect(). The latter seems to act
> as a destructor, so I end up having to re-instance a P4 object inside
> a foreach loop, i.e.:
> use P4;
> our $p4 = new P4;
> $p4->Connect();
> my $usersref = $p4->RunUsers();
> $p4->Disconnect();
> foreach my $userref (@$usersref) {
>     my $user = $userref->{'User'};
>     $p4 = new P4;
>     $p4->SetUser($user);
>     $p4->Connect();
>     my @info = $p4->RunInfo();
>     # Do something with @info
>     $p4->Disconnect();
> }
> Surely there must be a better way ! Any ideas ?

No, that's the right way to do it - authentication is done once per session, 
not once per command (otherwise that would be slow), so you need a new 
session for each user you want to impersonate.



More information about the p4perl mailing list