diff options
| author | manuel <manuel@mausz.at> | 2013-02-04 02:32:40 +0100 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2013-02-04 02:32:40 +0100 |
| commit | 8514473287c9594137c6fbc39f5619672ebc2430 (patch) | |
| tree | a5b965d8c7b60dee396bf8ebe25dd3eddfaa6753 /qregex.c | |
| parent | 35ddb916045abafaa4ae2c778b9383059fa06726 (diff) | |
| download | qmail-8514473287c9594137c6fbc39f5619672ebc2430.tar.gz qmail-8514473287c9594137c6fbc39f5619672ebc2430.tar.bz2 qmail-8514473287c9594137c6fbc39f5619672ebc2430.zip | |
[PATCH] qregex-starttls-2way-auth-20060423-mm
Diffstat (limited to 'qregex.c')
| -rw-r--r-- | qregex.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/qregex.c b/qregex.c new file mode 100644 index 0000000..59c0f76 --- /dev/null +++ b/qregex.c | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | /* | ||
| 2 | * qregex (v2) | ||
| 3 | * $Id: qregex.c,v 2.1 2001/12/28 07:05:21 evan Exp $ | ||
| 4 | * | ||
| 5 | * Author : Evan Borgstrom (evan at unixpimps dot org) | ||
| 6 | * Created : 2001/12/14 23:08:16 | ||
| 7 | * Modified: $Date: 2001/12/28 07:05:21 $ | ||
| 8 | * Revision: $Revision: 2.1 $ | ||
| 9 | * | ||
| 10 | * Do POSIX regex matching on addresses for anti-relay / spam control. | ||
| 11 | * It logs to the maillog | ||
| 12 | * See the qregex-readme file included with this tarball. | ||
| 13 | * If you didn't get this file in a tarball please see the following URL: | ||
| 14 | * http://www.unixpimps.org/software/qregex | ||
| 15 | * | ||
| 16 | * qregex.c is released under a BSD style copyright. | ||
| 17 | * See http://www.unixpimps.org/software/qregex/copyright.html | ||
| 18 | * | ||
| 19 | * Note: this revision follows the coding guidelines set forth by the rest of | ||
| 20 | * the qmail code and that described at the following URL. | ||
| 21 | * http://cr.yp.to/qmail/guarantee.html | ||
| 22 | * | ||
| 23 | */ | ||
| 24 | |||
| 25 | #include <sys/types.h> | ||
| 26 | #include <regex.h> | ||
| 27 | #include "qregex.h" | ||
| 28 | |||
| 29 | #define REGCOMP(X,Y) regcomp(&X, Y, REG_EXTENDED|REG_ICASE) | ||
| 30 | #define REGEXEC(X,Y) regexec(&X, Y, (size_t)0, (regmatch_t *)0, (int)0) | ||
| 31 | |||
| 32 | int matchregex(char *text, char *regex) { | ||
| 33 | regex_t qreg; | ||
| 34 | int retval = 0; | ||
| 35 | |||
| 36 | |||
| 37 | /* build the regex */ | ||
| 38 | if ((retval = REGCOMP(qreg, regex)) != 0) { | ||
| 39 | regfree(&qreg); | ||
| 40 | return(-retval); | ||
| 41 | } | ||
| 42 | |||
| 43 | /* execute the regex */ | ||
| 44 | if ((retval = REGEXEC(qreg, text)) != 0) { | ||
| 45 | /* did we just not match anything? */ | ||
| 46 | if (retval == REG_NOMATCH) { | ||
| 47 | regfree(&qreg); | ||
| 48 | return(0); | ||
| 49 | } | ||
| 50 | regfree(&qreg); | ||
| 51 | return(-retval); | ||
| 52 | } | ||
| 53 | |||
| 54 | /* signal the match */ | ||
| 55 | regfree(&qreg); | ||
| 56 | return(1); | ||
| 57 | } | ||
