Example #1
16
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)
{
    printf("Authenticating with context %p", context);
    if (context != NULL) {
        char *user_data = smbc_getOptionUserData(context);
        printf(" with user data %s", user_data);
    }
    printf("\n");

    get_auth_data_fn(pServer, pShare, pWorkgroup, maxLenWorkgroup,
                     pUsername, maxLenUsername, pPassword, maxLenPassword);
}
Example #2
0
/*
 * Authentication callback for libsmbclient
 */
static void get_auth_data_with_context_fn(SMBCCTX *smb_ctx,
    const char *srv,
    const char *shr,
    char *wg, int wglen,
    char *un, int unlen,
    char *pw, int pwlen)
{
  static int try_krb5 = 1;
  char *h;

  (void) smb_ctx;
  (void) shr;
  (void) wg;
  (void) wglen;

  DEBUG_SMB(("csync_smb - user=%s, workgroup=%s, server=%s, share=%s\n",
        un, wg, srv, shr));

  /* Don't authenticate for workgroup listing */
  if (srv == NULL || srv[0] == '\0') {
    DEBUG_SMB(("csync_smb - emtpy server name"));
    return;
  }

  /* Try kerberos authentication if available */
  if (try_krb5 && getenv("KRB5CCNAME")) {
    try_krb5 = 0;

    return;
  }

  /* check for an existing user */
  h = smbc_getUser(smb_ctx);
  if (h != NULL) {
    /* The username is known from the url. */
    DEBUG_SMB(("csync_smb - have username from url: %s\n", h));
    if (snprintf(un, unlen, "%s", h) < 0) {
      /* Even if that fials, go on. */
    }
  } else {
    if (_authcb != NULL) {
      DEBUG_SMB(("csync_smb - execute authentication callback\n"));
      (*_authcb) ("Username:"******"Password:"******"csync_smb - user=%s, workgroup=%s, server=%s, share=%s\n",
        un, wg, srv, shr));

  try_krb5 = 1;

  return;
}
Example #3
0
/*
 * Authentication callback for libsmbclient
 */
static void get_auth_data_with_context_fn(SMBCCTX *c,
    const char *srv,
    const char *shr,
    char *wg, int wglen,
    char *un, int unlen,
    char *pw, int pwlen) {

  static int try_krb5 = 1;

  (void) c;
  (void) shr;
  (void) wg;
  (void) wglen;

  DEBUG_SMB(("csync_smb - user=%s, workgroup=%s, server=%s, share=%s\n",
        un, wg, srv, shr));

  /* Don't authenticate for workgroup listing */
  if (srv == NULL || srv[0] == '\0') {
    DEBUG_SMB(("csync_smb - emtpy server name"));
    return;
  }

  /* Try kerberos authentication if available */
  if (try_krb5 && getenv("KRB5CCNAME")) {
    try_krb5 = 0;

    return;
  }

  /* Call the passwort prompt */
  if (_authcb != NULL) {
    DEBUG_SMB(("csync_smb - execute authentication callback\n"));
    (*_authcb) ("Username:"******"Password:"******"csync_smb - user=%s, workgroup=%s, server=%s, share=%s\n",
        un, wg, srv, shr));

  try_krb5 = 1;

  return;
}
Example #4
0
void auth_fn(SMBCCTX *c, const char *srv, const char *shr, char *wg, int wglen, char *un, int unlen, char *pw, int pwlen)
{
	SmbFs *fs = (SmbFs *) smbc_getOptionUserData(c);
	fs->auth(srv,shr,wg,wglen,un,unlen,pw,pwlen);
}
Example #5
0
static void
auth_fn (SMBCCTX *ctx,
	 const char *server, const char *share,
	 char *workgroup, int wgmaxlen,
	 char *username, int unmaxlen,
	 char *password, int pwmaxlen)
{
  PyObject *args;
  PyObject *kwds;
  PyObject *result;
  Context *self;
  const char *use_workgroup, *use_username, *use_password;

  debugprintf ("-> auth_fn (server=%s, share=%s)\n",
	       server ? server : "",
	       share ? share : "");

  self = smbc_getOptionUserData (ctx);
  if (self->auth_fn == NULL)
    {
      debugprintf ("<- auth_fn (), no callback\n");
      return;
    }

  if (!server || !*server)
    {
      debugprintf ("<- auth_fn(), no server\n");
      return;
    }

  args = Py_BuildValue ("(sssss)", server, share, workgroup,
			username, password);
  kwds = PyDict_New ();

  result = PyObject_Call (self->auth_fn, args, kwds);
  Py_DECREF (args);
  Py_DECREF (kwds);
  if (result == NULL)
    {
      debugprintf ("<- auth_fn(), failed callback\n");
      return;
    }

  if (!PyArg_ParseTuple (result, "sss",
			 &use_workgroup,
			 &use_username,
			 &use_password))
    {
      Py_DECREF (result);
      debugprintf ("<- auth_fn(), incorrect callback result\n");
      return;
    }

  strncpy (workgroup, use_workgroup, wgmaxlen - 1);
  workgroup[wgmaxlen - 1] = '\0';
  strncpy (username, use_username, unmaxlen - 1);
  username[unmaxlen - 1] = '\0';
  strncpy (password, use_password, pwmaxlen - 1);
  password[pwmaxlen - 1] = '\0';
  Py_DECREF (result);
  debugprintf ("<- auth_fn(), got callback result\n");
}
Example #6
0
static void
auth_fn (SMBCCTX    *smb_context,
         const char *server,
         const char *share,
         char       *workgroup,
         int         wgmaxlen,
         char       *username,
         int         unmaxlen,
         char       *password,
         int         pwmaxlen)
{
  PpSamba *samba;
  GSource *source;
  SMBData *data;

  data = (SMBData *) smbc_getOptionUserData (smb_context);
  samba = data->samba;

  if (!data->cancelled)
    {
      samba->priv->server = g_strdup (server);
      samba->priv->share = g_strdup (share);
      samba->priv->workgroup = g_strdup (workgroup);
      samba->priv->username = g_strdup (username);
      samba->priv->password = g_strdup (password);

      source = g_idle_source_new ();
      g_source_set_callback (source,
                             get_auth_info,
                             data,
                             NULL);
      g_source_attach (source, data->context);
      g_source_unref (source);

      samba->priv->waiting = TRUE;

      /*
       * smbclient needs to get authentication data
       * from this synchronous callback so we are blocking
       * until we get them
       */
      while (samba->priv->waiting)
        {
          g_usleep (POLL_DELAY);
        }

      /* Samba tries to call the auth_fn again if we just set the values
       * to NULL when we want to cancel the authentication 
       */
      if (samba->priv->username == NULL && samba->priv->password == NULL)
        data->cancelled = TRUE;

      if (samba->priv->username != NULL)
        {
          if (g_strcmp0 (username, samba->priv->username) != 0)
            g_strlcpy (username, samba->priv->username, unmaxlen);
        }
      else
        {
          username[0] = '\0';
        }

      if (samba->priv->password != NULL)
        {
          if (g_strcmp0 (password, samba->priv->password) != 0)
            g_strlcpy (password, samba->priv->password, pwmaxlen);
        }
      else
        {
          password[0] = '\0';
        }

    }
}