1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

r9805: Add 'data' property to param EJS object

Write out new smb.conf file. Parameters that have disappeared
between Samba 3 and 4 will optionally be prefixed with 'samba3:'
This commit is contained in:
Jelmer Vernooij 2005-08-30 16:09:38 +00:00 committed by Gerald (Jerry) Carter
parent bb0cef581a
commit 27eefbd905
5 changed files with 109 additions and 27 deletions

View File

@ -122,12 +122,14 @@ const char **param_get_string_list(struct param_context *ctx, const char *sectio
return p->list_value;
}
void 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 *section, const char *param, const char **list)
{
struct param *p = param_get_add(ctx, section, param);
p->value = str_list_join(p, list, ' ');
p->list_value = str_list_copy(p, list);
return 0;
}
int param_get_int(struct param_context *ctx, const char *section, const char *param, int default_v)

View File

@ -97,9 +97,12 @@ static int ejs_param_get_list(MprVarHandle eid, int argc, char **argv)
ok = param.set("name", "value");
ok = param.set("section", "name", "value");
*/
static int ejs_param_set(MprVarHandle eid, int argc, char **argv)
static int ejs_param_set(MprVarHandle eid, int argc, struct MprVar **argv)
{
struct param_context *ctx;
const char **list;
const char *section, *paramname;
struct MprVar *value;
bool ret;
if (argc != 2 && argc != 3) {
ejsSetErrorMsg(eid, "param.set invalid argument count");
@ -108,17 +111,66 @@ static int ejs_param_set(MprVarHandle eid, int argc, char **argv)
ctx = mprGetThisPtr(eid, "param");
mprAssert(ctx);
if (argc == 3) {
ret = param_set_string(ctx, argv[0], argv[1], argv[2]);
section = mprToString(argv[0]);
paramname = mprToString(argv[1]);
value = argv[2];
} else {
ret = param_set_string(ctx, NULL, argv[0], argv[2]);
section = NULL;
paramname = mprToString(argv[0]);
value = argv[1];
}
list = mprToList(mprMemCtx(), value);
if (list) {
ret = param_set_string_list(ctx, section, paramname, list);
} else {
ret = param_set_string(ctx, section, paramname, mprToString(value));
}
mpr_Return(eid, mprCreateBoolVar(ret));
return 0;
}
/*
param data as a two-level array
data = param.data;
*/
static int ejs_param_data(MprVarHandle eid, int argc, char **argv)
{
struct param_context *ctx;
struct MprVar ret;
struct param_section *sec;
if (argc != 0) {
ejsSetErrorMsg(eid, "param.data does not take arguments");
return -1;
}
ctx = mprGetThisPtr(eid, "param");
mprAssert(ctx);
ret = mprObject("array");
for (sec = ctx->sections; sec; sec = sec->next) {
struct MprVar ps = mprObject("array");
struct param *p;
for (p = sec->parameters; p; p = p->next) {
mprSetVar(&ps, p->name, mprString(p->value));
}
mprSetVar(&ret, sec->name, ps);
}
mpr_Return(eid, ret);
return 0;
}
/*
load file
@ -143,6 +195,7 @@ static int ejs_param_load(MprVarHandle eid, int argc, char **argv)
return 0;
}
/*
save file
@ -171,9 +224,10 @@ static void param_add_members(struct MprVar *obj)
{
mprSetStringCFunction(obj, "get", ejs_param_get);
mprSetStringCFunction(obj, "get_list", ejs_param_get_list);
mprSetStringCFunction(obj, "set", ejs_param_set);
mprSetCFunction(obj, "set", ejs_param_set);
mprSetStringCFunction(obj, "load", ejs_param_load);
mprSetStringCFunction(obj, "save", ejs_param_save);
mprSetStringCFunction(obj, "data", ejs_param_data);
}
/*

View File

@ -274,7 +274,7 @@ function upgrade_provision(samba3)
return subobj;
}
var keep = new Array(
smbconf_keep = new Array(
"dos charset",
"unix charset",
"display charset",
@ -371,43 +371,70 @@ var keep = new Array(
"host msdfs",
"winbind separator");
function upgrade_smbconf(samba3)
/*
Remove configuration variables not present in Samba4
oldconf: Old configuration structure
mark: Whether removed configuration variables should be
kept in the new configuration as "samba3:<name>"
*/
function upgrade_smbconf(oldconf,mark)
{
//FIXME
}
var data = oldconf.data();
var newconf = param_init();
function save_smbconf(path,smbconf)
{
var data = "
# Generated by upgrade.js";
for (var s in data) {
for (var p in data[s]) {
var keep = false;
for (var k in smbconf_keep) {
if (smbconf_keep[k] == p) {
keep = true;
break;
}
}
for (var i in smbconf.shares) {
var s = smbconf.shares[i];
data = data + "\n[" + s.name + "]\n";
for (var j in s.parameters) {
var p = s.parameters[j];
data = data + "\t" + p.name + " = " + p + "\n";
if (keep) {
newconf.set(s, p, oldconf.get(s, p));
} else if (mark) {
newconf.set(s, "samba3:"+p, oldconf.get(s,p));
}
}
}
sys.file_save(path,data);
return newconf;
}
function upgrade(subobj, samba3, message)
{
var ret = 0;
var lp = loadparm_init();
var samdb = ldb_init();
var ok = samdb.connect("sam.ldb");
assert(ok);
message("Writing configuration\n");
var newconf = upgrade_smbconf(samba3.configuration,true);
newconf.save(lp.get("config file"));
message("Importing account policies\n");
var ldif = upgrade_sam_policy(samba3,subobj.BASEDN);
ok = samdb.modify(ldif);
assert(ok);
// figure out ldapurl, if applicable
var ldapurl = undefined;
var pdb = samba3.configuration.get_list("passdb backends");
if (pdb != undefined) {
for (var b in pdb) {
if (substr(pdb[b], 0, 7) == "ldapsam") {
ldapurl = substr(pdb[b], 8);
}
}
}
// FIXME: figure out ldapurl
// URL was not specified in passdb backend but ldap /is/ used
if (ldapurl == "") {
ldapurl = "ldap://" + samba3.configuration.get("ldap server");
}
// Enable samba3sam module if original passdb backend was ldap
if (ldapurl != undefined) {
@ -417,7 +444,7 @@ dn: @MAP=samba3sam
samdb.add(ldif);
samdb.modify("dn: @MODULES
@LIST: samldb,timestamps,objectguid,rdn_name");
@LIST: samldb,timestamps,objectguid,rdn_name,samba3sam");
}
message("Importing users\n");
@ -473,5 +500,8 @@ dn: @MAP=samba3sam
ok = winsdb.add(ldif);
assert(ok);
message("Reloading smb.conf\n");
lp.reload();
return ret;
}

View File

@ -73,10 +73,6 @@ if (samba3 == undefined) {
exit(1);
}
message("Writing smb.conf\n");
var smbconf = upgrade_smbconf(samba3);
// FIXME: Write!
message("Provisioning\n");
var subobj = upgrade_provision(samba3);
provision(subobj, message, options.blank);

BIN
testdata/samba3/share_info.tdb vendored Normal file

Binary file not shown.