summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2010-01-21 16:28:24 +1300
committerJelmer Vernooij <jelmer@samba.org>2010-01-21 16:28:24 +1300
commit342aff75c5400ef6be855094e2fe42f444cc40de (patch)
treede439b5a0fd9769afb5b3b12907e21b31d5a85f7
parent6afb16253399a58ac06b0061cd7ceb112bcd172b (diff)
downloadsamba-342aff75c5400ef6be855094e2fe42f444cc40de.tar.gz
samba-342aff75c5400ef6be855094e2fe42f444cc40de.tar.bz2
samba-342aff75c5400ef6be855094e2fe42f444cc40de.zip
pyxattr: Use standard functions for error handling.
-rw-r--r--source4/scripting/python/pyxattr_native.c22
-rw-r--r--source4/scripting/python/pyxattr_tdb.c22
2 files changed, 23 insertions, 21 deletions
diff --git a/source4/scripting/python/pyxattr_native.c b/source4/scripting/python/pyxattr_native.c
index 969ee7d416..70fdf571f1 100644
--- a/source4/scripting/python/pyxattr_native.c
+++ b/source4/scripting/python/pyxattr_native.c
@@ -27,7 +27,7 @@
#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
#endif
-static PyObject *py_is_xattr_supported(PyObject *self)
+static PyObject *py_is_xattr_supported(PyObject *self)
{
#if !defined(HAVE_XATTR_SUPPORT)
return Py_False;
@@ -49,9 +49,9 @@ static PyObject *py_wrap_setxattr(PyObject *self, PyObject *args)
ret = wrap_setxattr(filename,attribute,blob.data,blob.length,0);
if( ret < 0 ) {
if (errno == ENOTSUP) {
- PyErr_SetString(PyExc_IOError, strerror(errno));
+ PyErr_SetFromErrno(PyExc_IOError);
} else {
- PyErr_SetString(PyExc_TypeError, strerror(errno));
+ PyErr_SetFromErrno(PyExc_TypeError);
}
return NULL;
}
@@ -63,7 +63,7 @@ static PyObject *py_wrap_getxattr(PyObject *self, PyObject *args)
char *filename, *attribute;
int len;
TALLOC_CTX *mem_ctx;
- uint8_t *buf;
+ char *buf;
PyObject *ret;
if (!PyArg_ParseTuple(args, "ss", &filename,&attribute))
return NULL;
@@ -71,24 +71,24 @@ static PyObject *py_wrap_getxattr(PyObject *self, PyObject *args)
len = wrap_getxattr(filename,attribute,NULL,0);
if( len < 0 ) {
if (errno == ENOTSUP) {
- PyErr_SetString(PyExc_IOError, strerror(errno));
+ PyErr_SetFromErrno(PyExc_IOError);
} else {
- PyErr_SetString(PyExc_TypeError, strerror(errno));
+ PyErr_SetFromErrno(PyExc_TypeError);
}
return NULL;
}
/* check length ... */
- buf = talloc_zero_array(mem_ctx, uint8_t, len);
- len = wrap_getxattr(filename,attribute,buf,len);
+ buf = talloc_zero_array(mem_ctx, char, len);
+ len = wrap_getxattr(filename, attribute, buf, len);
if( len < 0 ) {
if (errno == ENOTSUP) {
- PyErr_SetString(PyExc_IOError, strerror(errno));
+ PyErr_SetFromErrno(PyExc_IOError);
} else {
- PyErr_SetString(PyExc_TypeError, strerror(errno));
+ PyErr_SetFromErrno(PyExc_TypeError);
}
return NULL;
}
- ret = PyString_FromStringAndSize(buf,len);
+ ret = PyString_FromStringAndSize(buf, len);
talloc_free(buf);
return ret;
}
diff --git a/source4/scripting/python/pyxattr_tdb.c b/source4/scripting/python/pyxattr_tdb.c
index 071d4374f2..ed5a97fe3c 100644
--- a/source4/scripting/python/pyxattr_tdb.c
+++ b/source4/scripting/python/pyxattr_tdb.c
@@ -20,17 +20,18 @@
#include <Python.h>
#include "includes.h"
-#include "../tdb/include/tdb.h"
+#include <tdb.h>
#include "tdb_wrap.h"
#include "librpc/ndr/libndr.h"
#include "lib/util/wrap_xattr.h"
#include "ntvfs/posix/vfs_posix.h"
+#include "libcli/util/pyerrors.h"
#ifndef Py_RETURN_NONE
#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
#endif
-static PyObject *py_is_xattr_supported(PyObject *self)
+static PyObject *py_is_xattr_supported(PyObject *self)
{
#if !defined(HAVE_XATTR_SUPPORT)
return Py_False;
@@ -38,12 +39,13 @@ static PyObject *py_is_xattr_supported(PyObject *self)
return Py_True;
#endif
}
+
static PyObject *py_wrap_setxattr(PyObject *self, PyObject *args)
{
char *filename, *attribute, *tdbname;
DATA_BLOB blob;
int blobsize;
- NTSTATUS status;
+ NTSTATUS status;
TALLOC_CTX *mem_ctx;
struct tdb_wrap *eadb;
@@ -58,9 +60,10 @@ static PyObject *py_wrap_setxattr(PyObject *self, PyObject *args)
if (eadb == NULL) {
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
- } status = push_xattr_blob_tdb_raw(eadb,mem_ctx,attribute,filename,-1,&blob);
+ }
+ status = push_xattr_blob_tdb_raw(eadb,mem_ctx,attribute,filename,-1,&blob);
if( !NT_STATUS_IS_OK(status) ) {
- PyErr_SetString(PyExc_TypeError, strerror(errno));
+ PyErr_SetFromErrno(PyExc_TypeError);
return NULL;
}
Py_RETURN_NONE;
@@ -75,23 +78,22 @@ static PyObject *py_wrap_getxattr(PyObject *self, PyObject *args)
NTSTATUS status;
struct tdb_wrap *eadb = NULL;
- if (!PyArg_ParseTuple(args, "sss", &tdbname,&filename,&attribute))
+ if (!PyArg_ParseTuple(args, "sss", &tdbname, &filename, &attribute))
return NULL;
mem_ctx = talloc_new(NULL);
eadb = tdb_wrap_open(mem_ctx, tdbname, 50000,
TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
if (eadb == NULL) {
-
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
status = pull_xattr_blob_tdb_raw(eadb,mem_ctx,attribute,filename,-1,100,&blob);
- if( !NT_STATUS_IS_OK(status) || blob.length < 0 ) {
- PyErr_SetString(PyExc_TypeError, get_friendly_nt_error_msg(status));
+ if (!NT_STATUS_IS_OK(status) || blob.length < 0) {
+ PyErr_FromNTSTATUS(status);
return NULL;
}
- ret = PyString_FromStringAndSize(blob.data,blob.length);
+ ret = PyString_FromStringAndSize((char *)blob.data, blob.length);
return ret;
}