c prog that logs user off...
ok, heres what i want i need....well want, hehe...
in a c program, its a simple menu, i need to log the user running the program off...back to the login prompt. this is not a super user, just a normal account. i know i could just set the program to be the users login shell..but i'd rather do it this way. im not sure if this is possible. and i know it may not be that secure. but is there a way to do this? if its not possible from within a c prog, what about from a shell script? any one? :( |
well... i'm sure it's possible. compiling against the kernel headers might be one way to go (and you'd be totally on your own there :)), but running "exit" or "logout" using an exec variant would probably be the easiest way to go outside of a shell script. i'm not sure the shell script would even work.
|
yeah, ive tried using exit..but i couldnt get it to work. maybe (dont hate me =) you could give me an example. pretty please...
you know you cant resist :D |
Quote:
anyway, i tried writing a quick shell script, and all that happened was that it exited from itself. nothing exciting. offhand, if you want to write this prog, then you're going to need to learn more about the login process than i currently know. all i know is something vague about gettys and virtual consoles. i was wondering if it might be that a user-space prog can't access that particular function... it might be a security risk somehow. ummm... try checking out the source to "su" - that seems like it might have something useful or similar. |
or... (this just occured to me) you could just kill your user's main process and see what happens. i think that would work. (haven't tried it :))
|
heh...sorry i got you interested =)
im faily new to programming in a unix environment. i've been running a linux box for about a year i guess now, and im just trying to think of ways to get more familiar with how it ticks...and this is one of those ways... let me know if you find anything, or if you get bored looking. in the meantime i will keep lookin for a solution (after i sleep a little) thx alot |
Instead of checking the source of su. Wouldn´t it be better to check the source for logout?
|
logout isn't a program - it's a function in a shell program to terminate the shell. afaik, the login just activates a shell program, like bash, csh, tsh, ect, which then goes on to do all the other stuff, like X - after the original shell dies, the login terminates. so, we're looking for a way to kill the first shell after login. you can't call logout because it's a function inside the shell, and you don't have access to it if you're operating outside of it, as we hypotheticially are.
|
If you start the program from your login shell, this program will kill it. It gets the pid of its parent and calls kill on that pid.
Code:
#include <stdio.h> |
that would only work from the first shell - it wouldn't work inside X. what would work is to grep the output of 'ps -f' to get the shell program belonging to your user that has the lowest pid - that would be the first shell called after login, send it the SIGHUP.
|
i pretty much wanted this to work from the console. so that will work. but now that intrigues me to get it to work in X :)
thanks for the help guys |
I thought about a popen( "ps" ) type of deal, but you would really have to kill all the users processes. There is no guarantee that the lowest pid is the login shell especially on a busy system.
|
All times are GMT -5. The time now is 09:22 PM. |