~zulcss/samba/server-dailies-3.4

« back to all changes in this revision

Viewing changes to source4/lib/registry/hive.c

  • Committer: Chuck Short
  • Date: 2010-09-28 20:38:39 UTC
  • Revision ID: zulcss@ubuntu.com-20100928203839-pgjulytsi9ue63x1
Initial version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
   Unix SMB/CIFS implementation.
 
4
   Registry hive interface
 
5
   Copyright (C) Jelmer Vernooij                                  2003-2007.
 
6
 
 
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 3 of the License, or
 
10
   (at your option) any later version.
 
11
 
 
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.
 
16
 
 
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.
 
20
*/
 
21
 
 
22
#include "includes.h"
 
23
#include "registry.h"
 
24
#include "system/filesys.h"
 
25
#include "param/param.h"
 
26
 
 
27
/** Open a registry file/host/etc */
 
28
_PUBLIC_ WERROR reg_open_hive(TALLOC_CTX *parent_ctx, const char *location,
 
29
                              struct auth_session_info *session_info,
 
30
                              struct cli_credentials *credentials,
 
31
                              struct tevent_context *ev_ctx,
 
32
                              struct loadparm_context *lp_ctx,
 
33
                              struct hive_key **root)
 
34
{
 
35
        int fd, num;
 
36
        char peek[20];
 
37
 
 
38
        /* Check for directory */
 
39
        if (directory_exist(location)) {
 
40
                return reg_open_directory(parent_ctx, location, root);
 
41
        }
 
42
 
 
43
        fd = open(location, O_RDWR);
 
44
        if (fd == -1) {
 
45
                if (errno == ENOENT)
 
46
                        return WERR_BADFILE;
 
47
                return WERR_BADFILE;
 
48
        }
 
49
 
 
50
        num = read(fd, peek, 20);
 
51
        if (num == -1) {
 
52
                return WERR_BADFILE;
 
53
        }
 
54
 
 
55
        if (!strncmp(peek, "regf", 4)) {
 
56
                close(fd);
 
57
                return reg_open_regf_file(parent_ctx, location, lp_iconv_convenience(lp_ctx), root);
 
58
        } else if (!strncmp(peek, "TDB file", 8)) {
 
59
                close(fd);
 
60
                return reg_open_ldb_file(parent_ctx, location, session_info,
 
61
                                         credentials, ev_ctx, lp_ctx, root);
 
62
        }
 
63
 
 
64
        return WERR_BADFILE;
 
65
}
 
66
 
 
67
_PUBLIC_ WERROR hive_key_get_info(TALLOC_CTX *mem_ctx,
 
68
                                  const struct hive_key *key,
 
69
                                  const char **classname, uint32_t *num_subkeys,
 
70
                                  uint32_t *num_values,
 
71
                                  NTTIME *last_change_time,
 
72
                                  uint32_t *max_subkeynamelen,
 
73
                                  uint32_t *max_valnamelen,
 
74
                                  uint32_t *max_valbufsize)
 
75
{
 
76
        return key->ops->get_key_info(mem_ctx, key, classname, num_subkeys,
 
77
                                      num_values, last_change_time,
 
78
                                      max_subkeynamelen,
 
79
                                      max_valnamelen, max_valbufsize);
 
80
}
 
81
 
 
82
_PUBLIC_ WERROR hive_key_add_name(TALLOC_CTX *ctx,
 
83
                                  const struct hive_key *parent_key,
 
84
                                  const char *name, const char *classname,
 
85
                                  struct security_descriptor *desc,
 
86
                                  struct hive_key **key)
 
87
{
 
88
        SMB_ASSERT(strchr(name, '\\') == NULL);
 
89
 
 
90
        return parent_key->ops->add_key(ctx, parent_key, name, classname,
 
91
                                        desc, key);
 
92
}
 
93
 
 
94
_PUBLIC_ WERROR hive_key_del(const struct hive_key *key, const char *name)
 
95
{
 
96
        return key->ops->del_key(key, name);
 
97
}
 
98
 
 
99
_PUBLIC_ WERROR hive_get_key_by_name(TALLOC_CTX *mem_ctx,
 
100
                                     const struct hive_key *key,
 
101
                                     const char *name,
 
102
                                     struct hive_key **subkey)
 
103
{
 
104
        return key->ops->get_key_by_name(mem_ctx, key, name, subkey);
 
105
}
 
106
 
 
107
WERROR hive_enum_key(TALLOC_CTX *mem_ctx,
 
108
                     const struct hive_key *key, uint32_t idx,
 
109
                     const char **name,
 
110
                     const char **classname,
 
111
                     NTTIME *last_mod_time)
 
112
{
 
113
        return key->ops->enum_key(mem_ctx, key, idx, name, classname,
 
114
                                  last_mod_time);
 
115
}
 
116
 
 
117
WERROR hive_key_set_value(struct hive_key *key, const char *name, uint32_t type,
 
118
                                          const DATA_BLOB data)
 
119
{
 
120
        if (key->ops->set_value == NULL)
 
121
                return WERR_NOT_SUPPORTED;
 
122
 
 
123
        return key->ops->set_value(key, name, type, data);
 
124
}
 
125
 
 
126
WERROR hive_get_value(TALLOC_CTX *mem_ctx,
 
127
                      struct hive_key *key, const char *name,
 
128
                      uint32_t *type, DATA_BLOB *data)
 
129
{
 
130
        if (key->ops->get_value_by_name == NULL)
 
131
                return WERR_NOT_SUPPORTED;
 
132
 
 
133
        return key->ops->get_value_by_name(mem_ctx, key, name, type, data);
 
134
}
 
135
 
 
136
WERROR hive_get_value_by_index(TALLOC_CTX *mem_ctx,
 
137
                               struct hive_key *key, uint32_t idx,
 
138
                               const char **name,
 
139
                               uint32_t *type, DATA_BLOB *data)
 
140
{
 
141
        if (key->ops->enum_value == NULL)
 
142
                return WERR_NOT_SUPPORTED;
 
143
 
 
144
        return key->ops->enum_value(mem_ctx, key, idx, name, type, data);
 
145
}
 
146
 
 
147
WERROR hive_get_sec_desc(TALLOC_CTX *mem_ctx,
 
148
                         struct hive_key *key, 
 
149
                         struct security_descriptor **security)
 
150
{
 
151
        if (key->ops->get_sec_desc == NULL)
 
152
                return WERR_NOT_SUPPORTED;
 
153
 
 
154
        return key->ops->get_sec_desc(mem_ctx, key, security);
 
155
}
 
156
 
 
157
WERROR hive_set_sec_desc(struct hive_key *key, 
 
158
                         const struct security_descriptor *security)
 
159
{
 
160
        if (key->ops->set_sec_desc == NULL)
 
161
                return WERR_NOT_SUPPORTED;
 
162
 
 
163
        return key->ops->set_sec_desc(key, security);
 
164
}
 
165
 
 
166
WERROR hive_key_del_value(struct hive_key *key, const char *name)
 
167
{
 
168
        if (key->ops->delete_value == NULL)
 
169
                return WERR_NOT_SUPPORTED;
 
170
 
 
171
        return key->ops->delete_value(key, name);
 
172
}
 
173
 
 
174
WERROR hive_key_flush(struct hive_key *key)
 
175
{
 
176
        if (key->ops->flush_key == NULL)
 
177
                return WERR_OK;
 
178
 
 
179
        return key->ops->flush_key(key);
 
180
}