Back to index

glibc  2.9
Classes | Defines | Typedefs | Enumerations | Functions
nscd-client.h File Reference
#include <stdbool.h>
#include <stdint.h>
#include <sys/types.h>
#include <atomic.h>
#include <nscd-types.h>
#include <sys/uio.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  request_header
struct  pw_response_header
struct  gr_response_header
struct  hst_response_header
struct  ai_response_header
struct  nscd_ai_result
struct  initgr_response_header
struct  serv_response_header
struct  datahead
struct  hashentry
struct  database_pers_head
struct  mapped_database
struct  locked_map_ptr
union  datahead.data
union  hashentry.__unnamed__

Defines

#define NSCD_VERSION   2
#define _PATH_NSCDPID   "/var/run/nscd/nscd.pid"
#define _PATH_NSCDSOCKET   "/var/run/nscd/socket"
#define _PATH_NSCDCONF   "/etc/nscd.conf"
#define MAXKEYLEN   1024
#define ENDREF   UINT32_MAX
#define ALIGN   16
#define DB_VERSION   1
#define MAPPING_TIMEOUT   (5 * 60)
#define NO_MAPPING   ((struct mapped_database *) -1l)
#define libc_locked_map_ptr(class, name)   class struct locked_map_ptr name

Typedefs

typedef uint32_t ref_t
typedef uint64_t nscd_time_t

Enumerations

enum  request_type {
  GETPWBYNAME, GETPWBYUID, GETGRBYNAME, GETGRBYGID,
  GETHOSTBYNAME, GETHOSTBYNAMEv6, GETHOSTBYADDR, GETHOSTBYADDRv6,
  SHUTDOWN, GETSTAT, INVALIDATE, GETFDPW,
  GETFDGR, GETFDHST, GETAI, INITGROUPS,
  GETSERVBYNAME, GETSERVBYPORT, GETFDSERV, LASTREQ
}

Functions

int __nscd_open_socket (const char *key, size_t keylen, request_type type, void *response, size_t responselen) attribute_hidden
struct mapped_database__nscd_get_map_ref (request_type type, const char *name, volatile struct locked_map_ptr *mapptr, int *gc_cyclep)
void __nscd_unmap (struct mapped_database *mapped)
static int __nscd_drop_map_ref (struct mapped_database *map, int *gc_cycle)
struct datahead__nscd_cache_search (request_type type, const char *key, size_t keylen, const struct mapped_database *mapped)
ssize_t __readall (int fd, void *buf, size_t len) attribute_hidden
ssize_t __readvall (int fd, const struct iovec *iov, int iovcnt) attribute_hidden
ssize_t writeall (int fd, const void *buf, size_t len) attribute_hidden
ssize_t sendfileall (int tofd, int fromfd, off_t off, size_t len) attribute_hidden

Class Documentation

struct request_header

Definition at line 78 of file nscd-client.h.

Class Members
int32_t key_len
request_type type
int32_t version
struct pw_response_header

Definition at line 88 of file nscd-client.h.

Class Members
int32_t found
nscd_ssize_t pw_dir_len
nscd_ssize_t pw_gecos_len
gid_t pw_gid
nscd_ssize_t pw_name_len
nscd_ssize_t pw_passwd_len
nscd_ssize_t pw_shell_len
uid_t pw_uid
int32_t version
struct gr_response_header

Definition at line 104 of file nscd-client.h.

Class Members
int32_t found
gid_t gr_gid
nscd_ssize_t gr_mem_cnt
nscd_ssize_t gr_name_len
nscd_ssize_t gr_passwd_len
int32_t version
struct hst_response_header

Definition at line 117 of file nscd-client.h.

Class Members
int32_t error
int32_t found
nscd_ssize_t h_addr_list_cnt
int32_t h_addrtype
nscd_ssize_t h_aliases_cnt
int32_t h_length
nscd_ssize_t h_name_len
int32_t version
struct ai_response_header

Definition at line 132 of file nscd-client.h.

Class Members
nscd_ssize_t addrslen
nscd_ssize_t canonlen
int32_t error
int32_t found
nscd_ssize_t naddrs
int32_t version
struct nscd_ai_result

Definition at line 143 of file nscd-client.h.

Class Members
char * addrs
char * canon
uint8_t * family
int naddrs
struct initgr_response_header

