/usr/share/perl5/EBox/Samba/Model/SambaShares.pm is in zentyal-samba 2.3.12+quantal1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 | # Copyright (C) 2008-2012 eBox Technologies S.L.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# Class: EBox::Samba::Model::SambaShares
#
# This model is used to configure shares different to those which are
# given by the group share
#
package EBox::Samba::Model::SambaShares;
use base 'EBox::Model::DataTable';
use strict;
use warnings;
use Cwd 'abs_path';
use String::ShellQuote;
use EBox::Gettext;
use EBox::Global;
use EBox::Types::Text;
use EBox::Types::Union;
use EBox::Types::Boolean;
use EBox::Model::Manager;
use EBox::Exceptions::DataInUse;
use EBox::Sudo;
use Error qw(:try);
use constant DEFAULT_MASK => '0700';
use constant DEFAULT_USER => 'root';
use constant DEFAULT_GROUP => 'root';
use constant GUEST_DEFAULT_MASK => '0777';
use constant GUEST_DEFAULT_USER => 'nobody';
use constant GUEST_DEFAULT_GROUP => 'nogroup';
use constant FILTER_PATH => ('/bin', '/boot', '/dev', '/etc', '/lib', '/root',
'/proc', '/run', '/sbin', '/sys', '/var', '/usr');
# Dependencies
# Group: Public methods
# Constructor: new
#
# Create the new Samba shares table
#
# Overrides:
#
# <EBox::Model::DataTable::new>
#
# Returns:
#
# <EBox::Samba::Model::SambaShares> - the newly created object
# instance
#
sub new
{
my ($class, %opts) = @_;
my $self = $class->SUPER::new(%opts);
bless ($self, $class);
return $self;
}
# Group: Protected methods
# Method: _table
#
# Overrides:
#
# <EBox::Model::DataTable::_table>
#
sub _table
{
my ($self) = @_;
my @tableDesc = (
new EBox::Types::Text(
fieldName => 'share',
printableName => __('Share name'),
editable => 1,
unique => 1,
),
new EBox::Types::Union(
fieldName => 'path',
printableName => __('Share path'),
subtypes =>
[
new EBox::Types::Text(
fieldName => 'zentyal',
printableName =>
__('Directory under Zentyal'),
editable => 1,
unique => 1,
),
new EBox::Types::Text(
fieldName => 'system',
printableName => __('File system path'),
editable => 1,
unique => 1,
),
],
help => _pathHelp($self->parentModule()->SHARES_DIR())),
new EBox::Types::Text(
fieldName => 'comment',
printableName => __('Comment'),
editable => 1,
),
new EBox::Types::Boolean(
fieldName => 'guest',
printableName => __('Guest access'),
editable => 1,
defaultValue => 0,
help => __('This share will not require authentication.'),
),
new EBox::Types::HasMany(
fieldName => 'access',
printableName => __('Access control'),
foreignModel => 'SambaSharePermissions',
view => '/Samba/View/SambaSharePermissions'
),
# This hidden field is filled with the group name when the share is configured as
# a group share through the group addon
new EBox::Types::Text(
fieldName => 'groupShare',
hidden => 1,
optional => 1,
),
);
my $dataTable = {
tableName => 'SambaShares',
printableTableName => __('Shares'),
modelDomain => 'Samba',
defaultActions => [ 'add', 'del',
'editField', 'changeView' ],
tableDescription => \@tableDesc,
menuNamespace => 'Samba/View/SambaShares',
class => 'dataTable',
help => _sharesHelp(),
printableRowName => __('share'),
enableProperty => 1,
defaultEnabledValue => 1,
orderedBy => 'share',
};
return $dataTable;
}
# Method: validateTypedRow
#
# Override <EBox::Model::DataTable::validateTypedRow> method
#
# Check if the share path is allowed or not
sub validateTypedRow
{
my ($self, $action, $parms) = @_;
return unless ($action eq 'add' or $action eq 'update');
if (exists $parms->{'path'}) {
my $path = $parms->{'path'}->selectedType();
if ($path eq 'system') {
# Check if it is an allowed system path
my $normalized = abs_path($parms->{'path'}->value());
foreach my $filterPath (FILTER_PATH) {
if ($normalized =~ /^$filterPath/) {
throw EBox::Exceptions::External(
__x('Path not allowed. It cannot be under {dir}',
dir => $normalized
)
);
}
}
EBox::Validate::checkAbsoluteFilePath($parms->{'path'}->value(),
__('Samba share absolute path')
);
} else {
# Check if it is a valid directory
my $dir = $parms->{'path'}->value();
EBox::Validate::checkFilePath($dir,
__('Samba share directory'));
}
}
}
# Method: removeRow
#
# Override <EBox::Model::DataTable::removeRow> method
#
# Overriden to warn the user if the directory is not empty
#
sub removeRow
{
my ($self, $id, $force) = @_;
my $row = $self->row($id);
if ($force or $row->elementByName('path')->selectedType() eq 'system') {
return $self->SUPER::removeRow($id, $force);
}
my $path = $self->parentModule()->SHARES_DIR() . '/' .
$row->valueByName('path');
unless ( -d $path) {
return $self->SUPER::removeRow($id, $force);
}
opendir (my $dir, $path);
while(my $entry = readdir ($dir)) {
next if($entry =~ /^\.\.?$/);
closedir ($dir);
throw EBox::Exceptions::DataInUse(
__('The directory is not empty. Are you sure you want to remove it?'));
}
closedir($dir);
return $self->SUPER::removeRow($id, $force);
}
# Method: deletedRowNotify
#
# Override <EBox::Model::DataTable::validateRow> method
#
# Write down shares directories to be removed when saving changes
#
sub deletedRowNotify
{
my ($self, $row) = @_;
my $path = $row->elementByName('path');
# We are only interested in shares created under /home/samba/shares
return unless ($path->selectedType() eq 'zentyal');
my $mgr = EBox::Model::Manager->instance();
my $deletedModel = $mgr->model('SambaDeletedShares');
$deletedModel->addRow('path' => $path->value());
}
# Method: createDirs
#
# This method is used to create the necessary directories for those
# shares which must live under /home/samba/shares
# We must set here both POSIX ACLs and navite NT ACLs. If we only set
# POSIX ACLs, a user can change the permissions in the security tab
# of the share. To avoid it we set also navive NT ACLs and set the
# owner of the share to 'Domain Admins'.
#
sub createDirs
{
my ($self) = @_;
my $sambaModule = $self->parentModule();
my $ldb = $sambaModule->ldb();
my $domainSid = $ldb->domainSID();
my $domainAdminsSid = $domainSid . '-512';
my $domainUsersSid = $domainSid . '-513';
for my $id (@{$self->ids()}) {
my $row = $self->row($id);
my $pathType = $row->elementByName('path');
my $guestAccess = $row->valueByName('guest');
next unless ( $pathType->selectedType() eq 'zentyal');
my $path = $self->parentModule()->SHARES_DIR() . '/' . $pathType->value();
my @cmds = ();
push (@cmds, "mkdir -p '$path'");
if ($guestAccess) {
push (@cmds, 'chmod ' . GUEST_DEFAULT_MASK . " '$path'");
push (@cmds, 'chown ' . GUEST_DEFAULT_USER . ':' . GUEST_DEFAULT_GROUP . " '$path'");
} else {
push (@cmds, 'chmod ' . DEFAULT_MASK . " '$path'");
push (@cmds, 'chown ' . DEFAULT_USER . ':' . DEFAULT_GROUP . " '$path'");
}
push (@cmds, "setfacl -b $path"); # Clear POSIX ACLs
EBox::Sudo::root(@cmds);
if ($guestAccess) {
my $ntACL = '';
$ntACL .= "O:$domainAdminsSid"; # Object's owner
$ntACL .= "G:$domainUsersSid"; # Object's primary group
my $aceString = '(A;OICI;0x001301BF;;;S-1-1-0)';
$ntACL .= "D:$aceString";
my $cmd = EBox::Samba::SAMBATOOL() . " ntacl set '$ntACL' '$path'";
try {
EBox::Sudo::root($cmd);
} otherwise {
my $error = shift;
EBox::error("Coundn't enable NT ACLs for $path: $error");
};
next;
}
# Build the security descriptor string
my $ntACL = '';
$ntACL .= "O:$domainAdminsSid"; # Object's owner
$ntACL .= "G:$domainUsersSid"; # Object's primary group
# Build the ACS strings
my @aceStrings = ();
push (@aceStrings, '(A;;0x001f01ff;;;SY)'); # SYSTEM account has full access
push (@aceStrings, "(A;;0x001f01ff;;;$domainAdminsSid)"); # Domain admins have full access
# Posix ACL
my @posixACL;
push (@posixACL, 'u:root:rwx');
push (@posixACL, 'g::---');
push (@posixACL, 'g:' . DEFAULT_GROUP . ':---');
for my $subId (@{$row->subModel('access')->ids()}) {
my $subRow = $row->subModel('access')->row($subId);
my $permissions = $subRow->elementByName('permissions');
my $userType = $subRow->elementByName('user_group');
my $perm;
if ($userType->selectedType() eq 'group') {
$perm = 'g:';
} elsif ($userType->selectedType() eq 'user') {
$perm = 'u:';
}
my $account = $userType->printableValue();
my $qobject = shell_quote($account);
$perm .= $qobject . ':';
my $aceString = '(A;OICI;';
if ($permissions->value() eq 'readOnly') {
$aceString .= '0x001200A9;';
$perm .= 'rx';
} elsif ($permissions->value() eq 'readWrite') {
$aceString .= '0x001301BF;';
$perm .= 'rwx';
} elsif ($permissions->value() eq 'administrator') {
$aceString .= '0x001F01FF;';
$perm .= 'rwx';
} else {
my $type = $permissions->value();
EBox::error("Unknown share permission type '$type'");
next;
}
push (@posixACL, $perm);
# Account Sid
my $object = new EBox::Samba::LdbObject(samAccountName => $account);
if ($object->exists()) {
$aceString .= ';;' . $object->sid() . ')';
push (@aceStrings, $aceString);
}
}
if (@posixACL) {
try {
my $cmd = 'setfacl -R -m ' . join(',', @posixACL) . " $path";
my $defaultCmd = 'setfacl -R -m d:' . join(',d:', @posixACL) ." $path";
EBox::Sudo::root($cmd);
EBox::Sudo::root($defaultCmd);
} otherwise {
my $error = shift;
EBox::debug("Couldn't enable POSIX ACLs for $path: $error")
};
}
if (@aceStrings) {
try {
my $fullAce = join ('', @aceStrings);
$ntACL .= "D:$fullAce";
my $cmd = EBox::Samba::SAMBATOOL() . " ntacl set '$ntACL' '$path'";
EBox::Sudo::root($cmd);
} otherwise {
my $error = shift;
EBox::error("Coundn't enable NT ACLs for $path: $error");
};
}
}
}
# Private methods
sub _pathHelp
{
my ($sharesPath) = @_;
return __x( '{openit}Directory under Zentyal{closeit} will ' .
'automatically create the share.' .
"directory in {sharesPath} {br}" .
'{openit}File system path{closeit} will allow you to share '.
'an existing directory within your file system',
sharesPath => $sharesPath,
openit => '<i>',
closeit => '</i>',
br => '<br>');
}
sub _sharesHelp
{
return __('Here you can create shares with more fine-grained permission ' .
'control. ' .
'You can use an existing directory or pick a name and let Zentyal ' .
'create it for you.');
}
# Method: headTile
#
# Overrides <EBox::Model::DataTable::headTitle>
#
#
sub headTitle
{
return undef;
}
1;
|