NAME
Plugtools - LDAP and Posix
VERSION
Version 0.1.0
SYNOPSIS
use Plugtools;
my $pt = Plugtools->new();
...
METHODS
new
addGroup
args hash
group
This is the group name to add.
gid
This is the numeric ID of the group to add. If it is not defined, it will automatically be added.
dump
If this is true, call the dump method on the create Net::LDAP::Entry object.
#the most basic form
$pt->addGroup({
group=>'someGroup',
})
if($pt->{errpr}){
print "Error!\n";
}
#do more
$pt->addGroup({
group=>'someGroup',
gid=>'4444',
dump=>'1',
})
if($pt->{errpr}){
print "Error!\n";
}
addUser
args hash
user
The user to create.
uid
The numeric user ID for the new user. If this is note defined, the first free one will be used.
group
The primary group of user. If this is not defined, the username is used. If the user is this is not defined, it will be set to the same as the user.
gid
If this is defined, the specified GID will be used instead of automatically assigning one.
gecos
The gecos field for the user. If this is not defined, it is set to the user name.
shell
This is the shell for the user. If this is not defined, the default one is used.
home
This is the home directory for the user. If this is not defined, the home prototype is used.
createHome
If this is specified, the default value for createHome will be overrode the defaults or what is specified in the config.
If it exists, it assumes it does not need to be created, but it will still be chowned.
skel
Use this instead of the default skeleton or the one specified in the config file.
This is skipped, if the home already exists.
chmodValue
Overrides the default value for this or the one specified in the config.
chmodHome
Overrides the default value for this or the one specified in the config.
chownHome
If home should be chowned. This overrides the value specified in the config or the default one.
dump
If this is true, call the dump method on the create Net::LDAP::Entry object.
#the most basic form
$pt->addUser({
user=>'someUser',
})
if($pt->{errpr}){
print "Error!\n";
}
#do more
$pt->addUser({
user=>'someUser',
uid=>'3333',
group=>'someGroup',
gid=>'4444',
dump=>'1',
})
if($pt->{errpr}){
print "Error!\n";
}
connect
This forms a LDAP connection using the information in config file.
my $ldap=$pt->connect;
if($pt->{error}){
print "Error!\n";
}
deleteGroup
This removes a group.
$pt->deleteGroup('someGroup');
if($pt->{error}){
print "Error!\n";
}
deleteUser
This removes a user.
Only LDAP is touched at this time, so if a user is a member of a group setup in '/etc/groups', then it won't be removed from that group.
This does not remove the user's old home directory.
arge hash
'user' is the only required value.
user
This is the user to be removed.
removeHome
This removes the home directory of the user.
removeGroup
Remove the primary group if it is empty.
#the most basic form
$pt->deleteUser({
user=>'someUser',
})
if($pt->{errpr}){
print "Error!\n";
}
#do more
$pt->deleteUser({
user=>'someUser',
removeHome=>'1',
removeGroup=>'0',
})
if($pt->{errpr}){
print "Error!\n";
}
findGroupDN
This locates a DN for a already setup group.
my $dn=$pt->findGroupDN('someGroup');
if($pt->{error}){
print "Error!";
}
findUserDN
This locates a DN for a already setup group.
my $dn=$pt->findUserDN('someUser');
if($pt->{error}){
print "Error!";
}
groupAddUser
This adds a user from a group.
args hash
group
The group to act on.
user
The user to act remove from the group.
dump
Call the dump method on the entry afterwards.
$pt->groupAddUser({
group=>'someGroup',
user=>'someUser',
})
if($pt->{errpr}){
print "Error!\n";
}
groupGIDchange
This changes the GID for a group.
args hash
group
The group to act on.
gid
The GID to change this group to.
userUpdate
Update any user that has the old GID as their primary GID. This defaults to true, '1'.
dump
Call the dump method on the group afterwards.
$pt->groupGIDchange({
group=>'someGroup',
gid=>'2222',
})
if($pt->{errpr}){
print "Error!\n";
}
groupRemoveUser
This removes a user from a group.
args hash
group
The group to act on.
user
The user to act remove from the group.
dump
Call the dump method on the group afterwards.
$pt->groupRemoveUser({
group=>'someGroup',
user=>'someUser',
})
if($pt->{errpr}){
print "Error!\n";
}
groupClean
This checks through the groups setup in LDAP and removes any group that does not exist.
args hash
dump
If this is specified, the dump method is called on any updated entry. If this is not defined, it defaults to false.
$pt->groupClean;
if($pt->{error}){
print "Error!\n";
}
#do the same thing as above, but do $entry->dump for any changed entry
$pt->groupClean({dump=>'1'});
if($pt->{error}){
print "Error!\n";
}
isLDAPgroup
This tests if a group is in LDAP or not.
my $returned=$pt->isLDAPgroup('someGroup');
if($pt->{error}){
print "Error!\n";
}else{
if($returned){
print "Yes!\n";
}else{
print "No!\n";
}
}
isLDAPuser
This tests if a group is in LDAP or not.
my $returned=$pt->isLDAPuser('someUser');
if($pt->{error}){
print "Error!\n";
}else{
if($returned){
print "Yes!\n";
}else{
print "No!\n";
}
}
onlyMember
This figures out if a user is the only member of a group.
This returns true if the user is the only member of that group. A value of false means that user is not in that group and there are no members or that it that there are other members.
args hash
Both 'user' and 'group' are required.
user
This is the user it is checking to see if it is the only member of a group.
group
This is the group to check.
my $returned=$pt->onlyMember({
user=>'someUser',
group=>'someGroup',
});
if($pt->{error}){
print "Error!\n";
}
removeUserFromGroups
This removes a user from any group in LDAP they are a member of.
No checks are made to see if the user exists or not.
$pt->removeUserFromGroups('someUser');
if($pt->{error}){
print "Error!\n";
}
readConfig
This reads the specified config.
#reads the default config
$pt->readConfig();
if($pt->{error}){
print "Error!";
}
#reads the config '/some/config'
$pt->readConfig('/some/config');
if($pt->{error}){
print "Error!";
}
userGECOSchange
This changes the UID for a user.
args hash
user
The user to act on.
gecos
The GECOS to change this user to.
dump
Call the dump method on the group afterwards.
$pt->userGECOSchange({
user=>'someUser',
gecos=>'whatever',
});
if($pt->{error}){
print "Error!\n";
}
userSetPass
This changes the password for a user.
args hash
user
This is the user to act on.
pass
This is the new password to set.
$pt->userSetPass({
user=>'someUser',
pass=>'whatever',
});
if($pt->{error}){
print "Error!\n";
}
userGIDchange
This changes the UID for a user.
args hash
user
The user to act on.
gid
The GID to change this user to. This GID must already exist.
dump
Call the dump method on the group afterwards.
$pt->userGIDchange({
user=>'someUser',
gid=>'1234',
});
if($pt->{error}){
print "Error!\n";
}
userUIDchange
This changes the UID for a user.
args hash
user
The user to act on.
uid
The UID to change this user to.
dump
Call the dump method on the group afterwards.
$pt->userUIDchange({
user=>'someUser',
uid=>'1234',
});
if($pt->{error}){
print "Error!\n";
}
errorblank
This is a internal function and should not be called.
ERROR CODES
1
Could not read config.
2
Missing required variable.
3
Can't find a free UID.
4
Can't find a free GID.
5
No user name specified.
6
No group name specified.
7
UID is not numeric.
8
GID is not numeric.
9
User already exists.
10
Group already exists.
11
Connecting to LDAP failed.
12
Net::LDAP::posixGroup failed.
13
Failed to bind to the LDAP server.
14
The group does not exist.
15
The group does not exist in LDAP or under specified group base.
16
Failed to delete the group's entry.
17
The user does not exist.
18
The user does not exist in LDAP or under specified user base.
19
Adding the new entry failed.
20
The GID already exists.
21
Failed to create home.
22
Copying the skeleton to the home location failed.
23
Failed to chown the new home directory.
24
Failed to chmod the new home directory.
25
Failed to update a entry when removing a memberUid.
26
Failed to remove the users home directory.
27
Faild to fetch a list posixGroup objects.
28
No GID specified.
29
Failed to update the entry when changing the GID.
30
No UID specified.
31
Failed to update the entry when changing the UID.
32
Failed to fetch the user entry.
33
No GECOS specified.
34
Failed to update the entry when changing the GECOS.
35
No password specified.
36
Updating the password for the user failed.
37
Errored when fetching a list of users that may possibly need updated.
CONFIG FILE
The default is xdg_config_home().'/plugtoolsrc', which wraps around to "~/.config/plugtoolsrc".
bind
This is the DN to bind as.
pass
This is the password for the bind DN.
userbase
This is the base for where the users are located.
groupbase
This is the base where the groups are located.
server
This is the LDAP server to connect to. If the server is not specified, '127.0.0.1' is used.
port
This is the LDAP port to use. If the port is not specified, '389' is used.
UIDstart
This is the first UID to start checking for existing users at. The default is '1001'.
GIDstart
This is the first GID to start checking for existing groups at. The default is '1001'.
defaultShell
This is the default shell for a user. The default is '/bin/tcsh'.
HOMEproto
The prototype for the home directory. %%USERNAME%% is replaced with the username. The default is '/home/%%USERNAME%%/'.
skeletonHome
This is the location that will be copied for when creating a new home directory. If this is not defined, a blanked one will be created. The default is '/etc/skel'.
chmodValue
This is the numeric value the newly created home directory will be chmoded to. The default is '640'.
chmodHome
If home should be chmoded. The default value is '1', true.
chownHome
If home should be chowned. The default value is '1', true.
createHome
If this is true, it the home directory for the user will be created. The default is '1'.
groupPrimary
This is the attribute to use for when creating the DN for the group entry. Either 'cn' or 'gidNumber' are currently accepted. The default is 'cn'.
userPrimary
This is the attribute to use for when creating the DN for the user entry. Either 'cn', 'uid', or 'uidNumber' are currently accepted. The default is 'uid'.
starttls
Wether or not it should try to do start_tls.
TLSverify
The verify mode for TLS. The default is 'none'.
none
The server may provide a certificate but it will not be checked - this may mean you are be connected to the wrong server.
optional
Verify only when the server offers a certificate.
require
The server must provide a certificate, and it must be valid.
SSLversion
This is the SSL versions accepted.
'sslv2', 'sslv3', 'sslv2/3', or 'tlsv1' are the possible values. The default is 'tlsv1'.
SSLciphers
This is a list of ciphers to accept. The string is in the standard OpenSSL format. The default value is 'ALL'.
removeGroup
This determines if it should try to remove the user's primary group after removing the user.
The default value is '1', true.
removeHome
This determines if it should try to remove a user's home directory when deleting the user.
The default value is '0', false.
userUpdate
This determines if it should update the primary GIDs for users after groupGIDchange has been called.
The default value is '1', true.
AUTHOR
Zane C. Bowers, <vvelox at vvelox.net>
BUGS
Please report any bugs or feature requests to bug-plugtools at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Plugtools. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Plugtools
You can also look for information at:
RT: CPAN's request tracker
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
COPYRIGHT & LICENSE
Copyright 2009 Zane C. Bowers, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.