/* Mapping of request type to database. */
-static struct database_dyn *const serv2db[LASTREQ] =
+static struct
{
- [GETPWBYNAME] = &dbs[pwddb],
- [GETPWBYUID] = &dbs[pwddb],
- [GETGRBYNAME] = &dbs[grpdb],
- [GETGRBYGID] = &dbs[grpdb],
- [GETHOSTBYNAME] = &dbs[hstdb],
- [GETHOSTBYNAMEv6] = &dbs[hstdb],
- [GETHOSTBYADDR] = &dbs[hstdb],
- [GETHOSTBYADDRv6] = &dbs[hstdb],
- [GETFDPW] = &dbs[pwddb],
- [GETFDGR] = &dbs[grpdb],
- [GETFDHST] = &dbs[hstdb],
- [GETAI] = &dbs[hstdb],
- [INITGROUPS] = &dbs[grpdb],
- [GETSERVBYNAME] = &dbs[servdb],
- [GETSERVBYPORT] = &dbs[servdb],
- [GETFDSERV] = &dbs[servdb]
+ bool data_request;
+ struct database_dyn *db;
+} const servinfo[LASTREQ] =
+{
+ [GETPWBYNAME] = { true, &dbs[pwddb] },
+ [GETPWBYUID] = { true, &dbs[pwddb] },
+ [GETGRBYNAME] = { true, &dbs[grpdb] },
+ [GETGRBYGID] = { true, &dbs[grpdb] },
+ [GETHOSTBYNAME] = { true, &dbs[hstdb] },
+ [GETHOSTBYNAMEv6] = { true, &dbs[hstdb] },
+ [GETHOSTBYADDR] = { true, &dbs[hstdb] },
+ [GETHOSTBYADDRv6] = { true, &dbs[hstdb] },
+ [SHUTDOWN] = { false, NULL },
+ [GETSTAT] = { false, NULL },
+ [SHUTDOWN] = { false, NULL },
+ [GETFDPW] = { false, &dbs[pwddb] },
+ [GETFDGR] = { false, &dbs[grpdb] },
+ [GETFDHST] = { false, &dbs[hstdb] },
+ [GETAI] = { true, &dbs[hstdb] },
+ [INITGROUPS] = { true, &dbs[grpdb] },
+ [GETSERVBYNAME] = { true, &dbs[servdb] },
+ [GETSERVBYPORT] = { true, &dbs[servdb] },
+ [GETFDSERV] = { false, &dbs[servdb] }
};
/* Make sure the record is for this type of service. */
if (here->type >= LASTREQ
- || serv2db[here->type] != &dbs[dbnr])
+ || servinfo[here->type].db != &dbs[dbnr])
goto fail;
/* Validate boolean field value. */
&& nscd_request_avc_has_perm (fd, req->type) != 0)
return;
- struct database_dyn *db = serv2db[req->type];
+ struct database_dyn *db = servinfo[req->type].db;
- // XXX Clean up so that each new command need not introduce a
- // XXX new conditional.
- if ((__builtin_expect (req->type, GETPWBYNAME) >= GETPWBYNAME
- && __builtin_expect (req->type, GETHOSTBYADDRv6) <= GETHOSTBYADDRv6)
- || req->type == GETAI || req->type == INITGROUPS
- || req->type == GETSERVBYNAME || req->type == GETSERVBYPORT)
+ /* See whether we can service the request from the cache. */
+ if (__builtin_expect (servinfo[req->type].data_request, true))
{
if (__builtin_expect (debug_level, 0) > 0)
{
case GETFDHST:
case GETFDSERV:
#ifdef SCM_RIGHTS
- send_ro_fd (serv2db[req->type], key, fd);
+ send_ro_fd (servinfo[req->type].db, key, fd);
#endif
break;