diff options
author | Volker Lendecke <vl@samba.org> | 2012-08-20 14:38:42 +0200 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2012-09-23 07:20:20 -0700 |
commit | 982ddc478551c3eb11a6d01acaea22fb60743d2a (patch) | |
tree | dd0765c481b82f3e06a60eb6b3f2ee7dc8423bd7 /source3/libsmb | |
parent | a272635b792a806f589cd5a6a3a345cdc855b4be (diff) | |
download | samba-982ddc478551c3eb11a6d01acaea22fb60743d2a.tar.gz samba-982ddc478551c3eb11a6d01acaea22fb60743d2a.tar.bz2 samba-982ddc478551c3eb11a6d01acaea22fb60743d2a.zip |
s3: Add "readdir" to pylibsmb
Diffstat (limited to 'source3/libsmb')
-rw-r--r-- | source3/libsmb/pylibsmb.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/source3/libsmb/pylibsmb.c b/source3/libsmb/pylibsmb.c index 00fe2d9726..6641918e97 100644 --- a/source3/libsmb/pylibsmb.c +++ b/source3/libsmb/pylibsmb.c @@ -25,6 +25,7 @@ #include "system/select.h" #include "source4/libcli/util/pyerrors.h" #include "auth/credentials/pycredentials.h" +#include "trans2.h" static PyTypeObject *get_pytype(const char *module, const char *type) { @@ -626,6 +627,74 @@ static PyObject *py_cli_delete_on_close(struct py_cli_state *self, return Py_None; } +static PyObject *py_cli_list(struct py_cli_state *self, + PyObject *args, + PyObject *kwds) +{ + char *mask; + unsigned attribute = + FILE_ATTRIBUTE_DIRECTORY | + FILE_ATTRIBUTE_SYSTEM | + FILE_ATTRIBUTE_HIDDEN; + unsigned info_level = SMB_FIND_FILE_BOTH_DIRECTORY_INFO; + struct tevent_req *req; + NTSTATUS status; + struct file_info *finfos; + size_t i, num_finfos; + PyObject *result; + + const char *kwlist[] = { + "mask", "attribute", "info_level", NULL + }; + + if (!PyArg_ParseTupleAndKeywords( + args, kwds, "s|II", (char **)kwlist, + &mask, &attribute, &info_level)) { + return NULL; + } + + req = cli_list_send(NULL, self->ev, self->cli, mask, attribute, + info_level); + if (!py_tevent_req_wait_exc(self->ev, req)) { + return NULL; + } + status = cli_list_recv(req, NULL, &finfos, &num_finfos); + TALLOC_FREE(req); + + if (!NT_STATUS_IS_OK(status)) { + PyErr_SetNTSTATUS(status); + return NULL; + } + + result = Py_BuildValue("[]"); + if (result == NULL) { + return NULL; + } + + for (i=0; i<num_finfos; i++) { + struct file_info *finfo = &finfos[i]; + PyObject *file; + int ret; + + file = Py_BuildValue( + "{s:s,s:i}", + "name", finfo->name, + "mode", (int)finfo->mode); + if (file == NULL) { + Py_XDECREF(result); + return NULL; + } + + ret = PyList_Append(result, file); + if (ret == -1) { + Py_XDECREF(result); + return NULL; + } + } + + return result; +} + static PyMethodDef py_cli_state_methods[] = { { "create", (PyCFunction)py_cli_create, METH_VARARGS|METH_KEYWORDS, "Open a file" }, @@ -641,6 +710,9 @@ static PyMethodDef py_cli_state_methods[] = { { "delete_on_close", (PyCFunction)py_cli_delete_on_close, METH_VARARGS|METH_KEYWORDS, "Set/Reset the delete on close flag" }, + { "readdir", (PyCFunction)py_cli_list, + METH_VARARGS|METH_KEYWORDS, + "List a directory" }, { NULL, NULL, 0, NULL } }; |