diff --git a/CHANGELOG b/CHANGELOG index 0e31a60..c47648d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +?/7/2006 autofs-5.0.1 +--------------------- +- code cleanup. + 13/7/2006 autofs-5.0.1 rc1 -------------------------- - merge LDAP authentication update for GSSAPI (Jeff Moyer). diff --git a/daemon/automount.c b/daemon/automount.c index 673c005..23c123f 100644 --- a/daemon/automount.c +++ b/daemon/automount.c @@ -1,4 +1,3 @@ -#ident "$Id: automount.c,v 1.78 2006/04/06 20:02:04 raven Exp $" /* ----------------------------------------------------------------------- * * * automount.c - Linux automounter daemon @@ -54,10 +53,10 @@ static int *pst_stat = &st_stat; /* Attribute to create detached thread */ pthread_attr_t thread_attr; -struct master_readmap_cond mc = { - PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0, NULL, 0, 0}; +struct master_readmap_cond mrc = { + PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0, NULL, 0, 0, 0, 0}; -struct startup_cond sc = { +struct startup_cond suc = { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0, 0}; pthread_key_t key_thread_stdenv_vars; @@ -70,7 +69,7 @@ #define MAX_OPEN_FILES 10240 static int umount_all(struct autofs_point *ap, int force); extern pthread_mutex_t master_mutex; -extern struct master *master; +extern struct master *master_list; int mkdir_path(const char *path, mode_t mode) { @@ -547,7 +546,9 @@ int umount_multi(struct autofs_point *ap int left; struct mnt_list *mptr; struct list_head *p; - LIST_HEAD(list); + struct list_head list; + + INIT_LIST_HEAD(&list); debug(ap->logopt, "path %s incl %d", path, incl); @@ -615,7 +616,7 @@ static int umount_all(struct autofs_poin int umount_autofs(struct autofs_point *ap, int force) { - int status = 0; + int ret = 0; if (ap->state == ST_INIT) return -1; @@ -631,9 +632,9 @@ int umount_autofs(struct autofs_point *a if (umount_all(ap, force) && !force) return -1; - status = umount_autofs_indirect(ap); + ret = umount_autofs_indirect(ap); } else { - status = umount_autofs_direct(ap); + ret = umount_autofs_direct(ap); } if (ap->submount) { @@ -653,7 +654,7 @@ int umount_autofs(struct autofs_point *a fatal(status); } - return status; + return ret; } int send_ready(int ioctlfd, unsigned int wait_queue_token) @@ -929,7 +930,7 @@ static void do_master_cleanup_unlock(voi { int status; - status = pthread_mutex_unlock(&mc.mutex); + status = pthread_mutex_unlock(&mrc.mutex); if (status) fatal(status); @@ -944,26 +945,26 @@ static void *do_notify_state(void *arg) sig = *(int *) arg; - status = pthread_mutex_lock(&mc.mutex); + status = pthread_mutex_lock(&mrc.mutex); if (status) fatal(status); - master = mc.master; + master = mrc.master; debug(master->default_logging, "signal %d", sig); - mc.signaled = 1; - status = pthread_cond_signal(&mc.cond); + mrc.signaled = 1; + status = pthread_cond_signal(&mrc.cond); if (status) { error(master->default_logging, "failed to signal state notify condition"); - status = pthread_mutex_unlock(&mc.mutex); + status = pthread_mutex_unlock(&mrc.mutex); if (status) fatal(status); pthread_exit(NULL); } - status = pthread_mutex_unlock(&mc.mutex); + status = pthread_mutex_unlock(&mrc.mutex); if (status) fatal(status); @@ -972,34 +973,34 @@ static void *do_notify_state(void *arg) return NULL; } -static int do_signals(struct master *master, int signal) +static int do_signals(struct master *master, int sig) { pthread_t thid; - int sig = signal; + int r_sig = sig; int status; - status = pthread_mutex_lock(&mc.mutex); + status = pthread_mutex_lock(&mrc.mutex); if (status) fatal(status); - status = pthread_create(&thid, &thread_attr, do_notify_state, &sig); + status = pthread_create(&thid, &thread_attr, do_notify_state, &r_sig); if (status) { error(master->default_logging, "mount state notify thread create failed"); - status = pthread_mutex_unlock(&mc.mutex); + status = pthread_mutex_unlock(&mrc.mutex); if (status) fatal(status); return 0; } - mc.thid = thid; - mc.master = master; + mrc.thid = thid; + mrc.master = master; pthread_cleanup_push(do_master_cleanup_unlock, NULL); - mc.signaled = 0; - while (!mc.signaled) { - status = pthread_cond_wait(&mc.cond, &mc.mutex); + mrc.signaled = 0; + while (!mrc.signaled) { + status = pthread_cond_wait(&mrc.cond, &mrc.mutex); if (status) fatal(status); } @@ -1016,25 +1017,25 @@ static void *do_read_master(void *arg) int readall = 1; int status; - status = pthread_mutex_lock(&mc.mutex); + status = pthread_mutex_lock(&mrc.mutex); if (status) fatal(status); - master = mc.master; - age = mc.age; + master = mrc.master; + age = mrc.age; - mc.signaled = 1; - status = pthread_cond_signal(&mc.cond); + mrc.signaled = 1; + status = pthread_cond_signal(&mrc.cond); if (status) { error(master->default_logging, "failed to signal master read map condition"); - status = pthread_mutex_unlock(&mc.mutex); + status = pthread_mutex_unlock(&mrc.mutex); if (status) fatal(status); pthread_exit(NULL); } - status = pthread_mutex_unlock(&mc.mutex); + status = pthread_mutex_unlock(&mrc.mutex); if (status) fatal(status); @@ -1048,7 +1049,7 @@ static int do_hup_signal(struct master * pthread_t thid; int status; - status = pthread_mutex_lock(&mc.mutex); + status = pthread_mutex_lock(&mrc.mutex); if (status) fatal(status); @@ -1056,21 +1057,21 @@ static int do_hup_signal(struct master * if (status) { error(master->default_logging, "master read map thread create failed"); - status = pthread_mutex_unlock(&mc.mutex); + status = pthread_mutex_unlock(&mrc.mutex); if (status) fatal(status); return 0; } - mc.thid = thid; - mc.master = master; - mc.age = age; + mrc.thid = thid; + mrc.master = master; + mrc.age = age; pthread_cleanup_push(do_master_cleanup_unlock, NULL); - mc.signaled = 0; - while (!mc.signaled) { - status = pthread_cond_wait(&mc.cond, &mc.mutex); + mrc.signaled = 0; + while (!mrc.signaled) { + status = pthread_cond_wait(&mrc.cond, &mrc.mutex); if (status) fatal(status); } @@ -1083,21 +1084,21 @@ static int do_hup_signal(struct master * /* Deal with all the signal-driven events in the state machine */ static void *statemachine(void *arg) { - sigset_t sigset; + sigset_t signalset; int sig, status; - sigfillset(&sigset); - sigdelset(&sigset, SIGCHLD); - sigdelset(&sigset, SIGCONT); + sigfillset(&signalset); + sigdelset(&signalset, SIGCHLD); + sigdelset(&signalset, SIGCONT); while (1) { - sigwait(&sigset, &sig); + sigwait(&signalset, &sig); status = pthread_mutex_lock(&master_mutex); if (status) fatal(status); - if (list_empty(&master->mounts)) { + if (list_empty(&master_list->mounts)) { status = pthread_mutex_unlock(&master_mutex); if (status) fatal(status); @@ -1112,15 +1113,15 @@ static void *statemachine(void *arg) case SIGTERM: case SIGUSR2: case SIGUSR1: - do_signals(master, sig); + do_signals(master_list, sig); break; case SIGHUP: - do_hup_signal(master, time(NULL)); + do_hup_signal(master_list, time(NULL)); break; default: - error(master->default_logging, + error(master_list->default_logging, "got unexpected signal %d!", sig); continue; } @@ -1213,7 +1214,7 @@ static void handle_mounts_cleanup(void * master_free_mapent(ap->entry); /* If we are the last tell the state machine to shutdown */ - if (master_list_empty(master)) + if (master_list_empty(master_list)) kill(getpid(), SIGTERM); if (clean) { @@ -1236,14 +1237,14 @@ void *handle_mounts(void *arg) ap = (struct autofs_point *) arg; - pthread_cleanup_push(return_start_status, &sc); + pthread_cleanup_push(return_start_status, &suc); pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancel_state); status = pthread_mutex_lock(&ap->state_mutex); if (status) fatal(status); - status = pthread_mutex_lock(&sc.mutex); + status = pthread_mutex_lock(&suc.mutex); if (status) { crit(ap->logopt, "failed to lock startup condition mutex!"); fatal(status); @@ -1251,7 +1252,7 @@ void *handle_mounts(void *arg) if (mount_autofs(ap) < 0) { crit(ap->logopt, "mount of %s failed!", ap->path); - sc.status = 1; + suc.status = 1; status = pthread_mutex_unlock(&ap->state_mutex); if (status) fatal(status); @@ -1262,7 +1263,7 @@ void *handle_mounts(void *arg) if (ap->ghost && ap->type != LKP_DIRECT) msg("ghosting enabled"); - sc.status = 0; + suc.status = 0; pthread_cleanup_pop(1); /* We often start several automounters at the same time. Add some @@ -1395,7 +1396,6 @@ static int is_automount_running(void) struct dirent entry; struct dirent *result; char path[PATH_MAX + 1], buf[PATH_MAX]; - int len; if ((dir = opendir("/proc")) == NULL) { fprintf(stderr, "cannot opendir(/proc)\n"); @@ -1403,7 +1403,7 @@ static int is_automount_running(void) } while (readdir_r(dir, &entry, &result) == 0) { - int pid = 0; + int path_len, pid = 0; if (!result) break; @@ -1421,13 +1421,13 @@ static int is_automount_running(void) if (pid == getpid()) continue; - len = sprintf(path, "/proc/%s/cmdline", entry.d_name); - if (len >= PATH_MAX) { + path_len = sprintf(path, "/proc/%s/cmdline", entry.d_name); + if (path_len >= PATH_MAX) { fprintf(stderr, "buffer to small for /proc path\n"); return -1; } - path[len] = '\0'; + path[path_len] = '\0'; fp = fopen(path, "r"); if (fp) { @@ -1655,11 +1655,11 @@ #endif become_daemon(foreground); if (argc == 0) - master = master_new(NULL, timeout, ghost); + master_list = master_new(NULL, timeout, ghost); else - master = master_new(argv[0], timeout, ghost); + master_list = master_new(argv[0], timeout, ghost); - if (!master) { + if (!master_list) { crit(LOGOPT_ANY, "%s: can't create master map %s", program, argv[0]); close(start_pipefd[1]); @@ -1695,35 +1695,35 @@ #ifdef _POSIX_THREAD_ATTR_STACKSIZE #endif msg("Starting automounter version %s, master map %s", - version, master->name); + version, master_list->name); status = pthread_key_create(&key_thread_stdenv_vars, key_thread_stdenv_vars_destroy); if (status) { crit(LOGOPT_ANY, "failed to create thread data key for std env vars!"); - master_kill(master, 1); + master_kill(master_list); close(start_pipefd[1]); exit(1); } if (!alarm_start_handler()) { crit(LOGOPT_ANY, "failed to create alarm handler thread!"); - master_kill(master, 1); + master_kill(master_list); close(start_pipefd[1]); exit(1); } if (!st_start_handler()) { crit(LOGOPT_ANY, "failed to create FSM handler thread!"); - master_kill(master, 1); + master_kill(master_list); close(start_pipefd[1]); exit(1); } if (!sigchld_start_handler()) { crit(LOGOPT_ANY, "failed to create SIGCHLD handler thread!"); - master_kill(master, 1); + master_kill(master_list); close(start_pipefd[1]); exit(1); } @@ -1731,15 +1731,15 @@ #if 0 if (!load_autofs4_module()) { crit(LOGOPT_ANY, "%s: can't load %s filesystem module", program, FS_MODULE_NAME); - master_kill(master, 1); + master_kill(master_list); *pst_stat = 2; res = write(start_pipefd[1], pst_stat, sizeof(pst_stat)); close(start_pipefd[1]); exit(2); } #endif - if (!master_read_master(master, age, 0)) { - master_kill(master, 1); + if (!master_read_master(master_list, age, 0)) { + master_kill(master_list); *pst_stat = 3; res = write(start_pipefd[1], pst_stat, sizeof(pst_stat)); close(start_pipefd[1]); @@ -1751,7 +1751,7 @@ #endif statemachine(NULL); - master_kill(master, 1); + master_kill(master_list); if (pid_file) { unlink(pid_file); diff --git a/daemon/direct.c b/daemon/direct.c index bfe4dbf..bb75755 100644 --- a/daemon/direct.c +++ b/daemon/direct.c @@ -1,4 +1,3 @@ -#ident "$Id: direct.c,v 1.34 2006/04/03 23:00:05 raven Exp $" /* ----------------------------------------------------------------------- * * * direct.c - Linux automounter direct mount handling @@ -219,31 +218,12 @@ int umount_autofs_direct(struct autofs_p return 0; } -static int unlink_mount_tree(struct autofs_point *ap, struct list_head *list, const char *mount) +static int unlink_mount_tree(struct autofs_point *ap, struct list_head *list) { struct list_head *p; int rv, ret; pid_t pgrp = getpgrp(); char spgrp[10]; -/* - need_umount = 0; - list_for_each(p, list) { - struct mnt_list *mnt; - - mnt = list_entry(p, struct mnt_list, list); - - if (strcmp(mount, mnt->path)) - continue; - - if (!strstr(mnt->opts, "direct")) - continue; - - need_umount = 1; - } - - if (!need_umount) - return 1; -*/ sprintf(spgrp, "%d", pgrp); @@ -282,19 +262,21 @@ static int unlink_mount_tree(struct auto return ret; } -int do_mount_autofs_direct(struct autofs_point *ap, struct mnt_list *mnts, struct mapent *me, int now) +int do_mount_autofs_direct(struct autofs_point *ap, struct mnt_list *mnts, struct mapent *me) { struct map_source *map = ap->entry->current; struct mnt_params *mp; time_t timeout = ap->exp_timeout; struct stat st; int status, ret; - LIST_HEAD(list); + struct list_head list; + + INIT_LIST_HEAD(&list); if (tree_get_mnt_list(mnts, &list, me->key, 1)) { if (ap->state == ST_READMAP) return 0; - if (!unlink_mount_tree(ap, &list, me->key)) { + if (!unlink_mount_tree(ap, &list)) { debug(ap->logopt, "already mounted as other than autofs " "or failed to unlink entry in tree"); @@ -467,7 +449,7 @@ int mount_autofs_direct(struct autofs_po me = cache_enumerate(mc, NULL); while (me) { /* TODO: check return, locking me */ - do_mount_autofs_direct(ap, mnts, me, now); + do_mount_autofs_direct(ap, mnts, me); me = cache_enumerate(mc, me); } pthread_cleanup_pop(1); @@ -866,7 +848,7 @@ static void *do_expire_direct(void *arg) { struct pending_args *mt; struct autofs_point *ap; - int len; + size_t len; int status; mt = (struct pending_args *) arg; diff --git a/daemon/indirect.c b/daemon/indirect.c index 2427713..c46326c 100644 --- a/daemon/indirect.c +++ b/daemon/indirect.c @@ -1,4 +1,3 @@ -#ident "$Id: indirect.c,v 1.30 2006/04/03 23:00:05 raven Exp $" /* ----------------------------------------------------------------------- * * * indirect.c - Linux automounter indirect mount handling @@ -78,33 +77,12 @@ static int autofs_init_indirect(struct a return 0; } -static int unlink_mount_tree(struct autofs_point *ap, struct mnt_list *mnts, const char *mount) +static int unlink_mount_tree(struct autofs_point *ap, struct mnt_list *mnts) { struct mnt_list *this; int rv, ret; pid_t pgrp = getpgrp(); char spgrp[10]; -/* - need_umount = 0; - this = mnts; - while (this) { - if (strcmp(mount, this->path)) { - this = this->next; - continue; - } - - if (!strstr(this->opts, "indirect")) { - this = this->next; - continue; - } - - need_umount = 1; - break; - } - - if (!need_umount) - return 1; -*/ sprintf(spgrp, "%d", pgrp); @@ -153,7 +131,7 @@ static int do_mount_autofs_indirect(stru mnts = get_mnt_list(_PROC_MOUNTS, ap->path, 1); if (mnts) { - int ret = unlink_mount_tree(ap, mnts, ap->path); + ret = unlink_mount_tree(ap, mnts); free_mnt_list(mnts); if (!ret) { debug(ap->logopt, @@ -393,7 +371,7 @@ void *expire_proc_indirect(void *arg) struct mnt_list *mnts, *next; struct expire_args *ea; unsigned int now; - int offsets, submnts, count, ret; + int offsets, submnts, count; int ioctlfd; int status; @@ -427,6 +405,7 @@ void *expire_proc_indirect(void *arg) mnts = get_mnt_list(_PROC_MOUNTS, ap->path, 0); for (next = mnts; next; next = next->next) { char *ind_key; + int ret; if (!strcmp(next->fs_type, "autofs")) continue; @@ -546,6 +525,8 @@ void *expire_proc_indirect(void *arg) if (!list_empty(&ap->submounts)) { ea->status = 1; } else { + int ret; + if (!ioctl(ap->ioctlfd, AUTOFS_IOC_ASKUMOUNT, &ret)) { if (!ret) { debug(ap->logopt, diff --git a/daemon/lookup.c b/daemon/lookup.c index dda27f8..0681407 100644 --- a/daemon/lookup.c +++ b/daemon/lookup.c @@ -1,4 +1,3 @@ -#ident "$Id: lookup.c,v 1.17 2006/04/06 20:02:04 raven Exp $" /* ----------------------------------------------------------------------- * * * lookup.c - API layer to implement nsswitch semantics for map reading diff --git a/daemon/module.c b/daemon/module.c index 91d66b1..e83c929 100644 --- a/daemon/module.c +++ b/daemon/module.c @@ -1,4 +1,3 @@ -#ident "$Id: module.c,v 1.12 2006/03/29 10:32:36 raven Exp $" /* ----------------------------------------------------------------------- * * * module.c - common module-management functions diff --git a/daemon/mount.c b/daemon/mount.c index 93659a6..723c2f9 100644 --- a/daemon/mount.c +++ b/daemon/mount.c @@ -1,4 +1,3 @@ -#ident "$Id: mount.c,v 1.12 2006/03/08 02:40:22 raven Exp $" /* ----------------------------------------------------------------------- * * * mount.c - Abstract mount code used by modules for an unexpected diff --git a/daemon/spawn.c b/daemon/spawn.c index b3fd9de..a85b667 100644 --- a/daemon/spawn.c +++ b/daemon/spawn.c @@ -1,4 +1,3 @@ -#ident "$Id: spawn.c,v 1.25 2006/03/31 18:26:16 raven Exp $" /* ----------------------------------------------------------------------- * * * spawn.c - run programs synchronously with output redirected to syslog @@ -85,16 +84,16 @@ inline void dump_core(void) void *sigchld(void *dummy) { pid_t pid; - sigset_t sigchld; + sigset_t sig_child; int sig; int status; - sigemptyset(&sigchld); - sigaddset(&sigchld, SIGCHLD); - sigaddset(&sigchld, SIGCONT); + sigemptyset(&sig_child); + sigaddset(&sig_child, SIGCHLD); + sigaddset(&sig_child, SIGCONT); while (1) { - sigwait(&sigchld, &sig); + sigwait(&sig_child, &sig); status = pthread_mutex_lock(&sm.mutex); if (status) diff --git a/daemon/state.c b/daemon/state.c index cf9282f..4fda6df 100644 --- a/daemon/state.c +++ b/daemon/state.c @@ -1,4 +1,3 @@ -#ident "$Id: state.c,v 1.11 2006/04/03 08:15:36 raven Exp $" /* ----------------------------------------------------------------------- * * * state.c - state machine functions. @@ -15,8 +14,6 @@ #ident "$Id: state.c,v 1.11 2006/04/03 0 #include "automount.h" -extern struct master *master; - extern pthread_attr_t thread_attr; struct state_queue { @@ -36,7 +33,7 @@ static LIST_HEAD(state_queue); static unsigned int signaled = 0; static void st_set_thid(struct autofs_point *, pthread_t); -int do_mount_autofs_direct(struct autofs_point *, struct mnt_list *, struct mapent *, int); +int do_mount_autofs_direct(struct autofs_point *, struct mnt_list *, struct mapent *); void dump_state_queue(void) { @@ -389,7 +386,7 @@ static void *do_readmap(void *arg) debug(ap->logopt, "%s id mounted", me->key); } else - do_mount_autofs_direct(ap, mnts, me, now); + do_mount_autofs_direct(ap, mnts, me); me = cache_enumerate(mc, me); } pthread_cleanup_pop(1); diff --git a/include/automount.h b/include/automount.h index 3b2a1cf..908b308 100644 --- a/include/automount.h +++ b/include/automount.h @@ -1,4 +1,3 @@ -#ident "$Id: automount.h,v 1.50 2006/04/06 20:02:04 raven Exp $" /* * automount.h * @@ -30,14 +29,10 @@ #include "macros.h" #include "log.h" #include "rpc_subs.h" -#if WITH_DMALLOC +#ifdef WITH_DMALLOC #include #endif -/* OpenBSD re-entrant syslog -#include "syslog.h" -*/ - #define ENABLE_CORES 1 /* We MUST have the paths to mount(8) and umount(8) */ @@ -305,7 +300,7 @@ int close_mount(struct mount_mod *); /* buffer management */ -int _strlen(const char *str, size_t max); +size_t _strlen(const char *str, size_t max); int cat_path(char *buf, size_t len, const char *dir, const char *base); int ncat_path(char *buf, size_t len, const char *dir, const char *base, size_t blen); @@ -346,7 +341,7 @@ struct mnt_list *get_mnt_list(const char struct mnt_list *reverse_mnt_list(struct mnt_list *list); void free_mnt_list(struct mnt_list *list); int is_mounted(const char *table, const char *path, unsigned int type); -int has_fstab_option(const char *path, const char *opt); +int has_fstab_option(const char *opt); char *find_mnt_ino(const char *table, dev_t dev, ino_t ino); char *get_offset(const char *prefix, char *offset, struct list_head *head, struct list_head **pos); @@ -379,8 +374,6 @@ struct master_readmap_cond { unsigned int busy; /* Map read in progress. */ }; -extern struct master_readmap_cond mc; - struct pending_args { pthread_mutex_t mutex; pthread_cond_t cond; diff --git a/include/defaults.h b/include/defaults.h index 34a0f6c..b64735f 100644 --- a/include/defaults.h +++ b/include/defaults.h @@ -1,4 +1,3 @@ -#ident "$Id: defaults.h,v 1.4 2006/04/06 20:02:04 raven Exp $" /* ----------------------------------------------------------------------- * * * defaults.h - system initialization defaults. diff --git a/include/log.h b/include/log.h index 2fa83e4..3276cca 100644 --- a/include/log.h +++ b/include/log.h @@ -1,4 +1,3 @@ -#ident "$Id: log.h,v 1.1 2006/03/29 10:32:36 raven Exp $" /* ----------------------------------------------------------------------- * * * log.c - applcation logging declarations. diff --git a/include/lookup_ldap.h b/include/lookup_ldap.h index 9cc214a..d33bda9 100644 --- a/include/lookup_ldap.h +++ b/include/lookup_ldap.h @@ -1,7 +1,7 @@ #ifndef LOOKUP_LDAP_H #define LOOKUP_LDAP_H -#if WITH_SASL +#ifdef WITH_SASL #include #include #include @@ -37,17 +37,19 @@ struct lookup_context { char *client_princ; int kinit_done; int kinit_successful; +#ifdef WITH_SASL krb5_principal krb5_client_princ; krb5_context krb5ctxt; krb5_ccache krb5_ccache; sasl_conn_t *sasl_conn; +#endif /* keytab file name needs to be added */ struct parse_mod *parse; }; -#if WITH_SASL +#ifdef WITH_SASL #define LDAP_AUTH_CONF_FILE "test" #define LDAP_TLS_DONT_USE 0 @@ -68,6 +70,7 @@ int authtype_requires_creds(const char * int autofs_sasl_init(LDAP *ldap, struct lookup_context *ctxt); int autofs_sasl_bind(LDAP *ldap, struct lookup_context *ctxt); void autofs_sasl_unbind(struct lookup_context *ctxt); +void autofs_sasl_done(struct lookup_context *ctxt); #endif -#endif /* _lookup_ldap_h */ +#endif diff --git a/include/macros.h b/include/macros.h index d2c9103..96fda3b 100644 --- a/include/macros.h +++ b/include/macros.h @@ -1,4 +1,3 @@ -#ident "$Id: macros.h,v 1.2 2006/03/21 04:28:52 raven Exp $" /* ----------------------------------------------------------------------- * * * macros.h - header file for module to handle macro substitution diff --git a/include/master.h b/include/master.h index 78bfa27..8e1b375 100644 --- a/include/master.h +++ b/include/master.h @@ -1,4 +1,3 @@ -#ident "$Id: master.h,v 1.5 2006/03/31 18:26:16 raven Exp $" /* ----------------------------------------------------------------------- * * * master.h - header file for master map parser utility routines. @@ -93,6 +92,6 @@ int master_read_master(struct master *, void master_notify_state_change(struct master *, int); int master_mount_mounts(struct master *, time_t, int); int master_list_empty(struct master *); -int master_kill(struct master *, unsigned int); +int master_kill(struct master *); #endif diff --git a/include/nsswitch.h b/include/nsswitch.h index 79eed25..2b445a9 100644 --- a/include/nsswitch.h +++ b/include/nsswitch.h @@ -1,4 +1,3 @@ -#ident "$Id: nsswitch.h,v 1.3 2006/03/31 18:26:16 raven Exp $" /* ----------------------------------------------------------------------- * * * nsswitch.h - header file for module to call parser for nsswitch diff --git a/include/state.h b/include/state.h index c482d2d..69355b0 100644 --- a/include/state.h +++ b/include/state.h @@ -1,4 +1,3 @@ -#ident "$Id: state.h,v 1.6 2006/04/01 06:48:05 raven Exp $" /* ----------------------------------------------------------------------- * * * state.h - state queue functions. @@ -47,7 +46,7 @@ enum states { ST_READMAP, ST_SHUTDOWN_PENDING, ST_SHUTDOWN_FORCE, - ST_SHUTDOWN, + ST_SHUTDOWN }; struct expire_args { diff --git a/lib/alarm.c b/lib/alarm.c index 706a3b8..dc90b59 100755 --- a/lib/alarm.c +++ b/lib/alarm.c @@ -1,4 +1,3 @@ -#ident "$Id: alarm.c,v 1.8 2006/03/29 10:32:36 raven Exp $" /* ----------------------------------------------------------------------- * * * alarm.c - alarm queue handling module. @@ -34,10 +33,10 @@ void dump_alarms(void) pthread_mutex_lock(&mutex); list_for_each(p, head) { - struct alarm *alarm; + struct alarm *this; - alarm = list_entry(p, struct alarm, list); - msg("alarm time = %d", alarm->time); + this = list_entry(p, struct alarm, list); + msg("alarm time = %d", this->time); } pthread_mutex_unlock(&mutex); } @@ -126,20 +125,20 @@ void alarm_delete(struct autofs_point *a p = head->next; while (p != head) { - struct alarm *alarm; + struct alarm *this; - alarm = list_entry(p, struct alarm, list); + this = list_entry(p, struct alarm, list); p = p->next; - if (ap == alarm->ap) { - if (current != alarm) { - list_del_init(&alarm->list); - free(alarm); + if (ap == this->ap) { + if (current != this) { + list_del_init(&this->list); + free(this); continue; } /* Mark as canceled */ - alarm->cancel = 1; - alarm->time = 0; + this->cancel = 1; + this->time = 0; signal_cancel = 1; } } diff --git a/lib/args.c b/lib/args.c index 279c5d8..9e35388 100644 --- a/lib/args.c +++ b/lib/args.c @@ -1,4 +1,3 @@ -#ident "$Id: args.c,v 1.3 2006/03/24 03:43:40 raven Exp $" /* ----------------------------------------------------------------------- * * * args.c - argument vector handling. @@ -26,9 +25,11 @@ #include "automount.h" char **add_argv(int argc, char **argv, char *str) { char **vector; + size_t vector_size; int i; - vector = (char **) malloc((argc + 1) * sizeof(char *)); + vector_size = (argc + 1) * sizeof(char *); + vector = (char **) malloc(vector_size); if (!vector) return NULL; @@ -64,9 +65,11 @@ char **add_argv(int argc, char **argv, c const char **copy_argv(int argc, const char **argv) { char **vector; + size_t vector_size; int i; - vector = (char **) malloc((argc + 1) * sizeof(char *)); + vector_size = (argc + 1) * sizeof(char *); + vector = (char **) malloc(vector_size); if (!vector) return NULL; diff --git a/lib/cache.c b/lib/cache.c index 2e3e5ad..6736a88 100644 --- a/lib/cache.c +++ b/lib/cache.c @@ -1,4 +1,3 @@ -#ident "$Id: cache.c,v 1.30 2006/03/31 18:26:16 raven Exp $" /* ----------------------------------------------------------------------- * * * cache.c - mount entry cache management routines @@ -42,7 +41,7 @@ void cache_dump_multi(struct list_head * void cache_dump_cache(struct mapent_cache *mc) { struct mapent *me; - int i; + unsigned int i; for (i = 0; i < mc->size; i++) { me = mc->hash[i]; @@ -102,7 +101,8 @@ void cache_lock_cleanup(void *arg) struct mapent_cache *cache_init(struct map_source *map) { struct mapent_cache *mc; - int i, status; + unsigned int i; + int status; if (map->mc) cache_release(map); @@ -204,7 +204,7 @@ struct mapent *cache_lookup_ino(struct m struct mapent *cache_lookup_first(struct mapent_cache *mc) { struct mapent *me = NULL; - int i; + unsigned int i; for (i = 0; i < mc->size; i++) { me = mc->hash[i]; @@ -228,7 +228,7 @@ struct mapent *cache_lookup_next(struct { struct mapent *this; unsigned long hashval; - int i; + unsigned int i; if (!me) return NULL; @@ -245,7 +245,7 @@ struct mapent *cache_lookup_next(struct hashval = hash(me->key) + 1; if (hashval < mc->size) { - for (i = hashval; i < mc->size; i++) { + for (i = (unsigned int) hashval; i < mc->size; i++) { this = mc->hash[i]; if (!this) continue; @@ -354,8 +354,8 @@ done: struct mapent *cache_partial_match(struct mapent_cache *mc, const char *prefix) { struct mapent *me = NULL; - int len = strlen(prefix); - int i; + size_t len = strlen(prefix); + unsigned int i; for (i = 0; i < mc->size; i++) { me = mc->hash[i]; @@ -414,8 +414,8 @@ int cache_add(struct mapent_cache *mc, s INIT_LIST_HEAD(&me->multi_list); me->multi = NULL; me->ioctlfd = -1; - me->dev = -1; - me->ino = -1; + me->dev = (dev_t) -1; + me->ino = (ino_t) -1; /* * We need to add to the end if values exist in order to @@ -448,7 +448,8 @@ static void cache_add_ordered_offset(str struct mapent *this; list_for_each(p, head) { - int eq, tlen; + size_t tlen; + int eq; this = list_entry(p, struct mapent, multi_list); tlen = strlen(this->key); @@ -635,7 +636,7 @@ void cache_release(struct map_source *ma struct mapent_cache *mc; struct mapent *me, *next; int status; - int i; + unsigned int i; mc = map->mc; @@ -696,8 +697,8 @@ char *cache_get_offset(const char *prefi { struct list_head *next; struct mapent *this; - int plen = strlen(prefix); - int len = 0; + size_t plen = strlen(prefix); + size_t len = 0; if (*pos == head) return NULL; diff --git a/lib/cat_path.c b/lib/cat_path.c index 7aa846b..576b424 100644 --- a/lib/cat_path.c +++ b/lib/cat_path.c @@ -1,4 +1,3 @@ -#ident "$Id: cat_path.c,v 1.9 2006/03/21 04:28:53 raven Exp $" /* ----------------------------------------------------------------------- * * * cat_path.c - boundary aware buffer management routines @@ -58,16 +57,15 @@ int cat_path(char *buf, size_t len, cons return 1; } -int _strlen(const char *str, size_t max) +size_t _strlen(const char *str, size_t max) { - char *s = (char *) str; + const char *s = str; + size_t len = 0; - while (*s++ && max--) ; + while (*s++ && len < max) + len++; - if (max < 0) - return 0; - - return s - str - 1; + return len; } /* @@ -79,7 +77,7 @@ int ncat_path(char *buf, size_t len, const char *dir, const char *base, size_t blen) { char name[PATH_MAX+1]; - int alen = _strlen(base, blen); + size_t alen = _strlen(base, blen); if (blen > PATH_MAX || !alen) return 0; diff --git a/lib/defaults.c b/lib/defaults.c index 594afb3..65dbd8d 100644 --- a/lib/defaults.c +++ b/lib/defaults.c @@ -1,4 +1,3 @@ -#ident "$Id: defaults.c,v 1.3 2006/04/06 20:02:04 raven Exp $" /* ----------------------------------------------------------------------- * * * defaults.h - system initialization defaults. diff --git a/lib/lock.c b/lib/lock.c index d68b18b..d07ae21 100644 --- a/lib/lock.c +++ b/lib/lock.c @@ -1,4 +1,3 @@ -#ident "$Id: lock.c,v 1.20 2006/03/11 06:02:48 raven Exp $" /* ----------------------------------------------------------------------- * * * lock.c - autofs lockfile management diff --git a/lib/log.c b/lib/log.c index abdea26..e639e60 100644 --- a/lib/log.c +++ b/lib/log.c @@ -1,4 +1,3 @@ -#ident "$Id: log.c,v 1.3 2006/03/29 10:32:36 raven Exp $" /* ----------------------------------------------------------------------- * * * log.c - applcation logging routines. diff --git a/lib/macros.c b/lib/macros.c index 9453bfe..a8703c8 100644 --- a/lib/macros.c +++ b/lib/macros.c @@ -1,4 +1,3 @@ -#ident "$Id: macros.c,v 1.1 2006/03/09 23:01:01 raven Exp $" /* ----------------------------------------------------------------------- * * * macros.c - module to handle macro substitution variables for map diff --git a/lib/master.c b/lib/master.c index a0a7ae8..f035af2 100644 --- a/lib/master.c +++ b/lib/master.c @@ -1,4 +1,3 @@ -#ident "$Id: master.c,v 1.11 2006/04/03 08:15:36 raven Exp $" /* ----------------------------------------------------------------------- * * * master.c - master map utility routines. @@ -29,12 +28,12 @@ #include #include "automount.h" /* The root of the map entry tree */ -struct master *master; +struct master *master_list = NULL; /* Attribute to create detached thread */ extern pthread_attr_t thread_attr; -extern struct startup_cond sc; +extern struct startup_cond suc; static struct map_source * __master_find_map_source(struct master_mapent *, @@ -361,7 +360,7 @@ void master_free_map_source(struct map_s struct map_source *master_find_source_instance(struct map_source *source, const char *type, const char *format, int argc, const char **argv) { struct map_source *map; - struct map_source *instance = NULL;; + struct map_source *instance = NULL; int status, res; status = pthread_mutex_lock(&instance_mutex); @@ -657,14 +656,14 @@ void master_free_mapent(struct master_ma struct master *master_new(const char *name, unsigned int timeout, unsigned int ghost) { struct master *master; - const char *tmp; + char *tmp; master = malloc(sizeof(struct master)); if (!master) return NULL; if (!name) - tmp = defaults_get_master_map(); + tmp = (char *) defaults_get_master_map(); else tmp = strdup(name); @@ -838,12 +837,12 @@ static int master_do_mount(struct master pthread_t thid; int status; - status = pthread_mutex_lock(&sc.mutex); + status = pthread_mutex_lock(&suc.mutex); if (status) fatal(status); - sc.done = 0; - sc.status = 0; + suc.done = 0; + suc.status = 0; ap = entry->ap; @@ -853,28 +852,28 @@ static int master_do_mount(struct master crit(ap->logopt, "failed to create mount handler thread for %s", entry->path); - status = pthread_mutex_unlock(&sc.mutex); + status = pthread_mutex_unlock(&suc.mutex); if (status) fatal(status); return 0; } entry->thid = thid; - while (!sc.done) { - status = pthread_cond_wait(&sc.cond, &sc.mutex); + while (!suc.done) { + status = pthread_cond_wait(&suc.cond, &suc.mutex); if (status) fatal(status); } - if (sc.status) { + if (suc.status) { error(ap->logopt, "failed to startup mount"); - status = pthread_mutex_unlock(&sc.mutex); + status = pthread_mutex_unlock(&suc.mutex); if (status) fatal(status); return 0; } - status = pthread_mutex_unlock(&sc.mutex); + status = pthread_mutex_unlock(&suc.mutex); if (status) fatal(status); @@ -912,7 +911,7 @@ next: return; } -static void check_update_map_sources(struct master_mapent *entry, time_t age, int readall) +static void check_update_map_sources(struct master_mapent *entry, int readall) { struct map_source *source, *last; int status, state_pipe, map_stale = 0; @@ -1021,7 +1020,7 @@ int master_mount_mounts(struct master *m continue; } - check_update_map_sources(this, age, readall); + check_update_map_sources(this, readall); status = pthread_mutex_lock(&ap->state_mutex); if (status) @@ -1071,7 +1070,7 @@ int master_list_empty(struct master *mas return res; } -int master_kill(struct master *master, unsigned int mode) +int master_kill(struct master *master) { if (!list_empty(&master->mounts)) return 0; diff --git a/lib/master_parse.y b/lib/master_parse.y index 4def672..2f350f7 100644 --- a/lib/master_parse.y +++ b/lib/master_parse.y @@ -29,7 +29,7 @@ #include #include "automount.h" #include "master.h" -extern struct master *master; +extern struct master *master_list; char **add_argv(int, char **, char *); const char **copy_argv(int, const char **); @@ -63,6 +63,13 @@ static int lineno; #define YYDEBUG 0 +#ifndef YYENABLE_NLS +#define YYENABLE_NLS 0 +#endif +#ifndef YYLTYPE_IS_TRIVIAL +#define YYLTYPE_IS_TRIVIAL 0 +#endif + #if YYDEBUG static int master_fprintf(FILE *, char *, ...); #undef YYFPRINTF @@ -386,12 +393,12 @@ #endif static char *master_strdup(char *str) { - char *dup; + char *tmp; - dup = strdup(str); - if (!dup) + tmp = strdup(str); + if (!tmp) master_error("memory allocation error"); - return dup; + return tmp; } static int master_error(const char *s) @@ -441,6 +448,7 @@ void master_init_scan(void) int master_parse_entry(const char *buffer, unsigned int default_timeout, unsigned int logging, time_t age) { + struct master *master = master_list; struct master_mapent *entry, *new; struct map_source *source; unsigned int logopt = logging; diff --git a/lib/master_tok.l b/lib/master_tok.l index 2abdfc3..0903bcd 100644 --- a/lib/master_tok.l +++ b/lib/master_tok.l @@ -45,6 +45,19 @@ int master_wrap(void); /* no need for yywrap() */ #define YY_SKIP_YYWRAP +#ifndef YY_STACK_USED +#define YY_STACK_USED 0 +#endif +#ifndef YY_ALWAYS_INTERACTIVE +#define YY_ALWAYS_INTERACTIVE 0 +#endif +#ifndef YY_NEVER_INTERACTIVE +#define YY_NEVER_INTERACTIVE 0 +#endif +#ifndef YY_MAIN +#define YY_MAIN 0 +#endif + void master_set_scan_buffer(const char *); const char *line = NULL; @@ -62,7 +75,7 @@ #define input() (*(char *) line++) #define unput(c) (*(char *) --line = c) #endif -char buf[1024]; +char buff[1024]; char *bptr; %} @@ -99,13 +112,13 @@ MTYPE ((file|program|yp|nis|ni "+" { BEGIN(MAPSTR); - bptr = buf; + bptr = buff; yyless(0); } "/" { BEGIN(PATHSTR); - bptr = buf; + bptr = buff; yyless(0); } @@ -119,22 +132,22 @@ MTYPE ((file|program|yp|nis|ni \x00 { BEGIN(INITIAL); *bptr++ = *master_text; - strcpy(master_lval.strtype, buf); + strcpy(master_lval.strtype, buff); return NILL; } {WS}/{INTMAP} { BEGIN(MAPSTR); *bptr = '\0'; - strcpy(master_lval.strtype, buf); + strcpy(master_lval.strtype, buff); return(PATH); } {WS}/"-" { BEGIN(OPTSTR); *bptr = '\0'; - strcpy(master_lval.strtype, buf); - bptr = buf; + strcpy(master_lval.strtype, buff); + bptr = buff; return(PATH); } @@ -143,29 +156,29 @@ MTYPE ((file|program|yp|nis|ni BEGIN(INITIAL); *bptr++ = *master_text; *bptr = '\0'; - strcpy(master_lval.strtype, buf); + strcpy(master_lval.strtype, buff); return QUOTE; } {WS} { BEGIN(MAPSTR); *bptr = '\0'; - strcpy(master_lval.strtype, buf); - bptr = buf; + strcpy(master_lval.strtype, buff); + bptr = buff; return(PATH); } <> { BEGIN(INITIAL); *bptr = '\0'; - strcpy(master_lval.strtype, buf); + strcpy(master_lval.strtype, buff); return(PATH); } {NL} { BEGIN(INITIAL); *bptr = '\0'; - strcpy(master_lval.strtype, buf); + strcpy(master_lval.strtype, buff); return PATH; } @@ -212,15 +225,15 @@ MTYPE ((file|program|yp|nis|ni "/" { BEGIN(PATHSTR); - bptr = buf; + bptr = buff; yyless(0); } {OPTWS}/{NL} { BEGIN(INITIAL); *bptr = '\0'; - strcpy(master_lval.strtype, buf); - bptr = buf; + strcpy(master_lval.strtype, buff); + bptr = buff; return(MAPNAME); } @@ -229,8 +242,8 @@ MTYPE ((file|program|yp|nis|ni {WS} { BEGIN(OPTSTR); *bptr = '\0'; - strcpy(master_lval.strtype, buf); - bptr = buf; + strcpy(master_lval.strtype, buff); + bptr = buff; return(MAPNAME); } @@ -238,7 +251,7 @@ MTYPE ((file|program|yp|nis|ni <> { BEGIN(INITIAL); *bptr = '\0'; - strcpy(master_lval.strtype, buf); + strcpy(master_lval.strtype, buff); return(MAPNAME); } diff --git a/lib/mounts.c b/lib/mounts.c index b1d5e48..dd73f9f 100644 --- a/lib/mounts.c +++ b/lib/mounts.c @@ -1,4 +1,3 @@ -#ident "$Id: mounts.c,v 1.24 2006/04/03 08:15:36 raven Exp $" /* ----------------------------------------------------------------------- * * * mounts.c - module for Linux automount mount table lookup functions @@ -107,7 +106,7 @@ char *make_mnt_name_string(char *path) struct mnt_list *get_mnt_list(const char *table, const char *path, int include) { FILE *tab; - int pathlen = strlen(path); + size_t pathlen = strlen(path); struct mntent mnt_wrk; char buf[PATH_MAX * 3]; struct mntent *mnt; @@ -115,7 +114,7 @@ struct mnt_list *get_mnt_list(const char struct mnt_list *list = NULL; unsigned long count = 0; char *pgrp; - int len; + size_t len; if (!path || !pathlen || pathlen > PATH_MAX) return NULL; @@ -260,7 +259,7 @@ int is_mounted(const char *table, const struct mntent *mnt; struct mntent mnt_wrk; char buf[PATH_MAX]; - int pathlen = strlen(path); + size_t pathlen = strlen(path); FILE *tab; int ret = 0; @@ -275,7 +274,7 @@ int is_mounted(const char *table, const } while ((mnt = getmntent_r(tab, &mnt_wrk, buf, PATH_MAX))) { - int len = strlen(mnt->mnt_dir); + size_t len = strlen(mnt->mnt_dir); if (type) { unsigned int autofs_fs; @@ -301,7 +300,7 @@ int is_mounted(const char *table, const return ret; } -int has_fstab_option(const char *path, const char *opt) +int has_fstab_option(const char *opt) { struct mntent *mnt; struct mntent mnt_wrk; @@ -336,13 +335,13 @@ char *find_mnt_ino(const char *table, de struct mntent *mnt; char buf[PATH_MAX]; char *path = NULL; - unsigned long l_dev = dev; - unsigned long l_ino = ino; + unsigned long l_dev = (unsigned long) dev; + unsigned long l_ino = (unsigned long) ino; FILE *tab; tab = setmntent(table, "r"); if (!tab) { - char *estr = strerror_r(errno, buf, PATH_MAX - 1); + char *estr = strerror_r(errno, buf, (size_t) PATH_MAX - 1); error(LOGOPT_ANY, "setmntent: %s", estr); return 0; } @@ -357,14 +356,14 @@ char *find_mnt_ino(const char *table, de p_dev = strstr(mnt->mnt_opts, "dev="); if (!p_dev) continue; - sscanf(p_dev, "dev=%ld", &m_dev); + sscanf(p_dev, "dev=%lu", &m_dev); if (m_dev != l_dev) continue; p_ino = strstr(mnt->mnt_opts, "ino="); if (!p_ino) continue; - sscanf(p_ino, "ino=%ld", &m_ino); + sscanf(p_ino, "ino=%lu", &m_ino); if (m_ino == l_ino) { path = strdup(mnt->mnt_dir); break; @@ -380,8 +379,8 @@ char *get_offset(const char *prefix, cha { struct list_head *next; struct mnt_list *this; - int plen = strlen(prefix); - int len = 0; + size_t plen = strlen(prefix); + size_t len = 0; *offset = '\0'; next = *pos ? (*pos)->next : head->next; @@ -447,7 +446,8 @@ void add_ordered_list(struct mnt_list *e struct mnt_list *this; list_for_each(p, head) { - int eq, tlen; + size_t tlen; + int eq; this = list_entry(p, struct mnt_list, ordered); tlen = strlen(this->path); @@ -530,7 +530,8 @@ struct mnt_list *tree_make_mnt_tree(cons struct mnt_list *ent, *mptr; struct mnt_list *tree = NULL; char *pgrp; - int eq, plen; + size_t plen; + int eq; tab = setmntent(table, "r"); if (!tab) { @@ -542,7 +543,7 @@ struct mnt_list *tree_make_mnt_tree(cons plen = strlen(path); while ((mnt = getmntent_r(tab, &mnt_wrk, buf, PATH_MAX))) { - int len = strlen(mnt->mnt_dir); + size_t len = strlen(mnt->mnt_dir); /* Not matching path */ if (strncmp(mnt->mnt_dir, path, plen)) @@ -657,7 +658,7 @@ struct mnt_list *tree_make_mnt_tree(cons */ int tree_get_mnt_list(struct mnt_list *mnts, struct list_head *list, const char *path, int include) { - int mlen, plen; + size_t mlen, plen; if (!mnts) return 0; @@ -746,8 +747,10 @@ int tree_find_mnt_ents(struct mnt_list * int tree_is_mounted(struct mnt_list *mnts, const char *path) { struct list_head *p; - LIST_HEAD(list); - int is_mounted = 0; + struct list_head list; + int mounted = 0; + + INIT_LIST_HEAD(&list); if (!tree_find_mnt_ents(mnts, &list, path)) return 0; @@ -761,9 +764,9 @@ int tree_is_mounted(struct mnt_list *mnt if (!strcmp(mptr->fs_type, "autofs")) continue; - is_mounted++; + mounted++; } - return is_mounted; + return mounted; } diff --git a/lib/nss_parse.y b/lib/nss_parse.y index eaba7f8..38b84cc 100644 --- a/lib/nss_parse.y +++ b/lib/nss_parse.y @@ -37,6 +37,13 @@ struct nss_action act[NSS_STATUS_MAX]; #define YYDEBUG 0 +#ifndef YYENABLE_NLS +#define YYENABLE_NLS 0 +#endif +#ifndef YYLTYPE_IS_TRIVIAL +#define YYLTYPE_IS_TRIVIAL 0 +#endif + extern int nss_lineno; extern int nss_lex(void); extern FILE *nss_in; @@ -72,13 +79,11 @@ sources: nss_source nss_source: SOURCE { -// printf("source: %s\n", $1); src = add_source(nss_list, $1); } | SOURCE LBRACKET status_exp_list RBRACKET { enum nsswitch_status a; -// printf("source: %s\n", $1); src = add_source(nss_list, $1); for (a = 0; a < NSS_STATUS_MAX; a++) { if (act[a].action != NSS_ACTION_UNKNOWN) { @@ -98,11 +103,9 @@ status_exp_list: status_exp status_exp: STATUS EQUAL ACTION { -// printf("action: [ %s=%s ]\n", $1, $3); set_action(act, $1, $3, 0); } | BANG STATUS EQUAL ACTION { -// printf("action: [ ! %s=%s ]\n", $2, $4); set_action(act, $2, $4, 1); } | STATUS EQUAL OTHER {nss_error($3); YYABORT; } | STATUS OTHER {nss_error($2); YYABORT; } diff --git a/lib/nss_tok.l b/lib/nss_tok.l index fcff147..dea8203 100644 --- a/lib/nss_tok.l +++ b/lib/nss_tok.l @@ -45,6 +45,19 @@ int nss_wrap(void); #endif #define YY_SKIP_YYWRAP +#ifndef YY_STACK_USED +#define YY_STACK_USED 0 +#endif +#ifndef YY_ALWAYS_INTERACTIVE +#define YY_ALWAYS_INTERACTIVE 0 +#endif +#ifndef YY_NEVER_INTERACTIVE +#define YY_NEVER_INTERACTIVE 0 +#endif +#ifndef YY_MAIN +#define YY_MAIN 0 +#endif + %} %option nounput diff --git a/lib/nsswitch.c b/lib/nsswitch.c index 4c43e8f..c6163a7 100644 --- a/lib/nsswitch.c +++ b/lib/nsswitch.c @@ -1,4 +1,3 @@ -#ident "$Id: nsswitch.c,v 1.2 2006/03/21 04:28:53 raven Exp $" /* ----------------------------------------------------------------------- * * * nsswitch.c - module to call parser for nsswitch config and store diff --git a/lib/rpc_subs.c b/lib/rpc_subs.c index 6ce4cf7..d07ea71 100644 --- a/lib/rpc_subs.c +++ b/lib/rpc_subs.c @@ -1,4 +1,3 @@ -#ident "$Id: rpc_subs.c,v 1.11 2006/03/31 18:26:16 raven Exp $" /* ----------------------------------------------------------------------- * * * rpc_subs.c - routines for rpc discovery @@ -46,13 +45,14 @@ #endif */ static CLIENT *create_udp_client(struct conn_info *info) { - int fd, ret, h_errno; + int fd, ret, ghn_errno; CLIENT *client; struct sockaddr_in laddr, raddr; struct hostent hp; struct hostent *php = &hp; struct hostent *result; char buf[HOST_ENT_BUF_SIZE]; + size_t len; if (info->proto->p_proto != IPPROTO_UDP) return NULL; @@ -78,9 +78,9 @@ static CLIENT *create_udp_client(struct memset(&hp, 0, sizeof(struct hostent)); ret = gethostbyname_r(info->host, php, - buf, HOST_ENT_BUF_SIZE, &result, &h_errno); + buf, HOST_ENT_BUF_SIZE, &result, &ghn_errno); if (ret || !result) { - int err = h_errno == -1 ? errno : h_errno; + int err = ghn_errno == -1 ? errno : ghn_errno; char *estr = strerror_r(err, buf, HOST_ENT_BUF_SIZE); error(LOGOPT_ANY, "hostname lookup failed: %s", estr); return NULL; @@ -103,8 +103,8 @@ got_addr: laddr.sin_port = 0; laddr.sin_addr.s_addr = htonl(INADDR_ANY); - if (bind(fd, (struct sockaddr *)&laddr, - sizeof(struct sockaddr_in)) < 0) { + len = sizeof(struct sockaddr_in); + if (bind(fd, (struct sockaddr *)&laddr, len) < 0) { close(fd); fd = RPC_ANYSOCK; /* FALLTHROUGH */ @@ -186,7 +186,8 @@ static int connect_nb(int fd, struct soc * we set ret = -errno to capture it in case we decide to * use it later. */ - ret = connect(fd, (struct sockaddr *)addr, sizeof(struct sockaddr)); + len = sizeof(struct sockaddr); + ret = connect(fd, (struct sockaddr *)addr, len); if (ret < 0 && errno != EINPROGRESS) { ret = -errno; goto done; @@ -210,11 +211,11 @@ static int connect_nb(int fd, struct soc } if (FD_ISSET(fd, &rset) || FD_ISSET(fd, &wset)) { - int stat; + int status; len = sizeof(ret); - stat = getsockopt(fd, SOL_SOCKET, SO_ERROR, &ret, &len); - if (stat < 0) { + status = getsockopt(fd, SOL_SOCKET, SO_ERROR, &ret, &len); + if (status < 0) { ret = -errno; goto done; } @@ -234,7 +235,7 @@ done: */ static CLIENT *create_tcp_client(struct conn_info *info) { - int fd; + int fd, ghn_errno; CLIENT *client; struct sockaddr_in addr; struct hostent hp; @@ -266,9 +267,9 @@ static CLIENT *create_tcp_client(struct memset(&hp, 0, sizeof(struct hostent)); ret = gethostbyname_r(info->host, php, - buf, HOST_ENT_BUF_SIZE, &result, &h_errno); + buf, HOST_ENT_BUF_SIZE, &result, &ghn_errno); if (ret || !result) { - int err = h_errno == -1 ? errno : h_errno; + int err = ghn_errno == -1 ? errno : ghn_errno; char *estr = strerror_r(err, buf, HOST_ENT_BUF_SIZE); error(LOGOPT_ANY, "hostname lookup failed: %s", estr); return NULL; @@ -403,7 +404,7 @@ unsigned short rpc_portmap_getport(struc struct conn_info pmap_info; unsigned short port = 0; CLIENT *client; - enum clnt_stat stat; + enum clnt_stat status; int proto = info->proto->p_proto; memset(&pmap_info, 0, sizeof(struct conn_info)); @@ -437,12 +438,12 @@ unsigned short rpc_portmap_getport(struc * Check to see if server is up otherwise a getport will take * forever to timeout. */ - stat = clnt_call(client, PMAPPROC_NULL, + status = clnt_call(client, PMAPPROC_NULL, (xdrproc_t) xdr_void, 0, (xdrproc_t) xdr_void, 0, pmap_info.timeout); - if (stat == RPC_SUCCESS) { - stat = clnt_call(client, PMAPPROC_GETPORT, + if (status == RPC_SUCCESS) { + status = clnt_call(client, PMAPPROC_GETPORT, (xdrproc_t) xdr_pmap, (caddr_t) parms, (xdrproc_t) xdr_u_short, (caddr_t) &port, pmap_info.timeout); @@ -453,7 +454,7 @@ unsigned short rpc_portmap_getport(struc * Only play with the close options if we think it * completed OK */ - if (proto == IPPROTO_TCP && stat == RPC_SUCCESS) { + if (proto == IPPROTO_TCP && status == RPC_SUCCESS) { struct linger lin = { 1, 0 }; socklen_t lin_len = sizeof(struct linger); int fd; @@ -471,7 +472,7 @@ unsigned short rpc_portmap_getport(struc clnt_destroy(client); } - if (stat != RPC_SUCCESS) + if (status != RPC_SUCCESS) return 0; return port; @@ -480,7 +481,7 @@ unsigned short rpc_portmap_getport(struc int rpc_ping_proto(struct conn_info *info) { CLIENT *client; - enum clnt_stat stat; + enum clnt_stat status; int proto = info->proto->p_proto; if (info->client) @@ -500,7 +501,7 @@ int rpc_ping_proto(struct conn_info *inf clnt_control(client, CLSET_TIMEOUT, (char *) &info->timeout); clnt_control(client, CLSET_RETRY_TIMEOUT, (char *) &info->timeout); - stat = clnt_call(client, NFSPROC_NULL, + status = clnt_call(client, NFSPROC_NULL, (xdrproc_t) xdr_void, 0, (xdrproc_t) xdr_void, 0, info->timeout); @@ -509,7 +510,7 @@ int rpc_ping_proto(struct conn_info *inf * Only play with the close options if we think it * completed OK */ - if (proto == IPPROTO_TCP && stat == RPC_SUCCESS) { + if (proto == IPPROTO_TCP && status == RPC_SUCCESS) { struct linger lin = { 1, 0 }; socklen_t lin_len = sizeof(struct linger); int fd; @@ -527,7 +528,7 @@ int rpc_ping_proto(struct conn_info *inf clnt_destroy(client); } - if (stat != RPC_SUCCESS) + if (status != RPC_SUCCESS) return 0; return 1; @@ -575,21 +576,23 @@ static unsigned int __rpc_ping(const cha int rpc_ping(const char *host, long seconds, long micros, unsigned int option) { + unsigned long vers3 = NFS3_VERSION; + unsigned long vers2 = NFS2_VERSION; unsigned int status; - status = __rpc_ping(host, NFS2_VERSION, "udp", seconds, micros, option); + status = __rpc_ping(host, vers2, "udp", seconds, micros, option); if (status) return RPC_PING_V2 | RPC_PING_UDP; - status = __rpc_ping(host, NFS3_VERSION, "udp", seconds, micros, option); + status = __rpc_ping(host, vers3, "udp", seconds, micros, option); if (status) return RPC_PING_V3 | RPC_PING_UDP; - status = __rpc_ping(host, NFS2_VERSION, "tcp", seconds, micros, option); + status = __rpc_ping(host, vers2, "tcp", seconds, micros, option); if (status) return RPC_PING_V2 | RPC_PING_TCP; - status = __rpc_ping(host, NFS3_VERSION, "tcp", seconds, micros, option); + status = __rpc_ping(host, vers3, "tcp", seconds, micros, option); if (status) return RPC_PING_V3 | RPC_PING_TCP; @@ -613,9 +616,10 @@ int rpc_time(const char *host, struct timeval start, end; struct timezone tz; char *proto = (ping_proto & RPC_PING_UDP) ? "udp" : "tcp"; + unsigned long vers = ping_vers; gettimeofday(&start, &tz); - status = __rpc_ping(host, ping_vers, proto, seconds, micros, option); + status = __rpc_ping(host, vers, proto, seconds, micros, option); gettimeofday(&end, &tz); if (!status) { @@ -633,7 +637,7 @@ int rpc_time(const char *host, static int rpc_get_exports_proto(struct conn_info *info, exports *exp) { CLIENT *client; - enum clnt_stat stat; + enum clnt_stat status; int proto = info->proto->p_proto; unsigned int option = info->close_option; @@ -652,13 +656,13 @@ static int rpc_get_exports_proto(struct client->cl_auth = authunix_create_default(); - stat = clnt_call(client, MOUNTPROC_EXPORT, + status = clnt_call(client, MOUNTPROC_EXPORT, (xdrproc_t) xdr_void, NULL, (xdrproc_t) xdr_exports, (caddr_t) exp, info->timeout); /* Only play with the close options if we think it completed OK */ - if (proto == IPPROTO_TCP && stat == RPC_SUCCESS) { + if (proto == IPPROTO_TCP && status == RPC_SUCCESS) { struct linger lin = { 1, 0 }; socklen_t lin_len = sizeof(struct linger); int fd; @@ -676,7 +680,7 @@ static int rpc_get_exports_proto(struct auth_destroy(client->cl_auth); clnt_destroy(client); - if (stat != RPC_SUCCESS) + if (status != RPC_SUCCESS) return 0; return 1; @@ -720,13 +724,13 @@ static int masked_match(const char *myna struct hostent *result; char buf[HOST_ENT_BUF_SIZE], **haddr; struct sockaddr_in saddr, maddr; - int h_errno, ret; + int ghn_errno, ret; memset(buf, 0, HOST_ENT_BUF_SIZE); memset(&he, 0, sizeof(struct hostent)); ret = gethostbyname_r(myname, phe, - buf, HOST_ENT_BUF_SIZE, &result, &h_errno); + buf, HOST_ENT_BUF_SIZE, &result, &ghn_errno); if (ret || !result) return 0; @@ -739,7 +743,7 @@ static int masked_match(const char *myna if (!ret) return 0; } else { - uint32_t m = -1; + uint32_t m = (uint32_t) -1; int msize = atoi(mask); m = m << (32 - msize); @@ -836,13 +840,13 @@ static int string_match(const char *myna struct hostent *phe = &he; struct hostent *result; char buf[HOST_ENT_BUF_SIZE]; - int ret; + int ret, ghn_errno; memset(buf, 0, HOST_ENT_BUF_SIZE); memset(&he, 0, sizeof(struct hostent)); ret = gethostbyname_r(myname, phe, - buf, HOST_ENT_BUF_SIZE, &result, &h_errno); + buf, HOST_ENT_BUF_SIZE, &result, &ghn_errno); if (ret || !result) return 0; @@ -876,7 +880,7 @@ static int host_match(char *pattern) return 0; ret = innetgr(pattern + 1, myname, (char *) 0, ypdomain); } else if (inet_aton(pattern, &tmp) || strchr(pattern, '/')) { - int len = strlen(pattern) + 1; + size_t len = strlen(pattern) + 1; char *addr, *mask; addr = alloca(len); diff --git a/lib/syslog.c b/lib/syslog.c deleted file mode 100644 index 8f72eb1..0000000 --- a/lib/syslog.c +++ /dev/null @@ -1,382 +0,0 @@ -#ident "$Id: syslog.c,v 1.3 2006/03/11 06:02:48 raven Exp $" -/* - * Copyright (c) 1983, 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "syslog.h" - -#define TBUF_LEN 2048 -#define FMT_LEN 1024 -#define INTERNALLOG LOG_ERR|LOG_CONS|LOG_PERROR|LOG_PID - -#define DEC() \ - do { \ - if (prlen < 0) \ - prlen = 0; \ - if (prlen >= tbuf_left) \ - prlen = tbuf_left - 1; \ - p += prlen; \ - tbuf_left -= prlen; \ - } while (0) - -/* Use our internal printf routines */ -extern int snprintf_int(char * buf, size_t size, const char * fmt, ...) - __attribute__ ((format (printf, 3, 4))); -extern int vsnprintf_int(char *buf, size_t size, const char *fmt, va_list args) - __attribute__ ((format (printf, 3, 0))); - -static struct syslog_data sdata = SYSLOG_DATA_INIT; -static int LogType = SOCK_DGRAM; /* type of socket connection */ - -extern char *__progname; /* Program name, from crt0. */ - -static void disconnectlog_r(struct syslog_data *); /* disconnect from syslogd */ -static void connectlog_r(struct syslog_data *); /* (re)connect to syslogd */ - -/* - * syslog, vsyslog -- - * print message on log file; output is intended for syslogd(8). - */ -void -syslog(int pri, const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - vsyslog(pri, fmt, ap); - va_end(ap); -} - -void -vsyslog(int pri, const char *fmt, va_list ap) -{ - vsyslog_r(pri, &sdata, fmt, ap); -} - -void -openlog(const char *ident, int logstat, int logfac) -{ - openlog_r(ident, logstat, logfac, &sdata); -} - -void -closelog(void) -{ - closelog_r(&sdata); -} - -/* setlogmask -- set the log mask level */ -int -setlogmask(int pmask) -{ - return setlogmask_r(pmask, &sdata); -} - -/* Reentrant version of syslog, i.e. syslog_r() */ - -void -syslog_r(int pri, struct syslog_data *data, const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - vsyslog_r(pri, data, fmt, ap); - va_end(ap); -} - -void -vsyslog_r(int pri, struct syslog_data *data, const char *fmt, va_list ap) -{ - int cnt; - char ch, *p, *t; - time_t now; - int fd, saved_errno, error; - char *stdp = NULL, tbuf[TBUF_LEN], fmt_cpy[FMT_LEN]; - int tbuf_left, fmt_left, prlen; - - /* Check for invalid bits. */ - if (pri & ~(LOG_PRIMASK|LOG_FACMASK)) { - if (data == &sdata) { - syslog(INTERNALLOG, - "syslog: unknown facility/priority: %x", pri); - } else { - syslog_r(INTERNALLOG, data, - "syslog_r: unknown facility/priority: %x", pri); - } - pri &= LOG_PRIMASK|LOG_FACMASK; - } - - /* Check priority against setlogmask values. */ - if (!(LOG_MASK(LOG_PRI(pri)) & data->log_mask)) - return; - - saved_errno = errno; - - /* Set default facility if none specified. */ - if ((pri & LOG_FACMASK) == 0) - pri |= data->log_fac; - - /* If we have been called through syslog(), no need for reentrancy. */ - if (data == &sdata) - (void)time(&now); - - p = tbuf; - tbuf_left = TBUF_LEN; - - prlen = snprintf_int(p, tbuf_left, "<%d>", pri); - DEC(); - - /* - * syslogd will expand time automagically for reentrant case, and - * for normal case, just do like before - */ - if (data == &sdata) { - prlen = strftime(p, tbuf_left, "%h %e %T ", localtime(&now)); - DEC(); - } - - if (data->log_stat & LOG_PERROR) - stdp = p; - if (data->log_tag == NULL) - data->log_tag = __progname; - if (data->log_tag != NULL) { - prlen = snprintf_int(p, tbuf_left, "%s", data->log_tag); - DEC(); - } - if (data->log_stat & LOG_PID) { - prlen = snprintf_int(p, tbuf_left, "[%ld]", (long)getpid()); - DEC(); - } - if (data->log_tag != NULL) { - if (tbuf_left > 1) { - *p++ = ':'; - tbuf_left--; - } - if (tbuf_left > 1) { - *p++ = ' '; - tbuf_left--; - } - } - - /* strerror() is not reentrant */ - - for (t = fmt_cpy, fmt_left = FMT_LEN; (ch = *fmt); ++fmt) { - if (ch == '%' && fmt[1] == 'm') { - ++fmt; - if (data == &sdata) { - prlen = snprintf_int(t, fmt_left, "%s", - strerror(saved_errno)); - } else { - prlen = snprintf_int(t, fmt_left, "Error %d", - saved_errno); - } - if (prlen < 0) - prlen = 0; - if (prlen >= fmt_left) - prlen = fmt_left - 1; - t += prlen; - fmt_left -= prlen; - } else if (ch == '%' && fmt[1] == '%' && fmt_left > 2) { - *t++ = '%'; - *t++ = '%'; - fmt++; - fmt_left -= 2; - } else { - if (fmt_left > 1) { - *t++ = ch; - fmt_left--; - } - } - } - *t = '\0'; - - prlen = vsnprintf_int(p, tbuf_left, fmt_cpy, ap); - DEC(); - cnt = p - tbuf; - - /* Output to stderr if requested. */ - if (data->log_stat & LOG_PERROR) { - struct iovec iov[2]; - - iov[0].iov_base = stdp; - iov[0].iov_len = cnt - (stdp - tbuf); - iov[1].iov_base = "\n"; - iov[1].iov_len = 1; - (void)writev(STDERR_FILENO, iov, 2); - } - - /* Get connected, output the message to the local logger. */ - if (!data->opened) - openlog_r(data->log_tag, data->log_stat, 0, data); - connectlog_r(data); - - /* If we have a SOCK_STREAM connection, also send ASCII NUL as - a record terminator. */ - if (LogType == SOCK_STREAM) - cnt++; - - /* - * If the send() failed, there are two likely scenarios: - * 1) syslogd was restarted - * 2) /dev/log is out of socket buffer space - * We attempt to reconnect to /dev/log to take care of - * case #1 and keep send()ing data to cover case #2 - * to give syslogd a chance to empty its socket buffer. - */ - if ((error = send(data->log_file, tbuf, cnt, 0)) < 0) { - if (errno != ENOBUFS) { - disconnectlog_r(data); - connectlog_r(data); - } - do { - usleep(1); - if ((error = send(data->log_file, tbuf, cnt, 0)) >= 0) - break; - } while (errno == ENOBUFS); - } - - /* - * Output the message to the console; try not to block - * as a blocking console should not stop other processes. - * Make sure the error reported is the one from the syslogd failure. - */ - if (error == -1 && (data->log_stat & LOG_CONS) && - (fd = open(_PATH_CONSOLE, O_WRONLY|O_NONBLOCK, 0)) >= 0) { - struct iovec iov[2]; - - p = strchr(tbuf, '>') + 1; - iov[0].iov_base = p; - iov[0].iov_len = cnt - (p - tbuf); - iov[1].iov_base = "\r\n"; - iov[1].iov_len = 2; - (void)writev(fd, iov, 2); - (void)close(fd); - } - - if (data != &sdata) - closelog_r(data); -} - -static void -disconnectlog_r(struct syslog_data *data) -{ - /* - * If the user closed the FD and opened another in the same slot, - * that's their problem. They should close it before calling on - * system services. - */ - if (data->log_file != -1) { - close(data->log_file); - data->log_file = -1; - } - data->connected = 0; /* retry connect */ -} - -static void -connectlog_r(struct syslog_data *data) -{ - struct sockaddr_un SyslogAddr; /* AF_UNIX address of local logger */ - -again: - if (data->log_file == -1) { - if ((data->log_file = socket(AF_UNIX, LogType, 0)) == -1) - return; - (void)fcntl(data->log_file, F_SETFD, 1); - } - if (data->log_file != -1 && !data->connected) { - int old_errno; - - memset(&SyslogAddr, '\0', sizeof(SyslogAddr)); - SyslogAddr.sun_family = AF_UNIX; - strncpy(SyslogAddr.sun_path, _PATH_LOG, - sizeof(SyslogAddr.sun_path)); - old_errno = errno; - if (connect(data->log_file, (struct sockaddr *)&SyslogAddr, - sizeof(SyslogAddr)) == -1) { - int save_errno = errno; - (void)close(data->log_file); - data->log_file = -1; - if (LogType == SOCK_DGRAM && save_errno == EPROTOTYPE) { - /* retry with SOCK_STREAM */ - LogType = SOCK_STREAM; - errno = old_errno; - goto again; - } - } else - data->connected = 1; - } -} - -void -openlog_r(const char *ident, int logstat, int logfac, struct syslog_data *data) -{ - if (ident != NULL) - data->log_tag = ident; - data->log_stat = logstat; - if (logfac != 0 && (logfac &~ LOG_FACMASK) == 0) - data->log_fac = logfac; - - if (data->log_stat & LOG_NDELAY) /* open immediately */ - connectlog_r(data); - - data->opened = 1; /* ident and facility has been set */ -} - -void -closelog_r(struct syslog_data *data) -{ - (void)close(data->log_file); - data->log_file = -1; - data->connected = 0; - data->log_tag = NULL; -} - -/* setlogmask -- set the log mask level */ -int -setlogmask_r(int pmask, struct syslog_data *data) -{ - int omask; - - omask = data->log_mask; - if (pmask != 0) - data->log_mask = pmask; - return (omask); -} diff --git a/lib/vsprintf.c b/lib/vsprintf.c deleted file mode 100644 index b21b8cb..0000000 --- a/lib/vsprintf.c +++ /dev/null @@ -1,619 +0,0 @@ -#ident "$Id: vsprintf.c,v 1.2 2005/11/27 04:08:54 raven Exp $" -/* - * Stolen from the linux kernel. - * - * License: GPL - */ -/*------------------ Original Copyright -----------------*/ -/* - * linux/lib/vsprintf.c - * - * Copyright (C) 1991, 1992 Linus Torvalds - */ - -/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */ -/* - * Wirzenius wrote this portably, Torvalds fucked it up :-) - */ - -/* - * Fri Jul 13 2001 Crutcher Dunnavant - * - changed to provide snprintf and vsnprintf functions - * So Feb 1 16:51:32 CET 2004 Juergen Quade - * - scnprintf and vscnprintf - */ - -/* Also copied from: */ - -/* - * linux/lib/string.c - * - * Copyright (C) 1991, 1992 Linus Torvalds - */ - -/* - * stupid library routines.. The optimized versions should generally be found - * as inline code in - * - * These are buggy as well.. - * - * * Fri Jun 25 1999, Ingo Oeser - * - Added strsep() which will replace strtok() soon (because strsep() is - * reentrant and should be faster). Use only strsep() in new code, please. - * - * * Sat Feb 09 2002, Jason Thomas , - * Matthew Hawkins - * - Kissed strtok() goodbye - */ -/*-------------------------------------------------------*/ - -#include -#include -#include -#include -#include -#include - -#define BITS_PER_LONG __WORDSIZE -#define PAGE_SIZE getpagesize() - - -#if BITS_PER_LONG == 64 - -# define do_div(n,base) ({ \ - uint32_t __base = (base); \ - uint32_t __rem; \ - __rem = ((uint64_t)(n)) % __base; \ - (n) = ((uint64_t)(n)) / __base; \ - __rem; \ - }) - -#elif BITS_PER_LONG == 32 - -/* Not needed on 64bit architectures */ -uint32_t __div64_32(uint64_t *n, uint32_t base) -{ - uint64_t rem = *n; - uint64_t b = base; - uint64_t res, d = 1; - uint32_t high = rem >> 32; - - /* Reduce the thing a bit first */ - res = 0; - if (high >= base) { - high /= base; - res = (uint64_t) high << 32; - rem -= (uint64_t) (high*base) << 32; - } - - while ((int64_t)b > 0 && b < rem) { - b = b+b; - d = d+d; - } - - do { - if (rem >= b) { - rem -= b; - res += d; - } - b >>= 1; - d >>= 1; - } while (d); - - *n = res; - return rem; -} - -/* The unnecessary pointer compare is there - * to check for type safety (n must be 64bit) - */ -# define do_div(n,base) ({ \ - uint32_t __base = (base); \ - uint32_t __rem; \ - (void)(((typeof((n)) *)0) == ((uint64_t *)0)); \ - if (((n) >> 32) == 0) { \ - __rem = (uint32_t)(n) % __base; \ - (n) = (uint32_t)(n) / __base; \ - } else \ - __rem = __div64_32(&(n), __base); \ - __rem; \ - }) - -# else - -# error do_div() does not yet support the C64 - -#endif /* BITS_PER_LONG */ - - -/** - * strnlen - Find the length of a length-limited string - * @s: The string to be sized - * @count: The maximum number of bytes to search - */ -size_t strnlen(const char * s, size_t count) -{ - const char *sc; - - for (sc = s; count-- && *sc != '\0'; ++sc) - /* nothing */; - return sc - s; -} - -/** - * simple_strtoul - convert a string to an unsigned long - * @cp: The start of the string - * @endp: A pointer to the end of the parsed string will be placed here - * @base: The number base to use - */ -unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base) -{ - unsigned long result = 0,value; - - if (!base) { - base = 10; - if (*cp == '0') { - base = 8; - cp++; - if ((toupper(*cp) == 'X') && isxdigit(cp[1])) { - cp++; - base = 16; - } - } - } else if (base == 16) { - if (cp[0] == '0' && toupper(cp[1]) == 'X') - cp += 2; - } - while (isxdigit(*cp) && - (value = isdigit(*cp) ? *cp-'0' : toupper(*cp)-'A'+10) < base) { - result = result*base + value; - cp++; - } - if (endp) - *endp = (char *)cp; - return result; -} - -/** - * simple_strtol - convert a string to a signed long - * @cp: The start of the string - * @endp: A pointer to the end of the parsed string will be placed here - * @base: The number base to use - */ -long simple_strtol(const char *cp,char **endp,unsigned int base) -{ - if(*cp=='-') - return -simple_strtoul(cp+1,endp,base); - return simple_strtoul(cp,endp,base); -} - -/** - * simple_strtoull - convert a string to an unsigned long long - * @cp: The start of the string - * @endp: A pointer to the end of the parsed string will be placed here - * @base: The number base to use - */ -unsigned long long simple_strtoull(const char *cp,char **endp,unsigned int base) -{ - unsigned long long result = 0,value; - - if (!base) { - base = 10; - if (*cp == '0') { - base = 8; - cp++; - if ((toupper(*cp) == 'X') && isxdigit(cp[1])) { - cp++; - base = 16; - } - } - } else if (base == 16) { - if (cp[0] == '0' && toupper(cp[1]) == 'X') - cp += 2; - } - while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp-'0' : (islower(*cp) - ? toupper(*cp) : *cp)-'A'+10) < base) { - result = result*base + value; - cp++; - } - if (endp) - *endp = (char *)cp; - return result; -} - -/** - * simple_strtoll - convert a string to a signed long long - * @cp: The start of the string - * @endp: A pointer to the end of the parsed string will be placed here - * @base: The number base to use - */ -long long simple_strtoll(const char *cp,char **endp,unsigned int base) -{ - if(*cp=='-') - return -simple_strtoull(cp+1,endp,base); - return simple_strtoull(cp,endp,base); -} - -static int skip_atoi(const char **s) -{ - int i=0; - - while (isdigit(**s)) - i = i*10 + *((*s)++) - '0'; - return i; -} - -#define ZEROPAD 1 /* pad with zero */ -#define SIGN 2 /* unsigned/signed long */ -#define PLUS 4 /* show plus */ -#define SPACE 8 /* space if plus */ -#define LEFT 16 /* left justified */ -#define SPECIAL 32 /* 0x */ -#define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */ - -static char * number(char * buf, char * end, unsigned long long num, int base, int size, int precision, int type) -{ - char c,sign,tmp[66]; - const char *digits; - static const char small_digits[] = "0123456789abcdefghijklmnopqrstuvwxyz"; - static const char large_digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - int i; - - digits = (type & LARGE) ? large_digits : small_digits; - if (type & LEFT) - type &= ~ZEROPAD; - if (base < 2 || base > 36) - return NULL; - c = (type & ZEROPAD) ? '0' : ' '; - sign = 0; - if (type & SIGN) { - if ((signed long long) num < 0) { - sign = '-'; - num = - (signed long long) num; - size--; - } else if (type & PLUS) { - sign = '+'; - size--; - } else if (type & SPACE) { - sign = ' '; - size--; - } - } - if (type & SPECIAL) { - if (base == 16) - size -= 2; - else if (base == 8) - size--; - } - i = 0; - if (num == 0) - tmp[i++]='0'; - else while (num != 0) - tmp[i++] = digits[do_div(num,base)]; - if (i > precision) - precision = i; - size -= precision; - if (!(type&(ZEROPAD+LEFT))) { - while(size-->0) { - if (buf <= end) - *buf = ' '; - ++buf; - } - } - if (sign) { - if (buf <= end) - *buf = sign; - ++buf; - } - if (type & SPECIAL) { - if (base==8) { - if (buf <= end) - *buf = '0'; - ++buf; - } else if (base==16) { - if (buf <= end) - *buf = '0'; - ++buf; - if (buf <= end) - *buf = digits[33]; - ++buf; - } - } - if (!(type & LEFT)) { - while (size-- > 0) { - if (buf <= end) - *buf = c; - ++buf; - } - } - while (i < precision--) { - if (buf <= end) - *buf = '0'; - ++buf; - } - while (i-- > 0) { - if (buf <= end) - *buf = tmp[i]; - ++buf; - } - while (size-- > 0) { - if (buf <= end) - *buf = ' '; - ++buf; - } - return buf; -} - -/** - * vsnprintf_int - Format a string and place it in a buffer - * @buf: The buffer to place the result into - * @size: The size of the buffer, including the trailing null space - * @fmt: The format string to use - * @args: Arguments for the format string - * - * The return value is the number of characters which would - * be generated for the given input, excluding the trailing - * '\0', as per ISO C99. If you want to have the exact - * number of characters written into @buf as return value - * (not including the trailing '\0'), use vscnprintf. If the - * return is greater than or equal to @size, the resulting - * string is truncated. - * - * Call this function if you are already dealing with a va_list. - * You probably want snprintf instead. - */ -int vsnprintf_int(char *buf, size_t size, const char *fmt, va_list args) -{ - int len; - unsigned long long num; - int i, base; - char *str, *end, c; - const char *s; - - int flags; /* flags to number() */ - - int field_width; /* width of output field */ - int precision; /* min. # of digits for integers; max - number of chars for from string */ - int qualifier; /* 'h', 'l', or 'L' for integer fields */ - /* 'z' support added 23/7/1999 S.H. */ - /* 'z' changed to 'Z' --davidm 1/25/99 */ - - /* Reject out-of-range values early */ - if ((int) size < 0) - return 0; - - str = buf; - end = buf + size - 1; - - if (end < buf - 1) { - end = ((void *) -1); - size = end - buf + 1; - } - - for (; *fmt ; ++fmt) { - if (*fmt != '%') { - if (str <= end) - *str = *fmt; - ++str; - continue; - } - - /* process flags */ - flags = 0; - repeat: - ++fmt; /* this also skips first '%' */ - switch (*fmt) { - case '-': flags |= LEFT; goto repeat; - case '+': flags |= PLUS; goto repeat; - case ' ': flags |= SPACE; goto repeat; - case '#': flags |= SPECIAL; goto repeat; - case '0': flags |= ZEROPAD; goto repeat; - } - - /* get field width */ - field_width = -1; - if (isdigit(*fmt)) - field_width = skip_atoi(&fmt); - else if (*fmt == '*') { - ++fmt; - /* it's the next argument */ - field_width = va_arg(args, int); - if (field_width < 0) { - field_width = -field_width; - flags |= LEFT; - } - } - - /* get the precision */ - precision = -1; - if (*fmt == '.') { - ++fmt; - if (isdigit(*fmt)) - precision = skip_atoi(&fmt); - else if (*fmt == '*') { - ++fmt; - /* it's the next argument */ - precision = va_arg(args, int); - } - if (precision < 0) - precision = 0; - } - - /* get the conversion qualifier */ - qualifier = -1; - if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || - *fmt =='Z' || *fmt == 'z') { - qualifier = *fmt; - ++fmt; - if (qualifier == 'l' && *fmt == 'l') { - qualifier = 'L'; - ++fmt; - } - } - - /* default base */ - base = 10; - - switch (*fmt) { - case 'c': - if (!(flags & LEFT)) { - while (--field_width > 0) { - if (str <= end) - *str = ' '; - ++str; - } - } - c = (unsigned char) va_arg(args, int); - if (str <= end) - *str = c; - ++str; - while (--field_width > 0) { - if (str <= end) - *str = ' '; - ++str; - } - continue; - - case 's': - s = va_arg(args, char *); - if ((unsigned long)s < PAGE_SIZE) - s = ""; - - len = strnlen(s, precision); - - if (!(flags & LEFT)) { - while (len < field_width--) { - if (str <= end) - *str = ' '; - ++str; - } - } - for (i = 0; i < len; ++i) { - if (str <= end) - *str = *s; - ++str; ++s; - } - while (len < field_width--) { - if (str <= end) - *str = ' '; - ++str; - } - continue; - - case 'p': - if (field_width == -1) { - field_width = 2*sizeof(void *); - flags |= ZEROPAD; - } - str = number(str, end, - (unsigned long) va_arg(args, void *), - 16, field_width, precision, flags); - continue; - - - case 'n': - /* FIXME: - * What does C99 say about the overflow case here? */ - if (qualifier == 'l') { - long * ip = va_arg(args, long *); - *ip = (str - buf); - } else if (qualifier == 'Z' || qualifier == 'z') { - size_t * ip = va_arg(args, size_t *); - *ip = (str - buf); - } else { - int * ip = va_arg(args, int *); - *ip = (str - buf); - } - continue; - - case '%': - if (str <= end) - *str = '%'; - ++str; - continue; - - /* integer number formats - set up the flags and "break" */ - case 'o': - base = 8; - break; - - case 'X': - flags |= LARGE; - case 'x': - base = 16; - break; - - case 'd': - case 'i': - flags |= SIGN; - case 'u': - break; - - default: - if (str <= end) - *str = '%'; - ++str; - if (*fmt) { - if (str <= end) - *str = *fmt; - ++str; - } else { - --fmt; - } - continue; - } - if (qualifier == 'L') - num = va_arg(args, long long); - else if (qualifier == 'l') { - num = va_arg(args, unsigned long); - if (flags & SIGN) - num = (signed long) num; - } else if (qualifier == 'Z' || qualifier == 'z') { - num = va_arg(args, size_t); - } else if (qualifier == 'h') { - num = (unsigned short) va_arg(args, int); - if (flags & SIGN) - num = (signed short) num; - } else { - num = va_arg(args, unsigned int); - if (flags & SIGN) - num = (signed int) num; - } - str = number(str, end, num, base, - field_width, precision, flags); - } - if (str <= end) - *str = '\0'; - else if (size > 0) - /* don't write out a null byte if the buf size is zero */ - *end = '\0'; - /* the trailing null byte doesn't count towards the total - * ++str; - */ - return str-buf; -} - -/** - * snprintf_int - Format a string and place it in a buffer - * @buf: The buffer to place the result into - * @size: The size of the buffer, including the trailing null space - * @fmt: The format string to use - * @...: Arguments for the format string - * - * The return value is the number of characters which would be - * generated for the given input, excluding the trailing null, - * as per ISO C99. If the return is greater than or equal to - * @size, the resulting string is truncated. - */ -int snprintf_int(char * buf, size_t size, const char *fmt, ...) -{ - va_list args; - int i; - - va_start(args, fmt); - i=vsnprintf_int(buf,size,fmt,args); - va_end(args); - return i; -} - diff --git a/modules/cyrus-sasl.c b/modules/cyrus-sasl.c index 8571001..6058548 100644 --- a/modules/cyrus-sasl.c +++ b/modules/cyrus-sasl.c @@ -305,7 +305,6 @@ do_sasl_bind(LDAP *ld, sasl_conn_t *conn "bind request, but indicated that the bind was " "complete. LDAP SASL bind with mechansim %s " "failed.", auth_mech); - //debug(""); /* dump out the data we got */ ret = -1; break; } @@ -388,7 +387,7 @@ sasl_do_kinit(struct lookup_context *ctx debug(LOGOPT_NONE, "initializing kerberos ticket: client principal %s ", - ctxt->client_princ ?: "autofsclient"); + ctxt->client_princ ? "" : "autofsclient"); ret = krb5_init_context(&ctxt->krb5ctxt); if (ret) { @@ -431,7 +430,7 @@ sasl_do_kinit(struct lookup_context *ctx error(LOGOPT_ANY, "krb5_sname_to_principal failed for " "%s with error %d", - ctxt->client_princ ?: "autofsclient", ret); + ctxt->client_princ ? "" : "autofsclient", ret); goto out_cleanup_cc; } diff --git a/modules/lookup_file.c b/modules/lookup_file.c index d487418..dff7638 100644 --- a/modules/lookup_file.c +++ b/modules/lookup_file.c @@ -1,4 +1,3 @@ -#ident "$Id: lookup_file.c,v 1.36 2006/03/31 18:26:16 raven Exp $" /* ----------------------------------------------------------------------- * * * lookup_file.c - module for Linux automount to query a flat file map @@ -942,10 +941,10 @@ int lookup_mount(struct autofs_point *ap me = cache_lookup(mc, key); if (me) { pthread_cleanup_push(cache_lock_cleanup, mc); - mapent = alloca(strlen(me->mapent) + 1); - mapent_len = sprintf(mapent, me->mapent); + mapent_len = strlen(me->mapent); + mapent = alloca(mapent_len + 1); + strcpy(mapent, me->mapent); pthread_cleanup_pop(0); - mapent[mapent_len] = '\0'; } cache_unlock(mc); @@ -955,14 +954,13 @@ int lookup_mount(struct autofs_point *ap mapent, ctxt->parse->context); if (ret) { time_t now = time(NULL); - int status = CHE_OK; + int rv = CHE_OK; cache_writelock(mc); me = cache_lookup_distinct(mc, key); if (!me) - status = cache_update(mc, - source, key, NULL, now); - if (status != CHE_FAIL) { + rv = cache_update(mc, source, key, NULL, now); + if (rv != CHE_FAIL) { me = cache_lookup_distinct(mc, key); me->status = now + NEGATIVE_TIMEOUT; } diff --git a/modules/lookup_hesiod.c b/modules/lookup_hesiod.c index da4052d..4491c16 100644 --- a/modules/lookup_hesiod.c +++ b/modules/lookup_hesiod.c @@ -1,4 +1,3 @@ -#ident "$Id: lookup_hesiod.c,v 1.14 2006/03/29 10:32:36 raven Exp $" /* * lookup_hesiod.c * diff --git a/modules/lookup_hosts.c b/modules/lookup_hosts.c index f1bd68b..0e5152e 100644 --- a/modules/lookup_hosts.c +++ b/modules/lookup_hosts.c @@ -1,4 +1,3 @@ -#ident "$Id: lookup_hosts.c,v 1.10 2006/03/31 18:26:16 raven Exp $" /* ----------------------------------------------------------------------- * * * lookup_hosts.c - module for Linux automount to mount the exports diff --git a/modules/lookup_ldap.c b/modules/lookup_ldap.c index e0d7cb5..36e8457 100644 --- a/modules/lookup_ldap.c +++ b/modules/lookup_ldap.c @@ -1,4 +1,3 @@ -#ident "$Id: lookup_ldap.c,v 1.40 2006/04/06 20:02:04 raven Exp $" /* * lookup_ldap.c - Module for Linux automountd to access automount * maps in LDAP directories. @@ -55,7 +54,7 @@ int bind_ldap_anonymous(LDAP *ldap, stru if (rv != LDAP_SUCCESS) { crit(LOGOPT_ANY, MODPREFIX "Unable to bind to the LDAP server: " - "%s, error %s", ctxt->server ?: "(default)", + "%s, error %s", ctxt->server ? "" : "(default)", ldap_err2string(rv)); return -1; } @@ -67,7 +66,7 @@ int unbind_ldap_connection(LDAP *ldap, s { int rv; -#if WITH_SASL +#ifdef WITH_SASL debug(LOGOPT_NONE, "use_tls: %d", ctxt->use_tls); /* * The OpenSSL library can't handle having its message and error @@ -135,7 +134,7 @@ LDAP *init_ldap_connection(struct lookup MODPREFIX "failed to set connection timeout to %d", timeout); -#if WITH_SASL +#ifdef WITH_SASL if (ctxt->use_tls) { if (ctxt->version == 2) { if (ctxt->tls_required) { @@ -180,7 +179,7 @@ static LDAP *do_connect(struct lookup_co if (!ldap) return NULL; -#if WITH_SASL +#ifdef WITH_SASL debug(LOGOPT_NONE, "auth_required: %d, sasl_mech %s", ctxt->auth_required, ctxt->sasl_mech); @@ -207,7 +206,7 @@ #endif return ldap; } -#if WITH_SASL +#ifdef WITH_SASL int get_property(xmlNodePtr node, const char *prop, char **value) { xmlChar *ret; @@ -802,7 +801,7 @@ static int get_query_dn(LDAP *ldap, stru MODPREFIX "error forming query string"); return 0; } - scope = LDAP_SCOPE_ONE; + scope = LDAP_SCOPE_ONELEVEL; } else { if (sprintf(query, "(objectclass=%s)", class) >= l) { debug(LOGOPT_NONE, @@ -883,7 +882,7 @@ int lookup_init(const char *mapfmt, int return 1; } -#if WITH_SASL +#ifdef WITH_SASL /* * Determine which authentication mechanism to use. We sanity- * check by binding to the server temporarily. @@ -1281,7 +1280,6 @@ static int lookup_one(struct autofs_poin { struct map_source *source = ap->entry->current; struct mapent_cache *mc = source->mc; - struct mapent me; int rv, i, l, ql, count; char buf[MAX_ERR_BUF]; time_t age = time(NULL); @@ -1480,7 +1478,7 @@ static int check_map_indirect(struct aut exists = NULL; cache_unlock(mc); - ret = lookup_one(ap, key, strlen(key), ctxt); + ret = lookup_one(ap, key, key_len, ctxt); if (ret == CHE_FAIL) return NSS_STATUS_NOTFOUND; @@ -1590,9 +1588,9 @@ int lookup_mount(struct autofs_point *ap me = cache_lookup(mc, key); if (me) { pthread_cleanup_push(cache_lock_cleanup, mc); - mapent = alloca(strlen(me->mapent) + 1); - mapent_len = sprintf(mapent, me->mapent); - mapent[mapent_len] = '\0'; + mapent_len = strlen(me->mapent); + mapent = alloca(mapent_len + 1); + strcpy(mapent, me->mapent); pthread_cleanup_pop(0); } cache_unlock(mc); @@ -1603,15 +1601,14 @@ int lookup_mount(struct autofs_point *ap mapent, ctxt->parse->context); if (ret) { time_t now = time(NULL); - int status = CHE_OK; + int rv = CHE_OK; /* Record the the mount fail in the cache */ cache_writelock(mc); me = cache_lookup_distinct(mc, key); if (!me) - status = cache_update(mc, - source, key, NULL, now); - if (status != CHE_FAIL) { + rv = cache_update(mc, source, key, NULL, now); + if (rv != CHE_FAIL) { me = cache_lookup_distinct(mc, key); me->status = now + NEGATIVE_TIMEOUT; } @@ -1633,7 +1630,7 @@ int lookup_done(void *context) { struct lookup_context *ctxt = (struct lookup_context *) context; int rv = close_parse(ctxt->parse); -#if WITH_SASL +#ifdef WITH_SASL EVP_cleanup(); ERR_free_strings(); diff --git a/modules/lookup_multi.c b/modules/lookup_multi.c index c64a141..a3363b7 100644 --- a/modules/lookup_multi.c +++ b/modules/lookup_multi.c @@ -1,4 +1,3 @@ -#ident "$Id: lookup_multi.c,v 1.15 2006/03/21 04:28:53 raven Exp $" /* ----------------------------------------------------------------------- * * * lookup_multi.c - module for Linux automount to seek multiple lookup diff --git a/modules/lookup_nisplus.c b/modules/lookup_nisplus.c index bcba341..2f45ad8 100644 --- a/modules/lookup_nisplus.c +++ b/modules/lookup_nisplus.c @@ -1,4 +1,3 @@ -#ident "$Id: lookup_nisplus.c,v 1.16 2006/03/31 18:26:16 raven Exp $" /* * lookup_nisplus.c * @@ -81,16 +80,22 @@ int lookup_init(const char *mapfmt, int int lookup_read_master(struct master *master, time_t age, void *context) { struct lookup_context *ctxt = (struct lookup_context *) context; - char tablename[strlen(ctxt->mapname) + - strlen(ctxt->domainname) + 20]; unsigned int timeout = master->default_timeout; unsigned int logging = master->default_logging; + char *tablename; nis_result *result; nis_object *this; unsigned int current, result_count; char *path, *ent; char *buffer; + char buf[MAX_ERR_BUF]; + tablename = alloca(strlen(ctxt->mapname) + strlen(ctxt->domainname) + 20); + if (!tablename) { + char *estr = strerror_r(errno, buf, MAX_ERR_BUF); + crit(LOGOPT_ANY, MODPREFIX "alloca: %s", estr); + return NSS_STATUS_UNAVAIL; + } sprintf(tablename, "%s.org_dir.%s", ctxt->mapname, ctxt->domainname); /* check that the table exists */ @@ -153,13 +158,19 @@ int lookup_read_map(struct autofs_point struct lookup_context *ctxt = (struct lookup_context *) context; struct map_source *source = ap->entry->current; struct mapent_cache *mc = source->mc; - char tablename[strlen(ctxt->mapname) + - strlen(ctxt->domainname) + 20]; + char *tablename; nis_result *result; nis_object *this; unsigned int current, result_count; char *key, *mapent; + char buf[MAX_ERR_BUF]; + tablename = alloca(strlen(ctxt->mapname) + strlen(ctxt->domainname) + 20); + if (!tablename) { + char *estr = strerror_r(errno, buf, MAX_ERR_BUF); + crit(LOGOPT_ANY, MODPREFIX "alloca: %s", estr); + return NSS_STATUS_UNAVAIL; + } sprintf(tablename, "%s.org_dir.%s", ctxt->mapname, ctxt->domainname); /* check that the table exists */ @@ -217,14 +228,21 @@ static int lookup_one(struct autofs_poin { struct map_source *source = ap->entry->current; struct mapent_cache *mc = source->mc; - char tablename[strlen(key) + strlen(ctxt->mapname) + - strlen(ctxt->domainname) + 20]; + char *tablename; nis_result *result; nis_object *this; char *mapent; time_t age = time(NULL); int ret; + char buf[MAX_ERR_BUF]; + tablename = alloca(strlen(key) + + strlen(ctxt->mapname) + strlen(ctxt->domainname) + 20); + if (!tablename) { + char *estr = strerror_r(errno, buf, MAX_ERR_BUF); + crit(LOGOPT_ANY, MODPREFIX "alloca: %s", estr); + return -1; + } sprintf(tablename, "[key=%s],%s.org_dir.%s", key, ctxt->mapname, ctxt->domainname); @@ -254,14 +272,20 @@ static int lookup_wild(struct autofs_poi { struct map_source *source = ap->entry->current; struct mapent_cache *mc = source->mc; - char tablename[strlen(ctxt->mapname) + - strlen(ctxt->domainname) + 20]; + char *tablename; nis_result *result; nis_object *this; char *mapent; time_t age = time(NULL); int ret; + char buf[MAX_ERR_BUF]; + tablename = alloca(strlen(ctxt->mapname) + strlen(ctxt->domainname) + 20); + if (!tablename) { + char *estr = strerror_r(errno, buf, MAX_ERR_BUF); + crit(LOGOPT_ANY, MODPREFIX "alloca: %s", estr); + return -1; + } sprintf(tablename, "[key=*],%s.org_dir.%s", ctxt->mapname, ctxt->domainname); @@ -424,8 +448,9 @@ int lookup_mount(struct autofs_point *ap me = cache_lookup(mc, key); if (me) { pthread_cleanup_push(cache_lock_cleanup, mc); - mapent = alloca(strlen(me->mapent) + 1); - mapent_len = sprintf(mapent, "%s", me->mapent); + mapent_len = strlen(me->mapent); + mapent = alloca(mapent_len + 1); + strcpy(mapent, me->mapent); pthread_cleanup_pop(0); } cache_unlock(mc); @@ -436,14 +461,13 @@ int lookup_mount(struct autofs_point *ap mapent, ctxt->parse->context); if (ret) { time_t now = time(NULL); - int status = CHE_OK; + int rv = CHE_OK; cache_writelock(mc); me = cache_lookup_distinct(mc, key); if (!me) - status = cache_update(mc, - source, key, NULL, now); - if (status != CHE_FAIL) { + rv = cache_update(mc, source, key, NULL, now); + if (rv != CHE_FAIL) { me = cache_lookup_distinct(mc, key); me->status = time(NULL) + NEGATIVE_TIMEOUT; } diff --git a/modules/lookup_program.c b/modules/lookup_program.c index e527f52..c7c2418 100644 --- a/modules/lookup_program.c +++ b/modules/lookup_program.c @@ -1,4 +1,3 @@ -#ident "$Id: lookup_program.c,v 1.17 2006/03/29 10:32:36 raven Exp $" /* ----------------------------------------------------------------------- * * * lookup_program.c - module for Linux automount to access an diff --git a/modules/lookup_userhome.c b/modules/lookup_userhome.c index ee78bf4..0d84379 100644 --- a/modules/lookup_userhome.c +++ b/modules/lookup_userhome.c @@ -1,4 +1,3 @@ -#ident "$Id: lookup_userhome.c,v 1.10 2006/03/21 04:28:53 raven Exp $" /* ----------------------------------------------------------------------- * * * lookup_userhome.c - module for Linux automount to generate symlinks diff --git a/modules/lookup_yp.c b/modules/lookup_yp.c index d2f4133..ad37697 100644 --- a/modules/lookup_yp.c +++ b/modules/lookup_yp.c @@ -1,4 +1,3 @@ -#ident "$Id: lookup_yp.c,v 1.30 2006/03/31 18:26:16 raven Exp $" /* ----------------------------------------------------------------------- * * * lookup_yp.c - module for Linux automountd to access a YP (NIS) @@ -565,9 +564,9 @@ int lookup_mount(struct autofs_point *ap me = cache_lookup(mc, key); if (me) { pthread_cleanup_push(cache_lock_cleanup, mc); - mapent = alloca(strlen(me->mapent) + 1); - mapent_len = sprintf(mapent, "%s", me->mapent); - mapent[mapent_len] = '\0'; + mapent_len = strlen(me->mapent); + mapent = alloca(mapent_len + 1); + strcpy(mapent, me->mapent); pthread_cleanup_pop(0); } cache_unlock(mc); @@ -578,14 +577,13 @@ int lookup_mount(struct autofs_point *ap mapent, ctxt->parse->context); if (ret) { time_t now = time(NULL); - int status = CHE_OK; + int rv = CHE_OK; cache_writelock(mc); me = cache_lookup_distinct(mc, key); if (!me) - status = cache_update(mc, - source, key, NULL, now); - if (status != CHE_FAIL) { + rv = cache_update(mc, source, key, NULL, now); + if (rv != CHE_FAIL) { me = cache_lookup_distinct(mc, key); me->status = now + NEGATIVE_TIMEOUT; } diff --git a/modules/mount_afs.c b/modules/mount_afs.c index 1d9c363..252302e 100644 --- a/modules/mount_afs.c +++ b/modules/mount_afs.c @@ -1,4 +1,3 @@ -#ident "$Id: mount_afs.c,v 1.9 2006/03/11 06:02:48 raven Exp $" /* * mount_afs.c * diff --git a/modules/mount_autofs.c b/modules/mount_autofs.c index 885280a..af28c5c 100644 --- a/modules/mount_autofs.c +++ b/modules/mount_autofs.c @@ -1,4 +1,3 @@ -#ident "$Id: mount_autofs.c,v 1.25 2006/03/25 05:22:52 raven Exp $" /* ----------------------------------------------------------------------- * * * mount_autofs.c - Module for recursive autofs mounts. @@ -136,12 +135,12 @@ int mount_mount(struct autofs_point *ap, argc = 1; if (options) { - char *p = options; + char *t = options; do { argc++; - if (*p == ',') - p++; - } while ((p = strchr(p, ',')) != NULL); + if (*t == ',') + t++; + } while ((t = strchr(t, ',')) != NULL); } argv = (const char **) alloca((argc + 1) * sizeof(char *)); diff --git a/modules/mount_bind.c b/modules/mount_bind.c index 3d292a6..695dc9a 100644 --- a/modules/mount_bind.c +++ b/modules/mount_bind.c @@ -1,4 +1,3 @@ -#ident "$Id: mount_bind.c,v 1.22 2006/03/29 10:32:36 raven Exp $" /* ----------------------------------------------------------------------- * * * mount_bind.c - module to mount a local filesystem if possible; diff --git a/modules/mount_changer.c b/modules/mount_changer.c index 06e2032..29485cb 100644 --- a/modules/mount_changer.c +++ b/modules/mount_changer.c @@ -1,4 +1,3 @@ -#ident "$Id: mount_changer.c,v 1.20 2006/03/29 10:32:36 raven Exp $" /* ----------------------------------------------------------------------- * * * mount_changer.c - module for Linux automountd to mount filesystems diff --git a/modules/mount_ext2.c b/modules/mount_ext2.c index 976d23a..b395235 100644 --- a/modules/mount_ext2.c +++ b/modules/mount_ext2.c @@ -1,4 +1,3 @@ -#ident "$Id: mount_ext2.c,v 1.25 2006/03/29 10:32:36 raven Exp $" /* ----------------------------------------------------------------------- * * * mount_ext2.c - module for Linux automountd to mount ext2 filesystems diff --git a/modules/mount_generic.c b/modules/mount_generic.c index e744813..37ada41 100644 --- a/modules/mount_generic.c +++ b/modules/mount_generic.c @@ -1,4 +1,3 @@ -#ident "$Id: mount_generic.c,v 1.22 2006/03/29 10:32:36 raven Exp $" /* ----------------------------------------------------------------------- * * * mount_generic.c - module for Linux automountd to mount filesystems diff --git a/modules/mount_nfs.c b/modules/mount_nfs.c index b4df2f2..72a9c53 100644 --- a/modules/mount_nfs.c +++ b/modules/mount_nfs.c @@ -1,4 +1,3 @@ -#ident "$Id: mount_nfs.c,v 1.36 2006/03/31 18:26:16 raven Exp $" /* ----------------------------------------------------------------------- * * * mount_nfs.c - Module for Linux automountd to mount an NFS filesystem, @@ -47,7 +46,7 @@ int mount_init(void **context) { /* Make sure we have the local mount method available */ if (!mount_bind) { - if ((mount_bind = open_mount("bind", MODPREFIX))); + if ((mount_bind = open_mount("bind", MODPREFIX))) init_ctr++; } else init_ctr++; @@ -80,13 +79,13 @@ int mount_mount(struct autofs_point *ap, if (options) { const char *comma; char *nfsp; - int len = strlen(options) + 1; + int o_len = strlen(options) + 1; - nfsp = nfsoptions = alloca(len + 1); + nfsp = nfsoptions = alloca(o_len + 1); if (!nfsoptions) return 1; - memset(nfsoptions, '\0', len + 1); + memset(nfsoptions, '\0', o_len + 1); for (comma = options; *comma != '\0';) { const char *cp; diff --git a/modules/parse_hesiod.c b/modules/parse_hesiod.c index 2df981b..8483a99 100644 --- a/modules/parse_hesiod.c +++ b/modules/parse_hesiod.c @@ -1,4 +1,3 @@ -#ident "$Id: parse_hesiod.c,v 1.9 2006/03/11 06:02:48 raven Exp $" /* * parse_hesiod.c * diff --git a/modules/parse_sun.c b/modules/parse_sun.c index 3859d13..7e0f211 100644 --- a/modules/parse_sun.c +++ b/modules/parse_sun.c @@ -1,4 +1,3 @@ -#ident "$Id: parse_sun.c,v 1.49 2006/03/31 18:26:16 raven Exp $" /* ----------------------------------------------------------------------- * * * parse_sun.c - module for Linux automountd to parse a Sun-format @@ -477,18 +476,18 @@ int parse_init(int argc, const char *con } } -static char *dequote(const char *str, int strlen, unsigned int logopt) +static char *dequote(const char *str, int len, unsigned int logopt) { - char *ret = malloc(strlen + 1); + char *ret = malloc(len + 1); char *cp = ret; const char *scp; - int origlen = strlen; + int origlen = len; int quote = 0; if (ret == NULL) return NULL; - for (scp = str; strlen > 0 && *scp; scp++, strlen--) { + for (scp = str; len > 0 && *scp; scp++, len--) { if (*scp == '\\' && !quote ) { quote = 1; continue; @@ -700,7 +699,7 @@ static int sun_mount(struct autofs_point */ static int check_is_multi(const char *mapent) { - const char *p = (char *) mapent; + const char *p = mapent; int multi = 0; int not_first_chunk = 0; diff --git a/modules/replicated.c b/modules/replicated.c index 2d7e94a..aa484b3 100644 --- a/modules/replicated.c +++ b/modules/replicated.c @@ -75,17 +75,17 @@ #define mmax(x, y, z) (max(x, y) == x ? static unsigned int get_proximity(const char *host_addr, int addr_len) { struct sockaddr_in *msk_addr, *if_addr; - struct in_addr *h_addr; - char tmp[20], buf[MAX_ERR_BUF], *estr, *ptr; + struct in_addr *hst_addr; + char tmp[20], buf[MAX_ERR_BUF], *ptr; struct ifconf ifc; struct ifreq *ifr, nmptr; int sock, ret, i; uint32_t mask, ha, ia; memcpy(tmp, host_addr, addr_len); - h_addr = (struct in_addr *) tmp; + hst_addr = (struct in_addr *) tmp; - ha = ntohl((uint32_t) h_addr->s_addr); + ha = ntohl((uint32_t) hst_addr->s_addr); sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) { @@ -98,7 +98,7 @@ static unsigned int get_proximity(const ifc.ifc_req = (struct ifreq *) buf; ret = ioctl(sock, SIOCGIFCONF, &ifc); if (ret == -1) { - estr = strerror_r(errno, buf, MAX_ERR_BUF); + char *estr = strerror_r(errno, buf, MAX_ERR_BUF); error(LOGOPT_ANY, "ioctl: %s", estr); close(sock); return PROXIMITY_ERROR; @@ -116,7 +116,7 @@ static unsigned int get_proximity(const switch (ifr->ifr_addr.sa_family) { case AF_INET: if_addr = (struct sockaddr_in *) &ifr->ifr_addr; - ret = memcmp(&if_addr->sin_addr, h_addr, addr_len); + ret = memcmp(&if_addr->sin_addr, hst_addr, addr_len); if (!ret) { close(sock); return PROXIMITY_LOCAL; @@ -147,7 +147,7 @@ static unsigned int get_proximity(const nmptr = *ifr; ret = ioctl(sock, SIOCGIFNETMASK, &nmptr); if (ret == -1) { - estr = strerror_r(errno, buf, MAX_ERR_BUF); + char *estr = strerror_r(errno, buf, MAX_ERR_BUF); error(LOGOPT_ANY, "ioctl: %s", estr); return PROXIMITY_ERROR; } @@ -696,7 +696,7 @@ static int add_host_addrs(struct host ** struct hostent *result; struct sockaddr_in saddr; char buf[MAX_IFC_BUF], **haddr; - int h_errno, ret; + int ghn_errno, ret; struct host *new; unsigned int prx; @@ -721,14 +721,14 @@ static int add_host_addrs(struct host ** memset(&he, 0, sizeof(struct hostent)); ret = gethostbyname_r(host, phe, - buf, MAX_IFC_BUF, &result, &h_errno); + buf, MAX_IFC_BUF, &result, &ghn_errno); if (ret || !result) { - if (h_errno == -1) + if (ghn_errno == -1) error(LOGOPT_ANY, "host %s: lookup failure %d", host, errno); else error(LOGOPT_ANY, - "host %s: lookup failure %d", host, h_errno); + "host %s: lookup failure %d", host, ghn_errno); return 0; } @@ -778,7 +778,7 @@ static int add_path(struct host *hosts, int parse_location(struct host **hosts, const char *list) { char *str, *p, *delim; - unsigned int list_empty = 1; + unsigned int empty = 1; if (!list) return 0; @@ -830,7 +830,7 @@ int parse_location(struct host **hosts, } if (!add_host_addrs(hosts, p, weight)) { - if (list_empty) { + if (empty) { p = next; continue; } @@ -850,7 +850,7 @@ int parse_location(struct host **hosts, continue; } - list_empty = 0; + empty = 0; } } else { /* syntax error - no mount path */