Running as root, yet permission denied

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jn

    Running as root, yet permission denied

    They have a server here that runs PHP as root (which is probably bad). I
    wrote a test script that tries to create a text file.

    echo "<B>I'm running as user: " . $_ENV['USER'] . "</B><BR/><BR/>";

    //open the file
    echo "<B>Opening file text.txt for writing:</B>";
    $fp = fopen('text.txt ',w);
    echo "<BR/>";

    if(!$fp){
    echo "<B>UNABLE TO CREATE THE FILE!</B>";
    exit;
    }


    I get a permission denied error. The directory is CHMOD 755.


  • B. Johannessen

    #2
    Re: Running as root, yet permission denied

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    jn wrote:[color=blue]
    > They have a server here that runs PHP as root (which is probably
    > bad). I wrote a test script that tries to create a text file.
    >
    > echo "<B>I'm running as user: " . $_ENV['USER'] . "</B><BR/><BR/>";[/color]

    $USER == root is no guarantee that you are running as root. Try adding:

    <?php passthru('id'); ?>


    Bob



    -----BEGIN PGP SIGNATURE-----
    Comment: B. Johannessen <bob@db.org> - http://db.org/contact/en/

    iD8DBQFAQH1Oooi sUyMOFlgRAtRuAJ 9LGAfQn+uOxOctY dSfXm4VJFdBVwCf VT/v
    BW/CT3LehI/jWcSxyeMlm04=
    =Ykss
    -----END PGP SIGNATURE-----

    Comment

    • jn

      #3
      Re: Running as root, yet permission denied

      "B. Johannessen" <bob@db.org> wrote in message
      news:i3%%b.7090 $_c4.90605@news 4.e.nsc.no...[color=blue]
      > -----BEGIN PGP SIGNED MESSAGE-----
      > Hash: SHA1
      >
      > jn wrote:[color=green]
      > > They have a server here that runs PHP as root (which is probably
      > > bad). I wrote a test script that tries to create a text file.
      > >
      > > echo "<B>I'm running as user: " . $_ENV['USER'] . "</B><BR/><BR/>";[/color]
      >
      > $USER == root is no guarantee that you are running as root. Try adding:
      >
      > <?php passthru('id'); ?>
      >
      >
      > Bob
      >
      >
      >
      > -----BEGIN PGP SIGNATURE-----
      > Comment: B. Johannessen <bob@db.org> - http://db.org/contact/en/
      >
      > iD8DBQFAQH1Oooi sUyMOFlgRAtRuAJ 9LGAfQn+uOxOctY dSfXm4VJFdBVwCf VT/v
      > BW/CT3LehI/jWcSxyeMlm04=
      > =Ykss
      > -----END PGP SIGNATURE-----
      >[/color]

      Aha:
      uid=80(www) gid=80(www) groups=80(www)

      So, what do I need to do? Modify the permissions for this user or create a
      new user just for PHP?


      Comment

      • Pertti Kosunen

        #4
        Re: Running as root, yet permission denied

        "jn" <usenet*spamist ehsuckremovetor eply*@jasonnorr is.net> wrote in message
        news:ig%%b.1464 95$B81.1215874@ twister.tampaba y.rr.com...[color=blue]
        > Aha:
        > uid=80(www) gid=80(www) groups=80(www)
        >
        > So, what do I need to do? Modify the permissions for this user or create a
        > new user just for PHP?[/color]

        Modify owner group of directory you want to write (chown root:www
        /path/to/dir) and give group www permissions to write (chmod 775
        /path/to/dir).


        Comment

        • jn

          #5
          Re: Running as root, yet permission denied

          "Pertti Kosunen" <pertti.kosunen @kolumb.us.fi_i nvalid> wrote in message
          news:c1q2u3$ru5 $1@phys-news1.kolumbus. fi...[color=blue]
          > "jn" <usenet*spamist ehsuckremovetor eply*@jasonnorr is.net> wrote in message
          > news:ig%%b.1464 95$B81.1215874@ twister.tampaba y.rr.com...[color=green]
          > > Aha:
          > > uid=80(www) gid=80(www) groups=80(www)
          > >
          > > So, what do I need to do? Modify the permissions for this user or create[/color][/color]
          a[color=blue][color=green]
          > > new user just for PHP?[/color]
          >
          > Modify owner group of directory you want to write (chown root:www
          > /path/to/dir) and give group www permissions to write (chmod 775
          > /path/to/dir).
          >
          >
          >[/color]

          It's fixed. Thanks


          Comment

          • Five Cats

            #6
            Re: Running as root, yet permission denied

            In message <ig%%b.146495$B 81.1215874@twis ter.tampabay.rr .com>, jn
            <usenet*spamist ehsuckremovetor eply*@jasonnorr is.net> writes[color=blue]
            >"B. Johannessen" <bob@db.org> wrote in message
            >news:i3%%b.709 0$_c4.90605@new s4.e.nsc.no...[color=green]
            >> -----BEGIN PGP SIGNED MESSAGE-----
            >> Hash: SHA1
            >>
            >> jn wrote:[color=darkred]
            >> > They have a server here that runs PHP as root (which is probably
            >> > bad). I wrote a test script that tries to create a text file.
            >> >
            >> > echo "<B>I'm running as user: " . $_ENV['USER'] . "</B><BR/><BR/>";[/color]
            >>
            >> $USER == root is no guarantee that you are running as root. Try adding:
            >>
            >> <?php passthru('id'); ?>
            >>
            >>
            >> Bob
            >>
            >>
            >>
            >> -----BEGIN PGP SIGNATURE-----
            >> Comment: B. Johannessen <bob@db.org> - http://db.org/contact/en/
            >>
            >> iD8DBQFAQH1Oooi sUyMOFlgRAtRuAJ 9LGAfQn+uOxOctY dSfXm4VJFdBVwCf VT/v
            >> BW/CT3LehI/jWcSxyeMlm04=
            >> =Ykss
            >> -----END PGP SIGNATURE-----
            >>[/color]
            >
            >Aha:
            >uid=80(www) gid=80(www) groups=80(www)
            >
            >So, what do I need to do? Modify the permissions for this user or create a
            >new user just for PHP?
            >[/color]
            Ensure you have write permissions to the current working directory - if
            that is / it shouldn't be!
            [color=blue]
            >[/color]

            --
            Five Cats
            Email to: cats_spam at uk2 dot net

            Comment

            Working...