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

« back to all changes in this revision

Viewing changes to source4/auth/credentials/pycredentials.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:
16
16
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
17
*/
18
18
 
 
19
#include <Python.h>
19
20
#include "includes.h"
20
 
#include <Python.h>
21
21
#include "pycredentials.h"
22
22
#include "param/param.h"
23
23
#include "lib/cmdline/credentials.h"
24
24
#include "librpc/gen_ndr/samr.h" /* for struct samr_Password */
25
25
#include "libcli/util/pyerrors.h"
26
26
#include "param/pyparam.h"
27
 
 
28
 
#ifndef Py_RETURN_NONE
29
 
#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
30
 
#endif
 
27
#include <tevent.h>
31
28
 
32
29
static PyObject *PyString_FromStringOrNULL(const char *str)
33
30
{
196
193
        Py_RETURN_NONE;
197
194
}
198
195
 
 
196
static PyObject *py_creds_set_krb_forwardable(py_talloc_Object *self, PyObject *args)
 
197
{
 
198
        int state;
 
199
        if (!PyArg_ParseTuple(args, "i", &state))
 
200
                return NULL;
 
201
 
 
202
        cli_credentials_set_krb_forwardable(PyCredentials_AsCliCredentials(self), state);
 
203
        Py_RETURN_NONE;
 
204
}
 
205
 
199
206
static PyObject *py_creds_guess(py_talloc_Object *self, PyObject *args)
200
207
{
201
208
        PyObject *py_lp_ctx = Py_None;
202
209
        struct loadparm_context *lp_ctx;
 
210
        TALLOC_CTX *mem_ctx;
 
211
        struct cli_credentials *creds;
 
212
 
 
213
        creds = PyCredentials_AsCliCredentials(self);
 
214
 
203
215
        if (!PyArg_ParseTuple(args, "|O", &py_lp_ctx))
204
216
                return NULL;
205
217
 
206
 
        lp_ctx = lp_from_py_object(py_lp_ctx);
207
 
        if (lp_ctx == NULL) 
208
 
                return NULL;
209
 
 
210
 
        cli_credentials_guess(PyCredentials_AsCliCredentials(self), lp_ctx);
 
218
        mem_ctx = talloc_new(NULL);
 
219
        if (mem_ctx == NULL) {
 
220
                PyErr_NoMemory();
 
221
                return NULL;
 
222
        }
 
223
 
 
224
        lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx);
 
225
        if (lp_ctx == NULL) {
 
226
                talloc_free(mem_ctx);
 
227
                return NULL;
 
228
        }
 
229
 
 
230
        cli_credentials_guess(creds, lp_ctx);
 
231
 
 
232
        talloc_free(mem_ctx);
211
233
 
212
234
        Py_RETURN_NONE;
213
235
}
217
239
        PyObject *py_lp_ctx = Py_None;
218
240
        struct loadparm_context *lp_ctx;
219
241
        NTSTATUS status;
 
242
        struct cli_credentials *creds;
 
243
        TALLOC_CTX *mem_ctx;
 
244
 
 
245
        creds = PyCredentials_AsCliCredentials(self);
 
246
 
220
247
        if (!PyArg_ParseTuple(args, "|O", &py_lp_ctx))
221
248
                return NULL;
222
249
 
223
 
        lp_ctx = lp_from_py_object(py_lp_ctx);
224
 
        if (lp_ctx == NULL) 
225
 
                return NULL;
226
 
 
227
 
        status = cli_credentials_set_machine_account(PyCredentials_AsCliCredentials(self), lp_ctx);
 
250
        mem_ctx = talloc_new(NULL);
 
251
        if (mem_ctx == NULL) {
 
252
                PyErr_NoMemory();
 
253
                return NULL;
 
254
        }
 
255
 
 
256
        lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx);
 
257
        if (lp_ctx == NULL) {
 
258
                talloc_free(mem_ctx);
 
259
                return NULL;
 
260
        }
 
261
 
 
262
        status = cli_credentials_set_machine_account(creds, lp_ctx);
 
