Ejemplo n.º 1
0
  static int
  book_saslinter(LDAP *ld, unsigned flags __attribute__((unused)),
		 void *def, void *inter)
  {
    sasl_interact_t *in = (sasl_interact_t *)inter;
    interctx *ctx = (interctx *)def;
    struct berval p;
    int i, nprompts = 0;

    /* Fill in the prompts we have info for; count
     * how many we're missing.
     */
    for (;in->id != SASL_CB_LIST_END;in++)
      {
	p.bv_val = NULL;
	switch(in->id)
	  {
	  case SASL_CB_GETREALM:
	    ldap_get_option(ld, LDAP_OPT_X_SASL_REALM, &p.bv_val);
	    if (p.bv_val) p.bv_len = strlen(p.bv_val);
	    break;
	  case SASL_CB_AUTHNAME:
	    p.bv_len = ctx->authcID.length();
	    if (p.bv_len)
	      p.bv_val = (char *)ctx->authcID.c_str();
	    break;
	  case SASL_CB_USER:
	    /* If there was a default authcID, just ignore the authzID */
	    if (ctx->authcID.length()) {
	      p.bv_val = (char *)"";
	      p.bv_len = 0;
	    }
	    break;
	  case SASL_CB_PASS:
	    p.bv_len = ctx->password.length();
	    if (p.bv_len)
	      p.bv_val = (char *)ctx->password.c_str();
	    break;
	  default:
	    break;
	  }
	if (p.bv_val)
	  {
	    in->result = p.bv_val;
	    in->len = p.bv_len;
	  } else
	  {
	    nprompts++;
	    in->result = NULL;
	  }
      }

    /* If there are missing items, try to get them all in one dialog */
    if (nprompts) {
      boost::shared_ptr<Ekiga::FormRequestSimple> request = boost::shared_ptr<Ekiga::FormRequestSimple> (new Ekiga::FormRequestSimple (boost::bind (&OPENLDAP::Book::on_sasl_form_submitted, ctx->book, _1, _2, _3)));
      Ekiga::FormBuilder result;
      std::string prompt;
      std::string ctxt = "";
      char resbuf[32];

      request->title (_("LDAP SASL Interaction"));

      for (i=0, in = (sasl_interact_t *)inter;
	   in->id != SASL_CB_LIST_END;in++)
	{
	  bool noecho = false, challenge = false;

	  if (in->result) continue;

	  /* Give each dialog item a unique name */
	  sprintf(resbuf, "res%02x", i);
	  i++;

	  /* Check for prompts that need special handling */
	  switch(in->id)
	    {
	    case SASL_CB_PASS:
	      noecho = true;
	      break;
	    case SASL_CB_NOECHOPROMPT:
	      noecho = true;
	      challenge = true;
	      break;
	    case SASL_CB_ECHOPROMPT:
	      challenge = true;
	      break;
	    default:
	      break;
	    }

	  /* accumulate any challenge strings */
	  if (challenge && in->challenge) {

	    /* Translators, Howard explained : "Challenge" is a generic term
	     * in authentication. It's a prompt from the authentication mechanism
	     * for some type of credential. Exactly what kind of challenge and
	     * what kind of credential depends on the specific authentication
	     * mechanism. Since SASL is a generic interface, and can dynamically
	     * load arbitrary mechanisms, there's not much more specific you can
	     * say about it. You might google for "challenge response
	     * authentication" if you'd like more background context.
	     */
	    ctxt += std::string (_("Challenge: ")) +
	      std::string (in->challenge) +"\n";
	  }

	  /* use the provided prompt text, or our default? */
	  if (in->prompt)
	    prompt = std::string (in->prompt);
	  else
	    prompt = std::string (_("Interact"));

	  /* private text or not? */
	  if (noecho) {
	    request->text (std::string (resbuf), prompt, "", std::string (), Ekiga::FormVisitor::PASSWORD);
	  } else {
	    std::string dflt;
	    if (in->defresult)
	      dflt = std::string (in->defresult);
	    else
	      dflt = "";
	    request->text (std::string(resbuf), prompt, dflt, std::string ());
	  }
	}

      /* If we had any challenge text, set it now */
      if (!ctxt.empty())
	request->instructions (ctxt);

      /* Save a pointer for storing the form result */
      ctx->book->saslform = &result;
      ctx->book->questions (request);

      /* Extract answers from the result form */
      for (i=0, in = (sasl_interact_t *)inter;
	   in->id != SASL_CB_LIST_END;in++)
	{
	  bool noecho = false;

	  if (in->result) continue;

	  sprintf(resbuf, "res%02x", i);
	  i++;
	  switch(in->id)
	    {
	    case SASL_CB_PASS:
	    case SASL_CB_NOECHOPROMPT:
	      noecho = true;
	      break;
	    default:
	      break;
	    }
	  if (noecho)
	    prompt = result.text (std::string (resbuf));
	  else
	    prompt = result.text (std::string (resbuf));

	  /* Save the answers so they don't disappear before our
	   * caller can see them; return the saved copies.
	   */
	  ctx->results.push_back (prompt);
	  in->result = ctx->results.back().c_str();
	  in->len = ctx->results.back().length();
	}
    }
    return LDAP_SUCCESS;
  }
Ejemplo n.º 2
0
  void submit (Ekiga::FormBuilder &builder)
  {
    builder.text (name, description,
          gtk_entry_get_text (GTK_ENTRY (widget)), tooltip,
		  advanced);
  }