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(dictionary
*dict
,
60 uint32_t *version_out
)
62 const char *signature
= NULL
;
66 return NT_STATUS_INVALID_PARAMETER
;
69 if ((signature
= iniparser_getstring(dict
, GPTTMPL_SECTION_VERSION
70 ":"GPTTMPL_PARAMETER_SIGNATURE
, NULL
)) == NULL
) {
71 return NT_STATUS_INTERNAL_DB_CORRUPTION
;
74 if (!strequal(signature
, GPTTMPL_VALUE_CHICAGO
)) {
75 return NT_STATUS_INTERNAL_DB_CORRUPTION
;
78 if ((version
= iniparser_getint(dict
, GPTTMPL_SECTION_VERSION
79 ":"GPTTMPL_PARAMETER_REVISION
, Undefined
)) == Undefined
) {
80 return NT_STATUS_INTERNAL_DB_CORRUPTION
;
84 *version_out
= version
;
87 /* treat that as boolean */
88 if ((!iniparser_getboolean(dict
, GPTTMPL_SECTION_UNICODE
89 ":"GPTTMPL_PARAMETER_UNICODE
, Undefined
)) == Undefined
) {
90 return NT_STATUS_INTERNAL_DB_CORRUPTION
;
96 /****************************************************************
97 ****************************************************************/
99 static NTSTATUS
gpttmpl_init_context(TALLOC_CTX
*mem_ctx
,
101 const char *unix_path
,
102 struct gp_inifile_context
**ini_ctx
)
106 struct gp_inifile_context
*tmp_ctx
= NULL
;
108 status
= gp_inifile_init_context(mem_ctx
, flags
, unix_path
,
109 GPTTMPL_UNIX_PATH
, &tmp_ctx
);
110 NT_STATUS_NOT_OK_RETURN(status
);
112 status
= gpttmpl_parse_header(tmp_ctx
->dict
, &version
);
113 if (!NT_STATUS_IS_OK(status
)) {
114 DEBUG(1,("gpttmpl_init_context: failed: %s\n",
116 TALLOC_FREE(tmp_ctx
);
125 /****************************************************************
126 ****************************************************************/
128 static NTSTATUS
gpttmpl_process(struct gp_inifile_context
*ini_ctx
,
129 struct registry_key
*root_key
,
135 /****************************************************************
136 ****************************************************************/
138 static NTSTATUS
security_process_group_policy(ADS_STRUCT
*ads
,
141 struct registry_key
*root_key
,
142 const struct nt_user_token
*token
,
143 struct GROUP_POLICY_OBJECT
*gpo
,
144 const char *extension_guid
,
145 const char *snapin_guid
)
148 char *unix_path
= NULL
;
149 struct gp_inifile_context
*ini_ctx
= NULL
;
151 debug_gpext_header(0, "security_process_group_policy", flags
, gpo
,
152 extension_guid
, snapin_guid
);
154 /* this handler processes the gpttmpl files and merge output to the
157 status
= gpo_get_unix_path(mem_ctx
, gpo
, &unix_path
);
158 if (!NT_STATUS_IS_OK(status
)) {
162 status
= gpttmpl_init_context(mem_ctx
, flags
, unix_path
, &ini_ctx
);
163 if (!NT_STATUS_IS_OK(status
)) {
167 status
= gpttmpl_process(ini_ctx
, root_key
, flags
);
168 if (!NT_STATUS_IS_OK(status
)) {
173 if (!NT_STATUS_IS_OK(status
)) {
174 DEBUG(0,("security_process_group_policy: %s\n",
177 TALLOC_FREE(ini_ctx
);
182 /****************************************************************
183 ****************************************************************/
185 static NTSTATUS
security_get_reg_config(TALLOC_CTX
*mem_ctx
,
186 struct gp_extension_reg_info
**reg_info
)
189 struct gp_extension_reg_info
*info
= NULL
;
191 struct gp_extension_reg_table table
[] = {
192 /* FIXME: how can we store the "(Default)" value ??? */
193 /* { "", REG_SZ, "Security" }, */
194 { "ProcessGroupPolicy", REG_SZ
, "security_process_group_policy" },
195 { "NoUserPolicy", REG_DWORD
, "1" },
196 { "ExtensionDebugLevel", REG_DWORD
, "1" },
197 { NULL
, REG_NONE
, NULL
}
200 info
= TALLOC_ZERO_P(mem_ctx
, struct gp_extension_reg_info
);
201 NT_STATUS_HAVE_NO_MEMORY(info
);
203 status
= gp_ext_info_add_entry(mem_ctx
, GP_EXT_NAME
,
204 GP_EXT_GUID_SECURITY
,
206 NT_STATUS_NOT_OK_RETURN(status
);
214 /****************************************************************
215 ****************************************************************/
217 static NTSTATUS
security_initialize(TALLOC_CTX
*mem_ctx
)
222 /****************************************************************
223 ****************************************************************/
225 static NTSTATUS
security_shutdown(void)
229 status
= unregister_gp_extension(GP_EXT_NAME
);
230 if (NT_STATUS_IS_OK(status
)) {
239 /****************************************************************
240 ****************************************************************/
242 static struct gp_extension_methods security_methods
= {
243 .initialize
= security_initialize
,
244 .process_group_policy
= security_process_group_policy
,
245 .get_reg_config
= security_get_reg_config
,
246 .shutdown
= security_shutdown
249 /****************************************************************
250 ****************************************************************/
252 NTSTATUS
gpext_security_init(void)
256 ctx
= talloc_init("gpext_security_init");
257 NT_STATUS_HAVE_NO_MEMORY(ctx
);
259 status
= register_gp_extension(ctx
, SMB_GPEXT_INTERFACE_VERSION
,
260 GP_EXT_NAME
, GP_EXT_GUID_SECURITY
,
262 if (!NT_STATUS_IS_OK(status
)) {