Restrictions
Restrictions are implemented via the service XPRM_SRV_CHRES that expects a function of the form int chkres(int restr), where the restrictions to be checked are passed in the bit-encoded parameter restr.
static int chkres(int); static XPRMdsoserv tabserv[]= { {XPRM_SRV_CHKRES,(void*)chkres}, };
None of the example modules presented in this guide involve external file access or calls to external commands and therefore do not require any detailed checks of access restrictions. In all examples, we can simply add a function chkres that returns the value '0' to indicate that the module is compliant with all access restrictions, without any need for further modifications to the module definitions.
static int chkres(int r) { return 0; }
An example module that employs external file access functions is the data compression module zlib described in the whitepaper 'Generalized file handling in Mosel'. In this example, the 'CHKRES' service and function chkres are defined as shown above and in addition, we need to check for restrictions wherever external file access functions are being used, such as calls to file opening through an external compression library.
The relevant part of the `open a compressed file' function gzip_open is shown below (the complete code of this example is provided in the file zlib.c, located in the directory examples/mosel/Modules of the Xpress distribution). Notice the use of the NI function pathcheck to expand the file name and check whether it can be accessed given the current restrictions. NB: Mosel NI file access functions such as fopen automatically perform the necessary tests for restrictions and hence do not require the addition of any tests to achieve compliance with restrictions.
static void *gzip_open(XPRMcontext ctx,int *mode,const char *fname) { char cfname[MM_MAXPATHLEN]; char cmode[16]; if((fname==NULL)|| (mm->pathcheck(ctx,fname,cfname,MM_MAXPATHLEN, ((*mode)&MM_F_WRITE)?MM_RCHK_WRITE:MM_RCHK_READ)!=0)) { errno=EACCES; return NULL; } else { ... /* Build up 'cmode' */ return gzopen(cfname,cmode); /* Call external file access function */ } }
© 2001-2019 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.