2 * Unix SMB/CIFS implementation.
3 * Group Policy Object Support
4 * Copyright (C) Guenther Deschner 2005-2006
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 "system/filesys.h"
22 #include "../libgpo/gpo.h"
23 #include "../libgpo/gpo_ini.h"
25 #include "libgpo/gpo_proto.h"
26 #include "libsmb/libsmb.h"
28 /****************************************************************
29 explode the GPO CIFS URI into their components
30 ****************************************************************/
32 NTSTATUS
gpo_explode_filesyspath(TALLOC_CTX
*mem_ctx
,
33 const char *cache_dir
,
34 const char *file_sys_path
,
51 if (!next_token_talloc(mem_ctx
, &file_sys_path
, server
, "\\")) {
52 return NT_STATUS_INVALID_PARAMETER
;
54 NT_STATUS_HAVE_NO_MEMORY(*server
);
56 if (!next_token_talloc(mem_ctx
, &file_sys_path
, service
, "\\")) {
57 return NT_STATUS_INVALID_PARAMETER
;
59 NT_STATUS_HAVE_NO_MEMORY(*service
);
61 if ((*nt_path
= talloc_asprintf(mem_ctx
, "\\%s", file_sys_path
))
63 return NT_STATUS_NO_MEMORY
;
65 NT_STATUS_HAVE_NO_MEMORY(*nt_path
);
67 if ((path
= talloc_asprintf(mem_ctx
,
70 file_sys_path
)) == NULL
) {
71 return NT_STATUS_NO_MEMORY
;
73 path
= talloc_string_sub(mem_ctx
, path
, "\\", "/");
75 return NT_STATUS_NO_MEMORY
;
78 *unix_path
= talloc_strdup(mem_ctx
, path
);
79 NT_STATUS_HAVE_NO_MEMORY(*unix_path
);
85 /****************************************************************
86 prepare the local disc storage for "unix_path"
87 ****************************************************************/
89 static NTSTATUS
gpo_prepare_local_store(TALLOC_CTX
*mem_ctx
,
90 const char *cache_dir
,
91 const char *unix_path
)
96 current_dir
= talloc_strdup(mem_ctx
, cache_dir
);
97 NT_STATUS_HAVE_NO_MEMORY(current_dir
);
99 if ((mkdir(cache_dir
, 0644)) < 0 && errno
!= EEXIST
) {
100 return NT_STATUS_ACCESS_DENIED
;
103 while (next_token_talloc(mem_ctx
, &unix_path
, &tok
, "/")) {
104 if (strequal(tok
, GPO_CACHE_DIR
)) {
109 while (next_token_talloc(mem_ctx
, &unix_path
, &tok
, "/")) {
110 current_dir
= talloc_asprintf_append_buffer(current_dir
, "/%s", tok
);
111 NT_STATUS_HAVE_NO_MEMORY(current_dir
);
113 if ((mkdir(current_dir
, 0644)) < 0 && errno
!= EEXIST
) {
114 return NT_STATUS_ACCESS_DENIED
;
121 static NTSTATUS
gpo_connect_server(ADS_STRUCT
*ads
, struct loadparm_context
*lp_ctx
,
122 const char *server
, const char *service
, void *ret_cli
)
125 struct cli_state
*cli
;
127 result
= cli_full_connection(&cli
,
132 ads
->auth
.user_name
, NULL
,
134 CLI_FULL_CONNECTION_USE_KERBEROS
|
135 CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS
,
137 if (!NT_STATUS_IS_OK(result
)) {
138 DEBUG(10,("check_refresh_gpo: "
139 "failed to connect: %s\n",
143 *(struct cli_state
**) ret_cli
= cli
;
147 /****************************************************************
148 download a full GPO via CIFS
149 ****************************************************************/
151 NTSTATUS
gpo_fetch_files(TALLOC_CTX
*mem_ctx
,
153 struct loadparm_context
*lp_ctx
,
154 const char *cache_dir
,
155 struct GROUP_POLICY_OBJECT
*gpo
)
158 char *server
, *service
, *nt_path
, *unix_path
;
159 char *nt_ini_path
, *unix_ini_path
;
160 struct cli_state
*cli
;
163 result
= gpo_explode_filesyspath(mem_ctx
, cache_dir
, gpo
->file_sys_path
,
164 &server
, &service
, &nt_path
,
166 NT_STATUS_NOT_OK_RETURN(result
);
169 result
= gpo_connect_server(ads
, lp_ctx
, server
, service
, &cli
);
170 NT_STATUS_NOT_OK_RETURN(result
);
173 result
= gpo_prepare_local_store(mem_ctx
, cache_dir
, unix_path
);
174 NT_STATUS_NOT_OK_RETURN(result
);
176 unix_ini_path
= talloc_asprintf(mem_ctx
, "%s/%s", unix_path
, GPT_INI
);
177 nt_ini_path
= talloc_asprintf(mem_ctx
, "%s\\%s", nt_path
, GPT_INI
);
178 NT_STATUS_HAVE_NO_MEMORY(unix_ini_path
);
179 NT_STATUS_HAVE_NO_MEMORY(nt_ini_path
);
181 result
= gpo_copy_file(mem_ctx
, cli
, nt_ini_path
, unix_ini_path
);
182 NT_STATUS_NOT_OK_RETURN(result
);
184 result
= gpo_sync_directories(mem_ctx
, cli
, nt_path
, unix_path
);
185 NT_STATUS_NOT_OK_RETURN(result
);
190 /****************************************************************
191 get the locally stored gpt.ini version number
192 ****************************************************************/
194 NTSTATUS
gpo_get_sysvol_gpt_version(TALLOC_CTX
*mem_ctx
,
195 const char *unix_path
,
196 uint32_t *sysvol_version
,
200 uint32_t version
= 0;
201 char *local_path
= NULL
;
208 local_path
= talloc_asprintf(mem_ctx
, "%s/%s", unix_path
, GPT_INI
);
209 NT_STATUS_HAVE_NO_MEMORY(local_path
);
211 status
= parse_gpt_ini(mem_ctx
, local_path
, &version
, &name
);
212 if (!NT_STATUS_IS_OK(status
)) {
213 DEBUG(10,("gpo_get_sysvol_gpt_version: "
214 "failed to parse ini [%s]: %s\n",
215 local_path
, nt_errstr(status
)));
219 if (sysvol_version
) {
220 *sysvol_version
= version
;
223 if (name
&& *display_name
) {
224 *display_name
= talloc_strdup(mem_ctx
, name
);
225 NT_STATUS_HAVE_NO_MEMORY(*display_name
);