Send connman mailing list submissions to
        [email protected]

To subscribe or unsubscribe via email, send a message with subject or
body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of connman digest..."

Today's Topics:

   1. [PATCH v4 0/4]  Remove GDateTime API usage (Daniel Wagner)
   2. [PATCH v4 1/4] util: Add timestamp helpers (Daniel Wagner)
   3. [PATCH v4 2/4] service: Remove GDateTime API usage (Daniel Wagner)
   4. [PATCH v4 4/4] tools: Remove GDateTime API usage (Daniel Wagner)
   5. [PATCH v4 3/4] wifi: Replace GDateVal API usage (Daniel Wagner)
   6. Re: [PATCH 09/10] openvpn: Rewrite plugin to support VPN agent and 
encrypted private keys
      (Daniel Wagner)
   7. Re: [PATCH v4 0/4]  Remove GDateTime API usage (Daniel Wagner)
   8. Re: simpler reproduction of connman error (Daniel Wagner)


----------------------------------------------------------------------

Date: Wed, 13 Nov 2019 09:26:52 +0100
From: Daniel Wagner <[email protected]>
Subject: [PATCH v4 0/4]  Remove GDateTime API usage
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Message-ID: <[email protected]>

As it turns out, the GDateTime was introduced in 2.26 but not the
iso8601 function.

changes since v3:
  - rename the functions
  - dropped useless wrapper around gettimeofday()

changes since v2:
  - moved new code into util helper file
  - updated wifi plugin as well

changes since v1:
  - added error handling
  - use gettimeofday() like Glib does
  - backwards compatibility added to string parser

Daniel Wagner (4):
  util: Add timestamp helpers
  service: Remove GDateTime API usage
  wifi: Replace GDateVal API usage
  tools: Remove GDateTime API usage

 plugins/wifi.c     | 12 +++++++-----
 src/service.c      | 44 +++++++++-----------------------------------
 src/shared/util.c  | 39 +++++++++++++++++++++++++++++++++++++++
 src/shared/util.h  |  5 +++++
 tools/stats-tool.c | 13 +++----------
 5 files changed, 63 insertions(+), 50 deletions(-)

-- 
2.23.0

------------------------------

Date: Wed, 13 Nov 2019 09:26:53 +0100
From: Daniel Wagner <[email protected]>
Subject: [PATCH v4 1/4] util: Add timestamp helpers
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Message-ID: <[email protected]>

Use POSIX APIs to implement a simple replacement for GDateTime.

The Glib code uses gettimeofday() to implement g_date_time_new_now(),
so use the same interface to avoid breakage.

Furthermore, the Glib code writes the timestamps with sub seconds
values, e.g. "2019-10-20T14:45:31.079935Z". The new code only writes
with second precision. That means the string parser needs to be able
to deal with the old time and new format.
---
 src/shared/util.c | 39 +++++++++++++++++++++++++++++++++++++++
 src/shared/util.h |  5 +++++
 2 files changed, 44 insertions(+)

diff --git a/src/shared/util.c b/src/shared/util.c
index df045c5bf799..73c24aef5bdd 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -88,3 +88,42 @@ void util_hexdump(const char dir, const unsigned char *buf, 
size_t len,
                function(str, user_data);
        }
 }
+
+void util_iso8601_to_timeval(char *str, struct timeval *time)
+{
+       struct tm tm;
+       time_t t;
+       char *p;
+
+       p = strptime(str, "%FT%T", &tm);
+       if (!p)
+               return;
+
+       if (*p != 'Z') {
+               /* backwards compatibility */
+               if (*p != '.' || p[strlen(p) - 1] != 'Z')
+                       return;
+       }
+
+       t = mktime(&tm);
+       if (t < 0)
+               return;
+
+       time->tv_sec = t;
+       time->tv_usec = 0;
+}
+
+char *util_timeval_to_iso8601(struct timeval *time)
+{
+       char buf[255];
+       struct tm tm;
+       time_t t;
+
+       t = time->tv_sec;
+       if (!localtime_r(&t, &tm))
+               return NULL;
+       if (!strftime(buf, sizeof(buf), "%FT%TZ", &tm))
+               return NULL;
+
+       return g_strdup(buf);
+}
diff --git a/src/shared/util.h b/src/shared/util.h
index 293fb3a4f3ba..430b821fb588 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -21,6 +21,8 @@
  *
  */
 
