Skip to content

Commit

Permalink
is_pid_linked fun added to imem_seco #276
Browse files Browse the repository at this point in the history
  • Loading branch information
shamis committed Aug 5, 2019
1 parent e68b409 commit da5cb30
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions src/imem_seco.erl
Original file line number Diff line number Diff line change
Expand Up @@ -362,19 +362,21 @@ seco_register(#ddSeCo{skey=SKey, pid=Pid}=SeCo, AuthState) when Pid == self() ->
seco_unregister(#ddSeCo{skey=SKey, pid=Pid}) when Pid == self() ->
catch if_delete(SKey, ddSeCo@, SKey).

is_pid_linked(SKey, #ddSeCo{pid=Pid} = SeCo) ->
{links, Links} = erlang:process_info(self(), links),
case lists:member(Pid, Links) of
true ->
SeCo;
false ->
?SecurityViolation({"Not logged in", SKey})
end.

seco_existing(SKey) ->
case if_read(ddSeCo@, SKey) of
[#ddSeCo{pid=Pid} = SeCo] when Pid == self() ->
SeCo;
[#ddSeCo{pid=Pid} = SeCo] ->
{links, Links} = erlang:process_info(self(), links),
case lists:member(Pid, Links) of
true ->
SeCo;
false ->
?SecurityViolation({"Not logged in", SKey})
end;
[#ddSeCo{} = SeCo] ->
is_pid_linked(SKey, SeCo);
[] ->
?SecurityException({"Not logged in", SKey})
end.
Expand All @@ -395,17 +397,11 @@ seco_authorized(SKey) ->
case if_read(ddSeCo@, SKey) of
[#ddSeCo{pid=Pid, authState=authorized} = SeCo] when Pid == self() ->
SeCo;
[#ddSeCo{pid=Pid, authState=authorized} = SeCo] ->
{links, Links} = erlang:process_info(self(), links),
case lists:member(Pid, Links) of
true ->
SeCo;
false ->
?SecurityViolation({"Not logged in", SKey})
end;
[] ->
[#ddSeCo{authState=authorized} = SeCo] ->
is_pid_linked(SKey, SeCo);
[] ->
?SecurityException({"Not logged in", SKey})
end.
end.

seco_update(#ddSeCo{skey=SKey,pid=Pid}=SeCo, #ddSeCo{skey=SKey,pid=Pid}=SeCoNew) when Pid == self() ->
case if_read(ddSeCo@, SKey) of
Expand Down

0 comments on commit da5cb30

Please sign in to comment.