summaryrefslogtreecommitdiff
path: root/libgpo
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2009-03-01 02:53:42 +0100
committerGünther Deschner <gd@samba.org>2009-04-20 23:16:16 +0200
commit7761850b1f6062b61fbb05124e23703c191229d1 (patch)
tree13ebfa86b53847f0ca23d809c056315cd2911340 /libgpo
parentd2bd5895cf9b8a3572b17bca850e9c56a4cca901 (diff)
downloadsamba-7761850b1f6062b61fbb05124e23703c191229d1.tar.gz
Move gpo_fetch to top-level.
Signed-off-by: Günther Deschner <gd@samba.org>
Diffstat (limited to 'libgpo')
-rw-r--r--libgpo/config.mk2
-rw-r--r--libgpo/gpo_fetch.c189
2 files changed, 190 insertions, 1 deletions
diff --git a/libgpo/config.mk b/libgpo/config.mk
index 10cd2382858..20901bf28cb 100644
--- a/libgpo/config.mk
+++ b/libgpo/config.mk
@@ -1,4 +1,4 @@
[SUBSYSTEM::LIBGPO]
LIBGPO_OBJ_FILES = ../libgpo/gpo_util.o ../libgpo/gpo_sec.o \
- ../libgpo/gpext/gpext.o
+ ../libgpo/gpext/gpext.o ../libgpo/gpo_fetch.o
diff --git a/libgpo/gpo_fetch.c b/libgpo/gpo_fetch.c
new file mode 100644
index 00000000000..03759262cd6
--- /dev/null
+++ b/libgpo/gpo_fetch.c
@@ -0,0 +1,189 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * Group Policy Object Support
+ * Copyright (C) Guenther Deschner 2005-2006
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "includes.h"
+#include "system/filesys.h"
+#include "../libgpo/gpo.h"
+
+/****************************************************************
+ explode the GPO CIFS URI into their components
+****************************************************************/
+
+NTSTATUS gpo_explode_filesyspath(TALLOC_CTX *mem_ctx,
+ const char *file_sys_path,
+ char **server,
+ char **service,
+ char **nt_path,
+ char **unix_path)
+{
+ char *path = NULL;
+
+ *server = NULL;
+ *service = NULL;
+ *nt_path = NULL;
+ *unix_path = NULL;
+
+ if (!file_sys_path) {
+ return NT_STATUS_OK;
+ }
+
+ if (!next_token_talloc(mem_ctx, &file_sys_path, server, "\\")) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+ NT_STATUS_HAVE_NO_MEMORY(*server);
+
+ if (!next_token_talloc(mem_ctx, &file_sys_path, service, "\\")) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+ NT_STATUS_HAVE_NO_MEMORY(*service);
+
+ if ((*nt_path = talloc_asprintf(mem_ctx, "\\%s", file_sys_path))
+ == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
+ NT_STATUS_HAVE_NO_MEMORY(*nt_path);
+
+ if ((path = talloc_asprintf(mem_ctx,
+ "%s/%s",
+ cache_path(GPO_CACHE_DIR),
+ file_sys_path)) == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
+ path = talloc_string_sub(mem_ctx, path, "\\", "/");
+ if (!path) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ *unix_path = talloc_strdup(mem_ctx, path);
+ NT_STATUS_HAVE_NO_MEMORY(*unix_path);
+
+ talloc_free(path);
+ return NT_STATUS_OK;
+}
+
+/****************************************************************
+ prepare the local disc storage for "unix_path"
+****************************************************************/
+
+static NTSTATUS gpo_prepare_local_store(TALLOC_CTX *mem_ctx,
+ const char *unix_path)
+{
+ const char *top_dir = cache_path(GPO_CACHE_DIR);
+ char *current_dir;
+ char *tok;
+
+ current_dir = talloc_strdup(mem_ctx, top_dir);
+ NT_STATUS_HAVE_NO_MEMORY(current_dir);
+
+ if ((mkdir(top_dir, 0644)) < 0 && errno != EEXIST) {
+ return NT_STATUS_ACCESS_DENIED;
+ }
+
+ while (next_token_talloc(mem_ctx, &unix_path, &tok, "/")) {
+ if (strequal(tok, GPO_CACHE_DIR)) {
+ break;
+ }
+ }
+
+ while (next_token_talloc(mem_ctx, &unix_path, &tok, "/")) {
+ current_dir = talloc_asprintf_append_buffer(current_dir, "/%s", tok);
+ NT_STATUS_HAVE_NO_MEMORY(current_dir);
+
+ if ((mkdir(current_dir, 0644)) < 0 && errno != EEXIST) {
+ return NT_STATUS_ACCESS_DENIED;
+ }
+ }
+
+ return NT_STATUS_OK;
+}
+
+/****************************************************************
+ download a full GPO via CIFS
+****************************************************************/
+
+NTSTATUS gpo_fetch_files(TALLOC_CTX *mem_ctx,
+ struct cli_state *cli,
+ struct GROUP_POLICY_OBJECT *gpo)
+{
+ NTSTATUS result;
+ char *server, *service, *nt_path, *unix_path;
+ char *nt_ini_path, *unix_ini_path;
+
+ result = gpo_explode_filesyspath(mem_ctx, gpo->file_sys_path,
+ &server, &service, &nt_path,
+ &unix_path);
+ NT_STATUS_NOT_OK_RETURN(result);
+
+ result = gpo_prepare_local_store(mem_ctx, unix_path);
+ NT_STATUS_NOT_OK_RETURN(result);
+
+ unix_ini_path = talloc_asprintf(mem_ctx, "%s/%s", unix_path, GPT_INI);
+ nt_ini_path = talloc_asprintf(mem_ctx, "%s\\%s", nt_path, GPT_INI);
+ NT_STATUS_HAVE_NO_MEMORY(unix_ini_path);
+ NT_STATUS_HAVE_NO_MEMORY(nt_ini_path);
+
+ result = gpo_copy_file(mem_ctx, cli, nt_ini_path, unix_ini_path);
+ NT_STATUS_NOT_OK_RETURN(result);
+
+ result = gpo_sync_directories(mem_ctx, cli, nt_path, unix_path);
+ NT_STATUS_NOT_OK_RETURN(result);
+
+ return NT_STATUS_OK;
+}
+
+/****************************************************************
+ get the locally stored gpt.ini version number
+****************************************************************/
+
+NTSTATUS gpo_get_sysvol_gpt_version(TALLOC_CTX *mem_ctx,
+ const char *unix_path,
+ uint32_t *sysvol_version,
+ char **display_name)
+{
+ NTSTATUS status;
+ uint32_t version = 0;
+ char *local_path = NULL;
+ char *name = NULL;
+
+ if (!unix_path) {
+ return NT_STATUS_OK;
+ }
+
+ local_path = talloc_asprintf(mem_ctx, "%s/%s", unix_path, GPT_INI);
+ NT_STATUS_HAVE_NO_MEMORY(local_path);
+
+ status = parse_gpt_ini(mem_ctx, local_path, &version, &name);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(10,("gpo_get_sysvol_gpt_version: "
+ "failed to parse ini [%s]: %s\n",
+ local_path, nt_errstr(status)));
+ return status;
+ }
+
+ if (sysvol_version) {
+ *sysvol_version = version;
+ }
+
+ if (name && *display_name) {
+ *display_name = talloc_strdup(mem_ctx, name);
+ NT_STATUS_HAVE_NO_MEMORY(*display_name);
+ }
+
+ return NT_STATUS_OK;
+}