samba-tool gpo: do not use predictable temp directory
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Tue, 6 Nov 2018 22:43:26 +0000 (11:43 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 7 Nov 2018 16:55:08 +0000 (17:55 +0100)
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/netcmd/gpo.py

index 4d5fc8838768f34eb3ccf16a6d7f8a94d4e3d412..0e6e2626c255aa7665af0db9cd827fcba24bf6bb 100644 (file)
@@ -18,7 +18,7 @@
 # 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 __future__ import print_function
 import os
 import samba.getopt as options
 import ldb
@@ -939,7 +939,9 @@ class cmd_fetch(Command):
 
         # Copy GPT
         if tmpdir is None:
-            tmpdir = "/tmp"
+            tmpdir = tempfile.mkdtemp()
+            print("Using temporary directory %s (use --tmpdir to change)" % tmpdir,
+                  file=self.outf)
         if not os.path.isdir(tmpdir):
             raise CommandError("Temoprary directory '%s' does not exist" % tmpdir)
 
@@ -1017,7 +1019,9 @@ class cmd_backup(Command):
 
         # Copy GPT
         if tmpdir is None:
-            tmpdir = "/tmp"
+            tmpdir = tempfile.mkdtemp()
+            print("Using temporary directory %s (use --tmpdir to change)" % tmpdir,
+                  file=self.outf)
         if not os.path.isdir(tmpdir):
             raise CommandError("Temoprary directory '%s' does not exist" % tmpdir)
 
@@ -1168,7 +1172,9 @@ class cmd_create(Command):
 
         # Create GPT
         if tmpdir is None:
-            tmpdir = "/tmp"
+            tmpdir = tempfile.mkdtemp()
+            print("Using temporary directory %s (use --tmpdir to change)" % tmpdir,
+                  file=self.outf)
         if not os.path.isdir(tmpdir):
             raise CommandError("Temporary directory '%s' does not exist" % tmpdir)
         self.tmpdir = tmpdir