head 1.6; access; symbols OPENPKG_E1_MP_HEAD:1.6 OPENPKG_E1_MP:1.6 OPENPKG_E1_MP_2_STABLE:1.6 OPENPKG_E1_FP:1.6 OPENPKG_2_STABLE_MP:1.6 OPENPKG_2_STABLE_20061018:1.6 OPENPKG_2_STABLE_20060622:1.6 OPENPKG_2_STABLE:1.6.0.8 OPENPKG_2_STABLE_BP:1.6 OPENPKG_2_5_RELEASE:1.6 OPENPKG_2_5_SOLID:1.6.0.6 OPENPKG_2_5_SOLID_BP:1.6 OPENPKG_2_4_RELEASE:1.6 OPENPKG_2_4_SOLID:1.6.0.4 OPENPKG_2_4_SOLID_BP:1.6 OPENPKG_CW_FP:1.6 OPENPKG_2_3_RELEASE:1.6 OPENPKG_2_3_SOLID:1.6.0.2 OPENPKG_2_3_SOLID_BP:1.6 OPENPKG_2_2_RELEASE:1.3 OPENPKG_2_2_SOLID:1.3.0.6 OPENPKG_2_2_SOLID_BP:1.3 OPENPKG_2_1_RELEASE:1.3 OPENPKG_2_1_SOLID:1.3.0.4 OPENPKG_2_1_SOLID_BP:1.3 OPENPKG_2_0_RELEASE:1.3 OPENPKG_2_0_SOLID:1.3.0.2 OPENPKG_2_0_SOLID_BP:1.3 OPENPKG_1_2_SOLID:1.1.0.4 OPENPKG_1_3_RELEASE:1.1.2.1 OPENPKG_1_3_SOLID:1.1.2.1.0.2 OPENPKG_1_3_SOLID_BP:1.1.2.1 OPENPKG_1_STABLE:1.1.0.2 OPENPKG_1_STABLE_MP:1.1; locks; strict; comment @# @; 1.6 date 2005.02.10.08.39.09; author rse; state Exp; branches; next 1.5; 1.5 date 2005.01.12.15.24.11; author ms; state Exp; branches; next 1.4; 1.4 date 2004.12.16.11.52.35; author ms; state Exp; branches; next 1.3; 1.3 date 2004.02.11.14.25.02; author thl; state Exp; branches; next 1.2; 1.2 date 2003.09.19.07.53.45; author rse; state Exp; branches; next 1.1; 1.1 date 2003.07.04.14.31.32; author rse; state Exp; branches 1.1.2.1 1.1.4.1; next ; 1.1.2.1 date 2003.07.24.20.50.36; author rse; state Exp; branches 1.1.2.1.2.1; next ; 1.1.2.1.2.1 date 2003.09.19.07.42.59; author rse; state Exp; branches; next ; 1.1.4.1 date 2003.09.19.07.46.43; author rse; state Exp; branches; next ; desc @@ 1.6 log @fix building under Solaris 10 (final release version) @ text @--- sendmail/conf.c.orig Tue Oct 16 11:24:13 2001 +++ sendmail/conf.c Wed Oct 17 18:49:33 2001 @@@@ -504,6 +504,12 @@@@ ndbm_map_lookup, ndbm_map_store); #endif /* NDBM */ +#if MYSQLMAP + MAPDEF("mysql", NULL, MCF_ALIASOK | MCF_NOTPERSIST, + mysql_map_parseargs, mysql_map_open, mysql_map_close, + mysql_map_lookup, null_map_store); +#endif + #if NIS MAPDEF("nis", NULL, MCF_ALIASOK, map_parseargs, nis_map_open, null_map_close, @@@@ -5675,6 +5681,9 @@@@ #if NDBM "NDBM", #endif /* NDBM */ +#if MYSQLMAP + "MYSQL", +#endif /* MYSQLMAP */ #if NETINET "NETINET", #endif /* NETINET */ --- sendmail/map.c.orig Tue Oct 16 11:22:26 2001 +++ sendmail/map.c Thu Oct 18 09:34:53 2001 @@@@ -1840,12 +1840,443 @@@@ } #endif /* NDBM */ + + /* -** NEWDB (Hash and BTree) Modules +* MySQL map class for Sendmail 8.12.x +* +* (c) 2001 Igmar Palsenberg +* JDI Media Solutions +* +* MySQL can be obtained from http://www.mysql.com +* +* This version is subject to the Sendmail license. Sendmail Inc. is NOT +* responsible for this code, they don't have anything to do with it, and +* don't support it. +* +* USE AT YOUR OWN RISK. NO WARRANTY OF ANY KIND IS PROVIDED. PLEASE +* READ THE INSTRUCTIONS FOR USE OF THIS PATCH BEFORE CONTACTING THE +* AUTHOR OR SENDMAIL, INC. NO SUPPORT OF ANY KIND WILL BE PROVIDED +* BY SENDMAIL, INC. FOR THIS PATCH. +* +* Please use the sendmail_mysql@@jdimedia.nl adress for questions, comments, +* remarks, etc, not my personal address. +* +* See http://projects.jdimedia.nl for a HOWTO on installing / using it. +* +*/ +#ifdef MYSQLMAP +#include + +struct mysql_conn { + char * host; + char * user; + char * passwd; + char * db; + int port; +}; + +static char * parse_opt_arg(char * in, char * option, char ** value) +{ + int len = strlen(in); + char * tmp; + + /* Skip whitespaces */ + while ((*in == ' ') || (*in == '\t') && (*in != '\0')) + in++; + if (*in == '\0') + return NULL; + + while ((*in != '-') && (*in != '"')) + in++; + + /* " is an error in this case */ + if (*in == '"') + return NULL; + + in++; + *option = *in; + in++; + + while ((*in == ' ') || (*in == '\t')) + in++; + + /* Not a " is an error */ + if (*in != '"') + return NULL; + in++; + + tmp = (char *) sm_malloc(sizeof(char) * len); + *value = tmp; + + while (*in != '"') + *tmp++ = *in++; + + /* Null terminate */ + *tmp = '\0'; + in++; + + return in; +} + +static char * parse_delim_arg(char * in, char delim, char ** key, char ** value) +{ + int len = strlen(in); + char * tmp; + + while ((*in == ' ') || (*in == '\t') && (*in != '\0')) + in++; + if (*in == '\0') + return NULL; + + /* Key */ + tmp = (char *) sm_malloc(sizeof(char) * len); + + *key = tmp; + + while ((*in != delim) && (*in != '\0') && (*in != ' ') && (*in != '\t')) + *tmp++ = *in++; + + if ((*in != delim) ) { + free(*key); + return NULL; + } + *tmp = '\0'; + in++; + + /* Value */ + tmp = (char *) sm_malloc(sizeof(char) * len); + *value = tmp; + + while ((*in != '\0') && (*in != ' ') && (*in != '\t')) + *tmp++ = *in++; + *tmp = '\0'; + + return in; +} + + +/* +* Parse MYSQL map definitions. I call it an ugly hack :) +* +* return false if failed, true if succeeded +* +* Copied from the sendmail generic map_parseargs() code */ +bool +mysql_map_parseargs(map, args) + MAP * map; + char * args; +{ + char *p = args; + char option; + char * value; -#if NEWDB + map->map_mflags |= MF_TRY0NULL|MF_TRY1NULL; + map->map_spacesub = SpaceSub; /* default value */ + while (p) + { + p = parse_opt_arg(p, &option, &value); + if (!p) + break; + switch (option) + { + case 'N': /* Append NULL byte to all keys */ + map->map_mflags |= MF_INCLNULL; + map->map_mflags &= ~MF_TRY0NULL; + break; + + case 'O': /* Adaptive versus never add NULL */ + map->map_mflags &= ~MF_TRY1NULL; + break; + + case 'o': /* Database file is optional */ + map->map_mflags |= MF_OPTIONAL; + break; + + case 'f': /* Don't fold keys to lowercase */ + map->map_mflags |= MF_NOFOLDCASE; + break; + + case 'm': /* Supress replacement on match */ + map->map_mflags |= MF_MATCHONLY; + break; + + case 'A': /* Append values for duplicate keys */ + map->map_mflags |= MF_APPEND; + break; + + case 'q': /* Don't strip quotes */ + map->map_mflags |= MF_KEEPQUOTES; + break; + + case 'a': /* Append tag on successful match */ + map->map_app = value; + value = NULL; + break; + + case 'T': /* No idea */ + map->map_tapp = value; + value = NULL; + break; + + case 'k': /* No idea */ + map->map_keycolnm = value; + value = NULL; + break; + + case 'v': /* Specify the value's column */ + map->map_valcolnm = value; + value = NULL; + break; + + case 'z': /* Column delimiter */ + if (value[0] != '\\') + map->map_coldelim = value[0]; + else + { + switch (value[1]) + { + case 'n': + map->map_coldelim = '\n'; + break; + + case 't': + map->map_coldelim = '\t'; + break; + + default: + map->map_coldelim = '\\'; + } + } + break; + + case 't': /* No idea */ + map->map_mflags |= MF_NODEFER; + break; + + + case 'S': /* No idea */ + map->map_spacesub = value[0]; + break; + + case 'D': /* No idea, I need updated docs :( */ + map->map_mflags |= MF_DEFER; + break; + + case 'c': + map->map_keycolnm = value; + value = NULL; + break; + + case 's': + map->map_valcolnm = value; + value = NULL; + break; + + default: + syserr("mysql_map_parse_args : illegal option %c map `%s'", *p, map->map_mname); + break; + } + if (value) + sm_free(value); + } + if (map->map_keycolnm == NULL) { + syserr("mysql_map_parse_args : no connect string for MySQL map `%s'", map->map_mname); + return false; + } + + if (map->map_valcolnm == NULL) { + syserr("mysql_map_parse_args : no select statement for MySQL map `%s'", map->map_mname); + return false; + } + + return true; +} + +static bool +mysql_map_parse_connect(char * cs, struct mysql_conn * conn, MAP * map) +{ + char * p; + char * key, * value; + char * endptr; + + p = cs; + + memset(conn, '\0', sizeof(struct mysql_conn)); + while (p) { + p = parse_delim_arg(p, '=', &key, &value); + if (!p) + continue; + if (strcmp(key, "host") == 0) { + conn->host = value; + } else if (strcmp(key, "user") == 0) { + conn->user = value; + } else if (strcmp(key, "passwd") == 0) { + conn->passwd = value; + } else if (strcmp(key, "db") == 0) { + conn->db = value; + } else if (strcmp(key, "port") == 0) { + conn->port = (int) strtoul(value, &endptr, 10); + if (*endptr != '\0') + conn->port = 0; + sm_free(value); + } else { + syserr("mysql_map_parse_connect : illegal MySQL option %s map `%s'", key, map->map_mname); + } + sm_free(key); + } + + if ((conn->host == NULL) || (conn->user == NULL) || (conn->passwd == NULL)) + return false; + + return true; +} + +static void mysql_map_free_conn(struct mysql_conn * conn) +{ + if (conn->host) + sm_free(conn->host); + if (conn->user) + sm_free(conn->user); + if (conn->passwd) + sm_free(conn->passwd); + if (conn->db) + sm_free(conn->db); +} + +/* +* Open connection to the MySQL server +* +* returns true if all where OK, false if something went wrong +* +*/ +bool +mysql_map_open(map, mode) + MAP * map; + int mode; +{ + MYSQL * mysql; + struct mysql_conn conn; + + /* Make sure newaliases doesn't rebuild it */ + mode &= O_ACCMODE; + + if (mode != O_RDONLY) { + errno = EPERM; + return false; + } + + mysql = mysql_init(NULL); + + if (mysql_map_parse_connect(map->map_keycolnm, &conn, map) == false) { + syserr("mysql_map_open : cannot parse map arguments %s for map `%s'", map->map_keycolnm, map->map_mname); + mysql_map_free_conn(&conn); + return false; + } + + if (!mysql_real_connect(mysql, conn.host, conn.user, conn.passwd, conn.db, conn.port, NULL, 0)) { + mysql_map_free_conn(&conn); + syserr("mysql_map_open : cannot open a MySQL connection for map `%s' : %s", map->map_mname, mysql_error(mysql)); + return false; + } + mysql_map_free_conn(&conn); + map->map_db1 = (ARBPTR_T) mysql; + map->map_pid = getpid(); + + return true; +} + +/* +* Close connection to the MYSQL database +* +* +*/ +void +mysql_map_close(map) + MAP * map; +{ + if (map->map_pid == getpid()) + mysql_close(map->map_db1); +} + +/* +* +* Do a map look up. +* +* Returns value that comes with the key +* +*/ +char * +mysql_map_lookup(map, name, av, statp) + MAP * map; + char * name; + char ** av; + int * statp; +{ + MYSQL * mysql = (MYSQL *) map->map_db1; + MYSQL_RES * result; + MYSQL_ROW row; + char * query; + char * tmp; + int len; + + len = strlen(name) + strlen(map->map_valcolnm) + 5; + if (len > MAXNAME) + return NULL; + + tmp = (char *) sm_malloc(strlen(name) + 1); + strncpy(tmp, name, strlen(name) + 1); + + if (!bitset(MF_NOFOLDCASE, map->map_mflags)) + makelower(tmp); + + query = (char *) sm_malloc(sizeof(char) * len); + /* Create query */ + snprintf(query, len, map->map_valcolnm, tmp); + + sm_free(tmp); + + /* Query and retreive rows */ + if (mysql_real_query(mysql, query, strlen(query))) { + syserr("mysql_map_lookup : query %s : %s", query, mysql_error(mysql)); + sm_free(query); + return NULL; + } + + result = mysql_store_result(mysql); + if (result == NULL) { + syserr("mysql_map_lookup : store result : %s", mysql_error(mysql)); + sm_free(query); + return NULL; + } + + /* 0 rows == no result */ + if (mysql_num_rows(result) == 0) { + sm_free(query); + return NULL; + } + + row = mysql_fetch_row(result); + if (row[0] == NULL || strlen(row[0]) == 0) { + sm_free(query); + mysql_free_result(result); + return NULL; + } + + if (bitset(MF_MATCHONLY, map->map_mflags)) + return map_rewrite(map, name, strlen(name), NULL); + else + return map_rewrite(map, row[0], strlen(row[0]), av); +} +#endif /* MYSQLMAP */ + + +/* +** NEWDB (Hash and BTree) Modules +*/ +#if NEWDB /* ** BT_MAP_OPEN, HASH_MAP_OPEN -- database open primitives. ** @ 1.5 log @upgrading package: sendmail 8.13.2 -> 8.13.3 @ text @a473 11 --- include/sm/conf.h.orig 2004-02-11 13:58:36.443953000 +0100 +++ include/sm/conf.h 2004-02-11 15:15:07.077087000 +0100 @@@@ -448,7 +448,7 @@@@ # define HASFDWALK 1 /* fdwalk(3c) added in S9 */ # endif /* SOLARIS >= 20900 || (SOLARIS < 10000 && SOLARIS >= 209) */ # if SOLARIS >= 21000 || (SOLARIS < 10000 && SOLARIS >= 210) -# define HASUNSETENV 1 /* unsetenv() added in S10 */ +# define HASUNSETENV 0 /* unsetenv() added in S10 but not yet available in our S10beta */ # endif /* SOLARIS >= 21000 || (SOLARIS < 10000 && SOLARIS >= 210) */ # ifndef HASGETUSERSHELL # define HASGETUSERSHELL 0 /* getusershell(3) causes core dumps pre-2.7 */ @ 1.4 log @upgrading package: sendmail 8.13.1 -> 8.13.2 @ text @a31 2 -/* -** NEWDB (Hash and BTree) Modules d34 2 a35 1 +/* d253 1 a253 1 d298 1 a298 1 + a473 1 d476 2 a477 2 @@@@ -446,7 +446,7 @@@@ # define HASURANDOMDEV 1 /* /dev/[u]random added in S9 */ a484 1 @ 1.3 log @unsetenv() will be added in Solaris 10 but is not yet available in our Solaris 10beta @ text @d3 1 a3 1 @@@@ -470,6 +470,12 @@@@ d16 1 a16 1 @@@@ -5381,6 +5387,9 @@@@ d28 1 a28 1 @@@@ -1822,12 +1822,443 @@@@ @ 1.2 log @simplify packaging by reducing the number of required subshells @ text @d475 13 @ 1.1 log @rename patch file and apply it unconditionally because it is #ifdef'ed anyway (and this way it later can be converted to %patch more easily @ text @d1 2 a2 2 --- sendmail-8.12.0/sendmail/conf.c.orig Tue Oct 16 11:24:13 2001 +++ sendmail-8.12.0/sendmail/conf.c Wed Oct 17 18:49:33 2001 d26 2 a27 2 --- sendmail-8.12.0/sendmail/map.c.orig Tue Oct 16 11:22:26 2001 +++ sendmail-8.12.0/sendmail/map.c Thu Oct 18 09:34:53 2001 @ 1.1.4.1 log @apply security bugfixes (CAN-2003-0694 & CAN-2003-0681) @ text @d1 5 a5 26 Security bugfixes: http://www.sendmail.org/8.12.10.html http://cve.mitre.org/cgi-bin/cvename.cgi?name=CAN-2003-0694 http://cve.mitre.org/cgi-bin/cvename.cgi?name=CAN-2003-0681 Index: sendmail/parseaddr.c --- sendmail/parseaddr.c.orig 2003-03-27 03:39:53.000000000 +0100 +++ sendmail/parseaddr.c 2003-09-19 09:11:01.000000000 +0200 @@@@ -700,7 +700,11 @@@@ addr[MAXNAME] = '\0'; returnnull: if (delimptr != NULL) + { + if (p > addr) + p--; *delimptr = p; + } CurEnv->e_to = saveto; return NULL; } @@@@ -1000,6 +1004,8 @@@@ } if (pvp == NULL) return EX_USAGE; + if (maxatom <= 0) + return EX_USAGE; d7 23 a29 13 /* ** Run through the list of rewrite rules, applying @@@@ -1866,6 +1872,7 @@@@ register ENVELOPE *e; { bool tempfail = false; + int maxatom; struct mailer **mp; register struct mailer *m; register char *p; @@@@ -1880,6 +1887,7 @@@@ printav(tv); } d31 134 a164 9 + maxatom = MAXATOM; if (a == NULL) a = (ADDRESS *) sm_rpool_malloc_x(e->e_rpool, sizeof *a); memset((char *) a, '\0', sizeof *a); @@@@ -1919,14 +1927,22 @@@@ return a; } mname = *++tv; + --maxatom; d166 4 a169 2 /* extract host and user portions */ if (*++tv != NULL && (**tv & 0377) == CANONHOST) d171 204 a374 2 hostp = ++tv; + --maxatom; d376 82 a457 7 else hostp = NULL; + --maxatom; while (*tv != NULL && (**tv & 0377) != CANONUSER) + { tv++; + --maxatom; d459 16 a474 34 if (*tv == NULL) { syserr("554 5.3.5 buildaddr: no user"); @@@@ -1937,6 +1953,7 @@@@ else if (hostp != NULL) cataddr(hostp, tv - 1, hbuf, sizeof hbuf, '\0'); cataddr(++tv, NULL, ubuf, sizeof ubuf, ' '); + --maxatom; /* save away the host name */ if (sm_strcasecmp(mname, "error") == 0) @@@@ -2041,6 +2058,7 @@@@ { p++; tv++; + --maxatom; a->q_flags |= QNOTREMOTE; } @@@@ -2071,11 +2089,11 @@@@ !bitset(RF_SENDERADDR|RF_HEADERADDR, flags)) { /* sender addresses done later */ - (void) REWRITE(tv, 2, e); + (void) rewrite(tv, 2, 0, e, maxatom); if (m->m_re_rwset > 0) - (void) REWRITE(tv, m->m_re_rwset, e); + (void) rewrite(tv, m->m_re_rwset, 0, e, maxatom); } - (void) REWRITE(tv, 4, e); + (void) rewrite(tv, 4, 0, e, maxatom); /* save the result for the command line/RCPT argument */ cataddr(tv, NULL, ubuf, sizeof ubuf, '\0'); @ 1.1.2.1 log @mass Merge-From-CURRENT (MFC) in preparation for OpenPKG 1.3 [class PLUS only] @ text @@ 1.1.2.1.2.1 log @apply security bugfixes (CAN-2003-0694 & CAN-2003-0681) plus the sed(1) portability fix from CURRENT @ text @d1 2 a2 2 --- sendmail/conf.c.orig Tue Oct 16 11:24:13 2001 +++ sendmail/conf.c Wed Oct 17 18:49:33 2001 d26 2 a27 2 --- sendmail/map.c.orig Tue Oct 16 11:22:26 2001 +++ sendmail/map.c Thu Oct 18 09:34:53 2001 a474 102 ============================================================================== Security bugfixes: http://www.sendmail.org/8.12.10.html http://cve.mitre.org/cgi-bin/cvename.cgi?name=CAN-2003-0694 http://cve.mitre.org/cgi-bin/cvename.cgi?name=CAN-2003-0681 Index: sendmail/parseaddr.c --- sendmail/parseaddr.c.orig 2003-03-27 03:39:53.000000000 +0100 +++ sendmail/parseaddr.c 2003-09-19 09:11:01.000000000 +0200 @@@@ -700,7 +700,11 @@@@ addr[MAXNAME] = '\0'; returnnull: if (delimptr != NULL) + { + if (p > addr) + p--; *delimptr = p; + } CurEnv->e_to = saveto; return NULL; } @@@@ -1000,6 +1004,8 @@@@ } if (pvp == NULL) return EX_USAGE; + if (maxatom <= 0) + return EX_USAGE; /* ** Run through the list of rewrite rules, applying @@@@ -1866,6 +1872,7 @@@@ register ENVELOPE *e; { bool tempfail = false; + int maxatom; struct mailer **mp; register struct mailer *m; register char *p; @@@@ -1880,6 +1887,7 @@@@ printav(tv); } + maxatom = MAXATOM; if (a == NULL) a = (ADDRESS *) sm_rpool_malloc_x(e->e_rpool, sizeof *a); memset((char *) a, '\0', sizeof *a); @@@@ -1919,14 +1927,22 @@@@ return a; } mname = *++tv; + --maxatom; /* extract host and user portions */ if (*++tv != NULL && (**tv & 0377) == CANONHOST) + { hostp = ++tv; + --maxatom; + } else hostp = NULL; + --maxatom; while (*tv != NULL && (**tv & 0377) != CANONUSER) + { tv++; + --maxatom; + } if (*tv == NULL) { syserr("554 5.3.5 buildaddr: no user"); @@@@ -1937,6 +1953,7 @@@@ else if (hostp != NULL) cataddr(hostp, tv - 1, hbuf, sizeof hbuf, '\0'); cataddr(++tv, NULL, ubuf, sizeof ubuf, ' '); + --maxatom; /* save away the host name */ if (sm_strcasecmp(mname, "error") == 0) @@@@ -2041,6 +2058,7 @@@@ { p++; tv++; + --maxatom; a->q_flags |= QNOTREMOTE; } @@@@ -2071,11 +2089,11 @@@@ !bitset(RF_SENDERADDR|RF_HEADERADDR, flags)) { /* sender addresses done later */ - (void) REWRITE(tv, 2, e); + (void) rewrite(tv, 2, 0, e, maxatom); if (m->m_re_rwset > 0) - (void) REWRITE(tv, m->m_re_rwset, e); + (void) rewrite(tv, m->m_re_rwset, 0, e, maxatom); } - (void) REWRITE(tv, 4, e); + (void) rewrite(tv, 4, 0, e, maxatom); /* save the result for the command line/RCPT argument */ cataddr(tv, NULL, ubuf, sizeof ubuf, '\0'); @