Exemplo n.º 1
0
int main(){
    utmpp = getutxent();
    while ((utmpp = getutxent())!= (struct utmpx *) NULL) {
        if (utmpp->ut_type == USER_PROCESS){
            printf("%s %s %li %s\n",
                    utmpp->ut_user,
                    utmpp->ut_line,
                    utmpp->ut_tv.tv_sec,
                    utmpp->ut_host);
        }
    }
    return 0;
}
Exemplo n.º 2
0
static int user_busy_utmp (const char *name)
{
#ifdef USE_UTMPX
	struct utmpx *utent;

	setutxent ();
	while ((utent = getutxent ()) != NULL)
#else				/* !USE_UTMPX */
	struct utmp *utent;

	setutent ();
	while ((utent = getutent ()) != NULL)
#endif				/* !USE_UTMPX */
	{
		if (utent->ut_type != USER_PROCESS) {
			continue;
		}
		if (strncmp (utent->ut_user, name, sizeof utent->ut_user) != 0) {
			continue;
		}
		if (kill (utent->ut_pid, 0) != 0) {
			continue;
		}

		fprintf (stderr,
		         _("%s: user %s is currently logged in\n"),
		         Prog, name);
		return 1;
	}

	return 0;
}
Exemplo n.º 3
0
void
utmpx_mark_dead(pid_t pid, int status, boolean_t blocking)
{
	struct utmpx *up;
	int logged = 0;

	for (;;) {
		int found = 0;

		MUTEX_LOCK(&utmpx_lock);
		setutxent();

		while (up = getutxent()) {
			if (up->ut_pid == pid) {
				found = 1;

				if (up->ut_type == DEAD_PROCESS) {
					/*
					 * Cleaned up elsewhere.
					 */
					endutxent();
					MUTEX_UNLOCK(&utmpx_lock);
					return;
				}

				up->ut_type = DEAD_PROCESS;
				up->ut_exit.e_termination = WTERMSIG(status);
				up->ut_exit.e_exit = WEXITSTATUS(status);
				(void) time(&up->ut_tv.tv_sec);

				if (pututxline(up) != NULL) {
					/*
					 * Now attempt to add to the end of the
					 * wtmp and wtmpx files.  Do not create
					 * if they don't already exist.
					 */
					updwtmpx(WTMPX_FILE, up);
					endutxent();
					MUTEX_UNLOCK(&utmpx_lock);

					return;
				}
			}
		}

		endutxent();
		MUTEX_UNLOCK(&utmpx_lock);

		if (!found || !blocking)
			return;

		if (!logged) {
			log_framework(LOG_INFO, "retrying utmpx_dead on PID "
			    "%ld\n", pid);
			logged++;
		}

		(void) sleep(1);
	}
}
Exemplo n.º 4
0
int wall_main(int argc UNUSED_PARAM, char **argv)
{
	struct utmpx *ut;
	char *msg;
	int fd;

	fd = STDIN_FILENO;
	if (argv[1]) {
		/* The applet is setuid.
		 * Access to the file must be under user's uid/gid.
		 */
		fd = xopen_as_uid_gid(argv[1], O_RDONLY, getuid(), getgid());
	}
	msg = xmalloc_read(fd, NULL);
	if (ENABLE_FEATURE_CLEAN_UP && argv[1])
		close(fd);
	setutxent();
	while ((ut = getutxent()) != NULL) {
		char *line;
		if (ut->ut_type != USER_PROCESS)
			continue;
		line = concat_path_file("/dev", ut->ut_line);
		xopen_xwrite_close(line, msg);
		free(line);
	}
	if (ENABLE_FEATURE_CLEAN_UP) {
		endutxent();
		free(msg);
	}
	return EXIT_SUCCESS;
}
Exemplo n.º 5
0
static void
quick(void)
{
	struct utmpx *utx;
	int col, ncols, num;

	ncols = ttywidth();
	col = num = 0;
	while ((utx = getutxent()) != NULL) {
		if (utx->ut_type != USER_PROCESS)
			continue;
		printf("%-16s", utx->ut_user);
		if (++col < ncols / (16 + 1))
			putchar(' ');
		else {
			col = 0;
			putchar('\n');
		}
		num++;
	}
	if (col != 0)
		putchar('\n');

	printf("# users = %d\n", num);
}
Exemplo n.º 6
0
int main(int argc, char *argv[]) {
   struct utmpx *ut;
   
   setutxent();
   
   while ((ut = getutxent()) != NULL) {
      printf("%-10s ", ut->ut_user);
      printf("%-10s ", (ut->ut_type == EMPTY) ?          "EMPTY"    :
     	                (ut->ut_type == RUN_LVL) ?       "RUN_LVL"  :
                        (ut->ut_type == BOOT_TIME) ?     "BOOT_TIME":
                        (ut->ut_type == NEW_TIME) ?      "NEW_TIME" :
                        (ut->ut_type == OLD_TIME) ?      "OLD_TIME" :
                        (ut->ut_type == INIT_PROCESS) ?  "INIT_PR"  :
                        (ut->ut_type == LOGIN_PROCESS) ? "LOGIN_PR" :
                        (ut->ut_type == USER_PROCESS) ?  "USER_PR"  :
                        (ut->ut_type == DEAD_PROCESS) ?  "DEAD_PR"  : "?");
      printf("%-7ld %-6s %-5s %-10s ",
      	    (long) ut->ut_pid, ut->ut_line, ut->ut_id, ut->ut_host);
      printf("%s", ctime((time_t *) &(ut->ut_tv.tv_sec)));
   }
   
   endutxent();
   
   exit(EXIT_SUCCESS);
}
Exemplo n.º 7
0
/**
   goodNumberOfUsers method for SunOS implementation of OS Provider

   Goes through the utents, counting the number of type USER_PROCESS
   Works in isolated test env without new users logging in
  */
