Merge branch 'v3-2-test' of ssh://git.samba.org/data/git/samba into v3-2-test
[samba.git] / examples / libsmbclient / testbrowse.c
index b5337ae983ad0fb7b95c8973747fe2c8aa6b7eab..562d2c2aeb8689dcddb32f7d090060d1158e5ff1 100644 (file)
@@ -24,12 +24,24 @@ static void browse(char * path,
                    int indent);
 
 
+static void
+get_auth_data_with_context_fn(SMBCCTX * context,
+                              const char * pServer,
+                              const char * pShare,
+                              char * pWorkgroup,
+                              int maxLenWorkgroup,
+                              char * pUsername,
+                              int maxLenUsername,
+                              char * pPassword,
+                              int maxLenPassword);
 
 int
 main(int argc, char * argv[])
 {
     int                         debug = 0;
     int                         debug_stderr = 0;
+    int                         no_auth = 0;
+    int                         context_auth = 0;
     int                         scan = 0;
     int                         iterations = -1;
     int                         again;
@@ -58,6 +70,14 @@ main(int argc, char * argv[])
                 "iterations", 'i', POPT_ARG_INT, &iterations,
                 0, "Iterations", "integer"
             },
+            {
+                "noauth", 'A', POPT_ARG_NONE, &no_auth,
+                0, "Do not request authentication data", "integer"
+            },
+            {
+                "contextauth", 'C', POPT_ARG_NONE, &context_auth,
+                0, "Use new authentication function with context", "integer"
+            },
             {
                 NULL
             }
@@ -82,14 +102,28 @@ main(int argc, char * argv[])
         return 1;
     }
         
+    /* If we're scanning, do no requests for authentication data */
+    if (scan) {
+        no_auth = 1;
+    }
+
     /* Set mandatory options (is that a contradiction in terms?) */
     context->debug = debug;
-    context->callbacks.auth_fn = (scan ? no_auth_data_fn : get_auth_data_fn);
+    if (context_auth) {
+        context->callbacks.auth_fn = NULL;
+        smbc_option_set(context,
+                        "auth_function",
+                        (void *) get_auth_data_with_context_fn);
+        smbc_option_set(context, "user_data", "hello world");
+    } else {
+        context->callbacks.auth_fn =
+            (no_auth ? no_auth_data_fn : get_auth_data_fn);
+    }
 
-    /* If we've been asked to log to stderr instead of stdout... */
+    /* If we've been asked to log to stderr instead of stdout... */
     if (debug_stderr) {
         /* ... then set the option to do so */
-        smbc_option_set(context, "debug_stderr");
+        smbc_option_set(context, "debug_to_stderr", 1);
     }
        
     /* Initialize the context using the previously specified options */
@@ -102,7 +136,6 @@ main(int argc, char * argv[])
     /* Tell the compatibility layer to use this context */
     smbc_set_context(context);
 
-
     if (scan)
     {
         for (;
@@ -152,6 +185,29 @@ no_auth_data_fn(const char * pServer,
     return;
 }
 
+
+static void
+get_auth_data_with_context_fn(SMBCCTX * context,
+                              const char * pServer,
+                              const char * pShare,
+                              char * pWorkgroup,
+                              int maxLenWorkgroup,
+                              char * pUsername,
+                              int maxLenUsername,
+                              char * pPassword,
+                              int maxLenPassword)
+{
+    printf("Authenticating with context 0x%lx", context);
+    if (context != NULL) {
+        char *user_data = smbc_option_get(context, "user_data");
+        printf(" with user data %s", user_data);
+    }
+    printf("\n");
+
+    get_auth_data_fn(pServer, pShare, pWorkgroup, maxLenWorkgroup,
+                     pUsername, maxLenUsername, pPassword, maxLenPassword);
+}
+
 static void browse(char * path, int scan, int indent)
 {
     char *                      p;