Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 02 Jul 1996 00:02:06 +0900
From:      Masachika ISHIZUKA <ishizuka@isis.min.ntt.jp>
To:        ports@freebsd.org
Subject:   pidentd-2.7b3
Message-ID:  <199607011502.AAA01326@pumpkin.min.ntt.jp>

next in thread | raw e-mail | index | archive | help
  Hi.
  The pident-2.7b3 (and early versions) for FreeBSD does not show
a real ID. It shows an effective ID.
  I was fixed it.
----------------------------------------------------
% diff freebsd.c.orig freebsd.c
2c2
< ** kernel/other.c	Low level kernel access functions for FreeBSD 2.x
---
> ** kernel/freebsd.c		Low level kernel access functions for FreeBSD
7c7,9
< ** Last update: 11 April 1995 - torstenb@FreeBSD.ORG
---
> ** Last update: 18 Nov 1995
> **
> ** Please send bug fixes/bug reports to: Peter Eriksson <pen@lysator.liu.se>
9a12
> #include <paths.h>
10a14,15
> #include <errno.h>
> #include <ctype.h>
11a17,18
> #include <pwd.h>
> #include <signal.h>
15a23,24
> #include <sys/types.h>
> #include <sys/stat.h>
16a26
> #include <sys/ioctl.h>
20a31,32
> #include <sys/uio.h>
> 
25,26d36
< #include <fcntl.h>
< 
29,30c39,47
< #include <sys/resource.h>
< #include <sys/proc.h>
---
> #ifndef BSD4_4
> #  include <sys/kinfo.h>
> #else
> #  include <sys/sysctl.h>
> #  define KINFO_PROC_ALL KERN_PROC_ALL
> #endif
> 
> #include <fcntl.h>
> 
31a49
> 
33a52,58
> #include <sys/filedesc.h>
> #include <sys/proc.h>
> 
> #ifndef BSD4_4
> #  include <sys/kinfo_proc.h>
> #endif
> 
40c65
<  
---
> 
45,47d69
<  
< #include <netinet/tcpip.h>
<  
52a75,76
> #include <pwd.h>
> 
56,58d79
< #ifdef INPLOOKUP_SETLOCAL
< #define	_HAVE_OLD_INPCB
< #endif
66c87
< #define N_FILE 0  
---
> #define N_FILE 0
69c90
< 
---
>       
76d96
< static kvm_t *kd;
79d98
< 
82d100
< #ifdef _HAVE_OLD_INPCB
84,86c102
< #else
< static struct inpcbhead tcb;
< #endif
---
> static kvm_t *kd = NULL;
93c109
<   if (!(kd = kvm_open(path_unix, path_kmem, NULL, O_RDONLY, NULL)))
---
>   if ((kd = (kvm_t *)kvm_openfiles(path_unix, path_kmem, NULL, O_RDONLY, NULL)) == NULL)
99c115
<   if (kvm_nlist(kd, nl) != 0) 
---
>   if (kvm_nlist(kd, nl) < 0)
102d117
< 
112,115c127,130
<   long addr;
<   char *buf;
<   int len;
<   char *what;
---
>      long addr;
>      char *buf;
>      int len;
>      char *what;
117d131
< 
119,122c133,139
<   {
<     if (syslog_flag)
<       syslog(LOG_DEBUG,"getbuf: kvm_read(%08x, %d) - %s : %m",
< 	     addr, len, what);
---
>     {
>       if (syslog_flag)
> 	syslog(LOG_ERR, "getbuf: kvm_read(%08x, %d) - %s : %m",
> 	       addr, len, what);
> 
>       return 0;
>     }
124,126d140
<     return 0;
<   }
<   
130,131d143
< 
< 
169c181
<   {
---
>     {
172,174c184,186
< 	 pcbp->inp_laddr.s_addr == laddr->s_addr &&
< 	 pcbp->inp_fport        == fport &&
< 	 pcbp->inp_lport        == lport )
---
>          pcbp->inp_laddr.s_addr == laddr->s_addr &&
>          pcbp->inp_fport        == fport &&
>          pcbp->inp_lport        == lport )
177,180c189,192
< 	   getbuf((long) pcbp->inp_next,
< 		  pcbp,
< 		  sizeof(struct inpcb),
< 		  "tcblist"));
---
>            getbuf((long) pcbp->inp_next,
>                   pcbp,
>                   sizeof(struct inpcb),
>                   "tcblist"));
185,187c197,199
< 	pcbp.inp_fport        == fport &&
< 	pcbp.inp_lport        == lport )
< 	return(pcbp.inp_socket);
---
>         pcbp.inp_fport        == fport &&
>         pcbp.inp_lport        == lport )
>         return(pcbp.inp_socket);
189c201
<   } while (head != NULL);
---
> } while (head != NULL);
195,196d206
< 
< 
210,212c220,221
<   struct ucred ucb;
<  
<   /* -------------------- FILE DESCRIPTOR TABLE -------------------- */
---
>   struct kinfo_proc	*kp;
>   int			nentries;
214,218c223,227
<   char	*filebuf;
<   filebuf=kvm_getfiles(kd,KERN_FILE,0,&nfile);
<   if(filebuf==0)
<      ERROR("k_getuid: out of memory (file table)");
<   xfile = (struct file *)(filebuf + sizeof (struct file *));
---
>   if ((kp = kvm_getprocs(kd, KINFO_PROC_ALL, 0, &nentries)) == NULL)
>   {
>     ERROR("k_getuid: kvm_getprocs");
>     return -1;
>   }
223c232
<   
---
> 
228c237
<  
---
> 
236c245
<   for (i = 0; i < nfile; i++)
---
>   for (i = 0; i < nentries; i++)
238,242c247
<     if (xfile[i].f_count == 0)
<       continue;
< 
<     if (xfile[i].f_type == DTYPE_SOCKET &&
< 	(struct socket *) xfile[i].f_data == sockp)
---
>     if(kp[i].kp_proc.p_fd != NULL)
244,247c249,289
<       if (!getbuf(xfile[i].f_cred, &ucb, sizeof(ucb), "ucb"))
< 	return -1;
< 
<       *uid = ucb.cr_uid;
---
>       int				j;
>       struct filedesc	pfd;
>       struct file		**ofiles;
>       struct file		ofile;
> 
>       if(!getbuf(kp[i].kp_proc.p_fd, &pfd, sizeof(pfd), "pfd"))
>         return(-1);
> 
>       ofiles = (struct file **) malloc(pfd.fd_nfiles * sizeof(struct file *));
> 
>       if(!getbuf(pfd.fd_ofiles, ofiles,
>                  pfd.fd_nfiles * sizeof(struct file *), "ofiles"))
>       {
>         free(ofiles);
>         return(-1);
>       }
> 
>       for(j = 0; j < pfd.fd_nfiles; j ++)
>       {
>         if(!getbuf(ofiles[j], &ofile, sizeof(struct file), "ofile"))
>         {
>           free(ofiles);
>           return(-1);
>         }
> 
>         if(ofile.f_count == 0)
>           continue;
> 
>         if(ofile.f_type == DTYPE_SOCKET &&
>            (struct socket *) ofile.f_data == sockp)
>         {
>           struct pcred	pc;
> 
>           if(!getbuf(kp[i].kp_proc.p_cred, &pc, sizeof(pc), "pcred"))
>             return(-1);
> 
>           *uid = pc.p_ruid;
>           free(ofiles);
>           return 0;
>         }
>       }
249c291
<       return 0;
---
>       free(ofiles);
252c294
<   
---
> 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199607011502.AAA01326>