source: vendor/current/source3/param/pyparam.c

Last change on this file was 988, checked in by Silvan Scherrer, 9 years ago

Samba Server: update vendor to version 4.4.3

File size: 2.1 KB
Line 
1/*
2 Unix SMB/CIFS implementation.
3 Samba utility functions
4 Copyright (C) Amitay Isaacs <amitay@gmail.com> 2011
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#include <Python.h>
21#include "includes.h"
22#include "param/param.h"
23#include "param/loadparm.h"
24#include "lib/talloc/pytalloc.h"
25
26static PyTypeObject *loadparm_Type = NULL;
27
28void initparam(void);
29
30static PyObject *py_get_context(PyObject *self)
31{
32 PyObject *py_loadparm;
33 const struct loadparm_s3_helpers *s3_context;
34 const struct loadparm_context *s4_context;
35 TALLOC_CTX *mem_ctx;
36
37 mem_ctx = talloc_new(NULL);
38 if (mem_ctx == NULL) {
39 PyErr_NoMemory();
40 return NULL;
41 }
42
43 s3_context = loadparm_s3_helpers();
44
45 s4_context = loadparm_init_s3(mem_ctx, s3_context);
46 if (s4_context == NULL) {
47 PyErr_NoMemory();
48 return NULL;
49 }
50
51 py_loadparm = pytalloc_steal(loadparm_Type, discard_const_p(struct loadparm_context, s4_context));
52 if (py_loadparm == NULL) {
53 talloc_free(mem_ctx);
54 PyErr_NoMemory();
55 return NULL;
56 }
57
58 talloc_free(mem_ctx);
59
60 return py_loadparm;
61}
62
63static PyMethodDef pyparam_methods[] = {
64 { "get_context", (PyCFunction)py_get_context, METH_NOARGS,
65 "Returns LoadParm context." },
66 { NULL }
67};
68
69void initparam(void)
70{
71 PyObject *m, *mod;
72
73 m = Py_InitModule3("param", pyparam_methods, "Parsing and writing Samba3 configuration files.");
74 if (m == NULL)
75 return;
76
77 mod = PyImport_ImportModule("samba.param");
78 if (mod == NULL) {
79 return;
80 }
81
82 loadparm_Type = (PyTypeObject *)PyObject_GetAttrString(mod, "LoadParm");
83 Py_DECREF(mod);
84 if (loadparm_Type == NULL) {
85 return;
86 }
87}
Note: See TracBrowser for help on using the repository browser.