Remove logging to /var/run/tump and /var/run/wtmp 43/244343/3
authorINSUN PYO <insun.pyo@samsung.com>
Thu, 17 Sep 2020 11:07:42 +0000 (20:07 +0900)
committerINSUN PYO <insun.pyo@samsung.com>
Fri, 18 Sep 2020 00:40:15 +0000 (09:40 +0900)
1. Tizen does not use this functionality.
2. Systemd also removed this functionality.
3. Resolving Smack error
  - Jan 01 09:08:55 localhost audit[2765]: AVC lsm=SMACK fn=smack_file_open action=denied subject="User" object="System::Privileged" requested=r pid=2765 comm="tlm-sessiond" path="/opt/var/log/wtmp" dev="mmcblk0p3" ino=822

Change-Id: I7aa5f22fe509831afd19f629fd531119c2aac3e0

src/common/tlm-utils.c
src/common/tlm-utils.h
src/sessiond/tlm-session.c

index d5a372a..b496882 100755 (executable)
 #include <sys/types.h>
 #include <pwd.h>
 #include <sys/stat.h>
-#include <glib/gstdio.h>
-#include <utmp.h>
 #include <paths.h>
-#include <ctype.h>
-#include <sys/types.h>
-#include <sys/socket.h>
 #include <sys/inotify.h>
-#include <netdb.h>
 #include <string.h>
 #include <unistd.h>
 #include <glib/gstdio.h>
@@ -47,8 +41,6 @@
 #include "tlm-config.h"
 #include "tlm-config-general.h"
 
