diff options
author | Guido van Rossum <guido@python.org> | 2001-09-17 19:28:08 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2001-09-17 19:28:08 (GMT) |
commit | c299fc16f2a8572780d2130ab9e55a6f22a93279 (patch) | |
tree | 6087eb98f0bc194027bf913662f960f9a68ad545 /Python/structmember.c | |
parent | bf80a033ee76487de30ea272a8c79346d26536ff (diff) | |
download | cpython-c299fc16f2a8572780d2130ab9e55a6f22a93279.zip cpython-c299fc16f2a8572780d2130ab9e55a6f22a93279.tar.gz cpython-c299fc16f2a8572780d2130ab9e55a6f22a93279.tar.bz2 |
Add support for restricting access based on restricted execution mode.
Renamed the 'readonly' field to 'flags' and defined some new flag
bits: READ_RESTRICTED and WRITE_RESTRICTED, as well as a shortcut
RESTRICTED that means both.
Diffstat (limited to 'Python/structmember.c')
-rw-r--r-- | Python/structmember.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/Python/structmember.c b/Python/structmember.c index e155a6b..ed34783 100644 --- a/Python/structmember.c +++ b/Python/structmember.c @@ -38,6 +38,12 @@ PyMember_Get(char *addr, struct memberlist *mlist, char *name) for (l = mlist; l->name != NULL; l++) { if (strcmp(l->name, name) == 0) { PyObject *v; + if ((l->flags & READ_RESTRICTED) && + PyEval_GetRestricted()) { + PyErr_SetString(PyExc_RuntimeError, + "restricted attribute"); + return NULL; + } addr += l->offset; switch (l->type) { case T_BYTE: @@ -133,17 +139,22 @@ PyMember_Set(char *addr, struct memberlist *mlist, char *name, PyObject *v) for (l = mlist; l->name != NULL; l++) { if (strcmp(l->name, name) == 0) { + if ((l->flags & READONLY) || l->type == T_STRING #ifdef macintosh - if (l->readonly || l->type == T_STRING || - l->type == T_PSTRING) + || l->type == T_PSTRING +#endif + ) { -#else - if (l->readonly || l->type == T_STRING ) { -#endif /* macintosh */ PyErr_SetString(PyExc_TypeError, "readonly attribute"); return -1; } + if ((l->flags & WRITE_RESTRICTED) && + PyEval_GetRestricted()) { + PyErr_SetString(PyExc_RuntimeError, + "restricted attribute"); + return -1; + } if (v == NULL && l->type != T_OBJECT) { PyErr_SetString(PyExc_TypeError, "can't delete numeric/char attribute"); |