Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 4th, 2005, 6:59 AM   #1
thinkgeek
Newbie
 
Join Date: Jul 2005
Posts: 10
Rep Power: 0 thinkgeek is on a distinguished road
Question Trapping user logins on Linux in python

I am writting a daemon in python which should start at system start up with all inet.d services
on an NIS server. Then it should listen to any user login and then start a new process for that user on his login which will continue throughout his entire session.

Can anyone give any help or any suggestion or any useful links.

thinkgeek
thinkgeek is offline   Reply With Quote
Old Jul 4th, 2005, 6:19 PM   #2
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Well which part do you need help with? Just doing so in general? If so, that's quite a specialized thing you're trying to do... you're probably better off asking someone with a more extensive collection of information on these kind of things.
Cerulean is offline   Reply With Quote
Old Jul 4th, 2005, 11:01 PM   #3
thinkgeek
Newbie
 
Join Date: Jul 2005
Posts: 10
Rep Power: 0 thinkgeek is on a distinguished road
I want my daemon to start at system start up as other (start|stop|restart) services/daemons. It work is to listen to user logins. Whenever a user logins at the terminal(local or NIS client) it should get the username. It will start a new thread which will run throughout the session of that user. This should be done for any user who logs in. But I want my daemon to be smart enough to know immediately who is login into the system, so that it can respond accordingly.
thinkgeek is offline   Reply With Quote
Old Jul 5th, 2005, 1:52 PM   #4
Moldz
Programmer
 
Moldz's Avatar
 
Join Date: Feb 2005
Posts: 54
Rep Power: 4 Moldz is on a distinguished road
Quote:
Originally Posted by thinkgeek
I want my daemon to start at system start up as other (start|stop|restart) services/daemons.
What *nix are you using? FreeBSD is very different from RedHat which is different than Gentoo. They all involve creating some type of script.

Quote:
It work is to listen to user logins. Whenever a user logins at the terminal(local or NIS client) it should get the username.
I'm not sure how you would do that. You could make it work similar to the "who" program by simply rechecking the /var/run/utmp for new entries.
Moldz is offline   Reply With Quote
Old Jul 6th, 2005, 7:54 AM   #5
thinkgeek
Newbie
 
Join Date: Jul 2005
Posts: 10
Rep Power: 0 thinkgeek is on a distinguished road
More details...

1. I am using Redhat Enterprise Linux

2. Could you explain how to get username from /var/run/utmp.
It is in some different format which can't be understood.
thinkgeek is offline   Reply With Quote
Old Jul 6th, 2005, 8:51 AM   #6
Moldz
Programmer
 
Moldz's Avatar
 
Join Date: Feb 2005
Posts: 54
Rep Power: 4 Moldz is on a distinguished road
Ok then, check out /etc/init.d, it is full of scripts that start programs on boot. They are somewhat simple bash scripts, I would make a copy of one of them and change what you need. Then use the program /sbin/chkconfig to setup the script to run on boot

The utmp file is in a binary format. You can find out the exact structure by checking out the man page, "man utmp".
Moldz is offline   Reply With Quote
Old Jul 6th, 2005, 9:40 AM   #7
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Alternatively you can spawn a new who process every few seconds and read its output. That would be easier than parsing /var/run/utmp, but you'd get a performance hit for spawning a new process so often - i'd go with the file parsing option myself.
Cerulean is offline   Reply With Quote
Old Jul 6th, 2005, 10:37 PM   #8
thinkgeek
Newbie
 
Join Date: Jul 2005
Posts: 10
Rep Power: 0 thinkgeek is on a distinguished road
File parsing the /var/run/utmp

Quote:
Alternatively you can spawn a new who process every few seconds and read its output. That would be easier than parsing /var/run/utmp, but you'd get a performance hit for spawning a new process so often - i'd go with the file parsing option myself.
Could you explain how to parse the /var/run/utmp file. It is in binary format.
thinkgeek is offline   Reply With Quote
Old Jul 6th, 2005, 11:18 PM   #9
TheFalseDragon
Programmer
 
TheFalseDragon's Avatar
 
Join Date: Jun 2005
Location: |\|[][]B |_4|\|D
Posts: 41
Rep Power: 0 TheFalseDragon is on a distinguished road
couldn't you just have a program that when someone logs in autoruns telling this program that they have logged in? wouldn't that be much simpler....
TheFalseDragon is offline   Reply With Quote
Old Jul 7th, 2005, 4:58 AM   #10
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Quote:
couldn't you just have a program that when someone logs in autoruns telling this program that they have logged in? wouldn't that be much simpler....
I'd assume not, as this daemon wants to log all logins, so i'd assume it needs root powers (e.g it will write to certain files or do certain things that require root access). Giving each user access to the data this daemon will work with would not strike me as safe.

Quote:
Could you explain how to parse the /var/run/utmp file. It is in binary format.
As was said, read through the manpage for utmp. It's perfectly documented there.
Cerulean is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:33 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC