2 Unix SMB/CIFS implementation.
3 Generate ldb_message 's for samba3_*
5 Copyright (C) Jelmer Vernooij 2005
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "lib/samba3/samba3.h"
24 #include "lib/ldb/include/ldb.h"
26 static struct ldb_message *msg_array_add(struct ldb_context *ctx, struct ldb_message ***msgs, int *count)
28 struct ldb_message *ret;
29 *msgs = talloc_realloc(ctx, *msgs, struct ldb_message *, (*count)+1);
31 ret = (*msgs)[*count] = talloc_zero(ctx, struct ldb_message);
37 static struct ldb_dn *regkey_to_dn(struct ldb_context *ldb, const char *name)
40 struct ldb_dn *ret = ldb_dn_explode(ldb, "hive=NONE");
42 p = dup = talloc_strdup(ldb, name);
46 if (n) { *n = '\0'; n++; }
48 ret = ldb_dn_build_child(ldb, "key", p, ret);
58 /* Where prefix is any of:
66 int samba3_upgrade_registry(struct samba3_regdb *regdb, const char *prefix, struct ldb_context *ldb, struct ldb_message ***msgs)
69 struct ldb_message *msg;
71 char *prefix_up = strupper_talloc(ldb, prefix);
74 for (i = 0; i < regdb->key_count; i++) {
76 struct samba3_regkey *rk = ®db->keys[i];
79 /* Only handle selected hive */
80 if (strncmp(prefix_up, rk->name, strlen(prefix_up)) != 0) {
84 msg = msg_array_add(ldb, msgs, &count);
86 msg->num_elements = 0;
88 msg->private_data = NULL;
90 /* Convert key name to dn */
91 keydn = msg->dn = regkey_to_dn(ldb, rk->name);
93 ldb_msg_add_string(ldb, msg, "name", strrchr(rk->name, '/')?strrchr(rk->name, '/')+1:rk->name);
95 for (j = 0; j < rk->value_count; j++) {
96 struct samba3_regval *rv = &rk->values[j];
98 msg = msg_array_add(ldb, msgs, &count);
99 msg->dn = ldb_dn_build_child(ldb, "value", rv->name, keydn);
101 ldb_msg_add_string(ldb, msg, "value", rv->name);
102 ldb_msg_add_fmt(ldb, msg, "type", "%d", rv->type);
103 ldb_msg_add_value(ldb, msg, "data", &rv->data);
107 talloc_free(prefix_up);
112 int samba3_upgrade_sam(struct samba3 *samba3, struct ldb_context *ctx, struct ldb_message ***msgs)
118 int samba3_upgrade_winbind(struct samba3 *samba3, struct ldb_context *ctx, struct ldb_message ***msgs)
124 int samba3_upgrade_winsdb(struct samba3 *samba3, struct ldb_context *ldb, struct ldb_message ***msgs)
129 for (i = 0; i < samba3->winsdb_count; i++) {
130 struct samba3_winsdb_entry *e = &samba3->winsdb_entries[i];
132 struct ldb_message *msg = msg_array_add(ldb, msgs, &count);
134 msg->dn = ldb_dn_string_compose(ldb, NULL, "type=%d,name=%s", e->type, e->name);
136 ldb_msg_add_string(ldb, msg, "name", e->name);
137 ldb_msg_add_fmt(ldb, msg, "type", "%d", e->type);
138 ldb_msg_add_string(ldb, msg, "objectClass", "wins");
139 ldb_msg_add_fmt(ldb, msg, "nbFlags", "%x", e->nb_flags);
140 ldb_msg_add_string(ldb, msg, "expires",
141 ldap_timestring(msg, e->ttl));
143 for (j = 0; j < e->ip_count; j++) {
144 ldb_msg_add_string(ldb, msg, "address", sys_inet_ntoa(e->ips[j]));