summaryrefslogtreecommitdiff
path: root/source4/setup/upgrade
blob: 5d0b14bdd7a9a40efc28193cc3880e50d4b5a059 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/sh
exec smbscript "$0" ${1+"$@"}
/*
	Upgrade from Samba3
	Copyright Jelmer Vernooij 2005
	Released under the GNU GPL v2 or later
*/

options = GetOptions(ARGV,
		"POPT_AUTOHELP",
		"POPT_COMMON_SAMBA",
		"POPT_COMMON_VERSION",
		'ldif',
		'dn=s',
		'quiet', 'blank');

if (options == undefined) {
   println("Failed to parse options");
   return -1;
}

libinclude("base.js");
libinclude("provision.js");
libinclude("upgrade.js");

/*
  print a message if quiet is not set
*/
function message() 
{
	if (options["quiet"] == undefined) {
		print(vsprintf(arguments));
	}
}

function ldifprint(data)
{
	if (options["ldif"] != undefined) {
		print data;
	}
}

/*
 show some help
*/
function ShowHelp()
{
	print("
Samba4 import tool

provision [options] <libdir> <smbconf>
 --ldif				Dump LDIF
 --quiet			Be quiet
 --blank			do not add users or groups, just the structure

You must provide at least a realm and domain

");
	exit(1);
}

if (options.ARGV.length != 2) {
	ShowHelp();
	exit(1);
}

if (options.dn == undefined) {
	options.dn = "dc=example,dc=org";
}

message("Reading Samba3 databases and smb.conf\n");
var samba3 = samba3_read(options.ARGV[0], options.ARGV[1]);

if (samba3 == undefined) {
	println("Error reading Samba3 data");
	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, blank);

var samdb = ldb_init();
samdb.connect(lp.get("setup directory") + "/samdb.ldb");

message("Importing account policies\n");
var ldif = upgrade_policy(samba3);
ldifprint(ldif);
samdb.modify(ldif);

// FIXME: Enable samba3sam module if original passdb backend was ldap

message("Importing users\n");
for (var i in samba3.samaccounts) {
	message("Importing user '" + samba3.samaccounts[i].username + "'");
	var ldif = upgrade_sam_account(samba3.samaccounts[i]);
	ldifprint(ldif);
	samdb.add(ldif);
}

message("Importing groups\n");
for (var i in samba3.groupmappings) {
	message("Importing group '" + samba3.groupmappings[i].username + "'");
	var ldif = upgrade_sam_group(samba3.groupmappings[i]);
	ldifprint(ldif);
	samdb.add(ldif);
}

message("Importing WINS data\n");
var ldif = upgrade_wins(samba3)
ldifprint(ldif);
setup_ldb(ldif, "wins", Object());

message("Importing registry data\n");
var hives = ["hkcr","hkcu","hklm","hkpd"]; 
for (var i in hives) {
	var regdb = ldb_init();
	regdb.connect(lp.get("setup directory") + "/" + hives[i] + ".ldb");
	var ldif = upgrade_registry(samba3, hives[i]);
	ldifprint(ldif);
	ldb.add(ldif);
}


message("All OK\n");
return 0;