11da177e4SLinus Torvalds #include <netinet/in.h> 21da177e4SLinus Torvalds #ifdef __sun__ 31da177e4SLinus Torvalds #include <inttypes.h> 41da177e4SLinus Torvalds #else 51da177e4SLinus Torvalds #include <stdint.h> 61da177e4SLinus Torvalds #endif 71da177e4SLinus Torvalds #include <ctype.h> 81da177e4SLinus Torvalds #include <errno.h> 91da177e4SLinus Torvalds #include <string.h> 10fc31c771SMike Frysinger #include <limits.h> 111da177e4SLinus Torvalds #include "modpost.h" 121da177e4SLinus Torvalds 131da177e4SLinus Torvalds /* 141da177e4SLinus Torvalds * Stolen form Cryptographic API. 151da177e4SLinus Torvalds * 161da177e4SLinus Torvalds * MD4 Message Digest Algorithm (RFC1320). 171da177e4SLinus Torvalds * 181da177e4SLinus Torvalds * Implementation derived from Andrew Tridgell and Steve French's 191da177e4SLinus Torvalds * CIFS MD4 implementation, and the cryptoapi implementation 201da177e4SLinus Torvalds * originally based on the public domain implementation written 211da177e4SLinus Torvalds * by Colin Plumb in 1993. 221da177e4SLinus Torvalds * 231da177e4SLinus Torvalds * Copyright (c) Andrew Tridgell 1997-1998. 241da177e4SLinus Torvalds * Modified by Steve French (sfrench@us.ibm.com) 2002 251da177e4SLinus Torvalds * Copyright (c) Cryptoapi developers. 261da177e4SLinus Torvalds * Copyright (c) 2002 David S. Miller (davem@redhat.com) 271da177e4SLinus Torvalds * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> 281da177e4SLinus Torvalds * 291da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify 301da177e4SLinus Torvalds * it under the terms of the GNU General Public License as published by 311da177e4SLinus Torvalds * the Free Software Foundation; either version 2 of the License, or 321da177e4SLinus Torvalds * (at your option) any later version. 331da177e4SLinus Torvalds * 341da177e4SLinus Torvalds */ 351da177e4SLinus Torvalds #define MD4_DIGEST_SIZE 16 361da177e4SLinus Torvalds #define MD4_HMAC_BLOCK_SIZE 64 371da177e4SLinus Torvalds #define MD4_BLOCK_WORDS 16 381da177e4SLinus Torvalds #define MD4_HASH_WORDS 4 391da177e4SLinus Torvalds 401da177e4SLinus Torvalds struct md4_ctx { 411da177e4SLinus Torvalds uint32_t hash[MD4_HASH_WORDS]; 421da177e4SLinus Torvalds uint32_t block[MD4_BLOCK_WORDS]; 431da177e4SLinus Torvalds uint64_t byte_count; 441da177e4SLinus Torvalds }; 451da177e4SLinus Torvalds 461da177e4SLinus Torvalds static inline uint32_t lshift(uint32_t x, unsigned int s) 471da177e4SLinus Torvalds { 481da177e4SLinus Torvalds x &= 0xFFFFFFFF; 491da177e4SLinus Torvalds return ((x << s) & 0xFFFFFFFF) | (x >> (32 - s)); 501da177e4SLinus Torvalds } 511da177e4SLinus Torvalds 521da177e4SLinus Torvalds static inline uint32_t F(uint32_t x, uint32_t y, uint32_t z) 531da177e4SLinus Torvalds { 541da177e4SLinus Torvalds return (x & y) | ((~x) & z); 551da177e4SLinus Torvalds } 561da177e4SLinus Torvalds 571da177e4SLinus Torvalds static inline uint32_t G(uint32_t x, uint32_t y, uint32_t z) 581da177e4SLinus Torvalds { 591da177e4SLinus Torvalds return (x & y) | (x & z) | (y & z); 601da177e4SLinus Torvalds } 611da177e4SLinus Torvalds 621da177e4SLinus Torvalds static inline uint32_t H(uint32_t x, uint32_t y, uint32_t z) 631da177e4SLinus Torvalds { 641da177e4SLinus Torvalds return x ^ y ^ z; 651da177e4SLinus Torvalds } 661da177e4SLinus Torvalds 671da177e4SLinus Torvalds #define ROUND1(a,b,c,d,k,s) (a = lshift(a + F(b,c,d) + k, s)) 681da177e4SLinus Torvalds #define ROUND2(a,b,c,d,k,s) (a = lshift(a + G(b,c,d) + k + (uint32_t)0x5A827999,s)) 691da177e4SLinus Torvalds #define ROUND3(a,b,c,d,k,s) (a = lshift(a + H(b,c,d) + k + (uint32_t)0x6ED9EBA1,s)) 701da177e4SLinus Torvalds 711da177e4SLinus Torvalds /* XXX: this stuff can be optimized */ 721da177e4SLinus Torvalds static inline void le32_to_cpu_array(uint32_t *buf, unsigned int words) 731da177e4SLinus Torvalds { 741da177e4SLinus Torvalds while (words--) { 751da177e4SLinus Torvalds *buf = ntohl(*buf); 761da177e4SLinus Torvalds buf++; 771da177e4SLinus Torvalds } 781da177e4SLinus Torvalds } 791da177e4SLinus Torvalds 801da177e4SLinus Torvalds static inline void cpu_to_le32_array(uint32_t *buf, unsigned int words) 811da177e4SLinus Torvalds { 821da177e4SLinus Torvalds while (words--) { 831da177e4SLinus Torvalds *buf = htonl(*buf); 841da177e4SLinus Torvalds buf++; 851da177e4SLinus Torvalds } 861da177e4SLinus Torvalds } 871da177e4SLinus Torvalds 881da177e4SLinus Torvalds static void md4_transform(uint32_t *hash, uint32_t const *in) 891da177e4SLinus Torvalds { 901da177e4SLinus Torvalds uint32_t a, b, c, d; 911da177e4SLinus Torvalds 921da177e4SLinus Torvalds a = hash[0]; 931da177e4SLinus Torvalds b = hash[1]; 941da177e4SLinus Torvalds c = hash[2]; 951da177e4SLinus Torvalds d = hash[3]; 961da177e4SLinus Torvalds 971da177e4SLinus Torvalds ROUND1(a, b, c, d, in[0], 3); 981da177e4SLinus Torvalds ROUND1(d, a, b, c, in[1], 7); 991da177e4SLinus Torvalds ROUND1(c, d, a, b, in[2], 11); 1001da177e4SLinus Torvalds ROUND1(b, c, d, a, in[3], 19); 1011da177e4SLinus Torvalds ROUND1(a, b, c, d, in[4], 3); 1021da177e4SLinus Torvalds ROUND1(d, a, b, c, in[5], 7); 1031da177e4SLinus Torvalds ROUND1(c, d, a, b, in[6], 11); 1041da177e4SLinus Torvalds ROUND1(b, c, d, a, in[7], 19); 1051da177e4SLinus Torvalds ROUND1(a, b, c, d, in[8], 3); 1061da177e4SLinus Torvalds ROUND1(d, a, b, c, in[9], 7); 1071da177e4SLinus Torvalds ROUND1(c, d, a, b, in[10], 11); 1081da177e4SLinus Torvalds ROUND1(b, c, d, a, in[11], 19); 1091da177e4SLinus Torvalds ROUND1(a, b, c, d, in[12], 3); 1101da177e4SLinus Torvalds ROUND1(d, a, b, c, in[13], 7); 1111da177e4SLinus Torvalds ROUND1(c, d, a, b, in[14], 11); 1121da177e4SLinus Torvalds ROUND1(b, c, d, a, in[15], 19); 1131da177e4SLinus Torvalds 1141da177e4SLinus Torvalds ROUND2(a, b, c, d,in[ 0], 3); 1151da177e4SLinus Torvalds ROUND2(d, a, b, c, in[4], 5); 1161da177e4SLinus Torvalds ROUND2(c, d, a, b, in[8], 9); 1171da177e4SLinus Torvalds ROUND2(b, c, d, a, in[12], 13); 1181da177e4SLinus Torvalds ROUND2(a, b, c, d, in[1], 3); 1191da177e4SLinus Torvalds ROUND2(d, a, b, c, in[5], 5); 1201da177e4SLinus Torvalds ROUND2(c, d, a, b, in[9], 9); 1211da177e4SLinus Torvalds ROUND2(b, c, d, a, in[13], 13); 1221da177e4SLinus Torvalds ROUND2(a, b, c, d, in[2], 3); 1231da177e4SLinus Torvalds ROUND2(d, a, b, c, in[6], 5); 1241da177e4SLinus Torvalds ROUND2(c, d, a, b, in[10], 9); 1251da177e4SLinus Torvalds ROUND2(b, c, d, a, in[14], 13); 1261da177e4SLinus Torvalds ROUND2(a, b, c, d, in[3], 3); 1271da177e4SLinus Torvalds ROUND2(d, a, b, c, in[7], 5); 1281da177e4SLinus Torvalds ROUND2(c, d, a, b, in[11], 9); 1291da177e4SLinus Torvalds ROUND2(b, c, d, a, in[15], 13); 1301da177e4SLinus Torvalds 1311da177e4SLinus Torvalds ROUND3(a, b, c, d,in[ 0], 3); 1321da177e4SLinus Torvalds ROUND3(d, a, b, c, in[8], 9); 1331da177e4SLinus Torvalds ROUND3(c, d, a, b, in[4], 11); 1341da177e4SLinus Torvalds ROUND3(b, c, d, a, in[12], 15); 1351da177e4SLinus Torvalds ROUND3(a, b, c, d, in[2], 3); 1361da177e4SLinus Torvalds ROUND3(d, a, b, c, in[10], 9); 1371da177e4SLinus Torvalds ROUND3(c, d, a, b, in[6], 11); 1381da177e4SLinus Torvalds ROUND3(b, c, d, a, in[14], 15); 1391da177e4SLinus Torvalds ROUND3(a, b, c, d, in[1], 3); 1401da177e4SLinus Torvalds ROUND3(d, a, b, c, in[9], 9); 1411da177e4SLinus Torvalds ROUND3(c, d, a, b, in[5], 11); 1421da177e4SLinus Torvalds ROUND3(b, c, d, a, in[13], 15); 1431da177e4SLinus Torvalds ROUND3(a, b, c, d, in[3], 3); 1441da177e4SLinus Torvalds ROUND3(d, a, b, c, in[11], 9); 1451da177e4SLinus Torvalds ROUND3(c, d, a, b, in[7], 11); 1461da177e4SLinus Torvalds ROUND3(b, c, d, a, in[15], 15); 1471da177e4SLinus Torvalds 1481da177e4SLinus Torvalds hash[0] += a; 1491da177e4SLinus Torvalds hash[1] += b; 1501da177e4SLinus Torvalds hash[2] += c; 1511da177e4SLinus Torvalds hash[3] += d; 1521da177e4SLinus Torvalds } 1531da177e4SLinus Torvalds 1541da177e4SLinus Torvalds static inline void md4_transform_helper(struct md4_ctx *ctx) 1551da177e4SLinus Torvalds { 1561da177e4SLinus Torvalds le32_to_cpu_array(ctx->block, sizeof(ctx->block) / sizeof(uint32_t)); 1571da177e4SLinus Torvalds md4_transform(ctx->hash, ctx->block); 1581da177e4SLinus Torvalds } 1591da177e4SLinus Torvalds 1601da177e4SLinus Torvalds static void md4_init(struct md4_ctx *mctx) 1611da177e4SLinus Torvalds { 1621da177e4SLinus Torvalds mctx->hash[0] = 0x67452301; 1631da177e4SLinus Torvalds mctx->hash[1] = 0xefcdab89; 1641da177e4SLinus Torvalds mctx->hash[2] = 0x98badcfe; 1651da177e4SLinus Torvalds mctx->hash[3] = 0x10325476; 1661da177e4SLinus Torvalds mctx->byte_count = 0; 1671da177e4SLinus Torvalds } 1681da177e4SLinus Torvalds 1691da177e4SLinus Torvalds static void md4_update(struct md4_ctx *mctx, 1701da177e4SLinus Torvalds const unsigned char *data, unsigned int len) 1711da177e4SLinus Torvalds { 1721da177e4SLinus Torvalds const uint32_t avail = sizeof(mctx->block) - (mctx->byte_count & 0x3f); 1731da177e4SLinus Torvalds 1741da177e4SLinus Torvalds mctx->byte_count += len; 1751da177e4SLinus Torvalds 1761da177e4SLinus Torvalds if (avail > len) { 1771da177e4SLinus Torvalds memcpy((char *)mctx->block + (sizeof(mctx->block) - avail), 1781da177e4SLinus Torvalds data, len); 1791da177e4SLinus Torvalds return; 1801da177e4SLinus Torvalds } 1811da177e4SLinus Torvalds 1821da177e4SLinus Torvalds memcpy((char *)mctx->block + (sizeof(mctx->block) - avail), 1831da177e4SLinus Torvalds data, avail); 1841da177e4SLinus Torvalds 1851da177e4SLinus Torvalds md4_transform_helper(mctx); 1861da177e4SLinus Torvalds data += avail; 1871da177e4SLinus Torvalds len -= avail; 1881da177e4SLinus Torvalds 1891da177e4SLinus Torvalds while (len >= sizeof(mctx->block)) { 1901da177e4SLinus Torvalds memcpy(mctx->block, data, sizeof(mctx->block)); 1911da177e4SLinus Torvalds md4_transform_helper(mctx); 1921da177e4SLinus Torvalds data += sizeof(mctx->block); 1931da177e4SLinus Torvalds len -= sizeof(mctx->block); 1941da177e4SLinus Torvalds } 1951da177e4SLinus Torvalds 1961da177e4SLinus Torvalds memcpy(mctx->block, data, len); 1971da177e4SLinus Torvalds } 1981da177e4SLinus Torvalds 1991da177e4SLinus Torvalds static void md4_final_ascii(struct md4_ctx *mctx, char *out, unsigned int len) 2001da177e4SLinus Torvalds { 2011da177e4SLinus Torvalds const unsigned int offset = mctx->byte_count & 0x3f; 2021da177e4SLinus Torvalds char *p = (char *)mctx->block + offset; 2031da177e4SLinus Torvalds int padding = 56 - (offset + 1); 2041da177e4SLinus Torvalds 2051da177e4SLinus Torvalds *p++ = 0x80; 2061da177e4SLinus Torvalds if (padding < 0) { 2071da177e4SLinus Torvalds memset(p, 0x00, padding + sizeof (uint64_t)); 2081da177e4SLinus Torvalds md4_transform_helper(mctx); 2091da177e4SLinus Torvalds p = (char *)mctx->block; 2101da177e4SLinus Torvalds padding = 56; 2111da177e4SLinus Torvalds } 2121da177e4SLinus Torvalds 2131da177e4SLinus Torvalds memset(p, 0, padding); 2141da177e4SLinus Torvalds mctx->block[14] = mctx->byte_count << 3; 2151da177e4SLinus Torvalds mctx->block[15] = mctx->byte_count >> 29; 2161da177e4SLinus Torvalds le32_to_cpu_array(mctx->block, (sizeof(mctx->block) - 2171da177e4SLinus Torvalds sizeof(uint64_t)) / sizeof(uint32_t)); 2181da177e4SLinus Torvalds md4_transform(mctx->hash, mctx->block); 2191da177e4SLinus Torvalds cpu_to_le32_array(mctx->hash, sizeof(mctx->hash) / sizeof(uint32_t)); 2201da177e4SLinus Torvalds 2211da177e4SLinus Torvalds snprintf(out, len, "%08X%08X%08X%08X", 2221da177e4SLinus Torvalds mctx->hash[0], mctx->hash[1], mctx->hash[2], mctx->hash[3]); 2231da177e4SLinus Torvalds } 2241da177e4SLinus Torvalds 2251da177e4SLinus Torvalds static inline void add_char(unsigned char c, struct md4_ctx *md) 2261da177e4SLinus Torvalds { 2271da177e4SLinus Torvalds md4_update(md, &c, 1); 2281da177e4SLinus Torvalds } 2291da177e4SLinus Torvalds 2301da177e4SLinus Torvalds static int parse_string(const char *file, unsigned long len, 2311da177e4SLinus Torvalds struct md4_ctx *md) 2321da177e4SLinus Torvalds { 2331da177e4SLinus Torvalds unsigned long i; 2341da177e4SLinus Torvalds 2351da177e4SLinus Torvalds add_char(file[0], md); 2361da177e4SLinus Torvalds for (i = 1; i < len; i++) { 2371da177e4SLinus Torvalds add_char(file[i], md); 2381da177e4SLinus Torvalds if (file[i] == '"' && file[i-1] != '\\') 2391da177e4SLinus Torvalds break; 2401da177e4SLinus Torvalds } 2411da177e4SLinus Torvalds return i; 2421da177e4SLinus Torvalds } 2431da177e4SLinus Torvalds 2441da177e4SLinus Torvalds static int parse_comment(const char *file, unsigned long len) 2451da177e4SLinus Torvalds { 2461da177e4SLinus Torvalds unsigned long i; 2471da177e4SLinus Torvalds 2481da177e4SLinus Torvalds for (i = 2; i < len; i++) { 2491da177e4SLinus Torvalds if (file[i-1] == '*' && file[i] == '/') 2501da177e4SLinus Torvalds break; 2511da177e4SLinus Torvalds } 2521da177e4SLinus Torvalds return i; 2531da177e4SLinus Torvalds } 2541da177e4SLinus Torvalds 2551da177e4SLinus Torvalds /* FIXME: Handle .s files differently (eg. # starts comments) --RR */ 25661d9cdf2SJ.A. Magallon static int parse_file(const char *fname, struct md4_ctx *md) 2571da177e4SLinus Torvalds { 25861d9cdf2SJ.A. Magallon char *file; 2591da177e4SLinus Torvalds unsigned long i, len; 2601da177e4SLinus Torvalds 2617c8f5662SMasahiro Yamada file = read_text_file(fname); 2627c8f5662SMasahiro Yamada len = strlen(file); 2631da177e4SLinus Torvalds 2641da177e4SLinus Torvalds for (i = 0; i < len; i++) { 2651da177e4SLinus Torvalds /* Collapse and ignore \ and CR. */ 2661da177e4SLinus Torvalds if (file[i] == '\\' && (i+1 < len) && file[i+1] == '\n') { 2671da177e4SLinus Torvalds i++; 2681da177e4SLinus Torvalds continue; 2691da177e4SLinus Torvalds } 2701da177e4SLinus Torvalds 2711da177e4SLinus Torvalds /* Ignore whitespace */ 2721da177e4SLinus Torvalds if (isspace(file[i])) 2731da177e4SLinus Torvalds continue; 2741da177e4SLinus Torvalds 2751da177e4SLinus Torvalds /* Handle strings as whole units */ 2761da177e4SLinus Torvalds if (file[i] == '"') { 2771da177e4SLinus Torvalds i += parse_string(file+i, len - i, md); 2781da177e4SLinus Torvalds continue; 2791da177e4SLinus Torvalds } 2801da177e4SLinus Torvalds 2811da177e4SLinus Torvalds /* Comments: ignore */ 2821da177e4SLinus Torvalds if (file[i] == '/' && file[i+1] == '*') { 2831da177e4SLinus Torvalds i += parse_comment(file+i, len - i); 2841da177e4SLinus Torvalds continue; 2851da177e4SLinus Torvalds } 2861da177e4SLinus Torvalds 2871da177e4SLinus Torvalds add_char(file[i], md); 2881da177e4SLinus Torvalds } 2897c8f5662SMasahiro Yamada free(file); 2901da177e4SLinus Torvalds return 1; 2911da177e4SLinus Torvalds } 292e6e6733eSAshutosh Naik /* Check whether the file is a static library or not */ 293e6e6733eSAshutosh Naik static int is_static_library(const char *objfile) 294e6e6733eSAshutosh Naik { 295e6e6733eSAshutosh Naik int len = strlen(objfile); 296e6e6733eSAshutosh Naik if (objfile[len - 2] == '.' && objfile[len - 1] == 'a') 297e6e6733eSAshutosh Naik return 1; 298e6e6733eSAshutosh Naik else 299e6e6733eSAshutosh Naik return 0; 300e6e6733eSAshutosh Naik } 3011da177e4SLinus Torvalds 3027840fea2SMichal Marek /* We have dir/file.o. Open dir/.file.o.cmd, look for source_ and deps_ line 3037840fea2SMichal Marek * to figure out source files. */ 3041da177e4SLinus Torvalds static int parse_source_files(const char *objfile, struct md4_ctx *md) 3051da177e4SLinus Torvalds { 30670f30cfeSMasahiro Yamada char *cmd, *file, *line, *dir, *pos; 3071da177e4SLinus Torvalds const char *base; 3081da177e4SLinus Torvalds int dirlen, ret = 0, check_files = 0; 3091da177e4SLinus Torvalds 3101da177e4SLinus Torvalds cmd = NOFAIL(malloc(strlen(objfile) + sizeof("..cmd"))); 3111da177e4SLinus Torvalds 3121da177e4SLinus Torvalds base = strrchr(objfile, '/'); 3131da177e4SLinus Torvalds if (base) { 3141da177e4SLinus Torvalds base++; 3151da177e4SLinus Torvalds dirlen = base - objfile; 3161da177e4SLinus Torvalds sprintf(cmd, "%.*s.%s.cmd", dirlen, objfile, base); 3171da177e4SLinus Torvalds } else { 3181da177e4SLinus Torvalds dirlen = 0; 3191da177e4SLinus Torvalds sprintf(cmd, ".%s.cmd", objfile); 3201da177e4SLinus Torvalds } 3211da177e4SLinus Torvalds dir = NOFAIL(malloc(dirlen + 1)); 3221da177e4SLinus Torvalds strncpy(dir, objfile, dirlen); 3231da177e4SLinus Torvalds dir[dirlen] = '\0'; 3241da177e4SLinus Torvalds 32570f30cfeSMasahiro Yamada file = read_text_file(cmd); 32670f30cfeSMasahiro Yamada 32770f30cfeSMasahiro Yamada pos = file; 3281da177e4SLinus Torvalds 3299fc34767SRasmus Villemoes /* Sum all files in the same dir or subdirs. */ 33070f30cfeSMasahiro Yamada while ((line = get_line(&pos))) { 33161d9cdf2SJ.A. Magallon char* p = line; 3327840fea2SMichal Marek 3337840fea2SMichal Marek if (strncmp(line, "source_", sizeof("source_")-1) == 0) { 3347840fea2SMichal Marek p = strrchr(line, ' '); 3357840fea2SMichal Marek if (!p) { 3367840fea2SMichal Marek warn("malformed line: %s\n", line); 3377840fea2SMichal Marek goto out_file; 3387840fea2SMichal Marek } 3397840fea2SMichal Marek p++; 3407840fea2SMichal Marek if (!parse_file(p, md)) { 3417840fea2SMichal Marek warn("could not open %s: %s\n", 3427840fea2SMichal Marek p, strerror(errno)); 3437840fea2SMichal Marek goto out_file; 3447840fea2SMichal Marek } 3457840fea2SMichal Marek continue; 3467840fea2SMichal Marek } 3471da177e4SLinus Torvalds if (strncmp(line, "deps_", sizeof("deps_")-1) == 0) { 3481da177e4SLinus Torvalds check_files = 1; 3491da177e4SLinus Torvalds continue; 3501da177e4SLinus Torvalds } 3511da177e4SLinus Torvalds if (!check_files) 3521da177e4SLinus Torvalds continue; 3531da177e4SLinus Torvalds 3541da177e4SLinus Torvalds /* Continue until line does not end with '\' */ 3551da177e4SLinus Torvalds if ( *(p + strlen(p)-1) != '\\') 3561da177e4SLinus Torvalds break; 3571da177e4SLinus Torvalds /* Terminate line at first space, to get rid of final ' \' */ 3581da177e4SLinus Torvalds while (*p) { 3591da177e4SLinus Torvalds if (isspace(*p)) { 3601da177e4SLinus Torvalds *p = '\0'; 3611da177e4SLinus Torvalds break; 3621da177e4SLinus Torvalds } 3631da177e4SLinus Torvalds p++; 3641da177e4SLinus Torvalds } 3651da177e4SLinus Torvalds 3661da177e4SLinus Torvalds /* Check if this file is in same dir as objfile */ 3671da177e4SLinus Torvalds if ((strstr(line, dir)+strlen(dir)-1) == strrchr(line, '/')) { 3681da177e4SLinus Torvalds if (!parse_file(line, md)) { 369cb80514dSSam Ravnborg warn("could not open %s: %s\n", 3701da177e4SLinus Torvalds line, strerror(errno)); 3711da177e4SLinus Torvalds goto out_file; 3721da177e4SLinus Torvalds } 3731da177e4SLinus Torvalds 3741da177e4SLinus Torvalds } 3751da177e4SLinus Torvalds 3761da177e4SLinus Torvalds } 3771da177e4SLinus Torvalds 3781da177e4SLinus Torvalds /* Everyone parsed OK */ 3791da177e4SLinus Torvalds ret = 1; 3801da177e4SLinus Torvalds out_file: 38170f30cfeSMasahiro Yamada free(file); 3821da177e4SLinus Torvalds free(dir); 3831da177e4SLinus Torvalds free(cmd); 3841da177e4SLinus Torvalds return ret; 3851da177e4SLinus Torvalds } 3861da177e4SLinus Torvalds 3871da177e4SLinus Torvalds /* Calc and record src checksum. */ 3881da177e4SLinus Torvalds void get_src_version(const char *modname, char sum[], unsigned sumlen) 3891da177e4SLinus Torvalds { 390f531c1b5SMasahiro Yamada char *buf, *pos, *firstline; 3911da177e4SLinus Torvalds struct md4_ctx md; 392f531c1b5SMasahiro Yamada char *fname; 39341370d3bSSam Ravnborg char filelist[PATH_MAX + 1]; 39441370d3bSSam Ravnborg 39560ae1b19SMasahiro Yamada /* objects for a module are listed in the first line of *.mod file. */ 396*e54dd93aSMasahiro Yamada snprintf(filelist, sizeof(filelist), "%s.mod", modname); 3971da177e4SLinus Torvalds 398f531c1b5SMasahiro Yamada buf = read_text_file(filelist); 3991da177e4SLinus Torvalds 400f531c1b5SMasahiro Yamada pos = buf; 401f531c1b5SMasahiro Yamada firstline = get_line(&pos); 402f531c1b5SMasahiro Yamada if (!firstline) { 403cb80514dSSam Ravnborg warn("bad ending versions file for %s\n", modname); 404f531c1b5SMasahiro Yamada goto free; 4051da177e4SLinus Torvalds } 4061da177e4SLinus Torvalds 4071da177e4SLinus Torvalds md4_init(&md); 408f531c1b5SMasahiro Yamada while ((fname = strsep(&firstline, " "))) { 4091da177e4SLinus Torvalds if (!*fname) 4101da177e4SLinus Torvalds continue; 411e6e6733eSAshutosh Naik if (!(is_static_library(fname)) && 412e6e6733eSAshutosh Naik !parse_source_files(fname, &md)) 413f531c1b5SMasahiro Yamada goto free; 4141da177e4SLinus Torvalds } 4151da177e4SLinus Torvalds 4161da177e4SLinus Torvalds md4_final_ascii(&md, sum, sumlen); 417f531c1b5SMasahiro Yamada free: 418f531c1b5SMasahiro Yamada free(buf); 4191da177e4SLinus Torvalds } 420