s3-net: Fixed a small typo in net conf function table
[samba.git] / libgpo / gpo_fetch.c
index 03759262cd6cbdd1ddd0e3df9b9a33d9665888e3..4e895bf544efbcabe991a492b155d3f93d468387 100644 (file)
 #include "includes.h"
 #include "system/filesys.h"
 #include "../libgpo/gpo.h"
+#include "../libgpo/gpo_ini.h"
+
+#include "libgpo/gpo_proto.h"
+#include "libsmb/libsmb.h"
 
 /****************************************************************
  explode the GPO CIFS URI into their components
 ****************************************************************/
 
 NTSTATUS gpo_explode_filesyspath(TALLOC_CTX *mem_ctx,
+                                 const char *cache_dir,
                                 const char *file_sys_path,
                                 char **server,
                                 char **service,
@@ -61,7 +66,7 @@ NTSTATUS gpo_explode_filesyspath(TALLOC_CTX *mem_ctx,
 
        if ((path = talloc_asprintf(mem_ctx,
                                        "%s/%s",
-                                       cache_path(GPO_CACHE_DIR),
+                                       cache_dir,
                                        file_sys_path)) == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
@@ -82,16 +87,16 @@ NTSTATUS gpo_explode_filesyspath(TALLOC_CTX *mem_ctx,
 ****************************************************************/
 
 static NTSTATUS gpo_prepare_local_store(TALLOC_CTX *mem_ctx,
+                                        const char *cache_dir,
                                        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);
+       current_dir = talloc_strdup(mem_ctx, cache_dir);
        NT_STATUS_HAVE_NO_MEMORY(current_dir);
 
-       if ((mkdir(top_dir, 0644)) < 0 && errno != EEXIST) {
+       if ((mkdir(cache_dir, 0644)) < 0 && errno != EEXIST) {
                return NT_STATUS_ACCESS_DENIED;
        }
 
@@ -113,24 +118,59 @@ static NTSTATUS gpo_prepare_local_store(TALLOC_CTX *mem_ctx,
        return NT_STATUS_OK;
 }
 
+static NTSTATUS gpo_connect_server(ADS_STRUCT *ads, struct loadparm_context *lp_ctx,
+                                   const char *server, const char *service, void *ret_cli)
+{
+       NTSTATUS result;
+       struct cli_state *cli;
+
+       result = cli_full_connection(&cli,
+                       lp_netbios_name(),
+                       server,
+                       NULL, 0,
+                       service, "A:",
+                       ads->auth.user_name, NULL,
+                       ads->auth.password,
+                       CLI_FULL_CONNECTION_USE_KERBEROS |
+                       CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS,
+                       Undefined);
+       if (!NT_STATUS_IS_OK(result)) {
+               DEBUG(10,("check_refresh_gpo: "
+                               "failed to connect: %s\n",
+                               nt_errstr(result)));
+               return result;
+       }
+       *(struct cli_state **) ret_cli = cli;
+       return NT_STATUS_OK;
+}
+
 /****************************************************************
  download a full GPO via CIFS
 ****************************************************************/
 
 NTSTATUS gpo_fetch_files(TALLOC_CTX *mem_ctx,
-                        struct cli_state *cli,
+                         ADS_STRUCT *ads,
+                         struct loadparm_context *lp_ctx,
+                         const char *cache_dir,
                         struct GROUP_POLICY_OBJECT *gpo)
 {
        NTSTATUS result;
        char *server, *service, *nt_path, *unix_path;
        char *nt_ini_path, *unix_ini_path;
+       struct cli_state *cli;
+
 
-       result = gpo_explode_filesyspath(mem_ctx, gpo->file_sys_path,
+       result = gpo_explode_filesyspath(mem_ctx, cache_dir, 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);
+
+       result = gpo_connect_server(ads, lp_ctx, server, service, &cli);
+       NT_STATUS_NOT_OK_RETURN(result);
+
+
+       result = gpo_prepare_local_store(mem_ctx, cache_dir, unix_path);
        NT_STATUS_NOT_OK_RETURN(result);
 
        unix_ini_path = talloc_asprintf(mem_ctx, "%s/%s", unix_path, GPT_INI);