Definition at line 153 of file nscd-client.h.

Class Members
int32_t found
nscd_ssize_t ngrps
int32_t version
struct serv_response_header

Definition at line 163 of file nscd-client.h.

Class Members
int32_t found
nscd_ssize_t s_aliases_cnt
nscd_ssize_t s_name_len
int32_t s_port
nscd_ssize_t s_proto_len
int32_t version
struct datahead

Definition at line 187 of file nscd-client.h.

Class Members
uint64_t __pad0__:40
nscd_ssize_t allocsize
union datahead data
uint8_t notfound
uint8_t nreloads
nscd_ssize_t recsize
nscd_time_t timeout
uint8_t usable
struct hashentry

Definition at line 215 of file nscd-client.h.

Class Members
union hashentry __unnamed__
bool first
ref_t key
nscd_ssize_t len
ref_t next
int32_t owner
ref_t packet
request_type type:8
struct database_pers_head

Definition at line 242 of file nscd-client.h.

Class Members
uint64_t addfailed
ref_t array
nscd_ssize_t data_size
nscd_ssize_t first_free
volatile int32_t gc_cycle
int32_t header_size
nscd_ssize_t maxnentries
nscd_ssize_t maxnsearched
nscd_ssize_t module
uint64_t neghit
uint64_t negmiss
nscd_ssize_t nentries
volatile int32_t nscd_certainly_running
uint64_t poshit
uint64_t posmiss
uint64_t rdlockdelayed
volatile nscd_time_t timestamp
int32_t version
uint64_t wrlockdelayed
struct mapped_database

Definition at line 274 of file nscd-client.h.

Collaboration diagram for mapped_database:
Class Members
int counter
const char * data
size_t datasize
struct database_pers_head * head
size_t mapsize
struct locked_map_ptr

Definition at line 284 of file nscd-client.h.

Collaboration diagram for locked_map_ptr:
Class Members
int lock
struct mapped_database * mapped
union datahead.data

Definition at line 200 of file nscd-client.h.

Class Members
ai_response_header aidata
nscd_ssize_t align1
nscd_time_t align2
gr_response_header grdata
hst_response_header hstdata
initgr_response_header initgrdata
pw_response_header pwdata
serv_response_header servdata
union hashentry.__unnamed__

Definition at line 224 of file nscd-client.h.

Class Members
struct hashentry * dellist
ref_t * prevp

Define Documentation

#define _PATH_NSCDCONF   "/etc/nscd.conf"

Definition at line 45 of file nscd-client.h.

#define _PATH_NSCDPID   "/var/run/nscd/nscd.pid"

Definition at line 39 of file nscd-client.h.

#define _PATH_NSCDSOCKET   "/var/run/nscd/socket"

Definition at line 42 of file nscd-client.h.

#define ALIGN   16

Definition at line 183 of file nscd-client.h.

#define DB_VERSION   1

Definition at line 235 of file nscd-client.h.

#define ENDREF   UINT32_MAX

Definition at line 177 of file nscd-client.h.

#define libc_locked_map_ptr (   class,
  name 
)    class struct locked_map_ptr name

Definition at line 289 of file nscd-client.h.

#define MAPPING_TIMEOUT   (5 * 60)

Definition at line 238 of file nscd-client.h.

#define MAXKEYLEN   1024

Definition at line 48 of file nscd-client.h.

#define NO_MAPPING   ((struct mapped_database *) -1l)

Definition at line 282 of file nscd-client.h.

#define NSCD_VERSION   2

Definition at line 36 of file nscd-client.h.


Typedef Documentation

Definition at line 180 of file nscd-client.h.

typedef uint32_t ref_t

Definition at line 175 of file nscd-client.h.


Enumeration Type Documentation

Enumerator:
GETPWBYNAME 
GETPWBYUID 
GETGRBYNAME 
GETGRBYGID 
GETHOSTBYNAME 
GETHOSTBYNAMEv6 
GETHOSTBYADDR 
GETHOSTBYADDRv6 
SHUTDOWN 
GETSTAT 
INVALIDATE 
GETFDPW 
GETFDGR 
GETFDHST 
GETAI 
INITGROUPS 
GETSERVBYNAME 
GETSERVBYPORT 
GETFDSERV 
LASTREQ 

Definition at line 52 of file nscd-client.h.


Function Documentation

