diff options
author | Zhang zhengguang <zhengguang.zhang@intel.com> | 2014-10-11 16:46:50 +0800 |
---|---|---|
committer | Chengyi Zhao <chengyi1.zhao@archermind.com> | 2014-11-07 22:16:29 -0800 |
commit | 96469b8ff2cd0e7dc77b7974c431f1dd97981356 (patch) | |
tree | 2ac2d1e39ab4241b090f8d0eef39bdb2a99868e3 | |
parent | 9235632fd02062efa3a1af7eb1957fdd364f4a8c (diff) | |
download | connman-96469b8ff2cd0e7dc77b7974c431f1dd97981356.tar.gz connman-96469b8ff2cd0e7dc77b7974c431f1dd97981356.tar.bz2 connman-96469b8ff2cd0e7dc77b7974c431f1dd97981356.zip |
multi-user: Add multi-user support for auto connect servicesubmit/tizen/20141117.030429accepted/tizen/mobile/20141117.090654accepted/tizen/ivi/20141202.020921accepted/tizen/common/20141121.180554
Use case:
For wifi auto connect mechamnism, only when the user who owns the
wifi service login, the service is allowed to be auto connected.
Change-Id: I99135117facafda41532e0280c89194b27baac16
-rw-r--r-- | src/service.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/service.c b/src/service.c index a1124ae8..55cf02cc 100644 --- a/src/service.c +++ b/src/service.c @@ -30,6 +30,8 @@ #include <gdbus.h> #include <ctype.h> #include <stdint.h> +#include <pwd.h> +#include <utmpx.h> #include <connman/storage.h> #include <connman/setting.h> @@ -379,6 +381,61 @@ connman_service_is_user_allowed(struct connman_service *service, uid_t uid) return true; } +static GList *connman_service_get_login_users() +{ + struct utmpx *utmp; + struct passwd *pwd; + GList *user_list = NULL; + + setutxent(); + + while ((utmp = getutxent()) != NULL) { + if (utmp->ut_user != USER_ROOT && utmp->ut_type != USER_PROCESS) + continue; + + pwd = getpwnam(utmp->ut_user); + + if (!g_list_find(user_list, GUINT_TO_POINTER(pwd->pw_uid))) + user_list = g_list_append(user_list, + GUINT_TO_POINTER(pwd->pw_uid)); + + DBG("User Name: %s, UID: %d", utmp->ut_user, pwd->pw_uid); + } + + endutxent(); + + return user_list; +} + +static bool is_service_owner_user_login(struct connman_service *service) +{ + GList *list, *user_list; + bool ret = false; + + /* Here we only care about wifi service */ + if (service->type != CONNMAN_SERVICE_TYPE_WIFI) + return true; + + user_list = connman_service_get_login_users(); + + DBG("service favorite user id is: %d", service->user.favorite_user); + + for (list = user_list; list; list = list->next) { + uid_t uid = GPOINTER_TO_UINT(list->data); + + DBG("login user id is %d", uid); + + if (service->user.favorite_user == uid) { + ret = true; + break; + } + } + + g_list_free(user_list); + + return ret; +} + int __connman_service_load_modifiable(struct connman_service *service) { GKeyFile *keyfile; @@ -3800,6 +3857,11 @@ static bool auto_connect_service(GList *services, continue; } + if (!is_service_owner_user_login(service)) { + DBG("favorite user not login, wifi auto connect denied"); + continue; + } + DBG("service %p %s %s", service, service->name, (preferred) ? "preferred" : reason2string(reason)); |