Boolean OSTestClient::goodNumberOfUsers(
    const Uint32 &nusers,
    Boolean verbose)
{
   struct utmpx * utmpp;
   Uint32 numberOfUsers;

   if (verbose)
      cout<<"Checking NumberOfUsers " << nusers << endl;

   numberOfUsers = 0;

// ATTN-SLC-P3-17-Apr-02: optimization? parse uptime instead?

   while ((utmpp = getutxent()) != NULL)
   {
       if (utmpp->ut_type == USER_PROCESS)
       {
           numberOfUsers++;
       }
   }

   endutxent();
   if (verbose)
      cout << " Should be " << numberOfUsers << endl;

// works in isolated test env without new users logging in
   return (nusers == numberOfUsers);
}
Exemplo n.º 8
0
/*
Show utmp information via getutxent(3)
@function utmp
@return information (TABLE)
*/
static int
Futmp(lua_State *L)
{
	struct utmpx *utx = {0};
	setutxent();
	lua_createtable(L, 0, 7);
	while ((utx = getutxent())) {
		lua_pushstring(L, utx->ut_user);
		lua_setfield(L, -2, "user");
		lua_pushstring(L, utx->ut_line);
		lua_setfield(L, -2, "tty");
		lua_pushstring(L, utx->ut_host);
		lua_setfield(L, -2, "hostname");
		lua_pushnumber(L, (float)utx->ut_tv.tv_sec);
		lua_setfield(L, -2, "timestamp");
		lua_pushboolean(L, utx->ut_type & USER_PROCESS);
		lua_setfield(L, -2, "user_process");
		lua_pushboolean(L, utx->ut_type & INIT_PROCESS);
		lua_setfield(L, -2, "init_process");
		lua_pushboolean(L, utx->ut_type & LOGIN_PROCESS);
		lua_setfield(L, -2, "login_process");
	}
	endutxent();
	return 1;
}
Exemplo n.º 9
0
/*
 * Return users currently connected on the system.
 */
