03-01-2008
Check existence of a login
Hi everybody,
I need to check in C program wether a given login is known on the system. Is there any system function that could do this ?
So far, all I could find is getpwnam(), which answers my problem by parsing the local password database. But won't work if a user is authenticated by other means (PAM, Kerberos, ...).
I am suprised not to have found anything on that topic, because any shell is able to resolve a user's HOME while doing the tilde expansion, but how is it done? I had a look at the shell C sources, but I am a bit lost. Also, I don't have a system with network authentication handy, so I can't ktrace /bin/sh while doing a tilde expansion to see what function is called...
Thanks in advance, any help much appreciated.
Xavier
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
hi, I have a list of filenames and I want to verify if they all exist. I know "if filename" would do the trick but how do I go about a list of files? thanks (3 Replies)
Discussion started by: mpang_
3 Replies
2. UNIX for Dummies Questions & Answers
Hi ,
I have a script wherein i have a For Loop.
Within this for loop i create a variable and assign it a value.
The script goes to a For Loop only if certain conditions are met , which means the variable may or may not exists.
However down the line in the script i have to check if that... (2 Replies)
Discussion started by: samit_9999
2 Replies
3. Programming
Hi everybody,
I need to check in C program whether a given login is known on the system. Is there any system function that could do this ?
So far, all I could find is getpwnam(), which answers my problem by parsing the local password database. But won't work if a user is authenticated by... (2 Replies)
Discussion started by: xavier054
2 Replies
4. AIX
Hello
I am having a requirement like if there is no file in the directory then i need a message to pop on after the execution of the script.
My script basically does for File in `ls -t $DIRECTORY | tail -1`;
if there is no file the DIRECTORY then the script is simply exiting with out... (2 Replies)
Discussion started by: dsdev_123
2 Replies
5. AIX
I have requirement where i need to search for files which start with SALESORDER and PURCHASEORDER. i need to process the files with SALESORDER first and then PURCHASEORDER. If SALESORDER files are not there i dont want to process PURCHASEORDER and i want to come out of script. I have written a code... (4 Replies)
Discussion started by: dsdev_123
4 Replies
6. Shell Programming and Scripting
Hi
How can I check if the path exist or not?
echo "Enter path:";
read my_path;
##I should check whether my_path exists or not.... (5 Replies)
Discussion started by: tjay83
5 Replies
7. Shell Programming and Scripting
i want to check if the file is in the directory or not, and also it should be handle error conditions, like missing files and report the error and exit.
i did something like this:
file ="hello"
if !test -e "${file}"
then echo "No such files exist!"
exit 1
else
do something.......
fi
... (1 Reply)
Discussion started by: mingming88
1 Replies
8. UNIX for Dummies Questions & Answers
I need to check for the existence of a file *.log in a specific directory using a perl script.
Presently am not in that particular directory.
So i am using chdir ("/path/to/my/file)
And then i am using the -e in an if statement to check if it exists.
if (-e $File) {......}
$File contains the... (1 Reply)
Discussion started by: manutd
1 Replies
9. Shell Programming and Scripting
Hi
I have a requirement to check whether the files exists, then it will call other steps in shell script.
I did
ls *.csv|wc -l
if
then checking the count of the files should be more than 1 then it will call other steps.
I am getting the error that too many arguements as there n... (13 Replies)
Discussion started by: cnrj
13 Replies
10. Shell Programming and Scripting
hi
i wanted to check if the file exist or not(multiple files)
DIRE=/home/V478
if ;
then
echo "file present"
else
echo "file not present"
fi
But i am getting the error as
: [: unexpected operator/operand (3 Replies)
Discussion started by: ATWC
3 Replies
LOGIN(1) Linux Administrator's Manual LOGIN(1)
NAME
login - Begin session on the system
SYNOPSIS
login [ -p ] [ -h host ] [ -H ] [ -f username | username ]
DESCRIPTION
login is used when signing onto a system. If no argument is given, login prompts for the username.
The user is then prompted for a password, where approprate. Echoing is disabled to prevent revealing the password. Only a small number of
password failures are permitted before login exits and the communications link is severed.
If password aging has been enabled for the account, the user may be prompted for a new password before proceeding. He will be forced to
provide his old password and the new password before continuing. Please refer to passwd(1) for more information.
The user and group ID will be set according to their values in the file. There is one exception if the user ID is zero: in this case, only
the primary group ID of the account is set. This should prevent that the system adminitrator cannot login in case of network problems. The
value for $HOME, $SHELL, $PATH, $LOGNAME, and $MAIL are set according to the appropriate fields in the password entry. $PATH defaults to
/usr/local/bin:/bin:/usr/bin:. for normal users, and to /sbin:/bin:/usr/sbin:/usr/bin for root if not other configured. The environment
variable $TERM will be preserved, if it exists (other environment variables are preserved if the -p option is given) or be initialize to
the terminal type on your tty line, as specified in /etc/ttytype.
Then the user's shell is started. If no shell is specified for the user in /etc/passwd, then /bin/sh is used. If there is no directory
specified in /etc/passwd, then / is used (the home directory is checked for the .hushlogin file described above).
login reads the /etc/login.defs(5) configuration file. Please refer to this documenation for options which could be set.
OPTIONS
-p Used by getty(8) to tell login not to destroy the environment
-f Used to skip a second login authentication. This option is deprecated and should not be used. It does specifically not work for
root. Using this option also means, that not all PAM functions are called.
-h Used by other servers (i.e., telnetd(8)) to pass the name of the remote host to login so that it may be placed in utmp and wtmp.
Only the superuser may use this option.
-H Used by other servers (i.e., telnetd(8)) to tell login that printing the hostname should be suppressed in the login: prompt.
FILES
/var/run/utmp - list of current login sessins
/var/log/wtmp - list of previous login sessions
/etc/passwd - user account information
/etc/shadow - encrypted passwords and age information
/etc/motd - system message file
/etc/login.defs - configuration file
SEE ALSO
init(8), getty(8), mail(1), passwd(1), passwd(5), environ(7), shutdown(8), login.defs(5)
BUGS
A recursive login, as used to be possible in the good old days, no longer works; for most purposes su(1) is a satisfactory substitute.
Indeed, for security reasons, login does a vhangup() system call to remove any possible listening processes on the tty. This is to avoid
password sniffing. If one uses the command "login", then the surrounding shell gets killed by vhangup() because it's no longer the true
owner of the tty. This can be avoided by using "exec login" in a top-level shell or xterm.
AUTHOR
Derived from BSD login 5.40 (5/9/89) by Michael Glad (glad@daimi.dk) for HP-UX
Ported to Linux 0.12: Peter Orbaek (poe@daimi.aau.dk)
Added new features: Thorsten Kukuk (kukuk@suse.de)
PAM Login 3.32 2. May 2007 LOGIN(1)