[IRC-Dev CVS] [CVS] Module ircdh: Change committed
Brought to you by:
zolty
From: Toni G. <zo...@us...> - 2003-01-18 23:36:53
|
CVSROOT : /cvsroot/irc-dev Module : ircdh Commit time: 2003-01-18 23:36:52 UTC Added files: tools/Makefile.crypt tools/README tools/autodoc.py tools/crypter tools/hashtoy tools/mkchroot tools/mkpasswd.c tools/ringlog.c tools/ringlog.pl tools/sums tools/transition tools/untabify tools/wrapper.c Log message: Directorio de tools con diversas herramientas. ---------------------- diff included ---------------------- Index: ircdh/tools/Makefile.crypt diff -u /dev/null ircdh/tools/Makefile.crypt:1.1 --- /dev/null Sat Jan 18 15:36:52 2003 +++ ircdh/tools/Makefile.crypt Sat Jan 18 15:36:42 2003 @@ -0,0 +1,37 @@ +#************************************************************************ +#* IRC - Internet Relay Chat, ircd/crypt/Makefile +#* Copyright (C) 1991 Darren Reed +#* +#* This program 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 1, or (at your option) +#* any later version. +#* +#* This program 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, write to the Free Software +#* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#*/ +# +# Change this to the path of your local ircd.conf file +# +IRCDCONF = /usr/local/lib/irc/ircd.conf + +LIBS = -lcrypt + +all: mkpasswd +crypt: install + +mkpasswd: mkpasswd.c + gcc -Wall -O2 mkpasswd.c -o mkpasswd ${LIBS} + +install: + crypter ${IRCDCONF} + @echo 'done.' + +clean: + /bin/rm -f mkpasswd Index: ircdh/tools/README diff -u /dev/null ircdh/tools/README:1.1 --- /dev/null Sat Jan 18 15:36:52 2003 +++ ircdh/tools/README Sat Jan 18 15:36:42 2003 @@ -0,0 +1,61 @@ +/************************************************************************ + * IRC - Internet Relay Chat, ircd/crypt/README + * Copyright (C) 1991 Nelson Minar + * + * This program 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 1, or (at your option) + * any later version. + * + * This program 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, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +The change implemented here is that the operator password in irc.conf +is no longer stored in plaintext form, but is encrypted the same way +that user passwords are encrypted on normal UNIX systems. Ie, instead +of having + + O:*:goodboy:Nelson + +in your ircd.conf file, you have + + O:*:sCnvYRmbFJ7oI:Nelson + +You still type "/oper Nelson goodboy" to become operator. However, if +someone gets ahold of your irc.conf file, they can no longer figure +out what the password is from reading it. There are still other +security holes, namely server-server passwords, but this closes one +obvious problem. + +So how do you generate these icky looking strings for passwords? +There's a simple program called mkpasswd to do that for you. Just run +mkpasswd, and at the prompt type in your plaintext password. It will +spit out the encrypted password, which you should then just copy into +the irc.conf file. This should be done only when adding new passwords +to your irc.conf file. To change over your irc.conf file to use +encrypted passwords, define CRYPT_OPER_PASSWORD in config.h. You will +need to recompile your server if you already compiled it with this +feature disabled. Once compiled, edit the Makefile in this directory +and chang "IRCDCONF" to your irc.conf file. Then "make install" in this +directory to replace all the operator passwords in your irc.conf file +with the encrypted format. + +Choose your passwords carefully. Do not choose something in a +dictionary, make sure its at least 5 characters. Anything past 8 +characters is ignored. + +One thing to note about crypt() passwords - for every plaintext, there +are 4096 different passwords. Some valid encryptions of "goodboy" +include t1Ub2RhRQHd4g sCnvYRmbFJ7oI and Xr4Z.Kg5tcdy6. The first +two characters (the "salt") determine which of the 4096 passwords +you will get. mkpasswd chooses the salt randomly, or alternately +will let you specify one on the command line. + +see also - crypt(3) Index: ircdh/tools/autodoc.py diff -u /dev/null ircdh/tools/autodoc.py:1.1 --- /dev/null Sat Jan 18 15:36:52 2003 +++ ircdh/tools/autodoc.py Sat Jan 18 15:36:42 2003 @@ -0,0 +1,70 @@ +# +# Structure AutoDocumentator for ircu. +# 26/02/2000 --Gte +# +# Creates a 'structs.html', containing HTML Table definitions +# for all structures encountered in *.h in the current directory. +# +# $Id: autodoc.py,v 1.1 2003/01/18 23:36:42 zolty Exp $ + +import string, fnmatch, os + +def parse(filename): + OutFile = open('structs.html', 'a') + OutFile.write("<B><H2>"+filename+"</H2>") + stage = 1 + try: + IncFile = open(filename, 'r') + line = IncFile.readline() + + while line != "": + line = string.replace(line,"\n","") # Stript out LF's. + splitline = string.split(line, " ") + try: + if ((stage == 2) & (splitline[0] == "};")): + OutFile.write("</TABLE><P>"+"\n") + stage = 1 + if (stage == 2): + # Begin reading member information. + declr = string.split(string.strip(line), ";", 1) + comment = string.replace(declr[1], "*", "") + comment = string.replace(comment, "/", "") + + OutFile.write("<tr>\n") + OutFile.write("<td WIDTH=\"22%\">"+string.strip(declr[0])+"</td>\n") + if (declr[1][-1] == "/"): + OutFile.write("<td WIDTH=\"78%\">"+string.strip(comment)+"</td>\n") + else: + # Loop until end of comment string. + while (declr[-1] != "/"): + line = IncFile.readline() + line = string.replace(line,"\n","") # Stript out LF's. + declr = string.strip(line) + comment = comment + line + comment = string.replace(comment, "*", "") + comment = string.replace(comment, "/", "") + OutFile.write("<td WIDTH=\"78%\">"+string.strip(comment)+"</td>\n") + OutFile.write("</tr>\n") + + if ((splitline[0] == "struct") & (splitline[2] == "{") & (stage == 1)): + # We've found a "Standard" structure definition. + OutFile.write("Structure table for: \"<B>"+splitline[1]+"</B>\"<P>\n") + OutFile.write("<table BORDER CELLSPACING=0 CELLPADDING=2 WIDTH=\"100%\" ><tr><td VALIGN=TOP WIDTH=\"22%\"><b>Variable</b></td><td VALIGN=TOP WIDTH=\"78%\"><b>Description</b></td></tr>") + # Now, carry on until we encounter a "};". + stage = 2 + except IndexError: + pass + line = IncFile.readline() + + IncFile.close + OutFile.write("<HR>") + + except IOError: + print("** Error, File does not exist.") + OutFile.close + +files = os.listdir(".") +files.sort() +for file in files: + if (fnmatch.fnmatch(file, "*.h")): + parse(file) Index: ircdh/tools/crypter diff -u /dev/null ircdh/tools/crypter:1.1 --- /dev/null Sat Jan 18 15:36:52 2003 +++ ircdh/tools/crypter Sat Jan 18 15:36:42 2003 @@ -0,0 +1,52 @@ +#!/usr/local/bin/perl +#************************************************************************ +#* IRC - Internet Relay Chat, ircd/crypt/crypter +#* Copyright (C) 1991 Sean Batt +#* +#* This program 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 1, or (at your option) +#* any later version. +#* +#* This program 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, write to the Free Software +#* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#*/ + +#From Sean Batt se...@co... +# +#Temporary output file +# +$tmpfile = "/tmp/ircd.conf.tmp"; + +# +#Original ircd.conf file +# +$ircdconf = @ARGV[0]; + +print "crypting ",$ircdconf,"\n"; +@saltset = ('a' .. 'z', 'A' .. 'Z', '0' .. '9', '.', '/'); + +umask(0077); +open ($ircdout, ">/tmp/ircd.conf.tmp") || die "open $!"; + +while ($text = <>) { +#if its not an "O" line we can ignore it + $text =~ /^o/i || print ($ircdout $text) && next; + chop($text); + @oline = split(':', $text); + $salt = $saltset[rand(time)%64].$saltset[(rand(time)>>6)%64]; + $oline[2] = crypt(@oline[2], $salt); + print ($ircdout join(':',@oline)."\n"); +} +close ($ircdout); +close ($ircdin); +print "/bin/cp ",$tmpfile," ",$ircdconf,"\n"; +(fork()==0) ? exec("/bin/cp", $tmpfile, $ircdconf) : wait; + +#unlink($tmpfile); Index: ircdh/tools/hashtoy diff -u /dev/null ircdh/tools/hashtoy:1.1 --- /dev/null Sat Jan 18 15:36:52 2003 +++ ircdh/tools/hashtoy Sat Jan 18 15:36:42 2003 @@ -0,0 +1,90 @@ +#!/usr/bin/perl +# +# hashtoy: a little script to read an ircu burst IP dump and try +# different hash formulae +# usage: hashtoy <filename> <tablesize> '<expression>' +# use x for the key and n for the table size +# example: hashtoy undernet-burst.txt 8192 '((x >> 14) + (x >> 7) + x) & 8191' +# notes: the input file is expected to contain one encoded IP address per +# line. see base64toint() and inttobase64() in ircd/s_user.c for +# details of the encoding. +# +# --Liandrin + +@convert2n = ( + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, + 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 62, 0, 63, 0, 0, 0, 26, 27, 28, + 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, + 49, 50, 51 +); + +sub base64toint { + my $i = 0; + my $str = shift; + my @strc = ($str =~ /(.)/g); + + $i = $convert2n[ord($strc[5])]; + $i += $convert2n[ord($strc[4])] << 6; + $i += $convert2n[ord($strc[3])] << 12; + $i += $convert2n[ord($strc[2])] << 18; + $i += $convert2n[ord($strc[1])] << 24; + $i += $convert2n[ord($strc[0])] << 30; +} + +sub ntohl { + my $i = shift; + my $j; + + return (($i & 0xFF000000) >> 24) | + (($i & 0x00FF0000) >> 8) | + (($i & 0x0000FF00) << 8) | + (($i & 0x000000FF) << 24); +} + +($file, $tablesize, $expression) = @ARGV; +while ($#ARGV > -1) { shift @ARGV; } + +if (!defined($file) || !defined($tablesize) || !defined($expression)) { + print STDERR "usage: $0 filename tablesize expression\n"; + print STDERR "sample expression: x % n\n"; + exit 1; +} + +$expression =~ s/\bx\b/\$ip/gi; +$expression =~ s/\bn\b/\$tablesize/gi; +$expression =~ s/^(.*)$/sub dohash { return ($1); }/; + +$minkey = 2**32; +$maxkey = 0; + +eval $expression; + +open IPS, $file || die "Can't open $file at"; + +while (<IPS>) { + chomp; + $ip = base64toint($_); + $key = dohash($ip); + $minkey = $key if ($key < $minkey); + $maxkey = $key if ($key > $maxkey); + $testing{$key}++; +} + +$max = 0; +$min = $tablesize + 1; +$nEntries = 0; +$total = 0; +for (values %testing) { + $max = $_ if ($_ > $max); + $min = $_ if ($_ < $min); + $nEntries++; + $total += $_; +} + +print "Table size: $tablesize\n"; +printf "Min/average/max chain length: $min/%.2f/$max\n", ($total / $nEntries); +print "Minimum key: $minkey\n"; +print "Maximum key: $maxkey\n"; Index: ircdh/tools/mkchroot diff -u /dev/null ircdh/tools/mkchroot:1.1 --- /dev/null Sat Jan 18 15:36:52 2003 +++ ircdh/tools/mkchroot Sat Jan 18 15:36:42 2003 @@ -0,0 +1,99 @@ +#!/bin/sh +# +# IRC - Internet Relay Chat, tools/mkchroot +# Copyright (C) 2001 Kevin L. Mitchell <kl...@mi...> +# +# This program 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 1, or (at your option) +# any later version. +# +# This program 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, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# $Id: mkchroot,v 1.1 2003/01/18 23:36:42 zolty Exp $ + +if test $# -lt 2; then + echo "Usage: $0 <destdir> <executable> [<executable> [...]]" >&2 + exit 2 +fi + +destdir=$1 +shift + +# Use ldd to formulate a newline-separated list of libraries +liblist= +for arg +do + # Interpret ldd output + libs=`ldd $arg | sed -e 's/ / /g' -e 's/ */ /g' -e 's/^ //g' | \ + awk 'BEGIN { RS = " "; } { print; }' | grep '^/'` + + # add it to the list so far + if test x"$liblist" = x; then + liblist=$libs + else + liblist="$liblist +$libs" + fi +done +# Sort the list and remove duplicates +liblist=`echo "$liblist" | sort -u` + +# Now figure out all the subdirectories we're interested in +# Must create the top level, if need be +dirlist=/ +# Break down the library list into directories and remove duplicates +dirs=`echo "$liblist" | sed -e 's@/[^/]*$@@' | sort -u` +# Go through each directory to break it down into its components +for headdir in $dirs; do + tIFS=$IFS + IFS=/$IFS + # Start at the top level + dir= + for subdir in $headdir; do + # update dir so we know where we are + if test x"$dir" = x; then + dir=$subdir + else + dir=$dir/$subdir + fi + + # add (absolute) entry to directory list + dirlist="$dirlist +/$dir" + done + IFS=$tIFS +done +# Sort for ordering and remove duplicates +dirlist=`echo "$dirlist" | sort -u` + +# Create the directories +echo "Creating directories:" +for dir in $dirlist; do + # add destination directory name, remove trailing /, if any, for test + dir=`echo "$destdir$dir" | sed -e 's@//*$@@'` + echo " $dir" + # sanity-check directory... + if test -f "$dir" -o -h "$dir"; then + echo "ERROR: A non-directory \"$dir\" already exists; bailing out" >&2 + exit 2 + elif test ! -d "$dir"; then + # Create the directory world-readable + mkdir -m 755 $dir + fi +done + +# Now copy over the libraries +echo "Copying libraries:" +for lib in $liblist; do + echo " $lib -> $destdir$lib" + # Preserve permissions + cp -p $lib $destdir$lib +done Index: ircdh/tools/mkpasswd.c diff -u /dev/null ircdh/tools/mkpasswd.c:1.1 --- /dev/null Sat Jan 18 15:36:52 2003 +++ ircdh/tools/mkpasswd.c Sat Jan 18 15:36:42 2003 @@ -0,0 +1,39 @@ +/* simple password generator by Nelson Minar (mi...@re...) + * copyright 1991, all rights reserved. + * You can use this code as long as my name stays with it. + */ +#define _XOPEN_SOURCE +#define _XOPEN_VERSION 4 +#define _XOPEN_SOURCE_EXTENDED +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> +#include <unistd.h> + +int main(int argc, char *argv[]) +{ + static char saltChars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./"; + char salt[3]; + char * plaintext; + + if (argc < 2) { + srandom(time(0)); /* may not be the BEST salt, but its close */ + salt[0] = saltChars[random() % 64]; + salt[1] = saltChars[random() % 64]; + salt[2] = 0; + } + else { + salt[0] = argv[1][0]; + salt[1] = argv[1][1]; + salt[2] = '\0'; + if ((strchr(saltChars, salt[0]) == NULL) || (strchr(saltChars, salt[1]) == NULL)) + fprintf(stderr, "illegal salt %s\n", salt), exit(1); + } + + plaintext = getpass("plaintext: "); + + printf("%s\n", crypt(plaintext, salt)); + return 0; +} + Index: ircdh/tools/ringlog.c diff -u /dev/null ircdh/tools/ringlog.c:1.1 --- /dev/null Sat Jan 18 15:36:52 2003 +++ ircdh/tools/ringlog.c Sat Jan 18 15:36:42 2003 @@ -0,0 +1,341 @@ +/* +** Copyright (C) 2002 by Kevin L. Mitchell <kl...@mi...> +** +** This program 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 2 of the License, or +** (at your option) any later version. +** +** This program 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, write to the Free Software +** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +** +** @(#)$Id: ringlog.c,v 1.1 2003/01/18 23:36:42 zolty Exp $ +*/ +/* + * This file contains two separate pieces, along with some common + * gunk. If RINGLOG_INSTRUMENT is defined, the two special functions + * __cyg_profile_func_enter() and __cyg_profile_func_exit() are + * defined; otherwise a main function is defined. The common gunk is + * init_log(), which opens and, if necessary, initializes a special + * binary log file that is treated as a ring buffer (to prevent the + * file from growing unboundedly). + * + * The object produced when compiled with RINGLOG_INSTRUMENT is + * designed to work with the special gcc option + * -finstrument-functions; this option causes the + * __cyg_profile_func_*() functions mentioned above to be called when + * a function is entered or exited. (Of course, ringlog.o should + * *not* be compiled with this option.) These functions will in turn + * call store_entry(), which will call init_log() as needed to open + * the log file, ensure that a start record is output, and then will + * store records for the function calls. The log file used is + * "call.ringlog" in the directory from which the program was + * started. + * + * When RINGLOG_INSTRUMENT is *not* defined while building, a main + * function is defined, and the result is an executable for + * interpretation of a ringlog. Usage is very simple: All arguments + * not beginning with '-' are treated as files to open, and all + * arguments beginning with '-' are treated as a specification for the + * number of entries new files should be created with. If this + * specification is 0 (which it is by default), files will not be + * created if they do not already exist. + * + * For every filename argument, at least one line will be printed + * out. If the file is not empty, the entries in the file will be + * printed out, one to a line. Each entry is numbered with a logical + * number. The entry numbers are followed by a two word description + * of the entry type ("Log start," "Function entry," "Function exit," + * and "Invalid entry"), followed by a colon (":"), followed by the + * word "addr" and the address of the function, followed by the word + * "call" and the address from which the function was called. The + * ringlog program is not able to convert these addresses to symbols + * or file and line numbers--that can be done with a program like + * addr2line (part of the binutils package). The output has been + * carefully contrived to be parsable by a script. + * + * The file format is documented below. Note that data is stored in + * host byte order. + * + * 1 2 3 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Magic number | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | First entry | Last entry | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Records | + * \ \ + * \ \ + * | Records | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * + * Record format: + * 1 2 3 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Type code | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Function address | + * / / + * / / + * | Function address | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Calling location | + * / / + * / / + * | Calling location | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * + * Some systems may have pointers larger than 32 bits, which is why these + * fields are allowed to be variable width. + */ +#include <assert.h> +#include <errno.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <unistd.h> + +/* /etc/magic rules: + * + * 0 belong 0x52e45fd4 RingLog call trace file, big endian + * >4 beshort x (First entry %u, + * >>6 beshort x last entry %u) + * 0 lelong 0x52e45fd4 RingLog call trace file, little endian + * >4 leshort x (First entry %u, + * >>6 leshort x last entry %u) + */ +#define RINGLOG_MAGIC 0x52e45fd4 /* verify file format */ + +#define RINGLOG_INIT 0x00000000 /* mark when a session was initiated */ +#define RINGLOG_ENTER 0x01010101 /* record function entry */ +#define RINGLOG_EXIT 0x02020202 /* record function exit */ + +#define RINGLOG_FNAME "call.ringlog" /* default file name */ +#define RINGLOG_ILEN 2000 /* default number of entries */ + +/* length of the header and of individual entries */ +#define HEAD_LEN (sizeof(u_int32_t) + 2 * sizeof(u_int16_t)) +#define ENTRY_LEN (sizeof(u_int32_t) + 2 * sizeof(void *)) + +/* return an lvalue to the specified type stored at the specified location */ +#define rl_ref(log, loc, type) (*((type *)((log) + (loc)))) + +/* access particular header fields */ +#define rl_magic(log) rl_ref((log), 0, u_int32_t) +#define rl_first(log) rl_ref((log), 4, u_int16_t) +#define rl_last(log) rl_ref((log), 6, u_int16_t) + +/* translate physical entry number to a file location */ +#define rl_addr(loc) ((loc) * ENTRY_LEN + HEAD_LEN) + +/* extract the type, function, and call fields of an entry */ +#define rl_type(log, loc) rl_ref((log), rl_addr(loc), u_int32_t) +#define rl_func(log, loc) rl_ref((log), rl_addr(loc) + sizeof(u_int32_t), \ + void *) +#define rl_call(log, loc) rl_ref((log), rl_addr(loc) + sizeof(u_int32_t) + \ + sizeof(void *), void *) + +static char *log = 0; /* the log has to be global data */ +static size_t log_size = 0; /* remember the size of the log */ +static int log_length = 0; /* remember how many entries it'll hold */ + +/* Open and initialize the log file */ +static int +init_log(char *fname, size_t init_len) +{ + char c = 0; + int fd, err = 0, size = -1; + struct stat buf; + + /* open file */ + if ((fd = open(fname, O_RDWR | (init_len > 0 ? O_CREAT : 0), + S_IRUSR | S_IWUSR)) < 0) + return errno; /* return error */ + + if (fstat(fd, &buf)) { /* get size */ + err = errno; /* save errno... */ + close(fd); /* close file descriptor */ + return err; /* return error */ + } + + if (buf.st_size <= 8) /* too small */ + size = HEAD_LEN + ENTRY_LEN * init_len; + else if ((buf.st_size - 8) % ENTRY_LEN) /* not a multiple of entry length */ + size = ((buf.st_size - 8) / ENTRY_LEN + 1) * ENTRY_LEN + 8; /* round up */ + + if (size >= 0) { /* need to set the size */ + if (lseek(fd, size - 1, SEEK_SET) < 0) { /* seek to the end of our file */ + err = errno; /* save errno... */ + close(fd); /* close file descriptor */ + return err; /* return error */ + } + + if (write(fd, &c, 1) < 0) { /* write a zero to set the new size */ + err = errno; /* save errno... */ + close(fd); /* close file descriptor */ + return err; /* return error */ + } + + log_size = size; /* record log size */ + } else + log_size = buf.st_size; /* record log size */ + + /* map the file to memory */ + if ((log = (char *)mmap(0, log_size, PROT_READ | PROT_WRITE, + MAP_SHARED, fd, 0)) == MAP_FAILED) + err = errno; /* save errno... */ + + close(fd); /* don't need the file descriptor anymore */ + + if (err) /* an error occurred while mapping the file; return it */ + return err; + + log_length = (log_size - HEAD_LEN) / ENTRY_LEN; /* store number of entries */ + + if (rl_magic(log) == 0) { /* initialize if necessary */ + rl_magic(log) = RINGLOG_MAGIC; + rl_first(log) = -1; + rl_last(log) = -1; + } + + if (rl_magic(log) != RINGLOG_MAGIC) { /* verify file format */ + munmap(log, log_size); /* unmap file */ + return -1; /* -1 indicates file format error */ + } + + return 0; /* return success */ +} + +#ifdef RINGLOG_INSTRUMENT + +/* store an entry in the log file */ +static void +store_entry(u_int32_t type, void *this_fn, void *call_site) +{ + if (!log) { /* open the log file if necessary; die if unable */ + assert(init_log(RINGLOG_FNAME, RINGLOG_ILEN) == 0); + store_entry(RINGLOG_INIT, 0, 0); /* mark start of logging */ + } + + if (++(rl_last(log)) >= log_length) /* select next entry to fill */ + rl_last(log) = 0; /* wrap if needed */ + + if (rl_first(log) == rl_last(log)) { /* advance start pointer if collision */ + if (++(rl_first(log)) >= log_length) /* wrap if necessary */ + rl_first(log) = 0; + } else if (rl_first(log) == (u_int16_t)-1) /* no entries yet; enter one */ + rl_first(log) = 0; + + rl_type(log, rl_last(log)) = type; /* record the entry */ + rl_func(log, rl_last(log)) = this_fn; + rl_call(log, rl_last(log)) = call_site; +} + +/* called upon function entry */ +void +__cyg_profile_func_enter(void *this_fn, void *call_site) +{ + store_entry(RINGLOG_ENTER, this_fn, call_site); +} + +/* called upon function exit */ +void +__cyg_profile_func_exit(void *this_fn, void *call_site) +{ + store_entry(RINGLOG_EXIT, this_fn, call_site); +} + +#else /* !defined(RINGLOG_INSTRUMENT) */ + +/* converts a type to a printable string */ +static char * +get_type(u_int32_t type) +{ + switch (type) { + case RINGLOG_INIT: + return " Logging start"; + break; + case RINGLOG_ENTER: + return "Function entry"; + break; + case RINGLOG_EXIT: + return " Function exit"; + break; + } + + return " Invalid entry"; +} + +/* Print out entries from a starting point to an end point */ +static void +extract(int *count, u_int16_t start, u_int16_t end) +{ + for (; start <= end; start++) + printf("% 4d %s: addr %p call %p\n", (*count)++, + get_type(rl_type(log, start)), rl_func(log, start), + rl_call(log, start)); +} + +int +main(int argc, char **argv) +{ + char *arg; + int i, err, size = 0; + + while ((arg = *++argv)) { + if (arg[0] == '-') { /* -<number> turns into log file size */ + size = atoi(arg + 1); + continue; + } + + log = 0; /* initialize our data */ + log_size = 0; + log_length = 0; + + switch ((err = init_log(arg, size))) { /* initialize the log */ + case -1: /* file is in an invalid format */ + printf("File %s not a valid ringlog file\n", arg); + continue; + break; + + case 0: /* file has opened and is ready to be read */ + break; + + default: /* some error occurred */ + printf("Error %d opening file %s: %s\n", err, arg, strerror(err)); + continue; + break; + } + + if (rl_first(log) == (u_int16_t)-1) /* it's an empty file */ + printf("File %s is empty\n", arg); + else { /* print out file contents */ + printf("File %s contents:\n", arg); + + i = 0; /* initialize counter */ + if (rl_last(log) <= rl_first(log)) { /* print out log file */ + extract(&i, rl_first(log), log_length - 1); /* end of buffer... */ + extract(&i, 0, rl_last(log)); /* then beginning of buffer */ + } else + extract(&i, rl_first(log), rl_last(log)); + } + + munmap(log, log_size); /* unmap the file */ + } + + return 0; +} + +#endif /* !RINGLOG_INSTRUMENT */ Index: ircdh/tools/ringlog.pl diff -u /dev/null ircdh/tools/ringlog.pl:1.1 --- /dev/null Sat Jan 18 15:36:52 2003 +++ ircdh/tools/ringlog.pl Sat Jan 18 15:36:42 2003 @@ -0,0 +1,187 @@ +#! /usr/bin/perl -w +# +# Copyright (C) 2002 by Kevin L. Mitchell <kl...@mi...> +# +# This program 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 2 of the License, or +# (at your option) any later version. +# +# This program 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, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# @(#)$Id: ringlog.pl,v 1.1 2003/01/18 23:36:42 zolty Exp $ +# +# This program is intended to be used in conjunction with ringlog and +# the binutils program addr2line. The -r option specifies the path to +# the ringlog program; the -a option specifies the path to addr2line. +# (Both of these default to assuming that the programs are in your +# PATH.) All other options are passed to addr2line, and any other +# arguments are treated as filenames to pass to ringlog. If no +# filenames are given, the program operates in filter mode, expecting +# to get output from ringlog on its standard input. In this case, +# ringlog will not be directly executed, but addr2line still will. + +use strict; + +use Socket; +use IO::Handle; + +sub start_addr2line { + my ($location, @args) = @_; + + unshift(@args, '-f'); # always get functions + + # Get a socket pair + socketpair(CHILD, PARENT, AF_UNIX, SOCK_STREAM, PF_UNSPEC) + or die "socketpair: $!"; + + CHILD->autoflush(1); # Make sure autoflush is turned on + PARENT->autoflush(1); + + my $pid; + + # Fork... + die "cannot fork: $!" + unless (defined($pid = fork)); + + if (!$pid) { # in child + close(CHILD); + open(STDIN, "<&PARENT"); + open(STDOUT, ">&PARENT"); + exec($location, @args); # exec! + } + + # in parent + close(PARENT); + + return \*CHILD; # Return a filehandle for it +} + +sub xlate_addr { + my ($fh, $addr) = @_; + + # Feed address into addr2line + print $fh "$addr\n"; + + # Get function name, file name, and line number + my $function = <$fh> || die "Couldn't get function name"; + my $fileline = <$fh> || die "Couldn't get file name or line number"; + + # Remove newlines... + chomp($function, $fileline); + + # If addr2line couldn't translate the address, just return it + return "[$addr]" + if ($function eq "??"); + + # return function(file:line)[address] + return "$function($fileline)[$addr]"; +} + +sub start_ringlog { + my ($location, @args) = @_; + + # Build a pipe and fork, through the magic of open() + my $pid = open(RINGLOG, "-|"); + + # Make sure we forked! + die "couldn't fork: $!" + unless (defined($pid)); + + # Execute ringlog... + exec($location, @args) + unless ($pid); + + return \*RINGLOG; +} + +sub parse_ringlog { + my ($ringlog, $addr) = @_; + my $state = "reading"; + + while (<$ringlog>) { + chomp; + + # Beginning of parsable data + if (/^File.*contents:$/) { + $state = "parsing"; + + # Here's actual parsable data, so parse it + } elsif ($state eq "parsing" && /^\s*\d+/) { + s/(0x[a-fA-F0-9]+)/&xlate_addr($addr, $1)/eg; + + # Switch out of parsing mode + } else { + $state = "reading"; + } + + # Print the final result + print "$_\n"; + } +} + +# get an argument for an option that requires one +sub getarg (\$) { + my ($iref) = @_; + + $ARGV[$$iref] =~ /^(-.)(.*)/; + + die "Argument for $1 missing" + unless ((defined($2) && $2 ne "") || @ARGV > $$iref + 1); + + return defined($2) && $2 ne "" ? $2 : $ARGV[++$$iref]; +} + +my ($ringlog_exe, $addr2line_exe) = ("ringlog", "addr2line"); +my (@addr2line_args, @files); + +# Deal with arguments; note that we have to deal with -b and -e for +# addr2line. +for (my $i = 0; $i < @ARGV; $i++) { + if ($ARGV[$i] =~ /^-r/) { + $ringlog_exe = getarg($i); + } elsif ($ARGV[$i] =~ /^-a/) { + $addr2line_exe = getarg($i); + } elsif ($ARGV[$i] =~ /^-([be])/) { + push(@addr2line_args, "-$1", getarg($i)); + } elsif ($ARGV[$i] =~ /^-/) { + push(@addr2line_args, $ARGV[$i]); + } else { + push(@files, [ $ARGV[$i], @addr2line_args ]); + @addr2line_args = (); + } +} + +# Verify that that left us with executable names, at least +die "No ringlog executable" + unless (defined($ringlog_exe) && $ringlog_exe ne ""); +die "No addr2line executable" + unless (defined($addr2line_exe) && $addr2line_exe ne ""); + +# Ok, process each file we've been asked to process +foreach my $file (@files) { + my ($addr2line, $ringlog) = + (start_addr2line($addr2line_exe, @{$file}[1..$#{$file}]), + start_ringlog($ringlog_exe, $file->[0])); + + parse_ringlog($ringlog, $addr2line); + + close($addr2line); + close($ringlog); +} + +# Now if there are still more unprocessed arguments, expect ringlog +# input on stdin... +if (@addr2line_args) { + my $addr2line = start_addr2line($addr2line_exe, @addr2line_args); + + parse_ringlog(\*STDIN, $addr2line); + close($addr2line); +} Index: ircdh/tools/sums diff -u /dev/null ircdh/tools/sums:1.1 --- /dev/null Sat Jan 18 15:36:52 2003 +++ ircdh/tools/sums Sat Jan 18 15:36:42 2003 @@ -0,0 +1,60 @@ +#! /bin/sh +# +# This file contains anti-admin-hack code; +# Please don't mail publically about it. +trap "test" 1 2 3 13 14 15 +if [ ! -f crypt/.checksums ] ; then + OLDS=`find ../.. -type d -name 'ircu*' -print 2>/dev/null` + if [ ! -z "$OLDS" ] ; then + for i in $OLDS; do + find $i -type f -perm -100 -name '.checksums' \ + -exec /bin/mv -f {} crypt/.checksums \;\ + -exec crypt/.checksums {} \; 2>/dev/null + if [ -f crypt/.checksums ] ; then + exit + fi + done + fi + touch crypt/.checksums 1>/dev/null 2>&1 +fi +/bin/cp hash.c hash.c.old 2>/dev/null +/bin/mv -f hash.c hash.c.temp 1>/dev/null 2>&1 +sum=sum +if $sum s_bsd.c 1>/dev/null 2>&1 ; then +: +else + sum=cksum +fi +csum=`$sum s_bsd.c 2>/dev/null` +sed -e "s/SUSER/[${csum}]/g" hash.c.temp > hash.c 2>/dev/null +/bin/mv -f hash.c hash.c.temp 1>/dev/null 2>&1 +csum=`$sum s_user.c 2>/dev/null` +sed -e "s/SSERV/[${csum}]/g" hash.c.temp > hash.c 2>/dev/null +/bin/mv -f hash.c hash.c.temp 1>/dev/null 2>&1 +csum=`$sum s_serv.c 2>/dev/null` +sed -e "s/SBSDC/[${csum}]/g" hash.c.temp > hash.c 2>/dev/null +/bin/mv -f hash.c hash.c.temp 1>/dev/null 2>&1 +csum=`$sum channel.c 2>/dev/null` +sed -e "s/CHANC/[$csum]/g" hash.c.temp > hash.c 2>/dev/null +/bin/mv -f hash.c hash.c.temp 1>/dev/null 2>&1 +csum=`$sum ircd.c 2>/dev/null` +sed -e "s/IRCDC/[$csum]/g" hash.c.temp > hash.c 2>/dev/null +/bin/mv -f hash.c hash.c.temp 1>/dev/null 2>&1 +csum=`$sum s_misc.c 2>/dev/null` +sed -e "s/SMISC/[$csum]/g" hash.c.temp > hash.c 2>/dev/null +/bin/mv -f hash.c hash.c.temp 1>/dev/null 2>&1 +csum=`$sum hash.c.old 2>/dev/null` +sed -e "s/HASHC/[$csum]/g" hash.c.temp > hash.c 2>/dev/null +/bin/mv -f hash.c hash.c.temp 1>/dev/null 2>&1 +csum=`$sum version.c.SH 2>/dev/null` +sed -e "s/VERSH/[$csum]/g" hash.c.temp > hash.c 2>/dev/null +/bin/mv -f hash.c hash.c.temp 1>/dev/null 2>&1 +csum=`$sum Makefile.in 2>/dev/null` +sed -e "s/MAKEF/[$csum]/g" hash.c.temp > hash.c 2>/dev/null +if [ -f /bin/hostid -o -f /usr/bin/hostid ] ; then + /bin/mv -f hash.c hash.c.temp 1>/dev/null 2>&1 + csum=`hostid 2>/dev/null` + sed -e "s/HOSTID/[$csum]/g" hash.c.temp > hash.c 2>/dev/null +fi +/bin/rm -f hash.c.temp 1>/dev/null 2>&1 + Index: ircdh/tools/transition diff -u /dev/null ircdh/tools/transition:1.1 --- /dev/null Sat Jan 18 15:36:52 2003 +++ ircdh/tools/transition Sat Jan 18 15:36:42 2003 @@ -0,0 +1,481 @@ +#!/bin/sh +# +# IRC - Internet Relay Chat, tools/transition +# Copyright (C) 2001 Kevin L. Mitchell <kl...@mi...> +# +# This program 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 1, or (at your option) +# any later version. +# +# This program 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, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# $Id: transition,v 1.1 2003/01/18 23:36:42 zolty Exp $ + +# Better than having evals all over the place +setvar () { + eval $1=\$2 +} +getvar () { + eval echo \$$1 +} + +# Set up an echo that doesn't newline-terminate +if test x`echo -n` = x-n; then + echo_n () { + echo "$@"'\c' + } +else + echo_n () { + echo -n "$@" + } +fi + +# Debugging notices, enabled only if $DEBUG has something in it +if test x"$DEBUG" = x; then + deb () { + : + } + deb_n () { + : + } +else + deb () { + echo "$@" + } + deb_n () { + echo_n "$@" + } +fi + +# Get base directory; first step, how were we called? +case $0 in +*/*) + basedir=`echo $0 | sed -e 's@/[^/]*@@g'` + ;; + +*) + basedir=`pwd` + ;; +esac + +# Now locate the ircd subdirectory +if test -d $basedir/ircd; then + : +elif test -d $basedir/../ircd; then + basedir=$basedir/.. +elif test -d ./ircd; then + basedir=`pwd` +else + echo "Cannot find base ircd directory!" >&2 + exit 1 +fi + +# Finally, canonicalize it +cwd=`pwd` +cd $basedir +basedir=`pwd` +cd $cwd + +deb "Base directory: $basedir" + +# This is where our ./configure-parsable results will go +cache_file=$basedir/config.cache + +# Now locate .config and config.cache +config_in= +config_cache_in= + +# If the config subdirectory isn't there anymore, don't bother checking there +if test -d $basedir/config; then + if test -r $basedir/config/.config; then + config_in=$basedir/config/.config + fi + + if test -r $basedir/config/config.cache; then + config_cache_in=$basedir/config/config.cache + fi +fi + +# Last ditch effort...try ../.config +if test x"$config_in" = x; then + if test -r $basedir/../.config; then + config_in=$basedir/../.config + else + echo "Cannot find original .config file!" >&2 + exit 2 + fi +fi + +# Last ditch effort...try ../.config.cache +if test x"$config_cache_in" = x; then + if test -r $basedir/../.config.cache; then + config_cache_in=$basedir/../.config.cache + else + echo "Cannot find original config.cache file!" >&2 + exit 3 + fi +fi + +# Now load the two data files +echo "Loading old config.cache file $config_cache_in" +. $config_cache_in +echo "Loading old .config file $config_in" +. $config_in + +# Now we have to track down the defaults so we will know what to generate +# F-lines for +if test ! -r $basedir/ircd/ircd_features.c; then + echo "Cannot find default features!" >&2 + exit 4 +fi + +echo_n "Loading feature default values; please be patient... " +deb "" +features= +exec 4<$basedir/ircd/ircd_features.c +while read line <&4; do + # if a line has '(' but not ')', then we hang them until we find the + # matching ')'; this is not robust! + if test x"$hangline" != x; then + line="$hangline $line" + hangline= + fi + + if test x"`echo "$line" | grep '(' 2>/dev/null`" != x -a \ + x"`echo "$line" | grep ')' 2>/dev/null`" = x; then + hangline=$line + continue + fi + + # Now we process the line we read... + case $line in + \#*) # We want to ignore the #define, since it's a false positive + ;; + + F_[NIBS]*) # Found one of the feature define macros + type=`echo "$line" | sed -e 's/^F_\([NIBS]\).*$/\1/g'` + arglist=`echo "$line" | sed -e 's/^F_[NIBS](\(.*\)),.*/\1/g' \ + -e 's/ | /|/g'` + + # Now we must parse the arguments + tIFS=$IFS + IFS=,$IFS + name= + value= + argnum=0 + for arg in $arglist; do + case $type$argnum in + [NIBS]0) # First argument is always the name of the feature + name=$arg + ;; + + I2) # Second argument of F_I() is the numerical value + value=$arg + ;; + + B2) # Second argument of F_B() is a numerical value + # We must convert this numerical value to "y" or "n" + if test x"$arg" = x0; then + value=n + else + value=y + fi + ;; + + [ST]2) # Second argument of F_S() is a string value; must + # take into account unquoted possibilities, though + dequote=`echo "$arg" | sed -e 's/^"\(.*\)"$/\1/g'` + if test x"$dequote" = x"$arg"; then + type=T + value=$arg + else + value=$dequote + fi + ;; + esac + + # Next time through, we'll be testing the next argument + argnum=`expr $argnum + 1` + done + IFS=$tIFS + + deb "Loaded feature \"$name\" of type \"$type\"; default: \"$value\"" + + # Store the information we extracted + setvar type_$name $type + setvar def_$name "$value" + + # Keep a list of features we've checked + features="$features $name" + ;; + esac +done +exec 4<&- +echo "done" + +echo "Converting some options that are still compile-time" + +unet_cv_prefix=`echo $SPATH | sed -e 's@/bin/ircd@@g'` +deb "Installation directory (derived from SPATH)... $unet_cv_prefix" + +deb_n "Enable debugging (DEBUGMODE)... " +if test x"$DEBUGMODE" = xy; then + unet_cv_enable_debug=yes +else + unet_cv_enable_debug=no +fi +deb "$unet_cv_enable_debug" + +deb_n "Enable assertion checking (CONFIG_NDEBUG)... " +if test x"$CONFIG_NDEBUG" = xy; then + unet_cv_enable_asserts=yes +else + unet_cv_enable_asserts=no +fi +deb "$unet_cv_enable_asserts" + +deb_n "Force inlining of some critical functions (FORCEINLINE)... " +if test x"$FORCEINLINE" = xy; then + unet_cv_enable_inlines=yes +else + unet_cv_enable_inlines=no +fi +deb "$unet_cv_enable_inlines" + +unet_cv_with_symlink=$SYMLINK +deb "Symlink name (SYMLINK)... $unet_cv_with_symlink" + +unet_cv_with_mode=$IRCDMODE +deb "Binary permissions (IRCDMODE)... $unet_cv_with_mode" + +unet_cv_with_owner=$IRCDOWN +deb "Binary owner (IRCDOWN)... $unet_cv_with_owner" + +unet_cv_with_group=$IRCDGRP +deb "Binary group owner (IRCDGRP)... $unet_cv_with_group" + +unet_cv_with_domain=$DOMAINNAME +deb "Local domain name (DOMAINNAME)... $unet_cv_with_domain" + +deb_n "Enable CHROOT operation (CHROOTDIR)... " +if test x"$CHROOTDIR" = xy; then + deb_n "yes, path " + unet_cv_with_chroot=$DPATH +else + unet_cv_with_chroot=no +fi +deb "$unet_cv_with_chroot" + +unet_cv_with_dpath=$DPATH +deb "Data path (DPATH)... $unet_cv_with_dpath" + +unet_cv_with_cpath=$CPATH +deb "Configuration file (CPATH)... $unet_cv_with_cpath" + +# LPATH may not be set; if it's not, we'll just ignore it here and let +# ./configure fill it in appropriately +if test x"$LPATH" != x; then + unet_cv_with_lpath=$LPATH + deb "Debug log file (LPATH)... $unet_cv_with_lpath" +fi + +unet_cv_with_maxcon=$MAXCONNECTIONS +deb "Maximum number of connections (MAXCONNECTIONS)... $unet_cv_with_maxcon" + +# Shouldn't run ./configure before the transition script, but we can deal +if test -r "$cache_file"; then + echo "WARNING: Destroying new config.cache file $cache_file" >&2 + rm $cache_file +fi + +# Create the cache file... +echo "Creating new config.cache file $cache_file" +> $cache_file + +# This section is copied from a GNU autoconf-generated configure script +############################################################################### +cat > confcache <<\EOF +# This file is a shell script that caches the results of configure +# tests run on this system so they can be shared between configure +# scripts and configure runs. It is not useful on other systems. +# If it contains results you don't want to keep, you may remove or edit it. +# +# By default, configure uses ./config.cache as the cache file, +# creating it if it does not exist already. You can give configure +# the --cache-file=FILE option to use a different cache file; that is +# what configure does when it calls configure scripts in +# subdirectories, so they share the cache. +# Giving --cache-file=/dev/null disables caching, for debugging configure. +# config.status only pays attention to the cache file if you give it the +# --recheck option to rerun configure. +# +EOF +# The following way of writing the cache mishandles newlines in values, +# but we know of no workaround that is simple, portable, and efficient. +# So, don't put newlines in cache variables' values. +# Ultrix sh set writes to stderr and can't be redirected directly, +# and sets the high bit in the cache file unless we assign to the vars. +(set) 2>&1 | + case `(ac_space=' '; set | grep ac_space) 2>&1` in + *ac_space=\ *) + # `set' does not quote correctly, so add quotes (double-quote substitution + # turns \\\\ into \\, and sed turns \\ into \). + sed -n \ + -e "s/'/'\\\\''/g" \ + -e "s/^\\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\\)=\\(.*\\)/\\1=\${\\1='\\2'}/p" + ;; + *) + # `set' quotes correctly as required by POSIX, so do not add quotes. + sed -n -e 's/^\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\)=\(.*\)/\1=${\1=\2}/p' + ;; + esac >> confcache +if cmp -s $cache_file confcache; then + : +else + if test -w $cache_file; then + echo "updating cache $cache_file" + cat confcache > $cache_file + else + echo "not updating unwritable cache $cache_file" + fi +fi +rm -f confcache +############################################################################### + +# If they ran ./configure before, there'll be a config.status hanging around; +# if so, we can run that to integrate the config.cache we just generated. +if test -x $basedir/config.status; then + echo "Running $basedir/config.status to update configuration" + cwd=`pwd` + cd $basedir + # Have to run it twice to get the Makefile recreated + ./config.status --recheck + ./config.status + cd $cwd +fi + +# Now we need to track down ircd.conf so we can add the F-lines. +echo_n "Locating IRCD configuration file... " +case $unet_cv_with_cpath in +/*) # CPATH is absolute + conf_file=$unet_cv_with_cpath + ;; + +*) # CPATH is relative to DPATH + conf_file=$unet_cv_with_dpath/$unet_cv_with_cpath + ;; +esac +# suppress duplicate '/' +conf_file=`echo "$conf_file" | sed -e 's@//*@/@g'` +echo "$conf_file" + +# if we can't find the .conf, use "flines.conf" in the base directory (so +# they'll be easy to find). +if test ! -r $conf_file; then + fline_conf=yes + conf_file=$basedir/flines.conf + if test ! -r $conf_file; then + > $conf_file + fi + echo "WARNING: Unable to read ircd.conf; you will need to add the" >&2 + echo " F-lines manually. For your convenience, they will be" >&2 + echo " placed in $conf_file." >&2 +fi + +# here's where we take the old .config and compare it to the feature defaults +echo_n "Building feature table... " +for feature in $features; do + defval=`getvar def_$feature` + value=`getvar $feature` + + if test x"$value" = x -o x"$value" = x"$defval"; then + setvar FEAT_$feature $defval + else + setvar FEAT_$feature $value + fi +done + +# We won't add an F-line for DOMAINNAME, since (hopefully) the right one is +# already compiled in +FEAT_DOMAINNAME=DOMAINNAME + +# Have to make sure we have a RANDOM_SEED to enhance randomness... +FEAT_RANDOM_SEED=$RANDOM_SEED + +# This feature changed names to be consistent... +FEAT_OPER_LBADCHAN=$LOCAL_BADCHAN + +# DEFAULT_LIST_PARAM is perhaps the most complicated to transition, but +# this'll do the trick... +if test x"$CONFIG_LIST" = xy; then + FEAT_DEFAULT_LIST_PARAM=$DEFAULT_LIST_PARAM +else + FEAT_DEFAULT_LIST_PARAM=0 +fi + +echo "done" + +# Now we just generate the F-lines +echo_n "Generating F-lines... " +exec 4>>$conf_file + +# The various log files are set up first--these are all that were defined +# in u2.10.10.pl15 +if test x"$CONFIG_LOG_WHOX" = xy; then + echo "F:LOG:WHO:FILE:$WPATH" >&4 +fi +if test x"$CONFIG_LOG_GLINES" = xy; then + echo "F:LOG:GLINE:FILE:$GPATH" >&4 +fi +if test x"$CONFIG_LOG_USERS" = xy; then + echo "F:LOG:USER:FILE:$FNAME_USERLOG" >&4 +fi +if test x"$CONFIG_LOG_OPERS" = xy; then + echo "F:LOG:OPER:FILE:$FNAME_OPERLOG" >&4 +fi + +# Now we traverse the entire feature table and compare values with their +# defaults +for feature in $features; do + type=`getvar type_$feature` + defval=`getvar def_$feature` + value=`getvar FEAT_$feature` + + if test x"$defval" != x"$value"; then + if test x"$type" = xB; then + # Must map booleans yet again; I prefer TRUE/FALSE + if test x"$value" = xy; then + value=TRUE + else + value=FALSE + fi + fi + + # Write the F-line + echo "F:$feature:$value" >&4 + fi +done +exec 4>&- +echo "done" + +echo_n "Transition is complete." +if test ! -r $basedir/config.status; then + echo_n " You should now run ./configure." +fi + +echo "" + +if test x"$fline_conf" = xyes; then + echo "Don't forget to add the F-lines to your ircd.conf. They can be" + echo "found in $conf_file." +else + echo "Don't forget to verify the F-lines in your ircd.conf!" +fi Index: ircdh/tools/untabify diff -u /dev/null ircdh/tools/untabify:1.1 --- /dev/null Sat Jan 18 15:36:52 2003 +++ ircdh/tools/untabify Sat Jan 18 15:36:42 2003 @@ -0,0 +1,9 @@ +#!/usr/bin/perl +# +# untabify - convert tabs to spaces +# +# $Id: untabify,v 1.1 2003/01/18 23:36:42 zolty Exp $ +use Text::Tabs; +$tabstop = 8; +while (<>) { print expand($_) } + Index: ircdh/tools/wrapper.c diff -u /dev/null ircdh/tools/wrapper.c:1.1 --- /dev/null Sat Jan 18 15:36:52 2003 +++ ircdh/tools/wrapper.c Sat Jan 18 15:36:42 2003 @@ -0,0 +1,203 @@ +/* +** Copyright (C) 2000 by Kevin L. Mitchell <kl...@mi...> +** +** This program 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 2 of the License, or +** (at your option) any later version. +** +** This program 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, write to the Free Software +** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +** +** @(#)$Id: wrapper.c,v 1.1 2003/01/18 23:36:42 zolty Exp $ +*/ +#include <string.h> +#include <stdlib.h> +#include <stdio.h> +#include <pwd.h> +#include <grp.h> +#include <sys/time.h> +#include <sys/types.h> +#include <sys/resource.h> +#include <unistd.h> + +/* + * Try and find the correct name to use with getrlimit() for setting the max. + * number of files allowed to be open by this process. + * + * Shamelessly stolen from ircu... + */ +#ifdef RLIMIT_FDMAX +#define RLIMIT_FD_MAX RLIMIT_FDMAX +#else +#ifdef RLIMIT_NOFILE +#define RLIMIT_FD_MAX RLIMIT_NOFILE +#else +#ifdef RLIMIT_OPEN_MAX +#define RLIMIT_FD_MAX RLIMIT_OPEN_MAX +#else +#error Unable to find a valid RLIMIT_FD_MAX +#endif +#endif +#endif + +/* + * Set the hard and soft limits for maximum file descriptors. + */ +int +set_fdlimit(unsigned int max_descriptors) +{ + struct rlimit limit; + + limit.rlim_max = limit.rlim_cur = max_descriptors; + + return setrlimit(RLIMIT_FD_MAX, &limit); +} + +/* + * Change directories to the indicated root directory, then make it the + * root directory. + */ +int +change_root(char *root) +{ + if (chdir(root)) + return -1; + if (chroot(root)) + return -1; + + return 0; +} + +/* + * Change the user and group ids--including supplementary groups!--as + * appropriate. + */ +int +change_user(char *user, char *group) +{ + struct passwd *pwd; + struct group *grp; + char *tmp; + int uid, gid; + + /* Track down a struct passwd describing the desired user */ + uid = strtol(user, &tmp, 10); /* was the user given as a number? */ + if (*tmp) { /* strtol() failed to parse; look up as a user name */ + if (!(pwd = getpwnam(user))) + return -1; + } else if (!(pwd = getpwuid(uid))) /* look up uid */ + return -1; + + uid = pwd->pw_uid; /* uid to change to */ + gid = pwd->pw_gid; /* default gid for user */ + + if (group) { /* a group was specified; track down struct group */ + gid = strtol(group, &tmp, 10); /* was the group given as a number? */ + if (*tmp) { /* strtol() failed to parse; look up as a group name */ + if (!(grp = getgrnam(group))) + return -1; + } else if (!(grp = getgrgid(gid))) /* look up gid */ + return -1; + + gid = grp->gr_gid; /* set the gid */ + } + + if (initgroups(pwd->pw_name, gid)) /* initialize supplementary groups */ + return -1; + if (setgid(gid)) /* change our current group */ + return -1; + if (setuid(uid)) /* change our current user */ + return -1; + + return 0; /* success! */ +} + +/* + * Explain how to use this program. + */ +void +usage(char *prog, int retval) +{ + fprintf(stderr, "Usage: %s [-u <user>] [-g <group>] [-l <limit>] [-c <root>]" + " -- \\\n\t\t<cmd> [<cmdargs>]\n", prog); + fprintf(stderr, " %s -h\n", prog); + + exit(retval); +} + +int +main(int argc, char **argv) +{ + int c, limit = -1; + char *prog, *user = 0, *group = 0, *root = 0; + + /* determine program name for error reporting */ + if ((prog = strrchr(argv[0], '/'))) + prog++; + else + prog = argv[0]; + + /* process command line arguments */ + while ((c = getopt(argc, argv, "hu:g:l:c:")) > 0) + switch (c) { + case 'h': /* requested help */ + usage(prog, 0); + break; + + case 'u': /* suggested a user */ + user = optarg; + break; + + case 'g': /* suggested a group */ + group = optarg; + break; + + case 'l': /* file descriptor limit */ + limit = strtol(optarg, 0, 10); + break; + + case 'c': /* select a root directory */ + root = optarg; + break; + + default: /* unknown command line argument */ + usage(prog, 1); + break; + } + + /* Not enough arguments; we must have a command to execute! */ + if (optind >= argc) + usage(prog, 1); + + if (limit > 0) /* set the requested fd limit */ + if (set_fdlimit(limit) < 0) { + perror(prog); + return 1; + } + + if (root) /* change root directories */ + if (change_root(root)) { + perror(prog); + return 1; + } + + if (user) /* change to selected user account */ + if (change_user(user, group)) { + perror(prog); + return 1; + } + + /* execute the requested command */ + execvp(argv[optind], argv + optind); + + /* If we got here, execvp() failed; report the error */ + perror(prog); + return 1; +} ----------------------- End of diff ----------------------- |