示例#1
0
char *
filter_uid(char *uid)
{
	if (uid == (char *)0)
		return 0;

	if (!filter_start(&filter)  ||
	    !stralloc_copys(&filter,"(") ||
	    !stralloc_cats(&filter, LDAP_UID) ||
	    !stralloc_cats(&filter, "=") ||
	    !filter_escape(&filter, uid, str_len(uid)) ||
	    !stralloc_cats(&filter, ")") ||
	    !filter_end(&filter))
		return (char *)0;

	return filter.s;
}
示例#2
0
char *
filter_uid(char *uid)
{
	char	*escaped;
	
	if (uid == (char *)0) return 0;
	
	escaped = filter_escape(uid);
	if (escaped == (char *)0) return 0;
	
	if (!stralloc_copys(&filter,"(") ||
	    !stralloc_cats(&filter, LDAP_UID) ||
	    !stralloc_cats(&filter, "=") ||
	    !stralloc_cats(&filter, escaped) ||
	    !stralloc_cats(&filter, ")") ||
	    !stralloc_0(&filter))
		return (char *)0;
	return filter_objectclass(filter.s);
}
示例#3
0
char *
filter_mail(char *mail, int *done)
{
	char			*domain, *alias;
	unsigned int		at;
	int			round;
#ifdef DASH_EXT
	unsigned int 		i;
#endif

	if (mail == (char *)0) {
		ext = 0;
		return 0;
	}

	at = str_rchr(mail, '@');
	if (at == 0 || mail[at] != '@') {
		ext = 0;
		return 0;
	}
	domain = mail + at + 1;

	if (adok) {
		alias = constmap(&ad_map, domain, str_len(domain));
		if (alias && *alias)
			domain = alias;
	}

	if (ext == 0) {
		ext = at;
		extcnt = -1;
		*done = 0;
	} else {
		if (extcnt == 0) {
			*done = 1;
			ext = 0;
			return 0;
		}
#ifdef DASH_EXT
		/*
		 * limit ext to the first DASH_EXT_LEVELS extensions.
		 * We will only check for (DASH_EXT_LEVELS = 4):
		 * [email protected]
		 * [email protected]
		 * [email protected]
		 * [email protected]
		 * [email protected]
		 * [email protected]
		 */
		if (ext == at)
			for (i = 0, ext = 0, extcnt = 1;
			    ext < at && extcnt <= DASH_EXT_LEVELS; ext++)
				if (mail[ext] == *auto_break) extcnt++;
		while (ext != 0 && --ext > 0) {
			if (mail[ext] == *auto_break) break;
		}
		extcnt--;
#else
#error XXX XXX 
		/* basic qmail-ldap behavior test for [email protected] and
		   [email protected] */
		ext = 0;
		extcnt = 0;
#endif
	}
	
	for (round = 0; round < 2; round++) {
		switch (round) {
		case 0:
			/* build the search string for the email address */
			/* mail address */
			if (!filter_start(&filter) ||
			    !stralloc_cats(&filter, "(|(") ||
			    !stralloc_cats(&filter, LDAP_MAIL) ||
			    !stralloc_cats(&filter, "="))
				return 0;
			break;
		case 1:
			/* mailalternate address */
			if (!stralloc_cats(&filter, ")(") ||
			    !stralloc_cats(&filter, LDAP_MAILALTERNATE) ||
			    !stralloc_cats(&filter, "="))
				return 0;
			break;
		}

		/* username till current '-' or '@' */
		if (!filter_escape(&filter, mail, ext))
			return 0;
		/* do not append catchall in the first round */
		if (ext != at) {
			/* catchall or default */
			if (extcnt > 0) /* add '-' */
				if (!stralloc_cats(&filter, auto_break))
					return 0;
			if (!stralloc_cats(&filter, LDAP_CATCH_ALL))
				return 0;
		}
		/* @domain.com */
		if (!stralloc_append(&filter, "@") ||
		    !filter_escape(&filter, domain, str_len(domain)))
			return 0;
	}

	if (!stralloc_cats(&filter, "))") ||
	    !filter_end(&filter))
		return 0;

	if (extcnt == 0)
		*done = 1;

	if (mail[0] == *auto_break) *done = 1; // OSC: do not do DASH_EXT loop if first char is auto_break
	return filter.s;
}
示例#4
0
char *
filter_mail(char *mail, int *done)
{
	static char		*escaped;
	static unsigned int	at, ext, len = 0;
#ifdef DASH_EXT
	unsigned int 		i;
#endif

	if (mail == (char *)0) {
		len = 0;
		return 0;
	}

	if (len == 0) {
#ifdef DOMAIN_ALIAS
		escaped = filter_escape(replace_domain(mail));
#else
		escaped = filter_escape(mail);
#endif
		if (escaped == (char *)0) return 0;
		len = str_len(escaped);
		at = str_rchr(escaped, '@');
		if (escaped[at] != '@') {
			len = 0;
			return 0;
		}
		ext = at;
		extcnt = -1;
		*done = 0;
	} else {
		if (extcnt == 0) {
			*done = 1;
			return 0;
		}
#ifdef DASH_EXT
		/*
		 * limit ext to the first DASH_EXT_LEVELS extensions.
		 * We will only check for (DASH_EXT_LEVELS = 4):
		 * [email protected]
		 * [email protected]
		 * [email protected]
		 * [email protected]
		 * [email protected]
		 * [email protected]
		 */
		if (ext == at)
			for (i = 0, ext = 0, extcnt = 1;
			    ext < at && extcnt <= DASH_EXT_LEVELS; ext++)
				if (escaped[ext] == *auto_break) extcnt++;
		while (ext != 0 && --ext > 0) {
			if (escaped[ext] == *auto_break) break;
		}
		extcnt--;
#else
		/* basic qmail-ldap behavior test for [email protected] and
		   [email protected] */
		ext = 0;
		extcnt = 0;
#endif
	}
	
	/* build the search string for the email address */
	if (!stralloc_copys(&filter, "(|(" )) return 0;
	/* mail address */
	if (!stralloc_cats(&filter, LDAP_MAIL)) return 0;
	if (!stralloc_cats(&filter, "=")) return 0;
	/* username till current '-' */
	if (!stralloc_catb(&filter, escaped, ext)) return 0;
	if (ext != at) { /* do not append catchall in the first round */
		/* catchall or default */
		if (extcnt > 0) /* add '-' */
			if (!stralloc_cats(&filter, auto_break))
				return 0;
		if (!stralloc_cats(&filter, LDAP_CATCH_ALL)) return 0;
	}
	/* @damin.com */
	if (!stralloc_catb(&filter, escaped+at, len-at)) return 0;

	/* mailalternate address */
	if (!stralloc_cats(&filter, ")(")) return 0;
	if (!stralloc_cats(&filter, LDAP_MAILALTERNATE)) return 0;
	if (!stralloc_cats(&filter, "=")) return 0;
	/* username till current '-' */
	if (!stralloc_catb(&filter, escaped, ext)) return 0;
	if (ext != at) { /* do not append catchall in the first round */
		/* catchall or default */
		if (extcnt > 0) /* add '-' */
			if (!stralloc_cats(&filter, auto_break)) return 0;
		if (!stralloc_cats(&filter, LDAP_CATCH_ALL)) return 0;
	}
	/* @domain.com */
	if (!stralloc_catb(&filter, escaped+at, len-at)) return 0;
	if (!stralloc_cats(&filter, "))")) return 0;
	if (!stralloc_0(&filter)) return 0;

	if (extcnt == 0) *done = 1;
	return filter_objectclass(filter.s);
}