/* Given a username and password, expected to return AUTH_GRANTED if we can validate this user/password combination. */
static authn_status authn_crowd_check_password(request_rec *r, const char *user, const char *password)
{
    authnz_crowd_dir_config *config = get_config(r);
    if (config == NULL) {
        return AUTH_GENERAL_ERROR;
    }

    apr_array_header_t *basic_auth_xlates = config->basic_auth_xlates;
    int i;
    for (i = 0; i < basic_auth_xlates->nelts; i++) {
        apr_xlate_t *xlate = APR_ARRAY_IDX(basic_auth_xlates, i, apr_xlate_t *);
        char xlated_user[XLATE_BUFFER_SIZE] = {};
        char xlated_password[XLATE_BUFFER_SIZE] = {};
        if (!xlate_string(xlate, user, xlated_user) || !xlate_string(xlate, password, xlated_password)) {
            ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, "Failed to translate basic authentication credentials");
        } else {
            crowd_authenticate_result result = CROWD_AUTHENTICATE_NOT_ATTEMPTED;
            if (config->create_sso) {
                crowd_cookie_config_t *cookie_config = crowd_get_cookie_config(r, config->crowd_config);
                if (cookie_config != NULL && (!cookie_config->secure || is_https(r))) {
                    const char *token;
                    result = crowd_create_session(r, config->crowd_config, xlated_user, xlated_password, &token);
                    if (result == CROWD_AUTHENTICATE_SUCCESS && token != NULL) {
                        char *domain = "";
                        if (cookie_config->domain != NULL && cookie_config->domain[0] == '.') {
                            int domainlen = strlen(cookie_config->domain);
                            int hostlen = strlen(r->hostname);
                            if (hostlen > domainlen
                                && strcmp(cookie_config->domain, r->hostname + hostlen - domainlen) == 0) {
                                domain = apr_psprintf(r->pool, ";Domain=%s", cookie_config->domain);
                            }
                        }
                        char *cookie = log_ralloc(r,
                            apr_psprintf(r->pool, "%s=%s%s%s;Version=1", cookie_config->cookie_name, token, domain,
                            cookie_config->secure ? ";Secure" : ""));
                        if (cookie != NULL) {
                            apr_table_add(r->err_headers_out, "Set-Cookie", cookie);
                        }
                    }
                }
            }
            if (result == CROWD_AUTHENTICATE_NOT_ATTEMPTED) {
                result = crowd_authenticate(r, config->crowd_config, xlated_user, xlated_password);
            }
            switch (result) {
                case CROWD_AUTHENTICATE_SUCCESS:
                    ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, "Authenticated '%s'.", xlated_user);
                    return AUTH_GRANTED;
                case CROWD_AUTHENTICATE_FAILURE:
                    break;
                default:
                    ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, "Crowd authentication failed due to system exception");
            }
        }
    }

    return AUTH_DENIED;
}
示例#2
0
文件: tts.cpp 项目: Deslon/Supernova
static int spell_out(const char *word, int n, darray *phone)
{
	int nph = 0;

	while (n-- > 0)
	{
		nph += xlate_string(ASCII[*word++ & 0x7F], phone);
	}

	return nph;
}
示例#3
0
	result Speech::setText(const char *aText)
	{
		if (aText == NULL)
			return INVALID_PARAMETER;

		stop();
		mElement.clear();
		darray phone;
		xlate_string(aText, &phone);
		mFrames = klatt::phone_to_elm(phone.getData(), phone.getSize(), &mElement);
		return 0;
	}