+#include <sys/time.h>
+
 #include <glib.h>
 
 typedef void (*util_debug_func_t)(const char *str, void *user_data);
@@ -48,3 +50,6 @@ static inline struct cb_data *cb_data_new(void *cb, void 
*user_data)
 
        return ret;
 }
+
+void util_iso8601_to_timeval(char *str, struct timeval *time);
+char *util_timeval_to_iso8601(struct timeval *time);
-- 
2.23.0

------------------------------

Date: Wed, 13 Nov 2019 09:26:54 +0100
From: Daniel Wagner <[email protected]>
Subject: [PATCH v4 2/4] service: Remove GDateTime API usage
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Message-ID: <[email protected]>

The g_date_time_new_from_iso8601() was introduced with GLib v2.56. We
don't want to update our version dependency. Instead use our replacement
API.
---
 src/service.c | 44 +++++++++-----------------------------------
 1 file changed, 9 insertions(+), 35 deletions(-)

diff --git a/src/service.c b/src/service.c
index 7e1446b7cf3b..a6fc9638f70b 100644
--- a/src/service.c
+++ b/src/service.c
@@ -35,6 +35,8 @@
 #include <connman/setting.h>
 #include <connman/agent.h>
 
+#include "src/shared/util.h"
+
 #include "connman.h"
 
 #define CONNECT_TIMEOUT                120
@@ -84,7 +86,7 @@ struct connman_service {
        bool hidden;
        bool ignore;
        bool autoconnect;
-       GDateTime *modified;
+       struct timeval modified;
        unsigned int order;
        char *name;
        char *passphrase;
@@ -378,31 +380,6 @@ static void set_split_routing(struct connman_service 
*service, bool value)
                service->order = 10;
 }
 
-static void update_modified(struct connman_service *service)
-{
-       GTimeZone *tz;
-
-       if (service->modified)
-               g_date_time_unref(service->modified);
-
-       tz = g_time_zone_new_local();
-       service->modified = g_date_time_new_now(tz);
-       g_time_zone_unref(tz);
-}
-
-static void update_modified_from_iso8601(struct connman_service *service,
-                                       char *str)
-{
-       GTimeZone *tz;
-
-       if (service->modified)
-               g_date_time_unref(service->modified);
-
-       tz = g_time_zone_new_local();
-       service->modified = g_date_time_new_from_iso8601(str, tz);
-       g_time_zone_unref(tz);
-}
-
 int __connman_service_load_modifiable(struct connman_service *service)
 {
        GKeyFile *keyfile;
@@ -444,7 +421,7 @@ int __connman_service_load_modifiable(struct 
connman_service *service)
        str = g_key_file_get_string(keyfile,
                                service->identifier, "Modified", NULL);
        if (str) {
-               update_modified_from_iso8601(service, str);
+               util_iso8601_to_timeval(str, &service->modified);
                g_free(str);
        }
 
@@ -561,7 +538,7 @@ static int service_load(struct connman_service *service)
        str = g_key_file_get_string(keyfile,
                                service->identifier, "Modified", NULL);
        if (str) {
-               update_modified_from_iso8601(service, str);
+               util_iso8601_to_timeval(str, &service->modified);
                g_free(str);
        }
 
@@ -728,7 +705,7 @@ static int service_save(struct connman_service *service)
                break;
        }
 
-       str = g_date_time_format_iso8601(service->modified);
+       str = util_timeval_to_iso8601(&service->modified);
        if (str) {
                g_key_file_set_string(keyfile, service->identifier,
                                                        "Modified", str);
@@ -3962,7 +3939,7 @@ static void service_complete(struct connman_service 
*service)
        if (service->connect_reason != CONNMAN_SERVICE_CONNECT_REASON_USER)
                do_auto_connect(service, service->connect_reason);
 
-       update_modified(service);
+       gettimeofday(&service->modified, NULL);
        service_save(service);
 }
 
@@ -4890,7 +4867,7 @@ static DBusMessage *move_service(DBusConnection *conn,
                }
        }
 
-       update_modified(service);
+       gettimeofday(&service->modified, NULL);
        service_save(service);
        service_save(target);
 
@@ -5086,9 +5063,6 @@ static void service_free(gpointer user_data)
        g_free(service->config_file);
        g_free(service->config_entry);
 
-       if (service->modified)
-               g_date_time_unref(service->modified);
-
        if (service->stats.timer)
                g_timer_destroy(service->stats.timer);
        if (service->stats_roaming.timer)
@@ -5975,7 +5949,7 @@ static int service_indicate_state(struct connman_service 
*service)
                                                        "WiFi.UseWPS", false);
                }
 
-               update_modified(service);
+               gettimeofday(&service->modified, NULL);
                service_save(service);
 
                domain_changed(service);
-- 
2.23.0

------------------------------

Date: Wed, 13 Nov 2019 09:26:56 +0100
From: Daniel Wagner <[email protected]>
Subject: [PATCH v4 4/4] tools: Remove GDateTime API usage
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Message-ID: <[email protected]>

The g_date_time_new_from_iso8601() was introduced with GLib v2.56. We
don't want to update our version dependency. So let's use good old
POSIX APIs instead.
---
 tools/stats-tool.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/tools/stats-tool.c b/tools/stats-tool.c
index 193eed24565f..105dc4973edb 100644
--- a/tools/stats-tool.c
+++ b/tools/stats-tool.c
@@ -108,18 +108,11 @@ static char *option_last_file_name = NULL;
 static bool parse_start_ts(const char *key, const char *value,
                                        gpointer user_data, GError **error)
 {
-       GTimeZone *tz;
-       GDateTime *dt;
+       struct tm tm;
 
-       tz = g_time_zone_new_local();
-       dt = g_date_time_new_from_iso8601(value, tz);
-       g_time_zone_unref(tz);
-       if (!dt)
-               return false;
+       strptime(value, "%FT%TZ", &tm);
+       option_start_ts = mktime(&tm);
 
-       option_start_ts = g_date_time_get_second(dt);
-
-       g_date_time_unref(dt);
        return true;
 }
 
-- 
2.23.0

------------------------------

Date: Wed, 13 Nov 2019 09:26:55 +0100
From: Daniel Wagner <[email protected]>
Subject: [PATCH v4 3/4] wifi: Replace GDateVal API usage
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Message-ID: <[email protected]>

GTimeVal has been deprecated. Replace it with our own replacement API.
---
 plugins/wifi.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/plugins/wifi.c b/plugins/wifi.c
index e675e6a34804..fc304e3b96a0 100644
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -59,6 +59,8 @@
 
 #include <gsupplicant/gsupplicant.h>
 
+#include "src/shared/util.h"
+
 #define CLEANUP_TIMEOUT   8    /* in seconds */
 #define INACTIVE_TIMEOUT  12   /* in seconds */
 #define FAVORITE_MAXIMUM_RETRIES 2
@@ -1611,15 +1613,15 @@ static int wifi_disable(struct connman_device *device)
 }
 
 struct last_connected {
-       GTimeVal modified;
+       struct timeval modified;
        gchar *ssid;
        int freq;
 };
 
 static gint sort_entry(gconstpointer a, gconstpointer b, gpointer user_data)
 {
-       GTimeVal *aval = (GTimeVal *)a;
-       GTimeVal *bval = (GTimeVal *)b;
+       struct timeval *aval = (struct timeval *)a;
+       struct timeval *bval = (struct timeval *)b;
 
        /* Note that the sort order is descending */
        if (aval->tv_sec < bval->tv_sec)
@@ -1646,7 +1648,7 @@ static int get_latest_connections(int max_ssids,
        GSequence *latest_list;
        struct last_connected *entry;
        GKeyFile *keyfile;
-       GTimeVal modified;
+       struct timeval modified;
        gchar **services;
        gchar *str;
        char *ssid;
@@ -1690,7 +1692,7 @@ static int get_latest_connections(int max_ssids,
                        g_key_file_free(keyfile);
                        continue;
                }
-               g_time_val_from_iso8601(str, &modified);
+               util_iso8601_to_timeval(str, &modified);
                g_free(str);
 
                ssid = g_key_file_get_string(keyfile,
-- 
2.23.0

------------------------------

Date: Wed, 13 Nov 2019 09:41:02 +0100
From: Daniel Wagner <[email protected]>
Subject: Re: [PATCH 09/10] openvpn: Rewrite plugin to support VPN
        agent and encrypted private keys
To: Jussi Laakkonen <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

Good Morning Jussi,

On Tue, Nov 12, 2019 at 11:08:31AM +0200, Jussi Laakkonen wrote:
> > On Mon, Nov 11, 2019 at 04:01:53PM +0200, Jussi Laakkonen wrote:
> >
> > This link will go stale. Would the plugin still work if the OpenVPN
> > client doesn't have this patch? Or could it made at least not hard
> > depending on it?
> >
> 
> Plugin does work without the patch but it does not receive the error:
> > >PASSWORD:Verification Failed: 'Private Key'
> and just keeps trying with the invalid password. Maybe I just change the
> link to 
> https://git.sailfishos.org/mer-core/openvpn/blob/4f4b4af116292a207416c8a990392e35a6fc41af/rpm/privatekey-passphrase-handling.diff
> that should be more permanent.

Maybe add an paragraph to the OpenVPN section in README with the link
in it? We already list the minimum dependency. I'd like to avoid
hiding this information in the code. First of all, no user will find
it and it will get stale.

> > And now some nitpicks :)
> >
> 
> Well, it can be also called a review. Thanks for commenting :)

:)

> > Overall, this is looks pretty good. I know understand your comment
> > about to much infrastructure code in the plugin. Indeed moving some of
> > this code into a library so other plugins can reuse it makes absolutely
> > sense.
> >
> 
> Thanks. Yes, moving all that code from plugins into one library is a task in
> the future (I hope not so distant one).

Cool to hear this!

Thanks,
Daniel

------------------------------

Date: Wed, 13 Nov 2019 09:47:22 +0100
From: Daniel Wagner <[email protected]>
Subject: Re: [PATCH v4 0/4]  Remove GDateTime API usage
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Wed, Nov 13, 2019 at 09:26:52AM +0100, Daniel Wagner wrote:
> As it turns out, the GDateTime was introduced in 2.26 but not the
> iso8601 function.

Patches finally applied.

------------------------------

Date: Wed, 13 Nov 2019 10:02:39 +0100
From: Daniel Wagner <[email protected]>
Subject: Re: simpler reproduction of connman error
To: Thomas Green <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

Hi Thomas,

[Added the mailing list. There might be someone else 

On Tue, Nov 12, 2019 at 11:24:13PM +0000, Thomas Green wrote:

> Here is how I reproduce the problem I'm having in the simplest manner using 
> connmanctl:
> 
> :~# connmanctl
> connmanctl> agent on
> Agent registered
> connmanctl> services ethernet_0008720978e2_cable
> /net/connman/service/ethernet_0008720978e2_cable
>   Type = ethernet
>   Security = [  ]
>   State = online
>   Favorite = True
>   Immutable = False
>   AutoConnect = True
>   Name = Wired
>   Ethernet = [ Method=auto, Interface=eno1, Address=00:08:72:09:78:E2, 
> MTU=1500 ]
>   IPv4 = [ Method=manual, Address=10.20.187.13, Netmask=255.255.255.0, 
> Gateway=10.20.187.1 ]
>   IPv4.Configuration = [ Method=manual, Address=10.20.187.13, 
> Netmask=255.255.255.0, Gateway=10.20.187.1 ]
>   IPv6 = [ Method=auto, Address=2620:10a:90cc:e187:208:72ff:fe09:78e2, 
> PrefixLength=64, Privacy=disabled ]
>   IPv6.Configuration = [ Method=auto, Privacy=disabled ]
>   Nameservers = [ 10.20.55.200, 10.150.5.200 ]
>   Nameservers.Configuration = [ 10.20.55.200, 10.150.5.200 ]
>   Timeservers = [  ]
>   Timeservers.Configuration = [  ]
>   Domains = [  ]
>   Domains.Configuration = [  ]
>   Proxy = [ Method=direct ]
>   Proxy.Configuration = [  ]
>   mDNS = False
>   mDNS.Configuration = False
>   Provider = [  ]
> connmanctl> scan wifi
> Scan completed for wifi
> connmanctl> services
> *AO Wired                ethernet_0008720978e2_cable
>     XXXXXXX             wifi_4889e71fb337_YYYYYYYYYYYYY_managed_psk
> connmanctl> disconnect ethernet_0008720978e2_cable
> Disconnected ethernet_0008720978e2_cable
> connmanctl> config ethernet_0008720978e2_cable autoconnect off
> connmanctl> connect wifi_4889e71fb337_YYYYYYYYYYYYY_managed_psk
> Agent RequestInput wifi_4889e71fb337_YYYYYYYYYYYYY_managed_psk
>   Passphrase = [ Type=psk, Requirement=mandatory ]
> Agent request cancelled by ConnMan
> Error /net/connman/service/wifi_4889e71fb337_YYYYYYYYYYYYY_managed_psk: 
> Invalid arguments
> connmanctl> connect ethernet_0008720978e2_cable
> Connected ethernet_0008720978e2_cable
> connmanctl> services ethernet_0008720978e2_cable
> /net/connman/service/ethernet_0008720978e2_cable
>   Type = ethernet
>   Security = [  ]
>   State = ready
>   Favorite = True
>   Immutable = False
>   AutoConnect = False
>   Name = Wired
>   Ethernet = [ Method=auto, Interface=eno1, Address=00:08:72:09:78:E2, 
> MTU=1500 ]
>   IPv4 = [ Method=manual, Address=10.20.187.13, Netmask=255.255.255.0 ]
>   IPv4.Configuration = [ Method=manual, Address=10.20.187.13, 
> Netmask=255.255.255.0 ]
>   IPv6 = [  ]
>   IPv6.Configuration = [ Method=auto, Privacy=disabled ]
>   Nameservers = [ 10.20.55.200, 10.150.5.200 ]
>   Nameservers.Configuration = [ 10.20.55.200, 10.150.5.200 ]
>   Timeservers = [  ]
>   Timeservers.Configuration = [  ]
>   Domains = [  ]
>   Domains.Configuration = [  ]
>   Proxy = [ Method=direct ]
>   Proxy.Configuration = [  ]
>   mDNS = False
>   mDNS.Configuration = False
>   Provider = [  ]
> connmanctl> quit
> 
> As you notice, when being prompted for the passphrase for the
> wireless connection I cancel it.  (in this case I use another
> instance of connmanctl.  In my application an asynchronous thread
> issues the cancel).  Then try to reconnect the original manual
> config for the Ethernet.  At that point you see that in IPv4 and
> IPv4 configuration the gateway is absent.  So the connection is
> 'ready' but is never online, because it can't reach out on to the
> internet.  I'm not having any great luck determining why it's being
> deleted, except for the proposed patch I sent you before.  If you
> could help track this down, I'd appreciate it.

So the cancel is important to trigger this? This sounds like a race
somewhere. The patch will just hide the problem in this case.

I just realized, there are two services involved. Without the WiFi one
you don't see it?

I admit, this is really confusing. The two services should not have
any interactions at all.

Could you provide a log with --debug output when you do the steps
above?

Thanks,
Daniel

------------------------------

Subject: Digest Footer

_______________________________________________
connman mailing list -- [email protected]
To unsubscribe send an email to [email protected]


------------------------------

End of connman Digest, Vol 49, Issue 17
***************************************

Reply via email to