User and Group 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 perl functions :
- useradmin_create_user(user)
- This function is called when a new Unix user is created. The 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 first parameter is a hash containing the new details of the user,
and second 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 parameter is a hash containing the user's details.
| user | The login name of the new or modified user |
| uid | The Unix UID of the user |
| gid | The Unix GID for the user's primary group |
| pass | The user's password, encrypted with the crypt() function |
| plainpass | The user's password in plain text. This is only available when the passmode key is equal to 3 |
| passmode | This number depends on the choice made for the Password field
in the Create User or Edit User form.
|
| real | The user's real name |
| home | The user's home directory |
| shell | The user's login shell |
If the system has shadow passwords enabled, other keys may also be available - but 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 in order to update other config 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();
}
Webmin versions 1.090 and above have included a similar feature, but for Unix
groups instead of users. Your module's useradmin_update.pl script can
contain the following functions, which will be called when group changes are
made in the Users and Groups module :
- useradmin_create_group(group)
- This function is called when a new Unix group is created. The parameter
is a hash containing the details of the new group, described in more detail
below.
- useradmin_modify_group(group, oldgroup)
- This function is called when an existing Unix group is modified in any
way. The first parameter is a hash containing the new details of the group,
and second the details of the group before it was modified.
- useradmin_delete_group(group)
- This function is called when a Unix group is deleted. Like the other
functions, the parameter is a hash containing the group's details.
| group | The name of the new or modified group |
| gid | The Unix GID of the group |
| pass | The group's password, encrypted with the crypt() function, if any. |
| members | A comma-separate list of secondary members for this group |
