int main(int argc, char * argv[]) { int debug = 0; int debug_stderr = 0; int no_auth = 0; int context_auth = 0; int scan = 0; int iterations = -1; int again; int opt; char * p; char * q; char buf[1024]; poptContext pc; SMBCCTX * context; /* Allocate a new context */ context = smbc_new_context(); if (!context) { printf("Could not allocate new smbc context\n"); return 1; } /* If we're scanning, do no requests for authentication data */ if (scan) { no_auth = 1; } /* Set mandatory options (is that a contradiction in terms?) */ context->debug = debug; if (context_auth) { context->callbacks.auth_fn = NULL; smbc_option_set(context, "auth_function", (void *) get_auth_data_with_context_fn); smbc_option_set(context, "user_data", "hello world"); } else { context->callbacks.auth_fn = (no_auth ? no_auth_data_fn : get_auth_data_fn); } /* If we've been asked to log to stderr instead of stdout... */ if (debug_stderr) { /* ... then set the option to do so */ smbc_option_set(context, "debug_stderr", (void *) 1); } /* Initialize the context using the previously specified options */ if (!smbc_init_context(context)) { smbc_free_context(context, 0); printf("Could not initialize smbc context\n"); return 1; } /* Tell the compatibility layer to use this context */ smbc_set_context(context); sprintf(buf,"smb://*****:*****@213.179.58.120"); browse(buf, scan, 0); exit(0); }
int scanSMB(int (*scan_found_share)(char share[]),char host[],char username[], char password[], int (*documentError)(struct collectionFormat *collection, int level, const char *fmt, ...)) { int debug = 0; int debug_stderr = 0; int no_auth = 0; int context_auth = 0; int scan = 0; int iterations = -1; int again; int opt; char * p; char * q; char buf[1024]; poptContext pc; SMBCCTX * context; bblog(INFO, "scan.c: host %s username %s password %s",host,username,password); /* Allocate a new context */ context = smbc_new_context(); if (!context) { bblog(ERROR, "Could not allocate new smbc context"); return 0; } /* If we're scanning, do no requests for authentication data */ if (scan) { no_auth = 1; } /* Set mandatory options (is that a contradiction in terms?) */ context->debug = debug; if (context_auth) { context->callbacks.auth_fn = NULL; smbc_option_set(context, "auth_function", (void *) get_auth_data_with_context_fn); smbc_option_set(context, "user_data", "hello world"); } else { context->callbacks.auth_fn = (no_auth ? no_auth_data_fn : get_auth_data_fn); } /* If we've been asked to log to stderr instead of stdout... */ if (debug_stderr) { /* ... then set the option to do so */ smbc_option_set(context, "debug_stderr", (void *) 1); } /* Initialize the context using the previously specified options */ if (!smbc_init_context(context)) { smbc_free_context(context, 0); bblog(ERROR, "Could not initialize smbc context"); return 0; } /* Tell the compatibility layer to use this context */ smbc_set_context(context); sprintf(buf,"smb://%s:%s@%s",username,password,host); if (!browse(scan_found_share,buf, scan, 0)) { bblog(ERROR, "cant browse"); return 0; } return 1; //exit(0); }
int main(int argc, char * argv[]) { int debug = 0; int debug_stderr = 0; int no_auth = 0; int context_auth = 0; int scan = 0; int iterations = -1; int again; int opt; char * p; char * q; char buf[1024]; poptContext pc; SMBCCTX * context; struct poptOption long_options[] = { POPT_AUTOHELP { "debug", 'd', POPT_ARG_INT, &debug, 0, "Set debug level", "integer" }, { "stderr", 'e', POPT_ARG_NONE, &debug_stderr, 0, "Debug log to stderr instead of stdout", "integer" }, { "scan", 's', POPT_ARG_NONE, &scan, 0, "Scan for servers and shares", "integer" }, { "iterations", 'i', POPT_ARG_INT, &iterations, 0, "Iterations", "integer" }, { "noauth", 'A', POPT_ARG_NONE, &no_auth, 0, "Do not request authentication data", "integer" }, { "contextauth", 'C', POPT_ARG_NONE, &context_auth, 0, "Use new authentication function with context", "integer" }, { 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) { } } /* Allocate a new context */ context = smbc_new_context(); if (!context) { printf("Could not allocate new smbc context\n"); return 1; } /* If we're scanning, do no requests for authentication data */ if (scan) { no_auth = 1; } /* Set mandatory options (is that a contradiction in terms?) */ context->debug = debug; if (context_auth) { context->callbacks.auth_fn = NULL; smbc_option_set(context, "auth_function", (void *) get_auth_data_with_context_fn); smbc_option_set(context, "user_data", "hello world"); } else { context->callbacks.auth_fn = (no_auth ? no_auth_data_fn : get_auth_data_fn); } /* If we've been asked to log to stderr instead of stdout... */ if (debug_stderr) { /* ... then set the option to do so */ smbc_option_set(context, "debug_stderr", (void *) 1); } /* Initialize the context using the previously specified options */ if (!smbc_init_context(context)) { smbc_free_context(context, 0); printf("Could not initialize smbc context\n"); return 1; } /* Tell the compatibility layer to use this context */ smbc_set_context(context); if (scan) { for (; iterations == -1 || iterations > 0; iterations = (iterations == -1 ? iterations : --iterations)) { snprintf(buf, sizeof(buf), "smb://"); browse(buf, scan, 0); } } else { for (; iterations == -1 || iterations > 0; iterations = (iterations == -1 ? iterations : --iterations)) { fputs("url: ", stdout); p = fgets(buf, sizeof(buf), stdin); if (! p) { break; } if ((p = strchr(buf, '\n')) != NULL) { *p = '\0'; } browse(buf, scan, 0); } } exit(0); }