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/>.
22 /****************************************************************
23 explode the GPO CIFS URI into their components
24 ****************************************************************/
26 NTSTATUS gpo_explode_filesyspath(TALLOC_CTX *mem_ctx,
27 const char *file_sys_path,
45 if (!next_token(&file_sys_path, tok, "\\", sizeof(tok))) {
46 return NT_STATUS_INVALID_PARAMETER;
49 if ((*server = talloc_strdup(mem_ctx, tok)) == NULL) {
50 return NT_STATUS_NO_MEMORY;
53 if (!next_token(&file_sys_path, tok, "\\", sizeof(tok))) {
54 return NT_STATUS_INVALID_PARAMETER;
57 if ((*service = talloc_strdup(mem_ctx, tok)) == NULL) {
58 return NT_STATUS_NO_MEMORY;
61 if ((*nt_path = talloc_asprintf(mem_ctx, "\\%s", file_sys_path)) == NULL) {
62 return NT_STATUS_NO_MEMORY;
65 pstrcpy(path, lock_path(GPO_CACHE_DIR));
67 pstrcat(path, file_sys_path);
68 pstring_sub(path, "\\", "/");
70 if ((*unix_path = talloc_strdup(mem_ctx, path)) == NULL) {
71 return NT_STATUS_NO_MEMORY;
77 /****************************************************************
78 prepare the local disc storage for "unix_path"
79 ****************************************************************/
81 static NTSTATUS gpo_prepare_local_store(TALLOC_CTX *mem_ctx,
82 const char *unix_path)
84 const char *top_dir = lock_path(GPO_CACHE_DIR);
88 current_dir = talloc_strdup(mem_ctx, top_dir);
89 NT_STATUS_HAVE_NO_MEMORY(current_dir);
91 if ((mkdir(top_dir, 0644)) < 0 && errno != EEXIST) {
92 return NT_STATUS_ACCESS_DENIED;
95 while (next_token(&unix_path, tok, "/", sizeof(tok))) {
97 if (strequal(tok, GPO_CACHE_DIR)) {
102 while (next_token(&unix_path, tok, "/", sizeof(tok))) {
104 current_dir = talloc_asprintf_append(current_dir, "/%s", tok);
105 NT_STATUS_HAVE_NO_MEMORY(current_dir);
107 if ((mkdir(current_dir, 0644)) < 0 && errno != EEXIST) {
108 return NT_STATUS_ACCESS_DENIED;
115 /****************************************************************
116 download a full GPO via CIFS
117 ****************************************************************/
119 NTSTATUS gpo_fetch_files(TALLOC_CTX *mem_ctx,
120 struct cli_state *cli,
121 struct GROUP_POLICY_OBJECT *gpo)
124 char *server, *service, *nt_path, *unix_path, *nt_ini_path, *unix_ini_path;
126 result = gpo_explode_filesyspath(mem_ctx, gpo->file_sys_path,
127 &server, &service, &nt_path, &unix_path);
128 if (!NT_STATUS_IS_OK(result)) {
132 result = gpo_prepare_local_store(mem_ctx, unix_path);
133 if (!NT_STATUS_IS_OK(result)) {
137 unix_ini_path = talloc_asprintf(mem_ctx, "%s/%s", unix_path, GPT_INI);
138 nt_ini_path = talloc_asprintf(mem_ctx, "%s\\%s", nt_path, GPT_INI);
139 if (!unix_path || !nt_ini_path) {
140 result = NT_STATUS_NO_MEMORY;
144 result = gpo_copy_file(mem_ctx, cli, nt_ini_path, unix_ini_path);
145 if (!NT_STATUS_IS_OK(result)) {
149 result = gpo_sync_directories(mem_ctx, cli, nt_path, unix_path);
150 if (!NT_STATUS_IS_OK(result)) {
154 result = NT_STATUS_OK;
160 /****************************************************************
161 get the locally stored gpt.ini version number
162 ****************************************************************/
164 NTSTATUS gpo_get_sysvol_gpt_version(TALLOC_CTX *mem_ctx,
165 const char *unix_path,
166 uint32 *sysvol_version,
171 char *local_path = NULL;
178 local_path = talloc_asprintf(mem_ctx, "%s/%s", unix_path, GPT_INI);
179 NT_STATUS_HAVE_NO_MEMORY(local_path);
181 status = parse_gpt_ini(mem_ctx, local_path, &version, &name);
182 if (!NT_STATUS_IS_OK(status)) {
183 DEBUG(10,("gpo_get_sysvol_gpt_version: failed to parse ini [%s]: %s\n",
184 unix_path, nt_errstr(status)));
188 if (sysvol_version) {
189 *sysvol_version = version;
192 if (name && *display_name) {
193 *display_name = talloc_strdup(mem_ctx, name);
194 NT_STATUS_HAVE_NO_MEMORY(*display_name);