Logo Search packages:      
Sourcecode: yapet version File versions  Download package

void File::setFileSecurity (  )  throw (YAPETException) [private]

Sets the owner and permissions on a file.

Sets the owner and permissions on a file in a manner that File::checkFileSecurity does not complain.

If it cannot set the security permissions, it throws a YAPETRetryException if the error can be avoided using non-secure settings.

Definition at line 150 of file file.cc.

References fd, and filename.

Referenced by save().

                                            {
#if defined(HAVE_FCHOWN) && defined(HAVE_FCHMOD) && defined(HAVE_FSTAT)
    struct stat buf;

    int err = fstat(fd, &buf);
    if (err == -1)
      throw YAPETException(strerror(errno));

    err = fchown(fd, getuid(), buf.st_gid);
    if (err == -1) {
      std::string tmp(_("Cannot set the owner of "));
      throw YAPETRetryException(tmp + filename);
    }

    err = fchmod(fd, S_IRUSR | S_IWUSR);
    if (err == -1) {
      std::string tmp(_("Cannot set file permissions on ") );
      throw YAPETRetryException(tmp + filename);
    }
#endif
}


Generated by  Doxygen 1.6.0   Back to index