From 5801871bd36182875e34efdb935862f7d14fb55e Mon Sep 17 00:00:00 2001 From: IgnorantGuru Date: Sun, 26 Apr 2015 12:11:26 -0600 Subject: [PATCH] special handling for cifs mount ipv6 literal #46; retain literal host --- ChangeLog | 1 + src/udevil.c | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index c3e0ecd..2f5eecc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ [devmon 1.1.8] fix no error popup on --unmount-removable #42 [devmon 1.1.8] improve --exec-on-unmount for mounted during startup [devmon 1.1.8] unset %d %l for --exec-on-unmount #56 + special handling for cifs mount ipv6 literal #46; retain literal host 0.4.3 2013-12-09: fix default udevil.conf allowed_options missing fmask=0133 #35 0.4.2 2013-12-04: diff --git a/src/udevil.c b/src/udevil.c index f96a254..4e10491 100644 --- a/src/udevil.c +++ b/src/udevil.c @@ -2627,7 +2627,7 @@ static int parse_network_url( const char* url, const char* fstype, { str[0] = '\0'; if ( xurl[1] != '\0' ) - nm->host = g_strdup( xurl + 1 ); + nm->host = g_strdup_printf( "[%s]", xurl + 1 ); if ( str[1] == ':' && str[2] != '\0' ) nm->port = g_strdup( str + 1 ); } @@ -2690,11 +2690,23 @@ static int parse_network_url( const char* url, const char* fstype, } // lookup ip - if ( !( nm->ip = get_ip( nm->host ) ) || ( nm->ip && nm->ip[0] == '\0' ) ) + char* tmphost = g_strdup( nm->host ); + if ( tmphost && tmphost[0] == '[' && strchr( tmphost, ':' ) && + g_str_has_suffix( tmphost, "]" ) ) + { + // ipv6 literal - strip [] for get_ip + str = tmphost; + tmphost = g_strdup( str + 1 ); + g_free( str ); + tmphost[strlen( tmphost ) - 1] = '\0'; + } + if ( !( nm->ip = get_ip( tmphost ) ) || ( nm->ip && nm->ip[0] == '\0' ) ) { wlog( _("udevil: error 36: lookup host '%s' failed\n"), nm->host, 2 ); + g_free( tmphost ); goto _net_free; } + g_free( tmphost ); // valid *netmount = nm; @@ -3769,6 +3781,23 @@ _get_type: fstype = g_strdup( "fuse" ); } + // add option ip= for cifs ipv6 literal + if ( type == MOUNT_NET && + ( !strcmp( fstype, "smbfs" ) || !strcmp( fstype, "cifs" ) ) ) + { + if ( netmount->host && netmount->host[0] == '[' && + strchr( netmount->host, ':' ) && + g_str_has_suffix( netmount->host, "]" ) ) + { + // ipv6 literal as host - cifs requires special ip= option + // This is done after valid options test since ip= should not be + // an allowed option + str = options; + options = g_strdup_printf( "%s,ip=%s", str, netmount->ip ); + g_free( str ); + } + } + // no point and not remount if ( !data->point && !remount ) {