diff options
| author | christos <christos@NetBSD.org> | 2003-04-19 20:57:35 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2003-04-19 20:57:35 +0000 |
| commit | 99437fe16fa30b2eb26c0caaf5e0e719d3655fb5 (patch) | |
| tree | 18b9a876a9dd9b58dcc3250a4c2ae4141a1f5f10 /libexec/identd | |
| parent | 6141355bbc825713e9b8384a55316b99f457398f (diff) | |
PR/2352: Tor Egge: Use sysctl to get uid.
Diffstat (limited to 'libexec/identd')
| -rw-r--r-- | libexec/identd/Makefile | 4 | ||||
| -rw-r--r-- | libexec/identd/identd.c | 17 | ||||
| -rw-r--r-- | libexec/identd/netbsd.c | 183 |
3 files changed, 32 insertions, 172 deletions
diff --git a/libexec/identd/Makefile b/libexec/identd/Makefile index e83bc2d6c03..f77725b74fb 100644 --- a/libexec/identd/Makefile +++ b/libexec/identd/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.8 2002/11/30 03:18:45 lukem Exp $ +# $NetBSD: Makefile,v 1.9 2003/04/19 20:57:35 christos Exp $ PROG= identd MAN= identd.8 @@ -7,8 +7,6 @@ CPPFLAGS+= -DINCLUDE_EXTENSIONS -DSTRONG_LOG -DALLOW_FORMAT .ifdef DEFAULT_LIE_USER CPPFLAGS+= -DDEFAULT_LIE_USER=\"${DEFAULT_LIE_USER}\" .endif -LDADD+= -lkvm -DPADD+= ${LIBKVM} SRCS= netbsd.c version.c proxy.c config.c parse.c identd.c diff --git a/libexec/identd/identd.c b/libexec/identd/identd.c index 2490158f662..07840f1422e 100644 --- a/libexec/identd/identd.c +++ b/libexec/identd/identd.c @@ -1,4 +1,4 @@ -/* $NetBSD: identd.c,v 1.16 2002/09/23 12:48:02 mycroft Exp $ */ +/* $NetBSD: identd.c,v 1.17 2003/04/19 20:57:36 christos Exp $ */ /* ** identd.c A TCP/IP link identification protocol server @@ -388,11 +388,6 @@ int main(argc,argv) case 'l': /* Use the Syslog daemon for logging */ syslog_flag++; -#ifdef LOG_DAEMON - openlog("identd", LOG_PID, syslog_facility); -#else - openlog("identd", LOG_PID); -#endif break; case 'o': @@ -640,6 +635,16 @@ int main(argc,argv) ERROR2("main: setuid failed: wanted %d, got EUID %d", set_uid, geteuid()); } + if (syslog_flag) { +#ifdef LOG_DAEMON + openlog("identd", LOG_PID, syslog_facility); +#else + openlog("identd", LOG_PID); +#endif + } + (void)getpwnam("xyzzy"); + (void)gethostbyname("xyzzy"); + /* ** Do some special handling if the "-b" or "-w" flags are used */ diff --git a/libexec/identd/netbsd.c b/libexec/identd/netbsd.c index 9dbcf34bbed..cfb0b11794d 100644 --- a/libexec/identd/netbsd.c +++ b/libexec/identd/netbsd.c @@ -1,4 +1,4 @@ -/* $NetBSD: netbsd.c,v 1.15 2003/02/02 02:31:14 christos Exp $ */ +/* $NetBSD: netbsd.c,v 1.16 2003/04/19 20:57:36 christos Exp $ */ /* ** netbsd.c Low level kernel access functions for NetBSD @@ -23,7 +23,6 @@ #include <signal.h> #include <syslog.h> -#include "kvm.h" #include <sys/stat.h> #include <sys/param.h> @@ -65,108 +64,13 @@ #include "error.h" -struct nlist nl[] = -{ -#define N_FILE 0 -#define N_NFILE 1 -#define N_TCBTABLE 2 - - { "_filehead" }, - { "_nfiles" }, - { "_tcbtable" }, - { "" } -}; - -static kvm_t *kd; - -static struct file *xfile; -static int nfile; - -static struct inpcbtable tcbtable; - -static int getbuf __P((long, char *, int, char *)); -static struct socket *getlist __P((struct inpcbtable *, struct inpcbtable *, - struct in_addr *, int, struct in_addr *, int)); - int k_open() { - char errbuf[_POSIX2_LINE_MAX]; - - /* - ** Open the kernel memory device - */ - if ((kd = kvm_openfiles(path_unix, path_kmem, NULL, O_RDONLY, errbuf)) == - NULL) - ERROR1("main: kvm_open: %s", errbuf); - - /* - ** Extract offsets to the needed variables in the kernel - */ - if (kvm_nlist(kd, nl) < 0) - ERROR("main: kvm_nlist"); - return 0; } /* -** Get a piece of kernel memory with error handling. -** Returns 1 if call succeeded, else 0 (zero). -*/ -static int getbuf(addr, buf, len, what) - long addr; - char *buf; - int len; - char *what; -{ - if (kvm_read(kd, addr, buf, len) != len) - { - if (syslog_flag) - syslog(LOG_ERR, "getbuf: kvm_read(%#lx, %d) - %s : %m", - addr, len, what); - - return 0; - } - - return 1; -} - - - -/* -** Traverse the inpcb list until a match is found. -** Returns NULL if no match. -*/ -static struct socket * -getlist(tcbtablep, ktcbtablep, faddr, fport, laddr, lport) - struct inpcbtable *tcbtablep, *ktcbtablep; - struct in_addr *faddr; - int fport; - struct in_addr *laddr; - int lport; -{ - struct inpcb *kpcbp, pcb; - - if (!tcbtablep) - return NULL; - - for (kpcbp = tcbtablep->inpt_queue.cqh_first; - kpcbp != (struct inpcb *)ktcbtablep; - kpcbp = pcb.inp_queue.cqe_next) { - if (!getbuf((long) kpcbp, (char *)&pcb, sizeof(struct inpcb), "tcb")) - break; - if (pcb.inp_faddr.s_addr == faddr->s_addr && - pcb.inp_laddr.s_addr == laddr->s_addr && - pcb.inp_fport == fport && - pcb.inp_lport == lport ) - return pcb.inp_socket; - } - return NULL; -} - - - -/* ** Return the user number for the connection owner */ int k_getuid(faddr, fport, laddr, lport, uid @@ -184,77 +88,30 @@ int k_getuid(faddr, fport, laddr, lport, uid char **cmd, **cmd_and_args; #endif { - long addr; - struct socket *sockp; - int i, mib[2]; - struct ucred ucb; - - /* -------------------- FILE DESCRIPTOR TABLE -------------------- */ - if (!getbuf(nl[N_NFILE].n_value, (char *)&nfile, sizeof(nfile), "nfile")) - return -1; + int mib[4]; + uid_t myuid = -1; + size_t uidlen; + struct sysctl_tcp_ident_args args; + int rv; - if (!getbuf(nl[N_FILE].n_value, (char *)&addr, sizeof(addr), "&file")) - return -1; + mib[0] = CTL_NET; + mib[1] = PF_INET; + mib[2] = IPPROTO_TCP; + mib[3] = TCPCTL_IDENT; - { - size_t siz; - int rv; + args.raddr = *faddr; + args.rport = fport; + args.laddr = *laddr; + args.lport = lport; - mib[0] = CTL_KERN; - mib[1] = KERN_FILE; - if ((rv = sysctl(mib, 2, NULL, &siz, NULL, 0)) == -1) + uidlen = sizeof(myuid); + + if ((rv = sysctl(mib, 4, &myuid, &uidlen, &args,sizeof(args)))== -1) { ERROR1("k_getuid: sysctl 1 (%d)", rv); return -1; } - xfile = malloc(siz); - if (!xfile) - ERROR1("k_getuid: malloc(%ld)", (u_long)siz); - if ((rv = sysctl(mib, 2, xfile, &siz, NULL, 0)) == -1) - { - ERROR1("k_getuid: sysctl 2 (%d)", rv); - return -1; - } - xfile = (struct file *)((char *)xfile + sizeof(filehead)); - } - - /* -------------------- TCP PCB LIST -------------------- */ - if (!getbuf(nl[N_TCBTABLE].n_value, (char *)&tcbtable, sizeof(tcbtable), - "tcbtable")) - return -1; - - sockp = getlist(&tcbtable, (struct inpcbtable *)nl[N_TCBTABLE].n_value, - faddr, fport, laddr, lport); - - if (!sockp) - return -1; - -#ifdef ALLOW_FORMAT - *pid = 0; /* sorry, currently not implemented. */ - *cmd = NULL; - *cmd_and_args = NULL; -#endif - - /* - ** Locate the file descriptor that has the socket in question - ** open so that we can get the 'ucred' information - */ - for (i = 0; i < nfile; i++) - { - if (xfile[i].f_count == 0) - continue; - - if (xfile[i].f_type == DTYPE_SOCKET && - (struct socket *) xfile[i].f_data == sockp) - { - if (!getbuf((long)xfile[i].f_cred, (char *)&ucb, sizeof(ucb), "ucb")) - return -1; - - *uid = ucb.cr_uid; - return 0; - } - } - - return -1; + + *uid = myuid; + return 0; } - |
