libgpo: pass cli_credentials instead of ADS_STRUCT to check_refresh_gpo*()
[metze/samba/wip.git] / libgpo / gpo_fetch.c
index a5714f7243a5a8ff7dbf1ea24488a265994bb499..80b812820d396ace6e93e9432d064a6b7e391d5e 100644 (file)
 #include "includes.h"
 #include "system/filesys.h"
 #include "../libgpo/gpo.h"
+#include "../libgpo/gpo_ini.h"
 
-#if _SAMBA_BUILD_ == 4
-#include "param/param.h"
-#include "libcli/resolve/resolve.h"
-#include "../lib/tevent/tevent.h"
-#include "libcli/libcli.h"
-#include "libcli/raw/libcliraw.h"
-#include "libcli/libcli_proto.h"
-#include "libgpo/ads_convenience.h"
-#include "libgpo/gpo_s4.h"
-#include "lib/util/util.h"
-#endif
+#include "libgpo/gpo_proto.h"
+#include "libsmb/libsmb.h"
 
 /****************************************************************
  explode the GPO CIFS URI into their components
@@ -78,11 +70,7 @@ NTSTATUS gpo_explode_filesyspath(TALLOC_CTX *mem_ctx,
                                        file_sys_path)) == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
-#if _SAMBA_BUILD_ == 4
-       path = string_sub_talloc(mem_ctx, path, "\\", "/");
-#else
        path = talloc_string_sub(mem_ctx, path, "\\", "/");
-#endif
        if (!path) {
                return NT_STATUS_NO_MEMORY;
        }
@@ -113,7 +101,7 @@ static NTSTATUS gpo_prepare_local_store(TALLOC_CTX *mem_ctx,
        }
 
        while (next_token_talloc(mem_ctx, &unix_path, &tok, "/")) {
-               if (strequal(tok, cache_dir)) {
+               if (strequal(tok, GPO_CACHE_DIR)) {
                        break;
                }
        }
@@ -130,24 +118,19 @@ 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,
+static NTSTATUS gpo_connect_server(struct cli_credentials *creds,
                                    const char *server, const char *service, void *ret_cli)
 {
        NTSTATUS result;
-#if _SAMBA_BUILD_ == 3
-       struct cli_state *cli;
+       struct cli_state *cli = NULL;
 
-
-       result = cli_full_connection(&cli,
-                       global_myname(),
+       result = cli_full_connection_creds(&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, NULL);
+                       creds, 0,
+                       SMB_SIGNING_REQUIRED);
        if (!NT_STATUS_IS_OK(result)) {
                DEBUG(10,("check_refresh_gpo: "
                                "failed to connect: %s\n",
@@ -155,32 +138,6 @@ static NTSTATUS gpo_connect_server(ADS_STRUCT *ads, struct loadparm_context *lp_
                return result;
        }
        *(struct cli_state **) ret_cli = cli;
-#else
-       struct smbcli_state *cli = NULL;
-       struct smbcli_options options;
-       struct smbcli_session_options session_options;
-
-       lp_smbcli_options(lp_ctx, &options);
-       lp_smbcli_session_options(lp_ctx, &session_options);
-
-       result = smbcli_full_connection(NULL, &cli,
-                       server,
-                       NULL, service,
-                       NULL /*devtype*/, NULL /* socket options */,
-                       ads->credentials,
-                       lp_resolve_context(lp_ctx),
-                       tevent_context_init(ads),
-                       &options,
-                       &session_options,
-                       lp_iconv_convenience(lp_ctx),
-                       lp_gensec_settings(ads, lp_ctx));
-       if (!NT_STATUS_IS_OK(result)) {
-               DEBUG(10,("failed to connect: %s\n",
-                               nt_errstr(result)));
-               return result;
-       }
-       *(struct smbcli_state **) ret_cli = cli;
-#endif
        return NT_STATUS_OK;
 }
 
@@ -189,19 +146,14 @@ static NTSTATUS gpo_connect_server(ADS_STRUCT *ads, struct loadparm_context *lp_
 ****************************************************************/
 
 NTSTATUS gpo_fetch_files(TALLOC_CTX *mem_ctx,
-                         ADS_STRUCT *ads,
-                         struct loadparm_context *lp_ctx,
+                        struct cli_credentials *creds,
                          const char *cache_dir,
-                        struct GROUP_POLICY_OBJECT *gpo)
+                        const struct GROUP_POLICY_OBJECT *gpo)
 {
        NTSTATUS result;
        char *server, *service, *nt_path, *unix_path;
        char *nt_ini_path, *unix_ini_path;
-#if _SAMBA_BUILD_ == 3
-       struct cli_state *cli;
-#else
-       struct smbcli_state *cli;
-#endif
+       struct cli_state *cli = NULL;
 
 
        result = gpo_explode_filesyspath(mem_ctx, cache_dir, gpo->file_sys_path,
@@ -209,9 +161,10 @@ NTSTATUS gpo_fetch_files(TALLOC_CTX *mem_ctx,
                                         &unix_path);
        NT_STATUS_NOT_OK_RETURN(result);
 
+       /* for now reuse the existing ds connection */
 
-       result = gpo_connect_server(ads, lp_ctx, server, service, &cli);
-
+       result = gpo_connect_server(creds, 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);