2003-07-05 16:34:12 +04:00
|
|
|
/* $NetBSD: netbsd.c,v 1.21 2003/07/05 12:34:12 tsutsui Exp $ */
|
1997-10-08 11:07:40 +04:00
|
|
|
|
1994-02-05 00:41:32 +03:00
|
|
|
/*
|
1994-02-05 02:17:50 +03:00
|
|
|
** netbsd.c Low level kernel access functions for NetBSD
|
1994-02-05 00:41:32 +03:00
|
|
|
**
|
|
|
|
** This program is in the public domain and may be used freely by anyone
|
|
|
|
** who wants to.
|
|
|
|
**
|
1998-07-15 11:31:55 +04:00
|
|
|
** Last update: 15 July 1998
|
1994-02-05 00:41:32 +03:00
|
|
|
**
|
|
|
|
** Please send bug fixes/bug reports to: Peter Eriksson <pen@lysator.liu.se>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2003-07-05 16:34:12 +04:00
|
|
|
#include <stdlib.h>
|
1994-02-05 00:41:32 +03:00
|
|
|
#include <errno.h>
|
2003-06-26 21:31:12 +04:00
|
|
|
#include <string.h>
|
1994-02-05 00:41:32 +03:00
|
|
|
|
2003-06-26 21:31:12 +04:00
|
|
|
#include <sys/types.h>
|
1994-02-05 00:41:32 +03:00
|
|
|
#include <sys/param.h>
|
1994-05-14 23:39:03 +04:00
|
|
|
#include <sys/sysctl.h>
|
2003-06-26 21:31:12 +04:00
|
|
|
#include <sys/socket.h>
|
1994-02-05 00:41:32 +03:00
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/ip_var.h>
|
2003-06-26 21:31:12 +04:00
|
|
|
#include <netinet/tcp.h>
|
1994-02-05 00:41:32 +03:00
|
|
|
#include <netinet/tcp_timer.h>
|
|
|
|
#include <netinet/tcp_var.h>
|
|
|
|
|
|
|
|
#include "identd.h"
|
|
|
|
#include "error.h"
|
|
|
|
|
1998-07-15 11:31:55 +04:00
|
|
|
|
1994-02-05 00:41:32 +03:00
|
|
|
int k_open()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Return the user number for the connection owner
|
|
|
|
*/
|
2003-06-26 21:31:12 +04:00
|
|
|
int k_getuid(
|
|
|
|
struct in_addr *faddr,
|
|
|
|
int fport,
|
|
|
|
struct in_addr *laddr,
|
|
|
|
int lport,
|
|
|
|
int *uid
|
1998-07-15 11:31:55 +04:00
|
|
|
#ifdef ALLOW_FORMAT
|
2003-06-26 21:31:12 +04:00
|
|
|
, int *pid
|
|
|
|
, char **cmd
|
|
|
|
, char **cmd_and_args
|
1998-07-15 11:31:55 +04:00
|
|
|
#endif
|
2003-06-26 21:31:12 +04:00
|
|
|
)
|
1994-02-05 00:41:32 +03:00
|
|
|
{
|
2003-06-26 21:31:12 +04:00
|
|
|
int mib[8];
|
|
|
|
uid_t myuid = -1;
|
|
|
|
size_t uidlen = sizeof(myuid);
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
mib[0] = CTL_NET;
|
|
|
|
mib[1] = PF_INET;
|
|
|
|
mib[2] = IPPROTO_TCP;
|
|
|
|
mib[3] = TCPCTL_IDENT;
|
|
|
|
mib[4] = (int)faddr->s_addr;
|
|
|
|
mib[5] = fport;
|
|
|
|
mib[6] = (int)laddr->s_addr;
|
|
|
|
mib[7] = lport;
|
|
|
|
|
2003-06-27 22:37:48 +04:00
|
|
|
if ((rv = sysctl(mib, sizeof(mib) / sizeof(mib[0]), &myuid, &uidlen,
|
|
|
|
NULL, 0)) < 0) {
|
2003-06-26 21:31:12 +04:00
|
|
|
ERROR1("k_getuid: sysctl 1: %s", strerror(errno));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*uid = myuid;
|
|
|
|
return 0;
|
1994-02-05 00:41:32 +03:00
|
|
|
}
|