1
0
Fork 0
mirror of git://git.psyced.org/git/psyced synced 2024-08-15 03:25:10 +00:00

let the past begone in cvs land. welcome to igit igit!

This commit is contained in:
PSYC 2009-01-26 20:21:29 +01:00
commit 4e601cf1c7
509 changed files with 77963 additions and 0 deletions

68
utility/erq/Makefile.in Normal file
View file

@ -0,0 +1,68 @@
# These lines are needed on some machines.
MAKE=make
SHELL=@CONFIG_SHELL@
INSTALL=@INSTALL@
mkinstalldirs=$(SHELL) @top_srcdir@/mkinstalldirs
#
CC=@CC@
prefix=@prefix@
exec_prefix=@exec_prefix@
SUBDIRS = indent make_docs xerq
SED = sed
BINDIR=@bindir@
MUD_LIB=@libdir@
ERQ_DIR=@libexecdir@
#PROFIL= -DOPCPROF -DVERBOSE_OPCPROF
#PROFIL=-p -DMARK
#PROFIL=-pg
PROFIL=
#Enable warnings from the compiler, if wanted.
WARN= # no warning options - will work with all compilers :-)
#WARN= -Wall -Wshadow -Dlint
#WARN= -Wall -Wshadow -Wno-parentheses # gcc settings
#
# Optimization and source level debugging options.
# adding a -fomit-frame-pointer on the NeXT (gcc version 1.93 (68k, MIT syntax))
# will corrupt the driver.
HIGH_OPTIMIZE = @OCFLAGS@ # high optimization
MED_OPTIMIZE= @MCFLAGS@ # medium optimization
LOW_OPTIMIZE = @LCFLAGS@ # minimal optimization
NO_OPTIMIZE= @DCFLAGS@ # no optimization; for frequent recompilations.
OPTIMIZE= $(@val_optimize@_OPTIMIZE)
# The main debugging level is define in config.h
# Add additional options here.
DEBUG=
#
MPATH=-DMUD_LIB='"$(MUD_LIB)"' -DBINDIR='"$(BINDIR)"' -DERQ_DIR='"$(ERQ_DIR)"'
#
TOPINC=-I@top_srcdir@
#
CFLAGS= @EXTRA_CFLAGS@ $(OPTIMIZE) $(DEBUG) $(WARN) $(MPATH) $(PROFIL) $(TOPINC)
#
LIBS=@ERQ_LIBS@ -lresolv
#
LDFLAGS=@LDFLAGS@
all: erq@EXEEXT@
FORCE: install
erq@EXEEXT@: erq.c
# $(CC) erq.c -lresolv -o erq@EXEEXT@
$(CC) $(CFLAGS) $(LDFLAGS) erq.c -o erq@EXEEXT@ $(LIBS)
install: erq@EXEEXT@
$(mkinstalldirs) $(BINDIR)
$(INSTALL) erq@EXEEXT@ $(BINDIR)/erq@EXEEXT@
clean:
-rm -f *.o erq@EXEEXT@ *~

100
utility/erq/erq-srv.patch Normal file
View file

