8 #include <libsmbclient.h>
11 void error_message(char * pMessage)
13 printf("ERROR: %s\n", pMessage);
18 get_auth_data_fn(const char * pServer,
30 printf("Entered get_auth_data_fn\n");
32 fprintf(stdout, "Need password for //%s/%s\n", pServer, pShare);
34 fprintf(stdout, "Username: [%s] ", pUsername);
35 fgets(temp, sizeof(temp), stdin);
37 if (temp[strlen(temp) - 1] == '\n') /* A new line? */
39 temp[strlen(temp) - 1] = '\0';
44 strncpy(pUsername, temp, maxLenUsername - 1);
47 strcpy(temp, getpass("Password: "));
49 if (temp[strlen(temp) - 1] == '\n') /* A new line? */
51 temp[strlen(temp) - 1] = '\0';
56 strncpy(pPassword, temp, maxLenPassword - 1);
59 fprintf(stdout, "Workgroup: ");
60 fgets(temp, sizeof(temp), stdin);
62 if (temp[strlen(temp) - 1] == '\n') /* A new line? */
64 temp[strlen(temp) - 1] = '\0';
69 strncpy(pWorkgroup, temp, maxLenWorkgroup - 1);
77 main(int argc, char * argv[])
86 struct smbc_dirent * dirent;
88 struct poptOption long_options[] =
92 "debug", 'd', POPT_ARG_INT, &debug,
93 0, "Set debug level", "integer"
100 setbuf(stdout, NULL);
102 pc = poptGetContext("opendir", argc, (const char **)argv, long_options, 0);
104 poptSetOtherOptionHelp(pc, "");
106 while ((opt = poptGetNextOpt(pc)) != -1) {
107 printf("Got option %d = %c\n", opt, opt);
112 if (smbc_init(get_auth_data_fn, debug) != 0)
114 printf("Could not initialize smbc_ library\n");
118 for (fputs("url: ", stdout), p = fgets(buf, sizeof(buf), stdin);
119 p != NULL && *p != '\n' && *p != '\0';
120 fputs("url: ", stdout), p = fgets(buf, sizeof(buf), stdin))
122 if ((p = strchr(buf, '\n')) != NULL)
127 printf("Opening (%s)...\n", buf);
129 if ((dir = smbc_opendir(buf)) < 0)
131 printf("Could not open directory [%s] (%d:%s)\n",
132 buf, errno, strerror(errno));
136 while ((dirent = smbc_readdir(dir)) != NULL)
138 printf("%-30s", dirent->name);
139 printf("%-30s", dirent->comment);
141 switch(dirent->smbc_type)
151 case SMBC_FILE_SHARE:
152 printf("FILE_SHARE");
155 case SMBC_PRINTER_SHARE:
156 printf("PRINTER_SHARE");
159 case SMBC_COMMS_SHARE:
160 printf("COMMS_SHARE");
174 q = buf + strlen(buf);
176 strcat(q+1, dirent->name);
177 if (smbc_stat(buf, &stat) < 0)
179 printf(" unknown size (reason %d: %s)",
180 errno, strerror(errno));
184 printf(" size %lu", (unsigned long) stat.st_size);