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"
23 #define GP_EXT_NAME "security"
25 #define GPTTMPL_UNIX_PATH "Microsoft/Windows NT/SecEdit/GptTmpl.inf"
27 #define GPTTMPL_SECTION_UNICODE "Unicode"
28 #define GPTTMPL_SECTION_VERSION "Version"
30 #define GPTTMPL_SECTION_REGISTRY_VALUES "Registry Values"
31 #define GPTTMPL_SECTION_SYSTEM_ACCESS "System Access"
32 #define GPTTMPL_SECTION_KERBEROS_POLICY "Kerberos Policy"
33 #define GPTTMPL_SECTION_EVENT_AUDIT "Event Audit"
34 #define GPTTMPL_SECTION_PRIVILEGE_RIGHTS "Privilege Rights"
35 #define GPTTMPL_SECTION_APPLICATION_LOG "Application Log"
36 #define GPTTMPL_SECTION_SECURITY_LOG "Security Log"
37 #define GPTTMPL_SECTION_SYSTEM_LOG "System Log"
38 #define GPTTMPL_SECTION_GROUP_MEMBERSHIP "Group Membership"
39 #define GPTTMPL_SECTION_FILE_SECURITY "File Security"
40 #define GPTTMPL_SECTION_SERVICE_GENERAL_SETTING "Service General Setting"
42 static TALLOC_CTX *ctx = NULL;
44 struct gpttmpl_table {
46 const char *parameter;
47 enum winreg_Type type;
50 /****************************************************************
51 parse the Version section from gpttmpl file
52 ****************************************************************/
54 #define GPTTMPL_PARAMETER_REVISION "Revision"
55 #define GPTTMPL_PARAMETER_SIGNATURE "signature"
56 #define GPTTMPL_VALUE_CHICAGO "$CHICAGO$" /* whatever this is good for... */
57 #define GPTTMPL_PARAMETER_UNICODE "Unicode"
59 static NTSTATUS gpttmpl_parse_header(struct gp_inifile_context *ini_ctx,
60 uint32_t *version_out)
62 const char *signature = NULL;
68 return NT_STATUS_INVALID_PARAMETER;
71 result = gp_inifile_getstring(ini_ctx, GPTTMPL_SECTION_VERSION
72 ":"GPTTMPL_PARAMETER_SIGNATURE, &signature);
73 if (!NT_STATUS_IS_OK(result)) {
74 return NT_STATUS_INTERNAL_DB_CORRUPTION;
77 if (!strequal(signature, GPTTMPL_VALUE_CHICAGO)) {
78 return NT_STATUS_INTERNAL_DB_CORRUPTION;
80 result = gp_inifile_getint(ini_ctx, GPTTMPL_SECTION_VERSION
81 ":"GPTTMPL_PARAMETER_REVISION, &version);
82 if (!NT_STATUS_IS_OK(result))
83 return NT_STATUS_INTERNAL_DB_CORRUPTION;
87 *version_out = version;
90 result = gp_inifile_getint(ini_ctx, GPTTMPL_SECTION_UNICODE
91 ":"GPTTMPL_PARAMETER_UNICODE, is_unicode);
92 if (!NT_STATUS_IS_OK(result) || !is_unicode) {
93 return NT_STATUS_INTERNAL_DB_CORRUPTION;
99 /****************************************************************
100 ****************************************************************/
102 static NTSTATUS gpttmpl_init_context(TALLOC_CTX *mem_ctx,
104 const char *unix_path,
105 struct gp_inifile_context **ini_ctx)
109 struct gp_inifile_context *tmp_ctx = NULL;
111 status = gp_inifile_init_context(mem_ctx, flags, unix_path,
112 GPTTMPL_UNIX_PATH, &tmp_ctx);
113 NT_STATUS_NOT_OK_RETURN(status);
115 status = gpttmpl_parse_header(tmp_ctx, &version);
116 if (!NT_STATUS_IS_OK(status)) {
117 DEBUG(1,("gpttmpl_init_context: failed: %s\n",
119 TALLOC_FREE(tmp_ctx);
128 /****************************************************************
129 ****************************************************************/
131 static NTSTATUS gpttmpl_process(struct gp_inifile_context *ini_ctx,
132 struct registry_key *root_key,
138 /****************************************************************
139 ****************************************************************/
141 static NTSTATUS security_process_group_policy(ADS_STRUCT *ads,
144 struct registry_key *root_key,
145 const struct nt_user_token *token,
146 struct GROUP_POLICY_OBJECT *gpo,
147 const char *extension_guid,
148 const char *snapin_guid)
151 char *unix_path = NULL;
152 struct gp_inifile_context *ini_ctx = NULL;
154 debug_gpext_header(0, "security_process_group_policy", flags, gpo,
155 extension_guid, snapin_guid);
157 /* this handler processes the gpttmpl files and merge output to the
160 status = gpo_get_unix_path(mem_ctx, gpo, &unix_path);
161 if (!NT_STATUS_IS_OK(status)) {
165 status = gpttmpl_init_context(mem_ctx, flags, unix_path, &ini_ctx);
166 if (!NT_STATUS_IS_OK(status)) {
170 status = gpttmpl_process(ini_ctx, root_key, flags);
171 if (!NT_STATUS_IS_OK(status)) {
176 if (!NT_STATUS_IS_OK(status)) {
177 DEBUG(0,("security_process_group_policy: %s\n",
180 TALLOC_FREE(ini_ctx);
185 /****************************************************************
186 ****************************************************************/
188 static NTSTATUS security_get_reg_config(TALLOC_CTX *mem_ctx,
189 struct gp_extension_reg_info **reg_info)
192 struct gp_extension_reg_info *info = NULL;
194 struct gp_extension_reg_table table[] = {
195 /* FIXME: how can we store the "(Default)" value ??? */
196 /* { "", REG_SZ, "Security" }, */
197 { "ProcessGroupPolicy", REG_SZ, "security_process_group_policy" },
198 { "NoUserPolicy", REG_DWORD, "1" },
199 { "ExtensionDebugLevel", REG_DWORD, "1" },
200 { NULL, REG_NONE, NULL }
203 info = TALLOC_ZERO_P(mem_ctx, struct gp_extension_reg_info);
204 NT_STATUS_HAVE_NO_MEMORY(info);
206 status = gp_ext_info_add_entry(mem_ctx, GP_EXT_NAME,
207 GP_EXT_GUID_SECURITY,
209 NT_STATUS_NOT_OK_RETURN(status);
217 /****************************************************************
218 ****************************************************************/
220 static NTSTATUS security_initialize(TALLOC_CTX *mem_ctx)
225 /****************************************************************
226 ****************************************************************/
228 static NTSTATUS security_shutdown(void)
232 status = unregister_gp_extension(GP_EXT_NAME);
233 if (NT_STATUS_IS_OK(status)) {
242 /****************************************************************
243 ****************************************************************/
245 static struct gp_extension_methods security_methods = {
246 .initialize = security_initialize,
247 .process_group_policy = security_process_group_policy,
248 .get_reg_config = security_get_reg_config,
249 .shutdown = security_shutdown
252 /****************************************************************
253 ****************************************************************/
255 NTSTATUS gpext_security_init(void)
259 ctx = talloc_init("gpext_security_init");
260 NT_STATUS_HAVE_NO_MEMORY(ctx);
262 status = register_gp_extension(ctx, SMB_GPEXT_INTERFACE_VERSION,
263 GP_EXT_NAME, GP_EXT_GUID_SECURITY,
265 if (!NT_STATUS_IS_OK(status)) {