Example #1
0
int
read_utmp (char const *file, size_t *n_entries, STRUCT_UTMP **utmp_buf,
	   int options)
{
  size_t n_read = 0;
  size_t n_alloc = 0;
  STRUCT_UTMP *utmp = NULL;
  STRUCT_UTMP *u;

  /* Ignore the return value for now.
     Solaris' utmpname returns 1 upon success -- which is contrary
     to what the GNU libc version does.  In addition, older GNU libc
     versions are actually void.   */
  UTMP_NAME_FUNCTION (file);

  SET_UTMP_ENT ();

  while ((u = GET_UTMP_ENT ()) != NULL)
    if (desirable_utmp_entry (u, options))
      {
	if (n_read == n_alloc)
	  utmp = x2nrealloc (utmp, &n_alloc, sizeof *utmp);

	utmp[n_read++] = *u;
      }

  END_UTMP_ENT ();

  *n_entries = n_read;
  *utmp_buf = utmp;

  return 0;
}
Example #2
0
int
read_utmp (const char *filename, int *n_entries, STRUCT_UTMP **utmp_buf)
{
  int n_read;
  STRUCT_UTMP *u;
  STRUCT_UTMP *utmp = NULL;

  /* Ignore the return value for now.
     Solaris' utmpname returns 1 upon success -- which is contrary
     to what the GNU libc version does.  In addition, older GNU libc
     versions are actually void.   */
  UTMP_NAME_FUNCTION (filename);

  SET_UTMP_ENT ();

  n_read = 0;
  while ((u = GET_UTMP_ENT ()) != NULL)
    {
      ++n_read;
      utmp = (STRUCT_UTMP *) realloc (utmp, n_read * sizeof (STRUCT_UTMP));
      if (utmp == NULL)
	return 1;
      utmp[n_read - 1] = *u;
    }

  END_UTMP_ENT ();

  *n_entries = n_read;
  *utmp_buf = utmp;

  return 0;
}
Example #3
0
void
wtmpxrawdump (const char *wtmpfile, const char *user)
{
    STRUCT_UTMP *utp;
    struct in_addr addr;
    char *addr_string, *time_string;

    if (access (wtmpfile, R_OK))
        die (errno, "cannot access the file");

    /* Ignore the return value for now.
       Solaris' utmpname returns 1 upon success -- which is contrary
       to what the GNU libc version does.  In addition, older GNU libc
       versions are actually void.   */
    UTMP_NAME_FUNCTION (wtmpfile);

    SET_UTMP_ENT ();

    while ((utp = GET_UTMP_ENT ()) != NULL)
      {
          if (user && strncmp (UT_USER (utp), user, sizeof (UT_USER (utp))))
              continue;

          /* FIXME: missing support for IPv6 */
#ifdef HAVE_UTP_UT_ADDR_V6
          addr.s_addr = utp->ut_addr_v6[0];
#endif

          addr_string = inet_ntoa (addr);
          time_string = timetostr (UT_TIME_MEMBER (utp));

          switch (utp->ut_type)
            {
            default:
                /* Note: also catch EMPTY/UT_UNKNOWN values */
                printf ("%-9s", "NONE");
                break;
#ifdef RUN_LVL
                /* Undefined on AIX if _ALL_SOURCE is false */
            case RUN_LVL:
                printf ("%-9s", "RUNLEVEL");
                break;
#endif
            case BOOT_TIME:
                printf ("%-9s", "REBOOT");
                break;
            case OLD_TIME:
            case NEW_TIME:
                /* FIXME */
                break;
            case INIT_PROCESS:
                printf ("%-9s", "INIT");
                break;
            case LOGIN_PROCESS:
                printf ("%-9s", "LOGIN");
                break;
            case USER_PROCESS:
                printf ("%-9.*s", sizeof (UT_USER (utp)), UT_USER (utp));
                break;
            case DEAD_PROCESS:
                printf ("%-9s", "DEAD");
                break;
#ifdef ACCOUNTING
                /* Undefined on AIX if _ALL_SOURCE is false */
            case ACCOUNTING:
                printf ("%-9s", "ACCOUNT");
                break;
#endif
            }

          /* pid */
          UT_PID (utp) ? printf ("[%05d]", UT_PID (utp)) : printf ("[%5s]",
                                                                   "-");

          /*     line      id       host      addr       date&time */
          printf
              (" [%-12.*s] [%-4.*s] [%-19.*s] [%-15.15s] [%-19.19s]\n",
               sizeof (utp->ut_line), utp->ut_line,
               sizeof (utp->ut_id), utp->ut_id,
               sizeof (utp->ut_host), utp->ut_host, addr_string, time_string);

      }

    END_UTMP_ENT ();
}