summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source4/lib/samba3/samba3.c4
-rw-r--r--source4/param/generic.c54
-rw-r--r--source4/param/loadparm.c2
-rw-r--r--source4/param/param.i33
-rw-r--r--source4/param/param.py18
-rw-r--r--source4/param/param_wrap.c290
-rw-r--r--source4/param/tests/bindings.py11
-rw-r--r--source4/scripting/ejs/smbcalls_param.c8
-rw-r--r--source4/scripting/python/misc_wrap.c25
-rw-r--r--source4/scripting/python/samba/__init__.py56
-rw-r--r--source4/scripting/python/samba/provision.py30
-rw-r--r--source4/scripting/python/samba/tests/__init__.py2
-rwxr-xr-xsource4/setup/provision.py12
13 files changed, 414 insertions, 131 deletions
diff --git a/source4/lib/samba3/samba3.c b/source4/lib/samba3/samba3.c
index 74985fab8a..4bd08f188a 100644
--- a/source4/lib/samba3/samba3.c
+++ b/source4/lib/samba3/samba3.c
@@ -36,7 +36,7 @@ NTSTATUS samba3_read_passdb_backends(TALLOC_CTX *ctx, const char *libdir, struct
char *dbfile;
NTSTATUS status = NT_STATUS_OK;
int i;
- const char **backends = param_get_string_list(samba3->configuration, NULL, "passdb backend", NULL);
+ const char **backends = param_get_string_list(samba3->configuration, "passdb backend", NULL, NULL);
/* Default to smbpasswd */
if (backends == NULL)
@@ -59,7 +59,7 @@ NTSTATUS samba3_read_passdb_backends(TALLOC_CTX *ctx, const char *libdir, struct
const char *p = strchr(backends[i], ':');
if (p && p[1]) {
dbfile = talloc_strdup(ctx, p+1);
- } else if ((p = param_get_string(samba3->configuration, NULL, "smb passwd file"))) {
+ } else if ((p = param_get_string(samba3->configuration, "smb passwd file", NULL))) {
dbfile = talloc_strdup(ctx, p);
} else {
dbfile = talloc_strdup(ctx, "/etc/samba/smbpasswd");
diff --git a/source4/param/generic.c b/source4/param/generic.c
index f706dd6407..2327000fc9 100644
--- a/source4/param/generic.c
+++ b/source4/param/generic.c
@@ -49,7 +49,7 @@ struct param_opt *param_section_get(struct param_section *section,
return NULL;
}
-struct param_opt *param_get (struct param_context *ctx, const char *section_name, const char *name)
+struct param_opt *param_get (struct param_context *ctx, const char *name, const char *section_name)
{
struct param_section *section = param_get_section(ctx, section_name);
if (section == NULL)
@@ -58,8 +58,20 @@ struct param_opt *param_get (struct param_context *ctx, const char *section_name
return param_section_get(section, name);
}
+struct param_section *param_add_section(struct param_context *ctx, const char *section_name)
+{
+ struct param_section *section;
+ section = talloc_zero(ctx, struct param_section);
+ if (section == NULL)
+ return NULL;
+
+ section->name = talloc_strdup(section, section_name);
+ DLIST_ADD_END(ctx->sections, section, struct param_section *);
+ return section;
+}
+
/* Look up parameter. If it is not found, add it */
-static struct param_opt *param_get_add(struct param_context *ctx, const char *section_name, const char *name)
+struct param_opt *param_get_add(struct param_context *ctx, const char *name, const char *section_name)
{
struct param_section *section;
struct param_opt *p;
@@ -70,12 +82,7 @@ static struct param_opt *param_get_add(struct param_context *ctx, const char *se
section = param_get_section(ctx, section_name);
if (section == NULL) {
- section = talloc_zero(ctx, struct param_section);
- if (section == NULL)
- return NULL;
-
- section->name = talloc_strdup(section, section_name);
- DLIST_ADD_END(ctx->sections, section, struct param_section *);
+ section = param_add_section(ctx, section_name);
}
p = param_section_get(section, name);
@@ -91,9 +98,9 @@ static struct param_opt *param_get_add(struct param_context *ctx, const char *se
return p;
}
-const char *param_get_string(struct param_context *ctx, const char *section, const char *param)
+const char *param_get_string(struct param_context *ctx, const char *param, const char *section)
{
- struct param_opt *p = param_get(ctx, section, param);
+ struct param_opt *p = param_get(ctx, param, section);
if (p == NULL)
return NULL;
@@ -101,9 +108,9 @@ const char *param_get_string(struct param_context *ctx, const char *section, con
return p->value;
}
-int param_set_string(struct param_context *ctx, const char *section, const char *param, const char *value)
+int param_set_string(struct param_context *ctx, const char *param, const char *value, const char *section)
{
- struct param_opt *p = param_get_add(ctx, section, param);
+ struct param_opt *p = param_get_add(ctx, param, section);
if (p == NULL)
return -1;
@@ -113,10 +120,9 @@ int param_set_string(struct param_context *ctx, const char *section, const char
return 0;
}
-const char **param_get_string_list(struct param_context *ctx, const char *section, const char *param,
- const char *separator)
+const char **param_get_string_list(struct param_context *ctx, const char *param, const char *separator, const char *section)
{
- struct param_opt *p = param_get(ctx, section, param);
+ struct param_opt *p = param_get(ctx, param, section);
if (p == NULL)
return NULL;
@@ -127,18 +133,18 @@ const char **param_get_string_list(struct param_context *ctx, const char *sectio
return str_list_make(ctx, p->value, separator);
}
-int param_set_string_list(struct param_context *ctx, const char *section, const char *param, const char **list)
+int param_set_string_list(struct param_context *ctx, const char *param, const char **list, const char *section)
{
- struct param_opt *p = param_get_add(ctx, section, param);
+ struct param_opt *p = param_get_add(ctx, param, section);
p->value = str_list_join(p, list, ' ');
return 0;
}
-int param_get_int(struct param_context *ctx, const char *section, const char *param, int default_v)
+int param_get_int(struct param_context *ctx, const char *param, int default_v, const char *section)
{
- const char *value = param_get_string(ctx, section, param);
+ const char *value = param_get_string(ctx, param, section);
if (value)
return strtol(value, NULL, 0);
@@ -146,7 +152,7 @@ int param_get_int(struct param_context *ctx, const char *section, const char *pa
return default_v;
}
-void param_set_int(struct param_context *ctx, const char *section, const char *param, int value)
+void param_set_int(struct param_context *ctx, const char *param, int value, const char *section)
{
struct param_opt *p = param_get_add(ctx, section, param);
@@ -156,9 +162,9 @@ void param_set_int(struct param_context *ctx, const char *section, const char *p
p->value = talloc_asprintf(p, "%d", value);
}
-unsigned long param_get_ulong(struct param_context *ctx, const char *section, const char *param, unsigned long default_v)
+unsigned long param_get_ulong(struct param_context *ctx, const char *param, unsigned long default_v, const char *section)
{
- const char *value = param_get_string(ctx, section, param);
+ const char *value = param_get_string(ctx, param, section);
if (value)
return strtoul(value, NULL, 0);
@@ -166,9 +172,9 @@ unsigned long param_get_ulong(struct param_context *ctx, const char *section, co
return default_v;
}
-void param_set_ulong(struct param_context *ctx, const char *section, const char *name, unsigned long value)
+void param_set_ulong(struct param_context *ctx, const char *name, unsigned long value, const char *section)
{
- struct param_opt *p = param_get_add(ctx, section, name);
+ struct param_opt *p = param_get_add(ctx, name, section);
if (!p)
return;
diff --git a/source4/param/loadparm.c b/source4/param/loadparm.c
index 6c23a1d520..51d4beb0ae 100644
--- a/source4/param/loadparm.c
+++ b/source4/param/loadparm.c
@@ -2525,7 +2525,7 @@ struct loadparm_service *lp_service(struct loadparm_context *lp_ctx,
{
int iService;
char *serviceName;
-
+
for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
if (lp_ctx->services[iService] &&
lp_ctx->services[iService]->szService) {
diff --git a/source4/param/param.i b/source4/param/param.i
index d013fa7ae5..3d5deba5ff 100644
--- a/source4/param/param.i
+++ b/source4/param/param.i
@@ -29,6 +29,7 @@ typedef struct param_context param;
typedef struct loadparm_context loadparm_context;
typedef struct loadparm_service loadparm_service;
typedef struct param_section param_section;
+typedef struct param_opt param_opt;
%}
%import "stdint.i"
@@ -55,6 +56,7 @@ typedef struct loadparm_context {
const char *configfile() { return lp_configfile($self); }
bool is_mydomain(const char *domain) { return lp_is_mydomain($self, domain); }
bool is_myname(const char *name) { return lp_is_myname($self, name); }
+ int use(struct param_context *param) { return param_use($self, param); }
}
} loadparm_context;
@@ -76,10 +78,21 @@ typedef struct param_context {
%extend {
param(TALLOC_CTX *mem_ctx) { return param_init(mem_ctx); }
struct param_section *get_section(const char *name);
- struct param_opt *get(const char *section_name, const char *name);
- int set_string(const char *section, const char *param, const char *value);
+ struct param_section *add_section(const char *name);
+ struct param_opt *get(const char *name, const char *section_name="global");
+ const char *get_string(const char *name, const char *section_name="global");
+ int set_string(const char *param, const char *value, const char *section="global");
+ int set(const char *param, PyObject *ob, const char *section_name="global")
+ {
+ struct param_opt *opt = param_get_add($self, param, section_name);
+
+ talloc_free(opt->value);
+ opt->value = talloc_strdup(opt, PyObject_Str(ob));
+
+ return 0;
+ }
+
int read(const char *fn);
- int use(struct param_context *);
int write(const char *fn);
}
%pythoncode {
@@ -91,6 +104,16 @@ typedef struct param_context {
}
} param;
+%talloctype(param_opt);
+
+typedef struct param_opt {
+ %extend {
+#ifdef SWIGPYTHON
+ const char *__str__() { return $self->value; }
+#endif
+ }
+} param_opt;
+
%talloctype(param);
typedef struct param_section {
%extend {
@@ -98,9 +121,9 @@ typedef struct param_section {
}
%pythoncode {
def __getitem__(self, name):
- ret = self.get_section(name)
+ ret = self.get(name)
if ret is None:
- raise KeyError("No such section %s" % name)
+ raise KeyError("No such option %s" % name)
return ret
}
} param_section;
diff --git a/source4/param/param.py b/source4/param/param.py
index aa01d6e830..bd5965aa17 100644
--- a/source4/param/param.py
+++ b/source4/param/param.py
@@ -69,6 +69,7 @@ LoadParm.__getitem__ = new_instancemethod(_param.LoadParm___getitem__,None,LoadP
LoadParm.configfile = new_instancemethod(_param.LoadParm_configfile,None,LoadParm)
LoadParm.is_mydomain = new_instancemethod(_param.LoadParm_is_mydomain,None,LoadParm)
LoadParm.is_myname = new_instancemethod(_param.LoadParm_is_myname,None,LoadParm)
+LoadParm.use = new_instancemethod(_param.LoadParm_use,None,LoadParm)
LoadParm_swigregister = _param.LoadParm_swigregister
LoadParm_swigregister(LoadParm)
@@ -95,21 +96,32 @@ class ParamFile(object):
__swig_destroy__ = _param.delete_ParamFile
ParamFile.get_section = new_instancemethod(_param.ParamFile_get_section,None,ParamFile)
+ParamFile.add_section = new_instancemethod(_param.ParamFile_add_section,None,ParamFile)
ParamFile.get = new_instancemethod(_param.ParamFile_get,None,ParamFile)
+ParamFile.get_string = new_instancemethod(_param.ParamFile_get_string,None,ParamFile)
ParamFile.set_string = new_instancemethod(_param.ParamFile_set_string,None,ParamFile)
+ParamFile.set = new_instancemethod(_param.ParamFile_set,None,ParamFile)
ParamFile.read = new_instancemethod(_param.ParamFile_read,None,ParamFile)
-ParamFile.use = new_instancemethod(_param.ParamFile_use,None,ParamFile)
ParamFile.write = new_instancemethod(_param.ParamFile_write,None,ParamFile)
ParamFile_swigregister = _param.ParamFile_swigregister
ParamFile_swigregister(ParamFile)
+class param_opt(object):
+ thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
+ def __init__(self): raise AttributeError, "No constructor defined"
+ __repr__ = _swig_repr
+ __swig_destroy__ = _param.delete_param_opt
+param_opt.__str__ = new_instancemethod(_param.param_opt___str__,None,param_opt)
+param_opt_swigregister = _param.param_opt_swigregister
+param_opt_swigregister(param_opt)
+
class param_section(object):
thisown = _swig_property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc='The membership flag')
__repr__ = _swig_repr
def __getitem__(self, name):
- ret = self.get_section(name)
+ ret = self.get(name)
if ret is None:
- raise KeyError("No such section %s" % name)
+ raise KeyError("No such option %s" % name)
return ret
def __init__(self, *args, **kwargs):
diff --git a/source4/param/param_wrap.c b/source4/param/param_wrap.c
index 7f0b8c865b..ab54bca381 100644
--- a/source4/param/param_wrap.c
+++ b/source4/param/param_wrap.c
@@ -2522,6 +2522,7 @@ typedef struct param_context param;
typedef struct loadparm_context loadparm_context;
typedef struct loadparm_service loadparm_service;
typedef struct param_section param_section;
+typedef struct param_opt param_opt;
SWIGINTERN loadparm_context *new_loadparm_context(TALLOC_CTX *mem_ctx){ return loadparm_init(mem_ctx); }
@@ -2639,12 +2640,23 @@ SWIG_FromCharPtr(const char *cptr)
SWIGINTERN bool loadparm_context_is_mydomain(loadparm_context *self,char const *domain){ return lp_is_mydomain(self, domain); }
SWIGINTERN bool loadparm_context_is_myname(loadparm_context *self,char const *name){ return lp_is_myname(self, name); }
+SWIGINTERN int loadparm_context_use(loadparm_context *self,struct param_context *param){ return param_use(self, param); }
SWIGINTERN void delete_loadparm_context(loadparm_context *self){ talloc_free(self); }
SWIGINTERN char const *loadparm_service_volume_label(loadparm_service *self){ return volume_label(self); }
SWIGINTERN char const *loadparm_service_printername(loadparm_service *self){ return lp_printername(self); }
SWIGINTERN int loadparm_service_maxprintjobs(loadparm_service *self){ return lp_maxprintjobs(self); }
SWIGINTERN param *new_param(TALLOC_CTX *mem_ctx){ return param_init(mem_ctx); }
+SWIGINTERN int param_set(param *self,char const *param,PyObject *ob,char const *section_name){
+ struct param_opt *opt = param_get_add(self, param, section_name);
+
+ talloc_free(opt->value);
+ opt->value = talloc_strdup(opt, PyObject_Str(ob));
+
+ return 0;
+ }
SWIGINTERN void delete_param(param *self){ talloc_free(self); }
+SWIGINTERN char const *param_opt___str__(param_opt *self){ return self->value; }
+SWIGINTERN void delete_param_opt(param_opt *self){ talloc_free(self); }
#ifdef __cplusplus
extern "C" {
#endif
@@ -2901,6 +2913,47 @@ fail:
}
+SWIGINTERN PyObject *_wrap_LoadParm_use(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
+ PyObject *resultobj = 0;
+ loadparm_context *arg1 = (loadparm_context *) 0 ;
+ struct param_context *arg2 = (struct param_context *) 0 ;
+ int result;
+ void *argp1 = 0 ;
+ int res1 = 0 ;
+ void *argp2 = 0 ;
+ int res2 = 0 ;
+ PyObject * obj0 = 0 ;
+ PyObject * obj1 = 0 ;
+ char * kwnames[] = {
+ (char *) "self",(char *) "param", NULL
+ };
+
+ {
+ arg1 = loadparm_init(NULL);
+ }
+ if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"|OO:LoadParm_use",kwnames,&obj0,&obj1)) SWIG_fail;
+ if (obj0) {
+ res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_loadparm_context, 0 | 0 );
+ if (!SWIG_IsOK(res1)) {
+ SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "LoadParm_use" "', argument " "1"" of type '" "loadparm_context *""'");
+ }
+ arg1 = (loadparm_context *)(argp1);
+ }
+ if (obj1) {
+ res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_param_context, 0 | 0 );
+ if (!SWIG_IsOK(res2)) {
+ SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "LoadParm_use" "', argument " "2"" of type '" "struct param_context *""'");
+ }
+ arg2 = (struct param_context *)(argp2);
+ }
+ result = (int)loadparm_context_use(arg1,arg2);
+ resultobj = SWIG_From_int((int)(result));
+ return resultobj;
+fail:
+ return NULL;
+}
+
+
SWIGINTERN PyObject *_wrap_delete_LoadParm(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
PyObject *resultobj = 0;
loadparm_context *arg1 = (loadparm_context *) 0 ;
@@ -3072,11 +3125,48 @@ fail:
}
+SWIGINTERN PyObject *_wrap_ParamFile_add_section(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
+ PyObject *resultobj = 0;
+ param *arg1 = (param *) 0 ;
+ char *arg2 = (char *) 0 ;
+ struct param_section *result = 0 ;
+ void *argp1 = 0 ;
+ int res1 = 0 ;
+ int res2 ;
+ char *buf2 = 0 ;
+ int alloc2 = 0 ;
+ PyObject * obj0 = 0 ;
+ PyObject * obj1 = 0 ;
+ char * kwnames[] = {
+ (char *) "self",(char *) "name", NULL
+ };
+
+ if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:ParamFile_add_section",kwnames,&obj0,&obj1)) SWIG_fail;
+ res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_param_context, 0 | 0 );
+ if (!SWIG_IsOK(res1)) {
+ SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ParamFile_add_section" "', argument " "1"" of type '" "param *""'");
+ }
+ arg1 = (param *)(argp1);
+ res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2);
+ if (!SWIG_IsOK(res2)) {
+ SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ParamFile_add_section" "', argument " "2"" of type '" "char const *""'");
+ }
+ arg2 = (char *)(buf2);
+ result = (struct param_section *)param_add_section(arg1,(char const *)arg2);
+ resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_param_section, 0 | 0 );
+ if (alloc2 == SWIG_NEWOBJ) free((char*)buf2);
+ return resultobj;
+fail:
+ if (alloc2 == SWIG_NEWOBJ) free((char*)buf2);
+ return NULL;
+}
+
+
SWIGINTERN PyObject *_wrap_ParamFile_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
PyObject *resultobj = 0;
param *arg1 = (param *) 0 ;
char *arg2 = (char *) 0 ;
- char *arg3 = (char *) 0 ;
+ char *arg3 = (char *) "global" ;
struct param_opt *result = 0 ;
void *argp1 = 0 ;
int res1 = 0 ;
@@ -3090,10 +3180,10 @@ SWIGINTERN PyObject *_wrap_ParamFile_get(PyObject *SWIGUNUSEDPARM(self), PyObjec
PyObject * obj1 = 0 ;
PyObject * obj2 = 0 ;
char * kwnames[] = {
- (char *) "self",(char *) "section_name",(char *) "name", NULL
+ (char *) "self",(char *) "name",(char *) "section_name", NULL
};
- if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OOO:ParamFile_get",kwnames,&obj0,&obj1,&obj2)) SWIG_fail;
+ if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO|O:ParamFile_get",kwnames,&obj0,&obj1,&obj2)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_param_context, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ParamFile_get" "', argument " "1"" of type '" "param *""'");
@@ -3104,11 +3194,13 @@ SWIGINTERN PyObject *_wrap_ParamFile_get(PyObject *SWIGUNUSEDPARM(self), PyObjec
SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ParamFile_get" "', argument " "2"" of type '" "char const *""'");
}
arg2 = (char *)(buf2);
- res3 = SWIG_AsCharPtrAndSize(obj2, &buf3, NULL, &alloc3);
- if (!SWIG_IsOK(res3)) {
- SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "ParamFile_get" "', argument " "3"" of type '" "char const *""'");
+ if (obj2) {
+ res3 = SWIG_AsCharPtrAndSize(obj2, &buf3, NULL, &alloc3);
+ if (!SWIG_IsOK(res3)) {
+ SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "ParamFile_get" "', argument " "3"" of type '" "char const *""'");
+ }
+ arg3 = (char *)(buf3);
}
- arg3 = (char *)(buf3);
result = (struct param_opt *)param_get(arg1,(char const *)arg2,(char const *)arg3);
resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_param_opt, 0 | 0 );
if (alloc2 == SWIG_NEWOBJ) free((char*)buf2);
@@ -3121,12 +3213,63 @@ fail:
}
+SWIGINTERN PyObject *_wrap_ParamFile_get_string(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
+ PyObject *resultobj = 0;
+ param *arg1 = (param *) 0 ;
+ char *arg2 = (char *) 0 ;
+ char *arg3 = (char *) "global" ;
+ char *result = 0 ;
+ void *argp1 = 0 ;
+ int res1 = 0 ;
+ int res2 ;
+ char *buf2 = 0 ;
+ int alloc2 = 0 ;
+ int res3 ;
+ char *buf3 = 0 ;
+ int alloc3 = 0 ;
+ PyObject * obj0 = 0 ;
+ PyObject * obj1 = 0 ;
+ PyObject * obj2 = 0 ;
+ char * kwnames[] = {
+ (char *) "self",(char *) "name",(char *) "section_name", NULL
+ };
+
+ if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO|O:ParamFile_get_string",kwnames,&obj0,&obj1,&obj2)) SWIG_fail;
+ res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_param_context, 0 | 0 );
+ if (!SWIG_IsOK(res1)) {
+ SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ParamFile_get_string" "', argument " "1"" of type '" "param *""'");
+ }
+ arg1 = (param *)(argp1);
+ res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2);
+ if (!SWIG_IsOK(res2)) {
+ SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ParamFile_get_string" "', argument " "2"" of type '" "char const *""'");
+ }
+ arg2 = (char *)(buf2);
+ if (obj2) {
+ res3 = SWIG_AsCharPtrAndSize(obj2, &buf3, NULL, &alloc3);
+ if (!SWIG_IsOK(res3)) {
+ SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "ParamFile_get_string" "', argument " "3"" of type '" "char const *""'");
+ }
+ arg3 = (char *)(buf3);
+ }
+ result = (char *)param_get_string(arg1,(char const *)arg2,(char const *)arg3);
+ resultobj = SWIG_FromCharPtr((const char *)result);
+ if (alloc2 == SWIG_NEWOBJ) free((char*)buf2);
+ if (alloc3 == SWIG_NEWOBJ) free((char*)buf3);
+ return resultobj;
+fail:
+ if (alloc2 == SWIG_NEWOBJ) free((char*)buf2);
+ if (alloc3 == SWIG_NEWOBJ) free((char*)buf3);
+ return NULL;
+}
+
+
SWIGINTERN PyObject *_wrap_ParamFile_set_string(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
PyObject *resultobj = 0;
param *arg1 = (param *) 0 ;
char *arg2 = (char *) 0 ;
char *arg3 = (char *) 0 ;
- char *arg4 = (char *) 0 ;
+ char *arg4 = (char *) "global" ;
int result;
void *argp1 = 0 ;
int res1 = 0 ;
@@ -3144,10 +3287,10 @@ SWIGINTERN PyObject *_wrap_ParamFile_set_string(PyObject *SWIGUNUSEDPARM(self),
PyObject * obj2 = 0 ;
PyObject * obj3 = 0 ;
char * kwnames[] = {
- (char *) "self",(char *) "section",(char *) "param",(char *) "value", NULL
+ (char *) "self",(char *) "param",(char *) "value",(char *) "section", NULL
};
- if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OOOO:ParamFile_set_string",kwnames,&obj0,&obj1,&obj2,&obj3)) SWIG_fail;
+ if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OOO|O:ParamFile_set_string",kwnames,&obj0,&obj1,&obj2,&obj3)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_param_context, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ParamFile_set_string" "', argument " "1"" of type '" "param *""'");
@@ -3163,11 +3306,13 @@ SWIGINTERN PyObject *_wrap_ParamFile_set_string(PyObject *SWIGUNUSEDPARM(self),
SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "ParamFile_set_string" "', argument " "3"" of type '" "char const *""'");
}
arg3 = (char *)(buf3);
- res4 = SWIG_AsCharPtrAndSize(obj3, &buf4, NULL, &alloc4);
- if (!SWIG_IsOK(res4)) {
- SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "ParamFile_set_string" "', argument " "4"" of type '" "char const *""'");
+ if (obj3) {
+ res4 = SWIG_AsCharPtrAndSize(obj3, &buf4, NULL, &alloc4);
+ if (!SWIG_IsOK(res4)) {
+ SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "ParamFile_set_string" "', argument " "4"" of type '" "char const *""'");
+ }
+ arg4 = (char *)(buf4);
}
- arg4 = (char *)(buf4);
result = (int)param_set_string(arg1,(char const *)arg2,(char const *)arg3,(char const *)arg4);
resultobj = SWIG_From_int((int)(result));
if (alloc2 == SWIG_NEWOBJ) free((char*)buf2);
@@ -3182,73 +3327,93 @@ fail:
}
-SWIGINTERN PyObject *_wrap_ParamFile_read(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
+SWIGINTERN PyObject *_wrap_ParamFile_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
PyObject *resultobj = 0;
param *arg1 = (param *) 0 ;
char *arg2 = (char *) 0 ;
+ PyObject *arg3 = (PyObject *) 0 ;
+ char *arg4 = (char *) "global" ;
int result;
void *argp1 = 0 ;
int res1 = 0 ;
int res2 ;
char *buf2 = 0 ;
int alloc2 = 0 ;
+ int res4 ;
+ char *buf4 = 0 ;
+ int alloc4 = 0 ;
PyObject * obj0 = 0 ;
PyObject * obj1 = 0 ;
+ PyObject * obj2 = 0 ;
+ PyObject * obj3 = 0 ;
char * kwnames[] = {
- (char *) "self",(char *) "fn", NULL
+ (char *) "self",(char *) "param",(char *) "ob",(char *) "section_name", NULL
};
- if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:ParamFile_read",kwnames,&obj0,&obj1)) SWIG_fail;
+ if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OOO|O:ParamFile_set",kwnames,&obj0,&obj1,&obj2,&obj3)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_param_context, 0 | 0 );
if (!SWIG_IsOK(res1)) {
- SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ParamFile_read" "', argument " "1"" of type '" "param *""'");
+ SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ParamFile_set" "', argument " "1"" of type '" "param *""'");
}
arg1 = (param *)(argp1);
res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2);
if (!SWIG_IsOK(res2)) {
- SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ParamFile_read" "', argument " "2"" of type '" "char const *""'");
+ SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ParamFile_set" "', argument " "2"" of type '" "char const *""'");
}
arg2 = (char *)(buf2);
- result = (int)param_read(arg1,(char const *)arg2);
+ arg3 = obj2;
+ if (obj3) {
+ res4 = SWIG_AsCharPtrAndSize(obj3, &buf4, NULL, &alloc4);
+ if (!SWIG_IsOK(res4)) {
+ SWIG_exception_fail(SWIG_ArgError(res4), "in method '" "ParamFile_set" "', argument " "4"" of type '" "char const *""'");
+ }
+ arg4 = (char *)(buf4);
+ }
+ result = (int)param_set(arg1,(char const *)arg2,arg3,(char const *)arg4);
resultobj = SWIG_From_int((int)(result));
if (alloc2 == SWIG_NEWOBJ) free((char*)buf2);
+ if (alloc4 == SWIG_NEWOBJ) free((char*)buf4);
return resultobj;
fail:
if (alloc2 == SWIG_NEWOBJ) free((char*)buf2);
+ if (alloc4 == SWIG_NEWOBJ) free((char*)buf4);
return NULL;
}
-SWIGINTERN PyObject *_wrap_ParamFile_use(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
+SWIGINTERN PyObject *_wrap_ParamFile_read(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
PyObject *resultobj = 0;
param *arg1 = (param *) 0 ;
- struct param_context *arg2 = (struct param_context *) 0 ;
+ char *arg2 = (char *) 0 ;
int result;
void *argp1 = 0 ;
int res1 = 0 ;
- void *argp2 = 0 ;
- int res2 = 0 ;
+ int res2 ;
+ char *buf2 = 0 ;
+ int alloc2 = 0 ;
PyObject * obj0 = 0 ;
PyObject * obj1 = 0 ;
char * kwnames[] = {
- (char *) "self",(char *)"arg2", NULL
+ (char *) "self",(char *) "fn", NULL
};
- if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:ParamFile_use",kwnames,&obj0,&obj1)) SWIG_fail;
+ if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)"OO:ParamFile_read",kwnames,&obj0,&obj1)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_param_context, 0 | 0 );
if (!SWIG_IsOK(res1)) {
- SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ParamFile_use" "', argument " "1"" of type '" "param *""'");
+ SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "ParamFile_read" "', argument " "1"" of type '" "param *""'");
}
arg1 = (param *)(argp1);
- res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_param_context, 0 | 0 );
+ res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2);
if (!SWIG_IsOK(res2)) {
- SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ParamFile_use" "', argument " "2"" of type '" "struct param_context *""'");
+ SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "ParamFile_read" "', argument " "2"" of type '" "char const *""'");
}
- arg2 = (struct param_context *)(argp2);
- result = (int)param_use(arg1,arg2);
+ arg2 = (char *)(buf2);
+ result = (int)param_read(arg1,(char const *)arg2);
resultobj = SWIG_From_int((int)(result));
+ if (alloc2 == SWIG_NEWOBJ) free((char*)buf2);
return resultobj;
fail:
+ if (alloc2 == SWIG_NEWOBJ) free((char*)buf2);
return NULL;
}
@@ -3324,6 +3489,59 @@ SWIGINTERN PyObject *ParamFile_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject
return SWIG_Python_InitShadowInstance(args);
}
+SWIGINTERN PyObject *_wrap_param_opt___str__(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
+ PyObject *resultobj = 0;
+ param_opt *arg1 = (param_opt *) 0 ;
+ char *result = 0 ;
+ void *argp1 = 0 ;
+ int res1 = 0 ;
+ PyObject *swig_obj[1] ;
+
+ if (!args) SWIG_fail;
+ swig_obj[0] = args;
+ res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_param_opt, 0 | 0 );
+ if (!SWIG_IsOK(res1)) {
+ SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "param_opt___str__" "', argument " "1"" of type '" "param_opt *""'");
+ }
+ arg1 = (param_opt *)(argp1);
+ result = (char *)param_opt___str__(arg1);
+ resultobj = SWIG_FromCharPtr((const char *)result);
+ return resultobj;
+fail:
+ return NULL;
+}
+
+
+SWIGINTERN PyObject *_wrap_delete_param_opt(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
+ PyObject *resultobj = 0;
+ param_opt *arg1 = (param_opt *) 0 ;
+ void *argp1 = 0 ;
+ int res1 = 0 ;
+ PyObject *swig_obj[1] ;
+
+ if (!args) SWIG_fail;
+ swig_obj[0] = args;
+ res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_param_opt, SWIG_POINTER_DISOWN | 0 );
+ if (!SWIG_IsOK(res1)) {
+ SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "delete_param_opt" "', argument " "1"" of type '" "param_opt *""'");
+ }
+ arg1 = (param_opt *)(argp1);
+ delete_param_opt(arg1);
+
+ resultobj = SWIG_Py_Void();
+ return resultobj;
+fail:
+ return NULL;
+}
+
+
+SWIGINTERN PyObject *param_opt_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
+ PyObject *obj;
+ if (!SWIG_Python_UnpackTuple(args,(char*)"swigregister", 1, 1,&obj)) return NULL;
+ SWIG_TypeNewClientData(SWIGTYPE_p_param_opt, SWIG_NewClientData(obj));
+ return SWIG_Py_Void();
+}
+
SWIGINTERN PyObject *_wrap_param_section_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {
PyObject *resultobj = 0;
param_section *arg1 = (param_section *) 0 ;
@@ -3439,6 +3657,7 @@ static PyMethodDef SwigMethods[] = {
{ (char *)"LoadParm_configfile", (PyCFunction) _wrap_LoadParm_configfile, METH_VARARGS | METH_KEYWORDS, NULL},
{ (char *)"LoadParm_is_mydomain", (PyCFunction) _wrap_LoadParm_is_mydomain, METH_VARARGS | METH_KEYWORDS, NULL},
{ (char *)"LoadParm_is_myname", (PyCFunction) _wrap_LoadParm_is_myname, METH_VARARGS | METH_KEYWORDS, NULL},
+ { (char *)"LoadParm_use", (PyCFunction) _wrap_LoadParm_use, METH_VARARGS | METH_KEYWORDS, NULL},
{ (char *)"delete_LoadParm", (PyCFunction) _wrap_delete_LoadParm, METH_VARARGS | METH_KEYWORDS, NULL},
{ (char *)"LoadParm_swigregister", LoadParm_swigregister, METH_VARARGS, NULL},
{ (char *)"LoadParm_swiginit", LoadParm_swiginit, METH_VARARGS, NULL},
@@ -3448,14 +3667,19 @@ static PyMethodDef SwigMethods[] = {
{ (char *)"loadparm_service_swigregister", loadparm_service_swigregister, METH_VARARGS, NULL},
{ (char *)"new_ParamFile", (PyCFunction)_wrap_new_ParamFile, METH_NOARGS, NULL},
{ (char *)"ParamFile_get_section", (PyCFunction) _wrap_ParamFile_get_section, METH_VARARGS | METH_KEYWORDS, NULL},
+ { (char *)"ParamFile_add_section", (PyCFunction) _wrap_ParamFile_add_section, METH_VARARGS | METH_KEYWORDS, NULL},
{ (char *)"ParamFile_get", (PyCFunction) _wrap_ParamFile_get, METH_VARARGS | METH_KEYWORDS, NULL},
+ { (char *)"ParamFile_get_string", (PyCFunction) _wrap_ParamFile_get_string, METH_VARARGS | METH_KEYWORDS, NULL},
{ (char *)"ParamFile_set_string", (PyCFunction) _wrap_ParamFile_set_string, METH_VARARGS | METH_KEYWORDS, NULL},
+ { (char *)"ParamFile_set", (PyCFunction) _wrap_ParamFile_set, METH_VARARGS | METH_KEYWORDS, NULL},
{ (char *)"ParamFile_read", (PyCFunction) _wrap_ParamFile_read, METH_VARARGS | METH_KEYWORDS, NULL},
- { (char *)"ParamFile_use", (PyCFunction) _wrap_ParamFile_use, METH_VARARGS | METH_KEYWORDS, NULL},
{ (char *)"ParamFile_write", (PyCFunction) _wrap_ParamFile_write, METH_VARARGS | METH_KEYWORDS, NULL},
{ (char *)"delete_ParamFile", (PyCFunction)_wrap_delete_ParamFile, METH_O, NULL},
{ (char *)"ParamFile_swigregister", ParamFile_swigregister, METH_VARARGS, NULL},
{ (char *)"ParamFile_swiginit", ParamFile_swiginit, METH_VARARGS, NULL},
+ { (char *)"param_opt___str__", (PyCFunction)_wrap_param_opt___str__, METH_O, NULL},
+ { (char *)"delete_param_opt", (PyCFunction)_wrap_delete_param_opt, METH_O, NULL},
+ { (char *)"param_opt_swigregister", param_opt_swigregister, METH_VARARGS, NULL},
{ (char *)"param_section_get", (PyCFunction) _wrap_param_section_get, METH_VARARGS | METH_KEYWORDS, NULL},
{ (char *)"new_param_section", (PyCFunction)_wrap_new_param_section, METH_NOARGS, NULL},
{ (char *)"delete_param_section", (PyCFunction)_wrap_delete_param_section, METH_O, NULL},
@@ -3474,7 +3698,7 @@ static swig_type_info _swigt__p_loadparm_context = {"_p_loadparm_context", "stru
static swig_type_info _swigt__p_loadparm_service = {"_p_loadparm_service", "struct loadparm_service *|loadparm_service *", 0, 0, (void*)0, 0};
static swig_type_info _swigt__p_long_long = {"_p_long_long", "int_least64_t *|int_fast64_t *|int64_t *|long long *|intmax_t *", 0, 0, (void*)0, 0};
static swig_type_info _swigt__p_param_context = {"_p_param_context", "struct param_context *|param *", 0, 0, (void*)0, 0};
-static swig_type_info _swigt__p_param_opt = {"_p_param_opt", "struct param_opt *", 0, 0, (void*)0, 0};
+static swig_type_info _swigt__p_param_opt = {"_p_param_opt", "struct param_opt *|param_opt *", 0, 0, (void*)0, 0};
static swig_type_info _swigt__p_param_section = {"_p_param_section", "struct param_section *|param_section *", 0, 0, (void*)0, 0};
static swig_type_info _swigt__p_short = {"_p_short", "short *|int_least16_t *|int16_t *", 0, 0, (void*)0, 0};
static swig_type_info _swigt__p_signed_char = {"_p_signed_char", "signed char *|int_least8_t *|int_fast8_t *|int8_t *", 0, 0, (void*)0, 0};
diff --git a/source4/param/tests/bindings.py b/source4/param/tests/bindings.py
index 57ad23b21e..11f8a299be 100644
--- a/source4/param/tests/bindings.py
+++ b/source4/param/tests/bindings.py
@@ -35,6 +35,17 @@ class ParamTestCase(unittest.TestCase):
file = param.ParamFile()
self.assertTrue(file is not None)
+ def test_add_section(self):
+ file = param.ParamFile()
+ file.add_section("global")
+ self.assertTrue(file["global"] is not None)
+
+ def test_set_param_string(self):
+ file = param.ParamFile()
+ file.add_section("global")
+ file["global"]["data"] = "bar"
+ self.assertEquals("bar", file["global"]["data"])
+
def test_get_section(self):
file = param.ParamFile()
self.assertEquals(None, file.get_section("unknown"))
diff --git a/source4/scripting/ejs/smbcalls_param.c b/source4/scripting/ejs/smbcalls_param.c
index 830c45d978..5fbb0bb017 100644
--- a/source4/scripting/ejs/smbcalls_param.c
+++ b/source4/scripting/ejs/smbcalls_param.c
@@ -45,7 +45,7 @@ static int ejs_param_get(MprVarHandle eid, int argc, char **argv)
if (argc == 2) {
ret = param_get_string(ctx, argv[0], argv[1]);
} else {
- ret = param_get_string(ctx, NULL, argv[0]);
+ ret = param_get_string(ctx, argv[0], NULL);
}
if (ret) {
@@ -78,7 +78,7 @@ static int ejs_param_get_list(MprVarHandle eid, int argc, char **argv)
if (argc == 2) {
ret = param_get_string_list(ctx, argv[0], argv[1], NULL);
} else {
- ret = param_get_string_list(ctx, NULL, argv[0], NULL);
+ ret = param_get_string_list(ctx, argv[0], NULL, NULL);
}
if (ret != NULL) {
@@ -123,9 +123,9 @@ static int ejs_param_set(MprVarHandle eid, int argc, struct MprVar **argv)
list = mprToList(mprMemCtx(), value);
if (list) {
- ret = param_set_string_list(ctx, section, paramname, list);
+ ret = param_set_string_list(ctx, paramname, list, section);
} else {
- ret = param_set_string(ctx, section, paramname, mprToString(value));
+ ret = param_set_string(ctx, paramname, mprToString(value), section);
}
mpr_Return(eid, mprCreateBoolVar(ret));
diff --git a/source4/scripting/python/misc_wrap.c b/source4/scripting/python/misc_wrap.c
index f5e23d0407..25b6389f6a 100644
--- a/source4/scripting/python/misc_wrap.c
+++ b/source4/scripting/python/misc_wrap.c
@@ -2474,16 +2474,17 @@ SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags)
#define SWIGTYPE_p_loadparm_service swig_types[12]
#define SWIGTYPE_p_long_long swig_types[13]
#define SWIGTYPE_p_param_context swig_types[14]
-#define SWIGTYPE_p_param_section swig_types[15]
-#define SWIGTYPE_p_short swig_types[16]
-#define SWIGTYPE_p_signed_char swig_types[17]
-#define SWIGTYPE_p_unsigned_char swig_types[18]
-#define SWIGTYPE_p_unsigned_int swig_types[19]
-#define SWIGTYPE_p_unsigned_long swig_types[20]
-#define SWIGTYPE_p_unsigned_long_long swig_types[21]
-#define SWIGTYPE_p_unsigned_short swig_types[22]
-static swig_type_info *swig_types[24];
-static swig_module_info swig_module = {swig_types, 23, 0, 0, 0, 0};
+#define SWIGTYPE_p_param_opt swig_types[15]
+#define SWIGTYPE_p_param_section swig_types[16]
+#define SWIGTYPE_p_short swig_types[17]
+#define SWIGTYPE_p_signed_char swig_types[18]
+#define SWIGTYPE_p_unsigned_char swig_types[19]
+#define SWIGTYPE_p_unsigned_int swig_types[20]
+#define SWIGTYPE_p_unsigned_long swig_types[21]
+#define SWIGTYPE_p_unsigned_long_long swig_types[22]
+#define SWIGTYPE_p_unsigned_short swig_types[23]
+static swig_type_info *swig_types[25];
+static swig_module_info swig_module = {swig_types, 24, 0, 0, 0, 0};
#define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name)
#define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name)
@@ -2896,6 +2897,7 @@ static swig_type_info _swigt__p_loadparm_context = {"_p_loadparm_context", "stru
static swig_type_info _swigt__p_loadparm_service = {"_p_loadparm_service", "struct loadparm_service *|loadparm_service *", 0, 0, (void*)0, 0};
static swig_type_info _swigt__p_long_long = {"_p_long_long", "int_least64_t *|int_fast64_t *|int64_t *|long long *|intmax_t *", 0, 0, (void*)0, 0};
static swig_type_info _swigt__p_param_context = {"_p_param_context", "struct param_context *|param *", 0, 0, (void*)0, 0};
+static swig_type_info _swigt__p_param_opt = {"_p_param_opt", "struct param_opt *|param_opt *", 0, 0, (void*)0, 0};
static swig_type_info _swigt__p_param_section = {"_p_param_section", "struct param_section *|param_section *", 0, 0, (void*)0, 0};
static swig_type_info _swigt__p_short = {"_p_short", "short *|int_least16_t *|int16_t *", 0, 0, (void*)0, 0};
static swig_type_info _swigt__p_signed_char = {"_p_signed_char", "signed char *|int_least8_t *|int_fast8_t *|int8_t *", 0, 0, (void*)0, 0};
@@ -2921,6 +2923,7 @@ static swig_type_info *swig_type_initial[] = {
&_swigt__p_loadparm_service,
&_swigt__p_long_long,
&_swigt__p_param_context,
+ &_swigt__p_param_opt,
&_swigt__p_param_section,
&_swigt__p_short,
&_swigt__p_signed_char,
@@ -2946,6 +2949,7 @@ static swig_cast_info _swigc__p_loadparm_context[] = { {&_swigt__p_loadparm_con
static swig_cast_info _swigc__p_loadparm_service[] = { {&_swigt__p_loadparm_service, 0, 0, 0},{0, 0, 0, 0}};
static swig_cast_info _swigc__p_long_long[] = { {&_swigt__p_long_long, 0, 0, 0},{0, 0, 0, 0}};
static swig_cast_info _swigc__p_param_context[] = { {&_swigt__p_param_context, 0, 0, 0},{0, 0, 0, 0}};
+static swig_cast_info _swigc__p_param_opt[] = { {&_swigt__p_param_opt, 0, 0, 0},{0, 0, 0, 0}};
static swig_cast_info _swigc__p_param_section[] = { {&_swigt__p_param_section, 0, 0, 0},{0, 0, 0, 0}};
static swig_cast_info _swigc__p_short[] = { {&_swigt__p_short, 0, 0, 0},{0, 0, 0, 0}};
static swig_cast_info _swigc__p_signed_char[] = { {&_swigt__p_signed_char, 0, 0, 0},{0, 0, 0, 0}};
@@ -2971,6 +2975,7 @@ static swig_cast_info *swig_cast_initial[] = {
_swigc__p_loadparm_service,
_swigc__p_long_long,
_swigc__p_param_context,
+ _swigc__p_param_opt,
_swigc__p_param_section,
_swigc__p_short,
_swigc__p_signed_char,
diff --git a/source4/scripting/python/samba/__init__.py b/source4/scripting/python/samba/__init__.py
index 56adce4473..511dcd905a 100644
--- a/source4/scripting/python/samba/__init__.py
+++ b/source4/scripting/python/samba/__init__.py
@@ -33,11 +33,9 @@ if _in_source_tree():
default_ldb_modules_dir = "%s/bin/modules/ldb" % srcdir
-import misc
import ldb
-ldb.Ldb.set_credentials = misc.ldb_set_credentials
-ldb.Ldb.set_session_info = misc.ldb_set_session_info
-ldb.Ldb.set_loadparm = misc.ldb_set_loadparm
+import credentials
+import misc
class Ldb(ldb.Ldb):
"""Simple Samba-specific LDB subclass that takes care
@@ -47,38 +45,42 @@ class Ldb(ldb.Ldb):
not necessarily the Sam database. For Sam-specific helper
functions see samdb.py.
"""
- def __init__(url, session_info=None, credentials=None, modules_dir=None,
- lp=None):
+ def __init__(self, url=None, session_info=None, credentials=None,
+ modules_dir=None, lp=None):
"""Open a Samba Ldb file.
- :param url: LDB Url to open
+ :param url: Optional LDB URL to open
:param session_info: Optional session information
:param credentials: Optional credentials, defaults to anonymous.
- :param modules_dir: Modules directory, automatically set if not specified.
+ :param modules_dir: Modules directory, if not the default.
:param lp: Loadparm object, optional.
This is different from a regular Ldb file in that the Samba-specific
modules-dir is used by default and that credentials and session_info
can be passed through (required by some modules).
"""
- super(self, Ldb).__init__()
- import ldb
- ret = ldb.Ldb()
- if modules_dir is None:
- modules_dir = default_ldb_modules_dir
+ super(Ldb, self).__init__()
+
if modules_dir is not None:
- ret.set_modules_dir(modules_dir)
- def samba_debug(level,text):
- print "%d %s" % (level, text)
+ self.set_modules_dir(modules_dir)
+ elif default_ldb_modules_dir is not None:
+ self.set_modules_dir(default_ldb_modules_dir)
+
if credentials is not None:
- ldb.set_credentials(credentials)
+ self.set_credentials(self, credentials)
+
if session_info is not None:
- ldb.set_session_info(session_info)
+ self.set_session_info(self, session_info)
+
if lp is not None:
- ldb.set_loadparm(lp)
- #ret.set_debug(samba_debug)
- ret.connect(url)
- return ret
+ self.set_loadparm(self, lp)
+
+ if url:
+ self.connect(url)
+
+ set_credentials = misc.ldb_set_credentials
+ set_session_info = misc.ldb_set_session_info
+ set_loadparm = misc.ldb_set_loadparm
def searchone(self, basedn, expression, attribute):
"""Search for one attribute as a string."""
@@ -93,19 +95,19 @@ class Ldb(ldb.Ldb):
for attr in ["@INDEXLIST", "@ATTRIBUTES", "@SUBCLASSES", "@MODULES",
"@OPTIONS", "@PARTITION", "@KLUDGEACL"]:
try:
- self.delete(Dn(self, attr))
- except LdbError, (LDB_ERR_NO_SUCH_OBJECT, _):
+ self.delete(ldb.Dn(self, attr))
+ except ldb.LdbError, (LDB_ERR_NO_SUCH_OBJECT, _):
# Ignore missing dn errors
pass
- basedn = Dn(self, "")
+ basedn = ldb.Dn(self, "")
# and the rest
- for msg in self.search(basedn, SCOPE_SUBTREE,
+ for msg in self.search(basedn, ldb.SCOPE_SUBTREE,
"(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))",
["dn"]):
self.delete(msg.dn)
- res = self.search(basedn, SCOPE_SUBTREE, "(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))", ["dn"])
+ res = self.search(basedn, ldb.SCOPE_SUBTREE, "(&(|(objectclass=*)(dn=*))(!(dn=@BASEINFO)))", ["dn"])
assert len(res) == 0
diff --git a/source4/scripting/python/samba/provision.py b/source4/scripting/python/samba/provision.py
index 60dcf06c83..5332a9f9ff 100644
--- a/source4/scripting/python/samba/provision.py
+++ b/source4/scripting/python/samba/provision.py
@@ -16,6 +16,7 @@ import param
import registry
from samba import Ldb, substitute_var, valid_netbios_name
from samba.samdb import SamDB
+import security
from ldb import Dn, SCOPE_SUBTREE, SCOPE_ONELEVEL, SCOPE_BASE, LdbError, \
LDB_ERR_NO_SUCH_OBJECT, timestring
@@ -69,7 +70,7 @@ class ProvisionSettings(object):
"DOMAINDN_LDB": self.domaindn_ldb,
"DOMAINDN_MOD": "pdc_fsmo,password_hash",
"DOMAINDN_MOD2": ",objectguid",
- "DOMAINSID": self.domainsid,
+ "DOMAINSID": str(self.domainsid),
"MODULES_LIST": ",".join(self.modules_list),
"CONFIGDN_MOD": "naming_fsmo",
"CONFIGDN_MOD2": ",objectguid",
@@ -115,13 +116,13 @@ class ProvisionSettings(object):
if not valid_netbios_name(self.netbiosname):
raise InvalidNetbiosName(self.netbiosname)
- if lp.get("workgroup").upper() != self.domain.upper():
+ if lp.get_string("workgroup").upper() != self.domain.upper():
raise Error("workgroup '%s' in smb.conf must match chosen domain '%s'\n",
- lp.get("workgroup"), self.domain)
+ lp.get_string("workgroup"), self.domain)
- if lp.get("realm").upper() != self.realm.upper():
+ if lp.get_string("realm").upper() != self.realm.upper():
raise Error("realm '%s' in smb.conf must match chosen realm '%s'\n" %
- (lp.get("realm"), self.realm))
+ (lp.get_string("realm"), self.realm))
class ProvisionPaths:
@@ -147,9 +148,9 @@ class ProvisionPaths:
def install_ok(lp, session_info, credentials):
"""Check whether the current install seems ok."""
- if lp.get("realm") == "":
+ if lp.get_string("realm") == "":
return False
- ldb = Ldb(lp.get("sam database"), session_info=session_info,
+ ldb = Ldb(lp.get_string("sam database"), session_info=session_info,
credentials=credentials)
if len(ldb.search("(cn=Administrator)")) != 1:
return False
@@ -166,7 +167,6 @@ def findnss(nssfn, *names):
raise Exception("Unable to find user/group for %s" % arguments[1])
-
def hostip():
"""return first host IP."""
return gethostbyname(hostname())
@@ -230,7 +230,7 @@ def setup_ldb(setup_dir, ldif, session_info, credentials, subobj, dbname,
ldb.transaction_start()
try:
if erase:
- ldb_erase(ldb);
+ ldb.erase();
setup_add_ldif(setup_dir, ldif, subobj, ldb)
except:
ldb.transaction_cancel()
@@ -271,10 +271,10 @@ def provision_default_paths(lp, subobj):
:param subobj: Object
"""
paths = ProvisionPaths()
- private_dir = lp.get("private dir")
+ private_dir = lp.get_string("private dir")
paths.shareconf = os.path.join(private_dir, "share.ldb")
- paths.samdb = lp.get("sam database") or os.path.join(private_dir, "samdb.ldb")
- paths.secrets = lp.get("secrets database") or os.path.join(private_dir, "secrets.ldb")
+ paths.samdb = lp.get_string("sam database") or os.path.join(private_dir, "samdb.ldb")
+ paths.secrets = lp.get_string("secrets database") or os.path.join(private_dir, "secrets.ldb")
paths.templates = os.path.join(private_dir, "templates.ldb")
paths.keytab = os.path.join(private_dir, "secrets.keytab")
paths.dns = os.path.join(private_dir, subobj.dnsdomain + ".zone")
@@ -572,8 +572,8 @@ def provision_ldapbase(setup_dir, subobj, message, paths):
def provision_guess(lp):
"""guess reasonably default options for provisioning."""
- subobj = ProvisionSettings(realm=lp.get("realm").upper(),
- domain=lp.get("workgroup"),
+ subobj = ProvisionSettings(realm=lp.get_string("realm").upper(),
+ domain=lp.get_string("workgroup"),
hostname=hostname(),
hostip=hostip())
@@ -581,7 +581,7 @@ def provision_guess(lp):
assert subobj.domain is not None
assert subobj.hostname is not None
- subobj.domainsid = sid.random()
+ subobj.domainsid = security.random_sid()
subobj.invocationid = uuid.random()
subobj.policyguid = uuid.random()
subobj.krbtgtpass = misc.random_password(12)
diff --git a/source4/scripting/python/samba/tests/__init__.py b/source4/scripting/python/samba/tests/__init__.py
index d374f8bafa..d3930e217a 100644
--- a/source4/scripting/python/samba/tests/__init__.py
+++ b/source4/scripting/python/samba/tests/__init__.py
@@ -27,7 +27,7 @@ class LdbTestCase(unittest.TestCase):
self.filename = os.tempnam()
self.ldb = samba.Ldb(self.filename)
- def load_modules(self, modules=[]):
+ def set_modules(self, modules=[]):
m = ldb.Message()
m.dn = ldb.Dn(self.ldb, "@MODULES")
m["@LIST"] = ",".join(modules)
diff --git a/source4/setup/provision.py b/source4/setup/provision.py
index 71360cecc8..a65eff1cf8 100755
--- a/source4/setup/provision.py
+++ b/source4/setup/provision.py
@@ -110,15 +110,15 @@ if opts.realm is None or opts.domain is None or opts.host_name is None:
print >>sys.stderr, "No domain set"
if opts.host_name is None:
print >>sys.stderr, "No host name set"
- parser.print_help()
+ parser.print_usage()
sys.exit(1)
# cope with an initially blank smb.conf
-lp = param.ParamFile(opts.configfile)
+lp = param.ParamFile()
+lp.read(opts.configfile)
lp.set("realm", opts.realm);
lp.set("workgroup", opts.domain);
lp.set("server role", opts.server_role);
-lp.use()
subobj = provision_guess(lp)
subobj.domain_guid = opts.domain_guid
@@ -161,12 +161,12 @@ if opts.ldap_base:
message("Please install the LDIF located in %s, %s and into your LDAP server, and re-run with --ldap-backend=ldap://my.ldap.server" % (paths.ldap_basedn_ldif, paths.ldap_config_basedn_ldif, paths.ldap_schema_basedn_ldif))
elif opts.partitions_only:
provision_become_dc(setup_dir, subobj, message, False,
- paths, system_session, creds)
+ paths, system_session(), creds)
else:
provision(lp, setup_dir, subobj, message, opts.blank, paths,
- system_session, creds, opts.ldap_backend)
+ system_session(), creds, opts.ldap_backend)
provision_dns(setup_dir, subobj, message, paths,
- system_session, creds)
+ system_session(), creds)
message("To reproduce this provision, run with:")
message("--realm='" + subobj.realm_conf + "' --domain='" + subobj.domain_conf + "' --domain-guid='" + subobj.domain_guid + "' \\")
message("--policy-guid='" + subobj.policyguid + "' --host-name='" + subobj.hostname + "' --host-ip='" + subobj.hostip + "' \\")