X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=ircd%2Fumkpasswd.c;h=30d4130af6e09f878a3ca164a5570144683820e9;hb=refs%2Fheads%2Fupstream;hp=a259542d6b155af6c62d10c74ffbeff341542b89;hpb=ab4e884857268d2746f27f6bcd6af250f89c3f90;p=ircu2.10.12-pk.git diff --git a/ircd/umkpasswd.c b/ircd/umkpasswd.c index a259542..30d4130 100644 --- a/ircd/umkpasswd.c +++ b/ircd/umkpasswd.c @@ -20,6 +20,7 @@ */ #include "config.h" #include +#include #include #include #include @@ -120,7 +121,7 @@ char *make_salt(const char *salts) char *tmp = NULL; long int n = 0; - /* try and get around them running this time after time in quick sucession */ + /* try and get around them running this time after time in quick succession */ sleep(1); srandom((unsigned int)time(NULL)); @@ -140,12 +141,12 @@ long int n = 0; return tmp; } -/* our implemenation of ircd_crypt_register_mech() */ +/* our implementation of ircd_crypt_register_mech() */ int ircd_crypt_register_mech(crypt_mech_t* mechanism) { crypt_mechs_t* crypt_mech; - Debug((DEBUG_INFO, "ircd_crypt_register_mech: resistering mechanism: %s", mechanism->shortname)); + Debug((DEBUG_INFO, "ircd_crypt_register_mech: registering mechanism: %s", mechanism->shortname)); /* try to allocate some memory for the new mechanism */ if ((crypt_mech = (crypt_mechs_t*)MyMalloc(sizeof(crypt_mechs_t))) == NULL) @@ -175,60 +176,52 @@ crypt_mechs_t* crypt_mech; } /* we're done */ - Debug((DEBUG_INFO, "ircd_crypt_register_mech: resistered mechanism: %s, crypt_function is at 0x%X.", crypt_mech->mech->shortname, &crypt_mech->mech->crypt_function)); + Debug((DEBUG_INFO, "ircd_crypt_register_mech: registered mechanism: %s, crypt_function is at 0x%X.", crypt_mech->mech->shortname, &crypt_mech->mech->crypt_function)); Debug((DEBUG_INFO, "ircd_crypt_register_mech: %s: %s", crypt_mech->mech->shortname, crypt_mech->mech->description)); 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((char*)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 */ @@ -310,7 +303,7 @@ char* salt, *untagged, *tagged; salt = make_salt(default_salts); untagged = (char *)CryptFunc(crypt_mech->mech)(pw, salt); - tagged = (char *)MyMalloc(strlen(salt)+CryptTokSize(crypt_mech->mech)+1); + tagged = (char *)MyMalloc(strlen(untagged)+CryptTokSize(crypt_mech->mech)+1); memset(tagged, 0, strlen(untagged)+CryptTokSize(crypt_mech->mech)+1); strncpy(tagged, CryptTok(crypt_mech->mech), CryptTokSize(crypt_mech->mech)); strncpy(tagged+CryptTokSize(crypt_mech->mech), untagged, strlen(untagged)); @@ -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); @@ -356,9 +352,9 @@ const char* options = "a:d:lm:u:y:5:"; break; case 'u': - if(umkpasswd_conf->flags && ACT_UPDOPER) + if(umkpasswd_conf->flags & ACT_ADDOPER) { - fprintf(stderr, "-a and -u are mutually exclussive. Use either or neither.\n"); + fprintf(stderr, "-a and -u are mutually exclusive. Use either or neither.\n"); abort(); /* b0rk b0rk b0rk */ } @@ -387,9 +383,9 @@ const char* options = "a:d:lm:u:y:5:"; break; case 'a': - if(umkpasswd_conf->flags && ACT_UPDOPER) + if(umkpasswd_conf->flags & ACT_UPDOPER) { - fprintf(stderr, "-a and -u are mutually exclussive. Use either or neither.\n"); + fprintf(stderr, "-a and -u are mutually exclusive. Use either or neither.\n"); abort(); /* b0rk b0rk b0rk */ } @@ -400,7 +396,7 @@ const char* options = "a:d:lm:u:y:5:"; default: /* unknown option - spit out syntax and b0rk */ show_help(); - abort(); + exit(1); break; } }