meta-tizen: neard: move recipe and patches to the proper dir
[scm/bb/tizen-distro.git] / meta-tizen / meta-tizen-adaptation / meta / recipes-connectivity / connman / connman / 0030-multi-user-Add-multi-user-support-for-auto-connect-s.patch
1 From 96469b8ff2cd0e7dc77b7974c431f1dd97981356 Mon Sep 17 00:00:00 2001
2 From: Zhang zhengguang <zhengguang.zhang@intel.com>
3 Date: Sat, 11 Oct 2014 16:46:50 +0800
4 Subject: [PATCH 30/32] multi-user: Add multi-user support for auto connect
5  service
6
7 Use case:
8
9 For wifi auto connect mechamnism, only when the user who owns the
10 wifi service login, the service is allowed to be auto connected.
11
12 Change-Id: I99135117facafda41532e0280c89194b27baac16
13 ---
14  src/service.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
15  1 file changed, 62 insertions(+)
16
17 diff --git a/src/service.c b/src/service.c
18 index a1124ae..55cf02c 100644
19 --- a/src/service.c
20 +++ b/src/service.c
21 @@ -30,6 +30,8 @@
22  #include <gdbus.h>
23  #include <ctype.h>
24  #include <stdint.h>
25 +#include <pwd.h>
26 +#include <utmpx.h>
27  
28  #include <connman/storage.h>
29  #include <connman/setting.h>
30 @@ -379,6 +381,61 @@ connman_service_is_user_allowed(struct connman_service *service, uid_t uid)
31         return true;
32  }
33  
34 +static GList *connman_service_get_login_users()
35 +{
36 +       struct utmpx *utmp;
37 +       struct passwd *pwd;
38 +       GList *user_list = NULL;
39 +
40 +       setutxent();
41 +
42 +       while ((utmp = getutxent()) != NULL) {
43 +               if (utmp->ut_user != USER_ROOT && utmp->ut_type != USER_PROCESS)
44 +                       continue;
45 +
46 +               pwd = getpwnam(utmp->ut_user);
47 +
48 +               if (!g_list_find(user_list, GUINT_TO_POINTER(pwd->pw_uid)))
49 +                       user_list = g_list_append(user_list,
50 +                                               GUINT_TO_POINTER(pwd->pw_uid));
51 +
52 +               DBG("User Name: %s, UID: %d", utmp->ut_user, pwd->pw_uid);
53 +       }
54 +
55 +       endutxent();
56 +
57 +       return user_list;
58 +}
59 +
60 +static bool is_service_owner_user_login(struct connman_service *service)
61 +{
62 +       GList *list, *user_list;
63 +       bool ret = false;
64 +
65 +       /* Here we only care about wifi service */
66 +       if (service->type != CONNMAN_SERVICE_TYPE_WIFI)
67 +               return true;
68 +
69 +       user_list = connman_service_get_login_users();
70 +
71 +       DBG("service favorite user id is: %d", service->user.favorite_user);
72 +
73 +       for (list = user_list; list; list = list->next) {
74 +               uid_t uid = GPOINTER_TO_UINT(list->data);
75 +
76 +               DBG("login user id is %d", uid);
77 +
78 +               if (service->user.favorite_user == uid) {
79 +                       ret = true;
80 +                       break;
81 +               }
82 +       }
83 +
84 +       g_list_free(user_list);
85 +
86 +       return ret;
87 +}
88 +
89  int __connman_service_load_modifiable(struct connman_service *service)
90  {
91         GKeyFile *keyfile;
92 @@ -3800,6 +3857,11 @@ static bool auto_connect_service(GList *services,
93                         continue;
94                 }
95  
96 +               if (!is_service_owner_user_login(service)) {
97 +                       DBG("favorite user not login, wifi auto connect denied");
98 +                       continue;
99 +               }
100 +
101                 DBG("service %p %s %s", service, service->name,
102                         (preferred) ? "preferred" : reason2string(reason));
103  
104 -- 
105 1.8.1.4
106