LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-05-2002, 01:42 AM   #1
acromi
LQ Newbie
 
Registered: Feb 2002
Location: tx =/
Distribution: Slackware, SuSE
Posts: 14

Rep: Reputation: 0
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?
 
Old 02-05-2002, 02:06 AM   #2
isajera
Senior Member
 
Registered: Jun 2001
Posts: 1,635

Rep: Reputation: 45
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.
 
Old 02-05-2002, 02:43 AM   #3
acromi
LQ Newbie
 
Registered: Feb 2002
Location: tx =/
Distribution: Slackware, SuSE
Posts: 14

Original Poster
Rep: Reputation: 0
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
 
Old 02-05-2002, 02:56 AM   #4
isajera
Senior Member
 
Registered: Jun 2001
Posts: 1,635

Rep: Reputation: 45
Quote:
Originally posted by acromi
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
lol - you don't know how true that is. this is gonna bug me for days.

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.
 
Old 02-05-2002, 03:00 AM   #5
isajera
Senior Member
 
Registered: Jun 2001
Posts: 1,635

Rep: Reputation: 45
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 )
 
Old 02-05-2002, 03:04 AM   #6
acromi
LQ Newbie
 
Registered: Feb 2002
Location: tx =/
Distribution: Slackware, SuSE
Posts: 14

Original Poster
Rep: Reputation: 0
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
 
Old 02-05-2002, 11:16 AM   #7
micke.prag
LQ Newbie
 
Registered: Jan 2002
Posts: 9

Rep: Reputation: 0
Instead of checking the source of su. Wouldn´t it be better to check the source for logout?
 
Old 02-05-2002, 03:50 PM   #8
isajera
Senior Member
 
Registered: Jun 2001
Posts: 1,635

Rep: Reputation: 45
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.
 
Old 02-05-2002, 11:40 PM   #9
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
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>
#include <signal.h>
#include <sys/types.h>
#include <unistd.h>

main()
{
   pid_t iParentPid = 0;

   iParentPid = getppid();
   kill( ParentPid, SIGHUP );
}
 
Old 02-06-2002, 12:34 AM   #10
isajera
Senior Member
 
Registered: Jun 2001
Posts: 1,635

Rep: Reputation: 45
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.
 
Old 02-06-2002, 12:49 AM   #11
acromi
LQ Newbie
 
Registered: Feb 2002
Location: tx =/
Distribution: Slackware, SuSE
Posts: 14

Original Poster
Rep: Reputation: 0
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
 
Old 02-06-2002, 12:54 AM   #12
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
I want to start a prog from another prog but not as child grupoapunte Programming 5 05-23-2005 06:37 PM
Firefox logs user out? Where are error logs? case1984 Linux - General 0 10-09-2004 03:22 PM
Tracing which user logs onto which PC kenji1903 Linux - Networking 13 09-13-2004 11:04 AM
Program runs when a user logs in mindstormsguy Linux - Software 2 03-31-2004 06:01 PM
tracking user,when logs in godwin_73 Linux - Networking 1 03-06-2002 06:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration