But in that case, you can check in restrict.erl if any of the Args is equal to any of fun erlang:apply/A of erlang:spawn/A <div><br></div><div>or maybe it should detect any fun M:F/A and check it against your module.</div>
<div><div><br><div class="gmail_quote">On Tue, Jan 31, 2012 at 2:38 PM, Roberto Aloi <span dir="ltr"><<a href="mailto:roberto.aloi@erlang-solutions.com">roberto.aloi@erlang-solutions.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Not really. In R16 you could do:<br>
<br>
1> F = fun (M,F,A) -> lists:zipwith3(fun erlang:apply/3, [M], [F], [A]) end.<br>
#Fun<erl_eval.18.59269574><br>
2> F(init, stop, []).<br>
[ok]<br>
<br>
*dies*<br>
<br>
Regards,<br>
<span class="HOEnZb"><font color="#888888"><br>
Roberto Aloi<br>
---<br>
Erlang Solutions Ltd.<br>
<a href="http://www.erlang-solutions.com" target="_blank">www.erlang-solutions.com</a><br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
----- Original Message -----<br>
> It sounds to work only with tuple funs, which is going to be removed<br>
> soon anyway.<br>
><br>
><br>
> OTP-9649 Tuple funs (a two-element tuple with a module name and a<br>
> function) are now officially deprecated and will be removed<br>
> in R16. Use 'fun M:F/A' instead. To make you aware that your<br>
> system uses tuple funs, the very first time a tuple fun is<br>
> applied, a warning will be sent to the error logger.<br>
><br>
><br>
><br>
> 1> F = fun (M,F,A) -> lists:zipwith3(fun(M, F,A)-> erlang:apply(M, F,<br>
> A) end, [M], [F], [ A ]) end.<br>
> #Fun<erl_eval.18.59269574><br>
> 2> F(erlang, time, []).<br>
> ** exception exit: restricted shell does not allow time()<br>
> in function shell:non_local_allowed/4<br>
> in call from lists:zipwith3/4<br>
> 3><br>
><br>
><br>
> or am i wrong?<br>
><br>
><br>
> On Tue, Jan 31, 2012 at 12:46 PM, Roberto Aloi <<br>
> <a href="mailto:roberto.aloi@erlang-solutions.com">roberto.aloi@erlang-solutions.com</a> > wrote:<br>
><br>
><br>
> Hi all,<br>
><br>
> reading from the Erlang doc:<br>
><br>
> <a href="http://www.erlang.org/doc/man/shell.html#start_restricted-1" target="_blank">http://www.erlang.org/doc/man/shell.html#start_restricted-1</a><br>
><br>
> "The shell may be started in a restricted mode. In this mode, the<br>
> shell evaluates a function call only if allowed."<br>
><br>
> Let's write a minimal module which whitelists the 'lists' module<br>
> only:<br>
><br>
> =====<br>
> -module(restrict).<br>
><br>
> -export([local_allowed/3, non_local_allowed/3]).<br>
><br>
> -define(NON_LOCAL_ALLOWED, [lists]).<br>
><br>
> local_allowed(_Cmd, _Args, State) -><br>
> {false, State}.<br>
><br>
> non_local_allowed({Module, _Function}, _Args, State) -><br>
> {lists:member(Module, ?NON_LOCAL_ALLOWED), State}.<br>
> =====<br>
><br>
> Let's then start a restricted shell, using the above module.<br>
><br>
> $ erlc restrict.erl<br>
> $ erl -stdlib restricted_shell restrict<br>
><br>
> Erlang R14B04 (erts-5.8.5) [source] [64-bit] [smp:4:4] [rq:4]<br>
> [async-threads:0] [hipe] [kernel-poll:false]<br>
><br>
> Restricted Eshell V5.8.5 (abort with ^G)<br>
><br>
> And let's see if it works as expected.<br>
><br>
> 1> erlang:time().<br>
> ** exception exit: restricted shell does not allow time()<br>
><br>
> Cool.<br>
><br>
> 2> erlang:apply(erlang, time, []).<br>
> ** exception exit: restricted shell does not allow time()<br>
><br>
> Yeah.<br>
><br>
> 3> F = fun (M,F,A) -> lists:zipwith3({erlang, apply}, [M], [F], [ A<br>
> ]) end.<br>
> #Fun<erl_eval.18.59269574><br>
> 4> F(erlang, time, []).<br>
> [{12,35,45}]<br>
><br>
> Ooops.<br>
><br>
> Please notice that I'm not the one who actually discovered this bug<br>
> (or is it a feature?). It was actually one of the <a href="http://tryerlang.org" target="_blank">tryerlang.org</a><br>
> users, who kindly informed me about this. Originally I thought this<br>
> was an application bug, but it is not. This is more generic and it<br>
> affects the restricted shell itself.<br>
><br>
> Best regards,<br>
><br>
> Roberto Aloi<br>
> ---<br>
> @robertoaloi<br>
> Erlang Solutions Ltd.<br>
> <a href="http://www.erlang-solutions.com" target="_blank">www.erlang-solutions.com</a><br>
><br>
> _______________________________________________<br>
> erlang-bugs mailing list<br>
> <a href="mailto:erlang-bugs@erlang.org">erlang-bugs@erlang.org</a><br>
> <a href="http://erlang.org/mailman/listinfo/erlang-bugs" target="_blank">http://erlang.org/mailman/listinfo/erlang-bugs</a><br>
><br>
><br>
</div></div></blockquote></div><br></div></div>