bool MapiProfiles::updateInterim(const char *profile, const QString &username, const QString &password, const QString &domain, const QString &server)
{
    if (!attributeModify(profile, "username", username)) {
        return false;
    }
    if (!attributeModify(profile, "binding", server)) {
        return false;
    }
    if (!attributeModify(profile, "domain", domain)) {
        return false;
    }

    struct mapi_session *session = NULL;
    if (MAPI_E_SUCCESS != MapiLogonProvider(m_context, &session, profile, password.toUtf8(), PROVIDER_ID_NSPI)) {
        error() << "cannot get logon provider" << mapiError();
        return false;
    }

    int retval = ProcessNetworkProfile(session, username.toUtf8().constData(), profileSelectCallback, NULL);
    if (retval != MAPI_E_SUCCESS && retval != 0x1) {
        error() << "cannot process network profile, deleting profile..." << mapiError();
        return false;
    }
    return true;
}
Beispiel #2
0
/**
   \details Create a full MAPI session
 
   Open providers stored in the profile and return a pointer on a
   IMAPISession object.

   \param mapi_ctx pointer to the MAPI context
   \param session pointer to a pointer to a MAPI session object
   \param profname profile name to use
   \param password password to use for the profile

   password should be set to NULL if the password has been stored in
   the profile.

   \return MAPI_E_SUCCESS on success otherwise MAPI error.

   \note Developers may also call GetLastError() to retrieve the last
   MAPI error code. Possible MAPI error codes are:
   - MAPI_E_NOT_INITIALIZED: MAPI subsystem has not been initialized
   - MAPI_E_NOT_ENOUGH_RESOURCES: MAPI subsystem failed to allocate
     the necessary resources to operate properly
   - MAPI_E_CALL_FAILED: A network problem was encountered during the
   transaction

   \sa MAPIInitialize, OpenProfile, MapiLogonProvider
*/
_PUBLIC_ enum MAPISTATUS MapiLogonEx(struct mapi_context *mapi_ctx,
				     struct mapi_session **session, 
				     const char *profname, 
				     const char *password)
{
	struct mapi_session	*tmp_session = NULL;
	enum MAPISTATUS		retval;

	retval = MapiLogonProvider(mapi_ctx, &tmp_session, profname, password, PROVIDER_ID_NSPI);
	if (retval != MAPI_E_SUCCESS) return retval;

	retval = MapiLogonProvider(mapi_ctx, &tmp_session, profname, password, PROVIDER_ID_EMSMDB);
	if (retval != MAPI_E_SUCCESS) return retval;

	*session = tmp_session;

	return MAPI_E_SUCCESS;
}
bool MapiProfiles::add(const QString &profile, const QString &username, const QString &password, const QString &domain, const QString &server)
{
    if (!init()) {
        return false;
    }

    // It seams that the QByteArray returned by QString::toUtf8() are not backed up.
    // calling toUtf8() several times will destroy the data. Therefore I copy them
    // all to temporary objects in order to preserve them throughout the whole method
    QByteArray baProfile(profile.toUtf8());
    QByteArray baUser(username.toUtf8());
    QByteArray baPass(password.toUtf8());
    QByteArray baDomain(domain.toUtf8());
    QByteArray baServer(server.toUtf8());

    const char *profile8 = baProfile.constData();
    qDebug() << "New profile is:"<<profile8;

    if (MAPI_E_SUCCESS != CreateProfile(m_context, profile8, baUser.constData(), baPass.constData(), 0)) {
        error() << "cannot create profile:" << mapiError();
        return false;
    }

    // TODO get workstation as parameter (was is it needed for anyway?)
    char hostname[256] = {};
    gethostname(&hostname[0], sizeof(hostname) - 1);
    hostname[sizeof(hostname) - 1] = 0;
    QString workstation = QString::fromLatin1(hostname);

    if (!attributeAdd(profile8, "binding", server)) {
        return false;
    }
    if (!attributeAdd(profile8, "workstation", workstation)) {
        return false;
    }
    if (!attributeAdd(profile8, "domain", domain)) {
        return false;
    }
// What is seal for? Seams to have something to do with Exchange 2010
// 	mapi_profile_add_string_attr(m_context, profile.toUtf8().constData(), "seal", (seal == true) ? "true" : "false");

// TODO Get langage from parameter if needed
// 	const char* locale = (const char *) (language) ? mapi_get_locale_from_language(language) : mapi_get_system_locale();
    const char *locale = mapi_get_system_locale();
    if (!locale) {
        error() << "cannot find system locale:" << mapiError();
        return false;
    }

    uint32_t cpid = mapi_get_cpid_from_locale(locale);
    uint32_t lcid = mapi_get_lcid_from_locale(locale);
    if (!cpid || !lcid) {
        error() << "invalid Locale supplied or unknown system locale" << locale << ", deleting profile..." << mapiError();
        if (!remove(profile)) {
            return false;
        }
        return false;
    }

    if (!attributeAdd(profile8, "codepage", QString::number(cpid))) {
        return false;
    }
    if (!attributeAdd(profile8, "language", QString::number(lcid))) {
        return false;
    }
    if (!attributeAdd(profile8, "method", QString::number(lcid))) {
        return false;
    }

    struct mapi_session *session = NULL;
    if (MAPI_E_SUCCESS != MapiLogonProvider(m_context, &session, profile8, password.toUtf8(), PROVIDER_ID_NSPI)) {
        error() << "cannot get logon provider, deleting profile..." << mapiError();
        if (!remove(profile)) {
            return false;
        }
        return false;
    }

    int retval = ProcessNetworkProfile(session, username.toUtf8().constData(), profileSelectCallback, NULL);
    if (retval != MAPI_E_SUCCESS && retval != 0x1) {
        error() << "cannot process network profile, deleting profile..." << mapiError();
        if (!remove(profile)) {
            return false;
        }
        return false;
    }
    return true;
}