From a2cd649cc8291d89128b2b7abbf50855fa96403f Mon Sep 17 00:00:00 2001 From: Michael Poole Date: Wed, 15 Aug 2007 01:15:53 +0000 Subject: [PATCH] Consistently rebuild version.c; optimize how it is generated. git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/branches/u2_10_12_branch@1831 c9e4aea6-c8fd-4c43-8297-357d70d61c8c --- ircd/Makefile.in | 16 +++-------- ircd/umkpasswd.c | 68 ++++++++++++++++++++++------------------------- ircd/version.c.SH | 20 +++++--------- 3 files changed, 41 insertions(+), 63 deletions(-) diff --git a/ircd/Makefile.in b/ircd/Makefile.in index 027fd6e..a75a218 100644 --- a/ircd/Makefile.in +++ b/ircd/Makefile.in @@ -242,18 +242,8 @@ ircd: ${OBJS} ../include/patchlevel.h version.o convert-conf: ${CONVERT_CONF_OBJS} ${PURIFY} ${CC} ${CONVERT_CONF_OBJS} ${LDFLAGS} -o convert-conf -# -# Make sure the anti hack checksums get included when things change -# bleah -# -# Yeah, "bleah" is right. These checksums don't cover even a fraction of -# the "important" .c files...but are useful to determine whether someone -# actually is running the version they claim to be running or not. There -# must be a better solution...perhaps sum all of the .c files and include -# only that one sum? -# -version.c: ../include/patchlist.h version.c.SH umkpasswd \ - ../include/version.h ../include/patchlevel.h ${SRC} +.PHONY: version.c +version.c: version.c.SH umkpasswd ${SHELL} ${srcdir}/version.c.SH ${top_srcdir} ../include/patchlist.h: @@ -322,7 +312,7 @@ uninstall: @echo "Please remove the contents of ${DPATH} manually" clean: - ${RM} -f *.o *.bak ircd version.c umkpasswd convert-conf chattr.tab.c table_gen y.tab.* lex.yy.* + ${RM} -f *.o *.bak ircd umkpasswd convert-conf chattr.tab.c table_gen y.tab.* lex.yy.* distclean: clean ${RM} -f Makefile stamp-m diff --git a/ircd/umkpasswd.c b/ircd/umkpasswd.c index d3ef4e5..29014a1 100644 --- a/ircd/umkpasswd.c +++ b/ircd/umkpasswd.c @@ -20,6 +20,7 @@ */ #include "config.h" #include +#include #include #include #include @@ -181,54 +182,46 @@ crypt_mechs_t* crypt_mech; return 0; } -char *basename_into(char *tmp, char *target) -{ - unsigned int len, ii; - - len = strlen(tmp); - for (ii = len; ii > 0; ) - if (tmp[--ii] == '/') - break; - if (ii < len - 1) - return tmp + ii + (tmp[ii] == '/'); - else if (tmp[ii] != '/') - return tmp; - else if (ii == 0) - return tmp; - else - { - while (ii > 0) - if (tmp[--ii] == '/') - break; - if (tmp[ii] == '/') - ii++; - for (len = 0; tmp[ii] != '/'; ) - target[len++] = tmp[ii++]; - target[len] = '\0'; - return target; - } -} - void sum(char* tmp) { +char* str; FILE* file; MD5_CTX context; int len; -unsigned char buffer[1024], digest[16]; +unsigned char buffer[1024], digest[16], vstr[32]; +vstr[0] = '\0'; + str = tmp + strlen(tmp); + while (str[-1] == '\r' || str[-1] == '\n') *--str = '\0'; if (NULL == (file = fopen(tmp, "r"))) + { + fprintf(stderr, "unable to open %s: %s", tmp, strerror(errno)); exit(0); + } MD5Init(&context); - while ((len = fread (buffer, 1, 1024, file))) + while ((fgets((char*)buffer, sizeof(buffer), file)) != NULL) + { + MD5Update(&context, buffer, strlen(buffer)); + str = strstr((char*)buffer, "$Id: "); + if (str != NULL) + { + for (str += 5; !isspace(*str); ++str) {} + while (isspace(*++str)) {} + for (len = 0; !isspace(str[len]); ++len) vstr[len] = str[len]; + vstr[len] = '\0'; + break; + } + } + while ((len = fread (buffer, 1, sizeof(buffer), file))) MD5Update(&context, buffer, len); MD5Final(digest, &context); fclose(file); - printf("%s: ", basename_into(tmp, (char*)buffer)); + str = strrchr(tmp, '/'); + printf(" \"[ %s: ", str ? (str + 1) : tmp); for (len = 0; len < 16; len++) printf ("%02x", digest[len]); - printf("\n"); - exit(0); + printf(" %s ]\",\n", vstr); } /* dump the loaded mechs list */ @@ -321,7 +314,7 @@ return tagged; char* parse_arguments(int argc, char **argv) { int len = 0, c = 0; -const char* options = "a:d:lm:u:y:5:"; +const char* options = "a:d:lm:u:y:5"; umkpasswd_conf = (umkpasswd_conf_t*)MyMalloc(sizeof(umkpasswd_conf_t)); @@ -346,8 +339,11 @@ const char* options = "a:d:lm:u:y:5:"; switch (c) { case '5': - sum(optarg); - break; + { + char t1[1024]; + while (fgets(t1, sizeof(t1), stdin)) sum(t1); + } + exit(0); case 'y': umkpasswd_conf->operclass = atoi(optarg); diff --git a/ircd/version.c.SH b/ircd/version.c.SH index 0e87370..03c02c3 100644 --- a/ircd/version.c.SH +++ b/ircd/version.c.SH @@ -85,24 +85,16 @@ const char *infotext[] = { "Sources:", !SUB!THIS! -for file in ${srcdir}/ircd/*.[cly] ${srcdir}/ircd/version.c.SH ; do - base=`basename $file` - if [ $base != version.c -a $base != y.tab.c -a $base != lex.yy.c -a \ - $base != chattr.tab.c ] ; then - vers=`grep '$Id' $file | sed -e 's/.*\$Id\://' -e 's/\$[^$]*//' | \ - awk '{ print $2; exit; }'` - echo " \"[" `./umkpasswd -5 $file` " $vers ]\"," >> version.c - fi -done +( for file in ${srcdir}/ircd/*.[cly] ${srcdir}/ircd/version.c.SH ; do + case `basename $file` in + ( version.c | y.tab.c | lex.yy.c | chattr.tab.c ) ;; + ( * ) echo $file ;; + esac done ) | ./umkpasswd -5 >> version.c echo " \"\"," >> version.c echo " \"Headers:\"," >> version.c -for file in ${srcdir}/include/*.h ; do - vers=`grep '$Id' $file | sed -e 's/.*\$Id\://' -e 's/\$[^$]*//' | \ - awk '{ print $2; exit; }'` - echo " \"[" `./umkpasswd -5 $file` " $vers ]\"," >> version.c -done +( for file in ${srcdir}/include/*.h ; do echo $file ; done ) | ./umkpasswd -5 >> version.c /bin/cat >>version.c <