[bitlbee/el5/master: 3/4] New patch for libresolv on EPEL.
Matej Cepl
mcepl at fedoraproject.org
Mon Dec 27 12:36:02 UTC 2010
commit d4fdeeab6793f7e76f26435fd2e50b8facd76d70
Author: Matěj Cepl <mcepl at redhat.com>
Date: Mon Dec 27 13:18:28 2010 +0100
New patch for libresolv on EPEL.
bitlbee-libresolv.patch | 529 ++++++++++++++++-------------------------------
bitlbee.spec | 5 +-
2 files changed, 187 insertions(+), 347 deletions(-)
---
diff --git a/bitlbee-libresolv.patch b/bitlbee-libresolv.patch
index e38171c..356780f 100644
--- a/bitlbee-libresolv.patch
+++ b/bitlbee-libresolv.patch
@@ -1,7 +1,8 @@
-diff -up bitlbee-3.0/configure.libresolv bitlbee-3.0/configure
---- bitlbee-3.0/configure.libresolv 2010-11-22 02:38:33.000000000 +0100
-+++ bitlbee-3.0/configure 2010-11-22 02:38:33.000000000 +0100
-@@ -348,10 +349,10 @@ detect_resolv_static()
+diff --git a/configure b/configure
+index edc4adb..1b1336d 100755
+--- a/configure
++++ b/configure
+@@ -349,10 +349,10 @@ detect_resolv_static()
TMPFILE=$(mktemp /tmp/bitlbee-configure.XXXXXX)
ret=1
for i in $systemlibdirs; do
@@ -14,30 +15,57 @@ diff -up bitlbee-3.0/configure.libresolv bitlbee-3.0/configure
ret=0
fi
fi
-diff -up bitlbee-3.0/lib/Makefile.libresolv bitlbee-3.0/lib/Makefile
---- bitlbee-3.0/lib/Makefile.libresolv 2010-10-22 02:51:31.000000000 +0200
-+++ bitlbee-3.0/lib/Makefile 2010-11-22 02:38:33.000000000 +0100
-@@ -12,7 +12,7 @@ SRCDIR := $(SRCDIR)lib/
- endif
+diff --git a/lib/misc.c b/lib/misc.c
+index 05192d9..556fe1a 100644
+--- a/lib/misc.c
++++ b/lib/misc.c
+@@ -1,8 +1,8 @@
+- /********************************************************************\
+- * BitlBee -- An IRC to other IM-networks gateway *
+- * *
+- * Copyright 2002-2006 Wilmer van der Gaast and others *
+- \********************************************************************/
++/********************************************************************\
++* BitlBee -- An IRC to other IM-networks gateway *
++* *
++* Copyright 2002-2006 Wilmer van der Gaast and others *
++\********************************************************************/
- # [SH] Program variables
--objects = arc.o base64.o $(DES) $(EVENT_HANDLER) ftutil.o http_client.o ini.o md5.o misc.o oauth.o proxy.o sha1.o $(SSL_CLIENT) url.o xmltree.o
-+objects = arc.o base64.o $(DES) $(EVENT_HANDLER) ftutil.o http_client.o ini.o md5.o misc.o oauth.o proxy.o sha1.o srv.o $(SSL_CLIENT) url.o xmltree.o
+ /*
+ * Various utility functions. Some are copied from Gaim to support the
+@@ -30,6 +30,12 @@
+ Suite 330, Boston, MA 02111-1307 USA
+ */
- LFLAGS += -r
++#undef TEST
++
++#ifdef TEST
++#define HAVE_RESOLV_A
++#endif
++
+ #define BITLBEE_CORE
+ #include "nogaim.h"
+ #include "base64.h"
+@@ -42,13 +48,17 @@
+ #include <time.h>
-diff -up bitlbee-3.0/lib/misc.c.libresolv bitlbee-3.0/lib/misc.c
---- bitlbee-3.0/lib/misc.c.libresolv 2010-10-22 02:51:31.000000000 +0200
-+++ bitlbee-3.0/lib/misc.c 2010-11-22 02:38:33.000000000 +0100
-@@ -44,6 +44,7 @@
#ifdef HAVE_RESOLV_A
- #include <arpa/nameser.h>
+-#include <arpa/nameser.h>
#include <resolv.h>
-+#include <netinet/in.h>
#endif
#include "md5.h"
-@@ -514,66 +515,6 @@ int bool2int( char *value )
+ #include "ssl_client.h"
+
++/* Not every installation has gotten around to supporting SRVs yet...*/
++#ifndef T_SRV
++#define T_SRV 33
++#endif
++
+ void strip_linefeed(gchar *text)
+ {
+ int i, j;
+@@ -514,66 +524,6 @@ int bool2int( char *value )
return 0;
}
@@ -104,337 +132,146 @@ diff -up bitlbee-3.0/lib/misc.c.libresolv bitlbee-3.0/lib/misc.c
void srv_free( struct ns_srv_reply **srv )
{
int i;
-diff -up bitlbee-3.0/lib/misc.h.libresolv bitlbee-3.0/lib/misc.h
---- bitlbee-3.0/lib/misc.h.libresolv 2010-10-22 02:51:31.000000000 +0200
-+++ bitlbee-3.0/lib/misc.h 2010-11-22 02:39:51.000000000 +0100
-@@ -28,14 +28,7 @@
-
- #include <gmodule.h>
- #include <time.h>
--
--struct ns_srv_reply
--{
-- int prio;
-- int weight;
-- int port;
-- char name[];
--};
-+#include "srv.h"
-
- G_MODULE_EXPORT void strip_linefeed( gchar *text );
- G_MODULE_EXPORT char *add_cr( char *text );
-@@ -60,7 +53,6 @@ G_MODULE_EXPORT void random_bytes( unsig
- G_MODULE_EXPORT int is_bool( char *value );
- G_MODULE_EXPORT int bool2int( char *value );
-
--G_MODULE_EXPORT struct ns_srv_reply **srv_lookup( char *service, char *protocol, char *domain );
- G_MODULE_EXPORT void srv_free( struct ns_srv_reply **srv );
+@@ -586,6 +536,119 @@ void srv_free( struct ns_srv_reply **srv )
+ g_free( srv );
+ }
- G_MODULE_EXPORT char *word_wrap( const char *msg, int line_len );
-diff -up /dev/null bitlbee-3.0/lib/srv.c
---- /dev/null 2010-11-21 23:39:22.000456625 +0100
-+++ bitlbee-3.0/lib/srv.c 2010-11-22 02:38:33.000000000 +0100
-@@ -0,0 +1,249 @@
-+/* srv.c - DNS SRV code
-+ * Copyright (C) 2003 Free Software Foundation, Inc.
-+ *
-+ * This file is part of GNUPG.
-+ *
-+ * GNUPG is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation; either version 3 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * GNUPG is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
-+ */
-+
-+#undef TEST
-+
-+#ifdef TEST
-+#define HAVE_RESOLV_A
-+#endif
-+
-+#include <config.h>
-+#include <sys/types.h>
-+
-+#include <unistd.h>
-+#include <stdlib.h>
-+#include <string.h>
-+#include <time.h>
-+
-+#ifdef HAVE_RESOLV_A
-+# ifdef _WIN32
-+# include <windows.h>
-+# else
-+# include <netinet/in.h>
-+# include <arpa/nameser.h>
-+# include <resolv.h>
-+# endif /* !_WIN32 */
-+#endif /* USE_DNS_SRV */
-+
-+#include "srv.h"
-+#include <glib.h>
-+#include <glib/gprintf.h>
-+#include <glib/gutils.h>
-+
-+/* Not every installation has gotten around to supporting SRVs yet...*/
-+#ifndef T_SRV
-+#define T_SRV 33
-+#endif
-+
-+static int priosort(const void *a, const void *b) {
-+ const struct ns_srv_reply *sa=a, *sb=b;
-+ if (sa->prio>sb->prio)
-+ return 1;
-+ else if (sa->prio<sb->prio)
-+ return -1;
-+ else
-+ return 0;
++static int srv_compare(const void *a, const void *b) {
++ int prio;
++ const struct ns_srv_reply *sa = *(struct ns_srv_reply **) a;
++ const struct ns_srv_reply *sb = *(struct ns_srv_reply **) b;
++
++ prio = sa->prio - sb->prio;
++ if (prio == 0) {
++ /* Place weight 0 entries first. */
++ if (sa->weight == 0) return -1;
++ if (sb->weight == 0) return 1;
++ }
++
++ return prio;
+}
+
-+struct ns_srv_reply *srv_lookup(char *service, char *protocol, char *domain) {
-+ struct ns_srv_reply *reply = NULL;
-+ struct ns_srv_reply *list = NULL;
-+ char name[1024];
-+#ifdef HAVE_RESOLV_A
-+ unsigned char answer[PACKETSZ];
-+ int r, srvcount=0;
-+ unsigned char *pt, *emsg;
-+ int count, dlen;
-+
-+ g_snprintf(name, sizeof(name ), "_%s._%s.%s", service, protocol, domain);
-+
-+ _res.options |= RES_DEBUG;
-+
-+ if ( res_init() != 0 )
-+ return NULL;
-+
-+ r=res_query(name, C_IN, T_SRV, answer, PACKETSZ);
-+
-+ if (r<sizeof(HEADER) || r>PACKETSZ)
-+ return NULL;
-+
-+ if ((((HEADER *)answer)->rcode)==NOERROR && (count=ntohs(((HEADER *)answer)->ancount))) {
-+ int i, rc;
-+
-+ emsg=&answer[r]; /* end of message ??? */
-+ pt=&answer[sizeof(HEADER)];
-+
-+ /* Skip over the query */
-+ rc=dn_skipname(pt, emsg);
-+ if (rc==-1)
-+ goto fail;
-+
-+ pt+=rc+QFIXEDSZ;
-+
-+ while (count-->0 && pt<emsg) {
-+ struct ns_srv_reply *srv=NULL;
-+ int type, class;
-+
-+ list=g_realloc(list, (srvcount+1)*sizeof(struct ns_srv_reply));
-+ memset(&list[srvcount], 0, sizeof(struct ns_srv_reply));
-+ srv=&list[srvcount];
-+ srvcount++;
-+
-+ rc=dn_skipname(pt, emsg); /* the name we just queried for */
-+ if (rc==-1)
-+ goto fail;
-+ pt+=rc;
-+
-+ /* Truncated message? */
-+ if ((emsg-pt)<16)
-+ goto fail;
-+
-+ type=*pt++ << 8;
-+ type|=*pt++;
-+ /* We asked for SRV and got something else !? */
-+ if (type!=T_SRV)
-+ goto fail;
-+
-+ class=*pt++ << 8;
-+ class|=*pt++;
-+ /* We asked for IN and got something else !? */
-+ if (class!=C_IN)
-+ goto fail;
-+
-+ pt+=4; /* ttl */
-+ dlen=*pt++ << 8;
-+ dlen|=*pt++;
-+ srv->prio=*pt++ << 8;
-+ srv->prio|=*pt++;
-+ srv->weight=*pt++ << 8;
-+ srv->weight|=*pt++;
-+ srv->port=*pt++ << 8;
-+ srv->port|=*pt++;
-+
-+ /* Get the name. 2782 doesn't allow name compression, but
-+ dn_expand still works to pull the name out of the
-+ packet. */
-+ rc=dn_expand(answer, emsg, pt, srv->name, MAXDNAME);
-+ if (rc==1 && srv->name[0]==0) /* "." */
-+ goto noanswer;
-+ if (rc==-1)
-+ goto fail;
-+ pt+=rc;
-+ /* Corrupt packet? */
-+ if (dlen!=rc+6)
-+ goto fail;
-+ }
-+
-+ /* Now we have an array of all the srv records. */
-+
-+ /* Order by priority */
-+ qsort(list, srvcount, sizeof(struct ns_srv_reply), priosort);
-+
-+ /* For each priority, move the zero-weighted items first. */
-+ for (i=0; i<srvcount; i++) {
-+ int j;
-+
-+ for (j=i; j<srvcount && list[i].prio==list[j].prio; j++) {
-+ if (list[j].weight==0) {
-+ /* Swap j with i */
-+ if (j!=i) {
-+ struct ns_srv_reply temp;
-+
-+ memcpy(&temp, &list[j], sizeof(struct ns_srv_reply));
-+ memcpy(&list[j], &list[i], sizeof(struct ns_srv_reply));
-+ memcpy(&list[i], &temp, sizeof(struct ns_srv_reply));
-+ }
-+
-+ break;
-+ }
-+ }
-+ }
-+
-+ /* Run the RFC-2782 weighting algorithm. We don't need very
-+ high quality randomness for this, so regular libc srand/rand
-+ is sufficient. */
-+ srand(time(NULL)*getpid());
-+
-+ for (i=0; i<srvcount; i++) {
-+ int j;
-+ float prio_count=0, chose;
-+
-+ for (j=i; j<srvcount && list[i].prio==list[j].prio; j++) {
-+ prio_count+=list[j].weight;
-+ list[j].run_count=prio_count;
-+ }
-+
-+ chose=prio_count*rand()/RAND_MAX;
-+
-+ for (j=i; j<srvcount && list[i].prio==list[j].prio; j++) {
-+ if (chose<=list[j].run_count) {
-+ /* Swap j with i */
-+ if (j!=i) {
-+ struct ns_srv_reply temp;
-+
-+ memcpy(&temp, &list[j], sizeof(struct ns_srv_reply));
-+ memcpy(&list[j], &list[i], sizeof(struct ns_srv_reply));
-+ memcpy(&list[i], &temp, sizeof(struct ns_srv_reply));
-+ }
-+ break;
-+ }
-+ }
-+ }
-+ }
-+
-+ if (list == NULL)
-+ return NULL;
-+
-+ /* TODO: bitlbee should expect a situation when more than one server
-+ * is available for the given SRV record.
-+ */
-+ reply = g_malloc(sizeof(struct ns_srv_reply));
-+ *reply = *list;
-+ g_free(list);
-+ /* list=NULL; */
-+#endif /* HAVE_RESOLV_A */
-+ return reply;
-+
-+ noanswer: g_free(list);
-+ list=NULL;
-+ return NULL;
-+
-+ fail: g_free(list);
-+ list=NULL;
-+ return NULL;
++struct ns_srv_reply **srv_lookup(char *service, char *protocol, char *domain) {
++ struct ns_srv_reply **results = NULL;
++ struct ns_srv_reply *reply = NULL;
++ char name[1024];
++
++ /* PACKETSZ is a maximum packet size and
++ defined in arpa/nameser_compat.h as 512 */
++ unsigned char answer[PACKETSZ];
++ int len;
++ HEADER *header;
++ unsigned char *p;
++ unsigned char *end;
++ unsigned int count;
++ size_t n;
++
++ uint16_t type;
++ uint16_t class;
++ uint32_t ttl;
++ uint16_t rdlength;
++
++ g_snprintf(name, sizeof(name), "_%s._%s.%s", service, protocol, domain);
++
++ len = res_query(name, C_IN, T_SRV, answer, PACKETSZ);
++ if (len == -1) {
++ goto fail;
++ }
++
++ header = (HEADER *) answer;
++ p = answer + sizeof(HEADER);
++ end = answer + len;
++
++ if (header->rcode != NOERROR) {
++ goto fail;
++ }
++
++ len = dn_skipname(p, end);
++ if (len == -1) {
++ goto fail;
++ }
++ p += len + QFIXEDSZ;
++
++ count = ntohs(header->ancount);
++
++ results = g_new(struct ns_srv_reply *, count + 1);
++
++ n = 0;
++ while (count-- > 0 && p < end) {
++ len = dn_skipname(p, end);
++ if (len == -1) {
++ goto fail;
++ }
++ p += len;
++
++ GETSHORT(type, p);
++ GETSHORT(class, p);
++ GETLONG(ttl, p);
++ GETSHORT(rdlength, p);
++
++ if (type != T_SRV || class != C_IN) {
++ p += rdlength;
++ continue;
++ }
++
++ /* This is an overestimate of the needed size. */
++ reply = g_malloc(sizeof(struct ns_srv_reply) + rdlength + 1);
++
++ GETSHORT(reply->prio, p);
++ GETSHORT(reply->weight, p);
++ GETSHORT(reply->port, p);
++
++ len = dn_expand(answer, end, p, reply->name, rdlength + 1);
++ if (len == -1) {
++ g_free(reply);
++ goto fail;
++ }
++ p += len;
++
++ results[n++] = reply;
++ }
++
++ results[n] = NULL;
++
++ /* Order by priority. */
++ qsort(results, n, sizeof(struct ns_srv_reply *), srv_compare);
++
++ return results;
++
++fail:
++ if (results) {
++ while (n-- > 0) {
++ g_free(results[n]);
++ }
++ g_free(results);
++ }
++
++ return NULL;
+}
+
-+#ifdef TEST
-+int main(int argc, char *argv[]) {
-+ struct ns_srv_reply *srv;
-+ /*int rc,i;*/
-+
-+ srv=srv_lookup("xmpp-client", "tcp", "jabber.org");
-+ if (srv != NULL) {
-+ printf("priority=%hu\n", srv->prio);
-+ printf("weight=%hu\n", srv->weight);
-+ printf("port=%hu\n", srv->port);
-+ printf("target=%s\n", srv->name);
-+ printf("\n");
-+ g_free(srv);
-+ }
+ /* Word wrapping. Yes, I know this isn't UTF-8 clean. I'm willing to take the risk. */
+ char *word_wrap( const char *msg, int line_len )
+ {
+@@ -728,3 +791,22 @@ char **split_command_parts( char *command )
+
+ return cmd;
+ }
+
-+ return 0;
++#ifdef TEST
++int main() {
++ struct ns_srv_reply **srv;
++ int i;
++
++ srv = srv_lookup("xmpp-client", "tcp", "jabber.org");
++ for (i = 0; srv[i]; ++i) {
++ printf("priority=%hu\n", srv[i]->prio);
++ printf("weight=%hu\n", srv[i]->weight);
++ printf("port=%hu\n", srv[i]->port);
++ printf("target=%s\n", srv[i]->name);
++ printf("\n");
++ }
++ srv_free(srv);
++
++ return 0;
+}
+#endif /* TEST */
-diff -up /dev/null bitlbee-3.0/lib/srv.h
---- /dev/null 2010-11-21 23:39:22.000456625 +0100
-+++ bitlbee-3.0/lib/srv.h 2010-11-22 02:38:33.000000000 +0100
-@@ -0,0 +1,38 @@
-+/* srv.h
-+ * Copyright (C) 2003, 2004 Free Software Foundation, Inc.
-+ *
-+ * This file is part of GNUPG.
-+ *
-+ * GNUPG is free software; you can redistribute it and/or modify
-+ * it under the terms of the GNU General Public License as published by
-+ * the Free Software Foundation; either version 3 of the License, or
-+ * (at your option) any later version.
-+ *
-+ * GNUPG is distributed in the hope that it will be useful,
-+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
-+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+ * GNU General Public License for more details.
-+ *
-+ * You should have received a copy of the GNU General Public License
-+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
-+ */
-+
-+#ifndef GNUPG_COMMON_SRV_H
-+#define GNUPG_COMMON_SRV_H
-+
-+#ifndef MAXDNAME
-+#define MAXDNAME 1025
-+#endif
-+
-+struct ns_srv_reply
-+{
-+ int prio; /* priority */
-+ int weight; /* weight */
-+ int port; /* port */
-+ int run_count; /* from struct srventry at gnupg's common/srv.h */
-+ char name[MAXDNAME]; /* target */
-+};
-+
-+struct ns_srv_reply *srv_lookup(char *service, char *protocol, char *domain);
-+
-+#endif /*GNUPG_COMMON_SRV_H*/
-diff -up bitlbee-3.0/Makefile.libresolv bitlbee-3.0/Makefile
---- bitlbee-3.0/Makefile.libresolv 2010-10-22 02:51:31.000000000 +0200
-+++ bitlbee-3.0/Makefile 2010-11-22 02:38:33.000000000 +0100
-@@ -10,7 +10,7 @@
-
- # Program variables
- objects = bitlbee.o dcc.o help.o ipc.o irc.o irc_im.o irc_channel.o irc_commands.o irc_send.o irc_user.o irc_util.o nick.o $(OTR_BI) query.o root_commands.o set.o storage.o $(STORAGE_OBJS)
--headers = bitlbee.h commands.h conf.h config.h help.h ipc.h irc.h log.h nick.h query.h set.h sock.h storage.h lib/events.h lib/ftutil.h lib/http_client.h lib/ini.h lib/md5.h lib/misc.h lib/proxy.h lib/sha1.h lib/ssl_client.h lib/url.h protocols/account.h protocols/bee.h protocols/ft.h protocols/nogaim.h
-+headers = bitlbee.h commands.h conf.h config.h help.h ipc.h irc.h log.h nick.h query.h set.h sock.h storage.h lib/events.h lib/ftutil.h lib/http_client.h lib/ini.h lib/md5.h lib/misc.h lib/proxy.h lib/sha1.h lib/srv.h lib/ssl_client.h lib/url.h protocols/account.h protocols/bee.h protocols/ft.h protocols/nogaim.h
- subdirs = lib protocols
-
- ifeq ($(TARGET),i586-mingw32msvc)
diff --git a/bitlbee.spec b/bitlbee.spec
index a71049d..39559fe 100644
--- a/bitlbee.spec
+++ b/bitlbee.spec
@@ -1,7 +1,7 @@
Summary: IRC to other chat networks gateway
Name: bitlbee
Version: 3.0.1
-Release: 3%{?dist}
+Release: 4%{?dist}
License: GPLv2+ and MIT
Group: System Environment/Daemons
URL: http://www.bitlbee.org/
@@ -144,6 +144,9 @@ rm -rf $RPM_BUILD_ROOT
%endif
%changelog
+* Mon Dec 27 2010 Matěj Cepl <mcepl at redhat.com> - 3.0.1-4
+- Add Ricky Zhou's fixed patch for libresolv (#663934)
+
* Sun Dec 26 2010 Matěj Cepl <mcepl at redhat.com> - 3.0.1-3
- Add bitlbee-des3-implement patch with working ssl_des3_encrypt
implementation by Ricky Zhou.
More information about the scm-commits
mailing list