[comp.sys.hp] How can I know his current group ID?

kitano@judy.pa.Yokogawa.CO.JP (Kinichi "Kinchan" Kitano) (04/23/91)

Hello. I use HP9000/800 with HP-UX7.0.  What I want to know is the
group ID of every person who is logging in the system.

So foo belongs to several groups(A,B,C). Before he does job X, he
does newgrp A and he works under group ID A.

I want a command, say wgrp, which returns a current group ID of
a user. The result would be like this.


     foo                        me

     $ newgrp A
                                $ wgrp foo
                                A
  
     $ newgrp B

                                $ wgrp foo
                                B

I checked manual of who and ps but had no luck.

Command with little known options, shell script(with awk,perl) or C
program: any solutions will be fine.

Of cource, HP specific solutions are welcome.

thanks in advance.

--
====================================================================
	Kinichi Kitano		(kitano@pa.yokogawa.co.pa)
=====================================================================
	

darrylo@hpnmdla.hp.com (Darryl Okahata) (04/24/91)

In comp.sys.hp, kitano@judy.pa.Yokogawa.CO.JP (Kinichi "Kinchan" Kitano) writes:

> Hello. I use HP9000/800 with HP-UX7.0.  What I want to know is the
> group ID of every person who is logging in the system.

     See the man page for id(1).

     -- Darryl Okahata
	UUCP: {hplabs!, hpcea!, hpfcla!} hpnmd!darrylo
	Internet: darrylo%hpnmd@relay.hp.com

DISCLAIMER: this message is the author's personal opinion and does not
constitute the support, opinion or policy of Hewlett-Packard or of the
little green men that have been following him all day.

stroyan@hpfcso.FC.HP.COM (Mike Stroyan) (04/24/91)

>So foo belongs to several groups(A,B,C). Before he does job X, he
>does newgrp A and he works under group ID A.
>
>I want a command, say wgrp, which returns a current group ID of
>a user. The result would be like this.

The situation is not as simple as you think.  The group id is a property
of each process, rather than a property of each user.  When a user
executes "newgrp A", a new shell process is started with the requested
group id.  Rather than showing the group id of a user, the best a "wgrp"
command could do would be to show the group id of one or more processes.

There is no simple kernel call that determines the group id of another
process.  The two possible approaches that occur to me would be to use
the ptrace call or to read /dev/kmem.  A ptrace(PT_ATTACH,...) call can
be done by a super-user process to other processes.  Then a
ptrace(PT_RUAREA,...) call can be made to read the USER area of the
process.  As I understand it, this is not actually practical because
ptrace will not work on processes that are shared text and are running
in multiple processes.

The other approach would be to get the data by reading /dev/kmem and
digging out the process data from the kernel image.  I have no experience
with this kind of program.  It is a very system dependent exercise which
probably shouldn't be attempted without kernel sources.

Mike Stroyan, mike_stroyan@fc.hp.com