LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 03-21-2012, 03:55 AM   #1
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290
Locking a directory down for the duration of a SFTP session


Hi guys,

I'm confronted with a problem for which I haven't been able to find a solution on the internet yet, not even with the help of my greatest friend Google.

We're allowing a specific user access to a server to upload files with sftp. For security reasons this user is thrown in a chroot which works like it should.

My problem is that we never know how much time it might take to upload the files and we have a cron job that runs regularly to process the files uploaded to that directory.

What I've been thinking of is to put some kind of directory lock on that directory to prohibit reading/writing to it to anyone else but the sftp user / sftp session for the duration of that session.

Any ideas are as always very welcome.

Kind regards,

Eric
 
Old 03-21-2012, 04:56 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6
Posts: 1,529

Rep: Reputation: 472Reputation: 472Reputation: 472Reputation: 472Reputation: 472
Is your user uploading the files manually or by script?

If it's by script then get them to send their file with an extension that your scron job will ignore and then get them to rename the file to remove the extension after its been uploaded.

Alternatively, have your cron script do a ps to identify if the user is logged in, or has an sftp / scp / whatever process running, and if it is then skip processing that folder.
 
Old 03-21-2012, 05:14 AM   #3
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Original Poster
Rep: Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290
Hi,

Just thought about your second option, checking if the user has a sftp process running from within the cron job itself. Thanks for the ideas. I'm marking the thread as solved.

Kind regards,

Eric
 
Old 03-22-2012, 09:23 AM   #4
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 13.1
Posts: 1,320

Rep: Reputation: 252Reputation: 252Reputation: 252
Although you marked it as solved: instead of looking for the user having an sftp process running (it could be one from another file being uploaded), my suggestions would be to check with lsof or fuser for any process that still has the file in question open.
 
Old 03-22-2012, 03:11 PM   #5
EricTRA
Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Original Poster
Rep: Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290Reputation: 1290
Quote:
Originally Posted by Reuti View Post
Although you marked it as solved: instead of looking for the user having an sftp process running (it could be one from another file being uploaded), my suggestions would be to check with lsof or fuser for any process that still has the file in question open.
Hi Reuti,

Thank you very much for your input. The lsof or fuser option can work too and even better as you pointed out when another file is being uploaded. Since I don't control the way the other end will start the upload it might be advantageous to use the commands pointed out by you. Thanks again.

Kind regards,

Eric
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Locking a Session Sylvester Ink Linux - Desktop 1 03-08-2012 11:51 AM
Database Script Locking Session / Hanging SteveLoweIL Linux - Software 0 02-09-2011 10:25 AM
Locking a session Sehanru Fedora 2 07-11-2007 09:53 PM
Locking GNOME session waelaltaqi Linux - Software 1 12-02-2005 08:58 PM
X session crashed by lopster when locking screen? ac1980 Linux - Software 0 03-03-2004 07:21 AM


All times are GMT -5. The time now is 02:15 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration