Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #210799

Re: not wanting to delete somebody's home directory

From john doe <johndoe65534@mail.com>
Newsgroups linux.debian.user
Subject Re: not wanting to delete somebody's home directory
Date 2019-07-05 19:40 +0200
Message-ID <ygAlI-2Nn-7@gated-at.bofh.it> (permalink)
References <ygyjU-1Ef-5@gated-at.bofh.it> <ygzpD-2fB-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On 7/5/2019 6:31 PM, songbird wrote:
> mick crane wrote:
>> hello,
>> I doing some code in perl and I'm not very good at it.
>> code makes some images and saves them to a directory.
>> If the directory doesn't exist it gets made and if it does exist all the
>> files in it get deleted before putting some new ones in.
>> I'm thinking that if I ever give it to somebody it's possible they might
>> call the directory
>> "~/" or something and end up deleting all their files, which I'd like to
>> avoid.
>> How would that best be avoided ?
>> Is that something to do with chroot which I don't know anything about.
>

Answering here to the OP and assuming that the directory path is passed
to the script as argument:

~/ is a shortcut for ${HOME} which is the user home directory.

So ${HOME} will expand to '/home/user', you can simply check for that in
your script.
In a shell script I would do something like:

Take 1:

[ $1 = ${HOME} ] || { echo "   Directory (${1}) not allowed." >&2; exit 1; }
Take 2 (pick one of the two if lines):

if [ $1 != /home/$(id -u) ]; then
if [ $1 != /home/$USER ]; then
    echo "   Directory (${1}) not allowed." >&2
    exit 1
fi


The idea here is to eider only allow a specific directory to work in or
to deny access to some specific directories.
The former is easier to implement.

While you could execute your script in a chroot, not everyone will be
able to use a chroot.

--
John Doe

Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

not wanting to delete somebody's home directory mick crane <mick.crane@gmail.com> - 2019-07-05 17:30 +0200
  Re: not wanting to delete somebody's home directory Greg Wooledge <wooledg@eeg.ccf.org> - 2019-07-05 17:30 +0200
    Re: not wanting to delete somebody's home directory mick crane <mick.crane@gmail.com> - 2019-07-05 17:40 +0200
      Re: not wanting to delete somebody's home directory The Wanderer <wanderer@fastmail.fm> - 2019-07-05 17:40 +0200
        Re: not wanting to delete somebody's home directory Greg Wooledge <wooledg@eeg.ccf.org> - 2019-07-05 17:50 +0200
          Re: not wanting to delete somebody's home directory The Wanderer <wanderer@fastmail.fm> - 2019-07-05 18:20 +0200
            Re: not wanting to delete somebody's home directory Greg Wooledge <wooledg@eeg.ccf.org> - 2019-07-05 19:00 +0200
              Re: not wanting to delete somebody's home directory The Wanderer <wanderer@fastmail.fm> - 2019-07-05 19:30 +0200
      Re: not wanting to delete somebody's home directory mick crane <mick.crane@gmail.com> - 2019-07-05 17:40 +0200
  Re: not wanting to delete somebody's home directory songbird <songbird@anthive.com> - 2019-07-05 18:40 +0200
    Re: not wanting to delete somebody's home directory john doe <johndoe65534@mail.com> - 2019-07-05 19:40 +0200
      Re: not wanting to delete somebody's home directory Greg Wooledge <wooledg@eeg.ccf.org> - 2019-07-05 20:00 +0200
    Re: not wanting to delete somebody's home directory mick crane <mick.crane@gmail.com> - 2019-07-05 19:50 +0200
      Re: not wanting to delete somebody's home directory David Wright <deblis@lionunicorn.co.uk> - 2019-07-05 21:10 +0200
        Re: not wanting to delete somebody's home directory mick crane <mick.crane@gmail.com> - 2019-07-05 23:00 +0200
      Re: not wanting to delete somebody's home directory Curt <curty@free.fr> - 2019-07-06 10:40 +0200
        Re: not wanting to delete somebody's home directory songbird <songbird@anthive.com> - 2019-07-06 13:10 +0200
          Re: not wanting to delete somebody's home directory Curt <curty@free.fr> - 2019-07-06 14:40 +0200
            Re: not wanting to delete somebody's home directory Wolf Halton <wolf.halton@gmail.com> - 2019-07-06 15:10 +0200
            Re: not wanting to delete somebody's home directory rhkramer@gmail.com - 2019-07-06 16:30 +0200
              Re: not wanting to delete somebody's home directory "Thomas Schmitt" <scdbackup@gmx.net> - 2019-07-06 17:40 +0200
                Re: not wanting to delete somebody's home directory "Jeremy Nicoll" <jn.ml.dbn.25@letterboxes.org> - 2019-07-06 18:10 +0200
            Re: not wanting to delete somebody's home directory David Wright <deblis@lionunicorn.co.uk> - 2019-07-06 17:20 +0200
    Re: not wanting to delete somebody's home directory mick crane <mick.crane@gmail.com> - 2019-07-05 20:00 +0200
      Re: not wanting to delete somebody's home directory mick crane <mick.crane@gmail.com> - 2019-07-05 21:10 +0200
  Re: not wanting to delete somebody's home directory David Christensen <dpchrist@holgerdanske.com> - 2019-07-05 22:30 +0200

csiph-web