/usr/sbin/ltspfsmounter is in ltspfs 1.3-1.
This file is owned by root:root, with mode 0o755.
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 | #!/usr/bin/python
import os
import sys
from subprocess import call
import re
hook_dirs=list()
def run_hooks(mode, mountpoint):
executed_hooks=list()
valid_filename=re.compile('^[a-zA-Z0-9\-_]*$')
for dir in hook_dirs:
if os.path.isdir(dir):
# get a unique list of hook scripts
hook_scripts=list(set(os.listdir(dir)))
hook_scripts.sort()
for script in hook_scripts:
# only run the first script of a given name
if executed_hooks.count(script) == 0 and valid_filename.match(script):
executed_hooks.append(script)
try:
call([os.path.join(dir, script), mode, mountpoint])
except:
# be very tolerant of failures with hook scripts
pass
def get_var(name):
return os.environ.get(name)
def add_ltspfsmount(conn, path, root, dev, mediaroot):
hidden_mount = '%s/%s' % (root, dev)
lbmount_command = ['lbmount', dev]
ltspfs_mount = ['ltspfs', conn+':'+path, root+'/'+dev]
if not os.access(root, 0):
os.mkdir(root)
if not os.access(hidden_mount, 0):
os.mkdir(hidden_mount)
env = os.environ.copy()
try:
call(ltspfs_mount, env=env)
except OSError, e:
print >>sys.stderr, "mount failed:", e
try:
call(lbmount_command)
if os.access(hidden_mount, 0):
os.rmdir(hidden_mount)
if os.access(root, 0):
os.rmdir(root)
run_hooks('add', os.path.join(mediaroot, dev))
except OSError, e:
print >>sys.stderr, "suid mount failed:", e
def remove_ltspfsmount(root, dev):
lbumount_command=['lbmount', '--umount', dev]
ltspfs_umount=['fusermount', '-uzq', root+'/'+dev]
try:
call(lbumount_command)
except OSError, e:
print >>sys.stderr, "suid umount failed:", e
try:
call(ltspfs_umount)
run_hooks('remove', os.path.join(root, dev))
except OSError, e:
print >>sys.stderr, "umount failed:", e
def cleanup(user):
known_mounts = open( '/proc/mounts', 'r' ).readlines()
for dir in ['/media', '/tmp']:
for mount in known_mounts:
if mount.startswith('ltspfs') and user in mount:
mountpoint=mount.split()[1]
device=mountpoint.split('/')[-1]
if dir=='/media' and mountpoint.startswith(dir):
call(['lbmount', '--umount', device])
elif dir=='/tmp' and mountpoint.startswith(dir):
call(['fusermount', '-uzq', mountpoint])
if os.access(mountpoint, 0):
os.rmdir(mountpoint)
run_hooks('cleanup', '')
sys.exit(0)
def main():
if len(sys.argv) < 3:
print 'usage: %s mountpoint add|remove|cleanup' % sys.argv[0]
sys.exit(1)
if not os.access('/dev/fuse', 2):
sys.stderr.write('/dev/fuse not writeable\n')
sys.exit(1)
# check if hook dirs are present
for dir in ['/etc', '/usr/share', '/usr/lib']:
dir=os.path.join(dir, 'ltspfs/mounter.d')
if os.path.isdir(dir):
hook_dirs.append(dir)
path = sys.argv[1]
command = sys.argv[2]
username = get_var('USER')
root = "/tmp/.%s-ltspfs" % username
mediaroot = "/media/%s" % username
if not get_var('SSH_CONNECTION'):
conn = "127.0.0.1"
os.putenv('SSH_CONNECTION', '127.0.0.1')
else:
conn = get_var('SSH_CONNECTION').split()[0]
dev = path.split('/')[-1]
if command=='add':
add_ltspfsmount(conn, path, root, dev, mediaroot)
elif command=='remove':
remove_ltspfsmount(mediaroot, dev)
elif command=='cleanup':
cleanup(username)
else:
print 'unknown command'
if __name__ == "__main__":
main()
|