static PyObject *
psutil_users(PyObject *self, PyObject *args) {
    struct utmpx *ut;
    PyObject *py_tuple = NULL;
    PyObject *py_username = NULL;
    PyObject *py_tty = NULL;
    PyObject *py_hostname = NULL;
    PyObject *py_user_proc = NULL;
    PyObject *py_retlist = PyList_New(0);

    if (py_retlist == NULL)
        return NULL;

    setutxent();
    while (NULL != (ut = getutxent())) {
        if (ut->ut_type == USER_PROCESS)
            py_user_proc = Py_True;
        else
            py_user_proc = Py_False;
        py_username = PyUnicode_DecodeFSDefault(ut->ut_user);
        if (! py_username)
            goto error;
        py_tty = PyUnicode_DecodeFSDefault(ut->ut_line);
        if (! py_tty)
            goto error;
        py_hostname = PyUnicode_DecodeFSDefault(ut->ut_host);
        if (! py_hostname)
            goto error;
        py_tuple = Py_BuildValue(
            "(OOOfOi)",
            py_username,              // username
            py_tty,                   // tty
            py_hostname,              // hostname
            (float)ut->ut_tv.tv_sec,  // tstamp
            py_user_proc,             // (bool) user process
            ut->ut_pid                // process id
        );
        if (py_tuple == NULL)
            goto error;
        if (PyList_Append(py_retlist, py_tuple))
            goto error;
        Py_DECREF(py_username);
        Py_DECREF(py_tty);
        Py_DECREF(py_hostname);
        Py_DECREF(py_tuple);
    }
    endutxent();

    return py_retlist;

error:
    Py_XDECREF(py_username);
    Py_XDECREF(py_tty);
    Py_XDECREF(py_hostname);
    Py_XDECREF(py_tuple);
    Py_DECREF(py_retlist);
    endutxent();
    return NULL;
}
Exemplo n.º 10
0
int who_main(int argc UNUSED_PARAM, char **argv)
{
	struct utmpx *ut;
	unsigned opt;
	int do_users = (ENABLE_USERS && (!ENABLE_WHO || applet_name[0] == 'u'));
	const char *fmt = "%s";

	opt_complementary = "=0";
	opt = getopt32(argv, do_users ? "" : "aH");
	if (opt & 2) // -H
		puts("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST");

	setutxent();
	while ((ut = getutxent()) != NULL) {
		if (ut->ut_user[0]
		 && ((opt & 1) || ut->ut_type == USER_PROCESS)
		) {
			if (!do_users) {
				char str6[6];
				char name[sizeof("/dev/") + sizeof(ut->ut_line) + 1];
				struct stat st;
				time_t seconds;

				str6[0] = '?';
				str6[1] = '\0';
				strcpy(name, "/dev/");
				safe_strncpy(ut->ut_line[0] == '/' ? name : name + sizeof("/dev/")-1,
					ut->ut_line,
					sizeof(ut->ut_line)+1
				);
				if (stat(name, &st) == 0)
					idle_string(str6, st.st_atime);
				/* manpages say ut_tv.tv_sec *is* time_t,
				 * but some systems have it wrong */
				seconds = ut->ut_tv.tv_sec;
				/* How wide time field can be?
				 * "Nov 10 19:33:20": 15 chars
				 * "2010-11-10 19:33": 16 chars
				 */
				printf("%-15.*s %-15.*s %-7s %-16.16s %.*s\n",
						(int)sizeof(ut->ut_user), ut->ut_user,
						(int)sizeof(ut->ut_line), ut->ut_line,
						str6,
						ctime(&seconds) + 4,
						(int)sizeof(ut->ut_host), ut->ut_host
				);
			} else {
				printf(fmt, ut->ut_user);
				fmt = " %s";
			}
		}
	}
	if (do_users)
		bb_putchar('\n');
	if (ENABLE_FEATURE_CLEAN_UP)
		endutxent();
	return EXIT_SUCCESS;
}
Exemplo n.º 11
0
static int _userinfo_generic(unsigned int * userinfo)
{
	struct utmpx * ut;

	for(*userinfo = 0; (ut = getutxent()) != NULL;)
		if(ut->ut_type == USER_PROCESS)
			(*userinfo)++;
	endutxent();
	return 0;
}
Exemplo n.º 12
0
struct utmpx *getutxline(struct utmpx *ut) {
  struct utmpx *tmp;

