views:

53

answers:

3

I am developing a background service which needs to run on Windows, Linux, Mac OS and Solaris. The service is very simple and is to be used to track students logging in and out of university computers. I have almost finished the Windows implementation of the service.

I have invested in a number of books around native application / service development for Linux and for Mac OS. I can learn the fundamentals from those but there is something more specific which I need which seems to be much too specific a topic to be covered by the books I have.

The question is about native events on Linux and Mac OS which a background service can register to respond to when a user logs in and out. I would also need to get the user id of the user who logged in or out (which should be more straightforward once the first item is solved).

Being new to native development for Linux and Mac OS I could really benefit from some help from more experience developers for these platforms. A friend suggested that PAM can be used to register to be notified of such events. Is this true?

I may not need to know the exact details of everything I have to do but it would be good to know what native events / mechanisms are available to achieve this (if any but I am hoping there are because Windows certainly has them).

Kind Regards

Carl

A: 

This is already tracked for unix/linux/mac. Look at the command line program "last"... man last.

regulus6633
I appreciate that operating systems have their own mechanisms for tracking this but what this service does is send notification packets to a central server which will store the details in a database. The intension is that a web front end will be that teaching staff can check whether students have been coming in and using labs. The system is intended to track that regardless of which domain is logged into or what operating system is used or even if the login is just to the local machine (assuming the network is still working).
Carl Jokl
The idea was that the hard part is done already. You'd just need a cron job and script to check "last" for new info and forward it to the central database if found. Other than that on the mac you'd probably have to look into NSWorkspace or IOReg Kit notifications.
regulus6633
The tricky aspect of looking at Linux and Mac/OS is that I have an approach which works on Windows but have been looking into Linux and Mac O/S without being sure it is fundamentally possible to create a service for these platforms which operates in a similar way. I am hoping it can be done but there are less clean and tidy ways to achieve similar functionality.
Carl Jokl
Sorry I have not been here in a while but I am juggling multiple projects and I am getting close to completing the Windows Service but have not started the other services yet. This project may have to take a back seat to a web application I am currently developing. I will likely still benefit from some help when I get back to this project again.
Carl Jokl
A: 

On recent Linux distros, you might look into ConsoleKit, but for older ones, and Unix in general, I don't know of any way to be notified in realtime, short of writing your own code to insert into the system, such as a PAM module on OS'es supporting PAM.

alanc
I am not sure if it helps but the primary version of Linux to be supported is Red Hat Enterprise Workstation 5.4 but I believe the University will be updating to 5.5 in the future.There are many different ways of approaching this problem. I chose to try and track login events on the client rather than the server thinking that this may get around jumping through lots of hoops if any students are logging into servers/domains outside of department control and having to get permission to install software on those servers. Also the service might be extended for other things maybe.
Carl Jokl
A: 

On Mac OS X, you can define LoginHook and LogoutHook scripts to run as part of the login/logout process; see Apple's documentation and Mike Bombich's notes and examples. Another possibility would be to create a LaunchAgent -- the main difference would be that a LaunchAgent will run as the user, inside their login session, while LoginHook and LogoutHook scripts run as root. Most of Apple's docs about this concentrate on LaunchDaemons, but LaunchAgents are very similar except that they run within user login sessions, while LaunchDaemons run as root (but independently of login sessions, making them unsuitable for what you want).

Gordon Davisson
That looks interesting I will look into this.
Carl Jokl