mirror of
https://github.com/samba-team/samba.git
synced 2025-07-23 20:59:10 +03:00
pyxattr: Use standard functions for error handling.
This commit is contained in:
@ -27,7 +27,7 @@
|
|||||||
#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
|
#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static PyObject *py_is_xattr_supported(PyObject *self)
|
static PyObject *py_is_xattr_supported(PyObject *self)
|
||||||
{
|
{
|
||||||
#if !defined(HAVE_XATTR_SUPPORT)
|
#if !defined(HAVE_XATTR_SUPPORT)
|
||||||
return Py_False;
|
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);
|
ret = wrap_setxattr(filename,attribute,blob.data,blob.length,0);
|
||||||
if( ret < 0 ) {
|
if( ret < 0 ) {
|
||||||
if (errno == ENOTSUP) {
|
if (errno == ENOTSUP) {
|
||||||
PyErr_SetString(PyExc_IOError, strerror(errno));
|
PyErr_SetFromErrno(PyExc_IOError);
|
||||||
} else {
|
} else {
|
||||||
PyErr_SetString(PyExc_TypeError, strerror(errno));
|
PyErr_SetFromErrno(PyExc_TypeError);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -63,7 +63,7 @@ static PyObject *py_wrap_getxattr(PyObject *self, PyObject *args)
|
|||||||
char *filename, *attribute;
|
char *filename, *attribute;
|
||||||
int len;
|
int len;
|
||||||
TALLOC_CTX *mem_ctx;
|
TALLOC_CTX *mem_ctx;
|
||||||
uint8_t *buf;
|
char *buf;
|
||||||
PyObject *ret;
|
PyObject *ret;
|
||||||
if (!PyArg_ParseTuple(args, "ss", &filename,&attribute))
|
if (!PyArg_ParseTuple(args, "ss", &filename,&attribute))
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -71,24 +71,24 @@ static PyObject *py_wrap_getxattr(PyObject *self, PyObject *args)
|
|||||||
len = wrap_getxattr(filename,attribute,NULL,0);
|
len = wrap_getxattr(filename,attribute,NULL,0);
|
||||||
if( len < 0 ) {
|
if( len < 0 ) {
|
||||||
if (errno == ENOTSUP) {
|
if (errno == ENOTSUP) {
|
||||||
PyErr_SetString(PyExc_IOError, strerror(errno));
|
PyErr_SetFromErrno(PyExc_IOError);
|
||||||
} else {
|
} else {
|
||||||
PyErr_SetString(PyExc_TypeError, strerror(errno));
|
PyErr_SetFromErrno(PyExc_TypeError);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* check length ... */
|
/* check length ... */
|
||||||
buf = talloc_zero_array(mem_ctx, uint8_t, len);
|
buf = talloc_zero_array(mem_ctx, char, len);
|
||||||
len = wrap_getxattr(filename,attribute,buf,len);
|
len = wrap_getxattr(filename, attribute, buf, len);
|
||||||
if( len < 0 ) {
|
if( len < 0 ) {
|
||||||
if (errno == ENOTSUP) {
|
if (errno == ENOTSUP) {
|
||||||
PyErr_SetString(PyExc_IOError, strerror(errno));
|
PyErr_SetFromErrno(PyExc_IOError);
|
||||||
} else {
|
} else {
|
||||||
PyErr_SetString(PyExc_TypeError, strerror(errno));
|
PyErr_SetFromErrno(PyExc_TypeError);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
ret = PyString_FromStringAndSize(buf,len);
|
ret = PyString_FromStringAndSize(buf, len);
|
||||||
talloc_free(buf);
|
talloc_free(buf);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -20,17 +20,18 @@
|
|||||||
|
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include "includes.h"
|
#include "includes.h"
|
||||||
#include "../tdb/include/tdb.h"
|
#include <tdb.h>
|
||||||
#include "tdb_wrap.h"
|
#include "tdb_wrap.h"
|
||||||
#include "librpc/ndr/libndr.h"
|
#include "librpc/ndr/libndr.h"
|
||||||
#include "lib/util/wrap_xattr.h"
|
#include "lib/util/wrap_xattr.h"
|
||||||
#include "ntvfs/posix/vfs_posix.h"
|
#include "ntvfs/posix/vfs_posix.h"
|
||||||
|
#include "libcli/util/pyerrors.h"
|
||||||
|
|
||||||
#ifndef Py_RETURN_NONE
|
#ifndef Py_RETURN_NONE
|
||||||
#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
|
#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static PyObject *py_is_xattr_supported(PyObject *self)
|
static PyObject *py_is_xattr_supported(PyObject *self)
|
||||||
{
|
{
|
||||||
#if !defined(HAVE_XATTR_SUPPORT)
|
#if !defined(HAVE_XATTR_SUPPORT)
|
||||||
return Py_False;
|
return Py_False;
|
||||||
@ -38,12 +39,13 @@ static PyObject *py_is_xattr_supported(PyObject *self)
|
|||||||
return Py_True;
|
return Py_True;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *py_wrap_setxattr(PyObject *self, PyObject *args)
|
static PyObject *py_wrap_setxattr(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
char *filename, *attribute, *tdbname;
|
char *filename, *attribute, *tdbname;
|
||||||
DATA_BLOB blob;
|
DATA_BLOB blob;
|
||||||
int blobsize;
|
int blobsize;
|
||||||
NTSTATUS status;
|
NTSTATUS status;
|
||||||
TALLOC_CTX *mem_ctx;
|
TALLOC_CTX *mem_ctx;
|
||||||
struct tdb_wrap *eadb;
|
struct tdb_wrap *eadb;
|
||||||
|
|
||||||
@ -58,9 +60,10 @@ static PyObject *py_wrap_setxattr(PyObject *self, PyObject *args)
|
|||||||
if (eadb == NULL) {
|
if (eadb == NULL) {
|
||||||
PyErr_SetFromErrno(PyExc_IOError);
|
PyErr_SetFromErrno(PyExc_IOError);
|
||||||
return NULL;
|
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) ) {
|
if( !NT_STATUS_IS_OK(status) ) {
|
||||||
PyErr_SetString(PyExc_TypeError, strerror(errno));
|
PyErr_SetFromErrno(PyExc_TypeError);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
@ -75,23 +78,22 @@ static PyObject *py_wrap_getxattr(PyObject *self, PyObject *args)
|
|||||||
NTSTATUS status;
|
NTSTATUS status;
|
||||||
struct tdb_wrap *eadb = NULL;
|
struct tdb_wrap *eadb = NULL;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "sss", &tdbname,&filename,&attribute))
|
if (!PyArg_ParseTuple(args, "sss", &tdbname, &filename, &attribute))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
mem_ctx = talloc_new(NULL);
|
mem_ctx = talloc_new(NULL);
|
||||||
eadb = tdb_wrap_open(mem_ctx, tdbname, 50000,
|
eadb = tdb_wrap_open(mem_ctx, tdbname, 50000,
|
||||||
TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
|
TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
|
||||||
if (eadb == NULL) {
|
if (eadb == NULL) {
|
||||||
|
|
||||||
PyErr_SetFromErrno(PyExc_IOError);
|
PyErr_SetFromErrno(PyExc_IOError);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
status = pull_xattr_blob_tdb_raw(eadb,mem_ctx,attribute,filename,-1,100,&blob);
|
status = pull_xattr_blob_tdb_raw(eadb,mem_ctx,attribute,filename,-1,100,&blob);
|
||||||
if( !NT_STATUS_IS_OK(status) || blob.length < 0 ) {
|
if (!NT_STATUS_IS_OK(status) || blob.length < 0) {
|
||||||
PyErr_SetString(PyExc_TypeError, get_friendly_nt_error_msg(status));
|
PyErr_FromNTSTATUS(status);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
ret = PyString_FromStringAndSize(blob.data,blob.length);
|
ret = PyString_FromStringAndSize((char *)blob.data, blob.length);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user