  while ((tmp = getutxent())) {
    if ((tmp->ut_type == USER_PROCESS) || (tmp->ut_type == LOGIN_PROCESS)) {
      if (!strncmp(ut->ut_line,tmp->ut_line,__UT_LINESIZE)) break;
    }
  }
  return tmp;
}
Exemplo n.º 13
0
static int users_read (void)
{
#if HAVE_GETUTXENT
	unsigned int users = 0;
	struct utmpx *entry = NULL;

	/* according to the *utent(3) man page none of the functions sets errno
	   in case of an error, so we cannot do any error-checking here */
	setutxent();

	while (NULL != (entry = getutxent())) {
		if (USER_PROCESS == entry->ut_type) {
			++users;
		}
	}
	endutxent();

	users_submit (users);
/* #endif HAVE_GETUTXENT */
	
#elif HAVE_GETUTENT
	unsigned int users = 0;
	struct utmp *entry = NULL;

	/* according to the *utent(3) man page none of the functions sets errno
	   in case of an error, so we cannot do any error-checking here */
	setutent();

	while (NULL != (entry = getutent())) {
		if (USER_PROCESS == entry->ut_type) {
			++users;
		}
	}
	endutent();

	users_submit (users);
/* #endif HAVE_GETUTENT */

#elif HAVE_LIBSTATGRAB
	sg_user_stats *us;

	us = sg_get_user_stats ();
	if (us == NULL)
		return (-1);   

	users_submit ((gauge_t) us->num_entries);
/* #endif HAVE_LIBSTATGRAB */

#else
# error "No applicable input method."
#endif

	return (0);
} /* int users_read */
Exemplo n.º 14
0
static void
single(const char *cmd, char *ttyn)
{
	struct utmpx	*u;
	char		found = B_FALSE;

	if (ttyn == NULL)
		ttyn = findttyname(STDIN_FILENO);

	/*
	 * utmpx records on the console device are expected to be "console"
	 * by other processes, such as dtlogin.
	 */
	ttyn = stripttyname(ttyn);

	/* update the utmpx file. */
	while ((u = getutxent()) != NULL) {
		if (strcmp(u->ut_line, ttyn) == 0) {
			u->ut_tv.tv_sec = time(NULL);
			u->ut_type = USER_PROCESS;
			u->ut_pid = getpid();
			if (strcmp(u->ut_user, "root") != 0)
				(void) strcpy(u->ut_user, "root");
			(void) pututxline(u);
			found = B_TRUE;
			break;
		}
	}
	if (!found) {
		struct utmpx entryx;

		entryx.ut_tv.tv_sec = time(NULL);
		entryx.ut_type = USER_PROCESS;
		entryx.ut_pid = getpid();
		(void) strcpy(entryx.ut_user, "root");
		(void) strcpy(entryx.ut_line, ttyn);
		entryx.ut_tv.tv_usec = 0;
		entryx.ut_session = 0;
		entryx.ut_id[0] = 'c';
		entryx.ut_id[1] = 'o';
		entryx.ut_id[2] = 's';
		entryx.ut_id[3] = 'u';
		entryx.ut_syslen = 1;
		entryx.ut_host[0] = '\0';
		entryx.ut_exit.e_termination = WTERMSIG(0);
		entryx.ut_exit.e_exit = WEXITSTATUS(0);
		(void) pututxline(&entryx);
	}
	endutxent();
	(void) printf("Entering System Maintenance Mode\n\n");

	if (execl(cmd, cmd, "-", (char *)0) < 0)
		exit(EXIT_FAILURE);
}
Exemplo n.º 15
0
static PyObject* pyutmpx(PyObject* self, PyObject* args)
{

    PyObject *ret = PyList_New(0);
    PyObject *l_utmp = PyList_New(0);
    PyObject *l_wtmp = PyList_New(0);
    struct utmpx *ut;
    
    setutxdb(UTXDB_ACTIVE, UTX_ACTIVE);
    while ((ut = getutxent()) != NULL) PyList_Append(l_utmp, Py_BuildValue("sssi", ut->ut_line, ut->ut_user, ut->ut_host, ut->ut_tv));
    endutxent();

    setutxdb(UTXDB_LOG, UTX_LOG);
    while ((ut = getutxent()) != NULL) PyList_Append(l_wtmp, Py_BuildValue("sssi", ut->ut_line, ut->ut_user, ut->ut_host, ut->ut_tv));
    endutxent();

    PyList_Append(ret, Py_BuildValue("N", l_utmp));
    PyList_Append(ret, Py_BuildValue("N", l_wtmp));
    return Py_BuildValue("N", ret);
}
Exemplo n.º 16
0
static void
process_utmp(void)
{
	struct utmpx *utx;

	while ((utx = getutxent()) != NULL) {
		if (((aflag || !bflag) && utx->ut_type == USER_PROCESS) ||
		    (bflag && utx->ut_type == BOOT_TIME))
			if (ttystat(utx->ut_line) == 0)
				row(utx);
	}
}
Exemplo n.º 17
0
int
main (int argc, char **argv)
{
	int users = -1;
	int result = STATE_UNKNOWN;
	char *perf;
	struct utmpx *putmpx;

	setlocale (LC_ALL, "");
	bindtextdomain (PACKAGE, LOCALEDIR);
	textdomain (PACKAGE);

	perf = strdup ("");

	/* Parse extra opts if any */
	argv = np_extra_opts (&argc, argv, progname);

	if (process_arguments (argc, argv) == ERROR)
		usage4 (_("Could not parse arguments"));

	users = 0;

	/* get currently logged users from utmpx */
	setutxent ();

	while ((putmpx = getutxent ()) != NULL)
		if (putmpx->ut_type == USER_PROCESS)
			users++;

	endutxent ();

	/* check the user count against warning and critical thresholds */
	if (users > cusers)
		result = STATE_CRITICAL;
	else if (users > wusers)
		result = STATE_WARNING;
	else if (users >= 0)
		result = STATE_OK;

	if (result == STATE_UNKNOWN)
		printf ("%s\n", _("Unable to read output"));
	else {
		asprintf (&perf, "%s", perfdata ("users", users, "",
		  TRUE, wusers,
		  TRUE, cusers,
		  TRUE, 0,
		  FALSE, 0));
		printf (_("USERS %s - %d users currently logged in |%s\n"), state_text (result),
		  users, perf);
	}

	return result;
}
Exemplo n.º 18
0
static void
process_utmp(void)
{
	struct utmpx *utx;

	while ((utx = getutxent()) != NULL) {
		if (utx->ut_type != USER_PROCESS)
			continue;
		if (ttystat(utx->ut_line) != 0)
			continue;
		row(utx);
	}
}
Exemplo n.º 19
0
struct utmpx *getutxid(struct utmpx *ut) {
  struct utmpx *tmp;

