summaryrefslogtreecommitdiffstats
path: root/source4/lib/ldb/samba/samba3sam.c
blob: c1ac691e92c9174cd0ce1149e66f688d6c49e041 (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/* 
   ldb database library - Samba3 SAM compatibility backend

   Copyright (C) Jelmer Vernooij 2005

     ** NOTE! The following LGPL license applies to the ldb
     ** library. This does NOT imply that all of Samba is released
     ** under the LGPL
   
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#include "includes.h"
#include "ldb/ldb_map/ldb_map.h"
#include "ldb/include/ldb.h"
#include "ldb/include/ldb_private.h"

/* FIXME: 
 * sambaSID -> member 
 * sambaSIDList -> member (special!) 
 * sambaDomainName -> name 
 * sambaTrustPassword 
 * sambaUnixIdPool 
 * sambaIdmapEntry 
 * sambaAccountPolicy 
 * sambaSidEntry 
 * sambaAcctFlags -> systemFlags ?
 * sambaPasswordHistory  -> ntPwdHistory*/

/* Not necessary:
 * sambaConfig
 * sambaShare
 * sambaConfigOption 
 * sambaNextGroupRid
 * sambaNextUserRid
 * sambaAlgorithmicRidBase
 */

/* Not in Samba4: 
 * sambaKickoffTime
 * sambaPwdCanChange
 * sambaPwdMustChange
 * sambaHomePath
 * sambaHomeDrive
 * sambaLogonScript
 * sambaProfilePath
 * sambaUserWorkstations
 * sambaMungedDial
 * sambaLogonHours */

static struct ldb_message_element *convert_sid_rid(TALLOC_CTX *ctx, const char *remote_attr, const struct ldb_message_element *el)
{
	struct ldb_message_element *ret = talloc(ctx, struct ldb_message_element);
	int i;

	printf("Converting SID TO RID *\n");

	ret->flags = el->flags;
	ret->name = talloc_strdup(ret, remote_attr);
	ret->num_values = el->num_values;
	ret->values = talloc_array(ret, struct ldb_val, ret->num_values);

	for (i = 0; i < ret->num_values; i++) {
		ret->values[i] = ldb_val_dup(ret->values, &el->values[i]);
	}

	return ret;
}

static struct ldb_message_element *convert_rid_sid(TALLOC_CTX *ctx, const char *remote_attr, const struct ldb_message_element *el)
{
	struct ldb_message_element *ret = talloc(ctx, struct ldb_message_element);
	int i;

	printf("Converting RID TO SID *\n");

	ret->flags = el->flags;
	ret->name = talloc_strdup(ret, remote_attr);
	ret->num_values = el->num_values;
	ret->values = talloc_array(ret, struct ldb_val, ret->num_values);

	for (i = 0; i < ret->num_values; i++) {
		ret->values[i] = ldb_val_dup(ret->values, &el->values[i]);
	}

	return ret;
}

static struct ldb_message_element *convert_unix_id2name(TALLOC_CTX *ctx, const char *remote_attr, const struct ldb_message_element *el)
{
	int i;
	struct ldb_message_element *ret = talloc(ctx, struct ldb_message_element);

	printf("Converting UNIX ID to name\n");

	ret->flags = el->flags;
	ret->name = talloc_strdup(ret, remote_attr);
	ret->num_values = el->num_values;
	ret->values = talloc_array(ret, struct ldb_val, ret->num_values);

	for (i = 0; i < ret->num_values; i++) {
		ret->values[i] = ldb_val_dup(ret->values, &el->values[i]);
	}

	return ret;
}

static struct ldb_message_element *convert_unix_name2id(TALLOC_CTX *ctx, const char *remote_attr, const struct ldb_message_element *el)
{
	struct ldb_message_element *ret = talloc(ctx, struct ldb_message_element);
	int i;

	printf("Converting UNIX name to ID\n");

	ret->flags = el->flags;
	ret->name = talloc_strdup(ret, remote_attr);
	ret->num_values = el->num_values;
	ret->values = talloc_array(ret, struct ldb_val, ret->num_values);

	for (i = 0; i < ret->num_values; i++) {
		ret->values[i] = ldb_val_dup(ret->values, &el->values[i]);
	}

	return ret;
}

const struct ldb_map_objectclass samba3_objectclasses[] = {
	{ "group", "sambaGroupMapping" },
	{ "user", "sambaSAMAccount" },
	{ "domain", "sambaDomain" },
};

const struct ldb_map_attribute samba3_attributes[] = 
{
	/* sambaNextRid -> nextRid */
	{
		.local_name = "nextRid",
		.type = MAP_RENAME,
		.u.rename.remote_name = "sambaNextRid",
	},

	/* sambaBadPasswordTime -> badPasswordtime*/
	{
		.local_name = "badPasswordTime",
		.type = MAP_RENAME,
		.u.rename.remote_name = "sambaBadPasswordTime",
	},

	/* sambaLMPassword -> lmPwdHash*/
	{
		.local_name = "lmPwdHash",
		.type = MAP_RENAME,
		.u.rename.remote_name = "sambaLMPassword",
	},

	/* sambaGroupType -> groupType */
	{
		.local_name = "groupType",
		.type = MAP_RENAME,
		.u.rename.remote_name = "sambaGroupType",
	},

	/* sambaNTPassword -> ntPwdHash*/
	{
		.local_name = "badPwdCount",
		.type = MAP_RENAME,
		.u.rename.remote_name = "sambaNTPassword",
	},

	/* sambaPrimaryGroupSID -> primaryGroupID */
	{
		.local_name = "primaryGroupID",
		.type = MAP_CONVERT,
		.u.convert.remote_name = "sambaPrimaryGroupSID",
		.u.convert.convert_local = convert_rid_sid,
		.u.convert.convert_remote = convert_sid_rid, 
	},

	/* sambaBadPasswordCount -> badPwdCount */
	{
		.local_name = "badPwdCount",
		.type = MAP_RENAME,
		.u.rename.remote_name = "sambaBadPasswordCount",
	},

	/* sambaLogonTime -> lastLogon*/
	{
		.local_name = "lastLogon",
		.type = MAP_RENAME,
		.u.rename.remote_name = "sambaLogonTime",
	},

	/* sambaLogoffTime -> lastLogoff*/
	{
		.local_name = "lastLogoff",
		.type = MAP_RENAME,
		.u.rename.remote_name = "sambaLogoffTime",
	},

	/* gidNumber -> unixName */
	{
		.local_name = "unixName",
		.type = MAP_CONVERT,
		.u.convert.remote_name = "gidNumber",
		.u.convert.convert_local = convert_unix_name2id,
		.u.convert.convert_remote = convert_unix_id2name, 
	},

	/* uid -> unixName */
	{
		.local_name = "unixName",
		.type = MAP_CONVERT,
		.u.convert.remote_name = "uid",
		.u.convert.convert_local = convert_unix_name2id,
		.u.convert.convert_remote = convert_unix_id2name,
	},

	/* displayName -> name */
	{
		.local_name = "name",
		.type = MAP_RENAME,
		.u.rename.remote_name = "displayName",
	},

	/* cn */
	{
		.local_name = "cn",
		.type = MAP_KEEP,
	},

	/* description */
	{
		.local_name = "description",
		.type = MAP_KEEP,
	},

	/* sambaSID -> objectSid*/
	{
		.local_name = "objectSid",
		.type = MAP_RENAME,
		.u.rename.remote_name = "sambaSID", 
	},

	/* sambaPwdLastSet -> pwdLastSet*/
	{
		.local_name = "pwdLastSet",
		.type = MAP_RENAME,
		.u.rename.remote_name = "sambaPwdLastSet",
	},	
};

	/* the init function */
#ifdef HAVE_DLOPEN_DISABLED
struct ldb_module *init_module(struct ldb_context *ldb, const char *options[])
#else
struct ldb_module *ldb_samba3sam_module_init(struct ldb_context *ldb, const char *options[])
#endif
{
	return ldb_map_init(ldb, samba3_attributes, samba3_objectclasses, options);
}