two more questions [Archive] - C Board

PDA

View Full Version : two more questions


wozza
07-15-2002, 10:08 PM
1: What exactly is a Shadow Password?
I know that when using a setuid program in the example of a program to allow a user to change their own password, it changes the contents of /etc/passwd and /etc/shadow so what is the shadow password exactly?

2: say I have a script like

foreach arg (*)
if (-d $arg)
echo $arg
endif
end

which lists all directory files under the current working directory, is that correct? and if so how would it differ if I wanted it to list all file names under a directory? what about just executable files?
Would this script differ if I was using bash instead of tcsh?

Thats my final question and thank you for your time

wozza
07-16-2002, 03:30 AM
can I also just add, what would your write for a script that is to list all symbolic links under your home directory if the command line argument lnk exists

heres what I would think:

foreach arg (argv )
if (arg == "lnk")

and then somehow print out just symbolic links if any, would that just be: echo -l

???

Thanks

raimo
07-16-2002, 04:42 AM
Bash has not foreach.
This lists all directories in current directory:

for arg in *; do
if [ -d $arg ]; then
echo $arg;
fi;
done

If you want to list symbolic links, use -L instead of -d. See man test for all of the parameters.
Note that [ something ] is similar to test something.

wozza
07-16-2002, 06:04 PM
Thanks
If I was to have the shell script run only when the command line argument "something" is entered
would I do it like this for tcsh:

if (arg == "something") then
cd $argv
foreach arg (*)
echo $arg
endif
end

raimo
07-17-2002, 04:30 AM
Did you want to check every argument and bash or tcsh?
#!/usr/bin/env tcsh
foreach arg ($argv)
if ($arg == "something") then
echo "something entered as an argument"
break
endif
end


#!/usr/bin/env bash
for arg in $*
do
if [ $arg == "something" ];then
echo "something entered as an argument"
break
fi
done


I just noticed your first queston. ;) /etc/shadow is a separate file from /etc/passwd and normal user has no reading permission to it unlike to /etc/passwd. Passwords are now stored there using some not-so-secure des encryption. That is why only root has right to read that file.

wozza
07-17-2002, 08:26 PM
Thank you so much, I am studying for an exam and these were a few specifics I was still unclear on.