~ubuntu-branches/ubuntu/vivid/samba/vivid

« back to all changes in this revision

Viewing changes to source4/lib/ldb/pyldb_util.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-21 13:18:04 UTC
  • mfrom: (0.39.21 sid)
  • Revision ID: package-import@ubuntu.com-20111221131804-xtlr39wx6njehxxr
Tags: 2:3.6.1-3ubuntu1
* Merge from Debian testing.  Remaining changes:
  + debian/patches/VERSION.patch:
    - set SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/patches/error-trans.fix-276472:
    - Add the translation of Unix Error code -ENOTSUP to NT Error Code
    - NT_STATUS_NOT_SUPPORTED to prevent the Permission denied error.
  + debian/smb.conf:
    - add "(Samba, Ubuntu)" to server string.
    - comment out the default [homes] share, and add a comment about
      "valid users = %S" to show users how to restrict access to
      \\server\username to only username.
    - Set 'usershare allow guests', so that usershare admins are 
      allowed to create public shares in addition to authenticated
      ones.
    - add map to guest = Bad user, maps bad username to guest access.
  + debian/samba-common.config:
    - Do not change priority to high if dhclient3 is installed.
    - Use priority medium instead of high for the workgroup question.
  + debian/control:
    - Don't build against or suggest ctdb.
    - Add dependency on samba-common-bin to samba.
  + Add ufw integration:
    - Created debian/samba.ufw.profile
    - debian/rules, debian/samba.dirs, debian/samba.files: install
      profile
    - debian/control: have samba suggest ufw
  + Add apport hook:
    - Created debian/source_samba.py.
    - debian/rules, debian/samba.dirs, debian/samba-common-bin.files: install
  + Switch to upstart:
    - Add debian/samba.{nmbd,smbd}.upstart.
  + debian/samba.logrotate, debian/samba-common.dhcp, debian/samba.if-up:
    - Make them upstart compatible
  + debian/samba.postinst: 
    - Avoid scary pdbedit warnings on first import.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted
  + debian/patches/fix-debuglevel-name-conflict.patch: don't use 'debug_level'
    as a global variable name in an NSS module 
  + Dropped:
    - debian/patches/error-trans.fix-276472
    - debian/patches/fix-debuglevel-name-conflict.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Unix SMB/CIFS implementation.
 
3
 
 
4
   Python interface to ldb - utility functions.
 
5
 
 
6
   Copyright (C) 2007-2010 Jelmer Vernooij <jelmer@samba.org>
 
7
 
 
8
         ** NOTE! The following LGPL license applies to the ldb
 
9
         ** library. This does NOT imply that all of Samba is released
 
10
         ** under the LGPL
 
11
 
 
12
   This library is free software; you can redistribute it and/or
 
13
   modify it under the terms of the GNU Lesser General Public
 
14
   License as published by the Free Software Foundation; either
 
15
   version 3 of the License, or (at your option) any later version.
 
16
 
 
17
   This library is distributed in the hope that it will be useful,
 
18
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
20
   Lesser General Public License for more details.
 
21
 
 
22
   You should have received a copy of the GNU Lesser General Public
 
23
   License along with this library; if not, see <http://www.gnu.org/licenses/>.
 
24
*/
 
25
 
 
26
#include <Python.h>
 
27
#include "ldb.h"
 
28
#include "pyldb.h"
 
29
 
 
30
static PyObject *ldb_module = NULL;
 
31
 
 
32
/* There's no Py_ssize_t in 2.4, apparently */
 
33
#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 5
 
34
typedef int Py_ssize_t;
 
35
typedef inquiry lenfunc;
 
36
typedef intargfunc ssizeargfunc;
 
37
#endif
 
38
 
 
39
#ifndef Py_RETURN_NONE
 
40
#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
 
41
#endif
 
42
 
 
43
 
 
44
/**
 
45
 * Find out PyTypeObject in ldb module for a given typename
 
46
 */
 
47
static PyTypeObject * PyLdb_GetPyType(const char *typename)
 
48
{
 
49
        PyObject *py_obj = NULL;
 
50
 
 
51
        if (ldb_module == NULL) {
 
52
                ldb_module = PyImport_ImportModule("ldb");
 
53
                if (ldb_module == NULL) {
 
54
                        return NULL;
 
55
                }
 
56
        }
 
57
 
 
58
        py_obj = PyObject_GetAttrString(ldb_module, typename);
 
59
 
 
60
        return (PyTypeObject*)py_obj;
 
61
}
 
62
 
 
63
/**
 
64
 * Obtain a ldb DN from a Python object.
 
65
 *
 
66
 * @param mem_ctx Memory context
 
67
 * @param object Python object
 
68
 * @param ldb_ctx LDB context
 
69
 * @return Whether or not the conversion succeeded
 
70
 */
 
71
bool PyObject_AsDn(TALLOC_CTX *mem_ctx, PyObject *object, 
 
72
                   struct ldb_context *ldb_ctx, struct ldb_dn **dn)
 
73
{
 
74
        struct ldb_dn *odn;
 
75
        PyTypeObject *PyLdb_Dn_Type;
 
76
 
 
77
        if (ldb_ctx != NULL && PyString_Check(object)) {
 
78
                odn = ldb_dn_new(mem_ctx, ldb_ctx, PyString_AsString(object));
 
79
                *dn = odn;
 
80
                return true;
 
81
        }
 
82
 
 
83
        PyLdb_Dn_Type = PyLdb_GetPyType("Dn");
 
84
        if (PyLdb_Dn_Type == NULL) {
 
85
                return false;
 
86
        }
 
87
 
 
88
        if (PyObject_TypeCheck(object, PyLdb_Dn_Type)) {
 
89
                *dn = PyLdbDn_AsDn(object);
 
90
                return true;
 
91
        }
 
92
 
 
93
        PyErr_SetString(PyExc_TypeError, "Expected DN");
 
94
        return false;
 
95
}
 
96
 
 
97
PyObject *PyLdbDn_FromDn(struct ldb_dn *dn)
 
98
{
 
99
        PyLdbDnObject *py_ret;
 
100
        PyTypeObject *PyLdb_Dn_Type;
 
101
 
 
102
        if (dn == NULL) {
 
103
                Py_RETURN_NONE;
 
104
        }
 
105
 
 
106
        PyLdb_Dn_Type = PyLdb_GetPyType("Dn");
 
107
        if (PyLdb_Dn_Type == NULL) {
 
108
                return NULL;
 
109
        }
 
110
 
 
111
        py_ret = (PyLdbDnObject *)PyLdb_Dn_Type->tp_alloc(PyLdb_Dn_Type, 0);
 
112
        if (py_ret == NULL) {
 
113
                PyErr_NoMemory();
 
114
                return NULL;
 
115
        }
 
116
        py_ret->mem_ctx = talloc_new(NULL);
 
117
        py_ret->dn = talloc_reference(py_ret->mem_ctx, dn);
 
118
        return (PyObject *)py_ret;
 
119
}