  while ((tmp = getutxent())) {
    if (ut->ut_type && (ut->ut_type <= OLD_TIME)) {
      if (ut->ut_type == tmp->ut_type) break;
    }
    if ((ut->ut_type >= INIT_PROCESS) && (ut->ut_type <= DEAD_PROCESS)) {
      if (!strncmp(ut->ut_id,tmp->ut_id,4)) break;
    }
  }
  return tmp;
}
Exemplo n.º 20
0
/* calculate number of users on the system */
static int
ucount(void)
{
	int nusers = 0;
	struct utmpx *ut;

	setutxent();
	while ((ut = getutxent()) != NULL)
		if (ut->ut_type == USER_PROCESS)
			nusers++;
	endutxent();

	return (nusers);
}
Exemplo n.º 21
0
char* test_getlogin() {
    struct utmpx *ut;
    char *tty = ttyname(STDIN_FILENO);
    setutxent();
    while ((ut = getutxent()) != NULL) {
        if (strcmp(ut->ut_line, tty + 5) == 0) {
            strncpy(user, ut->ut_user, 255);
            user[255] = '\0';
            break;
        }
    }
    endutxent();
    return user;
}
Exemplo n.º 22
0
static int utmp_get_runlevel(struct lxc_utmp *utmp_data)
{
	#if HAVE_UTMPX_H
	struct utmpx *utmpx;
	#else
	struct utmp *utmpx;
	#endif
	char path[MAXPATHLEN];
	struct lxc_handler *handler = utmp_data->handler;

	if (snprintf(path, MAXPATHLEN, "/proc/%d/root/run/utmp",
		     handler->pid) > MAXPATHLEN) {
		ERROR("path is too long");
		return -1;
	}

	if (!access(path, F_OK) && !utmpxname(path))
		goto utmp_ok;

	if (snprintf(path, MAXPATHLEN, "/proc/%d/root/var/run/utmp",
		     handler->pid) > MAXPATHLEN) {
		ERROR("path is too long");
		return -1;
	}

	if (utmpxname(path)) {
		SYSERROR("failed to 'utmpxname'");
		return -1;
	}

utmp_ok:

	setutxent();

	while ((utmpx = getutxent())) {

		if (utmpx->ut_type == RUN_LVL) {
			utmp_data->prev_runlevel = utmpx->ut_pid / 256;
			utmp_data->curr_runlevel = utmpx->ut_pid % 256;
			DEBUG("utmp handler - run level is %c/%c",
			      utmp_data->prev_runlevel,
			      utmp_data->curr_runlevel);
		}
	}

	endutxent();

	return 0;
}
Exemplo n.º 23
0
/**
 * Get number of current users which are logged in
 */
