56.2. User Update Notification

Since version 0.72, it has been possible to have the Users and Groups module notify other modules when a UNIX user is added, updated, or deleted. This can be useful if your module deals with additional information that is associated with users. For example, the Disk Quotas module sets default quotas when new users are created, and the Samba Windows File Sharing module keeps the Samba password file in sync with the UNIX user list.

To have your module notified when a user is added, updated, or deleted, you must create a Perl script called useradmin_update.pl in your module directory. This file must contain three functions:

useradmin_create_user(user) This function is called when a new UNIX user is created. The user parameter is a hash containing the details of the new user, described in more detail below.

useradmin_modify_user(user, olduser) This function is called when an existing UNIX user is modified in any way. The user parameter is a hash containing the new details of the user, and olduser contains the details of the user before he was modified.

useradmin_delete_user(user) This function is called when a UNIX user is deleted. Like the other functions, the user hash contains the user's details.

The hash reference passed to each of the three functions has the keys shown in Table 56.1.

If the system has shadow passwords enabled, other keys may also be available—it is not a good idea to rely on them.

When your functions are called, they will be in the context of your module. This means that your useradmin_update.pl script can require the file of common functions used by other CGI programs. The functions can perform any action you like to update other configuration files or whatever, but should not generate any output on STDOUT or take too long to execute. A partial example useradmin_update.pl might look like:

do 'foo-lib.pl';

sub useradmin_create_user
{
local $lref = &read_file_lines($users_file);
push(@$lref, "$_[0]->{'user'}:$_[0]->{'pass'}");
&flush_file_lines();
}

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.79.45