summaryrefslogtreecommitdiffstats
path: root/src/dmidecodemodule.c
diff options
context:
space:
mode:
authornima <nima@abc39116-655e-4be6-ad55-d661dc543056>2008-12-21 07:53:54 +0000
committernima <nima@abc39116-655e-4be6-ad55-d661dc543056>2008-12-21 07:53:54 +0000
commit0ff1b5b45facd7543529dab5711cf2812c47c218 (patch)
tree7cb4ba131f2ee5437079ae5b959889fac172f1e4 /src/dmidecodemodule.c
parent42617d59e66684bff7272c9c49c0cadd2e53c7f9 (diff)
downloadpython-dmidecode-0ff1b5b45facd7543529dab5711cf2812c47c218.tar.gz
python-dmidecode-0ff1b5b45facd7543529dab5711cf2812c47c218.tar.xz
python-dmidecode-0ff1b5b45facd7543529dab5711cf2812c47c218.zip
Handle cases where user does not have appropriate permission to access the
memory file or device. git-svn-id: svn://svn.autonomy.net.au/python-dmidecode@155 abc39116-655e-4be6-ad55-d661dc543056
Diffstat (limited to 'src/dmidecodemodule.c')
-rw-r--r--src/dmidecodemodule.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/dmidecodemodule.c b/src/dmidecodemodule.c
index 31f4631..ef19ee5 100644
--- a/src/dmidecodemodule.c
+++ b/src/dmidecodemodule.c
@@ -135,6 +135,10 @@ static PyObject* dmidecode_get(PyObject *self, const char* section) {
opt.type = parse_opt_type(opt.type, section);
if(opt.type==NULL) return NULL;
+ const char *f = opt.dumpfile ? PyString_AsString(opt.dumpfile) : opt.devmem;
+ if(access(f, R_OK) < 0)
+ PyErr_SetString(PyExc_IOError, "Permission denied to memory file/device");
+
PyObject* pydata = PyDict_New();
/***********************************/
@@ -173,11 +177,16 @@ static PyObject* dmidecode_get(PyObject *self, const char* section) {
}
}
- if(ret==0) free(buf);
free(opt.type);
+ if(ret==0) {
+ free(buf);
+ } else {
+ Py_DECREF(pydata);
+ pydata = NULL;
+ }
//muntrace();
- return (ret != 1)?pydata:NULL;
+ return pydata;
}
static PyObject* dmidecode_get_bios(PyObject *self, PyObject *args) { return dmidecode_get(self, "bios"); }
@@ -205,10 +214,10 @@ static PyObject* dmidecode_get_type(PyObject *self, PyObject *args) {
static PyObject* dmidecode_dump(PyObject *self, PyObject *null) {
const char *f;
f = opt.dumpfile ? PyString_AsString(opt.dumpfile) : opt.devmem;
- struct stat buf;
- stat(f, &buf);
+ struct stat _buf;
+ stat(f, &_buf);
- if((access(f, F_OK) != 0) || ((access(f, W_OK) == 0) && S_ISREG(buf.st_mode)))
+ if((access(f, F_OK) != 0) || ((access(f, W_OK) == 0) && S_ISREG(_buf.st_mode)))
if(dump(PyString_AS_STRING(opt.dumpfile)))
Py_RETURN_TRUE;
Py_RETURN_FALSE;
@@ -290,5 +299,5 @@ PyMODINIT_FUNC initdmidecode(void) {
PyObject *dmi_version = NULL;
dmidecode_set_version(&dmi_version);
- PyModule_AddObject(module, "dmi", dmi_version);
+ PyModule_AddObject(module, "dmi", dmi_version?dmi_version:Py_None);
}