How to find the real uid/gid of a process?

dupuy at cs.columbia.edu dupuy at cs.columbia.edu
Thu Jun 6 00:17:00 AEST 1991


> I would like to determine the real uid and gid of each process, but can't
> seem to access them from each struct proc returned by kvm_nextproc();
> 
> Assuming:
> 	       struct proc theproc;
> 
> when I attempt to access theproc->p_cred I get a Memory Fault, and when I
> access it as root I get a Segv.

This is because theproc->p_cred is a pointer which is valid in the kernel's
address space - not in your process's address space.  You should use kvm_read
to get the data:

	kvm_t kmem = kvm_open(NULL, NULL, NULL, O_RDONLY, argv[0])
	struct proc *theproc = kvm_nextproc(kmem);
	struct ucred *cred = malloc (sizeof struct ucred);

	kvm_read(kmem, theproc->p_cred, cred, sizeof struct ucred);
	theproc->p_cred = cred;

@alex
--
inet: dupuy at cs.columbia.edu




More information about the Comp.sys.sun mailing list