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 int Context_setOptionUseKerberos (Context *self, PyObject *value, void *closure) { if (!PyBool_Check (value)) { PyErr_SetString (PyExc_TypeError, "must be Boolean"); return -1; } smbc_setOptionUseKerberos (self->context, value == Py_True); 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; }
/* * 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 main(int argc, char** argv) { int err = -1; char url[MAX_BUFF_SIZE]; struct stat st; char *user; SMBCCTX *ctx; memset(g_workgroup, '\0', MAX_BUFF_SIZE); memset(url, '\0', MAX_BUFF_SIZE); if ( argc == 2) { char *p; user = getenv("USER"); if (!user) { printf("no user??\n"); return 0; } printf("username: %s\n", user); p = strchr(user, '\\'); if (! p) { printf("BAD username??\n"); return 0; } strncpy(g_workgroup, user, strlen(user)); g_workgroup[p - user] = 0; strncpy(g_username, p + 1, strlen(p + 1)); memset(g_password, 0, sizeof(char) * MAX_BUFF_SIZE); strncpy(url,argv[1],strlen(argv[1])); err = smbc_init(auth_fn, 10); if (err) { printf("init smbclient context failed!!\n"); return err; } /* Using null context actually get the old context. */ ctx = smbc_set_context(NULL); smbc_setOptionUseKerberos(ctx, 1); smbc_setOptionFallbackAfterKerberos(ctx, 1); smbc_setWorkgroup(ctx, g_workgroup); smbc_setUser(ctx, g_username); err = smbc_stat(url, &st); if ( err < 0 ) { err = 1; printf("stat failed!!\n"); } else { err = 0; printf("stat succeeded!!\n"); } } return err; }
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 opt; char * p; 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?) */ smbc_setDebug(context, debug); if (context_auth) { smbc_setFunctionAuthDataWithContext(context, get_auth_data_with_context_fn); smbc_setOptionUserData(context, (void *)"hello world"); } else { smbc_setFunctionAuthData(context, get_auth_data_fn); } smbc_setOptionUseKerberos(context, 1); smbc_setOptionFallbackAfterKerberos(context, 1); /* If we've been asked to log to stderr instead of stdout, ... */ if (debug_stderr) { /* ... then set the option to do so */ smbc_setOptionDebugToStderr(context, 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); }