2 * Unix SMB/CIFS implementation.
4 * Copyright (C) Guenther Deschner 2005-2008
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include "../libgpo/gpo_ini.h"
22 #include "../libgpo/gpo.h"
23 #include "libgpo/gpo_proto.h"
24 #include "libgpo/gpext/gpext.h"
26 #define GP_EXT_NAME "security"
28 #define GPTTMPL_UNIX_PATH "Microsoft/Windows NT/SecEdit/GptTmpl.inf"
30 #define GPTTMPL_SECTION_UNICODE "Unicode"
31 #define GPTTMPL_SECTION_VERSION "Version"
33 #define GPTTMPL_SECTION_REGISTRY_VALUES "Registry Values"
34 #define GPTTMPL_SECTION_SYSTEM_ACCESS "System Access"
35 #define GPTTMPL_SECTION_KERBEROS_POLICY "Kerberos Policy"
36 #define GPTTMPL_SECTION_EVENT_AUDIT "Event Audit"
37 #define GPTTMPL_SECTION_PRIVILEGE_RIGHTS "Privilege Rights"
38 #define GPTTMPL_SECTION_APPLICATION_LOG "Application Log"
39 #define GPTTMPL_SECTION_SECURITY_LOG "Security Log"
40 #define GPTTMPL_SECTION_SYSTEM_LOG "System Log"
41 #define GPTTMPL_SECTION_GROUP_MEMBERSHIP "Group Membership"
42 #define GPTTMPL_SECTION_FILE_SECURITY "File Security"
43 #define GPTTMPL_SECTION_SERVICE_GENERAL_SETTING "Service General Setting"
45 NTSTATUS
gpext_security_init(TALLOC_CTX
*mem_ctx
);
47 static TALLOC_CTX
*ctx
= NULL
;
49 struct gpttmpl_table
{
51 const char *parameter
;
52 enum winreg_Type type
;
55 /****************************************************************
56 parse the Version section from gpttmpl file
57 ****************************************************************/
59 #define GPTTMPL_PARAMETER_REVISION "Revision"
60 #define GPTTMPL_PARAMETER_SIGNATURE "signature"
61 #define GPTTMPL_VALUE_CHICAGO "\"$CHICAGO$\"" /* whatever this is good for... */
62 #define GPTTMPL_PARAMETER_UNICODE "Unicode"
64 static NTSTATUS
gpttmpl_parse_header(struct gp_inifile_context
*ini_ctx
,
65 uint32_t *version_out
)
67 const char *signature
= NULL
;
70 bool is_unicode
= false;
73 return NT_STATUS_INVALID_PARAMETER
;
76 result
= gp_inifile_getstring(ini_ctx
, GPTTMPL_SECTION_VERSION
77 ":"GPTTMPL_PARAMETER_SIGNATURE
, &signature
);
78 if (!NT_STATUS_IS_OK(result
)) {
79 return NT_STATUS_INTERNAL_DB_CORRUPTION
;
82 if (!strequal(signature
, GPTTMPL_VALUE_CHICAGO
)) {
83 return NT_STATUS_INTERNAL_DB_CORRUPTION
;
85 result
= gp_inifile_getint(ini_ctx
, GPTTMPL_SECTION_VERSION
86 ":"GPTTMPL_PARAMETER_REVISION
, &version
);
87 if (!NT_STATUS_IS_OK(result
)) {
88 return NT_STATUS_INTERNAL_DB_CORRUPTION
;
92 *version_out
= version
;
95 result
= gp_inifile_getbool(ini_ctx
, GPTTMPL_SECTION_UNICODE
96 ":"GPTTMPL_PARAMETER_UNICODE
, &is_unicode
);
97 if (!NT_STATUS_IS_OK(result
) || !is_unicode
) {
98 return NT_STATUS_INTERNAL_DB_CORRUPTION
;
104 /****************************************************************
105 ****************************************************************/
107 static NTSTATUS
gpttmpl_init_context(TALLOC_CTX
*mem_ctx
,
109 const char *unix_path
,
110 struct gp_inifile_context
**ini_ctx
)
114 struct gp_inifile_context
*tmp_ctx
= NULL
;
116 status
= gp_inifile_init_context(mem_ctx
, flags
, unix_path
,
117 GPTTMPL_UNIX_PATH
, &tmp_ctx
);
118 NT_STATUS_NOT_OK_RETURN(status
);
120 status
= gpttmpl_parse_header(tmp_ctx
, &version
);
121 if (!NT_STATUS_IS_OK(status
)) {
122 DEBUG(1,("gpttmpl_init_context: failed: %s\n",
124 TALLOC_FREE(tmp_ctx
);
133 /****************************************************************
134 ****************************************************************/
136 static NTSTATUS
gpttmpl_process(struct gp_inifile_context
*ini_ctx
,
137 struct registry_key
*root_key
,
143 /****************************************************************
144 ****************************************************************/
146 static NTSTATUS
security_process_group_policy(TALLOC_CTX
*mem_ctx
,
148 struct registry_key
*root_key
,
149 const struct security_token
*token
,
150 const struct GROUP_POLICY_OBJECT
*deleted_gpo_list
,
151 const struct GROUP_POLICY_OBJECT
*changed_gpo_list
)
153 NTSTATUS status
= NT_STATUS_OK
;
154 char *unix_path
= NULL
;
155 struct gp_inifile_context
*ini_ctx
= NULL
;
156 const struct GROUP_POLICY_OBJECT
*gpo
;
157 char *gpo_cache_path
= cache_path(talloc_tos(), GPO_CACHE_DIR
);
158 if (gpo_cache_path
== NULL
) {
159 return NT_STATUS_NO_MEMORY
;
162 /* implementation of the policy callback function, see
163 * http://msdn.microsoft.com/en-us/library/aa373494%28v=vs.85%29.aspx
164 * for details - gd */
166 /* for now do not process the list of deleted group policies
168 for (gpo = deleted_gpo_list; gpo; gpo = gpo->next) {
173 for (gpo
= changed_gpo_list
; gpo
; gpo
= gpo
->next
) {
175 gpext_debug_header(0, "security_process_group_policy", flags
,
176 gpo
, GP_EXT_GUID_SECURITY
, NULL
);
178 /* this handler processes the gpttmpl files and merge output to the
181 status
= gpo_get_unix_path(mem_ctx
, gpo_cache_path
,
183 if (!NT_STATUS_IS_OK(status
)) {
187 status
= gpttmpl_init_context(mem_ctx
, flags
, unix_path
,
189 if (!NT_STATUS_IS_OK(status
)) {
193 status
= gpttmpl_process(ini_ctx
, root_key
, flags
);
194 if (!NT_STATUS_IS_OK(status
)) {
198 TALLOC_FREE(ini_ctx
);
202 if (!NT_STATUS_IS_OK(status
)) {
203 DEBUG(0,("security_process_group_policy: %s\n",
206 TALLOC_FREE(ini_ctx
);
207 talloc_free(gpo_cache_path
);
212 /****************************************************************
213 ****************************************************************/
215 static NTSTATUS
security_get_reg_config(TALLOC_CTX
*mem_ctx
,
216 struct gp_extension_reg_info
**reg_info
)
219 struct gp_extension_reg_info
*info
= NULL
;
221 struct gp_extension_reg_table table
[] = {
222 /* FIXME: how can we store the "(Default)" value ??? */
223 /* { "", REG_SZ, "Security" }, */
224 { "ProcessGroupPolicy", REG_SZ
, "security_process_group_policy" },
225 { "NoUserPolicy", REG_DWORD
, "1" },
226 { "ExtensionDebugLevel", REG_DWORD
, "1" },
227 { NULL
, REG_NONE
, NULL
}
230 info
= talloc_zero(mem_ctx
, struct gp_extension_reg_info
);
231 NT_STATUS_HAVE_NO_MEMORY(info
);
233 status
= gpext_info_add_entry(mem_ctx
, GP_EXT_NAME
,
234 GP_EXT_GUID_SECURITY
,
236 NT_STATUS_NOT_OK_RETURN(status
);
244 /****************************************************************
245 ****************************************************************/
247 static NTSTATUS
security_initialize(TALLOC_CTX
*mem_ctx
)
252 /****************************************************************
253 ****************************************************************/
255 static NTSTATUS
security_shutdown(void)
259 status
= gpext_unregister_gp_extension(GP_EXT_NAME
);
260 if (NT_STATUS_IS_OK(status
)) {
269 /****************************************************************
270 ****************************************************************/
272 static struct gp_extension_methods security_methods
= {
273 .initialize
= security_initialize
,
274 .process_group_policy
= security_process_group_policy
,
275 .get_reg_config
= security_get_reg_config
,
276 .shutdown
= security_shutdown
279 /****************************************************************
280 ****************************************************************/
282 NTSTATUS
gpext_security_init(TALLOC_CTX
*mem_ctx
)
286 ctx
= talloc_init("gpext_security_init");
287 NT_STATUS_HAVE_NO_MEMORY(ctx
);
289 status
= gpext_register_gp_extension(ctx
, SMB_GPEXT_INTERFACE_VERSION
,
290 GP_EXT_NAME
, GP_EXT_GUID_SECURITY
,
292 if (!NT_STATUS_IS_OK(status
)) {