示例#1
0
static struct chanacs *
mygroup_chanacs_match_entity(struct chanacs *ca, struct myentity *mt)
{
	struct mygroup *mg;

	mg = group(ca->entity);

	return_val_if_fail(mg != NULL, NULL);

	if (!isuser(mt))
		return NULL;

	return groupacs_find(mg, mt, GA_CHANACS, true) != NULL ? ca : NULL;
}
示例#2
0
bool DataBase::createaccount(QString name, QString password)
{
    if(isuser(name))
        return false;

    QSqlQuery query(db);

    query.prepare("INSERT INTO account (name, password) "
                  "VALUES (:name, :password)");
    query.bindValue(":name", name);
    query.bindValue(":password", QCryptographicHash::hash(password.toUtf8(), QCryptographicHash::Md5).toHex());

    if(!query.exec())
    {
        QMessageBox::critical(0, QObject::tr("Database insert acc"),
                              query.lastError().text());

        return false;
    }

    updaterecord(name, 0, true);

    return true;
}
示例#3
0
文件: mail.c 项目: avkrotov/fdm
char *
find_address(char *buf, size_t len, size_t *alen)
{
	char	*ptr, *hdr, *first, *last;

	/*
	 * RFC2822 email addresses are stupidly complicated, so we just do a
	 * naive match which is good enough for 99% of addresses used now. This
	 * code is pretty inefficient.
	 */

	/* Duplicate the header as a string to work on it. */
	if (len == 0)
		return (NULL);
	hdr = xmalloc(len + 1);
	strlcpy(hdr, buf, len + 1);

	/* First, replace any sections in "s with spaces. */
	ptr = hdr;
	while (*ptr != '\0') {
		if (*ptr == '"') {
			ptr++;
			while (*ptr != '"' && *ptr != '\0')
				*ptr++ = ' ';
			if (*ptr == '\0')
				break;
		}
		ptr++;
	}

	/*
	 * Now, look for sections matching:
	 *	[< ][A-Za-z0-9._%+-]+@[A-Za-z0-9.\[\]-]+[> ,;].
	 */
#define isfirst(c) ((c) == '<' || (c) == ' ')
#define islast(c) ((c) == '>' || (c) == ' ' || (c) == ',' || (c) == ';')
#define isuser(c) (isalnum(c) || \
	(c) == '.' || (c) == '_' || (c) == '%' || (c) == '+' || (c) == '-')
#define isdomain(c) (isalnum(c) || \
	(c) == '.' || (c) == '-' || (c) == '[' || (c) == ']')
	ptr = hdr + 1;
	for (;;) {
		/* Find an @. */
		if ((ptr = strchr(ptr, '@')) == NULL)
			break;

		/* Find the end. */
		last = ptr + 1;
		while (*last != '\0' && isdomain((u_char) *last))
			last++;
		if (*last != '\0' && !islast((u_char) *last)) {
			ptr = last + 1;
			continue;
		}

		/* Find the start. */
		first = ptr - 1;
		while (first != hdr && isuser((u_char) *first))
			first--;
		if (first != hdr && !isfirst((u_char) *first)) {
			ptr = last + 1;
			continue;
		}

		/* If the last is > the first must be < and vice versa. */
		if (*last == '>' && *first != '<') {
			ptr = last + 1;
			continue;
		}
		if (*first == '<' && *last != '>') {
			ptr = last + 1;
			continue;
		}

		/* If not right at the start, strip first character. */
		if (first != hdr)
			first++;

		/* Free header copy. */
		xfree(hdr);

		/* Have last and first, return the address. */
		*alen = last - first;
		return (buf + (first - hdr));
	}

	xfree(hdr);
	return (NULL);
}