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 2 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, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 /****************************************************************
24 explode the GPO CIFS URI into their components
25 ****************************************************************/
27 NTSTATUS ads_gpo_explode_filesyspath(ADS_STRUCT *ads,
29 const char *file_sys_path,
43 if (!next_token(&file_sys_path, tok, "\\", sizeof(tok))) {
44 return NT_STATUS_INVALID_PARAMETER;
47 if ((*server = talloc_strdup(mem_ctx, tok)) == NULL) {
48 return NT_STATUS_NO_MEMORY;
51 if (!next_token(&file_sys_path, tok, "\\", sizeof(tok))) {
52 return NT_STATUS_INVALID_PARAMETER;
55 if ((*service = talloc_strdup(mem_ctx, tok)) == NULL) {
56 return NT_STATUS_NO_MEMORY;
59 if ((*nt_path = talloc_asprintf(mem_ctx, "\\%s", file_sys_path)) == NULL) {
60 return NT_STATUS_NO_MEMORY;
63 pstrcpy(path, lock_path(GPO_CACHE_DIR));
65 pstrcat(path, file_sys_path);
66 pstring_sub(path, "\\", "/");
68 if ((*unix_path = talloc_strdup(mem_ctx, path)) == NULL) {
69 return NT_STATUS_NO_MEMORY;
75 /****************************************************************
76 prepare the local disc storage for "unix_path"
77 ****************************************************************/
79 NTSTATUS ads_gpo_prepare_local_store(ADS_STRUCT *ads,
81 const char *unix_path)
83 const char *top_dir = lock_path(GPO_CACHE_DIR);
87 current_dir = talloc_strdup(mem_ctx, top_dir);
88 NT_STATUS_HAVE_NO_MEMORY(current_dir);
90 if ((mkdir(top_dir, 0644)) < 0 && errno != EEXIST) {
91 return NT_STATUS_ACCESS_DENIED;
94 while (next_token(&unix_path, tok, "/", sizeof(tok))) {
96 if (strequal(tok, GPO_CACHE_DIR)) {
101 while (next_token(&unix_path, tok, "/", sizeof(tok))) {
103 current_dir = talloc_asprintf_append(current_dir, "/%s", tok);
104 NT_STATUS_HAVE_NO_MEMORY(current_dir);
106 if ((mkdir(current_dir, 0644)) < 0 && errno != EEXIST) {
107 return NT_STATUS_ACCESS_DENIED;
114 /****************************************************************
115 download a full GPO via CIFS
116 ****************************************************************/
118 NTSTATUS ads_fetch_gpo_files(ADS_STRUCT *ads,
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 = ads_gpo_explode_filesyspath(ads, mem_ctx, gpo->file_sys_path,
127 &server, &service, &nt_path, &unix_path);
128 if (!NT_STATUS_IS_OK(result)) {
132 result = ads_gpo_prepare_local_store(ads, 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 ads_gpo_get_sysvol_gpt_version(ADS_STRUCT *ads,
166 const char *unix_path,
167 uint32 *sysvol_version,
172 char *local_path = NULL;
175 local_path = talloc_asprintf(mem_ctx, "%s/%s", unix_path, GPT_INI);
176 NT_STATUS_HAVE_NO_MEMORY(local_path);
178 status = parse_gpt_ini(mem_ctx, local_path, &version, &name);
179 if (!NT_STATUS_IS_OK(status)) {
180 DEBUG(10,("ads_gpo_get_sysvol_gpt_version: failed to parse ini [%s]: %s\n",
181 unix_path, nt_errstr(status)));
185 if (sysvol_version) {
186 *sysvol_version = version;
189 if (name && *display_name) {
190 *display_name = talloc_strdup(mem_ctx, name);