Пример #1
0
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;
}
Пример #2
0
static int
Context_setOptionFallbackAfterKerberos (Context *self, PyObject *value,
					void *closure)
{
  if (!PyBool_Check (value))
    {
      PyErr_SetString (PyExc_TypeError, "must be Boolean");
      return -1;
    }

  smbc_setOptionFallbackAfterKerberos (self->context, value == Py_True);
  return 0;
}
Пример #3
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;
}
Пример #4
0
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;

}
Пример #5
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                         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);
}