From 1cdeb2372ddecac0dfe0c132a033e9590ffa07d2 Mon Sep 17 00:00:00 2001 From: Siddhesh Poyarekar Date: Wed, 30 Apr 2014 11:57:09 +0530 Subject: Consolidate code to initialize nscd dataset header This patch consolidates the code to initialize the header of a dataset into a single set of functions (one for positive and another for negative datasets) primarily to reduce repetition of code. The secondary reason is to simplify Patch 2/2 which fixes the problem of an uninitialized byte in the header by initializing an unused field in the structure and hence preventing a possible data leak into the cache file. --- nscd/nscd-client.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'nscd/nscd-client.h') diff --git a/nscd/nscd-client.h b/nscd/nscd-client.h index 98f77e7901..c069bf6810 100644 --- a/nscd/nscd-client.h +++ b/nscd/nscd-client.h @@ -236,6 +236,36 @@ struct datahead } data[0]; }; +static inline time_t +datahead_init_common (struct datahead *head, nscd_ssize_t allocsize, + nscd_ssize_t recsize, uint32_t ttl) +{ + head->allocsize = allocsize; + head->recsize = recsize; + head->usable = true; + + head->ttl = ttl; + /* Compute the timeout time. */ + return head->timeout = time (NULL) + ttl; +} + +static inline time_t +datahead_init_pos (struct datahead *head, nscd_ssize_t allocsize, + nscd_ssize_t recsize, uint8_t nreloads, uint32_t ttl) +{ + head->notfound = false; + head->nreloads = nreloads; + return datahead_init_common (head, allocsize, recsize, ttl); +} + +static inline time_t +datahead_init_neg (struct datahead *head, nscd_ssize_t allocsize, + nscd_ssize_t recsize, uint32_t ttl) +{ + head->notfound = true; + head->nreloads = 0; + return datahead_init_common (head, allocsize, recsize, ttl); +} /* Structure for one hash table entry. */ struct hashentry -- cgit v1.2.3