-#define HOST_NAME_SIZE 256
-
 void
 g_clear_string (gchar **str)
 {
@@ -291,178 +283,6 @@ tlm_utils_delete_dir (
     return TRUE;
 }
 
-static gchar *
-_get_tty_id (
-        const gchar *tty_name)
-{
-    gchar *id = NULL;
-    const gchar *tmp = tty_name;
-
-    while (tmp) {
-        if (isdigit (*tmp)) {
-            id = g_strdup (tmp);
-            break;
-        }
-        tmp++;
-    }
-    return id;
-}
-
-static size_t
-_get_host_address (
-        const gchar *hostname, gchar** hostaddress)
-{
-    struct addrinfo hints, *info = NULL;
-    size_t sz_hostaddress = 0;
-
-    if (!hostname) return 0;
-
-    memset (&hints, 0, sizeof (hints));
-    hints.ai_flags = AI_ADDRCONFIG;
-
-    if (getaddrinfo (hostname, NULL, &hints, &info) == 0) {
-        if (info) {
-            if (info->ai_family == AF_INET) {
-                struct sockaddr_in *sa = (struct sockaddr_in *) info->ai_addr;
-                sz_hostaddress = sizeof(struct in_addr);
-                *hostaddress = g_malloc0 (sz_hostaddress);
-                if (!*hostaddress) {
-                    CRITICAL("g_malloc0 memory allocation failure");
-                    freeaddrinfo (info);
-                    return 0;
-                }
-                memcpy (*hostaddress, &(sa->sin_addr), sz_hostaddress);
-            } else if (info->ai_family == AF_INET6) {
-                struct sockaddr_in6 *sa = (struct sockaddr_in6 *) info->ai_addr;
-                sz_hostaddress = sizeof(struct in6_addr);
-                *hostaddress = g_malloc0 (sz_hostaddress);
-                if (!*hostaddress) {
-                    CRITICAL("g_malloc0 memory allocation failure");
-                    freeaddrinfo (info);
-                    return 0;
-                }
-                memcpy (*hostaddress, &(sa->sin6_addr), sz_hostaddress);
-            }
-            freeaddrinfo (info);
-        }
-    }
-    return sz_hostaddress;
-}
-
-static gboolean
-_is_tty_same (
-        const gchar *tty1_name,
-        const gchar *tty2_name)
-{
-    gchar *tty1 = NULL, *tty2 = NULL;
-    gboolean res = FALSE;
-
-    if (tty1_name == tty2_name) return TRUE;
-    if (!tty1_name || !tty2_name) return FALSE;
-
-    if (*tty1_name == '/') tty1 = g_strdup (tty1_name);
-    else tty1 = g_strdup_printf ("/dev/%s", tty1_name);
-    if (*tty2_name == '/') tty2 = g_strdup (tty2_name);
-    else tty2 = g_strdup_printf ("/dev/%s", tty2_name);
-
-    res = (g_strcmp0 (tty1_name, tty2_name) == 0);
-
-    g_free (tty1);
-    g_free (tty2);
-    return res;
-}
-
-static gchar *
-_get_host_name ()
-{
-    gchar *name = g_malloc0 (HOST_NAME_SIZE);
-    if (!name) {
-        CRITICAL("g_malloc0 memory allocation failure");
-        return NULL;
-    }
-    if (gethostname (name, HOST_NAME_SIZE) != 0) {
-        g_free (name);
-        return NULL;
-    }
-    return name;
-}
-
-void
-tlm_utils_log_utmp_entry (const gchar *username)
-{
-    struct timeval tv;
-    pid_t pid;
-    struct utmp ut_ent;
-    struct utmp *ut_tmp = NULL;
-    gchar *hostname = NULL, *hostaddress = NULL;
-    size_t sz_hostaddress;
-    const gchar *tty_name = NULL;
-    gchar *tty_no_dev_name = NULL, *tty_id = NULL;
-    gchar tty_name_buf[TTY_NAME_MAX+1] = {0,};
-
-    DBG ("Log session entry to utmp/wtmp");
-
-    hostname = _get_host_name ();
-    sz_hostaddress = _get_host_address (hostname, &hostaddress);
-
-    if (0 == ttyname_r(0, tty_name_buf, TTY_NAME_MAX+1))
-        tty_name = tty_name_buf;
-
-    if (tty_name) {
-        tty_no_dev_name = g_strdup (strncmp(tty_name, "/dev/", 5) == 0 ?
-            tty_name + 5 : tty_name);
-    }
-    tty_id = _get_tty_id (tty_no_dev_name);
-    pid = getpid ();
-    utmpname (_PATH_UTMP);
-
-    setutent ();
-    while ((ut_tmp = getutent())) {
-        if ( (ut_tmp->ut_pid == pid) &&
-             (ut_tmp->ut_id[0] != '\0') &&
-             (ut_tmp->ut_type == LOGIN_PROCESS ||
-                     ut_tmp->ut_type == USER_PROCESS) &&
-             (_is_tty_same (ut_tmp->ut_line, tty_name))) {
-            break;
-        }
-    }
-
-    if (ut_tmp) memcpy (&ut_ent, ut_tmp, sizeof (ut_ent));
-    else        memset (&ut_ent, 0, sizeof (ut_ent));
-
-    ut_ent.ut_type = USER_PROCESS;
-    ut_ent.ut_pid = pid;
-    if (tty_id)
-        strncpy (ut_ent.ut_id, tty_id, sizeof (ut_ent.ut_id)-1);
-    if (username)
-        strncpy (ut_ent.ut_user, username, sizeof (ut_ent.ut_user)-1);
-    if (tty_no_dev_name)
-        strncpy (ut_ent.ut_line, tty_no_dev_name, sizeof (ut_ent.ut_line)-1);
-    if (hostname)
-        strncpy (ut_ent.ut_host, hostname, sizeof (ut_ent.ut_host)-1);
-    if (hostaddress)
-        memcpy (&ut_ent.ut_addr_v6, hostaddress, sz_hostaddress);
-
-    ut_ent.ut_session = getsid (0);
-    gettimeofday (&tv, NULL);
-#ifdef _HAVE_UT_TV
-    ut_ent.ut_tv.tv_sec = tv.tv_sec;
-    ut_ent.ut_tv.tv_usec = tv.tv_usec;
-#else
-    ut_ent.ut_time = tv.tv_sec;
-#endif
-
-    pututline (&ut_ent);
-    endutent ();
-
-    updwtmp (_PATH_WTMP, &ut_ent);
-
-    g_free (hostaddress);
-    g_free (hostname);
-    g_free (tty_no_dev_name);
-    g_free (tty_id);
-}
-
 static gchar **
 _split_command_line_with_regex(const char *command, GRegex *regex) {
   gchar **temp_strv = NULL;
index cdb836f..3554914 100755 (executable)
@@ -55,9 +55,6 @@ tlm_user_get_shell (const gchar *username);
 gboolean
 tlm_utils_delete_dir (const gchar *dir);
 
-void
-tlm_utils_log_utmp_entry (const gchar *username);
-
 gchar **
 tlm_utils_split_command_line (const gchar *command);
 
index 3ced70d..15cc0a7 100755 (executable)
@@ -847,7 +847,6 @@ tlm_session_start (TlmSession *session,
     }
     priv->sessionid = g_strdup (tlm_auth_session_get_sessionid (
             priv->auth_session));
-    tlm_utils_log_utmp_entry (priv->username);
 
     priv->session_pause =  tlm_config_get_boolean (priv->config,
                                              TLM_CONFIG_GENERAL,