Login program in C ??
HELLO sory if this Noob question. I want to create C program that is able to login into user and switch user on Linux using username and password input. Basically its a login GUI which ask for user input a string for username and password and then the program logins into the respective user. But i cant find any system calls for login, switching users or authentication. I tryed to study login.c, the source for the standard login command for GNU/Linux, but i still have no clue how it works. It seem to be even more complicated since the password is encrypted in shadow file for obvious security rasons.
One thing I think I can do is simply call the login program(which is called by getty on tty) which ask for username and pass word, using the system() function. But login command is an interactive prompt and you have to be in the shell to be able to input values for username and password. But in my case I want to be able to pass strings indirectly into the login program such as thru an input file. For example i have username and password strings and redirect that into the login program instead of answering the prompt interactively. Dunno if piping will works for login bcs it doesnt seem to be able to read from stdin. What is best approach to acomplish this in a C program ?? Is it even Posible? THANK YOU DISTRIBUTION: Debian 10(console) Language: C, Bash |
Maybe you could examine the source of programs 'login', 'passwd', 'su', 'xdm'.
|
this is how login process works: https://www.linuxnix.com/how-login-p...work-in-linux/
using GUI it is a bit different, but as you can see it is much more than a single app (like login). If you want to remote login to another computer - using ssh - you can configure it to read credentials from file, do not need to reinvent it. |
It's a non-trivial task. If you really want to investigate this rather than just using something like su, sudo, or gksu, then start reading here:
https://man7.org/linux/man-pages/man...entials.7.html http://www.linux-pam.org/Linux-PAM-h...x-PAM_ADG.html |
Not clear if you're asking for CLI or GUI solution, but in the latter case the login screen is sometimes referred to as a "greeter".
The LightDM Wikipedia page lists a bunch and includes links to their repositories, so you can examine how they work, maybe even customize an existing one to your own preferences. |
Tahnks you guys these are some graet resources. But i realise I am probly am too N00b for attempting this kind of thing, I tryed studying the source for LightDM, GDM greeters and login,su, but I am stumped . So From what i gather so far, you can login or switch user by changing USER environment variables, which is done thru PAM ?
On a more general note, dose anyone have tips on how to approach reading and understanding source code , for ejample where to start and how to break it down ? Especially tackling large source files with lot of included Libs ? THANk you |
Quote:
May have misunderstood your goal here...can you explain more clearly? Quote:
|
Quote:
To OP: what do you want to achieve at all? What is it all about? |
If you want to log in as a certain user and run certain commands, just use ssh.
If you want it a bit more automated, then use Ansible. Which just logs in and runs commands using ssh. If you want to do it a more old-fashioned way, use expect to automate ssh. Nobody does this. If you want to reinvent these wheels as an exercise: well, I’m currently reading Advanced Programming in the UNIX Environment, which goes into detail about how these things work. Pick up a copy. |
Quote:
heheh sorry guys i know this is abit vague. Basically in a broader sense wat I am creating is a basic custom login screen (GUI) using NCurses library. Kind of liek how on Microsoft Windows or any UNIX Login Managers they prompt user for login on startup. My progrem will run on system startup insted of the getty login process for the Debian console. So the UI will take key input, it will have a input for both Username and password that user can type in, and so these parameters will be stored to string or written to temp file. Problem is, what to do after with these Information ? I was thinking of ,instead of writing login system frum scratch, I use the existing user programs like login, su, sudo and call them thru Bash script. So basicly in the program, User inputs the username and password strings on a fancy GUI, and THEN i call the standard GNU/LINUX login program behind the scenes. But i dunno how to pass these credentials username and password (from the C program) to another login program. For example say i have user enter data on the login screen (GUI) -------------------------------- | Username: root | Password: abc123 | | [ Login ] -------------------------------- So then i store these two value into respective strings, such as char *uname, char *pwd. But thenI need somehow to pass these to login program. The login command is an interactive prompt, goes something liek this (on Debian): debian login: [ENTER USERNAME HERE] Password: [ENTER PASSWORD HERE] ** if password is incorrect ** Login incorrect But porblem is, this login program above is interactive, requires someone to be present at the shell and input username and value. But my program the user will not be directly using this login program/command. Is it posible to do something like this?:: debian login: [ char* uname ] Password: [ char* pwd ] ** if password is incorrect ** Login incorrect |
Quote:
Quote:
Quote:
|
TAHNK YOU man yes you right i should probs focus on laying the GUI down first . Later on I will look at some source for displey managers and try to see how they do the login user authentication stuff, copy some stuff here an there
|
Quote:
Here's one link: Using pseudo-terminals (pty) to control interactive programs |
All times are GMT -5. The time now is 10:16 PM. |