Forum archive 2000-2006

Jeff Seibert - is open function restricted?

Jeff Seibert - is open function restricted?

by Arnold Pizer -
Number of replies: 0
inactiveTopicis open function restricted? topic started 6/28/2006; 5:33:41 PM
last post 6/29/2006; 3:02:38 PM
userJeff Seibert - is open function restricted?  blueArrow
6/28/2006; 5:33:41 PM (reads: 358, responses: 5)
I was wondering if the open function was restricted in PG, because whenver I try to do something like this:

open(FILE, "test.txt");

I always get an error from WebWork:

'open' trapped by operation mask at line 2 of (eval 4845)

Is there no way to open files or am I doing something incorrectly?

Also, I was wondering if the 'use' keyword was restricted. If I wanted to use the floor or ceil function, I would need to import the POSIX library, but 'use POSIX;' gets a similar error message. Is there a workaround for this other than rewriting the functions?

Thanks, Jeff Seibert

<| Post or View Comments |>


userMichael Gage - Re: is open function restricted?  blueArrow
6/28/2006; 5:53:15 PM (reads: 414, responses: 0)
Hi Jeff,

use, require, print, open, eval are among the commands restricted from within the Safe compartment. Basically all attempts to write to the disk directly are restricted from within all macro files (the .pl files) and the problems themselves (.pg).

Direct access to the disk raises the possibility of all kinds of exploit opportunities and we prevent it except through specific access methods that have been written for WeBWorK.

The contents of the library modules (.pm) are not executed from within the Safe compartment. This is where many of the restricted IO operations have been placed, as well as in the file dangerousmacros.pl

You can write these yourself and load them by including them in the list in global.conf. You should think carefully however about whether the disk access has been sufficiently restricted to prevent accidental destruction when called from a .pg problem.

floor and ceil are defined in PGauxiliaryFunctions -- although I'd be curious to know whether they conform to POSIX standards.

I'm curious what you are building that uses disk access. We may be able to help you out with the construction of the appropriate library modules.

Take care,

Mike

<| Post or View Comments |>


userDavide P. Cervone - Re: is open function restricted?  blueArrow
6/29/2006; 10:16:15 AM (reads: 408, responses: 0)
If you are trying to READ data from a file, that may be able to be done. For example loadMacros() might be able to be used, in the right circumstances (and there are more general means as well). Writing files is a lot harder, and as Mike says, is pretty much restricted.

Davide

<| Post or View Comments |>


userDavide P. Cervone - Re: is open function restricted?  blueArrow
6/29/2006; 10:16:17 AM (reads: 397, responses: 0)
If you are trying to READ data from a file, that may be able to be done. For example loadMacros() might be able to be used, in the right circumstances (and there are more general means as well). Writing files is a lot harder, and as Mike says, is pretty much restricted.

Davide

<| Post or View Comments |>


userJeff Seibert - Re: is open function restricted?  blueArrow
6/29/2006; 2:44:44 PM (reads: 395, responses: 1)
Currently I'm writing problems for a thermodynamics class that have randomly generated variables in them. However, to solve some of these problems I need to be able to look up data in a table of information. I would like to store these tables in a sepearate file. So basically, all I really need to be able to do is read from files.

Thanks for the quick responses.

<| Post or View Comments |>


userDavide P. Cervone - Re: is open function restricted?  blueArrow
6/29/2006; 3:02:38 PM (reads: 473, responses: 0)
It looks like loadMacros() should be sufficient for your needs, then. Simply put your table in Perl code in a file ending with ".pl" and place that file in the same directory as your .pg file. Then loadMacros() should be able to load that file and you will have access to the variables that it defines. The nice thing about loading Perl code like that is that you don't have to write anything to parse the data yourself; Perl will do that for you.

Davide

PS, the ability for loadMacros() to load from the problem directory was added in v1.34 of pg/macros/dangerousMacros.pl over a year ago, but you might need to put the data file in your course's templates/macros directory instead if you are running an older verion.

<| Post or View Comments |>