static int
OS_getSystemNumUsers(uint32_t *nu)
{
	struct utmpx *utmp;

	setutxent();
	*nu = 0;
	while ((utmp = getutxent()) != NULL) {
		if (utmp->ut_type == USER_PROCESS)
			(*nu)++;
	}
	endutxent();

	return (SNMP_ERR_NOERROR);
}
Exemplo n.º 24
0
int
main(int argc, char **argv)
{
	struct utmpx *utmpx;

	setutxent();
	while ((utmpx = getutxent()) != NULL) {
		if (utmpx->ut_type == USER_PROCESS) {
			utmpx->ut_type = DEAD_PROCESS;
			time(&utmpx->ut_xtime);
			(void) updwtmpx(WTMPX_FILE, utmpx);
		}
	}
	endutxent();
	return (0);
}
Exemplo n.º 25
0
/*
 * Deactivates all entries if nfslogtab exists and is older than boot time
 * This will only happen the first time it is called.
 * Assumes 'fd' has been locked by the caller.
 * Returns 0 on success, otherwise -1.
 */
int
logtab_deactivate_after_boot(FILE *fd)
{
	struct stat st;
	struct utmpx *utmpxp;
	int error = 0;

	if ((fstat(fileno(fd), &st) == 0) &&
	    ((utmpxp = getutxent()) != NULL) &&
	    (utmpxp->ut_xtime > st.st_mtime)) {
		if (logtab_deactivate(fd, NULL, NULL, NULL))
			error = -1;
	}

	return (error);
}
Exemplo n.º 26
0
Arquivo: w.c Projeto: 0x6e3078/toybox
void w_main(void)
{
  struct utmpx *x;

  xprintf("USER     TTY             [email protected]              FROM");
  setutxent();
  while ((x=getutxent()) != NULL) {
    if (x->ut_type==7) {
      time_t tt = x->ut_tv.tv_sec;

      xprintf("\n%-9.8s%-9.8s %-4.24s (%-1.12s)", x->ut_user, x->ut_line,
        ctime(&tt), x->ut_host);
    }
  }
  xputc('\n');
}
Exemplo n.º 27
0
int
main(int argc, char *argv[])
{
    struct utmpx *ut;
    struct in_addr in;

    if (argc > 1 && strcmp(argv[1], "--help") == 0)
        usageErr("%s [utmp-pathname]\n", argv[0]);

    if (argc > 1)               /* Use alternate file if supplied */
        if (utmpxname(argv[1]) == -1)
            errExit("utmpxname");

    setutxent();

    printf("user     type            PID line   id  host     ");
    printf("term exit session  address         date/time\n");

    while ((ut = getutxent()) != NULL) {        /* Sequential scan to EOF */
        printf("%-8s ", ut->ut_user);
        printf("%-9.9s ",
                (ut->ut_type == EMPTY) ?         "EMPTY" :
                (ut->ut_type == RUN_LVL) ?       "RUN_LVL" :
                (ut->ut_type == BOOT_TIME) ?     "BOOT_TIME" :
                (ut->ut_type == NEW_TIME) ?      "NEW_TIME" :
                (ut->ut_type == OLD_TIME) ?      "OLD_TIME" :
                (ut->ut_type == INIT_PROCESS) ?  "INIT_PR" :
                (ut->ut_type == LOGIN_PROCESS) ? "LOGIN_PR" :
                (ut->ut_type == USER_PROCESS) ?  "USER_PR" :
                (ut->ut_type == DEAD_PROCESS) ?  "DEAD_PR" : "???");
        printf("(%1d) ", ut->ut_type);
        printf("%5ld %-6.6s %-3.5s %-9.9s ", (long) ut->ut_pid,
                ut->ut_line, ut->ut_id, ut->ut_host);
        printf("%3d %3d ", ut->ut_exit.e_termination, ut->ut_exit.e_exit);
        printf("%8ld ", (long) ut->ut_session);

        /* Display IPv4 address */

        in.s_addr = ut->ut_addr_v6[0];
        printf(" %-15.15s ", inet_ntoa(in));
        printf("%s", ctime((time_t *) &(ut->ut_tv.tv_sec)));
    }

    endutxent();
    exit(EXIT_SUCCESS);
}
Exemplo n.º 28
0
struct utmpx *
getutxid(const struct utmpx *utx)
{

	_DIAGASSERT(utx != NULL);

	if (utx->ut_type == EMPTY)
		return NULL;

	do {
		if (ut.ut_type == EMPTY)
			continue;
		switch (utx->ut_type) {
		case EMPTY:
			return NULL;
		case RUN_LVL:
		case BOOT_TIME:
		case OLD_TIME:
		case NEW_TIME:
			if (ut.ut_type == utx->ut_type)
				return &ut;
			break;
		case INIT_PROCESS:
		case LOGIN_PROCESS:
		case USER_PROCESS:
		case DEAD_PROCESS:
			switch (ut.ut_type) {
			case INIT_PROCESS:
			case LOGIN_PROCESS:
			case USER_PROCESS:
			case DEAD_PROCESS:
				if (memcmp(ut.ut_id, utx->ut_id,
				    sizeof(ut.ut_id)) == 0)
					return &ut;
				break;
			default:
				break;
			}
			break;
		default:
			return NULL;
		}
	} while (getutxent() != NULL);
	return NULL;
}
Exemplo n.º 29
0
int
main(int argc, char **argv)
{
	namebuf *names = NULL;
	int ncnt = 0;
	int nmax = 0;
	int cnt;
	struct utmpx *ut;
	int ch;

	while ((ch = getopt(argc, argv, "")) != -1)
		switch(ch) {
		case '?':
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	setutxent();
	while ((ut = getutxent()) != NULL) {
		if (ut->ut_type != USER_PROCESS)
			continue;
		if (ncnt >= nmax) {
			nmax += 32;
			names = realloc(names, sizeof(*names) * nmax);
			if (!names) {
				errx(1, "realloc");
				/* NOTREACHED */
			}
		}
		(void)strlcpy(names[ncnt], ut->ut_user, sizeof(*names));
		++ncnt;
	}
	endutxent();
	if (ncnt > 0) {
		qsort(names, ncnt, sizeof(namebuf), scmp);
		(void)printf("%s", names[0]);
		for (cnt = 1; cnt < ncnt; ++cnt)
			if (strcmp(names[cnt], names[cnt - 1]) != 0)
				(void)printf(" %s", names[cnt]);
		(void)printf("\n");
	}
	exit(0);
}
Exemplo n.º 30
0
Boolean OperatingSystem::getNumberOfUsers(Uint32& numberOfUsers)
{
    struct utmpx * utmpp;

    numberOfUsers = 0;

    while ((utmpp = getutxent()) != NULL)
    {
        if (utmpp->ut_type == USER_PROCESS)
        {
            numberOfUsers++;
        }
    }

    endutxent();

    return true;
}