Optionally a file can be specifided in the constructor to load the file on creation.
Returns a new Samba Object
Set or get the version of this smb.conf your want to edit the load method tries to determine the smb.conf version based on the keys it find
Params: [Optional] the version number Returns: the current version (either 2 or 3) Example: if($obj->version == 3) { # do Samba 3 options }
Get a list of key for a given section, use 'global' for the globl section
Params: section to list Returns: a sorted list of section keys Example: my @keys = $smb->keys('some section');
Get the value associated with a key in a given section (READ ONLY)
Params: section to list key to read Returns: the value associated with the key/section combination or undef if the key/section does nto exists Example: my $value = $smb->keys('some section','some key');
Get a list of shares defined in the smb.conf file EXCLUDING the global section
Params: none Returns: a sorted list of section names Example: my @list = $smb->listShares;
Delete a given share, this method can't delete the global section
Params: the share to delete Returns: none Example: $smb->deleteShare('some share');
Create a share with a given name
Params: the share to create Returns: none Example: $smb->createShare('some share'); Exceptions: If you try to create a share called global, the method will croak
Get or set a key in a given section, if value is not sepecifed this methods performs a lookup, otherwise it performs an edit
Params: the section you wish to modify/view the key to view the value to set Returns: the value set or read Example: $smb->sectionParameter('homes','guest ok','yes'); Exceptions: The key you pass in for a 'Set' operrtion will be checked against a list of valid key names, based on the smb.conf version. Setting an invalid key will result if croak
Get or set a key in the global section, if value is not sepecifed this methods performs a lookup, otherwise it performs an edit
Params: the key to view the value to set Returns: the value set or read Example: $smb->globalParameter('homes','guest ok','yes'); Exceptions: The key you pass in for a 'Set' operrtion will be checked against a list of valid key names, based on the smb.conf version. Setting an invalid key will result if croak
Read a smb.conf file from disk, and parse it. The version will be identified as best as possible but may not be correct, you should use version method after calling load to make sure the version detected correctly
Params: the smb.conf file to load Returns: none Example: $smb->load('/etc/samba/smbconf'); Exceptions: If the file does not exist croak
Save the current inmemory smb.conf file
Params: the file to save to Returns: none Example: $smb->save('/home/test.conf');
File::Samba - Samba configuration Object
use File::Samba; my $smb = File::Samba->new("/etc/samba/smb.conf"); @list = $smb->listShares; $smb->deleteShare('homes'); $smb->createShare('newShare');
This module allows for easy editing of smb.conf in an OO way. The need arised from openfiler http://www.openfiler.org which at this current time setups a smb conf for you, however any changes you made by hand are lost when you make change due to the fact it doesnt havea way to edit an existing smb.conf but simply creates a new one. This modules allows for any program to be ables to extract the current config, make changes nd save the file. Comments are lost however on save.
The following methods may be imported version keys value listShares deleteShare createShare sectionParameter globalParameter load save
http://www.samba.org Samba homepage All the config keys were extracted from version 2 and 3 man pages
Salvatore E. ScottoDiLuzio<lt>washu@olypmus.net<gt>
Copyright (C) 2004 by Salvatore ScottoDiLuzio
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.3 or, at your option, any later version of Perl 5 you may have available.
To install File::Samba, copy and paste the appropriate command in to your terminal.
cpanm
cpanm File::Samba
CPAN shell
perl -MCPAN -e shell install File::Samba
For more information on module installation, please visit the detailed CPAN module installation guide.