struct datahead* __nscd_cache_search ( request_type  type,
const char *  key,
size_t  keylen,
const struct mapped_database mapped 
) [read]

Definition at line 473 of file nscd_helper.c.

{
  unsigned long int hash = __nis_hash (key, keylen) % mapped->head->module;
  size_t datasize = mapped->datasize;

  ref_t trail = mapped->head->array[hash];
  ref_t work = trail;
  int tick = 0;

  while (work != ENDREF && work + sizeof (struct hashentry) <= datasize)
    {
      struct hashentry *here = (struct hashentry *) (mapped->data + work);

#ifndef _STRING_ARCH_unaligned
      /* Although during garbage collection when moving struct hashentry
        records around we first copy from old to new location and then
        adjust pointer from previous hashentry to it, there is no barrier
        between those memory writes.  It is very unlikely to hit it,
        so check alignment only if a misaligned load can crash the
        application.  */
      if ((uintptr_t) here & (__alignof__ (*here) - 1))
       return NULL;
#endif

      if (type == here->type
         && keylen == here->len
         && here->key + keylen <= datasize
         && memcmp (key, mapped->data + here->key, keylen) == 0
         && here->packet + sizeof (struct datahead) <= datasize)
       {
         /* We found the entry.  Increment the appropriate counter.  */
         struct datahead *dh
           = (struct datahead *) (mapped->data + here->packet);

#ifndef _STRING_ARCH_unaligned
         if ((uintptr_t) dh & (__alignof__ (*dh) - 1))
           return NULL;
#endif

         /* See whether we must ignore the entry or whether something
            is wrong because garbage collection is in progress.  */
         if (dh->usable && here->packet + dh->allocsize <= datasize)
           return dh;
       }

      work = here->next;
      /* Prevent endless loops.  This should never happen but perhaps
        the database got corrupted, accidentally or deliberately.  */
      if (work == trail)
       break;
      if (tick)
       {
         struct hashentry *trailelem;
         trailelem = (struct hashentry *) (mapped->data + trail);

#ifndef _STRING_ARCH_unaligned
         /* We have to redo the checks.  Maybe the data changed.  */
         if ((uintptr_t) trailelem & (__alignof__ (*trailelem) - 1))
           return NULL;
#endif
         trail = trailelem->next;
       }
      tick = 1 - tick;
    }

  return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int __nscd_drop_map_ref ( struct mapped_database map,
int gc_cycle 
) [inline, static]

Definition at line 307 of file nscd-client.h.

{
  if (map != NO_MAPPING)
    {
      int now_cycle = map->head->gc_cycle;
      if (__builtin_expect (now_cycle != *gc_cycle, 0))
       {
         /* We might have read inconsistent data.  */
         *gc_cycle = now_cycle;
         return -1;
       }

      if (atomic_decrement_val (&map->counter) == 0)
       __nscd_unmap (map);
    }

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

struct mapped_database* __nscd_get_map_ref ( request_type  type,
const char *  name,
volatile struct locked_map_ptr mapptr,
int gc_cyclep 
) [read]

Definition at line 423 of file nscd_helper.c.

{
  struct mapped_database *cur = mapptr->mapped;
  if (cur == NO_MAPPING)
    return cur;

  int cnt = 0;
  while (__builtin_expect (atomic_compare_and_exchange_val_acq (&mapptr->lock,
                                                        1, 0) != 0, 0))
    {
      // XXX Best number of rounds?
      if (__builtin_expect (++cnt > 5, 0))
       return NO_MAPPING;

      atomic_delay ();
    }

  cur = mapptr->mapped;

  if (__builtin_expect (cur != NO_MAPPING, 1))
    {
      /* If not mapped or timestamp not updated, request new map.  */
      if (cur == NULL
         || (cur->head->nscd_certainly_running == 0
             && cur->head->timestamp + MAPPING_TIMEOUT < time (NULL))
         || cur->head->data_size > cur->datasize)
       cur = get_mapping (type, name,
                        (struct mapped_database **) &mapptr->mapped);

      if (__builtin_expect (cur != NO_MAPPING, 1))
       {
         if (__builtin_expect (((*gc_cyclep = cur->head->gc_cycle) & 1) != 0,
                            0))
           cur = NO_MAPPING;
         else
           atomic_increment (&cur->counter);
       }
    }

  mapptr->lock = 0;

  return cur;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int __nscd_open_socket ( const char *  key,
size_t  keylen,
request_type  type,
void *  response,
size_t  responselen 
)

Definition at line 545 of file nscd_helper.c.

{
  /* This should never happen and it is something the nscd daemon
     enforces, too.  He it helps to limit the amount of stack
     used.  */
  if (keylen > MAXKEYLEN)
    return -1;

  int saved_errno = errno;

  int sock = open_socket (type, key, keylen);
  if (sock >= 0)
    {
      /* Wait for data.  */
      if (wait_on_socket (sock, 5 * 1000) > 0)
       {
         ssize_t nbytes = TEMP_FAILURE_RETRY (__read (sock, response,
                                                 responselen));
         if (nbytes == (ssize_t) responselen)
           return sock;
       }

      close_not_cancel_no_status (sock);
    }

  __set_errno (saved_errno);

  return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void __nscd_unmap ( struct mapped_database mapped)

Definition at line 269 of file nscd_helper.c.

{
  assert (mapped->counter == 0);
  __munmap ((void *) mapped->head, mapped->mapsize);
  free (mapped);
}

Here is the call graph for this function:

Here is the caller graph for this function:

ssize_t __readall ( int  fd,
void *  buf,
size_t  len 
)

Definition at line 81 of file nscd_helper.c.

{
  size_t n = len;
  ssize_t ret;
  do
    {
    again:
      ret = TEMP_FAILURE_RETRY (__read (fd, buf, n));
      if (ret <= 0)
       {
         if (__builtin_expect (ret < 0 && errno == EAGAIN, 0)
             /* The socket is still receiving data.  Wait a bit more.  */
             && wait_on_socket (fd, EXTRA_RECEIVE_TIME) > 0)
           goto again;

         break;
       }
      buf = (char *) buf + ret;
      n -= ret;
    }
  while (n > 0);
  return ret < 0 ? ret : len - n;
}

Here is the call graph for this function:

Here is the caller graph for this function:

ssize_t __readvall ( int  fd,
const struct iovec iov,
int  iovcnt 
)

Definition at line 107 of file nscd_helper.c.

{
  ssize_t ret = TEMP_FAILURE_RETRY (__readv (fd, iov, iovcnt));
  if (ret <= 0)
    {
      if (__builtin_expect (ret == 0 || errno != EAGAIN, 1))
       /* A genuine error or no data to read.  */
       return ret;

      /* The data has not all yet been received.  Do as if we have not
        read anything yet.  */
      ret = 0;
    }

  size_t total = 0;
  for (int i = 0; i < iovcnt; ++i)
    total += iov[i].iov_len;

  if (ret < total)
    {
      struct iovec iov_buf[iovcnt];
      ssize_t r = ret;

      struct iovec *iovp = memcpy (iov_buf, iov, iovcnt * sizeof (*iov));
      do
       {
         while (iovp->iov_len <= r)
           {
             r -= iovp->iov_len;
             --iovcnt;
             ++iovp;
           }
         iovp->iov_base = (char *) iovp->iov_base + r;
         iovp->iov_len -= r;
       again:
         r = TEMP_FAILURE_RETRY (__readv (fd, iovp, iovcnt));
         if (r <= 0)
           {
             if (__builtin_expect (r < 0 && errno == EAGAIN, 0)
                /* The socket is still receiving data.  Wait a bit more.  */
                && wait_on_socket (fd, EXTRA_RECEIVE_TIME) > 0)
              goto again;

             break;
           }
         ret += r;
       }
      while (ret < total);
      if (r < 0)
       ret = r;
    }
  return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

ssize_t sendfileall ( int  tofd,
int  fromfd,
off_t  off,
size_t  len 
)

Here is the caller graph for this function:

ssize_t writeall ( int  fd,
const void *  buf,
size_t  len 
)

Definition at line 255 of file connections.c.

{
  size_t n = len;
  ssize_t ret;
  do
    {
      ret = TEMP_FAILURE_RETRY (send (fd, buf, n, MSG_NOSIGNAL));
      if (ret <= 0)
       break;
      buf = (const char *) buf + ret;
      n -= ret;
    }
  while (n > 0);
  return ret < 0 ? ret : len - n;
}

Here is the call graph for this function:

Here is the caller graph for this function: