• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 357
  • Last Modified:

Execution upon directory entrance?

Just curious

If this is not possible, you'll still receive full credit saying "not possible"

But I was wondering if unix can automatically execute a script, (shell script or perl), upon entering a directory.

For example, lets say:

/usr/bin contains a script called "file_filter.sh".

Now, lets just say that "file_filter.sh" just contains a command like: ls -lart | grep -i ramble

So, we do this:

# pwd
/
# cd temp
# cd website
# cd Ramble
-rwx------   1 ramble    user       2166 Mar 19 11:21 index.html
-rw-------   1 ramble    user        877 Mar 19 11:21 something.cgi
drwx------   6 ramble    user        512 Mar 25 09:01 ..
-rwx------   1 ramble    user        852 Mar 26 11:22 README
drwxr-xr-x   2 ramble    user        512 Mar 26 14:38 .
#pwd
/temp/website/Ramble

So, upon entering the Ramble directory, the file_filter.sh script was executed, and displayed.


thanks_ramble
0
ramble
Asked:
ramble
  • 4
  • 3
  • 2
  • +5
7 Solutions
 
fim32Commented:
hmm, but to run a script and stay in the directory...

i would do this.  make your file_filter.sh like so:
#!/bin/sh
cd ${1}
ls -lart | grep -i ramble

then, make an alias named something like "chdir" (which doesn't exist on unix):
alias chdir=". file_filter.sh"

and then when you use chdir, it will work.

don't think you can alias cd and expect it to, tho, because the cd that you're using in your script would also get aliased... making a messy loop.
0
 
biraCommented:
Create an user whose home directory is /temp/website/ramble
create a .profile file to this user in this directory, containing the command:
 ls -lart | grep -i ramble

  Anytime you log as this user, the command will run
  automatically.
0
 
Karl Heinz KremerCommented:
It's not possible, this is not Windows :-) You may be able to play tricks with aliasing the cd command, but this will not work if you e.g. do a cd with the chdir system call (which would allow you to write your own cd command with e..g a Perl script that would circumvent your program).
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Alf666Commented:
Securitywise, it would be like hell with traps every other dir :-)

Imagine you are root, cd to /tmp and voila.... A nice hidden root shell script is created somewhere else.

BAAAAAD :-)
0
 
rambleAuthor Commented:

Yes, but perhaps it could be use *for* security purposes.  Kind of a tracking mechanism.  Imagine if the file_filter.sh was a mail.sh script, that would email someones pager, upon a user/power user entering/exploring areas that are otherwise restricted. (as well as logging enter time, and frequency)

Just a thought.
0
 
Karl Heinz KremerCommented:
I figured that you want to use this "non-feature" for security related purposes. That's why I said that it could be circumvented by very simple means.
You could modify your kernel file system drivers so that some program gets started (or the event gets logged to a log file), but short of messing with the kernel, it's not possible.
0
 
ahoffmannCommented:
not possible, as khkremer said.
either replace or alias cd and/or ls, that's it
but keep in mind that you need to take everywher when you alias basic system or shell commands, there're infinite dragons ...
0
 
gheistCommented:
ftp
ftp> !
$ cd /
$ .....
0
 
GnsCommented:
... Just to add another "non-solution" (I agree with the above nay-sayers (Karl Heinz and Achim mainly:))... Some shells have a "prompt command feature" that you could vell use too... Horribly inefficient, and as easily fooled. For "security" of this kind we're looking at "(non-)shell menu systems" or accounting and hostbased IDSes.

-- Glenn
0
 
fim32Commented:
ah, now if you really, really, really wanted to make this work... you could just rewrite the sh code?
0
 
Alf666Commented:
fim32 : Nope. As stated before. The real place is in the kernel. Though I would not want to have to write a kernel option that messes with user space files content...

If you just rewrite the shell, only the shell gets the security feature. Any other prog will circumvent it.

You'd have to add code to the chdir() and optionally open() system calls.
0
 
gheistCommented:
and modify semantics of any of few thousands of syscalls and make a system unlike any other in the world ....
0
 
rambleAuthor Commented:

gheist: what are you doing with the ftp?  Just wondering what you're thinking...

0
 
gheistCommented:
that you can exec any command from within ftp client, telnet client, vi editor and many more, especially alternate shell.

Have a look at jail from freebsd and systrace from openbsd, one makes restricted full system within running system subtree, another allows to imply restrictions on syscalls made by programs, there must be something alike for Linux too.
0
 
ahoffmannCommented:
gheist, don't tell people the power of a 250kb program (vi), which they abandoned 20 years ago ;-))
0
 
rambleAuthor Commented:
Well, I undertood you were firing off a shell, but I wasn't sure what the:

$ .....

Which now, i presume, just means: etc...
0
 
gheistCommented:
..... which means that you have unrestricted shell back.....
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 3
  • 2
  • +5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now