263
        talloc_free(mem_ctx);
 
264
 
228
265
        PyErr_NTSTATUS_IS_ERR_RAISE(status);
229
266
 
230
267
        Py_RETURN_NONE;
231
268
}
232
269
 
 
270
PyObject *PyCredentialCacheContainer_from_ccache_container(struct ccache_container *ccc)
 
271
{
 
272
        PyCredentialCacheContainerObject *py_ret;
 
273
 
 
274
        if (ccc == NULL) {
 
275
                Py_RETURN_NONE;
 
276
        }
 
277
 
 
278
        py_ret = (PyCredentialCacheContainerObject *)PyCredentialCacheContainer.tp_alloc(&PyCredentialCacheContainer, 0);
 
279
        if (py_ret == NULL) {
 
280
                PyErr_NoMemory();
 
281
                return NULL;
 
282
        }
 
283
        py_ret->mem_ctx = talloc_new(NULL);
 
284
        py_ret->ccc = talloc_reference(py_ret->mem_ctx, ccc);
 
285
        return (PyObject *)py_ret;
 
286
}
 
287
 
 
288
 
 
289
static PyObject *py_creds_get_named_ccache(py_talloc_Object *self, PyObject *args)
 
290
{
 
291
        PyObject *py_lp_ctx = Py_None;
 
292
        char *ccache_name;
 
293
        struct loadparm_context *lp_ctx;
 
294
        struct ccache_container *ccc;
 
295
        struct tevent_context *event_ctx;
 
296
        int ret;
 
297
        const char *error_string;
 
298
        struct cli_credentials *creds;
 
299
        TALLOC_CTX *mem_ctx;
 
300
 
 
301
        creds = PyCredentials_AsCliCredentials(self);
 
302
 
 
303
        if (!PyArg_ParseTuple(args, "|Os", &py_lp_ctx, &ccache_name))
 
304
                return NULL;
 
305
 
 
306
        mem_ctx = talloc_new(NULL);
 
307
        if (mem_ctx == NULL) {
 
308
                PyErr_NoMemory();
 
309
                return NULL;
 
310
        }
 
311
 
 
312
        lp_ctx = lpcfg_from_py_object(mem_ctx, py_lp_ctx);
 
313
        if (lp_ctx == NULL) {
 
314
                talloc_free(mem_ctx);
 
315
                return NULL;
 
316
        }
 
317
 
 
318
        event_ctx = tevent_context_init(mem_ctx);
 
319
 
 
320
        ret = cli_credentials_get_named_ccache(creds, event_ctx, lp_ctx,
 
321
                                               ccache_name, &ccc, &error_string);
 
322
        talloc_unlink(mem_ctx, lp_ctx);
 
323
        if (ret == 0) {
 
324
                talloc_steal(ccc, event_ctx);
 
325
                talloc_free(mem_ctx);
 
326
                return PyCredentialCacheContainer_from_ccache_container(ccc);
 
327
        }
 
328
 
 
329
        PyErr_SetString(PyExc_RuntimeError, error_string?error_string:"NULL");
 
330
 
 
331
        talloc_free(mem_ctx);
 
332
        return NULL;
 
333
}
 
334
 
 
335
static PyObject *py_creds_set_gensec_features(py_talloc_Object *self, PyObject *args)
 
336
{
 
337
        unsigned int gensec_features;
 
338
 
 
339
        if (!PyArg_ParseTuple(args, "I", &gensec_features))
 
340
                return NULL;
 
341
 
 
342
        cli_credentials_set_gensec_features(PyCredentials_AsCliCredentials(self), gensec_features);
 
343
 
 
344
        Py_RETURN_NONE;
 
345
}
 
346
 
 
347
static PyObject *py_creds_get_gensec_features(py_talloc_Object *self, PyObject *args)
 
348
{
 
349
        unsigned int gensec_features;
 
350
 
 
351
        gensec_features = cli_credentials_get_gensec_features(PyCredentials_AsCliCredentials(self));
 
352
        return PyInt_FromLong(gensec_features);
 
353
}
 
