Blame nscd/nscd.h

Packit 6c4009
/* Copyright (c) 1998-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#ifndef _NSCD_H
Packit 6c4009
#define _NSCD_H	1
Packit 6c4009
Packit 6c4009
#include <pthread.h>
Packit 6c4009
#include <stdbool.h>
Packit 6c4009
#include <time.h>
Packit 6c4009
#include <sys/uio.h>
Packit 6c4009
Packit 6c4009
/* The declarations for the request and response types are in the file
Packit 6c4009
   "nscd-client.h", which should contain everything needed by client
Packit 6c4009
   functions.  */
Packit 6c4009
#include "nscd-client.h"
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Handle databases.  */
Packit 6c4009
typedef enum
Packit 6c4009
{
Packit 6c4009
  pwddb,
Packit 6c4009
  grpdb,
Packit 6c4009
  hstdb,
Packit 6c4009
  servdb,
Packit 6c4009
  netgrdb,
Packit 6c4009
  lastdb
Packit 6c4009
} dbtype;
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Default limit on the number of times a value gets reloaded without
Packit 6c4009
   being used in the meantime.  NSCD does not throw a value out as
Packit 6c4009
   soon as it times out.  It tries to reload the value from the
Packit 6c4009
   server.  Only if the value has not been used for so many rounds it
Packit 6c4009
   is removed.  */
Packit 6c4009
#define DEFAULT_RELOAD_LIMIT 5
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Time before restarting the process in paranoia mode.  */
Packit 6c4009
#define RESTART_INTERVAL (60 * 60)
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Stack size for worker threads.  */
Packit 6c4009
#define NSCD_THREAD_STACKSIZE 1024 * 1024 * (sizeof (void *) / 4)
Packit 6c4009
Packit 6c4009
/* Maximum size of stack frames we allow the thread to use.  We use
Packit 6c4009
   80% of the thread stack size.  */
Packit 6c4009
#define MAX_STACK_USE ((8 * NSCD_THREAD_STACKSIZE) / 10)
Packit 6c4009
Packit 6c4009
/* Records the file registered per database that when changed
Packit 6c4009
   or modified requires invalidating the database.  */
