hello, if I have a unix shell script with permission ---x--x--x, how can a unix shell detect that it is not an execuable binary application and gives an error message "permission denied"? Thanks, Peter
hello, if I have a unix shell script with permission ---x--x--x, how can a unix shell detect that it is not an execuable binary application and gives an error message "permission denied"? Thanks, Peter
in comp.unix.shell i read: on most systems an executable script must also be readable. -- a signature
That is done at kernel level. The kernel first checks your permission to execute some file. Then get its header and if it is a binary executable, run the code. Otherwise, if it is some shebang (#! path stuff) it actually run, in user mode, the following command "path stuff your-file". As the program specified by "path" tries to read the file before interpret it, the permission denied is issued. file ~user/foo.mk with --x--x--x perms and contents: #! /bin/make -f all: ; echo all you try: exec ~user/foo.mk kernel checks 'x' flag, ok, then loads ~user/foo.mk, detects #! and try to run as : $ /bin/make -f ~user/foo.mk -- carlos ** http://www.**--****.com/
2004-01-14, 08:05(+00), peter: [...] [...] If it is a dynamically linked object. You can see if your dynamic linker as options to not execute the file but instead to write some informations about it: on HPUX: _HP_DLDOPTS=-ldd on Linux: LD_DEBUG=help or LD_TRACE_LOADED_OBJECTS=1 or LD_TRACE_PRELINKING=1 (env vars) ~$ ls -l ls passwd ---x--x--x 1 chazelas users 61144 2004-01-14 09:40 ls* ---x--x--x 1 chazelas users 2260 2004-01-14 09:44 passwd* ~$ LD_TRACE_LOADED_OBJECTS=1 ./ls librt.so.1 => /lib/librt.so.1 (0x40021000) libc.so.6 => /lib/libc.so.6 (0x40033000) libpthread.so.0 => /lib/libpthread.so.0 (0x40168000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000) ~$ LD_TRACE_LOADED_OBJECTS=1 ./passwd zsh: permission non accord: ./passwd (126)~$ See your dynamic linker man page (dld.sl, ld.so, ld-linux.so...) You may also play with LD_PRELOAD to override the _init or main functions. If the file is a valid binary file but statically linked, it will get executed... -- Sthane ["Stephane.Chazelas" at "free.fr"]
I think there might be a loop. #!/bin/bash printf("hello\n"); with permission --x--x--x. bash kernel will send it to system() or exec() for executing if the file is not readable (there is a chance that the file might be binary). However, if it is some shebang #!/bin/bash, system() through sh which calls exec() will send it to bash. Again, bash kernal cannot read this executale code, it will send it back to system() since bash itself cannot tell if it is binary code or not. Not sure how shell handles this dilema. thanks, Peter
hi again, there's no loop. Using your example and some pseudo-code: $ cat > xpto.sh #! /bin/bash echo "hi" ^D $ chmod 111 xpto.sh $ ./xpto.sh [bash: exec xpto.sh] [kernel: loads header, detects shebang, run /bin/bash path/xpto.sh...] [/bin/bash: open xpto.sh, permission denied] Bash, or some other program, must open files before doing anything. You are confusing a "bash file" with "bash -c file". The 2nd would in fact cause a loop, i.e. bash was to execute file and the same mechanism would occur again, but the kernel actually issues the first. -- carlos ** http://www.**--****.com/
The shell doesn't detect this. This is a job for your system's kernel, which the shell will shell will call via exec(). First, the kernel checks to make sure that you do in fact have permission to execute the file. Then, if you do, the kernel looks for the "#!" characters as the first two bytes. If it finds them, it is interpreted, and the first line after the "#!" is the pathname of the interpreter. The kernel loads the interpreter into memory, passing it the name of the file as a a parameter. If file does not begin "#!", the kernel looks to see if the file is valid binary format (exactly what this entails varies from system to system). If it is a valid binary, it loads into memory and starts it running. If neither begins with "#!" nor is a valid binary, the kernel assumes it is a script for the current shell. It loads the current shell into memory and starts it running, passing it the name of the file as a parameter. Since all this code runs in the kernel it doesn't care about your file permissions, and that's why you can run binary programs you can't read. But with interpreted files, the kernel actually loads the interpreter. The interpreter runs as user code, so it must have permission to read the script. Chris Mattern
1.Binary File Differences: When Do Differences Matter?
We will soon be building our software system on new hardware (same make/model, just new boxes). I have noticed that even on our existing hardware, building the exact same software from the same source will give differing binary files, some even with minor file size differences. So now, when we move over to the new hardware, how can we be sure that we are still building the same software given that the binaries contain differences even without changing systems? Of course, we will be completely testing the software built on the new system. Is there any way to tell if the differences in the binary files are differences that will affect the actual operation of the software, or perhaps the ability to update a single dynamic library? I'd like to be able to do some kind of checkout other than the full system test to give me some confidence that the new hardware is building the same system as the old hardware. Any suggestions?
2.what is the difference between binary and rom files
i found somewhere a line mentioning that the user has a choice between rpm and binary files what is the difference between the two ( some rpm packege for the mysql server software ) -Parag
3.Append image file to ASCII text file
I'm looking for a way on the Linux command line be be able to append an image file to an ASCII text file. One thought I had was to first convert the text file into postscript and then append the signature image to that file. # Convert ascii file to postscript enscript file.txt --no-header -o file.ps # Append both image files into one convert -append file.ps image.bmp file_with_image.pdf This sort of worked, but only part of the text file and image are viewable in the new pdf file so I'm looking for a better solution. The text file is a check that will be printed on a HP laser printer and the image is a signature to be printed on the bottom of the check. Does anyone have any suggestions on how I can do this?
4.Assigning contents of a ascii file to a script variable but maintain file structure
How do I assign the results of sed or grep to a shell variable but maintain its format. If I have a ascii file named sumdarnfil a1 a2 z1 z2 x1 b1 b2 j2 w9 h35 At the command line I run grep "2$" sumdarnfil the results are vidalc 31349: grep "2$" sumdarnfil a2 z2 b2 j2 If I tmpfile=`grep "2$" sumdarnfil echo $tmpfile the result is vidalc 31350: tmpfile=`grep "2$" sumdarnfil` vidalc 31351: echo $tmpfile a2 z2 b2 j2 For practical purposes echo $tmpfile | tr ' ' '\012' isnt a good option.
5.difference between normal file and named pipe file
HI, will anyone let me know the differences between the normal unix file and named pipe file? Regards
6. all files show differences with Unix files
Users browsing this forum: No registered users and 34 guest