354
 
 
355
 
233
356
static PyMethodDef py_creds_methods[] = {
234
357
        { "get_username", (PyCFunction)py_creds_get_username, METH_NOARGS,
235
358
                "S.get_username() -> username\nObtain username." },
284
407
                NULL },
285
408
        { "set_kerberos_state", (PyCFunction)py_creds_set_kerberos_state, METH_VARARGS,
286
409
                NULL },
 
410
        { "set_krb_forwardable", (PyCFunction)py_creds_set_krb_forwardable, METH_VARARGS,
 
411
                NULL },
287
412
        { "guess", (PyCFunction)py_creds_guess, METH_VARARGS, NULL },
288
413
        { "set_machine_account", (PyCFunction)py_creds_set_machine_account, METH_VARARGS, NULL },
 
414
        { "get_named_ccache", (PyCFunction)py_creds_get_named_ccache, METH_VARARGS, NULL },
 
415
        { "set_gensec_features", (PyCFunction)py_creds_set_gensec_features, METH_VARARGS, NULL },
 
416
        { "get_gensec_features", (PyCFunction)py_creds_get_gensec_features, METH_NOARGS, NULL },
289
417
        { NULL }
290
418
};
291
419
 
292
420
PyTypeObject PyCredentials = {
293
421
        .tp_name = "Credentials",
294
422
        .tp_basicsize = sizeof(py_talloc_Object),
295
 
        .tp_dealloc = py_talloc_dealloc,
296
423
        .tp_new = py_creds_new,
297
424
        .tp_flags = Py_TPFLAGS_DEFAULT,
298
425
        .tp_methods = py_creds_methods,
299
426
};
300
427
 
 
428
 
 
429
PyTypeObject PyCredentialCacheContainer = {
 
430
        .tp_name = "CredentialCacheContainer",
 
431
        .tp_basicsize = sizeof(py_talloc_Object),
 
432
        .tp_flags = Py_TPFLAGS_DEFAULT,
 
433
};
 
434
 
301
435
void initcredentials(void)
302
436
{
303
437
        PyObject *m;
 
438
        PyTypeObject *talloc_type = PyTalloc_GetObjectType();
 
439
        if (talloc_type == NULL)
 
440
                return;
 
441
 
 
442
        PyCredentials.tp_base = PyCredentialCacheContainer.tp_base = talloc_type;
304
443
 
305
444
        if (PyType_Ready(&PyCredentials) < 0)
306
445
                return;
307
446
 
 
447
        if (PyType_Ready(&PyCredentialCacheContainer) < 0)
 
448
                return;
 
449
 
308
450
        m = Py_InitModule3("credentials", NULL, "Credentials management.");
309
451
        if (m == NULL)
310
452
                return;
313
455
        PyModule_AddObject(m, "DONT_USE_KERBEROS", PyInt_FromLong(CRED_DONT_USE_KERBEROS));
314
456
        PyModule_AddObject(m, "MUST_USE_KERBEROS", PyInt_FromLong(CRED_MUST_USE_KERBEROS));
315
457
 
 
458
        PyModule_AddObject(m, "AUTO_KRB_FORWARDABLE",  PyInt_FromLong(CRED_AUTO_KRB_FORWARDABLE));
 
459
        PyModule_AddObject(m, "NO_KRB_FORWARDABLE",    PyInt_FromLong(CRED_NO_KRB_FORWARDABLE));
 
460
        PyModule_AddObject(m, "FORCE_KRB_FORWARDABLE", PyInt_FromLong(CRED_FORCE_KRB_FORWARDABLE));
 
461
 
316
462
        Py_INCREF(&PyCredentials);
317
463
        PyModule_AddObject(m, "Credentials", (PyObject *)&PyCredentials);
 
464
        Py_INCREF(&PyCredentialCacheContainer);
 
465
        PyModule_AddObject(m, "CredentialCacheContainer", (PyObject *)&PyCredentialCacheContainer);
318
466
}