[projects/pld-ftp-admin] checkdir: refuse a tree name through a symlink

arekm arekm at pld-linux.org
Sat Nov 21 10:44:02 CET 2026


commit a049a512859eaede288d71649a2320e16c959476
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Sat Nov 21 02:47:19 2026 +0100

    checkdir: refuse a tree name through a symlink
    
    What a tree is goes by its name: .archive in it, archived_trees and
    signed_trees. A symlink to a tree, or .. through one or out of ftp_dir,
    named it otherwise, so a move could skip the signature check or the
    archive. The moves check the names as given, and clean-dups.py and
    pfa-from-incoming their tree.

 bin/pfa-from-incoming | 4 +++-
 bin/pfa-mvpkg         | 7 ++++---
 bin/pfa-testmvpkg     | 7 ++++---
 modules/common.py     | 5 +++++
 wwwbin/clean-dups.py  | 2 ++
 5 files changed, 18 insertions(+), 7 deletions(-)
---
diff --git a/bin/pfa-from-incoming b/bin/pfa-from-incoming
index 9bdf124..69d93f2 100755
--- a/bin/pfa-from-incoming
+++ b/bin/pfa-from-incoming
@@ -13,7 +13,7 @@ sys.path.insert(0, os.environ['HOME']+'/pld-ftp-admin/modules')
 import config
 import ftpio
 from baseftptree import BaseFtpTree, BasePkg
-from common import noarchcachedir, tmpdir
+from common import checkdir, noarchcachedir, tmpdir
 from config import default_to, ftp_archs, incoming_dir
 from config import value as cval
 
@@ -117,6 +117,8 @@ def move_noarch(f, arch, rpmfile, dstpkg):
         mv(incoming_dir + arch + '/' + rpmfile, default_to + 'noarch/RPMS')
 
 # main()
+checkdir(cval['default_to'])
+
 try:
     ftpio.connect(f'from-incoming-pid-{os.getpid()}')
 except OSError:
diff --git a/bin/pfa-mvpkg b/bin/pfa-mvpkg
index adc0f09..2114140 100755
--- a/bin/pfa-mvpkg
+++ b/bin/pfa-mvpkg
@@ -25,13 +25,14 @@ from mailer import Message
 os.umask(0o022)
 
 nocheckbuild = args.nocheckbuild
+# the names as given: normpath() takes current/../ready for ready, wherever current leads
+checkdir(args.srctree)
+checkdir(args.dsttree)
+
 # PLD/, as the shell completes it, is PLD for archived_trees, signed_trees and the locks
 srcname = os.path.normpath(args.srctree)
 dstname = os.path.normpath(args.dsttree)
 
-checkdir(srcname)
-checkdir(dstname)
-
 if dstname in archived_trees:
     archivetreename = ".archive/" + dstname
     checkdir(archivetreename)
diff --git a/bin/pfa-testmvpkg b/bin/pfa-testmvpkg
index bc03979..4efef64 100755
--- a/bin/pfa-testmvpkg
+++ b/bin/pfa-testmvpkg
@@ -22,13 +22,14 @@ import ftptree
 from common import checkdir
 from config import archived_trees
 
+# the names as given: normpath() takes current/../ready for ready, wherever current leads
+checkdir(args.srctree)
+checkdir(args.dsttree)
+
 # PLD/, as the shell completes it, is PLD for archived_trees, signed_trees and the locks
 srcname = os.path.normpath(args.srctree)
 dstname = os.path.normpath(args.dsttree)
 
-checkdir(srcname)
-checkdir(dstname)
-
 if dstname in archived_trees:
     archivetreename = ".archive/" + dstname
     checkdir(archivetreename)
diff --git a/modules/common.py b/modules/common.py
index 27188b3..60d351b 100644
--- a/modules/common.py
+++ b/modules/common.py
@@ -18,6 +18,11 @@ def checkdir(dir, metadata = True):
     if not fileexists(dir):
         print('ERR: ' + config.value['ftp_dir']+'/' + dir + " does not exist", file=sys.stderr)
         sys.exit(1)
+    # the name tells what a tree is (.archive in it, archived_trees, signed_trees), so it has to be where the tree is
+    name = os.path.normpath(dir)
+    if name.split('/')[0] == '..' or os.path.relpath(os.path.realpath(config.ftp_dir + dir), os.path.realpath(config.ftp_dir)) != name:
+        print('ERR: ' + config.value['ftp_dir']+'/' + dir + " goes through a symlink or out of ftp_dir, which is not supported", file=sys.stderr)
+        sys.exit(1)
     if metadata and not fileexists(dir + '/SRPMS/.metadata'):
         print('ERR: ' + config.value['ftp_dir']+'/' + dir + " is not an ftp tree, it has no SRPMS/.metadata", file=sys.stderr)
         sys.exit(1)
diff --git a/wwwbin/clean-dups.py b/wwwbin/clean-dups.py
index 1962b84..c9134ae 100755
--- a/wwwbin/clean-dups.py
+++ b/wwwbin/clean-dups.py
@@ -23,6 +23,7 @@ cutoff = time.time() - args.min_age * 86400
 sys.path.insert(0, os.environ['HOME']+'/pld-ftp-admin/modules')
 import ftpio
 import ftptree
+from common import checkdir
 
 ftp_tree = "test"
 
@@ -48,6 +49,7 @@ def young(path):
     except FileNotFoundError:
         return False
 
+checkdir(ftp_tree)
 ftpio.connect('clean-dups')
 
 if not ftpio.lock(ftp_tree, True):
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/projects/pld-ftp-admin.git/commitdiff/a049a512859eaede288d71649a2320e16c959476



More information about the pld-cvs-commit mailing list