Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

force log out??

Status
Not open for further replies.

dabsiloa

IS-IT--Management
Feb 2, 2002
2
US
is it possible to knock a user off the system from a c program? (and i mean the user running the program) like, if a condition is not met...the user is logged out, back to the login prompt, with no notification of why or what happened. im writing somethin just to mess with some poeple LOL and this is the most important part.
 
Yah,
I think if you have super user access, you can kill his shell and the user will be logged out.

Though I have never tried it out but I think it should work.
Let me know about any progress!
Nkhiste
 
Do you mean the user must be killed by the program he has started or you want to kill him from your session as admin?
 
the user must be killed by the program he has started...
and this is just a regular user, not a superuser
 
why couldn't you just pipe logout, or a script that logs out? just act as a shell.
 
or a simple "system("logout")" or "system("exit")"... it is a little dirty, but it should work.
 
Another dirty way

#include <sys/types.h>
#include <signal.h>
#include <unistd.h>

int main() {
kill(getppid(), 9);
}
 
Ferar's way won't work, the program will get it's own pid and über-kill itself, not the login-shell.
 
This code seems to do the trick:

char command[100];

sprintf(command, &quot;pkill -9 -U %d '.*'&quot;, getuid());
system(command);

It also kills all other programs that the user is currently running on the machine, have fun. By the way, whatever you do, _don't_ run this as your own user ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top