@ -0,0 +1,100 @@
Index: erq.c
===================================================================
--- erq.c (revision 2308)
+++ erq.c (working copy)
@@ -108,6 +108,7 @@
#endif
#include "erq.h"
+#include "srv.c"
#define randomize_tickets(n) srandom(n)
#define get_ticket() random()
@@ -1172,7 +1173,75 @@
break;
}
#endif /* ERQ_RLOOKUPV6 */
+#ifdef ERQ_LOOKUP_SRV
+ case ERQ_LOOKUP_SRV:
+ {
+ /* lookup list of srv records */
+ struct srvhost * r;
+ struct srvhost * s;
+ char service[50], proto[20], hostname[200];
+ int counter;
+ char srvbuf[MAX_REPLY];
+
+ header[8] = CHILD_FREE;
+ counter = 0;
+ srvbuf[0] = '\0';
+ // TODO: sscanf this from req string
+ // format: <service>.<proto>.<hostname>
+ // example: _psyc._tcp.ve.symlynX.com
+ // getsrv(hostname, service, proto)
+ memcpy(header + 9, buf, msglen);
+ buf[msglen] = '\0';
+ sscanf(buf, "%49[^.].%19[^.].%199s", service, proto, hostname);
+#if ERQ_DEBUG > 0
+ fprintf(stderr, "%s: ERQ_LOOKUP_SRV '%s', %s,%s,%s\n", time_stamp(), buf, service, proto, hostname);
+#endif
+ r = getsrv(hostname, service, proto);
+ if (!r) {
+ /* lookup failed, send empty message*/
+ write_32(header, 8);
+ write1(header, 9);
+#if ERQ_DEBUG > 0
+ fprintf(stderr, "%s: ERQ_LOOKUP_SRV could not srv_resolve '%s'\n", time_stamp(), buf);
+#endif
+ break;
+ } else {
+ s = r;
+ while (s) {
+ /* walk list of structures */
+ /* important members: name, port, pref, weight */
+ if (strlen(srvbuf) < MAX_REPLY - 1) {
+ strncat(srvbuf, s -> name, MAX_REPLY - strlen(srvbuf));
+ strncat(srvbuf, "\n", MAX_REPLY - strlen(srvbuf));
+
+
+ if (strlen(srvbuf) < MAX_REPLY - 1) {
+ snprintf(hostname, MAX_REPLY - 1, "%d%c", s -> port, '\n');
+ strncat(srvbuf, hostname, MAX_REPLY - strlen(srvbuf));
+
+ if (strlen(srvbuf) < MAX_REPLY - 1) {
+ snprintf(hostname, MAX_REPLY - 1, "%d%c", s -> pref, '\n');
+ strncat(srvbuf, hostname, MAX_REPLY - strlen(srvbuf));
+ if (strlen(srvbuf) < MAX_REPLY - 1) {
+ snprintf(hostname, MAX_REPLY - 1, "%d%c", s -> weight, '\n');
+ strncat(srvbuf, hostname, MAX_REPLY - strlen(srvbuf));
+ } else s = NULL;
+ } else s = NULL;
+ } else s = NULL;
+ } else s = NULL;
+
+ s = s -> next;
+ counter++;
+ }
+ freesrvhost(r);
+ }
+ write_32(header, strlen(srvbuf) + 9);
+ write1(header, 9);
+ write1(srvbuf, strlen(srvbuf) + 1);
+ break;
+ }
+#endif /* ERQ_LOOKUP_SRV */
case ERQ_EXECUTE:
{
/* Execute a program, wait for its termination and
Index: erq.h
===================================================================
--- erq.h (revision 2308)
+++ erq.h (working copy)
@@ -21,6 +21,7 @@
#ifdef __IPV6__
#define ERQ_RLOOKUPV6 12 /* Lookup name/ip6 */
#endif
+#define ERQ_LOOKUP_SRV 13
/* Additional service request type flags evaluated by efun send_erq().
* The ERQ itself won't get to see it.

2616
utility/erq/erq.c Normal file

File diff suppressed because it is too large Load diff

60
utility/erq/erq.h Normal file
View file

@ -0,0 +1,60 @@
/* external request demon interface definitions */
#ifndef ERQ_H__
#define ERQ_H__ 1
/* servive request types */
#define ERQ_RLOOKUP 0 /* Lookup ip -> name */
#define ERQ_EXECUTE 1 /* Execute a program */
#define ERQ_FORK 2 /* Fork a program */
#define ERQ_AUTH 3 /* Connect to a remote authd */
#define ERQ_SPAWN 4 /* Spawn a program */
#define ERQ_SEND 5 /* Send data to a program or connection */
#define ERQ_KILL 6 /* Kill a program or connection */
#define ERQ_OPEN_UDP 7 /* Open a UDP socket */
#define ERQ_OPEN_TCP 8 /* Open a TCP connection */
#define ERQ_LISTEN 9 /* Open a TCP accept-socket */
#define ERQ_ACCEPT 10 /* Accept a connection from a accept-socket */
#define ERQ_LOOKUP 11 /* Lookup name -> ip */
#ifdef __IPV6__
#define ERQ_RLOOKUPV6 12 /* Lookup name/ip6 */
#endif
#define ERQ_LOOKUP_SRV 13
/* Additional service request type flags evaluated by efun send_erq().
* The ERQ itself won't get to see it.
*/
#define ERQ_CB_STRING (1 << 31) /* Callback closure takes a string arg */
/* answers from ERQ_EXECUTE / ERQ_FORK */
#define ERQ_OK 0
#define ERQ_SIGNALED 1
#define ERQ_E_NOTFOUND 2 /* process not found by wait */
#define ERQ_E_UNKNOWN 3 /* unknown exit condition from wait() */
#define ERQ_E_ARGLENGTH 4
#define ERQ_E_ARGFORMAT 5
#define ERQ_E_ARGNUMBER 6
#define ERQ_E_ILLEGAL 7
#define ERQ_E_PATHLEN 8
#define ERQ_E_FORKFAIL 9
#define ERQ_E_TICKET 11
#define ERQ_E_INCOMPLETE 12
#define ERQ_E_WOULDBLOCK 13
#define ERQ_E_PIPE 14
#define ERQ_STDOUT 15 /* Normal data received */
#define ERQ_STDERR 16
#define ERQ_EXITED 17 /* Connection closed on EOF */
#define ERQ_E_NSLOTS 18
/* reserved handles */
#define ERQ_HANDLE_RLOOKUP (-1)
#define ERQ_HANDLE_KEEP_HANDLE (-2)
#define ERQ_HANDLE_RLOOKUPV6 (-3)
#endif /* ERQ_H__ */

226
utility/erq/srv.c Normal file
View file

@ -0,0 +1,226 @@
/* SRV implementation by the PSYC developers at psyced.org
*
* REMINDER: when modifying anything about these files, remember
* that not only the psyced installer needs to be updated, you
* also have to manually update the gentoo tar.
*/
#include "srv.h"
#include <unistd.h>
#include <stdlib.h>
#include <strings.h>
#include <arpa/inet.h> // For solaris
#include <arpa/nameser.h>
#include <resolv.h>
#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__)
# include <malloc.h>
#else
# include <stdlib.h>
#endif
/* the biggest packet we'll send and receive */
#if PACKETSZ > 1024
#define MAXPACKET PACKETSZ
#else
#define MAXPACKET 1024
#endif
/* and what we send and receive */
typedef union {
HEADER hdr;
u_char buf[MAXPACKET];
} querybuf;
#ifndef T_SRV
#define T_SRV 33
#endif
void freesrvhost ( struct srvhost * s )
{
struct srvhost * n;
while( s ) {
n = s->next;
/* hack to make double-free visible by causing null dereference */
s->next = NULL;
free( (void *)s );
s = n;
}
}
static int compare( const void * a, const void * b )
{
struct srvhost * aa, * bb;
if ( !a )
return 1;
if ( !b )
return -1;
aa = (struct srvhost *) *(int*)a;
bb = (struct srvhost *) *(int*)b;
if ( aa->pref > bb->pref )
return 1;
if ( aa->pref < bb->pref )
return -1;
if ( aa->rweight > bb->rweight )
return -1;
if ( aa->rweight < bb->rweight )
return 1;
return 0;
}
struct srvhost * getsrv( const char * domain,
const char * service, const char * protocol ) {
querybuf answer; /* answer buffer from nameserver */
int n;
char * zone;
int ancount, qdcount; /* answer count and query count */
HEADER *hp; /* answer buffer header */
struct srvhost **replyarray;
struct srvhost * firsthost;
int answerno;
u_char hostbuf[256];
u_char *msg, *eom, *cp; /* answer buffer positions */
int dlen, type, pref, weight, port;
if ( !domain || !*domain ||
!service || !*service ||
!protocol || !*protocol )
return NULL;
zone = (char *)malloc( strlen( domain ) +
strlen( service ) +
strlen( protocol ) + 20 );
if (zone == NULL)
return NULL;
*zone = '\0';
if (*service != '_') // If service and protocol do not start with a
strcat(zone, "_"); // _, prepend the _ to them...
strcat(zone, service);
strcat(zone, ".");
if (*protocol != '_')
strcat(zone, "_");
strcat(zone, protocol);
strcat(zone, ".");
strcat(zone, domain);
n = res_query( zone, C_IN, T_SRV, (u_char *)&answer, sizeof( answer ) );
(void) free( zone );
zone = NULL;
if ( n < (int)sizeof(HEADER) )
return NULL;
/* valid answer received. skip the query record. */
hp = (HEADER *)&answer;
qdcount = ntohs(hp->qdcount);
ancount = ntohs(hp->ancount);
msg = (u_char *)&answer;
eom = (u_char *)&answer + n;
cp = (u_char *)&answer + sizeof(HEADER);
while ( qdcount-- > 0 && cp < eom ) {
n = dn_expand( msg, eom, cp, (char *)hostbuf, 256 );
if (n < 0)
return NULL;
cp += n + QFIXEDSZ;
}
/* make a big-enough (probably too big) reply array */
replyarray
= (struct srvhost **) malloc( ancount * sizeof(struct srvhost *) );
for( n = 0; n < ancount; n++ )
replyarray[n] = NULL;
answerno = 0;
/* loop through the answer buffer and extract SRV records */
while ( ancount-- > 0 && cp < eom ) {
n = dn_expand( msg, eom, cp, (char *)hostbuf, 256 );
if ( n < 0 ) {
for( n = 0; n < answerno; n++ )
(void) free( replyarray[n] );
(void)free( replyarray );
return NULL;
}
cp += n;
type = _getshort(cp);
cp += sizeof(u_short);
/* class = _getshort(cp); */
cp += sizeof(u_short);
/* ttl = _getlong(cp); */
cp += sizeof(u_long);
dlen = _getshort(cp);
cp += sizeof(u_short);
if ( type != T_SRV ) {
cp += dlen;
continue;
}
pref = _getshort(cp);
cp += sizeof(u_short);
weight = _getshort(cp);
cp += sizeof(u_short);
port = _getshort(cp);
cp += sizeof(u_short);
n = dn_expand( msg, eom, cp, (char *)hostbuf, 256 );
if (n < 0)
break;
cp += n;
replyarray[answerno]
= (struct srvhost *)malloc( sizeof( struct srvhost ) +
strlen( (char *)hostbuf ) );
replyarray[answerno]->pref = pref;
replyarray[answerno]->weight = weight;
if ( weight )
replyarray[answerno]->rweight = 1+random()%( 10000 * weight );
else
replyarray[answerno]->rweight = 0;
replyarray[answerno]->port = port;
replyarray[answerno]->next = NULL;
strcpy( replyarray[answerno]->name, (char *)hostbuf );
answerno++;
}
if (answerno == 0) return NULL;
qsort( replyarray, answerno, sizeof( struct srvhost * ),
compare );
// Recreate a linked list from the sorted array...
for( n = 0; n < answerno; n++ )
replyarray[n]->next = replyarray[n+1];
replyarray[answerno-1]->next = NULL;
firsthost = replyarray[0];
(void) free( replyarray );
return firsthost;
}

32
utility/erq/srv.h Normal file
View file

@ -0,0 +1,32 @@
/****************************************************************************
** $Id: srv.h,v 1.1 2006/05/22 11:18:10 lynx Exp $
**
** Definition of something or other
**
** Created : 979899
**
** Copyright (C) 1997 by Troll Tech AS. All rights reserved.
**
****************************************************************************/
#ifndef SRV_H
#define SRV_H
struct srvhost {
unsigned int pref;
struct srvhost * next;
unsigned int port;
unsigned int weight;
unsigned int rweight;
char name[1];
};
extern void freesrvhost ( struct srvhost * );
extern struct srvhost * getsrv( const char * domain,
const char * service,
const char * protocol );
#endif