diff options
Diffstat (limited to 'examples/libsmbclient/testbrowse.c')
-rw-r--r-- | examples/libsmbclient/testbrowse.c | 163 |
1 files changed, 55 insertions, 108 deletions
diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c index 27d6a697388..d2472230a20 100644 --- a/examples/libsmbclient/testbrowse.c +++ b/examples/libsmbclient/testbrowse.c @@ -1,144 +1,91 @@ -#include <sys/types.h> -#include <unistd.h> -#include <dirent.h> -#include <errno.h> +/* + 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 <stdio.h> +#include <errno.h> +#include <sys/time.h> #include <string.h> -#include <popt.h> +#include <unistd.h> #include <stdlib.h> #include <libsmbclient.h> -#include "get_auth_data_fn.h" -void error_message(char * 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) + { - printf("ERROR: %s\n", pMessage); + strncpy(pUsername, "anonymous", username_len); /* doesn't matter what */ + strncpy(pPassword, "password", password_len); /* ditto */ } int main(int argc, char * argv[]) { - int debug = 0; + int debug = 4; int opt; char * p; - char * q; char buf[1024]; int dir; - struct stat stat; struct smbc_dirent * dirent; - poptContext pc; - struct poptOption long_options[] = + char ** ppUrl; + char * urlList[] = { - POPT_AUTOHELP - { - "debug", 'd', POPT_ARG_INT, &debug, - 0, "Set debug level", "integer" - }, - { - NULL - } + "smb://", + "smb://?mb=.any", + "smb://?mb=.all", + "smb://?mb=xx", /* this one is suupposed to fail */ + NULL }; - 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) + if (smbc_init(auth_fn, debug) != 0) { printf("Could not initialize smbc_ library\n"); return 1; } - 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)) + for (ppUrl = urlList; *ppUrl != NULL; ppUrl++) { - if ((p = strchr(buf, '\n')) != NULL) - { - *p = '\0'; - } - - printf("Opening (%s)...\n", buf); - - if ((dir = smbc_opendir(buf)) < 0) + printf("Opening (%s)...\n", *ppUrl); + + if ((dir = smbc_opendir(*ppUrl)) < 0) { - printf("Could not open directory [%s] (%d:%s)\n", - buf, errno, strerror(errno)); + printf("Could not open [%s] (%d:%s)\n", + *ppUrl, errno, strerror(errno)); continue; } - + while ((dirent = smbc_readdir(dir)) != NULL) { - 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"); + printf("%s\n", dirent->name); } - + smbc_closedir(dir); } - + exit(0); } + |