~ubuntu-branches/ubuntu/oneiric/squid3/oneiric-security

« back to all changes in this revision

Viewing changes to src/fs/ufs/ufscommon.cc

  • Committer: Bazaar Package Importer
  • Author(s): Mahyuddin Susanto
  • Date: 2011-02-15 18:46:13 UTC
  • mfrom: (21.2.4 sid)
  • Revision ID: james.westby@ubuntu.com-20110215184613-1u3dh5sz4i055flk
Tags: 3.1.10-1ubuntu1
* Merge from debian unstable. (LP: #719283)  Remaining changes:
  - debian/patches/18-fix-ftbfs-binutils-gold.dpatch: Add library linker into
    LIBS instead to LDFLAGS to fixing FTBFS binutils-gold.
* Drop Ubuntu configuration for ufw which landed in Debian and sync it: 
  - debian/squid3.ufw.profile.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
 
46
46
CBDATA_CLASS_INIT(RebuildState);
47
47
 
48
 
 
49
 
class UFSSwapLogParser_old:public UFSSwapLogParser
50
 
{
51
 
public:
52
 
    struct StoreSwapLogDataOld {
53
 
        char op;
54
 
        sfileno swap_filen;
55
 
        time_t timestamp;
56
 
        time_t lastref;
57
 
        time_t expires;
58
 
        time_t lastmod;
59
 
        size_t swap_file_sz;
60
 
        u_short refcount;
61
 
        u_short flags;
62
 
        unsigned char key[SQUID_MD5_DIGEST_LENGTH];
63
 
    };
64
 
    UFSSwapLogParser_old(FILE *fp):UFSSwapLogParser(fp) {
65
 
        record_size = sizeof(UFSSwapLogParser_old::StoreSwapLogDataOld);
66
 
    }
67
 
    bool ReadRecord(StoreSwapLogData &swapData);
68
 
};
69
 
 
70
 
 
71
 
bool UFSSwapLogParser_old::ReadRecord(StoreSwapLogData &swapData)
72
 
{
73
 
    UFSSwapLogParser_old::StoreSwapLogDataOld readData;
74
 
    int bytes = sizeof(UFSSwapLogParser_old::StoreSwapLogDataOld);
75
 
 
76
 
    assert(log);
77
 
 
78
 
    if (fread(&readData, bytes, 1, log) != 1) {
79
 
        return false;
80
 
    }
81
 
    swapData.op = readData.op;
82
 
    swapData.swap_filen = readData.swap_filen;
83
 
    swapData.timestamp = readData.timestamp;
84
 
    swapData.lastref = readData.lastref;
85
 
    swapData.expires = readData.expires;
86
 
    swapData.lastmod = readData.lastmod;
87
 
    swapData.swap_file_sz = readData.swap_file_sz;
88
 
    swapData.refcount = readData.refcount;
89
 
    swapData.flags = readData.flags;
90
 
    xmemcpy(swapData.key, readData.key, SQUID_MD5_DIGEST_LENGTH);
91
 
    return true;
92
 
}
93
 
 
 
48
/// Parse a swap header entry created on a system with 32-bit size_t and sfileno
 
49
/// this is typical of 32-bit systems without large file support
 
50
/// NP: SQUID_MD5_DIGEST_LENGTH is very risky still.
 
51
class UFSSwapLogParser_v1_32bs:public UFSSwapLogParser
 
52
{
 
53
public:
 
54
    /// version 1 cache swap.state entry with 32-bit size_t (swap_file_sz)
 
55
    /// time_t an sfileno have no variation from the v1 baseline format
 
56
    struct StoreSwapLogDataOld {
 
57
        char op;
 
58
        sfileno swap_filen;
 
59
        time_t timestamp;
 
60
        time_t lastref;
 
61
        time_t expires;
 
62
        time_t lastmod;
 
63
        uint32_t swap_file_sz;
 
64
        u_short refcount;
 
65
        u_short flags;
 
66
        unsigned char key[SQUID_MD5_DIGEST_LENGTH];
 
67
    };
 
68
    UFSSwapLogParser_v1_32bs(FILE *fp):UFSSwapLogParser(fp) {
 
69
        record_size = sizeof(UFSSwapLogParser_v1_32bs::StoreSwapLogDataOld);
 
70
    }
 
71
    /// Convert the on-disk 32-bit format to our current format while reading
 
72
    bool ReadRecord(StoreSwapLogData &swapData) {
 
73
        UFSSwapLogParser_v1_32bs::StoreSwapLogDataOld readData;
 
74
        int bytes = sizeof(UFSSwapLogParser_v1_32bs::StoreSwapLogDataOld);
 
75
 
 
76
        assert(log);
 
77
 
 
78
        if (fread(&readData, bytes, 1, log) != 1) {
 
79
            return false;
 
80
        }
 
81
        swapData.op = readData.op;
 
82
        swapData.swap_filen = readData.swap_filen;
 
83
        swapData.timestamp = readData.timestamp;
 
84
        swapData.lastref = readData.lastref;
 
85
        swapData.expires = readData.expires;
 
86
        swapData.lastmod = readData.lastmod;
 
87
        swapData.swap_file_sz = readData.swap_file_sz;
 
88
        swapData.refcount = readData.refcount;
 
89
        swapData.flags = readData.flags;
 
90
        xmemcpy(swapData.key, readData.key, SQUID_MD5_DIGEST_LENGTH);
 
91
        return true;
 
92
    }
 
93
};
 
94
 
 
95
/// Parse a swap header entry created on a system with 32-bit size_t, time_t and sfileno
 
96
/// this is typical of 32-bit systems without large file support and with old kernels
 
97
/// NP: SQUID_MD5_DIGEST_LENGTH is very risky still.
 
98
class UFSSwapLogParser_v1_32bst:public UFSSwapLogParser
 
99
{
 
100
public:
 
101
    /// version 1 cache swap.state entry with 32-bit size_t (swap_file_sz)
 
102
    /// time_t also differs
 
103
    /// sfileno has no variation from the v1 baseline format
 
104
    struct StoreSwapLogDataOld {
 
105
        char op;
 
106
        sfileno swap_filen;
 
107
        int32_t timestamp;
 
108
        int32_t lastref;
 
109
        int32_t expires;
 
110
        int32_t lastmod;
 
111
        uint32_t swap_file_sz;
 
112
        u_short refcount;
 
113
        u_short flags;
 
114
        unsigned char key[SQUID_MD5_DIGEST_LENGTH];
 
115
    };
 
116
    UFSSwapLogParser_v1_32bst(FILE *fp):UFSSwapLogParser(fp) {
 
117
        record_size = sizeof(UFSSwapLogParser_v1_32bst::StoreSwapLogDataOld);
 
118
    }
 
119
    /// Convert the on-disk 32-bit format to our current format while reading
 
120
    bool ReadRecord(StoreSwapLogData &swapData) {
 
121
        UFSSwapLogParser_v1_32bst::StoreSwapLogDataOld readData;
 
122
        int bytes = sizeof(UFSSwapLogParser_v1_32bst::StoreSwapLogDataOld);
 
123
 
 
124
        assert(log);
 
125
 
 
126
        if (fread(&readData, bytes, 1, log) != 1) {
 
127
            return false;
 
128
        }
 
129
        swapData.op = readData.op;
 
130
        swapData.swap_filen = readData.swap_filen;
 
131
        swapData.timestamp = readData.timestamp;
 
132
        swapData.lastref = readData.lastref;
 
133
        swapData.expires = readData.expires;
 
134
        swapData.lastmod = readData.lastmod;
 
135
        swapData.swap_file_sz = readData.swap_file_sz;
 
136
        swapData.refcount = readData.refcount;
 
137
        swapData.flags = readData.flags;
 
138
        xmemcpy(swapData.key, readData.key, SQUID_MD5_DIGEST_LENGTH);
 
139
        return true;
 
140
    }
 
141
};
 
142
 
 
143
/// Parse a swap header entry created on a system with 64-bit size_t and sfileno
 
144
/// this is typical of 64-bit systems prior to this patch fixing sfileno to 32-bits
 
145
/// NP: SQUID_MD5_DIGEST_LENGTH is very risky still.
 
146
class UFSSwapLogParser_v1_64bfn:public UFSSwapLogParser
 
147
{
 
148
public:
 
149
    /// version 1 cache swap.state entry with 64-bit sfileno
 
150
    struct StoreSwapLogDataOld {
 
151
        char op;
 
152
        int64_t swap_filen;
 
153
        time_t timestamp;
 
154
        time_t lastref;
 
155
        time_t expires;
 
156
        time_t lastmod;
 
157
        uint64_t swap_file_sz;
 
158
        u_short refcount;
 
159
        u_short flags;
 
160
        unsigned char key[SQUID_MD5_DIGEST_LENGTH];
 
161
    };
 
162
    UFSSwapLogParser_v1_64bfn(FILE *fp):UFSSwapLogParser(fp) {
 
163
        record_size = sizeof(UFSSwapLogParser_v1_64bfn::StoreSwapLogDataOld);
 
164
    }
 
165
    /// Convert the on-disk 64-bit format to our current format while reading
 
166
    bool ReadRecord(StoreSwapLogData &swapData) {
 
167
        UFSSwapLogParser_v1_64bfn::StoreSwapLogDataOld readData;
 
168
        int bytes = sizeof(UFSSwapLogParser_v1_64bfn::StoreSwapLogDataOld);
 
169
 
 
170
        assert(log);
 
171
 
 
172
        if (fread(&readData, bytes, 1, log) != 1) {
 
173
            return false;
 
174
        }
 
175
        swapData.op = readData.op;
 
176
        if ((readData.swap_filen>>32) != 0) {
 
177
            fatalf("File ID on record is greater than maximum cache file ID.");
 
178
        }
 
179
        swapData.swap_filen = (int32_t)readData.swap_filen;
 
180
        swapData.timestamp = readData.timestamp;
 
181
        swapData.lastref = readData.lastref;
 
182
        swapData.expires = readData.expires;
 
183
        swapData.lastmod = readData.lastmod;
 
184
        swapData.swap_file_sz = readData.swap_file_sz;
 
185
        swapData.refcount = readData.refcount;
 
186
        swapData.flags = readData.flags;
 
187
        xmemcpy(swapData.key, readData.key, SQUID_MD5_DIGEST_LENGTH);
 
188
        return true;
 
189
    }
 
190
};
94
191
 
95
192
class UFSSwapLogParser_v1:public UFSSwapLogParser
96
193
{
125
222
        return NULL;
126
223
 
127
224
    if (header.op != SWAP_LOG_VERSION) {
128
 
        debugs(47, 1, "Old swap file detected... ");
 
225
        debugs(47, 1, "Old swap file detected...");
129
226
        fseek(fp, 0, SEEK_SET);
130
 
        return new UFSSwapLogParser_old(fp);
 
227
        return new UFSSwapLogParser_v1_32bs(fp); // Um. 32-bits except time_t, and can't determine that.
131
228
    }
132
229
 
133
230
    if (header.version == 1) {
134
231
        if (fseek(fp, header.record_size, SEEK_SET) != 0)
135
232
            return NULL;
136
233
 
137
 
        if (header.record_size == sizeof(struct UFSSwapLogParser_old::StoreSwapLogDataOld)) {
138
 
            debugs(47, 1, "Version 1 of swap file without LFS support detected... ");
139
 
            return new UFSSwapLogParser_old(fp);
140
 
        }
141
 
 
 
234
        // baseline
 
235
        // 32-bit sfileno
 
236
        // native time_t (hopefully 64-bit)
 
237
        // 64-bit file size
142
238
        if (header.record_size == sizeof(StoreSwapLogData)) {
143
239
            debugs(47, 1, "Version 1 of swap file with LFS support detected... ");
144
240
            return new UFSSwapLogParser_v1(fp);
145
241
        }
146
242
 
147
 
        debugs(47, 1, "The swap file has wrong format!... ");
 
243
        // which means we have a 3-way grid of permutations to import (yuck!)
 
244
        // 1) sfileno 32-bit / 64-bit  (64-bit was broken)
 
245
        // 2) time_t 32-bit / 64-bit
 
246
        // 3) size_t 32-bit / 64-bit  (32-bit was pre-LFS)
 
247
 
 
248
        // 32-bit systems...
 
249
        // only LFS (size_t) differs from baseline
 
250
        if (header.record_size == sizeof(struct UFSSwapLogParser_v1_32bs::StoreSwapLogDataOld)) {
 
251
            debugs(47, 1, "Version 1 (32-bit) swap file without LFS support detected... ");
 
252
            return new UFSSwapLogParser_v1_32bs(fp);
 
253
        }
 
254
        // LFS (size_t) and timestamps (time_t) differs from baseline
 
255
        if (header.record_size == sizeof(struct UFSSwapLogParser_v1_32bst::StoreSwapLogDataOld)) {
 
256
            debugs(47, 1, "Version 1 (32-bit) swap file with short timestamps and without LFS support detected... ");
 
257
            return new UFSSwapLogParser_v1_32bst(fp);
 
258
        }
 
259
        // No downgrade for 64-bit timestamps to 32-bit.
 
260
 
 
261
        // 64-bit systems
 
262
        // sfileno was 64-bit for a some builds
 
263
        if (header.record_size == sizeof(struct UFSSwapLogParser_v1_64bfn::StoreSwapLogDataOld)) {
 
264
            debugs(47, 1, "Version 1 (64-bit) swap file with broken sfileno detected... ");
 
265
            return new UFSSwapLogParser_v1_64bfn(fp);
 
266
        }
 
267
        // NP: 64-bit system with 32-bit size_t/time_t are not handled.
 
268
 
 
269
        debugs(47, 1, "WARNING: The swap file has wrong format!... ");
 
270
        debugs(47, 1, "NOTE: Cannot safely downgrade caches to short (32-bit) timestamps.");
148
271
        return NULL;
149
272
    }
150
273
 
 
274
    // XXX: version 2 of swapfile. This time use fixed-bit sizes for everything!!
 
275
    // and preferrably write to disk in network-order bytes for the larger fields.
 
276
 
151
277
    return NULL;
152
278
}
153
279