9 #include <libsmbclient.h>
10 #include "get_auth_data_fn.h"
13 no_auth_data_fn(const char * pServer,
22 static void browse(char * path,
29 main(int argc, char * argv[])
40 struct poptOption long_options[] =
44 "debug", 'd', POPT_ARG_INT, &debug,
45 0, "Set debug level", "integer"
48 "scan", 's', POPT_ARG_NONE, &scan,
49 0, "Scan for servers and shares", "integer"
52 "iterations", 'i', POPT_ARG_INT, &iterations,
53 0, "Iterations", "integer"
62 pc = poptGetContext("opendir", argc, (const char **)argv, long_options, 0);
64 poptSetOtherOptionHelp(pc, "");
66 while ((opt = poptGetNextOpt(pc)) != -1) {
67 printf("Got option %d = %c\n", opt, opt);
74 if (smbc_init(no_auth_data_fn, debug) != 0)
76 printf("Could not initialize smbc_ library\n");
81 iterations == -1 || iterations > 0;
82 iterations = (iterations == -1 ? iterations : --iterations))
84 snprintf(buf, sizeof(buf), "smb://");
90 if (smbc_init(get_auth_data_fn, debug) != 0)
92 printf("Could not initialize smbc_ library\n");
97 iterations == -1 || iterations > 0;
98 iterations = (iterations == -1 ? iterations : --iterations))
100 fputs("url: ", stdout);
101 p = fgets(buf, sizeof(buf), stdin);
107 if ((p = strchr(buf, '\n')) != NULL)
112 browse(buf, scan, 0);
121 no_auth_data_fn(const char * pServer,
133 static void browse(char * path, int scan, int indent)
139 struct smbc_dirent * dirent;
143 printf("Opening (%s)...\n", path);
146 if ((dir = smbc_opendir(path)) < 0)
148 printf("Could not open directory [%s] (%d:%s)\n",
149 path, errno, strerror(errno));
153 while ((dirent = smbc_readdir(dir)) != NULL)
155 printf("%*.*s%-30s", indent, indent, "", dirent->name);
157 switch(dirent->smbc_type)
167 case SMBC_FILE_SHARE:
168 printf("FILE_SHARE");
171 case SMBC_PRINTER_SHARE:
172 printf("PRINTER_SHARE");
175 case SMBC_COMMS_SHARE:
176 printf("COMMS_SHARE");
190 p = path + strlen(path);
192 strcat(p+1, dirent->name);
193 if (smbc_stat(path, &stat) < 0)
195 printf(" unknown size (reason %d: %s)",
196 errno, strerror(errno));
200 printf(" size %lu", (unsigned long) stat.st_size);
214 (dirent->smbc_type == SMBC_WORKGROUP ||
215 dirent->smbc_type == SMBC_SERVER))
218 * don't append server name to workgroup; what we want is:
220 * smb://workgroup_name
225 snprintf(buf, sizeof(buf), "smb://%s", dirent->name);
226 browse(buf, scan, indent + 2);