|
Packit |
8480eb |
/*
|
|
Packit |
8480eb |
* automount.h
|
|
Packit |
8480eb |
*
|
|
Packit |
8480eb |
* Header file for automounter modules
|
|
Packit |
8480eb |
*
|
|
Packit |
8480eb |
*/
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#ifndef AUTOMOUNT_H
|
|
Packit |
8480eb |
#define AUTOMOUNT_H
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#include <stdio.h>
|
|
Packit |
8480eb |
#include <paths.h>
|
|
Packit |
8480eb |
#include <limits.h>
|
|
Packit |
8480eb |
#include <time.h>
|
|
Packit |
8480eb |
#include <syslog.h>
|
|
Packit |
8480eb |
#include <sys/types.h>
|
|
Packit |
8480eb |
#include <pthread.h>
|
|
Packit |
8480eb |
#include <sched.h>
|
|
Packit |
8480eb |
#include <errno.h>
|
|
Packit |
8480eb |
#include <unistd.h>
|
|
Packit |
8480eb |
#include <fcntl.h>
|
|
Packit |
8480eb |
#include <mntent.h>
|
|
Packit |
8480eb |
#include "config.h"
|
|
Packit |
8480eb |
#include "list.h"
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#include <linux/auto_fs4.h>
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#include "defaults.h"
|
|
Packit |
8480eb |
#include "state.h"
|
|
Packit |
8480eb |
#include "master.h"
|
|
Packit |
8480eb |
#include "macros.h"
|
|
Packit |
8480eb |
#include "log.h"
|
|
Packit |
8480eb |
#include "rpc_subs.h"
|
|
Packit |
8480eb |
#include "mounts.h"
|
|
Packit |
8480eb |
#include "parse_subs.h"
|
|
Packit |
8480eb |
#include "mounts.h"
|
|
Packit |
8480eb |
#include "dev-ioctl-lib.h"
|
|
Packit |
8480eb |
#include "parse_amd.h"
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#ifdef WITH_DMALLOC
|
|
Packit |
8480eb |
#include <dmalloc.h>
|
|
Packit |
8480eb |
#endif
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#define ENABLE_CORES 1
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
/* We MUST have the paths to mount(8) and umount(8) */
|
|
Packit |
8480eb |
#ifndef HAVE_MOUNT
|
|
Packit |
8480eb |
#error Failed to locate mount(8)!
|
|
Packit |
8480eb |
#endif
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#ifndef HAVE_UMOUNT
|
|
Packit |
8480eb |
#error Failed to locate umount(8)!
|
|
Packit |
8480eb |
#endif
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#ifndef HAVE_LINUX_PROCFS
|
|
Packit |
8480eb |
#error Failed to verify existence of procfs filesystem!
|
|
Packit |
8480eb |
#endif
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
/* The -s (sloppy) option to mount is good, if we have it... */
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#ifdef HAVE_SLOPPY_MOUNT
|
|
Packit |
8480eb |
#define SLOPPYOPT "-s", /* For use in spawnl() lists */
|
|
Packit |
8480eb |
#define SLOPPY "-s " /* For use in strings */
|
|
Packit |
8480eb |
#else
|
|
Packit |
8480eb |
#define SLOPPYOPT
|
|
Packit |
8480eb |
#define SLOPPY
|
|
Packit |
8480eb |
#endif
|
|
Packit |
8480eb |
|
|
Packit Service |
c566b0 |
#define DAEMON_FLAGS_FOREGROUND 0x0001
|
|
Packit Service |
65ab84 |
#define DAEMON_FLAGS_SYSTEMD_SERVICE 0x0002
|
|
Packit Service |
c566b0 |
#define DAEMON_FLAGS_HAVE_GLOBAL_OPTIONS 0x0004
|
|
Packit Service |
c566b0 |
#define DAEMON_FLAGS_GHOST 0x0008
|
|
Packit Service |
c566b0 |
#define DAEMON_FLAGS_CHECK_DAEMON 0x0010
|
|
Packit Service |
c566b0 |
#define DAEMON_FLAGS_DUMP_MAPS 0x0020
|
|
Packit Service |
c566b0 |
|
|
Packit |
8480eb |
#define AUTOFS_SUPER_MAGIC 0x00000187L
|
|
Packit |
8480eb |
#define SMB_SUPER_MAGIC 0x0000517BL
|
|
Packit |
8480eb |
#define CIFS_MAGIC_NUMBER 0xFF534D42L
|
|
Packit |
8480eb |
#define NCP_SUPER_MAGIC 0x0000564CL
|
|
Packit |
8480eb |
#define NFS_SUPER_MAGIC 0x00006969L
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#define ATTEMPT_ID_SIZE 24
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
/* This sould be enough for at least 20 host aliases */
|
|
Packit |
8480eb |
#define HOST_ENT_BUF_SIZE 2048
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#define CHECK_RATIO 4 /* exp_runfreq = exp_timeout/CHECK_RATIO */
|
|
Packit |
8480eb |
#define AUTOFS_LOCK "/var/lock/autofs" /* To serialize access to mount */
|
|
Packit |
8480eb |
#define MOUNTED_LOCK _PATH_MOUNTED "~" /* mounts' lock file */
|
|
Packit |
8480eb |
#define MTAB_NOTUPDATED 0x1000 /* mtab succeded but not updated */
|
|
Packit |
8480eb |
#define NOT_MOUNTED 0x0100 /* path notmounted */
|
|
Packit |
8480eb |
#define MNT_FORCE_FAIL -1
|
|
Packit |
8480eb |
#define _PROC_MOUNTS "/proc/mounts"
|
|
Packit |
8480eb |
#define _PROC_SELF_MOUNTS "/proc/self/mounts"
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
/* Constants for lookup modules */
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#define LKP_FAIL 0x0001
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#define LKP_INDIRECT 0x0002
|
|
Packit |
8480eb |
#define LKP_DIRECT 0x0004
|
|
Packit |
8480eb |
#define LKP_MULTI 0x0008
|
|
Packit |
8480eb |
#define LKP_NOMATCH 0x0010
|
|
Packit |
8480eb |
#define LKP_MATCH 0x0020
|
|
Packit |
8480eb |
#define LKP_NEXT 0x0040
|
|
Packit |
8480eb |
#define LKP_MOUNT 0x0080
|
|
Packit |
8480eb |
#define LKP_WILD 0x0100
|
|
Packit |
8480eb |
#define LKP_LOOKUP 0x0200
|
|
Packit |
8480eb |
#define LKP_GHOST 0x0400
|
|
Packit |
8480eb |
#define LKP_REREAD 0x0800
|
|
Packit |
8480eb |
#define LKP_NORMAL 0x1000
|
|
Packit |
8480eb |
#define LKP_DISTINCT 0x2000
|
|
Packit |
8480eb |
#define LKP_ERR_MOUNT 0x4000
|
|
Packit |
8480eb |
#define LKP_NOTSUP 0x8000
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#define MAX_ERR_BUF 128
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#ifdef DEBUG
|
|
Packit |
8480eb |
#define DB(x) do { x; } while(0)
|
|
Packit |
8480eb |
#else
|
|
Packit |
8480eb |
#define DB(x) do { } while(0)
|
|
Packit |
8480eb |
#endif
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#define min(a, b) (a <= b ? a : b)
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
/* Forward declaraion */
|
|
Packit |
8480eb |
struct autofs_point;
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
/* mapent cache definition */
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#define CHE_FAIL 0x0000
|
|
Packit |
8480eb |
#define CHE_OK 0x0001
|
|
Packit |
8480eb |
#define CHE_UPDATED 0x0002
|
|
Packit |
8480eb |
#define CHE_RMPATH 0x0004
|
|
Packit |
8480eb |
#define CHE_MISSING 0x0008
|
|
Packit |
8480eb |
#define CHE_COMPLETED 0x0010
|
|
Packit |
8480eb |
#define CHE_DUPLICATE 0x0020
|
|
Packit |
8480eb |
#define CHE_UNAVAIL 0x0040
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#define NULL_MAP_HASHSIZE 64
|
|
Packit |
8480eb |
#define NEGATIVE_TIMEOUT 10
|
|
Packit |
8480eb |
#define UMOUNT_RETRIES 8
|
|
Packit |
8480eb |
#define EXPIRE_RETRIES 3
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
static u_int32_t inline hash(const char *key, unsigned int size)
|
|
Packit |
8480eb |
{
|
|
Packit |
8480eb |
u_int32_t hashval;
|
|
Packit |
8480eb |
char *s = (char *) key;
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
for (hashval = 0; *s != '\0';) {
|
|
Packit |
8480eb |
hashval += (unsigned char) *s++;
|
|
Packit |
8480eb |
hashval += (hashval << 10);
|
|
Packit |
8480eb |
hashval ^= (hashval >> 6);
|
|
Packit |
8480eb |
}
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
hashval += (hashval << 3);
|
|
Packit |
8480eb |
hashval ^= (hashval >> 11);
|
|
Packit |
8480eb |
hashval += (hashval << 15);
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
return hashval % size;
|
|
Packit |
8480eb |
}
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
struct mapent_cache {
|
|
Packit |
8480eb |
pthread_rwlock_t rwlock;
|
|
Packit |
8480eb |
unsigned int size;
|
|
Packit |
8480eb |
pthread_mutex_t ino_index_mutex;
|
|
Packit |
8480eb |
struct list_head *ino_index;
|
|
Packit |
8480eb |
struct autofs_point *ap;
|
|
Packit |
8480eb |
struct map_source *map;
|
|
Packit |
8480eb |
struct mapent **hash;
|
|
Packit |
8480eb |
};
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
struct stack {
|
|
Packit |
8480eb |
char *mapent;
|
|
Packit |
8480eb |
time_t age;
|
|
Packit |
8480eb |
struct stack *next;
|
|
Packit |
8480eb |
};
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
struct mapent {
|
|
Packit |
8480eb |
struct mapent *next;
|
|
Packit |
8480eb |
struct list_head ino_index;
|
|
Packit |
8480eb |
pthread_rwlock_t multi_rwlock;
|
|
Packit |
8480eb |
struct list_head multi_list;
|
|
Packit |
8480eb |
struct mapent_cache *mc;
|
|
Packit |
8480eb |
struct map_source *source;
|
|
Packit |
8480eb |
/* Need to know owner if we're a multi-mount */
|
|
Packit |
8480eb |
struct mapent *multi;
|
|
Packit |
8480eb |
/* Parent nesting point within multi-mount */
|
|
Packit |
8480eb |
struct mapent *parent;
|
|
Packit |
8480eb |
char *key;
|
|
Packit |
8480eb |
char *mapent;
|
|
Packit |
8480eb |
struct stack *stack;
|
|
Packit |
8480eb |
time_t age;
|
|
Packit |
8480eb |
/* Time of last mount fail */
|
|
Packit |
8480eb |
time_t status;
|
|
Packit |
8480eb |
/* For direct mounts per entry context is kept here */
|
|
Packit |
8480eb |
int flags;
|
|
Packit |
8480eb |
/* File descriptor for ioctls */
|
|
Packit |
8480eb |
int ioctlfd;
|
|
Packit |
8480eb |
dev_t dev;
|
|
Packit |
8480eb |
ino_t ino;
|
|
Packit |
8480eb |
};
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
void cache_lock_cleanup(void *arg);
|
|
Packit |
8480eb |
void cache_readlock(struct mapent_cache *mc);
|
|
Packit |
8480eb |
void cache_writelock(struct mapent_cache *mc);
|
|
Packit |
8480eb |
int cache_try_writelock(struct mapent_cache *mc);
|
|
Packit |
8480eb |
void cache_unlock(struct mapent_cache *mc);
|
|
Packit |
8480eb |
int cache_push_mapent(struct mapent *me, char *mapent);
|
|
Packit |
8480eb |
int cache_pop_mapent(struct mapent *me);
|
|
Packit |
8480eb |
struct mapent_cache *cache_init(struct autofs_point *ap, struct map_source *map);
|
|
Packit |
8480eb |
struct mapent_cache *cache_init_null_cache(struct master *master);
|
|
Packit |
8480eb |
int cache_set_ino_index(struct mapent_cache *mc, const char *key, dev_t dev, ino_t ino);
|
|
Packit |
8480eb |
/* void cache_set_ino(struct mapent *me, dev_t dev, ino_t ino); */
|
|
Packit |
8480eb |
struct mapent *cache_lookup_ino(struct mapent_cache *mc, dev_t dev, ino_t ino);
|
|
Packit |
8480eb |
struct mapent *cache_lookup_first(struct mapent_cache *mc);
|
|
Packit |
8480eb |
struct mapent *cache_lookup_next(struct mapent_cache *mc, struct mapent *me);
|
|
Packit |
8480eb |
struct mapent *cache_lookup_key_next(struct mapent *me);
|
|
Packit |
8480eb |
struct mapent *cache_lookup(struct mapent_cache *mc, const char *key);
|
|
Packit |
8480eb |
struct mapent *cache_lookup_distinct(struct mapent_cache *mc, const char *key);
|
|
Packit |
8480eb |
struct mapent *cache_lookup_offset(const char *prefix, const char *offset, int start, struct list_head *head);
|
|
Packit |
8480eb |
struct mapent *cache_partial_match(struct mapent_cache *mc, const char *prefix);
|
|
Packit |
8480eb |
struct mapent *cache_partial_match_wild(struct mapent_cache *mc, const char *prefix);
|
|
Packit |
8480eb |
int cache_add(struct mapent_cache *mc, struct map_source *ms, const char *key, const char *mapent, time_t age);
|
|
Packit |
8480eb |
int cache_update_offset(struct mapent_cache *mc, const char *mkey, const char *key, const char *mapent, time_t age);
|
|
Packit |
8480eb |
void cache_update_negative(struct mapent_cache *mc, struct map_source *ms, const char *key, time_t timeout);
|
|
Packit |
8480eb |
int cache_set_parents(struct mapent *mm);
|
|
Packit |
8480eb |
int cache_update(struct mapent_cache *mc, struct map_source *ms, const char *key, const char *mapent, time_t age);
|
|
Packit |
8480eb |
int cache_delete(struct mapent_cache *mc, const char *key);
|
|
Packit |
8480eb |
int cache_delete_offset(struct mapent_cache *mc, const char *key);
|
|
Packit |
8480eb |
void cache_multi_readlock(struct mapent *me);
|
|
Packit |
8480eb |
void cache_multi_writelock(struct mapent *me);
|
|
Packit |
8480eb |
void cache_multi_unlock(struct mapent *me);
|
|
Packit |
8480eb |
int cache_delete_offset_list(struct mapent_cache *mc, const char *key);
|
|
Packit |
8480eb |
void cache_release(struct map_source *map);
|
|
Packit |
8480eb |
void cache_clean_null_cache(struct mapent_cache *mc);
|
|
Packit |
8480eb |
void cache_release_null_cache(struct master *master);
|
|
Packit |
8480eb |
struct mapent *cache_enumerate(struct mapent_cache *mc, struct mapent *me);
|
|
Packit |
8480eb |
char *cache_get_offset(const char *prefix, char *offset, int start, struct list_head *head, struct list_head **pos);
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
/* Utility functions */
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
char **add_argv(int argc, char **argv, char *str);
|
|
Packit |
8480eb |
char **append_argv(int argc1, char **argv1, int argc2, char **argv2);
|
|
Packit |
8480eb |
const char **copy_argv(int argc, const char **argv);
|
|
Packit |
8480eb |
int compare_argv(int argc1, const char **argv1, int argc2, const char **argv2);
|
|
Packit |
8480eb |
int free_argv(int argc, const char **argv);
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
struct pending_args;
|
|
Packit |
8480eb |
void set_thread_mount_request_log_id(struct pending_args *mt);
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
void dump_core(void);
|
|
Packit |
8480eb |
int aquire_lock(void);
|
|
Packit |
8480eb |
void release_lock(void);
|
|
Packit |
8480eb |
int spawnl(unsigned logopt, const char *prog, ...);
|
|
Packit |
8480eb |
int spawnv(unsigned logopt, const char *prog, const char *const *argv);
|
|
Packit |
8480eb |
int spawn_mount(unsigned logopt, ...);
|
|
Packit |
8480eb |
int spawn_bind_mount(unsigned logopt, ...);
|
|
Packit |
8480eb |
int spawn_umount(unsigned logopt, ...);
|
|
Packit |
8480eb |
void open_mutex_lock(void);
|
|
Packit |
8480eb |
void open_mutex_unlock(void);
|
|
Packit |
8480eb |
int open_fd(const char *, int);
|
|
Packit |
8480eb |
int open_fd_mode(const char *, int, int);
|
|
Packit |
8480eb |
int open_pipe(int[2]);
|
|
Packit |
8480eb |
int open_sock(int, int, int);
|
|
Packit |
8480eb |
FILE *open_fopen_r(const char *);
|
|
Packit |
8480eb |
FILE *open_setmntent_r(const char *);
|
|
Packit |
8480eb |
void reset_signals(void);
|
|
Packit |
8480eb |
int do_mount(struct autofs_point *ap, const char *root, const char *name,
|
|
Packit |
8480eb |
int name_len, const char *what, const char *fstype,
|
|
Packit |
8480eb |
const char *options);
|
|
Packit Service |
a565d0 |
extern unsigned int mp_mode;
|
|
Packit |
8480eb |
int mkdir_path(const char *path, mode_t mode);
|
|
Packit |
8480eb |
int rmdir_path(struct autofs_point *ap, const char *path, dev_t dev);
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
/* Prototype for module functions */
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
/* lookup module */
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#define AUTOFS_LOOKUP_VERSION 5
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#define KEY_MAX_LEN NAME_MAX
|
|
Packit |
8480eb |
#define MAPENT_MAX_LEN 16384
|
|
Packit |
8480eb |
#define PARSE_MAX_BUF KEY_MAX_LEN + MAPENT_MAX_LEN + 2
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
int lookup_nss_read_master(struct master *master, time_t age);
|
|
Packit |
8480eb |
int lookup_nss_read_map(struct autofs_point *ap, struct map_source *source, time_t age);
|
|
Packit |
8480eb |
int lookup_enumerate(struct autofs_point *ap,
|
|
Packit |
8480eb |
int (*fn)(struct autofs_point *,struct mapent *, int), time_t now);
|
|
Packit |
8480eb |
int lookup_ghost(struct autofs_point *ap, const char *root);
|
|
Packit |
8480eb |
int lookup_nss_mount(struct autofs_point *ap, struct map_source *source, const char *name, int name_len);
|
|
Packit |
8480eb |
void lookup_close_lookup(struct autofs_point *ap);
|
|
Packit |
8480eb |
void lookup_prune_one_cache(struct autofs_point *ap, struct mapent_cache *mc, time_t age);
|
|
Packit |
8480eb |
int lookup_prune_cache(struct autofs_point *ap, time_t age);
|
|
Packit |
8480eb |
struct mapent *lookup_source_valid_mapent(struct autofs_point *ap, const char *key, unsigned int type);
|
|
Packit |
8480eb |
struct mapent *lookup_source_mapent(struct autofs_point *ap, const char *key, unsigned int type);
|
|
Packit |
8480eb |
int lookup_source_close_ioctlfd(struct autofs_point *ap, const char *key);
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#ifdef MODULE_LOOKUP
|
|
Packit |
8480eb |
int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **context);
|
|
Packit |
8480eb |
int lookup_reinit(const char *mapfmt, int argc, const char *const *argv, void **context);
|
|
Packit |
8480eb |
int lookup_read_master(struct master *master, time_t age, void *context);
|
|
Packit |
8480eb |
int lookup_read_map(struct autofs_point *, time_t, void *context);
|
|
Packit |
8480eb |
int lookup_mount(struct autofs_point *, const char *, int, void *);
|
|
Packit |
8480eb |
int lookup_done(void *);
|
|
Packit |
8480eb |
#endif
|
|
Packit |
8480eb |
typedef int (*lookup_init_t) (const char *, int, const char *const *, void **);
|
|
Packit |
8480eb |
typedef int (*lookup_reinit_t) (const char *, int, const char *const *, void **);
|
|
Packit |
8480eb |
typedef int (*lookup_read_master_t) (struct master *master, time_t, void *);
|
|
Packit |
8480eb |
typedef int (*lookup_read_map_t) (struct autofs_point *, time_t, void *);
|
|
Packit |
8480eb |
typedef int (*lookup_mount_t) (struct autofs_point *, const char *, int, void *);
|
|
Packit |
8480eb |
typedef int (*lookup_done_t) (void *);
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
struct lookup_mod {
|
|
Packit |
8480eb |
lookup_init_t lookup_init;
|
|
Packit |
8480eb |
lookup_reinit_t lookup_reinit;
|
|
Packit |
8480eb |
lookup_read_master_t lookup_read_master;
|
|
Packit |
8480eb |
lookup_read_map_t lookup_read_map;
|
|
Packit |
8480eb |
lookup_mount_t lookup_mount;
|
|
Packit |
8480eb |
lookup_done_t lookup_done;
|
|
Packit |
8480eb |
char *type;
|
|
Packit |
8480eb |
void *dlhandle;
|
|
Packit |
8480eb |
void *context;
|
|
Packit |
8480eb |
};
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
int open_lookup(const char *name, const char *err_prefix, const char *mapfmt,
|
|
Packit |
8480eb |
int argc, const char *const *argv, struct lookup_mod **lookup);
|
|
Packit |
8480eb |
int reinit_lookup(struct lookup_mod *mod, const char *name,
|
|
Packit |
8480eb |
const char *err_prefix, const char *mapfmt,
|
|
Packit |
8480eb |
int argc, const char *const *argv);
|
|
Packit |
8480eb |
int close_lookup(struct lookup_mod *);
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
/* parse module */
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#define AUTOFS_PARSE_VERSION 5
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#ifdef MODULE_PARSE
|
|
Packit |
8480eb |
int parse_init(int argc, const char *const *argv, void **context);
|
|
Packit |
8480eb |
int parse_reinit(int argc, const char *const *argv, void **context);
|
|
Packit |
8480eb |
int parse_mount(struct autofs_point *ap, const char *name,
|
|
Packit |
8480eb |
int name_len, const char *mapent, void *context);
|
|
Packit |
8480eb |
int parse_done(void *);
|
|
Packit |
8480eb |
#endif
|
|
Packit |
8480eb |
typedef int (*parse_init_t) (int, const char *const *, void **);
|
|
Packit |
8480eb |
typedef int (*parse_reinit_t) (int, const char *const *, void **);
|
|
Packit |
8480eb |
typedef int (*parse_mount_t) (struct autofs_point *, const char *, int, const char *, void *);
|
|
Packit |
8480eb |
typedef int (*parse_done_t) (void *);
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
struct parse_mod {
|
|
Packit |
8480eb |
parse_init_t parse_init;
|
|
Packit |
8480eb |
parse_reinit_t parse_reinit;
|
|
Packit |
8480eb |
parse_mount_t parse_mount;
|
|
Packit |
8480eb |
parse_done_t parse_done;
|
|
Packit |
8480eb |
void *dlhandle;
|
|
Packit |
8480eb |
void *context;
|
|
Packit |
8480eb |
};
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
struct parse_mod *open_parse(const char *name, const char *err_prefix,
|
|
Packit |
8480eb |
int argc, const char *const *argv);
|
|
Packit |
8480eb |
int reinit_parse(struct parse_mod *, const char *name,
|
|
Packit |
8480eb |
const char *err_prefix, int argc, const char *const *argv);
|
|
Packit |
8480eb |
int close_parse(struct parse_mod *);
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
/* mount module */
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#define AUTOFS_MOUNT_VERSION 4
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#ifdef MODULE_MOUNT
|
|
Packit |
8480eb |
int mount_init(void **context);
|
|
Packit |
8480eb |
int mount_reinit(void **context);
|
|
Packit |
8480eb |
int mount_mount(struct autofs_point *ap, const char *root, const char *name, int name_len,
|
|
Packit |
8480eb |
const char *what, const char *fstype, const char *options, void *context);
|
|
Packit |
8480eb |
int mount_done(void *context);
|
|
Packit |
8480eb |
#endif
|
|
Packit |
8480eb |
typedef int (*mount_init_t) (void **);
|
|
Packit |
8480eb |
typedef int (*mount_reinit_t) (void **);
|
|
Packit |
8480eb |
typedef int (*mount_mount_t) (struct autofs_point *, const char *, const char *, int,
|
|
Packit |
8480eb |
const char *, const char *, const char *, void *);
|
|
Packit |
8480eb |
typedef int (*mount_done_t) (void *);
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
struct mount_mod {
|
|
Packit |
8480eb |
mount_init_t mount_init;
|
|
Packit |
8480eb |
mount_reinit_t mount_reinit;
|
|
Packit |
8480eb |
mount_mount_t mount_mount;
|
|
Packit |
8480eb |
mount_done_t mount_done;
|
|
Packit |
8480eb |
void *dlhandle;
|
|
Packit |
8480eb |
void *context;
|
|
Packit |
8480eb |
};
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
struct mount_mod *open_mount(const char *name, const char *err_prefix);
|
|
Packit |
8480eb |
int reinit_mount(struct mount_mod *mod, const char *name, const char *err_prefix);
|
|
Packit |
8480eb |
int close_mount(struct mount_mod *);
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
/* buffer management */
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
size_t _strlen(const char *str, size_t max);
|
|
Packit |
8480eb |
int cat_path(char *buf, size_t len, const char *dir, const char *base);
|
|
Packit |
8480eb |
int ncat_path(char *buf, size_t len,
|
|
Packit |
8480eb |
const char *dir, const char *base, size_t blen);
|
|
Packit |
8480eb |
int _strncmp(const char *s1, const char *s2, size_t n);
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
/* Core automount definitions */
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#ifndef MNT_DETACH
|
|
Packit |
8480eb |
#define MNT_DETACH 0x00000002 /* Just detach from the tree */
|
|
Packit |
8480eb |
#endif
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
struct startup_cond {
|
|
Packit |
8480eb |
pthread_mutex_t mutex;
|
|
Packit |
8480eb |
pthread_cond_t cond;
|
|
Packit |
8480eb |
struct autofs_point *ap;
|
|
Packit |
8480eb |
char *root;
|
|
Packit |
8480eb |
unsigned int done;
|
|
Packit |
8480eb |
unsigned int status;
|
|
Packit |
8480eb |
};
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
int handle_mounts_startup_cond_init(struct startup_cond *suc);
|
|
Packit |
8480eb |
void handle_mounts_startup_cond_destroy(void *arg);
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
struct master_readmap_cond {
|
|
Packit |
8480eb |
pthread_mutex_t mutex;
|
|
Packit |
8480eb |
pthread_cond_t cond;
|
|
Packit |
8480eb |
pthread_t thid; /* map reader thread id */
|
|
Packit |
8480eb |
struct master *master;
|
|
Packit |
8480eb |
time_t age; /* Last time read */
|
|
Packit |
8480eb |
enum states state; /* Next state */
|
|
Packit |
8480eb |
unsigned int signaled; /* Condition has been signaled */
|
|
Packit |
8480eb |
unsigned int busy; /* Map read in progress. */
|
|
Packit |
8480eb |
};
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
struct pending_args {
|
|
Packit |
8480eb |
pthread_mutex_t mutex;
|
|
Packit |
8480eb |
pthread_cond_t cond;
|
|
Packit |
8480eb |
unsigned int signaled; /* Condition has been signaled */
|
|
Packit |
8480eb |
struct autofs_point *ap; /* autofs mount we are working on */
|
|
Packit |
8480eb |
int status; /* Return status */
|
|
Packit |
8480eb |
int type; /* Type of packet */
|
|
Packit |
8480eb |
int ioctlfd; /* Mount ioctl fd */
|
|
Packit |
8480eb |
struct mapent_cache *mc; /* Cache Containing entry */
|
|
Packit |
8480eb |
char name[PATH_MAX]; /* Name field of the request */
|
|
Packit |
8480eb |
dev_t dev; /* device number of mount */
|
|
Packit |
8480eb |
unsigned int len; /* Name field len */
|
|
Packit |
8480eb |
uid_t uid; /* uid of requester */
|
|
Packit |
8480eb |
gid_t gid; /* gid of requester */
|
|
Packit |
8480eb |
pid_t pid; /* pid of requestor */
|
|
Packit |
8480eb |
unsigned long wait_queue_token; /* Associated kernel wait token */
|
|
Packit |
8480eb |
};
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#ifdef INCLUDE_PENDING_FUNCTIONS
|
|
Packit |
8480eb |
static void pending_cond_init(void *arg)
|
|
Packit |
8480eb |
{
|
|
Packit |
8480eb |
struct pending_args *mt = (struct pending_args *) arg;
|
|
Packit |
8480eb |
pthread_condattr_t condattrs;
|
|
Packit |
8480eb |
int status;
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
status = pthread_condattr_init(&condattrs);
|
|
Packit |
8480eb |
if (status)
|
|
Packit |
8480eb |
fatal(status);
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
status = pthread_condattr_setclock(&condattrs, CLOCK_MONOTONIC);
|
|
Packit |
8480eb |
if (status)
|
|
Packit |
8480eb |
fatal(status);
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
status = pthread_cond_init(&mt->cond, &condattrs);
|
|
Packit |
8480eb |
if (status)
|
|
Packit |
8480eb |
fatal(status);
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
pthread_condattr_destroy(&condattrs);
|
|
Packit |
8480eb |
}
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
static void pending_cond_destroy(void *arg)
|
|
Packit |
8480eb |
{
|
|
Packit |
8480eb |
struct pending_args *mt = (struct pending_args *) arg;
|
|
Packit |
8480eb |
int status;
|
|
Packit |
8480eb |
status = pthread_cond_destroy(&mt->cond);
|
|
Packit |
8480eb |
if (status)
|
|
Packit |
8480eb |
fatal(status);
|
|
Packit |
8480eb |
}
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
static void pending_mutex_destroy(void *arg)
|
|
Packit |
8480eb |
{
|
|
Packit |
8480eb |
struct pending_args *mt = (struct pending_args *) arg;
|
|
Packit |
8480eb |
int status = pthread_mutex_destroy(&mt->mutex);
|
|
Packit |
8480eb |
if (status)
|
|
Packit |
8480eb |
fatal(status);
|
|
Packit |
8480eb |
}
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
static void free_pending_args(void *arg)
|
|
Packit |
8480eb |
{
|
|
Packit |
8480eb |
struct pending_args *mt = (struct pending_args *) arg;
|
|
Packit |
8480eb |
free(mt);
|
|
Packit |
8480eb |
}
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
static void pending_mutex_lock(void *arg)
|
|
Packit |
8480eb |
{
|
|
Packit |
8480eb |
struct pending_args *mt = (struct pending_args *) arg;
|
|
Packit |
8480eb |
int status = pthread_mutex_lock(&mt->mutex);
|
|
Packit |
8480eb |
if (status)
|
|
Packit |
8480eb |
fatal(status);
|
|
Packit |
8480eb |
}
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
static void pending_mutex_unlock(void *arg)
|
|
Packit |
8480eb |
{
|
|
Packit |
8480eb |
struct pending_args *mt = (struct pending_args *) arg;
|
|
Packit |
8480eb |
int status = pthread_mutex_unlock(&mt->mutex);
|
|
Packit |
8480eb |
if (status)
|
|
Packit |
8480eb |
fatal(status);
|
|
Packit |
8480eb |
}
|
|
Packit |
8480eb |
#endif
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
struct thread_stdenv_vars {
|
|
Packit |
8480eb |
uid_t uid;
|
|
Packit |
8480eb |
gid_t gid;
|
|
Packit |
8480eb |
char *user;
|
|
Packit |
8480eb |
char *group;
|
|
Packit |
8480eb |
char *home;
|
|
Packit |
8480eb |
};
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
extern pthread_key_t key_thread_stdenv_vars;
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
extern pthread_key_t key_thread_attempt_id;
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
struct kernel_mod_version {
|
|
Packit |
8480eb |
unsigned int major;
|
|
Packit |
8480eb |
unsigned int minor;
|
|
Packit |
8480eb |
};
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
/* Enable/disable ghosted directories */
|
|
Packit |
8480eb |
#define MOUNT_FLAG_GHOST 0x0001
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
/* Directory created for this mount? */
|
|
Packit |
8480eb |
#define MOUNT_FLAG_DIR_CREATED 0x0002
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
/* Use random policy when selecting a host from which to mount */
|
|
Packit |
8480eb |
#define MOUNT_FLAG_RANDOM_SELECT 0x0004
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
/* Mount being re-mounted */
|
|
Packit |
8480eb |
#define MOUNT_FLAG_REMOUNT 0x0008
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
/* Use server weight only for selection */
|
|
Packit |
8480eb |
#define MOUNT_FLAG_USE_WEIGHT_ONLY 0x0010
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
/* Don't use bind mounts even when system supports them */
|
|
Packit |
8480eb |
#define MOUNT_FLAG_NOBIND 0x0020
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
/* Use symlinks instead of bind mounting local mounts */
|
|
Packit |
8480eb |
#define MOUNT_FLAG_SYMLINK 0x0040
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
/* Read amd map even if it's not to be ghosted (browsable) */
|
|
Packit |
8480eb |
#define MOUNT_FLAG_AMD_CACHE_ALL 0x0080
|
|
Packit |
8480eb |
|
|
Packit Service |
bb8d86 |
/* Set mount propagation for bind mounts */
|
|
Packit Service |
bb8d86 |
#define MOUNT_FLAG_SLAVE 0x0100
|
|
Packit Service |
bb8d86 |
#define MOUNT_FLAG_PRIVATE 0x0200
|
|
Packit Service |
bb8d86 |
|
|
Packit Service |
a3f957 |
/* Use strict expire semantics if requested and kernel supports it */
|
|
Packit Service |
a3f957 |
#define MOUNT_FLAG_STRICTEXPIRE 0x0400
|
|
Packit Service |
a3f957 |
|
|
Packit Service |
5ed10e |
/* Indicator for applications to ignore the mount entry */
|
|
Packit Service |
5ed10e |
#define MOUNT_FLAG_IGNORE 0x0800
|
|
Packit Service |
5ed10e |
|
|
Packit |
8480eb |
struct autofs_point {
|
|
Packit |
8480eb |
pthread_t thid;
|
|
Packit |
8480eb |
char *path; /* Mount point name */
|
|
Packit |
8480eb |
mode_t mode; /* Mount point mode */
|
|
Packit |
8480eb |
char *pref; /* amd prefix */
|
|
Packit |
8480eb |
int pipefd; /* File descriptor for pipe */
|
|
Packit |
8480eb |
int kpipefd; /* Kernel end descriptor for pipe */
|
|
Packit |
8480eb |
int ioctlfd; /* File descriptor for ioctls */
|
|
Packit |
8480eb |
int logpri_fifo; /* FIFO used for changing log levels */
|
|
Packit |
8480eb |
dev_t dev; /* "Device" number assigned by kernel */
|
|
Packit |
8480eb |
struct master_mapent *entry; /* Master map entry for this mount */
|
|
Packit |
8480eb |
unsigned int type; /* Type of map direct or indirect */
|
|
Packit |
8480eb |
time_t exp_timeout; /* Indirect mount expire timeout */
|
|
Packit |
8480eb |
time_t exp_runfreq; /* Frequency for polling for timeouts */
|
|
Packit |
8480eb |
time_t negative_timeout; /* timeout in secs for failed mounts */
|
|
Packit |
8480eb |
unsigned int flags; /* autofs mount flags */
|
|
Packit |
8480eb |
unsigned int logopt; /* Per map logging */
|
|
Packit |
8480eb |
pthread_t exp_thread; /* Thread that is expiring */
|
|
Packit |
8480eb |
pthread_t readmap_thread; /* Thread that is reading maps */
|
|
Packit |
8480eb |
enum states state; /* Current state */
|
|
Packit |
8480eb |
int state_pipe[2]; /* State change router pipe */
|
|
Packit |
8480eb |
struct autofs_point *parent; /* Owner of mounts list for submount */
|
|
Packit |
8480eb |
pthread_mutex_t mounts_mutex; /* Protect mount lists */
|
|
Packit |
8480eb |
struct list_head mounts; /* List of autofs mounts at current level */
|
|
Packit |
8480eb |
struct list_head amdmounts; /* List of non submount amd mounts */
|
|
Packit |
8480eb |
unsigned int submount; /* Is this a submount */
|
|
Packit |
8480eb |
unsigned int shutdown; /* Shutdown notification */
|
|
Packit |
8480eb |
unsigned int submnt_count; /* Number of submounts */
|
|
Packit |
8480eb |
struct list_head submounts; /* List of child submounts */
|
|
Packit |
8480eb |
};
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
/* Foreably unlink existing mounts at startup. */
|
|
Packit |
8480eb |
extern int do_force_unlink;
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
/* Standard functions used by daemon or modules */
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#define MOUNT_OFFSET_OK 0
|
|
Packit |
8480eb |
#define MOUNT_OFFSET_FAIL -1
|
|
Packit |
8480eb |
#define MOUNT_OFFSET_IGNORE -2
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
void *handle_mounts(void *arg);
|
|
Packit |
8480eb |
int umount_multi(struct autofs_point *ap, const char *path, int incl);
|
|
Packit |
8480eb |
int do_expire(struct autofs_point *ap, const char *name, int namelen);
|
|
Packit |
8480eb |
void *expire_proc_indirect(void *);
|
|
Packit |
8480eb |
void *expire_proc_direct(void *);
|
|
Packit |
8480eb |
int expire_offsets_direct(struct autofs_point *ap, struct mapent *me, int now);
|
|
Packit |
8480eb |
int mount_autofs_indirect(struct autofs_point *ap, const char *root);
|
|
Packit Service |
42268b |
int do_mount_autofs_direct(struct autofs_point *ap, struct mnt_list *mnts, struct mapent *me, time_t timeout);
|
|
Packit |
8480eb |
int mount_autofs_direct(struct autofs_point *ap);
|
|
Packit |
8480eb |
int mount_autofs_offset(struct autofs_point *ap, struct mapent *me, const char *root, const char *offset);
|
|
Packit |
8480eb |
void submount_signal_parent(struct autofs_point *ap, unsigned int success);
|
|
Packit |
8480eb |
void close_mount_fds(struct autofs_point *ap);
|
|
Packit |
8480eb |
int umount_autofs(struct autofs_point *ap, const char *root, int force);
|
|
Packit |
8480eb |
int umount_autofs_indirect(struct autofs_point *ap, const char *root);
|
|
Packit Service |
42268b |
int do_umount_autofs_direct(struct autofs_point *ap, struct mnt_list *mnts, struct mapent *me);
|
|
Packit |
8480eb |
int umount_autofs_direct(struct autofs_point *ap);
|
|
Packit |
8480eb |
int umount_autofs_offset(struct autofs_point *ap, struct mapent *me);
|
|
Packit |
8480eb |
int handle_packet_expire_indirect(struct autofs_point *ap, autofs_packet_expire_indirect_t *pkt);
|
|
Packit |
8480eb |
int handle_packet_expire_direct(struct autofs_point *ap, autofs_packet_expire_direct_t *pkt);
|
|
Packit |
8480eb |
int handle_packet_missing_indirect(struct autofs_point *ap, autofs_packet_missing_indirect_t *pkt);
|
|
Packit |
8480eb |
int handle_packet_missing_direct(struct autofs_point *ap, autofs_packet_missing_direct_t *pkt);
|
|
Packit |
8480eb |
void rm_unwanted(struct autofs_point *ap, const char *path, int incl);
|
|
Packit |
8480eb |
int count_mounts(struct autofs_point *ap, const char *path, dev_t dev);
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#define mounts_mutex_lock(ap) \
|
|
Packit |
8480eb |
do { \
|
|
Packit |
8480eb |
int _m_lock = pthread_mutex_lock(&ap->mounts_mutex); \
|
|
Packit |
8480eb |
if (_m_lock) \
|
|
Packit |
8480eb |
fatal(_m_lock); \
|
|
Packit |
8480eb |
} while (0)
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#define mounts_mutex_unlock(ap) \
|
|
Packit |
8480eb |
do { \
|
|
Packit |
8480eb |
int _m_unlock = pthread_mutex_unlock(&ap->mounts_mutex); \
|
|
Packit |
8480eb |
if (_m_unlock) \
|
|
Packit |
8480eb |
fatal(_m_unlock); \
|
|
Packit |
8480eb |
} while(0)
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
static inline time_t monotonic_time(time_t *t)
|
|
Packit |
8480eb |
{
|
|
Packit |
8480eb |
struct timespec ts;
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
Packit |
8480eb |
if (t)
|
|
Packit |
8480eb |
*t = (time_t) ts.tv_sec;
|
|
Packit |
8480eb |
return (time_t) ts.tv_sec;
|
|
Packit |
8480eb |
}
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
/* Expire alarm handling routines */
|
|
Packit |
8480eb |
int alarm_start_handler(void);
|
|
Packit |
8480eb |
int alarm_add(struct autofs_point *ap, time_t seconds);
|
|
Packit |
8480eb |
void alarm_delete(struct autofs_point *ap);
|
|
Packit |
8480eb |
|
|
Packit |
8480eb |
#endif
|
|
Packit |
8480eb |
|