~ubuntu-branches/debian/sid/openchange/sid

« back to all changes in this revision

Viewing changes to pyopenchange/mapistore/pymapistore.c

  • Committer: Package Import Robot
  • Author(s): Jelmer Vernooij
  • Date: 2014-08-15 02:48:41 UTC
  • mfrom: (1.2.9)
  • Revision ID: package-import@ubuntu.com-20140815024841-egnb9akqjw7jvrsl
Tags: 1:2.2-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
97
97
 
98
98
static void openchange_ldb_init(const char *syspath)
99
99
{
100
 
        TALLOC_CTX              *mem_ctx;
101
 
        struct ldb_context      *ldb_ctx;
102
 
        char                    *ldb_path;
103
 
        struct tevent_context   *ev;
104
 
        int                     ret;
105
 
        struct ldb_result       *res;
106
 
        struct ldb_dn           *tmp_dn = NULL;
107
 
        static const char       *attrs[] = {
108
 
                "rootDomainNamingContext",
109
 
                "defaultNamingContext",
110
 
                NULL
111
 
        };
 
100
        TALLOC_CTX              *mem_ctx;
 
101
        struct loadparm_context *lp_ctx;
 
102
        const char              *openchangedb_backend;
112
103
 
113
 
        /* Sanity checks */
114
104
        if (globals.ocdb_ctx) return;
115
105
 
116
 
        /* ev = tevent_context_init(talloc_autofree_context()); */
117
 
        /* if (!ev) { */
118
 
        /*      return NULL; */
119
 
        /* } */
120
 
        ev = NULL;
121
 
 
122
106
        mem_ctx = talloc_zero(NULL, TALLOC_CTX);
123
 
 
124
 
        /* Step 1. Retrieve a LDB context pointer on openchange.ldb database */
125
 
        ldb_ctx = ldb_init(mem_ctx, ev);
126
 
        if (!ldb_ctx) {
127
 
                goto end;
128
 
        }
129
 
 
130
 
        /* Step 2. Connect to the database */
131
 
        ldb_path = talloc_asprintf(mem_ctx, "%s/openchange.ldb", syspath);
132
 
        ret = ldb_connect(ldb_ctx, ldb_path, 0, NULL);
133
 
        if (ret != LDB_SUCCESS) {
134
 
                goto end;
135
 
        }
136
 
 
137
 
        /* Step 3. Search for rootDSE record */
138
 
        ret = ldb_search(ldb_ctx, mem_ctx, &res, ldb_dn_new(mem_ctx, ldb_ctx, "@ROOTDSE"),
139
 
                         LDB_SCOPE_BASE, attrs, NULL);
140
 
        if (ret != LDB_SUCCESS || res->count != 1) {
141
 
                goto end;
142
 
        }
143
 
 
144
 
        /* Step 4. Set opaque naming */
145
 
        tmp_dn = ldb_msg_find_attr_as_dn(ldb_ctx, ldb_ctx, 
146
 
                                         res->msgs[0], "rootDomainNamingContext");
147
 
        ldb_set_opaque(ldb_ctx, "rootDomainNamingContext", tmp_dn);
148
 
        
149
 
        tmp_dn = ldb_msg_find_attr_as_dn(ldb_ctx, ldb_ctx,
150
 
                                         res->msgs[0], "defaultNamingContext");
151
 
        ldb_set_opaque(ldb_ctx, "defaultNamingContext", tmp_dn);
152
 
 
153
 
        globals.ocdb_ctx = ldb_ctx;
 
107
        lp_ctx = loadparm_init_global(true);
 
108
        openchangedb_backend = lpcfg_parm_string(lp_ctx, NULL, "mapiproxy", "openchangedb");
 
109
 
 
110
        if (openchangedb_backend) {
 
111
                openchangedb_mysql_initialize(mem_ctx, lp_ctx, &globals.ocdb_ctx);
 
112
        } else {
 
113
                openchangedb_ldb_initialize(mem_ctx, syspath, &globals.ocdb_ctx);
 
114
        }
 
115
 
 
116
        if (!globals.ocdb_ctx) {
 
117
                PyErr_SetString(PyExc_SystemError, "Cannot initialize openchangedb ldb");
 
118
                goto end;
 
119
        }
154
120
        (void) talloc_reference(NULL, globals.ocdb_ctx);
155
 
        
156
121
end:
157
122
        talloc_free(mem_ctx);
158
123
}
469
434
        .tp_methods = mapistore_methods,
470
435
        /* .tp_getset = mapistore_getsetters, */
471
436
        .tp_new = py_MAPIStore_new,
472
 
        .tp_dealloc = (destructor)py_MAPIStore_dealloc, 
 
437
        .tp_dealloc = (destructor)py_MAPIStore_dealloc,
473
438
        .tp_flags = Py_TPFLAGS_DEFAULT,
474
439
};
475
440
 
476
441
static PyObject *py_mapistore_set_mapping_path(PyObject *mod, PyObject *args)
477
442
{
478
443
        const char      *mapping_path;
479
 
        
 
444
 
480
445
        if (!PyArg_ParseTuple(args, "s", &mapping_path)) {
481
446
                return NULL;
482
447
        }