Use the ruby's stack for security

Hello,

I need to play with the internal stack of the interpreter like this

class A
def foo2
C.new.foo
end
end

class B
def foo2
C.new.foo
end
end

class C
def foo
klass=who_is_calling_me
if klass == A
puts ‘GOOD’
elsif klass == B
puts ‘BAD’
end
end
end

and now I want

A.new.foo2

GOOD
B.new.foo2
BAD

the method who_is_calling_me must use the internal stack but how ??? here
I use one level but in a real case there is a lot of levels
I can’t send this information via call to method

I need this mechanisme to implement a security system.
A logon session have all the informations for the security and all the
objects called by the loggon session can use this informations to check
security

Anybody have an idea or it’s impossible

Thank you
Bye

It seem to me that this is something similar to Acces+, a library to
emulate Eiffel access system in ruby:
http://raa.ruby-lang.org/list.rhtml?name=access

HTH

···

il Thu, 06 May 2004 22:54:46 +0200, “guillaume.dorchies” guillaume.dorchies@wanadoo.fr ha scritto::

the method who_is_calling_me must use the internal stack but how ??? here
I use one level but in a real case there is a lot of levels
I can’t send this information via call to method

I need this mechanisme to implement a security system.
A logon session have all the informations for the security and all the
objects called by the loggon session can use this informations to check
security

Anybody have an idea or it’s impossible

“guillaume.dorchies” guillaume.dorchies@wanadoo.fr schrieb im
Newsbeitrag news:pan.2004.05.06.20.54.38.101864@wanadoo.fr

Hello,

I need to play with the internal stack of the interpreter like this

class A
def foo2
C.new.foo
end
end

class B
def foo2
C.new.foo
end
end

class C
def foo
klass=who_is_calling_me
if klass == A
puts ‘GOOD’
elsif klass == B
puts ‘BAD’
end
end
end

and now I want

A.new.foo2

GOOD
B.new.foo2
BAD

the method who_is_calling_me must use the internal stack but how ???
here
I use one level but in a real case there is a lot of levels
I can’t send this information via call to method

I need this mechanisme to implement a security system.
A logon session have all the informations for the security and all the
objects called by the loggon session can use this informations to check
security

Anybody have an idea or it’s impossible

Either you can use caller or you use set_trace_func to remember the stack.

robert

guillaume.dorchies a écrit :

the method who_is_calling_me must use the internal stack but how ??? here
I use one level but in a real case there is a lot of levels
I can’t send this information via call to method

I need this mechanisme to implement a security system.
A logon session have all the informations for the security and all the
objects called by the loggon session can use this informations to check
security

Anybody have an idea or it’s impossible

Thank you
Bye

You can try robjectteams: RubyObjectTeams download | SourceForge.net

In the directory robjectteam/sample/observer, you will find some info on
how to use it for tracing function calls. Perhaps with that tool, you
will find it easier to get what you want?

Lio

Hi,

There is caller(). But it returns a array of strings. A caller() that
would return an array of Binding objects is missing as of today.

A workaround that I can think of:

With caller()[0] you can get the name of the source file where the calling
method is defined, together with the exact line number.

Using this information it is probably possible to figure out what is
the class defined in that source file around that line number.

This is not an easy/clean path, but it is not an impossible one either.

Yours,

Jean-Hugues

···

At 05:58 07/05/2004 +0900, you wrote:

Hello,

I need to play with the internal stack of the interpreter like this

class A
def foo2
C.new.foo
end
end

class B
def foo2
C.new.foo
end
end

class C
def foo
klass=who_is_calling_me
if klass == A
puts ‘GOOD’
elsif klass == B
puts ‘BAD’
end
end
end

and now I want

A.new.foo2

GOOD
B.new.foo2
BAD

the method who_is_calling_me must use the internal stack but how ??? here
I use one level but in a real case there is a lot of levels
I can’t send this information via call to method

I need this mechanisme to implement a security system.
A logon session have all the informations for the security and all the
objects called by the loggon session can use this informations to check
security

Anybody have an idea or it’s impossible

Thank you
Bye


Web: @jhr is virteal, virtually real
Phone: +33 (0) 4 92 27 74 17