From 8d976560e07ccf11ac49926ee742ca41ff77c248 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Fri, 19 Mar 2004 17:36:56 +0000 Subject: Apply some more of Derrell Lipman's changes. (This used to be commit a6457e1c817663cf5f3e77e4dd431ac0d9184dc7) --- examples/libsmbclient/testbrowse.c | 91 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 examples/libsmbclient/testbrowse.c (limited to 'examples/libsmbclient/testbrowse.c') diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c new file mode 100644 index 0000000000..d2472230a2 --- /dev/null +++ b/examples/libsmbclient/testbrowse.c @@ -0,0 +1,91 @@ +/* + Unix SMB/CIFS implementation. + SMB client library test program for browsing with different master browsers + Copyright (C) Derrell Lipman 2004 + + 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 2 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, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include +#include +#include +#include +#include +#include +#include + +static void +auth_fn(const char * pServer, + const char * pShare, + char * pWorkgroup, + int workgroup_len, + char * pUsername, + int username_len, + char * pPassword, + int password_len) + +{ + strncpy(pUsername, "anonymous", username_len); /* doesn't matter what */ + strncpy(pPassword, "password", password_len); /* ditto */ +} + + +int +main(int argc, char * argv[]) +{ + int debug = 4; + int opt; + char * p; + char buf[1024]; + int dir; + struct smbc_dirent * dirent; + char ** ppUrl; + char * urlList[] = + { + "smb://", + "smb://?mb=.any", + "smb://?mb=.all", + "smb://?mb=xx", /* this one is suupposed to fail */ + NULL + }; + + if (smbc_init(auth_fn, debug) != 0) + { + printf("Could not initialize smbc_ library\n"); + return 1; + } + + for (ppUrl = urlList; *ppUrl != NULL; ppUrl++) + { + printf("Opening (%s)...\n", *ppUrl); + + if ((dir = smbc_opendir(*ppUrl)) < 0) + { + printf("Could not open [%s] (%d:%s)\n", + *ppUrl, errno, strerror(errno)); + continue; + } + + while ((dirent = smbc_readdir(dir)) != NULL) + { + printf("%s\n", dirent->name); + } + + smbc_closedir(dir); + } + + exit(0); +} + -- cgit From fbc611f431db443c23486f768ca5e2bc4db95c24 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Tue, 29 Mar 2005 00:42:51 +0000 Subject: r6108: Added smbsh/smbwrapper for Linux to example/libsmbclient tree; provided more complete libsmbclient testbrowse utility (This used to be commit 15736b97c837a16d9c009b8bff18b31429ccbe83) --- examples/libsmbclient/testbrowse.c | 219 ++++++++++++++++++++++++++++--------- 1 file changed, 165 insertions(+), 54 deletions(-) (limited to 'examples/libsmbclient/testbrowse.c') diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c index d2472230a2..8122df5e2e 100644 --- a/examples/libsmbclient/testbrowse.c +++ b/examples/libsmbclient/testbrowse.c @@ -1,91 +1,202 @@ -/* - Unix SMB/CIFS implementation. - SMB client library test program for browsing with different master browsers - Copyright (C) Derrell Lipman 2004 - - 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 2 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, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#include +#include +#include +#include #include -#include +#include #include -#include -#include +#include #include +#include + +void error_message(char * pMessage) +{ + printf("ERROR: %s\n", pMessage); +} + static void -auth_fn(const char * pServer, - const char * pShare, - char * pWorkgroup, - int workgroup_len, - char * pUsername, - int username_len, - char * pPassword, - int password_len) +get_auth_data_fn(const char * pServer, + const char * pShare, + char * pWorkgroup, + int maxLenWorkgroup, + char * pUsername, + int maxLenUsername, + char * pPassword, + int maxLenPassword) { - strncpy(pUsername, "anonymous", username_len); /* doesn't matter what */ - strncpy(pPassword, "password", password_len); /* ditto */ + char temp[128]; + + printf("Entered get_auth_data_fn\n"); + + fprintf(stdout, "Need password for //%s/%s\n", pServer, pShare); + + fprintf(stdout, "Username: [%s] ", pUsername); + fgets(temp, sizeof(temp), stdin); + + if (temp[strlen(temp) - 1] == '\n') /* A new line? */ + { + temp[strlen(temp) - 1] = '\0'; + } + + if (temp[0] != '\0') + { + strncpy(pUsername, temp, maxLenUsername - 1); + } + + strcpy(temp, getpass("Password: ")); + + if (temp[strlen(temp) - 1] == '\n') /* A new line? */ + { + temp[strlen(temp) - 1] = '\0'; + } + + if (temp[0] != '\0') + { + strncpy(pPassword, temp, maxLenPassword - 1); + } + + fprintf(stdout, "Workgroup: "); + fgets(temp, sizeof(temp), stdin); + + if (temp[strlen(temp) - 1] == '\n') /* A new line? */ + { + temp[strlen(temp) - 1] = '\0'; + } + + if (temp[0] != '\0') + { + strncpy(pWorkgroup, temp, maxLenWorkgroup - 1); + } + + putchar('\n'); } int main(int argc, char * argv[]) { - int debug = 4; + int debug = 0; int opt; char * p; + char * q; char buf[1024]; int dir; + struct stat stat; struct smbc_dirent * dirent; - char ** ppUrl; - char * urlList[] = + poptContext pc; + struct poptOption long_options[] = { - "smb://", - "smb://?mb=.any", - "smb://?mb=.all", - "smb://?mb=xx", /* this one is suupposed to fail */ - NULL + POPT_AUTOHELP + { + "debug", 'd', POPT_ARG_INT, &debug, + 0, "Set debug level", "integer" + }, + { + NULL + } }; - if (smbc_init(auth_fn, debug) != 0) + setbuf(stdout, NULL); + + pc = poptGetContext("opendir", argc, (const char **)argv, long_options, 0); + + poptSetOtherOptionHelp(pc, ""); + + while ((opt = poptGetNextOpt(pc)) != -1) { + printf("Got option %d = %c\n", opt, opt); + switch (opt) { + } + } + + if (smbc_init(get_auth_data_fn, debug) != 0) { printf("Could not initialize smbc_ library\n"); return 1; } - for (ppUrl = urlList; *ppUrl != NULL; ppUrl++) + for (fputs("url: ", stdout), p = fgets(buf, sizeof(buf), stdin); + p != NULL && *p != '\n' && *p != '\0'; + fputs("url: ", stdout), p = fgets(buf, sizeof(buf), stdin)) { - printf("Opening (%s)...\n", *ppUrl); - - if ((dir = smbc_opendir(*ppUrl)) < 0) + if ((p = strchr(buf, '\n')) != NULL) { - printf("Could not open [%s] (%d:%s)\n", - *ppUrl, errno, strerror(errno)); + *p = '\0'; + } + + printf("Opening (%s)...\n", buf); + + if ((dir = smbc_opendir(buf)) < 0) + { + printf("Could not open directory [%s] (%d:%s)\n", + buf, errno, strerror(errno)); continue; } - + while ((dirent = smbc_readdir(dir)) != NULL) { - printf("%s\n", dirent->name); + printf("%-30s", dirent->name); + printf("%-30s", dirent->comment); + + switch(dirent->smbc_type) + { + case SMBC_WORKGROUP: + printf("WORKGROUP"); + break; + + case SMBC_SERVER: + printf("SERVER"); + break; + + case SMBC_FILE_SHARE: + printf("FILE_SHARE"); + break; + + case SMBC_PRINTER_SHARE: + printf("PRINTER_SHARE"); + break; + + case SMBC_COMMS_SHARE: + printf("COMMS_SHARE"); + break; + + case SMBC_IPC_SHARE: + printf("IPC_SHARE"); + break; + + case SMBC_DIR: + printf("DIR"); + break; + + case SMBC_FILE: + printf("FILE"); + + q = buf + strlen(buf); + strcat(q, "/"); + strcat(q+1, dirent->name); + if (smbc_stat(buf, &stat) < 0) + { + printf(" unknown size (reason %d: %s)", + errno, strerror(errno)); + } + else + { + printf(" size %lu", (unsigned long) stat.st_size); + } + *p = '\0'; + + break; + + case SMBC_LINK: + printf("LINK"); + break; + } + + printf("\n"); } - + smbc_closedir(dir); } - + exit(0); } - -- cgit From 9840db418bad5a39edc4a32a1786f5e2d2c9dff8 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Thu, 31 Mar 2005 05:06:04 +0000 Subject: r6149: Fixes bugs #2498 and 2484. 1. using smbc_getxattr() et al, one may now request all access control entities in the ACL without getting all other NT attributes. 2. added the ability to exclude specified attributes from the result set provided by smbc_getxattr() et al, when requesting all attributes, all NT attributes, or all DOS attributes. 3. eliminated all compiler warnings, including when --enable-developer compiler flags are in use. removed -Wcast-qual flag from list, as that is specifically to force warnings in the case of casting away qualifiers. Note: In the process of eliminating compiler warnings, a few nasties were discovered. In the file libads/sasl.c, PRIVATE kerberos interfaces are being used; and in libsmb/clikrb5.c, both PRIAVE and DEPRECATED kerberos interfaces are being used. Someone who knows kerberos should look at these and determine if there is an alternate method of accomplishing the task. (This used to be commit 994694f7f26da5099f071e1381271a70407f33bb) --- examples/libsmbclient/testbrowse.c | 62 ++------------------------------------ 1 file changed, 2 insertions(+), 60 deletions(-) (limited to 'examples/libsmbclient/testbrowse.c') diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c index 8122df5e2e..27d6a69738 100644 --- a/examples/libsmbclient/testbrowse.c +++ b/examples/libsmbclient/testbrowse.c @@ -5,8 +5,9 @@ #include #include #include -#include #include +#include +#include "get_auth_data_fn.h" void error_message(char * pMessage) { @@ -14,65 +15,6 @@ void error_message(char * pMessage) } -static void -get_auth_data_fn(const char * pServer, - const char * pShare, - char * pWorkgroup, - int maxLenWorkgroup, - char * pUsername, - int maxLenUsername, - char * pPassword, - int maxLenPassword) - -{ - char temp[128]; - - printf("Entered get_auth_data_fn\n"); - - fprintf(stdout, "Need password for //%s/%s\n", pServer, pShare); - - fprintf(stdout, "Username: [%s] ", pUsername); - fgets(temp, sizeof(temp), stdin); - - if (temp[strlen(temp) - 1] == '\n') /* A new line? */ - { - temp[strlen(temp) - 1] = '\0'; - } - - if (temp[0] != '\0') - { - strncpy(pUsername, temp, maxLenUsername - 1); - } - - strcpy(temp, getpass("Password: ")); - - if (temp[strlen(temp) - 1] == '\n') /* A new line? */ - { - temp[strlen(temp) - 1] = '\0'; - } - - if (temp[0] != '\0') - { - strncpy(pPassword, temp, maxLenPassword - 1); - } - - fprintf(stdout, "Workgroup: "); - fgets(temp, sizeof(temp), stdin); - - if (temp[strlen(temp) - 1] == '\n') /* A new line? */ - { - temp[strlen(temp) - 1] = '\0'; - } - - if (temp[0] != '\0') - { - strncpy(pWorkgroup, temp, maxLenWorkgroup - 1); - } - - putchar('\n'); -} - - int main(int argc, char * argv[]) { -- cgit From a54f9eddcea6497451dd6c720e9804ad5c6f3ad7 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Mon, 5 Dec 2005 23:30:40 +0000 Subject: r12080: r10673@cabra: derrell | 2005-12-05 13:22:34 -0500 Correct some memory and file descriptor leaks. This should fix bugs 3257, 3267 and 3273. (This used to be commit c5781c9cf5f1f8297e084fbe2c4a22257420a447) --- examples/libsmbclient/testbrowse.c | 238 +++++++++++++++++++++++++------------ 1 file changed, 163 insertions(+), 75 deletions(-) (limited to 'examples/libsmbclient/testbrowse.c') diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c index 27d6a69738..6fa70eab41 100644 --- a/examples/libsmbclient/testbrowse.c +++ b/examples/libsmbclient/testbrowse.c @@ -9,24 +9,34 @@ #include #include "get_auth_data_fn.h" -void error_message(char * pMessage) -{ - printf("ERROR: %s\n", pMessage); -} +static void +no_auth_data_fn(const char * pServer, + const char * pShare, + char * pWorkgroup, + int maxLenWorkgroup, + char * pUsername, + int maxLenUsername, + char * pPassword, + int maxLenPassword); + +static void browse(char * path, + int scan, + int indent); + int main(int argc, char * argv[]) { int debug = 0; + int scan = 0; + int iterations = -1; + int again; int opt; char * p; char * q; char buf[1024]; - int dir; - struct stat stat; - struct smbc_dirent * dirent; - poptContext pc; + poptContext pc; struct poptOption long_options[] = { POPT_AUTOHELP @@ -34,6 +44,14 @@ main(int argc, char * argv[]) "debug", 'd', POPT_ARG_INT, &debug, 0, "Set debug level", "integer" }, + { + "scan", 's', POPT_ARG_NONE, &scan, + 0, "Scan for servers and shares", "integer" + }, + { + "iterations", 'i', POPT_ARG_INT, &iterations, + 0, "Iterations", "integer" + }, { NULL } @@ -51,94 +69,164 @@ main(int argc, char * argv[]) } } - if (smbc_init(get_auth_data_fn, debug) != 0) + if (scan) { - printf("Could not initialize smbc_ library\n"); - return 1; + if (smbc_init(no_auth_data_fn, debug) != 0) + { + printf("Could not initialize smbc_ library\n"); + return 1; + } + + for (; + iterations == -1 || iterations > 0; + iterations = (iterations == -1 ? iterations : --iterations)) + { + snprintf(buf, sizeof(buf), "smb://"); + browse(buf, scan, 0); + } } - - for (fputs("url: ", stdout), p = fgets(buf, sizeof(buf), stdin); - p != NULL && *p != '\n' && *p != '\0'; - fputs("url: ", stdout), p = fgets(buf, sizeof(buf), stdin)) + else { - if ((p = strchr(buf, '\n')) != NULL) + if (smbc_init(get_auth_data_fn, debug) != 0) { - *p = '\0'; + printf("Could not initialize smbc_ library\n"); + return 1; } - - printf("Opening (%s)...\n", buf); - - if ((dir = smbc_opendir(buf)) < 0) + + for (; + iterations == -1 || iterations > 0; + iterations = (iterations == -1 ? iterations : --iterations)) { - printf("Could not open directory [%s] (%d:%s)\n", - buf, errno, strerror(errno)); - continue; + fputs("url: ", stdout); + p = fgets(buf, sizeof(buf), stdin); + if (! p) + { + break; + } + + if ((p = strchr(buf, '\n')) != NULL) + { + *p = '\0'; + } + + browse(buf, scan, 0); } + } - while ((dirent = smbc_readdir(dir)) != NULL) - { - printf("%-30s", dirent->name); - printf("%-30s", dirent->comment); + exit(0); +} - switch(dirent->smbc_type) - { - case SMBC_WORKGROUP: - printf("WORKGROUP"); - break; + +static void +no_auth_data_fn(const char * pServer, + const char * pShare, + char * pWorkgroup, + int maxLenWorkgroup, + char * pUsername, + int maxLenUsername, + char * pPassword, + int maxLenPassword) +{ + return; +} + +static void browse(char * path, int scan, int indent) +{ + char * p; + char buf[1024]; + int dir; + struct stat stat; + struct smbc_dirent * dirent; + + if (! scan) + { + printf("Opening (%s)...\n", path); + } + + if ((dir = smbc_opendir(path)) < 0) + { + printf("Could not open directory [%s] (%d:%s)\n", + path, errno, strerror(errno)); + return; + } + + while ((dirent = smbc_readdir(dir)) != NULL) + { + printf("%*.*s%-30s", indent, indent, "", dirent->name); + + switch(dirent->smbc_type) + { + case SMBC_WORKGROUP: + printf("WORKGROUP"); + break; - case SMBC_SERVER: - printf("SERVER"); - break; + case SMBC_SERVER: + printf("SERVER"); + break; - case SMBC_FILE_SHARE: - printf("FILE_SHARE"); - break; + case SMBC_FILE_SHARE: + printf("FILE_SHARE"); + break; - case SMBC_PRINTER_SHARE: - printf("PRINTER_SHARE"); - break; + case SMBC_PRINTER_SHARE: + printf("PRINTER_SHARE"); + break; - case SMBC_COMMS_SHARE: - printf("COMMS_SHARE"); - break; + case SMBC_COMMS_SHARE: + printf("COMMS_SHARE"); + break; - case SMBC_IPC_SHARE: - printf("IPC_SHARE"); - break; + case SMBC_IPC_SHARE: + printf("IPC_SHARE"); + break; - case SMBC_DIR: - printf("DIR"); - break; + case SMBC_DIR: + printf("DIR"); + break; - case SMBC_FILE: - printf("FILE"); - - q = buf + strlen(buf); - strcat(q, "/"); - strcat(q+1, dirent->name); - if (smbc_stat(buf, &stat) < 0) - { - printf(" unknown size (reason %d: %s)", - errno, strerror(errno)); - } - else - { - printf(" size %lu", (unsigned long) stat.st_size); - } - *p = '\0'; + case SMBC_FILE: + printf("FILE"); - break; - - case SMBC_LINK: - printf("LINK"); - break; + p = path + strlen(path); + strcat(p, "/"); + strcat(p+1, dirent->name); + if (smbc_stat(path, &stat) < 0) + { + printf(" unknown size (reason %d: %s)", + errno, strerror(errno)); } + else + { + printf(" size %lu", (unsigned long) stat.st_size); + } + *p = '\0'; - printf("\n"); + break; + + case SMBC_LINK: + printf("LINK"); + break; } - smbc_closedir(dir); + printf("\n"); + + if (scan && + (dirent->smbc_type == SMBC_WORKGROUP || + dirent->smbc_type == SMBC_SERVER)) + { + /* + * don't append server name to workgroup; what we want is: + * + * smb://workgroup_name + * or + * smb://server_name + * + */ + snprintf(buf, sizeof(buf), "smb://%s", dirent->name); + browse(buf, scan, indent + 2); + } } - exit(0); + smbc_closedir(dir); } + -- cgit From e13d0cb3ec89d83db8893341ca7ae24c07aad1fb Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Thu, 29 Dec 2005 16:26:06 +0000 Subject: r12576: r12115@cabra: derrell | 2005-12-29 11:16:03 -0500 bug (enhancement) #2651: add option to log debug messages to stderr instead of stdout (This used to be commit 4182eb99af5b343291a661a87d08edd91fd09a7a) --- examples/libsmbclient/testbrowse.c | 46 ++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 12 deletions(-) (limited to 'examples/libsmbclient/testbrowse.c') diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c index 6fa70eab41..eba6fff4eb 100644 --- a/examples/libsmbclient/testbrowse.c +++ b/examples/libsmbclient/testbrowse.c @@ -29,6 +29,7 @@ int main(int argc, char * argv[]) { int debug = 0; + int debug_stderr = 0; int scan = 0; int iterations = -1; int again; @@ -37,6 +38,7 @@ main(int argc, char * argv[]) char * q; char buf[1024]; poptContext pc; + SMBCCTX * context; struct poptOption long_options[] = { POPT_AUTOHELP @@ -44,6 +46,10 @@ main(int argc, char * argv[]) "debug", 'd', POPT_ARG_INT, &debug, 0, "Set debug level", "integer" }, + { + "stderr", 'e', POPT_ARG_NONE, &debug_stderr, + 0, "Debug log to stderr instead of stdout", "integer" + }, { "scan", 's', POPT_ARG_NONE, &scan, 0, "Scan for servers and shares", "integer" @@ -69,14 +75,36 @@ main(int argc, char * argv[]) } } + /* Allocate a new context */ + context = smbc_new_context(); + if (!context) { + printf("Could not allocate new smbc context\n"); + return 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 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", NULL); + } + + /* Initialize the context using the previously specified options */ + if (!smbc_init_context(context)) { + smbc_free_context(context, 0); + printf("Could not initialize smbc context\n"); + return 1; + } + + /* Tell the compatibility layer to use this context */ + smbc_set_context(context); + + if (scan) { - if (smbc_init(no_auth_data_fn, debug) != 0) - { - printf("Could not initialize smbc_ library\n"); - return 1; - } - for (; iterations == -1 || iterations > 0; iterations = (iterations == -1 ? iterations : --iterations)) @@ -87,12 +115,6 @@ main(int argc, char * argv[]) } else { - if (smbc_init(get_auth_data_fn, debug) != 0) - { - printf("Could not initialize smbc_ library\n"); - return 1; - } - for (; iterations == -1 || iterations > 0; iterations = (iterations == -1 ? iterations : --iterations)) -- cgit From cbc97b4e5aee1fe6488ef316374b75a58b667ccc Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Thu, 29 Dec 2005 17:03:39 +0000 Subject: r12579: r12122@cabra: derrell | 2005-12-29 12:03:00 -0500 allow for arbitrary option value types (This used to be commit 64c8e32b6382e48bce5c1f18179e66ca765a70af) --- examples/libsmbclient/testbrowse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/libsmbclient/testbrowse.c') diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c index eba6fff4eb..b5337ae983 100644 --- a/examples/libsmbclient/testbrowse.c +++ b/examples/libsmbclient/testbrowse.c @@ -89,7 +89,7 @@ main(int argc, char * argv[]) /* 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", NULL); + smbc_option_set(context, "debug_stderr"); } /* Initialize the context using the previously specified options */ -- cgit From 9a8ca1901c7520a140eaf9208e0b056c93d8471c Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sat, 7 Jan 2006 20:43:28 +0000 Subject: r12757: r12126@cabra: derrell | 2006-01-03 15:21:36 -0500 added flag to not request authentication information (This used to be commit 8396c4b26c9911887ed1c1ce17c31af462ee6883) --- examples/libsmbclient/testbrowse.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'examples/libsmbclient/testbrowse.c') diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c index b5337ae983..ca126c9510 100644 --- a/examples/libsmbclient/testbrowse.c +++ b/examples/libsmbclient/testbrowse.c @@ -30,6 +30,7 @@ main(int argc, char * argv[]) { int debug = 0; int debug_stderr = 0; + int no_auth = 0; int scan = 0; int iterations = -1; int again; @@ -58,6 +59,10 @@ 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" + }, { NULL } @@ -82,9 +87,14 @@ 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); + 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 (debug_stderr) { @@ -102,7 +112,6 @@ main(int argc, char * argv[]) /* Tell the compatibility layer to use this context */ smbc_set_context(context); - if (scan) { for (; -- cgit From e836508704dd964e22e8bfc0f8e9ec520a2c94f2 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Wed, 22 Mar 2006 22:05:19 +0000 Subject: r14664: r13868@cabra: derrell | 2006-03-22 17:04:30 -0500 Implement enhancement request 3505. Two additional features are added here. There is now a method of saving an opaque user data handle in the smbc_ context, and there is now a way to request that the context be passed to the authentication function. See examples/libsmbclient/testbrowse.c for an example of using these features. (This used to be commit 203b4911c16bd7e10198a6f0e63960f2813025ef) --- examples/libsmbclient/testbrowse.c | 51 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) (limited to 'examples/libsmbclient/testbrowse.c') diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c index ca126c9510..96f78aad85 100644 --- a/examples/libsmbclient/testbrowse.c +++ b/examples/libsmbclient/testbrowse.c @@ -24,6 +24,16 @@ 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[]) @@ -31,6 +41,7 @@ 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; @@ -63,6 +74,10 @@ main(int argc, char * argv[]) "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 } @@ -94,12 +109,21 @@ main(int argc, char * argv[]) /* Set mandatory options (is that a contradiction in terms?) */ context->debug = debug; - context->callbacks.auth_fn = (no_auth ? 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 (debug_stderr) { /* ... then set the option to do so */ - smbc_option_set(context, "debug_stderr"); + smbc_option_set(context, "debug_stderr", (void *) 1); } /* Initialize the context using the previously specified options */ @@ -161,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; -- cgit From 9718506d35ca14c5233b613c647609bf2589f38b Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Tue, 27 Jun 2006 02:30:58 +0000 Subject: r16550: Fix bug 3866. Thanks for the report! Although I've never met a computer or compiler that produced pointers to functions which are a different size than pointers to data, I suppose they probably exist. Assigning a pointer to a function is technically illegal in C anyway. Change casts of the option_value based on the option_name to use of variable argument lists. For binary compatibility, I've maintained but deprecated the old behavior of debug_stderr (which expected to be passed a NULL or non-NULL pointer) and added a new option debug_to_stderr which properly expects a boolean (int) parameter. Derrell (This used to be commit c1b4c510530ca3118d1eccb9615a8cad732c7373) --- examples/libsmbclient/testbrowse.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'examples/libsmbclient/testbrowse.c') diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c index 96f78aad85..562d2c2aeb 100644 --- a/examples/libsmbclient/testbrowse.c +++ b/examples/libsmbclient/testbrowse.c @@ -120,10 +120,10 @@ main(int argc, char * argv[]) (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", (void *) 1); + smbc_option_set(context, "debug_to_stderr", 1); } /* Initialize the context using the previously specified options */ -- cgit From 257b7b09298f7cb983b2f31b87fc5e46e0f62f0c Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Thu, 28 Feb 2008 11:23:20 -0500 Subject: Initial revamp of the libsmbclient interface. The libsmbclient interface has suffered from difficulty of improvement and feature enrichment without causing ABI breakage. Although there were a number of issues, the primary ones were: (a) the user of the library would manually manipulate the context structure members, meaning that nothing in the context structure could change other than adding stuff at the end; (b) there were three methods of setting options: setting bits in a flags field within the context structure, setting explicit options variables within an options structure in the context structure, and by calling the smbc_option_set() function; (c) the authentication callback did not traditionally provide enough information to the callee which required adding an option for a callback with a different signature, and now there are requests for even more information at the callback, requiring yet a third signature and option to set it (if we implement that feature). This commit provides a reorganization of the code which fixes (a) and (b). The context structure is now entirely opaque, and there are setter and getter functions for manipulating it. This makes maintaining ABI consistency much, much easier. Additionally, the options setting/getting has been unified into a single mechanism using smbc_option_set() and smbc_option_get(). Yet to be completed is a refactoring of the authentication callback (c). The test programs in examples/libsmbclient have been modified (if necessary; some applications require no changes at all) for the new API and a few have been minimally tested. Derrell (This used to be commit d4b4bae8ded824d06ad5ab0e219f71187ee5c771) --- examples/libsmbclient/testbrowse.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'examples/libsmbclient/testbrowse.c') diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c index 562d2c2aeb..495cf0fbec 100644 --- a/examples/libsmbclient/testbrowse.c +++ b/examples/libsmbclient/testbrowse.c @@ -108,7 +108,8 @@ main(int argc, char * argv[]) } /* Set mandatory options (is that a contradiction in terms?) */ - context->debug = debug; + smbc_setDebug(context, debug); +#if 0 if (context_auth) { context->callbacks.auth_fn = NULL; smbc_option_set(context, @@ -119,6 +120,11 @@ main(int argc, char * argv[]) context->callbacks.auth_fn = (no_auth ? no_auth_data_fn : get_auth_data_fn); } +#else +#warning "temporarily remove setting alternate auth function" + smbc_setFunctionAuthData(context, + (no_auth ? no_auth_data_fn : get_auth_data_fn)); +#endif /* If we've been asked to log to stderr instead of stdout, ... */ if (debug_stderr) { -- cgit From 223940d9a887c5b98a5c873797302a6a9407ad7f Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sat, 1 Mar 2008 20:44:21 -0500 Subject: Additional revamped libsmbclient documentation - Ensured that all public functions have documentation in libsmbclient.h - Reformatted for "proper" indentation - Re-added temporarily-disabled alternate authentication function capability Derrell (This used to be commit 64b7150d92849a1e1e2416b9dcc12fae8d6bea99) --- examples/libsmbclient/testbrowse.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'examples/libsmbclient/testbrowse.c') diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c index 495cf0fbec..1b0b54f9f0 100644 --- a/examples/libsmbclient/testbrowse.c +++ b/examples/libsmbclient/testbrowse.c @@ -109,22 +109,13 @@ main(int argc, char * argv[]) /* Set mandatory options (is that a contradiction in terms?) */ smbc_setDebug(context, debug); -#if 0 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"); + smbc_setFunctionAuthDataWithContext(context, + get_auth_data_with_context_fn); + smbc_setOptionUserData(context, "hello world"); } else { - context->callbacks.auth_fn = - (no_auth ? no_auth_data_fn : get_auth_data_fn); + smbc_setFunctionAuthData(context, get_auth_data_fn); } -#else -#warning "temporarily remove setting alternate auth function" - smbc_setFunctionAuthData(context, - (no_auth ? no_auth_data_fn : get_auth_data_fn)); -#endif /* If we've been asked to log to stderr instead of stdout, ... */ if (debug_stderr) { -- cgit From 8a05c0a8843c001bdb4ac31e9ea382dd89716b55 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sun, 2 Mar 2008 16:21:48 -0500 Subject: Remove use of deprecated function (This used to be commit 93580bce833453ba512ee436d6dfdbdcd2c53777) --- examples/libsmbclient/testbrowse.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'examples/libsmbclient/testbrowse.c') diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c index 1b0b54f9f0..c4ca6667e0 100644 --- a/examples/libsmbclient/testbrowse.c +++ b/examples/libsmbclient/testbrowse.c @@ -120,7 +120,7 @@ main(int argc, char * argv[]) /* 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_to_stderr", 1); + smbc_setOptionDebugToStderr(context, 1); } /* Initialize the context using the previously specified options */ @@ -196,7 +196,7 @@ get_auth_data_with_context_fn(SMBCCTX * context, { printf("Authenticating with context 0x%lx", context); if (context != NULL) { - char *user_data = smbc_option_get(context, "user_data"); + char *user_data = smbc_getOptionUserData(context); printf(" with user data %s", user_data); } printf("\n"); -- cgit From ee45d0d6630624b735a7ea07639ffa0d774a337c Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Mon, 3 Mar 2008 18:25:49 -0500 Subject: Missed a few 'deprecated' markers (This used to be commit 76ba37ac46b4a77fe228ca90635fa19140541ccd) --- examples/libsmbclient/testbrowse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/libsmbclient/testbrowse.c') diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c index c4ca6667e0..a7eda365af 100644 --- a/examples/libsmbclient/testbrowse.c +++ b/examples/libsmbclient/testbrowse.c @@ -122,7 +122,7 @@ main(int argc, char * argv[]) /* ... then set the option to do so */ smbc_setOptionDebugToStderr(context, 1); } - + /* Initialize the context using the previously specified options */ if (!smbc_init_context(context)) { smbc_free_context(context, 0); -- cgit From ef0a7b0b94cfb9b57d634b083d2b2652bb88865d Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Mon, 23 Jun 2008 11:00:20 +0200 Subject: Add krb5 support for the testbrowse example. Signed-off-by: Andreas Schneider Signed-off-by: Derrell Lipman (This used to be commit 84b1ea39a4f27ebcf06a2bafed78396c7353df0e) --- examples/libsmbclient/testbrowse.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'examples/libsmbclient/testbrowse.c') diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c index a7eda365af..a6e6395078 100644 --- a/examples/libsmbclient/testbrowse.c +++ b/examples/libsmbclient/testbrowse.c @@ -117,6 +117,9 @@ main(int argc, char * argv[]) smbc_setFunctionAuthData(context, get_auth_data_fn); } + smbc_setOptionUseKerberos(context, 1); + smbc_setOptionFallbackAfterKerberos(context, 1); + /* If we've been asked to log to stderr instead of stdout, ... */ if (debug_stderr) { /* ... then set the option to do so */ -- cgit