Exemplo n.º 1
0
static bool
_mongoc_cyrus_is_failure (int status, bson_error_t *error)
{
   bool ret = (status < 0);

   TRACE ("Got status: %d ok is %d, continue=%d interact=%d\n",
          status,
          SASL_OK,
          SASL_CONTINUE,
          SASL_INTERACT);
   if (ret) {
      switch (status) {
      case SASL_NOMEM:
         bson_set_error (error,
                         MONGOC_ERROR_SASL,
                         status,
                         "SASL Failure: insufficient memory.");
         break;
      case SASL_NOMECH: {
         bson_string_t *str = bson_string_new ("available mechanisms: ");
         const char **mechs = sasl_global_listmech ();
         int i = 0;

         for (i = 0; mechs[i]; i++) {
            bson_string_append (str, mechs[i]);
            if (mechs[i + 1]) {
               bson_string_append (str, ",");
            }
         }
         bson_set_error (error,
                         MONGOC_ERROR_SASL,
                         status,
                         "SASL Failure: failure to negotiate mechanism (%s)",
                         str->str);
         bson_string_free (str, 0);
      } break;
      case SASL_BADPARAM:
         bson_set_error (error,
                         MONGOC_ERROR_SASL,
                         status,
                         "Bad parameter supplied. Please file a bug "
                         "with mongo-c-driver.");
         break;
      default:
         bson_set_error (error,
                         MONGOC_ERROR_SASL,
                         status,
                         "SASL Failure: (%d): %s",
                         status,
                         sasl_errstring (status, NULL, NULL));
         break;
      }
   }

   return ret;
}
Exemplo n.º 2
0
bool
_mongoc_cyrus_set_mechanism (mongoc_cyrus_t *sasl,
                             const char *mechanism,
                             bson_error_t *error)
{
   bson_string_t *str = bson_string_new ("");
   const char **mechs = sasl_global_listmech ();
   int i = 0;
   bool ok = false;

   BSON_ASSERT (sasl);

   for (i = 0; mechs[i]; i++) {
      if (!strcmp (mechs[i], mechanism)) {
         ok = true;
         break;
      }
      bson_string_append (str, mechs[i]);
      if (mechs[i + 1]) {
         bson_string_append (str, ",");
      }
   }

   if (ok) {
      bson_free (sasl->credentials.mechanism);
      sasl->credentials.mechanism = mechanism ? bson_strdup (mechanism) : NULL;
   } else {
      bson_set_error (error,
                      MONGOC_ERROR_SASL,
                      SASL_NOMECH,
                      "SASL Failure: Unsupported mechanism by client: %s. "
                      "Available mechanisms: %s",
                      mechanism,
                      str->str);
   }

   bson_string_free (str, true);
   return ok;
}
Exemplo n.º 3
0
void
OPENLDAP::BookForm (boost::shared_ptr<Ekiga::FormRequestSimple> request,
		    struct BookInfo &info)
{
  std::string callAttr = "";
  char *title = NULL;

  if (!info.name.empty ())
    /* Translators: This is Edit name of the LDAP Account
     * e.g. Editing Ekiga.net Account.
     */
    title = g_strdup_printf (_("Editing %s Account"), info.name.c_str ());
  else
    title = g_strdup (_("Add Account"));

  request->title (title);
  g_free (title);

  request->text ("name", _("_Name"), info.name, _("Ekiga.net LDAP Server"),
                 Ekiga::FormVisitor::STANDARD, false, false);
  request->text ("uri", _("_URI"), info.uri_host, "ldap://ekiga.net", Ekiga::FormVisitor::URI);
  request->text ("base", _("_Base DN:"), info.urld->lud_dn, "dc=ekiga,dc=net");

  {
    std::map<std::string, std::string> choices;
    std::string scopes[]= {"base","one","sub"};

    choices["sub"] = _("Subtree");
    choices["onelevel"] = _("Single Level");
    request->single_choice ("scope", _("_Search Scope"),
			    scopes[info.urld->lud_scope], choices, true);
  }

  /* attrs[0] is the name attribute */
  for (int i=1; info.urld->lud_attrs[i]; i++) {
    if (i>1) callAttr += ",";
    callAttr += std::string(info.urld->lud_attrs[i]);
  }
  /* Translators: DisplayName Attribute is the name of the LDAP
   * attribute whose value will be used to name an addressbook entry.
   * On Microsoft systems the actual attribute is literally named
   * "DisplayName" (i.e., "the name that will be displayed") but on
   * most LDAP servers it's "CommonName".
   */
  request->text ("nameAttr", _("_DisplayName Attribute"), info.urld->lud_attrs[0],
                 "givenName", Ekiga::FormVisitor::STANDARD, true);
  request->text ("callAttr", _("Call _Attributes"), callAttr,
                 "telephoneNumber", Ekiga::FormVisitor::STANDARD, true);
  if (info.urld->lud_filter != NULL)
    request->text ("filter", _("_Filter"), info.urld->lud_filter,
                   "(cn=$)", Ekiga::FormVisitor::STANDARD, true);
  else
    request->text ("filter", _("_Filter"), std::string (),
                   "(cn=$)", Ekiga::FormVisitor::STANDARD, true);

  /* Translators: Bind ID - In LDAP, the operation that begins an LDAP
   * session and authenticates the user to the directory is called a
   * Bind operation.  There are two types of Binds supported in the
   * standard protocol - Simple Bind and SASL Bind.  Since both of
   * them are used for authentication, both of them require some type
   * of user ID as a parameter, and that is supplied here.  (Of
   * course, the Bind ID can be left blank, in which case the session
   * is anonymous / unauthenticated.)
   */
  request->text ("authcID", _("Bind _ID"), info.authcID,
                 std::string (), Ekiga::FormVisitor::STANDARD, true);
  request->text ("password", _("_Password"), info.password,
                 std::string (), Ekiga::FormVisitor::PASSWORD, true);
  request->boolean ("startTLS", _("Use _TLS"),
                    info.starttls, true, false);
  request->boolean ("sasl", _("Use SAS_L"),
                    info.sasl, true, false);
  {
    std::map<std::string, std::string> mechs;
    const char **mechlist;

    mechlist = sasl_global_listmech();

    mechs[""] = "<default>";
    if (mechlist) {
      for (int i=0; mechlist[i]; i++) {
        std::string mech = std::string(mechlist[i]);
        mechs[mech] = mech;
      }
    }
    request->single_choice ("saslMech", _("SASL _Mechanism"),
			    info.saslMech, mechs, true);
  }
}