示例#4
0
文件: tts.cpp 项目: Deslon/Supernova
/*
** Translate a number to phonemes.  This version is for ORDINAL numbers.
**       Note: this is recursive.
*/
static int xlate_ordinal(int value, darray *phone)
{
	int nph = 0;

	if (value < 0)
	{
		nph += xlate_string("minus", phone);
		value = (-value);

		if (value < 0)                 /* Overflow!  -32768 */
		{
			nph += xlate_string("a lot", phone);
			return nph;
		}
	}

	if (value >= 1000000000L)
		/* Billions */
	{
		nph += xlate_cardinal(value / 1000000000L, phone);
		value = value % 1000000000;

		if (value == 0)
		{
			nph += xlate_string("billionth", phone);
			return nph;                  /* Even billion */
		}

		nph += xlate_string("billion", phone);

		if (value < 100)
			nph += xlate_string("and", phone);

		/* as in THREE BILLION AND FIVE */
	}

	if (value >= 1000000L)
		/* Millions */
	{
		nph += xlate_cardinal(value / 1000000L, phone);
		value = value % 1000000L;

		if (value == 0)
		{
			nph += xlate_string("millionth", phone);
			return nph;                  /* Even million */
		}

		nph += xlate_string("million", phone);

		if (value < 100)
			nph += xlate_string("and", phone);

		/* as in THREE MILLION AND FIVE */
	}

	/* Thousands 1000..1099 2000..99999 */
	/* 1100 to 1999 is eleven-hunderd to ninteen-hunderd */

	if ((value >= 1000L && value <= 1099L) || value >= 2000L)
	{
		nph += xlate_cardinal(value / 1000L, phone);
		value = value % 1000L;

		if (value == 0)
		{
			nph += xlate_string("thousandth", phone);
			return nph;                  /* Even thousand */
		}

		nph += xlate_string("thousand", phone);

		if (value < 100)
			nph += xlate_string("and", phone);

		/* as in THREE THOUSAND AND FIVE */
	}

	if (value >= 100L)
	{
		nph += xlate_string(Cardinals[value / 100], phone);
		value = value % 100;

		if (value == 0)
		{
			nph += xlate_string("hundredth", phone);
			return nph;                  /* Even hundred */
		}

		nph += xlate_string("hundred", phone);
	}

	if (value >= 20)
	{
		if ((value % 10) == 0)
		{
			nph += xlate_string(Ord_twenties[(value - 20) / 10], phone);
			return nph;                  /* Even ten */
		}

		nph += xlate_string(Twenties[(value - 20) / 10], phone);

		value = value % 10;
	}

	nph += xlate_string(Ordinals[value], phone);

	return nph;
}
示例#5
0
文件: tts.cpp 项目: Deslon/Supernova
int xlate_string(const char *string, darray *phone)
{
	int nph = 0;
	const char *s = string;
	char ch;

	while (isspace(ch = *s))
		s++;

	while ((ch = *s))
	{
		const char *word = s;

		if (isalpha(ch))
		{
			while (isalpha(ch = *s) || ((ch == '\'' || ch == '-' || ch == '.') && isalpha(s[1])))
				s++;

			if (!ch || isspace(ch) || ispunct(ch) || (isdigit(ch) && !suspect_word(word, (int)(s - word))))
				nph += xlate_word(word, (int)(s - word), phone);
			else
			{
				while ((ch = *s) && !isspace(ch) && !ispunct(ch))
					s++;

				nph += spell_out(word, (int)(s - word), phone);
			}
		}

		else
			if (isdigit(ch) || (ch == '-' && isdigit(s[1])))
			{
				int sign = (ch == '-') ? -1 : 1;
				int value = 0;

				if (sign < 0)
					ch = *++s;

				while (isdigit(ch = *s))
				{
					value = value * 10 + ch - '0';
					s++;
				}

				if (ch == '.' && isdigit(s[1]))
				{
					word = ++s;
					nph += xlate_cardinal(value * sign, phone);
					nph += xlate_string("point", phone);

					while (isdigit(ch = *s))
						s++;

					nph += spell_out(word, (int)(s - word), phone);
				}

				else
				{
					/* check for ordinals, date, time etc. can go in here */
					nph += xlate_cardinal(value * sign, phone);
				}
			}

			else
				if (ch == '[' && strchr(s, ']'))
				{
					const char *word = s;

					while (*s && *s++ != ']')
						/* nothing */
						;

					nph += xlate_word(word, (int)(s - word), phone);
				}

				else
					if (ispunct(ch))
					{
						switch (ch)
						{

						case '!':

						case '?':

						case '.':
							s++;
							phone->put(' ');
							break;

						case '"':                 /* change pitch ? */

						case ':':

						case '-':

						case ';':

						case ',':

						case '(':

						case ')':
							s++;
							phone->put(' ');
							break;

						case '[':
							{
								const char *e = strchr(s, ']');

								if (e)
								{
									s++;

									while (s < e)
										phone->put(*s++);

									s = e + 1;

									break;
								}
							}

						default:
							nph += spell_out(word, 1, phone);
							s++;
							break;
						}
					}

					else
					{
						while ((ch = *s) && !isspace(ch))
							s++;

						nph += spell_out(word, (int)(s - word), phone);
					}

					while (isspace(ch = *s))
						s++;
	}

	return nph;
}