s3-net: display full value of "msDS-SupportedEncryptionTypes".
[sfrench/samba-autobuild/.git] / source3 / libsmb / libsmb_context.c
index dbf70e02c8d2d6188ca53406077c3b1b37249e48..ffa4d2de921f95f20cdbb94c11651441a8e246ce 100644 (file)
@@ -1,10 +1,10 @@
-/* 
+/*
    Unix SMB/Netbios implementation.
    SMB client library implementation
    Copyright (C) Andrew Tridgell 1998
    Copyright (C) Richard Sharpe 2000, 2002
    Copyright (C) John Terpstra 2000
-   Copyright (C) Tom Jansen (Ninja ISD) 2002 
+   Copyright (C) Tom Jansen (Ninja ISD) 2002
    Copyright (C) Derrell Lipman 2003-2008
    Copyright (C) Jeremy Allison 2007, 2008
 
 #include "libsmbclient.h"
 #include "libsmb_internal.h"
 #include "secrets.h"
-
+#include "../libcli/smb/smbXcli_base.h"
 
 /*
- * Is the logging working / configfile read ? 
+ * Is the logging working / configfile read ?
  */
 static bool SMBC_initialized = false;
 static unsigned int initialized_ctx_count = 0;
@@ -52,13 +52,11 @@ SMBC_module_init(void * punused)
 
     /* Here we would open the smb.conf file if needed ... */
 
