bool torture_libsmbclient_options(struct torture_context *tctx) { SMBCCTX *ctx; ctx = smbc_new_context(); torture_assert(tctx, ctx, "failed to get new context"); torture_assert(tctx, smbc_init_context(ctx), "failed to init context"); TEST_OPTION_INT(OptionDebugToStderr, true); TEST_OPTION_INT(OptionFullTimeNames, true); TEST_OPTION_INT(OptionOpenShareMode, SMBC_SHAREMODE_DENY_ALL); /* FIXME: OptionUserData */ TEST_OPTION_INT(OptionSmbEncryptionLevel, SMBC_ENCRYPTLEVEL_REQUEST); TEST_OPTION_INT(OptionCaseSensitive, false); TEST_OPTION_INT(OptionBrowseMaxLmbCount, 2); TEST_OPTION_INT(OptionUrlEncodeReaddirEntries, true); TEST_OPTION_INT(OptionOneSharePerServer, true); TEST_OPTION_INT(OptionUseKerberos, false); TEST_OPTION_INT(OptionFallbackAfterKerberos, false); TEST_OPTION_INT(OptionNoAutoAnonymousLogin, true); TEST_OPTION_INT(OptionUseCCache, true); smbc_free_context(ctx, 1); return true; }
static int Context_init (Context *self, PyObject *args, PyObject *kwds) { PyObject *auth = NULL; int debug = 0; SMBCCTX *ctx; static char *kwlist[] = { "auth_fn", "debug", NULL }; if (!PyArg_ParseTupleAndKeywords (args, kwds, "|Oi", kwlist, &auth, &debug)) { return -1; } if (auth) { if (!PyCallable_Check (auth)) { PyErr_SetString (PyExc_TypeError, "auth_fn must be callable"); return -1; } Py_XINCREF (auth); self->auth_fn = auth; } debugprintf ("-> Context_init ()\n"); errno = 0; ctx = smbc_new_context (); if (ctx == NULL) { PyErr_SetFromErrno (PyExc_RuntimeError); debugprintf ("<- Context_init() EXCEPTION\n"); return -1; } smbc_setDebug (ctx, debug); self->context = ctx; smbc_setOptionUserData (ctx, self); if (auth) smbc_setFunctionAuthDataWithContext (ctx, auth_fn); if (smbc_init_context (ctx) == NULL) { PyErr_SetFromErrno (PyExc_RuntimeError); smbc_free_context (ctx, 0); debugprintf ("<- Context_init() EXCEPTION\n"); return -1; } debugprintf ("%p <- Context_init() = 0\n", self->context); return 0; }
void create_and_destroy_context (void) { SMBCCTX *ctx; ctx = smbc_new_context (); smbc_init_context (ctx); smbc_free_context (ctx, 1); }
SmbFs::SmbFs(QString name, QObject *parent) : BaseFs(name,parent) { _ctx = smbc_new_context(); smbc_setTimeout(_ctx,10000); smbc_setOptionUserData(_ctx,this); //set this class as the user data, so we can get it from the auth function smbc_setOptionOneSharePerServer(_ctx,true); smbc_setFunctionAuthDataWithContext(_ctx,auth_fn); //set the authentication function _ctx = smbc_init_context(_ctx); if(_ctx == NULL) qDebug() << "Null Context!" << strerror(errno); }
/***************************************************** initialise structures *******************************************************/ static void do_init(StartupType startupType) { int i; char *p; smbw_initialized = 1; /* this must be first to avoid recursion! */ smbw_ctx = NULL; /* don't free context until it's established */ /* initially, no file descriptors are mapped */ for (i = 0; i < __FD_SETSIZE; i++) { smbw_fd_map[i] = -1; smbw_ref_count[i] = 0; } /* See if we've been told to start in a particular directory */ if ((p=getenv("SMBW_DIR")) != NULL) { smbw_strlcpy(smbw_cwd, p, PATH_MAX); /* we don't want the old directory to be busy */ (* smbw_libc.chdir)("/"); } else { *smbw_cwd = '\0'; } if ((p=getenv("DEBUG"))) { debug_level = atoi(p); } if ((smbw_ctx = smbc_new_context()) == NULL) { fprintf(stderr, "Could not create a context.\n"); exit(1); } smbw_ctx->debug = debug_level; smbw_ctx->callbacks.auth_fn = get_auth_data_fn; smbw_ctx->options.browse_max_lmb_count = 0; smbw_ctx->options.urlencode_readdir_entries = 1; smbw_ctx->options.one_share_per_server = 1; if (smbc_init_context(smbw_ctx) == NULL) { fprintf(stderr, "Could not initialize context.\n"); exit(1); } smbc_set_context(smbw_ctx); /* if not real startup, exit handler has already been established */ if (startupType == StartupType_Real) { atexit(do_shutdown); } }
static gboolean xmms_samba_plugin_setup (xmms_xform_plugin_t *xform_plugin) { xmms_xform_methods_t methods; gint err; XMMS_XFORM_METHODS_INIT (methods); methods.init = xmms_samba_init; methods.destroy = xmms_samba_destroy; methods.read = xmms_samba_read; methods.seek = xmms_samba_seek; methods.browse = xmms_samba_browse; xmms_xform_plugin_methods_set (xform_plugin, &methods); xmms_xform_plugin_indata_add (xform_plugin, XMMS_STREAM_TYPE_MIMETYPE, "application/x-url", XMMS_STREAM_TYPE_URL, "smb://*", XMMS_STREAM_TYPE_END); G_LOCK (mutex); if (smbc_set_context (NULL) == NULL) { /* This should really be cleaned up when the program closes. * However, given that we have no means of doing so, we're * just going to forget that we ever created it and let the OS * clean up after us. */ SMBCCTX *ctx = smbc_new_context (); if (ctx == NULL) { xmms_log_error ("Failed to create SMBCCTX.", NULL); return FALSE; } if (smbc_init_context (ctx) == NULL) { xmms_log_error ("Failed to init SMBCCTX.", NULL); smbc_free_context (ctx, 1); return FALSE; } smbc_setOptionUseKerberos (ctx, TRUE); smbc_setOptionFallbackAfterKerberos (ctx, TRUE); smbc_set_context (ctx); } err = smbc_init (xmms_samba_auth_fn, 0); G_UNLOCK (mutex); if (err < 0) { xmms_log_error ("%s", strerror (errno)); return FALSE; } return TRUE; }
static void _pp_samba_get_devices_thread (GSimpleAsyncResult *res, GObject *object, GCancellable *cancellable) { static GMutex mutex; SMBData *data; SMBCCTX *smb_context; gchar *dirname; gchar *path; gchar *hostname = NULL; data = g_simple_async_result_get_op_res_gpointer (res); data->devices = g_new0 (PpDevicesList, 1); data->devices->devices = NULL; data->samba = PP_SAMBA (object); g_mutex_lock (&mutex); smb_context = smbc_new_context (); if (smb_context) { if (smbc_init_context (smb_context)) { smbc_setOptionUserData (smb_context, data); g_object_get (object, "hostname", &hostname, NULL); if (hostname != NULL) { dirname = g_strdup_printf ("smb://%s", hostname); path = g_strdup_printf ("//%s", hostname); g_free (hostname); } else { dirname = g_strdup_printf ("smb://"); path = g_strdup_printf ("//"); } smbc_setFunctionAuthDataWithContext (smb_context, anonymous_auth_fn); list_dir (smb_context, dirname, path, cancellable, data); g_free (dirname); g_free (path); } smbc_free_context (smb_context, 1); } g_mutex_unlock (&mutex); }
int main() { SMBCCTX* smbCTX = smbc_new_context(); if ( !smbCTX ) { return 1; } if ( !smbc_init_context( smbCTX ) ) { return 1; } smbc_set_context( smbCTX ); smbc_setFunctionAuthData( smbCTX, smbcAuth ); smbc_setOptionUrlEncodeReaddirEntries( smbCTX, 0 ); return 0; }
csync_vio_method_t *vio_module_init(const char *method_name, const char *args, csync_auth_callback cb, void *userdata) { smb_context = smbc_new_context(); DEBUG_SMB(("csync_smb - method_name: %s\n", method_name)); DEBUG_SMB(("csync_smb - args: %s\n", args)); (void) method_name; (void) args; (void) cb; if (smb_context == NULL) { fprintf(stderr, "csync_smb - failed to create new smbc context\n"); return NULL; } if (cb != NULL) { _authcb = cb; } /* set debug level and authentication function callback */ smbc_setDebug(smb_context, 0); smbc_setOptionUserData(smb_context, userdata); smbc_setFunctionAuthDataWithContext(smb_context, get_auth_data_with_context_fn); /* Kerberos support */ smbc_setOptionUseKerberos(smb_context, 1); smbc_setOptionFallbackAfterKerberos(smb_context, 1); DEBUG_SMB(("csync_smb - use kerberos = %d\n", smbc_getOptionUseKerberos(smb_context))); DEBUG_SMB(("csync_smb - use fallback after kerberos = %d\n", smbc_getOptionFallbackAfterKerberos(smb_context))); if (smbc_init_context(smb_context) == NULL) { fprintf(stderr, "csync_smb - failed to initialize the smbc context"); smbc_free_context(smb_context, 0); smb_context = NULL; return NULL; } DEBUG_SMB(("csync_smb - KRB5CCNAME = %s\n", getenv("KRB5CCNAME") != NULL ? getenv("KRB5CCNAME") : "not set")); smbc_set_context(smb_context); return &_method; }
static bool torture_libsmbclient_initialize(struct torture_context *tctx) { SMBCCTX *ctx; torture_comment(tctx, "Testing smbc_new_context\n"); ctx = smbc_new_context(); torture_assert(tctx, ctx, "failed to get new context"); torture_comment(tctx, "Testing smbc_init_context\n"); torture_assert(tctx, smbc_init_context(ctx), "failed to init context"); smbc_free_context(ctx, 1); return true; }
bool torture_libsmbclient_configuration(struct torture_context *tctx) { SMBCCTX *ctx; ctx = smbc_new_context(); torture_assert(tctx, ctx, "failed to get new context"); torture_assert(tctx, smbc_init_context(ctx), "failed to init context"); TEST_OPTION_INT(Debug, DEBUGLEVEL); TEST_OPTION_STRING(NetbiosName, "torture_netbios"); TEST_OPTION_STRING(Workgroup, "torture_workgroup"); TEST_OPTION_STRING(User, "torture_user"); TEST_OPTION_INT(Timeout, 12345); smbc_free_context(ctx, 1); return true; }
bool torture_libsmbclient_init_context(struct torture_context *tctx, SMBCCTX **ctx_p) { SMBCCTX *ctx; ctx = smbc_new_context(); torture_assert(tctx, ctx, "failed to get new context"); torture_assert(tctx, smbc_init_context(ctx), "failed to init context"); smbc_setDebug(ctx, DEBUGLEVEL); smbc_setOptionDebugToStderr(ctx, 1); /* yes, libsmbclient API frees the username when freeing the context, so * have to pass malloced data here */ smbc_setUser(ctx, strdup(cli_credentials_get_username(cmdline_credentials))); *ctx_p = ctx; return true; }
static void InitSmb() { MutexLock lock( &smbMutex ); if ( smbCTX ) { return; } smbCTX = smbc_new_context(); if ( !smbCTX ) { throw_syserr( 0, "smbclient can`t allocate context" ); } if ( !smbc_init_context( smbCTX ) ) { smbc_free_context( smbCTX, 0 ); smbCTX = 0; throw_syserr( 0, "smbclient can`t init context" ); } smbc_set_context( smbCTX ); smbc_setFunctionAuthData( smbCTX, smbcAuth ); smbc_setOptionUrlEncodeReaddirEntries( smbCTX, 0 ); }
int smbc_init(smbc_get_auth_data_fn fn, int debug) { if (!smbc_compat_initialized) { statcont = smbc_new_context(); if (!statcont) return -1; smbc_setDebug(statcont, debug); smbc_setFunctionAuthData(statcont, fn); if (!smbc_init_context(statcont)) { smbc_free_context(statcont, False); return -1; } smbc_compat_initialized = 1; return 0; } return 0; }
static SMBCCTX* create_context(void) { SMBCCTX *ctx; extern int gTimeout; extern int gPassIsHash; //Create the Samba context struct , if it didn't work quit. if((ctx = smbc_new_context()) == NULL) return NULL; #ifdef DEBUG //Set the options for our context. a //If its enabled at the command line, turn on Samba library debugging smbc_setDebug(ctx, 1); //We want to log our errors to STDERR instead of STDOUT smbc_setOptionDebugToStderr(ctx, 1); #endif //Set the function that the Samba library will call when it needs //to authenticate smbc_setFunctionAuthData(ctx, auth_fn); //Set the timeout, we get the command line option as seconds and the //function takes milliseconds. smbc_setTimeout(ctx, 200); //If we got a hash at the command line, let the context know we're //giving it a hash smbc_setOptionUseNTHash(ctx, gPassIsHash); //Initialize our context with the options that we have set or null on fail. if(smbc_init_context(ctx) == NULL) { smbc_free_context(ctx, 1); return NULL; } return ctx; }
/* * Using its smb_uri components and cached_gpt_version inputs, this function * does several things: * - it downloads the GPT_INI file to GPO_CACHE * - it parses the sysvol_gpt_version field from the GPT_INI file * - if the sysvol_gpt_version is greater than the cached_gpt_version * - it downloads the policy file to GPO_CACHE * - else * - it doesn't retrieve the policy file * - in this case, the backend will use the existing policy file in GPO_CACHE * - it returns the sysvol_gpt_version in the _sysvol_gpt_version output param * * Note that if the cached_gpt_version sent by the backend is -1 (to indicate * that no gpt_version has been set in the cache for the corresponding gpo_guid), * then the parsed sysvol_gpt_version (which must be at least 0) will be greater * than the cached_gpt_version, thereby triggering a fresh download. * * Note that the backend will later do the following: * - backend will save the the sysvol_gpt_version to sysdb cache * - backend will read the policy file from the GPO_CACHE */ static errno_t perform_smb_operations(int cached_gpt_version, const char *smb_server, const char *smb_share, const char *smb_path, const char *smb_cse_suffix, int *_sysvol_gpt_version) { SMBCCTX *smbc_ctx; int ret; int sysvol_gpt_version; smbc_ctx = smbc_new_context(); if (smbc_ctx == NULL) { DEBUG(SSSDBG_CRIT_FAILURE, "Could not allocate new smbc context\n"); ret = ENOMEM; goto done; } smbc_setFunctionAuthData(smbc_ctx, sssd_krb_get_auth_data_fn); smbc_setOptionUseKerberos(smbc_ctx, 1); /* Initialize the context using the previously specified options */ if (smbc_init_context(smbc_ctx) == NULL) { DEBUG(SSSDBG_CRIT_FAILURE, "Could not initialize smbc context\n"); ret = ENOMEM; goto done; } /* download ini file */ ret = copy_smb_file_to_gpo_cache(smbc_ctx, smb_server, smb_share, smb_path, GPT_INI); if (ret != EOK) { DEBUG(SSSDBG_CRIT_FAILURE, "copy_smb_file_to_gpo_cache failed [%d][%s]\n", ret, strerror(ret)); goto done; } ret = ad_gpo_parse_ini_file(smb_path, &sysvol_gpt_version); if (ret != EOK) { DEBUG(SSSDBG_CRIT_FAILURE, "Cannot parse ini file: [%d][%s]\n", ret, strerror(ret)); goto done; } DEBUG(SSSDBG_TRACE_FUNC, "sysvol_gpt_version: %d\n", sysvol_gpt_version); if (sysvol_gpt_version > cached_gpt_version) { /* download policy file */ ret = copy_smb_file_to_gpo_cache(smbc_ctx, smb_server, smb_share, smb_path, smb_cse_suffix); if (ret != EOK) { DEBUG(SSSDBG_CRIT_FAILURE, "copy_smb_file_to_gpo_cache failed [%d][%s]\n", ret, strerror(ret)); goto done; } } *_sysvol_gpt_version = sysvol_gpt_version; done: smbc_free_context(smbc_ctx, 0); return ret; }
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); }
void CSMB::Init() { PLATFORM::CLockObject lock(*this); if (!m_context) { // Create ~/.smb/smb.conf. This file is used by libsmbclient. // http://us1.samba.org/samba/docs/man/manpages-3/libsmbclient.7.html // http://us1.samba.org/samba/docs/man/manpages-3/smb.conf.5.html char smb_conf[MAX_PATH]; sprintf(smb_conf, "%s/.smb", getenv("HOME")); mkdir(smb_conf, 0755); sprintf(smb_conf, "%s/.smb/smb.conf", getenv("HOME")); FILE* f = fopen(smb_conf, "w"); if (f != NULL) { fprintf(f, "[global]\n"); // make sure we're not acting like a server fprintf(f, "\tpreferred master = no\n"); fprintf(f, "\tlocal master = no\n"); fprintf(f, "\tdomain master = no\n"); // use the weaker LANMAN password hash in order to be compatible with older servers fprintf(f, "\tclient lanman auth = yes\n"); fprintf(f, "\tlanman auth = yes\n"); fprintf(f, "\tsocket options = TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=65536 SO_SNDBUF=65536\n"); fprintf(f, "\tlock directory = %s/.smb/\n", getenv("HOME")); fprintf(f, "\tname resolve order = lmhosts bcast host\n"); fclose(f); } // reads smb.conf so this MUST be after we create smb.conf // multiple smbc_init calls are ignored by libsmbclient. smbc_init(xb_smbc_auth, 0); // setup our context m_context = smbc_new_context(); m_context->debug = 10; //g_advancedSettings.m_logLevel == LOG_LEVEL_DEBUG_SAMBA ? 10 : 0; m_context->callbacks.auth_fn = xb_smbc_auth; orig_cache = m_context->callbacks.get_cached_srv_fn; m_context->callbacks.get_cached_srv_fn = xb_smbc_cache; m_context->options.one_share_per_server = false; m_context->options.browse_max_lmb_count = 0; m_context->timeout = 10000; //g_advancedSettings.m_sambaclienttimeout * 1000; // initialize samba and do some hacking into the settings if (smbc_init_context(m_context)) { /* setup old interface to use this context */ smbc_set_context(m_context); } else { smbc_free_context(m_context, 1); m_context = NULL; } } m_IdleTimeout = 180; }
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); }
void CSMB::Init() { PLATFORM::CLockObject lock(*this); if (!m_context) { // Create ~/.smb/smb.conf. This file is used by libsmbclient. // http://us1.samba.org/samba/docs/man/manpages-3/libsmbclient.7.html // http://us1.samba.org/samba/docs/man/manpages-3/smb.conf.5.html char smb_conf[MAX_PATH]; sprintf(smb_conf, "%s/.smb", getenv("HOME")); mkdir(smb_conf, 0755); sprintf(smb_conf, "%s/.smb/smb.conf", getenv("HOME")); FILE* f = fopen(smb_conf, "w"); if (f != NULL) { fprintf(f, "[global]\n"); // make sure we're not acting like a server fprintf(f, "\tpreferred master = no\n"); fprintf(f, "\tlocal master = no\n"); fprintf(f, "\tdomain master = no\n"); // use the weaker LANMAN password hash in order to be compatible with older servers fprintf(f, "\tclient lanman auth = yes\n"); fprintf(f, "\tlanman auth = yes\n"); fprintf(f, "\tsocket options = TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=65536 SO_SNDBUF=65536\n"); fprintf(f, "\tlock directory = %s/.smb/\n", getenv("HOME")); // set wins server if there's one. name resolve order defaults to 'lmhosts host wins bcast'. // if no WINS server has been specified the wins method will be ignored. // if ( g_guiSettings.GetString("smb.winsserver").length() > 0 && !g_guiSettings.GetString("smb.winsserver").Equals("0.0.0.0") ) // { // fprintf(f, "\twins server = %s\n", g_guiSettings.GetString("smb.winsserver").c_str()); // fprintf(f, "\tname resolve order = bcast wins host\n"); // } // else fprintf(f, "\tname resolve order = bcast host\n"); // use user-configured charset. if no charset is specified, // samba tries to use charset 850 but falls back to ASCII in case it is not available // if (g_advancedSettings.m_sambadoscodepage.length() > 0) // fprintf(f, "\tdos charset = %s\n", g_advancedSettings.m_sambadoscodepage.c_str()); // if no workgroup string is specified, samba will use the default value 'WORKGROUP' // if ( g_guiSettings.GetString("smb.workgroup").length() > 0 ) // fprintf(f, "\tworkgroup = %s\n", g_guiSettings.GetString("smb.workgroup").c_str()); fclose(f); } // reads smb.conf so this MUST be after we create smb.conf // multiple smbc_init calls are ignored by libsmbclient. smbc_init(xb_smbc_auth, 0); // setup our context m_context = smbc_new_context(); //#ifdef DEPRECATED_SMBC_INTERFACE // smbc_setDebug(m_context, g_advancedSettings.m_logLevel == LOG_LEVEL_DEBUG_SAMBA ? 10 : 0); // smbc_setFunctionAuthData(m_context, xb_smbc_auth); // orig_cache = smbc_getFunctionGetCachedServer(m_context); // smbc_setFunctionGetCachedServer(m_context, xb_smbc_cache); // smbc_setOptionOneSharePerServer(m_context, false); // smbc_setOptionBrowseMaxLmbCount(m_context, 0); // smbc_setTimeout(m_context, g_advancedSettings.m_sambaclienttimeout * 1000); //#else m_context->debug = 10; //g_advancedSettings.m_logLevel == LOG_LEVEL_DEBUG_SAMBA ? 10 : 0; m_context->callbacks.auth_fn = xb_smbc_auth; orig_cache = m_context->callbacks.get_cached_srv_fn; m_context->callbacks.get_cached_srv_fn = xb_smbc_cache; m_context->options.one_share_per_server = false; m_context->options.browse_max_lmb_count = 0; m_context->timeout = 10000; //g_advancedSettings.m_sambaclienttimeout * 1000; //#endif // initialize samba and do some hacking into the settings if (smbc_init_context(m_context)) { /* setup old interface to use this context */ smbc_set_context(m_context); } else { smbc_free_context(m_context, 1); m_context = NULL; } } m_IdleTimeout = 180; }
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); }