Blame sysdeps/solaris/procuid.c

Packit Service 407539
/* Copyright (C) 1998-99 Martin Baulig
Packit Service 407539
   This file is part of LibGTop 1.0.
Packit Service 407539
Packit Service 407539
   Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
Packit Service 407539
Packit Service 407539
   LibGTop is free software; you can redistribute it and/or modify it
Packit Service 407539
   under the terms of the GNU General Public License as published by
Packit Service 407539
   the Free Software Foundation; either version 2 of the License,
Packit Service 407539
   or (at your option) any later version.
Packit Service 407539
Packit Service 407539
   LibGTop is distributed in the hope that it will be useful, but WITHOUT
Packit Service 407539
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
Packit Service 407539
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
Packit Service 407539
   for more details.
Packit Service 407539
Packit Service 407539
   You should have received a copy of the GNU General Public License
Packit Service 407539
   along with LibGTop; see the file COPYING. If not, write to the
Packit Service 407539
   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Packit Service 407539
   Boston, MA 02110-1301, USA.
Packit Service 407539
*/
Packit Service 407539
Packit Service 407539
#include <config.h>
Packit Service 407539
#include <glibtop.h>
Packit Service 407539
#include <glibtop/procuid.h>
Packit Service 407539
Packit Service 407539
#include <glibtop_private.h>
Packit Service 407539
Packit Service 407539
static const unsigned long _glibtop_sysdeps_proc_uid_psinfo =
Packit Service 407539
(1L << GLIBTOP_PROC_UID_EUID) + (1L << GLIBTOP_PROC_UID_UID) +
Packit Service 407539
(1L << GLIBTOP_PROC_UID_EGID) + (1L << GLIBTOP_PROC_UID_GID) +
Packit Service 407539
(1L << GLIBTOP_PROC_UID_PID) + (1L << GLIBTOP_PROC_UID_PPID) +
Packit Service 407539
(1L << GLIBTOP_PROC_UID_PGRP) + (1L << GLIBTOP_PROC_UID_SESSION) +
Packit Service 407539
(1L << GLIBTOP_PROC_UID_TTY) + (1L << GLIBTOP_PROC_UID_PRIORITY) +
Packit Service 407539
(1L << GLIBTOP_PROC_UID_NICE);
Packit Service 407539
static const unsigned long _glibtop_sysdeps_proc_uid_prcred =
Packit Service 407539
#if LIBGTOP_VERSION_CODE >= 1001002
Packit Service 407539
#ifdef HAVE_PROCFS_H
Packit Service 407539
(1L << GLIBTOP_PROC_UID_GROUPS) +
Packit Service 407539
#endif
Packit Service 407539
(1L << GLIBTOP_PROC_UID_SUID) + (1L << GLIBTOP_PROC_UID_SGID) +
Packit Service 407539
(1L << GLIBTOP_PROC_UID_NGROUPS);
Packit Service 407539
#else
Packit Service 407539
0;
Packit Service 407539
#endif
Packit Service 407539
/* Init function. */
Packit Service 407539
Packit Service 407539
void
Packit Service 407539
_glibtop_init_proc_uid_s (glibtop *server)
Packit Service 407539
{
Packit Service 407539
	server->sysdeps.proc_uid = _glibtop_sysdeps_proc_uid_psinfo +
Packit Service 407539
	   			   _glibtop_sysdeps_proc_uid_prcred;
Packit Service 407539
}
Packit Service 407539
Packit Service 407539
/* Provides detailed information about a process. */
Packit Service 407539
Packit Service 407539
void
Packit Service 407539
glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
Packit Service 407539
{
Packit Service 407539
#if LIBGTOP_VERSION_CODE >= 1001002
Packit Service 407539
	struct prcred prcred;
Packit Service 407539
#endif
Packit Service 407539
#ifdef HAVE_PROCFS_H
Packit Service 407539
	struct psinfo psinfo;
Packit Service 407539
#if LIBGTOP_VERSION_CODE >= 1001002
Packit Service 407539
	gid_t groups[GLIBTOP_MAX_GROUPS];
Packit Service 407539
#endif
Packit Service 407539
#else
Packit Service 407539
	struct prpsinfo psinfo;
Packit Service 407539
	gid_t groups[1];	/* dummy for consistent function prototype */
Packit Service 407539
#endif
Packit Service 407539
Packit Service 407539
	memset (buf, 0, sizeof (glibtop_proc_uid));
Packit Service 407539
Packit Service 407539
	if (glibtop_get_proc_data_psinfo_s (server, &psinfo, pid))
Packit Service 407539
		return;
Packit Service 407539
Packit Service 407539
	buf->euid = psinfo.pr_euid;
Packit Service 407539
	buf->uid = psinfo.pr_uid;
Packit Service 407539
	buf->egid = psinfo.pr_egid;
Packit Service 407539
	buf->gid = psinfo.pr_gid;
Packit Service 407539
Packit Service 407539
	buf->pid = psinfo.pr_pid;
Packit Service 407539
	buf->ppid = psinfo.pr_ppid;
Packit Service 407539
#ifdef HAVE_PROCFS_H
Packit Service 407539
	buf->pgrp = psinfo.pr_pgid;
Packit Service 407539
#else
Packit Service 407539
	buf->pgrp = psinfo.pr_pgrp;
Packit Service 407539
#endif
Packit Service 407539
Packit Service 407539
	buf->session = psinfo.pr_sid;
Packit Service 407539
	buf->tty = psinfo.pr_ttydev;
Packit Service 407539
Packit Service 407539
#ifdef HAVE_PROCFS_H
Packit Service 407539
	buf->priority = psinfo.pr_lwp.pr_pri;
Packit Service 407539
	buf->nice = psinfo.pr_lwp.pr_nice - NZERO;
Packit Service 407539
#else
Packit Service 407539
	buf->priority = psinfo.pr_pri;
Packit Service 407539
	buf->nice = psinfo.pr_nice - NZERO;
Packit Service 407539
#endif
Packit Service 407539
Packit Service 407539
	buf->flags = _glibtop_sysdeps_proc_uid_psinfo;
Packit Service 407539
Packit Service 407539
#if LIBGTOP_VERSION_CODE >= 1001002
Packit Service 407539
	if(glibtop_get_proc_credentials_s(server, &prcred, groups, pid))
Packit Service 407539
		return;
Packit Service 407539
Packit Service 407539
	buf->suid = prcred.pr_suid;
Packit Service 407539
	buf->sgid = prcred.pr_sgid;
Packit Service 407539
	buf->ngroups = (prcred.pr_ngroups <= GLIBTOP_MAX_GROUPS) ?
Packit Service 407539
	   		prcred.pr_ngroups : GLIBTOP_MAX_GROUPS;
Packit Service 407539
Packit Service 407539
#ifdef HAVE_PROCFS_H
Packit Service 407539
	if(sizeof(int) == sizeof(gid_t))
Packit Service 407539
	   	memcpy(buf->groups, &groups, buf->ngroups * sizeof(gid_t));
Packit Service 407539
	else
Packit Service 407539
	{
Packit Service 407539
	   	int i;
Packit Service 407539
Packit Service 407539
		for(i = 0; i < buf->ngroups; ++i)
Packit Service 407539
		   	buf->groups[i] = groups[i];
Packit Service 407539
	}
Packit Service 407539
#endif
Packit Service 407539
#endif
Packit Service 407539
Packit Service 407539
	buf->flags += _glibtop_sysdeps_proc_uid_prcred;
Packit Service 407539
}