summaryrefslogtreecommitdiffstats
path: root/examples/libsmbclient/testbrowse.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/libsmbclient/testbrowse.c')
-rw-r--r--examples/libsmbclient/testbrowse.c219
1 files changed, 165 insertions, 54 deletions
diff --git a/examples/libsmbclient/testbrowse.c b/examples/libsmbclient/testbrowse.c
index d2472230a20..8122df5e2e7 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 <stdio.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <dirent.h>
#include <errno.h>
-#include <sys/time.h>
+#include <stdio.h>
#include <string.h>
-#include <unistd.h>
-#include <stdlib.h>
+#include <popt.h>
#include <libsmbclient.h>
+#include <stdlib.h>
+
+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);
}
-