Object Methods

new([config file])

Optionally a file can be specifided in the constructor to load the file on creation.

Returns a new Samba Object

version([version])

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 }

keys(section)

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');

value(section,key)

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');

listShares()

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;

deleteShare(share name)

Delete a given share, this method can't delete the global section

Params: the share to delete Returns: none Example: $smb->deleteShare('some share');

createShare(share name)

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

sectionParameter(section,key,[value])

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

globalParameter(key,[value])

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

load(filename)

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(filename)

Save the current inmemory smb.conf file

Params: the file to save to Returns: none Example: $smb->save('/home/test.conf');

NAME

File::Samba - Samba configuration Object

SYNOPSIS

use File::Samba;
my $smb = File::Samba->new("/etc/samba/smb.conf");
@list = $smb->listShares;
$smb->deleteShare('homes');
$smb->createShare('newShare');

DESCRIPTION

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.

EXPORT

The following methods may be imported version keys value listShares deleteShare createShare sectionParameter globalParameter load save

SEE ALSO

http://www.samba.org Samba homepage All the config keys were extracted from version 2 and 3 man pages

AUTHOR

Salvatore E. ScottoDiLuzio<lt>washu@olypmus.net<gt>

COPYRIGHT AND LICENSE

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.