-    lp_set_in_client(True);
-
     home = getenv("HOME");
     if (home) {
         char *conf = NULL;
         if (asprintf(&conf, "%s/.smb/smb.conf", home) > 0) {
-            if (lp_load(conf, True, False, False, True)) {
+            if (lp_load_client(conf)) {
                 conf_loaded = True;
             } else {
                 DEBUG(5, ("Could not load config file: %s\n",
@@ -76,7 +74,7 @@ SMBC_module_init(void * punused)
          * defaults ...
          */
 
-        if (!lp_load(get_dyn_CONFIGFILE(), True, False, False, False)) {
+        if (!lp_load_client(get_dyn_CONFIGFILE())) {
             DEBUG(5, ("Could not load config file: %s\n",
                       get_dyn_CONFIGFILE()));
         } else if (home) {
@@ -89,7 +87,7 @@ SMBC_module_init(void * punused)
             if (asprintf(&conf,
                          "%s/.smb/smb.conf.append",
                          home) > 0) {
-                if (!lp_load(conf, True, False, False, False)) {
+                if (!lp_load_client_no_reinit(conf)) {
                     DEBUG(10,
                           ("Could not append config file: "
                            "%s\n",
@@ -125,9 +123,11 @@ SMBC_module_init(void * punused)
 static void
 SMBC_module_terminate(void)
 {
+    TALLOC_CTX *frame = talloc_stackframe();
     secrets_shutdown();
     gfree_all();
     SMBC_initialized = false;
+    TALLOC_FREE(frame);
 }
 
 
@@ -138,6 +138,7 @@ SMBCCTX *
 smbc_new_context(void)
 {
         SMBCCTX *context;
+       TALLOC_CTX *frame = talloc_stackframe();
 
         /* The first call to this function should initialize the module */
         SMB_THREAD_ONCE(&SMBC_initialized, SMBC_module_init, NULL);
@@ -148,6 +149,7 @@ smbc_new_context(void)
          */
         context = SMB_MALLOC_P(SMBCCTX);
         if (!context) {
+               TALLOC_FREE(frame);
                 errno = ENOMEM;
                 return NULL;
         }
@@ -156,6 +158,7 @@ smbc_new_context(void)
 
         context->internal = SMB_MALLOC_P(struct SMBC_internal_data);
         if (!context->internal) {
+               TALLOC_FREE(frame);
                 SAFE_FREE(context);
                 errno = ENOMEM;
                 return NULL;
@@ -166,6 +169,7 @@ smbc_new_context(void)
 
         smbc_setDebug(context, 0);
         smbc_setTimeout(context, 20000);
+        smbc_setPort(context, 0);
 
         smbc_setOptionFullTimeNames(context, False);
         smbc_setOptionOpenShareMode(context, SMBC_SHAREMODE_DENY_NONE);
@@ -223,6 +227,7 @@ smbc_new_context(void)
         smbc_setFunctionListPrintJobs(context, SMBC_list_print_jobs_ctx);
         smbc_setFunctionUnlinkPrintJob(context, SMBC_unlink_print_job_ctx);
 
+       TALLOC_FREE(frame);
         return context;
 }
 
@@ -237,11 +242,14 @@ int
 smbc_free_context(SMBCCTX *context,
                   int shutdown_ctx)
 {
+       TALLOC_CTX *frame;
         if (!context) {
                 errno = EBADF;
                 return 1;
         }
 
+       frame = talloc_stackframe();
+
         if (shutdown_ctx) {
                 SMBCFILE * f;
                 DEBUG(1,("Performing aggressive shutdown.\n"));
@@ -261,8 +269,8 @@ smbc_free_context(SMBCCTX *context,
                                   "Nice way shutdown failed.\n"));
                         s = context->internal->servers;
                         while (s) {
-                                DEBUG(1, ("Forced shutdown: %p (fd=%d)\n",
-                                          s, s->cli->fd));
+                                DEBUG(1, ("Forced shutdown: %p (cli=%p)\n",
+                                          s, s->cli));
                                 cli_shutdown(s->cli);
                                 smbc_getFunctionRemoveCachedServer(context)(context,
                                                                          s);
@@ -280,18 +288,21 @@ smbc_free_context(SMBCCTX *context,
                         DEBUG(1, ("Could not purge all servers, "
                                   "free_context failed.\n"));
                         errno = EBUSY;
+                       TALLOC_FREE(frame);
                         return 1;
                 }
                 if (context->internal->servers) {
                         DEBUG(1, ("Active servers in context, "
                                   "free_context failed.\n"));
                         errno = EBUSY;
+                       TALLOC_FREE(frame);
                         return 1;
                 }
                 if (context->internal->files) {
                         DEBUG(1, ("Active files in context, "
                                   "free_context failed.\n"));
                         errno = EBUSY;
+                       TALLOC_FREE(frame);
                         return 1;
                 }
         }
@@ -327,6 +338,7 @@ smbc_free_context(SMBCCTX *context,
                 smb_panic("error unlocking 'initialized_ctx_count'");
        }
 
+       TALLOC_FREE(frame);
         return 0;
 }
 
@@ -349,6 +361,8 @@ smbc_option_set(SMBCCTX *context,
                 const char *s;
         } option_value;
 
+       TALLOC_CTX *frame = talloc_stackframe();
+
         va_start(ap, option_name);
 
         if (strcmp(option_name, "debug_to_stderr") == 0) {
@@ -415,6 +429,7 @@ smbc_option_set(SMBCCTX *context,
         }
 
         va_end(ap);
+       TALLOC_FREE(frame);
 }
 
 
@@ -470,7 +485,7 @@ smbc_option_get(SMBCCTX *context,
 
                 for (s = context->internal->servers; s; s = s->next) {
                         num_servers++;
-                        if (s->cli->trans_enc_state == NULL) {
+                        if (!smb1cli_conn_encryption_on(s->cli->conn)) {
                                 return (void *)false;
                         }
                 }
@@ -545,6 +560,7 @@ SMBCCTX *
 smbc_init_context(SMBCCTX *context)
 {
         int pid;
+        TALLOC_CTX *frame;
 
         if (!context) {
                 errno = EBADF;
@@ -556,11 +572,14 @@ smbc_init_context(SMBCCTX *context)
                 return NULL;
         }
 
+        frame = talloc_stackframe();
+
         if ((!smbc_getFunctionAuthData(context) &&
              !smbc_getFunctionAuthDataWithContext(context)) ||
             smbc_getDebug(context) < 0 ||
             smbc_getDebug(context) > 100) {
 
+                TALLOC_FREE(frame);
                 errno = EINVAL;
                 return NULL;
 
@@ -579,6 +598,7 @@ smbc_init_context(SMBCCTX *context)
                 }
 
                 if (!user) {
+                        TALLOC_FREE(frame);
                         errno = ENOMEM;
                         return NULL;
                 }
@@ -587,6 +607,7 @@ smbc_init_context(SMBCCTX *context)
                SAFE_FREE(user);
 
                if (!smbc_getUser(context)) {
+                        TALLOC_FREE(frame);
                         errno = ENOMEM;
                         return NULL;
                 }
@@ -606,9 +627,10 @@ smbc_init_context(SMBCCTX *context)
                          * Hmmm, I want to get hostname as well, but I am too
                          * lazy for the moment
                          */
-                        pid = sys_getpid();
+                        pid = getpid();
                         netbios_name = (char *)SMB_MALLOC(17);
                         if (!netbios_name) {
+                                TALLOC_FREE(frame);
                                 errno = ENOMEM;
                                 return NULL;
                         }
@@ -617,6 +639,7 @@ smbc_init_context(SMBCCTX *context)
                 }
 
                 if (!netbios_name) {
+                        TALLOC_FREE(frame);
                         errno = ENOMEM;
                         return NULL;
                 }
@@ -625,6 +648,7 @@ smbc_init_context(SMBCCTX *context)
                SAFE_FREE(netbios_name);
 
                 if (!smbc_getNetbiosName(context)) {
+                        TALLOC_FREE(frame);
                         errno = ENOMEM;
                         return NULL;
                 }
@@ -644,6 +668,7 @@ smbc_init_context(SMBCCTX *context)
                 }
 
                 if (!workgroup) {
+                        TALLOC_FREE(frame);
                         errno = ENOMEM;
                         return NULL;
                 }
@@ -652,6 +677,7 @@ smbc_init_context(SMBCCTX *context)
                SAFE_FREE(workgroup);
 
                if (!smbc_getWorkgroup(context)) {
+                        TALLOC_FREE(frame);
                        errno = ENOMEM;
                        return NULL;
                }
@@ -677,6 +703,7 @@ smbc_init_context(SMBCCTX *context)
                 smb_panic("error unlocking 'initialized_ctx_count'");
        }
 
+        TALLOC_FREE(frame);
         return context;
 }
 
@@ -712,12 +739,15 @@ void smbc_set_credentials_with_fallback(SMBCCTX *context,
        smbc_bool use_kerberos = false;
        const char *signing_state = "off";
        struct user_auth_info *auth_info = NULL;
+       TALLOC_CTX *frame;
 
        if (! context) {
 
                return;
        }
 
+       frame = talloc_stackframe();
+
        if (! workgroup || ! *workgroup) {
                workgroup = smbc_getWorkgroup(context);
        }
@@ -734,6 +764,7 @@ void smbc_set_credentials_with_fallback(SMBCCTX *context,
 
        if (! auth_info) {
                DEBUG(0, ("smbc_set_credentials_with_fallback: allocation fail\n"));
+               TALLOC_FREE(frame);
                return;
        }
 
@@ -741,12 +772,12 @@ void smbc_set_credentials_with_fallback(SMBCCTX *context,
                use_kerberos = True;
        }
 
-       if (lp_client_signing()) {
-               signing_state = "on";
+       if (lp_client_signing() != SMB_SIGNING_OFF) {
+               signing_state = "if_required";
        }
 
-       if (lp_client_signing() == Required) {
-               signing_state = "force";
+       if (lp_client_signing() == SMB_SIGNING_REQUIRED) {
+               signing_state = "required";
        }
 
         set_cmdline_auth_info_username(auth_info, user);
@@ -762,4 +793,5 @@ void smbc_set_credentials_with_fallback(SMBCCTX *context,
        TALLOC_FREE(context->internal->auth_info);
 
         context->internal->auth_info = auth_info;
+       TALLOC_FREE(frame);
 }