This is LogoutHook.m in view mode; [Download] [Up]
/* Copyright 1993 Jeremy Slade. You are free to use all or any parts of the LogHook project however you wish, just give credit where credit is due. The author (Jeremy Slade) shall not be held responsible for any damages that result out of use or misuse of any part of this project. */ /* Project: LogHook File: LogoutHook.m Description: This is a simple program intended to be run as the LogoutHook of the loginWindow. When set up as such, this program will be executed immediately after the user logs out, before the loginWindow comes up again. The program will be rin with the same owner as the loginWindow, which is generally root. A single command line parameter is specified for this program, and that is the name of the user who is logging in. When LogoutHook is run, it sets the owner of the process to the user who is logging out, and then executes the logout hook command, which is defined by LogoutHook's Hook preference setting. This preference is "~/.LogoutHook" by default ("~" beging the home of the user logging out), but each user can specify their own by changing the setting in their own defaults database for the owner LogoutHook. Original Author: Jeremy Slade Revision History: Created V.101 JGS Tue May 11 21:56:09 PDT 1993 */ #import <defaults/defaults.h> #import <libc.h> #import <pwd.h> #import <stdio.h> #import <stdlib.h> #import <string.h> #import <sys/param.h> #import <sys/types.h> #define OPTIONS_OWNER "LogoutHook" #define OPT_HOOK "Hook" NXDefaultsVector Options = { { OPT_HOOK, ".LogoutHook" }, // Script to execute for Logout { NULL, NULL } }; void main ( int argc, char *argv[] ) { const char *hook; char hookPath[MAXPATHLEN+1]; char theCommand[3001]; struct passwd *pwd; // Set up the Defaults registration table NXRegisterDefaults ( OPTIONS_OWNER, Options ); NXUpdateDefaults (); // Get the name of the user who is logging in/out // (should be first command-line parameter) // Get the user's password information, set the user id // of this process to that user pwd = getpwnam ( argv[1] ); if ( !pwd ) { // Unable to get passwd info for this user exit ( 0 ); } setuid ( pwd->pw_uid ); // Change the Defaults user to the person logging in, so we can // find out what command they want to run as their hook... NXSetDefaultsUser ( argv[1] ); NXRegisterDefaults ( OPTIONS_OWNER, Options ); NXUpdateDefaults (); // read the OPT_HOOK to see what program we are supposed to run. // If it is a relatively-specified filename, make it into a full path hook = NXGetDefaultValue ( OPTIONS_OWNER, OPT_HOOK ); if ( !hook ) exit ( 0 ); else if ( hook[0] != '/' ) { sprintf ( hookPath, "%s/%s", pwd->pw_dir, hook ); hook = hookPath; } // Run the user's Logout hook script. Make sure when this is done // that it acts as if the user were logged in // The call to system() does the following: // 1. Change to the user's home directory // 2. Execute the Logout hook sprintf ( theCommand, "cd %s; %s", pwd->pw_dir, hook ); system ( theCommand ); exit ( 0 ); }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.