[SCM] Samba Shared Repository - branch master updated
Jelmer Vernooij
jelmer at samba.org
Sun Feb 26 21:26:04 MST 2012
The branch, master has been updated
via 47c62ee upgradehelpers: Simplify transaction handling.
via 8008228 samba.xattr: Massively simplify copytree_with_xattrs.
via 2c9ff8a upgradeprovision: Only backup sysvol directory if it exists.
via f40c9ac samba.xattr: Split copying of tree with extended attributes out into separate module.
from 8e947f0 s4:torture:smb2:durable-open: prevent using a disconnected handle in reopen4
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 47c62eeb68b95d0505936bf1e63b36f18ac1f2b2
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Mon Feb 27 03:50:37 2012 +0100
upgradehelpers: Simplify transaction handling.
Autobuild-User: Jelmer Vernooij <jelmer at samba.org>
Autobuild-Date: Mon Feb 27 05:25:04 CET 2012 on sn-devel-104
commit 8008228b940bd8c28a7ae8ee1c2568cb2127f1d1
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Mon Feb 27 02:46:31 2012 +0100
samba.xattr: Massively simplify copytree_with_xattrs.
commit 2c9ff8a4d7d9217d69a7c4abdd4b776d138f9951
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Mon Feb 27 00:53:19 2012 +0100
upgradeprovision: Only backup sysvol directory if it exists.
This is not the case for standalone installations.
Bug: https://bugs.launchpad.net/samba/+bug/930370
Bug: https://bugzilla.samba.org/show_bug.cgi?id=8781
commit f40c9ac7ac794c09dbeaa1bf1fdb0df980b74b63
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Mon Feb 27 00:50:00 2012 +0100
samba.xattr: Split copying of tree with extended attributes out into separate module.
-----------------------------------------------------------------------
Summary of changes:
source4/scripting/bin/upgradeprovision | 70 +--------------------
source4/scripting/python/samba/tests/xattr.py | 25 ++++++++-
source4/scripting/python/samba/upgradehelpers.py | 49 +++++----------
source4/scripting/python/samba/xattr.py | 64 ++++++++++++++++++++
4 files changed, 108 insertions(+), 100 deletions(-)
create mode 100644 source4/scripting/python/samba/xattr.py
Changeset truncated at 500 lines:
diff --git a/source4/scripting/bin/upgradeprovision b/source4/scripting/bin/upgradeprovision
index 2adb9a5..7003717 100755
--- a/source4/scripting/bin/upgradeprovision
+++ b/source4/scripting/bin/upgradeprovision
@@ -50,7 +50,7 @@ from samba.provision import (get_domain_descriptor, find_provision_key_parameter
ProvisioningError, get_last_provision_usn,
get_max_usn, update_provision_usn, setup_path)
from samba.schema import get_linked_attributes, Schema, get_schema_descriptor
-from samba.dcerpc import security, drsblobs, xattr
+from samba.dcerpc import security, drsblobs
from samba.ndr import ndr_unpack
from samba.upgradehelpers import (dn_sort, get_paths, newprovision,
get_ldbs,
@@ -63,6 +63,7 @@ from samba.upgradehelpers import (dn_sort, get_paths, newprovision,
search_constructed_attrs_stored,
int64range2str, update_dns_account_password,
increment_calculated_keyversion_number)
+from samba.xattr import copytree_with_xattrs
replace=2**FLAG_MOD_REPLACE
add=2**FLAG_MOD_ADD
@@ -1463,66 +1464,6 @@ def update_samdb(ref_samdb, samdb, names, provisionUSNs, schema, prereloadfunc):
return 0
-def copyxattrs(dir, refdir):
- """ Copy owner, groups, extended ACL and NT acls from
- a reference dir to a destination dir
-
- Both dir are supposed to hold the same files
- :param dir: Destination dir
- :param refdir: Reference directory"""
-
- noxattr = 0
- for root, dirs, files in os.walk(dir, topdown=True):
- for name in files:
- subdir=root[len(dir):]
- ref = os.path.join("%s%s" % (refdir, subdir), name)
- statsinfo = os.stat(ref)
- tgt = os.path.join(root, name)
- try:
-
- os.chown(tgt, statsinfo.st_uid, statsinfo.st_gid)
- # Get the xattr attributes if any
- try:
- attribute = samba.xattr_native.wrap_getxattr(ref,
- xattr.XATTR_NTACL_NAME)
- samba.xattr_native.wrap_setxattr(tgt,
- xattr.XATTR_NTACL_NAME,
- attribute)
- except Exception:
- noxattr = 1
- attribute = samba.xattr_native.wrap_getxattr(ref,
- "system.posix_acl_access")
- samba.xattr_native.wrap_setxattr(tgt,
- "system.posix_acl_access",
- attribute)
- except Exception:
- continue
- for name in dirs:
- subdir=root[len(dir):]
- ref = os.path.join("%s%s" % (refdir, subdir), name)
- statsinfo = os.stat(ref)
- tgt = os.path.join(root, name)
- try:
- os.chown(os.path.join(root, name), statsinfo.st_uid,
- statsinfo.st_gid)
- try:
- attribute = samba.xattr_native.wrap_getxattr(ref,
- xattr.XATTR_NTACL_NAME)
- samba.xattr_native.wrap_setxattr(tgt,
- xattr.XATTR_NTACL_NAME,
- attribute)
- except Exception:
- noxattr = 1
- attribute = samba.xattr_native.wrap_getxattr(ref,
- "system.posix_acl_access")
- samba.xattr_native.wrap_setxattr(tgt,
- "system.posix_acl_access",
- attribute)
-
- except Exception:
- continue
-
-
def backup_provision(paths, dir):
"""This function backup the provision files so that a rollback
is possible
@@ -1530,9 +1471,8 @@ def backup_provision(paths, dir):
:param paths: Paths to different objects
:param dir: Directory where to store the backup
"""
-
- shutil.copytree(paths.sysvol, os.path.join(dir, "sysvol"))
- copyxattrs(os.path.join(dir, "sysvol"), paths.sysvol)
+ if paths.sysvol:
+ copytree_with_xattrs(paths.sysvol, os.path.join(dir, "sysvol"))
shutil.copy2(paths.samdb, dir)
shutil.copy2(paths.secrets, dir)
shutil.copy2(paths.idmapdb, dir)
@@ -1555,8 +1495,6 @@ def backup_provision(paths, dir):
shutil.copytree(samldbdir, os.path.join(dir, "sam.ldb.d"))
-
-
def sync_calculated_attributes(samdb, names):
"""Synchronize attributes used for constructed ones, with the
old constructed that were stored in the database.
diff --git a/source4/scripting/python/samba/tests/xattr.py b/source4/scripting/python/samba/tests/xattr.py
index 7b4627f..1f32532 100644
--- a/source4/scripting/python/samba/tests/xattr.py
+++ b/source4/scripting/python/samba/tests/xattr.py
@@ -20,10 +20,16 @@
"""Tests for samba.xattr_native and samba.xattr_tdb."""
import samba.xattr_native, samba.xattr_tdb
+from samba.xattr import copytree_with_xattrs
from samba.dcerpc import xattr
from samba.ndr import ndr_pack
-from samba.tests import TestCase, TestSkipped
+from samba.tests import (
+ TestCase,
+ TestCaseInTempDir,
+ TestSkipped,
+ )
import random
+import shutil
import os
class XattrTests(TestCase):
@@ -103,3 +109,20 @@ class XattrTests(TestCase):
finally:
os.unlink(tempf)
os.unlink(eadb_path)
+
+
+class TestCopyTreeWithXattrs(TestCaseInTempDir):
+
+ def test_simple(self):
+ os.chdir(self.tempdir)
+ os.mkdir("a")
+ os.mkdir("a/b")
+ os.mkdir("a/b/c")
+ f = open('a/b/c/d', 'w')
+ try:
+ f.write("foo")
+ finally:
+ f.close()
+ copytree_with_xattrs("a", "b")
+ shutil.rmtree("a")
+ shutil.rmtree("b")
diff --git a/source4/scripting/python/samba/upgradehelpers.py b/source4/scripting/python/samba/upgradehelpers.py
index c6c9527..396e665 100755
--- a/source4/scripting/python/samba/upgradehelpers.py
+++ b/source4/scripting/python/samba/upgradehelpers.py
@@ -74,11 +74,12 @@ class ProvisionLDB(object):
self.hku = None
self.hklm = None
+ def dbs(self):
+ return (self.sam, self.secrets, self.idmap, self.privilege)
+
def startTransactions(self):
- self.sam.transaction_start()
- self.secrets.transaction_start()
- self.idmap.transaction_start()
- self.privilege.transaction_start()
+ for db in self.dbs():
+ db.transaction_start()
# TO BE DONE
# self.hkcr.transaction_start()
# self.hkcu.transaction_start()
@@ -87,26 +88,11 @@ class ProvisionLDB(object):
def groupedRollback(self):
ok = True
- try:
- self.sam.transaction_cancel()
- except Exception:
- ok = False
-
- try:
- self.secrets.transaction_cancel()
- except Exception:
- ok = False
-
- try:
- self.idmap.transaction_cancel()
- except Exception:
- ok = False
-
- try:
- self.privilege.transaction_cancel()
- except Exception:
- ok = False
-
+ for db in self.dbs():
+ try:
+ db.transaction_cancel()
+ except Exception:
+ ok = False
return ok
# TO BE DONE
# self.hkcr.transaction_cancel()
@@ -116,10 +102,8 @@ class ProvisionLDB(object):
def groupedCommit(self):
try:
- self.sam.transaction_prepare_commit()
- self.secrets.transaction_prepare_commit()
- self.idmap.transaction_prepare_commit()
- self.privilege.transaction_prepare_commit()
+ for db in self.dbs():
+ db.transaction_prepare_commit()
except Exception:
return self.groupedRollback()
# TO BE DONE
@@ -128,10 +112,8 @@ class ProvisionLDB(object):
# self.hku.transaction_prepare_commit()
# self.hklm.transaction_prepare_commit()
try:
- self.sam.transaction_commit()
- self.secrets.transaction_commit()
- self.idmap.transaction_commit()
- self.privilege.transaction_commit()
+ for db in self.dbs():
+ db.transaction_commit()
except Exception:
return self.groupedRollback()
@@ -142,6 +124,7 @@ class ProvisionLDB(object):
# self.hklm.transaction_commit()
return True
+
def get_ldbs(paths, creds, session, lp):
"""Return LDB object mapped on most important databases
@@ -534,7 +517,7 @@ def update_secrets(newsecrets_ldb, secrets_ldb, messagefunc):
res2 = secrets_ldb.search(expression="(samaccountname=dns)",
scope=SCOPE_SUBTREE, attrs=["dn"])
- if (len(res2) == 1):
+ if len(res2) == 1:
messagefunc(SIMPLE, "Remove old dns account")
secrets_ldb.delete(res2[0]["dn"])
diff --git a/source4/scripting/python/samba/xattr.py b/source4/scripting/python/samba/xattr.py
new file mode 100644
index 0000000..1c53ae8
--- /dev/null
+++ b/source4/scripting/python/samba/xattr.py
@@ -0,0 +1,64 @@
+#!/usr/bin/env python
+# vim: expandtab
+#
+# Utility code for dealing with POSIX extended attributes
+#
+# Copyright (C) Jelmer Vernooij <jelmer at samba.org> 2012
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# 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, see <http://www.gnu.org/licenses/>.
+
+from samba.dcerpc import xattr
+import os
+import samba.xattr_native
+import shutil
+
+
+def copyattrs(frompath, topath):
+ """Copy ACL related attributes from a path to another path."""
+ for attr_name in (xattr.XATTR_NTACL_NAME, "system.posix_acl_access"):
+ # Get the xattr attributes if any
+ try:
+ attribute = samba.xattr_native.wrap_getxattr(frompath,
+ xattr.XATTR_NTACL_NAME)
+ samba.xattr_native.wrap_setxattr(topath,
+ xattr.XATTR_NTACL_NAME,
+ attribute)
+ except Exception:
+ pass
+ # FIXME:Catch a specific exception
+
+
+def copytree_with_xattrs(src, dst):
+ """Recursively copy a directory tree using shutil.copy2(), preserving xattrs.
+
+ The destination directory must not already exist.
+ If exception(s) occur, an Error is raised with a list of reasons.
+ """
+ names = os.listdir(src)
+
+ os.makedirs(dst)
+ errors = []
+ for name in names:
+ srcname = os.path.join(src, name)
+ dstname = os.path.join(dst, name)
+ if os.path.islink(srcname):
+ linkto = os.readlink(srcname)
+ os.symlink(linkto, dstname)
+ elif os.path.isdir(srcname):
+ copytree_with_xattrs(srcname, dstname)
+ else:
+ # Will raise a SpecialFileError for unsupported file types
+ shutil.copy2(srcname, dstname)
+ shutil.copystat(src, dst)
+ copyattrs(src, dst)
--
Samba Shared Repository
More information about the samba-cvs
mailing list