s3-registry: avoid using registry_value union.
[nivanova/samba-autobuild/.git] / source3 / include / registry.h
1 /*
2  *  Unix SMB/CIFS implementation.
3  *  Virtual Windows Registry Layer
4  *
5  *  Copyright (C) Gerald Carter              2002-2005
6  *  Copyright (C) Volker Lendecke            2006
7  *  Copyright (C) Michael Adam               2006-2010
8  *
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 3 of the License, or
12  *  (at your option) any later version.
13  *
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
21  */
22
23 #ifndef _REGISTRY_H
24 #define _REGISTRY_H
25
26 struct registry_value {
27         enum winreg_Type type;
28         DATA_BLOB data;
29 };
30
31 /* forward declarations. definitions in reg_objects.c */
32 struct regval_ctr;
33 struct regsubkey_ctr;
34
35 /*
36  * container for function pointers to enumeration routines
37  * for virtual registry view
38  */
39
40 struct registry_ops {
41         /* functions for enumerating subkeys and values */
42         int     (*fetch_subkeys)( const char *key, struct regsubkey_ctr *subkeys);
43         int     (*fetch_values) ( const char *key, struct regval_ctr *val );
44         bool    (*store_subkeys)( const char *key, struct regsubkey_ctr *subkeys );
45         WERROR  (*create_subkey)(const char *key, const char *subkey);
46         WERROR  (*delete_subkey)(const char *key, const char *subkey);
47         bool    (*store_values)( const char *key, struct regval_ctr *val );
48         bool    (*reg_access_check)( const char *keyname, uint32 requested,
49                                      uint32 *granted,
50                                      const NT_USER_TOKEN *token );
51         WERROR (*get_secdesc)(TALLOC_CTX *mem_ctx, const char *key,
52                               struct security_descriptor **psecdesc);
53         WERROR (*set_secdesc)(const char *key,
54                               struct security_descriptor *sec_desc);
55         bool    (*subkeys_need_update)(struct regsubkey_ctr *subkeys);
56         bool    (*values_need_update)(struct regval_ctr *values);
57 };
58
59 /* structure to store the registry handles */
60
61 struct registry_key_handle {
62         uint32          type;
63         char            *name;          /* full name of registry key */
64         uint32          access_granted;
65         struct registry_ops     *ops;
66 };
67
68 struct registry_key {
69         struct registry_key_handle *key;
70         struct regsubkey_ctr *subkeys;
71         struct regval_ctr *values;
72         struct nt_user_token *token;
73 };
74
75
76 /*
77  *
78  * Macros that used to reside in rpc_reg.h
79  *
80  */
81
82 #define HKEY_CLASSES_ROOT       0x80000000
83 #define HKEY_CURRENT_USER       0x80000001
84 #define HKEY_LOCAL_MACHINE      0x80000002
85 #define HKEY_USERS              0x80000003
86 #define HKEY_PERFORMANCE_DATA   0x80000004
87
88 #define KEY_HKLM                "HKLM"
89 #define KEY_HKU                 "HKU"
90 #define KEY_HKCC                "HKCC"
91 #define KEY_HKCR                "HKCR"
92 #define KEY_HKPD                "HKPD"
93 #define KEY_HKPT                "HKPT"
94 #define KEY_HKPN                "HKPN"
95 #define KEY_HKCU                "HKCU"
96 #define KEY_HKDD                "HKDD"
97 #define KEY_SERVICES            "HKLM\\SYSTEM\\CurrentControlSet\\Services"
98 #define KEY_EVENTLOG            "HKLM\\SYSTEM\\CurrentControlSet\\Services\\Eventlog"
99 #define KEY_SHARES              "HKLM\\SYSTEM\\CurrentControlSet\\Services\\LanmanServer\\Shares"
100 #define KEY_NETLOGON_PARAMS     "HKLM\\SYSTEM\\CurrentControlSet\\Services\\Netlogon\\Parameters"
101 #define KEY_TCPIP_PARAMS        "HKLM\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters"
102 #define KEY_PROD_OPTIONS        "HKLM\\SYSTEM\\CurrentControlSet\\Control\\ProductOptions"
103 #define KEY_PRINTING            "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Print"
104 #define KEY_PRINTING_2K         "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Print\\Printers"
105 #define KEY_PRINTING_PORTS      "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Ports"
106 #define KEY_CURRENT_VERSION     "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"
107 #define KEY_PERFLIB             "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Perflib"
108 #define KEY_PERFLIB_009         "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Perflib\\009"
109 #define KEY_GROUP_POLICY        "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Group Policy"
110 #define KEY_WINLOGON            "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"
111 #define KEY_SMBCONF             "HKLM\\SOFTWARE\\Samba\\smbconf"
112 #define KEY_SAMBA_GROUP_POLICY  "HKLM\\SOFTWARE\\Samba\\Group Policy"
113 #define KEY_TREE_ROOT           ""
114
115 #define KEY_GP_MACHINE_POLICY           "HKLM\\Software\\Policies"
116 #define KEY_GP_MACHINE_WIN_POLICY       "HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies"
117 #define KEY_GP_USER_POLICY              "HKCU\\Software\\Policies"
118 #define KEY_GP_USER_WIN_POLICY          "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies"
119
120 /*
121  * Registry key types
122  *      Most keys are going to be GENERIC -- may need a better name?
123  *      HKPD and HKPT are used by reg_perfcount.c
124  *              they are special keys that contain performance data
125  */
126 #define REG_KEY_GENERIC         0
127 #define REG_KEY_HKPD            1
128 #define REG_KEY_HKPT            2
129
130
131 /* The following definitions come from registry/reg_api.c  */
132
133 WERROR reg_openhive(TALLOC_CTX *mem_ctx, const char *hive,
134                     uint32 desired_access,
135                     const struct nt_user_token *token,
136                     struct registry_key **pkey);
137 WERROR reg_openkey(TALLOC_CTX *mem_ctx, struct registry_key *parent,
138                    const char *name, uint32 desired_access,
139                    struct registry_key **pkey);
140 WERROR reg_enumkey(TALLOC_CTX *mem_ctx, struct registry_key *key,
141                    uint32 idx, char **name, NTTIME *last_write_time);
142 WERROR reg_enumvalue(TALLOC_CTX *mem_ctx, struct registry_key *key,
143                      uint32 idx, char **pname, struct registry_value **pval);
144 WERROR reg_queryvalue(TALLOC_CTX *mem_ctx, struct registry_key *key,
145                       const char *name, struct registry_value **pval);
146 WERROR reg_querymultiplevalues(TALLOC_CTX *mem_ctx,
147                                struct registry_key *key,
148                                uint32_t num_names,
149                                const char **names,
150                                uint32_t *pnum_vals,
151                                struct registry_value **pvals);
152 WERROR reg_queryinfokey(struct registry_key *key, uint32_t *num_subkeys,
153                         uint32_t *max_subkeylen, uint32_t *max_subkeysize,
154                         uint32_t *num_values, uint32_t *max_valnamelen,
155                         uint32_t *max_valbufsize, uint32_t *secdescsize,
156                         NTTIME *last_changed_time);
157 WERROR reg_createkey(TALLOC_CTX *ctx, struct registry_key *parent,
158                      const char *subkeypath, uint32 desired_access,
159                      struct registry_key **pkey,
160                      enum winreg_CreateAction *paction);
161 WERROR reg_deletekey(struct registry_key *parent, const char *path);
162 WERROR reg_setvalue(struct registry_key *key, const char *name,
163                     const struct registry_value *val);
164 WERROR reg_deletevalue(struct registry_key *key, const char *name);
165 WERROR reg_getkeysecurity(TALLOC_CTX *mem_ctx, struct registry_key *key,
166                           struct security_descriptor **psecdesc);
167 WERROR reg_setkeysecurity(struct registry_key *key,
168                           struct security_descriptor *psecdesc);
169 WERROR reg_getversion(uint32_t *version);
170 WERROR reg_restorekey(struct registry_key *key, const char *fname);
171 WERROR reg_savekey(struct registry_key *key, const char *fname);
172 WERROR reg_deleteallvalues(struct registry_key *key);
173 WERROR reg_open_path(TALLOC_CTX *mem_ctx, const char *orig_path,
174                      uint32 desired_access, const struct nt_user_token *token,
175                      struct registry_key **pkey);
176 WERROR reg_deletekey_recursive(TALLOC_CTX *ctx,
177                                struct registry_key *parent,
178                                const char *path);
179 WERROR reg_deletesubkeys_recursive(TALLOC_CTX *ctx,
180                                    struct registry_key *parent,
181                                    const char *path);
182 WERROR reg_create_path(TALLOC_CTX *mem_ctx, const char *orig_path,
183                        uint32 desired_access,
184                        const struct nt_user_token *token,
185                        enum winreg_CreateAction *paction,
186                        struct registry_key **pkey);
187 WERROR reg_delete_path(const struct nt_user_token *token,
188                        const char *orig_path);
189
190 /* The following definitions come from registry/reg_init_basic.c  */
191
192 WERROR registry_init_common(void);
193 WERROR registry_init_basic(void);
194
195 /* The following definitions come from registry/reg_init_full.c  */
196
197 WERROR registry_init_full(void);
198
199 /* The following definitions come from registry/reg_init_smbconf.c  */
200
201 WERROR registry_init_smbconf(const char *keyname);
202
203 #endif /* _REGISTRY_H */