Packit 6c4009
struct traced_file
Packit 6c4009
{
Packit 6c4009
  /* Tracks the last modified time of the traced file.  */
Packit 6c4009
  time_t mtime;
Packit 6c4009
  /* Support multiple registered files per database.  */
Packit 6c4009
  struct traced_file *next;
Packit 6c4009
  int call_res_init;
Packit 6c4009
  /* Requires Inotify support to do anything useful.  */
Packit 6c4009
#define TRACED_FILE	0
Packit 6c4009
#define TRACED_DIR	1
Packit 6c4009
  int inotify_descr[2];
Packit 6c4009
# ifndef PATH_MAX
Packit 6c4009
#  define PATH_MAX 1024
Packit 6c4009
# endif
Packit 6c4009
  /* The parent directory is used to scan for creation/deletion.  */
Packit 6c4009
  char dname[PATH_MAX];
Packit 6c4009
  /* Just the name of the file with no directory component.  */
Packit 6c4009
  char *sfname;
Packit 6c4009
  /* The full-path name of the registered file.  */
Packit 6c4009
  char fname[];
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
/* Initialize a `struct traced_file`.  As input we need the name
Packit 6c4009
   of the file, and if invalidation requires calling res_init.
Packit 6c4009
   If CRINIT is 1 then res_init will be called after invalidation
Packit 6c4009
   or if the traced file is changed in any way, otherwise it will
Packit 6c4009
   not.  */
Packit 6c4009
static inline void
Packit 6c4009
init_traced_file(struct traced_file *file, const char *fname, int crinit)
Packit 6c4009
{
Packit 6c4009
   char *dname;
Packit 6c4009
   file->mtime = 0;
Packit 6c4009
   file->inotify_descr[TRACED_FILE] = -1;
Packit 6c4009
   file->inotify_descr[TRACED_DIR] = -1;
Packit 6c4009
   strcpy (file->fname, fname);
Packit 6c4009
   /* Compute the parent directory name and store a copy.  The copy makes
Packit 6c4009
      it much faster to add/remove watches while nscd is running instead
Packit 6c4009
      of computing this over and over again in a temp buffer.  */
Packit 6c4009
   file->dname[0] = '\0';
Packit 6c4009
   dname = strrchr (fname, '/');
Packit 6c4009
   if (dname != NULL)
Packit 6c4009
     {
Packit 6c4009
       size_t len = (size_t)(dname - fname);
Packit 6c4009
       if (len > sizeof (file->dname))
Packit 6c4009
	 abort ();
Packit 6c4009
       memcpy (file->dname, file->fname, len);
Packit 6c4009
       file->dname[len] = '\0';
Packit 6c4009
     }
Packit 6c4009
   /* The basename is the name just after the last forward slash.  */
Packit 6c4009
   file->sfname = &dname[1];
Packit 6c4009
   file->call_res_init = crinit;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#define define_traced_file(id, filename) 			\
Packit 6c4009
static union							\
Packit 6c4009
{								\
Packit 6c4009
  struct traced_file file;					\
Packit 6c4009
  char buf[sizeof (struct traced_file) + sizeof (filename)];	\
Packit 6c4009
} id##_traced_file;
Packit 6c4009
Packit 6c4009
/* Structure describing dynamic part of one database.  */
Packit 6c4009
struct database_dyn
Packit 6c4009
{
Packit 6c4009
  pthread_rwlock_t lock;
Packit 6c4009
  pthread_cond_t prune_cond;
Packit 6c4009
  pthread_mutex_t prune_lock;
Packit 6c4009
  pthread_mutex_t prune_run_lock;
Packit 6c4009
  time_t wakeup_time;
Packit 6c4009
Packit 6c4009
  int enabled;
Packit 6c4009
  int check_file;
Packit 6c4009
  int clear_cache;
Packit 6c4009
  int persistent;
Packit 6c4009
  int shared;
Packit 6c4009
  int propagate;
Packit 6c4009
  struct traced_file *traced_files;
Packit 6c4009
  const char *db_filename;
Packit 6c4009
  size_t suggested_module;
Packit 6c4009
  size_t max_db_size;
Packit 6c4009
Packit 6c4009
  unsigned long int postimeout;	/* In seconds.  */
Packit 6c4009
  unsigned long int negtimeout;	/* In seconds.  */
Packit 6c4009
Packit 6c4009
  int wr_fd;			/* Writable file descriptor.  */
Packit 6c4009
  int ro_fd;			/* Unwritable file descriptor.  */
Packit 6c4009
Packit 6c4009
  const struct iovec *disabled_iov;
Packit 6c4009
Packit 6c4009
  struct database_pers_head *head;
Packit 6c4009
  char *data;
Packit 6c4009
  size_t memsize;
Packit 6c4009
  pthread_mutex_t memlock;
Packit 6c4009
  bool mmap_used;
Packit 6c4009
  bool last_alloc_failed;
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Paths of the file for the persistent storage.  */
Packit 6c4009
#define _PATH_NSCD_PASSWD_DB	"/var/db/nscd/passwd"
Packit 6c4009
#define _PATH_NSCD_GROUP_DB	"/var/db/nscd/group"
Packit 6c4009
#define _PATH_NSCD_HOSTS_DB	"/var/db/nscd/hosts"
Packit 6c4009
#define _PATH_NSCD_SERVICES_DB	"/var/db/nscd/services"
Packit 6c4009
#define _PATH_NSCD_NETGROUP_DB	"/var/db/nscd/netgroup"
Packit 6c4009
Packit 6c4009
/* Path used when not using persistent storage.  */
Packit 6c4009
#define _PATH_NSCD_XYZ_DB_TMP	"/var/run/nscd/dbXXXXXX"
Packit 6c4009
Packit 6c4009
/* Maximum alignment requirement we will encounter.  */
Packit 6c4009
#define BLOCK_ALIGN_LOG 3
Packit 6c4009
#define BLOCK_ALIGN (1 << BLOCK_ALIGN_LOG)
Packit 6c4009
#define BLOCK_ALIGN_M1 (BLOCK_ALIGN - 1)
Packit 6c4009
Packit 6c4009
/* Default value for the maximum size of the database files.  */
Packit 6c4009
#define DEFAULT_MAX_DB_SIZE	(32 * 1024 * 1024)
Packit 6c4009
Packit 6c4009
/* Number of bytes of data we initially reserve for each hash table bucket.  */
Packit 6c4009
#define DEFAULT_DATASIZE_PER_BUCKET 1024
Packit 6c4009
Packit 6c4009
/* Default module of hash table.  */
Packit 6c4009
#define DEFAULT_SUGGESTED_MODULE 211
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Number of seconds between two cache pruning runs if we do not have
Packit 6c4009
   better information when it is really needed.  */
Packit 6c4009
#define CACHE_PRUNE_INTERVAL	15
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Global variables.  */
Packit 6c4009
extern struct database_dyn dbs[lastdb] attribute_hidden;
Packit 6c4009
extern const char *const dbnames[lastdb];
Packit 6c4009
extern const char *const serv2str[LASTREQ];
Packit 6c4009
Packit 6c4009
extern const struct iovec pwd_iov_disabled;
Packit 6c4009
extern const struct iovec grp_iov_disabled;
Packit 6c4009
extern const struct iovec hst_iov_disabled;
Packit 6c4009
extern const struct iovec serv_iov_disabled;
Packit 6c4009
extern const struct iovec netgroup_iov_disabled;
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Initial number of threads to run.  */
Packit 6c4009
extern int nthreads;
Packit 6c4009
/* Maximum number of threads to use.  */
Packit 6c4009
extern int max_nthreads;
Packit 6c4009
Packit 6c4009
/* Inotify descriptor.  */
Packit 6c4009
extern int inotify_fd;
Packit 6c4009
Packit 6c4009
/* User name to run server processes as.  */
Packit 6c4009
extern const char *server_user;
Packit 6c4009
Packit 6c4009
/* Name and UID of user who is allowed to request statistics.  */
Packit 6c4009
extern const char *stat_user;
Packit 6c4009
extern uid_t stat_uid;
Packit 6c4009
Packit 6c4009
/* Time the server was started.  */
Packit 6c4009
extern time_t start_time;
Packit 6c4009
Packit 6c4009
/* Number of times clients had to wait.  */
Packit 6c4009
extern unsigned long int client_queued;
Packit 6c4009
Packit 6c4009
/* Maximum needed alignment.  */
Packit 6c4009
extern const size_t block_align;
Packit 6c4009
Packit 6c4009
/* Number of times a value is reloaded without being used.  UINT_MAX
Packit 6c4009
   means unlimited.  */
Packit 6c4009
extern unsigned int reload_count;
Packit 6c4009
Packit 6c4009
/* Pagesize minus one.  */
Packit 6c4009
extern uintptr_t pagesize_m1;
Packit 6c4009
Packit 6c4009
/* Nonzero if paranoia mode is enabled.  */
Packit 6c4009
extern int paranoia;
Packit 6c4009
/* Time after which the process restarts.  */
Packit 6c4009
extern time_t restart_time;
Packit 6c4009
/* How much time between restarts.  */
Packit 6c4009
extern time_t restart_interval;
Packit 6c4009
/* Old current working directory.  */
Packit 6c4009
extern const char *oldcwd;
Packit 6c4009
/* Old user and group ID.  */
Packit 6c4009
extern uid_t old_uid;
Packit 6c4009
extern gid_t old_gid;
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Prototypes for global functions.  */
Packit 6c4009
Packit 6c4009
/* Wrapper functions with error checking for standard functions.  */
Packit 6c4009
#include <programs/xmalloc.h>
Packit 6c4009
Packit 6c4009
/* nscd.c */
Packit 6c4009
extern void termination_handler (int signum) __attribute__ ((__noreturn__));
Packit 6c4009
extern int nscd_open_socket (void);
Packit 6c4009
void notify_parent (int child_ret);
Packit 6c4009
void do_exit (int child_ret, int errnum, const char *format, ...);
Packit 6c4009
Packit 6c4009
/* connections.c */
Packit 6c4009
extern void nscd_init (void);
Packit 6c4009
extern void register_traced_file (size_t dbidx, struct traced_file *finfo);
Packit 6c4009
#ifdef HAVE_INOTIFY
Packit 6c4009
extern void install_watches (struct traced_file *finfo);
Packit 6c4009
#endif
Packit 6c4009
extern void close_sockets (void);
Packit 6c4009
extern void start_threads (void) __attribute__ ((__noreturn__));
Packit 6c4009
Packit 6c4009
/* nscd_conf.c */
Packit 6c4009
extern int nscd_parse_file (const char *fname,
Packit 6c4009
			    struct database_dyn dbs[lastdb]);
Packit 6c4009
Packit 6c4009
/* nscd_stat.c */
Packit 6c4009
extern void send_stats (int fd, struct database_dyn dbs[lastdb]);
Packit 6c4009
extern int receive_print_stats (void) __attribute__ ((__noreturn__));
Packit 6c4009
Packit 6c4009
/* cache.c */
Packit 6c4009
extern struct datahead *cache_search (request_type, const void *key,
Packit 6c4009
				      size_t len, struct database_dyn *table,
Packit 6c4009
				      uid_t owner);
Packit 6c4009
extern int cache_add (int type, const void *key, size_t len,
Packit 6c4009
		      struct datahead *packet, bool first,
Packit 6c4009
		      struct database_dyn *table, uid_t owner,
Packit 6c4009
		      bool prune_wakeup);
Packit 6c4009
extern time_t prune_cache (struct database_dyn *table, time_t now, int fd);
Packit 6c4009
Packit 6c4009
/* pwdcache.c */
Packit 6c4009
extern void addpwbyname (struct database_dyn *db, int fd, request_header *req,
Packit 6c4009
			 void *key, uid_t uid);
Packit 6c4009
extern void addpwbyuid (struct database_dyn *db, int fd, request_header *req,
Packit 6c4009
			void *key, uid_t uid);
Packit 6c4009
extern time_t readdpwbyname (struct database_dyn *db, struct hashentry *he,
Packit 6c4009
			     struct datahead *dh);
Packit 6c4009
extern time_t readdpwbyuid (struct database_dyn *db, struct hashentry *he,
Packit 6c4009
			    struct datahead *dh);
Packit 6c4009
Packit 6c4009
/* grpcache.c */
Packit 6c4009
extern void addgrbyname (struct database_dyn *db, int fd, request_header *req,
Packit 6c4009
			 void *key, uid_t uid);
Packit 6c4009
extern void addgrbygid (struct database_dyn *db, int fd, request_header *req,
Packit 6c4009
			void *key, uid_t uid);
Packit 6c4009
extern time_t readdgrbyname (struct database_dyn *db, struct hashentry *he,
Packit 6c4009
			     struct datahead *dh);
Packit 6c4009
extern time_t readdgrbygid (struct database_dyn *db, struct hashentry *he,
Packit 6c4009
			    struct datahead *dh);
Packit 6c4009
Packit 6c4009
/* hstcache.c */
Packit 6c4009
extern void addhstbyname (struct database_dyn *db, int fd, request_header *req,
Packit 6c4009
			  void *key, uid_t uid);
Packit 6c4009
extern void addhstbyaddr (struct database_dyn *db, int fd, request_header *req,
Packit 6c4009
			  void *key, uid_t uid);
Packit 6c4009
extern void addhstbynamev6 (struct database_dyn *db, int fd,
Packit 6c4009
			    request_header *req, void *key, uid_t uid);
Packit 6c4009
extern void addhstbyaddrv6 (struct database_dyn *db, int fd,
Packit 6c4009
			    request_header *req, void *key, uid_t uid);
Packit 6c4009
extern time_t readdhstbyname (struct database_dyn *db, struct hashentry *he,
Packit 6c4009
			      struct datahead *dh);
Packit 6c4009
extern time_t readdhstbyaddr (struct database_dyn *db, struct hashentry *he,
Packit 6c4009
			      struct datahead *dh);
Packit 6c4009
extern time_t readdhstbynamev6 (struct database_dyn *db, struct hashentry *he,
Packit 6c4009
				struct datahead *dh);
Packit 6c4009
extern time_t readdhstbyaddrv6 (struct database_dyn *db, struct hashentry *he,
Packit 6c4009
				struct datahead *dh);
Packit 6c4009
Packit 6c4009
/* aicache.c */
Packit 6c4009
extern void addhstai (struct database_dyn *db, int fd, request_header *req,
Packit 6c4009
		      void *key, uid_t uid);
Packit 6c4009
extern time_t readdhstai (struct database_dyn *db, struct hashentry *he,
Packit 6c4009
			  struct datahead *dh);
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* initgrcache.c */
Packit 6c4009
extern void addinitgroups (struct database_dyn *db, int fd,
Packit 6c4009
			   request_header *req, void *key, uid_t uid);
Packit 6c4009
extern time_t readdinitgroups (struct database_dyn *db, struct hashentry *he,
Packit 6c4009
			       struct datahead *dh);
Packit 6c4009
Packit 6c4009
/* servicecache.c */
Packit 6c4009
extern void addservbyname (struct database_dyn *db, int fd,
Packit 6c4009
			   request_header *req, void *key, uid_t uid);
Packit 6c4009
extern time_t readdservbyname (struct database_dyn *db, struct hashentry *he,
Packit 6c4009
			       struct datahead *dh);
Packit 6c4009
extern void addservbyport (struct database_dyn *db, int fd,
Packit 6c4009
			   request_header *req, void *key, uid_t uid);
Packit 6c4009
extern time_t readdservbyport (struct database_dyn *db, struct hashentry *he,
Packit 6c4009
			       struct datahead *dh);
Packit 6c4009
Packit 6c4009
/* netgroupcache.c */
Packit 6c4009
extern void addinnetgr (struct database_dyn *db, int fd, request_header *req,
Packit 6c4009
			void *key, uid_t uid);
Packit 6c4009
extern time_t readdinnetgr (struct database_dyn *db, struct hashentry *he,
Packit 6c4009
			    struct datahead *dh);
Packit 6c4009
extern void addgetnetgrent (struct database_dyn *db, int fd,
Packit 6c4009
			    request_header *req, void *key, uid_t uid);
Packit 6c4009
extern time_t readdgetnetgrent (struct database_dyn *db, struct hashentry *he,
Packit 6c4009
				struct datahead *dh);
Packit 6c4009
Packit 6c4009
/* mem.c */
Packit 6c4009
extern void *mempool_alloc (struct database_dyn *db, size_t len,
Packit 6c4009
			    int data_alloc);
Packit 6c4009
extern void gc (struct database_dyn *db);
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* nscd_setup_thread.c */
Packit 6c4009
extern int setup_thread (struct database_dyn *db);
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Special version of TEMP_FAILURE_RETRY for functions returning error
Packit 6c4009
   values.  */
Packit 6c4009
#define TEMP_FAILURE_RETRY_VAL(expression) \
Packit 6c4009
  (__extension__							      \
Packit 6c4009
    ({ long int __result;						      \
Packit 6c4009
       do __result = (long int) (expression);				      \
Packit 6c4009
       while (__result == EINTR);					      \
Packit 6c4009
       __result; }))
Packit 6c4009
Packit 6c4009
#endif /* nscd.h */