Current status of patches awaiting commit
Subsystems (3)
Ian Kent
maintainercover Current status of patches awaiting commit
Hi all,
Here are the pacthes I'm wanting to commit to the git repo. I think they are OK but any time that anyone has to review any of them would be much appreciated.
Clearly the configure script changes are the result of autoconf configuration changes so that bit doesn't really count. Try to find the actual changes amongst the patch.
The libtirpc configure patch adds an dlopen() (and a dlclose()) for libtirpc but it has become clear this method doesn't resolve the tsd SEGV we see that I still believe is due to libraries not handling these keys correctly. So there will be more to come on that front.
The ipv6 changes probably need more work as, and when, nfs over ipv6 becomes a reality and people start using it. I have done my best to verify these changes work against various current map configurations.
Ian
---
Ian Kent (10):
autofs-5.0.4 - ipv6 parse
autofs-5.0.4 - ipv6 name and address support autofs-5.0.4 - configure libtirpc autofs-5.0.4 - code analysis corrections autofs-5.0.4 - always read file maps autofs-5.0.4 - force unlink umount at startup autofs-5.0.4 - library reload fix update autofs-5.0.4 - renew sasl creds upon reconnect fail autofs-5.0.4 - uris list locking fix autofs-5.0.4 - use CLOEXEC flag for setmntent
Paul Wankadia (1):
autofs-5.0.4 - fix hosts map use after free
Valerie Aurora Henson (2):
autofs-5.0.4 - easy alloca replacements
autofs-5.0.4 - make MAX_ERR_BUF and PARSE_MAX_BUF use easier to audit
CHANGELOG | 8 Makefile.conf.in | 3 Makefile.rules | 5 aclocal.m4 | 81 ++ autofs.spec | 2 configure | 1548 +++++++++++++++++++++++++--------------------- configure.in | 6 daemon/automount.c | 91 ++- daemon/direct.c | 27 - daemon/flag.c | 13 daemon/indirect.c | 24 - daemon/lookup.c | 29 - daemon/module.c | 45 - daemon/state.c | 13 include/automount.h | 23 + include/config.h.in | 6 include/lookup_ldap.h | 3 include/master.h | 3 include/parse_subs.h | 8 include/replicated.h | 2 include/rpc_subs.h | 4 lib/alarm.c | 6 lib/cache.c | 35 - lib/cat_path.c | 1 lib/defaults.c | 1 lib/macros.c | 2 lib/master.c | 38 + lib/master_tok.l | 10 lib/mounts.c | 13 lib/parse_subs.c | 99 +++ lib/rpc_subs.c | 484 +++++++++----- man/automount.8 | 13 modules/cyrus-sasl.c | 17 - modules/lookup_file.c | 187 ++---- modules/lookup_hosts.c | 8 modules/lookup_ldap.c | 250 ++++--- modules/lookup_multi.c | 15 modules/lookup_nisplus.c | 71 +- modules/lookup_program.c | 4 modules/mount_autofs.c | 34 - modules/mount_bind.c | 7 modules/mount_changer.c | 7 modules/mount_ext2.c | 5 modules/mount_generic.c | 5 modules/mount_nfs.c | 5 modules/parse_hesiod.c | 79 ++ modules/parse_sun.c | 34 + modules/replicated.c | 263 ++++++-- redhat/autofs.init.in | 10 samples/rc.autofs.in | 10 50 files changed, 2221 insertions(+), 1436 deletions(-)
Signature · 1 line
Signature
Ian Kent
maintainerPATCH 1/13 autofs-5.0.4 - use CLOEXEC flag for setmntent
Update use of CLOEXEC functionality to cover setmntent(3) calls as well.
---
CHANGELOG | 1 + include/automount.h | 20 ++++++++++++++++++++ lib/mounts.c | 8 ++++---- 3 files changed, 25 insertions(+), 4 deletions(-)
CHANGELOG +1 -0
@@ -8,6 +8,7 @@ - make hash table scale to thousands of entries (Paul Wankadia, Valerie Aurora Henson). - clear the quoted flag after each character from program map input. +- use CLOEXEC flag for setmntent also. 4/11/2008 autofs-5.0.4 -----------------------
include/automount.h +20 -0
@@ -581,5 +581,25 @@ static inline FILE *open_fopen_r(const char *path) return f; } +static inline FILE *open_setmntent_r (const char *table) +{ +FILE *tab; + +#if defined(O_CLOEXEC ) && defined(SOCK_CLOEXEC ) +if (cloexec_works !=-1 ) { + tab =setmntent (table,"re" ); +if (tab !=NULL ) { +check_cloexec (fileno (tab)); +return tab; + } + } +#endif + tab =fopen (table,"r" ); +if (tab ==NULL ) +return NULL ; +check_cloexec (fileno (tab)); +return tab; +} +#endif
lib/mounts.c +4 -4
@@ -218,7 +218,7 @@ struct mnt_list *get_mnt_list(const char *table, const char *path, int include)if (!path || !pathlen || pathlen >PATH_MAX )return NULL ; - tab =setmntent (table,"r" ); + tab =open_setmntent_r (table);if (!tab) {char *estr =strerror_r (errno, buf,PATH_MAX -1 );logerr ("setmntent: %s" , estr);
@@ -415,7 +415,7 @@ static int table_is_mounted(const char *table, const char *path, unsigned int tyif (!path || !pathlen || pathlen >=PATH_MAX )return 0 ; - tab =setmntent (table,"r" ); + tab =open_setmntent_r (table);if (!tab) {char *estr =strerror_r (errno, buf,PATH_MAX -1 );logerr ("setmntent: %s" , estr);
@@ -489,7 +489,7 @@ int has_fstab_option(const char *opt)if (!opt)return 0 ; - tab =setmntent (_PATH_MNTTAB,"r" ); + tab =open_setmntent_r (_PATH_MNTTAB);if (!tab) {char *estr =strerror_r (errno, buf,PATH_MAX -1 );logerr ("setmntent: %s" , estr);
@@ -668,7 +668,7 @@ struct mnt_list *tree_make_mnt_tree(const char *table, const char *path)size_t plen;int eq; - tab =setmntent (table,"r" ); + tab =open_setmntent_r (table);if (!tab) {char *estr =strerror_r (errno, buf,PATH_MAX -1 );logerr ("setmntent: %s" , estr);
Ian Kent
maintainerPATCH 2/13 autofs-5.0.4 - fix hosts map use after free
In reply to Ian KentFrom: Paul Wankadia <[email protected]>
This patch fixed use a map entry after it has been freed in the hosts map lookup module.
---
CHANGELOG | 1 + modules/lookup_hosts.c | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-)
CHANGELOG +1 -0
@@ -9,6 +9,7 @@ Valerie Aurora Henson). - clear the quoted flag after each character from program map input. - use CLOEXEC flag for setmntent also. +- fix hosts map use after free (Paul Wankadia). 4/11/2008 autofs-5.0.4 -----------------------
modules/lookup_hosts.c +5 -3
@@ -138,17 +138,19 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void */* Check if we recorded a mount fail for this key anywhere */ me =lookup_source_mapent (ap, name,LKP_DISTINCT );if (me) { +struct mapent_cache *fmc = me->mc; +if (me->status >=time (NULL )) { -cache_unlock (me->mc); +cache_unlock (fmc);return NSS_STATUS_NOTFOUND ; }if (!me->mapent) { -cache_delete (me->mc, name); +cache_delete (fmc, name); me =NULL ; } -cache_unlock (me->mc); +cache_unlock (fmc); }cache_readlock (mc);
Ian Kent
maintainerPATCH 3/13 autofs-5.0.4 - uris list locking fix
In reply to Ian KentThe ldap uris list doesn't need to change we just need to keep track of current server uri in the list and try to connect in a round robin order. Also it's possible multiple concurrent connection attempts may not be able to use the full list of servers (if one is present).
---
CHANGELOG | 1 + include/lookup_ldap.h | 3 +- modules/lookup_ldap.c | 68 ++++++++++++++++++++++--------------------------- 3 files changed, 33 insertions(+), 39 deletions(-)
CHANGELOG +1 -0
@@ -10,6 +10,7 @@ - clear the quoted flag after each character from program map input. - use CLOEXEC flag for setmntent also. - fix hosts map use after free (Paul Wankadia). +- fix uri list locking (again). 4/11/2008 autofs-5.0.4 -----------------------
include/lookup_ldap.h +2 -1
@@ -55,7 +55,8 @@ struct lookup_context {* given in configuration. */ pthread_mutex_t uris_mutex; -struct list_head *uri; +struct list_head *uris; +struct ldap_uri *uri;char *cur_host;struct ldap_searchdn *sdns;
modules/lookup_ldap.c +30 -38
166 lines not on this page · raw message
Ian Kent
maintainerPATCH 4/13 autofs-5.0.4 - renew sasl creds upon reconnect fail
In reply to Ian KentIf a server re-connect fails it could be due to the authentication credentail having timed out. So we need to dispose of this and retry the connection including refreshing re-authenticating.
---
CHANGELOG | 1 + modules/lookup_ldap.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 0 deletions(-)
CHANGELOG +1 -0
@@ -11,6 +11,7 @@ - use CLOEXEC flag for setmntent also. - fix hosts map use after free (Paul Wankadia). - fix uri list locking (again). +- check for stale SASL credentials upon connect fail. 4/11/2008 autofs-5.0.4 -----------------------
modules/lookup_ldap.c +17 -0
@@ -675,6 +675,13 @@ static LDAP *do_reconnect(unsigned logopt, struct lookup_context *ctxt)if (ctxt->server || !ctxt->uris) { ldap =do_connect (logopt, ctxt->server, ctxt); +#ifdef WITH_SASL +/* Dispose of the sasl authentication connection and try again. */ +if (!ldap) { +autofs_sasl_dispose (ctxt); + ldap =connect_to_server (logopt, ctxt->server, ctxt); + } +#endif return ldap; }
@@ -682,6 +689,16 @@ static LDAP *do_reconnect(unsigned logopt, struct lookup_context *ctxt) this = ctxt->uri;uris_mutex_unlock (ctxt); ldap =do_connect (logopt, this->uri, ctxt); +#ifdef WITH_SASL +/* +* Dispose of the sasl authentication connection and try the +* current server again before trying other servers in the list. +*/ +if (!ldap) { +autofs_sasl_dispose (ctxt); + ldap =connect_to_server (logopt, this->uri, ctxt); + } +#endif if (ldap)return ldap;
Ian Kent
maintainerPATCH 5/13 autofs-5.0.4 - library reload fix update
In reply to Ian KentWe still have a problem with libxml2 being unloaded before its thread specific data destructor is called. This is due to the main thread exiting (closing the handle we hold open to prevent this) before all the mount handling threads have actually completed. This patch makes the mount handling threads joinable (and joins with them as they exit) to ensure that the mount handling threads have completed before allowing the main thread to complete.
---
daemon/automount.c | 35 +++++++++++++++++++++++------------ daemon/direct.c | 7 ++++--- daemon/indirect.c | 7 ++++--- daemon/state.c | 7 ++++--- include/master.h | 3 +++ lib/master.c | 38 ++++++++++++++++++++++++++++++++++---- modules/mount_autofs.c | 4 ++-- 7 files changed, 74 insertions(+), 27 deletions(-)
daemon/automount.c +23 -12
@@ -69,8 +69,9 @@ static size_t kpkt_len;/* Does kernel know about SOCK_CLOEXEC and friends */ static int cloexec_works =0 ; -/* Attribute to create detached thread */ -pthread_attr_t thread_attr; +/* Attributes for creating detached and joinable threads */ +pthread_attr_t th_attr; +pthread_attr_t th_attr_detached;struct master_readmap_cond mrc = {PTHREAD_MUTEX_INITIALIZER ,PTHREAD_COND_INITIALIZER ,0 ,NULL ,0 ,0 ,0 ,0 };
@@ -1192,7 +1193,7 @@ static pthread_t do_signals(struct master *master, int sig)if (status)fatal (status); - status =pthread_create (&thid, &thread_attr, do_notify_state, &r_sig); + status =pthread_create (&thid, &th_attr_detached, do_notify_state, &r_sig);if (status) {error (master->logopt,"mount state notify thread create failed" );
@@ -1281,7 +1282,7 @@ static int do_hup_signal(struct master *master, time_t age) master->reading =1 ; - status =pthread_create (&thid, &thread_attr, do_read_master,NULL ); + status =pthread_create (&thid, &th_attr_detached, do_read_master,NULL );if (status) {error (logopt,"master read map thread create failed" );
@@ -1327,7 +1328,7 @@ static void *statemachine(void *arg)case SIGTERM :case SIGINT :case SIGUSR2 : -if (master_list_empty (master_list)) +if (master_done (master_list))return NULL ;case SIGUSR1 :do_signals (master_list, sig);
@@ -1448,8 +1449,6 @@ static void handle_mounts_cleanup(void *arg)master_mutex_unlock ();destroy_logpri_fifo (ap); -master_free_mapent_sources (ap->entry,1 ); -master_free_mapent (ap->entry);if (clean) {if (rmdir (path) ==-1 ) {
@@ -1461,8 +1460,12 @@ static void handle_mounts_cleanup(void *arg)info (logopt,"shut down path %s" , path); -/* If we are the last tell the state machine to shutdown */ -if (!submount &&master_list_empty (master_list)) +/* +* If we are not a submount send a signal to the signal handler +* so it can join with any completed handle_mounts() threads and +* perform final cleanup. +*/ +if (!submount)pthread_kill (state_mach_thid,SIGTERM );return ;
@@ -1980,7 +1983,15 @@ int main(int argc, char *argv[])exit (1 ); } -if (pthread_attr_init (&thread_attr)) { +if (pthread_attr_init (&th_attr)) { +logerr ("%s: failed to init thread attribute struct!" , + program); +close (start_pipefd[1 ]); +release_flag_file (); +exit (1 ); + } + +if (pthread_attr_init (&th_attr_detached)) {logerr ("%s: failed to init thread attribute struct!" , program);close (start_pipefd[1 ]);
@@ -1989,7 +2000,7 @@ int main(int argc, char *argv[]) }if (pthread_attr_setdetachstate ( - &thread_attr,PTHREAD_CREATE_DETACHED )) { + &th_attr_detached,PTHREAD_CREATE_DETACHED )) {logerr ("%s: failed to set detached thread attribute!" , program);close (start_pipefd[1 ]);
@@ -1999,7 +2010,7 @@ int main(int argc, char *argv[])#ifdef _POSIX_THREAD_ATTR_STACKSIZEif (pthread_attr_setstacksize ( - &thread_attr,PTHREAD_STACK_MIN *64 )) { + &th_attr_detached,PTHREAD_STACK_MIN *64 )) {logerr ("%s: failed to set stack size thread attribute!" , program);close (start_pipefd[1 ]);
daemon/direct.c +4 -3
@@ -37,7 +37,8 @@#include "automount.h" -extern pthread_attr_t thread_attr; +/* Attribute to create detached thread */ +extern pthread_attr_t th_attr_detached;struct mnt_params {char *options;
@@ -1142,7 +1143,7 @@ int handle_packet_expire_direct(struct autofs_point *ap, autofs_packet_expire_didebug (ap->logopt,"token %ld, name %s" , (unsigned long ) pkt->wait_queue_token, mt->name); - status =pthread_create (&thid, &thread_attr, do_expire_direct, mt); + status =pthread_create (&thid, &th_attr_detached, do_expire_direct, mt);if (status) {error (ap->logopt,"expire thread create failed" ); ops->send_fail(ap->logopt,
@@ -1451,7 +1452,7 @@ int handle_packet_missing_direct(struct autofs_point *ap, autofs_packet_missing_ mt->gid = pkt->gid; mt->wait_queue_token = pkt->wait_queue_token; - status =pthread_create (&thid, &thread_attr, do_mount_direct, mt); + status =pthread_create (&thid, &th_attr_detached, do_mount_direct, mt);if (status) {error (ap->logopt,"missing mount thread create failed" ); ops->send_fail(ap->logopt,
daemon/indirect.c +4 -3
@@ -36,7 +36,8 @@#include "automount.h" -extern pthread_attr_t thread_attr; +/* Attribute to create detached thread */ +extern pthread_attr_t th_attr_detached;static pthread_mutex_t ea_mutex =PTHREAD_MUTEX_INITIALIZER ;
@@ -647,7 +648,7 @@ int handle_packet_expire_indirect(struct autofs_point *ap, autofs_packet_expire_ mt->len = pkt->len; mt->wait_queue_token = pkt->wait_queue_token; - status =pthread_create (&thid, &thread_attr, do_expire_indirect, mt); + status =pthread_create (&thid, &th_attr_detached, do_expire_indirect, mt);if (status) {error (ap->logopt,"expire thread create failed" ); ops->send_fail(ap->logopt,
@@ -835,7 +836,7 @@ int handle_packet_missing_indirect(struct autofs_point *ap, autofs_packet_missin mt->gid = pkt->gid; mt->wait_queue_token = pkt->wait_queue_token; - status =pthread_create (&thid, &thread_attr, do_mount_indirect, mt); + status =pthread_create (&thid, &th_attr_detached, do_mount_indirect, mt);if (status) {error (ap->logopt,"expire thread create failed" ); ops->send_fail(ap->logopt,
daemon/state.c +4 -3
@@ -16,7 +16,8 @@#include "automount.h" -extern pthread_attr_t thread_attr; +/* Attribute to create detached thread */ +extern pthread_attr_t th_attr_detached;struct state_queue {pthread_t thid;
@@ -292,7 +293,7 @@ static enum expire expire_proc(struct autofs_point *ap, int now)else expire = expire_proc_direct; - status =pthread_create (&thid, &thread_attr, expire, ea); + status =pthread_create (&thid, &th_attr_detached, expire, ea);if (status) {error (ap->logopt,"expire thread create for %s failed" , ap->path);
@@ -519,7 +520,7 @@ static unsigned int st_readmap(struct autofs_point *ap) ra->ap = ap; ra->now = now; - status =pthread_create (&thid, &thread_attr, do_readmap, ra); + status =pthread_create (&thid, &th_attr_detached, do_readmap, ra);if (status) {error (ap->logopt,"read map thread create failed" );st_readmap_cleanup (ra);
include/master.h +3 -0
@@ -48,6 +48,7 @@ struct master_mapent {struct map_source *maps;struct autofs_point *ap;struct list_head list; +struct list_head join; };struct master {
@@ -61,6 +62,7 @@ struct master {unsigned int logopt;struct mapent_cache *nc;struct list_head mounts; +struct list_head completed; };/* From the yacc master map parser */
@@ -109,6 +111,7 @@ void master_notify_state_change(struct master *, int);int master_mount_mounts (struct master *,time_t ,int );extern inline unsigned int master_get_logopt (void );int master_list_empty (struct master *); +int master_done (struct master *);int master_kill (struct master *);#endif
lib/master.c +34 -4
@@ -32,8 +32,8 @@ struct master *master_list = NULL;extern long global_negative_timeout; -/* Attribute to create detached thread */ -extern pthread_attr_t thread_attr; +/* Attribute to create a joinable thread */ +extern pthread_attr_t th_attr;extern struct startup_cond suc;
@@ -704,11 +704,16 @@ void master_add_mapent(struct master *master, struct master_mapent *entry)void master_remove_mapent (struct master_mapent *entry) { +struct master *master = entry->master; +if (entry->ap->submount)return ; -if (!list_empty (&entry->list)) +if (!list_empty (&entry->list)) {list_del_init (&entry->list); +list_add (&entry->join, &master->completed); + } +return ; }
@@ -786,6 +791,7 @@ struct master *master_new(const char *name, unsigned int timeout, unsigned int g master->logopt = master->default_logging;INIT_LIST_HEAD (&master->mounts); +INIT_LIST_HEAD (&master->completed);return master; }
@@ -993,7 +999,7 @@ static int master_do_mount(struct master_mapent *entry)debug (ap->logopt,"mounting %s" , entry->path); - status =pthread_create (&thid, &thread_attr, handle_mounts, &suc); + status =pthread_create (&thid, &th_attr, handle_mounts, &suc);if (status) { crit(ap->logopt, "failed to create mount handler thread for %s",
@@ -1170,6 +1176,30 @@ int master_list_empty(struct master *master)return res; } +int master_done (struct master *master) +{ +struct list_head *head, *p; +struct master_mapent *entry; +int res =0 ; + +master_mutex_lock (); + head = &master->completed; + p = head->next; +while (p != head) { + entry = list_entry(p, struct master_mapent, join); + p = p->next; +list_del (&entry->join); +pthread_join (entry->thid,NULL ); +master_free_mapent_sources (entry,1 ); +master_free_mapent (entry); + } +if (list_empty (&master->mounts)) + res =1 ; +master_mutex_unlock (); + +return res; +} +inline unsigned int master_get_logopt (void ) {return master_list ? master_list->logopt :LOGOPT_NONE ;
modules/mount_autofs.c +2 -2
@@ -30,7 +30,7 @@#define MODPREFIX "mount(autofs): "/* Attribute to create detached thread */ -extern pthread_attr_t thread_attr; +extern pthread_attr_t th_attr_detached;extern struct startup_cond suc;int mount_version =AUTOFS_MOUNT_VERSION ;/* Required by protocol */
@@ -235,7 +235,7 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, suc.done =0 ; suc.status =0 ; -if (pthread_create (&thid, &thread_attr, handle_mounts, &suc)) { +if (pthread_create (&thid, &th_attr_detached, handle_mounts, &suc)) { crit(ap->logopt, MODPREFIX "failed to create mount handler thread for %s",
Ian Kent
maintainerPATCH 6/13 autofs-5.0.4 - force unlink umount at startup
In reply to Ian KentVersion 5.0.3 autofs would unlink existing mounts at startup. This functioned OK most of the time but caused processes whose working directory was within unlinked automounted directories to not get a correct pwd reported by the system.
There can be situations where the unlink umounting is desirable, such as when the daemon is forceably killed and we want to get rid of any existing mounts at startup. This change provides a way to force this old behavior by passing the "--force" option to the daemon. This can also be done by using the "forcestart" and "forcerestart" actions to the init script.
Note that the old behavior will always be used if the kernel does not include the iotcl re-implementation which provides the ability to re-connect to existing mounts.
---
CHANGELOG | 2 ++ daemon/automount.c | 14 +++++++++++++- daemon/direct.c | 2 +- daemon/indirect.c | 2 +- include/automount.h | 3 +++ man/automount.8 | 13 +++++++++++++ redhat/autofs.init.in | 10 +++++++++- samples/rc.autofs.in | 10 +++++++++- 8 files changed, 51 insertions(+), 5 deletions(-)
CHANGELOG +2 -0
@@ -12,6 +12,8 @@ - fix hosts map use after free (Paul Wankadia). - fix uri list locking (again). - check for stale SASL credentials upon connect fail. +- add "forcestart" and "forcerestart" init script options to allow + use of 5.0.3 strartup behavior if required. 4/11/2008 autofs-5.0.4 -----------------------
daemon/automount.c +13 -1
@@ -57,6 +57,7 @@ static char *pid_file = NULL; /* File in which to keep pid */unsigned int global_random_selection;/* use random policy when selecting * which multi-mount host to mount */ long global_negative_timeout =-1 ; +int do_force_unlink =0 ;/* Forceably unlink mount tree at startup */ static int start_pipefd[2 ];static int st_stat =0 ;
@@ -1798,6 +1799,7 @@ int main(int argc, char *argv[]) {"version", 0, 0, 'V'}, {"set-log-priority", 1, 0, 'l'}, {"dont-check-daemon", 0, 0, 'C'}, + {"force", 0, 0, 'F'}, {0, 0, 0, 0} };
@@ -1819,7 +1821,7 @@ int main(int argc, char *argv[]) daemon_check =1 ; opterr =0 ; -while ((opt =getopt_long (argc, argv,"+hp:t:vdD:fVrO:l:n:C" , long_options,NULL )) !=EOF ) { +while ((opt =getopt_long (argc, argv,"+hp:t:vdD:fVrO:l:n:CF" , long_options,NULL )) !=EOF ) {switch (opt) {case 'h' :usage ();
@@ -1892,6 +1894,10 @@ int main(int argc, char *argv[]) daemon_check =0 ;break ; +case 'F' : + do_force_unlink =1 ; +break ; +case '?' :case ':' :printf ("%s: Ambiguous or unknown options\n" , program);
@@ -2066,6 +2072,12 @@ int main(int argc, char *argv[])exit (3 ); } +/* +* Mmm ... reset force unlink umount so we don't also do this +* in future when we receive a HUP signal. +*/ + do_force_unlink =0 ; + res =write (start_pipefd[1 ], pst_stat,sizeof (*pst_stat));close (start_pipefd[1 ]);
daemon/direct.c +1 -1
@@ -335,7 +335,7 @@ int do_mount_autofs_direct(struct autofs_point *ap, struct mnt_list *mnts, struc/* Calculate the timeouts */ ap->exp_runfreq = (timeout +CHECK_RATIO -1 ) /CHECK_RATIO ; -if (ops->version) { +if (ops->version && !do_force_unlink) { ap->flags |=MOUNT_FLAG_REMOUNT ; ret =try_remount (ap, me, t_direct); ap->flags &= ~MOUNT_FLAG_REMOUNT ;
daemon/indirect.c +1 -1
@@ -97,7 +97,7 @@ static int do_mount_autofs_indirect(struct autofs_point *ap, const char *root) ap->exp_runfreq = (timeout +CHECK_RATIO -1 ) /CHECK_RATIO ; -if (ops->version) { +if (ops->version && !do_force_unlink) { ap->flags |=MOUNT_FLAG_REMOUNT ; ret =try_remount (ap,NULL , t_indirect); ap->flags &= ~MOUNT_FLAG_REMOUNT ;
include/automount.h +3 -0
@@ -428,6 +428,9 @@ struct autofs_point {struct list_head submounts;/* List of child submounts */ }; +/* Foreably unlink existing mounts at startup. */ +extern int do_force_unlink; +/* Standard functions used by daemon or modules */ #define MOUNT_OFFSET_OK 0
man/automount.8 +13 -0
@@ -84,6 +84,11 @@ path name as specified in the master map. .TP .I "\-C, \-\-dont-check-daemon" Don't check if the daemon is currently running (see NOTES). +.TP +.I "\-F, \-\-force" +Force an unlink umount of existing mounts under autofs managed mount points +during startup. This can cause problems for processes with working directories +within these mounts (see NOTES). .SH ARGUMENTS \fBautomount\fP takes one optional argument, the name of the master map to use.
@@ -132,6 +137,14 @@ for certain types of automount maps. The mounts of the seperate daemons might interfere with one another. The implications of running multiple daemon instances needs to be checked and tested before we can say this is supported. +.P +If the option to force an unlink of mounts at startup is used then processes +whose working directory is within unlinked automounted directories will not +get the correct pwd from the system. This is because, after the mount is +unlinked from the mount tree, anything that needs to walk back up the mount +tree to construct a path, such as getcwd(2) and the proc filesystem +/proc/<pid>/cwd, cannot work because the point from which the path is +constructed has been detached from the mount tree. .SH "SEE ALSO" .BR autofs (5), .BR autofs (8),
redhat/autofs.init.in +9 -1
@@ -137,6 +137,10 @@ case "$1" in start) start ;; + forcestart) + OPTIONS="$OPTIONS --force" + start + ;; stop) stop ;;
@@ -146,6 +150,10 @@ case "$1" in restart) restart ;; + forcerestart) + OPTIONS="$OPTIONS --force" + restart + ;; reload) reload ;;
@@ -155,7 +163,7 @@ case "$1" in fi ;; *) - echo $"Usage: $0 {start|stop|status|restart|reload|condrestart}" + echo $"Usage: $0 {start|forcestart|stop|status|restart|orcerestart|reload|condrestart}" exit 1; ;; esac
samples/rc.autofs.in +9 -1
@@ -117,17 +117,25 @@ case "$1" in start) start ;; + forcestart) + OPTIONS="$OPTIONS --force" + start + ;; stop) stop ;; restart) restart ;; + forcerestart) + OPTIONS="$OPTIONS --force" + restart + ;; reload) reload ;; *) - echo $"Usage: $0 {start|stop|restart|reload}" + echo $"Usage: $0 {start|forcestart|stop|restart|forcerestart|reload}" exit 1; ;; esac
Ian Kent
maintainerPATCH 7/13 autofs-5.0.4 - always read file maps
In reply to Ian Kentautofs tries to not load an entire map into the internal cache unless it has to. For maps that do get loaded into the cache it relies on checks to work out if a map is up to date in order to trigger a map read. This is fine for maps that can do direct key lookups but file maps need to do a linear search through the file when locating an entry for a key. For large maps this can be a huge overhead. This patch make autofs always load file based maps at start and makes use of the map file mtime to discover if the cache needs to be refreshed.
---
CHANGELOG | 1 + daemon/lookup.c | 9 +++++-- modules/lookup_file.c | 65 ++++++++++++++++--------------------------------- 3 files changed, 28 insertions(+), 47 deletions(-)
CHANGELOG +1 -0
@@ -14,6 +14,7 @@ - check for stale SASL credentials upon connect fail. - add "forcestart" and "forcerestart" init script options to allow use of 5.0.3 strartup behavior if required. +- always read entire file map into cache to speed lookups. 4/11/2008 autofs-5.0.4 -----------------------
daemon/lookup.c +6 -3
@@ -283,10 +283,13 @@ static int do_read_map(struct autofs_point *ap, struct map_source *map, time_t a* for the fail cases to function correctly and to cache the * lookup handle. * -* We always need to whole map for direct mounts in order to -* mount the triggers. +* We always need to read the whole map for direct mounts in +* order to mount the triggers. We also want to read the whole +* map if it's a file map to avoid potentially lengthy linear +* file scanning. */ -if (!(ap->flags &MOUNT_FLAG_GHOST ) && ap->type !=LKP_DIRECT ) +if (strcmp (map->type,"file" ) && + !(ap->flags &MOUNT_FLAG_GHOST ) && ap->type !=LKP_DIRECT )return NSS_STATUS_SUCCESS ;if (!map->stale)
modules/lookup_file.c +21 -44
155 lines not on this page · raw message
Ian Kent
maintainerPATCH 8/13 autofs-5.0.4 - code analysis corrections
In reply to Ian KentSeveral mistakes have been reported:
- a malloc(3) allocation return was not being checked in make_fullpath().
- a double free and a use after free was identified in lookup_prune_cache().
- off-by-one buffer overflow in lib/macros.c:macro_parse_globalvar().
- several potential buffer overflows in modules/parse_hesiod.c.
- double free in daemon/indirect.c:do_mount_autofs_indirect().
- bogus struct name used for sizeof in lib/cache.c:cache_init() and lib/cache.c:cache_init_null_cache().
- in daemon/direct.c:handle_packet_expire_direct master_unlock_mutex() not needed and mutexes not unlocked for file descriptor fail case.
- in modules/lookup_multi.c:lookup_init() struct module_info array not checked before free for allocation failure case.
- in modules/lookup_program.c:lookup_mount() mapent not freed on cache update failure.
- in modules/mount_nfs.c allocation of mount location not checked.
- in modules/parse_sun.c:parse_mapent() mount location not freed on syntax error.
- in modules/parse_sun.c:parse_mount() mount location not freed on syntax error.
- in modules/parse_sun.c:parse_init() a malloc is not checked and the handling of the fail case is poor.
- in lib/mounts.c:tree_make_mnt_tree() variable ent is not freed on ent->path alloc fail.
- in modules/replicated.c:add_host() NULL pointer dereference.
- add missing pthread_attr_destroy() in lib/alarm.c:alarm_start_handler().
- add missing pthread_attr_destroy() in daemon/state.c:st_start_handler().
- add missing fclose() in lib/defaults.c:*defaults_get_searchdns().
- add missing close()es in modules/mount_changer.c:swapCD().
---
daemon/direct.c | 6 ++- daemon/indirect.c | 3 +- daemon/lookup.c | 20 +++++------- daemon/state.c | 6 ++- lib/alarm.c | 6 ++- lib/cache.c | 4 +- lib/defaults.c | 1 + lib/macros.c | 2 + lib/mounts.c | 5 ++- modules/lookup_multi.c | 15 +++++---- modules/lookup_program.c | 4 ++ modules/mount_changer.c | 2 + modules/mount_nfs.c | 5 +++ modules/parse_hesiod.c | 79 ++++++++++++++++++++++++++++++++++++++++------ modules/parse_sun.c | 18 ++++++---- modules/replicated.c | 2 + 16 files changed, 123 insertions(+), 55 deletions(-)
daemon/direct.c +3 -3
@@ -1088,7 +1088,6 @@ int handle_packet_expire_direct(struct autofs_point *ap, autofs_packet_expire_dicrit (ap->logopt,"can't find map entry for (%lu,%lu)" , (unsigned long ) pkt->dev, (unsigned long ) pkt->ino);master_source_unlock (ap->entry); -master_mutex_unlock ();pthread_setcancelstate (state,NULL );return 1 ; }
@@ -1098,8 +1097,9 @@ int handle_packet_expire_direct(struct autofs_point *ap, autofs_packet_expire_diint ioctlfd; ops->open (ap->logopt, &ioctlfd, me->dev, me->key);if (ioctlfd ==-1 ) { -crit (ap->logopt,"can't open ioctlfd for %s" , - me->key); +crit (ap->logopt,"can't open ioctlfd for %s" , me->key); +cache_unlock (mc); +master_source_unlock (ap->entry);pthread_setcancelstate (state,NULL );return 1 ; }
daemon/indirect.c +1 -2
@@ -159,6 +159,7 @@ static int do_mount_autofs_indirect(struct autofs_point *ap, const char *root) }free (options); + options =NULL ; ret =stat (root, &st);if (ret ==-1 ) {
@@ -167,8 +168,6 @@ static int do_mount_autofs_indirect(struct autofs_point *ap, const char *root) goto out_umount; } - options =NULL ; -if (ops->open (ap->logopt, &ap->ioctlfd, st.st_dev, root)) {crit (ap->logopt,"failed to create ioctl fd for autofs path %s" , ap->path);
daemon/lookup.c +8 -12
@@ -1001,12 +1001,16 @@ static char *make_fullpath(const char *root, const char *key)if (l >KEY_MAX_LEN )return NULL ; path =malloc (l); +if (!path) +return NULL ;strcpy (path, key); }else { l =strlen (key) +1 +strlen (root) +1 ;if (l >KEY_MAX_LEN )return NULL ; path =malloc (l); +if (!path) +return NULL ;sprintf (path,"%s/%s" , root, key); }return path;
@@ -1076,10 +1080,6 @@ int lookup_prune_cache(struct autofs_point *ap, time_t age) this =cache_lookup_distinct (mc, key);if (!this) {cache_unlock (mc); -free (key); -if (next_key) -free (next_key); -free (path); goto next; }
@@ -1097,18 +1097,14 @@ int lookup_prune_cache(struct autofs_point *ap, time_t age) }cache_unlock (mc); -if (!next_key) { -free (key); -free (path); -cache_readlock (mc); -continue ; - } next:cache_readlock (mc); - me =cache_lookup_distinct (mc, next_key); +if (next_key) { + me =cache_lookup_distinct (mc, next_key); +free (next_key); + }free (key);free (path); -free (next_key); }pthread_cleanup_pop (1 ); map->stale =0 ;
daemon/state.c +3 -3
@@ -1140,9 +1140,9 @@ int st_start_handler(void) } status =pthread_create (&thid, pattrs, st_queue_handler,NULL ); -if (status) -return 0 ; -return 1 ; +pthread_attr_destroy (pattrs); + +return !status; }
lib/alarm.c +3 -3
@@ -238,9 +238,9 @@ int alarm_start_handler(void) } status =pthread_create (&thid, pattrs, alarm_handler,NULL ); -if (status) -return 0 ; -return 1 ; +pthread_attr_destroy (pattrs); + +return !status; }
lib/cache.c +2 -2
@@ -192,7 +192,7 @@ struct mapent_cache *cache_init(struct autofs_point *ap, struct map_source *map) mc->size =defaults_get_map_hash_table_size (); - mc->hash =malloc (mc->size *sizeof (struct entry *)); + mc->hash =malloc (mc->size *sizeof (struct mapent *));if (!mc->hash) {free (mc);return NULL ;
@@ -243,7 +243,7 @@ struct mapent_cache *cache_init_null_cache(struct master *master) mc->size =NULL_MAP_HASHSIZE ; - mc->hash =malloc (mc->size *sizeof (struct entry *)); + mc->hash =malloc (mc->size *sizeof (struct mapent *));if (!mc->hash) {free (mc);return NULL ;
lib/defaults.c +1 -0
@@ -565,6 +565,7 @@ struct ldap_searchdn *defaults_get_searchdns(void)if (!new) {defaults_free_searchdns (sdn); +fclose (f);return NULL ; }
lib/macros.c +1 -1
@@ -165,7 +165,7 @@ int macro_parse_globalvar(const char *define)char buf[MAX_MACRO_STRING ];char *pbuf, *value; -if (strlen (define) >MAX_MACRO_STRING ) +if (strlen (define) >=MAX_MACRO_STRING )return 0 ;strcpy (buf, define);
lib/mounts.c +3 -2
@@ -257,10 +257,10 @@ struct mnt_list *get_mnt_list(const char *table, const char *path, int include)if (mptr == list) list = ent; +else + last->next = ent; ent->next = mptr; -if (last) - last->next = ent; ent->path =malloc (len +1 );if (!ent->path) {
@@ -705,6 +705,7 @@ struct mnt_list *tree_make_mnt_tree(const char *table, const char *path) ent->path =malloc (len +1 );if (!ent->path) {endmntent (tab); +free (ent);tree_free_mnt_tree (tree);return NULL ; }
modules/lookup_multi.c +8 -7
@@ -212,14 +212,15 @@ nomem:logerr (MODPREFIX "error: %s" , estr); error_out:if (ctxt) { -for (i =0 ; i < ctxt->n; i++) { -if (ctxt->m[i].mod) -close_lookup (ctxt->m[i].mod); -if (ctxt->m[i].argv) -free_argv (ctxt->m[i].argc, ctxt->m[i].argv); - } -if (ctxt->m) +if (ctxt->m) { +for (i =0 ; i < ctxt->n; i++) { +if (ctxt->m[i].mod) +close_lookup (ctxt->m[i].mod); +if (ctxt->m[i].argv) +free_argv (ctxt->m[i].argc, ctxt->m[i].argv); + }free (ctxt->m); + }if (ctxt->argl)free (ctxt->argl);free (ctxt);
modules/lookup_program.c +3 -1
@@ -396,8 +396,10 @@ next:cache_writelock (mc); ret =cache_update (mc, source, name, mapent,time (NULL ));cache_unlock (mc); -if (ret ==CHE_FAIL ) +if (ret ==CHE_FAIL ) { +free (mapent);return NSS_STATUS_UNAVAIL ; + }debug (ap->logopt,MODPREFIX "%s -> %s" , name, mapent);
modules/mount_changer.c +2 -0
@@ -162,6 +162,7 @@ int swapCD(const char *device, const char *slotName)logerr (MODPREFIX "Device %s is not an ATAPI compliant CD changer." , device); +close (fd);return 1 ; }
@@ -169,6 +170,7 @@ int swapCD(const char *device, const char *slotName) slot =ioctl (fd,CDROM_SELECT_DISC , slot);if (slot <0 ) {logerr (MODPREFIX "CDROM_SELECT_DISC failed" ); +close (fd);return 1 ; }
modules/mount_nfs.c +5 -0
@@ -221,6 +221,11 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int/* Not a local host - do an NFS mount */ loc =malloc (strlen (this->name) +1 +strlen (this->path) +1 ); +if (!loc) { +char *estr =strerror_r (errno, buf,MAX_ERR_BUF ); +error (ap->logopt,"malloc: %s" , estr); +return 1 ; + }strcpy (loc, this->name);strcat (loc,":" );strcat (loc, this->path);
modules/parse_hesiod.c +68 -11
146 lines not on this page · raw message
modules/parse_sun.c +11 -7
@@ -379,15 +379,17 @@ int parse_init(int argc, const char *const *argv, void **context)if (ctxt->optstr) { noptstr = (char *)realloc (ctxt->optstr, optlen + len +2 ); -if (!noptstr) -break ; - noptstr[optlen] =',' ; -strcpy (noptstr + optlen +1 , argv[i] + offset); - optlen += len +1 ; +if (noptstr) { + noptstr[optlen] =',' ; +strcpy (noptstr + optlen +1 , argv[i] + offset); + optlen += len +1 ; + } }else { noptstr = (char *)malloc (len +1 ); -strcpy (noptstr, argv[i] + offset); - optlen = len; +if (noptstr) { +strcpy (noptstr, argv[i] + offset); + optlen = len; + } }if (!noptstr) {char *estr =strerror_r (errno, buf,MAX_ERR_BUF );
@@ -895,6 +897,7 @@ static int parse_mapent(const char *ent, char *g_options, char **options, char *if (*p =='/' ) {warn (logopt,MODPREFIX "error location begins with \"/\"" );free (myoptions); +free (loc);return 0 ; }
@@ -1636,6 +1639,7 @@ int parse_mount(struct autofs_point *ap, const char *name,/* Location can't begin with a '/' */ if (*p =='/' ) {free (options); +free (loc);warn (ap->logopt,MODPREFIX "error location begins with \"/\"" );return 1 ;
modules/replicated.c +1 -1
@@ -304,7 +304,7 @@ static int add_host(struct host **list, struct host *host) {struct host *this, *last; -if (!list) { +if (!*list) { *list = host;return 1 ; }
Ian Kent
maintainerPATCH 9/13 autofs-5.0.4 - make MAX_ERR_BUF and PARSE_MAX_BUF use easier to audit
In reply to Ian KentFrom: Valerie Aurora Henson <[email protected]>
Non-critical changes to make auditing buffer lengths easier.
* Some buffers were the wrong (too big) size, some were used twice for different purposes.
* Use sizeof(buf) instead of repeating the *MAX* define in functions that need to know the size of a statically allocated buffer.
* Fix a compiler warning about discarding the const on a string.
---
CHANGELOG | 1 + modules/lookup_ldap.c | 51 ++++++++++++++++++++++--------------------------- 2 files changed, 24 insertions(+), 28 deletions(-)
CHANGELOG +1 -0
@@ -15,6 +15,7 @@ - add "forcestart" and "forcerestart" init script options to allow use of 5.0.3 strartup behavior if required. - always read entire file map into cache to speed lookups. +- make MAX_ERR_BUF and PARSE_MAX_BUF use easier to audit. 4/11/2008 autofs-5.0.4 -----------------------
modules/lookup_ldap.c +23 -28
169 lines not on this page · raw message
Ian Kent
maintainerPATCH 10/13 autofs-5.0.4 - easy alloca replacements
In reply to Ian KentFrom: Valerie Aurora Henson <[email protected]>
alloca() is compiler-dependent, non-standard, and has undefined behavior when it fails (IOW, the program crashes). Replace with normal C stack variables where possible and malloc() where not.
---
daemon/automount.c | 29 ++++++-------- daemon/direct.c | 12 ++---- daemon/flag.c | 13 +++--- daemon/indirect.c | 12 ++---- daemon/module.c | 45 +++++++--------------- lib/cache.c | 31 +++++---------- lib/cat_path.c | 1 modules/lookup_file.c | 82 +++++++++++++---------------------------- modules/lookup_ldap.c | 93 +++++++++++++++++++++++++++++----------------- modules/lookup_nisplus.c | 71 ++++++++++++++++++++--------------- modules/mount_autofs.c | 1 modules/mount_bind.c | 7 +-- modules/mount_changer.c | 5 -- modules/mount_ext2.c | 5 -- modules/mount_generic.c | 5 -- 15 files changed, 184 insertions(+), 228 deletions(-)
daemon/automount.c +13 -16
@@ -127,8 +127,8 @@ static int do_mkdir(const char *parent, const char *path, mode_t mode)int mkdir_path (const char *path,mode_t mode) { -char *buf =alloca (strlen (path) +1 ); -char *parent =alloca (strlen (path) +1 ); +char buf[PATH_MAX ]; +char parent[PATH_MAX ];const char *cp = path, *lcp = path;char *bp = buf, *pp = parent;
@@ -163,7 +163,7 @@ int mkdir_path(const char *path, mode_t mode)int rmdir_path (struct autofs_point *ap,const char *path,dev_t dev) {int len =strlen (path); -char *buf =alloca (len +1 ); +char buf[PATH_MAX ];char *cp;int first =1 ;struct stat st;
@@ -468,20 +468,17 @@ static int umount_subtree_mounts(struct autofs_point *ap, const char *path, unsipthread_cleanup_push (cache_lock_cleanup, mc);if (me->multi) { -char *root, *base; -size_t ap_len; +char root[PATH_MAX ]; +char *base;int cur_state; - ap_len =strlen (ap->path); - -if (!strchr (me->multi->key,'/' )) { +if (!strchr (me->multi->key,'/' ))/* Indirect multi-mount root */ - root =alloca (ap_len +strlen (me->multi->key) +2 ); -strcpy (root, ap->path); -strcat (root,"/" ); -strcat (root, me->multi->key); - }else - root = me->multi->key; +/* sprintf okay - if it's mounted, it's +* PATH_MAX or less bytes */ +sprintf (root,"%s/%s" , ap->path, me->multi->key); +else +strcpy (root, me->multi->key);if (is_mm_root) base =NULL ;
@@ -929,14 +926,14 @@ static int get_pkt(struct autofs_point *ap, union autofs_v5_packet_union *pkt)int do_expire (struct autofs_point *ap,const char *name,int namelen) { -char buf[PATH_MAX +1 ]; +char buf[PATH_MAX ];int len, ret;if (*name !='/' ) { len =ncat_path (buf,sizeof (buf), ap->path, name, namelen); }else { len =snprintf (buf,PATH_MAX ,"%s" , name); -if (len >PATH_MAX ) +if (len >=PATH_MAX ) len =0 ; }
daemon/direct.c +4 -8
@@ -637,7 +637,9 @@ int mount_autofs_offset(struct autofs_point *ap, struct mapent *me, const char *time_t timeout = ap->exp_timeout;struct stat st;int ioctlfd, status, ret; -const char *type, *map_name =NULL ; +const char *hosts_map_name ="-hosts" ; +const char *map_name = hosts_map_name; +const char *type;char mountpoint[PATH_MAX ];if (ops->version && ap->flags &MOUNT_FLAG_REMOUNT ) {
@@ -740,13 +742,7 @@ int mount_autofs_offset(struct autofs_point *ap, struct mapent *me, const char * mp->options, mountpoint); type = ap->entry->maps->type; -if (type && !strcmp (ap->entry->maps->type,"hosts" )) { -char *tmp =alloca (7 ); -if (tmp) { -strcpy (tmp,"-hosts" ); - map_name = (const char *) tmp; - } - }else +if (!type ||strcmp (ap->entry->maps->type,"hosts" )) map_name = me->mc->map->argv[0 ]; ret =mount (map_name, mountpoint,"autofs" ,MS_MGC_VAL , mp->options);
daemon/flag.c +7 -6
@@ -23,10 +23,10 @@#include <sys/stat.h> #include <time.h> #include <string.h> -#include <alloca.h> #include <stdio.h> #include <signal.h> #include <errno.h> +#include <limits.h> #include "automount.h"
@@ -113,12 +113,13 @@ void release_flag_file(void)/* * Try to create flag file */ int aquire_flag_file (void ) { -char *linkf; -int len; +char linkf[PATH_MAX ]; +size_t len; - len =strlen (FLAG_FILE ) +MAX_PIDSIZE ; - linkf =alloca (len +1 ); -snprintf (linkf, len,"%s.%d" ,FLAG_FILE ,getpid ()); + len =snprintf (linkf,sizeof (linkf),"%s.%d" ,FLAG_FILE ,getpid ()); +if (len >=sizeof (linkf)) +/* Didn't acquire it */ +return 0 ;/* * Repeat until it was us who made the link or we find the
daemon/indirect.c +4 -8
@@ -90,7 +90,9 @@ static int do_mount_autofs_indirect(struct autofs_point *ap, const char *root)struct ioctl_ops *ops =get_ioctl_ops ();time_t timeout = ap->exp_timeout;char *options =NULL ; -const char *type, *map_name =NULL ; +const char *hosts_map_name ="-hosts" ; +const char *map_name = hosts_map_name; +const char *type;struct stat st;struct mnt_list *mnts;int ret;
@@ -142,13 +144,7 @@ static int do_mount_autofs_indirect(struct autofs_point *ap, const char *root) } type = ap->entry->maps->type; -if (type && !strcmp (ap->entry->maps->type,"hosts" )) { -char *tmp =alloca (7 ); -if (tmp) { -strcpy (tmp,"-hosts" ); - map_name = (const char *) tmp; - } - }else +if (!type ||strcmp (ap->entry->maps->type,"hosts" )) map_name = ap->entry->maps->argv[0 ]; ret =mount (map_name, root,"autofs" ,MS_MGC_VAL , options);
daemon/module.c +15 -30
108 lines not on this page · raw message
lib/cache.c +11 -20
@@ -482,27 +482,23 @@ struct mapent *cache_lookup_offset(const char *prefix, const char *offset, int s {struct list_head *p;struct mapent *this; -int plen =strlen (prefix); -char *o_key; +/* Keys for direct maps may be as long as a path name */ +char o_key[PATH_MAX ]; +/* Avoid "//" at the beginning of paths */ +const char *path_prefix =strlen (prefix) >1 ? prefix :"" ; +size_t size;/* root offset duplicates "/" */ -if (plen >1 ) { - o_key =alloca (plen +strlen (offset) +1 ); -strcpy (o_key, prefix); -strcat (o_key, offset); - }else { - o_key =alloca (strlen (offset) +1 ); -strcpy (o_key, offset); - } + size =snprintf (o_key,sizeof (o_key),"%s%s" , path_prefix, offset); +if (size >=sizeof (o_key)) +return NULL ;list_for_each (p, head) { this = list_entry(p, struct mapent, multi_list);if (!strcmp (&this->key[start], o_key)) - goto done; +return this; } - this =NULL ; -done: -return this; +return NULL ; }/* cache must be read locked by caller */
@@ -759,13 +755,8 @@ int cache_delete(struct mapent_cache *mc, const char *key)struct mapent *me =NULL , *pred;u_int32_t hashval =hash (key, mc->size);int status, ret =CHE_OK ; -char *this; +char this[PATH_MAX ]; - this =alloca (strlen (key) +1 ); -if (!this) { - ret =CHE_FAIL ; - goto done; - }strcpy (this, key); me = mc->hash[hashval];
lib/cat_path.c +0 -1
@@ -12,7 +12,6 @@* * ----------------------------------------------------------------------- */ -#include <alloca.h> #include <string.h> #include <limits.h> #include <ctype.h>
modules/lookup_file.c +26 -56
127 lines not on this page · raw message
modules/lookup_ldap.c +58 -35
279 lines not on this page · raw message
modules/lookup_nisplus.c +41 -30
178 lines not on this page · raw message
modules/mount_autofs.c +0 -1
@@ -18,7 +18,6 @@#include <malloc.h> #include <string.h> #include <signal.h> -#include <alloca.h> #include <sys/param.h> #include <sys/types.h> #include <sys/stat.h>
modules/mount_bind.c +2 -5
@@ -69,7 +69,7 @@ out:int mount_mount (struct autofs_point *ap,const char *root,const char *name,int name_len,const char *what,const char *fstype,const char *options,void *context) { -char *fullpath; +char fullpath[PATH_MAX ];char buf[MAX_ERR_BUF ];int err;int i, len;
@@ -80,14 +80,11 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int/* Root offset of multi-mount */ len =strlen (root);if (root[len -1 ] =='/' ) { - fullpath =alloca (len); len =snprintf (fullpath, len,"%s" , root);/* Direct mount name is absolute path so don't use root */ }else if (*name =='/' ) { - fullpath =alloca (len +1 ); len =sprintf (fullpath,"%s" , root); }else { - fullpath =alloca (len + name_len +2 ); len =sprintf (fullpath,"%s/%s" , root, name); } fullpath[len] ='\0' ;
@@ -141,7 +138,7 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int } }else {char *cp; -char *basepath =alloca (strlen (fullpath) +1 ); +char basepath[PATH_MAX ];int status;struct stat st;
modules/mount_changer.c +1 -4
@@ -44,7 +44,7 @@ int mount_init(void **context)int mount_mount (struct autofs_point *ap,const char *root,const char *name,int name_len,const char *what,const char *fstype,const char *options,void *context) { -char *fullpath; +char fullpath[PATH_MAX ];char buf[MAX_ERR_BUF ];int err;int len, status, existed =1 ;
@@ -57,14 +57,11 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int/* Root offset of multi-mount */ len =strlen (root);if (root[len -1 ] =='/' ) { - fullpath =alloca (len); len =snprintf (fullpath, len,"%s" , root);/* Direct mount name is absolute path so don't use root */ }else if (*name =='/' ) { - fullpath =alloca (len +1 ); len =sprintf (fullpath,"%s" , root); }else { - fullpath =alloca (len + name_len +2 ); len =sprintf (fullpath,"%s/%s" , root, name); } fullpath[len] ='\0' ;
modules/mount_ext2.c +1 -4
@@ -36,7 +36,7 @@ int mount_init(void **context)int mount_mount (struct autofs_point *ap,const char *root,const char *name,int name_len,const char *what,const char *fstype,const char *options,void *context) { -char *fullpath; +char fullpath[PATH_MAX ];char buf[MAX_ERR_BUF ];const char *p, *p1;int err, ro =0 ;
@@ -49,14 +49,11 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int/* Root offset of multi-mount */ len =strlen (root);if (root[len -1 ] =='/' ) { - fullpath =alloca (len); len =snprintf (fullpath, len,"%s" , root);/* Direct mount name is absolute path so don't use root */ }else if (*name =='/' ) { - fullpath =alloca (len +1 ); len =sprintf (fullpath,"%s" , root); }else { - fullpath =alloca (len + name_len +2 ); len =sprintf (fullpath,"%s/%s" , root, name); } fullpath[len] ='\0' ;
modules/mount_generic.c +1 -4
@@ -37,7 +37,7 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int const char *what, const char *fstype, const char *options, void *context) { - char *fullpath; + char fullpath[PATH_MAX];char buf[MAX_ERR_BUF ];int err;int len, status, existed =1 ;
@@ -48,14 +48,11 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int/* Root offset of multi-mount */ len =strlen (root);if (root[len -1 ] =='/' ) { - fullpath =alloca (len); len =snprintf (fullpath, len,"%s" , root);/* Direct mount name is absolute path so don't use root */ }else if (*name =='/' ) { - fullpath =alloca (len +1 ); len =sprintf (fullpath,"%s" , root); }else { - fullpath =alloca (len + name_len +2 ); len =sprintf (fullpath,"%s/%s" , root, name); } fullpath[len] ='\0' ;
Ian Kent
maintainerPATCH 11/13 autofs-5.0.4 - configure libtirpc
In reply to Ian KentWith NFS over ipv6 on the way we need to update autofs to use the libtirpc library as it provides ipv6 functionality. This change adds configure checks to look for libtirpc (if it has been requested with --with-libtirpc) and checks whether it has been built with ipv6 support and uses it if so.
---
Makefile.conf.in | 3 Makefile.rules | 5 aclocal.m4 | 81 +++ autofs.spec | 2 configure | 1548 ++++++++++++++++++++++++++++----------------------- configure.in | 6 daemon/automount.c | 13 include/config.h.in | 6 8 files changed, 970 insertions(+), 694 deletions(-)
Makefile.conf.in +3 -0
@@ -49,6 +49,9 @@ YACC = @PATH_YACC@ RPCGEN = @PATH_RPCGEN@ RANLIB = @PATH_RANLIB@ +# Use libtirpc if requested and available +TIRPCLIB = @TIRPCLIB@ + # Use dmalloc for memory debuging DMALLOCLIB = @DMALLOCLIB@
Makefile.rules +5 -0
@@ -47,6 +47,11 @@ SOLDFLAGS = -shared CFLAGS += -D_REENTRANT -D_FILE_OFFSET_BITS=64 LDFLAGS += -lpthread +ifdef TIRPCLIB +CFLAGS += -I/usr/include/tirpc +LDFLAGS += $(TIRPCLIB) +endif + ifdef DMALLOCLIB LDFLAGS += $(DMALLOCLIB) endif
aclocal.m4 +81 -0
84 lines not on this page · raw message
autofs.spec +1 -1
@@ -57,7 +57,7 @@ inkludera n echo %{version}-%{release} > .version %build -CFLAGS="$RPM_OPT_FLAGS -Wall" ./configure --libdir=%{_libdir} --disable-mount-locking --enable-ignore-busy +CFLAGS="$RPM_OPT_FLAGS -Wall" ./configure --libdir=%{_libdir} --disable-mount-locking --enable-ignore-busy --with-libtirpc CFLAGS="$RPM_OPT_FLAGS -Wall" make initdir=/etc/rc.d/init.d DONTSTRIP=1 %install
configure +858 -690
1,596 lines not on this page · raw message
configure.in +6 -0
@@ -113,6 +113,12 @@ AC_MSG_RESULT([$flagdir]) AC_SUBST(flagdir) # +# Use libtirpc +# +AM_WITH_LIBTIRPC() +AC_SUBST(TIRPCLIB) + +# # Optional include dmalloc # AM_WITH_DMALLOC()
daemon/automount.c +10 -3
@@ -2057,7 +2057,10 @@ int main(int argc, char *argv[]) }#ifdef LIBXML2_WORKAROUND -void *dh =dlopen ("libxml2.so" ,RTLD_NOW ); +void *dh_xml2 =dlopen ("libxml2.so" ,RTLD_NOW ); +#endif +#ifdef TIRPC_WORKAROUND +void *dh_tirpc =dlopen ("libitirpc.so" ,RTLD_NOW );#endif if (!master_read_master (master_list, age,0 )) {
@@ -2090,9 +2093,13 @@ int main(int argc, char *argv[])closelog ();release_flag_file (); +#ifdef TIRPC_WORKAROUND +if (dh_tirpc) +dlclose (dh_tirpc); +#endif #ifdef LIBXML2_WORKAROUND -if (dh) -dlclose (dh); +if (dh_xml2) +dlclose (dh_xml2);#endif close_ioctl_ctl ();
include/config.h.in +6 -0
@@ -66,6 +66,9 @@ /* Define to 1 if you have the <unistd.h> header file. */ #undef HAVE_UNISTD_H +/* Use IPv6 with libtirpc */ +#undef INET6 + /* Use libxml2 tsd usage workaround */ #undef LIBXML2_WORKAROUND
@@ -114,6 +117,9 @@ /* Define to 1 if you have the ANSI C header files. */ #undef STDC_HEADERS +/* Use libtirpc tsd usage workaround */ +#undef TIRPC_WORKAROUND + /* Define if using the dmalloc debugging malloc package */ #undef WITH_DMALLOC
Ian Kent
maintainerPATCH 12/13 autofs-5.0.4 - ipv6 name and address support
In reply to Ian KentFor ipv6 we need to convert all ipv4 specific function calls to ipv6 compatible function calls and update the rpc code to deal with ipv6 addresses. The host proximity calculation also needes to be updated.
I'm sure this isn't completely correct yet and it will need more work as I become more familiar with how ipv6 and subneting with it is used. The changes so far function correctly for the current autofs connectathon test suite maps so I hope there aren't any regressions with current map configurations.
---
include/replicated.h | 2 include/rpc_subs.h | 4 lib/rpc_subs.c | 484 ++++++++++++++++++++++++++++++++------------------ modules/cyrus-sasl.c | 17 +- modules/replicated.c | 235 +++++++++++++++++------- 5 files changed, 499 insertions(+), 243 deletions(-)
include/replicated.h +1 -1
@@ -51,7 +51,7 @@struct host {char *name; -char *addr; +struct sockaddr *addr;size_t addr_len;char *path;unsigned int version;
include/rpc_subs.h +2 -2
@@ -46,7 +46,7 @@struct conn_info {const char *host; -const char *addr; +struct sockaddr *addr;size_t addr_len;unsigned short port;unsigned long program;
@@ -63,7 +63,7 @@ int rpc_udp_getclient(struct conn_info *, unsigned int, unsigned int);void rpc_destroy_udp_client (struct conn_info *);int rpc_tcp_getclient (struct conn_info *,unsigned int ,unsigned int );void rpc_destroy_tcp_client (struct conn_info *); -int rpc_portmap_getclient (struct conn_info *,const char *,const char *,size_t ,const char *,unsigned int ); +int rpc_portmap_getclient (struct conn_info *,const char *,struct sockaddr *,size_t ,const char *,unsigned int );unsigned short rpc_portmap_getport (struct conn_info *,struct pmap *);int rpc_ping_proto (struct conn_info *);int rpc_ping (const char *,long ,long ,unsigned int );
lib/rpc_subs.c +314 -170
573 lines not on this page · raw message
modules/cyrus-sasl.c +13 -4
@@ -732,16 +732,25 @@ sasl_bind_mech(unsigned logopt, LDAP *ldap, struct lookup_context *ctxt, const cdebug (logopt,"Attempting sasl bind with mechanism %s" , mech); result =ldap_get_option (ldap,LDAP_OPT_HOST_NAME , &host); -if (result !=LDAP_SUCCESS || !host) { +if (result !=LDAP_OPT_SUCCESS || !host) {debug (logopt,"failed to get hostname for connection" );return NULL ; } -if ((tmp =strchr (host,':' ))) - *tmp ='\0' ; +if ((tmp =strrchr (host,':' ))) { +if (*(tmp -1 ) !=']' ) { + *tmp ='\0' ; + tmp = host; + }else { + *(tmp -1 ) ='\0' ; + tmp = host; +if (*tmp =='[' ) + tmp++; + } + }/* Create a new authentication context for the service. */ - result =sasl_client_new ("ldap" , host,NULL ,NULL ,NULL ,0 , &conn); + result =sasl_client_new ("ldap" , tmp,NULL ,NULL ,NULL ,0 , &conn);if (result !=SASL_OK ) {error (logopt,"sasl_client_new failed with error %d" , result);
modules/replicated.c +169 -66
326 lines not on this page · raw message
Ian Kent
maintainerPATCH 13/13 autofs-5.0.4 - ipv6 parse
In reply to Ian KentSince ipv6 addresses use a colon separator and we use the colon quite a bit as a delimiting character we need to distinguish between when the colon is the delimeter we are looking for and when it is part of an ipv6 address. Since there is widespread use of "[" and "]" to provide the ability to separate a port specification from an ipv6 address this convention has also been used in autofs.
---
include/parse_subs.h | 8 ++++ lib/master_tok.l | 10 +++-- lib/parse_subs.c | 99 +++++++++++++++++++++++++++++++++++++++++++++--- modules/lookup_file.c | 40 +++++++------------ modules/lookup_ldap.c | 21 +++++++++- modules/mount_autofs.c | 29 ++++++-------- modules/parse_sun.c | 16 +++++--- modules/replicated.c | 26 ++++++++++++- 8 files changed, 186 insertions(+), 63 deletions(-)
include/parse_subs.h +8 -0
@@ -20,6 +20,12 @@struct mapent ; +struct map_type_info { +char *type; +char *format; +char *map; +}; +const char *skipspace (const char *);int check_colon (const char *);int chunklen (const char *,int );
@@ -27,5 +33,7 @@ int strmcmp(const char *, const char *, int);char *dequote (const char *,int ,unsigned int );int span_space (const char *,unsigned int );char *sanitize_path (const char *,int ,unsigned int ,unsigned int ); +void free_map_type_info (struct map_type_info *); +struct map_type_info *parse_map_type_info (const char *);#endif
lib/master_tok.l +6 -4
@@ -96,10 +96,12 @@ SLASHIFYSTR (--(no-)?slashify-colons) NUMBER [0-9]+ DNSERVSTR1 ([[:alpha:]][[:alnum:]\-.]*(:[0-9]+)?:) -DNSERVSTR2 (\/\/[[:alpha:]][[:alnum:]\-.]*(:[0-9]+)?\/) -DNSERVSTR3 (([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}(:[0-9]+)?:) -DNSERVSTR4 (\/\/([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}(:[0-9]+)?\/) -DNSERVERSTR ({DNSERVSTR1}|{DNSERVSTR2}|{DNSERVSTR3}|{DNSERVSTR4}) +DNSERVSTR2 (\[([[:xdigit:]]:.)+\](:[0-9]+)?:) +DNSERVSTR3 (\/\/[[:alpha:]][[:alnum:]\-.]*(:[0-9]+)?\/) +DNSERVSTR4 (\/\/\[([[:xdigit:]]:.)+\](:[0-9]+)?\/) +DNSERVSTR5 (([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}(:[0-9]+)?:) +DNSERVSTR6 (\/\/([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}(:[0-9]+)?\/) +DNSERVERSTR ({DNSERVSTR1}|{DNSERVSTR2}|{DNSERVSTR3}|{DNSERVSTR4}|{DNSERVSTR5}|{DNSERVSTR6}) AT_CN ([cC][[nN]) AT_NMN ([nN][iI][sS][Mm][aA][pP][Nn][aA][mM][eE])
lib/parse_subs.c +93 -6
122 lines not on this page · raw message
modules/lookup_file.c +15 -25
@@ -523,10 +523,10 @@ prepare_plus_include(struct autofs_point *ap, time_t age, char *key, unsigned in {struct map_source *current;struct map_source *source; -char *type, *map, *fmt; +struct map_type_info *info;const char *argv[2 ];int argc; -char *buf, *tmp; +char *buf; current = ap->entry->current; ap->entry->current =NULL ;
@@ -548,33 +548,19 @@ prepare_plus_include(struct autofs_point *ap, time_t age, char *key, unsigned inreturn NULL ; } - type = fmt =NULL ; - -/* Look for space terminator - ignore local options */ - map = buf; -for (tmp = buf; *tmp; tmp++) { -if (*tmp ==' ' ) { - *tmp ='\0' ; -break ; - }else if (*tmp ==',' ) { - type = buf; - *tmp++ ='\0' ; - fmt = tmp; - }else if (*tmp ==':' ) { -if (!fmt) - type = buf; - *tmp++ ='\0' ; - map = tmp; - } -if (*tmp =='\\' ) - tmp++; +if (!(info =parse_map_type_info (buf))) { +error (ap->logopt,MODPREFIX "failed to parse map info" ); +free (buf); +return NULL ; } argc =1 ; - argv[0 ] = map; + argv[0 ] = info->map; argv[1 ] =NULL ; - source =master_find_source_instance (current, type, fmt, argc, argv); + source =master_find_source_instance (current, + info->type, info->format, + argc, argv);if (source)/* * Make sure included map age is in sync with its owner
@@ -582,8 +568,11 @@ prepare_plus_include(struct autofs_point *ap, time_t age, char *key, unsigned in*/ source->age = age; else { - source =master_add_source_instance (current, type, fmt, age, argc, argv); + source =master_add_source_instance (current, + info->type, info->format, + age, argc, argv);if (!source) { +free_map_type_info (info);free (buf);error (ap->logopt,"failed to add included map instance" );return NULL ;
@@ -594,6 +583,7 @@ prepare_plus_include(struct autofs_point *ap, time_t age, char *key, unsigned inif (inc) source->recurse =1 ; +free_map_type_info (info);free (buf);return source;
modules/lookup_ldap.c +18 -3
@@ -1119,11 +1119,26 @@ static int parse_server_string(unsigned logopt, const char *url, struct lookup_cmemcpy(ctxt->server, s, l); */ } - }else if (strchr (ptr,':' ) !=NULL ) { -char *q =NULL ; + }else if (strchr (ptr,':' ) !=NULL || *ptr =='[' ) { +const char *q =NULL ;/* Isolate the server. Include the port spec */ - q =strchr (ptr,':' ); +if (*ptr !='[' ) + q =strchr (ptr,':' ); +else { + q = ++ptr; +while (*q ==':' ||isxdigit (*q)) + q++; +if (*q !=']' ) { +crit (logopt,MODPREFIX +"invalid LDAP map syntax %s" , ptr); +return 0 ; + } + q++; +if (*q ==':' ) + q++; + } +if (isdigit (*q))while (isdigit (*q)) q++;
modules/mount_autofs.c +12 -17
@@ -50,7 +50,7 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name,int argc, status, ghost = ap->flags &MOUNT_FLAG_GHOST ;time_t timeout = ap->exp_timeout;unsigned logopt = ap->logopt; -char *type, *format, *tmp, *tmp2; +struct map_type_info *info;struct master *master;struct master_mapent *entry;struct map_source *source;
@@ -174,21 +174,12 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, argc =1 ; - type =NULL ; - format =NULL ; - - tmp =strchr (what,':' ); -if (tmp) { - *tmp++ ='\0' ; - tmp2 =strchr (what,',' ); -if (tmp2) { - *tmp2++ ='\0' ; - format = tmp2; - } - type = (char *) what; - argv[0 ] = tmp; - }else - argv[0 ] = (char *) what; +if (!(info =parse_map_type_info (what))) { +error (ap->logopt,MODPREFIX "failed to parse map info" ); +master_free_mapent (entry); +return 1 ; + } + argv[0 ] = info->map;if (options) { p = options;
@@ -202,13 +193,17 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, } argv[argc] =NULL ; - source =master_add_map_source (entry, type, format,time (NULL ), argc, argv); + source =master_add_map_source (entry, + info->type, info->format, +time (NULL ), argc, argv);if (!source) {error (ap->logopt,MODPREFIX "failed to add map source to entry" );master_free_mapent (entry); +free_map_type_info (info);return 1 ; } +free_map_type_info (info); source->mc =cache_init (entry->ap, source);if (!source->mc) {
modules/parse_sun.c +10 -6
@@ -245,7 +245,9 @@ int expandsunent(const char *src, char *dst, const char *key, *(dst++) = (seen_colons && slashify_colons) ?'/' :':' ; len++; - seen_colons =1 ; +/* Were looking for the colon preceeding a path */ +if (*src =='/' ) + seen_colons =1 ;break ;default :
@@ -814,21 +816,23 @@ static int validate_location(char *loc)return 1 ;/* -* If a ':' is present now it must be a host name, except +* If a ':/' is present now it must be a host name, except * for those special file systems like sshfs which use "#" -* and "@" in the host name part. +* and "@" in the host name part and ipv6 addresses that +* have ":", "[" and "]". */ if (check_colon (ptr)) { -while (*ptr && *ptr !=':' ) { +while (*ptr &&strncmp (ptr,":/" ,2 )) {if (!(isalnum (*ptr) || *ptr =='-' || *ptr =='.' || *ptr =='_' || *ptr ==',' || *ptr =='(' || *ptr ==')' || - *ptr =='#' || *ptr =='@' )) + *ptr =='#' || *ptr =='@' || *ptr ==':' || + *ptr =='[' || *ptr ==']' ))return 0 ; ptr++; } -if (*ptr && *ptr ==':' ) +if (*ptr && !strncmp (ptr,":/" ,2 )) ptr++; }
modules/replicated.c +24 -2
@@ -1168,6 +1168,28 @@ static int add_local_path(struct host **hosts, const char *path)return 1 ; } +static char *seek_delim (const char *s) +{ +const char *p = s; +char *delim; + + delim =strpbrk (p,"(, \t:" ); +if (delim && *delim !=':' ) +return delim; + +while (*p) { +if (*p !=':' ) { + p++; +continue ; + } +if (!strncmp (p,":/" ,2 )) +return (char *) p; + p++; + } + +return NULL ; +} +int parse_location (unsigned logopt,struct host **hosts,const char *list) {char *str, *p, *delim;
@@ -1187,7 +1209,7 @@ int parse_location(unsigned logopt, struct host **hosts, const char *list)int weight =0 ; p +=strspn (p," \t," ); - delim =strpbrk (p,"(, \t:" ); + delim =seek_delim (p);if (delim) {if (*delim =='(' ) {
@@ -1211,7 +1233,7 @@ int parse_location(unsigned logopt, struct host **hosts, const char *list)/* Oh boy - might have spaces in the path */ next = path; -while (*next && *next !=':' ) +while (*next &&strncmp (next,":/" ,2 )) next++;/* No spaces in host names at least */