#include <sys/types.h>#include <unistd.h>#include <dirent.h>#include <errno.h>#include <stdio.h>#include <string.h>#include <popt.h>#include <stdlib.h>#include <libsmbclient.h>#include "get_auth_data_fn.h"Go to the source code of this file.
Functions | |
| 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) |
| 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[]) |
|
||||||||||||||||
|
Definition at line 211 of file testbrowse.c. References buf, dirent, errno, smbc_dirent::name, printf(), smbc_closedir(), SMBC_COMMS_SHARE, SMBC_DIR, SMBC_FILE, SMBC_FILE_SHARE, SMBC_IPC_SHARE, SMBC_LINK, smbc_opendir(), SMBC_PRINTER_SHARE, smbc_readdir(), SMBC_SERVER, smbc_stat(), smbc_dirent::smbc_type, SMBC_WORKGROUP, snprintf, stat(), strcat, and strerror. Referenced by main(). 00212 { 00213 char * p; 00214 char buf[1024]; 00215 int dir; 00216 struct stat stat; 00217 struct smbc_dirent * dirent; 00218 00219 if (! scan) 00220 { 00221 printf("Opening (%s)...\n", path); 00222 } 00223 00224 if ((dir = smbc_opendir(path)) < 0) 00225 { 00226 printf("Could not open directory [%s] (%d:%s)\n", 00227 path, errno, strerror(errno)); 00228 return; 00229 } 00230 00231 while ((dirent = smbc_readdir(dir)) != NULL) 00232 { 00233 printf("%*.*s%-30s", indent, indent, "", dirent->name); 00234 00235 switch(dirent->smbc_type) 00236 { 00237 case SMBC_WORKGROUP: 00238 printf("WORKGROUP"); 00239 break; 00240 00241 case SMBC_SERVER: 00242 printf("SERVER"); 00243 break; 00244 00245 case SMBC_FILE_SHARE: 00246 printf("FILE_SHARE"); 00247 break; 00248 00249 case SMBC_PRINTER_SHARE: 00250 printf("PRINTER_SHARE"); 00251 break; 00252 00253 case SMBC_COMMS_SHARE: 00254 printf("COMMS_SHARE"); 00255 break; 00256 00257 case SMBC_IPC_SHARE: 00258 printf("IPC_SHARE"); 00259 break; 00260 00261 case SMBC_DIR: 00262 printf("DIR"); 00263 break; 00264 00265 case SMBC_FILE: 00266 printf("FILE"); 00267 00268 p = path + strlen(path); 00269 strcat(p, "/"); 00270 strcat(p+1, dirent->name); 00271 if (smbc_stat(path, &stat) < 0) 00272 { 00273 printf(" unknown size (reason %d: %s)", 00274 errno, strerror(errno)); 00275 } 00276 else 00277 { 00278 printf(" size %lu", (unsigned long) stat.st_size); 00279 } 00280 *p = '\0'; 00281 00282 break; 00283 00284 case SMBC_LINK: 00285 printf("LINK"); 00286 break; 00287 } 00288 00289 printf("\n"); 00290 00291 if (scan && 00292 (dirent->smbc_type == SMBC_WORKGROUP || 00293 dirent->smbc_type == SMBC_SERVER)) 00294 { 00295 /* 00296 * don't append server name to workgroup; what we want is: 00297 * 00298 * smb://workgroup_name 00299 * or 00300 * smb://server_name 00301 * 00302 */ 00303 snprintf(buf, sizeof(buf), "smb://%s", dirent->name); 00304 browse(buf, scan, indent + 2); 00305 } 00306 } 00307 00308 smbc_closedir(dir); 00309 }
|
|
||||||||||||||||||||||||||||||||||||||||
|
Definition at line 190 of file testbrowse.c. References get_auth_data_fn, printf(), and smbc_option_get(). Referenced by main(). 00199 { 00200 printf("Authenticating with context 0x%lx", context); 00201 if (context != NULL) { 00202 char *user_data = smbc_option_get(context, "user_data"); 00203 printf(" with user data %s", user_data); 00204 } 00205 printf("\n"); 00206 00207 get_auth_data_fn(pServer, pShare, pWorkgroup, maxLenWorkgroup, 00208 pUsername, maxLenUsername, pPassword, maxLenPassword); 00209 }
|
|
||||||||||||
|
Definition at line 39 of file testbrowse.c. References _SMBCCTX::_smbc_callbacks::auth_fn, browse(), buf, _SMBCCTX::callbacks, _SMBCCTX::debug, get_auth_data_fn, get_auth_data_with_context_fn(), no_auth_data_fn(), POPT_ARG_INT, POPT_ARG_NONE, POPT_AUTOHELP, poptGetContext(), poptGetNextOpt(), poptSetOtherOptionHelp(), printf(), smbc_free_context(), smbc_init_context(), smbc_new_context(), smbc_option_set(), smbc_set_context(), and snprintf. 00040 { 00041 int debug = 0; 00042 int debug_stderr = 0; 00043 int no_auth = 0; 00044 int context_auth = 0; 00045 int scan = 0; 00046 int iterations = -1; 00047 int again; 00048 int opt; 00049 char * p; 00050 char * q; 00051 char buf[1024]; 00052 poptContext pc; 00053 SMBCCTX * context; 00054 struct poptOption long_options[] = 00055 { 00056 POPT_AUTOHELP 00057 { 00058 "debug", 'd', POPT_ARG_INT, &debug, 00059 0, "Set debug level", "integer" 00060 }, 00061 { 00062 "stderr", 'e', POPT_ARG_NONE, &debug_stderr, 00063 0, "Debug log to stderr instead of stdout", "integer" 00064 }, 00065 { 00066 "scan", 's', POPT_ARG_NONE, &scan, 00067 0, "Scan for servers and shares", "integer" 00068 }, 00069 { 00070 "iterations", 'i', POPT_ARG_INT, &iterations, 00071 0, "Iterations", "integer" 00072 }, 00073 { 00074 "noauth", 'A', POPT_ARG_NONE, &no_auth, 00075 0, "Do not request authentication data", "integer" 00076 }, 00077 { 00078 "contextauth", 'C', POPT_ARG_NONE, &context_auth, 00079 0, "Use new authentication function with context", "integer" 00080 }, 00081 { 00082 NULL 00083 } 00084 }; 00085 00086 setbuf(stdout, NULL); 00087 00088 pc = poptGetContext("opendir", argc, (const char **)argv, long_options, 0); 00089 00090 poptSetOtherOptionHelp(pc, ""); 00091 00092 while ((opt = poptGetNextOpt(pc)) != -1) { 00093 printf("Got option %d = %c\n", opt, opt); 00094 switch (opt) { 00095 } 00096 } 00097 00098 /* Allocate a new context */ 00099 context = smbc_new_context(); 00100 if (!context) { 00101 printf("Could not allocate new smbc context\n"); 00102 return 1; 00103 } 00104 00105 /* If we're scanning, do no requests for authentication data */ 00106 if (scan) { 00107 no_auth = 1; 00108 } 00109 00110 /* Set mandatory options (is that a contradiction in terms?) */ 00111 context->debug = debug; 00112 if (context_auth) { 00113 context->callbacks.auth_fn = NULL; 00114 smbc_option_set(context, 00115 "auth_function", 00116 (void *) get_auth_data_with_context_fn); 00117 smbc_option_set(context, "user_data", "hello world"); 00118 } else { 00119 context->callbacks.auth_fn = 00120 (no_auth ? no_auth_data_fn : get_auth_data_fn); 00121 } 00122 00123 /* If we've been asked to log to stderr instead of stdout, ... */ 00124 if (debug_stderr) { 00125 /* ... then set the option to do so */ 00126 smbc_option_set(context, "debug_to_stderr", 1); 00127 } 00128 00129 /* Initialize the context using the previously specified options */ 00130 if (!smbc_init_context(context)) { 00131 smbc_free_context(context, 0); 00132 printf("Could not initialize smbc context\n"); 00133 return 1; 00134 } 00135 00136 /* Tell the compatibility layer to use this context */ 00137 smbc_set_context(context); 00138 00139 if (scan) 00140 { 00141 for (; 00142 iterations == -1 || iterations > 0; 00143 iterations = (iterations == -1 ? iterations : --iterations)) 00144 { 00145 snprintf(buf, sizeof(buf), "smb://"); 00146 browse(buf, scan, 0); 00147 } 00148 } 00149 else 00150 { 00151 for (; 00152 iterations == -1 || iterations > 0; 00153 iterations = (iterations == -1 ? iterations : --iterations)) 00154 { 00155 fputs("url: ", stdout); 00156 p = fgets(buf, sizeof(buf), stdin); 00157 if (! p) 00158 { 00159 break; 00160 } 00161 00162 if ((p = strchr(buf, '\n')) != NULL) 00163 { 00164 *p = '\0'; 00165 } 00166 00167 browse(buf, scan, 0); 00168 } 00169 } 00170 00171 exit(0); 00172 }
|
|
||||||||||||||||||||||||||||||||||||
|
Definition at line 176 of file testbrowse.c. Referenced by main().
|